添加tcp心跳
添加升级小板程序、方案、jwt文件的进度条命令
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "base/check_cfg.h"
|
||||
#include "QDebug"
|
||||
#include "elec/elec_judge.h"
|
||||
#include "QDateTime"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -349,7 +350,6 @@ int selfdev_slaveupdate::dolater(int cmd, myarray data)
|
||||
emit send_data_signal(0xfe,myarray(1,char(0)));
|
||||
|
||||
// 自动给小板升级
|
||||
// start_updata_mcu(cfg_->config_path+name,slave_addrs);
|
||||
HandleBoardCast *b=new boardcast_updata();
|
||||
bool ack=slave->set_boardcast_handle(cfg_->calc_slave_addrs(),b);
|
||||
if(ack==false){
|
||||
@@ -357,6 +357,8 @@ int selfdev_slaveupdate::dolater(int cmd, myarray data)
|
||||
busy=0;
|
||||
}else{
|
||||
connect(b,&HandleBoardCast::end_signal,this,&selfdev_slaveupdate::slave_end_slot);
|
||||
connect(b,&HandleBoardCast::rate_signal,this,&selfdev_slaveupdate::rate_slot);
|
||||
handle_start_time=QDateTime::currentDateTime().toTime_t();
|
||||
b->start(data);
|
||||
}
|
||||
|
||||
@@ -368,6 +370,18 @@ void selfdev_slaveupdate::timeout(){
|
||||
qDebug("slave update timeout");
|
||||
}
|
||||
|
||||
void selfdev_slaveupdate::rate_slot(int rate, mystring str)
|
||||
{
|
||||
qint64 now_time=QDateTime::currentDateTime().toTime_t();
|
||||
now_time=now_time-handle_start_time;
|
||||
myarray data;
|
||||
data.append(char(rate&0xff));
|
||||
data.append(uint8_t(now_time&0xff));
|
||||
data.append(uint8_t((now_time>>8)&0xff));
|
||||
data.append(str.toLocal8Bit());
|
||||
emit send_data_signal(0x46,data);
|
||||
}
|
||||
|
||||
void selfdev_slaveupdate::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
qDebug("slave update end,ack=%s",ack?"failed":"success");
|
||||
@@ -414,11 +428,6 @@ int selfdev_update_scheme::dolater(int cmd, myarray data)
|
||||
r.append(ack?char(0):char(1));
|
||||
r.append(rw);
|
||||
if(ack){
|
||||
// 检测数据保存
|
||||
// if(comm_f_!=nullptr){
|
||||
// delete comm_f_;
|
||||
// comm_f_=nullptr;
|
||||
// }
|
||||
// 自动给小板升级
|
||||
HandleBoardCast *b=new boardcast_updata_scheme();
|
||||
bool ack=slave->set_boardcast_handle(cfg_->calc_slave_addrs(),b);
|
||||
@@ -427,6 +436,8 @@ int selfdev_update_scheme::dolater(int cmd, myarray data)
|
||||
busy=0;
|
||||
}else{
|
||||
connect(b,&HandleBoardCast::end_signal,this,&selfdev_update_scheme::slave_end_slot);
|
||||
connect(b,&HandleBoardCast::rate_signal,this,&selfdev_update_scheme::rate_slot);
|
||||
handle_start_time=QDateTime::currentDateTime().toTime_t();
|
||||
myarray scheme=myarray((const char *)ccfg_->check_scheme(),ccfg_->check_scheme_size());
|
||||
b->start(scheme);
|
||||
}
|
||||
@@ -444,6 +455,17 @@ void selfdev_update_scheme::timeout(){
|
||||
busy=0;
|
||||
qDebug("slave update timeout");
|
||||
}
|
||||
void selfdev_update_scheme::rate_slot(int rate, mystring str)
|
||||
{
|
||||
qint64 now_time=QDateTime::currentDateTime().toTime_t();
|
||||
now_time=now_time-handle_start_time;
|
||||
myarray data;
|
||||
data.append(char(rate&0xff));
|
||||
data.append(uint8_t(now_time&0xff));
|
||||
data.append(uint8_t((now_time>>8)&0xff));
|
||||
data.append(str.toLocal8Bit());
|
||||
emit send_data_signal(0x46,data);
|
||||
}
|
||||
|
||||
void selfdev_update_scheme::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
@@ -523,6 +545,8 @@ int selfdev_jwtupdate::dolater(int cmd, myarray data)
|
||||
busy=0;
|
||||
}else{
|
||||
connect(b,&HandleBoardCast::end_signal,this,&selfdev_slaveupdate::slave_end_slot);
|
||||
connect(b,&HandleBoardCast::rate_signal,this,&selfdev_slaveupdate::rate_slot);
|
||||
handle_start_time=QDateTime::currentDateTime().toTime_t();
|
||||
b->start(data);
|
||||
}
|
||||
|
||||
|
@@ -116,14 +116,19 @@ class selfdev_slaveupdate : public HandlePc
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
selfdev_slaveupdate() : HandlePc() {}
|
||||
selfdev_slaveupdate() : HandlePc() {
|
||||
handle_start_time=0;
|
||||
}
|
||||
~selfdev_slaveupdate() {}
|
||||
int dolater(int cmd, myarray data);
|
||||
void timeout();
|
||||
public slots:
|
||||
void slave_end_slot(int addr,int ack, slave_data data);
|
||||
void rate_slot(int rate, mystring str);
|
||||
signals:
|
||||
void send_to_m4_signal(myarray data);
|
||||
protected:
|
||||
qint64 handle_start_time;
|
||||
};
|
||||
|
||||
|
||||
@@ -142,8 +147,11 @@ public:
|
||||
void timeout();
|
||||
public slots:
|
||||
void slave_end_slot(int addr,int ack, slave_data data);
|
||||
void rate_slot(int rate, mystring str);
|
||||
signals:
|
||||
void send_to_m4_signal(myarray data);
|
||||
protected:
|
||||
qint64 handle_start_time;
|
||||
};
|
||||
|
||||
|
||||
@@ -277,7 +285,7 @@ public:
|
||||
// pc指令生成从机列表
|
||||
virtual QList<int> cmd_pc_to_addrs(myarray data)=0;
|
||||
// 从机发起命令
|
||||
virtual int cmd_slave()=0;
|
||||
virtual int cmd_slave(){return 0x20;}
|
||||
// pc收到回复,返回0不回复
|
||||
virtual int cmd_pc_recv()=0;
|
||||
// 生成接收回复到pc
|
||||
@@ -299,7 +307,30 @@ signals:
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
||||
selfdev_runtask 重载示例
|
||||
class selfdef_custom:public selfdev_runtask
|
||||
{
|
||||
// 重载此函数把pc的指令格式转化为从机能识别的格式
|
||||
myarray cmd_pc_to_slave(myarray data);
|
||||
// 重载此函数根据pc指令生成要执行命令的从机列表
|
||||
QList<int> cmd_pc_to_addrs(myarray data);
|
||||
// (可选)重载此函数设置从机要执行的命令,不重载则使用命令0x20
|
||||
int cmd_slave();
|
||||
// 重载此函数指定收到数据回复的命令字
|
||||
int cmd_pc_recv();
|
||||
// 重载此函数生成接收到数据回复的数据
|
||||
myarray cmd_pc_recv_to_pc();
|
||||
// 重载此函数指定操作结束回复的命令字
|
||||
int cmd_pc_ret();
|
||||
// 重载此函数把从机的数据格式转化为pc能识别的格式
|
||||
myarray ret_slave_to_pc(QList<myarray> data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// 赋码仪配置参数
|
||||
|
@@ -380,6 +380,16 @@ int boardcast_updata_scheme::start(myarray data)
|
||||
|
||||
int boardcast_updata_scheme::dolater(int cmd, myarray data)
|
||||
{
|
||||
for(int i=0;i<ret_data.size();i++){
|
||||
if(ret_data[i][0]!=0){
|
||||
timeout_stop();
|
||||
timeout_stop_retry();
|
||||
qDebug("slave updata scheme failed.");
|
||||
end(1,ret_data);
|
||||
busy=0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
timeout_start(5000);
|
||||
if(step==0){
|
||||
if(send_packet()==true){
|
||||
@@ -498,7 +508,8 @@ int slave_cmd::start(myarray data)
|
||||
if(data[0]!=3){
|
||||
timeout=check_plan()->get_check_time_out()*1000;
|
||||
}
|
||||
qDebug("addr %d start ,timeout=%d",addr,timeout);
|
||||
// 这里addr是bit数,用16进制打印
|
||||
qDebug("addr 0x%06X start ,timeout=%d",addr,timeout);
|
||||
this->data=data;
|
||||
send_pack_num=0;
|
||||
send_bytes=0;
|
||||
@@ -534,7 +545,8 @@ bool slave_cmd::send_next()
|
||||
void slave_cmd::timeout()
|
||||
{
|
||||
timeout_stop();
|
||||
qWarning("addr %d timeout.",addr);
|
||||
int addr_timeout=addr^addr_response;
|
||||
qWarning("addr 0x%06X timeout",addr_timeout);
|
||||
end(1,ret_data);
|
||||
busy=0;
|
||||
}
|
||||
@@ -571,7 +583,8 @@ int slave_cmd2::start(myarray data)
|
||||
{
|
||||
int timeout=5000;
|
||||
busy=1;
|
||||
qDebug("addr %d start ,timeout=%d",addr,timeout);
|
||||
// 这里addr是bit数,用16进制打印
|
||||
qDebug("addr 0x%06X start ,timeout=%d",addr,timeout);
|
||||
send_data(cmd,data,3);
|
||||
timeout_start(timeout);
|
||||
return 0;
|
||||
@@ -580,7 +593,8 @@ int slave_cmd2::start(myarray data)
|
||||
void slave_cmd2::timeout()
|
||||
{
|
||||
timeout_stop();
|
||||
qWarning("addr %d timeout.",addr);
|
||||
int addr_timeout=addr^addr_response;
|
||||
qWarning("addr 0x%06X timeout",addr_timeout);
|
||||
end(1,ret_data);
|
||||
busy=0;
|
||||
}
|
||||
|
@@ -147,6 +147,7 @@ public:
|
||||
|
||||
|
||||
// 获取命令数据,使用前先设置cmd
|
||||
// 自动加入包信息,可以发送长数据
|
||||
class slave_cmd:public HandleBoardCast
|
||||
{
|
||||
public:
|
||||
@@ -169,6 +170,7 @@ protected:
|
||||
|
||||
|
||||
// 获取命令数据,使用前先设置cmd
|
||||
// 不加入分包信息,不可发送长数据
|
||||
class slave_cmd2:public HandleBoardCast
|
||||
{
|
||||
public:
|
||||
|
113
prot_cmd/keep_live.cpp
Normal file
113
prot_cmd/keep_live.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "keep_live.h"
|
||||
#include "interface/if_tcp.h"
|
||||
#include "base/mycfg.h"
|
||||
#include "interface/if_tcp.h"
|
||||
#include "prot/prot_pc.h"
|
||||
#include "QDateTime"
|
||||
|
||||
|
||||
int keep_live_checker::dolater(int cmd,myarray data)
|
||||
{
|
||||
data.remove(0,1);
|
||||
QDateTime t=QDateTime::currentDateTime();
|
||||
if(t.toString("yyyy-MM-dd hh:mm:ss")!=QString(data))
|
||||
{
|
||||
// 时间不相等则设置
|
||||
//qInfo()<<"set time="<<QString(data)<<endl;
|
||||
QString m="date -s \"%1\"";
|
||||
m=m.arg(QString(data));
|
||||
//qInfo()<<m<<endl;
|
||||
system(m.toLocal8Bit().data()); // 0312 表示3月12日,1025表示当前时分
|
||||
system("hwclock -w"); // 同步系统时间
|
||||
system("sync"); // 保存配置
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HandlePc *get_keep_live_checker(){
|
||||
return new keep_live_checker();}
|
||||
protpc_export(0x23, get_keep_live_checker);
|
||||
|
||||
|
||||
|
||||
void keep_live::init()
|
||||
{
|
||||
mycfg *cfg_=syscfg();
|
||||
if_tcp *tcp=static_cast<if_tcp *>(if_tcp_get());
|
||||
if(cfg_->tcp_enable!=true){
|
||||
return;
|
||||
}
|
||||
if(timer_==nullptr){
|
||||
timer_=new QTimer();
|
||||
connect(timer_,&QTimer::timeout,this,&keep_live::timeout_slot);
|
||||
timer_->setInterval(1000);
|
||||
timer_->start();
|
||||
connect(tcp,&if_tcp::tcp_connected_signal,this,&keep_live::connected_slot);
|
||||
connect(tcp,&if_tcp::tcp_recv_signal,this,&keep_live::recv_slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keep_live::connected_slot()
|
||||
{
|
||||
if(timer_!=nullptr){
|
||||
timer_->setInterval(30*1000);
|
||||
timer_->start();
|
||||
}
|
||||
}
|
||||
|
||||
void keep_live::recv_slot()
|
||||
{
|
||||
if(timer_!=nullptr){
|
||||
timer_->start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// state 0idle,1,busy,2,failt
|
||||
void keep_checker::timeout_slot(){
|
||||
myarray data;
|
||||
mycfg *cfg_=syscfg();
|
||||
ProtPc *pc_=protPc();
|
||||
data.append(uint8_t(cfg_->local_id));
|
||||
data.append(uint8_t(pc_->busy()));
|
||||
data.append(myarray("正常"));
|
||||
pc_->send_data_slot(uint8_t(0x23),data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void keep_coder::timeout_slot(){
|
||||
myarray data;
|
||||
mycfg *cfg_=syscfg();
|
||||
ProtPc *pc_=protPc();
|
||||
data.append(uint8_t(0));
|
||||
data.append(uint8_t(0xff));
|
||||
data.append(uint8_t(0x03));
|
||||
data.append(uint8_t(cfg_->local_id));
|
||||
data.append(uint8_t(0xff));
|
||||
data.append(uint8_t(0x03));
|
||||
pc_->send_data_slot(uint8_t(0x8a),data);
|
||||
}
|
||||
|
||||
|
||||
keep_live *KeepLive()
|
||||
{
|
||||
static keep_live *kp=nullptr;
|
||||
mycfg *cfg_=syscfg();
|
||||
if(kp!=nullptr){
|
||||
return kp;
|
||||
}
|
||||
if(cfg_->tcp_enable){
|
||||
if(cfg_->device_type=="checker"){
|
||||
kp=new keep_checker();
|
||||
}else if(cfg_->device_type.contains("coder",Qt::CaseInsensitive)==true){
|
||||
kp=new keep_coder();
|
||||
}
|
||||
}
|
||||
return kp;
|
||||
}
|
||||
|
64
prot_cmd/keep_live.h
Normal file
64
prot_cmd/keep_live.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef KEEP_LIVE_H
|
||||
#define KEEP_LIVE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "prot/prot_pc.h"
|
||||
#include "QTimer"
|
||||
|
||||
class keep_live_checker : public HandlePc
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
keep_live_checker():HandlePc(){
|
||||
|
||||
}
|
||||
int dolater(int cmd,myarray data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class keep_live:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
keep_live():QObject(){
|
||||
timer_=nullptr;
|
||||
}
|
||||
void init();
|
||||
public slots:
|
||||
virtual void timeout_slot()=0;
|
||||
void connected_slot();
|
||||
void recv_slot();
|
||||
protected:
|
||||
QTimer *timer_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class keep_checker:public keep_live
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
keep_checker():keep_live(){
|
||||
}
|
||||
void timeout_slot();
|
||||
};
|
||||
|
||||
|
||||
class keep_coder:public keep_live
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
keep_coder():keep_live(){
|
||||
}
|
||||
void timeout_slot();
|
||||
};
|
||||
|
||||
|
||||
keep_live *KeepLive();
|
||||
|
||||
|
||||
#endif // KEEP_LIVE_H
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user