TCP FOR PGST

 

Uplink:

 1     //////////////////////////////////////////////////////////////
 2     EnLength = 0;
 3     
 4     //flagReport=fGasLowAlarm;
 5     //GasWorker.Alm_Lel = 25;
 6 
 7     encodingString[EnLength++]=0x5D;   //起始符
 8     encodingString[EnLength++]=0x6C;   //起始符
 9     //帧头 18B
10     encodingString[EnLength++]=0x00;   //流水号
11     encodingString[EnLength++]=0x10;   //协议版本号
12     for(i=0;i<15;i++)
13     {
14         encodingString[EnLength++]=GsmData.cTelitIMEI[i];   //IMEI 
15     }        
16     encodingString[EnLength++]=0x02;   //命令字 
17     //消息体
18     for(i=0;i<20;i++)
19     {//ICCID
20         encodingString[EnLength++]=GsmData.cSimICCID[i];   
21     }
22     //////////////////////////////////////////////////////////////
23     //主报警状态
24     if(flagReport&fChGasAlarm)
25     {
26         encodingString[EnLength++] = 0x01;              //open
27         ret = fChGasAlarm;
28         almlel = GasWorker.ALM_LEL;
29     }
30     else if(flagReport&fCoGasAlarm)
31     {
32         encodingString[EnLength++] = 0x01;              //open
33         ret = fCoGasAlarm;
34         almppm = GasWorker.ALM_PPM;
35     }
36     else if(flagReport&fGasDisarm)
37     {
38         encodingString[EnLength++] = 0x00;            //closed
39         ret = fGasDisarm;
40     }    
41 /*
42     else if(flagReport&fChGasDisarm)
43     {
44         encodingString[EnLength++] = 0x00;            //closed
45         ret = fChGasDisarm;
46     }
47     else if(flagReport&fCoGasDisarm)
48     {
49         encodingString[EnLength++] = 0x00;            //closed
50         ret = fCoGasDisarm;
51     }
52 */
53     else if(flagReport&fTestKey)
54     {
55         encodingString[EnLength++] = 0x00;            //closed
56         ret = fTestKey;
57         Testflag = 0x01;
58     }    
59     else if(flagReport&fHeartBeat)
60     {
61         encodingString[EnLength++] = 0x00;            //closed
62         ret = fHeartBeat;
63     }
64     else
65     {
66         flagReport = 0;
67         encodingString[EnLength++] = 0x00;        //event id(heartbeat)
68     }
69     encodingString[EnLength++]=0x00;   //报警动作    
70     encodingString[EnLength++]=0x00;   //故障状态
71     encodingString[EnLength++]=0x00;   //防折状态
72     encodingString[EnLength++]=0x00;   //电池低压状态
73     encodingString[EnLength++]=Testflag;   //测试状态
74     //设备运行参数
75     encodingString[EnLength++]=0;             //烟雾浓度
76     encodingString[EnLength++]=0x81;           //温度
77     encodingString[EnLength++]=almlel;       //气体浓度
78     encodingString[EnLength++]=almppm>>8;   //CO浓度H    
79     encodingString[EnLength++]=almppm;       //CO浓度L
80     
81     encodingString[EnLength++]=0x81;   //电池电压    
82     encodingString[EnLength++]=0x81;   //电池电量    
83     encodingString[EnLength++] = GsmData.rssi;   //信号强度        
84     //校验和
85     for(i=2,j=0;i<EnLength;i++)
86     {
87         j+=encodingString[i];
88     }
89     if(j>0xff){j=~j;j+=1;}
90     encodingString[EnLength++]=(u8)j;
91     //结束符
92     encodingString[EnLength++]=0x7E;   //END
93     encodingString[EnLength++]=0x5A;   //END

 

posted on 2023-10-20 13:48  Milo_lu  阅读(14)  评论(0编辑  收藏  举报

导航