Kaynağa Gözat

2020-06-20 / Alston Lin

Actions
1. Fix the psu task will shutdown bug for v906 of infy-power
2. System support led bar control function
3. System support three connectors (DC + AC) charging function
4. Add for OCTT test information
5. System support to update CCS function
6. Fix some syste bug

Files
1. As follow commit history
Alston 4 yıl önce
ebeveyn
işleme
824df06939
30 değiştirilmiş dosya ile 2543 ekleme ve 578 silme
  1. 14 6
      EVSE/Projects/DS60-120/Apps/Config.h
  2. 1 1
      EVSE/Projects/DS60-120/Apps/Ev_Comm.c
  3. BIN
      EVSE/Projects/DS60-120/Apps/FactoryConfig
  4. 15 10
      EVSE/Projects/DS60-120/Apps/FactoryConfig.c
  5. 15 4
      EVSE/Projects/DS60-120/Apps/Makefile
  6. BIN
      EVSE/Projects/DS60-120/Apps/Module_EvComm
  7. 148 57
      EVSE/Projects/DS60-120/Apps/Module_EvComm.c
  8. BIN
      EVSE/Projects/DS60-120/Apps/Module_EventLogging
  9. 23 20
      EVSE/Projects/DS60-120/Apps/Module_EventLogging.c
  10. BIN
      EVSE/Projects/DS60-120/Apps/Module_InternalComm
  11. 440 91
      EVSE/Projects/DS60-120/Apps/Module_InternalComm.c
  12. 8 3
      EVSE/Projects/DS60-120/Apps/Module_LcmContro.h
  13. BIN
      EVSE/Projects/DS60-120/Apps/Module_LcmControl
  14. 93 35
      EVSE/Projects/DS60-120/Apps/Module_LcmControl.c
  15. BIN
      EVSE/Projects/DS60-120/Apps/Module_PrimaryComm
  16. 19 11
      EVSE/Projects/DS60-120/Apps/Module_PrimaryComm.c
  17. BIN
      EVSE/Projects/DS60-120/Apps/Module_PsuComm
  18. 467 167
      EVSE/Projects/DS60-120/Apps/Module_PsuComm.c
  19. 2 0
      EVSE/Projects/DS60-120/Apps/Module_PsuComm.h
  20. 363 0
      EVSE/Projects/DS60-120/Apps/OutputTask.c
  21. 174 0
      EVSE/Projects/DS60-120/Apps/OutputTask.h
  22. BIN
      EVSE/Projects/DS60-120/Apps/ReadCmdline
  23. 151 32
      EVSE/Projects/DS60-120/Apps/ReadCmdline.c
  24. 137 24
      EVSE/Projects/DS60-120/Apps/internalComm.c
  25. 16 0
      EVSE/Projects/DS60-120/Apps/internalComm.h
  26. 1 0
      EVSE/Projects/DS60-120/Apps/kill.sh
  27. BIN
      EVSE/Projects/DS60-120/Apps/main
  28. 445 116
      EVSE/Projects/DS60-120/Apps/main.c
  29. 1 0
      EVSE/Projects/DS60-120/Apps/timeout.c
  30. 10 1
      EVSE/Projects/DS60-120/Apps/timeout.h

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

@@ -130,12 +130,14 @@ enum _SELF_TEST_SEQ
 
 enum _MODULE_PSU_WORK_STEP
 {
-	INITIAL_START 		= 			0,
-	GET_PSU_COUNT 		= 			1,
-	GET_SYS_CAP			=			2,
-	BOOTING_COMPLETE 	= 			3,
+	INITIAL_START 		= 		0,
+	GET_PSU_COUNT 		= 		1,
+	GET_SYS_CAP			=		2,
+	BOOTING_COMPLETE 	= 		3,
 
-	_WORK_CHARGING 	= 			10,
+	_WORK_CHARGING 		= 		10,
+
+	_TEST_MODE			=		20,
 
 	_NO_WORKING			= 		254,
 	_INIT_PSU_STATUS	= 		255
@@ -156,7 +158,6 @@ enum _REASSIGNED_RESOURCE_STEP
 	_REASSIGNED_GET_NEW_CAP = 		2,	// 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
 	_REASSIGNED_ADJUST_M_TO_A = 	3,	// 模塊重新分配完成
 	_REASSIGNED_RELAY_M_TO_A =		4,	// 切斷橋接的 Relay
-	_REASSIGNED_CHECK = 			5,
 
 	_REASSIGNED_PREPARE_A_TO_M = 	11,
 	_REASSIGNED_ADJUST_A_TO_M = 	12, // 模塊升壓
@@ -184,4 +185,11 @@ enum _CHARGER_TYPE
 	_CHARGER_TYPE_UL = 1,
 };
 
+enum _SYS_WIFI_MODE
+{
+	_SYS_WIFI_MODE_DISABLE = 0,
+	_SYS_WIFI_MODE_STATION = 1,
+	_SYS_WIFI_MODE_AP = 2
+};
+
 #endif /* CONFIG_H_ */

+ 1 - 1
EVSE/Projects/DS60-120/Apps/Ev_Comm.c

@@ -89,7 +89,7 @@ void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputP
 	data[4] = (aOutputCur >> 8) & 0xff;
 	data[5] = aOutputVol & 0xff;
 	data[6] = (aOutputVol >> 8) & 0xff;
-	data[7] = 0xff;
+	data[7] = 0xf0;
 
 	SendCmdToEvboard(id, data, sizeof(data));
 }

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


+ 15 - 10
EVSE/Projects/DS60-120/Apps/FactoryConfig.c

@@ -46,19 +46,21 @@ int StoreLogMsg(const char *fmt, ...)
 {
 	char Buf[4096+256];
 	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
 	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
 
 	va_start(args, fmt);
 	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 
 	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);
 	system(Buf);
@@ -103,8 +105,8 @@ int main(int argc,char *argv[])
 	*/
 	//********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
 	//
-	strcpy((char *)SysConfig.ModelName, "DSYE601J0EW2PH");
-	strcpy((char *)SysConfig.SerialNumber, "");
+	strcpy((char *)SysConfig.ModelName, "DSYE601J0EE2PH");
+	strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
 
 	memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
 	char Dash = '-';
@@ -146,7 +148,10 @@ int main(int argc,char *argv[])
 	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
 	strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
 	strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
-	SysConfig.AthInterface.WifiMode = 0;
+	if(SysConfig.ModelName[10] == 'W')
+		SysConfig.AthInterface.WifiMode = 2;
+	else
+		SysConfig.AthInterface.WifiMode = 0;
 	strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
 	strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
 	SysConfig.AthInterface.WifiRssi = 0;
@@ -174,7 +179,7 @@ int main(int argc,char *argv[])
 	strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
 	//********** Backend **********//
 	SysConfig.BackendConnTimeout = 300; //300 seconds
-	SysConfig.OfflinePolicy = 0;
+	SysConfig.OfflinePolicy = 2;
 	SysConfig.OfflineMaxChargeEnergy = 0;
 	SysConfig.OfflineMaxChargeDuration = 0;
 	strcpy((char *) SysConfig.OcppServerURL, "");

+ 15 - 4
EVSE/Projects/DS60-120/Apps/Makefile

@@ -5,17 +5,22 @@ export PATH=/bin:/sbin:/usr/bin:$(SDK_PATH_TARGET)/usr/bin:$PATH
 Internal485ProtocolLib = -L ../../../Modularization/Internal485Protocol -lInternal485Protocol
 #PsuCommProtocolLib = -L ../../../Modularization/PsuCommProtocol -lPsuCommProtocol
 
+#define library variable
+Lib_Module_RFID = "-L../../../Modularization" -lModule_RFID
+Lib_Module_Upgrade = "-L../../../Modularization" -lModule_Upgrade
+Lib_SQLite3 = "-L../../../Modularization/ocppfiles" -lsqlite3
+
 all: CopyFile apps
 #apps: Module_CSU Module_EvComm Module_EventLogging Module_InternalComm Module_LcmControl Module_PrimaryComm Module_PsuComm 
 # ReadCmdline kill.sh
-apps: MainTask EvCommTask EventLoggingTask InternalCommTask LcmControlTask PrimaryCommTask PsuCommTask ReadCmdlineTask FactoryConfigApp OtherTools
+apps: MainTask EvCommTask EventLoggingTask InternalCommTask LcmControlTask PrimaryCommTask PsuCommTask ReadCmdlineTask UnsafetyOutputTool FactoryConfigApp OtherTools
 
 MainTask:
 	rm -f *.o
 	rm -f main;
-	$(CC) -D $(Project) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o main.o main.c
-	$(CC) -D $(Project) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o timeout.o timeout.c
-	$(CC) -o main main.o timeout.o ../../../Modularization/libModule_RFID.a ../../../Modularization/libModule_Upgrade.a	
+	$(CC) -D $(Project) -include../../../Modularization/ocppfiles/sqlite3.h -include../../../Modularization/Module_Upgrade.h -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o main.o main.c
+	$(CC) -D $(Project) -include../../../Modularization/ocppfiles/sqlite3.h -include../../../Modularization/Module_Upgrade.h -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o timeout.o timeout.c
+	$(CC) -o main main.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3}	
 	cp -f main ../Images/root
 
 EvCommTask:
@@ -63,6 +68,12 @@ ReadCmdlineTask:
 	$(CC) -o ReadCmdline ReadCmdline.o
 	cp -f ReadCmdline ../Images/root
 
+UnsafetyOutputTool:
+	rm -f UnsafetyOutputTask; 
+	$(CC) -D $(Project) -include../../../Modularization/Infypwr_PsuCommObj.h -O0 -g3 -Wall -c -fmessage-length=0 -o OutputTask.o OutputTask.c
+	$(CC) -o UnsafetyOutputTask OutputTask.o ../../../Modularization/libInfypwr_PsuCommObj.a
+	cp -f UnsafetyOutputTask ../Images/root	
+
 FactoryConfigApp:
 	@echo "===== Module_FactoryConfig_Task =================================="
 	rm -f FactoryConfig

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


+ 148 - 57
EVSE/Projects/DS60-120/Apps/Module_EvComm.c

@@ -49,17 +49,25 @@ struct CcsData					*ShmCcsData;
 
 byte gun_count;
 int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 float _pow_1 = 0;
 float _cur_1 = 0;
 float _pow_2 = 0;
 float _cur_2 = 0;
 
+float _outVol_1 = 0;
+float _outCur_1 = 0;
+float _outVol_2 = 0;
+float _outCur_2 = 0;
+
 // 限制最大充電電壓,因應不同 type 槍線來限制
-// Chademo : 500V, GB : 750, CCS : 950V
+// Chademo : 500V, 125A,
+// GB : 750, 120A
+// CCS : 950V, 120A
 float maxChargingVol[2] = { 5000, 9500 };			// 限制最大充電電壓,如依照模塊則填上 0
 // 限制最大充電電流與能量透過 Web
-float maxChargingCur[2] = { 1250, 2000 };			// 限制最大充電電流,如依照模塊則填上 0
+float maxChargingCur[2] = { 1200, 1200 };			// 限制最大充電電流,如依照模塊則填上 0
 float maxChargingPow = 0;							// 限制最大充電能量,如依照模塊則填上 0
 
 // 槍資訊
@@ -112,22 +120,33 @@ int StoreLogMsg(const char *fmt, ...)
 {
 	char Buf[4096+256];
 	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
 	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
 
 	va_start(args, fmt);
 	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 
 	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
+		system(Buf);
+	}
 
 	return rc;
 }
@@ -150,10 +169,7 @@ void PRINTF_FUNC(char *string, ...)
 	vsnprintf(buffer, sizeof(buffer), string, args);
 	va_end(args);
 
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-		printf("%s \n", buffer);
-	else
-		DEBUG_INFO("%s \n", buffer);
+	DEBUG_INFO("%s \n", buffer);
 }
 
 //=================================
