masterslave.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #ifndef _DN_485_H_
  2. #define _DN_485_H_
  3. #include "../Hardware/boardinit.h"
  4. #include "public.h"
  5. #include "xspDataOpt.h"
  6. /*-------------------------------------系统指令 --------------------*/
  7. #define SYSTEM_1001_LEN 13
  8. #define SYSTEM_2030_LEN 24
  9. #define SYSTEM_1030_LEN 16
  10. typedef struct _system_0x1021_{ // 系统类指令 重启
  11. uint8_t object; // 重启对象
  12. uint8_t info[2]; // 用于存储crc 校验码
  13. }__attribute__((packed))system0x1021;
  14. typedef struct _system_0x1015_{ // 系统类指令 时间同步
  15. uint32_t timer; // 时间戳
  16. uint32_t reserve; // 预留
  17. }__attribute__((packed))system0x1015;
  18. typedef struct _sys_cmd_1026_{
  19. uint8_t priceInuseCout; // 对于单价屏是否探针板接线
  20. uint8_t confFileNum[8]; //配置文件编号
  21. uint16_t appointDevModel; // 配置文件适配设备类型
  22. uint8_t portStatus; // 端口是否启用
  23. uint8_t portNum[4]; // 每个端口连接针脚的个数
  24. uint8_t comGroup; // com端的级数
  25. uint8_t param[4][4]; // 一共4组,每组4个参数
  26. }__attribute__((packed))sysCmd1026;
  27. typedef struct _system_0x1026_{ // 系统类指令 com端文件配置
  28. uint32_t reserve; // 预留 不需要存储EPPROM -4
  29. uint16_t expireTime; // 过期时间 不需要存储EPPROM -2
  30. uint8_t priceInuseCout; // 对于单价屏是否探针板接线
  31. uint8_t confFileNum[8]; //配置文件编号
  32. uint16_t appointDevModel; // 配置文件适配设备类型
  33. uint8_t portStatus; // 端口是否启用
  34. uint8_t portNum[4]; // 每个端口连接针脚的个数
  35. uint8_t comGroup; // com端的级数
  36. uint8_t param[4][4]; // 一共4组,每组4个参数
  37. }__attribute__((packed))system0x1026;
  38. typedef struct _sys_cmd_1027_{
  39. uint8_t confFileNum[8]; //配置文件编号
  40. uint16_t appointDevModel; // 配置文件适配设备类型
  41. uint8_t groupNum; // 组数
  42. uint8_t table[300][2]; // 表的说明
  43. }__attribute__((packed))sysCmd1027;
  44. extern sysCmd1027 g_table1027;
  45. extern sysCmd1027 g_temtable1027; // ???±±í
  46. typedef struct _sys_0x1027_{
  47. uint32_t reserve; // 预留
  48. uint16_t expireTime; // 过期时间
  49. uint8_t framNo; // 帧号
  50. sysCmd1027 da1027;
  51. }__attribute__((packed))system0x1027;
  52. typedef struct _sys_0x1028_{
  53. uint32_t time; // 开启时常
  54. }__attribute__((packed))system0x1028;
  55. typedef struct _sys_0x1029_{
  56. uint8_t status; // 保存状态 1:保存 2:放弃
  57. }__attribute__((packed))system0x1029;
  58. typedef struct _sys_0x1030_{
  59. uint32_t reserve;
  60. uint8_t info[2];//用于校验位
  61. }__attribute__((packed))system0x1030;
  62. typedef struct _sys_0x2030_{
  63. uint8_t configfileNo[8]; //配置文件编号
  64. uint32_t reserve; //预留
  65. }__attribute__((packed))system0x2030;
  66. typedef union _system_cmd_table_{
  67. system0x1021 s0x1021;
  68. system0x1015 s0x1015;
  69. system0x1026 s0x1026; // com端配置文件
  70. system0x1027 s0x1027; // 探针脚配置文件
  71. system0x1028 s0x1028; // 开启8段码上报
  72. system0x1029 s0x1029; // 关闭8段码上报
  73. system0x1030 s0x1030; // 读取8段数据
  74. system0x2030 s0x2030; // 上报8段码数据
  75. }__attribute__((packed))systemCmdTable;
  76. typedef struct _system_cmd_{
  77. uint16_t devTypeM;
  78. uint32_t devSnM;
  79. uint16_t devTypeS;
  80. uint32_t devSnS;
  81. systemCmdTable sDa;
  82. }__attribute__((packed))systemCmd;
  83. /*-------------------------------------状态指令 --------------------*/
  84. enum {
  85. SELF_STATUS = 0x02,
  86. SLAVE_OFFLINE = 0x03,
  87. };
  88. typedef struct _status_0x2002_{
  89. uint16_t devTypeM; //主设备类型
  90. uint32_t devSnM; //主设备SN
  91. uint16_t devTypeS; //从设备类型
  92. uint32_t devSnS; //从设备SN
  93. uint8_t cfgFileNo[8]; //配置文件编号
  94. uint8_t identity; //主从身份 1:从 2:主
  95. uint8_t bHave4G; //是否有4G模块 0:无 1:有
  96. uint8_t status; //在线状态 0:离线 1:在线
  97. uint8_t lastResetType; // 最后一次复位类型
  98. uint32_t resetNum; // 复位次数
  99. uint32_t runTime; // 运行时常
  100. uint32_t voltage; // 电压
  101. uint32_t temperature; // 温度
  102. uint16_t rssi4G; // 4G强度
  103. uint16_t snr4G; // 4G信噪比
  104. uint32_t tempStamp; // 时间戳
  105. uint32_t reserve;
  106. }__attribute__((packed))status0x2002;
  107. typedef struct _status_0x2001_{
  108. uint16_t devTypeM; // 主设备类型
  109. uint32_t devSnM; // 主设备SN
  110. uint16_t devTypeS; // 从设备类型
  111. uint32_t devSnS; // 从设备SN
  112. uint8_t upCode; // 升级状态码
  113. uint32_t bootVer; // bootloader版本
  114. uint32_t ptVer; // pt版本
  115. uint32_t appVer; // app版本
  116. uint8_t uuid[12]; // UUID
  117. uint8_t imei[15]; // imei
  118. uint8_t iccid[20]; // iccid
  119. uint32_t reserve; // 预留
  120. }__attribute__((packed))status0x2001;
  121. #define STATUS_COMM_LEN 12
  122. typedef struct _status_comm_msg_{
  123. uint16_t devTypeM;
  124. uint32_t devSnM;
  125. uint16_t devTypeS;
  126. uint32_t devSnS;
  127. uint8_t info[2];
  128. }__attribute__((packed))statCom;
  129. /*-------------------------------------数据指令 --------------------*/
  130. #define DATA_1061_LEN 20
  131. typedef struct _data_0x1061_{
  132. uint16_t devTypeM;
  133. uint32_t devSnM;
  134. uint16_t devTypeS;
  135. uint32_t devSnS;
  136. uint32_t recordId;
  137. uint32_t reserve;
  138. uint8_t info[2];
  139. }__attribute__((packed))data0x1061;
  140. #define DATA_2061_LEN 18
  141. typedef struct _data_0x2061_{
  142. uint16_t devTypeM;
  143. uint32_t devSnM;
  144. uint16_t devTypeS;
  145. uint32_t devSnS;
  146. uint32_t reserve;
  147. uint8_t bnewflag; // 新交易标识
  148. uint8_t palen; // 参数长度
  149. uint8_t info[160];
  150. }__attribute__((packed))data0x2061;
  151. #define LOG_2062_LEN 17
  152. typedef struct _log_0x2062_{
  153. uint16_t devTypeM;
  154. uint32_t devSnM;
  155. uint16_t devTypeS;
  156. uint32_t devSnS;
  157. uint32_t reserve;
  158. uint8_t palen; // 参数长度
  159. uint8_t info[160];
  160. }__attribute__((packed))log0x2062;
  161. #define LOG_1062_LEN 21
  162. typedef struct _log_0x1062_{
  163. uint16_t devTypeM;
  164. uint32_t devSnM;
  165. uint16_t devTypeS;
  166. uint32_t devSnS;
  167. uint8_t logType; // 日志类型
  168. uint32_t time; // 开启日志的时间
  169. uint32_t reserve; // 预留
  170. }__attribute__((packed))log0x1062;
  171. #define LOG_2063_LEN 18
  172. typedef struct _log_0x2063_{
  173. uint16_t devTypeM;
  174. uint32_t devSnM;
  175. uint16_t devTypeS;
  176. uint32_t devSnS;
  177. uint8_t logtype; // 1:错误七段码上 2:log 日志 3:信号错误率
  178. uint32_t reserve;
  179. uint8_t palen; // 参数长度
  180. uint8_t info[256];
  181. }__attribute__((packed))log0x2063;
  182. #define LOG_1063_LEN 22
  183. typedef struct _log_0x1063_{
  184. uint16_t devTypeM;
  185. uint32_t devSnM;
  186. uint16_t devTypeS;
  187. uint32_t devSnS;
  188. uint8_t logType; // 日志类型 1: 去重七段码上报 2:lg日志 3: 信号采集率调试
  189. uint32_t time; // 开启日志的时间(秒) 0: 关闭 非0:开始时长
  190. uint8_t interval; // 间隔上报 秒
  191. uint32_t reserve; // 预留
  192. }__attribute__((packed))log0x1063;
  193. /*----------------------------------升级指令-------------------------*/
  194. typedef struct _update_0x1001_{
  195. uint16_t devType;
  196. uint32_t devSn;
  197. uint16_t taskId; // 任务号
  198. uint32_t reserve; // 预留
  199. }__attribute__((packed))update0x1001;
  200. typedef struct _update_0x2001_{
  201. uint16_t devType;
  202. uint32_t devSn;
  203. uint32_t appVer;
  204. uint16_t taskId;
  205. uint32_t reserve;
  206. }__attribute__((packed))update0x2001;
  207. typedef union _update_info_{
  208. update0x1001 up0x1001;
  209. update0x2001 up0x2001;
  210. }__attribute__((packed))updateCmd;
  211. /*------------------------------------------------------------------*/
  212. typedef union _comm_info_{
  213. //system0x1021 sys1021;
  214. systemCmd sysMsg;
  215. statCom statusMsg;
  216. updateCmd upMsg;
  217. data0x1061 da1061;
  218. data0x2061 da2061;
  219. log0x1062 lg1062;
  220. log0x2062 lg2062;
  221. log0x1063 lg1063;
  222. log0x2063 lg2063;
  223. uint8_t info[256];
  224. }__attribute__((packed))commInfo_t;
  225. #define COMM_HEAD_LEN 12
  226. typedef struct _HEAD_DATA_{
  227. uint16_t start;
  228. uint8_t proVer;
  229. uint32_t msgId;
  230. uint8_t msgType1;
  231. uint16_t msgType2;
  232. uint16_t palen;
  233. commInfo_t comInfo;
  234. }__attribute__((packed))MasterSlave;
  235. extern void slave_send_data_to_uart(uint8_t type1, uint16_t type2,uint8_t *data,uint8_t len);
  236. extern void slave_send_log_0x2063(uint16_t devType, uint32_t devSn,uint8_t logtype,uint8_t *data, uint8_t len);
  237. extern void slave_send_data_0x2030(uint16_t devType, uint32_t devSn,uint8_t *data,uint8_t *cfigNo, uint8_t len);
  238. extern void analysis_cmd_system(uint16_t cmd, uint8_t *data,uint8_t len);
  239. extern void analysis_cmd_status(uint16_t cmd, uint8_t *data,uint8_t len);
  240. extern void analysis_cmd_data(uint16_t cmd,uint8_t *data,uint8_t len);
  241. extern void analysis_cmd_update(uint16_t cmd,uint8_t *data,uint8_t len);
  242. extern void analysis_cmd_log(uint16_t cmd,uint8_t *data,uint8_t len);
  243. #endif