Преглед на файлове

2021.07.07 / Jerry Wang

Actions:
1. Merge branch 'master' into DD360Audi
2. Fixed send power cabinet PSU voltage to EV Board issue.
3. Fixed an issue where the Chiller OTP instead of the chiller gun could not be charged.
4. Fixed ReadCmdline test charging function and read/write temperature function.

Files:
1. As follow as commit history.
Jerry_Wang преди 3 години
родител
ревизия
f247fdd360
променени са 96 файла, в които са добавени 1618 реда и са изтрити 878 реда
  1. 52 27
      EVSE/Modularization/Module_4g.c
  2. 2 2
      EVSE/Modularization/Module_Wifi.c
  3. 4 4
      EVSE/Modularization/WebService.c
  4. 10 7
      EVSE/Modularization/ocpp20/MessageHandler.c
  5. 11 8
      EVSE/Modularization/ocppfiles/MessageHandler.c
  6. 1 1
      EVSE/Projects/AW-CCS/Apps/Makefile
  7. 157 18
      EVSE/Projects/AW-CCS/Apps/main.c
  8. 1 1
      EVSE/Projects/AW-CCS/Apps/main.h
  9. BIN
      EVSE/Projects/AW-CCS/Images/FactoryDefaultConfig.bin
  10. BIN
      EVSE/Projects/AW-CCS/Images/ramdisk.gz
  11. 3 3
      EVSE/Projects/AW-ChargeLab/Apps/Module_FactoryConfig.c
  12. 1 0
      EVSE/Projects/AW-ChargeLab/Apps/main.c
  13. BIN
      EVSE/Projects/AW-ChargeLab/Images/FactoryDefaultConfig.bin
  14. BIN
      EVSE/Projects/AW-ChargeLab/Images/ramdisk.gz
  15. 3 3
      EVSE/Projects/AW-Regular/Apps/Module_FactoryConfig.c
  16. 2 1
      EVSE/Projects/AW-Regular/Apps/main.c
  17. BIN
      EVSE/Projects/AW-Regular/Images/FactoryDefaultConfig.bin
  18. BIN
      EVSE/Projects/AW-Regular/Images/ramdisk.gz
  19. 11 0
      EVSE/Projects/DD360/Apps/CSU/Primary.c
  20. 25 4
      EVSE/Projects/DD360/Apps/CSU/main.c
  21. 11 11
      EVSE/Projects/DD360/Apps/CSU/main.h
  22. 2 2
      EVSE/Projects/DD360/Apps/Config.h
  23. 81 163
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  24. 30 26
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c
  25. 51 8
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  26. 95 27
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  27. BIN
      EVSE/Projects/DD360/Images/ramdisk.gz
  28. BIN
      EVSE/Projects/DD360/output/FactoryConfig
  29. BIN
      EVSE/Projects/DD360/output/Module_DoComm
  30. BIN
      EVSE/Projects/DD360/output/Module_EvComm
  31. BIN
      EVSE/Projects/DD360/output/Module_EventLogging
  32. BIN
      EVSE/Projects/DD360/output/Module_InternalComm
  33. BIN
      EVSE/Projects/DD360/output/Module_LcmControl
  34. BIN
      EVSE/Projects/DD360/output/Module_PrimaryComm
  35. BIN
      EVSE/Projects/DD360/output/ReadCmdline
  36. BIN
      EVSE/Projects/DD360/output/main
  37. 11 0
      EVSE/Projects/DD360Audi/Apps/CSU/Primary.c
  38. 25 4
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  39. 11 11
      EVSE/Projects/DD360Audi/Apps/CSU/main.h
  40. 2 2
      EVSE/Projects/DD360Audi/Apps/Config.h
  41. 81 163
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  42. 30 26
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c
  43. 51 8
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  44. 95 27
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c
  45. BIN
      EVSE/Projects/DD360Audi/Images/ramdisk.gz
  46. BIN
      EVSE/Projects/DD360Audi/output/Module_DoComm
  47. BIN
      EVSE/Projects/DD360Audi/output/Module_EvComm
  48. BIN
      EVSE/Projects/DD360Audi/output/Module_EventLogging
  49. BIN
      EVSE/Projects/DD360Audi/output/Module_InternalComm
  50. BIN
      EVSE/Projects/DD360Audi/output/Module_LcmControl
  51. BIN
      EVSE/Projects/DD360Audi/output/Module_PrimaryComm
  52. BIN
      EVSE/Projects/DD360Audi/output/ReadCmdline
  53. BIN
      EVSE/Projects/DD360Audi/output/main
  54. 11 0
      EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c
  55. 25 4
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  56. 11 11
      EVSE/Projects/DD360ComBox/Apps/CSU/main.h
  57. 2 2
      EVSE/Projects/DD360ComBox/Apps/Config.h
  58. 81 163
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c
  59. 30 26
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c
  60. 51 8
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c
  61. 95 27
      EVSE/Projects/DD360ComBox/Apps/ReadCmdline.c
  62. 127 0
      EVSE/Projects/Noodoe/Apps/Module_ConfigTools.c
  63. 92 0
      EVSE/Projects/Noodoe/Apps/Module_Debug.c
  64. 3 3
      EVSE/Projects/Noodoe/Apps/Module_FactoryConfig.c
  65. 95 1
      EVSE/Projects/Noodoe/Apps/main.c
  66. 1 0
      EVSE/Projects/Noodoe/Apps/main.h
  67. BIN
      EVSE/Projects/Noodoe/Images/FactoryDefaultConfig.bin
  68. BIN
      EVSE/Projects/Noodoe/Images/ramdisk.gz
  69. 9 0
      EVSE/rootfs/etc/init.d/rcS
  70. 24 17
      Makefile
  71. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[AW-CCS]am335x-evm.dts
  72. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[AW-ChargeLab]am335x-evm.dts
  73. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[AW-Regular]am335x-evm.dts
  74. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[Noodoe]am335x-evm.dts
  75. 2 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/Makefile
  76. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[ATE]am335x-evm.dts
  77. 2 2
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-CCS]am335x-evm.dts
  78. 2 2
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-ChargeLab]am335x-evm.dts
  79. 2 2
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-Regular]am335x-evm.dts
  80. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[CCS]am335x-evm.dts
  81. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DD360Audi]am335x-evm.dts
  82. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DD360]am335x-evm.dts
  83. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DM30]am335x-evm.dts
  84. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DO360]am335x-evm.dts
  85. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DS60-120-Infy]am335x-evm.dts
  86. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DS60-120]am335x-evm.dts
  87. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DW30]am335x-evm.dts
  88. 2 2
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Noodoe]am335x-evm.dts
  89. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[PlugIt360]am335x-evm.dts
  90. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Taurus]am335x-evm.dts
  91. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Zanobe]am335x-evm.dts
  92. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[e4you]am335x-evm.dts
  93. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
  94. 10 2
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/common/autoboot.c
  95. 63 29
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/include/configs/am335x_evm.h
  96. 1 1
      run_gen_make_script.sh

+ 52 - 27
EVSE/Modularization/Module_4g.c

@@ -82,7 +82,7 @@ void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
 
 char *portName[3] 				= {"/dev/ttyUSB2", "/dev/ttyUSB2", "/dev/ttyACM2"};
 char *valid_Internet[2] 		= {"8.8.8.8", "180.76.76.76"};
-char *Version_And_Date[2]		= {"V0.10","2021-03-16"};
+char *Version_And_Date[2]		= {"V0.11","2021-07-06"};
 pid_t	pid;
 
 struct dongle_info
@@ -95,6 +95,10 @@ struct dongle_info
 	char MODELNAME[10];
 	char REVISION[18];
 	unsigned char MODE;
+	char act[16];
+	char operator[16];
+	char band[16];
+	int channel;
 	int CSQ;
 	int cnt_InternetFail;
 	int cnt_ReadInfoFail;
@@ -414,26 +418,30 @@ int isReadInfo(void)
 				if(Length > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
-
-					strncpy(tmp, &rx[strcspn(rx,":")+2], strcspn(rx,",")-(strcspn(rx,":")+2));
-
-
-					if(strstr(tmp, "CDMA") != NULL)
-						Dongle.MODE = NET_MODE_CDMA;
-					else if((strstr(tmp, "GPRS") != NULL) || (strstr(tmp, "EDGE") != NULL))
-						Dongle.MODE = NET_MODE_GMS_GPRS;
-					else if(strstr(tmp, "WCDMA") != NULL)
-						Dongle.MODE = NET_MODE_WCDMA;
-					else if(strstr(tmp, "GSM") != NULL)
-						Dongle.MODE = NET_MODE_GSM_WCDMA;
-					else if(strstr(tmp, "TDSCDMA") != NULL)
-						Dongle.MODE = NET_MODE_TD_SCDMA;
-					else if(strstr(tmp, "LTE") != NULL)
-						Dongle.MODE = NET_MODE_LTE;
-					else if((strstr(tmp, "HSDPA") != NULL) || (strstr(tmp, "HSUPA") != NULL) || (strstr(tmp, "HSPA+") != NULL))
-						Dongle.MODE = NET_MODE_HSPA;
+					if(sscanf(rx, "%*[^:]:%[^,],%[^,],%[^,],%d", Dongle.act, Dongle.operator, Dongle.band, &Dongle.channel) == 4)
+					{
+						//strncpy(tmp, &rx[strcspn(rx,":")+2], strcspn(rx,",")-(strcspn(rx,":")+2));
+						if((strstr(Dongle.act, "GPRS") != NULL) || (strstr(Dongle.act, "EDGE") != NULL))
+							Dongle.MODE = NET_MODE_GMS_GPRS;
+						else if(strstr(Dongle.act, "WCDMA") != NULL)
+							Dongle.MODE = NET_MODE_WCDMA;
+						else if(strstr(Dongle.act, "GSM") != NULL)
+							Dongle.MODE = NET_MODE_GSM_WCDMA;
+						else if(strstr(Dongle.act, "TDSCDMA") != NULL)
+							Dongle.MODE = NET_MODE_TD_SCDMA;
+						else if(strstr(Dongle.act, "CDMA") != NULL)
+							Dongle.MODE = NET_MODE_CDMA;
+						else if(strstr(Dongle.act, "LTE") != NULL)
+							Dongle.MODE = NET_MODE_LTE;
+						else if((strstr(Dongle.act, "HSDPA") != NULL) || (strstr(Dongle.act, "HSUPA") != NULL) || (strstr(Dongle.act, "HSPA+") != NULL))
+							Dongle.MODE = NET_MODE_HSPA;
+						else
+							Dongle.MODE = NET_MODE_UNKNOWN;
+					}
 					else
-						Dongle.MODE = NET_MODE_UNKNOWN;
+					{
+						DEBUG_WARN("at+qnwinfo response can not parse.\n");
+					}
 				}
 				else
 					result = FAIL;
@@ -1264,6 +1272,9 @@ TOP:
 						DEBUG_INFO("Device IMEI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
 						DEBUG_INFO("Device RSSI: %d dBm (CSQ:%d)\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi, Dongle.CSQ);
 						DEBUG_INFO("Device MODE: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
+						DEBUG_INFO("Device Act: %s\n", Dongle.act);
+						DEBUG_INFO("Device Band: %s\n", Dongle.band);
+						DEBUG_INFO("Device Channel: %d\n", Dongle.channel);
 						DEBUG_INFO("========================================\n");
 						
 						Dongle.cnt_ReadInfoFail = 0;
@@ -1294,12 +1305,13 @@ TOP:
 								DEBUG_INFO("Status: PPP interface found...\n");
 								DEBUG_INFO("========================================\n");
 								DEBUG_INFO("PPP IP: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
+								DEBUG_INFO("Telecom network connection: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn);
 								DEBUG_INFO("========================================\n");
+								ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 1;
 
 								Dongle.cnt_pppFail = 0;
 								if(isReachableInternet() == PASS)
 								{
-									ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 1;
 									ShmStatusCodeData->AlarmCode.AlarmEvents.bits.Telecom4GModuleCommFail = 0;
 									ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 0;
 									ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi = 0;
@@ -1314,7 +1326,6 @@ TOP:
 									DEBUG_INFO("========================================\n");
 									DEBUG_INFO("Status: 4G Device connecting...\n");
 									DEBUG_INFO("========================================\n");
-									DEBUG_INFO("Network connection: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn);
 									DEBUG_INFO("Dongle internet valid result: Pass\n");
 									DEBUG_INFO("========================================\n");
 								
@@ -1330,12 +1341,11 @@ TOP:
 								{
 									DEBUG_INFO("Dongle internet valid result: Fail %d time\n", Dongle.cnt_InternetFail);
 
-									ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 0;
 									ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 1;
 									ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi = 1;
 
 									Dongle.cnt_InternetFail++;
-									if(Dongle.cnt_InternetFail > 3)
+									if((Dongle.cnt_InternetFail > 3) && !ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
 									{
 										system("killall 4GDetection");
 										system("killall pppd");
@@ -1350,6 +1360,8 @@ TOP:
 							}
 							else
 							{
+								ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 0;
+
 								if(Load4gConfiguration() == FAIL)
 								{
 									DEBUG_ERROR("4G configuration value NG.\n");
@@ -1518,9 +1530,22 @@ TOP:
 				memset(ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, 0, sizeof ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev);
 				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
 				
-				system("killall 4GDetection");
-				system("killall pppd");
-				system("ifconfig ppp0 down");
+				if(system("pidof -s 4GDetection > /dev/null") == 0)
+				{
+					DEBUG_INFO("4GDetection running, stop it.\n");
+					system("killall 4GDetection");
+				}
+
+				if(system("pidof -s pppd > /dev/null") == 0)
+				{
+					DEBUG_INFO("pppd running, stop it.\n");
+					system("killall pppd");
+				}
+
+				if(isPppUp() == PASS)
+				{
+					system("ifconfig ppp0 down");
+				}
 				
 				sleep(SystemInterval);
 				

+ 2 - 2
EVSE/Modularization/Module_Wifi.c

@@ -260,7 +260,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.18","2021-03-25"};
+char *Version_And_Date[2]		= {"V0.19","2021-07-06"};
 int protocol_Version [] 		= {0,7,0};
 
 int StoreLogMsg(const char *fmt, ...)
@@ -4540,7 +4540,7 @@ void proc_sta()
 				sleep(5);
 			}
 
-			if(cnt_pingDNS_Fail >= 3)
+			if((cnt_pingDNS_Fail >= 3) && !ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
 			{
 				ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1;
 				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0;

+ 4 - 4
EVSE/Modularization/WebService.c

@@ -2109,16 +2109,16 @@ int main(int argc, char *argv[]) {
 				DDStopDateTime[i] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.StopDateTime);
 				DDStartMethod[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.StartMethod);
 				if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp == 255){
-					ConnectorTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp);
+					DDConnectorTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp);
 				}
 				else{
-					ConnectorTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp-60);
+					DDConnectorTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp-60);
 				}
 				if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ChillerTemp == 0 || ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ChillerTemp == 255){
-					ChillerTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ChillerTemp);
+					DDChillerTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ChillerTemp);
 				}
 				else{
-					ChillerTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ChillerTemp-60);
+					DDChillerTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ChillerTemp-60);
 				}
 				DDPowerConsumption[i] = json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.PowerConsumption);
 			}

+ 10 - 7
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -8512,6 +8512,7 @@ S_FAULT                 =12
 	}
 	else
 	{
+		cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
 		result = PASS;
 	}
 
@@ -11932,6 +11933,8 @@ int handleDataTransferRequest(char *uuid, char *payload)
 		else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
 		{
 			system("/usr/bin/run_tmate_restart.sh &");
+
+			strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
 		}
 		else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
 		{
@@ -12411,11 +12414,11 @@ void* GetLogProcess(void* data)
 	pthread_detach(pthread_self());
 	mtrace();
 	int requestId, retriesInt=0, retryIntervalInt=0;
-	char logType[32], remoteLocation[512]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
-	char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
+	char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
+	char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
 	int port=0;
 	int isSuccess = FALSE;
-	char ftpbuf[200]={0};
+	char ftpbuf[1024]={0};
 	char cmdBuf[2048];
 	struct tm *tmNow;
 	time_t CurrentTime;
@@ -15500,12 +15503,12 @@ void *UpdateFirmwareProcess(void *data)
 	pthread_detach(pthread_self());
 	mtrace();
 	int retriesInt =0, retryIntervalInt=0;
-	char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
+	char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
 	int port=0;
-	char locationstr[512]={0}, retrieveDatestr[36]={0};
+	char locationstr[1024]={0}, retrieveDatestr[36]={0};
 	int isSuccess = 0;
-	char ftpbuf[512];
-	char temp[100];
+	char ftpbuf[1024];
+	char temp[1024];
 	char * pch;
 
 

+ 11 - 8
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -4401,6 +4401,7 @@ S_FAULT                 =12
 	}
 	else
 	{
+		cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
 		result = PASS;
 	}
 
