123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- /*
- * LcmCommandDriver.c
- *
- * Created on: 2022/3/31
- * Author: folus
- */
- #include "Module_LcmControl_Wistron.h"
- /**
- *
- * @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)
- {
- 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 eth0 %s", clientInfo.macAddr);
- system(cmd);
- 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);
- }
- /**
- *
- * @param mosq
- */
- int publish_textview_add(struct mosquitto *mosq, Text_List *textList, uint8_t listCount)
- {
- json_object *payload = json_object_new_array();
- char outputStr[2048]={0};
- for(int idx=0;idx<listCount;idx++)
- {
- 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));
- 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_imageview_add(struct mosquitto *mosq, Image_List *imageList, 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", 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_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));
- 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++)
- {
- 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++)
- {
- 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++)
- {
- 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++)
- {
- 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++)
- {
- 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);
- }
|