appl.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #ifndef __APPL_H__
  2. #define __APPL_H__
  3. #include "modbus.h"
  4. enum CommState_t
  5. {
  6. ST_COMM_ERR = 0,
  7. ST_COMM_NORM = 1,
  8. };
  9. enum chan485_state_t
  10. {
  11. ST_485_INIT = 0,
  12. ST_485_RUN,
  13. ST_485_ERR,
  14. };
  15. enum chan485_err_t{
  16. ERR_485_NONE = 0,
  17. ERR_485_INIT_FAIL,
  18. };
  19. enum chan485_cmd_t
  20. {
  21. CMD_485_DONE = 0,
  22. CMD_485_RESET = 1,
  23. };
  24. #define CHAN485_NBR 8
  25. struct chan485_t{
  26. pthread_mutex_t mutex;
  27. char szinfo[128];
  28. int state;
  29. char szstate[32];
  30. int err;
  31. char szerr[64];
  32. int Cmd;
  33. int CmdParam;
  34. int baud;
  35. char szdev[32];
  36. char parity;
  37. int64_t reqcnt;
  38. int64_t failcnt;
  39. int64_t loopcnt;
  40. int64_t looptime;
  41. };
  42. enum chancan_state_t
  43. {
  44. ST_CAN_INIT = 1,
  45. ST_CHANCAN_RUN,
  46. ST_CHANCAN_ERR,
  47. };
  48. enum chancan_err_t{
  49. ERR_CAN_NONE = 0,
  50. ERR_CAN_INIT_FAIL,
  51. };
  52. enum chancan_cmd_t
  53. {
  54. CMD_CHANCAN_DONE = 0,
  55. CMD_CHANCAN_RESET = 1,
  56. };
  57. #define CHANCAN_NBR 3
  58. struct chancan_t{
  59. int State;
  60. char szState[32];
  61. int Err;
  62. char szErr[128];
  63. int Cmd;
  64. int sock;
  65. char szdev[32];
  66. int64_t RdCnt;
  67. int64_t RdFailcnt;
  68. int64_t WrCnt;
  69. int64_t WrFailcnt;
  70. int64_t Loopcnt;
  71. int64_t LoopTime;
  72. char szinfo[128];
  73. pthread_mutex_t mutex;
  74. };
  75. #define CHAN_MQTT_NBR 4
  76. struct chanmqtt_t{
  77. char szs_url[128];
  78. char szs_sub_topic[16][128];
  79. char szs_pub_topic[16][128];
  80. char szusrname[128];
  81. char szpasswd[128];
  82. char szclientid[128];
  83. int s_qos; // MQTT QoS
  84. struct mg_connection* s_conn; // Client connection
  85. char szState[64];
  86. int bConnected;
  87. int64_t LastFastUpload;
  88. int64_t LastMediumUpload;
  89. int64_t LastSlowUpload;
  90. int Cmd;
  91. int CmdParam;
  92. int64_t TotalReconn;
  93. int64_t TotalSend;
  94. int64_t TotalRecv;
  95. int MaxIntv;
  96. int AvgIntv;
  97. int64_t TotalIntv;
  98. int64_t LastRecv;
  99. };
  100. enum MqttCmd_t{
  101. CMD_MQTT_DONE = 0,
  102. CMD_MQTT_REGISTER = 1,
  103. };
  104. // !!! 注意,不要插入
  105. struct Settings_t{
  106. long long chksum;
  107. int bErr;
  108. char szState[32];
  109. char szCloudUserName[128];
  110. char szCloudPasswd[128];
  111. char szCloudUrl[128];
  112. char szClientId[128];
  113. int DataKeepDay;
  114. int UploadHighSpeed; // ms
  115. int UploadMediumSpeed; //ms
  116. int UploadSlowSpeed; //ms
  117. };
  118. union UnSettings_t{
  119. struct Settings_t s;
  120. char buf[1024*64];
  121. };
  122. enum SettingsCmd_t{
  123. SETTINGS_CMD_SET_CLOUD_USERNAME = 101,
  124. SETTINGS_CMD_SET_CLOUD_PASSWD = 102,
  125. SETTINGS_CMD_SET_CLOUD_URL = 103,
  126. SETTINGS_CMD_REGISTER = 104,
  127. SETTINGS_CMD_SET_CLOUD_CLIENTID = 105,
  128. SETTINGS_CMD_SET_CLOUD_UPLOADINTV = 106,
  129. SETTINGS_CMD_SET_DATAKEEPDAY = 200,
  130. SETTINGS_CMD_SET_UPLOADHIHGSPEED = 201,
  131. SETTINGS_CMD_SET_UPLOADMEDIUMSPEED = 202,
  132. SETTINGS_CMD_SET_UPLOADSLOWSPEED = 203,
  133. SETTINGS_CMD_TEST = 1000,
  134. };
  135. enum Metersettings{
  136. PT = 201,
  137. CT = 202,
  138. };
  139. struct Snap_t{
  140. int enable;
  141. int timer;
  142. int intv;
  143. int bStart;
  144. int bErr;
  145. char szState[32];
  146. char szcurrDatePath[32];
  147. int datechk_timer;
  148. int KeepDay;
  149. FILE* fpcs;
  150. FILE* fbms;
  151. FILE* fac;
  152. FILE* fctl;
  153. FILE* fmisc;
  154. FILE* f[8];
  155. int64_t LastSnap;
  156. };
  157. #define DTSD1352_NBR 8
  158. struct Dtsd1352_t{
  159. char szinfo[128];
  160. int Adr;
  161. modbus_t* ctx;
  162. double com_active_e;
  163. double com_active_p;
  164. double com_ractive_p;
  165. double pos_active_e;
  166. double pos_active_dem;
  167. double neg_active_dem;
  168. double neg_active_e;
  169. double pwr_factor;
  170. int PT;
  171. int CT;
  172. double ua;
  173. double ub;
  174. double uc;
  175. double ia;
  176. double ib;
  177. double ic;
  178. double freq;
  179. int64_t LastUpdate;
  180. char szLastUpdate[32];
  181. int CommState;
  182. char szCommState[32];
  183. int64_t CommFailTotalCnt;
  184. };
  185. struct appl_t{
  186. struct chan485_t chan485[CHAN485_NBR + 1];
  187. struct chancan_t chancan[CHANCAN_NBR + 1];
  188. struct chanmqtt_t chanmqtt[CHAN_MQTT_NBR + 1];
  189. union UnSettings_t Set;
  190. struct Dtsd1352_t Dtsd1352[DTSD1352_NBR + 1];
  191. struct Snap_t Snap;
  192. };
  193. extern char* VERSION;
  194. extern char* CFG_FN;
  195. extern struct appl_t APPL;
  196. extern void appl_chan485_lock(int idx);
  197. extern void appl_chan485_unlock(int idx);
  198. #endif