添加广播命令的解析和回复指令

This commit is contained in:
ranchuan
2023-12-04 18:17:48 +08:00
parent 95a4faff3f
commit d6b1177af9
4 changed files with 37 additions and 20 deletions

View File

@@ -247,13 +247,24 @@ array_def *protm_decode(protu_def *p,array_def *data)
str_set(p->str_err,"crc check err.");
}
p->cmd=arr_get(data,6);
arr_delete(r);
r=arr_mid(data,9,len-10);
if(dst==0x1f){
p->silent=1;
// 广播命令需判断额外字节
int self_addr=elec_local_addr();
int dst_addrs=arr_get(r,0)|(arr_get(r,1)<<8)|(arr_get(r,2)<<16);
if((dst_addrs&(1<<(self_addr-1)))!=0){
p->silent=1;
arr_remove(r,0,3);
}else{
arr_delete(r);
r=arr_creat();
str_set(p->str_err,"bordcast without this.");
}
}else{
p->silent=0;
}
arr_delete(r);
return arr_mid(data,9,len-10);
return r;
}
@@ -262,18 +273,23 @@ array_def *protm_encode(protu_def *p,array_def *data)
{
array_def *t=arr_creat();
param_check(t);
uint16_t len=arr_length(data)+10;
arr_append(t,'Y');
arr_append(t,'e');
arr_append(t,len&0xff);
arr_append(t,len>>8);
arr_append(t,elec_local_addr());// 源地址
arr_append(t,0);// 目标地址
arr_append(t,p->cmd);// 命令码
arr_append(t,p->cmd_no&0xff);
arr_append(t,p->cmd_no>>8);
arr_appends_from(t,data);
arr_append(t,crc_crc8(arr_data(t),arr_length(t)));
if(p->silent==0){
uint16_t len=arr_length(data)+10;
arr_append(t,'Y');
arr_append(t,'e');
arr_append(t,len&0xff);
arr_append(t,len>>8);
arr_append(t,elec_local_addr());// 地址
arr_append(t,0);// 目标地址
arr_append(t,p->cmd);// 命令码
arr_append(t,p->cmd_no&0xff);
arr_append(t,p->cmd_no>>8);
arr_appends_from(t,data);
arr_append(t,crc_crc8(arr_data(t),arr_length(t)));
}else{
// 广播命令只需回复本机地址
arr_append(t,elec_local_addr());
}
return t;
}