@@ -658,9 +674,7 @@ void ClearAbnormalStatus_Chademo(byte gun_index)
 	{
 		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
 		{
-			if (index == gun_index)
-				continue;
-			else
+			if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
 			{
 				PRINTF_FUNC("CHA clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
 				if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL)
@@ -1152,9 +1166,7 @@ void ClearAbnormalStatus_GB(byte gun_index)
 	{
 		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
 		{
-			if (index == gun_index)
-				continue;
-			else
+			if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
 			{
 				PRINTF_FUNC("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
 				if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL)
@@ -1928,6 +1940,13 @@ void ClearAbnormalStatus_CCS(byte gun_index)
 		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
 		isCleanCheck = true;
 	}
+	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023850", 6) == EQUAL &&
+			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime == YES)
+	{
+		memcpy(code, "023850", 6);
+		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+		isCleanCheck = true;
+	}
 	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023855", 6) == EQUAL &&
 			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO == YES)
 	{
@@ -2180,14 +2199,26 @@ void ClearAbnormalStatus_CCS(byte gun_index)
 		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
 		isCleanCheck = true;
 	}
+	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023891", 6) == EQUAL &&
+			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging == YES)
+	{
+		memcpy(code, "023891", 6);
+		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+		isCleanCheck = true;
+	}
+	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023892", 6) == EQUAL &&
+			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
+	{
+		memcpy(code, "023892", 6);
+		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+		isCleanCheck = true;
+	}
 
 	if (isCleanCheck)
 	{
 		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
 		{
-			if (index == gun_index)
-				continue;
-			else
+			if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
 			{
 				PRINTF_FUNC("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
 				if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL)
@@ -2291,6 +2322,7 @@ void ClearAbnormalStatus_CCS(byte gun_index)
 					if (strncmp(code, "023847", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = NO;
 					if (strncmp(code, "023848", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = NO;
 					if (strncmp(code, "023849", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = NO;
+					if (strncmp(code, "023850", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = NO;
 					if (strncmp(code, "023855", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = NO;
 					if (strncmp(code, "023856", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = NO;
 					if (strncmp(code, "023857", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = NO;
@@ -2327,6 +2359,8 @@ void ClearAbnormalStatus_CCS(byte gun_index)
 					if (strncmp(code, "023888", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = NO;
 					if (strncmp(code, "023889", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = NO;
 					if (strncmp(code, "023890", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = NO;
+					if (strncmp(code, "023891", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = NO;
+					if (strncmp(code, "023892", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = NO;
 				}
 			}
 		}
@@ -2480,6 +2514,7 @@ void AbnormalStopAnalysis(byte gun_index, byte *errCode)
 	if (strcmp(string, "023847") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = YES;
 	if (strcmp(string, "023848") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = YES;
 	if (strcmp(string, "023849") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = YES;
+	if (strcmp(string, "023850") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = YES;
 	if (strcmp(string, "023855") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = YES;
 	if (strcmp(string, "023856") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = YES;
 	if (strcmp(string, "023857") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = YES;
@@ -2516,6 +2551,8 @@ void AbnormalStopAnalysis(byte gun_index, byte *errCode)
 	if (strcmp(string, "023888") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = YES;
 	if (strcmp(string, "023889") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = YES;
 	if (strcmp(string, "023890") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = YES;
+	if (strcmp(string, "023891") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = YES;
+	if (strcmp(string, "023892") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = YES;
 
 	if (strcmp(string, "023702") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = YES;
 	if (strcmp(string, "023900") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = YES;
@@ -2612,6 +2649,8 @@ void CANReceiver()
 					break;
 				}
 			}
+
+			sleep(1);
 		}
 
 		for (byte _index = 0; _index < gun_count; _index++)
@@ -2681,15 +2720,20 @@ void CANReceiver()
 						break;
 					case ACK_EV_FW_VERSION:
 					{
+						byte ver[16];
+
+						memset(ver, 0, sizeof(ver));
 						if (_chargingData[targetGun]->Type == _Type_Chademo)
 						{
-							memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, frame.data, frame.can_dlc);
+							memcpy(ver, frame.data, frame.can_dlc);
+							memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
 							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
 							PRINTF_FUNC("chademo ver. : %s\n", ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version);
 						}
 						else if (_chargingData[targetGun]->Type == _Type_GB)
 						{
-							memcpy(ShmGBTData->evse[_chargingData[targetGun]->type_index].version, frame.data, ARRAY_SIZE(frame.data));
+							memcpy(ver, frame.data, frame.can_dlc);
+							memcpy(ShmGBTData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
 							ShmGBTData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
 							PRINTF_FUNC("gbt ver. : %s\n", ShmGBTData->evse[_chargingData[targetGun]->type_index].version);
 						}
@@ -2697,7 +2741,18 @@ void CANReceiver()
 						{
 							if (ShmCcsData->CommProtocol == 0x01)
 							{
-								memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, frame.data, frame.can_dlc);
+								for (byte _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++)
+								{
+									if (_vCount % 2 == 0 && _vCount != 0)
+									{
+										ver[_vCount + _vPoint] = 0x2E;
+										_vPoint++;
+									}
+
+									ver[_vCount + _vPoint] = frame.data[_vCount];
+								}
+
+								memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
 								ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
 								PRINTF_FUNC("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version);
 							}
@@ -2706,12 +2761,12 @@ void CANReceiver()
 						if (targetGun == 0)
 						{
 							memset(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
-							memcpy(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, frame.data, frame.can_dlc);
+							memcpy(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, ver, ARRAY_SIZE(ver));
 						}
 						else
 						{
 							memset(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
-							memcpy(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, frame.data, frame.can_dlc);
+							memcpy(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, ver, ARRAY_SIZE(ver));
 						}
 					}
 						break;
@@ -2723,33 +2778,33 @@ void CANReceiver()
 					case ACK_GET_OUTPUT_REQ:
 					{
 						_chargingData[targetGun]->EvBatterySoc = frame.data[1];
-						_chargingData[targetGun]->EvBatterytargetVoltage = ((short) frame.data[3] << 8) + (short) frame.data[2];
-						_chargingData[targetGun]->EvBatterytargetCurrent = ((short) frame.data[5] << 8) + (short) frame.data[4];
-						_chargingData[targetGun]->PresentChargedDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
+						_chargingData[targetGun]->EvBatterytargetVoltage = (((short) frame.data[3] << 8) + (short) frame.data[2]) / 10;
+						_chargingData[targetGun]->EvBatterytargetCurrent = (((short) frame.data[5] << 8) + (short) frame.data[4]) / 10;
+						_chargingData[targetGun]->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
 
 						if (_chargingData[targetGun]->Type == _Type_Chademo)
 						{
-							if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
+							//if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
 							{
 								ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
 							}
 
 							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
 							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = _chargingData[targetGun]->EvBatterytargetVoltage;
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = _chargingData[targetGun]->EvBatterytargetCurrent;
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
 						}
 						else if (_chargingData[targetGun]->Type == _Type_GB)
 						{
-							if (ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
+							//if (ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
 							{
 								ShmGBTData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
 							}
 
 							ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
 							ShmGBTData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
-							ShmGBTData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = _chargingData[targetGun]->EvBatterytargetVoltage;
-							ShmGBTData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = _chargingData[targetGun]->EvBatterytargetCurrent;
+							ShmGBTData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
+							ShmGBTData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
 						}
 						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
 						{
@@ -2769,7 +2824,7 @@ void CANReceiver()
 					{
 						//_chargingData[target].EvACorDCcharging = frame.data[0];
 						//_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
-						_chargingData[targetGun]->EvBatteryMaxVoltage = ((short) frame.data[4] << 8) + (short) frame.data[3];
+						_chargingData[targetGun]->EvBatteryMaxVoltage = (((short) frame.data[4] << 8) + (short) frame.data[3]) / 10;
 						//_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
 						//_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
 						if (_chargingData[targetGun]->Type == _Type_Chademo)
@@ -2875,17 +2930,23 @@ void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, stru
 	float vol1 = 0, cur1 = 0;
 	float vol2 = 0, cur2 = 0;
 
-	//PRINTF_FUNC("f vol - 0 = %f \n", chargingData_1->FireChargingVoltage);
-	//PRINTF_FUNC("index = 0, out cur = %f \n", chargingData_1->PresentChargingCurrent);
-	//PRINTF_FUNC("***********************f vol - 1 = %f \n", chargingData_2->FireChargingVoltage);
-	//PRINTF_FUNC("index = 1, out cur = %f \n", chargingData_2->PresentChargingCurrent);
-
 	vol1 = chargingData_1->FireChargingVoltage;
 	cur1 = (chargingData_1->PresentChargingCurrent * 10);
 
 	vol2 = chargingData_2->FireChargingVoltage;
 	cur2 = (chargingData_2->PresentChargingCurrent * 10);
 
+	if (_outVol_1 != vol1 ||
+		_outCur_1 != cur1 ||
+		_outVol_2 != vol2 ||
+		_outCur_2 != cur2)
+	{
+		PRINTF_FUNC("G1 -> Output Vol = %f, Output Cur = %f -- G2 -> Output Vol = %f, Output Cur = %f \n",
+			vol1, cur1, vol2, cur2);
+
+		_outVol_1 = vol1; _outCur_1 = cur1; _outVol_2 = vol2; _outCur_2 = cur2;
+	}
+
 	SetPresentOutputPower(vol1, cur1, vol2, cur2);
 }
 
@@ -2945,6 +3006,7 @@ void Initialization()
 				break;
 			}
 		}
+		sleep(1);
 	}
 }
 
@@ -3166,13 +3228,6 @@ int main(int argc, char *argv[])
 			{
 				case S_IDLE:
 				case S_RESERVATION:
-					_chargingData[_index]->PresentChargedEnergy = 0;
-					_chargingData[_index]->PresentChargingPower = 0;
-					_chargingData[_index]->GroundFaultStatus = GFD_WAIT;
-					_chargingData[_index]->StopChargeFlag = NO;
-					_chargingData[_index]->ChargingFee = 0.0;
-					chargingTime[_index] = 0;
-
 					if (_chargingData[_index]->Type == _Type_Chademo)
 					{
 						ClearAbnormalStatus_Chademo(_index);
@@ -3188,6 +3243,19 @@ int main(int argc, char *argv[])
 
 					if (priorityLow == 1)
 					{
+						_chargingData[_index]->PresentChargedEnergy = 0;
+						_chargingData[_index]->PresentChargingPower = 0;
+						_chargingData[_index]->GroundFaultStatus = GFD_WAIT;
+						_chargingData[_index]->RealRatingPower = 0;
+						_chargingData[_index]->StopChargeFlag = NO;
+						_chargingData[_index]->ChargingFee = 0.0;
+						_chargingData[_index]->EvBatterySoc = 0;
+						_chargingData[_index]->PresentChargingVoltage = 0;
+						_chargingData[_index]->PresentChargingCurrent = 0;
+						_chargingData[_index]->EvBatteryMaxVoltage = 0;
+
+						chargingTime[_index] = 0;
+
 						//maxChargingCur[_index] = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
 						maxChargingPow = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
 					}
@@ -3240,6 +3308,7 @@ int main(int argc, char *argv[])
 						// 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
 						GetEvBatteryInfo(_index, _chargingData[_index]->Evboard_id);
 					}
+					//gettimeofday(&_chk_ratingPower_timeout[_index], NULL);
 				}
 					break;
 				case S_PREPARING_FOR_EVSE:
@@ -3272,12 +3341,34 @@ int main(int argc, char *argv[])
 //							_chargingData[_index]->GroundFaultStatus = GFD_PASS;
 
 						//PRINTF_FUNC("To EV_%d GFD = %d \n",	_index, _chargingData[_index]->GroundFaultStatus);
-						if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
+						//if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
 						{
-							unsigned char _result = _chargingData[_index]->GroundFaultStatus;
+							//if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
+							unsigned char _result = GFD_WAIT;
+
+							_result = _chargingData[_index]->GroundFaultStatus;
+
+							// GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
+							if(_chargingData[_index]->Type == _Type_Chademo ||
+								_chargingData[_index]->Type == _Type_GB)
+							{
+								if (_result == GFD_WARNING)
+								{
+									_result = GFD_PASS;
+								}
+							}
 
-							if (_result == GFD_WARNING)
-								_result = GFD_PASS;
+//							if (_result == GFD_WARNING || _result == GFD_PASS)
+//							{
+//								if ((GetTimeoutValue(_chk_ratingPower_timeout[_index]) / 1000) > 10000)
+//								{
+//									if (_chargingData[_index]->RealRatingPower == 0)
+//										_chargingData[_index]->RealRatingPower = _chargingData[_index]->AvailableChargingPower;
+//									_result = GFD_PASS;
+//								}
+//								else
+//									_result = GFD_WAIT;
+//							}
 
 							SetIsolationStatus(_index, _result, _chargingData[_index]->Evboard_id);
 						}
@@ -3296,13 +3387,13 @@ int main(int argc, char *argv[])
 					_chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
 
 					if (chargingTime[_index] == 0 ||
-							chargingTime[_index] < _chargingData[_index]->RemainChargingDuration)
+							chargingTime[_index] > _chargingData[_index]->PresentChargedDuration)
 					{
-						chargingTime[_index] = _chargingData[_index]->RemainChargingDuration;
+						chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
 					}
 					else
 					{
-						int passTime = _chargingData[_index]->RemainChargingDuration - chargingTime[_index];
+						int passTime = _chargingData[_index]->PresentChargedDuration - chargingTime[_index];
 
 						if (passTime > 0)
 						{
@@ -3313,7 +3404,7 @@ int main(int argc, char *argv[])
 							}
 
 							_chargingData[_index]->PresentChargedEnergy += changingPow;
-							chargingTime[_index] = _chargingData[_index]->RemainChargingDuration;
+							chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
 						}
 					}
 

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


+ 23 - 20
EVSE/Projects/DS60-120/Apps/Module_EventLogging.c

@@ -48,22 +48,33 @@ int StoreLogMsg(const char *fmt, ...)
 {
 	char Buf[4096+256];
 	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
 	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
 
 	va_start(args, fmt);
 	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 
 	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
+		system(Buf);
+	}
 
 	return rc;
 }
@@ -86,10 +97,7 @@ void PRINTF_FUNC(char *string, ...)
 	vsnprintf(buffer, sizeof(buffer), string, args);
 	va_end(args);
 
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-		printf("%s \n", buffer);
-	else
-		DEBUG_INFO("%s \n", buffer);
+	DEBUG_INFO("%s \n", buffer);
 }
 
 //=================================
@@ -188,20 +196,15 @@ void RemoveFaultCodeToBuf(unsigned char *Code)
 			}
 			else
 			{
-				if(i == ShmSysConfigAndInfo->SysWarningInfo.WarningCount - 1)
-				{
-					memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "", 7);
-				}
-				else
-				{
-					memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
-							&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + 1][0], 7);
-				}
+				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
+					&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
 			}
 		}
 
 		if (find)
+		{
 			ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+		}
 	}
 }
 

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


+ 440 - 91
EVSE/Projects/DS60-120/Apps/Module_InternalComm.c

@@ -40,19 +40,26 @@
 #define ENV_TEMP_MIN		45
 #define ENV_TEMP_MAX		50
 #define DEFAULT_AC_INDEX	2
+#define EQUAL				0
+#define COLOR_MAX_LV		100
+#define COLOR_MIN_LV		0
+
+#define AC_DEFAULT_VOL		220
+
+#define	NO_DEFINE			255
+#define	NDEFAULT_AC_INDEX	2
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
 struct FanModuleData			*ShmFanModuleData;
 struct RelayModuleData			*ShmRelayModuleData;
-struct CHAdeMOData				*ShmCHAdeMOData;
-struct CcsData					*ShmCcsData;
+struct LedModuleData			*ShmLedModuleData;
 struct PsuData 					*ShmPsuData;
 
-#define VIN_MAX_VOLTAGE_IEC		296	// 大於該值 : OVP
-#define VIN_MIN_VOLTAGE_IEC		166	// 小於該值 : UVP
-#define VIN_MAX_VOLTAGE_UL		305	// 大於該值 : OVP
-#define VIN_MIN_VOLTAGE_UL		215	// 小於該值 : UVP
+#define VIN_MAX_VOLTAGE_IEC		285	// 大於該值 : OVP
+#define VIN_MIN_VOLTAGE_IEC		160	// 小於該值 : UVP
+#define VIN_MAX_VOLTAGE_UL		315	// 大於該值 : OVP
+#define VIN_MIN_VOLTAGE_UL		210	// 小於該值 : UVP
 
 #define VIN_DROP_VOLTAGE	150	// 小於該值 : ac drop
 
@@ -102,6 +109,7 @@ bool isStopChargingCount = false;
 struct timeval _close_ac_contactor;
 
 struct timeval _priority_time;
+struct timeval _led_priority_time;
 
 struct timeval	_ac_charging_comp;
 struct timeval	_ac_preparing;
@@ -109,6 +117,11 @@ struct timeb 	_ac_startChargingTime;
 struct timeb 	_ac_endChargingTime;
 
 unsigned short _setFanSpeed = 0;
+float _beforeChargingTotalEnergy = 0.0;
+byte _checkLedChanged = 3;
+double _psuInputVolR = 0;
+double _psuInputVolS = 0;
+double _psuInputVolT = 0;
 
 Ver ver;
 PresentInputVoltage inputVoltage;
@@ -123,6 +136,8 @@ Gpio_out gpio_out;
 Relay outputRelay;
 Relay regRelay;
 Rtc rtc;
+Led_Color cur_led_color;
+Led_Color led_color;
 
 Ac_Status acStatus;
 Ac_Led_Status ledStatus;
@@ -176,22 +191,33 @@ int StoreLogMsg(const char *fmt, ...)
 {
 	char Buf[4096+256];
 	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
 	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
 
 	va_start(args, fmt);
 	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 
 	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
+		system(Buf);
+	}
 
 	return rc;
 }
@@ -220,10 +246,7 @@ void PRINTF_FUNC(char *string, ...)
 	vsnprintf(buffer, sizeof(buffer), string, args);
 	va_end(args);
 
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-		printf("%s \n", buffer);
-	else
-		DEBUG_INFO("%s \n", buffer);
+	DEBUG_INFO("%s \n", buffer);
 }
 
 //==========================================
@@ -252,7 +275,7 @@ void GetFwAndHwVersion_Relay()
 {
 	if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
 	{
-		// FanModuleData
+		// RelayModuleData
 		strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
 		// SystemInfo
 		strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ver.Version_FW);
@@ -267,6 +290,30 @@ void GetFwAndHwVersion_Relay()
 	}
 }
 
+void GetFwAndHwVersion_Led()
+{
+	if (Query_FW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
+	{
+		// LedModuleData
+		strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, ver.Version_FW);
+		PRINTF_FUNC("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
+		ShmLedModuleData->SelfTest_Comp = YES;
+	}
+	else
+	{
+		//PRINTF_FUNC("GetFwAndHwVersion_Led fail \n");
+	}
+
+//	if (Query_HW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
+//	{
+//		// SystemInfo
+//		strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
+//		//PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
+//	}
+}
+
 void GetFwVersion_AC()
 {
 	if (Query_FW_Ver(Uart5Fd, Addr.AcPlug, &ver) == PASS)
@@ -276,6 +323,15 @@ void GetFwVersion_AC()
 	}
 }
 
+void GetAcModelName()
+{
+	memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
+	if (Query_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS)
+	{
+		PRINTF_FUNC("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
+	}
+}
+
 void SetRtcData_Relay()
 {
 	struct timeb csuTime;
@@ -373,34 +429,52 @@ void GetPresentInputVol()
 		if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
 		{
 			if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC)
+			{
+				PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
 
 			if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC)
+			{
+				PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
 
 			if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC)
+			{
+				PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
 		}
 		else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
 		{
 			if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL)
+			{
+				PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
 
 			if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL)
+			{
+				PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
 
 			if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL)
+			{
+				PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
 		}
@@ -409,34 +483,52 @@ void GetPresentInputVol()
 		if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
 		{
 			if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC)
+			{
+				PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
 
 			if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC)
+			{
+				PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
 
 			if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC)
+			{
+				PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
 		}
 		else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
 		{
 			if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL)
+			{
+				PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
 
 			if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL)
+			{
+				PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
 
 			if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL)
+			{
+				PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
+			}
 			else
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
 		}
@@ -617,6 +709,8 @@ void GetGfdAdc()
 			if (i == 0)
 			{
 				_chargingData[i]->GroundFaultStatus = gfd_adc.result_conn1;
+//				PRINTF_FUNC("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
+//						_chargingData[i]->GroundFaultStatus, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
 				if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
 				{
 					PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
@@ -625,8 +719,11 @@ void GetGfdAdc()
 				else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
 						_chargingData[i]->GroundFaultStatus == GFD_WARNING)
 				{
-//					PRINTF_FUNC("GFD Result. index = %d, Result = %d, R = %d, Vol = %d \n",
-//						i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
+					if (_chargingData[i]->GroundFaultStatus == GFD_WARNING)
+					{
+						PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
+								i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
+					}
 				}
 			}
 			else if (i == 1)
@@ -640,8 +737,11 @@ void GetGfdAdc()
 				else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
 						_chargingData[i]->GroundFaultStatus == GFD_WARNING)
 				{
-//					PRINTF_FUNC("GFD Result. index = %d, Result = %d, R = %d, Vol = %d \n",
-//						i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn2, gfd_adc.voltage_conn2);
+					if (_chargingData[i]->GroundFaultStatus == GFD_WARNING)
+					{
+						PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
+							i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
+					}
 				}
 			}
 		}
@@ -793,6 +893,15 @@ void SetFanModuleSpeed()
 //==========================================
 void SetK1K2RelayStatus(byte index)
 {
+	if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
+	{
+		if(regRelay.relay_event.bits.Gun1_N == NO)
+			outputRelay.relay_event.bits.Gun1_N = YES;
+		else if (regRelay.relay_event.bits.Gun1_P == NO)
+			outputRelay.relay_event.bits.Gun1_P = YES;
+		return;
+	}
+
 	if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE)
 	{
 		if (_chargingData[index]->Evboard_id == 0x01)
@@ -924,7 +1033,35 @@ void CheckAcInputOvpStatus(byte index)
 			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
 			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
 	{
-		_chargingData[index]->StopChargeFlag = YES;
+//		if ((_chargingData[index]->SystemStatus >= S_PREPARNING && _chargingData[index]->SystemStatus <= S_CHARGING) ||
+//				(_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+//		{
+//			if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
+//			{
+//				if (_psuInputVolR > VIN_MAX_VOLTAGE_IEC ||
+//						_psuInputVolS > VIN_MAX_VOLTAGE_IEC ||
+//						_psuInputVolT > VIN_MAX_VOLTAGE_IEC)
+//				{
+//					PRINTF_FUNC("IEC _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
+//							_psuInputVolR, _psuInputVolS, _psuInputVolT);
+//					_chargingData[index]->StopChargeFlag = YES;
+//				}
+//
+//			}
+//			else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
+//			{
+//				if (_psuInputVolR > VIN_MAX_VOLTAGE_UL ||
+//						_psuInputVolS > VIN_MAX_VOLTAGE_UL ||
+//						_psuInputVolT > VIN_MAX_VOLTAGE_UL)
+//				{
+//					PRINTF_FUNC("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
+//							_psuInputVolR, _psuInputVolS, _psuInputVolT);
+//					_chargingData[index]->StopChargeFlag = YES;
+//				}
+//			}
+//		}
+//		else
+			_chargingData[index]->StopChargeFlag = YES;
 	}
 }
 
@@ -940,7 +1077,8 @@ void CheckPhaseLossStatus(byte index)
 
 void SetParalleRelayStatus()
 {
-	if (gunCount >= 2 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+	// 之後雙槍單模機種,橋接都會上
+	if (gunCount >= 2)
 	{
 		if (_chargingData[0]->SystemStatus == S_BOOTING || _chargingData[1]->SystemStatus == S_BOOTING ||
 				(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE))
@@ -1020,7 +1158,7 @@ void CheckAlarmOccur()
 			case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
 			case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = YES; break;
 			case AC_HANDSHAKE_TIMEOUT: break;
-			case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES; break;
+			//case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES; break;
 			case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = YES; break;
 			case AC_GF_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = YES; break;
 			case AC_SHUTTER_FAULT: break;
@@ -1045,7 +1183,7 @@ void CheckAlarmOccur()
 			case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
 			case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = NO; break;
 			case AC_HANDSHAKE_TIMEOUT: break;
-			case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO; break;
+			//case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO; break;
 			case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = NO; break;
 			case AC_GF_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = NO; break;
 			case AC_SHUTTER_FAULT: break;
@@ -1061,6 +1199,109 @@ void CheckAlarmOccur()
 	ac_chargingInfo[0]->IsErrorOccur = isErr;
 }
 
+bool IsNoneMatchLedColor()
+{
+	bool result = false;
+
+	if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
+		cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
+		cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
+		cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
+		cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
+		cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue)
+	{
+		result = true;
+	}
+
+	return result;
+}
+
+void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+{
+	if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
+	{
+		 if ((chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION) &&
+				 (chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION))
+		 {
+			 led_color.Connect_1_Green = COLOR_MAX_LV;
+			 led_color.Connect_1_Blue = COLOR_MIN_LV;
+			 led_color.Connect_1_Red = COLOR_MIN_LV;
+			 led_color.Connect_2_Green = COLOR_MAX_LV;
+			 led_color.Connect_2_Blue = COLOR_MIN_LV;
+			 led_color.Connect_2_Red = COLOR_MIN_LV;
+		 }
+		 else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
+		          	  (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
+					  (chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
+					  (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1))
+		 {
+			 led_color.Connect_1_Green = COLOR_MIN_LV;
+			 led_color.Connect_1_Blue = COLOR_MAX_LV;
+			 led_color.Connect_1_Red = COLOR_MIN_LV;
+			 led_color.Connect_2_Green = COLOR_MIN_LV;
+			 led_color.Connect_2_Blue = COLOR_MAX_LV;
+			 led_color.Connect_2_Red = COLOR_MIN_LV;
+		 }
+	}
+	else
+	{
+		if (chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION)
+		{
+			led_color.Connect_1_Green = COLOR_MAX_LV;
+			led_color.Connect_1_Blue = COLOR_MIN_LV;
+			led_color.Connect_1_Red = COLOR_MIN_LV;
+		}
+		else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
+				(chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1))
+		{
+			led_color.Connect_1_Green = COLOR_MIN_LV;
+			led_color.Connect_1_Blue = COLOR_MAX_LV;
+			led_color.Connect_1_Red = COLOR_MIN_LV;
+		}
+
+		// --------------------------------------------------------------------------
+		if (chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION)
+		{
+			led_color.Connect_2_Green = COLOR_MAX_LV;
+			led_color.Connect_2_Blue = COLOR_MIN_LV;
+			led_color.Connect_2_Red = COLOR_MIN_LV;
+		}
+		else if ((chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
+				(chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1))
+		{
+			led_color.Connect_2_Green = COLOR_MIN_LV;
+			led_color.Connect_2_Blue = COLOR_MAX_LV;
+			led_color.Connect_2_Red = COLOR_MIN_LV;
+		}
+	}
+
+	if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
+	{
+		led_color.Connect_1_Green = COLOR_MIN_LV;
+		led_color.Connect_1_Blue = COLOR_MIN_LV;
+		led_color.Connect_1_Red = COLOR_MAX_LV;
+		led_color.Connect_2_Green = COLOR_MIN_LV;
+		led_color.Connect_2_Blue = COLOR_MIN_LV;
+		led_color.Connect_2_Red = COLOR_MAX_LV;
+	}
+
+	if (_checkLedChanged > 0)
+	{
+		if (Config_Led_Color(Uart5Fd, Addr.Led, &led_color) == PASS)
+		{
+			_checkLedChanged--;
+
+			cur_led_color.Connect_1_Red 	= led_color.Connect_1_Red;
+			cur_led_color.Connect_1_Green 	= led_color.Connect_1_Green;
+			cur_led_color.Connect_1_Blue 	= led_color.Connect_1_Blue;
+			cur_led_color.Connect_2_Red 	= led_color.Connect_2_Red;
+			cur_led_color.Connect_2_Green	= led_color.Connect_2_Green;
+			cur_led_color.Connect_2_Blue 	= led_color.Connect_2_Blue;
+		}
+	}
+	else if (IsNoneMatchLedColor())
+		_checkLedChanged = 3;
+}
 //==========================================
 // Init all share memory
 //==========================================
@@ -1083,8 +1324,8 @@ int InitShareMemory()
 		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
 		#endif
 		result = FAIL;
-	 }
-	 //creat ShmStatusCodeData
+	}
+	//creat ShmStatusCodeData
 	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
 	{
 		#ifdef SystemLogMessage
@@ -1114,9 +1355,10 @@ int InitShareMemory()
 		DEBUG_ERROR("shmat ShmFanModuleData NG\n");
 		#endif
 		result = FAIL;
-	 }
-	 memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
-	 //creat ShmRelayModuleData
+	}
+	memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
+
+	//creat ShmRelayModuleData
 	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  0777)) < 0)
 	{
 		#ifdef SystemLogMessage
@@ -1131,60 +1373,41 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	}
+	memset(ShmRelayModuleData,0,sizeof(struct RelayModuleData));
 
-	//creat ShmPsuData
-	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
+	//creat ShmLedModuleData
+	if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0)
 	{
 		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmPsuData NG \n");
+		DEBUG_ERROR("shmget ShmLedModuleData NG\n");
 		#endif
 		result = FAIL;
 	}
-	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
 		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmat ShmPsuData NG \n");
+		DEBUG_ERROR("shmat ShmLedModuleData NG\n");
 		#endif
 		result = FAIL;
 	}
-	memset(ShmPsuData,0,sizeof(struct PsuData));
+	memset(ShmLedModuleData,0,sizeof(struct LedModuleData));
 
-	if(CHAdeMO_QUANTITY > 0)
+	//creat ShmPsuData
+	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
 	{
-		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),	IPC_CREAT | 0777)) < 0)
-		{
-			#ifdef SystemLogMessage
-			DEBUG_ERROR("[shmget ShmCHAdeMOData NG \n");
-			#endif
-			return FAIL;
-		}
-		else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
-			#ifdef SystemLogMessage
-			DEBUG_ERROR("shmat ShmCHAdeMOData NG \n");
-			#endif
-			return FAIL;
-		}
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmPsuData NG \n");
+		#endif
+		result = FAIL;
 	}
-
-	if(CCS_QUANTITY > 0)
+	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
-		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),	IPC_CREAT | 0777)) < 0)
-		{
-			#ifdef SystemLogMessage
-			DEBUG_ERROR("shmget ShmCcsData NG \n");
-			#endif
-			return FAIL;
-		}
-		else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-		{
-			#ifdef SystemLogMessage
-		   	DEBUG_ERROR("shmat ShmCcsData NG \n");
-			#endif
-			return FAIL;
-		}
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmPsuData NG \n");
+		#endif
+		result = FAIL;
 	}
 
-
 	return result;
 }
 
@@ -1282,11 +1505,13 @@ void Initialization()
 		{
 			if (!FindChargingInfoData(_index, &_chargingData[0]))
 			{
-				DEBUG_ERROR("EvComm : FindChargingInfoData false \n");
+				DEBUG_ERROR("InternalComm : FindChargingInfoData false \n");
 				isPass = false;
 				break;
 			}
 		}
+
+		sleep(1);
 	}
 
 	isPass = false;
@@ -1305,6 +1530,8 @@ void Initialization()
 					break;
 				}
 			}
+
+			sleep(1);
 		}
 	}
 }
