浏览代码

[Improve][AW-CCS][master]

2020.09.26 / Folus Wen

Actions:
1. EVSE/Modularization/Module_ProduceUtils.c disable debug info on terminal console.
2. EVSE/Modularization/Module_ProduceUtils.c flash operation method change to nandwrite tool.
3. EVSE/Modularization/ocppfiles/ disable debuginfo on terminal console.
4. EVSE/Projects/AW-CCS/Apps/CCS/define_ccs.h V2GT_MSG_PROTOCOL_PREFERENCE change to V2GT_MSG_PROTOCOL_ISO15118_2014.
5. add Module_ConfigTools & Module_Debug to AW-CCS.
6. EVSE/Projects/AW-CCS/Apps/main.c flash operation method change to nandwrite & nanddump tools.

Files:
1. As follow commit history

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

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 4 年之前
父节点
当前提交
190e83f90d

+ 92 - 68
EVSE/Modularization/Module_ProduceUtils.c

@@ -62,7 +62,7 @@ int StoreLogMsg(const char *fmt, ...)
 	memset(Buf,0,sizeof(Buf));
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]ProduceUtils_SystemLog",
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]ProduceUtils_SystemLog",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);
@@ -70,11 +70,34 @@ int StoreLogMsg(const char *fmt, ...)
 	system(Buf);
 #endif
 
+#ifdef ConsloePrintLog
 	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
 
 	return rc;
 }
 
+int runShellCmd(const char*cmd)
+{
+	int result = FAIL;
+	char buf[256];
+	FILE *fp;
+
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			DEBUG_INFO("%s\n", buf);
+		}
+
+		result = PASS;
+	}
+	pclose(fp);
+
+	return result;
+}
+
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
 	//return milli-second
@@ -181,64 +204,65 @@ void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
 int StoreUsrConfigData(struct SysConfigData *UsrData)
 {
 	int result = PASS;
-	int fd,wrd;
-	unsigned int i,Chk;
-	unsigned char *ptr, *BufTmp;
+		int fd,wrd;
+		unsigned int i,Chk;
+		unsigned char *ptr, *BufTmp;
 
-	Chk=0;
-	ptr=(unsigned char *)UsrData;
-	if((BufTmp=malloc(MtdBlockSize))!=NULL)
-	{
-		memset(BufTmp,0,MtdBlockSize);
-		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
-		for(i=0;i<MtdBlockSize-4;i++)
-			Chk+=*(BufTmp+i);
-		memcpy(	BufTmp+MtdBlockSize-4,&Chk,4);
-		fd = open("/dev/mtdblock10", O_RDWR);
-		if (fd>0)
+		Chk=0;
+		ptr=(unsigned char *)UsrData;
+		if((BufTmp=malloc(MtdBlockSize))!=NULL)
 		{
-			wrd=write(fd, BufTmp, MtdBlockSize);
-			close(fd);
-			if(wrd>=MtdBlockSize)
+			memset(BufTmp,0,MtdBlockSize);
+			memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
+			for(i=0;i<MtdBlockSize-4;i++)
+				Chk+=*(BufTmp+i);
+			memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
+
+			// Output configuration to file.
+			fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
+			if (fd < 0)
 			{
-				fd = open("/dev/mtdblock11", O_RDWR);
-				if (fd>0)
-				{
-					wrd=write(fd, BufTmp, MtdBlockSize);
-    					close(fd);
-				   	if(wrd<MtdBlockSize)
-					{
-						DEBUG_ERROR("write /dev/mtdblock11(backup) NG\r\n");
-				   		result = FAIL;
-					}
-				}
-				else
-				{
-					DEBUG_ERROR("open /dev/mtdblock11(backup) NG\r\n");
-					result = FAIL;
-				}
+				DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
+
+				free(BufTmp);
+				return 0;
 			}
-			else
+			wrd=write(fd, BufTmp, MtdBlockSize);
+			close(fd);
+			if(wrd<MtdBlockSize)
 			{
-		    		DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
-		    		result = FAIL;
+				DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
+
+				free(BufTmp);
+				return 0;
 			}
+			DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
+
+
+			DEBUG_INFO("Erase /dev/mtd10.\n");
+			runShellCmd("flash_erase /dev/mtd10 0 12");
+			DEBUG_INFO("Write /dev/mtd10.\n");
+			runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
+
+			DEBUG_INFO("Erase /dev/mtd11.\n");
+			runShellCmd("flash_erase /dev/mtd11 0 12");
+			DEBUG_INFO("Write /dev/mtd11.\n");
+			runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
+
+
+			system("rm -f /mnt/EvseConfig.bin");
+			DEBUG_INFO("EvseConfig write to flash OK\n");
 		}
 		else
 		{
-			DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
-			result = FAIL;
+			DEBUG_ERROR("alloc BlockSize NG\r\n");
+	    		result = FAIL;
 		}
-	}
-	else
-	{
-		DEBUG_ERROR("alloc BlockSize NG\r\n");
-    		result = FAIL;
-	}
-	if(BufTmp!=NULL)
-		free(BufTmp);
 
-	return result;
+		if(BufTmp!=NULL)
+			free(BufTmp);
+
+		return result;
 }
 
 int isValidCheckSum(uint8_t *message)
