cmdDecode.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #ifndef _cmdDecode_H
  2. #define _cmdDecode_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #define CLIENT_NUMBER 2
  6. #define CLIENT_PRODUCT_TYPE_X 0
  7. typedef enum
  8. {
  9. DOG_SLT_NONE,
  10. DOG_SLT_A,
  11. DOG_SLT_B,
  12. DOG_SLT_AB,
  13. MAX_DOG_SLT_COUNT,
  14. }dogSelect_te;
  15. typedef struct
  16. {
  17. uint8_t head1; //固定=0x57
  18. uint8_t head2; //固定=0xab
  19. uint8_t cmd; //
  20. uint8_t buffer[4];
  21. }intCmdFram_ts;
  22. typedef enum
  23. {
  24. CMD_SET_RF_CHANNEL = 0x01,
  25. CMD_SET_RF_FREQ_BAND = 0x02,
  26. CMD_SET_RF_POWER = 0x03,
  27. CMD_SET_RF_BAUDRATE = 0x04,
  28. CMD_SET_UART_BAUDRATE = 0x05,
  29. CMD_TRIGGLE_RF_PERIOD_SEND = 0x06,
  30. CMD_GET_RF_RSSI = 0x07,
  31. CMD_SET_PACKET_FORMAT = 0x08,
  32. CMD_SET_RF_ACK = 0x09,
  33. CMD_SET_DATA_DIRECT = 0x0A,
  34. CMD_SET_RF_FREQ_STEP = 0x0B,
  35. CMD_LOGIN_SERVER_PASSWORD = 0x0C,
  36. CMD_DEVICE_IMEI = 0x0D,
  37. CMD_TARGET_IMEI = 0x0E,
  38. CMD_RF_SYNC_WORD = 0x0F,
  39. CMD_GET_POWER_VALUE = 0x20,
  40. CMD_PARAMS_FACTORY = 0x21,
  41. CMD_RESET_DEVICE = 0x22,
  42. CMD_RF_CARRIY_WAVE = 0x23,
  43. CMD_GET_ALL_PARAMS = 0x24,
  44. CMD_GET_SOFTWARE_VERSION = 0x25,
  45. CMD_ENTER_CONFIG_MODE = 0x26,
  46. CMD_TEST_RF_RX_SENSTY = 0x27,
  47. CMD_SET_GROUP_ID = 0x28,
  48. CMD_DEVICE_PAIR = 0x10,
  49. CMD_TRIGLE_VIRBRA = 0x11,
  50. CMD_TRIGLE_ELECTR = 0x12,
  51. CMD_TRIGLE_LAMP = 0x13,
  52. CMD_TRIGLE_TRAIN_VOL = 0x14,
  53. CMD_REBACK_SEND = 0x15,
  54. CMD_ACK = 0x16,
  55. CMD_DIRECT_DATA = 0x52, //透传数据
  56. CMD_TO_BOOTLOADER = 0x53,
  57. CMD_HEART = 0x54,
  58. CMD_ACK_ERROR = 0xEE,
  59. CMD_WRITE_ROLL_ID = 0xFE,
  60. }cmd_te;
  61. typedef enum
  62. {
  63. UART_BAUDRATE_xxxx,
  64. UART_BAUDRATE_2400,
  65. UART_BAUDRATE_4800,
  66. UART_BAUDRATE_9600,
  67. UART_BAUDRATE_38400,
  68. UART_BAUDRATE_57600,
  69. UART_BAUDRATE_115200,
  70. UART_BAUDRATE_460800,
  71. UART_BAUDRATE_19200,
  72. MAX_UART_BAUDRATE_COUNT,
  73. }uartBaudrate_te;
  74. typedef enum
  75. {
  76. CMD_SRC_UART1,
  77. CMD_SRC_UART2,
  78. }cmdSrc_te;
  79. typedef enum
  80. {
  81. DD_RF_TO_UART, //
  82. DD_RF_TO_RF, //
  83. DD_PROTOCOL_ID, //
  84. DD_PROTOCOL_ID_CHL, //
  85. DD_PROTOCOL, //
  86. DD_PROTOCOL_POT, //
  87. DD_MAX_COUNT, //
  88. }dataDirect_te;
  89. typedef enum
  90. {
  91. PKT_FMT_NORMAL,
  92. PKT_FMT_PACKET_RSSI, //
  93. PKT_FMT_PACKET_RSSI_ID, //
  94. MAX_PKT_FMT_COUNT,
  95. }packetFormat_te;
  96. typedef struct
  97. {
  98. uint8_t len; //[0]LEN(cmd)+LEN(bufferByte)+LEN(crc1)
  99. uint8_t cmd; //[1]
  100. uint8_t bufferByte;//[2],LEN=(len -4) + 1
  101. uint8_t crc1; //[len-1]
  102. }baseCmdFram_ts;
  103. #pragma pack(1)
  104. typedef struct
  105. {
  106. uint32_t id;
  107. uint8_t flag; //固定=0x7e
  108. }deviceIdFram_ts;
  109. typedef struct
  110. {
  111. uint8_t wafer_lot_number[6];
  112. }wafer_lot_number_ts;
  113. typedef struct
  114. {
  115. uint8_t wafer_lot_number[6];
  116. uint8_t wafer_X;
  117. uint8_t wafer_Y;
  118. uint8_t wafer_number;
  119. uint8_t revId;
  120. }uid_ts;
  121. typedef enum
  122. {
  123. PD_RL_NODE, //终端节点
  124. PD_RL_LOWPWR_NODE, //低功耗终端节点
  125. PD_RL_MID, //中继设备
  126. PD_RL_NET, //网关主机
  127. }product_role_te;
  128. typedef struct
  129. {
  130. uint32_t id;
  131. uint8_t rfChannel; //
  132. uint8_t bufferAddr; //
  133. }targetPacketFram_ts;
  134. typedef struct
  135. {
  136. uint32_t id;
  137. uint8_t bufferAddr; //
  138. }targetPacketIdFram_ts;
  139. typedef union
  140. {
  141. uint32_t value;
  142. struct
  143. {
  144. uint32_t cmd : 5;
  145. uint32_t rfChannel : 5;
  146. uint32_t type : 2;
  147. uint32_t deviceId : 20;
  148. }infor;
  149. }clientInfor_tu;
  150. typedef struct
  151. {
  152. uint8_t len;
  153. clientInfor_tu clientInfor;
  154. uint32_t value;
  155. uint8_t crc;
  156. }devicePairFram_ts;
  157. typedef struct
  158. {
  159. uint8_t len; //
  160. uint8_t cmd;
  161. clientInfor_tu clientInfor;
  162. uint32_t deviceId;
  163. uint32_t targetId;
  164. uint32_t buffer;
  165. uint8_t crc8; //
  166. }rfProtocol4ByteBuffer_ts;
  167. typedef struct
  168. {
  169. uint8_t len; //
  170. uint8_t cmd;
  171. clientInfor_tu clientInfor;
  172. uint32_t deviceId;
  173. uint32_t targetId;
  174. //⬇⬇⬇⬇⬇⬇ payload ⬇⬇⬇⬇⬇⬇
  175. uint8_t bufferAddr;
  176. //⬆⬆⬆⬆⬆⬆ payload ⬆⬆⬆⬆⬆⬆
  177. uint8_t crc8; //
  178. }rfProtocol_ts;
  179. typedef struct
  180. {
  181. uint8_t len; //[0]LEN(cmd)+LEN(bufferByte)+LEN(crc1)
  182. uint8_t cmd; //[1]
  183. uint32_t buffer;//[2],
  184. uint8_t crc1; //[len-1]
  185. }ipCmdFram_ts;
  186. typedef struct
  187. {
  188. uint8_t len; //[0]LEN(cmd)+LEN(bufferByte)+LEN(crc1)
  189. uint8_t cmd; //[1]
  190. uint16_t buffer;//[2],
  191. uint8_t crc1; //[len-1]
  192. }ipCmdFram2_ts;
  193. typedef enum
  194. {
  195. VIBR_LEVEL_1,
  196. VIBR_LEVEL_2,
  197. VIBR_LEVEL_3,
  198. VIBR_LEVEL_4,
  199. VIBR_LEVEL_5,
  200. VIBR_LEVEL_6,
  201. MAX_VIBR_LEVEL_COUNT,
  202. }vibrLevel_te;
  203. typedef enum
  204. {
  205. TRAIN_VOL_LEVEL_1,
  206. TRAIN_VOL_LEVEL_2,
  207. TRAIN_VOL_LEVEL_3,
  208. MAX_TRAIN_VOL_LEVEL_COUNT,
  209. }trainVol_te;
  210. typedef enum
  211. {
  212. ELECT_LEVEL_1,
  213. ELECT_LEVEL_2,
  214. ELECT_LEVEL_3,
  215. ELECT_LEVEL_4,
  216. ELECT_LEVEL_5,
  217. ELECT_LEVEL_6,
  218. ELECT_LEVEL_7,
  219. ELECT_LEVEL_8,
  220. ELECT_LEVEL_9,
  221. ELECT_LEVEL_99 = 98,
  222. MAX_ELECT_LEVEL_COUNT,
  223. }electLevel_te;
  224. typedef enum
  225. {
  226. CHG_MD_NONE = 0,
  227. CHG_MD_TONE = 1,
  228. CHG_MD_VIBR = 2,
  229. CHG_MD_ELECT = 3,
  230. }changeMode_te;
  231. typedef struct
  232. {
  233. uint8_t len; //
  234. uint8_t cmd;
  235. uint8_t dhcpEnable;
  236. uint8_t deviceIpAddr[4];
  237. uint8_t deviceSubMask[4];
  238. uint8_t deviceNetIpAddr[4];
  239. uint8_t netMode; //@ netMode_te
  240. uint8_t randLocalPortEnable;
  241. uint8_t targetIp[4];
  242. uint16_t targetPort;
  243. uint16_t localPort;
  244. uint8_t crc1; //
  245. }intInfor_ts;
  246. typedef struct
  247. {
  248. uint8_t len; //
  249. uint8_t cmd;
  250. uint8_t channel;
  251. uint8_t freqBand; //@freqBand_te
  252. uint8_t rfPower;
  253. uint8_t freqStep; //freqStep*10kHz,范围:250k~2MHz
  254. uint8_t syncWord; //同步字
  255. uint32_t targetImei; //目标ID号
  256. uint8_t dogABselect; // =0 选择AB, =1 选择A, =2 选择B
  257. uint8_t crc1; //
  258. }deviceInfor_ts;
  259. typedef struct
  260. {
  261. uint8_t len; //
  262. uint8_t cmd;
  263. uint8_t updateFlag; //
  264. uint8_t eraseFlag; //
  265. uint8_t version; //
  266. // uint8_t appVersion; //
  267. uint32_t uartBr; //
  268. uint32_t appAddr; //
  269. uint8_t crc; //
  270. }deviceBootInfor_ts;
  271. #pragma pack()
  272. extern uint8_t levelChangeMode;
  273. extern bool safeKeyLockFlag;
  274. extern bool localOpenFlag;
  275. extern bool remoteLampOpenFlag;
  276. extern deviceInfor_ts deviceInfor;
  277. extern uint8_t remoteBatLevel;
  278. bool checkFramLegal(uint8_t *srcBuffer, uint8_t srcLen);
  279. void completFramParams(uint8_t *srcBuffer, uint8_t srcLen);
  280. #endif