tb.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. #include "plt.h"
  2. struct tb_t tb;
  3. /* in seconds */
  4. static long long tb_get_unixts()
  5. {
  6. return (long long)time(NULL);
  7. }
  8. /* in ms */
  9. static long long tb_get_ts()
  10. {
  11. return (tb_get_unixts() + tbmqtt_get_tz() * (long long)3600) * (long long)1000;
  12. // return tb_get_unixts()*1000;
  13. }
  14. static int tb_send_rpc_response(char *request_topic, char *response_payload)
  15. {
  16. char *p = NULL;
  17. char szreqid[256];
  18. char *pszreqid = szreqid;
  19. int reqid = 0;
  20. tbmqtt_ringbuffer_element_t e;
  21. p = strrchr(request_topic, '/');
  22. if (p != NULL)
  23. {
  24. p++;
  25. while (*p != 0)
  26. {
  27. *pszreqid++ = *p++;
  28. }
  29. *pszreqid = 0;
  30. reqid = atoi(szreqid);
  31. e.cmd = CMD_MQTT_SENDKV;
  32. e.sztopic[0] = 0;
  33. e.szpayload[0] = 0;
  34. strcpy(e.szpayload, response_payload);
  35. sprintf(e.sztopic, "v1/devices/me/rpc/response/%s", szreqid);
  36. tbmqtt_lock_txbuf();
  37. tbmqtt_queue_txbuf(e);
  38. tbmqtt_unlock_txbuf();
  39. }
  40. return 0;
  41. }
  42. bool tb_check_invt(int *timer, const int invt)
  43. {
  44. if (invt <= 0)
  45. return false;
  46. if ((*timer)++ > invt)
  47. {
  48. *timer = 0;
  49. return true;
  50. }
  51. return false;
  52. }
  53. void tb_send_telemetry(const char *data)
  54. {
  55. tbmqtt_ringbuffer_element_t e;
  56. e.sztopic[0] = 0;
  57. e.szpayload[0] = 0;
  58. e.cmd = CMD_MQTT_SENDKV;
  59. strcpy(e.sztopic, "v1/devices/me/telemetry");
  60. sprintf(e.szpayload, "{'ts':%lld,'values':{%s}}", tb_get_ts(), data);
  61. // log_dbg("%s, e.szpayload : %s", __func__, e.szpayload);
  62. // if (cJSON_Parse(e.szpayload) == NULL)
  63. // {
  64. // log_err("%s, invalid json string : %s", __func__, data);
  65. // return;
  66. // }
  67. // else
  68. // {
  69. // }
  70. #ifdef DEBUG_MQTT
  71. printf("%s: ready to send payload:%s\n", __func__, data);
  72. #endif
  73. tbmqtt_lock_txbuf();
  74. tbmqtt_queue_txbuf(e);
  75. tbmqtt_unlock_txbuf();
  76. }
  77. static int tb_update_attributes(char *payload)
  78. {
  79. tbmqtt_ringbuffer_element_t e;
  80. e.cmd = CMD_MQTT_SENDKV;
  81. e.sztopic[0] = 0;
  82. e.szpayload[0] = 0;
  83. sprintf(e.szpayload, "{%s}", payload);
  84. strcpy(e.sztopic, "v1/devices/me/attributes");
  85. log_dbg("%s, topic:%s, payload:%s", __func__, e.sztopic, e.szpayload);
  86. tbmqtt_lock_txbuf();
  87. tbmqtt_queue_txbuf(e);
  88. tbmqtt_unlock_txbuf();
  89. return 0;
  90. }
  91. static void tb_upload_param()
  92. {
  93. char tb_buf[4096] = {0};
  94. if (tb.param_en > 0)
  95. {
  96. tb_buf[0] = 0;
  97. tb.param_en = 0;
  98. // ctn 直接发送给对应的设备,不需要 idx
  99. tb_buf[0] = 0;
  100. sprintf(tb_buf, "'sys_sw_version':'%s', 'norm_cap':%d,'norm_pow':%d",
  101. plt_get_version_string(), ctn_get_norm_cap(), ctn_get_norm_pow());
  102. tb_send_telemetry(tb_buf);
  103. }
  104. }
  105. static void tb_upload_sys()
  106. {
  107. char tb_buf[4096] = {0};
  108. if (tb_check_invt(&tb.sys_timer[0], tb.sys_intv[0]))
  109. {
  110. tb_buf[0] = 0;
  111. // sys state and err
  112. sprintf(tb_buf, "'state':'%s','err':'%s','ap':%d,'soc':%.1f,'ems_state':'%s','host':'%s'",
  113. ctn_get_state_str(), ctn_get_err_str(), ctn_get_ap(), ctn_get_soc(), ems_get_state_str(), ctn_get_hostname());
  114. tb_send_telemetry(tb_buf);
  115. }
  116. /* 300 seconds period */
  117. if (tb_check_invt(&tb.sys_timer[1], tb.sys_intv[1]))
  118. {
  119. /* cpu mem disk */
  120. tb_buf[0] = 0;
  121. mac_get_tbmqtt_data(tb_buf);
  122. tb_send_telemetry(tb_buf);
  123. }
  124. }
  125. static void tb_upload_pcs()
  126. {
  127. if (pcs_get_comm_st() != COMMST_NORMAL)
  128. {
  129. return;
  130. }
  131. char tb_buf[4096] = {0};
  132. if (tb_check_invt(&tb.pcs_timer[0], tb.pcs_intv[0]))
  133. {
  134. tb_buf[0] = 0;
  135. pcs_get_tbmqtt_data_interval_30s(tb_buf);
  136. tb_send_telemetry(tb_buf);
  137. }
  138. if (tb_check_invt(&tb.pcs_timer[1], tb.pcs_intv[1]))
  139. {
  140. tb_buf[0] = 0;
  141. pcs_get_tbmqtt_data_interval_60s(tb_buf);
  142. tb_send_telemetry(tb_buf);
  143. }
  144. if (tb_check_invt(&tb.pcs_timer[2], tb.pcs_intv[2]))
  145. {
  146. tb_buf[0] = 0;
  147. pcs_get_tbmqtt_data_interval_half_hour(tb_buf);
  148. tb_send_telemetry(tb_buf);
  149. }
  150. }
  151. static void tb_upload_pack()
  152. {
  153. char tb_buf[8192] = {0};
  154. if (pack_get_comm_st() != COMMST_NORMAL)
  155. {
  156. return;
  157. }
  158. if (tb_check_invt(&tb.pack_timer[0], tb.pack_intv[0]))
  159. {
  160. tb_buf[0] = 0;
  161. pack_get_tbmqtt_data_inteval_30s(tb_buf);
  162. tb_send_telemetry(tb_buf);
  163. }
  164. if (tb_check_invt(&tb.pack_timer[1], tb.pack_intv[1]))
  165. {
  166. tb_buf[0] = 0;
  167. pack_get_tbmqtt_data_inteval_60s(tb_buf);
  168. tb_send_telemetry(tb_buf);
  169. }
  170. #ifdef DEBUG_MQTT
  171. else
  172. {
  173. log_dbg("timer :%d, intv :%d", tb.pack_timer[1], tb.pack_intv[1]);
  174. }
  175. #endif
  176. int model = pack_get_model();
  177. if (tb_check_invt(&tb.pack_timer[2], tb.pack_intv[2]))
  178. { /* cell voltage*/
  179. tb_buf[0] = 0;
  180. pack_get_tbmqtt_data_inteval_level3(tb_buf);
  181. tb_send_telemetry(tb_buf);
  182. tb.cellt_sub_idx++;
  183. if ((model == DEVM_CATL280A && tb.cellt_sub_idx > BMU_NBR) || (model == DEVM_KL && tb.cellt_sub_idx > KL_CLUSTER_NBR))
  184. {
  185. tb.cellt_sub_idx = 1;
  186. }
  187. }
  188. #ifdef DEBUG_MQTT
  189. else
  190. {
  191. log_dbg("timer :%d, intv :%d", tb.pack_timer[2], tb.pack_intv[2]);
  192. }
  193. #endif
  194. if (tb_check_invt(&tb.pack_timer[3], tb.pack_intv[3]))
  195. { /* cell temperature*/
  196. tb_buf[0] = 0;
  197. pack_get_tbmqtt_data_inteval_300s(tb_buf);
  198. tb_send_telemetry(tb_buf);
  199. // tb.cellt_sub_idx++;
  200. // if ((model == DEVM_CATL280A && tb.cellt_sub_idx > BMU_NBR) || (model == DEVM_KL && tb.cellt_sub_idx > KL_CLUSTER_NBR))
  201. // {
  202. // tb.cellt_sub_idx = 1;
  203. // }
  204. }
  205. }
  206. static void tb_upload_ac(void)
  207. {
  208. char tb_buf[4096] = {0};
  209. if (tb_check_invt(&tb.ac_timer[0], tb.ac_intv[0]))
  210. {
  211. tb_buf[0] = 0;
  212. ac_get_tbmqtt_data(tb_buf);
  213. tb_send_telemetry(tb_buf);
  214. }
  215. }
  216. static int tb_upload_meter(void)
  217. {
  218. char tb_buf[4096] = {0};
  219. if (tb_check_invt(&tb.meter_timer[0], tb.meter_intv[0]))
  220. {
  221. tb_buf[0] = 0;
  222. meter_get_tbmqtt_data(tb_buf);
  223. tb_send_telemetry(tb_buf);
  224. }
  225. }
  226. static void tb_upload_env(void)
  227. {
  228. char tb_buf[4096] = {0};
  229. if (tb_check_invt(&tb.env_timer[0], tb.env_intv[0]))
  230. {
  231. tb_buf[0] = 0;
  232. env_get_tbmqtt_data(tb_buf);
  233. tb_send_telemetry(tb_buf);
  234. }
  235. }
  236. static void tb_upload_dehumi(void)
  237. {
  238. char tb_buf[4096] = {0};
  239. if (tb_check_invt(&tb.dehumi_timer[0], tb.dehumi_intv[0]))
  240. {
  241. tb_buf[0] = 0;
  242. dehumi_get_tbmqtt_data(tb_buf);
  243. tb_send_telemetry(tb_buf);
  244. }
  245. }
  246. static void tb_upload_fe(void)
  247. {
  248. char tb_buf[4096] = {0};
  249. static char tb_buf_cache[4096] = {0};
  250. memset(tb_buf, 0, sizeof(tb_buf));
  251. fe_get_tbmqtt_data(tb_buf);
  252. if (tb_check_invt(&tb.fe_timer[0], tb.fe_intv[0] || strcmp(tb_buf, tb_buf_cache) != 0))
  253. {
  254. tb_send_telemetry(tb_buf);
  255. strcpy(tb_buf_cache, tb_buf);
  256. }
  257. }
  258. static void tb_upload_fa(void)
  259. {
  260. char tb_buf[4096] = {0};
  261. static char tb_buf_cache[4096] = {0};
  262. memset(tb_buf, 0, sizeof(tb_buf));
  263. fa_get_tbmqtt_data(tb_buf);
  264. if (tb_check_invt(&tb.fa_timer[0], tb.fa_intv[0] || strcmp(tb_buf, tb_buf_cache) != 0))
  265. {
  266. tb_send_telemetry(tb_buf);
  267. strcpy(tb_buf_cache, tb_buf);
  268. }
  269. }
  270. static void tb_upload_plc(void)
  271. {
  272. char tb_buf[4096] = {0};
  273. if (tb_check_invt(&tb.plc_timer[0], tb.plc_intv[0]))
  274. {
  275. tb_buf[0] = 0;
  276. plc_get_tbmqtt_data(tb_buf);
  277. tb_send_telemetry(tb_buf);
  278. }
  279. }
  280. static void tb_upload_ups(void)
  281. {
  282. char tb_buf[4096] = {0};
  283. if (ups_get_comm_state() != COMMST_NORMAL)
  284. {
  285. return;
  286. }
  287. if (tb_check_invt(&tb.ups_timer[0], tb.ups_intv[0]))
  288. {
  289. tb_buf[0] = 0;
  290. ups_get_tbmqtt_data(tb_buf);
  291. tb_send_telemetry(tb_buf);
  292. }
  293. }
  294. static void tb_upload_ctn_cal(void)
  295. {
  296. char tb_buf[4096] = {0};
  297. if (ctn_cal_get_state() != SMST_RUN)
  298. {
  299. return;
  300. }
  301. if (tb_check_invt(&tb.ctn_cal_timer[0], tb.ctn_cal_intv[0]))
  302. {
  303. tb_buf[0] = 0;
  304. ctn_cal_get_tb_data(tb_buf);
  305. tb_send_telemetry(tb_buf);
  306. }
  307. }
  308. static void tb_upload_dido(void)
  309. {
  310. char tb_buf[4096] = {0};
  311. static char tb_buf_cache[4096] = {0};
  312. memset(tb_buf, 0, sizeof(tb_buf));
  313. dido_get_tbmqtt_data(tb_buf);
  314. if (tb_check_invt(&tb.dido_timer[0], tb.dido_intv[0]) || strcmp(tb_buf, tb_buf_cache) != 0)
  315. {
  316. tb_send_telemetry(tb_buf);
  317. strcpy(tb_buf_cache, tb_buf);
  318. }
  319. }
  320. static void tb_upload_ctn(void)
  321. {
  322. char tb_buf[4096] = {0};
  323. if (tb_check_invt(&tb.ctn_timer[0], tb.ctn_intv[0]))
  324. {
  325. tb_buf[0] = 0;
  326. ctn_get_tbmqtt_data(tb_buf);
  327. tb_send_telemetry(tb_buf);
  328. }
  329. }
  330. int tb_is_upload_enable()
  331. {
  332. struct tb_t *dev = &tb;
  333. return dev->upload_enable;
  334. }
  335. int tb_enable_upload()
  336. {
  337. struct tb_t *dev = &tb;
  338. dev->upload_enable = 1;
  339. return 0;
  340. }
  341. int tb_disable_upload()
  342. {
  343. struct tb_t *dev = &tb;
  344. dev->upload_enable = 0;
  345. return 0;
  346. }
  347. int tb_init(void)
  348. {
  349. struct tb_t *dev = &tb;
  350. int ret = 0;
  351. dev->upload_enable = 1;
  352. dev->param_en = 0;
  353. dev->sys_intv[0] = 60;
  354. dev->sys_intv[1] = 300;
  355. dev->pcs_intv[0] = 30;
  356. dev->pcs_intv[1] = 60;
  357. dev->pcs_intv[2] = 60 * 30;
  358. dev->cellv_sub_idx = 1;
  359. dev->cellt_sub_idx = 1;
  360. dev->pack_intv[0] = 30;
  361. dev->pack_intv[1] = 60;
  362. dev->pack_intv[2] = 180;
  363. dev->pack_intv[3] = 300;
  364. // tb_set_cellv_lowspeed();
  365. dev->ac_intv[0] = 60;
  366. dev->meter_intv[0] = 60;
  367. dev->env_intv[0] = 60;
  368. dev->dehumi_intv[0] = 60;
  369. dev->fe_intv[0] = 60;
  370. dev->fa_intv[0] = 60;
  371. dev->plc_intv[0] = 60;
  372. dev->ups_intv[0] = 60;
  373. dev->ctn_cal_intv[0] = 60;
  374. dev->dido_intv[0] = 30;
  375. dev->dido_intv[0] = 30;
  376. dev->ctn_intv[0] = 60;
  377. dev->tb_init = 1;
  378. dev->tb_lock_timer = 0;
  379. dev->tb_lock = 1;
  380. dev->tb_lock_intv = 15;
  381. if (tbmqtt_init() != 0)
  382. {
  383. log_dbg("%s, tbmqtt init fail", __func__);
  384. }
  385. log_dbg("%s, ret:%d", __func__, ret);
  386. return ret;
  387. }
  388. int tb_set_cellv_highspeed()
  389. {
  390. struct tb_t *dev = &tb;
  391. dev->pack_intv[2] = 6; /* cell v */
  392. /* 6 = high: 6*10=60s=1min for all 10 cabinet */
  393. return 0;
  394. }
  395. int tb_set_cellv_lowspeed()
  396. {
  397. struct tb_t *dev = &tb;
  398. dev->pack_intv[2] = 60; /* cell v */
  399. /* 60 = low: 60*10=600s=10min for all 10 cabinet */
  400. }
  401. static int tmpaps_received = 0;
  402. static int tmpaps;
  403. static void tb_proc_recv()
  404. {
  405. struct tb_t *dev = &tb;
  406. if (dev->tb_init == 1)
  407. {
  408. dev->param_en = 1;
  409. dev->tb_init = 0;
  410. tb_update_attributes("'TbLock':true");
  411. }
  412. if ((dev->tb_lock == 0) && (dev->tb_lock_timer++ >= dev->tb_lock_intv))
  413. {
  414. dev->tb_lock_timer = 0;
  415. dev->tb_lock = 1;
  416. tb_update_attributes("'TbLock':true");
  417. }
  418. cJSON *root = NULL;
  419. cJSON *item = NULL;
  420. int aps = 0;
  421. int rc;
  422. tbmqtt_ringbuffer_element_t e;
  423. tbmqtt_lock_rxbuf();
  424. rc = tbmqtt_dequeue_rxbuf(&e);
  425. tbmqtt_unlock_rxbuf();
  426. if (rc == 1)
  427. {
  428. log_dbg("%s, get topic:%s", __func__, e.sztopic);
  429. log_dbg("%s, and payload:%s", __func__, e.szpayload);
  430. root = cJSON_Parse(e.szpayload);
  431. if (!root)
  432. {
  433. log_dbg("%s, cJSON_Parse null, payload : %s", __func__, e.szpayload);
  434. }
  435. else
  436. {
  437. item = cJSON_GetObjectItem(root, "method");
  438. if (!item)
  439. {
  440. log_dbg("%s, cJSON_GetObjectItem method fail", __func__);
  441. }
  442. else
  443. {
  444. log_dbg("%s, get method:%s", __func__, item->valuestring);
  445. if (strcmp(item->valuestring, "set_lock") == 0)
  446. {
  447. item = cJSON_GetObjectItem(root, "params");
  448. if (!item)
  449. {
  450. log_dbg("%s, set_lock failed to get params ", __func__);
  451. }
  452. else
  453. {
  454. log_dbg("%s, set_lock, value :%s", __func__, item->valuestring);
  455. if (strcmp(item->valuestring, "lock") == 0)
  456. {
  457. dev->tb_lock = 1;
  458. }
  459. else
  460. {
  461. dev->tb_lock = 0;
  462. dev->tb_lock_timer = 0;
  463. }
  464. }
  465. }
  466. else if (strcmp(item->valuestring, "get_lock") == 0)
  467. {
  468. sprintf(e.szpayload, "%d", dev->tb_lock);
  469. tb_send_rpc_response(e.sztopic, e.szpayload);
  470. }
  471. else if (strcmp(item->valuestring, "set_debug") == 0)
  472. {
  473. item = cJSON_GetObjectItem(root, "params");
  474. if (!item)
  475. {
  476. log_dbg("%s, set_debug failed to get params ", __func__);
  477. }
  478. else
  479. {
  480. log_dbg("%s, set_debug, value :%s", __func__, item->valuestring);
  481. if (strcmp(item->valuestring, "debug") == 0)
  482. {
  483. ems_set_debug_mode(1);
  484. }
  485. else
  486. {
  487. ems_set_debug_mode(0);
  488. }
  489. }
  490. }
  491. else if (strcmp(item->valuestring, "get_debug") == 0)
  492. {
  493. sprintf(e.szpayload, "%d", ems_get_debug_mode());
  494. tb_send_rpc_response(e.sztopic, e.szpayload);
  495. }
  496. else if (strcmp(item->valuestring, "get_aps") == 0)
  497. {
  498. sprintf(e.szpayload, "%d", ess_get_aps());
  499. tb_send_rpc_response(e.sztopic, e.szpayload);
  500. }
  501. else
  502. {
  503. // if (dev->tb_lock)
  504. if (0)
  505. {
  506. log_dbg("%s, thingsboard is locked, do nothing", __func__);
  507. }
  508. else
  509. {
  510. int clearTimer = 0;
  511. if (strcmp(item->valuestring, "stdby") == 0)
  512. {
  513. ess_send_sm_cmd(CMD_SM_STDBY);
  514. }
  515. else if (strcmp(item->valuestring, "stop") == 0)
  516. {
  517. ess_send_sm_cmd(CMD_SM_STOP);
  518. }
  519. else if (strcmp(item->valuestring, "ready") == 0)
  520. {
  521. ess_send_sm_cmd(CMD_SM_READY);
  522. }
  523. else if (strcmp(item->valuestring, "offgrid") == 0)
  524. {
  525. ess_send_sm_cmd(CMD_SM_OFFGRID);
  526. }
  527. else if (strcmp(item->valuestring, "active_aps") == 0)
  528. {
  529. if (tmpaps_received == 1)
  530. {
  531. ess_set_aps(tmpaps);
  532. tmpaps_received = 0;
  533. }
  534. }
  535. else if (strcmp(item->valuestring, "set_aps") == 0)
  536. {
  537. item = cJSON_GetObjectItem(root, "params");
  538. if (!item)
  539. {
  540. log_dbg("%s, cJSON_GetObjectItem params fail", __func__);
  541. }
  542. else
  543. {
  544. // ess_set_aps(item->valueint);
  545. log_dbg("%s, aps:%d", __func__, item->valueint);
  546. tmpaps = item->valueint;
  547. tmpaps_received = 1;
  548. }
  549. }
  550. else if (strcmp(item->valuestring, "fe_start") == 0) // 消防喷发
  551. {
  552. item = cJSON_GetObjectItem(root, "params");
  553. if (item)
  554. {
  555. fe_set_start(item->valueint);
  556. }
  557. }
  558. else if (strcmp(item->valuestring, "bms_ctrl_pwrup") == 0)
  559. {
  560. plc_bms_ctrl_pwrup();
  561. }
  562. else if (strcmp(item->valuestring, "pack_stop") == 0)
  563. {
  564. pack_send_sm_cmd(CMD_SM_STOP);
  565. }
  566. else if (strcmp(item->valuestring, "pack_ready") == 0)
  567. {
  568. pack_send_sm_cmd(CMD_SM_READY);
  569. }
  570. else if (strcmp(item->valuestring, "pcs_stop") == 0)
  571. {
  572. pcs_send_sm_cmd(CMD_SM_STOP);
  573. }
  574. else if (strcmp(item->valuestring, "pcs_ready") == 0)
  575. {
  576. pcs_send_sm_cmd(CMD_SM_READY);
  577. }
  578. else if (strcmp(item->valuestring, "bms_ctrl_pwrup_without_shielding_signal") == 0)
  579. {
  580. plc_bms_ctrl_pwrup_without_shielding_signal();
  581. }
  582. else if (strcmp(item->valuestring, "pcs_dev_start") == 0)
  583. {
  584. gt_comm_set_dev_hv_on(1);
  585. while (gt_get_hv_status(1) != BMSHV_ON)
  586. {
  587. sleep(1);
  588. }
  589. n9_set_dev_stopcmd(1);
  590. n9_set_dev_resetcmd(1);
  591. n9_set_dev_startcmd(1);
  592. while (n9_get_runstat(1) != N9_RUNSTAT_IDLE)
  593. {
  594. sleep(1);
  595. }
  596. n9_set_dev_aps(1, 0);
  597. // pcs_set_dev_startcmd();
  598. }
  599. else if (strcmp(item->valuestring, "pcs_dev_stop") == 0)
  600. {
  601. n9_set_dev_stopcmd(1);
  602. gt_comm_set_dev_hv_off(1);
  603. // pcs_set_dev_stopcmd();
  604. }
  605. else if (strcmp(item->valuestring, "pcs_dev_reset") == 0)
  606. {
  607. n9_set_dev_resetcmd(1);
  608. // pcs_set_dev_resetcmd();
  609. }
  610. else if (strcmp(item->valuestring, "pcs_dev_active_aps") == 0)
  611. {
  612. if (tmpaps_received == 1)
  613. {
  614. n9_set_dev_aps(1, tmpaps);
  615. // pcs_set_dev_aps(tmpaps);
  616. tmpaps_received = 0;
  617. }
  618. }
  619. else if (strcmp(item->valuestring, "dido_fire_confirm") == 0)
  620. {
  621. dido_fire_confirm(1, 1);
  622. }
  623. else if (strcmp(item->valuestring, "dido_fire_cancle") == 0)
  624. {
  625. fe_set_start(-1);
  626. sleep(1);
  627. dido_fire_confirm(1, 0);
  628. }
  629. else if (strcmp(item->valuestring, "dido_fan_start") == 0)
  630. {
  631. dido_fan_switch(1, 1);
  632. }
  633. else if (strcmp(item->valuestring, "dido_fan_stop") == 0)
  634. {
  635. dido_fan_switch(1, 0);
  636. }
  637. else if (strcmp(item->valuestring, "dido_alarm_on") == 0)
  638. {
  639. dido_sys_alarm(1, 1);
  640. }
  641. else if (strcmp(item->valuestring, "dido_alarm_off") == 0)
  642. {
  643. dido_sys_alarm(1, 0);
  644. }
  645. else
  646. {
  647. clearTimer = dev->tb_lock_timer;
  648. log_dbg("%s, unknown cmd : %s", __func__, item->valuestring);
  649. }
  650. dev->tb_lock_timer = clearTimer;
  651. }
  652. }
  653. }
  654. cJSON_Delete(root);
  655. }
  656. }
  657. }
  658. void tb_exe(void)
  659. {
  660. tb_proc_recv();
  661. if (tb_is_upload_enable())
  662. {
  663. tb_upload_param();
  664. tb_upload_sys();
  665. tb_upload_ctn();
  666. tb_upload_pcs();
  667. tb_upload_pack();
  668. tb_upload_ac();
  669. tb_upload_meter();
  670. tb_upload_env();
  671. tb_upload_dehumi();
  672. tb_upload_fe();
  673. tb_upload_dido();
  674. tb_upload_fa();
  675. }
  676. }
  677. int tb_set_param_en(int val)
  678. {
  679. struct tb_t *dev = &tb;
  680. dev->param_en = val;
  681. }
  682. char *tb_get_state_str(void)
  683. {
  684. return tbmqtt_get_state_str();
  685. }
  686. int tb_get_stp(void)
  687. {
  688. return tbmqtt_get_stp();
  689. }
  690. char *tb_get_err_str(void)
  691. {
  692. return tbmqtt_get_err_str();
  693. }
  694. int tb_get_tick(void)
  695. {
  696. return tbmqtt_get_tick();
  697. }
  698. double tb_get_timing_ave(void)
  699. {
  700. return tbmqtt_get_timing_ave();
  701. }
  702. double tb_get_timing_cur(void)
  703. {
  704. return tbmqtt_get_timing_cur();
  705. }
  706. double tb_get_timing_max(void)
  707. {
  708. return tbmqtt_get_timing_max();
  709. }
  710. int tb_get_enable(void)
  711. {
  712. return tbmqtt_get_enable();
  713. }
  714. char *tb_get_servip_str(void)
  715. {
  716. return tbmqtt_get_servip_str();
  717. }
  718. int tb_get_servport(void)
  719. {
  720. return tbmqtt_get_servport();
  721. }
  722. char *tb_get_client_id(void)
  723. {
  724. return tbmqtt_get_client_id();
  725. }
  726. double tb_get_txbuf_usage(void)
  727. {
  728. return tbmqtt_get_txbuf_usage();
  729. }
  730. char *tb_get_access_token(void)
  731. {
  732. return tbmqtt_get_access_token();
  733. }
  734. int tb_get_tz(void)
  735. {
  736. return tbmqtt_get_tz();
  737. }
  738. int tb_get_tool_data(char *buf)
  739. {
  740. struct tb_t *t = &tb;
  741. char buf_temp[1024];
  742. sprintf(buf, "" REVERSE " TB " NONE " \n");
  743. tbmqtt_get_tool_data(buf_temp);
  744. strcat(buf, buf_temp);
  745. sprintf(buf_temp, " upload_en:%d param_en:%d\n", t->upload_enable, t->param_en);
  746. strcat(buf, buf_temp);
  747. return 0;
  748. }