diff --git a/ReadMe.txt b/ReadMe.txt index c89c181..25de325 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -8,6 +8,7 @@ 广播方式升级从机发现卡死现象 2023.12.5 广播方式升级从机成功 - +2023.12.7 + 批检仪检测流程验证成功 diff --git a/base/mycfg.cpp b/base/mycfg.cpp index 54d64c0..86b183b 100644 --- a/base/mycfg.cpp +++ b/base/mycfg.cpp @@ -151,7 +151,7 @@ void mycfg::to_class(mystring str) } else { - QJsonObject j = doc.object(); + j = doc.object(); } tcp_enable = j.value("tcp_enable").toBool(true); server_ip = j.value("server_ip").toString("192.168.80.80"); diff --git a/checker_host.pro b/checker_host.pro index 143ca95..fe8463e 100644 --- a/checker_host.pro +++ b/checker_host.pro @@ -42,6 +42,7 @@ SOURCES += \ prot/prot_pc.cpp \ prot/prot_slave.cpp \ prot_cmd/cmd_cmdline.cpp \ + prot_cmd/cmd_m4.cpp \ prot_cmd/cmd_pc.cpp \ prot_cmd/cmd_slave.cpp @@ -68,6 +69,7 @@ HEADERS += \ prot/prot_pc.h \ prot/prot_slave.h \ prot_cmd/cmd_cmdline.h \ + prot_cmd/cmd_m4.h \ prot_cmd/cmd_pc.h \ prot_cmd/cmd_slave.h diff --git a/complier_info.h b/complier_info.h index 3f5fba2..c9cc723 100644 --- a/complier_info.h +++ b/complier_info.h @@ -6,7 +6,7 @@ -#define BUILD_DATE "2023-12-05 18:18:14" +#define BUILD_DATE "2023-12-07 18:27:08" diff --git a/info.json b/info.json index ba3716e..1bf1d1a 100644 --- a/info.json +++ b/info.json @@ -1,5 +1,5 @@ { - "build_date": "2023-12-05 18:18:14", + "build_date": "2023-12-07 18:27:08", "hard_version": "MHPZ2_V1.00", "private": [ "info.json", diff --git a/main.cpp b/main.cpp index dccae9e..ad789ee 100644 --- a/main.cpp +++ b/main.cpp @@ -12,6 +12,7 @@ #include "prot/prot_slave.h" #include "prot/prot_cmdline.h" #include "base/debug.h" +#include "prot_cmd/cmd_m4.h" @@ -22,8 +23,8 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); MainWindow w; // w.show(); + mydebug_init(); mycfg *cfg=syscfg(); - if(cfg->log_redirect=="file"){ mydebug_init("debug"); }else{ @@ -35,6 +36,7 @@ int main(int argc, char *argv[]) protPc(); protSlave(); command_start(); + cmd_m4_init(); // 注册信号数据类型 qRegisterMetaType("myarray"); diff --git a/prot/prot_pc.cpp b/prot/prot_pc.cpp index 2a9a442..98c867e 100644 --- a/prot/prot_pc.cpp +++ b/prot/prot_pc.cpp @@ -41,20 +41,7 @@ void ProtPc::init() myarray data=codec_->decode(src,dst,cmd,recv_data); recv_data.remove(0,pack_len); // qDebug("host recv removed:%s",recv_data.toHex(' ').data()); - if(handle_!=nullptr){ - if(handle_->busy==0){ - disconnect(handle_,&HandlePc::send_data_signal,this,&ProtPc::send_data_slot); - delete handle_; - }else{ - qWarning("prot_pc is busy."); - return; - } - } - handle_=handlePcFind(cmd); - if(handle_!=nullptr){ - connect(handle_,&HandlePc::send_data_signal,this,&ProtPc::send_data_slot); - handle_->dolater(cmd,data); - } + docmd(cmd,data); } }); } @@ -68,6 +55,31 @@ void ProtPc::send_data_slot(int cmd, myarray data) } } + +bool ProtPc::docmd(int cmd,myarray data) +{ + if(handle_!=nullptr){ + if(handle_->busy==0){ + disconnect(handle_,&HandlePc::send_data_signal,this,&ProtPc::send_data_slot); + delete handle_; + }else{ + qWarning("prot_pc is busy."); + return false; + } + } + handle_=handlePcFind(cmd); + if(handle_!=nullptr){ + connect(handle_,&HandlePc::send_data_signal,this,&ProtPc::send_data_slot); + handle_->dolater(cmd,data); + return true; + } + return false; +} + + + + + static ProtPc *g_protpc; ProtPc *protPc() { diff --git a/prot/prot_pc.h b/prot/prot_pc.h index d6a97da..82cc75a 100644 --- a/prot/prot_pc.h +++ b/prot/prot_pc.h @@ -60,7 +60,8 @@ public: } ~ProtPc() {} void init(); -protected slots: + bool docmd(int cmd,myarray data); +public slots: void send_data_slot(int cmd, myarray data); protected: diff --git a/prot/prot_slave.cpp b/prot/prot_slave.cpp index 5b555e6..56286a2 100644 --- a/prot/prot_slave.cpp +++ b/prot/prot_slave.cpp @@ -32,9 +32,11 @@ void prot_slave::init() }else{ handle=slaves[src-1]; if(handle!=nullptr){ - // handle->dolater(cmd,data); - emit slave_dolater_signal(cmd,data); - }else{ + handle->dolater(cmd,data); +// connect(this,&prot_slave::slave_dolater_signal,handle,&HandleSlave::dolater); +// emit slave_dolater_signal(cmd,data); +// disconnect(this,&prot_slave::slave_dolater_signal,handle,&HandleSlave::dolater); + }else{ qWarning("slave addr=%d not have handle.",src); } } @@ -66,7 +68,6 @@ bool prot_slave::set_slave_handle(int addr, HandleSlave *handle) } handle->addr=addr; connect(handle, &HandleSlave::send_data_signal, this, &prot_slave::send_data_slot); - connect(this,&prot_slave::slave_dolater_signal,handle,&HandleSlave::dolater); slaves.replace(addr - 1, handle); return true; } diff --git a/prot_cmd/cmd_m4.cpp b/prot_cmd/cmd_m4.cpp new file mode 100644 index 0000000..44b5f2f --- /dev/null +++ b/prot_cmd/cmd_m4.cpp @@ -0,0 +1,49 @@ + +#include "base/base.h" +#include "base/check_cfg.h" +#include "base/mycfg.h" +#include "prot/prot_m4.h" +#include "prot/prot_pc.h" + + +typedef struct{ + int key_pressed; + int ke1_pressed; +}self_def; + + +static self_def g_self; + + +void cmd_m4_init() +{ + prot_m4 *m4=protM4(); + m4->set_irq_fun([=](myarray data){ + ProtPc *pc=protPc(); + g_self.key_pressed=1; + qDebug("key press"); + pc->send_data_slot(0x37,myarray(1,char(0))); + },"key press"); + m4->set_irq_fun([=](myarray data){ + g_self.key_pressed=0; + qDebug("key up"); + },"key up"); + m4->set_irq_fun([=](myarray data){ + g_self.ke1_pressed=1; + qDebug("ke1 press"); + },"ke1 press"); + m4->set_irq_fun([=](myarray data){ + g_self.ke1_pressed=0; + qDebug("ke1 up"); + },"ke1 up"); +// m4->set_irq_fun([=](myarray data){ +// ProtPc *pc=protPc(); +// qDebug("send 0x37 to pc"); +// pc->send_data_slot(0x37,myarray(1,char(0))); +// },"key press"); +} + + + + + diff --git a/prot_cmd/cmd_m4.h b/prot_cmd/cmd_m4.h new file mode 100644 index 0000000..6ae07b0 --- /dev/null +++ b/prot_cmd/cmd_m4.h @@ -0,0 +1,14 @@ +#ifndef CMD_M4_H +#define CMD_M4_H + + + + +void cmd_m4_init(); + + + + + + +#endif // CMD_M4_H diff --git a/prot_cmd/cmd_pc.cpp b/prot_cmd/cmd_pc.cpp index 5b083d8..5beb8da 100644 --- a/prot_cmd/cmd_pc.cpp +++ b/prot_cmd/cmd_pc.cpp @@ -201,11 +201,19 @@ protpc_export(0x31, get_selfdev_checkend); int selfdev_moter::dolater(int cmd, myarray data) { prot_m4 *m4 = protM4(); + mycfg *cfg_=syscfg(); connect(this, &selfdev_moter::send_to_m4_signal, m4, &prot_m4::send_data_slot); if(data[0]==0x02){ emit send_to_m4_signal(moter_ctrl("up")); }else if(data[0]==0x03){ emit send_to_m4_signal(moter_ctrl("down")); + }else if(data[0]==0x01){ + if(data.size()>=3){ + int count=(data[1])|(data[2]<<8); + cfg_->moter_count=20000+count; + qDebug("moter count=%d",cfg_->moter_count); + cfg_->save(); + } } emit send_data_signal(0x40,myarray(1,char(0))); return 0; @@ -281,7 +289,7 @@ protpc_export(0xfe, get_selfdev_slaveupdate); - +// 方案升级 int selfdev_update_scheme::dolater(int cmd, myarray data) { myarray r; @@ -358,6 +366,229 @@ protpc_export(0x22, get_selfdev_update_scheme); +// 本机升级 +int selfdev_hostupdate::dolater(int cmd, myarray data) +{ + myarray r; + int len_filename=data[0]; + mystring name=data.mid(1,len_filename); + prot_slave *slave=protSlave(); + mycfg *cfg_=syscfg(); + busy=1; + qInfo()<<"host_app name:"<save_file(name,data); + emit send_data_signal(0xfd,myarray(1,char(0))); + + return 0; +} + +static HandlePc *get_selfdev_hostupdata(){ + return new selfdev_hostupdate(); +} + +protpc_export(0xfd, get_selfdev_hostupdata); + + + + + + + +// jwt升级 +int selfdev_jwtupdate::dolater(int cmd, myarray data) +{ + myarray r; + int len_filename=data[0]; + mystring name=data.mid(1,len_filename); + prot_slave *slave=protSlave(); + mycfg *cfg_=syscfg(); + busy=1; + qInfo()<<"jwt_app name:"<save_file(name,data); + emit send_data_signal(0xfe,myarray(1,char(0))); + + // 自动给小板升级 + // start_updata_mcu(cfg_->config_path+name,slave_addrs); + HandleBoardCast *b=new boardcast_updata_jwt(); + bool ack=slave->set_boardcast_handle(cfg_->calc_slave_addrs(),b); + if(ack==false){ + qWarning("handle is busy."); + busy=0; + }else{ + connect(b,&HandleBoardCast::end_signal,this,&selfdev_slaveupdate::slave_end_slot); + b->start(data); + } + + return 0; +} + +static HandlePc *get_selfdev_jwtupdate(){ + return new selfdev_jwtupdate(); +} + +protpc_export(0x27, get_selfdev_jwtupdate); + + + + + + + + +// 自研批检仪自检 +int selfdev_bootinfo::dolater(int cmd, myarray data) +{ + prot_slave *slave=protSlave(); + mycfg *cfg=syscfg(); + busy=1; + // 这里开始检测 + qDebug("get bootinfo."); + emit send_data_signal(cmd,myarray(1,0)); + QList addrs=cfg->calc_slave_addrs(); + foreach(int addr, addrs){ + HandleSlave *s=new slave_check(); + bool ack=slave->set_slave_handle(addr,s); + if(ack==false){ + qWarning("addr %d handle is busy.",addr); + }else{ + connect(s,&HandleSlave::end_signal,this,&selfdev_bootinfo::slave_end_slot); + s->start(myarray()); + } + } + slave_acked.clear(); + for(int i=0;islave_num;i++){ + slave_acked.append(myarray()); + } + slave_acked_num=0; + return 0; +} + +void selfdev_bootinfo::timeout() +{ + busy=0; +} + +#pragma pack(1) +typedef struct{ + char build_time[20]; + char softverion[8]; + int runtime; + uint8_t wdog; + char devicetype[12]; + uint8_t localip[4]; + uint8_t hostip[4]; + uint16_t hostport; + uint8_t localid; + uint32_t schemeid; + uint32_t slave_online; +}local_bootinfo; +#pragma pack() + +#pragma pack(1) +typedef struct{ + uint8_t app_state; + uint8_t slaver_addr; + uint16_t chip_tmper; + uint16_t ad_2v5; + uint16_t ad_1v25; + uint16_t ad_wave; + uint16_t ad_5v5_just; + uint16_t ad_26v_just; + uint16_t hard_version; + uint16_t soft_version; + uint16_t res_just; + uint32_t scheme_id; +}bootinfo_data; +#pragma pack() + +// 填充本机自检信息 +myarray bootinfo_fill_local(void) +{ + int tick=-1; + uint8_t wdog=0; + uint32_t temp32=0; + uint16_t temp16=0; + uint8_t temp8=0; + uint8_t ip[4]={0}; + QStringList iplist; + mycfg *cfg_=syscfg(); + check_cfg *ccfg_=check_plan(); + uint8_t *d=(uint8_t *)calloc(1,sizeof(local_bootinfo)); + memcpy(d,cfg_->build_date.toLocal8Bit(),cfg_->build_date.size()+1);d+=20; + memcpy(d,cfg_->soft_version.toLocal8Bit(),cfg_->soft_version.size()+1);d+=8; + memcpy(d,&tick,4);d+=4; + memcpy(d,&wdog,1);d+=1; + memcpy(d,cfg_->device_type.toLocal8Bit(),cfg_->device_type.size()+1);d+=12; + iplist=cfg_->local_ip.split('.'); + ip[0]=iplist[0].toInt(); + ip[1]=iplist[1].toInt(); + ip[2]=iplist[2].toInt(); + ip[3]=iplist[3].toInt(); + memcpy(d,ip,4);d+=4; + iplist=cfg_->server_ip.split('.'); + ip[0]=iplist[0].toInt(); + ip[1]=iplist[1].toInt(); + ip[2]=iplist[2].toInt(); + ip[3]=iplist[3].toInt(); + memcpy(d,ip,4);d+=4; + temp16=cfg_->server_port; + memcpy(d,&temp16,2);d+=2; + temp8=cfg_->local_id; + memcpy(d,&temp8,1);d+=1; + temp32=ccfg_->get_plan_id(); + memcpy(d,&temp32,4);d+=4; + temp32=0; + for(int i=0;islave_num;i++){ + temp32|=1<slave_acked.size()){ + qWarning("slave addr err:%d",addr); + return; + } + slave_acked.replace(addr-1,data); + slave_acked_num++; + if(slave_acked_num>=slave_acked.size()){ + myarray r; + r.append(char(0)); + r+=bootinfo_fill_local(); + for(int i=0;i slave_acked; + int slave_acked_num; +}; + + + + #endif diff --git a/prot_cmd/cmd_slave.cpp b/prot_cmd/cmd_slave.cpp index af8e558..a4ca836 100644 --- a/prot_cmd/cmd_slave.cpp +++ b/prot_cmd/cmd_slave.cpp @@ -383,3 +383,42 @@ int boardcast_updata_jwt::start(myarray data) + + +// 获取自检信息 +int slave_bootinfo::start(myarray data) +{ + mycfg *cfg_=syscfg(); + int timeout=5000; + busy=1; + cmd=0x13; + qDebug("addr %d get bootinfo,timeout=%d",addr,timeout); + send_data(cmd,myarray(),3); + timeout_start(timeout); + return 0; +} + +void slave_bootinfo::timeout() +{ + timeout_stop(); + qWarning("addr %d get bootinfo.",addr); + end(1,myarray()); + busy=0; +} + +int slave_bootinfo::dolater(int cmd, myarray data) +{ + if(cmd!=this->cmd){ + qWarning("addr %d recv err cmd:%02x",addr,cmd); + return 1; + } + timeout_stop_retry(); + end(0,data); + busy=0; + return 0; +} + + + + + diff --git a/prot_cmd/cmd_slave.h b/prot_cmd/cmd_slave.h index e9e43c0..bfdd5a7 100644 --- a/prot_cmd/cmd_slave.h +++ b/prot_cmd/cmd_slave.h @@ -122,4 +122,18 @@ public: + +// 自检信息 +class slave_bootinfo:public HandleSlave +{ +public: + slave_bootinfo():HandleSlave(){} + int start(myarray data); + int dolater(int cmd, myarray data); + void timeout(); +}; + + + + #endif // CMD_SLAVE_H