解决上位机协议中crc校验错误依然执行命令的问题
赋码仪新检测赋码命令测试成功 解决找不到槽任务返回值的bug 从机返回数据按地址排序 解决从机无返回时报错异常通道与实际不符的bug
This commit is contained in:
@@ -221,19 +221,23 @@ int coder_slave_pack(myarray &d,int addr)
|
||||
myarray coder_slave_find_ret_data(myarray data,int task_index,int size)
|
||||
{
|
||||
myarray r;
|
||||
int task_len;
|
||||
// qDebug()<<"find data,task_index="<<task_index<<"src="<<data.toHex(' ');
|
||||
for(int i=0;i<data.size();)
|
||||
{
|
||||
task_len=data[i+1]*2;
|
||||
if(data[i]==task_index){
|
||||
r=data.mid(i+2,data[i+1]);
|
||||
r=data.mid(i+2,task_len);
|
||||
break;
|
||||
}
|
||||
i+=2+data[i+1];
|
||||
i+=2+task_len;
|
||||
}
|
||||
if(r.size()>=size){
|
||||
r=r.left(size);
|
||||
}else{
|
||||
int len=size-r.size();
|
||||
r.append(len,uint8_t(0));
|
||||
qWarning("can not find data,append by 0.");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@@ -512,7 +516,19 @@ myarray cmd_coder_code2::ret_slave_to_pc(QList<myarray> data)
|
||||
r.append(uint8_t((addrs>>8)&0xff));
|
||||
r.append(uint8_t((addrs>>16)&0xff));
|
||||
r.append(uint8_t(coder_chip_type()));
|
||||
r.append(uint8_t(!syscfg()->coder_return_mode));
|
||||
// coder_return_mode 1是完整模式,协议0是完整模式
|
||||
if(syscfg()->coder_return_mode){
|
||||
r.append(uint8_t(0));
|
||||
r.append(13);
|
||||
if(chip_mode==0){
|
||||
r.append(15);
|
||||
}else{
|
||||
r.append(16);
|
||||
}
|
||||
}else{
|
||||
r.append(uint8_t(1));
|
||||
}
|
||||
r.append(8);
|
||||
for (int i=0;i<data.size();i++)
|
||||
{
|
||||
myarray &sdata=data[i];
|
||||
@@ -525,8 +541,9 @@ myarray cmd_coder_code2::ret_slave_to_pc(QList<myarray> data)
|
||||
}else{
|
||||
err=uint8_t(0xd0);
|
||||
}
|
||||
sdata.remove(0,1);
|
||||
// 如果延时不对,则失败
|
||||
myarray sret=coder_slave_find_ret_data(sdata.mid(1),3,2);
|
||||
myarray sret=coder_slave_find_ret_data(sdata,3,2);
|
||||
uint16_t sdelay=sret[0]|(sret[1]<<8);
|
||||
if(sdelay!=delay){
|
||||
if(err==0){
|
||||
@@ -535,11 +552,12 @@ myarray cmd_coder_code2::ret_slave_to_pc(QList<myarray> data)
|
||||
}
|
||||
r.append(err);
|
||||
// 添加工厂信息
|
||||
sret=coder_slave_find_ret_data(sdata.mid(1),4,4);
|
||||
sret=coder_slave_find_ret_data(sdata,4,4);
|
||||
r.append(sret);
|
||||
// 完整模式
|
||||
if(syscfg()->coder_return_mode){
|
||||
r.append(uid_codes[i].shell,13);
|
||||
// r.append(13,i+'0');
|
||||
if(chip_mode==0){
|
||||
r.append(uid_codes[i].uid,15);
|
||||
}else{
|
||||
|
@@ -262,7 +262,7 @@ public:
|
||||
}
|
||||
// pc回复命令,返回0不回复
|
||||
int cmd_pc_ret(){
|
||||
return 0x82;
|
||||
return 0x91;
|
||||
}
|
||||
// 从机返回转pc
|
||||
myarray ret_slave_to_pc(QList<myarray> data);
|
||||
|
@@ -871,20 +871,47 @@ void selfdev_runtask::timeout()
|
||||
busy=0;
|
||||
}
|
||||
|
||||
// 排序,再接收了从机数据之后
|
||||
void selfdev_runtask::slave_sort(){
|
||||
myarray temp;
|
||||
int slave_num=slave_acked.size();
|
||||
if(slave_num==0) return;
|
||||
for(int i=0;i<slave_num;i++){
|
||||
temp=slave_acked[i];
|
||||
for(int j=i+1;j<slave_num;j++){
|
||||
if(slave_acked[i][0]>slave_acked[j][0]){
|
||||
slave_acked[i]=slave_acked[j];
|
||||
slave_acked[j]=temp;
|
||||
temp=slave_acked[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void selfdev_runtask::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
qDebug("selfdev runtask end.");
|
||||
for(int i=0;i<data.size();i++){
|
||||
qDebug("index=%d",i);
|
||||
slave_ret slave=data.at(i);
|
||||
qDebug("index=%d end",i);
|
||||
// for(int i=0;i<data.size();i++){
|
||||
// //qDebug("index=%d",i);
|
||||
// slave_ret slave=data.at(i);
|
||||
// //qDebug("index=%d end",i);
|
||||
// // 数据的第一位是来源的地址
|
||||
// slave.data.insert(0,slave.addr);
|
||||
// slave_acked.replace(i,slave.data);
|
||||
// // qDebug("index=%d end 2",i);
|
||||
// slave_acked_num++;
|
||||
// }
|
||||
for(int i=0;i<addrs.size();i++){
|
||||
int addr=addrs[i];
|
||||
myarray sdata=data[addr-1];
|
||||
// 数据的第一位是来源的地址
|
||||
slave.data.insert(0,slave.addr);
|
||||
slave_acked.replace(i,slave.data);
|
||||
// qDebug("index=%d end 2",i);
|
||||
sdata.insert(0,addr);
|
||||
slave_acked.replace(addr-1,sdata);
|
||||
slave_acked_num++;
|
||||
}
|
||||
if(cmd_pc_ret()!=0){
|
||||
slave_sort();
|
||||
emit send_data_signal(cmd_pc_ret(),ret_slave_to_pc(slave_acked));
|
||||
}
|
||||
busy=0;
|
||||
|
@@ -288,6 +288,8 @@ public:
|
||||
virtual myarray ret_slave_to_pc(QList<myarray> data)=0;
|
||||
public slots:
|
||||
void slave_end_slot(int addr,int ack, slave_data data);
|
||||
protected:
|
||||
void slave_sort();
|
||||
protected:
|
||||
QList<myarray> slave_acked;
|
||||
int slave_acked_num;
|
||||
|
Reference in New Issue
Block a user