Bladeren bron

2021-05-06

Actions
1. Fix the problem that the default getway disappears when the Ethernet is deleted
2. Remove the pre-charge relay function
3. The system supports detecting the connector temperature (OTP) - only CCS
4. Modify the OCPP structure
5. When stop by swipe, if the number is wrong then show verification failed
6. Fix the problem of charging profile with incorrect output power
7. Soft reset one time if the self-test was failure
8. Use the psu communication function to check the AC contact status
9. Modify the upgrade structure
10. Update the file system from jffs2 to ubifs
11. LCM supports obtaining FW version
12. Change the status to maintenance be fore resetting the system
13. If a psu error occurs, the AC contactor will be forcibly disconnected for 30s
14. Support press button to stop charging
15. System Optimization

Files
1. As follow commit history.
Alston 3 jaren geleden
bovenliggende
commit
6dc568e313

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

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

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


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


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

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

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


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


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

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

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

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

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


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

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

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


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


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

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

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


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

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

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


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


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

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

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


BIN
EVSE/rootfs/root/Module_Payment


BIN
EVSE/rootfs/root/OcppBackend20