Răsfoiți Sursa

[Improve][AW-CCS][main / Module_ConfigTools]

2021.08.03 / Folus Wen

Actions:
1. If CCS v2g hand shake timeout back to BS mode.
2. PWM duty control logic improvement.

Files:
1. As follow commit history

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

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 3 ani în urmă
părinte
comite
c28908ea9a
2 a modificat fișierele cu 215 adăugiri și 98 ștergeri
  1. 188 69
      EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c
  2. 27 29
      EVSE/Projects/AW-CCS/Apps/main.c

+ 188 - 69
EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c

@@ -37,14 +37,11 @@
 #include	<stddef.h>
 #include	<stdint.h>
 #include 	"define.h"
+#include 	"main.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
@@ -57,6 +54,7 @@
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData			*ShmStatusCodeData;
 struct OCPP16Data 				*ShmOCPP16Data;
+struct Charger					*ShmCharger;
 
 int StoreLogMsg(const char *fmt, ...)
 {
@@ -211,7 +209,8 @@ int InitShareMemory()
 	else
 	{}
 
-   	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0)
+	//Initial ShmOCPP16Data
+   	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
 	{
 		DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
 		result = FAIL;
@@ -224,7 +223,21 @@ int InitShareMemory()
 	else
 	{}
 
-	return result;
+	//Initial ShmCharger
+   	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
+    {
+   		DEBUG_ERROR("shmget ShmCharger NG\n");
+   		result = FAIL;
+	}
+    else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	DEBUG_ERROR("shmat ShmCharger NG\n");
+    	result = FAIL;
+   	}
+    else
+    {}
+
+   	return result;
 }
 
 int main(void)
@@ -245,7 +258,7 @@ int main(void)
 	}
 	else
 	{
-		DEBUG_INFO("InitShareMemory OK.\r\n");
+		DEBUG_INFO("InitShareMemory OK.\n");
 	}
 
 
@@ -253,7 +266,7 @@ int main(void)
 	{
 		system("clear");
 		memset(cmd, 0x00, ARRAY_SIZE(cmd));
-		printf("\n ===== main menu ===================================");
+		printf("\n ===== main menu ==================================");
 		printf("\n  system: system configuration menu.");
 		printf("\n  ocpp: ocpp configuration menu.");
 		printf("\n  network: netwok configuration menu.");
@@ -261,7 +274,7 @@ int main(void)
 		printf("\n  upgrade: trigger firmware upgrade.");
 		printf("\n  save: Save config.");
 		printf("\n  exit: Exit config tools.");
-		printf("\n =================================================");
+		printf("\n ==================================================");
 		printf("\n  Please input item name to config: ");
 		scanf("%s", &cmd[0]);
 
@@ -274,18 +287,18 @@ int main(void)
 			printf("\n  serialnumber: EVSE serial number.");
 			printf("\n  authentication: Authentication function.");
 			printf("\n  rfidendian: RFID read endian.");
-			printf("\n *************************************************");
+			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 ***** modelname **********************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -296,16 +309,17 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.ModelName[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ModelName[0], (char*)&cmd[0]);
+					DEBUG_INFO("Input model name: %s\n", ShmSysConfigAndInfo->SysConfig.ModelName);
 				}
 			}
 			else if(strcmp(cmd, "serialnumber") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** serialnumber *******************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -316,58 +330,65 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], (char*)&cmd[0]);
+					DEBUG_INFO("Input serial number: %s\n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
 				}
 			}
 			else if(strcmp(cmd, "authentication") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** authentication *****************************");
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.AuthorisationMode);
 				printf("\n  0: Enable.");
 				printf("\n  1: Disable.");