@@ -316,7 +340,7 @@ int main(void)
 	for(;;)
 	{
 		clientSockFd = accept(sockFd, (struct sockaddr*) &clientInfo, &addrlen);
-		DEBUG_INFO("Client connect in.\r\n");
+		DEBUG_INFO("Client connect in.\n");
 
 		if(fork()==0)
 		{
@@ -331,7 +355,7 @@ int main(void)
 					switch(inputBuffer[3])
 					{
 						case CMD_QUERY_FW_VER:
-							DEBUG_INFO("Query firmware version: %s.\r\n", (char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+							DEBUG_INFO("Query firmware version: %s.\n", (char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
 							tx_size= 7 + (strlen((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
 							outBuffer[0] = 0xaa;
 							outBuffer[1] = PROTOCOL_ADDR;
@@ -352,7 +376,7 @@ int main(void)
 
 							break;
 						case CMD_QUERY_HW_VER:
-							DEBUG_INFO("Query hardware version: %s.\r\n", (char*)ShmSysConfigAndInfo->SysInfo.CsuHwRev);
+							DEBUG_INFO("Query hardware version: %s.\n", (char*)ShmSysConfigAndInfo->SysInfo.CsuHwRev);
 							tx_size = 7 + strlen((char*)ShmSysConfigAndInfo->SysInfo.CsuHwRev);
 							outBuffer[0] = 0xaa;
 							outBuffer[1] = PROTOCOL_ADDR;
@@ -372,10 +396,10 @@ int main(void)
 							outBuffer[6+(outBuffer[4] | (outBuffer[5]<<8))] = chksum;
 							break;
 						case CMD_QUERY_PRESENT_INPUTVOLTAGE:
-							DEBUG_INFO("Query present input voltage.\r\n");
-							DEBUG_INFO("  -Input R: %.2f.\r\n", ShmSysConfigAndInfo->SysInfo.InputVoltageR);
-							DEBUG_INFO("  -Input S: %.2f.\r\n", ShmSysConfigAndInfo->SysInfo.InputVoltageS);
-							DEBUG_INFO("  -Input T: %.2f.\r\n", ShmSysConfigAndInfo->SysInfo.InputVoltageT);
+							DEBUG_INFO("Query present input voltage.\n");
+							DEBUG_INFO("  -Input R: %.2f.\n", ShmSysConfigAndInfo->SysInfo.InputVoltageR);
+							DEBUG_INFO("  -Input S: %.2f.\n", ShmSysConfigAndInfo->SysInfo.InputVoltageS);
+							DEBUG_INFO("  -Input T: %.2f.\n", ShmSysConfigAndInfo->SysInfo.InputVoltageT);
 							tx_size = 14;
 							outBuffer[0] = 0xaa;
 							outBuffer[1] = PROTOCOL_ADDR;
@@ -402,9 +426,9 @@ int main(void)
 						case CMD_QUERY_FAN_SPEED:
 							break;
 						case CMD_QUERY_TEMPERATURE:
-							DEBUG_INFO("Query temperature.\r\n");
-							DEBUG_INFO("  -SystemAmbientTemp: %d\r\n", ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp);
-							DEBUG_INFO("  -CcsConnectorTemp: %d\r\n", ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp);
+							DEBUG_INFO("Query temperature.\n");
+							DEBUG_INFO("  -SystemAmbientTemp: %d\n", ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp);
+							DEBUG_INFO("  -CcsConnectorTemp: %d\n", ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp);
 							tx_size = 15;
 							outBuffer[0] = 0xaa;
 							outBuffer[1] = PROTOCOL_ADDR;
@@ -441,7 +465,7 @@ int main(void)
 						case CMD_QUERY_SN:
 							ftime(&csuTime);
 							tmCSU = localtime(&csuTime.time);
-							DEBUG_INFO("Query serial number: %s\r\n", (char*)ShmSysConfigAndInfo->SysConfig.SerialNumber);
+							DEBUG_INFO("Query serial number: %s\n", (char*)ShmSysConfigAndInfo->SysConfig.SerialNumber);
 							tx_size = 15 + strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber);
 							outBuffer[0] = 0xaa;
 							outBuffer[1] = PROTOCOL_ADDR;
@@ -470,7 +494,7 @@ int main(void)
 							outBuffer[6+(outBuffer[4] | (outBuffer[5]<<8))] = chksum;
 							break;
 						case CMD_QUERY_MODEL_NAME:
-							DEBUG_INFO("Query model name: %s\r\n", (char*)ShmSysConfigAndInfo->SysConfig.ModelName);
+							DEBUG_INFO("Query model name: %s\n", (char*)ShmSysConfigAndInfo->SysConfig.ModelName);
 							tx_size = 7 + strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName);
 							outBuffer[0] = 0xaa;
 							outBuffer[1] = PROTOCOL_ADDR;
@@ -492,7 +516,7 @@ int main(void)
 						case CMD_QUERY_PARAMETER:
 							break;
 						case CMD_QUERY_RTC:
-							DEBUG_INFO("Query system time.\r\n");
+							DEBUG_INFO("Query system time.\n");
 							ftime(&csuTime);
 							tmCSU = localtime(&csuTime.time);
 
@@ -525,7 +549,7 @@ int main(void)
 							outBuffer[20] = chksum;
 							break;
 						case CMD_QUERY_4G_REVISION:
-							DEBUG_INFO("Query 4G module revision: %s\r\n", (char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
+							DEBUG_INFO("Query 4G module revision: %s\n", (char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
 							tx_size = 7 + strlen((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
 							outBuffer[0] = 0xaa;
 							outBuffer[1] = PROTOCOL_ADDR;
@@ -605,7 +629,7 @@ int main(void)
 							outBuffer[6] = 0x01;
 							outBuffer[7] = outBuffer[6];
 
-							DEBUG_INFO("Config serial number: %s\r\n", (char*)ShmSysConfigAndInfo->SysConfig.SerialNumber);
+							DEBUG_INFO("Config serial number: %s\n", (char*)ShmSysConfigAndInfo->SysConfig.SerialNumber);
 
 							break;
 						case CMD_CONFIG_MODEL_NAME:
@@ -629,14 +653,14 @@ int main(void)
 							outBuffer[5] = 0x00;
 							outBuffer[6] = 0x01;
 							outBuffer[7] = outBuffer[6];
-							DEBUG_INFO("Config model name: %s\r\n", (char*)ShmSysConfigAndInfo->SysConfig.ModelName);
+							DEBUG_INFO("Config model name: %s\n", (char*)ShmSysConfigAndInfo->SysConfig.ModelName);
 							break;
 						case CMD_CONFIG_RELAY_OUTPUT:
 							break;
 						case CMD_CONFIG_GPIO_OUTPUT:
 							break;
 						case CMD_CONFIG_RTC:
-							DEBUG_INFO("Config system time.\r\n");
+							DEBUG_INFO("Config system time.\n");
 							tx_size = 8;
 							outBuffer[0] = 0xaa;
 							outBuffer[1] = PROTOCOL_ADDR;
@@ -678,7 +702,7 @@ int main(void)
 							outBuffer[5] = 0x00;
 							outBuffer[6] = (StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig)!=0x01?0x00:0x01);
 							outBuffer[7] = outBuffer[6];
-							DEBUG_INFO("Save configuration\r\n");
+							DEBUG_INFO("Save configuration\n");
 
 							if((outBuffer[6] == PASS))
 							{
@@ -730,13 +754,13 @@ int main(void)
 			if(read_size == 0)
 			{
 				close(clientSockFd);
-				DEBUG_INFO("Client disconnected.\r\n");
+				DEBUG_INFO("Client disconnected.\n");
 				fflush(stdout);
 			}
 			else if(read_size == -1)
 			{
 				close(clientSockFd);
-				DEBUG_ERROR("Socket recv failed.\r\n");
+				DEBUG_ERROR("Socket recv failed.\n");
 			}
 
 			exit(0);

+ 1 - 1
EVSE/Modularization/Module_Upgrade.h

@@ -111,5 +111,5 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName);
 int Upgrade_UART(unsigned char uartfd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName);
 int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName);
 int Upgrade_CCS(int canfd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName);
-
+extern int runShellCmd(const char*cmd);
 #endif /* MODULE_UPGRADE_H_ */

+ 23 - 134
EVSE/Modularization/ocppfiles/JsonParser.c

@@ -84,11 +84,9 @@ static FunCallErrorPtr funcallerror[] = {	handleError	};
 
 void ReceivedMessage(void *in, size_t len)
 {
-	printf("ReceivedMessage\n");
-	//char tempin[1024*4];
+	DEBUG_INFO("ReceivedMessage\n");
 	char tempin[65536];
 	int MsgType = 0;
-	//char UniqueId[37],Action[33],Payload[10241],ErrorCode[129],ErrorDescription[513];
 	char UniqueId[37],Action[33],Payload[64824],ErrorCode[129],ErrorDescription[513];
 	char *arr[2]= {};
 	int gun_index = 0;
@@ -96,8 +94,6 @@ void ReceivedMessage(void *in, size_t len)
 	char *substr = NULL;
 	int count = 0;
 	int i = 0;
-	//int c = 0;
-	//int templen = 0;
 	char key_value[VALUE_MAX_LENGTH];
 
 	//parsing received message and do something
@@ -107,7 +103,6 @@ void ReceivedMessage(void *in, size_t len)
 	memset(Payload, 0, sizeof Payload);
 	memset(ErrorCode, 0, sizeof ErrorCode);
 	memset(ErrorDescription, 0, sizeof ErrorDescription);
-
 	memset(tempin, 0, 1024*4);
 	strcpy(tempin, (const char *)in);
 	memset( (void *)in, 0, sizeof(char)*len );
@@ -116,34 +111,19 @@ void ReceivedMessage(void *in, size_t len)
 	MsgType = json_object_get_int(json_object_array_get_idx(json_tokener_parse(tempin), 0));
 	sprintf(UniqueId, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 1)));
 
-	//char *str = "[ ]";
 	if(strcmp((const char *)tempin,"[ ]") == 0)
 	{
-		printf("Message is empty arrary. \n");
+		DEBUG_WARN("Message is empty arrary. \n");
 	    return;
 	}
 
-	if(tempin[0] != '\0')//if(jobj != NULL)
+	if(tempin[0] != '\0')
 	{
-		//MsgType = tempin[1] - '0';
-		//printf("MsgType=%d\n",MsgType);
-		//c = 0;
-
 		if((MsgType != 2) && (MsgType != 3) && (MsgType != 4) )
 		{
 			return;
 		}
 
-		/*
-		while ((tempin[4+c] != '\"') && (tempin[4+c] != '\0'))
-		{
-			UniqueId[c] = tempin[4+c];
-			//printf("i=%d UniqueId[c]=%c\n",c, UniqueId[c]);
-			c++;
-		}
-		UniqueId[c] = '\0';*/
-		//printf("UniqueId=%s\n",UniqueId);
-
 		if(UniqueId[0] == '\0')
 		{
 			return;
@@ -154,69 +134,30 @@ void ReceivedMessage(void *in, size_t len)
 		switch (MsgType)
 		{
 			case MESSAGE_TYPE_CALL:
-				//DEBUG_INFO("MESSAGE_TYPE_CALL\n");
-				/*
-				c = 0;
-				while (tempin[4+4+strlen(UniqueId)-1+c] != '\"')
-				{
-					Action[c] = tempin[4+4+strlen(UniqueId)-1+c];
-					//printf("i=%d Action[c]=%c\n",c, Action[c]);
-					c++;
-				}
-				Action[c] = '\0';*/
 				sprintf(Action, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 2)));
-				//printf("Action=%s\n",Action);
-				/*
-				c = 0;
-				templen= 4+4+3+strlen(UniqueId)-1+strlen(Action)-1;
-				while ((c+ templen) < (strlen(tempin)-1))
-				{
-					Payload[c] = tempin[templen + c];
-					//printf("i=%d Payload[c]=%c\n",c, Payload[c]);
-					c++;
-				}
-				Payload[c] = '\0';*/
-
-				//printf("Payload=%s\n",Payload);
 				sprintf(Payload, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 3)));
 			   	CallHandler(UniqueId,Action,Payload);
 			   	break;
 
 			case MESSAGE_TYPE_CALLRESULT:
-				/*
-			   	c = 0;
-			   	templen= 4+3+strlen(UniqueId)-1;
-			   	while ((c+ templen) < (strlen(tempin)-1))
-			   	{
-			   		Payload[c] = tempin[templen + c];
-			   		//printf("i=%d sstr=%c\n",c, Payload[c]);
-			   		c++;
-			   	}
-			   	Payload[c] = '\0';*/
 				sprintf(Payload, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 2)));
-			   	//printf("Payload=%s\n",Payload);
 
-			   	if(hashmap_operation(HASH_OP_GET, UniqueId, key_value) == TRUE)//if(hashmap_operation(1,NULL/*hashMap*/, UniqueId, mapItem, key_value/*(void**)(&mapItem)*/) ==  MAP_OK/*hashmap_get(hashMap, UniqueId, (void**)(&mapItem)) == MAP_OK*/)
+			   	if(hashmap_operation(HASH_OP_GET, UniqueId, key_value) == TRUE)
 			   	{
-			   		hashmap_operation(HASH_OP_REMOVE, UniqueId, key_value);//hashmap_operation(2,NULL/*hashMap*/, UniqueId, mapItem, key_value/*(void**)(&mapItem)*/);//hashmap_remove(hashMap, UniqueId);
-			   		char * const testdup  = strdup(key_value/*mapItem->key_value*/);
-
-			   		//printf("original string: %s (@%p)\n", testdup, testdup);
+			   		hashmap_operation(HASH_OP_REMOVE, UniqueId, key_value);
+			   		char * const testdup  = strdup(key_value);
 
 			   		substr = strtok(testdup, del);
-			   		while (substr != NULL) {
-			   				arr[count] = substr;
-			   			//	printf(" arr string: %s (@%p)\n", arr[count], substr);
-			   			//	printf("#%d sub string: %s (@%p)\n", count++, substr, substr);
-			   				count++;
-			   				substr = strtok(NULL, del);
+			   		while (substr != NULL)
+			   		{
+						arr[count] = substr;
+						count++;
+						substr = strtok(NULL, del);
 			   		}
 
 		            i=0;
 			   		sprintf(Action, "%s", *(arr+i++));
-
 			   		gun_index = atoi(*(arr+i++));
-
 			   		CallResultHandler(Action, Payload, gun_index);
 			   		free(testdup);
 			   	}
@@ -224,66 +165,26 @@ void ReceivedMessage(void *in, size_t len)
 			   	break;
 
 		   case MESSAGE_TYPE_CALLERROR:
-			   //DEBUG_INFO("MESSAGE_TYPE_CALLERROR\n");
-			   /*
-			   c = 0;
-			   while (tempin[4+4+strlen(UniqueId)-1+c] != '\"')
-			   {
-				   ErrorCode[c] = tempin[4+4+strlen(UniqueId)-1+c] ;
-				  // printf("i=%d sstr=%c\n",c, ErrorCode[c]);
-				   c++;
-			   }
-			   ErrorCode[c] = '\0';*/
-
 			   sprintf(ErrorCode, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 2)));
-			  // DEBUG_INFO("ErrorCode=%s\n",ErrorCode);
-			   /*
-			   c = 0;
-			   while (tempin[4+4+4+strlen(UniqueId)-1+strlen(ErrorCode)-1+c] != '\"')
-			   {
-				   ErrorDescription[c] = tempin[4+4+4+strlen(UniqueId)-1+strlen(ErrorCode)-1+c];
-				   //printf("i=%d sstr=%c\n",c, ErrorDescription[c]);
-				   c++;
-			   }
-			   ErrorDescription[c] = '\0';*/
 			   sprintf(ErrorDescription, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 3)));
+			   sprintf(Payload, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 4)));
 
-			  // DEBUG_INFO("ErrorDescription=%s\n",ErrorDescription);
-
-			   /*
-			   c = 0;
-			   templen= 4+4+4+3+strlen(UniqueId)-1+strlen(ErrorCode)-1+strlen(ErrorDescription)-1;
-			   while ((c+ templen) < (strlen(tempin)-1))
+			   if(hashmap_operation(HASH_OP_GET, UniqueId, key_value) == TRUE)
 			   {
-				   Payload[c] = tempin[templen + c];
-				  // printf("i=%d sstr=%c\n",c, Payload[c]);
-				   c++;
+				   hashmap_operation(HASH_OP_REMOVE, UniqueId, key_value);
+				   sprintf(Action, "%s", key_value);
+				   CallErrorHandler(UniqueId,ErrorCode, ErrorDescription, "");
 			   }
-			   Payload[c] = '\0';*/
-			   sprintf(Payload, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 4)));
-			  // DEBUG_INFO("Payload=%s\n",Payload);
-
-
-
-			   if(hashmap_operation(HASH_OP_GET, UniqueId, key_value) == TRUE)//if(hashmap_operation(1,NULL/*hashMap*/, UniqueId, mapItem, key_value/*(void**)(&mapItem)*/) ==  MAP_OK/*hashmap_get(hashMap, UniqueId, (void**)(&mapItem)) == MAP_OK*/)
-				{
-				   hashmap_operation(HASH_OP_REMOVE, UniqueId, key_value);//hashmap_operation(2,NULL/*hashMap*/, UniqueId, mapItem, key_value/*(void**)(&mapItem)*/);//hashmap_remove(hashMap, UniqueId);
-
-					sprintf(Action, "%s", key_value/*mapItem->key_value*/);
 
-					CallErrorHandler(UniqueId,ErrorCode, ErrorDescription, "");
-				}
-
-				break;
+			   break;
 
 			default:
-
 				break;
 		}
 	}
 	else
 	{
-		printf("Message is null. cant parse messgae. \n");
+		DEBUG_WARN("Message is null. cant parse messgae.\n");
 	}
 }
 
