masterslave.h 8.0 KB

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