-				printf("\n *************************************************");
-
-				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.AuthorisationMode);
+				printf("\n **************************************************");
 				printf("\n  Please input authentication mode: ");
 				scanf("%s", &cmd[0]);
 
 				ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+				if(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
+					DEBUG_INFO("Authentication: Disable\n");
+				else
+					DEBUG_INFO("Authentication: Enable\n");
 			}
 			else if(strcmp(cmd, "rfidendian") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** rfidendian *********************************");
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
 				printf("\n  0: Little endian.");
 				printf("\n  1: Big endian.");
-				printf("\n *************************************************");
-
-				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
+				printf("\n **************************************************");
 				printf("\n  Please input rfid endian mode: ");
 				scanf("%s", &cmd[0]);
 
 				ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+				if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+					DEBUG_INFO("Authentication: Little endian\n");
+				else
+					DEBUG_INFO("Authentication: Big endian\n");
 			}
 		}
 		else if(strcmp(cmd, "ocpp") == 0)
 		{
 			memset(cmd, 0x00, ARRAY_SIZE(cmd));
-			printf("\n *************************************************");
+			printf("\n ***** ocpp ***************************************");
 			printf("\n  ocppurl: OCPP backend server url.");
 			printf("\n  cboxid: Charger box id.");
 			printf("\n  vender: Charger point vender.");
 			printf("\n  offlinepolicy: Charger off line policy.");
 			printf("\n  localloadbalance: Charger local load balance.");
-			printf("\n *************************************************");
+			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 ***** ocppurl ************************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -378,16 +399,17 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], (char*)&cmd[0]);
+					DEBUG_INFO("Input ocpp url: %s\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
 				}
 			}
 			else if(strcmp(cmd, "cboxid") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** cboxid *************************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -398,16 +420,17 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
+					DEBUG_INFO("Input ocpp charger box id: %s\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
 				}
 			}
 			else if(strcmp(cmd, "vender") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** vender *************************************");
 				printf("\n  Current OCPP vender: %s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
 				printf("\n  0: Keep current config.");
 				printf("\n  1: Input new charger box id.");
-				printf("\n *************************************************");
+				printf("\n **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -418,42 +441,58 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], (char*)&cmd[0]);
+					DEBUG_INFO("Input ocpp vender: %s\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
 				}
 			}
 			else if(strcmp(cmd, "offlinepolicy") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** offlinepolicy ******************************");
+				printf("\n  Current off line policy: %d", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
 				printf("\n  0: Local list.");
 				printf("\n  2: Free charging.");
 				printf("\n  3: Deny charging.");
-				printf("\n *************************************************");
-
-				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
+				printf("\n **************************************************");
 				printf("\n  Please input off line policy mode: ");
 				scanf("%s", &cmd[0]);
 
 				ShmSysConfigAndInfo->SysConfig.OfflinePolicy = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
+
+				switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
+				{
+					case 0:
+						DEBUG_INFO("Off line policy: Local list.\n");
+						break;
+					case 2:
+						DEBUG_INFO("Off line policy: Free charging.\n");
+						break;
+					case 3:
+						DEBUG_INFO("Off line policy: Deny charging.\n");
+						break;
+				}
 			}
 			else if(strcmp(cmd, "localloadbalance") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** localloadbalance ***************************");
+				printf("\n  Current local loading balance: %d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging);
 				printf("\n  0: Disable.");
 				printf("\n  1: Enable.");
-				printf("\n *************************************************");
-
-				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging);
+				printf("\n **************************************************");
 				printf("\n  Please input local load balance mode: ");
 				scanf("%s", &cmd[0]);
 
 				ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+				if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+					DEBUG_INFO("Local loading balance: Enable\n");
+				else
+					DEBUG_INFO("Local loading balance: Disable\n");
 			}
 }
 		else if(strcmp(cmd, "network") == 0)
 		{
 			memset(cmd, 0x00, ARRAY_SIZE(cmd));
-			printf("\n *************************************************");
+			printf("\n ***** network *************************************");
 			printf("\n  ethdhcp: Ethernet DHCP client.");
 			printf("\n  wifimode: WiFi mode.");
 			printf("\n  wifidhcp: WiFi DHCP client.");
@@ -463,61 +502,79 @@ int main(void)
 			printf("\n  teleapn: Telecomm APN.");
 			printf("\n  teleid: Telecomm login id.");
 			printf("\n  telepwd: Telecomm login password.");
-			printf("\n *************************************************");
+			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 ***** ethdhcp ************************************");
+				printf("\n  Current ethernet dhcp mode: %d", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1);
 				printf("\n  0: Disable.");
 				printf("\n  1: Enable.");
-				printf("\n *************************************************");
-
-				printf("\n  Current ethernet dhcp mode: %d", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1);
+				printf("\n **************************************************");
 				printf("\n  Please input dhcp mode: ");
 				scanf("%s", &cmd[0]);
 
 				ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
+				if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient)
+					DEBUG_INFO("Ethernet dhcp client: Disable\n");
+				else
+					DEBUG_INFO("Ethernet dhcp client: Enable\n");
+
 			}
 			else if(strcmp(cmd, "wifimode") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** wifimode ***********************************");
+				printf("\n  Current WiFi mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
 				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 **************************************************");
 				printf("\n  Please input WiFi mode: ");
 				scanf("%s", &cmd[0]);
 
 				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode = ((0<=atoi(cmd))&&(atoi(cmd)<=2)?atoi(cmd):0);
+				switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode)
+				{
+					case 0:
+						DEBUG_INFO("Wifi mode: Disable.\n");
+						break;
+					case 1:
+						DEBUG_INFO("Wifi mode: Station.\n");
+						break;
+					case 2:
+						DEBUG_INFO("Wifi mode: AP.\n");
+						break;
+				}
 			}
 			else if(strcmp(cmd, "wifidhcp") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** wifidhcp ***********************************");
+				printf("\n  Current WiFi dhcp client mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1);
 				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 **************************************************");
 				printf("\n  Please input WiFi mode: ");
 				scanf("%s", &cmd[0]);
 
 				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
+				if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient)
+					DEBUG_INFO("Wifi dhcp client: Disable\n");
+				else
+					DEBUG_INFO("Wifi dhcp client: Enable\n");
 			}
 			else if(strcmp(cmd, "wificssid") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** wificssid **********************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -528,16 +585,17 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], (char*)&cmd[0]);