@@ -8455,6 +8456,10 @@ int handleDataTransferRequest(char *uuid, char *payload)
 		else if(strstr(tempmessageId, "ID_Tmate") != NULL)
 		{
 			system("/usr/bin/run_tmate_restart.sh &");
+
+			json_object_object_add(response, "status", json_object_new_string("Accepted"));
+			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
+			json_object_put(response);
 		}
 		else if(strstr(tempmessageId, "SetLEDBar") != NULL)
 		{
@@ -8847,11 +8852,10 @@ void* GetDiagnosticsProcess(void* data)
 	pthread_detach(pthread_self());
 	mtrace();
 	int retriesInt=0, retryIntervalInt=0;
-	char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
-	char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
+	char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
+	char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
 	int port=0;
 	int isSuccess = FALSE;
-	char ftpbuf[200]={0};
 	char cmdBuf[2048];
 	struct tm *tmNow;
 	time_t CurrentTime;
@@ -9070,7 +9074,6 @@ void* GetDiagnosticsProcess(void* data)
 		memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
 		strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
 		filenametemp[i+1] = 0;
-		memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
 
 		if(port == 0)
 		   port = 21;
@@ -11784,12 +11787,12 @@ void *UpdateFirmwareProcess(void *data)
 	pthread_detach(pthread_self());
 	mtrace();
 	int retriesInt =0, retryIntervalInt=0;
-	char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
+	char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
 	int port=0;
-	char locationstr[512]={0}, retrieveDatestr[36]={0};
+	char locationstr[1024]={0}, retrieveDatestr[36]={0};
 	int isSuccess = 0;
-	char ftpbuf[512];
-	char temp[100];
+	char ftpbuf[1024];
+	char temp[1024];
 	char * pch;
 
 	DEBUG_INFO("handleUpdateFirmwareRequest ...\n");

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

@@ -129,7 +129,7 @@ Module_CCS_Task:
 Module_LcmControl_Task:
 	@echo "===== Module_LcmControl_Task ==================================="
 	rm -f Module_LcmControl
-	$(CC) -D $(Project) "-I../../../Modularization/ocppfiles/" "-I./" "-I../../" -O0 -g3 -Wall -fmessage-length=0 LCM/lcmComm_dgus.c LCM/Module_LcmControl.c -o Module_LcmControl
+	$(CC) -D $(Project) "-I../../../Modularization/ocppfiles/" "-I./" "-I../../" -O0 -g3 -Wall -fmessage-length=0 LCM/lcmComm_dgus.c LCM/Module_LcmControl.c LCM/cbmp.c -o Module_LcmControl
 	rm -f *.o	
 	mv -f Module_LcmControl ../Images/root
 

+ 157 - 18
EVSE/Projects/AW-CCS/Apps/main.c

@@ -1,10 +1,12 @@
 #include	"define.h"
 #include 	"main.h"
 
+//#define CDFA_CERTIFICATE	// Only enable for CDFA certificate to send receipt by Phihong back end API
 
 //==========================
 // System basic sample constant
 //==========================
+#define is_error(ptr) 					((unsigned long)ptr > (unsigned long)-4000L)
 #define ARRAY_SIZE(A)					(sizeof(A) / sizeof(A[0]))
 #define PASS							1
 #define FAIL							-1
@@ -1192,9 +1194,91 @@ int CreatShareMemory()
     return result;
 }
 
-//===============================================
+//======================================================
+// Call WEBAPI to mail receipt (Only for CDFA verify)
+//======================================================
+#ifdef CDFA_CERTIFICATE
+int sendReceiptMail(char *startDateTime, char *stopDateTime, char *receiptInfo)
+{
+	int result = FAIL;
+	char reciever[128];
+	char subject[128];
+	char content[8192];
+	char priceDetail[4098]={0};
+	char cmdBuf[8192];
+
+	double totalEnergy;
+	double totalPrice;
+	json_object *detailPrice = json_tokener_parse(receiptInfo);
+
+	if(!is_error(detailPrice))
+	{
+		if(json_object_object_get(detailPrice, "totalChargedEnergy") != NULL)
+			totalEnergy = json_object_get_double(json_object_object_get(detailPrice, "totalChargedEnergy"));
+
+		if(json_object_object_get(detailPrice, "totalPrice") != NULL)
+			totalPrice = json_object_get_double(json_object_object_get(detailPrice, "totalPrice"));
+
+		if(json_object_object_get(detailPrice, "receiptDetail") != NULL)
+		{
+			for(int idx=0;idx<json_object_array_length(json_object_object_get(detailPrice, "receiptDetail"));idx++)
+			{
+				sprintf(priceDetail, "%s---%02d:00, %.4f KWH @ $ %.2f = $ %.2f<br/>\n", priceDetail
+																                 , json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(detailPrice, "receiptDetail"), idx), "hour"))
+																			     , json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(detailPrice, "receiptDetail"), idx), "chargedEnergy"))
+																				 , json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(detailPrice, "receiptDetail"), idx), "unitPrice"))
+																				 , json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(detailPrice, "receiptDetail"), idx), "periodPrice")));
+			}
+		}
+
+	}
+	json_object_put(detailPrice);
+
+	// Generate mail content
+	sprintf(reciever, "folus_wen@phihong.com.tw");
+	sprintf(subject, "Charging Receipt From %s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
+	sprintf(content, "<img src=\"https://www.phihong.com/images/logo.png\"/><br/>\n"
+					 "<h1>Receipt of charging on %s</h1><br/>\n"
+					 "<b>Location Name:</b> CDFA Lab<br/>\n"
+					 "<b>Location Address:</b> xxxxxxxxxxx<br/>\n"
+					 "<b>EVSE ID:</b> %s<br/>\n"
+					 "<b>Maximum Rate of Energy Transfer:</b> 11.5 KW AC<br/>\n"
+					 "<b>Charging start date time:</b> %s<br/>\n"
+					 "<b>Charging stop date time:</b> %s<br/>\n"
+					 "<b>Energy Delivered:</b> %.4f KWH<br/>\n"
+					 "<b>Cost of Charging:</b><br/>\n"
+				     "%s"
+					 "***Total charged cost: $ %.2f<br/>\n"
+					 "<br/>\n"
+					 "<br/>\n"
+					 "%s<br/>\n"
+					 "47800 Fremont Blvd.<br/>\n"
+					 "Fremont, CA 94538, USA<br/>\n", startDateTime
+					 	 	 	 	 	 	   	    , ShmSysConfigAndInfo->SysConfig.ChargeBoxId
+													, startDateTime
+												    , stopDateTime
+												    , totalEnergy
+												    , priceDetail
+												    , totalPrice
+												    , ShmSysConfigAndInfo->SysConfig.chargePointVendor);
+
+	json_object *post = json_object_new_object();
+	json_object_object_add(post, "Receiver", json_object_new_string(reciever));
+	json_object_object_add(post, "Subject", json_object_new_string(subject));
+	json_object_object_add(post, "Body", json_object_new_string(content));
+	json_object_object_add(post, "UseHtml", json_object_new_boolean(1));
+	// Call WEBAPI
+	sprintf(cmdBuf, "curl -X POST -k -d '%s' -H \"Content-Type: application/json\" https://ocpp.phihong.com.tw:5014/api/Notification/ &", json_object_to_json_string_ext(post, JSON_C_TO_STRING_PLAIN));
+	system(cmdBuf);
+	//DEBUG_INFO("cmdBuf: %s\n", cmdBuf);
+	json_object_put(post);
+
+	return result;
+}
+#endif	/* CDFA_CERTIFICATE */
+//======================================================
 // SQLite3 related routine
-//===============================================
+//======================================================
 int getReceiptInfo(uint8_t gun_index, char *receiptInfo)
 {
 	int result = PASS;
@@ -1229,6 +1313,8 @@ int getReceiptInfo(uint8_t gun_index, char *receiptInfo)
 	sprintf(receiptInfo, "%s", json_object_to_json_string_ext(receipt, JSON_C_TO_STRING_PLAIN));
 	json_object_put(receipt);
 
+	//DEBUG_INFO("receiptInfo: %s\n", receiptInfo);
+
 	return result;
 }
 
@@ -1369,6 +1455,13 @@ int DB_Check_Record_Buf(sqlite3 *db, int gun_index)
 				{
 					DEBUG_INFO( "Copy local charging record buffer successfully\n");
 				}
+
+#ifdef CDFA_CERTIFICATE
+				// Only for CDFA certificate
+				sendReceiptMail(rs[(idxRow*cols)+4],
+								rs[(idxRow*cols)+5],
+								rs[(idxRow*cols)+10]);
+#endif /* CDFA_CERTIFICATE */
 			}
 
 			// Delete buffer
@@ -1399,6 +1492,9 @@ int DB_Update_Record_Buf(sqlite3 *db, int gun_index)
 	int result = PASS;
 	char* errMsg = NULL;
 	char sqlStr[4096];
+	char receiptInfo[2048];
+
+	getReceiptInfo(gun_index, receiptInfo);
 
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
@@ -1414,12 +1510,21 @@ int DB_Update_Record_Buf(sqlite3 *db, int gun_index)
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
 					    "Power Loss",
-					    ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+#ifdef CDFA_CERTIFICATE
+						receiptInfo);// Only for CDFA certificate
+#else
+						ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+#endif /* CDFA_CERTIFICATE */
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		sprintf(sqlStr, "insert into charging_record_buffer(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
- 					    "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%f');",
+#ifdef CDFA_CERTIFICATE
+				"values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
+#else
+				"values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%f');",
+#endif /* CDFA_CERTIFICATE */
+
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
 					    ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId,
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
@@ -1430,7 +1535,12 @@ int DB_Update_Record_Buf(sqlite3 *db, int gun_index)
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
 					    "Power Loss",
-					    ShmOCPP20Data->CostUpdated.totalCost);
+#ifdef CDFA_CERTIFICATE
+						//receiptInfo);// Only for CDFA certificate
+#else
+						ShmOCPP20Data->CostUpdated.totalCost);
+#endif /* CDFA_CERTIFICATE */
+
 	}
 
 	if(sqlite3_open(DB_FILE, &db))
@@ -1477,12 +1587,11 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
 	char receiptInfo[2048];
 
 	getReceiptInfo(gun_index, receiptInfo);
-	DEBUG_INFO("Receipt Info: %s\n", receiptInfo);
 
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		sprintf(sqlStr, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
- 					    "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
+						"values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
 					    ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
@@ -1493,12 +1602,21 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
 					    ShmOCPP16Data->StopTransaction[gun_index].StopReason,
-					    ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+#ifdef CDFA_CERTIFICATE
+						receiptInfo);// Only for CDFA certificate
+#else
+						ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+#endif /* CDFA_CERTIFICATE */
+
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		sprintf(sqlStr, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
- 					    "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%f');",
+#ifdef CDFA_CERTIFICATE
+ 					    "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
+#else
+						"values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%f');",
+#endif /* CDFA_CERTIFICATE */
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
 					    ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId,
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
@@ -1509,7 +1627,13 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
 					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
 					    ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason,
-					    ShmOCPP20Data->CostUpdated.totalCost);
+#ifdef CDFA_CERTIFICATE
+						receiptInfo);// Only for CDFA certificate
+#else
+						ShmOCPP20Data->CostUpdated.totalCost);
+#endif /* CDFA_CERTIFICATE */
+
+
 	}
 	//DEBUG_INFO("sqlStr= %s\n", sqlStr);
 
@@ -1557,6 +1681,13 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
 		sqlite3_close(db);
 	}
 
+#ifdef CDFA_CERTIFICATE
+	// Only for CDFA certificate
+	sendReceiptMail((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
+					(char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
+					receiptInfo);
+#endif
+
 	return result;
 }
 
@@ -1637,7 +1768,6 @@ int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
 	return result;
 }
 
-
 //======================================================
 // Peripheral initial
 //======================================================
@@ -4347,15 +4477,23 @@ int main(void)
 		ShmSysConfigAndInfo->SysInfo.OcppConnStatus = ocpp_get_connection_status();
 
 		//==============================================
-		// Check task processing
+		// Period check for 10 seconds
 		//==============================================
-		if(ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus != SYS_MODE_BOOTING)
-			checkTask();
+		if(DiffTimebWithNow(startTime[0][TMR_IDX_CHECK_TASK]) > 10000)
+		{
+			//==============================================
+			// Check task processing
+			//==============================================
+			if(ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus != SYS_MODE_BOOTING)
+				checkTask();
 
-		//==============================================
-		// Check connection timeout specification
-		//==============================================
-		checkConnectionTimeout();
+			//==============================================
+			// Check connection timeout specification
+			//==============================================
+			checkConnectionTimeout();
+
+			ftime(&startTime[0][TMR_IDX_CHECK_TASK]);
+		}
 
 		//==============================================
 		// Something need run in Idle mode
@@ -4372,6 +4510,7 @@ int main(void)
 					setLedMotion(gun_index,LED_ACTION_INIT);
 				}
 
+				sleep(5);
 				system("cd /root;./Module_FactoryConfig -m");
 				system("rm -f /Storage/OCPP/OCPPConfiguration");
 				system("sync");

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

@@ -221,7 +221,7 @@ enum TIMER_IDX
 	TMR_IDX_POWERSAVING_RFID,
 	TMR_IDX_POWERSAVING_METER,
 	TMR_IDX_POWERSAVING_STATE_B,
-	TMR_IDX_11,
+	TMR_IDX_CHECK_TASK,
 	TMR_IDX_12,
 	TMR_IDX_13,
 	TMR_IDX_14,

BIN
EVSE/Projects/AW-CCS/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/AW-CCS/Images/ramdisk.gz


+ 3 - 3
EVSE/Projects/AW-ChargeLab/Apps/Module_FactoryConfig.c

@@ -406,17 +406,17 @@ int main(int argc, char *argv[])
 	if((outType&OUTPUT_FLASH)>0)
 	{
 		DEBUG_INFO("Erase /dev/mtd10.\n");
-		runShellCmd("flash_erase /dev/mtd10 0 12");
+		runShellCmd("flash_erase /dev/mtd10 0 0");
 		DEBUG_INFO("Write /dev/mtd10.\n");
 		runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
 
 		DEBUG_INFO("Erase /dev/mtd11.\n");
-		runShellCmd("flash_erase /dev/mtd11 0 12");
+		runShellCmd("flash_erase /dev/mtd11 0 0");
 		DEBUG_INFO("Write /dev/mtd11.\n");
 		runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
 
 		DEBUG_INFO("Erase /dev/mtd12.\n");
-		runShellCmd("flash_erase /dev/mtd12 0 12");
+		runShellCmd("flash_erase /dev/mtd12 0 0");
 		DEBUG_INFO("Write /dev/mtd12.\n");
 		runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
 

+ 1 - 0
EVSE/Projects/AW-ChargeLab/Apps/main.c

@@ -3599,6 +3599,7 @@ int main(void)
 					setLedMotion(gun_index,LED_ACTION_INIT);
 				}
 
+				sleep(5);
 				system("cd /root;./Module_FactoryConfig -m");
 				system("rm -f /Storage/OCPP/OCPPConfiguration");
 				system("sync");

BIN
EVSE/Projects/AW-ChargeLab/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/AW-ChargeLab/Images/ramdisk.gz


+ 3 - 3
EVSE/Projects/AW-Regular/Apps/Module_FactoryConfig.c

@@ -403,17 +403,17 @@ int main(int argc, char *argv[])
 	if((outType&OUTPUT_FLASH)>0)
 	{
 		DEBUG_INFO("Erase /dev/mtd10.\n");
-		runShellCmd("flash_erase /dev/mtd10 0 12");
+		runShellCmd("flash_erase /dev/mtd10 0 0");
 		DEBUG_INFO("Write /dev/mtd10.\n");
 		runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
 
 		DEBUG_INFO("Erase /dev/mtd11.\n");
-		runShellCmd("flash_erase /dev/mtd11 0 12");
+		runShellCmd("flash_erase /dev/mtd11 0 0");
 		DEBUG_INFO("Write /dev/mtd11.\n");
 		runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
 
 		DEBUG_INFO("Erase /dev/mtd12.\n");
-		runShellCmd("flash_erase /dev/mtd12 0 12");
+		runShellCmd("flash_erase /dev/mtd12 0 0");
 		DEBUG_INFO("Write /dev/mtd12.\n");
 		runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
 

+ 2 - 1
EVSE/Projects/AW-Regular/Apps/main.c

@@ -3598,7 +3598,8 @@ int main(void)
 				{
 					setLedMotion(gun_index,LED_ACTION_INIT);
 				}
-
+				
+				sleep(5);
 				system("cd /root;./Module_FactoryConfig -m");
 				system("rm -f /Storage/OCPP/OCPPConfiguration");
 				system("sync");

BIN
EVSE/Projects/AW-Regular/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/AW-Regular/Images/ramdisk.gz


+ 11 - 0
EVSE/Projects/DD360/Apps/CSU/Primary.c

@@ -12,6 +12,17 @@
 #include "main.h"
 
 //------------------------------------------------------------------------------
+typedef struct StLedConfig {
+    //OutputDrvValue[0]
+    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
+    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
+    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+    uint8_t Reserved: 1;                        //bit 7 reserved
+} LedConfig;
 
 //------------------------------------------------------------------------------
 static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)

+ 25 - 4
EVSE/Projects/DD360/Apps/CSU/main.c

@@ -1765,9 +1765,29 @@ void RecordAlarmCode(uint8_t gunIndex, char *code)
     } else if (strcmp(code, "011020") == EQUAL) {
         ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
     } else if (strcmp(code, "012323") == EQUAL) {
-        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        if ((gunIndex == 0) &&
+                ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+                 (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
+           ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        } else if ((gunIndex == 1) &&
+                   ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+                    (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
+                  ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        }
     } else if (strcmp(code, "011038") == EQUAL) {
-        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        if ((gunIndex == 0) &&
+                ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+                 (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
+           ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        } else if ((gunIndex == 1) &&
+                   ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+                    (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
+                  ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        }
     }
 }
 
@@ -2300,7 +2320,7 @@ uint8_t isModeChange(uint8_t gunIndex)
     }
 
     pDcChargingInfo->PreviousSystemStatus = pDcChargingInfo->SystemStatus;
-    ShmDcCommonData->SystemModeChange = YES; //for Module_EvRxComm print temperature message
+    ShmDcCommonData->SystemModeChange[gunIndex] = YES; //for Module_EvRxComm print temperature message
 
     return YES;
 }
@@ -4813,7 +4833,8 @@ int main(void)
                         pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
                     }
                 } else if (isPrechargeStatus_ccs(gunIndex) == 45 ||
-                           isPrechargeStatus_ccs(gunIndex) == 46) {
+                           isPrechargeStatus_ccs(gunIndex) == 46
+                          ) {
                     setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP1);
                 }
 

+ 11 - 11
EVSE/Projects/DD360/Apps/CSU/main.h

@@ -49,17 +49,17 @@
 //#define log_error(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
-typedef struct StLedConfig {
-    //OutputDrvValue[0]
-    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
-    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
-    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
-    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
-    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
-    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
-    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
-    uint8_t Reserved: 1;                        //bit 7 reserved
-} LedConfig;
+//typedef struct StLedConfig {
+//    //OutputDrvValue[0]
+//    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+//    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+//    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
+//    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+//    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
+//    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+//    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+//    uint8_t Reserved: 1;                        //bit 7 reserved
+//} LedConfig;
 
 //------------------------------------------------------------------------------
 bool isDetectPlugin(void);

+ 2 - 2
EVSE/Projects/DD360/Apps/Config.h

