downlink.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #ifndef __DOWNLINK_H__
  2. #define __DOWNLINK_H__
  3. #include "stm32f10x.h"
  4. #include "../network_mgr/net_proc.h"
  5. #include "../encode/encodeOpt.h"
  6. #define COLLECT_MAX_NUM 16
  7. #define TAX_MAX_NUM 2
  8. #define GUN_MAX_NUM 8
  9. #define DOWNLINK_CONFIG_TYPE 0x10 //0x65
  10. #define CONFIG_ADDR 0X100
  11. #define CONFIG_WRITE 0x01
  12. typedef struct _tax_conf
  13. {
  14. uint8_t tax_id; //报税口编号
  15. uint8_t gun_num; //加油枪数量
  16. uint8_t gunid[GUN_MAX_NUM]; //加油枪编号
  17. uint8_t alrd_sn; //是否查询过加油机的信息
  18. uint8_t factory; /*厂家 1:英泰 2:拓盛 */
  19. uint8_t status; // 报税口的状态 ,是否连接
  20. uint8_t encryption; // 报税口的加密状态 ,由服务器下发的,暂停没有用于
  21. uint8_t monitor_serino[16]; //序列号
  22. }__attribute__((packed)) tax_conf_t;
  23. typedef struct _collect_conf
  24. {
  25. uint32_t collect_no; //采集器编号
  26. uint8_t tax_num; //报税口数量
  27. uint8_t tax_type; //报税口类型,明文或密文
  28. uint8_t collect_status; // 采集器的状态 在线或是离线 0 离线 1:在线
  29. uint8_t coll_send_num; // 采集器发送的次数
  30. tax_conf_t tax_conf[TAX_MAX_NUM];
  31. }__attribute__((packed)) collect_conf_t;
  32. #define INSTALL_5A 0x5A // 完成过程,配置第一步时用到,最后一步完成,则清零
  33. typedef struct _downlink_config
  34. {
  35. uint8_t config_flag; //采集器配置标记
  36. uint32_t gateway_id; //网关id
  37. uint8_t collect_num; //采集器数量
  38. uint8_t bInstallFinish; // 完成是否完成, 非5A,则为完成,如果为5A,则为安装的过程,// 完成过程,配置第一步时用到,最后一步完成,则清零
  39. collect_conf_t collect_conf[COLLECT_MAX_NUM];
  40. }__attribute__((packed)) downlink_config_t;
  41. extern downlink_config_t downlink_config;
  42. /*==============================================================*/
  43. /* 以下是服务器下发 需要用到的解析*/
  44. /* 升级信息下行 0x1001 */
  45. typedef struct _downlink_system_cmd_0x1001 {
  46. uint16_t targetType; // 设备类型(0x0101:网关;0x0201;采集器:0x0301:液位仪采集器;0x0401:屏采集器)
  47. uint32_t sn; // sn 编号
  48. uint16_t taskNo; // 任务号
  49. uint8_t urlLen; // URL长度
  50. char url[128]; // url地址
  51. }__attribute__((packed)) downlinkSysCmd0x1001;
  52. /* 切换mqtt IP地址 0x1003 */
  53. typedef struct _downlink_system_cmd_0x1003 {
  54. uint32_t gateway_sn; // 网关SN
  55. uint16_t targettype; // 类型 0x0101网关 0x0201:采集器 0x0301:液位仪
  56. uint8_t iplen; // ip地址长度
  57. uint8_t portlen; // 端口长度
  58. uint8_t userlen; // 用户名长度
  59. uint8_t pwdlen; // 密码长度
  60. // char port[6]; // 端口号
  61. // char ip[32]; //IP地址
  62. // char admin[8]; // 用户名
  63. // char password[16]; // 密码
  64. uint8_t str[76];
  65. }__attribute__((packed)) downlinkSysCmd0x1003;
  66. /* 采集器路由信息初始化 0x1011 */
  67. typedef struct _configmsg_{
  68. uint32_t collectSn;
  69. uint8_t comEncrypt[2]; //报税口的加密状态
  70. }__attribute__((packed)) configMsg;
  71. typedef struct _downlink_system_cmd_0x1011 {
  72. uint32_t gateway_id; //网关SN
  73. uint8_t configNo; // 配置流水号
  74. uint8_t collect_num; //采集器数量
  75. configMsg cfigMsg[16];
  76. }__attribute__((packed)) downlinkSysCmd0x1011;
  77. /* 刷新税控序列号 0x1012*/
  78. typedef struct _downlink_system_cmd_0x1012_{
  79. uint32_t gateway_sn; // 网关SN
  80. uint32_t coll_sn; // 采集器编号
  81. uint8_t tax_no; // 报税口编号
  82. }__attribute__((packed)) downlinkSysCmd0x1012;
  83. /* 设备重新启动 0x1021*/
  84. typedef struct _downlink_system_cmd_0x1021_{
  85. uint16_t targetType; // 设备类型(0x0101:网关;0x0201;采集器:0x0301:液位仪采集器;0x0401:屏采集器)
  86. uint32_t sn; // 设备sn号
  87. }__attribute__((packed)) downlinkSysCmd0x1021;
  88. /* 时间轮询间隔 */
  89. typedef struct _downlink_system_cmd_0x1013_{
  90. uint32_t gateway_sn; // 网关SN
  91. uint16_t time_interval; // 时间轮询
  92. }__attribute__((packed)) downlinkSysCmd0x1013;
  93. /* 系统信息(0x01) 0x1016 指令 切换lora信道信息 */
  94. typedef struct _downlink_system_cmd_0x1016_{
  95. uint8_t paraflag ; // 标志
  96. uint8_t loraIndex; // lora通道号
  97. uint32_t freq; // lora 发射频率
  98. uint8_t power; // 发射功率
  99. uint8_t bandwidth; // 带宽
  100. uint8_t spreadingfactor; // 扩频因子
  101. uint8_t codingrate; // 纠错编码率
  102. uint16_t preambleLen; // 前导码长度
  103. }__attribute__((packed)) downlinkSysCmd0x1016;
  104. /* 系统信息(0x01) 0x1017 指令 读取 lora信道信息 */
  105. typedef struct _downlink_system_cmd_0x1017_{
  106. uint32_t gateway_sn; // 网关编号
  107. uint32_t coll_sn; // 采集器编号
  108. }__attribute__((packed)) downlinkSysCmd0x1017;
  109. /* 系统信息(0x01) 0x1018 指令, 手动刷新税控序列号 */
  110. typedef struct _downlink_system_cmd_0x1018_{
  111. uint32_t gateway_sn; // 网关编号
  112. uint8_t prara; // 参数
  113. uint32_t coll_sn; // 采集器编号
  114. uint8_t taxNo; // 报税口号
  115. uint32_t reserve; // 预留
  116. }__attribute__((packed)) downlinkSysCmd0x1018;
  117. enum {
  118. CONFIG_STEP_01 = 0x01, // 配置第一步
  119. CONFIG_STEP_02 = 0x02, // 配置第二步 配置显示屏
  120. CONFIG_STEP_03 = 0x03, // 配置第三步 配置显示屏
  121. CONFIG_STEP_04 = 0x04, // 配置第四步 配置编码器路由表
  122. CONFIG_STEP_05 = 0x05, // 配置 第五步,配置编码器使能
  123. CONFIG_STEP_09 = 0x09, // 配置第九步 完成
  124. };
  125. /* 系统信息(0x01) 0x1019 带屏或不带屏的路由信息初始化 */
  126. typedef struct _xspDnMsg_{
  127. uint32_t xsp_sn; // 显示屏的SN
  128. uint8_t cbusId; // 总线索引
  129. uint8_t cdaId; // 报税口采集器索引
  130. uint8_t portid; // 对应的报税口号
  131. uint8_t gunid; // 对应的枪号
  132. uint8_t priceid; // 单价屏索引
  133. }__attribute__((packed)) xspDnMsg;
  134. typedef struct _downlink_system_cmd_0x1019_01{ //第一步
  135. uint8_t bencoder; // 是否有编码器 0:没有 1:有
  136. uint8_t collect_num; //采集器数量
  137. configMsg cfigMsg[16];
  138. }__attribute__((packed)) downlink0x1019_01;
  139. typedef struct _downlink_system_cmd_0x1019_02{ // 第二步 第三步
  140. uint8_t frame_no; // 是否有后续帧
  141. uint8_t groupNo; // 组数
  142. xspDnMsg _xspMsg[16]; //显示屏的信息 【16组】
  143. }__attribute__((packed)) downlink0x1019_02;
  144. typedef struct _downlink_encode_{
  145. uint8_t daColl;
  146. uint8_t daPort;
  147. uint8_t daGun;
  148. uint8_t busColl;
  149. uint8_t busPort;
  150. uint8_t busGun;
  151. }__attribute__((packed)) encodeda;
  152. typedef struct _downlink_system_cmd_0x1019_04 { // 第四步
  153. uint8_t reserve; // 预留
  154. uint8_t frame_no; // 是否有后续帧
  155. uint8_t groupNo; // 组数
  156. encodeda da[16];
  157. }__attribute__((packed)) downlink0x1019_04;
  158. typedef struct _downlink_system_cmd_0x1019_05 { // 第五步
  159. uint8_t reserve; // 预留
  160. uint8_t enableTime; // 编码器启用的时间 0xFF:永久启用 0x00:不启用,其它:单位为分钟
  161. }__attribute__((packed)) downlink0x1019_05;
  162. typedef struct _downlink_system_cmd_0x1019_09{ // 第九步
  163. uint32_t reserve; // 预留
  164. }__attribute__((packed)) downlink0x1019_09;
  165. typedef union _downlink_system_cmd_0x1019_step {
  166. downlink0x1019_01 step1;
  167. downlink0x1019_02 step2;
  168. downlink0x1019_04 step4;
  169. downlink0x1019_05 step5;
  170. downlink0x1019_09 step9;
  171. }__attribute__((packed)) dwonlink0x1019_step;
  172. typedef struct _downlink_system_cmd_0x1019 {
  173. uint32_t gateway_sn; // 网关编号
  174. uint8_t configNo; // 配置流水号
  175. uint8_t step; // 步骤
  176. dwonlink0x1019_step da;
  177. }__attribute__((packed)) downlinkSyscmd0x1019;
  178. typedef struct _downlink_system_cmd_0x1020 {
  179. uint32_t gateway_sn; // 网关编号
  180. uint32_t coll_sn; // 采集器编号
  181. uint32_t reserve; // 预留
  182. uint8_t taxNo01; // 报税口1 , 从1开始,如果为0,则无效
  183. uint8_t gunNum01; // 对应该报税口1的枪的个数
  184. uint8_t taxNo02; // 报税口2,从1开始,如果为0,则无效
  185. uint8_t gunNum02; // 对应该报税口2的枪的个数
  186. }__attribute__((packed)) downlinkSysCmd0x1020;
  187. /* 编码器路由表是否启用 */
  188. typedef struct _downlink_system_cmd_0x1022_{
  189. uint32_t gateway_sn; // 网关SN
  190. uint16_t tagettype; // 设备类型
  191. uint8_t benable; // 编码器路由表是否启用 0:未启用 1:启用
  192. uint32_t reserve; // 预留
  193. }__attribute__((packed)) downlinkSysCmd0x1022;
  194. /* 采集器设备设置 0x1023*/
  195. typedef struct _downlink_system_cmd_0x1023_{
  196. uint32_t gateway_sn; // 网关SN
  197. uint16_t targetType; // 设备类型(0x0101:网关;0x0201;采集器:0x0301:液位仪采集器;0x0401:屏采集器)
  198. uint32_t sn; // 设备sn号
  199. uint8_t cmd; // 指令
  200. uint32_t reserve; // 预留
  201. }__attribute__((packed)) downlinkSysCmd0x1023;
  202. /* 读取报税口数据 0x1034 */
  203. typedef struct _downlink_system_cmd_0x1034_{
  204. uint32_t gateway_sn; // 网关SN
  205. uint8_t read_type; // 读取类型 0xff:全站读取 0x00:只读取一个
  206. uint32_t coll_sn; // 采集器SN
  207. uint8_t taxNo; // 报税口编号 从1开始
  208. uint8_t gunNo; // 枪的编号 从1开始
  209. uint32_t reserve; // 预留
  210. }__attribute__((packed)) downlinkSysCmd0x1034;
  211. /* 拓盛密文实时读取 0x1051*/
  212. typedef struct _downlink_system_cmd_0x1051_{
  213. uint32_t gateway_sn; // 网关SN
  214. uint32_t coll_sn; // 采集器sn号
  215. uint8_t taxNo; // 报税口号
  216. uint8_t benable; // 是否启用时实读取 0:非时实 1:时实
  217. uint32_t reserve; // 预留
  218. }__attribute__((packed)) downlinkSysCmd0x1051;
  219. /* 透传指令(直接透传到采集器) 0x1052*/
  220. typedef struct _downlink_system_cmd_0x1052_{
  221. uint32_t gateway_sn; // 网关SN
  222. uint32_t coll_sn; // 采集器sn号
  223. uint8_t taxNo; // 报税口号
  224. uint8_t reserve; // 预留
  225. uint16_t palen; // 数据长度
  226. uint8_t info[128]; // 透传的数据
  227. }__attribute__((packed)) downlinkSysCmd0x1052;
  228. /* 0x01---0x1053 0x1023指令的格式 */
  229. typedef struct _downlink_system_cmd_0x1053_
  230. {
  231. uint16_t firstLevelType; //一级设备类型
  232. uint32_t firstLevelSn; //一级设备SN
  233. uint16_t rcvDevType; // 接收设备类型
  234. uint32_t rcvDevSn; // 接收设备SN
  235. uint16_t targetDevType; // 目标设备类型
  236. uint32_t targetDevSn; // 目标设备SN
  237. uint32_t reserve;
  238. uint8_t optType; // 执行操作1:设置 2:读取
  239. uint8_t cmdType; // 执行指令 1:编码器与抬枪信号正反序
  240. uint16_t cmdVal; // 1:正序 2:反序 其它:无
  241. uint32_t reserve01; // 预留
  242. }__attribute__((packed))downlinkSysCmd0x1053;
  243. /* 状态信息 固件信息下行 0x1001*/
  244. typedef struct _downlink_status_cmd_0x1001_{
  245. uint32_t gateway_sn; // 网关ID
  246. uint16_t targetType; // 设备类型(0x0101:网关;0x0201;采集器:0x0301:液位仪采集器;0x0401:屏采集器)
  247. uint32_t sn; // 设备编号
  248. }__attribute__((packed)) downlinkStatusCmd0x1001;
  249. /* 异常类下行 0x1001*/
  250. typedef struct _downlink_log_cmd_0x1001_{
  251. uint32_t gateway_sn; // 网关ID
  252. uint16_t targetType; // 设备类型(0x0101:网关;0x0201;采集器:0x0301:液位仪采集器;0x0401:屏采集器)
  253. uint8_t bEnable; // 0:关闭日志上报 1:开启日志上报
  254. uint32_t timer; // 开启时间 单位:秒
  255. uint32_t reserve; // 预留
  256. }__attribute__((packed)) downlinkLogCmd0x1001;
  257. /* 异常类下行 0x1002*/
  258. typedef struct _downlink_log_cmd_0x1002_{
  259. uint32_t gateway_sn; // 网关ID
  260. uint16_t targetType; // 设备类型(0x0101:网关;0x0201;采集器:0x0301:液位仪采集器;0x0401:屏采集器)
  261. uint8_t bEnable; // 0:关闭日志上报 1:开启日志上报
  262. uint32_t timer; // 开启时间 单位:秒
  263. uint8_t opentype; // 打开类型
  264. uint32_t collSN ; // 采集器SN
  265. uint8_t taxno; // 报税口编号
  266. uint8_t gunno; //枪的编号
  267. uint32_t reserve; // 预留
  268. }__attribute__((packed)) downlinkLogCmd0x1002;
  269. extern void downlink_init(void);
  270. int downlink_gateway_analyze(uint8_t *data, uint16_t len);
  271. #endif