+					DEBUG_INFO("Wifi client SSID: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
 				}
 			}
 			else if(strcmp(cmd, "wificpasswd") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** wificpasswd ********************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -548,30 +606,35 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], (char*)&cmd[0]);
+					DEBUG_INFO("Wifi client password: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
 				}
 			}
 			else if(strcmp(cmd, "telemode") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** telemode ***********************************");
 				printf("\n  0: Disable.");
 				printf("\n  1: Enable.");
-				printf("\n *************************************************");
+				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);
+				if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode)
+					DEBUG_INFO("Wifi dhcp client: Disable\n");
+				else
+					DEBUG_INFO("Wifi dhcp client: Enable\n");
 			}
 			else if(strcmp(cmd, "teleapn") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** teleapn ************************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -582,16 +645,17 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], (char*)&cmd[0]);
+					DEBUG_INFO("Telecomm APN: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
 				}
 			}
 			else if(strcmp(cmd, "teleid") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** teleid *************************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -602,16 +666,17 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], (char*)&cmd[0]);
+					DEBUG_INFO("Telecomm CHAP id: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
 				}
 			}
 			else if(strcmp(cmd, "telepwd") == 0)
 			{
 				memset(cmd, 0x00, ARRAY_SIZE(cmd));
-				printf("\n *************************************************");
+				printf("\n ***** telepwd ************************************");
 				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 **************************************************");
 				printf("\n  Please input operation item: ");
 				scanf("%s", &cmd[0]);
 
@@ -622,18 +687,20 @@ int main(void)
 
 					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd));
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], (char*)&cmd[0]);
+					DEBUG_INFO("Telecomm CHAP password: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
 				}
 			}
 		}
 		else if(strcmp(cmd, "test") == 0)
 		{
 			memset(cmd, 0x00, ARRAY_SIZE(cmd));
-			printf("\n ***** test menu ******************");
+			printf("\n ***** test menu **********************************");
 			printf("\n  start: EVSE start charging request.");
 			printf("\n  stop: EVSE stop charging request.");
 			printf("\n  auth: Authorize request.");
+			printf("\n  ccs: CCS flow status.");
 			printf("\n  cancel: return to main menu.");
-			printf("\n *************************************************");
+			printf("\n **************************************************");
 			printf("\n  Please input operation item: ");
 			scanf("%s", &cmd[0]);
 
@@ -646,6 +713,7 @@ int main(void)
 				if((0 < atoi(cmd)) && (atoi(cmd) < 3))
 				{
 					ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStart = ON;
+					DEBUG_INFO("Test start gun-%d, start charging session.\n", atoi(cmd));
 				}
 				else
 				{
@@ -661,6 +729,7 @@ int main(void)
 				if((0 < atoi(cmd)) && (atoi(cmd) < 3))
 				{
 					ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStop = ON;
+					DEBUG_INFO("Test start gun-%d, stop charging session.\n", atoi(cmd));
 				}
 				else
 				{
@@ -674,7 +743,54 @@ int main(void)
 				scanf("%s", &cmd[0]);
 
 				sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%s", cmd);
-				ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 1;
+				ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
+				DEBUG_INFO("Test authentication by %s.\n", ShmSysConfigAndInfo->SysConfig.UserId);
+			}
+			else if(strcmp(cmd, "ccs") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n  Please input gun index(1~2): ");
+				scanf("%s", &cmd[0]);
+
+				if((0 < atoi(cmd)) && (atoi(cmd) < 3))
+				{
+					uint8_t gun_index = atoi(cmd)-1;
+					memset(cmd, 0x00, ARRAY_SIZE(cmd));
+					printf("\n ***** ccs ****************************************");
+					printf("\n  ccs_hs_status: CCS hand shake status.");
+					printf("\n  cancel: return to main menu.");
+					printf("\n **************************************************");
+					printf("\n  Please input operation item: ");
+					scanf("%s", &cmd[0]);
+
+					if(strcmp(cmd, "ccs_hs_status") == 0)
+					{
+						printf("\n ***** ccs_hs_status *******************************");
+						printf("\n  Current ccs_hs_status: %d", ShmCharger->gun_info[gun_index].ccsHandshakeState);
+						printf("\n  1: HANDSHAKE_DUTY_5.");
+						printf("\n  2: HANDSHAKE_DUTY_5_CHECK.");
+						printf("\n  3: HANDSHAKE_CCS.");
+						printf("\n  4: HANDSHAKE_CP_STATE_E.");
+						printf("\n  5: HANDSHAKE_SET_MAX_CURRENT.");
+						printf("\n  6: HANDSHAKE_BS_MODE.");
+						printf("\n  7: HANDSHAKE_HLC_MODE.");
+						printf("\n **************************************************");
+						printf("\n  Please input operation item: ");
+						scanf("%s", &cmd[0]);
+
+						if((0 < atoi(cmd)) && (atoi(cmd) < 9))
+						{
+							ShmCharger->gun_info[gun_index].ccsHandshakeState = atoi(cmd);
+							DEBUG_INFO("Gun-%d CCS hand shake state: %d.\n", gun_index, ShmCharger->gun_info[gun_index].ccsHandshakeState);
+						}
+						else
+							printf("\n  Invalid hand shake state.");
+					}
+				}
+				else
+				{
+					printf("\n  Invalid input gun_index.");
+				}
 			}
 			else if(strcmp(cmd, "cancel") == 0)
 			{}
@@ -684,7 +800,7 @@ int main(void)
 			printf("\n  Firmware upgrade trigger.");
 
 			ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = ON;
-
+			DEBUG_INFO("Trigger firmware upgrade.\n");
 			sleep(2);
 		}
 		else if(strcmp(cmd, "save") == 0)
@@ -694,13 +810,16 @@ int main(void)
 				printf("\n  Write configuration fail.\r\n");
 			}
 			else