@@ -1421,7 +1648,7 @@ void CableCheckDetected(byte index)
 			}
 			else if (_chargingData[index]->SystemStatus <= S_CHARGING)
 			{
-				if (_chargingData[index]->Type == _Type_GB)
+				if (_chargingData[index]->Type == _Type_GB || _chargingData[index]->Type == _Type_Chademo)
 					SetGfdConfig(index, GFD_IDLE);
 				else
 					SetGfdConfig(index, GFD_CHARGING);
@@ -1438,9 +1665,9 @@ void CableCheckDetected(byte index)
 void CheckOutputPowerOverCarReq(byte index)
 {
 	float fireV = _chargingData[index]->FireChargingVoltage;
-	float carV = _chargingData[index]->EvBatterytargetVoltage;
+	float carV = _chargingData[index]->EvBatterytargetVoltage * 10;
 
-	if (_chargingData[index]->EvBatterytargetVoltage > 1500 &&
+	if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
 			(_chargingData[index]->Type == _Type_Chademo ||
 				_chargingData[index]->Type == _Type_CCS_2 ||
 				_chargingData[index]->Type == _Type_GB))
@@ -1448,9 +1675,9 @@ void CheckOutputPowerOverCarReq(byte index)
 		if (fireV >= (carV + (carV * 0.1)))
 		{
 			PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-					_chargingData[index]->FireChargingVoltage, _chargingData[index]->EvBatterytargetVoltage);
+					_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
 			DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-					_chargingData[index]->FireChargingVoltage, _chargingData[index]->EvBatterytargetVoltage);
+					_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
 			_chargingData[index]->StopChargeFlag = YES;
 		}
 	}