@@ -292,7 +193,6 @@ int CallHandler(char *uuid, char *str1,char *payload)
 	static int CallHandlerNumber = 0;
     static int CallHandlerIndex = 0;
     int (*callfptr)(char *uuid,char *payload);
-    //DEBUG_INFO("enter CallHandler\n");
 	CallHandlerNumber = sizeof(requestNames)/sizeof(requestNames[0]);
 	for(int i= 0; i < CallHandlerNumber ; i ++ )
 	{
@@ -301,27 +201,23 @@ int CallHandler(char *uuid, char *str1,char *payload)
 			CallHandlerIndex = i ;
 			break;
 		}
-
 	}
 
 	callfptr = NULL;
 	callfptr = funcalls[CallHandlerIndex];
 
 	if(callfptr == NULL)
-	{
-		//printf("callfptr is null\n");
-	}
+	{}
 
 	if ( callfptr )
 	{
-		//printf("exec CallHandler ... \n");
 		callfptr(uuid, payload);
 		callfptr = NULL;
 		return PASS;
 	}
 
 	callfptr = NULL;
-	 return FAIL;
+	return FAIL;
 }
 
 void CallResultHandler(char *str1, char *payload, int gun_index)
@@ -329,7 +225,7 @@ void CallResultHandler(char *str1, char *payload, int gun_index)
 	static int CallResultHandlerNumber = 0;
 	static int CallResultHandlerIndex = 0;
 	void (*callResultfptr)(char *payload, int gun_index );
-	//printf("enter CallResultHandler\n");
+
 	CallResultHandlerNumber = sizeof(responseNames)/sizeof(responseNames[0]);
 	for(int i= 0; i < CallResultHandlerNumber ; i ++ )
 	{
@@ -338,16 +234,13 @@ void CallResultHandler(char *str1, char *payload, int gun_index)
 			CallResultHandlerIndex = i ;
 			break;
 		}
-
 	}
 
 	callResultfptr = NULL;
 	callResultfptr = funs[CallResultHandlerIndex];
 
 	if(callResultfptr == NULL)