+			{
 				printf("\n  Write configuration OK.\r\n");
-
+				DEBUG_INFO("Save configuration.\n");
+			}
 			sleep(2);
 		}
 		else if(strcmp(cmd, "exit") == 0)
 		{
 			printf("\n  exit program.\n\n");
+			DEBUG_INFO("Exit configuration tools.\n");
 			return FAIL;
 		}
 	}

+ 27 - 29
EVSE/Projects/AW-CCS/Apps/main.c

@@ -4972,12 +4972,20 @@ int main(void)
 						if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
 						{
 							ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
-							ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
+
+							if(ShmCharger->isCcsEnable)
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_5;
+							else
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
 						}
 						else
 						{
 							ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
-							ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
+
+							if(ShmCharger->isCcsEnable)
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_5;
+							else
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
 						}
 						ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
 
@@ -5092,25 +5100,20 @@ int main(void)
 									//restore normal CP PWM duty
 									// Determine max charging current to MCU
 									DEBUG_INFO("Determine max charging current to MCU.\n");
+									ocpp_set_profile_req(gun_index, ON);
+									sleep(1);
+									checkChargingProfileLimit(gun_index);
 									if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
 									{
 										ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
-										if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
-										{
-											ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
-											ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
-										}
+										ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
 									}
 									else
 									{
 										ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
-										if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
-										{
-											ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
-											ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
-										}
+										ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
 									}