@@ -1458,7 +1685,7 @@ void CheckOutputPowerOverCarReq(byte index)
 
 void CheckOutputVolNoneMatchFire(byte index)
 {
-	if (_chargingData[index]->EvBatterytargetVoltage > 1500 &&
+	if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
 			(_chargingData[index]->Type == _Type_Chademo ||
 					_chargingData[index]->Type == _Type_CCS_2 ||
 					_chargingData[index]->Type == _Type_GB))
@@ -1524,15 +1751,28 @@ void CheckRelayWeldingStatus(byte index)
 void GetPsuTempForFanSpeed()
 {
 	char temp = 0;
+	//double volR = 0, volS = 0, volT = 0;
 	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
 	{
 		for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
 		{
 			if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp)
 				temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
+
+//			if (volR < (ShmPsuData->PsuGroup[index].PsuModule[count].InputVoltageL1 / 10) / 1.732)
+//				volR = (ShmPsuData->PsuGroup[index].PsuModule[count].InputVoltageL1 / 10) / 1.732;
+//
+//			if (volS < (ShmPsuData->PsuGroup[index].PsuModule[count].InputVoltageL2 / 10) / 1.732)
+//				volS = (ShmPsuData->PsuGroup[index].PsuModule[count].InputVoltageL2 / 10) / 1.732;
+//
+//			if (volT < (ShmPsuData->PsuGroup[index].PsuModule[count].InputVoltageL3 / 10) / 1.732)
+//				volT = (ShmPsuData->PsuGroup[index].PsuModule[count].InputVoltageL3 / 10) / 1.732;
 		}
 	}
 
+	//_psuInputVolR = volR; _psuInputVolS = volS; _psuInputVolT = volT;
+	ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = temp;
+
 	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
 	{
 		if (ShmFanModuleData->TestFanSpeed == NORMAL_FAN_SPEED)
@@ -1559,7 +1799,8 @@ void GetAcStatus()
 		if(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0)
 			ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
 
-	//				printf("CpStatus = %d \n", acStatus.CpStatus);
+		ac_chargingInfo[0]->ConnectorPlugIn = acStatus.CpStatus;
+	//	PRINTF_FUNC("CpStatus = %d \n", acStatus.CpStatus);
 	//				printf("CurLimit = %d \n", acStatus.CurLimit);
 	//				printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
 	//				printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
@@ -1574,6 +1815,8 @@ void GetAcStatus()
 	//
 	//				ac_chargingInfo[0]->SystemStatus = acStatus.CpStatus;
 	}
+//	else
+//		PRINTF_FUNC("GetAcStatus return fail. \n");
 }
 
 void GetAcAlarmCode()
@@ -1626,6 +1869,24 @@ void ChangeToCsuMode()
 //	}
 }
 
