Эх сурвалжийг харах

[Improve][AX80][Module_LcmControl_Wistron]

2022.06.10 / Folus Wen

Actions:
1. Wistron lcmCommand driver add "Show QR code image".
2. MQTT message set RETAIN as false.
3. crc32 calculate function fix for large size file.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 2 жил өмнө
parent
commit
470f216fab

+ 83 - 10
EVSE/Projects/AX80/Apps/LCM_Wistron/LcmCommandDriver.c

@@ -18,7 +18,7 @@ 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_YES);
+	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));
 
@@ -91,16 +91,27 @@ int publish_restart(struct mosquitto *mosq, uint8_t isHardReset)
  */
 int publish_power_saving(struct mosquitto *mosq, uint8_t isSleep)
 {
-	json_object *payload = json_object_new_object();
-	char outputStr[2048]={0};
+	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"));
+		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);
+		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);
+		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;
+	}
 }
 
 /**
@@ -278,7 +289,7 @@ int publish_videoview_add(struct mosquitto *mosq, Video_List *videoList, uint8_t
 		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));
+		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));
@@ -305,12 +316,60 @@ int publish_videoview_add(struct mosquitto *mosq, Video_List *videoList, uint8_t
  *
  * @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)
+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};
 
@@ -350,6 +409,18 @@ int publish_view_remove(struct mosquitto *mosq, Text_List *textList, uint8_t tex
 	}
 	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);
 
@@ -372,3 +443,5 @@ int publish_clear_screen(struct mosquitto *mosq)
 
 	return publish_data(mosq, "client/command", outputStr);
 }
+
+

+ 78 - 20
EVSE/Projects/AX80/Apps/LCM_Wistron/Module_LcmControl_Wistron.c

@@ -103,14 +103,16 @@ uint32_t getFileCrc32(char *filename)
     {
     	struct stat st;
 		stat(filename, &st);
-		uint8_t data[st.st_size];
+		uint8_t *data;
+		data = malloc(st.st_size);
 
 		if(read(fd,data,st.st_size) == st.st_size)
 		{
 			result = crc32(data, st.st_size);
+			close(fd);
 		}
 
-		close(fd);
+		free(data);
     }
 
 	return result;
@@ -304,12 +306,19 @@ int on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_me
 		 */
 		if(strstr(msg->topic, "client/connect"))
 		{
-			DEBUG_INFO("HW_version: %s\n", json_object_get_string(json_object_object_get(payload, "HW_version")));
-			DEBUG_INFO("FW_version_OS: %s\n", json_object_get_string(json_object_object_get(payload, "FW_version_OS")));
-			DEBUG_INFO("FW_version_APK: %s\n", json_object_get_string(json_object_object_get(payload, "FW_version_APK")));
-			DEBUG_INFO("FW_version_UI: %s\n", json_object_get_string(json_object_object_get(payload, "FW_version_UI")));
-			DEBUG_INFO("MAC_addr: %s\n", json_object_get_string(json_object_object_get(payload, "MAC_addr")));
-			DEBUG_INFO("Orientation: %s\n", json_object_get_string(json_object_object_get(payload, "Orientation")));
+			sprintf((char*)clientInfo.verHW, "%s", json_object_get_string(json_object_object_get(payload, "HW_version")));
+			sprintf((char*)clientInfo.verFW_OS, "%s", json_object_get_string(json_object_object_get(payload, "FW_version_OS")));
+			sprintf((char*)clientInfo.verFW_APK, "%s", json_object_get_string(json_object_object_get(payload, "FW_version_APK")));
+			sprintf((char*)clientInfo.verFW_UI, "%s", json_object_get_string(json_object_object_get(payload, "FW_version_UI")));
+			sprintf((char*)clientInfo.macAddr, "%s", json_object_get_string(json_object_object_get(payload, "MAC_addr")));
+			sprintf((char*)clientInfo.orientation, "%s", json_object_get_string(json_object_object_get(payload, "Orientation")));
+
+			DEBUG_INFO("HW_version: %s\n", clientInfo.verHW);
+			DEBUG_INFO("FW_version_OS: %s\n", clientInfo.verFW_OS);
+			DEBUG_INFO("FW_version_APK: %s\n", clientInfo.verFW_APK);
+			DEBUG_INFO("FW_version_UI: %s\n", clientInfo.verFW_UI);
+			DEBUG_INFO("MAC_addr: %s\n", clientInfo.macAddr);
+			DEBUG_INFO("Orientation: %s\n", clientInfo.orientation);
 		}
 		else if(strstr(msg->topic, "client/touch"))
 		{
@@ -346,11 +355,27 @@ int on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_me
 					case 5:
 						DEBUG_INFO("Status reset.\n");
 						break;
+					case 6:
+						DEBUG_INFO("Status sleep.\n");
+						break;
+					case 255:
+						DEBUG_INFO("Status fault.\n");
+						break;
 					default:
 						DEBUG_INFO("Unknown status.\n");
 						break;
 				}
 			}
