appl.h 4.2 KB

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