zh200.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. #include "zh200.h"
  2. #include "plt.h"
  3. struct zh200_t zh200[ZH200_NBR_MAX + 1];
  4. int zh200_enable_pcs_bsytiksnd(int idx)
  5. {
  6. zh200[idx].pcstik.en = 1;
  7. return 0;
  8. }
  9. int zh200_disable_pcs_bsytiksnd(int idx)
  10. {
  11. zh200[idx].pcstik.en = 0;
  12. return 0;
  13. }
  14. int zh200_get_pcs_bsytiksnd_en(int idx)
  15. {
  16. return zh200[idx].pcstik.en;
  17. }
  18. int zh200_enable_bms_bsytiksnd(int idx)
  19. {
  20. zh200[idx].bmstik.en = 1;
  21. return 0;
  22. }
  23. int zh200_disable_bms_bsytiksnd(int idx)
  24. {
  25. zh200[idx].bmstik.en = 0;
  26. return 0;
  27. }
  28. int zh200_get_bms_bsytiksnd_en(int idx)
  29. {
  30. return zh200[idx].bmstik.en;
  31. }
  32. int zh200_reset_bsytikchk(int idx)
  33. {
  34. zh200[idx].bsytik.timer = 0;
  35. zh200[idx].bsytik.timeout = 0;
  36. zh200[idx].bsytik.chkcnt = 0;
  37. return 0;
  38. }
  39. int zh200_enable_bsytikchk(int idx)
  40. {
  41. zh200[idx].bsytik.en = 1;
  42. return 0;
  43. }
  44. int zh200_disable_bsytikchk(int idx)
  45. {
  46. zh200[idx].bsytik.en = 0;
  47. return 0;
  48. }
  49. int zh200_get_bsytikchk_en(int idx)
  50. {
  51. return zh200[idx].bsytik.en;
  52. }
  53. int zh200_get_bsytikchk_from_host(int idx)
  54. {
  55. return zh200[idx].bsytik.from_host;
  56. }
  57. int zh200_get_bsytikchk_timeout(int idx)
  58. {
  59. return zh200[idx].bsytik.timeout;
  60. }
  61. int zh200_is_enable_bsytikchk(int idx)
  62. {
  63. return zh200[idx].bsytik.en;
  64. }
  65. static double zh200_get_timeofday()
  66. {
  67. struct timeval tv;
  68. struct timezone tz;
  69. gettimeofday(&tv, &tz);
  70. return (double)tv.tv_sec * 1000 + (double)tv.tv_usec / 1000;
  71. }
  72. static int zh200_dbcb_0(void *para, int ncolumn, char **columnvalue, char *columnname[])
  73. {
  74. int i;
  75. struct dbcbparam_t *pcbparam = (struct dbcbparam_t *)para;
  76. struct zh200_t *dev = &zh200[1];
  77. pcbparam->nrow++;
  78. log_dbg("%s, ++, row:%d, col:%d", __func__, pcbparam->nrow, ncolumn);
  79. for (i = 0; i < ncolumn; i++)
  80. {
  81. if (strcmp("info", columnname[i]) == 0)
  82. {
  83. strcpy(dev->szinfo, columnvalue[i]);
  84. }
  85. else if (strcmp("chan_idx", columnname[i]) == 0)
  86. {
  87. dev->chan_idx = atoi(columnvalue[i]);
  88. }
  89. else if (strcmp("norm_cap", columnname[i]) == 0)
  90. {
  91. dev->pow.norm_cap = atoi(columnvalue[i]);
  92. }
  93. else if (strcmp("norm_pow", columnname[i]) == 0)
  94. {
  95. dev->pow.norm_pow = atoi(columnvalue[i]);
  96. }
  97. else if (strcmp("min_pow", columnname[i]) == 0)
  98. {
  99. dev->pow.min_pow = atoi(columnvalue[i]);
  100. }
  101. else if (strcmp("socc", columnname[i]) == 0)
  102. {
  103. dev->socc = atof(columnvalue[i]);
  104. }
  105. else if (strcmp("socd", columnname[i]) == 0)
  106. {
  107. dev->socd = atof(columnvalue[i]);
  108. }
  109. else if (strcmp("max_v", columnname[i]) == 0)
  110. {
  111. dev->max_v = atof(columnvalue[i]);
  112. }
  113. else if (strcmp("min_v", columnname[i]) == 0)
  114. {
  115. dev->min_v = atof(columnvalue[i]);
  116. }
  117. else if (strcmp("cell_otp", columnname[i]) == 0)
  118. {
  119. dev->cell_otp = atoi(columnvalue[i]);
  120. }
  121. else if (strcmp("cell_utp", columnname[i]) == 0)
  122. {
  123. dev->cell_utp = atoi(columnvalue[i]);
  124. }
  125. else if (strcmp("modbus_tcp_slave_port", columnname[i]) == 0)
  126. {
  127. dev->modbus_tcp_slave_port = atoi(columnvalue[i]);
  128. }
  129. else if (strcmp("modbus_tcp_slave_port_EMA", columnname[i]) == 0)
  130. {
  131. dev->modbus_tcp_slave_port_EMA = atoi(columnvalue[i]);
  132. }
  133. else if (strcmp("idx", columnname[i]) == 0)
  134. {
  135. dev->idx = atoi(columnvalue[i]);
  136. }
  137. else if (strcmp("devid", columnname[i]) == 0)
  138. {
  139. if (columnvalue[i] != NULL && strcmp(columnvalue[i], "") != 0)
  140. {
  141. strcpy(dev->szdev_id, columnvalue[i]);
  142. }
  143. else
  144. {
  145. dev->szdev_id[0] = 0;
  146. log_dbg("%s, devid is null", __func__);
  147. }
  148. }
  149. }
  150. pcbparam->ret = 0;
  151. log_dbg("%s, --,ret:%d", __func__, pcbparam->ret);
  152. return 0;
  153. }
  154. void zh200_set_state(int idx, int state, int err)
  155. {
  156. sm_set_state(&zh200[idx].sm, state, err);
  157. }
  158. int zh200_get_state(int idx)
  159. {
  160. return zh200[idx].sm.state;
  161. }
  162. int zh200_get_step(int idx)
  163. {
  164. return zh200[idx].sm.step;
  165. }
  166. int zh200_get_tick(int idx)
  167. {
  168. return zh200[idx].sm.tick;
  169. }
  170. double zh200_get_tick_ave(int idx)
  171. {
  172. return zh200[idx].sm.timing_ave;
  173. }
  174. double zh200_get_tick_cur(int idx)
  175. {
  176. return zh200[idx].sm.timing_cur;
  177. }
  178. double zh200_get_tick_max(int idx)
  179. {
  180. return zh200[idx].sm.timing_max;
  181. }
  182. char *zh200_get_state_str(int idx)
  183. {
  184. return zh200[idx].sm.szState;
  185. }
  186. char *zh200_get_err_str(int idx)
  187. {
  188. return zh200[idx].sm.szerr;
  189. }
  190. int zh200_get_err(int idx)
  191. {
  192. return zh200[idx].sm.err;
  193. }
  194. int zh200_set_aps(int idx, int aps)
  195. {
  196. struct zh200_t *dev = &zh200[idx];
  197. int ret = 0;
  198. dev->pow.last_aps = dev->pow.aps;
  199. dev->pow.aps = aps;
  200. log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, aps, ret);
  201. return ret;
  202. }
  203. int zh200_reset_aps(int idx)
  204. {
  205. struct zh200_t *dev = &zh200[idx];
  206. int ret = 0;
  207. dev->pow.last_aps = 0;
  208. dev->pow.aps = 0;
  209. return ret;
  210. }
  211. int zh200_get_ap(int idx)
  212. {
  213. return zh200[idx].pow.ap;
  214. }
  215. int zh200_get_dhgable(int idx)
  216. {
  217. return zh200[idx].pow.bdhgable;
  218. }
  219. void zh200_set_dhgable(int idx, int val)
  220. {
  221. zh200[idx].pow.bdhgable = val;
  222. }
  223. int zh200_get_chgable(int idx)
  224. {
  225. return zh200[idx].pow.bchgable;
  226. }
  227. void zh200_set_chgable(int idx, int val)
  228. {
  229. zh200[idx].pow.bchgable = val;
  230. }
  231. int zh200_get_aps(int idx)
  232. {
  233. return zh200[idx].pow.aps;
  234. }
  235. int zh200_get_last_aps(int idx)
  236. {
  237. return zh200[idx].pow.last_aps;
  238. }
  239. double zh200_get_soc(int idx)
  240. {
  241. return zh200[idx].pow.soc;
  242. }
  243. double zh200_get_soh(int idx)
  244. {
  245. return zh200[idx].pow.soh;
  246. }
  247. int zh200_get_norm_cap(int idx)
  248. {
  249. return zh200[idx].pow.norm_cap;
  250. }
  251. int zh200_get_norm_pow(int idx)
  252. {
  253. return zh200[idx].pow.norm_pow;
  254. }
  255. int zh200_get_min_pow(int idx)
  256. {
  257. return zh200[idx].pow.min_pow;
  258. }
  259. int zh200_send_cmd(int idx, int cmd)
  260. {
  261. int ret = 0;
  262. zh200[idx].cmd = cmd;
  263. log_dbg("%s, idx:%d, cmd:%d, ret:%d", __func__, idx, cmd, ret);
  264. return ret;
  265. }
  266. /*************************************
  267. static void zh200_usleep(unsigned int nusecs)
  268. {
  269. struct timeval tval;
  270. tval.tv_sec = nusecs / 1000000;
  271. tval.tv_usec = nusecs % 1000000;
  272. select(0, NULL, NULL, NULL, &tval);
  273. }
  274. *************************************/
  275. static void zh200_update(int idx)
  276. {
  277. struct zh200_t *dev = &zh200[idx];
  278. struct statemachine_t *sm = &dev->sm;
  279. dev->pow.ap = pcs_get_ap();
  280. dev->pow.soc = pack_get_soc();
  281. dev->pow.soh = pack_get_soh();
  282. }
  283. static void zh200_aux(int idx)
  284. {
  285. struct zh200_t *dev = &zh200[idx];
  286. struct statemachine_t *sm = &dev->sm;
  287. if (dev->bsytik.timer++ >= 100)
  288. {
  289. dev->bsytik.timer = 0;
  290. // log_dbg("%s, idx:%d, from_host:%d, last_from_host:%d", __func__, idx, dev->bsytik.from_host, dev->bsytik.last_from_host);
  291. if (dev->bsytik.last_from_host != dev->bsytik.from_host)
  292. {
  293. dev->bsytik.last_from_host = dev->bsytik.from_host;
  294. dev->bsytik.chkcnt = 0;
  295. }
  296. else
  297. {
  298. if (dev->bsytik.chkcnt++ >= 10)
  299. {
  300. dev->bsytik.timeout = 1;
  301. }
  302. }
  303. // log_dbg("%s, idx:%d, from_host:%d, last_from_host:%d, chk count:%d, timeout:%d", __func__, idx, dev->bsytik.from_host, dev->bsytik.last_from_host, dev->bsytik.chkcnt, dev->bsytik.timeout);
  304. }
  305. if (zh200_get_pcs_bsytiksnd_en(idx))
  306. {
  307. if (dev->pcstik.timer++ >= 100)
  308. { // 1s
  309. dev->pcstik.timer = 0;
  310. pcs_set_bsytik();
  311. }
  312. }
  313. if (zh200_get_bms_bsytiksnd_en(idx))
  314. {
  315. if (dev->bmstik.timer++ >= 100)
  316. { // 1s
  317. dev->bmstik.timer = 0;
  318. pack_set_bsytik();
  319. }
  320. }
  321. static int cnt = 0;
  322. if (cnt < 1 && mqtt_get_state() == SMST_READY)
  323. {
  324. cnt++;
  325. if (idx == 1)
  326. {
  327. cloud.sys_init = 0;
  328. }
  329. char buf[4096] = {0};
  330. zh200_get_init_data(1, buf);
  331. cloud_send_init(buf);
  332. }
  333. }
  334. static void *zh200_thrd_main(void *param)
  335. {
  336. struct zh200_t *dev = &zh200[1];
  337. log_dbg("%s, ++", __func__);
  338. zh200_set_dhgable(1, 1);
  339. zh200_set_chgable(1, 1);
  340. zh200_disable_bsytikchk(1); // cyx : 默认不开启,只有当 9527 端口连上时
  341. zh200_disable_pcs_bsytiksnd(1);
  342. zh200_disable_bms_bsytiksnd(1);
  343. pack_set_bsytikchk_en(1);
  344. zh200_sm_init(1);
  345. while (1)
  346. {
  347. zh200_sm(1);
  348. zh200_update(1);
  349. zh200_aux(1);
  350. usleep(10000); /* 10ms */
  351. }
  352. log_dbg("%s, --", __func__);
  353. return NULL;
  354. }
  355. // static void zh200_task(int signo){
  356. // zh200_sm( 1 );
  357. // }
  358. // static void zh200_init_sigaction(){
  359. // struct sigaction act;
  360. // act.sa_handler = zh200_task;
  361. // act.sa_flags = 0;
  362. // sigemptyset(&act.sa_mask);
  363. // sigaction(SIGPROF,&act,NULL); //设置信号 SIGPROF 的处理函数为 print_info
  364. // }
  365. // static void zh200_init_timer()
  366. //{
  367. // struct itimerval value;
  368. // value.it_value.tv_sec = 0;
  369. // value.it_value.tv_usec = 10000;
  370. // value.it_interval=value.it_value;
  371. // setitimer(ITIMER_PROF,&value,NULL);
  372. // }
  373. /********************************************
  374. static int zh200_init_timer2()
  375. {
  376. struct sigevent evp;
  377. struct itimerspec ts;
  378. timer_t timer;
  379. int ret;
  380. memset(&evp, 0, sizeof(evp));
  381. evp.sigev_value.sival_ptr = &timer;
  382. evp.sigev_notify = SIGEV_THREAD;
  383. evp.sigev_notify_function = zh200_task;
  384. evp.sigev_value.sival_int = 3; //作为handle()的参数
  385. ret = timer_create(CLOCK_REALTIME, &evp, &timer);
  386. if( ret){
  387. perror("timer_create");
  388. }
  389. ts.it_interval.tv_sec = 0;
  390. ts.it_interval.tv_nsec = 10000000;
  391. ts.it_value.tv_sec = 0;
  392. ts.it_value.tv_nsec = 10000000;
  393. ret = timer_settime(timer, TIMER_ABSTIME, &ts, NULL);
  394. if( ret )
  395. {
  396. perror("timer_settime");
  397. }
  398. }
  399. *************************************************/
  400. int zh200_get_cmd(int idx)
  401. {
  402. return zh200[idx].cmd;
  403. }
  404. void zh200_reset_cmd(int idx)
  405. {
  406. zh200[idx].cmd = CMD_SM_DONE;
  407. }
  408. int zh200_init(void)
  409. {
  410. pthread_t thrd;
  411. char buf[32];
  412. int result;
  413. char *errmsg = NULL;
  414. sqlite3 *db = NULL;
  415. char sql[1024];
  416. struct dbcbparam_t cbparam;
  417. int ret = 0;
  418. struct zh200_t *dev = &zh200[1];
  419. log_dbg("%s, ++", __func__);
  420. plt_lock_ctndb();
  421. db = plt_get_ctndb();
  422. sprintf(sql, "select * from zh200");
  423. cbparam.nrow = 0;
  424. result = sqlite3_exec(db, sql, zh200_dbcb_0, (void *)&cbparam, &errmsg);
  425. plt_unlock_ctndb();
  426. if (result != SQLITE_OK)
  427. {
  428. log_dbg("%s, result != SQLITE_OK : %d", __func__, result);
  429. ret = -1;
  430. }
  431. else if (cbparam.ret != 0)
  432. {
  433. log_dbg("%s, cbparam.ret != 0 : %d", __func__, cbparam.ret);
  434. ret = -2;
  435. }
  436. else if (cbparam.nrow != 1)
  437. {
  438. log_dbg("%s, cbparam.nrow != 1 : %d", __func__, cbparam.nrow);
  439. ret = -3;
  440. }
  441. else
  442. {
  443. db = plt_get_devdb();
  444. cbparam.nrow = 0;
  445. plt_lock_devdb();
  446. sprintf(sql, "select * from zh200");
  447. result = sqlite3_exec(db, sql, zh200_dbcb_0, (void *)&cbparam, &errmsg);
  448. plt_unlock_devdb();
  449. for (int i = 1; i <= 1; ++i)
  450. {
  451. if (strcmp(zh200[i].szdev_id, "") == 0)
  452. {
  453. if (get_snow_id(zh200[i].szdev_id) != 0)
  454. {
  455. ret = -4;
  456. }
  457. else
  458. {
  459. char sql[1024];
  460. char *errmsg = NULL;
  461. sprintf(sql, "update zh200 set devid=\"%s\" where idx=%d", zh200[i].szdev_id, zh200[i].idx);
  462. plt_lock_devdb();
  463. int rc = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
  464. plt_unlock_devdb();
  465. if (rc != SQLITE_OK)
  466. {
  467. log_dbg("%s, failed to update level device id:%s", __func__, errmsg);
  468. ret = -4;
  469. goto leave;
  470. }
  471. else
  472. {
  473. log_dbg("%s, update device id:%s", __func__, zh200[i].szdev_id);
  474. }
  475. }
  476. }
  477. }
  478. // chan_set_mbs(dev->chan_idx, DEVM_ZH200, 1);
  479. // chan_set_en(dev->chan_idx, 1);
  480. if (pthread_create(&thrd, NULL, zh200_thrd_main, NULL) != 0)
  481. {
  482. log_dbg("%s, create zh200 thrd main fail", __func__);
  483. ret = -1;
  484. }
  485. }
  486. leave:
  487. log_dbg("%s, --, ret:%d", __func__, ret);
  488. return ret;
  489. }
  490. int zh200_is_aps_changed(int idx)
  491. {
  492. return (zh200[idx].pow.aps != zh200[idx].pow.last_aps) ? 1 : 0;
  493. }
  494. int zh200_set_socd(int idx, double val)
  495. {
  496. zh200[idx].socd = val;
  497. return 0;
  498. }
  499. int zh200_set_socc(int idx, double val)
  500. {
  501. zh200[idx].socc = val;
  502. return 0;
  503. }
  504. double zh200_get_socd(int idx)
  505. {
  506. return zh200[idx].socd;
  507. }
  508. double zh200_get_socc(int idx)
  509. {
  510. return zh200[idx].socc;
  511. }
  512. int zh200_get_cell_otp(int idx)
  513. {
  514. return zh200[idx].cell_otp;
  515. }
  516. int zh200_get_cell_utp(int idx)
  517. {
  518. return zh200[idx].cell_utp;
  519. }
  520. int zh200_cfg_save_socc(int idx)
  521. {
  522. sqlite3 *db = NULL;
  523. char sql[1024];
  524. int result = 0;
  525. plt_lock_ctndb();
  526. db = plt_get_ctndb();
  527. sprintf(sql, "update zh200 set socc=%d where idx=1", (int)zh200_get_socc(idx));
  528. result = sqlite3_exec(db, sql, NULL, NULL, NULL);
  529. plt_unlock_ctndb();
  530. if (result == SQLITE_OK)
  531. {
  532. return 0;
  533. }
  534. else
  535. {
  536. return -1;
  537. }
  538. }
  539. int zh200_cfg_save_socd(int idx)
  540. {
  541. sqlite3 *db = NULL;
  542. char sql[1024];
  543. int result = 0;
  544. plt_lock_ctndb();
  545. db = plt_get_ctndb();
  546. sprintf(sql, "update zh200 set socd=%d where idx=1", (int)zh200_get_socd(idx));
  547. result = sqlite3_exec(db, sql, NULL, NULL, NULL);
  548. plt_unlock_ctndb();
  549. if (result == SQLITE_OK)
  550. {
  551. return 0;
  552. }
  553. else
  554. {
  555. return -1;
  556. }
  557. }
  558. int zh200_get_tool_data(int idx, char *buf)
  559. {
  560. struct zh200_t *dev = &zh200[idx];
  561. struct statemachine_t *sm = &dev->sm;
  562. char buf_temp[1024];
  563. if (idx < 1 || idx > ZH200_NBR_MAX)
  564. return -1;
  565. sprintf(buf, "dev id :%s norm_cap:%d norm_pow:%d min_pow:%d\n", dev->szdev_id, dev->pow.norm_cap, dev->pow.norm_pow, dev->pow.min_pow);
  566. sm_get_summary(sm, buf_temp, sizeof(buf_temp));
  567. strcat(buf, buf_temp);
  568. sprintf(buf_temp, " ap:" L_GREEN "%d" NONE " aps:%d soc:" L_GREEN "%.1f" NONE " dhgable:%d chgable:%d socd:%.1f socc:%.1f cell_otp:%d utp:%d min_v:%.1f max_v:%.1f\n",
  569. dev->pow.ap, dev->pow.aps, dev->pow.soc,
  570. dev->pow.bdhgable, dev->pow.bchgable, dev->socd, dev->socc, dev->cell_otp, dev->cell_utp, dev->min_v, dev->max_v);
  571. strcat(buf, buf_temp);
  572. sprintf(buf_temp, " bsytik_en:%d from_host:%03d tiemout:%d pcs_bsytik_en:%d\n",
  573. dev->bsytik.en, dev->bsytik.from_host, dev->bsytik.timeout,
  574. dev->pcstik.en);
  575. strcat(buf, buf_temp);
  576. return 0;
  577. }
  578. unsigned short zh200_get_cmd_param1(int idx)
  579. {
  580. return zh200[idx].cmdpara[0];
  581. }
  582. unsigned short zh200_get_cmd_param2(int idx)
  583. {
  584. return zh200[idx].cmdpara[1];
  585. }
  586. unsigned short zh200_get_cmd_param3(int idx)
  587. {
  588. return zh200[idx].cmdpara[2];
  589. }
  590. unsigned short zh200_get_cmd_param4(int idx)
  591. {
  592. return zh200[idx].cmdpara[3];
  593. }
  594. int zh200_set_cmd(int idx, int cmd)
  595. {
  596. zh200[idx].cmd = cmd;
  597. return 0;
  598. }
  599. int zh200_set_cmd_param1(int idx, unsigned short param)
  600. {
  601. zh200[idx].cmdpara[0] = param;
  602. return 0;
  603. }
  604. int zh200_set_cmd_param2(int idx, unsigned short param)
  605. {
  606. zh200[idx].cmdpara[1] = param;
  607. return 0;
  608. }
  609. int zh200_set_cmd_param3(int idx, unsigned short param)
  610. {
  611. zh200[idx].cmdpara[2] = param;
  612. return 0;
  613. }
  614. int zh200_set_cmd_param4(int idx, unsigned short param)
  615. {
  616. zh200[idx].cmdpara[3] = param;
  617. return 0;
  618. }
  619. int zh200_set_bsytikchk_from_host(int idx, unsigned char tick)
  620. {
  621. zh200[idx].bsytik.from_host = tick;
  622. return 0;
  623. }
  624. char *zh200_get_devid(int idx)
  625. {
  626. return zh200[idx].szdev_id;
  627. }
  628. int zh200_get_init_data(int idx, char *buf)
  629. {
  630. sprintf(buf, "{\"device_id\":\"%s\", \"type\":1, \"idx\":%d, \"config\":{ \
  631. \"norm_cap\":%d, \"norm_pow\":%d, \"min_pow\":%d, \"socd\":%.1f, \"socc\":%.1f, \
  632. \"cell_otp\":%d, \"cell_utp\":%d, \"min_v\":%.1f, \"max_v\":%.1f }}",
  633. zh200[idx].szdev_id,
  634. ctn_get_idx_in_ess(),
  635. zh200[idx].pow.norm_cap,
  636. zh200[idx].pow.norm_pow,
  637. zh200[idx].pow.min_pow,
  638. zh200[idx].socd,
  639. zh200[idx].socc,
  640. zh200[idx].cell_otp,
  641. zh200[idx].cell_utp,
  642. zh200[idx].min_v,
  643. zh200[idx].max_v);
  644. return 0;
  645. }
  646. int zh200_get_tbmqtt_data(int idx, char *buff)
  647. {
  648. struct zh200_t *dev = &zh200[idx];
  649. if (strcmp(dev->szRunInfo, "ok") != 0)
  650. {
  651. sprintf(buff, "'ctn_stop_info':'%s'", dev->szRunInfo);
  652. return 0;
  653. }
  654. return -1;
  655. }