+void ChangeStartOrStopDateTime(byte isStart)
+{
+	char cmdBuf[32];
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+
+	sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
+			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+			tmCSU->tm_sec);
+	if (isStart)
+		strcpy((char *)ac_chargingInfo[0]->StartDateTime, cmdBuf);
+	else
+		strcpy((char *)ac_chargingInfo[0]->StopDateTime, cmdBuf);
+}
+
 void AcChargeTypeProcess()
 {
 	if (acgunCount > 0)
@@ -1634,6 +1895,7 @@ void AcChargeTypeProcess()
 		{
 			ac_chargingInfo[0]->IsModeChagned = NO;
 			GetFwVersion_AC();
+			GetAcModelName();
 		}
 		else if (ac_chargingInfo[0]->SelfTest_Comp == YES)
 		{
@@ -1654,7 +1916,7 @@ void AcChargeTypeProcess()
 					_status = S_TERMINATING;
 				else if (ac_chargingInfo[0]->SystemStatus >= S_TERMINATING)
 				{
-					if (GetTimeoutValue(_ac_charging_comp) >= 10000000)
+					if (GetTimeoutValue(_ac_charging_comp) >= 10000000 && acStatus.CpStatus == AC_SYS_A)
 						_status = S_IDLE;
 				}
 				else
@@ -1668,18 +1930,29 @@ void AcChargeTypeProcess()
 				else if (GetTimeoutValue(_ac_preparing) >= 30000000)
 					_status = S_IDLE;
 			}
-			else if (acStatus.CpStatus == AC_SYS_B &&
+			else if ((acStatus.CpStatus == AC_SYS_B || ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_B) &&
 					ac_chargingInfo[0]->IsAvailable &&
 					!ac_chargingInfo[0]->IsErrorOccur &&
 					(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
 						ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE))
 			{
-				PRINTF_FUNC("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
-				strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
-				PRINTF_FUNC("** CardNumber = %s \n", ac_chargingInfo[0]->StartUserId);
-				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-				ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-				_status = S_PREPARNING;
+				if (ac_chargingInfo[0]->RemoteStartFlag == YES)
+				{
+					PRINTF_FUNC("** AC Remote \n");
+					ac_chargingInfo[0]->RemoteStartFlag = NO;
+					strcpy((char *)ac_chargingInfo[0]->StartUserId, "");
+					ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+					_status = S_PREPARNING;
+				}
+				else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
+				{
+					PRINTF_FUNC("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
+					strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+					PRINTF_FUNC("** CardNumber = %s \n", ac_chargingInfo[0]->StartUserId);
+					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+					ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+					_status = S_PREPARNING;
+				}
 			}
 
 			//printf("_status = %d \n", _status);
@@ -1698,6 +1971,9 @@ void AcChargeTypeProcess()
 					if (_isStatusChanged)
 					{
 						ac_chargingInfo[0]->PresentChargedEnergy = 0.0;
+						ac_chargingInfo[0]->PresentChargingVoltage = 0;
+						ac_chargingInfo[0]->ChargingFee = 0.0;
+						_beforeChargingTotalEnergy = 0.0;
 					}
 
 					ChangeLedStatus();
@@ -1709,12 +1985,15 @@ void AcChargeTypeProcess()
 					{
 						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
 						ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+						if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
+							ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
 						gettimeofday(&_ac_preparing, NULL);
 					}
 
 					if (GetChargingEnergy() == PASS)
 					{
-						ac_chargingInfo[0]->PresentChargedEnergy = acChargingEnergy.Energy / 100;
+						//ac_chargingInfo[0]->PresentChargedEnergy = acChargingEnergy.Energy / 100;
+						_beforeChargingTotalEnergy = acChargingEnergy.Energy;
 					}
 
 					SetLegacyReq(YES);
@@ -1726,17 +2005,31 @@ void AcChargeTypeProcess()
 					if (_isStatusChanged)
 					{
 						ftime(&_ac_startChargingTime);
+						ChangeStartOrStopDateTime(YES);
 						ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
 					}
 
 					if (GetChargingEnergy() == PASS)
-						ac_chargingInfo[0]->PresentChargedEnergy = acChargingEnergy.Energy / 100;
+					{
+						if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0)
+						{
+							ac_chargingInfo[0]->PresentChargedEnergy += (acChargingEnergy.Energy - _beforeChargingTotalEnergy) / 100;
+							if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+							{
+								ac_chargingInfo[0]->ChargingFee += ac_chargingInfo[0]->PresentChargedEnergy * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+							}
+						}
+
+						_beforeChargingTotalEnergy = acChargingEnergy.Energy;
+					}
 
 					if (GetChargingCurrent() == PASS)
-						ac_chargingInfo[0]->PresentChargingPower = (220 * (acChargingCurrent.OuputCurrentL1 / 10)) / 1000;
+						ac_chargingInfo[0]->PresentChargingPower = (((float)(AC_DEFAULT_VOL * acChargingCurrent.OuputCurrentL1) / 10) / 1000);
 
 					ftime(&_ac_endChargingTime);
-					ac_chargingInfo[0]->RemainChargingDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
+					ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
+					ac_chargingInfo[0]->PresentChargingVoltage = AC_DEFAULT_VOL;
+					ac_chargingInfo[0]->PresentChargingCurrent = ((float)acChargingCurrent.OuputCurrentL1 / 10);
 
 					// 用以判斷是否有在輸出
 					ac_chargingInfo[0]->IsCharging = acStatus.RelayStatus;
@@ -1749,6 +2042,7 @@ void AcChargeTypeProcess()
 				{
 					if (_isStatusChanged)
 					{
+						ChangeStartOrStopDateTime(NO);
 						gettimeofday(&_ac_charging_comp, NULL);
 					}
 
@@ -1763,7 +2057,8 @@ void AcChargeTypeProcess()
 					{
 						gettimeofday(&_ac_charging_comp, NULL);
 						ftime(&_ac_endChargingTime);
-						ac_chargingInfo[0]->RemainChargingDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
+						ChangeStartOrStopDateTime(NO);
+						ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
 					}
 				}
 					break;
@@ -1811,7 +2106,14 @@ int main(void)
 	if(Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay) != PASS)
 		PRINTF_FUNC("Config_Relay_Output fail \n");
 
-	bool printRelayStatus = true;
+	cur_led_color.Connect_1_Red = COLOR_MIN_LV;
+	cur_led_color.Connect_1_Green = COLOR_MIN_LV;
+	cur_led_color.Connect_1_Blue = COLOR_MIN_LV;
+	cur_led_color.Connect_2_Red = COLOR_MIN_LV;
+	cur_led_color.Connect_2_Green = COLOR_MIN_LV;
+	cur_led_color.Connect_2_Blue = COLOR_MIN_LV;
+
+	//bool printRelayStatus = true;
 	for(;;)
 	{
 		bool isCharging = false;
@@ -1832,6 +2134,24 @@ int main(void)
 			gettimeofday(&_priority_time, NULL);
 		}
 
+		// 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
+		if (ShmLedModuleData->SelfTest_Comp == NO)
+		{
+			// 自檢階段
+			if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq <= _STEST_PSU_CAP)
+			{
+				GetFwAndHwVersion_Led();
+				sleep(1);
+				gettimeofday(&_led_priority_time, NULL);
+			}
+			else
+			{
+				// 自檢階段沒有問到版號
+				if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail == NO)
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES;
+			}
+		}
+
 		AcChargeTypeProcess();
 
 		if (ShmRelayModuleData->SelfTest_Comp == YES)
@@ -1911,7 +2231,8 @@ int main(void)
 //			else
 //				outputRelay.relay_event.bits.AC_Contactor = NO;
 
-			if (isCharging)
+			if (isCharging ||
+				(ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE))
 			{
 				isStopChargingCount = false;
 				outputRelay.relay_event.bits.AC_Contactor = YES;
@@ -1930,6 +2251,9 @@ int main(void)
 				}
 			}
 
+			if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
+				outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
+
 			// 搭上/鬆開 Relay
 			if(IsNoneMatchRelayStatus())
 			{
@@ -2005,6 +2329,14 @@ int main(void)
 
 		if (ShmFanModuleData->SelfTest_Comp == YES)
 		{
+			// 風控修改 :
+			// ******************************************************* //
+			//
+			//       當前PSU輸出總 KW       PSU Temp
+			// 30 x -------------------- x ---------- + 14 x (PSU Temp - 45)
+			//       當前樁最大功率 KW         45
+			//
+			// ******************************************************* //
 			if (GetTimeoutValue(_priority_time) / 1000 >= 1000)
 			{
 				GetPsuTempForFanSpeed();
@@ -2068,6 +2400,23 @@ int main(void)
 			}
 		}
 
+		if (ShmLedModuleData->SelfTest_Comp == YES)
+		{
+			if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000)
+			{
+				if(gunCount == 1)
+				{
+					SetLedColor(_chargingData[0], _chargingData[0]);
+				}
+				else if (gunCount == 2)
+				{
+					SetLedColor(_chargingData[0], _chargingData[1]);
+				}
+
+				gettimeofday(&_led_priority_time, NULL);
+			}
+		}
+
 		usleep(10000);
 	}
 

+ 8 - 3
EVSE/Projects/DS60-120/Apps/Module_LcmContro.h

@@ -41,7 +41,12 @@ struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
 struct FanModuleData			*ShmFanModuleData;
 
-#define	NO_DEFINE			255
+#define NO_DEFINE			255
+#define DEFAULT_AC_INDEX	2
+
+#define TIME_MAX_SEC		2592000 // ¤@­Ó¤ë¡A¬í¼Æ
+#define POWER_MAX_KW		5000
+#define ENERGY_MAX_KWH		5000
 
 #define CMD_TITLE_1				0x5A
 #define CMD_TITLE_2				0xA5
@@ -79,10 +84,10 @@ byte isChangeBattMap = false;
 short _currentPage = _LCM_NONE;
 short _oldPage = _LCM_NONE;
 byte _gunIndex = 0;
-byte _idlePageRotate = 1;
-bool _backend_conn_status = false;
 bool _wifi_conn_status = false;
 bool _battery_display_ani = false;
+byte _curPage_index = 0;
+bool _page_reload = false;
 
 // LCM - HW
 byte _everyPageRollChange = 0;

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


+ 93 - 35
EVSE/Projects/DS60-120/Apps/Module_LcmControl.c

@@ -18,22 +18,33 @@ int StoreLogMsg(const char *fmt, ...)
 {
 	char Buf[4096+256];
 	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
 	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
 
 	va_start(args, fmt);
 	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 
 	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
+		system(Buf);
+	}
 
 	return rc;
 }
@@ -59,10 +70,7 @@ void PRINTF_FUNC(char *string, ...)
 	vsnprintf(buffer, sizeof(buffer), string, args);
 	va_end(args);
 
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-		printf("%s \n", buffer);
-	else
-		DEBUG_INFO("%s \n", buffer);
+	DEBUG_INFO("%s \n", buffer);
 }
 
 //==========================================
@@ -747,7 +755,8 @@ void RefreshPageAnimation(byte value)
 void RefreshConnStatus()
 {
 	// Wifi priority is higher than Ethernet
-	if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES)
+	if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ||
+			ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP)
 	{
 		_wifi_conn_status = true;
 		ChangeDisplay2Value(__wifi_status, _wifi_connect);
@@ -761,7 +770,8 @@ void RefreshConnStatus()
 
 	if (!_wifi_conn_status)
 	{
-		if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES)
+		if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ||
+				ShmSysConfigAndInfo->SysInfo.InternetConn == YES)
 		{
 			ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
 		}
@@ -791,8 +801,34 @@ byte FirstPageChanged()
 	return result;
 }
 
+bool IsPageReloadChk()
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
+	{
+		if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+		{
+			_curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
+			result = true;
+		}
+	}
+	else
+	{
+		if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc)
+		{
+			_curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
+			result = true;
+		}
+	}
+
+	return result;
+}
+
 void ProcessPageInfo()
 {
+	_page_reload = IsPageReloadChk();
+
 	switch(_currentPage)
 	{
 		case _LCM_IDLE:
@@ -816,12 +852,15 @@ void ProcessPageInfo()
 			else
 				ChangeDisplay2Value(__main_app, _main_none_app);
 
-			if (FirstPageChanged() == YES || needReloadQr)
+			if (FirstPageChanged() == YES || needReloadQr || _page_reload)
 			{
 				if (ShmSysConfigAndInfo->SysConfig.isQRCode)
 				{
 					needReloadQr = false;
-					ChangeQrCode_Idle("http://google.com.tw");
+					char QrCodeContent[128];
+					strcpy(QrCodeContent, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
+					strcat(QrCodeContent, (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
+					ChangeQrCode_Idle(QrCodeContent);
 				}
 			}
 		}
@@ -877,17 +916,20 @@ void ProcessPageInfo()
 					if (_currentPage == _LCM_CHARGING)
 					{
 						ChangeAcBattMapAndValue(_LCM_CHARGING);
-						if (ac_chargingInfo[0]->RemainChargingDuration >= 0)
-							ChangeRemainTime(ac_chargingInfo[0]->RemainChargingDuration);
+						if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
+								ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC)
+							ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
 						else
 							ChangeRemainTime(0);
 
-						if (ac_chargingInfo[0]->PresentChargingPower >= 0.1)
+						if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
+								ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW)
 							ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
 						else
 							ChangeChargingPowerValue(0);
 
-						if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1)
+						if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
+								ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH)
 							ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
 						else
 							ChangeChargingEnergyValue(0);
@@ -900,17 +942,20 @@ void ProcessPageInfo()
 					else if (_currentPage == _LCM_COMPLETE)
 					{
 						ChangeAcBattMapAndValue(_LCM_COMPLETE);
-						if (ac_chargingInfo[0]->RemainChargingDuration >= 0)
-							ChangeRemainTime(ac_chargingInfo[0]->RemainChargingDuration);
+						if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
+								ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC)
+							ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
 						else
 							ChangeRemainTime(0);
 
-						if (ac_chargingInfo[0]->PresentChargingPower >= 0.1)
+						if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
+								ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW)
 							ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
 						else
 							ChangeChargingPowerValue(0);
 
-						if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1)
+						if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1&&
+								ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH)
 						{
 							ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
 
@@ -991,17 +1036,20 @@ void ProcessPageInfo()
 					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
 					{
 						ChangeBattMapAndValue(_LCM_CHARGING, _chargingInfoData[i]->EvBatterySoc);
-						if (_chargingInfoData[i]->RemainChargingDuration >= 0)
-							ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
+						if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
+								_chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC)
+							ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
 						else
 							ChangeRemainTime(0);
 
-						if (_chargingInfoData[i]->PresentChargingPower >= 0)
+						if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
+								_chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW)
 							ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
 						else
 							ChangeChargingPowerValue(0);
 
-						if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1)
+						if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
+								_chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH)
 							ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
 						else
 							ChangeChargingEnergyValue(0);
@@ -1017,17 +1065,20 @@ void ProcessPageInfo()
 					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
 					{
 						ChangeBattMapAndValue(_LCM_COMPLETE, _chargingInfoData[i]->EvBatterySoc);
-						if (_chargingInfoData[i]->RemainChargingDuration >= 0)
-							ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
+						if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
+								_chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC)
+							ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
 						else
 							ChangeRemainTime(0);
 
-						if (_chargingInfoData[i]->PresentChargingPower >= 0)
+						if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
+								_chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW)
 							ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
 						else
 							ChangeChargingPowerValue(0);
 
