Browse Source

Merge branch 'master' into DD360Audi

Jerry_Wang 3 years ago
parent
commit
d4e4e52292
40 changed files with 1586 additions and 1166 deletions
  1. 1 3
      EVSE/Modularization/Module_4g.c
  2. 328 221
      EVSE/Modularization/Module_Payment.c
  3. 8 2
      EVSE/Modularization/Module_Payment.h
  4. 5 5
      EVSE/Modularization/WebService.c
  5. 65 15
      EVSE/Modularization/ocpp20/MessageHandler.c
  6. 0 30
      EVSE/Modularization/ocpp20/Module_OcppBackend20.c
  7. 55 26
      EVSE/Modularization/ocppfiles/MessageHandler.c
  8. 0 19
      EVSE/Modularization/ocppfiles/Module_OcppBackend.c
  9. 77 58
      EVSE/Projects/AW-CCS/Apps/LCM/Module_LcmControl.c
  10. 12 24
      EVSE/Projects/AW-CCS/Apps/Module_InternalComm.c
  11. 358 514
      EVSE/Projects/AW-CCS/Apps/main.c
  12. 5 3
      EVSE/Projects/AW-CCS/Apps/main.h
  13. BIN
      EVSE/Projects/AW-CCS/Images/FactoryDefaultConfig.bin
  14. BIN
      EVSE/Projects/AW-CCS/Images/ramdisk.gz
  15. 48 1
      EVSE/Projects/AW-ChargeLab/Apps/main.c
  16. 47 0
      EVSE/Projects/AW-Regular/Apps/main.c
  17. 7 6
      EVSE/Projects/DS60-120/Apps/Config.h
  18. BIN
      EVSE/Projects/DS60-120/Apps/FactoryConfig
  19. BIN
      EVSE/Projects/DS60-120/Apps/Module_EvComm
  20. 29 13
      EVSE/Projects/DS60-120/Apps/Module_EvComm.c
  21. BIN
      EVSE/Projects/DS60-120/Apps/Module_EventLogging
  22. BIN
      EVSE/Projects/DS60-120/Apps/Module_InternalComm
  23. 117 53
      EVSE/Projects/DS60-120/Apps/Module_InternalComm.c
  24. 2 0
      EVSE/Projects/DS60-120/Apps/Module_LcmContro.h
  25. BIN
      EVSE/Projects/DS60-120/Apps/Module_LcmControl
  26. 33 12
      EVSE/Projects/DS60-120/Apps/Module_LcmControl.c
  27. BIN
      EVSE/Projects/DS60-120/Apps/Module_PrimaryComm
  28. BIN
      EVSE/Projects/DS60-120/Apps/Module_PsuComm
  29. 37 4
      EVSE/Projects/DS60-120/Apps/Module_PsuComm.c
  30. BIN
      EVSE/Projects/DS60-120/Apps/ReadCmdline
  31. 16 2
      EVSE/Projects/DS60-120/Apps/ReadCmdline.c
  32. BIN
      EVSE/Projects/DS60-120/Apps/UnsafetyOutputTask
  33. BIN
      EVSE/Projects/DS60-120/Apps/main
  34. 276 142
      EVSE/Projects/DS60-120/Apps/main.c
  35. BIN
      EVSE/Projects/DS60-120/Images/ramdisk.gz
  36. 47 0
      EVSE/Projects/Noodoe/Apps/main.c
  37. BIN
      EVSE/rootfs/root/Module_Payment
  38. BIN
      EVSE/rootfs/root/OcppBackend20
  39. 2 2
      EVSE/rootfs/var/www/set_charging.php
  40. 11 11
      EVSE/rootfs/var/www/set_system.php

+ 1 - 3
EVSE/Modularization/Module_4g.c

@@ -218,9 +218,7 @@ int Check4GModem(void)
     else if((access("/dev/ttyACM0", F_OK) != -1) &&
     		(access("/dev/ttyACM1", F_OK) != -1) &&
         	(access("/dev/ttyACM2", F_OK) != -1) &&
-			(access("/dev/ttyACM3", F_OK) != -1) &&
-			(access("/dev/ttyACM4", F_OK) != -1) &&
-			(access("/dev/ttyACM5", F_OK) != -1))
+			(access("/dev/ttyACM3", F_OK) != -1))
     {
     	result = DONGLE_UBLOX;
     }

+ 328 - 221
EVSE/Modularization/Module_Payment.c

@@ -6,7 +6,7 @@
  */
 
 #include	"Module_Payment.h"
-unsigned char version[]					= {'D', '0', '.', '0', '3'};
+unsigned char version[]					= {'D', '0', '.', '0', '4'};
 unsigned char BLP_CMD_CARD_DETECT[]		= {0x09, 0, 0x07, 'M','F','1','4','1','2','1', 0x32};				// Enable payment, MIFARE, 15693 card; Detect Payment Card First;  Enable ApplePay VAS
 unsigned char BLP_CMD_USI2[]     		= {0x09, 0, 0x03, 'P', 'C', '0', 0x29};								// Configure protocol to USI2
 unsigned char BLP_CMD_SET_BAUD[] 		= {0x09, 0, 0x03, 'B', 'R', '7', 0x2d};								// Configure module baud rate to 115200
@@ -16,6 +16,7 @@ unsigned char BLP_CMD_SET_AID[]			= {0x09, 0, 0x04, 'A', 'D', '0', 0, 0x38};
 unsigned char BLP_CMD_LED_IND[]			= {0x09, 0, 0x05, 'R', 'I', 'E', 0x01, 0x01, 'R'};					// Reader LED indicator
 unsigned char BLP_CMD_CA_PKEY[]			= {0x09, 0, 0x03, 'C', 'K', 0x01, 0x03};							// Enable user CA Key
 unsigned char BLP_CMD_SOFTCARD_DISABLE[]= {0x09, 0, 0x03, 'I', 'S', 'D', 'T'};								// Disable soft card wallet application
+unsigned char BLP_CMD_BEEP_DISABLE[] 	= {0x09, 0, 0x03, 'B', 'A', 'D', 'M'};								// Beep disable
 unsigned char BLP_CMD_ERR_BEEP_STYLE[] 	= {0x09, 0, 0x03, 'B', 'D', 0, 0x0c};								// Error beep style configure 2 beeps
 unsigned char BLP_CMD_ERR_BEEP[]		= {0x09, 0, 0x03, 'B', 'T', 'D', 'X'};								// Error beep give sound
 unsigned char BLP_CMD_LRC_ENABLE[]		= {0x09, 0, 0x03, 'L', 'C', 'E', '@'};								// Enable LRC character of track data
@@ -32,14 +33,15 @@ unsigned char USI_CMD_C8_POLL[]			= {0x01, 0x00, 0x00, 0x2b,											// STX, a
 	                         	   	   	   0x9c, 0x01, 0x00,												// Transaction Type, sample: 00
 										   0x9a, 0x03, 0x21, 0x03, 0x24,									// Transaction Date, sample: 2021/03/24
 										   0x9f, 0x21, 0x03, 0x13, 0x36, 0x10,								// Transaction Time, sample: 13:36:10
-										   0xff, 0xff, 0x82, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00,			// Command timeout unit is million second, sample: umlimit
+										   0xff, 0xff, 0x82, 0x05, 0x04, 0x00, 0x00, 0x01, 0x2c,			// Command timeout unit is million second, sample: 300ms
 										   0x00};															// Checksum
 unsigned char USI_CMD_HALT_CARD[]		= {0x01, 0x00, 0x00, 0x01, 'x', 0x78};								// Halt card
 unsigned char USI_CMD_SET_DATE[]		= {0x01, 0, 0, 0x07, '5', '4', 0x14, 0x15, 0x05, 0x02, 0x01, 0x18};
 unsigned char USI_CMD_SET_TIME[]		= {0x01, 0, 0, 0x07, '5', '5', 0x0f, 0x1e, 0x20, 0, 0, 0x37};
 unsigned char USI_CMD_ARM_DISABLE[]		= {0x01, 0, 0, 0x02, 'H', '0', '{'};
+unsigned char USI_CMD_NFC_ACTIVE[]		= {0x01, 0, 0, 0x02, 'N', 0x00, 'M'};								// Enable NFC function
 unsigned char USI_CMD_NFC_POLL[]		= {0x01, 0, 0, 0x05, 'N', ' ', '3', 0x02, 0x01, 'Z'};				// Polling FELICA(NFC Type 3, 414kbps)
-
+unsigned char USI_CMD_BEEP_CONTROL[]	= {0x01, 0, 0, 0x05, 'B', '1', 0x7f, 0x09, 0x09, 0x08};				// Beep on 100ms 1 count
 
 int system_command(int uart, unsigned char* cmd, int cmd_len, unsigned char* rx);
 int USI2_Parse(unsigned char* rx, unsigned char* rx_data);
@@ -305,11 +307,8 @@ int InitComPort()
 {
 	int fd;
 	struct termios tios;
-#ifndef X86
-	fd = open("/dev/ttyS3", O_RDWR);
-#else
-	fd = open("/dev/ttyUSB3", O_RDWR);
-#endif
+
+	fd = open(TTY_PORT, O_RDWR);
 	if(fd<=0)
 	{
 		return FAIL;
@@ -395,6 +394,19 @@ int USI2_Parse(unsigned char* rx, unsigned char* rx_data)
 	return result;
 }
 
+/**
+ *
+ * @param onCnt: Buzzer on quantity
+ */
+void buzzer_on(int UartFd, uint8_t onCnt)
+{
+	unsigned char rx_Array[512]={0};
+
+	USI_CMD_BEEP_CONTROL[5] = 0x30 + onCnt;
+	USI_CMD_BEEP_CONTROL[ARRAY_SIZE(USI_CMD_BEEP_CONTROL)-1] = calChksum(USI_CMD_BEEP_CONTROL, ARRAY_SIZE(USI_CMD_BEEP_CONTROL));
+	system_command(UartFd, USI_CMD_BEEP_CONTROL, ARRAY_SIZE(USI_CMD_BEEP_CONTROL), rx_Array);
+}
+
 //==========================================
 // Main loop
 //==========================================
@@ -442,7 +454,7 @@ int main(void)
 	}
 	else
 	{
-		DEBUG_INFO("ttyS3 port open success.\n");
+		DEBUG_INFO("%s port open success.\n", TTY_PORT);
 	}
 
 	//===============================================
@@ -665,6 +677,30 @@ int main(void)
 		}
 	}while((rx_Array[0] != ACK) || (rx_len !=1));
 
+	//===============================================
+	// Disable beep (BLP Protocol)
+	//===============================================
+	do
+	{
+		rx_len = system_command(UartFd, BLP_CMD_BEEP_DISABLE, ARRAY_SIZE(BLP_CMD_BEEP_DISABLE), rx_Array);
+		if((rx_Array[0] == ACK) && (rx_len ==1))
+		{
+			DEBUG_INFO("Set beep disable success.\n");
+			failCount = 0;
+		}
+		else
+		{
+			DEBUG_WARN("Set beep disable fail (<%02x>).\n", rx_Array[0]);
+			failCount++;
+		}
+
+		if(failCount > RETRY_LIMIT)
+		{
+			DEBUG_ERROR("Set beep disable fail over retry limit.\n");
+			return FAIL;
+		}
+	}while((rx_Array[0] != ACK) || (rx_len !=1));
+
 	//===============================================
 	// Set error beep style (BLP Protocol)
 	//===============================================
@@ -825,206 +861,48 @@ int main(void)
 		}
 	}while((rx_Data[0] != ACK) || (rx_len < 0));
 
