From 2451c5dfc57cf4a6209ed376560563b774092294 Mon Sep 17 00:00:00 2001 From: ranchuan Date: Mon, 4 Dec 2023 18:15:37 +0800 Subject: [PATCH] =?UTF-8?q?=20=20=E8=87=AA=E7=A0=94=E6=89=B9=E6=A3=80?= =?UTF-8?q?=E4=BB=AA=E6=A3=80=E6=B5=8B=E5=91=BD=E4=BB=A4=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=88=90=E5=8A=9F=20=20=20=E5=B9=BF=E6=92=AD=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BB=8E=E6=9C=BA=E5=8F=91=E7=8E=B0=E5=8D=A1?= =?UTF-8?q?=E6=AD=BB=E7=8E=B0=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReadMe.txt | 4 +- base/base.cpp | 18 ++++---- base/base.h | 9 +++- base/check_cfg.cpp | 4 +- base/debug.cpp | 4 +- checker_app_pre.sh | 15 +++++++ complier_info.h | 2 +- info.json | 2 +- interface/codec_ym.cpp | 9 ++-- interface/if_can.cpp | 3 ++ interface/if_uart.cpp | 2 +- main.cpp | 2 + prot/prot_m4.cpp | 17 +++++--- prot/prot_pc.cpp | 1 + prot/prot_slave.h | 47 +++++++++++++++------ prot_cmd/cmd_cmdline.cpp | 47 ++++++++++++++++++++- prot_cmd/cmd_pc.cpp | 91 +++++++++++++++++++++++++++++++++------- prot_cmd/cmd_pc.h | 18 ++++++++ prot_cmd/cmd_slave.cpp | 30 +++++++------ 19 files changed, 256 insertions(+), 69 deletions(-) create mode 100644 checker_app_pre.sh diff --git a/ReadMe.txt b/ReadMe.txt index 8f2de9e..97fc4c8 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -3,7 +3,9 @@ 2023.11.26 重新构建的批检仪主板程序 - +2023.12.4 + 自研批检仪检测命令测试成功 + 广播方式升级从机发现卡死现象 diff --git a/base/base.cpp b/base/base.cpp index cde4528..4767e46 100644 --- a/base/base.cpp +++ b/base/base.cpp @@ -4,15 +4,15 @@ #include "QList" // 字符串转化为数字列表 -template -QList str_to_nums(mystring str, char c) -{ - QStringList snums = str.split(c); - QList nums; - for (int i = 0; i < snums.size(); i++) - nums.append(T(snums[i].toInt(nullptr, 10))); - return nums; -} +//template +//QList str_to_nums(mystring str, char c) +//{ +// QStringList snums = str.split(c); +// QList nums; +// for (int i = 0; i < snums.size(); i++) +// nums.append(T(snums[i].toInt(nullptr, 10))); +// return nums; +//} // 字符串转化为数组 myarray str_to_data(mystring str, char c) diff --git a/base/base.h b/base/base.h index a9293ad..e6b13b0 100644 --- a/base/base.h +++ b/base/base.h @@ -102,7 +102,14 @@ protected: }; template -QList str_to_nums(mystring str, char c); +QList str_to_nums(mystring str, char c) +{ + QStringList snums = str.split(c); + QList nums; + for (int i = 0; i < snums.size(); i++) + nums.append(T(snums[i].toInt(nullptr, 10))); + return nums; +} myarray str_to_data(mystring str, char c); diff --git a/base/check_cfg.cpp b/base/check_cfg.cpp index 5818b61..77c1d18 100644 --- a/base/check_cfg.cpp +++ b/base/check_cfg.cpp @@ -95,10 +95,10 @@ void check_cfg::scheme_json_to_struct() QList rangs = ct.get_ranges(); int rangs_num = rangs.size(); int err_num = ret_errs.size(); - qDebug("st,err,item_num=%d,taskid=%d,taskindex=%d", st->item_num, st->taskid, st->taskindex); + // qDebug("st,err,item_num=%d,taskid=%d,taskindex=%d", st->item_num, st->taskid, st->taskindex); for (int i = 0; i < st->item_num; i++) { - qDebug("\ti=%d", i); + // qDebug("\ti=%d", i); if (rangs_num > i) { st->range[i].err = 0; diff --git a/base/debug.cpp b/base/debug.cpp index d08a568..56a9f3e 100644 --- a/base/debug.cpp +++ b/base/debug.cpp @@ -91,7 +91,7 @@ void print_to_console(QtMsgType type, const QMessageLogContext &context, const Q if(context.file!=0){ fprintf(stderr, "%s | %s | %s:%u | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), &context.file[20], context.line, localMsg.constData()); }else{ - fprintf(stderr,"%s | %s | %s:%u | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), context.file, context.line, localMsg.constData()); + fprintf(stderr,"%s | %s | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), localMsg.constData()); } g_debug.mutex.unlock(); } @@ -107,7 +107,7 @@ void print_to_file(QtMsgType type, const QMessageLogContext &context, const QStr if(context.file!=0){ tWrite << QString::asprintf("%s | %s | %s:%u | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), &context.file[20], context.line, localMsg.constData()); }else{ - tWrite << QString::asprintf("%s | %s | %s:%u | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), context.file, context.line, localMsg.constData()); + tWrite << QString::asprintf("%s | %s | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), localMsg.constData()); } } g_debug.mutex.unlock(); diff --git a/checker_app_pre.sh b/checker_app_pre.sh new file mode 100644 index 0000000..f381845 --- /dev/null +++ b/checker_app_pre.sh @@ -0,0 +1,15 @@ +#! /bin/bash +#ifconfig eth0 up +#sleep 1 +#效果:将设备号eth0对应的物理端口设置为速率为100Mbps,全双工工作模式,同时关闭自动协商 +#ethtool -s eth0 speed 100 duplex full autoneg off +#sleep 2 +#ifconfig eth0 up + +# 加载m4固件 +echo stop > /sys/class/remoteproc/remoteproc0/state +echo checker_m4.axf > /sys/class/remoteproc/remoteproc0/firmware +echo start > /sys/class/remoteproc/remoteproc0/state + +echo Prapare_OK + diff --git a/complier_info.h b/complier_info.h index ec4a3dc..005fbc5 100644 --- a/complier_info.h +++ b/complier_info.h @@ -6,7 +6,7 @@ -#define BUILD_DATE "2023-12-01 11:08:00" +#define BUILD_DATE "2023-12-04 18:04:43" diff --git a/info.json b/info.json index f5d1d53..3243477 100644 --- a/info.json +++ b/info.json @@ -1,5 +1,5 @@ { - "build_date": "2023-12-01 11:08:00", + "build_date": "2023-12-04 18:04:43", "hard_version": "MHPZ2_V1.00", "private": [ "info.json", diff --git a/interface/codec_ym.cpp b/interface/codec_ym.cpp index 9102238..3ebb2a3 100644 --- a/interface/codec_ym.cpp +++ b/interface/codec_ym.cpp @@ -71,8 +71,9 @@ myarray CodecYm::decode(int &srcAddr, int &dstAddr, int &cmd, myarray data) Q_UNUSED(srcAddr); Q_UNUSED(dstAddr); myarray r; - if (packCheck(data) == true) + if (packCheck(data) >0) { + qDebug("offset=%d",offset); cmd = this->cmd; if (is_big_data == false) r = data.mid(offset+7, len - 3); @@ -100,7 +101,7 @@ int CodecYm::packCheck(myarray data) if (data.size() < 9) { // 主机一帧数据至少9字节 - qWarning("recv data len too less"); + // qWarning("recv data len too less"); return ack; } @@ -118,7 +119,7 @@ int CodecYm::packCheck(myarray data) if (len + 6 > data.size()) { // 如果长度不相等则产生了数据丢失 - qWarning("recv data have lossed"); + // qWarning("recv data have lossed"); return ack; } uint8_t chk_a = 0, chk_b = 0; @@ -133,7 +134,7 @@ int CodecYm::packCheck(myarray data) cmd_no = data[5] | (data[6] << 8); cmd = data[4]; // 数据负载 - return len+offset; + return len+offset+6; } myarray CodecYm::encode(int srcAddr, int dstAddr, int cmd, myarray data) { diff --git a/interface/if_can.cpp b/interface/if_can.cpp index 430c1f4..d04ec99 100644 --- a/interface/if_can.cpp +++ b/interface/if_can.cpp @@ -189,6 +189,7 @@ void can_host::recv_data_cb() irq_fun(myarray(slave.get_data())); } } + qDebug()<<"can recv from:"<readAll(); - qDebug("uart recv:%s", data.toHex(' ').data()); + // qDebug("uart recv:%s", data.toHex(' ').data()); if (irq_fun) { irq_fun(myarray(data)); diff --git a/main.cpp b/main.cpp index 7372323..dccae9e 100644 --- a/main.cpp +++ b/main.cpp @@ -35,6 +35,8 @@ int main(int argc, char *argv[]) protPc(); protSlave(); command_start(); + // 注册信号数据类型 + qRegisterMetaType("myarray"); // 获取m4的编译时间 m4->set_irq_fun([=](myarray data){ diff --git a/prot/prot_m4.cpp b/prot/prot_m4.cpp index f40fb9d..b9ff1f0 100644 --- a/prot/prot_m4.cpp +++ b/prot/prot_m4.cpp @@ -45,19 +45,26 @@ void prot_m4::send_data_slot(myarray data) bool prot_m4::exe_cb_fun(myarray data) { int left; + QList cb_funs; for (int i = 0; i < funs.size(); i++) + { + cb_funs.append(this->funs[i]); + } + for (int i = 0; i < cb_funs.size(); i++) { // 这里size包含结尾符,要去掉 - left = funs[i].cmd.size()-1; - if (data.left(left) == funs[i].cmd) + left = qstrlen(cb_funs[i].cmd.data()); + // qDebug()<<"cmp m4 str:"<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); diff --git a/prot/prot_slave.h b/prot/prot_slave.h index b97ce69..29b57f1 100644 --- a/prot/prot_slave.h +++ b/prot/prot_slave.h @@ -33,7 +33,7 @@ public: public: virtual int start(myarray data) = 0; virtual int dolater(int cmd, myarray data) = 0; - virtual void timeout(){timer_->stop();}; + virtual void timeout(){timer_->stop();} int busy; int addr; int cmd; @@ -45,9 +45,9 @@ protected: this->times_retry=times; if(timer_retry_==nullptr){ timer_retry_=new QTimer(); - connect(timer_,&QTimer::timeout,this,&HandleSlave::timeout_retry); + connect(timer_retry_,&QTimer::timeout,this,&HandleSlave::timeout_retry); } - timer_retry_->start(60); + timeout_retry(); return 0; } // 发送操作结束信号 @@ -82,7 +82,9 @@ private: void timeout_retry(){ if(times_retry>0){ times_retry--; + qDebug("send to slave:%d",addr); emit send_data_signal(addr,cmd,data_send); + timer_retry_->start(60); }else{ timer_retry_->stop(); } @@ -126,7 +128,7 @@ public: public: virtual int start(myarray data) = 0; virtual int dolater(int cmd, myarray data) = 0; - virtual void timeout(){timer_->stop();}; + virtual void timeout(){timer_->stop();} int busy; int addr; int addr_response; @@ -143,6 +145,11 @@ public: addr|=1<<(adr-1); } } +signals: + void timeout_stop_retry_signal(); + void timeout_stop_signal(); + void timeout_start_signal(int ms); + void timeout_start_retry_signal(int ms); protected: // 发送数据到从机 int send_data(int cmd,myarray data,int times){ @@ -152,8 +159,11 @@ protected: if(timer_retry_==nullptr){ timer_retry_=new QTimer(); connect(timer_,&QTimer::timeout,this,&HandleBoardCast::timeout_retry); + connect(this,&HandleBoardCast::timeout_stop_retry_signal,timer_retry_,&QTimer::stop); + connect(this,&HandleBoardCast::timeout_start_retry_signal,this,&HandleBoardCast::timeout_start_retry_cb); } - timer_retry_->start(300); + qDebug("handle_board:start retry"); + timeout_retry(); return 0; } // 发送操作结束信号 @@ -163,29 +173,39 @@ protected: } // 开始超时计时器,此计时器用于整个操作的超时 void timeout_start(int ms){ + qDebug("handle_board:start timeout"); if(timer_==nullptr){ timer_=new QTimer(); connect(timer_,&QTimer::timeout,this,&HandleBoardCast::timeout); + connect(this,&HandleBoardCast::timeout_stop_signal,timer_,&QTimer::stop); + connect(this,&HandleBoardCast::timeout_start_signal,this,&HandleBoardCast::timeout_start_cb); + }else{ + emit timeout_start_signal(ms); + // timer_->start(ms); } + } + void timeout_start_cb(int ms){ timer_->start(ms); } + void timeout_start_retry_cb(int ms){ + timer_retry_->start(ms); + } // 停止超时计时器,此方法同时停止重发计时器 void timeout_stop(){ - if(timer_!=nullptr){ - timer_->stop(); - } + qDebug("handle_board:stop timeout"); + emit timeout_stop_signal(); timeout_stop_retry(); } // 停止数据回复超时重试计时器 void timeout_stop_retry(){ - if(timer_retry_!=nullptr){ - timer_retry_->stop(); - } + qDebug("handle_board:stop retry"); + emit timeout_stop_retry_signal(); times_retry=0; } private: // 重试回调 void timeout_retry(){ + qDebug("in retry."); if(times_retry>0){ times_retry--; myarray s; @@ -196,8 +216,11 @@ private: s.append((addr_retry>>16)&0xff); s.append(data_send); emit send_data_signal(0x1f,cmd,s); + // timer_retry_->start(300); + emit timeout_start_retry_signal(300); }else{ - timer_retry_->stop(); + // timer_retry_->stop(); + emit timeout_stop_retry_signal(); } } private: diff --git a/prot_cmd/cmd_cmdline.cpp b/prot_cmd/cmd_cmdline.cpp index c545d04..9f1819e 100644 --- a/prot_cmd/cmd_cmdline.cpp +++ b/prot_cmd/cmd_cmdline.cpp @@ -3,7 +3,10 @@ #include "QNetworkConfigurationManager" #include "QTimer" #include "QtNetwork" - +#include "prot/prot_slave.h" +#include "prot_cmd/cmd_slave.h" +#include "QFile" +#include "base/base.h" @@ -46,3 +49,45 @@ cmdline_export(whos, whos, print device base info.); + +// mcu 相关 +static void mcu_cmdlines(QList args) +{ + command *c=command_start(); + if(args.size()<2){ + c->send("cmd len too less."); + return ; + } + if((args.size()>=4)&&(args[1]=="updata")){ + QList addrs=str_to_nums(args[2],','); + HandleBoardCast *b=new boardcast_updata(); + prot_slave *slave=protSlave(); + mycfg *cfg_=syscfg(); + bool ack=slave->set_boardcast_handle(addrs,b); + if(ack==false){ + qWarning("handle is busy."); + }else{ +// connect(b,&HandleBoardCast::end_signal,nullptr,[=](int addr,int ack, myarray data){ +// if(ack==0) +// c->send("slave updata success."); +// else +// c->send("slave updata failed."); +// }); + QFile file; + file.setFileName(args[3]); + if(file.open(QIODevice::ReadOnly)){ + myarray data=file.readAll(); + b->start(data); + file.close(); + }else{ + qWarning("open file failed."); + } + } + } +} +cmdline_export(mcu, mcu_cmdlines, mcu cmdlines` input [mcu help] to detail.); + + + + + diff --git a/prot_cmd/cmd_pc.cpp b/prot_cmd/cmd_pc.cpp index 5a77bae..93c6803 100644 --- a/prot_cmd/cmd_pc.cpp +++ b/prot_cmd/cmd_pc.cpp @@ -77,23 +77,32 @@ int selfdev_check::dolater(int cmd, myarray data) connect(this, &selfdev_check::send_to_m4_signal, m4, &prot_m4::send_data_slot); moter_down_cb_fun=[=](myarray data) { - m4->del_irq_fun(moter_down_cb_fun,"moter "); - if(data=="down"){ + m4->del_irq_fun(moter_down_cb_fun,"moter down"); + { // 这里开始检测 + qDebug("start check."); + emit send_data_signal(cmd,myarray(1,0)); QList addrs=cfg->calc_slave_addrs(); - HandleSlave *s=new slave_check(); 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_check::slave_end_slot); + s->start(myarray()); } } } }; - m4->set_irq_fun(moter_down_cb_fun,"moter "); - emit send_to_m4_signal(moter_ctrl("down")); + myarray moter_cmd=moter_ctrl("down"); + if(moter_cmd.size()==0){ + busy=0; + qWarning("moter failed."); + }else{ + m4->set_irq_fun(moter_down_cb_fun,"moter down"); + emit send_to_m4_signal(moter_cmd); + } slave_acked.clear(); for(int i=0;islave_num;i++){ slave_acked.append(myarray()); @@ -104,7 +113,7 @@ int selfdev_check::dolater(int cmd, myarray data) void selfdev_check::timeout() { - + busy=0; } // 把小板的返回数据转化为自研批检仪上位机的格式 @@ -136,8 +145,10 @@ static myarray tran_slave_to_selfdev_check(myarray &data) void selfdev_check::slave_end_slot(int addr,int ack, myarray data) { if(addr<=0||addr>slave_acked.size()){ - slave_acked.replace(addr-1,data); + 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; @@ -160,7 +171,33 @@ protpc_export(0x30, get_selfdev_check); +// 检测结束 电机上升 +int selfdev_checkend::dolater(int cmd, myarray data) +{ + prot_m4 *m4 = protM4(); + connect(this, &selfdev_checkend::send_to_m4_signal, m4, &prot_m4::send_data_slot); + emit send_to_m4_signal(moter_ctrl("up")); + return 0; +} +void selfdev_checkend::timeout(){ + +} + +static HandlePc *get_selfdev_checkend(){ + return new selfdev_checkend(); +} + +protpc_export(0x31, get_selfdev_checkend); + + + + + + + + +// 电机控制 int selfdev_moter::dolater(int cmd, myarray data) { prot_m4 *m4 = protM4(); @@ -189,17 +226,34 @@ protpc_export(0x40, get_selfdev_moter); - +// 从机升级 int selfdev_slaveupdate::dolater(int cmd, myarray data) { - prot_m4 *m4 = protM4(); - connect(this, &selfdev_slaveupdate::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")); + myarray r; + int len_filename=data[0]; + mystring name=data.mid(1,len_filename); + prot_slave *slave=protSlave(); + mycfg *cfg_=syscfg(); + qInfo()<<"slave_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(); + bool ack=slave->set_boardcast_handle(cfg_->calc_slave_addrs(),b); + if(ack==false){ + qWarning("handle is busy."); + }else{ + connect(b,&HandleBoardCast::end_signal,this,&selfdev_slaveupdate::slave_end_slot); + b->start(data); } - emit send_data_signal(0x40,myarray(1,char(0))); + return 0; } @@ -207,11 +261,16 @@ void selfdev_slaveupdate::timeout(){ } +void selfdev_slaveupdate::slave_end_slot(int addr,int ack, myarray data) +{ + qDebug("slave update end,ack=%d",ack); +} + static HandlePc *get_selfdev_slaveupdate(){ return new selfdev_slaveupdate(); } -protpc_export(0x41, get_selfdev_slaveupdate); +protpc_export(0xfe, get_selfdev_slaveupdate); diff --git a/prot_cmd/cmd_pc.h b/prot_cmd/cmd_pc.h index a026af4..05c600f 100644 --- a/prot_cmd/cmd_pc.h +++ b/prot_cmd/cmd_pc.h @@ -37,6 +37,22 @@ signals: +// 检测结束 自研批检仪 +class selfdev_checkend : public HandlePc +{ + Q_OBJECT +public: + selfdev_checkend() : HandlePc() {} + ~selfdev_checkend() {} + int dolater(int cmd, myarray data); + void timeout(); +signals: + void send_to_m4_signal(myarray data); +}; + + + + // 电机 自研批检仪 class selfdev_moter : public HandlePc { @@ -63,6 +79,8 @@ public: ~selfdev_slaveupdate() {} int dolater(int cmd, myarray data); void timeout(); +public slots: + void slave_end_slot(int addr,int ack, myarray data); signals: void send_to_m4_signal(myarray data); }; diff --git a/prot_cmd/cmd_slave.cpp b/prot_cmd/cmd_slave.cpp index e9d3e5b..3ba1afe 100644 --- a/prot_cmd/cmd_slave.cpp +++ b/prot_cmd/cmd_slave.cpp @@ -10,7 +10,7 @@ int slave_check::start(myarray data) { mycfg *cfg_=syscfg(); check_cfg *ccfg_=check_plan(); - int timeout=ccfg_->get_check_time_out(); + int timeout=ccfg_->get_check_time_out()*1000; busy=1; cmd=0x0c; qDebug("addr %d start check,timeout=%d",addr,timeout); @@ -34,14 +34,16 @@ int slave_check::dolater(int cmd, myarray data) return 1; } timeout_stop_retry(); - if(data.size()<=16){ - qDebug("addr %d recv first ack.",addr); - }else{ - qDebug("addr %d recv secend ack.",addr); - send_data(0x14,myarray(),1); - end(0,data); - busy=0; - timeout_stop(); + if(cmd==0x0c){ + if(data.size()<=16){ + qDebug("addr %d recv first ack.",addr); + }else{ + qDebug("addr %d recv secend ack.",addr); + send_data(0x14,myarray(),1); + end(0,data); + busy=0; + timeout_stop(); + } } return 0; } @@ -209,27 +211,28 @@ int slave_resvalue::dolater(int cmd, myarray data) void boardcast_updata::timeout() { timeout_stop(); - qWarning("addr %d updata timeout.",addr); + qWarning("slave updata timeout."); end(1,myarray()); busy=0; } int boardcast_updata::start(myarray data) { - int timeout=5000; + int timeout=50000; busy=1; qWarning()<<"addr "<data=data; + send_data(0xfe,myarray(),10); return 0; } int boardcast_updata::dolater(int cmd, myarray data) { timeout_stop_retry(); - timeout_start(5000); + timeout_start(50000); if(step==0){ if(send_packet()==true){ step=1; @@ -254,6 +257,7 @@ int boardcast_updata::dolater(int cmd, myarray data) send_data(0xfb,s,10); step=2; }else if(step==2){ + qDebug("slave updata end."); end(0,data); busy=0; }