解决上位机协议中crc校验错误依然执行命令的问题
赋码仪新检测赋码命令测试成功 解决找不到槽任务返回值的bug 从机返回数据按地址排序 解决从机无返回时报错异常通道与实际不符的bug
This commit is contained in:
@@ -31,6 +31,13 @@
|
||||
添加检测并写入流水号命令
|
||||
2023.12.25
|
||||
解决生成新赋码任务数据长度异常的bug
|
||||
2023.12.26
|
||||
解决上位机协议中crc校验错误依然执行命令的问题
|
||||
赋码仪新检测赋码命令测试成功
|
||||
解决找不到槽任务返回值的bug
|
||||
从机返回数据按地址排序
|
||||
解决从机无返回时报错异常通道与实际不符的bug
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
|
||||
#define BUILD_DATE "2023-12-25 18:43:09"
|
||||
#define BUILD_DATE "2023-12-26 17:53:34"
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"build_date": "2023-12-25 18:43:09",
|
||||
"build_date": "2023-12-26 17:53:34",
|
||||
"hard_version": "MHPZ2_V1.00",
|
||||
"private": [
|
||||
"info.json",
|
||||
|
@@ -11,6 +11,7 @@ public:
|
||||
Codec()
|
||||
{
|
||||
fullFrame = false;
|
||||
failed = false;
|
||||
}
|
||||
virtual ~Codec() {}
|
||||
// 返回true,则是一个完整的帧
|
||||
@@ -31,7 +32,8 @@ public:
|
||||
}
|
||||
return myarray();
|
||||
}
|
||||
|
||||
public:
|
||||
bool failed;// true时解析失败
|
||||
protected:
|
||||
bool fullFrame;
|
||||
myarray data;
|
||||
|
@@ -86,6 +86,7 @@ int CodecYm::packCheck(myarray data)
|
||||
{
|
||||
int ack = 0;
|
||||
offset=0;
|
||||
failed=false;
|
||||
while(data.size()>=2){
|
||||
if ((uint8_t(data[0]) != 0x59u) || (uint8_t(data[1]) != 0x6du))
|
||||
{
|
||||
@@ -129,6 +130,7 @@ int CodecYm::packCheck(myarray data)
|
||||
// crc校验不对
|
||||
qWarning("recv data check error:%02x,%02x %02x,%02x", chk_a, chk_b, int(data[data.size() - 2]),
|
||||
int(data[data.size() - 1]));
|
||||
failed=true;
|
||||
}
|
||||
// 保存此流水号
|
||||
cmd_no = data[5] | (data[6] << 8);
|
||||
|
@@ -25,7 +25,11 @@ HandlePc *handlePcFind(int cmd)
|
||||
|
||||
void ProtPc::init()
|
||||
{
|
||||
if_ = interFaceFind("uart_host");
|
||||
if(syscfg()->tcp_enable==false){
|
||||
if_ = interFaceFind("uart_host");
|
||||
}else{
|
||||
if_ = interFaceFind("tcp");
|
||||
}
|
||||
codec_ = codecFind("codec_ym");
|
||||
if(if_==nullptr||codec_==nullptr){
|
||||
return;
|
||||
@@ -41,7 +45,11 @@ 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());
|
||||
docmd(cmd,data);
|
||||
if(codec_->failed!=true){
|
||||
docmd(cmd,data);
|
||||
}else{
|
||||
qWarning("host data decode failed.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -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