@@ -362,14 +362,14 @@ typedef struct StDcCommonInfo {
     uint8_t CheckRelayStatus[6]; //check Relay welding or driving fault
     uint8_t GunRelayWeldingOccur[2];
     uint8_t GunRelayDrivingOccur[2];
-    uint8_t SystemModeChange;
+    uint8_t SystemModeChange[2]; //for Module_EvRxComm
     PowerAlarmState PowerAlarmState;
     ChillerTempErr ChillerTempErr[2];
     ChillerValve ChillerValve;
     uint8_t TestTemperature; //ReadCmdline test, manual input value
     uint8_t CcsTypeSaved[2];
     PcPsuOutput PcPsuOutput[2];
-    uint8_t Reserved[4];
+    uint8_t Reserved[3];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 81 - 163
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -281,10 +281,10 @@ static int doCommConnToServer(void)
     //    fcntl(TcpSock, F_SETFL, flag );
     //}
 
-    tv.tv_sec = 0;
-    tv.tv_usec = 100000;
-    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
-    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
+    tv.tv_sec = 3;
+    tv.tv_usec = 0;
+    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval)); //設定等待3s
+    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));  //設定傳送3s
     flag = 1;
     setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
 
@@ -1154,10 +1154,10 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
 
         ShmDcCommonData->PcPsuOutput[plugNum].Voltage = ntohs((uint16_t)pPcPsuOutput->Voltage);
         ShmDcCommonData->PcPsuOutput[plugNum].Current = ntohs((uint16_t)pPcPsuOutput->Current);
-        log_info("%d ower cabinet PSU output vol = %d, cur = %d\r\n",
-                 plugNum,
-                 ShmDcCommonData->PcPsuOutput[plugNum].Voltage,
-                 ShmDcCommonData->PcPsuOutput[plugNum].Current);
+        //log_info("%d power cabinet PSU output vol = %f, cur = %f\r\n",
+        //         plugNum,
+        //         (float)ShmDcCommonData->PcPsuOutput[plugNum].Voltage,
+        //         (float)ShmDcCommonData->PcPsuOutput[plugNum].Current);
         break;
 
     case REG_QRCODE_URL_INFO:
@@ -1361,17 +1361,6 @@ static int readMiscCommand(int fd, uint8_t id)
 
 static int readChargePermission(int fd, uint8_t id)
 {
-    //int ret = PASS;
-
-    //if ((ret = composeSocketData(fd,
-    //                             id,
-    //                             OP_READ_DATA,
-    //                             REG_CHARGING_PERMISSION,
-    //                             0,
-    //                             NULL)) == FAIL) {
-    //    return ret;
-    //}
-
     return composeSocketData(fd,
                              id,
                              OP_READ_DATA,
@@ -1645,95 +1634,6 @@ static int CheckNetworkStatus(void)
     return 0;
 }
 
-#if 0
-static int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
-{
-    uint8_t index = 0;
-
-    for (index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (pSysInfo->ChademoChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (index = 0; index < CCS_QUANTITY; index++) {
-        if (pSysInfo->CcsChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (index = 0; index < GB_QUANTITY; index++) {
-        if (pSysInfo->GbChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-static int InitShareMemory(void)
-{
-    int result = 1;
-    int MeterSMId = 0;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        log_error("shmget ShmSysConfigAndInfo NG\n");
-        result = 0;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("[shmat ShmSysConfigAndInfo NG\n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        log_error("shmget ShmStatusCodeData NG\n");
-        result = 0;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmStatusCodeData NG\n");
-        result = 0;
-    }
-
-    //creat ShmPsuData
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-        log_error("shmget ShmPsuData NG \n");
-        result = 0;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmPsuData NG \n");
-        result = 0;
-    }
-
-    //creat ShmOCPP16Data
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
-        log_error("shmget ShmOCPP16Data NG \n");
-        result = 0;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmOCPP16Data NG \n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        log_error("shmget ShmPrimaryMcuData NG\n");
-        result = 0;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmPrimaryMcuData NG\n");
-        result = 0;
-    }
-
-    //creat Audi customization info
-    if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
-        log_error("[main]CreatShareMemory:shmget select gun info NG \n");
-        return 0;
-    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
-        return 0;
-    }
-
-    return result;
-}
-#endif //0
-
 static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
 {
     bool canUpdateFirmware = true;
@@ -1787,7 +1687,7 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
 #else
     gunID = ID_REGISTER;
 
-    ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0;
+    ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0; //非Audi 不需要等待主櫃回報餘額
 #endif // DD360Audi
 
     if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == YES) ||
@@ -1964,7 +1864,9 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 
         case REG_QRCODE_URL_INFO:
             if (gunID == 1) {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10)) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
+                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
+                   ) {
                     readQRcodeURLAndSystemDate(fd);
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
@@ -2026,13 +1928,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10)) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
+           ) {
             writeWaitPlugItState(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
@@ -2040,13 +1946,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_PREPARNING: //get permission
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) < 0
+           ) {
             writeConnectorState(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CONNECTOR_STATE]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) && readChargingCapability(fd, gunID)) {
                 for (i = 0; i < totalGun; i++) {
                     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
@@ -2059,7 +1969,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2067,13 +1979,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_PREPARING_FOR_EV://wait connector lock
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2084,7 +2000,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2096,13 +2014,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         writeChargingTarget(fd, plugNum, gunID);
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2113,7 +2035,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2122,13 +2046,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CHARGING: //charging
     case S_TERMINATING:
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2141,7 +2069,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         writeChargingTarget(fd, plugNum, gunID);
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2149,7 +2079,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_COMPLETE:
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
@@ -2222,17 +2154,6 @@ int main(int argc, char *argv[])
     InitSocketSigPipe();
 
     /**************** Initialization **********/
-    /*if (InitShareMemory() == 0) {
-        if (ShmStatusCodeData != NULL) {
-            pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = YES;
-        }
-
-        log_error("DoComm Initial share memory fail\r\n");
-        sleep(5);
-
-        return 0;
-    }
-    */
     if (CreateAllCsuShareMemory() == FAIL) {
         log_error("create share memory error\r\n");
         return FAIL;
@@ -2254,16 +2175,13 @@ int main(int argc, char *argv[])
     totalConnCount = pSysConfig->TotalConnectorCount;
 
     for (index = 0; index < totalConnCount; index++) {
-        //if (!FindChargingInfoData(index, &ChargingData[0])) {
-        //    log_error("FindChargingInfoData false \n");
-        //    break;
-        //}
         clearPricesInfo(index);
     }
 
     //initial trigger message timer
     for (index = 0; index < MAX_REGISTER_NUM; index++) {
         ftime(&gRegTimeUp[0][index]);
+        usleep(128);
         ftime(&gRegTimeUp[1][index]);
         usleep(50000);
     }
@@ -2280,8 +2198,9 @@ int main(int argc, char *argv[])
             gunID = 0;
             for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
                 //checkAuthorProcess(fd, plugNum);
-                //plugNum = setup chargingData value for bottom layer
-                //gunID = (plugNum  + 1); //connector Id, 1 = left gun, 2 = right gun
+
+                //plugNum : setup chargingData value for bottom layer
+                //gunID : connector Id from power cabinet, 1 = left gun, 2 = right gun,
                 gunID = gDoCommGblData.ConnectorID[plugNum];
                 systemStatusProcess(fd, totalConnCount, plugNum, gunID);
 
@@ -2296,33 +2215,32 @@ int main(int argc, char *argv[])
             }
         }
 
-        if (initDone == DISPENSER_SOCKET_RECONN) {
-            //system("udhcpc -r eth0");
-            log_info("Disconnected from power cabinet...re-connecting");
-            setTcpStatus(ABNORMAL);
-
+        if (initDone != DISPENSER_SOCKET_RECONN) {
+            //update dispenser firmware
+            updateFirmwareProcess(fd, gDoCommGblData.ConnectorID[0], totalConnCount);
 
-            if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
-                sprintf(tmpbuf,
-                        "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
-                        pSysConfig->SystemId);
-                system(tmpbuf);
-            }
+            usleep(100000);
+            continue;
+        }
 
-            gDoCommGblData.DisConnCount = 0;
-            gDoCommGblData.SeqNum = 0;
+        //Ethernet error recovery handle
+        log_info("Disconnected from power cabinet...re-connecting");
+        setTcpStatus(ABNORMAL);
 
-            closeSocket(fd);
-            fd = 0;
 
-            initDone = DISPENER_INIT_FAIL;
+        if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
+            sprintf(tmpbuf,
+                    "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
+                    pSysConfig->SystemId);
+            system(tmpbuf);
         }
 
-        //update dispenser firmware
-        if (initDone != DISPENER_INIT_FAIL) {
-            updateFirmwareProcess(fd, gDoCommGblData.ConnectorID[0], totalConnCount);
-        }
+        gDoCommGblData.DisConnCount = 0;
+        gDoCommGblData.SeqNum = 0;
+
+        closeSocket(fd);
+        fd = 0;
 
-        usleep(100000);
+        initDone = DISPENER_INIT_FAIL;
     }
 }

+ 30 - 26
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -205,8 +205,10 @@ void CANReceiver(int fd)
         uint8_t targetGun = 0x00;
         uint8_t gunTypeIndex = 0;
         uint8_t ver[16] = {0};
-        uint8_t sameChillerTemp = NO;
-        uint8_t sameConnTemp = NO;
+        uint8_t printChillerTemp = NO;
+        uint8_t printConnTemp = NO;
+        uint8_t maxChillerTemp = 0;
+        uint8_t maxConnTemp = 0;
         struct can_frame frame;
         ChillerTemp chiilerTemp = {0};
         struct ChargingInfoData *pDcChargingInfo = NULL;
@@ -226,8 +228,6 @@ void CANReceiver(int fd)
         log_info("Module_EvRXComm Child's PID is %d\r\n", getpid());
 
         while (isContinue) {
-            sameChillerTemp = NO;
-            sameConnTemp = NO;
             memset(&frame, 0, sizeof(struct can_frame));
 
             nbytes = read(fd, &frame, sizeof(struct can_frame));
@@ -430,18 +430,18 @@ void CANReceiver(int fd)
             case ACK_GET_EV_BATTERY_INFO:
                 //_chargingData[target].EvACorDCcharging = frame.data[0];
                 //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
-                pDcChargingInfo->EvBatteryMaxVoltage = (((short) frame.data[4] << 8) + (short) frame.data[3]) / 10;
+                pDcChargingInfo->EvBatteryMaxVoltage = ((float)(((uint16_t)frame.data[4] << 8) + (uint16_t)frame.data[3])) / 10;
                 //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
                 //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
                 if (pDcChargingInfo->Type == _Type_Chademo) {
-                    ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
                     ShmCHAdeMOData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
 
                     //log_info("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
                     //log_info("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
                     //log_info("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
                 } else if (pDcChargingInfo->Type == _Type_GB) {
-                    ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
                     ShmGBTData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
                 }
                 //else if (pDcChargingInfo->Type == _Type_CCS_2) {
@@ -450,7 +450,7 @@ void CANReceiver(int fd)
 
             case ACK_GET_MISCELLANEOUS_INFO:
                 pDcChargingInfo->GunLocked = frame.data[0];
-                pDcChargingInfo->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+                pDcChargingInfo->PilotVoltage = ((float)(-120 + frame.data[3])) / 10;
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
                     ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
@@ -472,40 +472,44 @@ void CANReceiver(int fd)
                     break;
                 }
 
+                printChillerTemp = NO;
+                printConnTemp = NO;
+
                 if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
                     getChillerTemperature(&chiilerTemp);
-                    if (getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]) == (pDcChargingInfo->ChillerTemp + 3)) {
-                        sameChillerTemp = YES;
+                    maxChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
+
+                    if ((maxChillerTemp - 3) >= pDcChargingInfo->ChillerTemp) {
+                        printChillerTemp = YES;
                     }
 
                     pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
                 }
 
-                if (getMaxConnectTemp(frame.data[1], frame.data[2]) == (pDcChargingInfo->ConnectorTemp + 3)) {
-                    sameConnTemp = YES;
+                maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
+                if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
+                    printConnTemp = YES;
                 }
 
                 pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
 
                 //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
