前提主要搞清楚 指针数组,二级指针相关。
debug_type *params2[30]={0}; //指针数组
debug_type params[30]={0}; //数组
params2[0]=¶ms[0]; //地址传入
track_cust_paket_ubi(TIME_SHOT, ¶ms2[0],number); //success
协议拼包多包代码如下:
int main()
{
debug_type *params2[30]={0}; //指针数组
debug_type params[30]={0}; //数组
kal_uint8 bui=0;
kal_uint8 number=2; //传一次透传数据
char *ptr ="hhhhhhhhhhhhhh";
#if 1 //循环赋值
for(bui=0;bui<30;bui++)
{
params[bui].sn=1; //每包序号1-30
params[bui].ubi_kind=1;// 0无 1 UBI事件 2UBI报警
params[bui].ins_flag=0;//准备初始化
params[bui].ubi_on=1;//1-8 1 急加速
params[bui].ubi_A=8; //报警参数的设置值
params[bui].ubi_B=8; //报警参数的设置值
memcpy(params[bui].ubi_data,ptr,14);//UBI事件数据
params2[bui]=¶ms[bui]; //取&=加*
}
#endif
printf("bui =%d\n", bui); //bui =number
printf("ubi_on =%d\n", params2[0]->sn);
printf("ubi_kind =%d\n", params2[0]->ubi_kind);
printf("ubi_data =%s\n", params2[0]->ubi_data);
printf("ubi_on =%d\n", params2[1]->sn);
printf("ubi_kind =%d\n", params2[1]->ubi_kind);
printf("ubi_data =%s\n", params2[1]->ubi_data);
track_cust_paket_ubi(TIME_SHOT, ¶ms2[0],number); //success
}
void track_cust_paket_ubi(kal_uint32 timeshot,debug_type **de,kal_uint8 num)
{
kal_uint8 *sendData=0;
char time[16];
kal_uint16 no=0;
int size= 0;
int count=0;
int car=0;
size = num *20 + 16;
sendData = (kal_uint8*)malloc(sizeof(kal_uint8)*size); //分配足够大的内存
if(sendData == NULL)
{
printf(" cannot malloc sendData \n");
return;
}
memset(sendData, 0, size);
sendData[5] =0x07;//
//_itoa_s(timeshot,time,10); //转换
//memcpy(&sendData[6],time,4); //4+20*N(1-30秒)
memcpy(&sendData[6],×hot,4); //原数据copy
printf("%x\n",sendData[5]);
printf("%x\n",sendData[6]); //12345678
printf("%x\n",sendData[7]);
printf("%x\n",sendData[8]);
printf("%x\n",sendData[9]);
printf("ubi_sn =%x\n", sendData[10]);
printf("ubi_on =%x\n", sendData[11]);
printf("ubi_kind =%x\n", sendData[12]);
printf("ubi_A =%x\n", sendData[13]);
printf("ubi_B =%x\n", sendData[14]);
printf("ins_flag =%x\n", sendData[29]);
printf(" size ok!%d\n",size);
printf("num %d\n",num);
printf("count %d\n",count);
#if 1
for(count=0;count<num;count++)
{
memcpy(&sendData[10+20*count],&de[count]->sn,1); //&de[count]
memcpy(&sendData[11+20*count],&de[count]->ubi_on,1);
memcpy(&sendData[12+20*count],&de[count]->ubi_kind,1);
memcpy(&sendData[13+20*count],&de[count]->ubi_A,1);
memcpy(&sendData[14+20*count],&de[count]->ubi_B,1);
memcpy(&sendData[15+20*count],&de[count]->ubi_data[0],14);
memcpy(&sendData[29+20*count],&de[count]->ins_flag,1);
}
#endif
no = DataPacketEncode79(0x9C, sendData, size);
printf("UBI packet:\n");
for(car=0;car<size;car++)
{
printf("%.2x",sendData[car]);
}
printf("\n");
printf("no =%d\n",no);
free(sendData);
}