-	{
-		//printf("callResultfptr is null\n");
-	}
+	{}
 
 	if ( callResultfptr )
 	{
@@ -363,17 +256,13 @@ void CallErrorHandler(char *id, char *errorCode, char *errorDescription,char *pa
 	callErrorfptr = NULL;
 	callErrorfptr = funcallerror[0];
 
-	//printf("CallErrorHandler \n");
-
 	if(callErrorfptr == NULL)
 	{
-		printf("callErrorfptr is null\n");
+		DEBUG_ERROR("callErrorfptr is null\n");
 	}
 
 	if ( callErrorfptr )
 	{
-		//printf("callErrorfptr is not null\n");
-
 		callErrorfptr(id, errorCode, errorDescription, payload);
 	}
 

+ 1 - 1
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -10881,7 +10881,7 @@ void handleHeartbeatResponse(char *payload, int gun_index)
 
 		diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
 
-		printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
+		DEBUG_INFO("handleHeartbeatResponse differnt time=%f..\n",diff_t);
 
 		if(((int)diff_t / 3600) > HeartBeatCountPerHour)
 		{

+ 149 - 190
EVSE/Modularization/ocppfiles/hashmap.c

@@ -7,44 +7,38 @@
 #include "Module_OcppBackend.h"
 
 typedef enum boolean { FALSE, TRUE } BOOL;
-static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
-
+static pthread_mutex_t mutexMap = PTHREAD_MUTEX_INITIALIZER;
 
 int MessageSent_add(char *uuid, char *data)
 {
+	int result = PASS;
 	FILE *outfile;
 	char rmFileCmd[100]={0};
-	struct stat stats;
 	char tempstring[100]={0};
+	struct stat stats;
 
 	stat("/Storage/OCPP", &stats);
-	// Check for directory existence
 	if (S_ISDIR(stats.st_mode) == 1)
-	{
-		//printf("\n directory exist \n");
-	}
+	{}
 	else
 	{
-		printf("\n directory not exist, create dir \n");
+		DEBUG_INFO("/Storage/OCPP directory not exist, create dir \n");
 		sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 		system(rmFileCmd);
 	}
 
 	memset(&rmFileCmd, 0, sizeof rmFileCmd);
-
-	if((access("/Storage/OCPP/MessageSent",F_OK))!=-1)
-	{
-		//printf("MessageSent exist.\n");
-	}
+	if((access("/Storage/OCPP/MessageSent",F_OK)) != -1)
+	{}
 	else
 	{
-		printf("MessageSent not exist\n");
+		DEBUG_INFO("/Storage/OCPP/MessageSent not exist\n");
 		FILE *log = fopen("/Storage/OCPP/MessageSent", "w+");
 
 		if(log == NULL)
 		{
-			printf("Can't Create File MessageSent \n");
-			return 0;
+			DEBUG_ERROR("Can't Create File /Storage/OCPP/MessageSent \n");
+			result = FAIL;
 		}
 		else
 		{
@@ -53,21 +47,23 @@ int MessageSent_add(char *uuid, char *data)
 	}
 
 	// open file for writing
-	outfile = fopen ("/Storage/OCPP/MessageSent", "a");
-	sprintf(tempstring,"%s,%s\n", uuid,data);
-	fputs(tempstring, outfile);
-	fclose (outfile);
-	//printf("MessageSent add\n");
-	return 1;
+	if(result != FAIL)
+	{
+		outfile = fopen ("/Storage/OCPP/MessageSent", "a");
+		sprintf(tempstring,"%s,%s\n", uuid,data);
+		fputs(tempstring, outfile);
+		fclose (outfile);
+	}
+
+	return result;
 }
 
 int MessageSent_get(char *uuid, char *data)
 {
+	int result = PASS;
 	FILE *fp;
-	int result = FALSE; // 1: TRUE  0:FALSE
 	char str[1200]={0};
-	char sstr[50]={ 0 }, datastr[30]={0};//sstr[200]={ 0 };
-	//int pos = 0, l = 0, c = 0;
+	char sstr[50]={ 0 }, datastr[30]={0};
 	int c = 0;
 	char *loc;
 	char rmFileCmd[100]={0};
@@ -76,31 +72,27 @@ int MessageSent_get(char *uuid, char *data)
 
 	// Check for directory existence
 	if (S_ISDIR(stats.st_mode) == 1)
-	{
-		//printf("\n directory exist \n");
-	}
+	{}
 	else
 	{
-		printf("\n directory not exist, create dir \n");
+		DEBUG_INFO("/Storage/OCPP directory not exist, create dir \n");
 		sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
 		system(rmFileCmd);
 	}
 
 	memset(&rmFileCmd, 0, sizeof rmFileCmd);
 
-	if((access("/Storage/OCPP/MessageSent",F_OK))!=-1)
-	{
-		//printf("MessageSent exist.\n");
-	}
+	if((access("/Storage/OCPP/MessageSent",F_OK)) != -1)
+	{}
 	else
 	{
-		printf("MessageSent not exist\n");
+		DEBUG_INFO("/Storage/OCPP/MessageSent not exist\n");
 		FILE *log = fopen("/Storage/OCPP/MessageSent", "w+");
 
 		if(log == NULL)
 		{
-			printf("Can't Create File MessageSent \n");
-			return 0;
+			DEBUG_ERROR("Can't Create File /Storage/OCPP/MessageSent \n");
+			result = FAIL;
 		}
 		else
 		{
@@ -108,211 +100,178 @@ int MessageSent_get(char *uuid, char *data)
 		}
 	}
 
-
-	/* opening file for reading */
-	fp = fopen("/Storage/OCPP/MessageSent" , "r");
-	if(fp == NULL) {
-		printf("Error opening file");
-		return FALSE;
-	}
-
-	c = fgetc(fp);
-	//printf("c:%d\n",c);
-	rewind(fp);
-
-	if(c == EOF)
-	{
-		printf("MessageSent is null\n");
-		//strcpy(uuid,"");
-		strcpy(data,"");
-		result = FALSE;
-	}
-	else
+	if(result != FAIL)
 	{
-		result = FALSE;
-		while (fgets (str, 1200, fp)!=NULL)
+		/* opening file for reading */
+		fp = fopen("/Storage/OCPP/MessageSent" , "r");
+		if(fp == NULL)
 		{
-			//printf("Orignal File get strings \n");
-			str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
-
-			/* writing content to stdout */
-			//puts(str);
-			//printf("str[0]=%c\n",str[0]);
-
-			/*********************uuid***************/
-			int d = 0;
-			while (str[d] != ',')
-			{
-				sstr[d] = str[d];
-				d=d+ 1;
-			}
-			sstr[d] = '\0';
-
-			//printf("sstr=%s\n",sstr);
-			//printf("uuid=%s\n",uuid);
+			DEBUG_ERROR("Error opening /Storage/OCPP/MessageSent\n");
+			result = FAIL;
+		}
 
-			if(strcmp(sstr, uuid) == 0)
+		c = fgetc(fp);
+		rewind(fp);
+		if(c == EOF)
+		{
+			DEBUG_INFO("/Storage/OCPP/MessageSent is null\n");
+			strcpy(data,"");
+			result = FAIL;
+		}
+		else
+		{
+			result = FAIL;
+			while (fgets (str, 1200, fp)!=NULL)
 			{
-				//printf("\n uuid:%s compare all right!!! ", sstr);
+				str[strlen(str) - 1] = '\0';
 
-				loc = strstr(str, ",");
-				memset(sstr ,0, sizeof(sstr) );
-				int e = 0;
-				while (loc[1+e] != '\0')
+				/*********************uuid***************/
+				int d = 0;
+				while (str[d] != ',')
 				{
-					datastr[e] = loc[1+e];
-					e++;
+					sstr[d] = str[d];
+					d=d+ 1;
 				}
-				datastr[e] = '\0';
+				sstr[d] = '\0';
 
-				//printf("\n data:%s", datastr);
-				//strcpy(uuid,sstr);
-				strcpy(data,datastr);
-				result = TRUE;
-				break;
+				if(strcmp(sstr, uuid) == 0)
+				{
+					loc = strstr(str, ",");
+					memset(sstr ,0, sizeof(sstr) );
+					int e = 0;
+					while (loc[1+e] != '\0')
+					{
+						datastr[e] = loc[1+e];
+						e++;
+					}
+					datastr[e] = '\0';
+					strcpy(data,datastr);
+					result = PASS;
+					break;
+				}
 			}
-
-
 		}
+		fclose(fp);
 	}
 
-
-	fclose(fp);
 	return result;
-
 }
 
 int MessageSent_remove(char *uuid, char *data)
 {
-char tempfile[] = "/Storage/OCPP/temp1.json";
-FILE *infile;
-FILE *outfile;
-int  resultRename=0;
-char filename[60]={0};
-char rmFileCmd[100]={0};
-char tempstring[100]={0};
-struct stat stats;
-stat("../Storage/OCPP", &stats);
-
-// Check for directory existence
-if (S_ISDIR(stats.st_mode) == 1)
-{
-	//printf("\n directory exist \n");
-}
-else
-{
-	printf("\n directory not exist, create dir \n");
-	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
-	system(rmFileCmd);
-}
-
-memset(&rmFileCmd, 0, sizeof rmFileCmd);
-
-if((access("/Storage/OCPP/MessageSent",F_OK))!=-1)
-{
-	//printf("MessageSent exist.\n");
-}
-else
-{
-	printf("MessageSent not exist\n");
-	FILE *log = fopen("/Storage/OCPP/MessageSent", "w+");
+	int result = PASS;
+	char tempfile[] = "/Storage/OCPP/temp1.json";
+	FILE *infile;
+	FILE *outfile;
+	int  resultRename=0;
+	char filename[60]={0};
+	char rmFileCmd[100]={0};
+	char tempstring[100]={0};
+	struct stat stats;
+	stat("/Storage/OCPP", &stats);
 
-	if(log == NULL)
-	{
-		printf("log is NULL\n");
-		return 0;
-	}
+	// Check for directory existence
+	if (S_ISDIR(stats.st_mode) == 1)
+	{}
 	else
 	{
-		fclose(log);
+		DEBUG_INFO("/Storage/OCPP directory not exist, create dir \n");
+		sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
+		system(rmFileCmd);
 	}
-}
 
+	memset(&rmFileCmd, 0, sizeof rmFileCmd);
 
-sprintf(tempstring,"%s,%s", uuid,data);
+	if((access("/Storage/OCPP/MessageSent",F_OK)) != -1)
+	{}
+	else
+	{
+		DEBUG_INFO("/Storage/OCPP/MessageSent not exist\n");
+		FILE *log = fopen("/Storage/OCPP/MessageSent", "w+");
 
-// open file for writing
-strcpy(filename, "/Storage/OCPP/MessageSent");
-infile = fopen ("/Storage/OCPP/MessageSent", "r");
-outfile = fopen (tempfile, "w");
+		if(log == NULL)
+		{
+			DEBUG_INFO("/Storage/OCPP/MessageSent is NULL\n");
+			result = FAIL;
+		}
+		else
+		{
+			fclose(log);
+		}
+	}
 
-/*璉�瘚��辣蝏������1嚗�����0��*/
-//DEBUG_INFO("feof(infile) =%d\n",feof(infile));
-int c;
-c = fgetc(infile);
-//printf("file c:%d\n",c);
-rewind(infile);
+	if(result != FAIL)
+	{
+		sprintf(tempstring,"%s,%s", uuid,data);
 
-if(c == EOF)
-{
-	printf("MessageSent is  NULL\n");
+		// open file for writing
+		strcpy(filename, "/Storage/OCPP/MessageSent");
+		infile = fopen ("/Storage/OCPP/MessageSent", "r");
+		outfile = fopen (tempfile, "w");
 
-	fclose(infile);
-	fclose(outfile);
+		int c;
+		c = fgetc(infile);
+		rewind(infile);
 
-	sprintf(rmFileCmd,"rm -f %s",tempfile);
-	system(rmFileCmd);
-}
-else
-{
-	char buf[1200]={0};
+		if(c == EOF)
+		{
+			DEBUG_INFO("/Storage/OCPP/MessageSent is  NULL\n");
 
-	//int i = 0;
-	//printf("Orignal File is not NULL\n");
-	while (fgets(buf, sizeof(buf), infile) != NULL)
-	{
-		//printf("Orignal File get strings \n");
-		buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
+			fclose(infile);
+			fclose(outfile);
 
-		//printf("buf=%s\n",buf);
-		//printf("tempstring=%s\n",tempstring);
-		//if(i != 0)
-		if(strcmp(tempstring, buf)== 0)
-		{
-			//printf("Remove OK ! \n");
+			sprintf(rmFileCmd,"rm -f %s",tempfile);
+			system(rmFileCmd);
 		}
 		else
 		{
-			fprintf(outfile,"%s\n", buf);
-		}
+			char buf[1200]={0};
 
-		//i = i + 1;
-	}
+			while (fgets(buf, sizeof(buf), infile) != NULL)
+			{
+				buf[strlen(buf) - 1] = '\0';
 
-	fclose(infile);
-	fclose(outfile);
+				if(strcmp(tempstring, buf)== 0)
+				{}
+				else
+				{
+					fprintf(outfile,"%s\n", buf);
+				}
+			}
 
-	sprintf(rmFileCmd,"rm -f %s",filename);
-	system(rmFileCmd);
+			fclose(infile);
+			fclose(outfile);
 
-	resultRename = rename(tempfile, filename);
+			sprintf(rmFileCmd,"rm -f %s",filename);
+			system(rmFileCmd);
 
-	if(resultRename == 0)
-	{
-		//printf("File renamed successfully");
-	}
-	else
-	{
-		printf("Error: unable to rename the file");
-	}
-}
+			resultRename = rename(tempfile, filename);
 
-return 0;
+			if(resultRename == 0)
+			{}
+			else
+			{
+				DEBUG_ERROR("Error: unable to rename the file");
+				result = FAIL;
+			}
+		}
+	}
 
+	return result;
 }
 
 int hashmap_operation(int type, char *uuid, char *data)
 {
-	pthread_mutex_lock(&m);
+	pthread_mutex_lock(&mutexMap);
 	int result=0;
-
 	if(type == HASH_OP_ADD)
 		result = MessageSent_add(uuid, data);
 	else if(type  == HASH_OP_GET)
 		result = MessageSent_get(uuid,data);
 	else if(type == HASH_OP_REMOVE)
 		result = MessageSent_remove(uuid, data);
-	pthread_mutex_unlock(&m);
+	pthread_mutex_unlock(&mutexMap);
+
 	return result;
 }
 

+ 22 - 12
EVSE/Projects/AW-CCS/Apps/CCS/Module_CCS.c

@@ -2401,7 +2401,9 @@ int MmeProcess(unsigned char *Buffer, int DataLength)
     struct MmeHeader *MmePacket;
     static unsigned char counter;
     unsigned char state = 0;
+#if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
     unsigned char tmpBuf[2048]={0};
+#endif
     int Rtn = 0;
 #if(NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
     int idx = 0;
@@ -3920,7 +3922,10 @@ int SlacComm()
     int packet_size = 0;
     int count = 0;
     //int idx = 0;
+#if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
     unsigned char tmpBuf[2048]={0};
+#endif
+
 #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
     unsigned char *EvMac_in;
     unsigned char *RunID_in;
@@ -6521,7 +6526,7 @@ GLOBAL VARIABLES:
 int Proc_iso1_ServiceDiscoveryReq(int AcceptFd)
 {
     int errn = 0;
-    DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_iso1_ServiceDiscoveryReq]Got ServiceDiscoveryReq\n");
+    DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_iso1_ServiceDiscoveryReq]Got ServiceDiscoveryReq\n");
 
     //Print the decoded XML Document
     PRINT_XML_DOC_ISO1_ServiceDiscoveryReq(&ccs_exi_doc_ISO1);
@@ -7154,7 +7159,7 @@ int Proc_iso1_AuthorizationRes(int AcceptFd)
         #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
         {
             //Set PWM as 5% (for SLAC first case)
-            SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Set PWM as 5%%");
+            SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Set PWM as 5%");
             SwitchCpStateE(DISABLE);
             OutputCpPwmDuty(5);
         }
@@ -7236,7 +7241,7 @@ GLOBAL VARIABLES:
 int Proc_iso1_AuthenticationReq(int AcceptFd)
 {
     int errn = 0;
-    DEBUG_PRINTF_EVCOMM_DETAIL("\n[SeccComm][Proc_iso1_AuthenticationReq]Got AuthorizationReq\n");
+    DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][Proc_iso1_AuthenticationReq]Got AuthorizationReq\n");
 
 
     //Print the decoded XML Document
@@ -7249,7 +7254,7 @@ int Proc_iso1_AuthenticationReq(int AcceptFd)
     if (errn == 0)
     {
         //send response successfully.
-        //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]AuthorizationRes");
+        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ISO1][V2G][Tx]AuthorizationRes");
     }
     else
     {
@@ -16283,19 +16288,24 @@ int SyncAcShreaMemory()
 					//========================================
 					// CCS -> CSU check
 					//========================================
-					// CP check status
-					/*
-					if(ShmCharger->gun_info[gun_index].acCcsInfo.CpSetPWMDuty != ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentPWMDuty)
-					{
-						DEBUG_INFO("acCcsInfo.CpSetPWMDuty: %d -> %d\n", ShmCharger->gun_info[gun_index].acCcsInfo.CpSetPWMDuty, ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentPWMDuty);
-						ShmCharger->gun_info[gun_index].acCcsInfo.CpSetPWMDuty = ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentPWMDuty;
-					}*/
-
 					// V2G message flow status
 					if(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus != Check_V2G_Flow_Status())
 					{
 						//DEBUG_INFO("PresentMsgFlowStatus: %d -> %d\n", ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus, Check_V2G_Flow_Status());
 						ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus = Check_V2G_Flow_Status();
+
+						switch(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus)
+						{
+							case PowerDeliveryRequestStart ... ChargingStatusResponse:
+								ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_START_MODE;
+								break;
+							case CM_SLAC_PARM_REQ ... PreChargeResponse:
+								ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_STANDBY_MODE;
+								break;
+							default:
+								ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_STOP_MODE;
+								break;
+						}
 					}
 				}
 			}

+ 1 - 1
EVSE/Projects/AW-CCS/Apps/CCS/Module_CCS.h

@@ -42,7 +42,7 @@
 #define SAVE_SYS_LOG_MSG_EVCOMM_SWITCH		ENABLE
 #define DEBUG_PRINTF_EVCOMM_SHOW			ENABLE
 #define DEBUG_PRINTF_EVCOMM_BRIEF_SHOW		ENABLE
-#define DEBUG_PRINTF_EVCOMM_DETAIL_SHOW		ENABLE
+#define DEBUG_PRINTF_EVCOMM_DETAIL_SHOW		DISABLE
 #define	DEBUG_PRINTF_EVCOMM_SYSTEM_LOG_SHOW	ENABLE
 
 

+ 1 - 1
EVSE/Projects/AW-CCS/Apps/CCS/define_ccs.h

@@ -78,7 +78,7 @@
 #define V2GT_MSG_PROTOCOL_ISO15118_2018             2    //i.e. ISO15118-20 (ISO 2)
 #define V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY          255  //for auto detect highest priority protocol
 
-#define V2GT_MSG_PROTOCOL_PREFERENCE                V2GT_MSG_PROTOCOL_DIN70121
+#define V2GT_MSG_PROTOCOL_PREFERENCE                V2GT_MSG_PROTOCOL_ISO15118_2014
 #define CCS_ENERGY_TRANSFER_MODE                    MODE_AC_THREE_PHASE_CORE
                                                     //DC: MODE_DC_EXTENDED (default)
                                                     //AC: MODE_AC_SINGLE_PHASE_CORE, MODE_AC_THREE_PHASE_CORE

+ 4 - 16
EVSE/Projects/AW-CCS/Apps/LCM/Module_LcmControl.c

@@ -75,22 +75,10 @@ int StoreLogMsg(const char *fmt, ...)
 	tm=localtime(&CurrentTime);
 	gettimeofday(&tv, NULL); // get microseconds, 10^-6
 
-	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
-	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_LcmSystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
-					buffer,
-					tm->tm_year+1900,tm->tm_mon+1,
-					ShmSysConfigAndInfo->SysConfig.ModelName,
-					ShmSysConfigAndInfo->SysConfig.SerialNumber);
-	}
-	else
-	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld] - %s\" >> /Storage/SystemLog/[%04d.%02d]LcmSystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
-					buffer,
-					tm->tm_year+1900,tm->tm_mon+1);
-	}
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld] - %s\" >> /Storage/SystemLog/[%04d.%02d]Module_LcmControl",
+						tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+						buffer,
+						tm->tm_year+1900,tm->tm_mon+1);
 
 #ifdef SystemLogMessage
 	system(Buf);