+	DEBUG_INFO("Payment module initialize completed.\n");
+
 	//===============================================
 	// Main loop
 	//===============================================
 	for(;;)
 	{
-		if(C8_Polling == true)
+		USI_CMD_NFC_ACTIVE[ARRAY_SIZE(USI_CMD_NFC_ACTIVE)-1] = calChksum(USI_CMD_NFC_ACTIVE, ARRAY_SIZE(USI_CMD_NFC_ACTIVE));
+		if(system_command(UartFd, USI_CMD_NFC_ACTIVE, ARRAY_SIZE(USI_CMD_NFC_ACTIVE), rx_Array) > 0)
 		{
-			Wait_C9 = false;
-			CurrentTime = time(NULL);
-			tm=localtime(&CurrentTime);
-
-			USI_CMD_C8_DEACTIVAVE[ARRAY_SIZE(USI_CMD_C8_DEACTIVAVE)-1] = calChksum(USI_CMD_C8_DEACTIVAVE, ARRAY_SIZE(USI_CMD_C8_DEACTIVAVE));
-			if(system_command(UartFd, USI_CMD_C8_DEACTIVAVE, ARRAY_SIZE(USI_CMD_C8_DEACTIVAVE), rx_Array) > 0)
+			rx_len = USI2_Parse(rx_Array, rx_Data);
+			if((rx_Data[2] == 0x00) && (rx_len >= 0))
 			{
-				rx_len = USI2_Parse(rx_Array, rx_Data);
-				if((rx_Data[0] == ACK) && (rx_len >= 0))
+				USI_CMD_NFC_POLL[ARRAY_SIZE(USI_CMD_NFC_POLL)-1] = calChksum(USI_CMD_NFC_POLL, ARRAY_SIZE(USI_CMD_NFC_POLL));
+				if(system_command(UartFd, USI_CMD_NFC_POLL, ARRAY_SIZE(USI_CMD_NFC_POLL), rx_Array) > 0)
 				{
-					DEBUG_INFO("C8 deactivate command success.\n");
-					failCount = 0;
-
-					USI_CMD_C8_POLL[9]  = decTobcd((1000/10000000000)%100);
-					USI_CMD_C8_POLL[10] = decTobcd((1000/100000000)%100);
-					USI_CMD_C8_POLL[11] = decTobcd((1000/1000000)%100);
-					USI_CMD_C8_POLL[12] = decTobcd((1000/10000)%100);
-					USI_CMD_C8_POLL[13] = decTobcd((1000/100)%100);
-					USI_CMD_C8_POLL[14] = decTobcd((1000/1)%100);
-					USI_CMD_C8_POLL[18] = (CURRENCY_USD>>0x08)&0xff;
-					USI_CMD_C8_POLL[19] = (CURRENCY_USD>>0x00)&0xff;
-					USI_CMD_C8_POLL[29] = decTobcd((tm->tm_year+1900)-2000);
-					USI_CMD_C8_POLL[30] = decTobcd(tm->tm_mon+1);
-					USI_CMD_C8_POLL[31] = decTobcd(tm->tm_mday);
-					USI_CMD_C8_POLL[35] = decTobcd(tm->tm_hour);
-					USI_CMD_C8_POLL[36] = decTobcd(tm->tm_min);
-					USI_CMD_C8_POLL[37] = decTobcd(tm->tm_sec);
-					USI_CMD_C8_POLL[ARRAY_SIZE(USI_CMD_C8_POLL)-1] = calChksum(USI_CMD_C8_POLL, ARRAY_SIZE(USI_CMD_C8_POLL));
-
-					if(system_command(UartFd, USI_CMD_C8_POLL, ARRAY_SIZE(USI_CMD_C8_POLL), rx_Array) > 0)
+					rx_len = USI2_Parse(rx_Array, rx_Data);
+					if((rx_Data[2] == 0x00) && (rx_len >= 0))
 					{
-						rx_len = USI2_Parse(rx_Array, rx_Data);
-						if((rx_Data[0] == ACK) && (rx_len >= 0))
-						{
-							DEBUG_INFO("C8 polling command success.\n");
-							Wait_C9 = true;
-							failCount = 0;
-							C9_Result.isCommandError = OFF;
-						}
-						else
-						{
-							DEBUG_INFO("C8 polling command fail (<%02x>).\n", rx_Data[0]);
-							C9_Result.isCommandError = ON;
-						}
-					}
-				}
-				else
-				{
-					DEBUG_INFO("C8 deactivate command fail.\n");
-					C9_Result.isCommandError = ON;
-				}
-			}
-
-			if(Wait_C9 == true)
-			{
-				//=============================================
-				// wait card to attach the reader and wait C9
-				//=============================================
-				tcflush(UartFd,TCIOFLUSH);
-				memset(rx_Array, 0x00, ARRAY_SIZE(rx_Array));
-				rx_len = 0;
-
-				do
-				{
-					DEBUG_INFO("C9 response reading...\n");
-					usleep(2000000);
-					rx_len = read(UartFd, rx_Array, ARRAY_SIZE(rx_Array)); // read response if data count match 512 or timeout.
-					failCount++;
-				} while ((rx_len == 0) && (failCount < RETRY_LIMIT));
-
-				//=============================================
-				// Parse rx_Array to rx_Data
-				//=============================================
-				if((rx_len > 3)  && (failCount < RETRY_LIMIT))
-				{
-					// print this raw data before parse it.
-					//show_data(rx_Array, rx_len);
-
-					if((rx_len = USI2_Parse( rx_Array, rx_Data)) > 0)
-					{
-						// debug the input data message
-						//show_data(rx_Data, rx_len);
-
-						// Copy RAW data to structure
+						// FELICA
 						memcpy(&C9_Result.result_data, rx_Data, rx_len);
-						C9_Result.status = C9_Result.result_data[1];
-						C9_Result.pos_entry = C9_Result.result_data[2];
-
-						switch(C9_Result.pos_entry)
-						{
-							case VISA_qVSDC:
-							case VISA_MSD:
-							case MASTER_MChip:
-							case Master_MagStripe:
-							case AMEX_EMV:
-							case AMEX_MSD:
-								memset(C9_Result.u_id, 0x00, ARRAY_SIZE(C9_Result.u_id));
-								memcpy(C9_Result.u_id, &C9_Result.result_data[5], 16);
-								DEBUG_INFO("Credit card SN:\n");
-								show_data(C9_Result.u_id, 16);
-
-								for(uint8_t idx=0;idx<getSentinelQuantity(C9_Result.result_data, rx_len);idx++)
-								{
-									memset(C9_Result.tkData[idx], 0x00, ARRAY_SIZE(C9_Result.tkData[idx]));
-									memcpy(C9_Result.tkData[idx],
-										   &C9_Result.result_data[((idx==0)?3:getSentinelPosition(C9_Result.result_data, rx_len, idx-1)+2)],
-										   (idx==0?getSentinelPosition(C9_Result.result_data, rx_len, idx)+1-3+1:getSentinelPosition(C9_Result.result_data, rx_len, idx)+1-getSentinelPosition(C9_Result.result_data, rx_len, idx-1)+2+1));
-
-									DEBUG_INFO("TK[%d]: \n", idx);
-									show_data(C9_Result.tkData[idx], getSentinelPosition(C9_Result.tkData[idx], ARRAY_SIZE(C9_Result.tkData[idx]), 0)+2);
-								}
-								break;
-							case Mifare:
-								data_len = C9_Result.result_data[6];
-								memset(C9_Result.u_id, 0x00, ARRAY_SIZE(C9_Result.u_id));
-								memcpy(C9_Result.u_id, &C9_Result.result_data[7], data_len);
+						C9_Result.status = C9_Result.result_data[2];
+						C9_Result.pos_entry = Felica;
+						memset(C9_Result.u_id, 0x00, ARRAY_SIZE(C9_Result.u_id));
+						memcpy(C9_Result.u_id, &C9_Result.result_data[6], 6);
+						DEBUG_INFO("FELICA, UID: %02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5]);
 
-								switch(C9_Result.result_data[3])
-								{
-									case MIFARE_ULTRALIGHT:
-										DEBUG_INFO("MIFARE Ultralight, UID: %02X-%02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5], C9_Result.u_id[6]);
-										break;
-									case MIFARE_CLASSIC_1K:
-										DEBUG_INFO("MIFARE Classic 1K, UID: %02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3]);
-										break;
-									case MIFARE_CLASSIC_4K:
-										DEBUG_INFO("MIFARE Classic 4K, UID: %02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3]);
-										break;
-									case MIFARE_DESFIRE:
-										DEBUG_INFO("MIFARE DESFire, UID: %02X-%02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5], C9_Result.u_id[6]);
-										break;
-									case MIFARE_PLUS_2K:
-										DEBUG_INFO("MIFARE Plus 2k, UID: %02X-%02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5], C9_Result.u_id[6]);
-										break;
-									case MIFARE_MINI:
-										DEBUG_INFO("MIFARE Mini, UID: %02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3]);
-										break;
-									case MIFARE_RESERVE:
-										DEBUG_INFO("MIFARE Reserve, UID: \n");
-										break;
-									case MIFARE_JEWEL:
-										DEBUG_INFO("MIFARE Jewel, UID: \n");
-										break;
-									case MIFARE_JCOP31:
-										DEBUG_INFO("MIFARE JCOP31, UID: \n");
-										break;
-								}
-								break;
-							case ISO_15693:
-								data_len =(C9_Result.result_data[5]<<8) | C9_Result.result_data[6];
-								memset(C9_Result.u_id, 0x00, ARRAY_SIZE(C9_Result.u_id));
-								memcpy(C9_Result.u_id, &C9_Result.result_data[4+data_len-8], 8);
-
-								DEBUG_INFO("ISO_15693, UID: %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5], C9_Result.u_id[6], C9_Result.u_id[7]);
-								break;
-							case Apple_Pay:
-								DEBUG_INFO("Apple_Pay VAS only.\n");
-								for(uint8_t idx=0;idx<getSentinelQuantity(C9_Result.result_data, rx_len);idx++)
-								{
-									memcpy(C9_Result.tkData[idx],
-										   &C9_Result.result_data[((idx==0)?3:getSentinelPosition(C9_Result.result_data, rx_len, idx-1)+2)],
-										   (idx==0?getSentinelPosition(C9_Result.result_data, rx_len, idx)+1-3+1:getSentinelPosition(C9_Result.result_data, rx_len, idx)+1-getSentinelPosition(C9_Result.result_data, rx_len, idx-1)+2+1));
-
-									DEBUG_INFO("TK[%d]: \n", idx);
-									show_data(C9_Result.tkData[idx], getSentinelPosition(C9_Result.tkData[idx], ARRAY_SIZE(C9_Result.tkData[idx]), 0)+2);
-								}
-								break;
-							case No_Data:
-								DEBUG_INFO("No any data.\n");
-								break;
-							default:
-								DEBUG_WARN("Unknown pos entry.\n");
-								if(C9_Result.status == C9_RES_C8_CMD_TIMEOUT)
-									DEBUG_WARN("C8 command timeout.\n");
-								else if(C9_Result.status == C9_RES_CMD_EXECUTING)
-									DEBUG_WARN("Command executing or Wait Card to be Removed.\n");
-
-								break;
-						}
-						failCount = 0;
+						buzzer_on(UartFd, 1);
 
 						// Wait card removed
 						do
 						{
-							system_command(UartFd, USI_CMD_MODULE_STATUS, ARRAY_SIZE(USI_CMD_MODULE_STATUS), rx_Array);
+							USI_CMD_NFC_POLL[ARRAY_SIZE(USI_CMD_NFC_POLL)-1] = calChksum(USI_CMD_NFC_POLL, ARRAY_SIZE(USI_CMD_NFC_POLL));
+							system_command(UartFd, USI_CMD_NFC_POLL, ARRAY_SIZE(USI_CMD_NFC_POLL), rx_Array);
 							rx_len = USI2_Parse(rx_Array, rx_Data);
-							if(!(rx_Data[0]&0x02) && (rx_len >= 0))
+							if((rx_Data[2] != 0x00) && (rx_len >= 0))
 							{
 								DEBUG_INFO("Card removed.\n");
 								C9_Result.isCardPreset = OFF;
 								failCount = 0;
 							}
-							else if((rx_Data[0]&0x02) && (rx_len >= 0))
+							else if((rx_Data[0] == 0x00) && (rx_len >= 0))
 							{
 								//DEBUG_INFO("Card seated.\n");
 								C9_Result.isCardPreset = ON;
@@ -1041,53 +919,282 @@ int main(void)
 								C9_Result.isCardPreset = OFF;
 								DEBUG_ERROR("Module status read fail over retry limit.\n");
 							}
-						}while(((rx_Data[0]&0x02) || (rx_len < 0)) && (failCount < RETRY_LIMIT));
+						}while(((rx_Data[2] == 0x00) || (rx_len < 0)) && (failCount < RETRY_LIMIT));
 					}
 					else
 					{
-						DEBUG_INFO("C9 Parsing result fail.\n");
-						C9_Result.isCommandError = ON;
-						// Wait card removed
-						do
+						// MIFARE, IDO-15693, Credit Card, Apple Pay in query
+						if(C8_Polling == true)
 						{
-							usleep(500000);
-							system_command(UartFd, USI_CMD_MODULE_STATUS, ARRAY_SIZE(USI_CMD_MODULE_STATUS), rx_Array);
-							rx_len = USI2_Parse(rx_Array, rx_Data);
-							if(!(rx_Data[0]&0x02) && (rx_len >= 0))
-							{
-								DEBUG_INFO("Card removed.\n");
-								C9_Result.isCardPreset = OFF;
-								C9_Result.isCommandError = OFF;
-								failCount = 0;
-							}
-							else if((rx_Data[0]&0x02) && (rx_len >= 0))
-							{
-								//DEBUG_INFO("Card seated.\n");
-								C9_Result.isCardPreset = ON;
-								failCount = 0;
-							}
-							else
+							Wait_C9 = false;
+							CurrentTime = time(NULL);
+							tm=localtime(&CurrentTime);
+
+							USI_CMD_C8_DEACTIVAVE[ARRAY_SIZE(USI_CMD_C8_DEACTIVAVE)-1] = calChksum(USI_CMD_C8_DEACTIVAVE, ARRAY_SIZE(USI_CMD_C8_DEACTIVAVE));
+							if(system_command(UartFd, USI_CMD_C8_DEACTIVAVE, ARRAY_SIZE(USI_CMD_C8_DEACTIVAVE), rx_Array) > 0)
 							{
-								DEBUG_WARN("Module status read fail (<%02x>).\n", rx_Data[0]);
-								failCount++;
+								rx_len = USI2_Parse(rx_Array, rx_Data);
+								if((rx_Data[0] == ACK) && (rx_len >= 0))
+								{
+									//DEBUG_INFO("C8 deactivate command success.\n");
+									failCount = 0;
+
+									USI_CMD_C8_POLL[9]  = decTobcd((1000/10000000000)%100);
+									USI_CMD_C8_POLL[10] = decTobcd((1000/100000000)%100);
+									USI_CMD_C8_POLL[11] = decTobcd((1000/1000000)%100);
+									USI_CMD_C8_POLL[12] = decTobcd((1000/10000)%100);
+									USI_CMD_C8_POLL[13] = decTobcd((1000/100)%100);
+									USI_CMD_C8_POLL[14] = decTobcd((1000/1)%100);
+									USI_CMD_C8_POLL[18] = (CURRENCY_USD>>0x08)&0xff;
+									USI_CMD_C8_POLL[19] = (CURRENCY_USD>>0x00)&0xff;
+									USI_CMD_C8_POLL[29] = decTobcd((tm->tm_year+1900)-2000);
+									USI_CMD_C8_POLL[30] = decTobcd(tm->tm_mon+1);
+									USI_CMD_C8_POLL[31] = decTobcd(tm->tm_mday);
+									USI_CMD_C8_POLL[35] = decTobcd(tm->tm_hour);
+									USI_CMD_C8_POLL[36] = decTobcd(tm->tm_min);
+									USI_CMD_C8_POLL[37] = decTobcd(tm->tm_sec);
+									USI_CMD_C8_POLL[ARRAY_SIZE(USI_CMD_C8_POLL)-1] = calChksum(USI_CMD_C8_POLL, ARRAY_SIZE(USI_CMD_C8_POLL));
+
+									if(system_command(UartFd, USI_CMD_C8_POLL, ARRAY_SIZE(USI_CMD_C8_POLL), rx_Array) > 0)
+									{
+										rx_len = USI2_Parse(rx_Array, rx_Data);
+										if((rx_Data[0] == ACK) && (rx_len >= 0))
+										{
+											//DEBUG_INFO("C8 polling command success.\n");
+											Wait_C9 = true;
+											failCount = 0;
+											C9_Result.isCommandError = OFF;
+										}
+										else
+										{
+											DEBUG_INFO("C8 polling command fail (<%02x>).\n", rx_Data[0]);
+											C9_Result.isCommandError = ON;
+										}
+									}
+								}
+								else
+								{
+									DEBUG_INFO("C8 deactivate command fail.\n");
+									C9_Result.isCommandError = ON;
+								}
 							}
 
-							if(failCount > RETRY_LIMIT)
+							if(Wait_C9 == true)
 							{
-								C9_Result.isCardPreset = OFF;
-								DEBUG_ERROR("Module status read fail over retry limit.\n");
+								//=============================================
+								// wait card to attach the reader and wait C9
+								//=============================================
+								tcflush(UartFd,TCIOFLUSH);
+								memset(rx_Array, 0x00, ARRAY_SIZE(rx_Array));
+								rx_len = 0;
+
+								do
+								{
+									//DEBUG_INFO("C9 response reading...\n");
+									usleep(1000000);
+									rx_len = read(UartFd, rx_Array, ARRAY_SIZE(rx_Array)); // read response if data count match 512 or timeout.
+									failCount++;
+								} while ((rx_len == 0) && (failCount < RETRY_LIMIT));
+
+								//=============================================
+								// Parse rx_Array to rx_Data
+								//=============================================
+								if((rx_len > 3)  && (failCount < RETRY_LIMIT))
+								{
+									// print this raw data before parse it.
+									//show_data(rx_Array, rx_len);
+
+									if((rx_len = USI2_Parse( rx_Array, rx_Data)) > 0)
+									{
+										// debug the input data message
+										//show_data(rx_Data, rx_len);
+
+										// Copy RAW data to structure
+										memcpy(&C9_Result.result_data, rx_Data, rx_len);
+										C9_Result.status = C9_Result.result_data[1];
+										C9_Result.pos_entry = C9_Result.result_data[2];
+
+										switch(C9_Result.pos_entry)
+										{
+											case VISA_qVSDC:
+											case VISA_MSD:
+											case MASTER_MChip:
+											case Master_MagStripe:
+											case AMEX_EMV:
+											case AMEX_MSD:
+												memset(C9_Result.u_id, 0x00, ARRAY_SIZE(C9_Result.u_id));
+												memcpy(C9_Result.u_id, &C9_Result.result_data[5], 16);
+												DEBUG_INFO("Credit card SN:\n");
+												show_data(C9_Result.u_id, 16);
+
+												for(uint8_t idx=0;idx<getSentinelQuantity(C9_Result.result_data, rx_len);idx++)
+												{
+													memset(C9_Result.tkData[idx], 0x00, ARRAY_SIZE(C9_Result.tkData[idx]));
+													memcpy(C9_Result.tkData[idx],
+														   &C9_Result.result_data[((idx==0)?3:getSentinelPosition(C9_Result.result_data, rx_len, idx-1)+2)],
+														   (idx==0?getSentinelPosition(C9_Result.result_data, rx_len, idx)+1-3+1:getSentinelPosition(C9_Result.result_data, rx_len, idx)+1-getSentinelPosition(C9_Result.result_data, rx_len, idx-1)+2+1));
+
+													DEBUG_INFO("TK[%d]: \n", idx);
+													show_data(C9_Result.tkData[idx], getSentinelPosition(C9_Result.tkData[idx], ARRAY_SIZE(C9_Result.tkData[idx]), 0)+2);
+												}
+												buzzer_on(UartFd, 1);
+												break;
+											case Mifare:
+												data_len = C9_Result.result_data[6];
+												memset(C9_Result.u_id, 0x00, ARRAY_SIZE(C9_Result.u_id));
+												memcpy(C9_Result.u_id, &C9_Result.result_data[7], data_len);
+
+												switch(C9_Result.result_data[3])
+												{
+													case MIFARE_ULTRALIGHT:
+														DEBUG_INFO("MIFARE Ultralight, UID: %02X-%02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5], C9_Result.u_id[6]);
+														break;
+													case MIFARE_CLASSIC_1K:
+														DEBUG_INFO("MIFARE Classic 1K, UID: %02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3]);
+														break;
+													case MIFARE_CLASSIC_4K:
+														DEBUG_INFO("MIFARE Classic 4K, UID: %02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3]);
+														break;
+													case MIFARE_DESFIRE:
+														DEBUG_INFO("MIFARE DESFire, UID: %02X-%02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5], C9_Result.u_id[6]);
+														break;
+													case MIFARE_PLUS_2K:
+														DEBUG_INFO("MIFARE Plus 2k, UID: %02X-%02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5], C9_Result.u_id[6]);
+														break;
+													case MIFARE_MINI:
+														DEBUG_INFO("MIFARE Mini, UID: %02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3]);
+														break;
+													case MIFARE_RESERVE:
+														DEBUG_INFO("MIFARE Reserve, UID: \n");
+														break;
+													case MIFARE_JEWEL:
+														DEBUG_INFO("MIFARE Jewel, UID: \n");
+														break;
+													case MIFARE_JCOP31:
+														DEBUG_INFO("MIFARE JCOP31, UID: \n");
+														break;
+												}
+												buzzer_on(UartFd, 1);
+												break;
+											case ISO_15693:
+												data_len =(C9_Result.result_data[5]<<8) | C9_Result.result_data[6];
+												memset(C9_Result.u_id, 0x00, ARRAY_SIZE(C9_Result.u_id));
+												memcpy(C9_Result.u_id, &C9_Result.result_data[4+data_len-8], 8);
+
+												DEBUG_INFO("ISO_15693, UID: %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", C9_Result.u_id[0], C9_Result.u_id[1], C9_Result.u_id[2], C9_Result.u_id[3], C9_Result.u_id[4], C9_Result.u_id[5], C9_Result.u_id[6], C9_Result.u_id[7]);
+												buzzer_on(UartFd, 1);
+												break;
+											case Apple_Pay:
+												DEBUG_INFO("Apple_Pay VAS only.\n");
+												for(uint8_t idx=0;idx<getSentinelQuantity(C9_Result.result_data, rx_len);idx++)
+												{
+													memcpy(C9_Result.tkData[idx],
+														   &C9_Result.result_data[((idx==0)?3:getSentinelPosition(C9_Result.result_data, rx_len, idx-1)+2)],
+														   (idx==0?getSentinelPosition(C9_Result.result_data, rx_len, idx)+1-3+1:getSentinelPosition(C9_Result.result_data, rx_len, idx)+1-getSentinelPosition(C9_Result.result_data, rx_len, idx-1)+2+1));
+
+													DEBUG_INFO("TK[%d]: \n", idx);
+													show_data(C9_Result.tkData[idx], getSentinelPosition(C9_Result.tkData[idx], ARRAY_SIZE(C9_Result.tkData[idx]), 0)+2);
+												}
+												buzzer_on(UartFd, 1);
+												break;
+											case No_Data:
+												//DEBUG_INFO("No any data.\n");
+												break;
+											default:
+												DEBUG_WARN("Unknown pos entry.\n");
+												if(C9_Result.status == C9_RES_C8_CMD_TIMEOUT)
+													DEBUG_WARN("C8 command timeout.\n");
+												else if(C9_Result.status == C9_RES_CMD_EXECUTING)
+													DEBUG_WARN("Command executing or Wait Card to be Removed.\n");
+
+												break;
+										}
+										failCount = 0;
+
+										// Wait card removed
+										if(C9_Result.pos_entry != No_Data)
+										{
+											do
+											{
+												system_command(UartFd, USI_CMD_MODULE_STATUS, ARRAY_SIZE(USI_CMD_MODULE_STATUS), rx_Array);
+												rx_len = USI2_Parse(rx_Array, rx_Data);
+												if(!(rx_Data[0]&0x02) && (rx_len >= 0))
+												{
+													DEBUG_INFO("Card removed.\n");
+													C9_Result.isCardPreset = OFF;
+													failCount = 0;
+												}
+												else if((rx_Data[0]&0x02) && (rx_len >= 0))
+												{
+													//DEBUG_INFO("Card seated.\n");
+													C9_Result.isCardPreset = ON;
+													failCount = 0;
+												}
+												else
+												{
+													DEBUG_WARN("Module status read fail (<%02x>).\n", rx_Data[0]);
+													failCount++;
+												}
+
+												if(failCount > RETRY_LIMIT)
+												{
+													C9_Result.isCardPreset = OFF;
+													DEBUG_ERROR("Module status read fail over retry limit.\n");
+												}
+											}while(((rx_Data[0]&0x02) || (rx_len < 0)) && (failCount < RETRY_LIMIT));
+										}
+									}
+									else
+									{
+										DEBUG_INFO("C9 Parsing result fail.\n");
+										C9_Result.isCommandError = ON;
+										buzzer_on(UartFd, 3);
+										// Wait card removed
+										do
+										{
+											usleep(500000);
+											system_command(UartFd, USI_CMD_MODULE_STATUS, ARRAY_SIZE(USI_CMD_MODULE_STATUS), rx_Array);
+											rx_len = USI2_Parse(rx_Array, rx_Data);
+											if(!(rx_Data[0]&0x02) && (rx_len >= 0))
+											{
+												DEBUG_INFO("Card removed.\n");
+												C9_Result.isCardPreset = OFF;
+												C9_Result.isCommandError = OFF;
+												failCount = 0;
+											}
+											else if((rx_Data[0]&0x02) && (rx_len >= 0))
+											{
+												//DEBUG_INFO("Card seated.\n");
+												C9_Result.isCardPreset = ON;
+												failCount = 0;
+											}
+											else
+											{
+												DEBUG_WARN("Module status read fail (<%02x>).\n", rx_Data[0]);
+												failCount++;
+											}
+
+											if(failCount > RETRY_LIMIT)
+											{
+												C9_Result.isCardPreset = OFF;
+												DEBUG_ERROR("Module status read fail over retry limit.\n");
+											}
+										}while(((rx_Data[0]&0x02) || (rx_len < 0)) && (failCount < RETRY_LIMIT));
+									}
+								}
+								else
+								{
+									DEBUG_WARN("C9 Response timeout: %d \n", failCount);
+									buzzer_on(UartFd, 3);
+								}
 							}
-						}while(((rx_Data[0]&0x02) || (rx_len < 0)) && (failCount < RETRY_LIMIT));
+						}
 					}
 				}
-				else
-				{
-					DEBUG_WARN("C9 Response timeout: %d \n", failCount);
-				}
 			}
 		}
 
-		usleep(1000000);
+		usleep(500000);
 	}
 
 	return FAIL;

+ 8 - 2
EVSE/Modularization/Module_Payment.h

@@ -7,6 +7,7 @@
 
 #ifndef MODULE_PAYMENT_H_
 #define MODULE_PAYMENT_H_
+//#define	X86
 
 #include 	<sys/time.h>
 #include 	<sys/timeb.h>
@@ -39,9 +40,14 @@
 #include 	<math.h>
 #include	<limits.h>
 #include	<stdint.h>
-#include	"define.h"
+#ifndef X86
+	#include	"define.h"
+	#define TTY_PORT		"/dev/ttyS2"
+#else
+	#define ConsloePrintLog
+	#define TTY_PORT		"/dev/ttyUSB0"
+#endif
 
-//#define	X86
 
 #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)

+ 5 - 5
EVSE/Modularization/WebService.c

@@ -1333,7 +1333,7 @@ int main(int argc, char *argv[]) {
 				PsuQuantity = RatedPower/30;
 			}
 		}
-		if(strcmp(IsDO, "DO") == 0){
+		if(strcmp(IsDO, "DO") == 0 || strcmp(IsDO, "DK") == 0){
 		}
 		
 		struct json_object *jobj1;
@@ -1632,7 +1632,7 @@ int main(int argc, char *argv[]) {
 				json_object_array_add(FwSecondVersionArr,FwSecondVersion[i]);
 			}
 		}
-		if(strcmp(IsDO, "DO") == 0){
+		if(strcmp(IsDO, "DO") == 0 || strcmp(IsDO, "DK") == 0){
 			if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity>4 || ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity<0)ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity=0;
 			DispenserQuantity = json_object_new_int(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity);
 			TotalConnectorQuantity = json_object_new_int(ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
@@ -2041,7 +2041,7 @@ int main(int argc, char *argv[]) {
 				AcGunQty++;
 			}
 		}
-		if(strcmp(IsDO, "DO") == 0){
+		if(strcmp(IsDO, "DO") == 0 || strcmp(IsDO, "DK") == 0){
 			if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity>4 || ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity<0)ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity=0;
 			int DDTotalConnectorQuantity = ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity;
 			for(int i=0;i<DDTotalConnectorQuantity;i++){
@@ -2182,7 +2182,7 @@ int main(int argc, char *argv[]) {
 			json_object_object_add(jobj1,"FwPrimaryVersion",FwPrimaryVersionArr);
 			json_object_object_add(jobj1,"FwSecondVersion",FwSecondVersionArr);
 		}
-		if(strcmp(IsDO, "DO") == 0){
+		if(strcmp(IsDO, "DO") == 0 || strcmp(IsDO, "DK") == 0){
 			json_object_object_add(jobj1,"DispenserQuantity",DispenserQuantity);
 			json_object_object_add(jobj1,"TotalConnectorQuantity",TotalConnectorQuantity);
 			json_object_object_add(jobj1,"DDModelName",DDModelNameArr);
@@ -2321,7 +2321,7 @@ int main(int argc, char *argv[]) {
 			json_object_object_add(ChargingInfo3,"PowerConsumption",PowerConsumption[2]);
 			json_object_object_add(jobj2,"ChargingInfo3",ChargingInfo3);
 		}
-		if(strcmp(IsDO, "DO") == 0){
+		if(strcmp(IsDO, "DO") == 0 || strcmp(IsDO, "DK") == 0){
 			if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity>4|| ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity<0)ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity=0;
 			int DDTotalConnectorQuantity = ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity;
 			DDChargingInfo1=json_object_new_object();

+ 65 - 15
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -5178,14 +5178,6 @@ void CheckSystemValue(void)
 		HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
 	}
 
-	//===============================
-	// CSU Trigger Reset Conf
-	//===============================
-	if(isWebsocketSendable && (ShmOCPP20Data->MsMsg.bits.ResetConf == ON))
-	{
-		sendResetConfirmation((char *)ShmOCPP20Data->Reset.guid);
-	}
-
 	//===============================
 	// CSU Trigger Authorize Request
 	//===============================
@@ -14026,13 +14018,11 @@ int handleResetRequest(char *uuid, char *payload)
 
 	if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
 	{
-	  	ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
 	    strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
+	    strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
+	    ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
 
-	    if(!GetServerSign())
-	    	strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
-
-	    result = TRUE;
+	    result = PASS;
 	}
 	else
 	{
@@ -17289,7 +17279,7 @@ void InitialSystemValue(void)
 	sleep(1);
 }
 
-void LWS_Send(char * str)
+void LWS_Send(char *str)
 {
 	//=====================================================
 	// Check InternetConn 0: disconnected, 1: connected
@@ -17300,6 +17290,36 @@ void LWS_Send(char * str)
 		return;
 	}
 
+    // Only disable isWebsocketSendable operation initiated by charger
+    if((strstr((char*)str, "\"Authorize\"") != NULL)
+    || (strstr((char*)str, "\"BootNotification\"") != NULL)
+	|| (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
+	|| (strstr((char*)str, "\"DataTransfer\"") != NULL)
+	|| (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
+	|| (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
+	|| (strstr((char*)str, "\"Heartbeat\"") != NULL)
+	|| (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"MeterValues\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyEvent\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyReport\"") != NULL)
+	|| (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
+	|| (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
+	|| (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
+	|| (strstr((char*)str, "\"SignCertificate\"") != NULL)
+	|| (strstr((char*)str, "\"StatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"TransactionEven\"") != NULL))
+    {
+    	isWebsocketSendable = OFF;
+    }
+
 	pthread_mutex_lock(&lock_send);
 	memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
 	sprintf((char *)SendBuffer, "%s", str);
@@ -17311,7 +17331,7 @@ void LWS_Send(char * str)
 	//sleep(1);
 }
 
-void LWS_SendNow(char * str)
+void LWS_SendNow(char *str)
 {
 	//=====================================================
 	// Check InternetConn 0: disconnected, 1: connected
@@ -17322,6 +17342,36 @@ void LWS_SendNow(char * str)
 		return;
 	}
 
+    // Only disable isWebsocketSendable operation initiated by charger
+    if((strstr((char*)str, "\"Authorize\"") != NULL)
+    || (strstr((char*)str, "\"BootNotification\"") != NULL)
+	|| (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
+	|| (strstr((char*)str, "\"DataTransfer\"") != NULL)
+	|| (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
+	|| (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
+	|| (strstr((char*)str, "\"Heartbeat\"") != NULL)
+	|| (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"MeterValues\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyEvent\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
+	|| (strstr((char*)str, "\"NotifyReport\"") != NULL)
+	|| (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
+	|| (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
+	|| (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
+	|| (strstr((char*)str, "\"SignCertificate\"") != NULL)
+	|| (strstr((char*)str, "\"StatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"TransactionEven\"") != NULL))
+    {
+    	isWebsocketSendable = OFF;
+    }
+
 	pthread_mutex_lock(&lock_send);
 	memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
 	sprintf((char *)SendBuffer, "%s", str);

+ 0 - 30
EVSE/Modularization/ocpp20/Module_OcppBackend20.c

@@ -56,36 +56,6 @@ int SendData(struct lws *wsi)
     int len;
     unsigned char out[LWS_SEND_BUFFER_PRE_PADDING + (1024*20) + LWS_SEND_BUFFER_POST_PADDING] = {0};
 
-    // Only disable isWebsocketSendable operation initiated by charger
-    if((strstr((char*)SendBuffer, "\"Authorize\"") != NULL)
-    || (strstr((char*)SendBuffer, "\"BootNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"ClearedChargingLimit\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"DataTransfer\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"FirmwareStatusNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"Get15118EVCertificate\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"GetCertificateStatus\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"Heartbeat\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"LogStatusNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"MeterValues\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"NotifyChargingLimit\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"NotifyCustomerInformation\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"NotifyDisplayMessages\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"NotifyEVChargingNeeds\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"NotifyEVChargingSchedule\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"NotifyEvent\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"NotifyMonitoringReport\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"NotifyReport\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"PublishFirmwareStatusNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"ReportChargingProfiles\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"ReservationStatusUpdate\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"SecurityEventNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"SignCertificate\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"StatusNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"TransactionEven\"") != NULL))
-    {
-    	isWebsocketSendable = 0;
-    }
-
     len = strlen((char *)SendBuffer);
 
     if(len == 0)

+ 55 - 26
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -2793,14 +2793,6 @@ void CheckSystemValue(void)
 			ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
 		}
 
-		//===============================
-		// CSU Trigger Reset Conf
-		//===============================
-		if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
-		{
-			sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
-		}
-
 		//===============================
 		// CSU Trigger Authorize Request
 		//===============================
@@ -3137,7 +3129,7 @@ void CheckSystemValue(void)
 			(
 				(statusModeChage[gun_index] == TRUE) ||
 				//((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
-				((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
+				((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
 			)
 		  )
 		{
@@ -10253,19 +10245,18 @@ int handleResetRequest(char *uuid, char *payload)
 	sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
 	if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
 	{
-	  	ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
+		ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
 	    strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
-	    result = TRUE;
-	    return result;
-	 }
-	 else
-	 {
-		 strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
-		 sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
-		 goto errorend;
-	 }
+	    strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
+	    sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
+	}
+	else
+	{
+		strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
+		sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
+		result = PASS;
+	}
 
-errorend:
 	sendResetConfirmation(uuid, comfirmstr);
 	return result;
 }
@@ -12644,7 +12635,7 @@ int initialConfigurationTable(void)
 	char sstr[256]={0};
 	int c = 0;
 	char *loc;
-	int	confVersion = 1;
+	int	confVersion = 2;
 
 	DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
 	//start_t = clock();
@@ -12746,11 +12737,11 @@ int initialConfigurationTable(void)
 		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
 
 		// LocalPreAuthorize
-		ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
+		ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
 		strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
 		strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
 
-		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
+		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
 
 		// MaxEnergyOnInvalidId
 		ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
@@ -13578,7 +13569,7 @@ void StoreConfigurationTable(void)
 	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
 	*/
 
-	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
+	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
 
 	// MaxEnergyOnInvalidId
 	/*
@@ -17896,7 +17887,7 @@ void InitialSystemValue(void)
 	sleep(1);
 }
 
-void LWS_Send(char * str)
+void LWS_Send(char *str)
 {
 	//=====================================================
 	// Check InternetConn 0: disconnected, 1: connected
@@ -17907,6 +17898,25 @@ void LWS_Send(char * str)
 		return;
 	}
 
+	 // Only disable isWebsocketSendable operation initiated by charger
+	if((strstr((char*)str, "\"Authorize\"") != NULL)
+    || (strstr((char*)str, "\"BootNotification\"") != NULL)
+	|| (strstr((char*)str, "\"DataTransfer\"") != NULL)
+	|| (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"Heartbeat\"") != NULL)
+	|| (strstr((char*)str, "\"MeterValues\"") != NULL)
+	|| (strstr((char*)str, "\"StartTransaction\"") != NULL)
+	|| (strstr((char*)str, "\"StatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"StopTransaction\"") != NULL)
+	|| (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
+	|| (strstr((char*)str, "\"SignCertificate\"") != NULL)
+	|| (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
+    {
+    	isWebsocketSendable = 0;
+    }
+
 	pthread_mutex_lock(&lock_send);
 	memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
 	sprintf((char *)SendBuffer, "%s", str);
@@ -17918,7 +17928,7 @@ void LWS_Send(char * str)
 	//sleep(1);
 }
 
-void LWS_SendNow(char * str)
+void LWS_SendNow(char *str)
 {
 	//=====================================================
 	// Check InternetConn 0: disconnected, 1: connected
@@ -17929,6 +17939,25 @@ void LWS_SendNow(char * str)
 		return;
 	}
 
+	 // Only disable isWebsocketSendable operation initiated by charger
+	if((strstr((char*)str, "\"Authorize\"") != NULL)
+    || (strstr((char*)str, "\"BootNotification\"") != NULL)
+	|| (strstr((char*)str, "\"DataTransfer\"") != NULL)
+	|| (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"Heartbeat\"") != NULL)
+	|| (strstr((char*)str, "\"MeterValues\"") != NULL)
+	|| (strstr((char*)str, "\"StartTransaction\"") != NULL)
+	|| (strstr((char*)str, "\"StatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"StopTransaction\"") != NULL)
+	|| (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
+	|| (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
+	|| (strstr((char*)str, "\"SignCertificate\"") != NULL)
+	|| (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
+	{
+		isWebsocketSendable = 0;
+	}
+
 	pthread_mutex_lock(&lock_send);
 	memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
 	sprintf((char *)SendBuffer, "%s", str);

+ 0 - 19
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -110,25 +110,6 @@ int SendData(struct lws *wsi)
     int len;
     unsigned char out[LWS_SEND_BUFFER_PRE_PADDING + ARRAY_SIZE(SendBuffer) + LWS_SEND_BUFFER_POST_PADDING] = {0};
 
-    // Only disable isWebsocketSendable operation initiated by charger
-    if((strstr((char*)SendBuffer, "\"Authorize\"") != NULL)
-    || (strstr((char*)SendBuffer, "\"BootNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"DataTransfer\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"DiagnosticsStatusNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"FirmwareStatusNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"Heartbeat\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"MeterValues\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"StartTransaction\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"StatusNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"StopTransaction\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"LogStatusNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"SecurityEventNotification\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"SignCertificate\"") != NULL)
-	|| (strstr((char*)SendBuffer, "\"SignedFirmwareStatusNotification\"") != NULL))
-    {
-    	isWebsocketSendable = 0;
-    }
-
     len = strlen((char *)SendBuffer);
 
     if(len == 0)

+ 77 - 58
EVSE/Projects/AW-CCS/Apps/LCM/Module_LcmControl.c

@@ -72,16 +72,19 @@ void setBillingFromWebsite();
 //=======================================
 // Declare Timer
 //=======================================
-#define TMR_IDX_BATTERY					0
-#define TMR_IDX_CONNECTION				1
-#define TMR_IDX_PLUGIN					2
-#define TMR_IDX_ALARM					3
-#define TMR_IDX_PRICE					4
-#define TMR_IDX_EMULATOR				5
-#define TMR_IDX_6						6
-#define TMR_IDX_7						7
-#define TMR_IDX_8						8
-#define TMR_IDX_9 						9
+enum TMR_IDX
+{
+	TMR_IDX_BATTERY=0,
+	TMR_IDX_CONNECTION,
+	TMR_IDX_PLUGIN,
+	TMR_IDX_ALARM,
+	TMR_IDX_PRICE,
+	TMR_IDX_EMULATOR,
+	TMR_IDX_6,
+	TMR_IDX_7,
+	TMR_IDX_8,
+	TMR_IDX_SHOW_AUTH_RESULT
+};
 
 struct timeb					startTime[AC_QUANTITY][10];
 
@@ -90,6 +93,7 @@ struct timeb					startTime[AC_QUANTITY][10];
 #define TIME_ANIMATION_CONNECTION		1000
 #define TIME_ANIMATION_ALARM			5000
 #define TIME_REFRESH_TIME				2000
+#define TIME_AUTH_RESULT_TIME			5000
 
 //=======================================
 // Declare Variable
@@ -361,7 +365,7 @@ void page_preparing(uint8_t gun_index, uint8_t system_mode)
 
 void page_charging(uint8_t gun_index, uint8_t system_mode)
 {
-	if((getCurrentPage() != SYSTEM_SCREEN_CHARGING) && (ShmCharger->gun_info[gun_index].resultAuthorization == DEFAULT_RFID))
+	if((getCurrentPage() != SYSTEM_SCREEN_CHARGING) && (!ShmCharger->isAuthrizing && !ShmCharger->isGetAuthResult))
 	{
 		setCurrentPage(SYSTEM_SCREEN_CHARGING);
 		setDefaultValue(gun_index, system_mode);
@@ -372,7 +376,7 @@ void page_charging(uint8_t gun_index, uint8_t system_mode)
 	}
 	else
 	{
-		setAuthorizationPage(gun_index);
+		//setAuthorizationPage(gun_index);
 		setConnectionAnimation(gun_index, system_mode);
 		setBatteryAnimation(gun_index, system_mode);
 		setPresentChargedDuration(gun_index);
@@ -435,7 +439,7 @@ void page_complete(uint8_t gun_index, uint8_t system_mode)
 
 void page_terminating(uint8_t gun_index, uint8_t system_mode)
 {
-	if((getCurrentPage() != SYSTEM_SCREEN_TERMINATING) && (ShmCharger->gun_info[gun_index].resultAuthorization == DEFAULT_RFID))
+	if((getCurrentPage() != SYSTEM_SCREEN_TERMINATING) && (!ShmCharger->isAuthrizing && !ShmCharger->isGetAuthResult))
 	{
 		setCurrentPage(SYSTEM_SCREEN_TERMINATING);
 		setDefaultValue(gun_index, system_mode);
@@ -443,7 +447,7 @@ void page_terminating(uint8_t gun_index, uint8_t system_mode)
 	}
 	else
 	{
-		setAuthorizationPage(gun_index);
+		//setAuthorizationPage(gun_index);
 		setConnectionAnimation(gun_index, system_mode);
 		setBatteryAnimation(gun_index, system_mode);
 		setPresentChargedDuration(gun_index);
@@ -2074,53 +2078,68 @@ int main(void)
 			previousMode = ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus;
 		}
 
-		switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
+		if(ShmCharger->isAuthrizing || ShmCharger->isGetAuthResult)
 		{
-			case SYS_MODE_BOOTING:
-				page_booting();
-				break;
-			case SYS_MODE_IDLE:
-				page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
-				break;
-			case SYS_MODE_AUTHORIZING:
+			if(DiffTimebWithNow(startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]) >= TIME_AUTH_RESULT_TIME)
+				ShmCharger->isGetAuthResult = FALSE;
+
+			if(DiffTimebWithNow(startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]) < TIME_AUTH_RESULT_TIME)
 				page_authorizing(ShmCharger->gun_selectd);
-				break;
-			case SYS_MODE_PREPARING:
+			else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus == SYS_MODE_IDLE) && (ShmCharger->gun_info[ShmCharger->gun_selectd].resultAuthorization == VALIDATED_RFID))
 				page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
-				break;
-			case SYS_MODE_CHARGING:
-				page_charging(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
-				break;
-			case SYS_MODE_TERMINATING:
-				page_terminating(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
-				break;
-			case SYS_MODE_COMPLETE:
-				page_complete(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
-				break;
-			case SYS_MODE_ALARM:
-				page_alarm();
-				break;
-			case SYS_MODE_FAULT:
-				page_fault();
-				break;
-			case SYS_MODE_MAINTAIN:
-				page_maintain();
-				break;
-			case SYS_MODE_UPDATE:
-				page_update();
-				break;
-			case SYS_MODE_RESERVATION:
-				page_reservation();
-				break;
-			case SYS_MODE_BOOKING:
-				page_booking();
-				break;
-			case SYS_MODE_DEBUG:
-				page_debug();
-				break;
-			default:
-				page_unknown();
-				break;
+		}
+		else
+		{
+			ftime(&startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]);
+
+			switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
+			{
+				case SYS_MODE_BOOTING:
+					page_booting();
+					break;
+				case SYS_MODE_IDLE:
+					page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
+					break;
+				case SYS_MODE_AUTHORIZING:
+					//page_authorizing(ShmCharger->gun_selectd);
+					break;
+				case SYS_MODE_PREPARING:
+					page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
+					break;
+				case SYS_MODE_CHARGING:
+					page_charging(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
+					break;
+				case SYS_MODE_TERMINATING:
+					page_terminating(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
+					break;
+				case SYS_MODE_COMPLETE:
+					page_complete(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
+					break;
+				case SYS_MODE_ALARM:
+					page_alarm();
+					break;
+				case SYS_MODE_FAULT:
+					page_fault();
+					break;
+				case SYS_MODE_MAINTAIN:
+					page_maintain();
+					break;
+				case SYS_MODE_UPDATE:
+					page_update();
+					break;
+				case SYS_MODE_RESERVATION:
+					page_reservation();
+					break;
+				case SYS_MODE_BOOKING:
+					page_booking();
+					break;
+				case SYS_MODE_DEBUG:
+					page_debug();
+					break;
+				default:
+					page_unknown();
+					break;
+			}
 		}
 
 		page_header(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);

+ 12 - 24
EVSE/Projects/AW-CCS/Apps/Module_InternalComm.c

@@ -989,18 +989,18 @@ unsigned char Query_Power_Consumption(unsigned char fd, unsigned char targetAddr
 		   (rx[3] == tx[3]))
 		{
 #ifndef SIMULATION
-			Ret_Buf_T-> power_consumption = ((uint32_t)rx[6] | (((uint32_t)rx[7])<<8) | (((uint32_t)rx[8])<<16) | (((uint32_t)rx[9])<<24));
-			Ret_Buf_L1-> power_consumption = ((uint32_t)rx[10] | (((uint32_t)rx[11])<<8) | (((uint32_t)rx[12])<<16) | (((uint32_t)rx[13])<<24));
+			Ret_Buf_T-> power_consumption = ((uint64_t)rx[6] | (((uint64_t)rx[7])<<8) | (((uint64_t)rx[8])<<16) | (((uint64_t)rx[9])<<24) | (((uint64_t)rx[10])<<32) | (((uint64_t)rx[11])<<40) | (((uint64_t)rx[12])<<48) | (((uint64_t)rx[13])<<56));
+			Ret_Buf_L1-> power_consumption = ((uint64_t)rx[14] | (((uint64_t)rx[15])<<8) | (((uint64_t)rx[16])<<16) | (((uint64_t)rx[17])<<24) | (((uint64_t)rx[18])<<32) | (((uint64_t)rx[19])<<40) | (((uint64_t)rx[20])<<48) | (((uint64_t)rx[21])<<56));
 			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
 			{
-				Ret_Buf_L2-> power_consumption = ((uint32_t)rx[14] | (((uint32_t)rx[15])<<8) | (((uint32_t)rx[16])<<16) | (((uint32_t)rx[17])<<24));
-				Ret_Buf_L3-> power_consumption = ((uint32_t)rx[18] | (((uint32_t)rx[19])<<8) | (((uint32_t)rx[20])<<16) | (((uint32_t)rx[21])<<24));
+				Ret_Buf_L2-> power_consumption = ((uint64_t)rx[22] | (((uint64_t)rx[23])<<8) | (((uint64_t)rx[24])<<16) | (((uint64_t)rx[25])<<24) | (((uint64_t)rx[26])<<32) | (((uint64_t)rx[27])<<40) | (((uint64_t)rx[28])<<48) | (((uint64_t)rx[29])<<56));
+				Ret_Buf_L3-> power_consumption = ((uint64_t)rx[30] | (((uint64_t)rx[31])<<8) | (((uint64_t)rx[32])<<16) | (((uint64_t)rx[33])<<24) | (((uint64_t)rx[34])<<32) | (((uint64_t)rx[35])<<40) | (((uint64_t)rx[36])<<48) | (((uint64_t)rx[37])<<56));
 			}
 
 #else	//SIMULATION
 			tsNow = current_timestamp();
 			tmpPowerConsumption += (ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltage*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent)*((tsNow-tsLast)/36000000.0);
-			Ret_Buf_T-> power_consumption = (uint32_t)tmpPowerConsumption;
+			Ret_Buf_T-> power_consumption = (uint64_t)tmpPowerConsumption;
 			tsLast = tsNow;
 #endif	//SIMULATION
 			result = PASS;
@@ -2403,15 +2403,15 @@ int main(void)
 						DEBUG_INFO("MCU-%d get ble central id : %s\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
 					}
 					
-					DEBUG_INFO("===========================================\n");
-					DEBUG_INFO("==== High priority polling : Case 10 ====\n");
-					DEBUG_INFO("===========================================\n");
-					DEBUG_INFO("MCU-%d get total power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100));
-					DEBUG_INFO("MCU-%d get L1N_L12 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/100));
+					DEBUG_INFO("*******************************************\n");
+					DEBUG_INFO("**** High priority polling : Case 10 ****\n");
+					DEBUG_INFO("*******************************************\n");
+					DEBUG_INFO("MCU-%d get total power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0));
+					DEBUG_INFO("MCU-%d get L1N_L12 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/10000.0));
 					if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
 					{
-						DEBUG_INFO("MCU-%d get L2N_L23 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/100));
-						DEBUG_INFO("MCU-%d get L3N_L31 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/100));
+						DEBUG_INFO("MCU-%d get L2N_L23 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/10000.0));
+						DEBUG_INFO("MCU-%d get L3N_L31 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/10000.0));
 					}
 				}
 			}
@@ -2845,18 +2845,6 @@ int main(void)
 							}
 							break;
 						case 6:
-							/*
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("==== Normal priority polling : Case 13 ====\n");
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("MCU-%d get total power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100));
-							DEBUG_INFO("MCU-%d get L1N_L12 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/100));
-							if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
-							{
-								DEBUG_INFO("MCU-%d get L2N_L23 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/100));
-								DEBUG_INFO("MCU-%d get L3N_L31 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/100));
-							}
-							*/
 							break;
 						case 7:
 							if(ShmCharger->gun_info[gun_index].isSetBreatheLedTiming == ON)

File diff suppressed because it is too large
+ 358 - 514
EVSE/Projects/AW-CCS/Apps/main.c


+ 5 - 3
EVSE/Projects/AW-CCS/Apps/main.h

@@ -229,7 +229,7 @@ enum TIMER_IDX
 	TMR_IDX_17,
 	TMR_IDX_18,
 	TMR_IDX_19,
-	TMR_IDX_20,
+	TMR_IDX_GUN_DETECT,
 	TMR_IDX_CNT
 };
 
@@ -447,8 +447,8 @@ typedef struct LEGACY_REQUEST
 
 typedef struct POWER_CONSUMPTION
 {
-	uint32_t power_consumption;
-	uint32_t power_consumption_at_start;
+	uint64_t power_consumption;
+	uint64_t power_consumption_at_start;
 
 }Power_Consumption;
 
@@ -734,6 +734,8 @@ struct Charger
 	uint8_t		 			isUpdateSuccess:1;
 	uint8_t		 			isCcsEnable:1;
 	uint8_t					isLcdOn:1;
+	uint8_t					isAuthrizing:1;
+	uint8_t					isGetAuthResult:1;
 };
 
 #endif /* CONFIG_MAIN_H_ */

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


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


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

@@ -1606,6 +1606,53 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	free(buf);
 
 	system("rm -f /mnt/EvseConfig.bin");
+
+	// SysConfig in flash is empty (0xffffffff)
+	if((strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)) ||
+	   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)) ||
+	   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)) ||
+	   (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff))
+	{
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.ModelName, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId));
+		}
+
+		if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff)
+		{
+			DEBUG_INFO("Ethernet dhcp config is null.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) == 0x00)
+		{
+			DEBUG_INFO("Model name over length.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) == 0x00)
+		{
+			DEBUG_INFO("Model serial number over length.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) == 0x00)
+		{
+			DEBUG_INFO("System id over length.\n");
+		}
+
+		system("cd /root;./Module_FactoryConfig -m");
+		sleep(3);
+		system("/usr/bin/run_evse_restart.sh");
+	}
+
 	DEBUG_INFO("Load SysConfigData OK\n");
 
 	return PASS;
@@ -2094,7 +2141,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.68.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.69.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)

+ 47 - 0
EVSE/Projects/AW-Regular/Apps/main.c

@@ -1606,6 +1606,53 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	free(buf);
 
 	system("rm -f /mnt/EvseConfig.bin");
+	
+	// SysConfig in flash is empty (0xffffffff)
+	if((strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)) ||
+	   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)) ||
+	   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)) ||
+	   (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff))
+	{
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.ModelName, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId));
+		}
+
+		if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff)
+		{
+			DEBUG_INFO("Ethernet dhcp config is null.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) == 0x00)
+		{
+			DEBUG_INFO("Model name over length.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) == 0x00)
+		{
+			DEBUG_INFO("Model serial number over length.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) == 0x00)
+		{
+			DEBUG_INFO("System id over length.\n");
+		}
+
+		system("cd /root;./Module_FactoryConfig -m");
+		sleep(3);
+		system("/usr/bin/run_evse_restart.sh");
+	}
+
 	DEBUG_INFO("Load SysConfigData OK\n");
 
 	return PASS;

+ 7 - 6
EVSE/Projects/DS60-120/Apps/Config.h

@@ -301,18 +301,19 @@ struct DcCommonInformation
 	char RelayCheckStatus[6];
 	char GunRelayWeldingOccur[2];
 	char GunRelayDrivingOccur[2];
-	unsigned char ConnectorTemp1[2]; //0x00: -60¢XC  ~  0xFE: 194
-	unsigned char ConnectorTemp2[2]; //0x00: -60¢XC  ~  0xFE: 194
+	byte ConnectorTemp1[2]; //0x00: -60¢XC  ~  0xFE: 194
+	byte ConnectorTemp2[2]; //0x00: -60¢XC  ~  0xFE: 194
 	// to check the ac contact status with psu communication
-	unsigned char acContactSwitch;
-	unsigned char psuKeepCommunication;
-	unsigned char startTransationFlag[2];
+	byte acContactSwitch;
+	byte psuKeepCommunication;
+	byte startTransationFlag[2];
 
 	GunErr ConnectErrList[2];
 
 	// Plugit Rack180 : for checking start/stop charging flag
-	unsigned char StartToChargingFlag[2]; // 0 : Stop, 1 : Start by modbus
+	byte StartToChargingFlag[2]; // 0 : Stop, 1 : Start by modbus
 	unsigned short LcmFwVersion;
+	byte ShowLogoFlag;
 };
 
 #endif /* CONFIG_H_ */

BIN
EVSE/Projects/DS60-120/Apps/FactoryConfig


BIN
EVSE/Projects/DS60-120/Apps/Module_EvComm


+ 29 - 13
EVSE/Projects/DS60-120/Apps/Module_EvComm.c

@@ -2495,7 +2495,7 @@ bool AbnormalStopAnalysis(byte gun_index, byte *errCode)
 	sprintf(string, "%d%d%d%d%d%d", *(errCode + 0), *(errCode + 1), *(errCode + 2), *(errCode + 3), *(errCode + 4), *(errCode + 5));
 
 	PRINTF_FUNC("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
-	if (strncmp(string, "000000", 6) == EQUAL)
+	if (strncmp(string, "000000", 6) == EQUAL || strncmp(string, "012219", 6) == EQUAL)
 		return false;
 
 	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) != EQUAL)
@@ -3687,6 +3687,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	unsigned long _timeBuf = 0;
 	while(CanFd)
 	{
 		for(byte _index = 0; _index < gun_count; _index++)
@@ -3786,10 +3787,17 @@ int main(int argc, char *argv[])
 							}
 							else
 							{
-								if (GetTimeoutValue(_chk_chademo_permission_timeout[_index]) / 1000 > 10000)
-								{
-									SendCommunicationOnly(_index);
+								_timeBuf = GetTimeoutValue(_chk_chademo_permission_timeout[_index]);
+
+								if (_timeBuf < 0)
 									gettimeofday(&_chk_chademo_permission_timeout[_index], NULL);
+								else
+								{
+									if (_timeBuf / 1000 > 10000)
+									{
+										SendCommunicationOnly(_index);
+										gettimeofday(&_chk_chademo_permission_timeout[_index], NULL);
+									}
 								}
 							}
 						}
@@ -3997,19 +4005,27 @@ int main(int argc, char *argv[])
 
 							if (_result == GFD_WARNING || _result == GFD_PASS)
 							{
-								if (((GetTimeoutValue(_chk_ratingPower_timeout[_index]) / 1000) > 12000 &&
-										_chargingData[_index]->RealRatingPower > 0) ||
-										(GetTimeoutValue(_chk_ratingPower_timeout[_index]) / 1000) > 14000)
+								_timeBuf = GetTimeoutValue(_chk_ratingPower_timeout[_index]);
+								if (_timeBuf < 0)
 								{
-									if (LogInfo[_index][EV_LOG_REAL_CAP_POW] != _chargingData[_index]->RealRatingPower)
+									gettimeofday(&_chk_ratingPower_timeout[_index], NULL);
+								}
+								else
+								{
+									if (((_timeBuf / 1000) > 12000 &&
+											_chargingData[_index]->RealRatingPower > 0) ||
+											(_timeBuf / 1000) > 14000)
 									{
-										LogInfo[_index][EV_LOG_REAL_CAP_POW] = _chargingData[_index]->RealRatingPower;
-										PRINTF_FUNC("Conn %d, RealRatingPower = %d \n",
-											_index, _chargingData[_index]->RealRatingPower);
+										if (LogInfo[_index][EV_LOG_REAL_CAP_POW] != _chargingData[_index]->RealRatingPower)
+										{
+											LogInfo[_index][EV_LOG_REAL_CAP_POW] = _chargingData[_index]->RealRatingPower;
+											PRINTF_FUNC("Conn %d, RealRatingPower = %d \n",
+												_index, _chargingData[_index]->RealRatingPower);
+										}
 									}
+									else
+										_result = GFD_WAIT;
 								}
-								else
-									_result = GFD_WAIT;
 							}
 
 							SetIsolationStatus(_index, _result, targetID);

BIN
EVSE/Projects/DS60-120/Apps/Module_EventLogging


BIN
EVSE/Projects/DS60-120/Apps/Module_InternalComm


+ 117 - 53
EVSE/Projects/DS60-120/Apps/Module_InternalComm.c

@@ -36,10 +36,12 @@
 #define NO					0
 #define STOP				0
 #define START				1
+#define NORMAL				0
 #define	ABNORMAL			1
 #define RELAY_CHECK_TIME	5		// s
 #define OUTPUT_VOL_CHK_TIME	200 	// ms
 #define TEN_MINUTES			600		// s
+#define FORCE_STOP_TIME		30
 //#define TEN_MINUTES			5
 #define ENV_TEMP_MIN		45
 #define ENV_TEMP_MAX		50
@@ -149,6 +151,9 @@ struct timeval	_ac_preparing;
 struct timeb 	_ac_startChargingTime;
 struct timeb 	_ac_endChargingTime;
 
+bool isCriticalStop;
+struct timeval	_psuCriticalStop;
+
 unsigned short _setFanSpeed = 0;
 float _beforeChargingTotalEnergy = 0.0;
 byte _checkLedChanged = 3;
@@ -1832,13 +1837,20 @@ void StartCheckRelayInfo(byte _chkIndex, byte toState)
 	}
 	else
 	{
-		if ((GetTimeoutValue(_relayStateChkTimer[_chkIndex]) / 1000) > RELAY_CHECK_TIME * 1000)
+		unsigned long _timebuf = GetTimeoutValue(_relayStateChkTimer[_chkIndex]);
+
+		if (_timebuf < 0)
+			gettimeofday(&_relayStateChkTimer[_chkIndex], NULL);
+		else
 		{
-			//PRINTF_FUNC ("relay welding or driving fault = %d \n", _chkIndex);
-			if (toState == 1)
-				ShmDcCommonData->RelayCheckStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
-			else
-				ShmDcCommonData->RelayCheckStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
+			if ((_timebuf / 1000) > RELAY_CHECK_TIME * 1000)
+			{
+				//PRINTF_FUNC ("relay welding or driving fault = %d \n", _chkIndex);
+				if (toState == 1)
+					ShmDcCommonData->RelayCheckStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
+				else
+					ShmDcCommonData->RelayCheckStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
+			}
 		}
 	}
 }
@@ -2054,33 +2066,40 @@ void CheckOutputPowerOverCarReq(byte index)
 			}
 			else
 			{
-				if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME)
-				{
-					PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
-							_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
-					DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
-							_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
+				unsigned long _timebuf = GetTimeoutValue(_checkOutputVolProtectTimer[index]);
 
-					if (_chargingData[index]->Type == _Type_Chademo)
-					{
-						ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectOVP = YES;
-						if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
-							memcpy(_chargingData[index]->ConnectorAlarmCode, "012217", 6);
-					}
-					else if (_chargingData[index]->Type == _Type_CCS_2)
-					{
-						ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectOVP = YES;
-						if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
-							memcpy(_chargingData[index]->ConnectorAlarmCode, "012219", 6);
-					}
-					else if (_chargingData[index]->Type == _Type_GB)
+				if (_timebuf < 0)
+					gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
+				else
+				{
+					if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME)
 					{
-						ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectOVP = YES;
-						if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
-							memcpy(_chargingData[index]->ConnectorAlarmCode, "012221", 6);
-					}
+						PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
+								_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
+						DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
+								_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
+
+						if (_chargingData[index]->Type == _Type_Chademo)
+						{
+							ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectOVP = YES;
+							if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012217", 6);
+						}
+						else if (_chargingData[index]->Type == _Type_CCS_2)
+						{
+							ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectOVP = YES;
+							if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012219", 6);
+						}
+						else if (_chargingData[index]->Type == _Type_GB)
+						{
+							ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectOVP = YES;
+							if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012221", 6);
+						}
 
-					_chargingData[index]->StopChargeFlag = YES;
+						_chargingData[index]->StopChargeFlag = YES;
+					}
 				}
 			}
 		}
@@ -2588,6 +2607,30 @@ void AcChargeTypeProcess()
 	}
 }
 
+void RunForceStopProcess()
+{
+	if (isCriticalStop == NO)
+	{
+		isCriticalStop = YES;
+		gettimeofday(&_psuCriticalStop, NULL);
+	}
+	else
+	{
+		unsigned long _timebuf = GetTimeoutValue(_psuCriticalStop);
+
+		if (_timebuf < 0)
+			gettimeofday(&_psuCriticalStop, NULL);
+		else
+		{
+			if (_timebuf / 1000 >= (FORCE_STOP_TIME * 1000))
+			{
+				isCriticalStop = NO;
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NORMAL;
+			}
+		}
+	}
+}
+
 int main(void)
 {
 	if(InitShareMemory() == FAIL)
@@ -2635,6 +2678,7 @@ int main(void)
 	cur_led_color.Connect_2_Blue = COLOR_MIN_LV;
 
 	relayMatchFlag = NO;
+	isCriticalStop = NO;
 	for(;;)
 	{
 		bool isCharging = false;
@@ -2762,6 +2806,12 @@ int main(void)
 			if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
 				outputRelay.relay_event.bits.AC_Contactor = NO;
 
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == ABNORMAL)
+			{
+				RunForceStopProcess();
+				outputRelay.relay_event.bits.AC_Contactor = NO;
+			}
+
 			ShmDcCommonData->acContactSwitch = outputRelay.relay_event.bits.AC_Contactor;
 
 			if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
@@ -2836,38 +2886,52 @@ int main(void)
 		{
 			ShmFanModuleData->SelfTest_Comp = YES;
 
-			if (GetTimeoutValue(_priority_time) / 1000 >= 1300)
-			{
-				//GetPsuTempForFanSpeed();
-				GetFanSpeedByFunction();
-				GetFanSpeed();
-				ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
-				gettimeofday(&_priority_time, NULL);
+			unsigned long _timebuf = GetTimeoutValue(_priority_time);
 
-				ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-				ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-				ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-				ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-
-				//PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
-				SetFanModuleSpeed();
+			if (_timebuf < 0)
+				gettimeofday(&_priority_time, NULL);
+			else
+			{
+				if (_timebuf / 1000 >= 1000)
+				{
+					//GetPsuTempForFanSpeed();
+					GetFanSpeedByFunction();
+					GetFanSpeed();
+					ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
+					gettimeofday(&_priority_time, NULL);
+
+					ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
+
+					//PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
+					SetFanModuleSpeed();
+				}
 			}
 		}
 
 		if (ShmLedModuleData->SelfTest_Comp == YES)
 		{
-			if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000)
+			unsigned long _timebuf = GetTimeoutValue(_led_priority_time);
+
+			if (_timebuf < 0)
+				gettimeofday(&_led_priority_time, NULL);
+			else
 			{
-				if(gunCount == 1)
-				{
-					SetLedColor(_chargingData[0], _chargingData[0]);
-				}
-				else if (gunCount == 2)
+				if (_timebuf / 1000 >= 1000)
 				{
-					SetLedColor(_chargingData[0], _chargingData[1]);
-				}
+					if(gunCount == 1)
+					{
+						SetLedColor(_chargingData[0], _chargingData[0]);
+					}
+					else if (gunCount == 2)
+					{
+						SetLedColor(_chargingData[0], _chargingData[1]);
+					}
 
-				gettimeofday(&_led_priority_time, NULL);
+					gettimeofday(&_led_priority_time, NULL);
+				}
 			}
 		}
 

+ 2 - 0
EVSE/Projects/DS60-120/Apps/Module_LcmContro.h

@@ -91,6 +91,7 @@ byte QRCodeBuf[128];
 
 // LCM - HW
 byte _everyPageRollChange = 0;
+short __logo = 0x0000;
 short __conn_status = 0x0030;
 short __ethernet_status = 0x0032;
 short __3G4G_status = 0x0036;
@@ -134,6 +135,7 @@ short __output_eng_tx = 0x0120;
 short __total_out_eng_tx = 0x0130;
 short __conn_line_comp = 0x0140;
 short __charging_fee_map = 0x0146;
+short __logo_cmp = 0x014A;
 short __charging_fee_tx = 0x0150;
 
 short __money_by_rate = 0x0200;

BIN
EVSE/Projects/DS60-120/Apps/Module_LcmControl


+ 33 - 12
EVSE/Projects/DS60-120/Apps/Module_LcmControl.c

@@ -308,7 +308,7 @@ void GetCurrentPage()
 	cmd[5] = 0x02;
 
 	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-	//usleep(10000);
+	usleep(10000);
 	ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
 }
 
@@ -357,7 +357,7 @@ void GetDeviceInfoStatus(short address, byte len)
 	cmd[6] = len;
 
 	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-	//usleep(100000);
+	usleep(10000);
 	ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
 }
 
@@ -1356,6 +1356,8 @@ void ProcessPageInfo()
 				// 新增隨插即充功能預設在等待插槍頁面在開啟
 				ChangeDisplay2Value(__ret_home_btn, _disappear);
 			}
+			else
+				ChangeDisplay2Value(__ret_home_btn, _back_home_btn);
 
 			if (isCharging && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
 			{
@@ -1373,7 +1375,8 @@ void ProcessPageInfo()
 		{
 			bool isShowAc = false;
 			byte gunTargetIndex = 0;
-			bool idleGun = false;
+
+			ChangeDisplay2Value(__ret_home_btn, _back_home_btn);
 
 			if (acgunCount > 0)
 			{
@@ -1407,7 +1410,8 @@ void ProcessPageInfo()
 						else
 							ChangeChargingEnergyValue(0);
 
-						if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == 0)
+						if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == 0 ||
+								ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES)
 							ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
 						else
 							ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
@@ -1570,7 +1574,8 @@ void ProcessPageInfo()
 						else
 							ChangeChargingEnergyValue(0);
 
-						if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0)
+						if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0 ||
+								ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES)
 							ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
 						else
 							ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
@@ -1622,12 +1627,10 @@ void ProcessPageInfo()
 						}
 					}
 				}
-
-				if (_chargingInfoData[i]->SystemStatus == S_IDLE)
-					idleGun = true;
 			}
 
-			if (idleGun && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+			if (_totalCount > 1 &&
+					ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
 			{
 				ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
 			}
@@ -1783,12 +1786,14 @@ int main(void)
 	ChangeBackLight(true);
 	_totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
 	acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
 	Initialization();
 
-	//ChangeToOtherPage(_LCM_EMC);
-	//return -1;
+//	ChangeToOtherPage(_LCM_EMC);
+//	return -1;
 
 	DefaultIconStatus();
+	byte _verShowCount = 3;
 
 	while(_port != -1)
 	{
@@ -1797,7 +1802,23 @@ int main(void)
 			GetDeviceInfoStatus(__lcm_version, 3);
 			GetCurrentPage();
 			sleep(1);
-			PRINTF_FUNC("LCM Version = V.%03d \n", ShmDcCommonData->LcmFwVersion);
+
+			if (_verShowCount > 0)
+			{
+				PRINTF_FUNC("LCM Version = V.%03d \n", ShmDcCommonData->LcmFwVersion);
+				_verShowCount--;
+			}
+
+			if (ShmDcCommonData->ShowLogoFlag)
+			{
+				ChangeDisplay2Value(__logo, _logo);
+				ChangeDisplay2Value(__logo_cmp, _logo_cmp);
+			}
+			else
+			{
+				ChangeDisplay2Value(__logo, _disappear);
+				ChangeDisplay2Value(__logo_cmp, _disappear);
+			}
 		}
 		else
 		{

BIN
EVSE/Projects/DS60-120/Apps/Module_PrimaryComm


BIN
EVSE/Projects/DS60-120/Apps/Module_PsuComm


+ 37 - 4
EVSE/Projects/DS60-120/Apps/Module_PsuComm.c

@@ -1134,6 +1134,17 @@ void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char st
 
 	ShmPsuData->PsuGroup[group1].PsuModule[address].AlarmCode = alarm;
 	//AbnormalStopAnalysis(group1, alarm);
+
+	if(isErr)
+	{
+		// 012267 - need to test the variable (short circuit output)
+		if (!ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm )
+		{
+			//ShmPsuData->PsuGroup[group1].GroupErrorFlag.bits.PsuFailure = YES;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
+			PRINTF_FUNC("Group_%d, PSU Error Occurred. \n", group1);
+		}
+	}
 }
 
 void GetModuleInputCallback(byte address, unsigned short inputR,
@@ -1537,6 +1548,8 @@ int main(void)
 				int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
 				byte moduleCount = 0;
 
+				if (time < 0)
+					gettimeofday(&_cmdSubPriority_time, NULL);
 				// 發送取得目前全部模組數量
 				GetModuleCount(SYSTEM_CMD);
 
@@ -1580,6 +1593,9 @@ int main(void)
 			{
 				int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
 
+				if (time < 0)
+					gettimeofday(&_cmdSubPriority_time, NULL);
+
 				if (time > 500)
 				{
 					bool isFinish = true;
@@ -1655,6 +1671,10 @@ int main(void)
 			case _WORK_CHARGING:
 			{
 				int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+				unsigned long _timebuf = 0;
+
+				if (time < 0)
+					gettimeofday(&_cmdSubPriority_time, NULL);
 
 				// 低 Priority 的指令
 				if (time > 1500)
@@ -1706,7 +1726,11 @@ int main(void)
 							(chargingInfo[groupIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= S_CHARGING && chargingInfo[groupIndex]->Type == _Type_GB) ||
 							(chargingInfo[groupIndex]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[groupIndex]->SystemStatus <= S_CCS_PRECHARGE_ST1))
 					{
-						if (GetTimeoutValue(_log_time) / 1000 > 1000)
+						_timebuf = GetTimeoutValue(_log_time);
+						if (_timebuf < 0)
+							gettimeofday(&_log_time, NULL);
+
+						if (_timebuf / 1000 > 1000)
 						{
 							OutputChargingLogFuncion(groupIndex);
 							gettimeofday(&_log_time, NULL);
@@ -1818,7 +1842,9 @@ int main(void)
 								}
 								else
 								{
-									if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
+									int _t = GetTimeoutValue(_derating_time);
+
+									if ((_t / 1000) > 1000 || _t < 0)
 									{
 										gettimeofday(&_derating_time, NULL);
 									}
@@ -1973,7 +1999,9 @@ int main(void)
 								}
 								else
 								{
-									if ((GetTimeoutValue(_max_time) / 1000) > 500)
+									int _tMax_1 = GetTimeoutValue(_max_time);
+
+									if ((_tMax_1 / 1000) > 500 || _tMax_1 < 0)
 									{
 										gettimeofday(&_max_time, NULL);
 									}
@@ -2010,7 +2038,9 @@ int main(void)
 								}
 								else
 								{
-									if ((GetTimeoutValue(_max_time) / 1000) > 300)
+									int _tMax_2 = GetTimeoutValue(_max_time);
+
+									if ((_tMax_2 / 1000) > 300 || _tMax_2 < 0)
 									{
 										gettimeofday(&_max_time, NULL);
 									}
@@ -2251,6 +2281,9 @@ int main(void)
 				// 在測試模式中,保持與模塊的通訊
 				int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
 
+				if (time < 0)
+					gettimeofday(&_cmdSubPriority_time, NULL);
+
 				if (time > 1500)
 				{
 					for (byte index = 0; index < ShmPsuData->GroupCount; index++)

BIN
EVSE/Projects/DS60-120/Apps/ReadCmdline


+ 16 - 2
EVSE/Projects/DS60-120/Apps/ReadCmdline.c

@@ -446,6 +446,21 @@ void GetFwVerProc(char *v1)
 		}
 		printf("AC Version = %s \n", ac_chargingInfo[0]->version);
 	}
+	else if (strcmp(v1, "all") == 0)
+	{
+		printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+		printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
+		printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
+		printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
+		printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
+		printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
+		printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
+		if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
+		{
+			printf("FindChargingInfoData (AC) false \n");
+		}
+		printf("AC Version = %s \n", ac_chargingInfo[0]->version);
+	}
 }
 
 void CreateOneError()
@@ -1365,8 +1380,7 @@ int main(void)
 				printf ("FindChargingInfoData error\n");
 				continue;
 			}
-
-			_chargingData[1]->PowerConsumption += 4.2;
+			ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0x01;
 		}
 		else if(strcmp(newString[0], "strchg") == 0)
 		{

BIN
EVSE/Projects/DS60-120/Apps/UnsafetyOutputTask


BIN
EVSE/Projects/DS60-120/Apps/main


+ 276 - 142
EVSE/Projects/DS60-120/Apps/main.c

@@ -109,6 +109,7 @@ void gpio_set_value(unsigned int gpio, unsigned int value);
 void PRINTF_FUNC(char *string, ...);
 void ChangeGunSelectByIndex(byte sel);
 void ChargingAlarmProcess(byte gunIndex);
+void CheckSystemErrorFunction(byte index);
 
 int opcc_chk_reserve_expired(byte gunIndex);
 void ocpp_process_start();
@@ -174,8 +175,11 @@ struct DcCommonInformation		*ShmDcCommonData;
 
 struct ChargingInfoData			*chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 struct ChargingInfoData			*ac_chargingInfo[AC_QUANTITY];
+
 struct timeb 					startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 struct timeb 					endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+int 							_presentChargingTimeBuf[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
 struct timeval 					_startTransation_time[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 float gunOutputVol [CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
@@ -758,9 +762,20 @@ void ChangeLcmByIndex(byte page_index)
 	if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
 			page_index == _LCM_COMPLETE || page_index == _LCM_FIX || page_index == _LCM_EMC)
 	{
-		if (page_index == _LCM_FIX || page_index == _LCM_EMC)
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0 &&
+				(page_index == _LCM_FIX || page_index == _LCM_EMC))
 		{
-			if (chargingInfo[page_index]->SystemStatus != S_RESERVATION &&
+			bool isUpdate = false;
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo[_index]->SystemStatus != S_RESERVATION &&
+						chargingInfo[_index]->SystemStatus != S_MAINTAIN)
+				{
+					isUpdate = true;
+				}
+			}
+
+			if (isUpdate &&
 					ShmDcCommonData->LcmFwVersion > 0 &&
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
 				ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_EMC;
@@ -1458,6 +1473,13 @@ void GetFirmwareVersion()
 		ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
 	else if (strcmp(_buf, "WU") == EQUAL)
 		ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
+
+	memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2);
+
+	if (strcmp(_buf, "PH") == EQUAL)
+		ShmDcCommonData->ShowLogoFlag = YES;
+	else
+		ShmDcCommonData->ShowLogoFlag = NO;
 }
 
 void InitialGunIndexToUnUse()
@@ -1576,7 +1598,6 @@ void InitialShareMemoryInfo()
 	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
 	InitialGunIndexToUnUse();
 
-	ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
 	ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
 
 	ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
@@ -1585,6 +1606,8 @@ void InitialShareMemoryInfo()
 	ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
 	ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
 	ShmDcCommonData->LcmFwVersion = 0;
+
+	ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
 }
 
 int Initialization()
@@ -1597,7 +1620,7 @@ int Initialization()
 	// UART 2 for Rfid
 	rfidFd = InitialRfidPort();
 
-	int pinOut[2] = { 116, 115 };
+	int pinOut[2] = { 116, 115 }; //D13(Cha)、C13(CCS)
 	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
 	{
 		chargingInfo[count]->RemoteStartFlag = NO;
@@ -2185,7 +2208,7 @@ void _SelfTestTimeout()
 
 void _AuthorizedTimeout()
 {
-	if(IsAuthorizingMode())
+	//if(IsAuthorizingMode())
 	{
 		PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
 		isCardScan = false;
@@ -2353,6 +2376,15 @@ void ResetChargerAlarmCode(byte gunIndex, char *code)
 void ReleaseSysAlarmCode(byte gunIndex)
 {
 	// 回 idle 後主要清除  GFD Trip、UVP、OVP、GFD Warning
+	if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
+	{
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL)
+		{
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+		}
+	}
+
 	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
 	{
 		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
@@ -2411,6 +2443,11 @@ void ReleaseSysAlarmCode(byte gunIndex)
 	ocpp_clear_errorCode_cmd(gunIndex);
 }
 
+void NormalStop(byte gunIndex)
+{
+	PRINTF_FUNC("NormalStop (%d) \n", gunIndex);
+}
+
 //===============================================
 // EmergencyStop and Charging Stop
 //===============================================
@@ -2421,6 +2458,7 @@ void ChargingTerminalProcess(byte gunIndex)
 
 void ChargingAlarmProcess(byte gunIndex)
 {
+	CheckSystemErrorFunction(gunIndex);
 	ocpp_set_errCode_cmd(gunIndex);
 	setChargerMode(gunIndex, MODE_ALARM);
 }
@@ -2533,9 +2571,7 @@ void ChkPrimaryStatus()
 		ReleaseEmsOccureByString(0, "012238");
 
 	if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
-	{
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
-	}
 	else
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
 
@@ -2547,6 +2583,13 @@ void ChkPrimaryStatus()
 	else
 		ReleaseEmsOccureByString(0, "012252");
 
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
+	{
+		EmcOccureThenStopCharging();
+	}
+	else
+		ReleaseEmsOccureByString(0, "012267");
+
 	if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
 			ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS)
 		ShmSysConfigAndInfo->SysConfig.ShowInformation = YES;
@@ -2627,10 +2670,12 @@ void ChkPrimaryStatus()
 					break;
 				case S_CHARGING:
 				{
-					if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
-							chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->isRemoteStart == NO)
+					if (ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES ||
+							(ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
+							chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->isRemoteStart == NO))
 					{
 						// 按鈕 - 停止充電
+						NormalStop(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
 						ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
 					}
 				}
@@ -2718,6 +2763,9 @@ void CheckSystemErrorFunction(byte index)
 	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen)
 		RecordAlarmCode(index, "012252");
 
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
+		RecordAlarmCode(index, "012267");
+
 	if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
 	{
 		if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
@@ -3031,6 +3079,7 @@ void UserScanFunction()
 						// 同一張卡直接停掉
 						if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
 						{
+							NormalStop(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
 							ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
 							strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
 						}
@@ -3596,6 +3645,7 @@ int CheckUpdateProcess(void)
             fd = open(new_str, O_RDONLY);
             if (fd < 0)
             {
+            	close(fd);
             	result = FAIL;
             	sleep(1);
             	continue;
@@ -3608,6 +3658,7 @@ int CheckUpdateProcess(void)
             ImageLen = read(fd, ptr, MaxLen);
             bool isModelNameFail = false;
 
+            // DS-----J0E-2PH
             if((ShmSysConfigAndInfo->SysConfig.ModelName[0] != ptr[0]) ||
             	   (ShmSysConfigAndInfo->SysConfig.ModelName[1] != ptr[1]) ||
             	   (ShmSysConfigAndInfo->SysConfig.ModelName[7] != ptr[7]) ||
@@ -3622,7 +3673,10 @@ int CheckUpdateProcess(void)
             }
 
             if (isModelNameFail)
+            {
+            	close(fd);
             	continue;
+            }
 
             PRINTF_FUNC("model name check pass. \n");
             if (ImageLen > 20) {
@@ -3765,6 +3819,7 @@ int CheckUpdateProcess(void)
                 }
             }
             free(ptr);
+            close(fd);
         }
     }
     free(dir);
@@ -3954,83 +4009,103 @@ void CreateTimeoutFork()
 		gettimeofday(&_cmdSubPriority_time, NULL);
 		CheckConnectionTimeout();
 
+		unsigned long _timebuf = 0;
+
 		while(true)
 		{
-			if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000)
+			_timebuf = GetTimeoutValue(_cmdSubPriority_time);
+			if (_timebuf < 0)
 			{
-				CheckConnectionTimeout();
-
 				gettimeofday(&_cmdSubPriority_time, NULL);
 			}
+			else
+			{
+				if ((_timebuf / 1000) > 5000)
+				{
+					CheckConnectionTimeout();
+					gettimeofday(&_cmdSubPriority_time, NULL);
+				}
+			}
 
 			//printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
 			// 系統
-			switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
+			_timebuf = GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
+			if (_timebuf < 0)
 			{
-				case Timeout_SelftestChk:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT)
-					{
-						_SelfTestTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_Authorizing:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT)
-					{
-						_AuthorizedTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_VerifyFail:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT)
-					{
-						_AutoReturnTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_VerifyComp:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT)
-					{
-						_AutoReturnTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_WaitPlug:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout)
-					{
-						_DetectPlugInTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_ReturnToChargingGunDet:
-				{
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE)
-					{
-						DisplayChargingInfo();
-						StopSystemTimeoutDet();
-					}
-				}
-					break;
-				case Timeout_AuthorizingForStop:
+				gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
+			}
+			else
+			{
+				switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
 				{
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT)
+					case Timeout_SelftestChk:
+						if (_timebuf / uSEC_VAL >= SELFTEST_TIMEOUT)
+						{
+							_SelfTestTimeout();
+							StopSystemTimeoutDet();
+						}
+						break;
+					case Timeout_Authorizing:
+						if (_timebuf / uSEC_VAL >= AUTHORIZE_TIMEOUT)
+						{
+							_AuthorizedTimeout();
+							StopSystemTimeoutDet();
+						}
+						break;
+					case Timeout_VerifyFail:
+						if (_timebuf / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT)
+						{
+							_AutoReturnTimeout();
+							StopSystemTimeoutDet();
+						}
+						break;
+					case Timeout_VerifyComp:
+						if (_timebuf / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT)
+						{
+							_AutoReturnTimeout();
+							StopSystemTimeoutDet();
+						}
+						break;
+					case Timeout_WaitPlug:
+						if (_timebuf / uSEC_VAL >= _connectionTimeout)
+						{
+							_DetectPlugInTimeout();
+							StopSystemTimeoutDet();
+						}
+						break;
+					case Timeout_ReturnToChargingGunDet:
 					{
-						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-						ClearAuthorizedFlag();
-						StopSystemTimeoutDet();
+						if (_timebuf / uSEC_VAL >= RETURN_TO_CHARGING_PAGE)
+						{
+							DisplayChargingInfo();
+							StopSystemTimeoutDet();
+						}
 					}
+						break;
+//					case Timeout_AuthorizingForStop:
+//					{
+//						if (_timebuf / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT)
+//						{
+//							strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+//							ClearAuthorizedFlag();
+//							StopSystemTimeoutDet();
+//						}
+//					}
+//						break;
 				}
-					break;
 			}
+
 			// 各槍
 			for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
 			{
+				_timebuf = GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer);
+
 				//printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
 				switch(chargingInfo[gun_index]->TimeoutFlag)
 				{
 					case Timeout_Preparing:
 					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT)
+						if (_timebuf / uSEC_VAL >= GUN_PREPARE_TIMEOUT)
 						{
 							_PrepareTimeout(gun_index);
 							StopGunInfoTimeoutDet(gun_index);
@@ -4039,7 +4114,7 @@ void CreateTimeoutFork()
 						break;
 					case Timeout_EvChargingDet:
 					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT)
+						if (_timebuf / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT)
 						{
 							_DetectEvChargingEnableTimeout(gun_index);
 							StopGunInfoTimeoutDet(gun_index);
@@ -4048,7 +4123,7 @@ void CreateTimeoutFork()
 						break;
 					case Timeout_EvseChargingDet:
 					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT)
+						if (_timebuf / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT)
 						{
 							_DetectEvseChargingEnableTimeout(gun_index);
 							StopGunInfoTimeoutDet(gun_index);
@@ -4057,7 +4132,7 @@ void CreateTimeoutFork()
 						break;
 					case Timeout_EvseCompleteDet:
 					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT)
+						if (_timebuf / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT)
 						{
 							StopGunInfoTimeoutDet(gun_index);
 						}
@@ -4065,7 +4140,7 @@ void CreateTimeoutFork()
 						break;
 					case Timeout_ForCcsPrechargeDet:
 					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT)
+						if (_timebuf / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT)
 						{
 							_CcsPrechargeTimeout(gun_index);
 							StopGunInfoTimeoutDet(gun_index);
@@ -4329,7 +4404,6 @@ void ocpp_sub_run_reset(bool canReset)
 			sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
 			ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
 			ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
-			ChangeLcmByIndex(_LCM_FIX);
 			sleep(3);
 			system("reboot -f");
 		}
@@ -4339,7 +4413,6 @@ void ocpp_sub_run_reset(bool canReset)
 			sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
 			ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
 			ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
-			ChangeLcmByIndex(_LCM_FIX);
 			sleep(3);
 			KillAllTask();
 			system("/usr/bin/run_evse_restart.sh");
@@ -4353,7 +4426,6 @@ void ocpp_sub_run_reset(bool canReset)
 			sprintf((char*)ShmOCPP20Data->Reset.Response_status, "Accepted");
 			ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
 			ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
-			ChangeLcmByIndex(_LCM_FIX);
 			sleep(3);
 			system("reboot -f");
 		}
@@ -4363,7 +4435,6 @@ void ocpp_sub_run_reset(bool canReset)
 			sprintf((char*)ShmOCPP20Data->Reset.Response_status, "Accepted");
 			ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
 			ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
-			ChangeLcmByIndex(_LCM_FIX);
 			sleep(3);
 			KillAllTask();
 			system("/usr/bin/run_evse_restart.sh");
@@ -4396,6 +4467,16 @@ void ocpp_chk_reset_cmd()
 			}
 		}
 
+		if (canReset)
+		{
+			// Reset -> change status to maintain.
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				setChargerMode(_index, MODE_MAINTAIN);
+			}
+			ChangeLcmByIndex(_LCM_FIX);
+		}
+
 		ocpp_sub_run_reset(canReset);
 	}
 }
