فهرست منبع

2020-10-07 / Eason Yang
Action
1. Rename : version and date
2. Disable : log print out

File
1. Module_Wifi.c

Version : V0.13

8009 4 سال پیش
والد
کامیت
d228d3c6dc
3فایلهای تغییر یافته به همراه822 افزوده شده و 9 حذف شده
  1. 19 9
      EVSE/Modularization/Module_Wifi.c
  2. 568 0
      EVSE/Projects/AW-Regular/Apps/Module_ConfigTools.c
  3. 235 0
      EVSE/Projects/AW-Regular/Apps/Module_Debug.c

+ 19 - 9
EVSE/Modularization/Module_Wifi.c

@@ -2,9 +2,9 @@
  *  Module_Wifi.c
  *
  *  Created on: 2020-01-14
- *  Update on: 2020-09-29
+ *  Update on: 2020-10-07
  *  Author: Jerry Wang, Eason Yang, Folus Wen
- *  Version: V0.12
+ *  Version: V0.13
  *
  *  Issue tracking:
  *  1. Set AP mode should be waiting for 30 seconds.
@@ -261,7 +261,7 @@ int isValidCheckSum(uint8_t *message);
 char *Support_InterfaceSTA[2]	= {"mlan0", "wlan0"};
 char *Support_InterfaceAP[1]	= {"uap0"};
 char *valid_Internet[2]			= {"8.8.8.8", "180.76.76.76"};
-char *Version_And_Date[2]		= {"V0.12","2020-09-29"};
+char *Version_And_Date[2]		= {"V0.13","2020-10-07"};
 int protocol_Version [] 		= {0,7,0};
 
 int StoreLogMsg(const char *fmt, ...)
@@ -2523,7 +2523,7 @@ void checkSchedule()
 			
 			if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
 			{
-				DEBUG_INFO("Schedule gun_index : [%d].\n", gun_index);
+				//DEBUG_INFO("Schedule gun_index : [%d].\n", gun_index);
 				
 				if(gun_index == 2)
 				{
@@ -2538,7 +2538,7 @@ void checkSchedule()
 					AC_GUN_IDX = 2;
 				}
 
-				DEBUG_INFO("Schedule AC_GUN_IDX : [%d].\n", AC_GUN_IDX);
+				//DEBUG_INFO("Schedule AC_GUN_IDX : [%d].\n", AC_GUN_IDX);
 				
 				for(uint8_t idx=0;idx<AC_GUN_IDX;idx++)
 				{
@@ -2552,6 +2552,7 @@ void checkSchedule()
 					}
 				}
 				
+				/*
 				DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
 				DEBUG_INFO("idxAC : [%d].\n", idxAC);
 				DEBUG_INFO("AC Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable);
@@ -2561,6 +2562,7 @@ void checkSchedule()
 				DEBUG_INFO("AC Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour, tm->tm_hour);
 				DEBUG_INFO("AC Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute, tm->tm_min);
 				DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+				*/
 				
 				switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX])
 				{
@@ -2628,7 +2630,8 @@ void checkSchedule()
 				switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index])
 				{
 					case '1' ... '6':
-					
+						
+						/*
 						DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
 						DEBUG_INFO("idxAC : [%d].\n", idxAC);
 						DEBUG_INFO("AC Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable);
@@ -2638,6 +2641,7 @@ void checkSchedule()
 						DEBUG_INFO("AC Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour, tm->tm_hour);
 						DEBUG_INFO("AC Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute, tm->tm_min);
 						DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+						*/
 						
 						// AC
 						// Check schedule start
@@ -2677,7 +2681,8 @@ void checkSchedule()
 
 						break;
 					case 'J':
-					
+						
+						/*
 						DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
 						DEBUG_INFO("idxCHAdeMO : [%d].\n", idxCHAdeMO);
 						DEBUG_INFO("CHAdeMO Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isEnable);
@@ -2687,6 +2692,7 @@ void checkSchedule()
 						DEBUG_INFO("CHAdeMO Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeHour, tm->tm_hour);
 						DEBUG_INFO("CHAdeMO Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeMinute, tm->tm_min);
 						DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+						*/
 						
 						// CHAdeMO
 						// Check schedule start
@@ -2727,7 +2733,8 @@ void checkSchedule()
 						break;
 					case 'U':
 					case 'E':
-					
+						
+						/*
 						DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
 						DEBUG_INFO("idxCCS : [%d].\n", idxCCS);
 						DEBUG_INFO("CCS Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isEnable);
@@ -2737,6 +2744,7 @@ void checkSchedule()
 						DEBUG_INFO("CCS Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeHour, tm->tm_hour);
 						DEBUG_INFO("CCS Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeMinute, tm->tm_min);
 						DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+						*/
 						
 						// CCS
 						// Check schedule start
@@ -2776,7 +2784,8 @@ void checkSchedule()
 
 						break;
 					case 'G':
-					
+						
+						/*
 						DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
 						DEBUG_INFO("idxGBT : [%d].\n", idxGBT);
 						DEBUG_INFO("GBT Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isEnable);
@@ -2786,6 +2795,7 @@ void checkSchedule()
 						DEBUG_INFO("GBT Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeHour, tm->tm_hour);
 						DEBUG_INFO("GBT Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeMinute, tm->tm_min);
 						DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+						*/
 						
 						// GBT
 						// Check schedule start

+ 568 - 0
EVSE/Projects/AW-Regular/Apps/Module_ConfigTools.c

@@ -0,0 +1,568 @@
+/*
+ * 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;
+	struct timeval tv;
+	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);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%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,tv.tv_usec,
+				buffer,
+				tm->tm_year+1900,tm->tm_mon+1);
+
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, 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;
+}
+
+
+
+

+ 235 - 0
EVSE/Projects/AW-Regular/Apps/Module_Debug.c

@@ -0,0 +1,235 @@
+#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;
+	struct timeval tv;
+	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);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_Debug",
+				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);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, 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;
+}