+ 21 - 1
EVSE/Projects/AW-CCS/Apps/Makefile

@@ -36,7 +36,27 @@ EXI_ENGINE= CCS/v2g/api/api.c \
 	    CCS/Module_CCS.c
 
 all: CopyFile apps
-apps: Module_InternalComm_Task Module_FactoryConfig_Task Module_AlarmDetect_Task Module_CSU_Task Module_Speaker_Task Module_CCS_Task Module_LcmControl_Task
+apps: Module_InternalComm_Task Module_FactoryConfig_Task Module_AlarmDetect_Task Module_CSU_Task Module_Speaker_Task Module_CCS_Task Module_LcmControl_Task Module_ConfigTools_Task Module_Debug_Task
+
+Module_ConfigTools_Task:
+	@echo "===== Module_ConfigTools_Task  ==================================="
+	rm -f Module_ConfigTools
+	rm -f Module_InternalComm
+	$(CC) -D $(Project) "-I../../" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_ConfigTools.o "./Module_ConfigTools.c"
+	$(CC) -o Module_ConfigTools Module_ConfigTools.o
+	rm -f *.o
+	mv -f Module_ConfigTools ../Images/root
+	@echo \
+
+Module_Debug_Task:
+	@echo "===== Module_Debug_Task  ==================================="
+	rm -f Module_Debug
+	rm -f Module_Debug
+	$(CC) -D $(Project) "-I../../" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_Debug.o "./Module_Debug.c"
+	$(CC) -o Module_Debug Module_Debug.o
+	rm -f *.o
+	mv -f Module_Debug ../Images/root
+	@echo \
 
 Module_InternalComm_Task:
 	@echo "===== Module_InternalComm_Task ==================================="