-						if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1)
+						if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
+								_chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH)
 						{
 							ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
 
@@ -1073,12 +1124,15 @@ void ProcessPageInfo()
 						_chargingInfoData[index]->SystemStatus == S_RESERVATION ||
 						_chargingInfoData[index]->SystemStatus == S_BOOTING)
 				{
-					if (FirstPageChanged() == YES || needReloadQr)
+					if (FirstPageChanged() == YES || needReloadQr || _page_reload)
 					{
 						if (ShmSysConfigAndInfo->SysConfig.isQRCode)
 						{
 							needReloadQr = false;
-							ChangeQrCode_Charge("http://google.com.tw");
+							char QrCodeContent[128];
+							strcpy(QrCodeContent, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
+							strcat(QrCodeContent, (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
+							ChangeQrCode_Charge(QrCodeContent);
 						}
 					}
 				}
@@ -1128,12 +1182,14 @@ void Initialization()
 		{
 			if (!FindChargingInfoData(_index, &_chargingInfoData[0]))
 			{
-				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+				DEBUG_ERROR("LcmComm (main) : FindChargingInfoData false \n");
 				isPass = false;
 				count--;
 				break;
 			}
 		}
+
+		sleep(1);
 	}
 
 	isPass = false;
@@ -1147,11 +1203,13 @@ void Initialization()
 			{
 				if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0]))
 				{
-					DEBUG_ERROR("EvComm : FindAcChargingInfoData false \n");
+					DEBUG_ERROR("LcmComm : FindAcChargingInfoData false \n");
 					isPass = false;
 					break;
 				}
 			}
+
+			sleep(1);
 		}
 	}
 

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


+ 19 - 11
EVSE/Projects/DS60-120/Apps/Module_PrimaryComm.c

@@ -68,22 +68,33 @@ int StoreLogMsg(const char *fmt, ...)
 {
 	char Buf[4096+256];
 	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
 	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
 
 	va_start(args, fmt);
 	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 
 	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
+		system(Buf);
+	}
 
 	return rc;
 }
@@ -106,10 +117,7 @@ void PRINTF_FUNC(char *string, ...)
 	vsnprintf(buffer, sizeof(buffer), string, args);
 	va_end(args);
 
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-		printf("%s \n", buffer);
-	else
-		DEBUG_INFO("%s \n", buffer);
+	DEBUG_INFO("%s \n", buffer);
 }
 //=================================
 // Common routine

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


Dosya farkı çok büyük olduğundan ihmal edildi
+ 467 - 167
EVSE/Projects/DS60-120/Apps/Module_PsuComm.c


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

@@ -38,6 +38,7 @@ typedef unsigned int 		unit;
 
 unsigned char _gunCount;
 struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+bool isStartOutputSwitch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 struct timeval _cmdSubPriority_time;
 byte _getCapDelayCount;
@@ -49,6 +50,7 @@ struct timeval _test_time;
 bool isCharging = false;
 bool isWaitingAver = false;
 bool isReadToCharging = false;
+bool CanAverageCharging = false;
 int preChargingTarget;
 int preChargingCur;
 

+ 363 - 0
EVSE/Projects/DS60-120/Apps/OutputTask.c

@@ -0,0 +1,363 @@
+/*
+ * OutputTask.c
+ *
+ *  Created on: 2020年2月25日
+ *      Author: 7564
+ */
+
+#include 	"OutputTask.h"
+
+bool isOpen;
+
+int InitComPort()
+{
+	int fd;
+	struct termios tios;
+
+	fd = open(priPortName, O_RDWR);
+	if(fd<=0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("open 407 Communication port NG \n");
+		#endif
+		return -1;
+	}
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(unsigned char)1;
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+	struct timeval _end_time;
+	gettimeofday(&_end_time, NULL);
+
+	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+}
+
+void ShowMainMsg()
+{
+	printf("Max Vol : %f, Max Cur : %d, POW : %d \n", UnSafeDataInfo->PSU_VOLTAGE,
+			UnSafeDataInfo->PSU_CURRENT, UnSafeDataInfo->PSU_POWER);
+	printf("=> ");
+}
+
+void ChkButtonStatus()
+{
+	if (Button1 == PRESS && !leftBtnPush)
+	{
+		if(!leftBtnPush)
+		{
+			leftBtnPush = true;
+			if (_charging_mode == CHARGING_MODE_STOP)
+			{
+				_charging_mode = CHARGING_MODE_START;
+				printf("****************** Switch to Charging Mode ******************\n");
+			}
+		}
+		else if (Button1 == RELEASE)
+		{
+			if(leftBtnPush)
+			{
+				leftBtnPush = false;
+			}
+		}
+	}
+
+	if (Button2 == PRESS && !rightBtnPush)
+	{
+		if(!rightBtnPush)
+		{
+			rightBtnPush = true;
+			if (_charging_mode == CHARGING_MODE_START)
+			{
+				_charging_mode = CHARGING_MODE_TERMINATING;
+				printf("****************** Switch to Stop Mode ******************\n");
+			}
+		}
+		else if (Button2 == RELEASE)
+		{
+			if(rightBtnPush)
+			{
+				rightBtnPush = false;
+			}
+		}
+	}
+}
+
+void GetModuleCountCallback(byte group, byte count)
+{
+	printf("group = %d, count = %d \n", group, count);
+	if (group == SYSTEM_CMD)
+		UnSafeDataInfo->PSU_COUNT = count;
+}
+
+void GetAvailableCapCallback(byte address, short maxVol, short minVol, short maxCur, short totalPow)
+{
+	int _groupPower = 0, _groupCurrent = 0;
+
+	UnSafeDataInfo->PsuModule[address].PSU_VOLTAGE_INFO = maxVol;
+	UnSafeDataInfo->PsuModule[address].PSU_CURRENT_INFO = maxCur;
+	UnSafeDataInfo->PsuModule[address].PSU_POWER_INFO = totalPow;
+
+	for (byte index = 0; index < UnSafeDataInfo->PSU_COUNT; index++)
+	{
+		_groupCurrent += UnSafeDataInfo->PsuModule[address].PSU_CURRENT_INFO;
+		_groupPower += UnSafeDataInfo->PsuModule[address].PSU_POWER_INFO;
+	}
+
+	UnSafeDataInfo->PSU_VOLTAGE = maxVol;
+	UnSafeDataInfo->PSU_CURRENT = _groupCurrent;
+	UnSafeDataInfo->PSU_POWER = _groupPower;
+}
+
+void GetStatusCallback(byte group, byte address, byte temp, int alarm)
+{
+	printf("alarm = %d \n", alarm);
+}
+
+void GetInputVoltageCallback(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3)
+{
+	printf("vol1 = %d, vol2 = %d, vol3 = %d \n", vol1, vol2, vol3);
+}
+
+int CreateShareMemory()
+{
+	int MeterSMId;
+
+	if ((MeterSMId = shmget(ShmTestKey,	sizeof(struct UnSafeData), IPC_CREAT | 0777)) < 0)
+	{
+		return 0;
+	}
+	else if ((UnSafeDataInfo = shmat(MeterSMId, NULL, 0))	== (void *) -1)
+	{
+		return 0;
+	}
+	memset(UnSafeDataInfo, 0, sizeof(struct UnSafeData));
+
+	return 1;
+}
+
+static void get_char(char *word)
+{
+    fd_set rfds;
+    struct timeval tv;
+
+    FD_ZERO(&rfds);
+    FD_SET(0, &rfds);
+    tv.tv_sec = 0;
+    tv.tv_usec = 10; //wait input timout time
+
+    //if input
+    if (select(1, &rfds, NULL, NULL, &tv) > 0)
+    {
+    	fgets(word, 128, stdin);
+    }
+}
+
+void GetInputString()
+{
+	char word[128];
+	char newString[7][10];
+	int i, j, ctr;
+
+	get_char(word);
+
+	if (strlen(word) == 0)
+	    return;
+	//fgets(word, sizeof(word), stdin);
+
+	j = 0;
+	ctr = 0;
+	for (i = 0; i <= (strlen(word)); i++) {
+		if (word[i] == ' ' || word[i] == '\0' || word[i] == 10) {
+			newString[ctr][j] = '\0';
+			ctr++;
+			j = 0;
+		} else {
+			newString[ctr][j] = word[i];
+			j++;
+		}
+	}
+
+	VOLTAGE = atof(newString[0]);
+	CURRENT = atof(newString[1]);
+	if (VOLTAGE <= UnSafeDataInfo->PSU_VOLTAGE && CURRENT <= UnSafeDataInfo->PSU_CURRENT)
+	{
+		//printf("OutputVol = %f, OutputCur = %f \n", VOLTAGE, CURRENT);
+	}
+	else
+	{
+		ShowMainMsg();
+	}
+}
+
+void GetIavailableCallback(byte address, unsigned short Iavail, unsigned short Vext)
+{
+	printf("address = %d, Iavail = %d, Vext = %d \n", address, Iavail, Vext);
+}
+
+void GetOutputAndTempCallback(byte address, unsigned short outputVol,
+		unsigned short outputCur, unsigned short outputPower, unsigned char Temperature)
+{
+//	PRINTF_FUNC("***Output Value and Temp*** address = %d, Vol = %d, Cur = %d, Pow = %d, Temp = %d \n",
+//			address, outputVol, outputCur, outputPower, Temperature);
+}
+
+void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char status,
+		unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4)
+{
+	int alarm = (err2 << 24) | (err3 << 16) | (err4 << 8);
+
+	// err2 == state 2
+	// err3 == state 1
+	// err4 == state 0
+	//printf("***Status*** address = %d, alarm = %d \n", address, alarm);
+	printf("***Status*** address = %d, err1 = %d, err2 = %d, err3 = %d, err4 = %d \n",
+			address, err1,err2,err3,err4);
+}
+
+void GetModuleInputCallback(byte address, unsigned short inputR,
+		unsigned short inputS, unsigned short inputT)
+{
+
+}
+
+int main(void)
+{
+	isOpen =false;
+
+	if(CreateShareMemory() == 0)
+	{
+		printf("CreateShareMemory fail. \n");
+		return 0;
+	}
+	RefreshModuleCount(&GetModuleCountCallback);
+	RefreshAvailableCap(&GetAvailableCapCallback);
+
+	RefreshStatus(&GetStatusCallback);
+	RefreshInputVol(&GetInputVoltageCallback);
+
+	RefreshIavailable(&GetIavailableCallback);
+
+	AutoMode_RefreshOutputAndTemp(&GetOutputAndTempCallback);
+	AutoMode_RefreshModuleStatus(&GetModuleStatusCallback);
+	AutoMode_RefreshModuleInput(&GetModuleInputCallback);
+
+	Uart1Fd = InitComPort();
+	libInitialize = InitialCommunication();
+
+	if (Uart1Fd < 0 || !libInitialize)
+	{
+		printf("Initial port fail. \n");
+		return 0;
+	}
+
+	sleep(5);
+	gettimeofday(&_cmdSubPriority_time, NULL);
+	VOLTAGE = 0.0;
+	CURRENT = 0.0;
+
+	SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+	while (1)
+	{
+		printf("++++++++++++++2++++++++++++++++++++++++++++++++++++++\n");
+		SetWalkInConfig(0, YES, 0);
+		SetWalkInConfig(1, NO, 0);
+		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+		sleep(1);
+	}
+
+	sleep(1);
+		printf("++++++++++++++2++++++++++++++++++++++++++++++++++++++\n");
+		SetWalkInConfig(SYSTEM_CMD, NO, 0);
+		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+	return 0;
+	while (1)
+	{
+		GetInputGpioStatus();
+		//ChkButtonStatus();
+		// 切換 Walk-in mode (default 5s -> 2s)
+		SetWalkInConfig(SYSTEM_CMD, NO, 0);
+
+		int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+		while(isGetCount == YES)
+		{
+			if (_charging_mode == CHARGING_MODE_START)
+			{
+				// 取得模塊輸出額定電流能力
+				GetModuleIavailable(0);
+			}
+
+			GetInputString();
+			if (VOLTAGE > 150 && CURRENT >= 0)
+				_charging_mode = CHARGING_MODE_START;
+			else
+				_charging_mode = CHARGING_MODE_TERMINATING;
+			//printf("_charging_mode = %d \n", _charging_mode);
+			switch(_charging_mode)
+			{
+				case CHARGING_MODE_START:
+				{
+					if (!isOpen)
+					{
+						SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
+						FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
+					}
+					PresentOutputVol(SYSTEM_CMD, VOLTAGE * 10, CURRENT * 10);
+				}
+					break;
+				case CHARGING_MODE_TERMINATING:
+				{
+					if (isOpen)
+					{
+						SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+						FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+					}
+				}
+					break;
+			}
+			//GetStatus(0);
+			//GetModuleInput(0);
+			sleep(1);
+		}
+
+		if (UnSafeDataInfo->PSU_COUNT <= 0)
+		{
+			if (time > 1000)
+			{
+				printf("Step 1 : GetModuleCount...... \n");
+				GetModuleCount(SYSTEM_CMD);
+				gettimeofday(&_cmdSubPriority_time, NULL);
+			}
+		}
+		else if (time < 5000)
+		{
+			printf("Step 2 : GetModuleCap...... \n");
+			GetModuleCap(0);
+
+			SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+			FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+		}
+		else
+		{
+			ShowMainMsg();
+			isGetCount = YES;
+		}
+
+		sleep(1);
+	}
+
+	return 0;
+}
+
+