-                if (((sameConnTemp == YES) ||
-                        (sameChillerTemp == YES)) &&
-                        (ShmDcCommonData->SystemModeChange == YES) ||
-                        (((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
-                          (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
-                         ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
-                          (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
+                if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
+                        (printConnTemp == YES) ||
+                        (printChillerTemp == YES) //&&
+                        //(((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
+                        //  (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
+                        // ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
+                        //  (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
                    ) {
-                    ShmDcCommonData->SystemModeChange = NO;
-                    log_info("Conn %d Temp 0= %d, Temp 1 = %d, chillerTemp1 = %d, chillerTemp2 = %d\r\n",
+                    ShmDcCommonData->SystemModeChange[targetGun] = NO;
+                    log_info("Conn %d max head temp %d, max chiller = %d\r\n",
                              targetGun,
-                             frame.data[1],
-                             frame.data[2],
-                             chiilerTemp.Temp[0],
-                             chiilerTemp.Temp[1]);
+                             maxConnTemp,
+                             maxChillerTemp);
                 }
 
-                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) == NO) {
+                if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
                     //沒有水冷槍
                     break;
                 }

+ 51 - 8
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -421,6 +421,20 @@ static void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
     }
 }
 
+static uint8_t waitPsuVolwithRealyVol(uint8_t gunIndex)
+{
+    PcPsuOutput *pPcPsuOutput = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[gunIndex];
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+    int vol = 0;
+
+    vol = abs(pPcPsuOutput->Voltage - pDcChargingInfo->FireChargingVoltage);
+    if (vol <= 10) {
+        return YES;
+    }
+
+    return NO;
+}
+
 /**
  * [SetPresentChargingOutputFromPcPsu 充電狀態讀取電源櫃PSU輸出電壓電流,縮小誤差值]
  * @Author   Jerry
@@ -432,23 +446,29 @@ static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
     float vol2 = 0, cur2 = 0;
     PcPsuOutput *pPcPsuOutput0 = NULL;
     PcPsuOutput *pPcPsuOutput1 = NULL;
+    struct ChargingInfoData *chargingData0 = NULL;
+    struct ChargingInfoData *chargingData1 = NULL;
 
     switch (gunCount) {
     case 1:
         pPcPsuOutput0 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
+        chargingData0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
         break;
 
     case 2:
         pPcPsuOutput0 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[1];
+        chargingData0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData1 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
         break;
     }
 
-    vol1 = (((float)pPcPsuOutput0->Voltage) * 0.1);
-    cur1 = (((float)pPcPsuOutput0->Current) * 0.1);
-    vol2 = (((float)pPcPsuOutput1->Voltage) * 0.1);
-    cur2 = (((float)pPcPsuOutput1->Current) * 0.1);
+    vol1 = (((float)pPcPsuOutput0->Voltage));
+    cur1 = (chargingData0->PresentChargingCurrent * 10);//(((float)pPcPsuOutput0->Current) * 0.1);
+    vol2 = (((float)pPcPsuOutput1->Voltage));
+    cur2 = (chargingData1->PresentChargingCurrent * 10);//(((float)pPcPsuOutput1->Current) * 0.1);
 
     if (
         (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
@@ -461,9 +481,9 @@ static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
         (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
     ) {
         log_info("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f\r\n",
-                 vol1 / 10,
+                 vol1,
                  cur1 / 10,
-                 vol2 / 10,
+                 vol2,
                  cur2 / 10);
 
         LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
@@ -621,6 +641,17 @@ static void FormatVoltageAndCurrent(void)
     }
 }
 
+static int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+    //return milli-second
+    unsigned int StartTime, StopTime;
+
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
+}
+
 int main(int argc, char *argv[])
 {
     bool chkChademoPermission[2] = {false};
@@ -637,6 +668,8 @@ int main(int argc, char *argv[])
     struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
     time_t rtc = {0};
     struct ChargingInfoData *pDcChargingInfo = NULL;
+    struct timeb waitChargingTime;
+    struct timeb nowTime;
 
     if (CreateAllCsuShareMemory() == FAIL) {
         log_error("create share memory error\r\n");
@@ -928,9 +961,14 @@ int main(int argc, char *argv[])
                         SetEvsePrechargeInfo(gunIndex, PRECHARGE_PRERELAY_PASS, pDcChargingInfo->Evboard_id);
                     }
                 }
+                ftime(&waitChargingTime);
                 break;
 
             case S_CHARGING:
+                //if (waitPsuVolwithRealyVol(gunIndex) == NO) {
+                //    continue;
+                //}
+
                 // 計算 Power
                 pDcChargingInfo->PresentChargingPower =
                     ((float)((pDcChargingInfo->PresentChargingVoltage) *
@@ -959,8 +997,13 @@ int main(int argc, char *argv[])
                 GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
 
                 // 設定當前輸出
-                //SetPresentChargingOutputPower();
-                SetPresentChargingOutputFromPcPsu(pSysConfig->TotalConnectorCount);
+                ftime(&nowTime);
+                if (DiffTimeb(waitChargingTime, nowTime) < 3000 ||
+                        DiffTimeb(waitChargingTime, nowTime) < 0) {
+                    SetPresentChargingOutputPower();
+                } else {
+                    SetPresentChargingOutputFromPcPsu(pSysConfig->TotalConnectorCount);
+                }
 
                 // for test end
                 if (priorityLow % 5 == 0) {

+ 95 - 27
EVSE/Projects/DD360/Apps/ReadCmdline.c

@@ -89,6 +89,17 @@ static struct ChargingInfoData *pAcChargingInfo = NULL;
 static char newString[8][16] = {0};
 
 //------------------------------------------------------------------------------
+static int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+    //return milli-second
+    unsigned int StartTime, StopTime;
+
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
+}
+
 static void get_char(char *word)
 {
     fd_set rfds;
@@ -325,7 +336,7 @@ void GetFwVerProc(void)
                      "      help | ? | h\n";
 
     while (isContinue) {
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
             continue;
         }
 
@@ -672,6 +683,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     uint8_t gunIndex = 0;
     uint8_t stopChg = 0;
     uint8_t curGun = 0;
+    int isContinue = 1;
     float _Voltage;
     float _Current;
     uint8_t PreviousSystemStatus[2] = {0xff};
@@ -679,7 +691,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                      "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
                      "       chg    <voltage> <current>            ex: chg 500 100\n"
                      "       c      <index>                        ex: c 0\n"
-                     "       help | ? | h\n";
+                     "       help | ? | h\n"
+                     "\r\n";
 
     if (strcmp(v1, "auto") == EQUAL) {
         _usingAutoRun = 0x01;
@@ -710,7 +723,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     pSysInfo->CurGunSelected = _GunIndex;
 
-    while (true) {
+    while (isContinue) {
+
         curGun = pSysInfo->CurGunSelected;
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
 
@@ -912,8 +926,9 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 if (PreviousSystemStatus[gunIndex] == 0xFF) {
                     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-
                     pDcChargingInfo->SystemStatus = S_IDLE;
+                } else {
+                    pSysInfo->CurGunSelected = gunIndex;
                 }
 
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
@@ -928,6 +943,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             if (stopChg == pSysConfig->TotalConnectorCount) {
                 system("/root/Module_EvComm &");
                 sleep(3);
+
+                for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+                    pDcChargingInfo->SystemStatus = S_IDLE;
+                }
                 return;
             }
             break;
@@ -1021,29 +1042,71 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     }
 }
 
+int printTimeMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256] = {0};
+    char buffer[4096] = {0};
+    int rc = -1;
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    va_start(args, fmt);
+    rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+            tm->tm_hour,
+            tm->tm_min,
+            tm->tm_sec,
+            SeqEndTime.millitm,
+            buffer);
+    printf("%s", Buf);
+
+    return rc;
+}
+
 static void resdGunAndChillerTemp(void)
 {
     int isContinue = 1;
     uint8_t i = 0;
-    uint8_t sleepTime = 3;
+    uint32_t sleepTime = 500000;
+    uint32_t loopTime = 1000;
+    struct timeb showTime;
+    struct timeb nowTime;
+
     char *usageMsg = "Usage:\n"
                      "       t <index>: loop time, ex: t 1\n"
                      "       exit | c | C: exit test\n"
-                     "       h | help | ?: show usage message\n";
+                     "       h | help | ?: show usage message\n"
+                     "\r\n";
+
+    ftime(&showTime);
 
     while (isContinue) {
-        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        ftime(&nowTime);
 
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+        if (DiffTimeb(showTime, nowTime) > loopTime ||
+                DiffTimeb(showTime, nowTime) < 0) {
+            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
 
-            printf("get %d gun temp = %d, chiller temp = %d\r\n",
-                   i,
-                   pDcChargingInfo->ConnectorTemp,
-                   pDcChargingInfo->ChillerTemp);
-        }//for
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                printTimeMsg("get %d gun temp = %d, chiller temp = %d\r\n",
+                             i,
+                             pDcChargingInfo->ConnectorTemp,
+                             pDcChargingInfo->ChillerTemp);
+            }//for
+            ftime(&showTime);
+        }
 
         if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
-            sleep(sleepTime);
+            usleep(sleepTime);
             continue;
         }
 
@@ -1056,15 +1119,17 @@ static void resdGunAndChillerTemp(void)
                 continue;
             }
 
-            sleepTime = atoi((char *)newString[1]);
-
+            loopTime = ((atoi((char *)newString[1])) * 1000);
+            printf("loopTime = %d\r\n", loopTime);
+            ftime(&showTime);
+            continue;
         } else if (exitCmd() == YES) {
             return;
         } else if (helpCmd() == YES) {
             printf ("%s\n", usageMsg);
         }
 
-        sleep(sleepTime);
+        usleep(sleepTime);
     }//while
 }
 
@@ -1072,18 +1137,19 @@ static void writeGunAndChillerTemp(void)
 {
     uint8_t _GunIndex = 0;
     int isContinue = 1;
-    uint8_t sleepTime = 3;
+    uint32_t sleepTime = 500000;
     char *usageMsg = "Usage:\n"
                      "       conn    <index> <temp>, ex: conn 0 150\n"
                      "       chiller <index> <temp>, ex: chiller 0 150\n"
                      "       tempR\n"
                      "       exit | c | C\n"
-                     "       help | ? | h\n";
+                     "       help | ? | h\n"
+                     "\r\n";
 
     ShmDcCommonData->TestTemperature = YES;
 
     while (isContinue) {
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
             sleep(sleepTime);
             continue;
         }
@@ -1095,6 +1161,8 @@ static void writeGunAndChillerTemp(void)
             ShmDcCommonData->TestTemperature = NO;
             sleep(1);
             return;
+        } else if (strcmp(newString[0], "tempR") == 0) {
+            resdGunAndChillerTemp();
         }
 
         if ((strcmp(newString[0], "chiller") != 0) &&
@@ -1105,7 +1173,8 @@ static void writeGunAndChillerTemp(void)
             continue;
         }
 
-        if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) {
+        if (atoi(newString[2]) > 255 ||
+                atoi(newString[2]) == -1) {
             printf("temperature value overflow\r\n");
             continue;
         }
@@ -1134,11 +1203,9 @@ static void writeGunAndChillerTemp(void)
             printf("set %d connector temp = %d\r\n",
                    _GunIndex,
                    pDcChargingInfo->ConnectorTemp);
-        } else if (strcmp(newString[0], "tempR") == 0) {
-            resdGunAndChillerTemp();
         }
 
-        sleep(1);
+        usleep(sleepTime);
     }//while
 }
 
@@ -1154,7 +1221,7 @@ int main(void)
                      "       sysid                             : test system ID\n"
                      "       self                              : self test state (x)\n"
                      "       version | v | -v                  : version of board (407 or relay or other)\n"
-                     "       update                            : update firmware"
+                     "       update                            : update firmware\n"
                      "       ac                                : get ac relay state (x) \n"
                      "       cable <index> <state>             : set ground fault state\n"
                      "       pow <index> <power>               : set power value\n"
@@ -1164,7 +1231,8 @@ int main(void)
                      "       strchg <auto>                     : auto test charging\n"
                      "       strchg <index> <voltage <current> : select gun test charging\n"
                      "       tempW                             : write connector header and Chiller temperature\r\n"
-                     "       tempR                             : print connector header and chiller temperature\r\n";
+                     "       tempR                             : print connector header and chiller temperature\r\n"
+                     "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
         printf("create share memory error\r\n");
@@ -1332,7 +1400,7 @@ int main(void)
         } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
             resdGunAndChillerTemp();
         } else {
-            printf ("%s\n", usageMsg);
+            printf("%s\n", usageMsg);
         }
 
         sleep(1);

BIN
EVSE/Projects/DD360/Images/ramdisk.gz


BIN
EVSE/Projects/DD360/output/FactoryConfig


BIN
EVSE/Projects/DD360/output/Module_DoComm


BIN
EVSE/Projects/DD360/output/Module_EvComm


BIN
EVSE/Projects/DD360/output/Module_EventLogging


BIN
EVSE/Projects/DD360/output/Module_InternalComm


BIN
EVSE/Projects/DD360/output/Module_LcmControl


BIN
EVSE/Projects/DD360/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360/output/ReadCmdline


BIN
EVSE/Projects/DD360/output/main


+ 11 - 0
EVSE/Projects/DD360Audi/Apps/CSU/Primary.c

@@ -12,6 +12,17 @@
 #include "main.h"
 
 //------------------------------------------------------------------------------
+typedef struct StLedConfig {
+    //OutputDrvValue[0]
+    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
+    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
+    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+    uint8_t Reserved: 1;                        //bit 7 reserved
+} LedConfig;
 
 //------------------------------------------------------------------------------
 static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)

+ 25 - 4
EVSE/Projects/DD360Audi/Apps/CSU/main.c

@@ -1765,9 +1765,29 @@ void RecordAlarmCode(uint8_t gunIndex, char *code)
     } else if (strcmp(code, "011020") == EQUAL) {
         ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
     } else if (strcmp(code, "012323") == EQUAL) {
-        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        if ((gunIndex == 0) &&
+                ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+                 (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
+           ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        } else if ((gunIndex == 1) &&
+                   ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+                    (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
+                  ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        }
     } else if (strcmp(code, "011038") == EQUAL) {
-        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        if ((gunIndex == 0) &&
+                ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+                 (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
+           ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        } else if ((gunIndex == 1) &&
+                   ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+                    (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
+                  ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        }
     }
 }
 
@@ -2300,7 +2320,7 @@ uint8_t isModeChange(uint8_t gunIndex)
     }
 
     pDcChargingInfo->PreviousSystemStatus = pDcChargingInfo->SystemStatus;
-    ShmDcCommonData->SystemModeChange = YES; //for Module_EvRxComm print temperature message
+    ShmDcCommonData->SystemModeChange[gunIndex] = YES; //for Module_EvRxComm print temperature message
 
     return YES;
 }
@@ -4813,7 +4833,8 @@ int main(void)
                         pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
                     }
                 } else if (isPrechargeStatus_ccs(gunIndex) == 45 ||
-                           isPrechargeStatus_ccs(gunIndex) == 46) {
+                           isPrechargeStatus_ccs(gunIndex) == 46
+                          ) {
                     setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP1);
                 }
 

+ 11 - 11
EVSE/Projects/DD360Audi/Apps/CSU/main.h

@@ -49,17 +49,17 @@
 //#define log_error(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
-typedef struct StLedConfig {
-    //OutputDrvValue[0]
-    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
-    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
-    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
-    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
-    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
-    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
-    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
-    uint8_t Reserved: 1;                        //bit 7 reserved
-} LedConfig;
+//typedef struct StLedConfig {
+//    //OutputDrvValue[0]
+//    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+//    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+//    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
+//    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+//    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
+//    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+//    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+//    uint8_t Reserved: 1;                        //bit 7 reserved
+//} LedConfig;
 
 //------------------------------------------------------------------------------
 bool isDetectPlugin(void);

+ 2 - 2
EVSE/Projects/DD360Audi/Apps/Config.h

@@ -362,14 +362,14 @@ typedef struct StDcCommonInfo {
     uint8_t CheckRelayStatus[6]; //check Relay welding or driving fault
     uint8_t GunRelayWeldingOccur[2];
     uint8_t GunRelayDrivingOccur[2];
-    uint8_t SystemModeChange;
+    uint8_t SystemModeChange[2]; //for Module_EvRxComm
     PowerAlarmState PowerAlarmState;
     ChillerTempErr ChillerTempErr[2];
     ChillerValve ChillerValve;
     uint8_t TestTemperature; //ReadCmdline test, manual input value
     uint8_t CcsTypeSaved[2];
     PcPsuOutput PcPsuOutput[2];
-    uint8_t Reserved[4];
+    uint8_t Reserved[3];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 81 - 163
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -281,10 +281,10 @@ static int doCommConnToServer(void)
     //    fcntl(TcpSock, F_SETFL, flag );
     //}
 
-    tv.tv_sec = 0;
-    tv.tv_usec = 100000;
-    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
-    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
+    tv.tv_sec = 3;
+    tv.tv_usec = 0;
+    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval)); //設定等待3s
+    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));  //設定傳送3s
     flag = 1;
     setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
 
@@ -1154,10 +1154,10 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
 
         ShmDcCommonData->PcPsuOutput[plugNum].Voltage = ntohs((uint16_t)pPcPsuOutput->Voltage);
         ShmDcCommonData->PcPsuOutput[plugNum].Current = ntohs((uint16_t)pPcPsuOutput->Current);
-        log_info("%d ower cabinet PSU output vol = %d, cur = %d\r\n",
-                 plugNum,
-                 ShmDcCommonData->PcPsuOutput[plugNum].Voltage,
-                 ShmDcCommonData->PcPsuOutput[plugNum].Current);
+        //log_info("%d power cabinet PSU output vol = %f, cur = %f\r\n",
+        //         plugNum,
+        //         (float)ShmDcCommonData->PcPsuOutput[plugNum].Voltage,
+        //         (float)ShmDcCommonData->PcPsuOutput[plugNum].Current);
         break;
 
     case REG_QRCODE_URL_INFO:
@@ -1361,17 +1361,6 @@ static int readMiscCommand(int fd, uint8_t id)
 
 static int readChargePermission(int fd, uint8_t id)
 {
-    //int ret = PASS;
-
-    //if ((ret = composeSocketData(fd,
-    //                             id,
-    //                             OP_READ_DATA,
-    //                             REG_CHARGING_PERMISSION,
-    //                             0,
-    //                             NULL)) == FAIL) {
-    //    return ret;
-    //}
-
     return composeSocketData(fd,
                              id,
                              OP_READ_DATA,
@@ -1645,95 +1634,6 @@ static int CheckNetworkStatus(void)
     return 0;
 }
 
-#if 0
-static int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
-{
-    uint8_t index = 0;
-
-    for (index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (pSysInfo->ChademoChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (index = 0; index < CCS_QUANTITY; index++) {
-        if (pSysInfo->CcsChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (index = 0; index < GB_QUANTITY; index++) {
-        if (pSysInfo->GbChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-static int InitShareMemory(void)
-{
-    int result = 1;
-    int MeterSMId = 0;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        log_error("shmget ShmSysConfigAndInfo NG\n");
-        result = 0;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("[shmat ShmSysConfigAndInfo NG\n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        log_error("shmget ShmStatusCodeData NG\n");
-        result = 0;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmStatusCodeData NG\n");
-        result = 0;
-    }
-
-    //creat ShmPsuData
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-        log_error("shmget ShmPsuData NG \n");
-        result = 0;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmPsuData NG \n");
-        result = 0;
-    }
-
-    //creat ShmOCPP16Data
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
-        log_error("shmget ShmOCPP16Data NG \n");
-        result = 0;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmOCPP16Data NG \n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        log_error("shmget ShmPrimaryMcuData NG\n");
-        result = 0;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmPrimaryMcuData NG\n");
-        result = 0;
-    }
-
-    //creat Audi customization info
-    if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
-        log_error("[main]CreatShareMemory:shmget select gun info NG \n");
-        return 0;
-    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
-        return 0;
-    }
-
-    return result;
-}
-#endif //0
-
 static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
 {
     bool canUpdateFirmware = true;
@@ -1787,7 +1687,7 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
 #else
     gunID = ID_REGISTER;
 
-    ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0;
+    ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0; //非Audi 不需要等待主櫃回報餘額
 #endif // DD360Audi
 
     if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == YES) ||
@@ -1964,7 +1864,9 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 
         case REG_QRCODE_URL_INFO:
             if (gunID == 1) {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10)) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
+                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
+                   ) {
                     readQRcodeURLAndSystemDate(fd);
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
@@ -2026,13 +1928,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10)) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
+           ) {
             writeWaitPlugItState(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
@@ -2040,13 +1946,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_PREPARNING: //get permission
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) < 0
+           ) {
             writeConnectorState(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CONNECTOR_STATE]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) && readChargingCapability(fd, gunID)) {
                 for (i = 0; i < totalGun; i++) {
                     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
@@ -2059,7 +1969,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2067,13 +1979,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_PREPARING_FOR_EV://wait connector lock
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2084,7 +2000,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2096,13 +2014,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         writeChargingTarget(fd, plugNum, gunID);
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2113,7 +2035,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2122,13 +2046,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CHARGING: //charging
     case S_TERMINATING:
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2141,7 +2069,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         writeChargingTarget(fd, plugNum, gunID);
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2149,7 +2079,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_COMPLETE:
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
@@ -2222,17 +2154,6 @@ int main(int argc, char *argv[])
     InitSocketSigPipe();
 
     /**************** Initialization **********/
-    /*if (InitShareMemory() == 0) {
-        if (ShmStatusCodeData != NULL) {
-            pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = YES;
-        }
-
-        log_error("DoComm Initial share memory fail\r\n");
-        sleep(5);
-
-        return 0;
-    }
-    */
     if (CreateAllCsuShareMemory() == FAIL) {
         log_error("create share memory error\r\n");
         return FAIL;
@@ -2254,16 +2175,13 @@ int main(int argc, char *argv[])
     totalConnCount = pSysConfig->TotalConnectorCount;
 
     for (index = 0; index < totalConnCount; index++) {
-        //if (!FindChargingInfoData(index, &ChargingData[0])) {
-        //    log_error("FindChargingInfoData false \n");
-        //    break;
-        //}
         clearPricesInfo(index);
     }
 
     //initial trigger message timer
     for (index = 0; index < MAX_REGISTER_NUM; index++) {
         ftime(&gRegTimeUp[0][index]);
+        usleep(128);
         ftime(&gRegTimeUp[1][index]);
         usleep(50000);
     }
@@ -2280,8 +2198,9 @@ int main(int argc, char *argv[])
             gunID = 0;
             for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
                 //checkAuthorProcess(fd, plugNum);
-                //plugNum = setup chargingData value for bottom layer
-                //gunID = (plugNum  + 1); //connector Id, 1 = left gun, 2 = right gun
+
+                //plugNum : setup chargingData value for bottom layer
+                //gunID : connector Id from power cabinet, 1 = left gun, 2 = right gun,
                 gunID = gDoCommGblData.ConnectorID[plugNum];
                 systemStatusProcess(fd, totalConnCount, plugNum, gunID);
 
@@ -2296,33 +2215,32 @@ int main(int argc, char *argv[])
             }
         }
 
-        if (initDone == DISPENSER_SOCKET_RECONN) {
-            //system("udhcpc -r eth0");
-            log_info("Disconnected from power cabinet...re-connecting");
-            setTcpStatus(ABNORMAL);
-
+        if (initDone != DISPENSER_SOCKET_RECONN) {
+            //update dispenser firmware
+            updateFirmwareProcess(fd, gDoCommGblData.ConnectorID[0], totalConnCount);
 
-            if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
-                sprintf(tmpbuf,
-                        "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
-                        pSysConfig->SystemId);
-                system(tmpbuf);
-            }
+            usleep(100000);
+            continue;
+        }
 
-            gDoCommGblData.DisConnCount = 0;
-            gDoCommGblData.SeqNum = 0;
+        //Ethernet error recovery handle
+        log_info("Disconnected from power cabinet...re-connecting");
+        setTcpStatus(ABNORMAL);
 
-            closeSocket(fd);
-            fd = 0;
 
-            initDone = DISPENER_INIT_FAIL;
+        if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
+            sprintf(tmpbuf,
+                    "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
+                    pSysConfig->SystemId);
+            system(tmpbuf);
         }
 
-        //update dispenser firmware
-        if (initDone != DISPENER_INIT_FAIL) {
-            updateFirmwareProcess(fd, gDoCommGblData.ConnectorID[0], totalConnCount);
-        }
+        gDoCommGblData.DisConnCount = 0;
+        gDoCommGblData.SeqNum = 0;
+
+        closeSocket(fd);
+        fd = 0;
 