+ 566 - 0
EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c

@@ -0,0 +1,566 @@
+/*
+ * Module_ConfigTools.c
+ *
+ *  Created on: 2020年6月22日
+ *      Author: foluswen
+ */
+
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+#include	<dirent.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	<stdbool.h>
+#include	<stddef.h>
+#include	<stdint.h>
+#include 	"define.h"
+
+//=================================
+// System basic sample constant
+//=================================
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+#define ARRAY_SIZE(A)					(sizeof(A) / sizeof(A[0]))
+#define PASS							1
+#define FAIL							-1
+#define YES								1
+#define NO								0
+#define ON								1
+#define OFF								0
+#define MtdBlockSize 					0x600000
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData			*ShmStatusCodeData;
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]ConfigToolsLog",
+				tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+				buffer,
+				tm->tm_year+1900,tm->tm_mon+1);
+
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
+
+	return rc;
+}
+
+int runShellCmd(const char*cmd)
+{
+	int result = FAIL;
+	char buf[256];
+	FILE *fp;
+
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			DEBUG_INFO("%s\n", buf);
+		}
+
+		result = PASS;
+	}
+	pclose(fp);
+
+	return result;
+}
+
+int StoreUsrConfigData(struct SysConfigData *UsrData)
+{
+	int result = PASS;
+	int fd,wrd;
+	unsigned int i,Chk;
+	unsigned char *ptr, *BufTmp;
+
+	Chk=0;
+	ptr=(unsigned char *)UsrData;
+	if((BufTmp=malloc(MtdBlockSize))!=NULL)
+	{
+		memset(BufTmp,0,MtdBlockSize);
+		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
+		for(i=0;i<MtdBlockSize-4;i++)
+			Chk+=*(BufTmp+i);
+		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
+
+		// Output configuration to file.
+		fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
+		if (fd < 0)
+		{
+			DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
+
+			free(BufTmp);
+			return 0;
+		}
+		wrd=write(fd, BufTmp, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
+
+			free(BufTmp);
+			return 0;
+		}
+		DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
+
+
+		DEBUG_INFO("Erase /dev/mtd10.\n");
+		runShellCmd("flash_erase /dev/mtd10 0 12");
+		DEBUG_INFO("Write /dev/mtd10.\n");
+		runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
+
+		DEBUG_INFO("Erase /dev/mtd11.\n");
+		runShellCmd("flash_erase /dev/mtd11 0 12");
+		DEBUG_INFO("Write /dev/mtd11.\n");
+		runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
+
+
+		system("rm -f /mnt/EvseConfig.bin");
+		DEBUG_INFO("EvseConfig write to flash OK\n");
+	}
+	else
+	{
+		DEBUG_ERROR("alloc BlockSize NG\r\n");
+    		result = FAIL;
+	}
+
+	if(BufTmp!=NULL)
+		free(BufTmp);
+
+	return result;
+}
+
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//Initial ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//Initial ShmStatusCodeData
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	return result;
+}
+
+int main(void)
+{
+	char cmd[128];
+
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO("InitShareMemory OK.\r\n");
+	}
+
+
+	for(;;)
+	{
+		system("clear");
+		memset(cmd, 0x00, ARRAY_SIZE(cmd));
+		printf("\n ===== main menu ===================================");
+		printf("\n  system: system configuration menu.");
+		printf("\n  ocpp: ocpp configuration menu.");
+		printf("\n  network: netwok configuration menu.");
+		printf("\n  upgrade: trigger firmware upgrade.");
+		printf("\n  save: Save config.");
+		printf("\n  exit: Exit config tools.");
+		printf("\n =================================================");
+		printf("\n  Please input item name to config: ");
+		scanf("%s", &cmd[0]);
+
+
+		if(strcmp(cmd, "system") == 0)
+		{
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n ***** system configuration menu ******************");
+			printf("\n  modelname: EVSE model name.");
+			printf("\n  serialnumber: EVSE serial number.");
+			printf("\n *************************************************");
+			printf("\n  Please input operation item: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "modelname") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current model name: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new model name.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n Please input model name: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.ModelName[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ModelName[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "serialnumber") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current serial number: %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new serial number.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n Please input serial number: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], (char*)&cmd[0]);
+				}
+			}
+		}
+		else if(strcmp(cmd, "ocpp") == 0)
+		{
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n *************************************************");
+			printf("\n  ocppurl: OCPP backend server url.");
+			printf("\n  cboxid: Charger box id.");
+			printf("\n *************************************************");
+			printf("\n  Please input operation item: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "ocppurl") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current OCPP url: %s", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new ocpp url.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n Please input ocpp url: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "cboxid") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current OCPP charger box id: %s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new charger box id.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input OCPP charger box id: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
+				}
+			}
+		}
+		else if(strcmp(cmd, "network") == 0)
+		{
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n *************************************************");
+			printf("\n  ethdhcp: Ethernet DHCP client.");
+			printf("\n  wifimode: WiFi mode.");
+			printf("\n  wifidhcp: WiFi DHCP client.");
+			printf("\n  wificssid: WiFi client SSID.");
+			printf("\n  wificpasswd: WiFi client password.");
+			printf("\n  telemode: Telecomm mode.");
+			printf("\n  teleapn: Telecomm APN.");
+			printf("\n  teleid: Telecomm login id.");
+			printf("\n  telepwd: Telecomm login password.");
+			printf("\n *************************************************");
+			printf("\n  Please input operation item: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "ethdhcp") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Enable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current ethernet dhcp mode: %d", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1);
+				printf("\n  Please input dhcp mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
+			}
+			else if(strcmp(cmd, "wifimode") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Station.");
+				printf("\n  2: Access point.");
+				printf("\n *************************************************");
+
+				printf("\n  Current WiFi mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
+				printf("\n  Please input WiFi mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode = ((0<=atoi(cmd))&&(atoi(cmd)<=2)?atoi(cmd):0);
+			}
+			else if(strcmp(cmd, "wifidhcp") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Enable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current WiFi dhcp client mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1);
+				printf("\n  Please input WiFi mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
+			}
+			else if(strcmp(cmd, "wificssid") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current WiFi client SSID: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new WiFi client SSID.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input WiFi client SSID: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "wificpasswd") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current WiFi client password: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new WiFi client password.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input WiFi client password: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "telemode") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Enable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current telecomm mode: %d", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode^1);
+				printf("\n  Please input telecomm mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
+			}
+			else if(strcmp(cmd, "teleapn") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current telecomm APN: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new telecomm APN.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input telecomm APN: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "teleid") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current telecomm login id: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new telecomm login id.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input telecomm login id: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "telepwd") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current telecomm login password: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new telecomm login password.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input telecomm login password: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], (char*)&cmd[0]);
+				}
+			}
+		}
+		else if(strcmp(cmd, "upgrade") == 0)
+		{
+			printf("\n  Firmware upgrade trigger.");
+
+			ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = ON;
+
+			sleep(2);
+		}
+		else if(strcmp(cmd, "save") == 0)
+		{
+			if(StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig) != PASS)
+			{
+				printf("\n  Write configuration fail.\r\n");
+			}
+			else
+				printf("\n  Write configuration OK.\r\n");
+
+			sleep(2);
+		}
+		else if(strcmp(cmd, "exit") == 0)
+		{
+			printf("\n  exit program.\n\n");
+			return FAIL;
+		}
+	}
+
+
+
+	return -1;
+}
+
+
+
+

