forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

wujiazhi
2024-06-11 65062d0d5b21f838aa0043a15ce54cfab8d72c43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#ifndef _GPRS_PROTOCOL_API_H_
#define _GPRS_PROTOCOL_API_H_
 
#include "define_all.h" 
#include "gprs_sundry_api.h"
#include "administrator.h"
 
/*ЭÒéÖ¡¹Ì¶¨µÄ³¤¶È*/
#define PROTOCOL_HEAD_LENGTH sizeof(GPRS_PROTOCOL_HEAD_T)                       //ЭÒéÍ·¹Ì¶¨³¤¶È
#define PROTOCOL_DATA_FIELD_HEAD_LENGTH sizeof(GPRS_PROTOCOL_DATA_FIELD_HEAD_T) //Êý¾ÝÓòÍ·¹Ì¶¨³¤¶È
#define PROTOCOL_TAIL_LENGTH sizeof(GPRS_PROTOCOL_TAIL_T)                       //ЭÒéβ¹Ì¶¨³¤¶È
 
/*ÆÕͨ·¢ËÍÊý¾ÝÄÚÈݹ̶¨³¤¶È*/
#define PROTOCOL_NORMAL_DATA_HEAD_LENGTH sizeof(GPRS_PROTOCOL_NORMAL_DATA_HEAD_T) //ÆÕͨ·¢ËÍÊý¾ÝÍ·¹Ì¶¨³¤¶È
#define PROTOCOL_NORMAL_DATA_PACK_LENGTH sizeof(GPRS_PROTOCOL_NORMAL_DATA_PACK_T) //ÆÕͨ·¢ËÍÊý¾Ý°ü¹Ì¶¨³¤¶È
 
/*ÉèÖÃÃüÁîÓ¦´ðÊý¾ÝÄÚÈݹ̶¨³¤¶È*/
#define PROTOCOL_SET_CMD_DATA_BACK_LENGTH 1 //ËùÓÐÆ½Ì¨Ï·¢µÄÉèÖÃÃüÁîµÄ·µ»ØÊý¾Ý³¤¶È
 
#define PROTOCOL_START_CODE 0x68 //ЭÒéÆðʼ·û
#define PROTOCOL_END_CODE 0x16   //ЭÒé½áÊø·û
#define KEY_VERSION 0x80         //ЭÒéÃÜÔ¿°æ±¾
#define PROTOCOL_VERSION 0x20    //ЭÒé°æ±¾
 
/*ЭÒé¿ØÖÆÂëÓɸߵÍλ×éºÏ¶ø³É*/
#define PROTOCOL_CMD_DOWN_U8_H 0
#define PROTOCOL_CMD_UP_U8_H 0x80
#define PROTOCOL_CMD_READ_U8_L 0x01
#define PROTOCOL_CMD_WRITE_U8_L 0x04
#define PROTOCOL_CMD_INITIATIVE_SEND_U8_L (PROTOCOL_CMD_READ_U8_L | PROTOCOL_CMD_WRITE_U8_L)
 
#define PROTOCOL_NORMAL_SEND_CMD_U16 0x8460 //ÆÕͨÉϱ¨ÃüÁî±êʶ
#define PROTOCOL_SET_TIME_CMD_U16 0xA464    //ÉèÖÃʱ¼äÃüÁî±êʶ
#define PROTOCOL_END_CMD_U16 0xA450         //½áÊøÖ¡ÃüÁî±êʶ
#define PROTOCOL_ALARM_CMD_U16 0x8461                //±¨¾¯ÃüÁî±êʶ
 
#define GPRS_PROTOCOL_SEND_FUNC_TABLE_NUM (sizeof(gprs_protocol_send_tab_func) / sizeof(GPRS_PROTOCOL_SEND_FUNC_TABLE_DRV_T))
#define GPRS_PROTOCOL_RECV_FUNC_TABLE_NUM (sizeof(gprs_protocol_recv_tab_func) / sizeof(GPRS_PROTOCOL_RECV_FUNC_TABLE_DRV_T))
 
typedef enum
{
  PROTOCOL_UNKOWN_STATUS = 0U,
  PROTOCOL_END_STATUS,
 
  PROTOCOL_NORMAL_SEND_CMD,
  PROTOCOL_ALARM_SEND_CMD,
 
  PROTOCOL_SET_TIME_CMD_BACK,
 
} GPRS_PROTOCOL_STATUS;
 