+ 174 - 0
EVSE/Projects/DS60-120/Apps/OutputTask.h

@@ -0,0 +1,174 @@
+/*
+ * OutputTask.h
+ *
+ *  Created on: 2020¦~2¤ë25¤é
+ *      Author: 7564
+ */
+
+#ifndef OUTPUTTASK_H_
+#define OUTPUTTASK_H_
+
+
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<linux/can.h>
+#include 	<linux/can/raw.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>
+#include    <stdlib.h>
+#include    <unistd.h>
+#include    <fcntl.h>
+#include    <termios.h>
+#include    <errno.h>
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<stdbool.h>
+
+#define ShmTestKey	2001
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define YES					1
+#define NO					0
+#define PRESS				1
+#define RELEASE				0
+#define MAX_PSU_QUANTITY        62
+
+int Uart1Fd = -1;
+char *priPortName = "/dev/ttyS1";
+
+bool libInitialize = false;
+struct timeval _cmdSubPriority_time;
+
+unsigned char Button1 = RELEASE;
+unsigned char Button2 = RELEASE;
+bool leftBtnPush = false;
+bool rightBtnPush = false;
+
+unsigned char _psuCount = 0;
+unsigned char isGetCount = NO;
+
+float VOLTAGE;
+float CURRENT;
+
+struct PsuModuleInfo
+{
+	unsigned int 	PSU_POWER_INFO;
+	float			PSU_VOLTAGE_INFO;
+	unsigned short	PSU_CURRENT_INFO;
+};
+
+struct UnSafeData
+{
+	unsigned char 			PSU_COUNT;
+	struct PsuModuleInfo 	PsuModule[MAX_PSU_QUANTITY];
+	unsigned int 			PSU_POWER;
+	float					PSU_VOLTAGE;
+	unsigned short			PSU_CURRENT;
+};
+
+struct UnSafeData			*UnSafeDataInfo;
+
+typedef struct GPIO_IN
+{
+	unsigned char AC_Connector;
+	unsigned char AC_MainBreaker;
+	unsigned char SPD;
+	unsigned char Door_Open;
+	unsigned char GFD[2];
+	unsigned char AC_Drop;
+	unsigned char Emergency_IO;
+
+	unsigned char Emergency_Btn;
+	unsigned char Button[2];
+	unsigned char Key[4];
+}Gpio_in;
+
+Gpio_in gpio_in;
+
+enum CHARGING_MODE
+{
+	CHARGING_MODE_STOP = 			0x00,
+	CHARGING_MODE_START = 			0x01,
+	CHARGING_MODE_TERMINATING = 	0x10,
+};
+
+unsigned char _charging_mode = CHARGING_MODE_STOP;
+
+int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
+{
+	int len;
+	tcflush(fd,TCIOFLUSH);
+	if(write(fd, cmd, cmd_len) >= cmd_len)
+	{
+		usleep(50000);
+		len = read(fd, rx, 512);
+	}
+	else
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+		#endif
+	}
+
+	return len;
+}
+
+unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, 0x0a, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 0)
+	{
+		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			Ret_Buf->Button[0] 			= (rx[7] >> 1) & 0x01;
+			Ret_Buf->Button[1] 			= (rx[7] >> 2) & 0x01;
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+void GetInputGpioStatus()
+{
+	if (Query_Gpio_Input(Uart1Fd, 0x04, &gpio_in) == PASS)
+	{
+		Button1 = gpio_in.Button[0];
+		Button2 = gpio_in.Button[1];
+	}
+}
+
+#endif /* OUTPUTTASK_H_ */

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


+ 151 - 32
EVSE/Projects/DS60-120/Apps/ReadCmdline.c

@@ -57,6 +57,7 @@ struct CcsData					*ShmCcsData;
 struct GBTData					*ShmGBTData;
 struct FanModuleData			*ShmFanModuleData;
 struct RelayModuleData			*ShmRelayModuleData;
+struct LedModuleData			*ShmLedModuleData;
 struct PsuData 					*ShmPsuData;
 
 struct ChargingInfoData 		*_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
@@ -200,6 +201,15 @@ int InitShareMemory()
    		result = FAIL;
    	}
 
+   	if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		result = FAIL;
+   	}
+
    	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),	IPC_CREAT | 0777)) < 0)
    	{
    		result = FAIL;
@@ -212,8 +222,28 @@ int InitShareMemory()
     return result;
 }
 
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+	struct timeval _end_time;
+	gettimeofday(&_end_time, NULL);
+
+	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+}
+
 void RunStatusProc(char *v1, char *v2)
 {
+	printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
+	printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+	if (strcmp(v1, "ac") == 0)
+	{
+		if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
+		{
+			printf("FindChargingInfoData (AC) false \n");
+		}
+		printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
+		return;
+	}
+
 	int _index = atoi(v1);
 	if (_index <= 1)
 	{
@@ -273,13 +303,35 @@ void RunCardProc(char *v1, char *v2)
 	}
 	else
 	{
-		memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, ARRAY_SIZE(v1));
+		strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+		memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
+		ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
 		printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
 	}
 }
 
 void RunGunPlugitProc(char *v1, char *v2)
 {
+	if (strcmp(v1, "ac") == 0)
+	{
+		if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
+		{
+			printf("FindChargingInfoData (AC) false \n");
+		}
+
+		if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
+		{
+			// get
+			printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
+		}
+		else
+		{
+			// set
+			ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
+		}
+		return;
+	}
+
 	int _index = atoi(v1);
 	if (!FindChargingInfoData(_index, &_chargingData[0]))
 	{
@@ -307,8 +359,12 @@ void GetGunLockStatusProc(char *v1, char *v2)
 		printf("FindChargingInfoData error\n");
 		return;
 	}
+	if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
+	{
+		_chargingData[_index]->GunLocked = atoi(v2);
+	}
 
-	printf("Gun Locked Status = %x \n", _chargingData[_index]->GunLocked);
+	printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
 }
 
 void SetSystemIDProc()
@@ -328,17 +384,14 @@ void GetFwVerProc(char *v1)
 	{
 		printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
 	}
-	else if (strcmp(v1, "0") == 0)
+	else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0)
 	{
-		printf("Ev board 0 FW Version = %s \n", ShmCHAdeMOData->evse[0].version);
-	}
-	else if (strcmp(v1, "1") == 0)
-	{
-		printf("Ev board 1 FW Version = %s \n", ShmCcsData->V2GMessage_DIN70121->version);
-	}
-	else if (strcmp(v1, "2") == 0)
-	{
-		printf("Ev board 2 FW Version = %s \n", ShmGBTData->evse[0].version);
+		int _index = atoi(v1);
+
+		if (_index == 0)
+			printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
+		else if (_index == 1)
+			printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
 	}
 	else if (strcmp(v1, "rb") == 0)
 	{
@@ -352,6 +405,10 @@ void GetFwVerProc(char *v1)
 	{
 		printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
 	}
+	else if (strcmp(v1, "led") == 0)
+	{
+		printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
+	}
 	else if (strcmp(v1, "ac") == 0)
 	{
 		if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
@@ -370,6 +427,26 @@ void CreateOneError(char *v1)
 	ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
 }
 
+void GetAuthorizeFlag(char *v1)
+{
+	if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
+		printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
+	else
+		ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
+}
+
+void GetOrClearId(char *v1)
+{
+	int _index = atoi(v1);
+
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf("FindChargingInfoData error\n");
+		return;
+	}
+	printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
+}
+
 void FwUpdateFlagProc()
 {
 	ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
@@ -409,12 +486,15 @@ void SetPowerValue(char *v1, char *v2)
 		return;
 	}
 
-	_chargingData[_index]->EvBatterytargetCurrent = _Current * 10;
+	_chargingData[_index]->EvBatterytargetCurrent = _Current;
 }
 
 void GetSystemInfo()
 {
 	printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+	printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
+
 	printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
 			ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
 			ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
@@ -514,7 +594,7 @@ void GetAcInputVol()
 			ShmSysConfigAndInfo->SysInfo.InputVoltageT);
 }
 
-void GetPsuInformation(char *v1)
+void GetPsuInformation(char *v1, char *v2, char *v3)
 {
 	printf("**********************AC Contact needed*************************\n");
 	if(strcmp(v1, "count") == 0)
@@ -549,6 +629,20 @@ void GetPsuInformation(char *v1)
 					i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
 		}
 	}
+	else if(strcmp(v1, "input") == 0)
+	{
+		for (int i = 0; i < ShmPsuData->GroupCount; i++)
+		{
+			for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
+			{
+				printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
+						i, count,
+						ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
+						ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
+						ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
+			}
+		}
+	}
 	else if (strcmp(v1, "output") == 0)
 	{
 		for (int i = 0; i < ShmPsuData->GroupCount; i++)
@@ -557,6 +651,31 @@ void GetPsuInformation(char *v1)
 					i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
 		}
 	}
+	else if (strcmp(v1, "test") == 0)
+	{
+		int mode = atoi(v2);
+
+		if (mode >= _TEST_MODE && mode <= _TEST_MODE)
+		{
+			ShmPsuData->Work_Step = mode;
+		}
+	}
+	else if (strcmp(v1, "out") == 0)
+	{
+		float vol = atof(v2);
+		float cur = atof(v3);
+
+		if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
+		{
+			if (!FindChargingInfoData(0, &_chargingData[0]))
+			{
+				printf ("FindChargingInfoData error\n");
+				return;
+			}
+			_chargingData[0]->EvBatterytargetVoltage = vol;
+			_chargingData[0]->EvBatterytargetCurrent = cur;
+		}
+	}
 	printf("*************************************************\n");
 }
 
@@ -615,7 +734,6 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     if(_Voltage > 1000 || _Voltage < 50)
     {
-
         printf ("Input Voltage over range\n");
         return;
     }
@@ -632,8 +750,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     //kill ev task
     system("killall Module_EvComm");
 
-    _Voltage = (_Voltage * 10);
-    _Current = (_Current * 10);
+    //_Voltage = (_Voltage * 10);
+    //_Current = (_Current * 10);
 
     //system(STTY_US TTY_PATH);
 
@@ -699,7 +817,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
 
         	        printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
-        	        printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage,_Current);
+        	        printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
 
         	    }
     		    //清除 main timeout 機制
@@ -709,8 +827,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     		    //充電電壓電流
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-   		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 5000;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 20;
+   		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
 
     		    //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
@@ -746,8 +864,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     		    //充電電壓電流
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 5000;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 20;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
 
     		    //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
@@ -796,12 +914,6 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     		         printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
     		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
     		    }
-
-    		    if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03){
-    		         printf ("Charging Ground Fault Warning (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
-    		    }
-
     		}
     		break;
 
@@ -815,7 +927,6 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	        printf ("[UnconditionalCharge - S_TERMINATING]\n");
         	        //無阻塞偵測 keybaord 結束
         	        system(STTY_DEF TTY_PATH);
-
         	    }
 
         	    sleep(3);
@@ -880,8 +991,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     		   continue;
 
     		printf("vol = %f, cur = %f \n", _vol, _cur);
-    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol * 10;
-    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur * 10;
+    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
+    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
     	}
     	else if (strcmp(newString[0], "c") == 0)
     	{
@@ -1057,7 +1168,7 @@ int main(void)
 			}
 
 			// 取得 PSU 資訊