+ 245 - 0
EVSE/Projects/AW-CCS/Apps/Module_Debug.c

@@ -0,0 +1,245 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include  	<sys/types.h>
+#include  	<sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include  	<stdio.h>
+#include  	<stdlib.h>
+#include  	<unistd.h>
+#include  	<fcntl.h>
+#include  	<termios.h>
+#include 	<errno.h>
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include	"define.h"
+#include	"main.h"
+
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				0
+#define ON					1
+#define OFF					0
+
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct Charger					*ShmCharger;
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
+	{
+		sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+					buffer,
+					tm->tm_year+1900,tm->tm_mon+1,
+					ShmSysConfigAndInfo->SysConfig.ModelName,
+					ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+					buffer,
+					tm->tm_year+1900,tm->tm_mon+1);
+	}
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
+
+	return rc;
+}
+
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//Initial ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//Initial ShmStatusCodeData
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//Initial ShmCharger
+	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+
+	return result;
+}
+
+void wait()
+{
+	printf("\n Please press any key then \"Enter\" to continue.");
+	while(getchar() =='\n') usleep(100000);
+}
+
+int main(void)
+{
+	char cmd[128];
+
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO("InitShareMemory OK.\r\n");
+	}
+
+	for(;;)
+	{
+		system("clear");
+		memset(cmd, 0x00, ARRAY_SIZE(cmd));
+		printf("\n ============== Debug main menu ==================");
+		printf("\n  info: List charger status info.");
+		printf("\n  exit: Exit Module_Debug_Test.");
+		printf("\n =================================================");
+		printf("\n  Please input debug command: ");
+		scanf("%s", &cmd[0]);
+
+		if(strcmp(cmd, "info") == 0)
+		{
+			uint8_t isExit = FALSE;
+			int gun_index;
+
+			do
+			{
+				system("clear");
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n ***************** Info menu *********************");
+				printf("\n  csu: charger info");
+				printf("\n  mcu: mcu request state");
+				printf("\n  exit: exit to previous menu.");
+				printf("\n *************************************************");
+				printf("\n  Please input info need to query: ");
+				scanf("%s", &cmd[0]);
+
+				if(strcmp(cmd, "csu") == 0)
+				{
+					printf("\n  Please input gun index: ");
+					scanf("%d", &gun_index);
+					printf("\n CSU info.\n\n");
+
+					gun_index = gun_index<AC_QUANTITY?gun_index:0;
+
+					printf("\n  Charger connector plug times: %d", ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+					printf("\n  CP positive voltage: %.2f", ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive);
+					printf("\n  CP negative voltage: %.2f", ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative);
+					printf("\n  CSU to MCU legacyRequest: %d", ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
+					printf("\n  CSU to MCU relay on request: %d", ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn);
+					printf("\n  Charger charging mode BS/HLC: %d", ShmCharger->gun_info[gun_index].chargingMode);
+					printf("\n  Charger input voltage L1: %.2f", ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
+					printf("\n  CSU output current L1: %.2f", ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
+					printf("\n  CSU temperature: %d", ShmCharger->gun_info[gun_index].temperature.point[0]);
+
+					wait();
+				}
+				else if(strcmp(cmd, "mcu") == 0)
+				{
+					printf("\n  Please input gun index: ");
+					scanf("%d", &gun_index);
+					printf("\n  MCU info.\n\n");
+
+
+
+					wait();
+				}
+				else if(strcmp(cmd, "exit") == 0)
+				{
+					printf("\n  Exit to previous.\n\n");
+					isExit = TRUE;
+				}
+			}while(!isExit);
+		}
+		else if(strcmp(cmd, "exit") == 0)
+		{
+			printf("\n  exit program.\n\n");
+			return FAIL;
+		}
+	}
+
+	return FAIL;
+}

+ 77 - 90
EVSE/Projects/AW-CCS/Apps/Module_FactoryConfig.c

@@ -145,6 +145,26 @@ void split(char **arr, char *str, const char *del)
 	}
 }
 
+int runShellCmd(const char*cmd)
+{
+	int result = FAIL;
+	char buf[256];
+	FILE *fp;
+
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			DEBUG_INFO("%s\n", buf);
+		}
+
+		result = PASS;
+	}
+	pclose(fp);
+
+	return result;
+}
 
 //==========================================
 // Init all share memory
@@ -191,12 +211,12 @@ int InitShareMemory()
 
 void helpOutput(void)
 {
-	printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
-	printf("Generate factory default configuration value\r\n\r\n");
-	printf("OPTION:\r\n");
-	printf("	-a Write to file(/mnt) & flash\r\n");
-	printf("	-f Write to file(/mnt)\r\n");
-	printf("	-m Write to flash\r\n");
+	printf("Usage: Module_FactoryConfig [OPTION]...\n\n");
+	printf("Generate factory default configuration value\n\n");
+	printf("OPTION:\n");
+	printf("	-a Write to file(/mnt) & flash\n");
+	printf("	-f Write to file(/mnt)\n");
+	printf("	-m Write to flash\n");
 }
 
 //================================================