-        usleep(100000);
+        initDone = DISPENER_INIT_FAIL;
     }
 }

+ 30 - 26
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -205,8 +205,10 @@ void CANReceiver(int fd)
         uint8_t targetGun = 0x00;
         uint8_t gunTypeIndex = 0;
         uint8_t ver[16] = {0};
-        uint8_t sameChillerTemp = NO;
-        uint8_t sameConnTemp = NO;
+        uint8_t printChillerTemp = NO;
+        uint8_t printConnTemp = NO;
+        uint8_t maxChillerTemp = 0;
+        uint8_t maxConnTemp = 0;
         struct can_frame frame;
         ChillerTemp chiilerTemp = {0};
         struct ChargingInfoData *pDcChargingInfo = NULL;
@@ -226,8 +228,6 @@ void CANReceiver(int fd)
         log_info("Module_EvRXComm Child's PID is %d\r\n", getpid());
 
         while (isContinue) {
-            sameChillerTemp = NO;
-            sameConnTemp = NO;
             memset(&frame, 0, sizeof(struct can_frame));
 
             nbytes = read(fd, &frame, sizeof(struct can_frame));
@@ -430,18 +430,18 @@ void CANReceiver(int fd)
             case ACK_GET_EV_BATTERY_INFO:
                 //_chargingData[target].EvACorDCcharging = frame.data[0];
                 //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
-                pDcChargingInfo->EvBatteryMaxVoltage = (((short) frame.data[4] << 8) + (short) frame.data[3]) / 10;
+                pDcChargingInfo->EvBatteryMaxVoltage = ((float)(((uint16_t)frame.data[4] << 8) + (uint16_t)frame.data[3])) / 10;
                 //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
                 //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
                 if (pDcChargingInfo->Type == _Type_Chademo) {
-                    ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
                     ShmCHAdeMOData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
 
                     //log_info("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
                     //log_info("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
                     //log_info("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
                 } else if (pDcChargingInfo->Type == _Type_GB) {
-                    ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
                     ShmGBTData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
                 }
                 //else if (pDcChargingInfo->Type == _Type_CCS_2) {
@@ -450,7 +450,7 @@ void CANReceiver(int fd)
 
             case ACK_GET_MISCELLANEOUS_INFO:
                 pDcChargingInfo->GunLocked = frame.data[0];
-                pDcChargingInfo->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+                pDcChargingInfo->PilotVoltage = ((float)(-120 + frame.data[3])) / 10;
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
                     ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
@@ -472,40 +472,44 @@ void CANReceiver(int fd)
                     break;
                 }
 
+                printChillerTemp = NO;
+                printConnTemp = NO;
+
                 if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
                     getChillerTemperature(&chiilerTemp);
-                    if (getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]) == (pDcChargingInfo->ChillerTemp + 3)) {
-                        sameChillerTemp = YES;
+                    maxChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
+
+                    if ((maxChillerTemp - 3) >= pDcChargingInfo->ChillerTemp) {
+                        printChillerTemp = YES;
                     }
 
                     pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
                 }
 
-                if (getMaxConnectTemp(frame.data[1], frame.data[2]) == (pDcChargingInfo->ConnectorTemp + 3)) {
-                    sameConnTemp = YES;
+                maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
+                if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
+                    printConnTemp = YES;
                 }
 
                 pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
 
                 //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
-                if (((sameConnTemp == YES) ||
-                        (sameChillerTemp == YES)) &&
-                        (ShmDcCommonData->SystemModeChange == YES) ||
-                        (((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
-                          (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
-                         ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
-                          (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
+                if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
+                        (printConnTemp == YES) ||
+                        (printChillerTemp == YES) //&&
+                        //(((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
+                        //  (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
+                        // ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
+                        //  (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
                    ) {
-                    ShmDcCommonData->SystemModeChange = NO;
-                    log_info("Conn %d Temp 0= %d, Temp 1 = %d, chillerTemp1 = %d, chillerTemp2 = %d\r\n",
+                    ShmDcCommonData->SystemModeChange[targetGun] = NO;
+                    log_info("Conn %d max head temp %d, max chiller = %d\r\n",
                              targetGun,
-                             frame.data[1],
-                             frame.data[2],
-                             chiilerTemp.Temp[0],
-                             chiilerTemp.Temp[1]);
+                             maxConnTemp,
+                             maxChillerTemp);
                 }
 
-                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) == NO) {
+                if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
                     //沒有水冷槍
                     break;
                 }

+ 51 - 8
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -421,6 +421,20 @@ static void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
     }
 }
 
+static uint8_t waitPsuVolwithRealyVol(uint8_t gunIndex)
+{
+    PcPsuOutput *pPcPsuOutput = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[gunIndex];
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+    int vol = 0;
+
+    vol = abs(pPcPsuOutput->Voltage - pDcChargingInfo->FireChargingVoltage);
+    if (vol <= 10) {
+        return YES;
+    }
+
+    return NO;
+}
+
 /**
  * [SetPresentChargingOutputFromPcPsu 充電狀態讀取電源櫃PSU輸出電壓電流,縮小誤差值]
  * @Author   Jerry
@@ -432,23 +446,29 @@ static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
     float vol2 = 0, cur2 = 0;
     PcPsuOutput *pPcPsuOutput0 = NULL;
     PcPsuOutput *pPcPsuOutput1 = NULL;
+    struct ChargingInfoData *chargingData0 = NULL;
+    struct ChargingInfoData *chargingData1 = NULL;
 
     switch (gunCount) {
     case 1:
         pPcPsuOutput0 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
+        chargingData0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
         break;
 
     case 2:
         pPcPsuOutput0 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[1];
+        chargingData0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData1 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
         break;
     }
 
-    vol1 = (((float)pPcPsuOutput0->Voltage) * 0.1);
-    cur1 = (((float)pPcPsuOutput0->Current) * 0.1);
-    vol2 = (((float)pPcPsuOutput1->Voltage) * 0.1);
-    cur2 = (((float)pPcPsuOutput1->Current) * 0.1);
+    vol1 = (((float)pPcPsuOutput0->Voltage));
+    cur1 = (chargingData0->PresentChargingCurrent * 10);//(((float)pPcPsuOutput0->Current) * 0.1);
+    vol2 = (((float)pPcPsuOutput1->Voltage));
+    cur2 = (chargingData1->PresentChargingCurrent * 10);//(((float)pPcPsuOutput1->Current) * 0.1);
 
     if (
         (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
@@ -461,9 +481,9 @@ static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
         (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
     ) {
         log_info("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f\r\n",
-                 vol1 / 10,
+                 vol1,
                  cur1 / 10,
-                 vol2 / 10,
+                 vol2,
                  cur2 / 10);
 
         LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
@@ -621,6 +641,17 @@ static void FormatVoltageAndCurrent(void)
     }
 }
 
+static int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+    //return milli-second
+    unsigned int StartTime, StopTime;
+
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
+}
+
 int main(int argc, char *argv[])
 {
     bool chkChademoPermission[2] = {false};
@@ -637,6 +668,8 @@ int main(int argc, char *argv[])
     struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
     time_t rtc = {0};
     struct ChargingInfoData *pDcChargingInfo = NULL;
+    struct timeb waitChargingTime;
+    struct timeb nowTime;
 
     if (CreateAllCsuShareMemory() == FAIL) {
         log_error("create share memory error\r\n");
@@ -928,9 +961,14 @@ int main(int argc, char *argv[])
                         SetEvsePrechargeInfo(gunIndex, PRECHARGE_PRERELAY_PASS, pDcChargingInfo->Evboard_id);
                     }
                 }
+                ftime(&waitChargingTime);
                 break;
 
             case S_CHARGING:
+                //if (waitPsuVolwithRealyVol(gunIndex) == NO) {
+                //    continue;
+                //}
+
                 // 計算 Power
                 pDcChargingInfo->PresentChargingPower =
                     ((float)((pDcChargingInfo->PresentChargingVoltage) *
@@ -959,8 +997,13 @@ int main(int argc, char *argv[])
                 GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
 
                 // 設定當前輸出
-                //SetPresentChargingOutputPower();
-                SetPresentChargingOutputFromPcPsu(pSysConfig->TotalConnectorCount);
+                ftime(&nowTime);
+                if (DiffTimeb(waitChargingTime, nowTime) < 3000 ||
+                        DiffTimeb(waitChargingTime, nowTime) < 0) {
+                    SetPresentChargingOutputPower();
+                } else {
+                    SetPresentChargingOutputFromPcPsu(pSysConfig->TotalConnectorCount);
+                }
 
                 // for test end
                 if (priorityLow % 5 == 0) {

+ 95 - 27
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -89,6 +89,17 @@ static struct ChargingInfoData *pAcChargingInfo = NULL;
 static char newString[8][16] = {0};
 
 //------------------------------------------------------------------------------
+static int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+    //return milli-second
+    unsigned int StartTime, StopTime;
+
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
+}
+
 static void get_char(char *word)
 {
     fd_set rfds;
@@ -325,7 +336,7 @@ void GetFwVerProc(void)
                      "      help | ? | h\n";
 
     while (isContinue) {
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
             continue;
         }
 
@@ -672,6 +683,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     uint8_t gunIndex = 0;
     uint8_t stopChg = 0;
     uint8_t curGun = 0;
+    int isContinue = 1;
     float _Voltage;
     float _Current;
     uint8_t PreviousSystemStatus[2] = {0xff};
@@ -679,7 +691,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                      "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
                      "       chg    <voltage> <current>            ex: chg 500 100\n"
                      "       c      <index>                        ex: c 0\n"
-                     "       help | ? | h\n";
+                     "       help | ? | h\n"
+                     "\r\n";
 
     if (strcmp(v1, "auto") == EQUAL) {
         _usingAutoRun = 0x01;
@@ -710,7 +723,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     pSysInfo->CurGunSelected = _GunIndex;
 
-    while (true) {
+    while (isContinue) {
+
         curGun = pSysInfo->CurGunSelected;
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
 
@@ -912,8 +926,9 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 if (PreviousSystemStatus[gunIndex] == 0xFF) {
                     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-
                     pDcChargingInfo->SystemStatus = S_IDLE;
+                } else {
+                    pSysInfo->CurGunSelected = gunIndex;
                 }
 
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
@@ -928,6 +943,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             if (stopChg == pSysConfig->TotalConnectorCount) {
                 system("/root/Module_EvComm &");
                 sleep(3);
+
+                for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+                    pDcChargingInfo->SystemStatus = S_IDLE;
+                }
                 return;
             }
             break;
@@ -1021,29 +1042,71 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     }
 }
 
+int printTimeMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256] = {0};
+    char buffer[4096] = {0};
+    int rc = -1;
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    va_start(args, fmt);
+    rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+            tm->tm_hour,
+            tm->tm_min,
+            tm->tm_sec,
+            SeqEndTime.millitm,
+            buffer);
+    printf("%s", Buf);
+
+    return rc;
+}
+
 static void resdGunAndChillerTemp(void)
 {
     int isContinue = 1;
     uint8_t i = 0;
-    uint8_t sleepTime = 3;
+    uint32_t sleepTime = 500000;
+    uint32_t loopTime = 1000;
+    struct timeb showTime;
+    struct timeb nowTime;
+
     char *usageMsg = "Usage:\n"
                      "       t <index>: loop time, ex: t 1\n"
                      "       exit | c | C: exit test\n"
-                     "       h | help | ?: show usage message\n";
+                     "       h | help | ?: show usage message\n"
+                     "\r\n";
+
+    ftime(&showTime);
 
     while (isContinue) {
-        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        ftime(&nowTime);
 
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+        if (DiffTimeb(showTime, nowTime) > loopTime ||
+                DiffTimeb(showTime, nowTime) < 0) {
+            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
 
-            printf("get %d gun temp = %d, chiller temp = %d\r\n",
-                   i,
-                   pDcChargingInfo->ConnectorTemp,
-                   pDcChargingInfo->ChillerTemp);
-        }//for
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                printTimeMsg("get %d gun temp = %d, chiller temp = %d\r\n",
+                             i,
+                             pDcChargingInfo->ConnectorTemp,
+                             pDcChargingInfo->ChillerTemp);
+            }//for
+            ftime(&showTime);
+        }
 
         if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
-            sleep(sleepTime);
+            usleep(sleepTime);
             continue;
         }
 
@@ -1056,15 +1119,17 @@ static void resdGunAndChillerTemp(void)
                 continue;
             }
 
-            sleepTime = atoi((char *)newString[1]);
-
+            loopTime = ((atoi((char *)newString[1])) * 1000);
+            printf("loopTime = %d\r\n", loopTime);
+            ftime(&showTime);
+            continue;
         } else if (exitCmd() == YES) {
             return;
         } else if (helpCmd() == YES) {
             printf ("%s\n", usageMsg);
         }
 
-        sleep(sleepTime);
+        usleep(sleepTime);
     }//while
 }
 
@@ -1072,18 +1137,19 @@ static void writeGunAndChillerTemp(void)
 {
     uint8_t _GunIndex = 0;
     int isContinue = 1;
-    uint8_t sleepTime = 3;
+    uint32_t sleepTime = 500000;
     char *usageMsg = "Usage:\n"
                      "       conn    <index> <temp>, ex: conn 0 150\n"
                      "       chiller <index> <temp>, ex: chiller 0 150\n"
                      "       tempR\n"
                      "       exit | c | C\n"
-                     "       help | ? | h\n";
+                     "       help | ? | h\n"
+                     "\r\n";
 
     ShmDcCommonData->TestTemperature = YES;
 
     while (isContinue) {
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
             sleep(sleepTime);
             continue;
         }
@@ -1095,6 +1161,8 @@ static void writeGunAndChillerTemp(void)
             ShmDcCommonData->TestTemperature = NO;
             sleep(1);
             return;
+        } else if (strcmp(newString[0], "tempR") == 0) {
+            resdGunAndChillerTemp();
         }
 
         if ((strcmp(newString[0], "chiller") != 0) &&
@@ -1105,7 +1173,8 @@ static void writeGunAndChillerTemp(void)
             continue;
         }
 
-        if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) {
+        if (atoi(newString[2]) > 255 ||
+                atoi(newString[2]) == -1) {
             printf("temperature value overflow\r\n");
             continue;
         }
@@ -1134,11 +1203,9 @@ static void writeGunAndChillerTemp(void)
             printf("set %d connector temp = %d\r\n",
                    _GunIndex,
                    pDcChargingInfo->ConnectorTemp);
-        } else if (strcmp(newString[0], "tempR") == 0) {
-            resdGunAndChillerTemp();
         }
 
-        sleep(1);
+        usleep(sleepTime);
     }//while
 }
 
@@ -1154,7 +1221,7 @@ int main(void)
                      "       sysid                             : test system ID\n"
                      "       self                              : self test state (x)\n"
                      "       version | v | -v                  : version of board (407 or relay or other)\n"
-                     "       update                            : update firmware"
+                     "       update                            : update firmware\n"
                      "       ac                                : get ac relay state (x) \n"
                      "       cable <index> <state>             : set ground fault state\n"
                      "       pow <index> <power>               : set power value\n"
@@ -1164,7 +1231,8 @@ int main(void)
                      "       strchg <auto>                     : auto test charging\n"
                      "       strchg <index> <voltage <current> : select gun test charging\n"
                      "       tempW                             : write connector header and Chiller temperature\r\n"
-                     "       tempR                             : print connector header and chiller temperature\r\n";
+                     "       tempR                             : print connector header and chiller temperature\r\n"
+                     "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
         printf("create share memory error\r\n");
@@ -1332,7 +1400,7 @@ int main(void)
         } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
             resdGunAndChillerTemp();
         } else {
-            printf ("%s\n", usageMsg);
+            printf("%s\n", usageMsg);
         }
 
         sleep(1);

BIN
EVSE/Projects/DD360Audi/Images/ramdisk.gz


BIN
EVSE/Projects/DD360Audi/output/Module_DoComm


BIN
EVSE/Projects/DD360Audi/output/Module_EvComm


BIN
EVSE/Projects/DD360Audi/output/Module_EventLogging


BIN
EVSE/Projects/DD360Audi/output/Module_InternalComm


BIN
EVSE/Projects/DD360Audi/output/Module_LcmControl


BIN
EVSE/Projects/DD360Audi/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Audi/output/ReadCmdline


BIN
EVSE/Projects/DD360Audi/output/main


+ 11 - 0
EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c

@@ -12,6 +12,17 @@
 #include "main.h"
 
 //------------------------------------------------------------------------------
+typedef struct StLedConfig {
+    //OutputDrvValue[0]
+    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
+    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
+    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+    uint8_t Reserved: 1;                        //bit 7 reserved
+} LedConfig;
 
 //------------------------------------------------------------------------------
 static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)

+ 25 - 4
EVSE/Projects/DD360ComBox/Apps/CSU/main.c

@@ -1765,9 +1765,29 @@ void RecordAlarmCode(uint8_t gunIndex, char *code)
     } else if (strcmp(code, "011020") == EQUAL) {
         ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
     } else if (strcmp(code, "012323") == EQUAL) {
-        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        if ((gunIndex == 0) &&
+                ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+                 (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
+           ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        } else if ((gunIndex == 1) &&
+                   ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+                    (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
+                  ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+        }
     } else if (strcmp(code, "011038") == EQUAL) {
-        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        if ((gunIndex == 0) &&
+                ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+                 (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
+           ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        } else if ((gunIndex == 1) &&
+                   ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+                    (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
+                  ) {
+            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+        }
     }
 }
 
@@ -2300,7 +2320,7 @@ uint8_t isModeChange(uint8_t gunIndex)
     }
 
     pDcChargingInfo->PreviousSystemStatus = pDcChargingInfo->SystemStatus;
-    ShmDcCommonData->SystemModeChange = YES; //for Module_EvRxComm print temperature message
+    ShmDcCommonData->SystemModeChange[gunIndex] = YES; //for Module_EvRxComm print temperature message
 
     return YES;
 }
@@ -4813,7 +4833,8 @@ int main(void)
                         pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
                     }
                 } else if (isPrechargeStatus_ccs(gunIndex) == 45 ||
-                           isPrechargeStatus_ccs(gunIndex) == 46) {
+                           isPrechargeStatus_ccs(gunIndex) == 46
+                          ) {
                     setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP1);
                 }
 

+ 11 - 11
EVSE/Projects/DD360ComBox/Apps/CSU/main.h

@@ -49,17 +49,17 @@
 //#define log_error(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
-typedef struct StLedConfig {
-    //OutputDrvValue[0]
-    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
-    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
-    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
-    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
-    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
-    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
-    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
-    uint8_t Reserved: 1;                        //bit 7 reserved
-} LedConfig;
+//typedef struct StLedConfig {
+//    //OutputDrvValue[0]
+//    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+//    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+//    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
+//    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+//    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
+//    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+//    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+//    uint8_t Reserved: 1;                        //bit 7 reserved
+//} LedConfig;
 
 //------------------------------------------------------------------------------
 bool isDetectPlugin(void);

+ 2 - 2
EVSE/Projects/DD360ComBox/Apps/Config.h

@@ -362,14 +362,14 @@ typedef struct StDcCommonInfo {
     uint8_t CheckRelayStatus[6]; //check Relay welding or driving fault
     uint8_t GunRelayWeldingOccur[2];
     uint8_t GunRelayDrivingOccur[2];
-    uint8_t SystemModeChange;
+    uint8_t SystemModeChange[2]; //for Module_EvRxComm
     PowerAlarmState PowerAlarmState;
     ChillerTempErr ChillerTempErr[2];
     ChillerValve ChillerValve;
     uint8_t TestTemperature; //ReadCmdline test, manual input value
     uint8_t CcsTypeSaved[2];
     PcPsuOutput PcPsuOutput[2];
-    uint8_t Reserved[4];
+    uint8_t Reserved[3];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 81 - 163
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c

@@ -281,10 +281,10 @@ static int doCommConnToServer(void)
     //    fcntl(TcpSock, F_SETFL, flag );
     //}
 
-    tv.tv_sec = 0;
-    tv.tv_usec = 100000;
-    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
-    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
+    tv.tv_sec = 3;
+    tv.tv_usec = 0;
+    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval)); //設定等待3s
+    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));  //設定傳送3s
     flag = 1;
     setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
 
@@ -1154,10 +1154,10 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
 
         ShmDcCommonData->PcPsuOutput[plugNum].Voltage = ntohs((uint16_t)pPcPsuOutput->Voltage);
         ShmDcCommonData->PcPsuOutput[plugNum].Current = ntohs((uint16_t)pPcPsuOutput->Current);
-        log_info("%d ower cabinet PSU output vol = %d, cur = %d\r\n",
-                 plugNum,
-                 ShmDcCommonData->PcPsuOutput[plugNum].Voltage,
-                 ShmDcCommonData->PcPsuOutput[plugNum].Current);
+        //log_info("%d power cabinet PSU output vol = %f, cur = %f\r\n",
+        //         plugNum,
+        //         (float)ShmDcCommonData->PcPsuOutput[plugNum].Voltage,
+        //         (float)ShmDcCommonData->PcPsuOutput[plugNum].Current);
         break;
 
     case REG_QRCODE_URL_INFO:
@@ -1361,17 +1361,6 @@ static int readMiscCommand(int fd, uint8_t id)
 
 static int readChargePermission(int fd, uint8_t id)
 {
-    //int ret = PASS;
-
-    //if ((ret = composeSocketData(fd,
-    //                             id,
-    //                             OP_READ_DATA,
-    //                             REG_CHARGING_PERMISSION,
-    //                             0,
-    //                             NULL)) == FAIL) {
-    //    return ret;
-    //}
-
     return composeSocketData(fd,
                              id,
                              OP_READ_DATA,
@@ -1645,95 +1634,6 @@ static int CheckNetworkStatus(void)
     return 0;
 }
 
-#if 0
-static int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
-{
-    uint8_t index = 0;
-
-    for (index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (pSysInfo->ChademoChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (index = 0; index < CCS_QUANTITY; index++) {
-        if (pSysInfo->CcsChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (index = 0; index < GB_QUANTITY; index++) {
-        if (pSysInfo->GbChargingData[index].Index == target) {
-            chargingData[target] = &pSysInfo->GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-static int InitShareMemory(void)
-{
-    int result = 1;
-    int MeterSMId = 0;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        log_error("shmget ShmSysConfigAndInfo NG\n");
-        result = 0;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("[shmat ShmSysConfigAndInfo NG\n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        log_error("shmget ShmStatusCodeData NG\n");
-        result = 0;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmStatusCodeData NG\n");
-        result = 0;
-    }
-
-    //creat ShmPsuData
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-        log_error("shmget ShmPsuData NG \n");
-        result = 0;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmPsuData NG \n");
-        result = 0;
-    }
-
-    //creat ShmOCPP16Data
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
-        log_error("shmget ShmOCPP16Data NG \n");
-        result = 0;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmOCPP16Data NG \n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        log_error("shmget ShmPrimaryMcuData NG\n");
-        result = 0;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("shmat ShmPrimaryMcuData NG\n");
-        result = 0;
-    }
-
-    //creat Audi customization info
-    if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
-        log_error("[main]CreatShareMemory:shmget select gun info NG \n");
-        return 0;
-    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
-        return 0;
-    }
-
-    return result;
-}
-#endif //0
-
 static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
 {
     bool canUpdateFirmware = true;
@@ -1787,7 +1687,7 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
 #else
     gunID = ID_REGISTER;
 
-    ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0;
+    ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0; //非Audi 不需要等待主櫃回報餘額
 #endif // DD360Audi
 
     if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == YES) ||
@@ -1964,7 +1864,9 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 
         case REG_QRCODE_URL_INFO:
             if (gunID == 1) {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10)) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
+                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
+                   ) {
                     readQRcodeURLAndSystemDate(fd);
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
@@ -2026,13 +1928,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10)) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
+           ) {
             writeWaitPlugItState(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
@@ -2040,13 +1946,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_PREPARNING: //get permission
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CONNECTOR_STATE], AuthNowTime) < 0
+           ) {
             writeConnectorState(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CONNECTOR_STATE]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) && readChargingCapability(fd, gunID)) {
                 for (i = 0; i < totalGun; i++) {
                     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
@@ -2059,7 +1969,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2067,13 +1979,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_PREPARING_FOR_EV://wait connector lock
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2084,7 +2000,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2096,13 +2014,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         writeChargingTarget(fd, plugNum, gunID);
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2113,7 +2035,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2122,13 +2046,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CHARGING: //charging
     case S_TERMINATING:
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+           ) {
             if (readChargePermission(fd, gunID) == 0) {
                 log_info("Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
@@ -2141,7 +2069,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         writeChargingTarget(fd, plugNum, gunID);
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+           ) {
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
@@ -2149,7 +2079,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_COMPLETE:
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
+           ) {
             readChargingCapability(fd, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
@@ -2222,17 +2154,6 @@ int main(int argc, char *argv[])
     InitSocketSigPipe();
 
     /**************** Initialization **********/
-    /*if (InitShareMemory() == 0) {
-        if (ShmStatusCodeData != NULL) {
-            pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = YES;
-        }
-
-        log_error("DoComm Initial share memory fail\r\n");
-        sleep(5);
-
-        return 0;
-    }
-    */
     if (CreateAllCsuShareMemory() == FAIL) {
         log_error("create share memory error\r\n");
         return FAIL;
@@ -2254,16 +2175,13 @@ int main(int argc, char *argv[])
     totalConnCount = pSysConfig->TotalConnectorCount;
 
     for (index = 0; index < totalConnCount; index++) {
-        //if (!FindChargingInfoData(index, &ChargingData[0])) {
-        //    log_error("FindChargingInfoData false \n");
-        //    break;
-        //}
         clearPricesInfo(index);
     }
 
     //initial trigger message timer
     for (index = 0; index < MAX_REGISTER_NUM; index++) {
         ftime(&gRegTimeUp[0][index]);
+        usleep(128);
         ftime(&gRegTimeUp[1][index]);
         usleep(50000);
     }
@@ -2280,8 +2198,9 @@ int main(int argc, char *argv[])
             gunID = 0;
             for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
                 //checkAuthorProcess(fd, plugNum);
-                //plugNum = setup chargingData value for bottom layer
-                //gunID = (plugNum  + 1); //connector Id, 1 = left gun, 2 = right gun
+
+                //plugNum : setup chargingData value for bottom layer
+                //gunID : connector Id from power cabinet, 1 = left gun, 2 = right gun,
                 gunID = gDoCommGblData.ConnectorID[plugNum];
                 systemStatusProcess(fd, totalConnCount, plugNum, gunID);
 
@@ -2296,33 +2215,32 @@ int main(int argc, char *argv[])
             }
         }
 
