实现赋码仪命令
升级小板程序失败时停止
This commit is contained in:
@@ -117,7 +117,7 @@ void selfdev_check::timeout()
|
||||
}
|
||||
|
||||
// 把小板的返回数据转化为自研批检仪上位机的格式
|
||||
static myarray tran_slave_to_selfdev_check(myarray &data)
|
||||
myarray tran_slave_to_selfdev_check(myarray &data)
|
||||
{
|
||||
check_cfg *ccfg_=check_plan();
|
||||
// 返回值个数
|
||||
@@ -126,13 +126,14 @@ static myarray tran_slave_to_selfdev_check(myarray &data)
|
||||
int paramerr_num=(return_num+7)/8;
|
||||
// 每个通道占用的长度
|
||||
int len_for_each=1+8+paramerr_num+return_num*2;
|
||||
// 去掉应答位
|
||||
data.remove(0,1);
|
||||
myarray r;
|
||||
if(data.size()<17){
|
||||
// 无返回则填充为异常
|
||||
r.append(char(208));
|
||||
r.append((len_for_each-1),char(0xff));
|
||||
}else{
|
||||
// 去掉应答位
|
||||
data.remove(0,1);
|
||||
myarray paramerr=ccfg_->returns_to_paramerr(data.right(return_num*2));
|
||||
r=data.left(8)+paramerr+data.right(return_num*2);
|
||||
uint8_t marerr=0,suberr=0;
|
||||
@@ -818,8 +819,8 @@ int selfdev_runtask::dolater(int cmd, myarray data)
|
||||
mycfg *cfg_=syscfg();
|
||||
busy=1;
|
||||
// 这里开始检测
|
||||
qDebug("set_rescv.");
|
||||
emit send_data_signal(cmd,myarray(1,0));
|
||||
qDebug("runtask.");
|
||||
// emit send_data_signal(cmd,myarray(1,0));
|
||||
HandleBoardCast *b=new slave_cmd();
|
||||
addrs=cmd_pc_to_addrs(data);
|
||||
bool ack=slave->set_boardcast_handle(addrs,b);
|
||||
@@ -868,3 +869,179 @@ void selfdev_runtask::slave_end_slot(int addr,int ack, slave_data data)
|
||||
|
||||
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct{
|
||||
char devicetype[12];
|
||||
char hostif[8];
|
||||
uint8_t localip[4];
|
||||
uint8_t hostip[4];
|
||||
uint16_t hostport;
|
||||
uint8_t localid;
|
||||
int uartbsp;
|
||||
uint8_t coder_return_mode;
|
||||
uint8_t slave_addr_start;
|
||||
}paraminfo_def;
|
||||
#pragma pack()
|
||||
|
||||
static void ip_fill(QString str,uint8_t *ip){
|
||||
QStringList snums = str.split('.');
|
||||
for(int i=0;i<snums.size();i++){
|
||||
ip[i]=snums[i].toInt(nullptr, 10);
|
||||
}
|
||||
}
|
||||
|
||||
// 填充配置项
|
||||
static void paraminfo_fill(paraminfo_def *p)
|
||||
{
|
||||
mycfg *cfg_=syscfg();
|
||||
memcpy(p->devicetype,cfg_->device_type.toLocal8Bit(),cfg_->device_type.size()+1);
|
||||
if(cfg_->tcp_enable==true){
|
||||
memcpy(p->hostif,"utcp",5);
|
||||
}else{
|
||||
memcpy(p->hostif,"uart4",6);
|
||||
}
|
||||
ip_fill(cfg_->local_ip,p->localip);
|
||||
ip_fill(cfg_->server_ip,p->hostip);
|
||||
p->hostport=cfg_->server_port;
|
||||
p->localid=cfg_->local_id;
|
||||
p->uartbsp=cfg_->uart_bsp;
|
||||
p->coder_return_mode=cfg_->coder_return_mode;
|
||||
p->slave_addr_start=cfg_->slave_addr_start;
|
||||
}
|
||||
|
||||
// 保存配置项
|
||||
static int paraminfo_save(paraminfo_def *p)
|
||||
{
|
||||
int ret=0;
|
||||
mycfg *cfg_=syscfg();
|
||||
uint8_t ip_zero[4]={0,0,0,0};
|
||||
if(strcmp("coder",p->devicetype)==0||strcmp("checker",p->devicetype)==0)
|
||||
cfg_->device_type=QString(p->devicetype);
|
||||
else {
|
||||
qWarning()<<"devicetype param must be \"coder\" or \"checker\"."<<p->devicetype;
|
||||
ret=1;return ret;}
|
||||
if(strcmp("utcp",p->hostif)==0){
|
||||
cfg_->tcp_enable=true;
|
||||
}else{
|
||||
cfg_->tcp_enable=false;
|
||||
}
|
||||
if(memcmp(p->localip,ip_zero,4)!=0){
|
||||
cfg_->local_ip=QString("%1.%2.%3.%4").arg(p->localip[0]).arg(p->localip[1]).arg(p->localip[2]).arg(p->localip[3]);
|
||||
}else {
|
||||
qWarning()<<"localip param must not be all zero";
|
||||
ret=3;return ret;}
|
||||
if(memcmp(p->hostip,ip_zero,4)!=0){
|
||||
cfg_->server_ip=QString("%1.%2.%3.%4").arg(p->hostip[0]).arg(p->hostip[1]).arg(p->hostip[2]).arg(p->hostip[3]);
|
||||
}else {
|
||||
qWarning()<<"hostip param must not be all zero";
|
||||
ret=4;return ret;}
|
||||
cfg_->server_port=p->hostport;
|
||||
cfg_->local_id=p->localid;
|
||||
if(p->uartbsp==115200||p->uartbsp==9600)
|
||||
cfg_->uart_bsp=p->uartbsp;
|
||||
else {
|
||||
qWarning()<<"uartbsp param must be 115200 or 9600";
|
||||
ret=5;return ret;}
|
||||
if(p->coder_return_mode==0||p->coder_return_mode==1)
|
||||
cfg_->coder_return_mode=p->coder_return_mode;
|
||||
else {
|
||||
qWarning()<<"coder_return_mode param must be 0 or 1";
|
||||
ret=6;return ret;}
|
||||
if(p->slave_addr_start==0||p->slave_addr_start==1)
|
||||
cfg_->slave_addr_start=p->slave_addr_start;
|
||||
else {
|
||||
qWarning()<<"slave_addr_start param must be 0 or 1";
|
||||
ret=7;return ret;}
|
||||
cfg_->save();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 赋码仪配置参数
|
||||
int coder_sysparam::dolater(int cmd, myarray data)
|
||||
{
|
||||
uint8_t op=data[1];
|
||||
paraminfo_def par={{0},{0},{0},{0},{0},{0},{0},{0},{0}};
|
||||
// 1是写,0是读
|
||||
if(op==0)
|
||||
{
|
||||
paraminfo_fill(&par);
|
||||
uint8_t *d=(uint8_t *)(&par);
|
||||
QByteArray arr;
|
||||
// 赋码仪添加通道数
|
||||
arr.append(data[0]);
|
||||
// 赋码仪添加读写位
|
||||
arr.append(op);
|
||||
arr.append(uint8_t(0));
|
||||
QByteArray temp=QByteArray::fromRawData((const char *)d,sizeof(paraminfo_def));
|
||||
arr.append(temp);
|
||||
emit send_data_signal(cmd,arr);
|
||||
}else if(op==1)
|
||||
{
|
||||
QByteArray arr;
|
||||
// 赋码仪添加通道数
|
||||
arr.append(data[0]);
|
||||
// 赋码仪添加读写位
|
||||
arr.append(op);
|
||||
|
||||
if(data.size()<1+1+sizeof(paraminfo_def)){
|
||||
arr.append(uint8_t(0xff));
|
||||
emit send_data_signal(cmd,arr);
|
||||
}else{
|
||||
qDebug()<<"param:"<<data.toHex(' ')<<endl;
|
||||
memcpy(&par,data.data()+1+1,sizeof(paraminfo_def));
|
||||
int ret=paraminfo_save(&par);
|
||||
arr.append(uint8_t(ret));
|
||||
emit send_data_signal(cmd,arr);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void coder_sysparam::timeout()
|
||||
{
|
||||
|
||||
}
|
||||
static HandlePc *get_coder_sysparam(){
|
||||
return new coder_sysparam();
|
||||
}
|
||||
protpc_export(0x08, get_coder_sysparam);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void coder_bootinfo::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
qDebug("selfdev get bootinfo end.");
|
||||
myarray r;
|
||||
r.append(uint8_t(syscfg()->slave_num));
|
||||
r.append(char(0));
|
||||
r+=bootinfo_fill_local();
|
||||
for(int i=0;i<data.size();i++){
|
||||
slave_ret slave=data.at(i);
|
||||
slave_acked.replace(slave.addr-1,slave.data);
|
||||
slave_acked_num++;
|
||||
}
|
||||
for(int i=0;i<slave_acked.size();i++){
|
||||
r.append(slave_to_bootinfo_byte(slave_acked[i]));
|
||||
}
|
||||
emit send_data_signal(0x84,r);
|
||||
busy=0;
|
||||
}
|
||||
static HandlePc *get_coder_bootinfo(){
|
||||
return new coder_bootinfo();
|
||||
}
|
||||
protpc_export(0x04, get_coder_bootinfo);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user