-			GetPsuInformation(newString[1]);
+			GetPsuInformation(newString[1], newString[2], newString[3]);
 		}
 		else if (strcmp(newString[0], "cap") == 0)
 		{
@@ -1067,6 +1178,14 @@ int main(void)
 		{
 			CreateOneError(newString[1]);
 		}
+		else if (strcmp(newString[0], "auth") == 0)
+		{
+			GetAuthorizeFlag(newString[1]);
+		}
+		else if (strcmp(newString[0], "id") == 0)
+		{
+			GetOrClearId(newString[1]);
+		}
 		else if(strcmp(newString[0], "strchg") == 0)
 		{
 			//如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數

+ 137 - 24
EVSE/Projects/DS60-120/Apps/internalComm.c

@@ -38,15 +38,37 @@
 #define PASS				1
 #define FAIL				-1
 
-struct Address Addr={0x01,0x02,0x03,0x05,0xFF};
-struct Command Cmd={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x27,0x28,0x29,0x2C,0x81,0x83,
-		0x85,0x86,0x87,0x88,0x089,0x8A,0x8B,0x8C,0x90,0xe0,0xe1,0xe2,0xe3};
+struct Address Addr={0x01,0x02,0x03,0x05,0x06,0xFF};
+struct Command Cmd={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x24,0x27,0x28,0x29,0x2C,0x81,0x83,
+		0x85,0x86,0x87,0x88,0x089,0x8A,0x8B,0x8C,0x90,0x93,0xe0,0xe1,0xe2,0xe3};
+
+int tranceiveRelDelayTime(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx, unsigned short _delay)
+{
+	int len;
+	//sleep(2); //required to make flush work, for some reason
+	tcflush(fd,TCIOFLUSH);
+
+	if(write(fd, cmd, cmd_len) >= cmd_len)
+	{
+		usleep(_delay * 1000);
+		len = read(fd, rx, 512);
+	}
+	else
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+		#endif
+	}
+
+	return len;
+}
 
 int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
 {
 	int len;
 	//sleep(2); //required to make flush work, for some reason
 	tcflush(fd,TCIOFLUSH);
+
 	if(write(fd, cmd, cmd_len) >= cmd_len)
 	{
 		usleep(15000);
@@ -139,7 +161,7 @@ unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetA
 	unsigned char chksum = 0x00;
 	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
 
-	if(len > 6)
+	if(len > 13)
 	{
 		if (len < 6+(rx[4] | rx[5]<<8))
 			return result;
@@ -151,14 +173,22 @@ unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetA
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 		   (rx[2] == tx[1]) &&
 		   (rx[1] == tx[2]) &&
-		   (rx[3] == tx[3]))
+		   (rx[3] == tx[3]) &&
+		   chksum != 0)
 		{
 			Ret_Buf->inputType = rx[6];
 			Ret_Buf->L1N_L12 =(rx[7] | (rx[8]<<8))/10.0;
 			Ret_Buf->L2N_L23 =(rx[9] | (rx[10]<<8))/10.0;
 			Ret_Buf->L3N_L31 =(rx[11] | (rx[12]<<8))/10.0;
 
-			result = PASS;
+			if (Ret_Buf->L1N_L12 >= 320 ||
+					Ret_Buf->L2N_L23 >= 320 ||
+					Ret_Buf->L3N_L31 >= 320)
+			{
+				result = FAIL;
+			}
+			else
+				result = PASS;
 		}
 	}
 
@@ -444,6 +474,37 @@ unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_
 	return result;
 }
 
+unsigned char Query_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Model_Name, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			strncpy((char *)modelname, (char *)(rx + 6), (rx[4] | rx[5]<<8));
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
 unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf)
 {
 	unsigned char result = FAIL;
@@ -470,7 +531,8 @@ unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSp
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 		   (rx[2] == tx[1]) &&
 		   (rx[1] == tx[2]) &&
-		   (rx[3] == tx[3]))
+		   (rx[3] == tx[3]) &&
+		   rx[6] == PASS)
 		{
 			result = PASS;
 		}
@@ -513,7 +575,7 @@ unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Re
 		   (rx[2] == tx[1]) &&
 		   (rx[1] == tx[2]) &&
 		   (rx[3] == tx[3]) &&
-		   (rx[6] == 0x01))
+		   rx[6] == PASS)
 		{
 			result = PASS;
 		}
@@ -638,7 +700,8 @@ unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsi
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 			  (rx[2] == tx[1]) &&
 			  (rx[1] == tx[2]) &&
-			  (rx[3] == tx[3]))
+			  (rx[3] == tx[3]) &&
+			  rx[6] == PASS)
 		{
 			result = PASS;
 		}
@@ -671,7 +734,8 @@ unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *S
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 				(rx[2] == tx[1]) &&
 				(rx[1] == tx[2]) &&
-				(rx[3] == tx[3]))
+				(rx[3] == tx[3]) &&
+				rx[6] == PASS)
 		{
 			result = PASS;
 		}
@@ -832,7 +896,7 @@ unsigned char Query_AC_Status(unsigned char fd, unsigned char targetAddr, Ac_Sta
 	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_status, 0x00, 0x00, 0x00};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+	unsigned char len = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
 
 	if(len > 6)
 	{
@@ -892,7 +956,7 @@ unsigned char Query_AC_Alarm_Code(unsigned char fd, unsigned char targetAddr, Ac
 	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_alarm_code, 0x00, 0x00};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+	unsigned char len = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
 
 	if(len > 6)
 	{
@@ -923,7 +987,7 @@ unsigned char Query_Charging_Energy(unsigned char fd, unsigned char targetAddr,
 	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_output_energy, 0x00, 0x00,0x00};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+	unsigned char len = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
 
 	if(len > 6)
 	{
@@ -954,7 +1018,7 @@ unsigned char Query_Charging_Current(unsigned char fd, unsigned char targetAddr,
 	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_output_current, 0x00, 0x00, 0x00};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+	unsigned char len = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
 
 	if(len > 6)
 	{
@@ -993,7 +1057,7 @@ unsigned char Config_LED_Status(unsigned char fd, unsigned char targetAddr, Ac_L
 			chksum ^= tx[6 + idx];
 	tx[11] = chksum;
 
-	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+	if (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 0)
 	{
 		chksum = 0x00;
 		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
@@ -1004,7 +1068,8 @@ unsigned char Config_LED_Status(unsigned char fd, unsigned char targetAddr, Ac_L
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 			(rx[2] == tx[1]) &&
 			(rx[1] == tx[2]) &&
-			(rx[3] == tx[3]))
+			(rx[3] == tx[3]) &&
+			rx[6] == PASS)
 		{
 			result = PASS;
 		}
@@ -1024,7 +1089,7 @@ unsigned char Config_Legacy_Req(unsigned char fd, unsigned char targetAddr, unsi
 		chksum ^= tx[6 + idx];
 	tx[8] = chksum;
 
-	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+	if (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 0)
 	{
 		chksum = 0x00;
 		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
@@ -1035,7 +1100,8 @@ unsigned char Config_Legacy_Req(unsigned char fd, unsigned char targetAddr, unsi
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 				(rx[2] == tx[1]) &&
 				(rx[1] == tx[2]) &&
-				(rx[3] == tx[3]))
+				(rx[3] == tx[3]) &&
+				rx[6] == PASS)
 		{
 			result = PASS;
 		}
@@ -1055,7 +1121,7 @@ unsigned char Config_Ac_Duty(unsigned char fd, unsigned char targetAddr, unsigne
 		chksum ^= tx[6 + idx];
 	tx[7] = chksum;
 
-	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+	if (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 0)
 	{
 		chksum = 0x00;
 		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
@@ -1066,7 +1132,8 @@ unsigned char Config_Ac_Duty(unsigned char fd, unsigned char targetAddr, unsigne
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 				(rx[2] == tx[1]) &&
 				(rx[1] == tx[2]) &&
-				(rx[3] == tx[3]))
+				(rx[3] == tx[3]) &&
+				rx[6] == PASS)
 		{
 			result = PASS;
 		}
@@ -1086,7 +1153,7 @@ unsigned char Config_CSU_Mode(unsigned char fd, unsigned char targetAddr)
 		chksum ^= tx[6 + idx];
 	tx[7] = chksum;
 
-	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+	if (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 0)
 	{
 		chksum = 0x00;
 		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
@@ -1097,7 +1164,8 @@ unsigned char Config_CSU_Mode(unsigned char fd, unsigned char targetAddr)
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 				(rx[2] == tx[1]) &&
 				(rx[1] == tx[2]) &&
-				(rx[3] == tx[3]))
+				(rx[3] == tx[3]) &&
+				rx[6] == PASS)
 		{
 			result = PASS;
 		}
@@ -1117,7 +1185,7 @@ unsigned char Config_Reset_MCU(unsigned char fd, unsigned char targetAddr)
 		chksum ^= tx[6 + idx];
 	tx[7] = chksum;
 
-	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+	if (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 0)
 	{
 		chksum = 0x00;
 		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
@@ -1128,7 +1196,52 @@ unsigned char Config_Reset_MCU(unsigned char fd, unsigned char targetAddr)
 		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
 				(rx[2] == tx[1]) &&
 				(rx[1] == tx[2]) &&
-				(rx[3] == tx[3]))
+				(rx[3] == tx[3]) &&
+				rx[6] == PASS)
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Led_Color(unsigned char fd, unsigned char targetAddr, Led_Color *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[13] = {0xaa, 0x00, targetAddr, Cmd.config_led_color, 0x06, 0x00,
+			Ret_Buf->Connect_1_Red, Ret_Buf->Connect_1_Green, Ret_Buf->Connect_1_Blue,
+			Ret_Buf->Connect_2_Red, Ret_Buf->Connect_2_Green, Ret_Buf->Connect_2_Blue};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+		chksum ^= tx[6 + idx];
+	tx[13] = chksum;
+
+//	for(int i = 0; i < 13; i++)
+//			printf ("tx = %x \n", tx[i]);
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+//	for(int i = 0; i < len; i++)
+//		printf ("rx = %x \n", rx[i]);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+			  (rx[2] == tx[1]) &&
+			  (rx[1] == tx[2]) &&
+			  (rx[3] == tx[3]) &&
+			  (rx[6] == PASS))
 		{
 			result = PASS;
 		}

+ 16 - 0
EVSE/Projects/DS60-120/Apps/internalComm.h

@@ -14,6 +14,7 @@ extern struct Address
 	unsigned char Fan;
 	unsigned char Relay;
 	unsigned char AcPlug;
+	unsigned char Led;
 	unsigned char Broadcast;
 }Addr;
 
@@ -30,6 +31,7 @@ extern struct Command
 	unsigned char query_Gfd_Adc;				//0x09
 	unsigned char query_Gpio_In;				//0x0a
 
+	unsigned char query_Model_Name;				//0x24
 	unsigned char query_ac_output_current;		//0x27
 	unsigned char query_ac_status;				//0x28
 	unsigned char query_ac_alarm_code;			//0x29
@@ -50,6 +52,8 @@ extern struct Command
 
 	unsigned char config_csu_mode;			//0x90
 
+	unsigned char config_led_color;			//0x93
+
 	unsigned char update_Start;				//0xe0
 	unsigned char update_Abort;				//0xe1
 	unsigned char update_Transfer;				//0xe2
@@ -182,6 +186,16 @@ typedef struct RTC
 	unsigned char RtcData[14];
 }Rtc;
 
+typedef struct LED_Color
+{
+	unsigned char Connect_1_Red;
+	unsigned char Connect_1_Green;
+	unsigned char Connect_1_Blue;
+	unsigned char Connect_2_Red;
+	unsigned char Connect_2_Green;
+	unsigned char Connect_2_Blue;
+}Led_Color;
+
 typedef struct AC_Status
 {
 	unsigned char 		CpStatus;
@@ -235,6 +249,7 @@ extern unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targ
 extern unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf);
 extern unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf);
 extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
+extern unsigned char Query_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
 
 extern unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf);
 extern unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf);
@@ -257,4 +272,5 @@ extern unsigned char Config_Legacy_Req(unsigned char fd, unsigned char targetAdd
 extern unsigned char Config_Ac_Duty(unsigned char fd, unsigned char targetAddr, unsigned char _value);
 extern unsigned char Config_CSU_Mode(unsigned char fd, unsigned char targetAddr);
 extern unsigned char Config_Reset_MCU(unsigned char fd, unsigned char targetAddr);
+extern unsigned char Config_Led_Color(unsigned char fd, unsigned char targetAddr, Led_Color *Ret_Buf);
 #endif /* INTERNALCOMM_H_ */

+ 1 - 0
EVSE/Projects/DS60-120/Apps/kill.sh

@@ -8,5 +8,6 @@ pkill Module_PsuComm
 pkill Module_4g
 pkill Module_Wifi
 pkill OcppBackend
+pkill Module_ProduceUtils
 pkill main
 

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


Dosya farkı çok büyük olduğundan ihmal edildi
+ 445 - 116
EVSE/Projects/DS60-120/Apps/main.c


+ 1 - 0
EVSE/Projects/DS60-120/Apps/timeout.c

@@ -3,3 +3,4 @@
 //===============================================
 // Initial Callback function
 //===============================================
+

+ 10 - 1
EVSE/Projects/DS60-120/Apps/timeout.h

@@ -32,6 +32,8 @@
 #include	<ctype.h>
 #include 	<ifaddrs.h>
 
+#define CONN_PLUG_TIME_OUT			40
+
 enum Timeout_flag
 {
 	Timeout_None =						0,
@@ -46,8 +48,15 @@ enum Timeout_flag
 	Timeout_EvseChargingDet = 			8,
 	Timeout_EvseCompleteDet = 			9,
 	Timeout_ForCcsPrechargeDet = 		10,
-	Timeout_ReturnToChargingGunDet = 	11
+	Timeout_ReturnToChargingGunDet = 	11,
+	Timeout_AuthorizingForStop = 		12
 };
 
+// for timeout fork
+struct timeval _cmdSubPriority_time;
+unsigned short _connectionTimeout;
+
+// for main
+struct timeval _cmdMainPriority_time;
 struct timeval _toAverage_time;
 #endif /* TIMEOUT_H_ */

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor