LcmCommandDriver.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. /*
  2. * LcmCommandDriver.c
  3. *
  4. * Created on: 2022/3/31
  5. * Author: folus
  6. */
  7. #include "Module_LcmControl_Wistron.h"
  8. #include "../Config.h"
  9. Text_List TextList[100];
  10. int TextIndex = 0;
  11. Image_List ImageList[100];
  12. int ImageIndex = 0;
  13. APNG_List ApngList[5];
  14. int ApngIndex = 0;
  15. QrCode_List QRCodeList[5];
  16. int QRCodeIndex = 0;
  17. TextScroll_List TextScrollList[5];
  18. int TextScrollIndex = 0;
  19. /**
  20. *
  21. * @param mosq
  22. * @param topic
  23. * @param outputStr
  24. * @return
  25. */
  26. int publish_data(struct mosquitto *mosq, char *topic, char *outputStr)
  27. {
  28. int result;
  29. result = mosquitto_publish(mosq, NULL, topic, strlen(outputStr), outputStr, QOS_ENSURE_BROKER, RETAIN_NO);
  30. if(result != MOSQ_ERR_SUCCESS)DEBUG_ERROR("Publish %s error publishing: %s\n", topic, mosquitto_strerror(result));
  31. return (result != MOSQ_ERR_SUCCESS)?FAIL:PASS;
  32. }
  33. /**
  34. *
  35. * @param mosq
  36. */
  37. int publish_profile(struct mosquitto *mosq, char *parameter, char *value)
  38. {
  39. json_object *payload = json_object_new_object();
  40. char outputStr[2048]={0};
  41. json_object_object_add(payload, parameter, json_object_new_string(value));
  42. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  43. json_object_put(payload);
  44. return publish_data(mosq, "client/profile", outputStr);
  45. }
  46. /**
  47. *
  48. * @param mosq
  49. */
  50. int publish_upgrade(struct mosquitto *mosq, char *otaType, char *url, char *checksum, char *verInfo)
  51. {
  52. json_object *payload = json_object_new_object();
  53. char outputStr[2048]={0};
  54. json_object_object_add(payload, "task_name", json_object_new_string(otaType));
  55. if((strstr(otaType, OTA_TYPE_APK) != NULL) || (strstr(otaType, OTA_TYPE_UI) != NULL))
  56. json_object_object_add(payload, "ftp server", json_object_new_string(url));
  57. if(strstr(otaType, OTA_TYPE_UI) != NULL)
  58. {
  59. json_object_object_add(payload, "file_checksum", json_object_new_string(checksum));
  60. json_object_object_add(payload, "version_info", json_object_new_string(verInfo));
  61. }
  62. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  63. json_object_put(payload);
  64. return publish_data(mosq, "client/command", outputStr);
  65. }
  66. /**
  67. *
  68. * @param mosq
  69. */
  70. int publish_restart(struct mosquitto *mosq, uint8_t isHardReset)
  71. {
  72. json_object *payload = json_object_new_object();
  73. char outputStr[2048]={0};
  74. json_object_object_add(payload, "task_name", json_object_new_string(isHardReset?"restart":"reset"));
  75. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  76. json_object_put(payload);
  77. return publish_data(mosq, "client/command", outputStr);
  78. }
  79. /**
  80. *
  81. * @param mosq
  82. */
  83. int publish_power_saving(struct mosquitto *mosq, uint8_t isSleep,char* mac)
  84. {
  85. if(isSleep)
  86. {
  87. json_object *payload = json_object_new_object();
  88. char outputStr[2048]={0};
  89. json_object_object_add(payload, "task_name", json_object_new_string("power_saving"));
  90. json_object_object_add(payload, "mode", json_object_new_string(isSleep?"1":"0"));
  91. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  92. json_object_put(payload);
  93. return publish_data(mosq, "client/command", outputStr);
  94. }
  95. else
  96. {
  97. char cmd[64];
  98. sprintf(cmd, "/usr/sbin/ether-wake -i eth1 %s\n",mac);
  99. system(cmd);
  100. DEBUG_INFO("MAC:%s\n", mac);
  101. return PASS;
  102. }
  103. }
  104. /**
  105. *
  106. * @param mosq
  107. */
  108. int publish_back_dimming(struct mosquitto *mosq, uint8_t lightLevel)
  109. {
  110. json_object *payload = json_object_new_object();
  111. char outputStr[2048]={0};
  112. char buf[8];
  113. json_object_object_add(payload, "task_name", json_object_new_string("backlight"));
  114. sprintf(buf, "%d", lightLevel);
  115. json_object_object_add(payload, "brightness", json_object_new_string(buf));
  116. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  117. json_object_put(payload);
  118. return publish_data(mosq, "client/command", outputStr);
  119. }
  120. /**
  121. *
  122. * @param mosq
  123. */
  124. int publish_audio_volume(struct mosquitto *mosq, uint8_t volume)
  125. {
  126. json_object *payload = json_object_new_object();
  127. char outputStr[2048]={0};
  128. char buf[8];
  129. json_object_object_add(payload, "task_name", json_object_new_string("audio_volume"));
  130. sprintf(buf, "%d", volume);
  131. json_object_object_add(payload, "volume", json_object_new_string(buf));
  132. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  133. json_object_put(payload);
  134. return publish_data(mosq, "client/command", outputStr);
  135. }
  136. /**
  137. *
  138. * @param mosq
  139. */
  140. int publish_trigger_report_status(struct mosquitto *mosq)
  141. {
  142. json_object *payload = json_object_new_object();
  143. char outputStr[2048]={0};
  144. json_object_object_add(payload, "task_name", json_object_new_string("report_status"));
  145. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  146. json_object_put(payload);
  147. return publish_data(mosq, "client/command", outputStr);
  148. }
  149. /**
  150. *
  151. * @param mosq
  152. */
  153. int publish_timesync(struct mosquitto *mosq)
  154. {
  155. char outputStr[64]={0};
  156. time_t CurrentTime;
  157. struct tm *tm;
  158. struct timeval tv;
  159. CurrentTime = time(NULL);
  160. tm=localtime(&CurrentTime);
  161. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  162. sprintf(outputStr,"%04d-%02d-%02dT%02d:%02d:%02d+00:00", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  163. return publish_data(mosq, "client/timesync", outputStr);
  164. }
  165. int publish_textview_add(struct mosquitto* mosq, Text_List* textList, uint8_t listCount)
  166. {
  167. json_object *payload = json_object_new_array();
  168. char outputStr[250*100]={0};
  169. for(int idx=0;idx<listCount;idx++)
  170. {
  171. if (textList[idx].textviewIndex == 0 || textList[idx].textviewIndex >= 9999) {
  172. continue;
  173. }
  174. json_object *textview = json_object_new_object();
  175. char buf[32];
  176. sprintf(buf, "%d", textList[idx].textviewIndex);
  177. json_object_object_add(textview, "textviewIndex", json_object_new_string(buf));
  178. json_object_object_add(textview, "textString", json_object_new_string(textList[idx].textString));
  179. json_object_object_add(textview, "textFont", json_object_new_string(textList[idx].textFont));
  180. json_object_object_add(textview, "textStyle", json_object_new_string(textList[idx].textStyle));
  181. sprintf(buf, "%d", textList[idx].textSize);
  182. json_object_object_add(textview, "textSize", json_object_new_string(buf));
  183. sprintf(buf, "%d", textList[idx].layout_x);
  184. json_object_object_add(textview, "layout_x", json_object_new_string(buf));
  185. sprintf(buf, "%d", textList[idx].layout_y);
  186. json_object_object_add(textview, "layout_y", json_object_new_string(buf));
  187. sprintf(buf, "%d", textList[idx].width);
  188. json_object_object_add(textview, "width", json_object_new_string(buf));
  189. sprintf(buf, "%d", textList[idx].color_r);
  190. json_object_object_add(textview, "color_r", json_object_new_string(buf));
  191. sprintf(buf, "%d", textList[idx].color_g);
  192. json_object_object_add(textview, "color_g", json_object_new_string(buf));
  193. sprintf(buf, "%d", textList[idx].color_b);
  194. json_object_object_add(textview, "color_b", json_object_new_string(buf));
  195. sprintf(buf, "%d", textList[idx].alignment);
  196. json_object_object_add(textview, "alignment", json_object_new_string(buf));
  197. json_object_array_add(payload, textview);
  198. }
  199. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  200. json_object_put(payload);
  201. return publish_data(mosq, "client/layout/textview", outputStr);
  202. }
  203. /**
  204. *
  205. * @param mosq
  206. */
  207. int publish_textscroll_add(struct mosquitto* mosq, TextScroll_List* textList, uint8_t listCount)
  208. {
  209. json_object *payload = json_object_new_array();
  210. char outputStr[250*100]={0};
  211. for(int idx=0;idx<listCount;idx++)
  212. {
  213. if (textList[idx].textscrollIndex == 0 || textList[idx].textscrollIndex >= 9999) {
  214. continue;
  215. }
  216. json_object *textscroll = json_object_new_object();
  217. char buf[32];
  218. sprintf(buf, "%d", textList[idx].textscrollIndex);
  219. json_object_object_add(textscroll, "textscrollIndex", json_object_new_string(buf));
  220. json_object_object_add(textscroll, "textString", json_object_new_string(textList[idx].textString));
  221. json_object_object_add(textscroll, "textFont", json_object_new_string(textList[idx].textFont));
  222. json_object_object_add(textscroll, "textStyle", json_object_new_string(textList[idx].textStyle));
  223. sprintf(buf, "%d", textList[idx].textSize);
  224. json_object_object_add(textscroll, "textSize", json_object_new_string(buf));
  225. sprintf(buf, "%d", textList[idx].layout_x);
  226. json_object_object_add(textscroll, "layout_x", json_object_new_string(buf));
  227. sprintf(buf, "%d", textList[idx].layout_y);
  228. json_object_object_add(textscroll, "layout_y", json_object_new_string(buf));
  229. sprintf(buf, "%d", textList[idx].width);
  230. json_object_object_add(textscroll, "width", json_object_new_string(buf));
  231. sprintf(buf, "%d", textList[idx].color_r);
  232. json_object_object_add(textscroll, "color_r", json_object_new_string(buf));
  233. sprintf(buf, "%d", textList[idx].color_g);
  234. json_object_object_add(textscroll, "color_g", json_object_new_string(buf));
  235. sprintf(buf, "%d", textList[idx].color_b);
  236. json_object_object_add(textscroll, "color_b", json_object_new_string(buf));
  237. sprintf(buf, "%d", textList[idx].direction);
  238. json_object_object_add(textscroll, "direction", json_object_new_string(buf));
  239. json_object_array_add(payload, textscroll);
  240. }
  241. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  242. json_object_put(payload);
  243. return publish_data(mosq, "client/layout/textscroll", outputStr);
  244. }
  245. /**
  246. *
  247. * @param mosq
  248. */
  249. int publish_imageview_add(struct mosquitto *mosq, Image_List *imageList, uint8_t listCount)
  250. {
  251. json_object *payload = json_object_new_array();
  252. char outputStr[250*100]={0};
  253. for(int idx=0;idx<listCount;idx++)
  254. {
  255. if (imageList[idx].imageviewIndex == 0 || imageList[idx].imageviewIndex >= 9999) {
  256. continue;
  257. }
  258. json_object *imageview = json_object_new_object();
  259. char buf[32];
  260. sprintf(buf, "%d", imageList[idx].imageviewIndex);
  261. json_object_object_add(imageview, "imageviewIndex", json_object_new_string(buf));
  262. sprintf(buf, "%d", imageList[idx].imgsrc_addr);
  263. json_object_object_add(imageview, "imgsrc_addr", json_object_new_string(buf));
  264. sprintf(buf, "%d", imageList[idx].layout_x);
  265. json_object_object_add(imageview, "layout_x", json_object_new_string(buf));
  266. sprintf(buf, "%d", imageList[idx].layout_y);
  267. json_object_object_add(imageview, "layout_y", json_object_new_string(buf));
  268. sprintf(buf, "%d", imageList[idx].width);
  269. json_object_object_add(imageview, "width", json_object_new_string(buf));
  270. sprintf(buf, "%d", imageList[idx].height);
  271. json_object_object_add(imageview, "height", json_object_new_string(buf));
  272. json_object_array_add(payload, imageview);
  273. }
  274. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  275. json_object_put(payload);
  276. return publish_data(mosq, "client/layout/imageview", outputStr);
  277. }
  278. /**
  279. *
  280. * @param mosq
  281. */
  282. int publish_apngview_add(struct mosquitto *mosq, APNG_List *apngList, uint8_t listCount)
  283. {
  284. json_object *payload = json_object_new_array();
  285. char outputStr[250*100]={0};
  286. for(int idx=0;idx<listCount;idx++)
  287. {
  288. if (apngList[idx].apngIndex == 0 || apngList[idx].apngIndex >= 9999) {
  289. continue;
  290. }
  291. json_object *apngview = json_object_new_object();
  292. char buf[32];
  293. sprintf(buf, "%d", apngList[idx].apngIndex);
  294. json_object_object_add(apngview, "apngIndex", json_object_new_string(buf));
  295. sprintf(buf, "%d", apngList[idx].apngsrc_addr);
  296. json_object_object_add(apngview, "apngsrc_addr", json_object_new_string(buf));
  297. sprintf(buf, "%d", apngList[idx].layout_x);
  298. json_object_object_add(apngview, "layout_x", json_object_new_string(buf));
  299. sprintf(buf, "%d", apngList[idx].layout_y);
  300. json_object_object_add(apngview, "layout_y", json_object_new_string(buf));
  301. sprintf(buf, "%d", apngList[idx].width);
  302. json_object_object_add(apngview, "width", json_object_new_string(buf));
  303. sprintf(buf, "%d", apngList[idx].height);
  304. json_object_object_add(apngview, "height", json_object_new_string(buf));
  305. sprintf(buf, "%d", apngList[idx].loop);
  306. json_object_object_add(apngview, "loop", json_object_new_string(buf));
  307. json_object_array_add(payload, apngview);
  308. }
  309. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  310. json_object_put(payload);
  311. return publish_data(mosq, "client/layout/apngview", outputStr);
  312. }
  313. /**
  314. *
  315. * @param mosq
  316. */
  317. int publish_videoview_add(struct mosquitto *mosq, Video_List *videoList, uint8_t listCount)
  318. {
  319. json_object *payload = json_object_new_array();
  320. char outputStr[2048]={0};
  321. for(int idx=0;idx<listCount;idx++)
  322. {
  323. json_object *imageview = json_object_new_object();
  324. char buf[32];
  325. sprintf(buf, "%d", videoList[idx].videoviewIndex);
  326. json_object_object_add(imageview, "videoviewIndex", json_object_new_string(buf));
  327. sprintf(buf, "%d", videoList[idx].videosrc_addr);
  328. json_object_object_add(imageview, "videoSrc_addr", json_object_new_string(buf));
  329. sprintf(buf, "%d", videoList[idx].layout_x);
  330. json_object_object_add(imageview, "layout_x", json_object_new_string(buf));
  331. sprintf(buf, "%d", videoList[idx].layout_y);
  332. json_object_object_add(imageview, "layout_y", json_object_new_string(buf));
  333. sprintf(buf, "%d", videoList[idx].width);
  334. json_object_object_add(imageview, "width", json_object_new_string(buf));
  335. sprintf(buf, "%d", videoList[idx].height);
  336. json_object_object_add(imageview, "height", json_object_new_string(buf));
  337. sprintf(buf, "%d", videoList[idx].replay);
  338. json_object_object_add(imageview, "replay", json_object_new_string(buf));
  339. json_object_array_add(payload, imageview);
  340. }
  341. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  342. json_object_put(payload);
  343. return publish_data(mosq, "client/layout/videoview", outputStr);
  344. }
  345. /**
  346. *
  347. * @param mosq
  348. */
  349. int publish_qrcodeimage_add(struct mosquitto *mosq, QrCode_List *qrCodeList, uint8_t listCount)
  350. {
  351. json_object *payload = json_object_new_array();
  352. char outputStr[2048]={0};
  353. for(int idx=0;idx<listCount;idx++)
  354. {
  355. if (qrCodeList[idx].qrCodeIndex == 0 || qrCodeList[idx].qrCodeIndex >= 9999) {
  356. continue;
  357. }
  358. json_object *qrcodeImage = json_object_new_object();
  359. char buf[32];
  360. sprintf(buf, "%d", qrCodeList[idx].qrCodeIndex);
  361. json_object_object_add(qrcodeImage, "qrCodeIndex", json_object_new_string(buf));
  362. sprintf(buf, "%s", qrCodeList[idx].qrCodeContent);
  363. json_object_object_add(qrcodeImage, "qrCodeContent", json_object_new_string(buf));
  364. sprintf(buf, "%s", qrCodeList[idx].errorCorrection);
  365. json_object_object_add(qrcodeImage, "errorCorrection", json_object_new_string(buf));
  366. sprintf(buf, "%d", qrCodeList[idx].layout_x);
  367. json_object_object_add(qrcodeImage, "layout_x", json_object_new_string(buf));
  368. sprintf(buf, "%d", qrCodeList[idx].layout_y);
  369. json_object_object_add(qrcodeImage, "layout_y", json_object_new_string(buf));
  370. sprintf(buf, "%d", qrCodeList[idx].width);
  371. json_object_object_add(qrcodeImage, "width", json_object_new_string(buf));
  372. sprintf(buf, "%d", qrCodeList[idx].height);
  373. json_object_object_add(qrcodeImage, "height", json_object_new_string(buf));
  374. json_object_array_add(payload, qrcodeImage);
  375. }
  376. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  377. json_object_put(payload);
  378. return publish_data(mosq, "client/layout/qrcodeview", outputStr);
  379. }
  380. /**
  381. *
  382. * @param mosq
  383. */
  384. int publish_view_remove(struct mosquitto *mosq, Text_List *textList, uint8_t textListCount,
  385. Image_List *imageList, uint8_t imageListCount,
  386. Video_List *videoList, uint8_t videoListCount,
  387. QrCode_List *qrCodeList, uint8_t qrCodeListCount)
  388. {
  389. json_object *payload = json_object_new_object();
  390. json_object *text = json_object_new_array();
  391. json_object *image = json_object_new_array();
  392. json_object *video = json_object_new_array();
  393. json_object *qrCode = json_object_new_array();
  394. char outputStr[2048]={0};
  395. // Remove text view
  396. for(int idx=0;idx<textListCount;idx++)
  397. {
  398. if (textList[idx].textviewIndex == 0 ) {
  399. continue;
  400. }
  401. json_object *textview = json_object_new_object();
  402. char buf[8];
  403. sprintf(buf, "%d", textList[idx].textviewIndex);
  404. json_object_object_add(textview, "textviewIndex", json_object_new_string(buf));
  405. json_object_array_add(text, textview);
  406. }
  407. json_object_object_add(payload, "rm_textview_list", text);
  408. // Remove image view
  409. for(int idx=0;idx<imageListCount;idx++)
  410. {
  411. if (imageList[idx].imageviewIndex == 0) {
  412. continue;
  413. }
  414. json_object *imageview = json_object_new_object();
  415. char buf[8];
  416. sprintf(buf, "%d", imageList[idx].imageviewIndex);
  417. json_object_object_add(imageview, "imageviewIndex", json_object_new_string(buf));
  418. json_object_array_add(image, imageview);
  419. }
  420. json_object_object_add(payload, "rm_imageview_list", image);
  421. // Remove video view
  422. for(int idx=0;idx<videoListCount;idx++)
  423. {
  424. if (videoList[idx].videoviewIndex == 0) {
  425. continue;
  426. }
  427. json_object *videoview = json_object_new_object();
  428. char buf[8];
  429. sprintf(buf, "%d", videoList[idx].videoviewIndex);
  430. json_object_object_add(videoview, "videoviewIndex", json_object_new_string(buf));
  431. json_object_array_add(video, videoview);
  432. }
  433. json_object_object_add(payload, "rm_videoview_list", video);
  434. // Remove qrCode view
  435. for(int idx=0;idx<qrCodeListCount;idx++)
  436. {
  437. if (qrCodeList[idx].qrCodeIndex == 0 ) {
  438. continue;
  439. }
  440. json_object *qrCodeview = json_object_new_object();
  441. char buf[8];
  442. sprintf(buf, "%d", qrCodeList[idx].qrCodeIndex);
  443. json_object_object_add(qrCodeview, "qrCodeIndex", json_object_new_string(buf));
  444. json_object_array_add(qrCode, qrCodeview);
  445. }
  446. json_object_object_add(payload, "rm_qrcode_list", qrCode);
  447. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  448. json_object_put(payload);
  449. return publish_data(mosq, "client/layout/remove", outputStr);
  450. }
  451. /**
  452. *
  453. * @param mosq
  454. */
  455. int publish_clear_screen(struct mosquitto *mosq)
  456. {
  457. json_object *payload = json_object_new_object();
  458. char outputStr[2048]={0};
  459. json_object_object_add(payload, "task_name", json_object_new_string("clear_screen"));
  460. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  461. json_object_put(payload);
  462. return publish_data(mosq, "client/command", outputStr);
  463. }
  464. /**
  465. *
  466. * @param mosq
  467. */
  468. int publish_Trigger_line_scan(struct mosquitto *mosq)
  469. {
  470. json_object *payload = json_object_new_object();
  471. char outputStr[2048]={0};
  472. json_object_object_add(payload, "task_name", json_object_new_string("line_scan"));
  473. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  474. json_object_put(payload);
  475. return publish_data(mosq, "client/command", outputStr);
  476. }
  477. /**
  478. *
  479. * @param mosq
  480. */
  481. int publish_show_Page(struct mosquitto *mosq,uint8_t page)
  482. {
  483. json_object *payload = json_object_new_object();
  484. char outputStr[2048]={0};
  485. char buf[32];
  486. sprintf(buf, "%d", page);
  487. json_object_object_add(payload, "PageIndex", json_object_new_string(buf));
  488. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  489. json_object_put(payload);
  490. return publish_data(mosq,"client/page", outputStr);
  491. }
  492. ///////////////////////////////////////////////////////////////
  493. // 儲存各頁面資訊
  494. ///////////////////////////////////////////////////////////////
  495. int publish_textview_store(struct mosquitto* mosq,uint8_t page)
  496. {
  497. json_object *payload = json_object_new_array();
  498. int listCount = TextIndex;
  499. char outputStr[250*100]={0};
  500. char buf[32];
  501. if (listCount <= 0 )
  502. return FAIL;
  503. json_object *pageView = json_object_new_object();
  504. sprintf(buf, "%d", page);
  505. json_object_object_add(pageView, "PageIndex", json_object_new_string(buf));
  506. json_object_array_add(payload, pageView);
  507. for(int idx=0;idx<listCount;idx++)
  508. {
  509. if (TextList[idx].textviewIndex == 0 || TextList[idx].textviewIndex >= 9999) {
  510. continue;
  511. }
  512. json_object *textview = json_object_new_object();
  513. sprintf(buf, "%d", TextList[idx].textviewIndex);
  514. json_object_object_add(textview, "textviewIndex", json_object_new_string(buf));
  515. json_object_object_add(textview, "textString", json_object_new_string(TextList[idx].textString));
  516. json_object_object_add(textview, "textFont", json_object_new_string(TextList[idx].textFont));
  517. json_object_object_add(textview, "textStyle", json_object_new_string(TextList[idx].textStyle));
  518. sprintf(buf, "%d", TextList[idx].textSize);
  519. json_object_object_add(textview, "textSize", json_object_new_string(buf));
  520. sprintf(buf, "%d", TextList[idx].layout_x);
  521. json_object_object_add(textview, "layout_x", json_object_new_string(buf));
  522. sprintf(buf, "%d", TextList[idx].layout_y);
  523. json_object_object_add(textview, "layout_y", json_object_new_string(buf));
  524. sprintf(buf, "%d", TextList[idx].width);
  525. json_object_object_add(textview, "width", json_object_new_string(buf));
  526. sprintf(buf, "%d", TextList[idx].color_r);
  527. json_object_object_add(textview, "color_r", json_object_new_string(buf));
  528. sprintf(buf, "%d", TextList[idx].color_g);
  529. json_object_object_add(textview, "color_g", json_object_new_string(buf));
  530. sprintf(buf, "%d", TextList[idx].color_b);
  531. json_object_object_add(textview, "color_b", json_object_new_string(buf));
  532. sprintf(buf, "%d", TextList[idx].alignment);
  533. json_object_object_add(textview, "alignment", json_object_new_string(buf));
  534. json_object_array_add(payload, textview);
  535. }
  536. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  537. json_object_put(payload);
  538. return publish_data(mosq, "client/page/storetext", outputStr);
  539. }
  540. /**
  541. *
  542. * @param mosq
  543. */
  544. int publish_textscroll_store(struct mosquitto* mosq,uint8_t page)
  545. {
  546. json_object *payload = json_object_new_array();
  547. char outputStr[250*100]={0};
  548. char buf[32];
  549. int listCount = TextScrollIndex;
  550. if (listCount <= 0 )
  551. return FAIL;
  552. json_object *pageView = json_object_new_object();
  553. sprintf(buf, "%d", page);
  554. json_object_object_add(pageView, "PageIndex", json_object_new_string(buf));
  555. json_object_array_add(payload, pageView);
  556. for(int idx=0;idx<listCount;idx++)
  557. {
  558. if (TextScrollList[idx].textscrollIndex == 0 || TextScrollList[idx].textscrollIndex >= 9999) {
  559. continue;
  560. }
  561. json_object *textscroll = json_object_new_object();
  562. sprintf(buf, "%d", TextScrollList[idx].textscrollIndex);
  563. json_object_object_add(textscroll, "textscrollIndex", json_object_new_string(buf));
  564. json_object_object_add(textscroll, "textString", json_object_new_string(TextScrollList[idx].textString));
  565. json_object_object_add(textscroll, "textFont", json_object_new_string(TextScrollList[idx].textFont));
  566. json_object_object_add(textscroll, "textStyle", json_object_new_string(TextScrollList[idx].textStyle));
  567. sprintf(buf, "%d", TextScrollList[idx].textSize);
  568. json_object_object_add(textscroll, "textSize", json_object_new_string(buf));
  569. sprintf(buf, "%d", TextScrollList[idx].layout_x);
  570. json_object_object_add(textscroll, "layout_x", json_object_new_string(buf));
  571. sprintf(buf, "%d", TextScrollList[idx].layout_y);
  572. json_object_object_add(textscroll, "layout_y", json_object_new_string(buf));
  573. sprintf(buf, "%d", TextScrollList[idx].width);
  574. json_object_object_add(textscroll, "width", json_object_new_string(buf));
  575. sprintf(buf, "%d", TextScrollList[idx].color_r);
  576. json_object_object_add(textscroll, "color_r", json_object_new_string(buf));
  577. sprintf(buf, "%d", TextScrollList[idx].color_g);
  578. json_object_object_add(textscroll, "color_g", json_object_new_string(buf));
  579. sprintf(buf, "%d", TextScrollList[idx].color_b);
  580. json_object_object_add(textscroll, "color_b", json_object_new_string(buf));
  581. sprintf(buf, "%d", TextScrollList[idx].direction);
  582. json_object_object_add(textscroll, "direction", json_object_new_string(buf));
  583. json_object_array_add(payload, textscroll);
  584. }
  585. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  586. json_object_put(payload);
  587. return publish_data(mosq, "client/page/storetextscroll", outputStr);
  588. }
  589. /**
  590. *
  591. * @param mosq
  592. */
  593. int publish_imageview_store(struct mosquitto *mosq,uint8_t page)
  594. {
  595. json_object *payload = json_object_new_array();
  596. char outputStr[250*100]={0};
  597. char buf[32];
  598. int listCount = ImageIndex;
  599. if (listCount <= 0 )
  600. return FAIL;
  601. json_object *pageView = json_object_new_object();
  602. sprintf(buf, "%d", page);
  603. json_object_object_add(pageView, "PageIndex", json_object_new_string(buf));
  604. json_object_array_add(payload, pageView);
  605. for(int idx=0;idx<listCount;idx++)
  606. {
  607. if (ImageList[idx].imageviewIndex == 0 || ImageList[idx].imageviewIndex >= 9999) {
  608. continue;
  609. }
  610. json_object *imageview = json_object_new_object();
  611. sprintf(buf, "%d", ImageList[idx].imageviewIndex);
  612. json_object_object_add(imageview, "imageviewIndex", json_object_new_string(buf));
  613. sprintf(buf, "%d", ImageList[idx].imgsrc_addr);
  614. json_object_object_add(imageview, "imgsrc_addr", json_object_new_string(buf));
  615. sprintf(buf, "%d", ImageList[idx].layout_x);
  616. json_object_object_add(imageview, "layout_x", json_object_new_string(buf));
  617. sprintf(buf, "%d", ImageList[idx].layout_y);
  618. json_object_object_add(imageview, "layout_y", json_object_new_string(buf));
  619. sprintf(buf, "%d", ImageList[idx].width);
  620. json_object_object_add(imageview, "width", json_object_new_string(buf));
  621. sprintf(buf, "%d", ImageList[idx].height);
  622. json_object_object_add(imageview, "height", json_object_new_string(buf));
  623. json_object_array_add(payload, imageview);
  624. }
  625. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  626. json_object_put(payload);
  627. return publish_data(mosq, "client/page/storeimg", outputStr);
  628. }
  629. /**
  630. *
  631. * @param mosq
  632. */
  633. int publish_apngview_store(struct mosquitto *mosq,uint8_t page)
  634. {
  635. json_object *payload = json_object_new_array();
  636. char outputStr[250*100]={0};
  637. char buf[32];
  638. int listCount = ApngIndex;
  639. if (listCount <= 0 )
  640. return FAIL;
  641. json_object *pageView = json_object_new_object();
  642. sprintf(buf, "%d", page);
  643. json_object_object_add(pageView, "PageIndex", json_object_new_string(buf));
  644. json_object_array_add(payload, pageView);
  645. for(int idx=0;idx<listCount;idx++)
  646. {
  647. if (ApngList[idx].apngIndex == 0 || ApngList[idx].apngIndex >= 9999) {
  648. continue;
  649. }
  650. json_object *apngview = json_object_new_object();
  651. sprintf(buf, "%d", ApngList[idx].apngIndex);
  652. json_object_object_add(apngview, "apngIndex", json_object_new_string(buf));
  653. sprintf(buf, "%d", ApngList[idx].apngsrc_addr);
  654. json_object_object_add(apngview, "apngsrc_addr", json_object_new_string(buf));
  655. sprintf(buf, "%d", ApngList[idx].layout_x);
  656. json_object_object_add(apngview, "layout_x", json_object_new_string(buf));
  657. sprintf(buf, "%d", ApngList[idx].layout_y);
  658. json_object_object_add(apngview, "layout_y", json_object_new_string(buf));
  659. sprintf(buf, "%d", ApngList[idx].width);
  660. json_object_object_add(apngview, "width", json_object_new_string(buf));
  661. sprintf(buf, "%d", ApngList[idx].height);
  662. json_object_object_add(apngview, "height", json_object_new_string(buf));
  663. sprintf(buf, "%d", ApngList[idx].loop);
  664. json_object_object_add(apngview, "loop", json_object_new_string(buf));
  665. json_object_array_add(payload, apngview);
  666. }
  667. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  668. json_object_put(payload);
  669. return publish_data(mosq, "client/page/apngview", outputStr);
  670. }
  671. ////////////////////////////////////////////////////////////////////////////
  672. int publish_textview_push(Text_List* textList, uint8_t listCount)
  673. {
  674. int cmpIndex = 0;
  675. for(int idx=0;idx<listCount;idx++)
  676. {
  677. if (TextIndex >= 100) {
  678. DEBUG_INFO("OVER TEXT LIST BUFFER SIZE");
  679. break;
  680. }
  681. if (TextIndex < 100) {
  682. for (cmpIndex = 0; cmpIndex < TextIndex; cmpIndex++) {
  683. if (TextList[cmpIndex].textviewIndex == textList[idx].textviewIndex)
  684. break;
  685. }
  686. if (TextList[cmpIndex].textviewIndex != textList[idx].textviewIndex) {
  687. memcpy(&TextList[TextIndex],&textList[idx],sizeof(Text_List));
  688. //DEBUG_INFO("Push TextIndex[%d] into Buffer(%d)",textList[idx].textviewIndex,TextIndex);
  689. TextIndex++;
  690. }
  691. }
  692. }
  693. return TextIndex;
  694. }
  695. int publish_textscroll_push(TextScroll_List* textList, uint8_t listCount)
  696. {
  697. int cmpIndex = 0;
  698. for(int idx=0;idx<listCount;idx++)
  699. {
  700. if (TextScrollIndex >= 100) {
  701. DEBUG_INFO("OVER TEXT LIST BUFFER SIZE");
  702. break;
  703. }
  704. if (TextScrollIndex < 100) {
  705. for (cmpIndex = 0; cmpIndex < TextScrollIndex; cmpIndex++) {
  706. if (TextScrollList[cmpIndex].textscrollIndex == textList[idx].textscrollIndex)
  707. break;
  708. }
  709. if (TextScrollList[cmpIndex].textscrollIndex != textList[idx].textscrollIndex) {
  710. memcpy(&TextScrollList[TextScrollIndex],&textList[idx],sizeof(TextScroll_List));
  711. //DEBUG_INFO("Push TextScrollIndex[%d] into Buffer(%d)",TextScrollList[idx].textscrollIndex,TextScrollIndex);
  712. TextScrollIndex++;
  713. }
  714. }
  715. }
  716. return TextScrollIndex;
  717. }
  718. int publish_imageview_push(Image_List *imageList, uint8_t listCount)
  719. {
  720. int cmpIndex = 0;
  721. for(int idx=0;idx<listCount;idx++)
  722. {
  723. if (ImageIndex >= 100) {
  724. DEBUG_INFO("OVER TEXT LIST BUFFER SIZE");
  725. break;
  726. }
  727. for (cmpIndex = 0; cmpIndex < ImageIndex; cmpIndex++) {
  728. if (ImageList[cmpIndex].imageviewIndex == imageList[idx].imageviewIndex)
  729. break;
  730. }
  731. if (ImageList[cmpIndex].imageviewIndex != imageList[idx].imageviewIndex) {
  732. memcpy(&ImageList[ImageIndex],&imageList[idx],sizeof(Image_List));
  733. //DEBUG_INFO("Push ImageIndex[%d] into Buffer(%d)",imageList[idx].imageviewIndex,ImageIndex);
  734. ImageIndex++;
  735. }
  736. }
  737. return ImageIndex;
  738. }
  739. int publish_apngview_push( APNG_List *apngList, uint8_t listCount)
  740. {
  741. int cmpIndex = 0;
  742. for(int idx=0;idx<listCount;idx++)
  743. {
  744. if (ApngIndex >= 5) {
  745. DEBUG_INFO("OVER APNG LIST BUFFER SIZE");
  746. break;
  747. }
  748. for (cmpIndex = 0; cmpIndex < listCount; cmpIndex++) {
  749. if (ApngList[cmpIndex].apngIndex == apngList[idx].apngIndex)
  750. break;
  751. }
  752. if (ApngList[cmpIndex].apngIndex != apngList[idx].apngIndex) {
  753. memcpy(&ApngList[ApngIndex],&apngList[idx],sizeof(APNG_List));
  754. //DEBUG_INFO("Push ApngIndex[%d] into Buffer(%d)",apngList[idx].apngIndex,ApngIndex);
  755. ApngIndex++;
  756. }
  757. }
  758. return ApngIndex;
  759. }
  760. void clearPushBuffer()
  761. {
  762. memset(TextList, 0, sizeof(TextList));
  763. memset(ImageList, 0, sizeof(ImageList));
  764. memset(ApngList, 0, sizeof(ApngList));
  765. memset(QRCodeList, 0, sizeof(QRCodeList));
  766. memset(TextScrollList, 0, sizeof(TextScrollList));
  767. TextIndex = 0;
  768. ImageIndex = 0;
  769. QRCodeIndex = 0;
  770. TextScrollIndex = 0;
  771. ApngIndex = 0;
  772. }
  773. void PushPageInfoToLcm(struct mosquitto *mosq,int page)
  774. {
  775. //DEBUG_INFO("Push Page%d to LCM",page);
  776. publish_textview_store(mosq,page);
  777. publish_textscroll_store(mosq,page);
  778. publish_imageview_store(mosq,page);
  779. publish_apngview_store(mosq,page);
  780. clearPushBuffer();
  781. }
  782. int publish_apng_remove(struct mosquitto *mosq, APNG_List *apngList, uint8_t apngListCount)
  783. {
  784. json_object *payload = json_object_new_object();
  785. json_object *image = json_object_new_array();
  786. char outputStr[2048]={0};
  787. // Remove image view
  788. for(int idx=0;idx<apngListCount;idx++)
  789. {
  790. if (apngList[idx].apngIndex == 0) {
  791. continue;
  792. }
  793. json_object *imageview = json_object_new_object();
  794. char buf[8];
  795. sprintf(buf, "%d", apngList[idx].apngIndex);
  796. json_object_object_add(imageview, "ApngIndex", json_object_new_string(buf));
  797. json_object_array_add(image, imageview);
  798. }
  799. json_object_object_add(payload, "rm_APNG_list", image);
  800. sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
  801. json_object_put(payload);
  802. return publish_data(mosq, "client/layout/remove", outputStr);
  803. }