/*¿ª±ÙÈáÐÔÊý×é*/
typedef struct
{
  uint8_t send_len;
  uint8_t send_buffer[];
} GPRS_PROTOCOL_SEND_BUFFER_T;
 
#pragma pack(1)
 
// gprs_start_cnt = gprs_send_succ_cnt + gprs_start_defeat_cnt
typedef struct
{
    uint32_t gprs_start_cnt;//gprsÆô¶¯´ÎÊý
    uint32_t gprs_send_succ_cnt;//gprs·¢Ëͳɹ¦´ÎÊý
    uint32_t gprs_time_cnt;//gprs³¬Ê±´ÎÊý
    uint32_t gprs_recv_cnt;
    uint32_t gprs_iccid_cnt;
    uint32_t gprs_imei_cnt;
    uint32_t gprs_csq_cnt;
    uint32_t gprs_call_cnt;
    uint32_t gprs_tcp_cnt;
    uint32_t gprs_len_cnt;
}GPRS_SUCC_TEST_T;//Ô¶´«³É¹¦ÂʲâÊÔ
 
typedef struct
{
  uint8_t frame_start_code;
  uint8_t device_num[8];
  uint8_t data_start_code;
  uint8_t cmd_code_u8;
  uint16_t data_field_length;
} GPRS_PROTOCOL_HEAD_T; //¹Ì¶¨µÄÖ¡Í·Êý¾Ý
 
typedef struct
{
  uint8_t device_time[6];
  uint8_t protocol_ver;
  uint16_t cmd_code_u16;
  uint16_t frame_num;
  uint16_t frame_sum;
  uint8_t key_ver;
} GPRS_PROTOCOL_DATA_FIELD_HEAD_T; //¹Ì¶¨µÄÊý¾ÝÓòÍ·Êý¾Ý
 
typedef struct
{
  uint8_t checksum;
  uint8_t frame_end_code;
} GPRS_PROTOCOL_TAIL_T; //¹Ì¶¨µÄ֡βÊý¾Ý
 
typedef struct
{
  uint8_t signal_intensity; //ÐźÅÇ¿¶È
  uint8_t iccid[20];
  uint8_t sys_send_type;
  uint8_t pwr_type;
  uint8_t data_get_type;
  uint8_t billing_type;
  uint8_t use_state;
  uint8_t net_info;
  uint8_t reserve[2];
  uint8_t valve_state;
  uint8_t one_frame_num;            //Ò»Ö¡Êý¾ÝµÄÊý¾Ý×éÊý
} GPRS_PROTOCOL_NORMAL_DATA_HEAD_T; //ÆÕͨÊý¾ÝµÄ¹Ì¶¨¸ñʽͷ
 
typedef struct
{
  GPRS_PROTOCOL_HEAD_T gprs_protocol_head;
  GPRS_PROTOCOL_DATA_FIELD_HEAD_T gprs_protocol_data_field_head;
  GPRS_PROTOCOL_TAIL_T gprs_protocol_tail;
  GPRS_PROTOCOL_NORMAL_DATA_HEAD_T gprs_protocol_normal_data_head;
} GPRS_PROTOCOL_HEAD_TAIL_T;
 
typedef struct
{
    GPRS_PROTOCOL_HEAD_T gprs_protocol_head;
  GPRS_PROTOCOL_DATA_FIELD_HEAD_T gprs_protocol_data_field_head;
  GPRS_PROTOCOL_TAIL_T gprs_protocol_tail;
} GPRS_PROTOCOL_ALARM_HEAD_T;        //230306
 