@@ -4738,6 +4819,7 @@ void ocpp_chk_update_cmd()
 			if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
 			{
 				DEBUG_INFO_MSG("Backend : update start. \n");
+				sleep(2);
 				strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
 				strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
 				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
@@ -4791,6 +4873,7 @@ void ocpp_chk_update_cmd()
 			if (strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded") == EQUAL)
 			{
 				DEBUG_INFO_MSG("Backend : update start. \n");
+				sleep(2);
 				strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "");
 				strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installing");
 				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
@@ -5121,6 +5204,23 @@ bool ocpp_get_authorize_conf()
 	return false;
 }
 
+bool ocpp_get_startTransation_req(byte gunIndex)
+{
+	bool result = false;
+
+	// 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		result = ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		result = ShmOCPP20Data->CpMsg.bits[gunIndex].TransactionEventReq;
+	}
+
+	return result;
+}
+
 void ocpp_chargingProfile_process(byte _index)
 {
 	int _time = 0;
@@ -5473,7 +5573,7 @@ void DB_Update_PowerConsumption(sqlite3 *db, uint8_t gun_index, float value)
 		}
 		else
 		{
-			PRINTF_FUNC("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
+			//PRINTF_FUNC("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
 		}
 
 		sqlite3_close(db);
@@ -5729,6 +5829,7 @@ void StopProcessingLoop()
 	{
 		CheckFactoryConfigFunction();
 		CheckFwUpdateFunction();
+		ocpp_chk_reset_cmd();
 		if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
 		{
 			ChkPrimaryStatus();
@@ -5986,9 +6087,19 @@ bool GetStartChargingByAlterMode(byte _gun)
 
 void TheEndCharging(byte gun_index)
 {
+	int _diffTime = 0;
+
 	ftime(&endChargingTime[gun_index]);
-	if (chargingInfo[gun_index]->PresentChargedDuration != 0)
-			chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+	_diffTime = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+
+	// below 0 or over 5 sec is abnormal
+	if (_diffTime < 0 ||
+			_diffTime > chargingInfo[gun_index]->PresentChargedDuration + 5)
+	{
+		PRINTF_FUNC("TimeZone changed End (%d) \n", gun_index);
+	}
+	else
+		chargingInfo[gun_index]->PresentChargedDuration = _presentChargingTimeBuf[gun_index] + _diffTime;
 
 	chargingInfo[gun_index]->isRemoteStart = NO;
 
@@ -6050,7 +6161,8 @@ void ReviewCriticalAlarm()
 			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
 			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
 			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen ||
-			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE)
+			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
 	{
 		ShmSysConfigAndInfo->SysWarningInfo.Level = 2;
 	}
@@ -6326,6 +6438,25 @@ void AlarmCheck(byte type)
 	}
 }
 
+void SavePresentChargedDuration(byte gun_index)
+{
+	int _diffTime = 0;
+
+	ftime(&endChargingTime[gun_index]);
+	_diffTime = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+
+	// below 0 or over 5 sec is abnormal
+	if (_diffTime < 0 ||
+			_diffTime > chargingInfo[gun_index]->PresentChargedDuration + 5)
+	{
+		_presentChargingTimeBuf[gun_index] = chargingInfo[gun_index]->PresentChargedDuration;
+		ftime(&startChargingTime[gun_index]);
+		PRINTF_FUNC("TimeZone changed (%d) \n", gun_index);
+	}
+	else
+		chargingInfo[gun_index]->PresentChargedDuration = _presentChargingTimeBuf[gun_index] + _diffTime;
+}
+
 int main(void)
 {
 	if(CreateShareMemory() == 0)
@@ -6384,32 +6515,33 @@ int main(void)
 	CreateTimeoutFork();
 	SelfTestRun();
 	StopSystemTimeoutDet();
+
 	if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
 			ShmPsuData->Work_Step == _NO_WORKING ||
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
+			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES ||
+			strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == EQUAL)
 	{
 		if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
 		{
-			if (!DisplaySelfTestFailReason())
+			if (!DisplaySelfTestFailReason() &&
+					ShmDcCommonData->rebootCount < 1)
 			{
-				PRINTF_FUNC("Soft reboot for retry self-tets. \n");
+				printf("Soft reboot for retry self-tets. \n");
+				SetupRebootCount(1);
 				sleep(3);
 				KillAllTask();
 				system("/usr/bin/run_evse_restart.sh");
 			}
-			else
+			else if (ShmDcCommonData->rebootCount < 1)
 			{
-				if (ShmDcCommonData->rebootCount <= 1)
-				{
-					PRINTF_FUNC("Soft reboot for retry self-tets (Nomal). \n");
-					SetupRebootCount(1);
-					sleep(3);
-					KillAllTask();
-					system("/usr/bin/run_evse_restart.sh");
-				}
-				else
-					SetupRebootCount(0);
+				printf("Soft reboot for retry self-tets (Nomal). \n");
+				SetupRebootCount(1);
+				sleep(3);
+				KillAllTask();
+				system("/usr/bin/run_evse_restart.sh");
 			}
+			else
+				SetupRebootCount(0);
 		}
 
 		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
@@ -6479,6 +6611,8 @@ int main(void)
 		system ("pkill OcppBackend");
 	}
 
+	unsigned long _mainTimebuf = 0;
+
 	for (;;)
 	{
 		ocpp_auto_response_BootNotification();
@@ -6493,6 +6627,12 @@ int main(void)
 			CheckFwUpdateFunction();
 		}
 
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0)
+		{
+			sleep(1);
+			continue;
+		}
+
 		// OCPP 邏輯
 		ocpp_chk_remoteStart_cmd();
 		// 讀卡邏輯