-        if (initDone == DISPENSER_SOCKET_RECONN) {
-            //system("udhcpc -r eth0");
-            log_info("Disconnected from power cabinet...re-connecting");
-            setTcpStatus(ABNORMAL);
-
+        if (initDone != DISPENSER_SOCKET_RECONN) {
+            //update dispenser firmware
+            updateFirmwareProcess(fd, gDoCommGblData.ConnectorID[0], totalConnCount);
 
-            if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
-                sprintf(tmpbuf,
-                        "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
-                        pSysConfig->SystemId);
-                system(tmpbuf);
-            }
+            usleep(100000);
+            continue;
+        }
 
-            gDoCommGblData.DisConnCount = 0;
-            gDoCommGblData.SeqNum = 0;
+        //Ethernet error recovery handle
+        log_info("Disconnected from power cabinet...re-connecting");
+        setTcpStatus(ABNORMAL);
 
-            closeSocket(fd);
-            fd = 0;
 
-            initDone = DISPENER_INIT_FAIL;
+        if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
+            sprintf(tmpbuf,
+                    "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
+                    pSysConfig->SystemId);
+            system(tmpbuf);
         }
 
-        //update dispenser firmware
-        if (initDone != DISPENER_INIT_FAIL) {
-            updateFirmwareProcess(fd, gDoCommGblData.ConnectorID[0], totalConnCount);
-        }
+        gDoCommGblData.DisConnCount = 0;
+        gDoCommGblData.SeqNum = 0;
+
+        closeSocket(fd);
+        fd = 0;
 
-        usleep(100000);
+        initDone = DISPENER_INIT_FAIL;
     }
 }

+ 30 - 26
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -205,8 +205,10 @@ void CANReceiver(int fd)
         uint8_t targetGun = 0x00;
         uint8_t gunTypeIndex = 0;
         uint8_t ver[16] = {0};
-        uint8_t sameChillerTemp = NO;
-        uint8_t sameConnTemp = NO;
+        uint8_t printChillerTemp = NO;
+        uint8_t printConnTemp = NO;
+        uint8_t maxChillerTemp = 0;
+        uint8_t maxConnTemp = 0;
         struct can_frame frame;
         ChillerTemp chiilerTemp = {0};
         struct ChargingInfoData *pDcChargingInfo = NULL;
@@ -226,8 +228,6 @@ void CANReceiver(int fd)
         log_info("Module_EvRXComm Child's PID is %d\r\n", getpid());
 
         while (isContinue) {
-            sameChillerTemp = NO;
-            sameConnTemp = NO;
             memset(&frame, 0, sizeof(struct can_frame));
 
             nbytes = read(fd, &frame, sizeof(struct can_frame));
@@ -430,18 +430,18 @@ void CANReceiver(int fd)
             case ACK_GET_EV_BATTERY_INFO:
                 //_chargingData[target].EvACorDCcharging = frame.data[0];
                 //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
-                pDcChargingInfo->EvBatteryMaxVoltage = (((short) frame.data[4] << 8) + (short) frame.data[3]) / 10;
+                pDcChargingInfo->EvBatteryMaxVoltage = ((float)(((uint16_t)frame.data[4] << 8) + (uint16_t)frame.data[3])) / 10;
                 //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
                 //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
                 if (pDcChargingInfo->Type == _Type_Chademo) {
-                    ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
                     ShmCHAdeMOData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
 
                     //log_info("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
                     //log_info("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
                     //log_info("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
                 } else if (pDcChargingInfo->Type == _Type_GB) {
-                    ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
                     ShmGBTData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
                 }
                 //else if (pDcChargingInfo->Type == _Type_CCS_2) {
@@ -450,7 +450,7 @@ void CANReceiver(int fd)
 
             case ACK_GET_MISCELLANEOUS_INFO:
                 pDcChargingInfo->GunLocked = frame.data[0];
-                pDcChargingInfo->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+                pDcChargingInfo->PilotVoltage = ((float)(-120 + frame.data[3])) / 10;
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
                     ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
@@ -472,40 +472,44 @@ void CANReceiver(int fd)
                     break;
                 }
 
+                printChillerTemp = NO;
+                printConnTemp = NO;
+
                 if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
                     getChillerTemperature(&chiilerTemp);
-                    if (getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]) == (pDcChargingInfo->ChillerTemp + 3)) {
-                        sameChillerTemp = YES;
+                    maxChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
+
+                    if ((maxChillerTemp - 3) >= pDcChargingInfo->ChillerTemp) {
+                        printChillerTemp = YES;
                     }
 
                     pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
                 }
 
-                if (getMaxConnectTemp(frame.data[1], frame.data[2]) == (pDcChargingInfo->ConnectorTemp + 3)) {
-                    sameConnTemp = YES;
+                maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
+                if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
+                    printConnTemp = YES;
                 }
 
                 pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
 
                 //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
