广播命令根据数据量自动计算发送数据的窗口时间
This commit is contained in:
@@ -201,6 +201,16 @@ array_def *protu_encode2(protu_def *p,array_def *data)
|
||||
|
||||
|
||||
|
||||
// 计算在第n为之前,bit为1的个数
|
||||
static int calc_bit_num(int bits,int n)
|
||||
{
|
||||
int num=0;
|
||||
for(int i=0;i<n;i++){
|
||||
if(bits&(1<<i))
|
||||
num++;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
// 小板协议解码
|
||||
array_def *protm_decode(protu_def *p,array_def *data)
|
||||
@@ -256,6 +266,8 @@ array_def *protm_decode(protu_def *p,array_def *data)
|
||||
if((dst_addrs&(1<<(self_addr-1)))!=0){
|
||||
p->silent=1;
|
||||
p->timer->write(p->timer,0);
|
||||
p->rank=calc_bit_num(dst_addrs,self_addr-1);
|
||||
p->num=calc_bit_num(dst_addrs,32);
|
||||
arr_remove(r,0,3);
|
||||
}else{
|
||||
arr_delete(r);
|
||||
@@ -263,6 +275,8 @@ array_def *protm_decode(protu_def *p,array_def *data)
|
||||
str_set(p->str_err,"bordcast without this.");
|
||||
}
|
||||
}else{
|
||||
p->rank=dst-1;
|
||||
p->num=20;// 最多支持20个设备
|
||||
p->silent=0;
|
||||
}
|
||||
return r;
|
||||
@@ -274,7 +288,7 @@ array_def *protm_encode(protu_def *p,array_def *data)
|
||||
{
|
||||
array_def *t=arr_creat();
|
||||
param_check(t);
|
||||
if(p->silent==0){
|
||||
// if(p->silent==0){
|
||||
uint16_t len=arr_length(data)+10;
|
||||
arr_append(t,'Y');
|
||||
arr_append(t,'e');
|
||||
@@ -287,10 +301,10 @@ array_def *protm_encode(protu_def *p,array_def *data)
|
||||
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());
|
||||
}
|
||||
// }else{
|
||||
// // 广播命令只需回复本机地址
|
||||
// arr_append(t,elec_local_addr());
|
||||
// }
|
||||
return t;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user