@@ -232,16 +252,16 @@ int main(int argc, char *argv[])
 	{
 		DEBUG_ERROR("InitShareMemory NG\n");
 
-		strcpy((char*)SysConfig.ModelName,"");
-		strcpy((char*)SysConfig.SerialNumber,"");
+		strcpy((char*)SysConfig.ModelName, "");
+		strcpy((char*)SysConfig.SerialNumber, "");
 		sleep(5);
 	}
 	else
 	{
-		memcpy((char*)SysConfig.ModelName,ShmSysConfigAndInfo->SysConfig.ModelName,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
-		memcpy((char*)SysConfig.SerialNumber,ShmSysConfigAndInfo->SysConfig.SerialNumber,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+		memcpy((char*)SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+		memcpy((char*)SysConfig.SerialNumber, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
 
-		DEBUG_INFO("InitShareMemory OK.\r\n");
+		DEBUG_INFO("InitShareMemory OK.\n");
 	}
 	
 	sprintf((char*)SysConfig.SystemId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
@@ -280,14 +300,25 @@ int main(int argc, char *argv[])
 	SysConfig.TelecomInterface.TelcomModemMode = 0;	//0: No services	1: CDMA		2: GSM/GPRS	3: WCDMA	4: GSM/WCDMA	5: TD_SCDMA		6: Unknown
 
 	// Backend configuration
+	strcpy((char*)SysConfig.OcppServerURL, "");
+	sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
 	SysConfig.BackendConnTimeout=300; 		// 300 seconds
 	SysConfig.OfflinePolicy = 2;			// 0: local list, 1: Phihong RFID tag, 2: free charging, 3: no charging
 	SysConfig.OfflineMaxChargeEnergy = 0;	// 0: Same as MaxChargeEnergy	Other: 1~65535KWH
 	SysConfig.OfflineMaxChargeDuration = 0; // 0: Same as MaxChargeDuration Other: 1~65535 minutes
-	strcpy((char*)SysConfig.OcppServerURL, "");
-	sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
 
 
+	// Customization configuration item
+	if(strstr((char*)&SysConfig.ModelName[12], "P0") != NULL)
+	{
+		strcpy((char*)SysConfig.OcppServerURL, "");
+		sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
+	}
+	else
+	{
+
+	}
+
 	// Copy default configuration to pointer
 	memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
 
@@ -297,7 +328,7 @@ int main(int argc, char *argv[])
 	{
 		Chk+=*(ptr+i);
 	}
-	memcpy(	ptr+MtdBlockSize-4,&Chk,4);
+	memcpy(ptr+MtdBlockSize-4, &Chk, 4);
 
 	/*
 	 * Parameter process
@@ -338,98 +369,54 @@ int main(int argc, char *argv[])
 	/*
 	 * Configuration bin file generate
 	 */
-	if((outType&OUTPUT_FILE)>0)
+	// Save factory default setting value to file
+	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
+	if (fd < 0)
 	{
-		// Save factory default setting value to file
-		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
-		if (fd < 0)
-		{
-
-			DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\r\n");
 
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+		DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\n");
 
-			free(ptr);
-			return 0;
-		}
+		free(ptr);
+		return 0;
+	}
+	wrd=write(fd, ptr, MtdBlockSize);
+	close(fd);
+	if(wrd<MtdBlockSize)
+	{
+		DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\n");
 
-		DEBUG_INFO("FactoryConfig write to file in /mnt OK.\r\n");
+		free(ptr);
+		return 0;
 	}
 
+	DEBUG_INFO("FactoryConfig write to file in /mnt OK.\n");
+
+
 	/*
 	 * Flash memory write
 	 */
 	if((outType&OUTPUT_FLASH)>0)
 	{
-		// Save factory default setting value to flash factory default setting block
-		fd = open("/dev/mtdblock12", O_RDWR);
-		if (fd < 0)
-		{
+		DEBUG_INFO("Erase /dev/mtd10.\n");
+		runShellCmd("flash_erase /dev/mtd10 0 12");
+		DEBUG_INFO("Write /dev/mtd10.\n");
+		runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
 
-			DEBUG_ERROR("open /dev/mtdblock12 NG\r\n");
+		DEBUG_INFO("Erase /dev/mtd11.\n");
+		runShellCmd("flash_erase /dev/mtd11 0 12");
+		DEBUG_INFO("Write /dev/mtd11.\n");
+		runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
 
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			DEBUG_ERROR("write /dev/mtdblock12 NG\r\n");
-
-			free(ptr);
-			return 0;
-		}
+		DEBUG_INFO("Erase /dev/mtd12.\n");
+		runShellCmd("flash_erase /dev/mtd12 0 12");
+		DEBUG_INFO("Write /dev/mtd12.\n");
+		runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
 
-		// Save factory default setting value to flash backup setting block
-		fd = open("/dev/mtdblock11", O_RDWR);
-		if (fd < 0)
-		{
-			DEBUG_ERROR("open /dev/mtdblock11 NG\r\n");
+		system("rm -f /mnt/FactoryDefaultConfig.bin");
 
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			DEBUG_ERROR("write /dev/mtdblock11 NG\r\n");
-
-			free(ptr);
-			return 0;
-		}
-
-		// Save factory default setting value to flash setting block
-		fd = open("/dev/mtdblock10", O_RDWR);
-		if (fd < 0)
-		{
-			DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
-
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
-
-			free(ptr);
-			return 0;
-		}
-
-		DEBUG_INFO("FactoryConfig write to flash OK\r\n");
+		DEBUG_INFO("FactoryConfig write to flash OK\n");
 	}
-
 	free(ptr);
 
-	return FAIL;
+	return PASS;
 }

+ 43 - 44
EVSE/Projects/AW-CCS/Apps/main.c

@@ -725,7 +725,8 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	//================================================
 	// Load configuration from mtdblock10
 	//================================================
-	fd = open("/dev/mtdblock10", O_RDWR);
+	system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
+	fd = open("/mnt/EvseConfig.bin", O_RDWR);
 	if (fd < 0)
 	{
 		free(buf);
@@ -770,10 +771,9 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	//================================================
 	if(ChkSum!=ChkSumOrg)
 	{
-
 		DEBUG_ERROR("Primary SysConfigData checksum NG, read backup\n");
-
-		fd = open("/dev/mtdblock11", O_RDWR);
+		system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
+		fd = open("/mnt/EvseConfig", O_RDWR);
 		if (fd < 0)
 		{
 			free(buf);
@@ -820,8 +820,8 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 		if(ChkSum!=ChkSumOrg)
 		{
 			DEBUG_WARN("backup SysConfigData checksum NG, read Factory default\n");
-
-			fd = open("/dev/mtdblock12", O_RDWR);
+			system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
+			fd = open("/mnt/EvseConfig.bin", O_RDWR);
 			if (fd < 0)
 			{
 				DEBUG_ERROR("open mtdblock12 (Factory default) NG,rebooting..\n");
@@ -880,6 +880,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
 	free(buf);
 
+	system("rm -f /mnt/EvseConfig.bin");
 	DEBUG_INFO("Load SysConfigData OK\n");
 
 	return PASS;
@@ -900,49 +901,47 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
 		for(i=0;i<MtdBlockSize-4;i++)
 			Chk+=*(BufTmp+i);
-		memcpy(	BufTmp+MtdBlockSize-4,&Chk,4);
-		fd = open("/dev/mtdblock10", O_RDWR);
-		if (fd>0)
+		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
+
+		// Output configuration to file.
+		fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
+		if (fd < 0)
 		{
-			wrd=write(fd, BufTmp, MtdBlockSize);
-			close(fd);
-			if(wrd>=MtdBlockSize)
-			{
-				fd = open("/dev/mtdblock11", O_RDWR);
-				if (fd>0)
-				{
-					wrd=write(fd, BufTmp, MtdBlockSize);
-    					close(fd);
-				   	if(wrd<MtdBlockSize)
-					{
-						DEBUG_ERROR("write /dev/mtdblock11(backup) NG\n");
-				   		result = FAIL;
-					}
-				}
-				else
-				{
-					DEBUG_ERROR("open /dev/mtdblock11(backup) NG\n");
-					result = FAIL;
-				}
-			}
-			else
-			{
-		    	DEBUG_ERROR("write /dev/mtdblock10 NG\n");
-		    	result = FAIL;
-			}
+			DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
+
+			free(BufTmp);
+			return 0;
 		}
-		else
+		wrd=write(fd, BufTmp, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
 		{
-			DEBUG_ERROR("open /dev/mtdblock10 NG\n");
-			result = FAIL;
+			DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
+
+			free(BufTmp);
+			return 0;
 		}
+		DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
+
+		DEBUG_INFO("Erase /dev/mtd10.\n");
+		runShellCmd("flash_erase /dev/mtd10 0 12");
+		DEBUG_INFO("Write /dev/mtd10.\n");
+		runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
+
+		DEBUG_INFO("Erase /dev/mtd11.\n");
+		runShellCmd("flash_erase /dev/mtd11 0 12");
+		DEBUG_INFO("Write /dev/mtd11.\n");
+		runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
+
+		system("rm -f /mnt/EvseConfig.bin");
+		DEBUG_INFO("EvseConfig write to flash OK\n");
 	}
 	else
 	{
-		DEBUG_ERROR("alloc BlockSize NG\n");
-    	result = FAIL;
+		DEBUG_ERROR("alloc BlockSize NG\r\n");
+    		result = FAIL;
 	}
-	
+
 	if(BufTmp!=NULL)
 		free(BufTmp);
 
@@ -985,8 +984,8 @@ void InitEthernet()
     //Run DHCP client if enabled
 	system("killall udhcpc");
 	system("rm -rf /etc/resolv.conf");
-	system("echo nameserver 8.8.8.8 > /etc/resolv.conf");		//Google DNS server
-	system("echo nameserver 180.76.76.76 > /etc/resolv.conf");	//Baidu DNS server
+	system("echo nameserver 8.8.8.8 >> /etc/resolv.conf");		//Google DNS server
+	system("echo nameserver 180.76.76.76 >> /etc/resolv.conf");	//Baidu DNS server
 
 	if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient==0)
 	{
@@ -1360,7 +1359,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.36.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.37.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)