-                if (((sameConnTemp == YES) ||
-                        (sameChillerTemp == YES)) &&
-                        (ShmDcCommonData->SystemModeChange == YES) ||
-                        (((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
-                          (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
-                         ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
-                          (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
+                if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
+                        (printConnTemp == YES) ||
+                        (printChillerTemp == YES) //&&
+                        //(((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
+                        //  (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
+                        // ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
+                        //  (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
                    ) {
-                    ShmDcCommonData->SystemModeChange = NO;
-                    log_info("Conn %d Temp 0= %d, Temp 1 = %d, chillerTemp1 = %d, chillerTemp2 = %d\r\n",
+                    ShmDcCommonData->SystemModeChange[targetGun] = NO;
+                    log_info("Conn %d max head temp %d, max chiller = %d\r\n",
                              targetGun,
-                             frame.data[1],
-                             frame.data[2],
-                             chiilerTemp.Temp[0],
-                             chiilerTemp.Temp[1]);
+                             maxConnTemp,
+                             maxChillerTemp);
                 }
 
-                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) == NO) {
+                if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
                     //沒有水冷槍
                     break;
                 }

+ 51 - 8
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -421,6 +421,20 @@ static void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
     }
 }
 
+static uint8_t waitPsuVolwithRealyVol(uint8_t gunIndex)
+{
+    PcPsuOutput *pPcPsuOutput = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[gunIndex];
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+    int vol = 0;
+
+    vol = abs(pPcPsuOutput->Voltage - pDcChargingInfo->FireChargingVoltage);
+    if (vol <= 10) {
+        return YES;
+    }
+
+    return NO;
+}
+
 /**
  * [SetPresentChargingOutputFromPcPsu 充電狀態讀取電源櫃PSU輸出電壓電流,縮小誤差值]
  * @Author   Jerry
@@ -432,23 +446,29 @@ static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
     float vol2 = 0, cur2 = 0;
     PcPsuOutput *pPcPsuOutput0 = NULL;
     PcPsuOutput *pPcPsuOutput1 = NULL;
+    struct ChargingInfoData *chargingData0 = NULL;
+    struct ChargingInfoData *chargingData1 = NULL;
 
     switch (gunCount) {
     case 1:
         pPcPsuOutput0 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
+        chargingData0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
         break;
 
     case 2:
         pPcPsuOutput0 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[1];
+        chargingData0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData1 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
         break;
     }
 
-    vol1 = (((float)pPcPsuOutput0->Voltage) * 0.1);
-    cur1 = (((float)pPcPsuOutput0->Current) * 0.1);
-    vol2 = (((float)pPcPsuOutput1->Voltage) * 0.1);
-    cur2 = (((float)pPcPsuOutput1->Current) * 0.1);
+    vol1 = (((float)pPcPsuOutput0->Voltage));
+    cur1 = (chargingData0->PresentChargingCurrent * 10);//(((float)pPcPsuOutput0->Current) * 0.1);
+    vol2 = (((float)pPcPsuOutput1->Voltage));
+    cur2 = (chargingData1->PresentChargingCurrent * 10);//(((float)pPcPsuOutput1->Current) * 0.1);
 
     if (
         (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
@@ -461,9 +481,9 @@ static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
         (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
     ) {
         log_info("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f\r\n",
-                 vol1 / 10,
+                 vol1,
                  cur1 / 10,
-                 vol2 / 10,
+                 vol2,
                  cur2 / 10);
 
         LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
@@ -621,6 +641,17 @@ static void FormatVoltageAndCurrent(void)
     }
 }
 
+static int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+    //return milli-second
+    unsigned int StartTime, StopTime;
+
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
+}
+
 int main(int argc, char *argv[])
 {
     bool chkChademoPermission[2] = {false};
@@ -637,6 +668,8 @@ int main(int argc, char *argv[])
     struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
     time_t rtc = {0};
     struct ChargingInfoData *pDcChargingInfo = NULL;
+    struct timeb waitChargingTime;
+    struct timeb nowTime;
 
     if (CreateAllCsuShareMemory() == FAIL) {
         log_error("create share memory error\r\n");
@@ -928,9 +961,14 @@ int main(int argc, char *argv[])
                         SetEvsePrechargeInfo(gunIndex, PRECHARGE_PRERELAY_PASS, pDcChargingInfo->Evboard_id);
                     }
                 }
+                ftime(&waitChargingTime);
                 break;
 
             case S_CHARGING:
+                //if (waitPsuVolwithRealyVol(gunIndex) == NO) {
+                //    continue;
+                //}
+
                 // 計算 Power
                 pDcChargingInfo->PresentChargingPower =
                     ((float)((pDcChargingInfo->PresentChargingVoltage) *
@@ -959,8 +997,13 @@ int main(int argc, char *argv[])
                 GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
 
                 // 設定當前輸出
-                //SetPresentChargingOutputPower();
-                SetPresentChargingOutputFromPcPsu(pSysConfig->TotalConnectorCount);
+                ftime(&nowTime);
+                if (DiffTimeb(waitChargingTime, nowTime) < 3000 ||
+                        DiffTimeb(waitChargingTime, nowTime) < 0) {
+                    SetPresentChargingOutputPower();
+                } else {
+                    SetPresentChargingOutputFromPcPsu(pSysConfig->TotalConnectorCount);
+                }
 
                 // for test end
                 if (priorityLow % 5 == 0) {

+ 95 - 27
EVSE/Projects/DD360ComBox/Apps/ReadCmdline.c

@@ -89,6 +89,17 @@ static struct ChargingInfoData *pAcChargingInfo = NULL;
 static char newString[8][16] = {0};
 
 //------------------------------------------------------------------------------
+static int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+    //return milli-second
+    unsigned int StartTime, StopTime;
+
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
+}
+
 static void get_char(char *word)
 {
     fd_set rfds;
@@ -325,7 +336,7 @@ void GetFwVerProc(void)
                      "      help | ? | h\n";
 
     while (isContinue) {
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
             continue;
         }
 
@@ -672,6 +683,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     uint8_t gunIndex = 0;
     uint8_t stopChg = 0;
     uint8_t curGun = 0;
+    int isContinue = 1;
     float _Voltage;
     float _Current;
     uint8_t PreviousSystemStatus[2] = {0xff};
@@ -679,7 +691,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                      "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
                      "       chg    <voltage> <current>            ex: chg 500 100\n"
                      "       c      <index>                        ex: c 0\n"
-                     "       help | ? | h\n";
+                     "       help | ? | h\n"
+                     "\r\n";
 
     if (strcmp(v1, "auto") == EQUAL) {
         _usingAutoRun = 0x01;
@@ -710,7 +723,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     pSysInfo->CurGunSelected = _GunIndex;
 
-    while (true) {
+    while (isContinue) {
+
         curGun = pSysInfo->CurGunSelected;
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
 
@@ -912,8 +926,9 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 if (PreviousSystemStatus[gunIndex] == 0xFF) {
                     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-
                     pDcChargingInfo->SystemStatus = S_IDLE;
+                } else {
+                    pSysInfo->CurGunSelected = gunIndex;
                 }
 
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
@@ -928,6 +943,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             if (stopChg == pSysConfig->TotalConnectorCount) {
                 system("/root/Module_EvComm &");
                 sleep(3);
+
+                for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+                    pDcChargingInfo->SystemStatus = S_IDLE;
+                }
                 return;
             }
             break;
@@ -1021,29 +1042,71 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     }
 }
 
+int printTimeMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256] = {0};
+    char buffer[4096] = {0};
+    int rc = -1;
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    va_start(args, fmt);
+    rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+            tm->tm_hour,
+            tm->tm_min,
+            tm->tm_sec,
+            SeqEndTime.millitm,
+            buffer);
+    printf("%s", Buf);
+
+    return rc;
+}
+
 static void resdGunAndChillerTemp(void)
 {
     int isContinue = 1;
     uint8_t i = 0;
-    uint8_t sleepTime = 3;
+    uint32_t sleepTime = 500000;
+    uint32_t loopTime = 1000;
+    struct timeb showTime;
+    struct timeb nowTime;
+
     char *usageMsg = "Usage:\n"
                      "       t <index>: loop time, ex: t 1\n"
                      "       exit | c | C: exit test\n"
-                     "       h | help | ?: show usage message\n";
+                     "       h | help | ?: show usage message\n"
+                     "\r\n";
+
+    ftime(&showTime);
 
     while (isContinue) {
-        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        ftime(&nowTime);
 
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+        if (DiffTimeb(showTime, nowTime) > loopTime ||
+                DiffTimeb(showTime, nowTime) < 0) {
+            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
 
-            printf("get %d gun temp = %d, chiller temp = %d\r\n",
-                   i,
-                   pDcChargingInfo->ConnectorTemp,
-                   pDcChargingInfo->ChillerTemp);
-        }//for
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                printTimeMsg("get %d gun temp = %d, chiller temp = %d\r\n",
+                             i,
+                             pDcChargingInfo->ConnectorTemp,
+                             pDcChargingInfo->ChillerTemp);
+            }//for
+            ftime(&showTime);
+        }
 
         if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
-            sleep(sleepTime);
+            usleep(sleepTime);
             continue;
         }
 
@@ -1056,15 +1119,17 @@ static void resdGunAndChillerTemp(void)
                 continue;
             }
 
-            sleepTime = atoi((char *)newString[1]);
-
+            loopTime = ((atoi((char *)newString[1])) * 1000);
+            printf("loopTime = %d\r\n", loopTime);
+            ftime(&showTime);
+            continue;
         } else if (exitCmd() == YES) {
             return;
         } else if (helpCmd() == YES) {
             printf ("%s\n", usageMsg);
         }
 
-        sleep(sleepTime);
+        usleep(sleepTime);
     }//while
 }
 
@@ -1072,18 +1137,19 @@ static void writeGunAndChillerTemp(void)
 {
     uint8_t _GunIndex = 0;
     int isContinue = 1;
-    uint8_t sleepTime = 3;
+    uint32_t sleepTime = 500000;
     char *usageMsg = "Usage:\n"
                      "       conn    <index> <temp>, ex: conn 0 150\n"
                      "       chiller <index> <temp>, ex: chiller 0 150\n"
                      "       tempR\n"
                      "       exit | c | C\n"
-                     "       help | ? | h\n";
+                     "       help | ? | h\n"
+                     "\r\n";
 
     ShmDcCommonData->TestTemperature = YES;
 
     while (isContinue) {
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
             sleep(sleepTime);
             continue;
         }
@@ -1095,6 +1161,8 @@ static void writeGunAndChillerTemp(void)
             ShmDcCommonData->TestTemperature = NO;
             sleep(1);
             return;
+        } else if (strcmp(newString[0], "tempR") == 0) {
+            resdGunAndChillerTemp();
         }
 
         if ((strcmp(newString[0], "chiller") != 0) &&
@@ -1105,7 +1173,8 @@ static void writeGunAndChillerTemp(void)
             continue;
         }
 
-        if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) {
+        if (atoi(newString[2]) > 255 ||
+                atoi(newString[2]) == -1) {
             printf("temperature value overflow\r\n");
             continue;
         }
@@ -1134,11 +1203,9 @@ static void writeGunAndChillerTemp(void)
             printf("set %d connector temp = %d\r\n",
                    _GunIndex,
                    pDcChargingInfo->ConnectorTemp);
-        } else if (strcmp(newString[0], "tempR") == 0) {
-            resdGunAndChillerTemp();
         }
 
-        sleep(1);
+        usleep(sleepTime);
     }//while
 }
 
@@ -1154,7 +1221,7 @@ int main(void)
                      "       sysid                             : test system ID\n"
                      "       self                              : self test state (x)\n"
                      "       version | v | -v                  : version of board (407 or relay or other)\n"
-                     "       update                            : update firmware"
+                     "       update                            : update firmware\n"
                      "       ac                                : get ac relay state (x) \n"
                      "       cable <index> <state>             : set ground fault state\n"
                      "       pow <index> <power>               : set power value\n"
@@ -1164,7 +1231,8 @@ int main(void)
                      "       strchg <auto>                     : auto test charging\n"
                      "       strchg <index> <voltage <current> : select gun test charging\n"
                      "       tempW                             : write connector header and Chiller temperature\r\n"
-                     "       tempR                             : print connector header and chiller temperature\r\n";
+                     "       tempR                             : print connector header and chiller temperature\r\n"
+                     "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
         printf("create share memory error\r\n");
@@ -1332,7 +1400,7 @@ int main(void)
         } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
             resdGunAndChillerTemp();
         } else {
-            printf ("%s\n", usageMsg);
+            printf("%s\n", usageMsg);
         }
 
         sleep(1);

+ 127 - 0
EVSE/Projects/Noodoe/Apps/Module_ConfigTools.c

@@ -247,6 +247,7 @@ int main(void)
 		printf("\n  system: system configuration menu.");
 		printf("\n  ocpp: ocpp configuration menu.");
 		printf("\n  network: netwok configuration menu.");
+		printf("\n  test: charger start/stop test.");
 		printf("\n  upgrade: trigger firmware upgrade.");
 		printf("\n  save: Save config.");
 		printf("\n  exit: Exit config tools.");
@@ -261,6 +262,8 @@ int main(void)
 			printf("\n ***** system configuration menu ******************");
 			printf("\n  modelname: EVSE model name.");
 			printf("\n  serialnumber: EVSE serial number.");
+			printf("\n  authentication: Authentication function.");
+			printf("\n  rfidendian: RFID read endian.");
 			printf("\n *************************************************");
 			printf("\n  Please input operation item: ");
 			scanf("%s", &cmd[0]);
@@ -305,6 +308,34 @@ int main(void)
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], (char*)&cmd[0]);
 				}
 			}
+			else if(strcmp(cmd, "authentication") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Enable.");
+				printf("\n  1: Disable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.AuthorisationMode);
+				printf("\n  Please input authentication mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+			}
+			else if(strcmp(cmd, "rfidendian") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Little endian.");
+				printf("\n  1: Big endian.");
+				printf("\n *************************************************");
+
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
+				printf("\n  Please input rfid endian mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+			}
 		}
 		else if(strcmp(cmd, "ocpp") == 0)
 		{
@@ -312,6 +343,9 @@ int main(void)
 			printf("\n *************************************************");
 			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  Please input operation item: ");
 			scanf("%s", &cmd[0]);
@@ -356,6 +390,55 @@ int main(void)
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
 				}
 			}
+			else if(strcmp(cmd, "vender") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				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  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input OCPP vender: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "offlinepolicy") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				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  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);
+			}
+			else if(strcmp(cmd, "localloadbalance") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Enable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging);
+				printf("\n  Please input local load balance mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+			}
 		}
 		else if(strcmp(cmd, "network") == 0)
 		{
@@ -532,6 +615,50 @@ int main(void)
 				}
 			}
 		}
+		else if(strcmp(cmd, "test") == 0)
+		{
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n ***** test menu ******************");
+			printf("\n  start: EVSE start charging request.");
+			printf("\n  stop: EVSE stop charging request.");
+			printf("\n  cancel: return to main menu.");
+			printf("\n *************************************************");
+			printf("\n  Please input operation item: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "start") == 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))
+				{
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStart = ON;
+				}
+				else
+				{
+					printf("\n  Invalid input gun_index.");
+				}
+			}
+			else if(strcmp(cmd, "stop") == 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))
+				{
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[atoi(cmd)-1].schedule.isTriggerStop = ON;
+				}
+				else
+				{
+					printf("\n  Invalid input gun_index.");
+				}
+			}
+			else if(strcmp(cmd, "cancel") == 0)
+			{}
+		}
 		else if(strcmp(cmd, "upgrade") == 0)
 		{
 			printf("\n  Firmware upgrade trigger.");

+ 92 - 0
EVSE/Projects/Noodoe/Apps/Module_Debug.c

@@ -40,6 +40,7 @@
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
+struct OCPP16Data				*ShmOCPP16Data;
 struct Charger					*ShmCharger;
 
 int StoreLogMsg(const char *fmt, ...)
@@ -113,6 +114,18 @@ int InitShareMemory()
 		result = FAIL;
 	}
 
+	// Initial ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
+	{
+		DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
+		result = FAIL;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
+		result = FAIL;
+	}
+
 	//Initial ShmCharger
 	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
 	{
@@ -165,6 +178,7 @@ int main(void)
 		memset(cmd, 0x00, ARRAY_SIZE(cmd));
 		printf("\n ============== Debug main menu ==================");
 		printf("\n  info: List charger status info.");
+		printf("\n  test: Charger test command.");
 		printf("\n  exit: Exit Module_Debug_Test.");
 		printf("\n =================================================");
 		printf("\n  Please input debug command: ");
@@ -195,14 +209,26 @@ int main(void)
 
 					gun_index = gun_index<AC_QUANTITY?gun_index:0;
 
+					printf("\n  CSU u-boot version: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
+					printf("\n  CSU kernel version: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
+					printf("\n  CSU rootfs version: %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+					printf("\n --------------------------------------------------");
 					printf("\n  Charger connector plug times: %d", ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+					printf("\n --------------------------------------------------");
 					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 --------------------------------------------------");
 					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 --------------------------------------------------");
 					printf("\n  Charger charging mode BS/HLC: %d", ShmCharger->gun_info[gun_index].chargingMode);
+					printf("\n --------------------------------------------------");
 					printf("\n  Charger input voltage L1: %.2f", ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
+					printf("\n --------------------------------------------------");
 					printf("\n  CSU output current L1: %.2f", ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
+					printf("\n --------------------------------------------------");
+					printf("\n  CSU power total consumption: %.2f", (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0));
+					printf("\n --------------------------------------------------");
 					printf("\n  CSU temperature: %d", ShmCharger->gun_info[gun_index].temperature.point[0]);
 
 					wait();
@@ -213,7 +239,9 @@ int main(void)
 					scanf("%d", &gun_index);
 					printf("\n  MCU info.\n\n");
 
+					gun_index = gun_index<AC_QUANTITY?gun_index:0;
 
+					printf("\n  Firmware version: %s", ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 					wait();
 				}
@@ -224,6 +252,70 @@ int main(void)
 				}
 			}while(!isExit);
 		}
+		else if(strcmp(cmd, "test") == 0)
+		{
+			int gun_index;
+
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n ***************** Info menu *********************");
+			printf("\n  start: start charging session");
+			printf("\n  stop: stop charging session");
+			printf("\n  operative: enable charger gun");
+			printf("\n  inoperative: disable charger gun");
+			printf("\n  exit: exit to previous menu.");
+			printf("\n *************************************************");
+			printf("\n  Please input command: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "start") == 0)
+			{
+				printf("\n  Please input gun index: ");
+				scanf("%d", &gun_index);
+
+				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].schedule.isTriggerStart = ON;
+			}
+			else if(strcmp(cmd, "stop") == 0)
+			{
+				printf("\n  Please input gun index: ");
+				scanf("%d", &gun_index);
+
+				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].schedule.isTriggerStop = ON;
+			}
+			else if(strcmp(cmd, "operative") == 0)
+			{
+				printf("\n  Please input gun index: ");
+				scanf("%d", &gun_index);
+
+				if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+				{
+					sprintf((char*)ShmOCPP16Data->ChangeAvailability[gun_index].Type, "Operative");
+					ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = ON;
+				}
+				else
+				{
+				
+				}
+			}
+			else if(strcmp(cmd, "inoperative") == 0)
+			{
+				printf("\n  Please input gun index: ");
+				scanf("%d", &gun_index);
+
+				if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+				{
+					sprintf((char*)ShmOCPP16Data->ChangeAvailability[gun_index].Type, "Inoperative");
+					ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = ON;
+				}
+				else
+				{
+				
+				}
+			}
+			else if(strcmp(cmd, "exit") == 0)
+			{
+				printf("\n  Exit to previous.\n\n");
+			}
+		}
 		else if(strcmp(cmd, "exit") == 0)
 		{
 			printf("\n  exit program.\n\n");

+ 3 - 3
EVSE/Projects/Noodoe/Apps/Module_FactoryConfig.c

@@ -395,17 +395,17 @@ int main(int argc, char *argv[])
 	if((outType&OUTPUT_FLASH)>0)
 	{
 		DEBUG_INFO("Erase /dev/mtd10.\n");
-		runShellCmd("flash_erase /dev/mtd10 0 12");
+		runShellCmd("flash_erase /dev/mtd10 0 0");
 		DEBUG_INFO("Write /dev/mtd10.\n");
 		runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
 
 		DEBUG_INFO("Erase /dev/mtd11.\n");
-		runShellCmd("flash_erase /dev/mtd11 0 12");
+		runShellCmd("flash_erase /dev/mtd11 0 0");
 		DEBUG_INFO("Write /dev/mtd11.\n");
 		runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
 
 		DEBUG_INFO("Erase /dev/mtd12.\n");
-		runShellCmd("flash_erase /dev/mtd12 0 12");
+		runShellCmd("flash_erase /dev/mtd12 0 0");
 		DEBUG_INFO("Write /dev/mtd12.\n");
 		runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
 

+ 95 - 1
EVSE/Projects/Noodoe/Apps/main.c

@@ -34,6 +34,9 @@
 #define TIMEOUT_SPEC_PROFILE_PREPARE	5000
 #define TIMEOUT_SPEC_PWN_CHANGE			5000
 
+#define SPEC_TEMPERATURE_WARN			75
+#define SPEC_TEMPERATURE_RECOVER		65
+
 #define MtdBlockSize 					0x300000
 
 #define DB_FILE							"/Storage/ChargeLog/localCgargingRecord.db"
@@ -1986,6 +1989,53 @@ unsigned char isModeChange(unsigned char gun_index)
 	return result;
 }
 
+void gpio_set_value(unsigned int gpio, unsigned int value)
+{
+	int fd;
+	char buf[256];
+
+	sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
+	fd = open(buf, O_WRONLY);
+	if (fd < 0)
+	{
+		DEBUG_ERROR("GPIO-%d set %d fail.\n", gpio, value);
+	    return;
+	}
+
+	if (value)
+		write(fd, "1", 2);
+	else
+	    write(fd, "0", 2);
+
+	close(fd);
+}
+
+int gpio_get_value(unsigned int gpio)
+{
+    int fd;
+    char buf[256];
+    char ch;
+    int8_t result = FAIL;
+
+    sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
+    fd = open(buf, O_RDONLY);
+    if (fd < 0)
+    {
+        DEBUG_ERROR("GPIO-%d get fail\n", gpio);
+        return result;
+    }
+
+    read(fd, &ch, 1);
+    if (ch != '0')
+        result = 1;
+    else
+        result = 0;
+
+    close(fd);
+
+    return result;
+}
+
 //===============================================
 // Get firmware version
 //===============================================
@@ -3350,7 +3400,8 @@ int main(void)
 				{
 					setLedMotion(gun_index,LED_ACTION_INIT);
 				}
-
+				
+				sleep(5);
 				system("cd /root;./Module_FactoryConfig -m");
 				system("rm -f /Storage/OCPP/OCPPConfiguration");
 				system("sync");
@@ -4012,6 +4063,17 @@ int main(void)
 						// Checking profile id > 0 and current time is between charging profile validFrom & validTo
 						checkChargingProfileLimit(gun_index);
 
+						// If temperature warning derating PWM duty 20%
+						if(ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp >= SPEC_TEMPERATURE_WARN)
+						{
+							ShmCharger->gun_info[gun_index].tempCoefficient = 0.8;
+						}
+						else if(ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp <= SPEC_TEMPERATURE_RECOVER)
+						{
+							ShmCharger->gun_info[gun_index].tempCoefficient = 1.0;
+						}
+						ShmCharger->gun_info[gun_index].targetCurrent = (ShmCharger->gun_info[gun_index].targetCurrent==0?ShmCharger->gun_info[gun_index].targetCurrent:(((ShmCharger->gun_info[gun_index].targetCurrent*ShmCharger->gun_info[gun_index].tempCoefficient)>=6) ?	(ShmCharger->gun_info[gun_index].targetCurrent*ShmCharger->gun_info[gun_index].tempCoefficient):6));
+
 						// Determine max charging current to MCU
 						if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
 						{
@@ -4334,6 +4396,38 @@ int main(void)
 							}
 						}
 
+						// Charging profile preparation
+						if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_PROFILE_PREPARE]) > TIMEOUT_SPEC_PROFILE_PREPARE)
+						{
+							if(!ocpp_get_profile_conf(gun_index))
+							{
+								ocpp_set_profile_req(gun_index, ON);
+								ftime(&startTime[gun_index][TMR_IDX_PROFILE_PREPARE]);
+							}
+							else
+							{
+								ocpp_set_profile_conf(gun_index, OFF);
+							}
+						}
+
+						// Check target current if charging profile limit > 0
+						checkChargingProfileLimit(gun_index);
+						if(ShmCharger->gun_info[gun_index].targetCurrent > 0)
+						{
+							setRelay(gun_index, ON);
+						}
+
+						// Debug information
+						if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_LOGPPRINTOUT]) > TIMEOUT_SPEC_LOGPPRINTOUT)
+						{
+							DEBUG_INFO("=============================================================\n");
+							DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent: %d\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
+							DEBUG_INFO("ShmCharger->gun_info[%d].primaryMcuCp_Pwn_Duty.max_current: %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+							DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent: %d\n", gun_index, ShmCharger->gun_info[gun_index].targetCurrent);
+							DEBUG_INFO("=============================================================\n");
+							ftime(&startTime[gun_index][TMR_IDX_LOGPPRINTOUT]);
+						}
+
 						if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) &&
 						   (ShmCharger->gun_info[gun_index].rfidReq != ON) &&
 						   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop != ON)  &&

+ 1 - 0
EVSE/Projects/Noodoe/Apps/main.h

@@ -413,6 +413,7 @@ typedef struct GUN_INFO
 	Set_Led_Brightness								setLedBrightness;
 	uint8_t											chargingMode;
 	uint16_t										targetCurrent;
+	float											tempCoefficient;
 	uint16_t										isAuthPassEnd:1;
 	uint16_t										rfidReq:1;
 	uint16_t										isGunPlugged:1;

BIN
EVSE/Projects/Noodoe/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/Noodoe/Images/ramdisk.gz


+ 9 - 0
EVSE/rootfs/etc/init.d/rcS

@@ -118,3 +118,12 @@ echo 3 > /proc/sys/kernel/panic
 #echo 1 > /proc/sys/kernel/panic_on_rcu_stall
 /sbin/klogd
 /sbin/syslogd -f /etc/syslog.conf
+
+#   ---------------------------------------------
+#   Enable swap
+#   ---------------------------------------------
+#dd if=/dev/zero of=/Storage/swapfile bs=1024 count=65535
+#losetup /dev/loop7 /Storage/swapfile
+#mkswap /dev/loop7
+#swapon /dev/loop7
+

+ 24 - 17
Makefile

@@ -22,9 +22,10 @@ Taurus-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Taurus]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/Taurus/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/Taurus/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/Taurus/Images/
 
 Taurus-linux-default: linux_clean linux
 	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/Taurus/Images/
@@ -97,7 +98,7 @@ DD360-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DD360]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/DD360/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/DD360/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/DD360/Images/
@@ -171,9 +172,10 @@ CCS-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[CCS]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/CCS/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/CCS/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/CCS/Images/
 
 CCS-linux-default: linux_clean linux
 	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/CCS/Images/
@@ -275,9 +277,10 @@ DM30-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DM30]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/DM30/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/DM30/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/DM30/Images/
 
 DM30-linux-default: linux_clean linux
 	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/DM30/Images/
@@ -370,9 +373,10 @@ DW30-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DW30]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/DW30/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/DW30/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/DW30/Images/
 
 DW30-linux-default: linux_clean linux
 	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/DW30/Images/
@@ -469,9 +473,10 @@ DS60-120-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DS60-120]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/DS60-120/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/DS60-120/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/DS60-120/Images/
 
 DS60-120-linux-default: linux_clean linux
 	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/DS60-120/Images/
@@ -540,9 +545,10 @@ AW-Regular-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-Regular]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F8G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/AW-Regular/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/AW-Regular/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/AW-Regular/Images/
 
 AW-Regular-linux-default: linux_clean linux
 	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/AW-Regular/Images/
@@ -611,9 +617,10 @@ BYTON-GB-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[BYTON-GB]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/BYTON-GB/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/BYTON-GB/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/BYTON-GB/Images/
 
 BYTON-GB-linux-default: linux_clean linux
 	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/BYTON-GB/Images/
@@ -1034,7 +1041,7 @@ Noodoe-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Noodoe]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F8G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/Noodoe/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/Noodoe/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/Noodoe/Images/
@@ -1107,7 +1114,7 @@ PlugIt360-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[PlugIt360]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/PlugIt360/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/PlugIt360/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/PlugIt360/Images/
@@ -1180,7 +1187,7 @@ AW-CCS-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-CCS]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F8G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/AW-CCS/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/AW-CCS/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/AW-CCS/Images/
@@ -1252,7 +1259,7 @@ DO360-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DO360]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/DO360/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/DO360/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/DO360/Images/
@@ -1325,7 +1332,7 @@ ATE-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[ATE]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/ATE/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/ATE/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/ATE/Images/
@@ -1398,7 +1405,7 @@ Zanobe-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Zanobe]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/Zanobe/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/Zanobe/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/Zanobe/Images/
@@ -1471,7 +1478,7 @@ e4you-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[e4you]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/e4you/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/e4you/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/e4you/Images/
@@ -1544,7 +1551,7 @@ DD360Audi-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DD360Audi]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/DD360Audi/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/DD360Audi/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/DD360Audi/Images/
@@ -1616,7 +1623,7 @@ AW-ChargeLab-uboot:
 	@echo    Building U-boot
 	@echo ===================================
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-ChargeLab]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F8G08
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/AW-ChargeLab/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/AW-ChargeLab/Images/
 	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/AW-ChargeLab/Images/

+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[AW-CCS]am335x-evm.dts

@@ -426,7 +426,7 @@
 		interrupts = <0 IRQ_TYPE_NONE>, /* fifoevent */
                     <1 IRQ_TYPE_NONE>;	/* termcount */
 		rb-gpios = <&gpmc 0 GPIO_ACTIVE_HIGH>; /* gpmc_wait0 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[AW-ChargeLab]am335x-evm.dts

@@ -414,7 +414,7 @@
 		interrupts = <0 IRQ_TYPE_NONE>, /* fifoevent */
                     <1 IRQ_TYPE_NONE>;	/* termcount */
 		rb-gpios = <&gpmc 0 GPIO_ACTIVE_HIGH>; /* gpmc_wait0 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[AW-Regular]am335x-evm.dts

@@ -414,7 +414,7 @@
 		interrupts = <0 IRQ_TYPE_NONE>, /* fifoevent */
                     <1 IRQ_TYPE_NONE>;	/* termcount */
 		rb-gpios = <&gpmc 0 GPIO_ACTIVE_HIGH>; /* gpmc_wait0 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[Noodoe]am335x-evm.dts

@@ -414,7 +414,7 @@
 		interrupts = <0 IRQ_TYPE_NONE>, /* fifoevent */
                     <1 IRQ_TYPE_NONE>;	/* termcount */
 		rb-gpios = <&gpmc 0 GPIO_ACTIVE_HIGH>; /* gpmc_wait0 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 2 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/Makefile

@@ -359,7 +359,8 @@ KBUILD_CPPFLAGS := -D__KERNEL__ -D__UBOOT__
 
 KBUILD_CFLAGS   := -Wall -Wstrict-prototypes \
 		   -Wno-format-security \
-		   -fno-builtin -ffreestanding
+		   -fno-builtin -ffreestanding \
+		   -D $(FLASH_IC)
 KBUILD_AFLAGS   := -D__ASSEMBLY__
 
 # Read UBOOTRELEASE from include/config/uboot.release (if it exists)

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[ATE]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 2 - 2
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-CCS]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 
@@ -521,7 +521,7 @@
 	ranges = <0 0 0x08000000 0x40000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 2 - 2
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-ChargeLab]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 
@@ -521,7 +521,7 @@
 	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 2 - 2
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-Regular]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 
@@ -521,7 +521,7 @@
 	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[CCS]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DD360Audi]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DD360]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DM30]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DO360]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DS60-120-Infy]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DS60-120]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[DW30]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 2 - 2
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Noodoe]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 
@@ -521,7 +521,7 @@
 	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[PlugIt360]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Taurus]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Zanobe]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[e4you]am335x-evm.dts

@@ -27,7 +27,7 @@
 
 	memory {
 		device_type = "memory";
-		reg = <0x80000000 0x10000000>; /* 256 MB */
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
 		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
 	};
 

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts

@@ -521,7 +521,7 @@
 	ranges = <0 0 0x08000000 0x40000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;

+ 10 - 2
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/common/autoboot.c

@@ -17,7 +17,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define uboot_version "01.01"
+#define uboot_version "01.02"
 
 #define MAX_DELAY_STOP_STR 32
 
@@ -358,7 +358,15 @@ void autoboot_command(const char *s)
 	                memset(BufTmp,0,0x600000);
                 	run_command_list("nand read 0x80000000 0x09000000 0x00600000", -1, 0);
         	        sprintf(BufTmp,&uboot_version,strlen(uboot_version));
-	                for(i=0;i<(0x00600000-4);i++)
+	
+			for(i=32;i<(0x00300000-4);i++)
+                        {
+                                Chk+=*(BufTmp+i);
+                        }
+                        memcpy(BufTmp+(0x00300000-4),&Chk,4);
+
+			Chk=0;
+			for(i=0;i<(0x00600000-4);i++)
                 	{
                         	Chk+=*(BufTmp+i);
         	        }

+ 63 - 29
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/include/configs/am335x_evm.h

@@ -230,47 +230,81 @@
 
 #ifdef CONFIG_NAND
 /* NAND: device related configs */
+#if defined(MT29F8G08)
+	#define CONFIG_SYS_NAND_ECCPOS	{ 2, 3, 4, 5, 6, 7, 8, 9, \
+					  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, \
+					  20, 21, 22, 23, 24, 25, 26, 27, 28, 29, \
+					  30, 31, 32, 33, 34, 35, 36, 37, 38, 39, \
+					  40, 41, 42, 43, 44, 45, 46, 47, 48, 49, \
+					  50, 51, 52, 53, 54, 55, 56, 57, 58, 59, \
+					  60, 61, 62, 63, 64, 65, 66, 67, 68, 69, \
+					  70, 71, 72, 73, 74, 75, 76, 77, 78, 79, \
+					  80, 81, 82, 83, 84, 85, 86, 87, 88, 89, \
+					  90, 91, 92, 93, 94, 95, 96, 97, 98, 99, \
+					  100, 101, 102, 103, 104, 105, 106, 107, 108, 109, \
+					  110, 111, 112, 113, 114, 115, 116, 117, 118, 119, \
+					  120, 121, 122, 123, 124, 125, 126, 127, 128, 129, \
+					  130, 131, 132, 133, 134, 135, 136, 137, 138, 139, \
+					  140, 141, 142, 143, 144, 145, 146, 147, 148, 149, \
+					  150, 151, 152, 153, 154, 155, 156, 157, 158, 159, \
+					  160, 161, 162, 163, 164, 165, 166, 167, 168, 169, \
+					  170, 171, 172, 173, 174, 175, 176, 177, 178, 179, \
+					  180, 181, 182, 183, 184, 185, 186, 187, 188, 189, \
+					  190, 191, 192, 193, 194, 195, 196, 197, 198, 199, \
+					  200, 201, 202, 203, 204, 205, 206, 207, 208, 209, }
+	#define CONFIG_SYS_NAND_ECCBYTES	26
+	#define CONFIG_NAND_OMAP_ECCSCHEME	OMAP_ECC_BCH16_CODE_HW
+	#define CONFIG_SYS_NAND_OOBSIZE		256//64 /*++++ vern,NAND,20161127 ---*/
+	#define CONFIG_SYS_NAND_PAGE_SIZE	4096//2048 /*++++ vern,NAND,20161127 ---*/
+	#define CONFIG_SYS_NAND_BLOCK_SIZE	(64*4096)//(128*1024)/*++++ vern,NAND,20161127 ---*/
+#elif defined(MT29F16G08)
+	#define CONFIG_SYS_NAND_ECCPOS	{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, \
+					 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, \
+					 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, \
+					 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, \
+					 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, \
+					 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, \
+					 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, \
+					 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, \
+					 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, \
+					 110, 111, 112, 113 }
+	#define CONFIG_SYS_NAND_ECCBYTES	14
+	#define CONFIG_NAND_OMAP_ECCSCHEME	OMAP_ECC_BCH8_CODE_HW
+	#define CONFIG_SYS_NAND_OOBSIZE		224//64 /*++++ vern,NAND,20161127 ---*/
+	#define CONFIG_SYS_NAND_PAGE_SIZE	4096//2048 /*++++ vern,NAND,20161127 ---*/
+	#define CONFIG_SYS_NAND_BLOCK_SIZE	(64*4096)//(128*1024)/*++++ vern,NAND,20161127 ---*/
+#else
+	#define CONFIG_SYS_NAND_ECCPOS  {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, \
+                                         16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, \
+                                         28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, \
+                                         40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, \
+                                         52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, \
+                                         64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, \
+                                         76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, \
+                                         88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, \
+                                         100, 101, 102, 103, 104, 105, 106, 107, 108, 109, \
+                                         110, 111, 112, 113 }
+        #define CONFIG_SYS_NAND_ECCBYTES        14
+        #define CONFIG_NAND_OMAP_ECCSCHEME      OMAP_ECC_BCH8_CODE_HW
+        #define CONFIG_SYS_NAND_OOBSIZE         224//64 /*++++ vern,NAND,20161127 ---*/
+        #define CONFIG_SYS_NAND_PAGE_SIZE       4096//2048 /*++++ vern,NAND,20161127 ---*/
+        #define CONFIG_SYS_NAND_BLOCK_SIZE      (64*4096)//(128*1024)/*++++ vern,NAND,20161127 ---*/
+#endif
+
 #define CONFIG_SYS_NAND_5_ADDR_CYCLE
 #define CONFIG_SYS_NAND_PAGE_COUNT	(CONFIG_SYS_NAND_BLOCK_SIZE / \
 					 CONFIG_SYS_NAND_PAGE_SIZE)
-#define CONFIG_SYS_NAND_PAGE_SIZE	4096//2048 /*++++ vern,NAND,20161127 ---*/
-#define CONFIG_SYS_NAND_OOBSIZE		224//64 /*++++ vern,NAND,20161127 ---*/
-#define CONFIG_SYS_NAND_BLOCK_SIZE	(64*4096)//(128*1024)/*++++ vern,NAND,20161127 ---*/
+
+#define CONFIG_SYS_NAND_ECCSIZE		512	
 /* NAND: driver related configs */
 #define CONFIG_NAND_OMAP_GPMC
 #define CONFIG_NAND_OMAP_GPMC_PREFETCH
 #define CONFIG_NAND_OMAP_ELM
 #define CONFIG_SYS_NAND_BAD_BLOCK_POS	NAND_LARGE_BADBLOCK_POS
  /*++++ vern,NAND,20161127 +++*/
-/*æ¯?12 Bytes ?„page size?€? ä?14 Bytes
-  ?€ä»?096 page size ?€? ä? (4096/512)*14=112 Bytes
-*/
-#define CONFIG_SYS_NAND_ECCPOS	   {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, \
-					16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, \
-					28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, \
-					40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, \
-					52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, \
-					64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, \
-					76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, \
-					88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, \
-					100, 101, 102, 103, 104, 105, 106, 107, 108, 109, \
-					110, 111, 112, 113 }
-/*
-#define CONFIG_SYS_NAND_ECCPOS		{ 2, 3, 4, 5, 6, 7, 8, 9, \
-					 10, 11, 12, 13, 14, 15, 16, 17, \
-					 18, 19, 20, 21, 22, 23, 24, 25, \
-					 26, 27, 28, 29, 30, 31, 32, 33, \
-					 34, 35, 36, 37, 38, 39, 40, 41, \
-					 42, 43, 44, 45, 46, 47, 48, 49, \
-					 50, 51, 52, 53, 54, 55, 56, 57, }
-*/
 
-#define CONFIG_SYS_NAND_ECCSIZE		512	/*æ¯?12 Bytes ?„page size?€? ä?14 Bytes*/
-#define CONFIG_SYS_NAND_ECCBYTES	14	/*æ¯?12 Bytes ?„page size?€? ä?14 Bytes*/
  /*--- vern,NAND,20161127 ---*/
-
 #define CONFIG_SYS_NAND_ONFI_DETECTION
-#define CONFIG_NAND_OMAP_ECCSCHEME	OMAP_ECC_BCH8_CODE_HW
 #define MTDIDS_DEFAULT			"nand0=nand.0"
 /*++++ vern,set up environment,20161127 +++*/
 /*

+ 1 - 1
run_gen_make_script.sh

@@ -15,7 +15,7 @@ echo -e "\t@echo ==================================="
 echo -e "\t@echo    Building U-boot"
 echo -e "\t@echo ==================================="
 echo -e "\t@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[$1]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts"
-echo -e "\t\$(MAKE) -j \$(MAKE_JOBS) -C \$(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=\$(CROSS_COMPILE)"
+echo -e "\t\$(MAKE) -j \$(MAKE_JOBS) -C \$(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=\$(CROSS_COMPILE) FLASH_IC=MT29F16G08"
 echo -e "\t@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/$1/Images/"
 echo -e "\t@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/$1/Images/"
 echo -e "\t@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/$1/Images/"