123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029 |
- /*
- * LcmCommandDriver.c
- *
- * Created on: 2022/3/31
- * Author: folus
- */
- #include "Module_LcmControl_Wistron.h"
- #include "../Config.h"
- Text_List TextList[100];
- int TextIndex = 0;
- Image_List ImageList[100];
- int ImageIndex = 0;
- APNG_List ApngList[5];
- int ApngIndex = 0;
- QrCode_List QRCodeList[5];
- int QRCodeIndex = 0;
- TextScroll_List TextScrollList[5];
- int TextScrollIndex = 0;
- /**
- *
- * @param mosq
- * @param topic
- * @param outputStr
- * @return
- */
- int publish_data(struct mosquitto *mosq, char *topic, char *outputStr)
- {
- int result;
- result = mosquitto_publish(mosq, NULL, topic, strlen(outputStr), outputStr, QOS_ENSURE_BROKER, RETAIN_NO);
- if(result != MOSQ_ERR_SUCCESS)DEBUG_ERROR("Publish %s error publishing: %s\n", topic, mosquitto_strerror(result));
- return (result != MOSQ_ERR_SUCCESS)?FAIL:PASS;
- }
- /**
- *
- * @param mosq
- */
- int publish_profile(struct mosquitto *mosq, char *parameter, char *value)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- json_object_object_add(payload, parameter, json_object_new_string(value));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/profile", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_upgrade(struct mosquitto *mosq, char *otaType, char *url, char *checksum, char *verInfo)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- json_object_object_add(payload, "task_name", json_object_new_string(otaType));
- if((strstr(otaType, OTA_TYPE_APK) != NULL) || (strstr(otaType, OTA_TYPE_UI) != NULL))
- json_object_object_add(payload, "ftp server", json_object_new_string(url));
- if(strstr(otaType, OTA_TYPE_UI) != NULL)
- {
- json_object_object_add(payload, "file_checksum", json_object_new_string(checksum));
- json_object_object_add(payload, "version_info", json_object_new_string(verInfo));
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/command", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_restart(struct mosquitto *mosq, uint8_t isHardReset)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- json_object_object_add(payload, "task_name", json_object_new_string(isHardReset?"restart":"reset"));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/command", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_power_saving(struct mosquitto *mosq, uint8_t isSleep,char* mac)
- {
- if(isSleep)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- json_object_object_add(payload, "task_name", json_object_new_string("power_saving"));
- json_object_object_add(payload, "mode", json_object_new_string(isSleep?"1":"0"));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/command", outputStr);
- }
- else
- {
- char cmd[64];
- sprintf(cmd, "/usr/sbin/ether-wake -i eth1 %s\n",mac);
- system(cmd);
- DEBUG_INFO("MAC:%s\n", mac);
- return PASS;
- }
- }
- /**
- *
- * @param mosq
- */
- int publish_back_dimming(struct mosquitto *mosq, uint8_t lightLevel)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- char buf[8];
- json_object_object_add(payload, "task_name", json_object_new_string("backlight"));
- sprintf(buf, "%d", lightLevel);
- json_object_object_add(payload, "brightness", json_object_new_string(buf));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/command", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_audio_volume(struct mosquitto *mosq, uint8_t volume)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- char buf[8];
- json_object_object_add(payload, "task_name", json_object_new_string("audio_volume"));
- sprintf(buf, "%d", volume);
- json_object_object_add(payload, "volume", json_object_new_string(buf));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/command", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_trigger_report_status(struct mosquitto *mosq)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- json_object_object_add(payload, "task_name", json_object_new_string("report_status"));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/command", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_timesync(struct mosquitto *mosq)
- {
- char outputStr[64]={0};
- time_t CurrentTime;
- struct tm *tm;
- struct timeval tv;
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- gettimeofday(&tv, NULL); // get microseconds, 10^-6
- 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);
- return publish_data(mosq, "client/timesync", outputStr);
- }
- int publish_textview_add(struct mosquitto* mosq, Text_List* textList, uint8_t listCount)
- {
- json_object *payload = json_object_new_array();
- char outputStr[250*100]={0};
- for(int idx=0;idx<listCount;idx++)
- {
- if (textList[idx].textviewIndex == 0 || textList[idx].textviewIndex >= 9999) {
- continue;
- }
- json_object *textview = json_object_new_object();
- char buf[32];
- sprintf(buf, "%d", textList[idx].textviewIndex);
- json_object_object_add(textview, "textviewIndex", json_object_new_string(buf));
- json_object_object_add(textview, "textString", json_object_new_string(textList[idx].textString));
- json_object_object_add(textview, "textFont", json_object_new_string(textList[idx].textFont));
- json_object_object_add(textview, "textStyle", json_object_new_string(textList[idx].textStyle));
- sprintf(buf, "%d", textList[idx].textSize);
- json_object_object_add(textview, "textSize", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].layout_x);
- json_object_object_add(textview, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].layout_y);
- json_object_object_add(textview, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].width);
- json_object_object_add(textview, "width", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].color_r);
- json_object_object_add(textview, "color_r", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].color_g);
- json_object_object_add(textview, "color_g", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].color_b);
- json_object_object_add(textview, "color_b", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].alignment);
- json_object_object_add(textview, "alignment", json_object_new_string(buf));
- json_object_array_add(payload, textview);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/textview", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_textscroll_add(struct mosquitto* mosq, TextScroll_List* textList, uint8_t listCount)
- {
- json_object *payload = json_object_new_array();
- char outputStr[250*100]={0};
- for(int idx=0;idx<listCount;idx++)
- {
- if (textList[idx].textscrollIndex == 0 || textList[idx].textscrollIndex >= 9999) {
- continue;
- }
- json_object *textscroll = json_object_new_object();
- char buf[32];
- sprintf(buf, "%d", textList[idx].textscrollIndex);
- json_object_object_add(textscroll, "textscrollIndex", json_object_new_string(buf));
- json_object_object_add(textscroll, "textString", json_object_new_string(textList[idx].textString));
- json_object_object_add(textscroll, "textFont", json_object_new_string(textList[idx].textFont));
- json_object_object_add(textscroll, "textStyle", json_object_new_string(textList[idx].textStyle));
- sprintf(buf, "%d", textList[idx].textSize);
- json_object_object_add(textscroll, "textSize", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].layout_x);
- json_object_object_add(textscroll, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].layout_y);
- json_object_object_add(textscroll, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].width);
- json_object_object_add(textscroll, "width", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].color_r);
- json_object_object_add(textscroll, "color_r", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].color_g);
- json_object_object_add(textscroll, "color_g", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].color_b);
- json_object_object_add(textscroll, "color_b", json_object_new_string(buf));
- sprintf(buf, "%d", textList[idx].direction);
- json_object_object_add(textscroll, "direction", json_object_new_string(buf));
- json_object_array_add(payload, textscroll);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/textscroll", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_imageview_add(struct mosquitto *mosq, Image_List *imageList, uint8_t listCount)
- {
- json_object *payload = json_object_new_array();
- char outputStr[250*100]={0};
- for(int idx=0;idx<listCount;idx++)
- {
- if (imageList[idx].imageviewIndex == 0 || imageList[idx].imageviewIndex >= 9999) {
- continue;
- }
- json_object *imageview = json_object_new_object();
- char buf[32];
- sprintf(buf, "%d", imageList[idx].imageviewIndex);
- json_object_object_add(imageview, "imageviewIndex", json_object_new_string(buf));
- sprintf(buf, "%d", imageList[idx].imgsrc_addr);
- json_object_object_add(imageview, "imgsrc_addr", json_object_new_string(buf));
- sprintf(buf, "%d", imageList[idx].layout_x);
- json_object_object_add(imageview, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", imageList[idx].layout_y);
- json_object_object_add(imageview, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", imageList[idx].width);
- json_object_object_add(imageview, "width", json_object_new_string(buf));
- sprintf(buf, "%d", imageList[idx].height);
- json_object_object_add(imageview, "height", json_object_new_string(buf));
- json_object_array_add(payload, imageview);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/imageview", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_apngview_add(struct mosquitto *mosq, APNG_List *apngList, uint8_t listCount)
- {
- json_object *payload = json_object_new_array();
- char outputStr[250*100]={0};
- for(int idx=0;idx<listCount;idx++)
- {
- if (apngList[idx].apngIndex == 0 || apngList[idx].apngIndex >= 9999) {
- continue;
- }
- json_object *apngview = json_object_new_object();
- char buf[32];
- sprintf(buf, "%d", apngList[idx].apngIndex);
- json_object_object_add(apngview, "apngIndex", json_object_new_string(buf));
- sprintf(buf, "%d", apngList[idx].apngsrc_addr);
- json_object_object_add(apngview, "apngsrc_addr", json_object_new_string(buf));
- sprintf(buf, "%d", apngList[idx].layout_x);
- json_object_object_add(apngview, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", apngList[idx].layout_y);
- json_object_object_add(apngview, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", apngList[idx].width);
- json_object_object_add(apngview, "width", json_object_new_string(buf));
- sprintf(buf, "%d", apngList[idx].height);
- json_object_object_add(apngview, "height", json_object_new_string(buf));
- sprintf(buf, "%d", apngList[idx].loop);
- json_object_object_add(apngview, "loop", json_object_new_string(buf));
- json_object_array_add(payload, apngview);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/apngview", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_videoview_add(struct mosquitto *mosq, Video_List *videoList, uint8_t listCount)
- {
- json_object *payload = json_object_new_array();
- char outputStr[2048]={0};
- for(int idx=0;idx<listCount;idx++)
- {
- json_object *imageview = json_object_new_object();
- char buf[32];
- sprintf(buf, "%d", videoList[idx].videoviewIndex);
- json_object_object_add(imageview, "videoviewIndex", json_object_new_string(buf));
- sprintf(buf, "%d", videoList[idx].videosrc_addr);
- json_object_object_add(imageview, "videoSrc_addr", json_object_new_string(buf));
- sprintf(buf, "%d", videoList[idx].layout_x);
- json_object_object_add(imageview, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", videoList[idx].layout_y);
- json_object_object_add(imageview, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", videoList[idx].width);
- json_object_object_add(imageview, "width", json_object_new_string(buf));
- sprintf(buf, "%d", videoList[idx].height);
- json_object_object_add(imageview, "height", json_object_new_string(buf));
- sprintf(buf, "%d", videoList[idx].replay);
- json_object_object_add(imageview, "replay", json_object_new_string(buf));
- json_object_array_add(payload, imageview);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/videoview", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_qrcodeimage_add(struct mosquitto *mosq, QrCode_List *qrCodeList, uint8_t listCount)
- {
- json_object *payload = json_object_new_array();
- char outputStr[2048]={0};
- for(int idx=0;idx<listCount;idx++)
- {
- if (qrCodeList[idx].qrCodeIndex == 0 || qrCodeList[idx].qrCodeIndex >= 9999) {
- continue;
- }
- json_object *qrcodeImage = json_object_new_object();
- char buf[32];
- sprintf(buf, "%d", qrCodeList[idx].qrCodeIndex);
- json_object_object_add(qrcodeImage, "qrCodeIndex", json_object_new_string(buf));
- sprintf(buf, "%s", qrCodeList[idx].qrCodeContent);
- json_object_object_add(qrcodeImage, "qrCodeContent", json_object_new_string(buf));
- sprintf(buf, "%s", qrCodeList[idx].errorCorrection);
- json_object_object_add(qrcodeImage, "errorCorrection", json_object_new_string(buf));
- sprintf(buf, "%d", qrCodeList[idx].layout_x);
- json_object_object_add(qrcodeImage, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", qrCodeList[idx].layout_y);
- json_object_object_add(qrcodeImage, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", qrCodeList[idx].width);
- json_object_object_add(qrcodeImage, "width", json_object_new_string(buf));
- sprintf(buf, "%d", qrCodeList[idx].height);
- json_object_object_add(qrcodeImage, "height", json_object_new_string(buf));
- json_object_array_add(payload, qrcodeImage);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/qrcodeview", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_view_remove(struct mosquitto *mosq, Text_List *textList, uint8_t textListCount,
- Image_List *imageList, uint8_t imageListCount,
- Video_List *videoList, uint8_t videoListCount,
- QrCode_List *qrCodeList, uint8_t qrCodeListCount)
- {
- json_object *payload = json_object_new_object();
- json_object *text = json_object_new_array();
- json_object *image = json_object_new_array();
- json_object *video = json_object_new_array();
- json_object *qrCode = json_object_new_array();
- char outputStr[2048]={0};
- // Remove text view
- for(int idx=0;idx<textListCount;idx++)
- {
- if (textList[idx].textviewIndex == 0 ) {
- continue;
- }
- json_object *textview = json_object_new_object();
- char buf[8];
- sprintf(buf, "%d", textList[idx].textviewIndex);
- json_object_object_add(textview, "textviewIndex", json_object_new_string(buf));
- json_object_array_add(text, textview);
- }
- json_object_object_add(payload, "rm_textview_list", text);
- // Remove image view
- for(int idx=0;idx<imageListCount;idx++)
- {
- if (imageList[idx].imageviewIndex == 0) {
- continue;
- }
- json_object *imageview = json_object_new_object();
- char buf[8];
- sprintf(buf, "%d", imageList[idx].imageviewIndex);
- json_object_object_add(imageview, "imageviewIndex", json_object_new_string(buf));
- json_object_array_add(image, imageview);
- }
- json_object_object_add(payload, "rm_imageview_list", image);
- // Remove video view
- for(int idx=0;idx<videoListCount;idx++)
- {
- if (videoList[idx].videoviewIndex == 0) {
- continue;
- }
- json_object *videoview = json_object_new_object();
- char buf[8];
- sprintf(buf, "%d", videoList[idx].videoviewIndex);
- json_object_object_add(videoview, "videoviewIndex", json_object_new_string(buf));
- json_object_array_add(video, videoview);
- }
- json_object_object_add(payload, "rm_videoview_list", video);
- // Remove qrCode view
- for(int idx=0;idx<qrCodeListCount;idx++)
- {
- if (qrCodeList[idx].qrCodeIndex == 0 ) {
- continue;
- }
- json_object *qrCodeview = json_object_new_object();
- char buf[8];
- sprintf(buf, "%d", qrCodeList[idx].qrCodeIndex);
- json_object_object_add(qrCodeview, "qrCodeIndex", json_object_new_string(buf));
- json_object_array_add(qrCode, qrCodeview);
- }
- json_object_object_add(payload, "rm_qrcode_list", qrCode);
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/remove", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_clear_screen(struct mosquitto *mosq)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- json_object_object_add(payload, "task_name", json_object_new_string("clear_screen"));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/command", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_Trigger_line_scan(struct mosquitto *mosq)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- json_object_object_add(payload, "task_name", json_object_new_string("line_scan"));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/command", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_show_Page(struct mosquitto *mosq,uint8_t page)
- {
- json_object *payload = json_object_new_object();
- char outputStr[2048]={0};
- char buf[32];
- sprintf(buf, "%d", page);
- json_object_object_add(payload, "PageIndex", json_object_new_string(buf));
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq,"client/page", outputStr);
- }
- ///////////////////////////////////////////////////////////////
- // 儲存各頁面資訊
- ///////////////////////////////////////////////////////////////
- int publish_textview_store(struct mosquitto* mosq,uint8_t page)
- {
- json_object *payload = json_object_new_array();
- int listCount = TextIndex;
- char outputStr[250*100]={0};
- char buf[32];
- if (listCount <= 0 )
- return FAIL;
- json_object *pageView = json_object_new_object();
- sprintf(buf, "%d", page);
- json_object_object_add(pageView, "PageIndex", json_object_new_string(buf));
- json_object_array_add(payload, pageView);
- for(int idx=0;idx<listCount;idx++)
- {
- if (TextList[idx].textviewIndex == 0 || TextList[idx].textviewIndex >= 9999) {
- continue;
- }
- json_object *textview = json_object_new_object();
- sprintf(buf, "%d", TextList[idx].textviewIndex);
- json_object_object_add(textview, "textviewIndex", json_object_new_string(buf));
- json_object_object_add(textview, "textString", json_object_new_string(TextList[idx].textString));
- json_object_object_add(textview, "textFont", json_object_new_string(TextList[idx].textFont));
- json_object_object_add(textview, "textStyle", json_object_new_string(TextList[idx].textStyle));
- sprintf(buf, "%d", TextList[idx].textSize);
- json_object_object_add(textview, "textSize", json_object_new_string(buf));
- sprintf(buf, "%d", TextList[idx].layout_x);
- json_object_object_add(textview, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", TextList[idx].layout_y);
- json_object_object_add(textview, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", TextList[idx].width);
- json_object_object_add(textview, "width", json_object_new_string(buf));
- sprintf(buf, "%d", TextList[idx].color_r);
- json_object_object_add(textview, "color_r", json_object_new_string(buf));
- sprintf(buf, "%d", TextList[idx].color_g);
- json_object_object_add(textview, "color_g", json_object_new_string(buf));
- sprintf(buf, "%d", TextList[idx].color_b);
- json_object_object_add(textview, "color_b", json_object_new_string(buf));
- sprintf(buf, "%d", TextList[idx].alignment);
- json_object_object_add(textview, "alignment", json_object_new_string(buf));
- json_object_array_add(payload, textview);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/page/storetext", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_textscroll_store(struct mosquitto* mosq,uint8_t page)
- {
- json_object *payload = json_object_new_array();
- char outputStr[250*100]={0};
- char buf[32];
- int listCount = TextScrollIndex;
- if (listCount <= 0 )
- return FAIL;
- json_object *pageView = json_object_new_object();
- sprintf(buf, "%d", page);
- json_object_object_add(pageView, "PageIndex", json_object_new_string(buf));
- json_object_array_add(payload, pageView);
- for(int idx=0;idx<listCount;idx++)
- {
- if (TextScrollList[idx].textscrollIndex == 0 || TextScrollList[idx].textscrollIndex >= 9999) {
- continue;
- }
- json_object *textscroll = json_object_new_object();
- sprintf(buf, "%d", TextScrollList[idx].textscrollIndex);
- json_object_object_add(textscroll, "textscrollIndex", json_object_new_string(buf));
- json_object_object_add(textscroll, "textString", json_object_new_string(TextScrollList[idx].textString));
- json_object_object_add(textscroll, "textFont", json_object_new_string(TextScrollList[idx].textFont));
- json_object_object_add(textscroll, "textStyle", json_object_new_string(TextScrollList[idx].textStyle));
- sprintf(buf, "%d", TextScrollList[idx].textSize);
- json_object_object_add(textscroll, "textSize", json_object_new_string(buf));
- sprintf(buf, "%d", TextScrollList[idx].layout_x);
- json_object_object_add(textscroll, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", TextScrollList[idx].layout_y);
- json_object_object_add(textscroll, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", TextScrollList[idx].width);
- json_object_object_add(textscroll, "width", json_object_new_string(buf));
- sprintf(buf, "%d", TextScrollList[idx].color_r);
- json_object_object_add(textscroll, "color_r", json_object_new_string(buf));
- sprintf(buf, "%d", TextScrollList[idx].color_g);
- json_object_object_add(textscroll, "color_g", json_object_new_string(buf));
- sprintf(buf, "%d", TextScrollList[idx].color_b);
- json_object_object_add(textscroll, "color_b", json_object_new_string(buf));
- sprintf(buf, "%d", TextScrollList[idx].direction);
- json_object_object_add(textscroll, "direction", json_object_new_string(buf));
- json_object_array_add(payload, textscroll);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/page/storetextscroll", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_imageview_store(struct mosquitto *mosq,uint8_t page)
- {
- json_object *payload = json_object_new_array();
- char outputStr[250*100]={0};
- char buf[32];
- int listCount = ImageIndex;
- if (listCount <= 0 )
- return FAIL;
- json_object *pageView = json_object_new_object();
- sprintf(buf, "%d", page);
- json_object_object_add(pageView, "PageIndex", json_object_new_string(buf));
- json_object_array_add(payload, pageView);
- for(int idx=0;idx<listCount;idx++)
- {
- if (ImageList[idx].imageviewIndex == 0 || ImageList[idx].imageviewIndex >= 9999) {
- continue;
- }
- json_object *imageview = json_object_new_object();
- sprintf(buf, "%d", ImageList[idx].imageviewIndex);
- json_object_object_add(imageview, "imageviewIndex", json_object_new_string(buf));
- sprintf(buf, "%d", ImageList[idx].imgsrc_addr);
- json_object_object_add(imageview, "imgsrc_addr", json_object_new_string(buf));
- sprintf(buf, "%d", ImageList[idx].layout_x);
- json_object_object_add(imageview, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", ImageList[idx].layout_y);
- json_object_object_add(imageview, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", ImageList[idx].width);
- json_object_object_add(imageview, "width", json_object_new_string(buf));
- sprintf(buf, "%d", ImageList[idx].height);
- json_object_object_add(imageview, "height", json_object_new_string(buf));
- json_object_array_add(payload, imageview);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/page/storeimg", outputStr);
- }
- /**
- *
- * @param mosq
- */
- int publish_apngview_store(struct mosquitto *mosq,uint8_t page)
- {
- json_object *payload = json_object_new_array();
- char outputStr[250*100]={0};
- char buf[32];
- int listCount = ApngIndex;
- if (listCount <= 0 )
- return FAIL;
- json_object *pageView = json_object_new_object();
- sprintf(buf, "%d", page);
- json_object_object_add(pageView, "PageIndex", json_object_new_string(buf));
- json_object_array_add(payload, pageView);
- for(int idx=0;idx<listCount;idx++)
- {
- if (ApngList[idx].apngIndex == 0 || ApngList[idx].apngIndex >= 9999) {
- continue;
- }
- json_object *apngview = json_object_new_object();
- sprintf(buf, "%d", ApngList[idx].apngIndex);
- json_object_object_add(apngview, "apngIndex", json_object_new_string(buf));
- sprintf(buf, "%d", ApngList[idx].apngsrc_addr);
- json_object_object_add(apngview, "apngsrc_addr", json_object_new_string(buf));
- sprintf(buf, "%d", ApngList[idx].layout_x);
- json_object_object_add(apngview, "layout_x", json_object_new_string(buf));
- sprintf(buf, "%d", ApngList[idx].layout_y);
- json_object_object_add(apngview, "layout_y", json_object_new_string(buf));
- sprintf(buf, "%d", ApngList[idx].width);
- json_object_object_add(apngview, "width", json_object_new_string(buf));
- sprintf(buf, "%d", ApngList[idx].height);
- json_object_object_add(apngview, "height", json_object_new_string(buf));
- sprintf(buf, "%d", ApngList[idx].loop);
- json_object_object_add(apngview, "loop", json_object_new_string(buf));
- json_object_array_add(payload, apngview);
- }
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/page/storeapng", outputStr);
- }
- ////////////////////////////////////////////////////////////////////////////
- int publish_textview_push(Text_List* textList, uint8_t listCount)
- {
- int cmpIndex = 0;
- for(int idx=0;idx<listCount;idx++)
- {
- if (TextIndex >= 100) {
- DEBUG_INFO("OVER TEXT LIST BUFFER SIZE");
- break;
- }
- if (TextIndex < 100) {
- for (cmpIndex = 0; cmpIndex < TextIndex; cmpIndex++) {
- if (TextList[cmpIndex].textviewIndex == textList[idx].textviewIndex)
- break;
- }
- if (TextList[cmpIndex].textviewIndex != textList[idx].textviewIndex) {
- memcpy(&TextList[TextIndex],&textList[idx],sizeof(Text_List));
- //DEBUG_INFO("Push TextIndex[%d] into Buffer(%d)",textList[idx].textviewIndex,TextIndex);
- TextIndex++;
- }
- }
- }
- return TextIndex;
- }
- int publish_textscroll_push(TextScroll_List* textList, uint8_t listCount)
- {
- int cmpIndex = 0;
- for(int idx=0;idx<listCount;idx++)
- {
- if (TextScrollIndex >= 100) {
- DEBUG_INFO("OVER TEXT LIST BUFFER SIZE");
- break;
- }
- if (TextScrollIndex < 100) {
- for (cmpIndex = 0; cmpIndex < TextScrollIndex; cmpIndex++) {
- if (TextScrollList[cmpIndex].textscrollIndex == textList[idx].textscrollIndex)
- break;
- }
- if (TextScrollList[cmpIndex].textscrollIndex != textList[idx].textscrollIndex) {
- memcpy(&TextScrollList[TextScrollIndex],&textList[idx],sizeof(TextScroll_List));
- //DEBUG_INFO("Push TextScrollIndex[%d] into Buffer(%d)",TextScrollList[idx].textscrollIndex,TextScrollIndex);
- TextScrollIndex++;
- }
- }
- }
- return TextScrollIndex;
- }
- int publish_imageview_push(Image_List *imageList, uint8_t listCount)
- {
- int cmpIndex = 0;
- for(int idx=0;idx<listCount;idx++)
- {
- if (ImageIndex >= 100) {
- DEBUG_INFO("OVER TEXT LIST BUFFER SIZE");
- break;
- }
- for (cmpIndex = 0; cmpIndex < ImageIndex; cmpIndex++) {
- if (ImageList[cmpIndex].imageviewIndex == imageList[idx].imageviewIndex)
- break;
- }
- if (ImageList[cmpIndex].imageviewIndex != imageList[idx].imageviewIndex) {
- memcpy(&ImageList[ImageIndex],&imageList[idx],sizeof(Image_List));
- //DEBUG_INFO("Push ImageIndex[%d] into Buffer(%d)",imageList[idx].imageviewIndex,ImageIndex);
- ImageIndex++;
- }
- }
- return ImageIndex;
- }
- int publish_apngview_push( APNG_List *apngList, uint8_t listCount)
- {
- int cmpIndex = 0;
- for(int idx=0;idx<listCount;idx++)
- {
- if (ApngIndex >= 5) {
- DEBUG_INFO("OVER APNG LIST BUFFER SIZE");
- break;
- }
- for (cmpIndex = 0; cmpIndex < listCount; cmpIndex++) {
- if (ApngList[cmpIndex].apngIndex == apngList[idx].apngIndex)
- break;
- }
- if (ApngList[cmpIndex].apngIndex != apngList[idx].apngIndex) {
- memcpy(&ApngList[ApngIndex],&apngList[idx],sizeof(APNG_List));
- //DEBUG_INFO("Push ApngIndex[%d] into Buffer(%d)",apngList[idx].apngIndex,ApngIndex);
- ApngIndex++;
- }
- }
- return ApngIndex;
- }
- void clearPushBuffer()
- {
- memset(TextList, 0, sizeof(TextList));
- memset(ImageList, 0, sizeof(ImageList));
- memset(ApngList, 0, sizeof(ApngList));
- memset(QRCodeList, 0, sizeof(QRCodeList));
- memset(TextScrollList, 0, sizeof(TextScrollList));
- TextIndex = 0;
- ImageIndex = 0;
- QRCodeIndex = 0;
- TextScrollIndex = 0;
- ApngIndex = 0;
- }
- void PushPageInfoToLcm(struct mosquitto *mosq,int page)
- {
- //DEBUG_INFO("Push Page%d to LCM",page);
- publish_textview_store(mosq,page);
- publish_textscroll_store(mosq,page);
- publish_imageview_store(mosq,page);
- publish_apngview_store(mosq,page);
- clearPushBuffer();
- }
- int publish_image_remove(struct mosquitto *mosq, Image_List *imageList, uint8_t ListCount)
- {
- json_object *payload = json_object_new_object();
- json_object *image = json_object_new_array();
- char outputStr[2048]={0};
- // Remove image view
- for(int idx=0;idx<ListCount;idx++)
- {
- if (imageList[idx].imageviewIndex == 0) {
- continue;
- }
- json_object *imageview = json_object_new_object();
- char buf[8];
- sprintf(buf, "%d", imageList[idx].imageviewIndex);
- json_object_object_add(imageview, "imageviewIndex", json_object_new_string(buf));
- json_object_array_add(image, imageview);
- }
- json_object_object_add(payload, "rm_imageview_list", image);
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/remove", outputStr);
- }
- int publish_apng_remove(struct mosquitto *mosq, APNG_List *apngList, uint8_t apngListCount)
- {
- json_object *payload = json_object_new_object();
- json_object *image = json_object_new_array();
- char outputStr[2048]={0};
- // Remove image view
- for(int idx=0;idx<apngListCount;idx++)
- {
- if (apngList[idx].apngIndex == 0) {
- continue;
- }
- json_object *imageview = json_object_new_object();
- char buf[8];
- sprintf(buf, "%d", apngList[idx].apngIndex);
- json_object_object_add(imageview, "ApngIndex", json_object_new_string(buf));
- json_object_array_add(image, imageview);
- }
- json_object_object_add(payload, "rm_APNG_list", image);
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/remove", outputStr);
- }
- int publish_vido_remove(struct mosquitto *mosq, Video_List *videoList, uint8_t ListCount)
- {
- json_object *payload = json_object_new_object();
- json_object *video = json_object_new_array();
- char outputStr[2048]={0};
- // Remove image view
- for(int idx=0;idx<ListCount;idx++)
- {
- if (videoList[idx].videoviewIndex == 0) {
- continue;
- }
- json_object *videoview = json_object_new_object();
- char buf[8];
- sprintf(buf, "%d", videoList[idx].videoviewIndex);
- json_object_object_add(videoview, "videoviewIndex", json_object_new_string(buf));
- json_object_array_add(video, videoview);
- }
- json_object_object_add(payload, "rm_videoview_list", video);
- sprintf(outputStr, "%s", json_object_to_json_string_ext(payload, JSON_C_TO_STRING_PLAIN));
- json_object_put(payload);
- return publish_data(mosq, "client/layout/remove", outputStr);
- }
|