@@ -6507,6 +6647,11 @@ int main(void)
 			ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
 		}
 
+		_mainTimebuf = GetTimeoutValue(_cmdMainPriority_time);
+
+		if (_mainTimebuf < 0)
+			gettimeofday(&_cmdMainPriority_time, NULL);
+
 		if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000)
 		{
 			CheckTask();
@@ -6541,20 +6686,20 @@ int main(void)
 				// OTP
 				if (chargingInfo[_index]->Type == _Type_Chademo)
 				{
-					if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
-					{
-						if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
-							RecordAlarmCode(_index, "012229");
-						else if (chargingInfo[_index]->ConnectorTemp != 0 &&
-								chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
-							ResetChargerAlarmCode(_index, "012229");
-					}
-					else
-					{
-						// 沒接上 Sensor or 異常
-						//RecordAlarmCode(_index, "011018");
-						ResetChargerAlarmCode(_index, "012229");
-					}
+//					if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
+//					{
+//						if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
+//							RecordAlarmCode(_index, "012229");
+//						else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+//								chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
+//							ResetChargerAlarmCode(_index, "012229");
+//					}
+//					else
+//					{
+//						// 沒接上 Sensor or 異常
+//						//RecordAlarmCode(_index, "011018");
+//						ResetChargerAlarmCode(_index, "012229");
+//					}
 				}
 				else if (chargingInfo[_index]->Type == _Type_CCS_2)
 				{
@@ -6578,20 +6723,20 @@ int main(void)
 				}
 				else if (chargingInfo[_index]->Type == _Type_GB)
 				{
-					if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
-					{
-						if(chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
-							RecordAlarmCode(_index, "012231");
-						else if (chargingInfo[_index]->ConnectorTemp != 0 &&
-								chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
-							ResetChargerAlarmCode(_index, "012231");
-					}
-					else
-					{
-						// 沒接上 Sensor or 異常
-						RecordAlarmCode(_index, "011020");
-						ResetChargerAlarmCode(_index, "012231");
-					}
+//					if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
+//					{
+//						if(chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
+//							RecordAlarmCode(_index, "012231");
+//						else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+//								chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
+//							ResetChargerAlarmCode(_index, "012231");
+//					}
+//					else
+//					{
+//						// 沒接上 Sensor or 異常
+//						RecordAlarmCode(_index, "011020");
+//						ResetChargerAlarmCode(_index, "012231");
+//					}
 				}
 			}
 
@@ -7009,6 +7154,7 @@ int main(void)
 					if (isModeChange(gun_index))
 					{
 						PRINTF_FUNC("================== S_PREPARING_FOR_EV (%x) ================ \n", gun_index);
+						_presentChargingTimeBuf[gun_index] = 0;
 						//strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
 						StopGunInfoTimeoutDet(gun_index);
 						StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
@@ -7030,6 +7176,7 @@ int main(void)
 						{
 							if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING ||
 									ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									!ocpp_get_startTransation_req(gun_index) ||
 									_isAllowChargingOnDisconnect)
 							{
 								ShmDcCommonData->startTransationFlag[gun_index] = START_TRANSATION_STATUS_PASS;
@@ -7081,6 +7228,11 @@ int main(void)
 					{
 						// 後臺要求停止
 						ChargingTerminalProcess(gun_index);
+						if (ShmDcCommonData->startTransationFlag[gun_index] == START_TRANSATION_STATUS_FAIL ||
+								ShmDcCommonData->startTransationFlag[gun_index] == START_TRANSATION_STATUS_WAIT)
+						{
+							PRINTF_FUNC("StartTransaction req fail. (%d) \n", gun_index);
+						}
 					}
 
 					// LCM => Pre-charging
@@ -7198,8 +7350,7 @@ int main(void)
 						ChangeStartOrStopDateTime(YES, gun_index);
 					}
 
-					ftime(&endChargingTime[gun_index]);
-					chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+					SavePresentChargedDuration(gun_index);
 
 					if (chargingInfo[gun_index]->Type == _Type_Chademo)
 					{
@@ -7208,13 +7359,6 @@ int main(void)
 							// GFD 錯誤停止
 							RecordAlarmCode(gun_index, "012234");
 						}
-//						else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-//								(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))
-//						{
-//							// UVP
-//							RecordAlarmCode(gun_index, "012289");
-//							ChargingTerminalProcess(gun_index);
-//						}
 						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
 						{
 							// GFD 警告
@@ -7228,14 +7372,6 @@ int main(void)
 							// GFD 錯誤停止
 							RecordAlarmCode(gun_index, "012236");
 						}
-//						else if (isPrechargeStatus_gb(gun_index) == 10 &&
-//								(((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-//								(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)))
-//						{
-//							// UVP
-//							RecordAlarmCode(gun_index, "012290");
-//							ChargingTerminalProcess(gun_index);
-//						}
 						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
 						{
 							// GFD 警告
@@ -7249,13 +7385,6 @@ int main(void)
 							// GFD 錯誤停止
 							RecordAlarmCode(gun_index, "012235");
 						}
-//						else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-//								(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))
-//						{
-//							// UVP
-//							RecordAlarmCode(gun_index, "012288");
-//							ChargingTerminalProcess(gun_index);
-//						}
 						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
 						{
 							// GFD 警告
@@ -7313,7 +7442,10 @@ int main(void)
 							TheEndCharging(gun_index);
 						}
 						else
+						{
+							ocpp_set_errCode_cmd(gun_index);
 							PRINTF_FUNC("================== S_TERMINATING (%x) ================ \n", gun_index);
+						}
 
 						StopGunInfoTimeoutDet(gun_index);
 					}
@@ -7363,6 +7495,7 @@ int main(void)
 					{
 						if(chargingInfo[gun_index]->ConnectorPlugIn == NO &&
 							GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
+						//if(GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
 						{
 							setChargerMode(gun_index, MODE_IDLE);
 						}
@@ -7418,6 +7551,7 @@ int main(void)
 
 					if(chargingInfo[gun_index]->ConnectorPlugIn == NO &&
 							GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
+					//if(GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
 					{
 						setChargerMode(gun_index, MODE_IDLE);
 					}

BIN
EVSE/Projects/DS60-120/Images/ramdisk.gz


+ 47 - 0
EVSE/Projects/Noodoe/Apps/main.c

@@ -864,6 +864,53 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	free(buf);
 
 	system("rm -f /mnt/EvseConfig.bin");
+
+	// SysConfig in flash is empty (0xffffffff)
+	if((strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)) ||
+	   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)) ||
+	   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)) ||
+	   (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff))
+	{
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.ModelName, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId))
+		{
+			memset(ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId));
+		}
+
+		if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff)
+		{
+			DEBUG_INFO("Ethernet dhcp config is null.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) == 0x00)
+		{
+			DEBUG_INFO("Model name over length.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) == 0x00)
+		{
+			DEBUG_INFO("Model serial number over length.\n");
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) == 0x00)
+		{
+			DEBUG_INFO("System id over length.\n");
+		}
+
+		system("cd /root;./Module_FactoryConfig -m");
+		sleep(3);
+		system("/usr/bin/run_evse_restart.sh");
+	}
+
 	DEBUG_INFO("Load SysConfigData OK\n");
 
 	return PASS;

BIN
EVSE/rootfs/root/Module_Payment


BIN
EVSE/rootfs/root/OcppBackend20


+ 2 - 2
EVSE/rootfs/var/www/set_charging.php

@@ -11,7 +11,7 @@
 	$Connector1=substr($ModelName,7,1);
 	$Connector2=substr($ModelName,9,1);
 	$Connector3=substr($ModelName,8,1);
-	if(substr($ModelName,0,2)!="DO"){
+	if(substr($ModelName,0,2)!="DO" && substr($ModelName,0,2)!="DK"){
 		$connectorType1=ConnectorType($Connector1);
 		$connectorType2=ConnectorType($Connector2);
 		$connectorType3=ConnectorType($Connector3);
@@ -806,7 +806,7 @@ img {
 										</div>*/?>
 									</section>
 								</article>
-<?php if(substr($ModelName,0,2)=="DO"){?>
+<?php if(substr($ModelName,0,2)=="DO" || substr($ModelName,0,2)=="DK"){?>
 <?php if($obj['DDChargingInfo1']){ $idx++;?>
 								<!--Charging Information-->
 								<article class="envor-sorting-item css">

+ 11 - 11
EVSE/rootfs/var/www/set_system.php

@@ -135,7 +135,7 @@ img {
 												<option value="1" <?php echo $obj->{'FactoryConfiguration'}=="1"?"selected":""?>>Trigger</option>
 											</select>*/?>
 										</div>
-<?php if(substr($ModelName,0,2)!="DO"){?>
+<?php //if(substr($ModelName,0,2)!="DO"){?>
 										<div class="form-group" style="display:<?php echo $am111;?>">
 											<label>Authentication</label>
 											<select class="form-control" id="AuthorisationMode" name="AuthorisationMode" onchange="AuthorisationMode_changed()">
@@ -143,7 +143,7 @@ img {
 												<option value="1" <?php echo $obj->{'AuthorisationMode'}=="1"?"selected":""?>>disable</option>
 											</select>
 										</div>
-<?php } ?>
+<?php //} ?>
 										<div class="form-group" style="display:<?php echo $am111;?>">
 											<label>Input Voltage R</label>
 											<input type="text" readonly class="form-control" placeholder="<?php echo round($obj->{'InputVoltageR'},2);?> volt">
@@ -164,7 +164,7 @@ img {
 											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'SystemFanRotaSpeed'};?> RPM">
 											<input type="hidden" name="SystemFanRotaSpeed" id="SystemFanRotaSpeed" value="<?php echo $obj->{'SystemFanRotaSpeed'};?>">
 										</div>
-<?php if(substr($ModelName,0,2)!="DO"){?>
+<?php //if(substr($ModelName,0,2)!="DO"){?>
 										<div class="form-group" style="display:<?php echo $am111;?>">
 											<label>Rfid Card Num Endian</label>
 											<select class="form-control" id="RfidCardNumEndian" name="RfidCardNumEndian">
@@ -221,8 +221,8 @@ img {
 												<option value="2" <?php echo $obj->{'Intensity'}=="2"?"selected":""?>>Brightest</option>
 											</select>
 										</div>
-<?php } ?>
-<?php if(substr($ModelName,0,2)=="DO"){?>
+<?php //} ?>
+<?php if(substr($ModelName,0,2)=="DO" || substr($ModelName,0,2)=="DK"){?>
 										<div class="form-group">
 											<label>Dispenser Quantity</label>
 											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'DispenserQuantity'};?>">
@@ -281,7 +281,7 @@ img {
 											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'RelayModuleFwRev'};?>">
 											<input type="hidden" name="RelayModuleFwRev" id="RelayModuleFwRev" value="<?php echo $obj->{'RelayModuleFwRev'};?>">
 										</div>
-<?php if(substr($ModelName,0,2)=="DO"){?>
+<?php if(substr($ModelName,0,2)=="DO" || substr($ModelName,0,2)=="DK"){?>
 										<div class="form-group" style="display:<?php echo $am001;?>">
 											<label>Relay2 Module Fw Rev</label>
 											<input type="text" readonly class="form-control" placeholder="<?php echo $obj->{'Relay2ModuleFwRev'};?>">
@@ -310,7 +310,7 @@ img {
 										</div>
 									</section>
 								</article>
-<?php if(substr($ModelName,0,2)=="DO"){?>
+<?php if(substr($ModelName,0,2)=="DO" || substr($ModelName,0,2)=="DK"){?>
 <?php for($idx=0;$idx<$obj->{'DispenserQuantity'};$idx++){ $idx2=$idx+1;?>
 								<article class="envor-sorting-item css">
 									<header><?php echo $lang->showWord("system_information"); ?> Dispenser <?php echo $idx2;?><i class="fa fa-plus"></i></header>
@@ -464,7 +464,7 @@ img {
 		else{
 			document.getElementById("AcModelNameDiv").style.display="none";
 		}
-<?php if(substr($ModelName,0,2)=="DO"){?>
+<?php if(substr($ModelName,0,2)=="DO" || substr($ModelName,0,2)=="DK"){?>
 <?php for($idx=0;$idx<$obj->{'DispenserQuantity'};$idx++){ $idx2=$idx+1;?>
 		DDisQRCode_clicked(<?php echo $idx2; ?>);
 		DDAuthorisationMode_changed(<?php echo $idx2; ?>);
@@ -495,7 +495,7 @@ img {
 			var data =  "SystemId=" + document.getElementById("SystemId").value+
 						"&SystemDateTime=" + document.getElementById("SystemDateTime").value+
 						"&FactoryConfiguration=" + (document.getElementById("FactoryConfiguration").checked?1:0);
-<?php if(substr($ModelName,0,2)!="DO"){?>
+<?php //if(substr($ModelName,0,2)!="DO"){?>
 				data +=  "&PhaseLossPolicy=" + document.getElementById("PhaseLossPolicy").value+
 						"&AuthorisationMode=" + document.getElementById("AuthorisationMode").value+
 						"&isAPP=" + (document.getElementById("isAPP").checked?1:0)+
@@ -506,8 +506,8 @@ img {
 						"&Intensity=" + document.getElementById("Intensity").value+
 						"&RfidCardNumEndian=" + document.getElementById("RfidCardNumEndian").value+
 						"&PsuAcInputType=" + document.getElementById("PsuAcInputType").value;
-<?php } ?>
-<?php if(substr($ModelName,0,2)=="DO"){?>
+<?php //} ?>
+<?php if(substr($ModelName,0,2)=="DO" || substr($ModelName,0,2)=="DK"){?>
 <?php for($idx=0;$idx<$obj->{'DispenserQuantity'};$idx++){ $idx2=$idx+1;?>
 				data +=  "&DDSystemId<?php echo $idx2; ?>=" + document.getElementById("DDSystemId<?php echo $idx2; ?>").value+
 						"&DDFactoryConfiguration<?php echo $idx2; ?>=" + (document.getElementById("DDFactoryConfiguration<?php echo $idx2; ?>").checked?1:0)+

Some files were not shown because too many files changed in this diff