批检仪检测流程验证成功

This commit is contained in:
ranchuan
2023-12-07 18:29:49 +08:00
parent 32129cbf9a
commit dc6487c309
15 changed files with 438 additions and 25 deletions

49
prot_cmd/cmd_m4.cpp Normal file
View File

@@ -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");
}

14
prot_cmd/cmd_m4.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef CMD_M4_H
#define CMD_M4_H
void cmd_m4_init();
#endif // CMD_M4_H

View File

@@ -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:"<<name<<endl;
data.remove(0,len_filename+1);
// TODO 校验主板程序
r.append(uint8_t(0));
cfg_->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:"<<name<<endl;
data.remove(0,len_filename+1);
// TODO 校验小板程序
r.append(uint8_t(0));
cfg_->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<int> 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;i<cfg->slave_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;i<cfg_->slave_num;i++){
temp32|=1<<i;
}
memcpy(d,&temp32,4);d+=4;
myarray arry((char *)d,sizeof(local_bootinfo));
free(d);
return arry;
}
static myarray slave_to_bootinfo_byte(myarray data){
data.append(sizeof(bootinfo_data)-data.size(),0);
return data;
}
void selfdev_bootinfo::slave_end_slot(int addr,int ack, myarray data)
{
if(addr<=0||addr>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.size();i++){
r.append(slave_to_bootinfo_byte(slave_acked[i]));
}
emit send_data_signal(0x34,r);
busy=0;
}
}
static HandlePc *get_selfdev_bootinfo(){
return new selfdev_bootinfo();
}
protpc_export(0x34, get_selfdev_bootinfo);

View File

@@ -109,6 +109,53 @@ signals:
// 本机升级
class selfdev_hostupdate : public selfdev_slaveupdate
{
Q_OBJECT
public:
selfdev_hostupdate() : selfdev_slaveupdate() {}
~selfdev_hostupdate() {}
int dolater(int cmd, myarray data);
};
// jwt升级
class selfdev_jwtupdate : public selfdev_slaveupdate
{
Q_OBJECT
public:
selfdev_jwtupdate() : selfdev_slaveupdate() {}
~selfdev_jwtupdate() {}
int dolater(int cmd, myarray data);
};
// 自检
class selfdev_bootinfo : public HandlePc
{
Q_OBJECT
public:
selfdev_bootinfo() : HandlePc() {
slave_acked_num=0;
}
~selfdev_bootinfo() {
}
int dolater(int cmd, myarray data);
void timeout();
public slots:
void slave_end_slot(int addr,int ack, myarray data);
protected:
QList<myarray> slave_acked;
int slave_acked_num;
};
#endif

View File

@@ -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;
}

View File

@@ -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