+
+			if(json_object_object_get(payload, "temperature") != NULL)
+			{
+				DEBUG_INFO("Temperature: %s.\n", json_object_get_string(json_object_object_get(payload, "temperature")));
+			}
+
+			if(json_object_object_get(payload, "cpu_temperatue") != NULL)
+			{
+				DEBUG_INFO("CPU temperature: %s.\n", json_object_get_string(json_object_object_get(payload, "cpu_temperatue")));
+			}
 		}
 		else if(strstr(msg->topic, "client/profile") ||
 				strstr(msg->topic, "client/command") ||
@@ -580,10 +605,10 @@ int publish_upgrade_sample(struct mosquitto *mosq)
 	char chkCrc32[16];
 
 	sprintf(url, "ftp://ftpuser:ftppasswd@%s/mnt/dummy_Image.zip", BROKER_ADDRESS);
+	sprintf(chkCrc32, "0x%08X", getFileCrc32("/mnt/dummy_Image.zip"));
+	DEBUG_INFO("image file crc32: %s\n", chkCrc32);
 
-	sprintf(chkCrc32, "0x%08X", getFileCrc32("/root/main"));
-
-	return publish_upgrade(mosq, OTA_TYPE_UI, url, chkCrc32, "V0.01");
+	return publish_upgrade(mosq, OTA_TYPE_SDCARD, url, chkCrc32, "V0.01");
 }
 
 /**
@@ -592,7 +617,7 @@ int publish_upgrade_sample(struct mosquitto *mosq)
  */
 int publish_restart_sample(struct mosquitto *mosq)
 {
-	return publish_restart(mosq, TRUE);
+	return publish_restart(mosq, FALSE);
 }
 
 /**
@@ -637,8 +662,8 @@ int publish_textview_add_sample(struct mosquitto *mosq)
 		sprintf(textList[idx].textFont, FONT_ARIAL);
 		sprintf(textList[idx].textStyle, FONT_STYLE_NORMAL);
 		textList[idx].textSize = FONT_SIZE_20PX;
-		textList[idx].layout_x = (rand()%800+100);
-		textList[idx].layout_y = (rand()%800+100);
+		textList[idx].layout_x = 10;//(rand()%800+100);
+		textList[idx].layout_y = 10;//(rand()%800+100);
 	}
 
 	return publish_textview_add(mosq, textList, ARRAY_SIZE(textList));
@@ -656,8 +681,8 @@ int publish_imageview_add_sample(struct mosquitto *mosq)
 	{
 		imageList[idx].imageviewIndex = idx;
 		imageList[idx].imgsrc_addr = (rand()%10+0);
-		imageList[idx].layout_x = (rand()%800+100);
-		imageList[idx].layout_y = (rand()%800+100);
+		imageList[idx].layout_x = 100;//(rand()%800+100);
+		imageList[idx].layout_y = 100;//(rand()%800+100);
 		imageList[idx].width = (rand()%800+100);
 		imageList[idx].height = (rand()%800+100);
 	}
@@ -676,15 +701,38 @@ int publish_videoview_add_sample(struct mosquitto *mosq)
 	for(int idx=0;idx<ARRAY_SIZE(videoList);idx++)
 	{
 		videoList[idx].videoviewIndex = idx;
-		videoList[idx].videosrc_addr = (rand()%10+0);
-		videoList[idx].layout_x = (rand()%800+100);
-		videoList[idx].layout_y = (rand()%800+100);
+		videoList[idx].videosrc_addr = 11;//(rand()%10+0);
+		videoList[idx].layout_x = 200;//(rand()%800+100);
+		videoList[idx].layout_y = 200;//(rand()%800+100);
 		videoList[idx].width = (rand()%800+100);
 		videoList[idx].height = (rand()%800+100);
 	}
 
 	return publish_videoview_add(mosq, videoList, ARRAY_SIZE(videoList));
 }
+
+/**
+ *
+ * @param mosq
+ */
+int publish_qr_code_image(struct mosquitto *mosq)
+{
+	QrCode_List qrCodeList[2] = {0};
+
+	for(int idx=0;idx<ARRAY_SIZE(qrCodeList);idx++)
+	{
+		qrCodeList[idx].qrCodeIndex = idx;
+		sprintf((char*)qrCodeList[idx].qrCodeContent, "djsalkdjskjslkdjsalkdjslkdjsalkdjsal");
+		sprintf((char*)qrCodeList[idx].errorCorrection, "M");
+		qrCodeList[idx].layout_x = 100;//(rand()%800+100);
+		qrCodeList[idx].layout_y = 100;//(rand()%800+100);
+		qrCodeList[idx].width = (rand()%800+100);
+		qrCodeList[idx].height = (rand()%800+100);
+	}
+
+	return publish_qrcodeimage_add(mosq, qrCodeList, ARRAY_SIZE(qrCodeList));
+}
+
 /**
  *
  * @param mosq
@@ -694,6 +742,7 @@ int publish_view_remove_sample(struct mosquitto *mosq)
 	Text_List textList[2] = {0};
 	Image_List imageList[2] = {0};
 	Video_List videoList[2] = {0};
+	QrCode_List qrCodeList[2] = {0};
 
 	// Remove text view
 	for(int idx=0;idx<ARRAY_SIZE(textList);idx++)
@@ -713,7 +762,13 @@ int publish_view_remove_sample(struct mosquitto *mosq)
 		videoList[idx].videoviewIndex = idx;
 	}
 
-	return publish_view_remove(mosq, textList, ARRAY_SIZE(textList), imageList, ARRAY_SIZE(imageList), videoList, ARRAY_SIZE(videoList));
+	// Remove qrCode view
+	for(int idx=0;idx<ARRAY_SIZE(qrCodeList);idx++)
+	{
+		qrCodeList[idx].qrCodeIndex = idx;
+	}
+
+	return publish_view_remove(mosq, textList, ARRAY_SIZE(textList), imageList, ARRAY_SIZE(imageList), videoList, ARRAY_SIZE(videoList), qrCodeList, ARRAY_SIZE(qrCodeList));
 }
 
 /**
@@ -1039,6 +1094,7 @@ int main(void)
 		printf("\n  11: publish_clear_screen.");
 		printf("\n  12: publish_audio_volume.");
 		printf("\n  13: publish_trigger_report_status.");
+		printf("\n  14: publish_qr_code_image.");
 		printf("\n ==================================================");
 		printf("\n  Please input item to test: ");
 		scanf("%s", &cmd[0]);
@@ -1083,6 +1139,8 @@ int main(void)
 				break;
 			case 13:
 				publish_trigger_report_status_sample(mosq);
+			case 14:
+				publish_qr_code_image(mosq);
 				break;
 		}
 #endif

+ 27 - 2
EVSE/Projects/AX80/Apps/LCM_Wistron/Module_LcmControl_Wistron.h

@@ -42,7 +42,7 @@
 #include	"json-c/json.h"
 #include 	"mosquitto.h"
 
-//#define TEST_MODE
+#define TEST_MODE
 
 #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
 #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
@@ -128,6 +128,18 @@ typedef struct VIDEO_LIST
 
 }Video_List;
 
+typedef struct QRCODE_LIST
+{
+	uint16_t	qrCodeIndex;
+	int8_t		qrCodeContent[512];
+	int8_t		errorCorrection[8];
+	uint16_t	layout_x;
+	uint16_t	layout_y;
+	uint16_t	width;
+	uint16_t	height;
+
+}QrCode_List;
+
 #define ARRAY_SIZE(A)				(sizeof(A) / sizeof(A[0]))
 #define is_error(ptr) 				((unsigned long)ptr > (unsigned long)-4000L)
 
@@ -186,6 +198,15 @@ enum FONT_SIZE
 	FONT_SIZE_96PX=96,
 };
 
+struct ClientInfo
+{
+	int8_t verHW[32];
+	int8_t verFW_OS[32];
+	int8_t verFW_APK[32];
+	int8_t verFW_UI[32];
+	int8_t macAddr[32];
+	int8_t orientation[32];
+}clientInfo;
 
 extern int StoreLogMsg(const char *fmt, ...);
 extern int publish_data(struct mosquitto *mosq, char *topic, char *outputStr);
@@ -198,7 +219,11 @@ extern int publish_timesync(struct mosquitto *mosq);
 extern int publish_textview_add(struct mosquitto *mosq, Text_List *textList, uint8_t listCount);
 extern int publish_imageview_add(struct mosquitto *mosq, Image_List *imageList, uint8_t listCount);
 extern int publish_videoview_add(struct mosquitto *mosq, Video_List *videoList, uint8_t listCount);
-extern 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);
+extern int publish_qrcodeimage_add(struct mosquitto *mosq, QrCode_List *qrCodeList, uint8_t listCount);
+extern 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);
 extern int publish_clear_screen(struct mosquitto *mosq);
 extern int publish_audio_volume(struct mosquitto *mosq, uint8_t volume);
 extern int publish_trigger_report_status(struct mosquitto *mosq);