typedef struct
{
  uint8_t sample_time[6];
  uint16_t balance_dec; //Óà¶îСÊý²¿·Ö£¨Ð¡Êý²»¿ÉÄÜΪ¸ºÊýËùÒÔU16£©
  int32_t balance_int;  //Óà¶îÕûÊý²¿·Ö£¨ÕûÊý²¿·Ö¿ÉÄÜΪ¸ºÓÃINT32£©
  uint16_t gas_use_total_dec;
  int32_t gas_use_total_int;
  uint16_t fee_use_total_dec;
  int32_t fee_use_total_int;
 
  uint16_t sc_cumulate_dec;
  int32_t sc_cumulate_int;
  uint16_t wc_cumulate_dec;
  int32_t wc_cumulate_int;
  uint16_t sc_instant_dec;
  int32_t sc_instant_int;
  uint16_t wc_instant_dec;
  int32_t wc_instant_int;
  float temperature;
  float pressure;
  uint8_t lith_vcc_dec;
  int8_t lith_vcc_int;
  uint8_t alka_vcc_dec;
  int8_t alka_vcc_int;
  uint8_t reserved[20];
} GPRS_PROTOCOL_NORMAL_DATA_PACK_T;
 
typedef struct
{
    uint8_t alarm_num;
    uint8_t alarm_time[6];
    uint16_t alarm_id;
}    GPRS_PROTOCOL_ALARM_ID_PACK_T;        //230306
 
typedef struct
{
    __IO GPRS_PROTOCOL_STATUS gprs_protocol_type;
} GPRS_PROTOCOL_PARA_T;
 
typedef void (*pGprs_Protocol_Send_FuncHandler)(uint8_t *pData, GPRS_PROTOCOL_HEAD_TAIL_T *gprs_protocol_head_tail);
typedef struct
{
  const GPRS_PROTOCOL_STATUS gprs_protocol_cmd_table;
  pGprs_Protocol_Send_FuncHandler GprsProtocolSendFuncHandler;
} GPRS_PROTOCOL_SEND_FUNC_TABLE_DRV_T; /*·¢ËÍЭÒé±íÇý¶¯*/
 
typedef GPRS_PROTOCOL_STATUS (*pGprs_Protocol_Recv_FuncHandler)(uint8_t *pData);
typedef struct
{
  const uint16_t gprs_protocol_cmd_table_u16;
  pGprs_Protocol_Recv_FuncHandler GprsProtocolRecvFuncHandler;
} GPRS_PROTOCOL_RECV_FUNC_TABLE_DRV_T; /*½ÓÊÕЭÒé±íÇý¶¯*/
 
#pragma pack()
 
extern GPRS_SUCC_TEST_T gprs_test_g; //230531
 
extern GPRS_PROTOCOL_HEAD_TAIL_T gprs_protocol_head_tail_g;
extern GPRS_PROTOCOL_PARA_T gprs_protocol_para_g;
extern GPRS_PROTOCOL_ALARM_HEAD_T gprs_protocol_alarm_head_tail_g; //230306
extern GPRS_PROTOCOL_ALARM_ID_PACK_T gprs_protocol_alarm_id_pack_g;    //230306
 
uint16_t Gprs_Protocol_DataLength(uint8_t send_type, GPRS_PROTOCOL_ENCRYPT_PARA *gprs_protocol_encrypt_para_p);
 
/************************************** Send Data **************************************************************/
void Gprs_Protocol_SendSetTimeResultHandler(uint8_t *pData, GPRS_PROTOCOL_HEAD_TAIL_T *gprs_protocol_head_tail_p);
void Gprs_Protocol_SendNormalDataHandler(uint8_t *pData, GPRS_PROTOCOL_HEAD_TAIL_T *gprs_protocol_head_tail_p);
void Gprs_Protocol_SendDataConfig(uint8_t send_type, uint8_t *pSendData, GPRS_PROTOCOL_HEAD_TAIL_T *gprs_protocol_head_tail_p);
void Gprs_Protocol_SendAlarmPack(uint8_t *pSendData, GPRS_PROTOCOL_ALARM_HEAD_T *gprs_protocol_alarm_head_p);
/************************************** Recv Data **************************************************************/
GPRS_PROTOCOL_STATUS Gprs_Protocol_RecvSetTimeHandler(uint8_t *pData);
GPRS_PROTOCOL_STATUS Gprs_Protocol_RecvNormalDataHandler(uint8_t *pData);
GPRS_PROTOCOL_STATUS Gprs_Protocol_RecvEndHandler(uint8_t *pData);
GPRS_PROTOCOL_STATUS Gprs_Protocol_RecvDataConfig(uint8_t *pRecvData, uint16_t recv_data_length);
 
#endif