/* * 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