/* * 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); } /** * * @param mosq */ int publish_textview_add(struct mosquitto* mosq, Text_List* textList, uint8_t listCount) { int cmpIndex = 0; for(int idx=0;idx= 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_textview_push(struct mosquitto* mosq) { json_object *payload = json_object_new_array(); char outputStr[250*100]={0}; int cmpIndex = 0; for(int idx=0;idx= 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_textscroll_push(struct mosquitto* mosq) { json_object *payload = json_object_new_array(); char outputStr[250*100]={0}; int cmpIndex = 0; for(int idx=0;idx= 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] != 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_imageview_push(struct mosquitto *mosq) { json_object *payload = json_object_new_array(); char outputStr[250*100]={0}; int cmpIndex = 0; for(int idx=0;idx= 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] != 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; } int publish_apngview_push(struct mosquitto *mosq) { json_object *payload = json_object_new_array(); char outputStr[250*100]={0}; int cmpIndex = 0; for(int idx=0;idx= 5) { DEBUG_INFO("OVER APNG LIST BUFFER SIZE"); break; } for (cmpIndex = 0; cmpIndex < listCount; cmpIndex++) { if (QRCodeList[cmpIndex].qrCodeIndex == qrCodeList[idx].qrCodeIndex) break; } if (QRCodeList[cmpIndex] != qrCodeList[idx].qrCodeIndex) { memcpy(&QRCodeList[QRCodeIndex],&qrCodeList[idx],sizeof(QrCode_List)); DEBUG_INFO("Push QRCodeList[%d] into Buffer(%d)",QRCodeList[idx].qrCodeList,qrCodeIndex); QRCodeIndex++; } } return QRCodeIndex; } /** * * @param mosq */ int publish_qrcodeimage_push(struct mosquitto *mosq) { json_object *payload = json_object_new_array(); char outputStr[2048]={0}; int cmpIndex = 0; for(int idx=0;idx