-									ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
+									ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
 									ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_SET_MAX_CURRENT;
 									ftime(&startTime[gun_index][TMR_IDX_BS_HLC_HANDSHAKE]);
 								}
@@ -5264,27 +5267,27 @@ int main(void)
 
 									if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > TIMEOUT_SPEC_CCS_HANDSHAKE+5000)
 									{
-										DEBUG_INFO("CCS 120 secs handshake timeout.\n");
+										DEBUG_INFO("CCS 120 secs handshake timeout, change to BS Mode...\n");
 										//Cancel CCS task negotiating
 										ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;
 										ShmCharger->gun_info[gun_index].acCcsInfo.EVSENotification = NOTIFICATION_STOP;
-										ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;
+										//ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;
+
+										if((ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission == OFF) && (ShmCharger->gun_info[gun_index].acCcsInfo.CpSetPWMDuty != CCS_PWM_DUTY_5))
+										{
+											DEBUG_INFO("Wait CCS give up negotiagting.\n");
+											ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_CP_STATE_F;
+											ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
+											ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_CP_STATE_E;
+											ShmCharger->gun_info[gun_index].chargingMode = CHARGING_MODE_BS;
+										}
 									}
 								}
 
-								if((ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty == ON) && ShmCharger->gun_info[gun_index].acCcsInfo.CpSetPWMDuty == CCS_PWM_DUTY_100)
-								{
-									ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_100;
-									ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
-									ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = OFF;
-
-									setChargerMode(gun_index, SYS_MODE_IDLE);
-								}
 								break;
 							default:
 								break;
 						}
-
 					}
 					else if(ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode)
 					{
@@ -5302,8 +5305,6 @@ int main(void)
 					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) && (ShmCharger->gun_info[gun_index].isGunPlugged == YES))
 					{
 						DEBUG_INFO("Charging gun is plugged before.\n");
-						//setChargerMode(gun_index, SYS_MODE_IDLE);
-						
 						//Cancel CCS task negotiating
 						ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
 						ShmCharger->gun_info[gun_index].acCcsInfo.EVSENotification = NOTIFICATION_STOP;
@@ -5314,9 +5315,6 @@ int main(void)
 					if((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchPresentUser(gun_index))
 					{
 						DEBUG_INFO("Use RFID card to stop handshaking.\n");
-						//setSpeaker(ON,SPEAKER_SHORT);
-						//setChargerMode(gun_index, SYS_MODE_IDLE);
-
 						//Cancel CCS task negotiating
 						ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
 						ShmCharger->gun_info[gun_index].acCcsInfo.EVSENotification = NOTIFICATION_STOP;