本帖最后由 林尘寄 于 2023-9-9 11:14 编辑
项目开发二 电力终端抄表之抄表命令 一、RZ/G2L串口抄表帧解析 以04_Sources\myir-linux-examples\uart为模板改造成串口接收并解析回复请求报文,关键代码如下: - //698:68 17 00 43 05 11 11 11 11 11 11 01 62 37 05 01 07 40 01 02 00 00 3c 1f 16
- //645:68 AA AA AA AA AA AA 68 13 00 DF 16
- if(reqCmdBuff[0]!=CMD645_START||reqCmdBuff[11]!=CMD645_STOP||reqCmdBuff[10]!=csCal(reqCmdBuff,10))
- {
- printf("Frame error\n");
- return;
- }
- //645:68 44 44 44 44 44 44 68 93 06 44 44 44 44 44 44 99 16
- rspCmdBuff[0]=CMD645_START;
- for(int i=0;i<6;i++)
- rspCmdBuff[1+i]=meterAddr[i]+0x33;
- rspCmdBuff[7]=CMD645_START;
- if(reqCmdBuff[8]==CMD_READADDR)
- {
- rspCmdBuff[8]=0x93;
- rspCmdBuff[9]=sizeof(meterAddr);
- for(int i=0;i<6;i++)
- rspCmdBuff[10+i]=meterAddr[i]+0x33;
- rspCmdBuff[16]=csCal(rspCmdBuff,16);
- rspCmdBuff[17]=CMD645_STOP;
- nwrite=18;
- }
- if(reqCmdBuff[8]==CMD_READDATA)
- {
- int oi=u8x4_u32(reqCmdBuff+10,4);
- switch(oi)
- {
- case 0x02010100:
- break;
-
- default:
- break;
- }
- }
- rspCmdBuff[nwrite++] = 0x0d;
- rspCmdBuff[nwrite++] = 0x0a;
- write(fd,rspCmdBuff,nwrite);
- for(i = 0; i < nwrite;i++){
- printf("%02x ",rspCmdBuff[i]);
- }
复制代码
敲击$CC uart_test.c dlt645.c -o uart_test交叉编译生成执行文件,此时敲击ip addr show或者ifconfig -a可以看到RZ/G2L分配的ip: Scp 命令上传执行文件至目标板RZ/G2L的ip: 可以看到提示” Unable to negotiate with 192.168.31.241 port 22: no matching hostkey type found. Their offer: ssh-rsa”,在命令加入”-oHostKeyAlgorithms=+ssh-rsa”参数即可。然后执行程序,通过蓝牙抄表可以读到电表地址为11 11 11 11 11 11: 上行:68 aa aa aa aa aa aa 68 13 00 df 16 下行:68 44 44 44 44 44 44 68 93 06 44 44 44 44 44 44 99 16 此时手机蓝牙下行报文也能看到,配置见第一章: |