Przeglądaj źródła

2020-10-20 / Eason Yang
Action
1. Merge : merge AW-Regular fixed issue.

File
1. As follow by commit history.
2. Upgrade items please check AW-Regular V0.53.XX.XXXX.XX -> V0.60.XX.XXXX.XX .

Noodoe Image : V0.45.XX.XXXX.XX

8009 4 lat temu
rodzic
commit
a594f9a4e7

+ 21 - 2
EVSE/Projects/Noodoe/Apps/Makefile

@@ -7,8 +7,27 @@ Lib_Module_Upgrade = "-L../../../Modularization" -lModule_Upgrade
 Lib_SQLite3 = "-L../../../Modularization/ocppfiles" -lsqlite3
 
 all: CopyFile apps
-apps: Module_InternalComm_Task Module_FactoryConfig_Task Module_AlarmDetect_Task Module_CSU_Task Module_Speaker_Task
+apps: Module_InternalComm_Task Module_FactoryConfig_Task Module_AlarmDetect_Task Module_CSU_Task Module_Speaker_Task Module_ConfigTools_Task Module_Debug_Task
 
+Module_ConfigTools_Task:
+	@echo "===== Module_ConfigTools_Task  ==================================="
+	rm -f Module_ConfigTools
+	rm -f Module_InternalComm
+	$(CC) -D $(Project) "-I../../" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_ConfigTools.o "./Module_ConfigTools.c"
+	$(CC) -o Module_ConfigTools Module_ConfigTools.o
+	rm -f *.o
+	mv -f Module_ConfigTools ../Images/root
+	@echo \
+
+Module_Debug_Task:
+	@echo "===== Module_Debug_Task  ==================================="
+	rm -f Module_Debug
+	rm -f Module_Debug
+	$(CC) -D $(Project) "-I../../" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_Debug.o "./Module_Debug.c"
+	$(CC) -o Module_Debug Module_Debug.o
+	rm -f *.o
+	mv -f Module_Debug ../Images/root
+	@echo \
 
 Module_InternalComm_Task:
 	@echo "===== Module_InternalComm_Task ==================================="
@@ -61,7 +80,7 @@ Module_CSU_Task:
 	@echo \
 
 Module_Speaker_Task:
-	@echo "===== Module_Speaker_Task ===================================="
+	@echo "===== Module_Speaker_Task ======================================="
 	rm -f Module_Speaker
 	$(CC) -D $(Project) "-I../../"  -O0 -g3 -Wall -c -fmessage-length=0 -o Module_Speaker.o  "./Module_Speaker.c"
 	$(CC) -o Module_Speaker Module_Speaker.o 

+ 61 - 59
EVSE/Projects/Noodoe/Apps/Module_AlarmDetect.c

@@ -80,6 +80,7 @@ int StoreLogMsg(const char *fmt, ...)
 	char buffer[4096];
 	time_t CurrentTime;
 	struct tm *tm;
+	struct timeval tv;
 	va_list args;
 
 	va_start(args, fmt);
@@ -89,11 +90,12 @@ int StoreLogMsg(const char *fmt, ...)
 	memset(Buf,0,sizeof(Buf));
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
 
 	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
 	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
 					buffer,
 					tm->tm_year+1900,tm->tm_mon+1,
 					ShmSysConfigAndInfo->SysConfig.ModelName,
@@ -101,8 +103,8 @@ int StoreLogMsg(const char *fmt, ...)
 	}
 	else
 	{
-		sprintf(Buf,"echo -n \"[%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,
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%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,tv.tv_usec,
 					buffer,
 					tm->tm_year+1900,tm->tm_mon+1);
 	}
@@ -112,7 +114,7 @@ int StoreLogMsg(const char *fmt, ...)
 #endif
 
 #ifdef ConsloePrintLog
-	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
 #endif
 
 	return rc;
@@ -176,14 +178,14 @@ int InitShareMemory()
    	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
 	{
 
-		DEBUG_ERROR("shmget ShmCharger NG\r\n");
+		DEBUG_ERROR("shmget ShmCharger NG\n");
 
 		result = FAIL;
 	}
 	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
 
-		DEBUG_ERROR("shmat ShmCharger NG\r\n");
+		DEBUG_ERROR("shmat ShmCharger NG\n");
 
 		result = FAIL;
 	}
@@ -194,14 +196,14 @@ int InitShareMemory()
 	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
 	{
 
-		DEBUG_ERROR("shmget ShmOCPP16Data NG\r\n");
+		DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
 
 		result = FAIL;
 	}
 	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
 
-		DEBUG_ERROR("shmat ShmOCPP16Data NG\r\n");
+		DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
 
 		result = FAIL;
 	}
@@ -272,7 +274,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
-						DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \n");
 					}
 				}
 				else
@@ -287,7 +289,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
-					DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+					DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \n");
 				}
 			}
 
@@ -301,7 +303,7 @@ int main(void)
 						{
 							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = ON;
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
-							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \n");
 						}
 					}
 					else
@@ -316,7 +318,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = OFF;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
-						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \n");
 					}
 				}
 
@@ -328,7 +330,7 @@ int main(void)
 						{
 							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = ON;
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
-							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \n");
 						}
 					}
 					else
@@ -343,7 +345,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = OFF;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
-						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \n");
 					}
 				}
 			}
@@ -359,7 +361,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
-						DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \n");
 					}
 				}
 				else
@@ -374,7 +376,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
-					DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+					DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \n");
 				}
 			}
 
@@ -388,7 +390,7 @@ int main(void)
 						{
 							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = ON;
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
-							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \n");
 						}
 					}
 					else
@@ -403,7 +405,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = OFF;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
-						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \n");
 					}
 				}
 
@@ -415,7 +417,7 @@ int main(void)
 						{
 							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = ON;
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
-							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \n");
 						}
 					}
 					else
@@ -430,7 +432,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = OFF;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
-						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \n");
 					}
 				}
 			}
@@ -444,7 +446,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
-					DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+					DEBUG_INFO("ALARM_OVER_CURRENT : alarm \n");
 				}
 			}
 			else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
@@ -453,7 +455,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
-					DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+					DEBUG_INFO("ALARM_OVER_CURRENT : recover \n");
 				}
 			}
 
@@ -465,7 +467,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
-						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \n");
 					}
 				}
 				else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
@@ -474,7 +476,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
-						DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+						DEBUG_INFO("ALARM_OVER_CURRENT : recover \n");
 					}
 				}
 
@@ -484,7 +486,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
-						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \n");
 					}
 				}
 				else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
@@ -493,7 +495,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
-						DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+						DEBUG_INFO("ALARM_OVER_CURRENT : recover \n");
 					}
 				}
 			}
@@ -509,7 +511,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_TEMPERATURE;
-						DEBUG_INFO("ALARM_OVER_TEMPERATURE : alarm \r\n");
+						DEBUG_INFO("ALARM_OVER_TEMPERATURE : alarm \n");
 					}
 				}
 				else
@@ -524,7 +526,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_TEMPERATURE;
-					DEBUG_INFO("ALARM_OVER_TEMPERATURE : recover \r\n");
+					DEBUG_INFO("ALARM_OVER_TEMPERATURE : recover \n");
 				}
 			}
 
@@ -539,7 +541,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_GROUND_FAIL;
-						DEBUG_INFO("ALARM_GROUND_FAIL : alarm \r\n");
+						DEBUG_INFO("ALARM_GROUND_FAIL : alarm \n");
 					}
 				}
 				else
@@ -554,7 +556,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_GROUND_FAIL;
-					DEBUG_INFO("ALARM_GROUND_FAIL : recover \r\n");
+					DEBUG_INFO("ALARM_GROUND_FAIL : recover \n");
 				}
 			}
 
@@ -569,7 +571,7 @@ int main(void)
 					{
 						ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CP_ERROR;
-						DEBUG_INFO("ALARM_CP_ERROR : alarm \r\n");
+						DEBUG_INFO("ALARM_CP_ERROR : alarm \n");
 					}
 				}
 				else
@@ -584,7 +586,7 @@ int main(void)
 				{
 					ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CP_ERROR;
-					DEBUG_INFO("ALARM_CP_ERROR : recover \r\n");
+					DEBUG_INFO("ALARM_CP_ERROR : recover \n");
 				}
 			}
 
@@ -603,13 +605,13 @@ int main(void)
 						{
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
 							ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = ON;
-							DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \r\n");
+							DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \n");
 						}
 						else if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
 						{
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
 							ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = ON;
-							DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \r\n");
+							DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \n");
 						}
 					}
 				}
@@ -629,13 +631,13 @@ int main(void)
 					{
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
 						ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = OFF;
-						DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \r\n");
+						DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \n");
 					}
 					else if(ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage == ON)
 					{
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
 						ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = OFF;
-						DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
+						DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \n");
 					}
 				}
 			}
@@ -651,7 +653,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_MCU_TESTFAIL;
-						DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \r\n");
+						DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \n");
 					}
 				}
 				else
@@ -666,7 +668,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_MCU_TESTFAIL;
-					DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \r\n");
+					DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \n");
 				}
 			}
 
@@ -679,7 +681,7 @@ int main(void)
 				{
 					ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  = ON;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_HANDSHAKE_TIMEOUT;
-					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : alarm \r\n");
+					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : alarm \n");
 				}
 
 			}
@@ -689,7 +691,7 @@ int main(void)
 				{
 					ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_HANDSHAKE_TIMEOUT;
-					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : recover \r\n");
+					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : recover \n");
 				}
 			}
 
@@ -704,7 +706,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_EMERGENCY_STOP;
-						DEBUG_INFO("ALARM_EMERGENCY_STOP : alarm \r\n");
+						DEBUG_INFO("ALARM_EMERGENCY_STOP : alarm \n");
 					}
 				}
 				else
@@ -719,7 +721,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_EMERGENCY_STOP;
-					DEBUG_INFO("ALARM_EMERGENCY_STOP : recover \r\n");
+					DEBUG_INFO("ALARM_EMERGENCY_STOP : recover \n");
 				}
 			}
 
@@ -734,7 +736,7 @@ int main(void)
 					{
 						ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_WELDING;
-						DEBUG_INFO("ALARM_RELAY_STATUS : alarm \r\n");
+						DEBUG_INFO("ALARM_RELAY_STATUS : alarm \n");
 					}
 				}
 				else
@@ -749,7 +751,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_WELDING;
-					DEBUG_INFO("ALARM_RELAY_STATUS : recover \r\n");
+					DEBUG_INFO("ALARM_RELAY_STATUS : recover \n");
 				}
 			}
 
@@ -764,7 +766,7 @@ int main(void)
 					{
 						ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_DRIVE_FAULT;
-						DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : alarm \r\n");
+						DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : alarm \n");
 					}
 				}
 				else
@@ -779,7 +781,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_DRIVE_FAULT;
-					DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : recover \r\n");
+					DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : recover \n");
 				}
 			}
 
@@ -794,7 +796,7 @@ int main(void)
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_SHORT;
-						DEBUG_INFO("ALARM_CIRCUIT_SHORT : alarm \r\n");
+						DEBUG_INFO("ALARM_CIRCUIT_SHORT : alarm \n");
 					}
 				}
 				else
@@ -809,7 +811,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_SHORT;
-					DEBUG_INFO("ALARM_CIRCUIT_SHORT : recover \r\n");
+					DEBUG_INFO("ALARM_CIRCUIT_SHORT : recover \n");
 				}
 			}
 
@@ -822,7 +824,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = ON;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_ROTATORY_SWITCH_FAULT;
-					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \r\n");
+					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \n");
 				}
 			}
 			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT))
@@ -831,7 +833,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_ROTATORY_SWITCH_FAULT;
-					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \r\n");
+					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \n");
 				}
 			}
 
@@ -844,7 +846,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = ON;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LEAK_MODULE_FAIL;
-					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \r\n");
+					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \n");
 				}
 			}
 			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL))
@@ -853,7 +855,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LEAK_MODULE_FAIL;
-					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \r\n");
+					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \n");
 				}
 			}
 
@@ -866,7 +868,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = ON;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_SHUTTER_FAULT;
-					DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \r\n");
+					DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \n");
 				}
 			}
 			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT))
@@ -875,7 +877,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_SHUTTER_FAULT;
-					DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \r\n");
+					DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \n");
 				}
 			}
 
@@ -888,7 +890,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = ON;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LOCKER_FAULT;
-					DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \r\n");
+					DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \n");
 				}
 			}
 			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT))
@@ -897,7 +899,7 @@ int main(void)
 				{
 					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LOCKER_FAULT;
-					DEBUG_INFO("ALARM_LOCKER_FAULT : recover \r\n");
+					DEBUG_INFO("ALARM_LOCKER_FAULT : recover \n");
 				}
 			}
 
@@ -910,7 +912,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = ON;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_POWER_DROP;
-					DEBUG_INFO("ALARM_POWER_DROP : alarm \r\n");
+					DEBUG_INFO("ALARM_POWER_DROP : alarm \n");
 				}
 			}
 			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP))
@@ -919,7 +921,7 @@ int main(void)
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = OFF;
 					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_POWER_DROP;
-					DEBUG_INFO("ALARM_POWER_DROP : recover \r\n");
+					DEBUG_INFO("ALARM_POWER_DROP : recover \n");
 				}
 			}
 

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

@@ -0,0 +1,568 @@
+/*
+ * Module_ConfigTools.c
+ *
+ *  Created on: 2020年6月22日
+ *      Author: foluswen
+ */
+
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+#include	<dirent.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	<stdbool.h>
+#include	<stddef.h>
+#include	<stdint.h>
+#include 	"define.h"
+
+//=================================
+// System basic sample constant
+//=================================
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+#define ARRAY_SIZE(A)					(sizeof(A) / sizeof(A[0]))
+#define PASS							1
+#define FAIL							-1
+#define YES								1
+#define NO								0
+#define ON								1
+#define OFF								0
+#define MtdBlockSize 					0x600000
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData			*ShmStatusCodeData;
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	struct timeval tv;
+	va_list args;
+
+	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);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]ConfigToolsLog",
+				tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+				buffer,
+				tm->tm_year+1900,tm->tm_mon+1);
+
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
+#endif
+
+	return rc;
+}
+
+int runShellCmd(const char*cmd)
+{
+	int result = FAIL;
+	char buf[256];
+	FILE *fp;
+
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			DEBUG_INFO("%s\n", buf);
+		}
+
+		result = PASS;
+	}
+	pclose(fp);
+
+	return result;
+}
+
+int StoreUsrConfigData(struct SysConfigData *UsrData)
+{
+	int result = PASS;
+	int fd,wrd;
+	unsigned int i,Chk;
+	unsigned char *ptr, *BufTmp;
+
+	Chk=0;
+	ptr=(unsigned char *)UsrData;
+	if((BufTmp=malloc(MtdBlockSize))!=NULL)
+	{
+		memset(BufTmp,0,MtdBlockSize);
+		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
+		for(i=0;i<MtdBlockSize-4;i++)
+			Chk+=*(BufTmp+i);
+		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
+
+		// Output configuration to file.
+		fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
+		if (fd < 0)
+		{
+			DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
+
+			free(BufTmp);
+			return 0;
+		}
+		wrd=write(fd, BufTmp, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
+
+			free(BufTmp);
+			return 0;
+		}
+		DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
+
+
+		DEBUG_INFO("Erase /dev/mtd10.\n");
+		runShellCmd("flash_erase /dev/mtd10 0 12");
+		DEBUG_INFO("Write /dev/mtd10.\n");
+		runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
+
+		DEBUG_INFO("Erase /dev/mtd11.\n");
+		runShellCmd("flash_erase /dev/mtd11 0 12");
+		DEBUG_INFO("Write /dev/mtd11.\n");
+		runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
+
+
+		system("rm -f /mnt/EvseConfig.bin");
+		DEBUG_INFO("EvseConfig write to flash OK\n");
+	}
+	else
+	{
+		DEBUG_ERROR("alloc BlockSize NG\r\n");
+    		result = FAIL;
+	}
+
+	if(BufTmp!=NULL)
+		free(BufTmp);
+
+	return result;
+}
+
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//Initial ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//Initial ShmStatusCodeData
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	return result;
+}
+
+int main(void)
+{
+	char cmd[128];
+
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO("InitShareMemory OK.\r\n");
+	}
+
+
+	for(;;)
+	{
+		system("clear");
+		memset(cmd, 0x00, ARRAY_SIZE(cmd));
+		printf("\n ===== main menu ===================================");
+		printf("\n  system: system configuration menu.");
+		printf("\n  ocpp: ocpp configuration menu.");
+		printf("\n  network: netwok configuration menu.");
+		printf("\n  upgrade: trigger firmware upgrade.");
+		printf("\n  save: Save config.");
+		printf("\n  exit: Exit config tools.");
+		printf("\n =================================================");
+		printf("\n  Please input item name to config: ");
+		scanf("%s", &cmd[0]);
+
+
+		if(strcmp(cmd, "system") == 0)
+		{
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n ***** system configuration menu ******************");
+			printf("\n  modelname: EVSE model name.");
+			printf("\n  serialnumber: EVSE serial number.");
+			printf("\n *************************************************");
+			printf("\n  Please input operation item: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "modelname") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current model name: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new model name.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n Please input model name: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.ModelName[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ModelName[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "serialnumber") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current serial number: %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new serial number.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n Please input serial number: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], (char*)&cmd[0]);
+				}
+			}
+		}
+		else if(strcmp(cmd, "ocpp") == 0)
+		{
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n *************************************************");
+			printf("\n  ocppurl: OCPP backend server url.");
+			printf("\n  cboxid: Charger box id.");
+			printf("\n *************************************************");
+			printf("\n  Please input operation item: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "ocppurl") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current OCPP url: %s", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new ocpp url.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n Please input ocpp url: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.OcppServerURL[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "cboxid") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current OCPP charger box id: %s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new charger box id.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input OCPP charger box id: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
+				}
+			}
+		}
+		else if(strcmp(cmd, "network") == 0)
+		{
+			memset(cmd, 0x00, ARRAY_SIZE(cmd));
+			printf("\n *************************************************");
+			printf("\n  ethdhcp: Ethernet DHCP client.");
+			printf("\n  wifimode: WiFi mode.");
+			printf("\n  wifidhcp: WiFi DHCP client.");
+			printf("\n  wificssid: WiFi client SSID.");
+			printf("\n  wificpasswd: WiFi client password.");
+			printf("\n  telemode: Telecomm mode.");
+			printf("\n  teleapn: Telecomm APN.");
+			printf("\n  teleid: Telecomm login id.");
+			printf("\n  telepwd: Telecomm login password.");
+			printf("\n *************************************************");
+			printf("\n  Please input operation item: ");
+			scanf("%s", &cmd[0]);
+
+			if(strcmp(cmd, "ethdhcp") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Enable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current ethernet dhcp mode: %d", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1);
+				printf("\n  Please input dhcp mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
+			}
+			else if(strcmp(cmd, "wifimode") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Station.");
+				printf("\n  2: Access point.");
+				printf("\n *************************************************");
+
+				printf("\n  Current WiFi mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
+				printf("\n  Please input WiFi mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode = ((0<=atoi(cmd))&&(atoi(cmd)<=2)?atoi(cmd):0);
+			}
+			else if(strcmp(cmd, "wifidhcp") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Enable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current WiFi dhcp client mode: %d", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1);
+				printf("\n  Please input WiFi mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
+			}
+			else if(strcmp(cmd, "wificssid") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current WiFi client SSID: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new WiFi client SSID.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input WiFi client SSID: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "wificpasswd") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current WiFi client password: %s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new WiFi client password.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input WiFi client password: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "telemode") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Enable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current telecomm mode: %d", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode^1);
+				printf("\n  Please input telecomm mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd)^1:0);
+			}
+			else if(strcmp(cmd, "teleapn") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current telecomm APN: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new telecomm APN.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input telecomm APN: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "teleid") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current telecomm login id: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new telecomm login id.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input telecomm login id: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "telepwd") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current telecomm login password: %s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new telecomm login password.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input telecomm login password: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd[0], (char*)&cmd[0]);
+				}
+			}
+		}
+		else if(strcmp(cmd, "upgrade") == 0)
+		{
+			printf("\n  Firmware upgrade trigger.");
+
+			ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = ON;
+
+			sleep(2);
+		}
+		else if(strcmp(cmd, "save") == 0)
+		{
+			if(StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig) != PASS)
+			{
+				printf("\n  Write configuration fail.\r\n");
+			}
+			else
+				printf("\n  Write configuration OK.\r\n");
+
+			sleep(2);
+		}
+		else if(strcmp(cmd, "exit") == 0)
+		{
+			printf("\n  exit program.\n\n");
+			return FAIL;
+		}
+	}
+
+
+
+	return -1;
+}
+
+
+
+

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

@@ -0,0 +1,235 @@
+#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 	<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 	<math.h>
+#include	"define.h"
+#include	"main.h"
+
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				0
+#define ON					1
+#define OFF					0
+
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct Charger					*ShmCharger;
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	struct timeval tv;
+	va_list args;
+
+	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);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_Debug",
+				tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+				buffer,
+				tm->tm_year+1900,tm->tm_mon+1);
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
+#endif
+
+	return rc;
+}
+
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//Initial ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//Initial ShmStatusCodeData
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//Initial ShmCharger
+	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+
+	return result;
+}
+
+void wait()
+{
+	printf("\n Please press any key then \"Enter\" to continue.");
+	while(getchar() =='\n') usleep(100000);
+}
+
+int main(void)
+{
+	char cmd[128];
+
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO("InitShareMemory OK.\r\n");
+	}
+
+	for(;;)
+	{
+		system("clear");
+		memset(cmd, 0x00, ARRAY_SIZE(cmd));
+		printf("\n ============== Debug main menu ==================");
+		printf("\n  info: List charger status info.");
+		printf("\n  exit: Exit Module_Debug_Test.");
+		printf("\n =================================================");
+		printf("\n  Please input debug command: ");
+		scanf("%s", &cmd[0]);
+
+		if(strcmp(cmd, "info") == 0)
+		{
+			uint8_t isExit = FALSE;
+			int gun_index;
+
+			do
+			{
+				system("clear");
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n ***************** Info menu *********************");
+				printf("\n  csu: charger info");
+				printf("\n  mcu: mcu request state");
+				printf("\n  exit: exit to previous menu.");
+				printf("\n *************************************************");
+				printf("\n  Please input info need to query: ");
+				scanf("%s", &cmd[0]);
+
+				if(strcmp(cmd, "csu") == 0)
+				{
+					printf("\n  Please input gun index: ");
+					scanf("%d", &gun_index);
+					printf("\n CSU info.\n\n");
+
+					gun_index = gun_index<AC_QUANTITY?gun_index:0;
+
+					printf("\n  Charger connector plug times: %d", ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+					printf("\n  CP positive voltage: %.2f", ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive);
+					printf("\n  CP negative voltage: %.2f", ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative);
+					printf("\n  CSU to MCU legacyRequest: %d", ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
+					printf("\n  CSU to MCU relay on request: %d", ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn);
+					printf("\n  Charger charging mode BS/HLC: %d", ShmCharger->gun_info[gun_index].chargingMode);
+					printf("\n  Charger input voltage L1: %.2f", ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
+					printf("\n  CSU output current L1: %.2f", ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
+					printf("\n  CSU temperature: %d", ShmCharger->gun_info[gun_index].temperature.point[0]);
+
+					wait();
+				}
+				else if(strcmp(cmd, "mcu") == 0)
+				{
+					printf("\n  Please input gun index: ");
+					scanf("%d", &gun_index);
+					printf("\n  MCU info.\n\n");
+
+
+
+					wait();
+				}
+				else if(strcmp(cmd, "exit") == 0)
+				{
+					printf("\n  Exit to previous.\n\n");
+					isExit = TRUE;
+				}
+			}while(!isExit);
+		}
+		else if(strcmp(cmd, "exit") == 0)
+		{
+			printf("\n  exit program.\n\n");
+			return FAIL;
+		}
+	}
+
+	return FAIL;
+}

+ 87 - 95
EVSE/Projects/Noodoe/Apps/Module_FactoryConfig.c

@@ -57,6 +57,7 @@ int StoreLogMsg(const char *fmt, ...)
 	char buffer[4096];
 	time_t CurrentTime;
 	struct tm *tm;
+	struct timeval tv;
 	va_list args;
 
 	va_start(args, fmt);
@@ -66,17 +67,32 @@ int StoreLogMsg(const char *fmt, ...)
 	memset(Buf,0,sizeof(Buf));
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/%04d-%02d_%s_%s_SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1,
-			SysConfig.ModelName,
-			SysConfig.SerialNumber);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
+	{
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+					buffer,
+					tm->tm_year+1900,tm->tm_mon+1,
+					ShmSysConfigAndInfo->SysConfig.ModelName,
+					ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	}
+	else
+	{
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%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,tv.tv_usec,
+					buffer,
+					tm->tm_year+1900,tm->tm_mon+1);
+	}
+
 #ifdef SystemLogMessage
 	system(Buf);
 #endif
 
-	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
+#endif
 
 	return rc;
 }
@@ -145,6 +161,26 @@ void split(char **arr, char *str, const char *del)
 	}
 }
 
+int runShellCmd(const char*cmd)
+{
+	int result = FAIL;
+	char buf[256];
+	FILE *fp;
+
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			DEBUG_INFO("%s\n", buf);
+		}
+
+		result = PASS;
+	}
+	pclose(fp);
+
+	return result;
+}
 
 //==========================================
 // Init all share memory
@@ -191,12 +227,12 @@ int InitShareMemory()
 
 void helpOutput(void)
 {
-	printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
-	printf("Generate factory default configuration value\r\n\r\n");
-	printf("OPTION:\r\n");
-	printf("	-a Write to file(/mnt) & flash\r\n");
-	printf("	-f Write to file(/mnt)\r\n");
-	printf("	-m Write to flash\r\n");
+	printf("Usage: Module_FactoryConfig [OPTION]...\n\n");
+	printf("Generate factory default configuration value\n\n");
+	printf("OPTION:\n");
+	printf("	-a Write to file(/mnt) & flash\n");
+	printf("	-f Write to file(/mnt)\n");
+	printf("	-m Write to flash\n");
 }
 
 //================================================
@@ -232,16 +268,16 @@ int main(int argc, char *argv[])
 	{
 		DEBUG_ERROR("InitShareMemory NG\n");
 
-		strcpy((char*)SysConfig.ModelName,"");
-		strcpy((char*)SysConfig.SerialNumber,"");
+		strcpy((char*)SysConfig.ModelName, "");
+		strcpy((char*)SysConfig.SerialNumber, "");
 		sleep(5);
 	}
 	else
 	{
-		memcpy((char*)SysConfig.ModelName,ShmSysConfigAndInfo->SysConfig.ModelName,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
-		memcpy((char*)SysConfig.SerialNumber,ShmSysConfigAndInfo->SysConfig.SerialNumber,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+		memcpy((char*)SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+		memcpy((char*)SysConfig.SerialNumber, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
 
-		DEBUG_INFO("InitShareMemory OK.\r\n");
+		DEBUG_INFO("InitShareMemory OK.\n");
 	}
 	
 	sprintf((char*)SysConfig.SystemId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
@@ -300,7 +336,7 @@ int main(int argc, char *argv[])
 	{
 		Chk+=*(ptr+i);
 	}
-	memcpy(	ptr+MtdBlockSize-4,&Chk,4);
+	memcpy(ptr+MtdBlockSize-4, &Chk, 4);
 
 	/*
 	 * Parameter process
@@ -341,98 +377,54 @@ int main(int argc, char *argv[])
 	/*
 	 * Configuration bin file generate
 	 */
-	if((outType&OUTPUT_FILE)>0)
+	// Save factory default setting value to file
+	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
+	if (fd < 0)
 	{
-		// Save factory default setting value to file
-		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
-		if (fd < 0)
-		{
 
-			DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\r\n");
+		DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\n");
 
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\r\n");
-
-			free(ptr);
-			return 0;
-		}
+		free(ptr);
+		return 0;
+	}
+	wrd=write(fd, ptr, MtdBlockSize);
+	close(fd);
+	if(wrd<MtdBlockSize)
+	{
+		DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\n");
 
-		DEBUG_INFO("FactoryConfig write to file in /mnt OK.\r\n");
+		free(ptr);
+		return 0;
 	}
 
+	DEBUG_INFO("FactoryConfig write to file in /mnt OK.\n");
+
+
 	/*
 	 * Flash memory write
 	 */
 	if((outType&OUTPUT_FLASH)>0)
 	{
-		// Save factory default setting value to flash factory default setting block
-		fd = open("/dev/mtdblock12", O_RDWR);
-		if (fd < 0)
-		{
-
-			DEBUG_ERROR("open /dev/mtdblock12 NG\r\n");
+		DEBUG_INFO("Erase /dev/mtd10.\n");
+		runShellCmd("flash_erase /dev/mtd10 0 12");
+		DEBUG_INFO("Write /dev/mtd10.\n");
+		runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
 
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			DEBUG_ERROR("write /dev/mtdblock12 NG\r\n");
+		DEBUG_INFO("Erase /dev/mtd11.\n");
+		runShellCmd("flash_erase /dev/mtd11 0 12");
+		DEBUG_INFO("Write /dev/mtd11.\n");
+		runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
 
-			free(ptr);
-			return 0;
-		}
+		DEBUG_INFO("Erase /dev/mtd12.\n");
+		runShellCmd("flash_erase /dev/mtd12 0 12");
+		DEBUG_INFO("Write /dev/mtd12.\n");
+		runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
 
-		// Save factory default setting value to flash backup setting block
-		fd = open("/dev/mtdblock11", O_RDWR);
-		if (fd < 0)
-		{
-			DEBUG_ERROR("open /dev/mtdblock11 NG\r\n");
+		system("rm -f /mnt/FactoryDefaultConfig.bin");
 
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			DEBUG_ERROR("write /dev/mtdblock11 NG\r\n");
-
-			free(ptr);
-			return 0;
-		}
-
-		// Save factory default setting value to flash setting block
-		fd = open("/dev/mtdblock10", O_RDWR);
-		if (fd < 0)
-		{
-			DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
-
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
-
-			free(ptr);
-			return 0;
-		}
-
-		DEBUG_INFO("FactoryConfig write to flash OK\r\n");
+		DEBUG_INFO("FactoryConfig write to flash OK\n");
 	}
-
 	free(ptr);
 
-	return FAIL;
+	return PASS;
 }

+ 169 - 177
EVSE/Projects/Noodoe/Apps/Module_InternalComm.c

@@ -67,6 +67,7 @@ int StoreLogMsg(const char *fmt, ...)
 	char buffer[4096];
 	time_t CurrentTime;
 	struct tm *tm;
+	struct timeval tv;
 	va_list args;
 
 	va_start(args, fmt);
@@ -76,30 +77,19 @@ int StoreLogMsg(const char *fmt, ...)
 	memset(Buf,0,sizeof(Buf));
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
 
-	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
-	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-					buffer,
-					tm->tm_year+1900,tm->tm_mon+1,
-					ShmSysConfigAndInfo->SysConfig.ModelName,
-					ShmSysConfigAndInfo->SysConfig.SerialNumber);
-	}
-	else
-	{
-		sprintf(Buf,"echo -n \"[%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,
-					buffer,
-					tm->tm_year+1900,tm->tm_mon+1);
-	}
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_InterComm",
+				tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+				buffer,
+				tm->tm_year+1900,tm->tm_mon+1);
 
 #ifdef SystemLogMessage
 	system(Buf);
 #endif
 
 #ifdef ConsloePrintLog
-	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
 #endif
 
 	return rc;
@@ -221,14 +211,14 @@ int InitShareMemory()
 	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
 	{
 		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\r\n");
+		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
 		#endif
 		result = FAIL;
 	}
 	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
 		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\r\n");
+		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
 		#endif
 		result = FAIL;
 	}
@@ -255,14 +245,14 @@ int InitShareMemory()
 	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
 	{
 		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
+		DEBUG_ERROR("shmget ShmChargerKey NG\n");
 		#endif
 		result = FAIL;
 	}
 	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
 		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
+		DEBUG_ERROR("shmat ShmChargerKey NG\n");
 		#endif
 		result = FAIL;
 	}
@@ -1758,7 +1748,7 @@ int main(void)
 	}
 	else
 	{
-		DEBUG_INFO("InitShareMemory OK.\r\n");
+		DEBUG_INFO("InitShareMemory OK.\n");
 	}
 
 	Uart1Fd=InitComPort();
@@ -1774,7 +1764,7 @@ int main(void)
 	}
 	else
 	{
-		DEBUG_INFO("ttyS1 port open success.\r\n");
+		DEBUG_INFO("ttyS1 port open success.\n");
 	}
 
 	for(;;)
@@ -1800,7 +1790,7 @@ int main(void)
 				}
 				else
 				{
-					DEBUG_WARN("MCU-%d set led fail...%d\r\n", gun_index, failCount[gun_index]);
+					DEBUG_WARN("MCU-%d set led fail...%d\n", gun_index, failCount[gun_index]);
 					if(failCount[gun_index]<1000)
 					{
 						failCount[gun_index]++;
@@ -1816,7 +1806,7 @@ int main(void)
 				}
 				else
 				{
-					DEBUG_WARN("MCU-%d set relay request fail...%d\r\n", gun_index, failCount[gun_index]);
+					DEBUG_WARN("MCU-%d set relay request fail...%d\n", gun_index, failCount[gun_index]);
 					if(failCount[gun_index]<1000)
 					{
 						failCount[gun_index]++;
@@ -1838,7 +1828,7 @@ int main(void)
 				}
 				else
 				{
-					DEBUG_WARN("MCU-%d get status fail...%d\r\n", gun_index, failCount[gun_index]);
+					DEBUG_WARN("MCU-%d get status fail...%d\n", gun_index, failCount[gun_index]);
 					if(failCount[gun_index]<1000)
 					{
 						failCount[gun_index]++;
@@ -1850,7 +1840,7 @@ int main(void)
 				//===============================
 				if(Query_AC_MCU_Alarm(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuAlarm))
 				{
-					//DEBUG_INFO("MCU-%d get alarm code success.\r\n",gun_index);
+					//DEBUG_INFO("MCU-%d get alarm code success.\n",gun_index);
 
 					//================================================
 					// Byte[6]
@@ -1971,7 +1961,7 @@ int main(void)
 				}
 				else
 				{
-					DEBUG_WARN("MCU-%d get alarm fail...%d\r\n", gun_index, failCount[gun_index]);
+					DEBUG_WARN("MCU-%d get alarm fail...%d\n", gun_index, failCount[gun_index]);
 					if(failCount[gun_index]<1000)
 					{
 						failCount[gun_index]++;
@@ -1991,7 +1981,7 @@ int main(void)
 				}
 				else
 				{
-					DEBUG_WARN("MCU-%d get ble config fail...%d\r\n", gun_index, failCount[gun_index]);
+					DEBUG_WARN("MCU-%d get ble config fail...%d\n", gun_index, failCount[gun_index]);
 					if(failCount[gun_index]<1000)
 					{
 						failCount[gun_index]++;
@@ -2009,7 +1999,7 @@ int main(void)
 				}
 				else
 				{
-					DEBUG_WARN("MCU-%d get ble login central id fail...%d\r\n", gun_index, failCount[gun_index]);
+					DEBUG_WARN("MCU-%d get ble login central id fail...%d\n", gun_index, failCount[gun_index]);
 					if(failCount[gun_index]<1000)
 					{
 						failCount[gun_index]++;
@@ -2025,10 +2015,10 @@ int main(void)
 					{
 						if(Config_AC_MCU_RESET_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].mcuResetRequest) == PASS)
 						{
-							DEBUG_INFO("**************************************************\r\n");
-							DEBUG_INFO("********* High priority polling : Case 7 *********\r\n");
-							DEBUG_INFO("**************************************************\r\n");
-							DEBUG_INFO("MCU-%d set MCU reset Request : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest);
+							DEBUG_INFO("**************************************************\n");
+							DEBUG_INFO("********* High priority polling : Case 7 *********\n");
+							DEBUG_INFO("**************************************************\n");
+							DEBUG_INFO("MCU-%d set MCU reset Request : %d\n", gun_index, ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest);
 
 							ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest = OFF;
 
@@ -2036,7 +2026,7 @@ int main(void)
 						}
 						else
 						{
-							DEBUG_WARN("MCU-%d get MCU reset fail...%d\r\n", gun_index, failCount[gun_index]);
+							DEBUG_WARN("MCU-%d get MCU reset fail...%d\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
 							{
 								failCount[gun_index]++;
@@ -2066,39 +2056,39 @@ int main(void)
 					//===============================
 					// Config primary MCU LED
 					//===============================
-					DEBUG_INFO("**************************************************\r\n");
-					DEBUG_INFO("********* High priority polling : Case 1 *********\r\n");
-					DEBUG_INFO("**************************************************\r\n");
-					DEBUG_INFO("MCU-%d set Led mode : %d\r\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.mode);
-					DEBUG_INFO("MCU-%d set Alarm code : %x\r\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code);
+					DEBUG_INFO("**************************************************\n");
+					DEBUG_INFO("********* High priority polling : Case 1 *********\n");
+					DEBUG_INFO("**************************************************\n");
+					DEBUG_INFO("MCU-%d set Led mode : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.mode);
+					DEBUG_INFO("MCU-%d set Alarm code : %x\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code);
 
 					//===============================
 					// Config primary Legacy request
 					//===============================
-					DEBUG_INFO("**************************************************\r\n");
-					DEBUG_INFO("********* High priority polling : Case 2 *********\r\n");
-					DEBUG_INFO("**************************************************\r\n");
-					DEBUG_INFO("MCU-%d set relay request : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
+					DEBUG_INFO("**************************************************\n");
+					DEBUG_INFO("********* High priority polling : Case 2 *********\n");
+					DEBUG_INFO("**************************************************\n");
+					DEBUG_INFO("MCU-%d set relay request : %d\n", gun_index, ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
 
 					//===============================
 					// Query primary MCU status
 					//===============================
-					DEBUG_INFO("**************************************************\r\n");
-					DEBUG_INFO("********* High priority polling : Case 3 *********\r\n");
-					DEBUG_INFO("**************************************************\r\n");
-					DEBUG_INFO("MCU-%d get Pilot State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
-					DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
-					DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
-					DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
-					DEBUG_INFO("MCU-%d get Relay State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
-					DEBUG_INFO("MCU-%d get Rating Current : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
-					DEBUG_INFO("MCU-%d get Rotary switch : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
+					DEBUG_INFO("**************************************************\n");
+					DEBUG_INFO("********* High priority polling : Case 3 *********\n");
+					DEBUG_INFO("**************************************************\n");
+					DEBUG_INFO("MCU-%d get Pilot State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
+					DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
+					DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
+					DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
+					DEBUG_INFO("MCU-%d get Relay State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
+					DEBUG_INFO("MCU-%d get Rating Current : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
+					DEBUG_INFO("MCU-%d get Rotary switch : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
 
 					/*
-					DEBUG_INFO("MCU-%d get Locker State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
-					DEBUG_INFO("MCU-%d get Shutter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
-					DEBUG_INFO("MCU-%d get Meter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
-					DEBUG_INFO("MCU-%d get PP State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
+					DEBUG_INFO("MCU-%d get Locker State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
+					DEBUG_INFO("MCU-%d get Shutter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
+					DEBUG_INFO("MCU-%d get Meter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
+					DEBUG_INFO("MCU-%d get PP State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
 										*/
 
 					//===============================
@@ -2106,29 +2096,29 @@ int main(void)
 					//===============================
 					if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode>0))
 					{
-						DEBUG_INFO("**************************************************\r\n");
-						DEBUG_INFO("********* High priority polling : Case 4 *********\r\n");
-						DEBUG_INFO("**************************************************\r\n");
-						DEBUG_INFO("MCU-%d get OVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP);
-						DEBUG_INFO("MCU-%d get UVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP);
-						DEBUG_INFO("MCU-%d get OCP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP);
-						DEBUG_INFO("MCU-%d get OTP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
-						DEBUG_INFO("MCU-%d get gmi_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
-						DEBUG_INFO("MCU-%d get cp_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
-						DEBUG_INFO("MCU-%d get ac_leak : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
-						DEBUG_INFO("MCU-%d get dc_leak : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
-						DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
-						DEBUG_INFO("MCU-%d get handshaking_timeout : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
-						DEBUG_INFO("MCU-%d get emergency_stop : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
-						DEBUG_INFO("MCU-%d get relay_welding : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
-						DEBUG_INFO("MCU-%d get leak_module_fail : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
-						DEBUG_INFO("MCU-%d get shutter_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
-						DEBUG_INFO("MCU-%d get locker_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
-						DEBUG_INFO("MCU-%d get power_drop : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
-						DEBUG_INFO("MCU-%d get circuit_short : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.circuit_short);
-						DEBUG_INFO("MCU-%d get set_circuit : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.set_circuit);
-						DEBUG_INFO("MCU-%d get relay_drive_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
-						DEBUG_INFO("MCU-%d get InputAlarmCode : %x\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
+						DEBUG_INFO("**************************************************\n");
+						DEBUG_INFO("********* High priority polling : Case 4 *********\n");
+						DEBUG_INFO("**************************************************\n");
+						DEBUG_INFO("MCU-%d get OVP : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP);
+						DEBUG_INFO("MCU-%d get UVP : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP);
+						DEBUG_INFO("MCU-%d get OCP : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP);
+						DEBUG_INFO("MCU-%d get OTP : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
+						DEBUG_INFO("MCU-%d get gmi_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
+						DEBUG_INFO("MCU-%d get cp_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
+						DEBUG_INFO("MCU-%d get ac_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
+						DEBUG_INFO("MCU-%d get dc_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
+						DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
+						DEBUG_INFO("MCU-%d get handshaking_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
+						DEBUG_INFO("MCU-%d get emergency_stop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
+						DEBUG_INFO("MCU-%d get relay_welding : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
+						DEBUG_INFO("MCU-%d get leak_module_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
+						DEBUG_INFO("MCU-%d get shutter_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
+						DEBUG_INFO("MCU-%d get locker_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
+						DEBUG_INFO("MCU-%d get power_drop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
+						DEBUG_INFO("MCU-%d get circuit_short : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.circuit_short);
+						DEBUG_INFO("MCU-%d get set_circuit : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.set_circuit);
+						DEBUG_INFO("MCU-%d get relay_drive_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
+						DEBUG_INFO("MCU-%d get InputAlarmCode : %x\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
 					}
 
 					//===============================
@@ -2136,12 +2126,12 @@ int main(void)
 					//===============================
 					if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin == ON)
 					{
-						DEBUG_INFO("**************************************************\r\n");
-						DEBUG_INFO("********* High priority polling : Case 5 *********\r\n");
-						DEBUG_INFO("**************************************************\r\n");
-						DEBUG_INFO("MCU-%d get isUserLogin : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
-						DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
-						DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
+						DEBUG_INFO("**************************************************\n");
+						DEBUG_INFO("********* High priority polling : Case 5 *********\n");
+						DEBUG_INFO("**************************************************\n");
+						DEBUG_INFO("MCU-%d get isUserLogin : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
+						DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
+						DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
 					}
 
 					//===============================
@@ -2149,10 +2139,10 @@ int main(void)
 					//===============================
 					if(strcmp((char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id,"") != 0)
 					{
-						DEBUG_INFO("**************************************************\r\n");
-						DEBUG_INFO("********* High priority polling : Case 6 *********\r\n");
-						DEBUG_INFO("**************************************************\r\n");
-						DEBUG_INFO("MCU-%d get ble central id : %s\r\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
+						DEBUG_INFO("**************************************************\n");
+						DEBUG_INFO("********* High priority polling : Case 6 *********\n");
+						DEBUG_INFO("**************************************************\n");
+						DEBUG_INFO("MCU-%d get ble central id : %s\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
 					}
 
 					usleep(100000);
@@ -2184,7 +2174,7 @@ int main(void)
 						}
 						else
 						{
-							DEBUG_WARN("MCU-%d get input voltage fail...%d\r\n", gun_index, failCount[gun_index]);
+							DEBUG_WARN("MCU-%d get input voltage fail...%d\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
 							{
 								failCount[gun_index]++;
@@ -2206,7 +2196,7 @@ int main(void)
 						}
 						else
 						{
-							DEBUG_WARN("MCU-%d get output current fail...%d\r\n", gun_index, failCount[gun_index]);
+							DEBUG_WARN("MCU-%d get output current fail...%d\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
 							{
 								failCount[gun_index]++;
@@ -2225,7 +2215,7 @@ int main(void)
 						}
 						else
 						{
-							DEBUG_WARN("MCU-%d get gun plugin times fail...%d\r\n", gun_index, failCount[gun_index]);
+							DEBUG_WARN("MCU-%d get gun plugin times fail...%d\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
 							{
 								failCount[gun_index]++;
@@ -2245,7 +2235,7 @@ int main(void)
 						}
 						else
 						{
-							DEBUG_WARN("MCU-%d get temperature fail...%d\r\n", gun_index, failCount[gun_index]);
+							DEBUG_WARN("MCU-%d get temperature fail...%d\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
 							{
 								failCount[gun_index]++;
@@ -2265,7 +2255,7 @@ int main(void)
 							}
 							else
 							{
-								DEBUG_WARN("MCU-%d set cp pwn duty fail...%d\r\n", gun_index, failCount[gun_index]);
+								DEBUG_WARN("MCU-%d set cp pwn duty fail...%d\n", gun_index, failCount[gun_index]);
 								if(failCount[gun_index]<1000)
 								{
 									failCount[gun_index]++;
@@ -2326,7 +2316,7 @@ int main(void)
 						}
 						else
 						{
-							DEBUG_WARN("MCU-%d get rtc fail...%d\r\n", gun_index, failCount[gun_index]);
+							DEBUG_WARN("MCU-%d get rtc fail...%d\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
 							{
 								failCount[gun_index]++;
@@ -2343,7 +2333,7 @@ int main(void)
 						}
 						else
 						{
-							DEBUG_WARN("MCU-%d get power consumption fail...%d\r\n", gun_index, failCount[gun_index]);
+							DEBUG_WARN("MCU-%d get power consumption fail...%d\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
 							{
 								failCount[gun_index]++;
@@ -2356,21 +2346,21 @@ int main(void)
 						//===============================
 						if(ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq)
 						{
-							DEBUG_INFO("==================================================\r\n");
-							DEBUG_INFO("======== Normal priority polling : Case 15 =======\r\n");
-							DEBUG_INFO("==================================================\r\n");
+							DEBUG_INFO("==================================================\n");
+							DEBUG_INFO("======== Normal priority polling : Case 15 =======\n");
+							DEBUG_INFO("==================================================\n");
 
 							unsigned char cmd[512];
 							if(Upgrade_UART(Uart1Fd, AC_WALLMOUNT_CONTROLLER, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), ShmCharger->fwUpgradeInfo.location, ShmCharger->fwUpgradeInfo.modelName))
 							{
-								DEBUG_INFO("MCU-%d upgrade firmware OK...%s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
+								DEBUG_INFO("MCU-%d upgrade firmware OK...%s\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
 								sleep(20);
 								ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq = OFF;
 								failCount[gun_index] = 0;
 							}
 							else
 							{
-								DEBUG_WARN("MCU-%d upgrade firmware fail...%d\r\n", gun_index, failCount[gun_index]);
+								DEBUG_WARN("MCU-%d upgrade firmware fail...%d\n", gun_index, failCount[gun_index]);
 								if(failCount[gun_index]<1000)
 								{
 									failCount[gun_index]++;
@@ -2393,7 +2383,7 @@ int main(void)
 							}
 							else
 							{
-								DEBUG_WARN("MCU-%d set breathe led timing fail...%d\r\n", gun_index, failCount[gun_index]);
+								DEBUG_WARN("MCU-%d set breathe led timing fail...%d\n", gun_index, failCount[gun_index]);
 								if(failCount[gun_index]<1000)
 								{
 									failCount[gun_index]++;
@@ -2413,7 +2403,7 @@ int main(void)
 							}
 							else
 							{
-								DEBUG_WARN("MCU-%d set led brightness fail...%d\r\n", gun_index, failCount[gun_index]);
+								DEBUG_WARN("MCU-%d set led brightness fail...%d\n", gun_index, failCount[gun_index]);
 								if(failCount[gun_index]<1000)
 								{
 									failCount[gun_index]++;
@@ -2427,12 +2417,12 @@ int main(void)
 						//===============================
 						if(ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass != PASS)
 						{
-							DEBUG_INFO("==================================================\r\n");
-							DEBUG_INFO("======== Normal priority polling : Case 21-1======\r\n");
-							DEBUG_INFO("==================================================\r\n");
+							DEBUG_INFO("==================================================\n");
+							DEBUG_INFO("======== Normal priority polling : Case 21-1======\n");
+							DEBUG_INFO("==================================================\n");
 							if(Query_FW_Ver(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].ver) == PASS)
 							{
-								DEBUG_INFO("MCU-%d get firmware version : %s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
+								DEBUG_INFO("MCU-%d get firmware version : %s\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
 								memcpy(ShmPrimaryMcuData->version, ShmCharger->gun_info[gun_index].ver.Version_FW, sizeof(ShmPrimaryMcuData->version));
 								ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass = PASS;
 
@@ -2440,7 +2430,7 @@ int main(void)
 							}
 							else
 							{
-								DEBUG_WARN("MCU-%d get firmware version fail...%d\r\n", gun_index, failCount[gun_index]);
+								DEBUG_WARN("MCU-%d get firmware version fail...%d\n", gun_index, failCount[gun_index]);
 								if(failCount[gun_index]<1000)
 								{
 									failCount[gun_index]++;
@@ -2453,20 +2443,20 @@ int main(void)
 						//===============================
 						if(ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass != PASS)
 						{
-							DEBUG_INFO("==================================================\r\n");
-							DEBUG_INFO("======== Normal priority polling : Case 21-2======\r\n");
-							DEBUG_INFO("==================================================\r\n");
+							DEBUG_INFO("==================================================\n");
+							DEBUG_INFO("======== Normal priority polling : Case 21-2======\n");
+							DEBUG_INFO("==================================================\n");
 							memcpy(ShmCharger->evseId.serial_number, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmCharger->evseId.serial_number));
 							if(Config_Serial_Number(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
 							{
-								DEBUG_INFO("MCU-%d set serial number : %.12s\r\n",gun_index,ShmCharger->evseId.serial_number);
+								DEBUG_INFO("MCU-%d set serial number : %.12s\n",gun_index,ShmCharger->evseId.serial_number);
 								ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass = PASS;
 
 								failCount[gun_index] = 0;
 							}
 							else
 							{
-								DEBUG_WARN("MCU-%d set serial number fail...%d\r\n", gun_index, failCount[gun_index]);
+								DEBUG_WARN("MCU-%d set serial number fail...%d\n", gun_index, failCount[gun_index]);
 								if(failCount[gun_index]<1000)
 								{
 									failCount[gun_index]++;
@@ -2479,20 +2469,20 @@ int main(void)
 						//===============================
 						if(ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass != PASS)
 						{
-							DEBUG_INFO("==================================================\r\n");
-							DEBUG_INFO("======== Normal priority polling : Case 21-3======\r\n");
-							DEBUG_INFO("==================================================\r\n");
+							DEBUG_INFO("==================================================\n");
+							DEBUG_INFO("======== Normal priority polling : Case 21-3======\n");
+							DEBUG_INFO("==================================================\n");
 							memcpy(ShmCharger->evseId.model_name, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmCharger->evseId.model_name));
 							if(Config_Model_Name(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
 							{
-								DEBUG_INFO("MCU-%d set model name : %.14s\r\n",gun_index,ShmCharger->evseId.model_name);
+								DEBUG_INFO("MCU-%d set model name : %.14s\n",gun_index,ShmCharger->evseId.model_name);
 								ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass = PASS;
 
 								failCount[gun_index] = 0;
 							}
 							else
 							{
-								DEBUG_WARN("MCU-%d set model name fail...%d\r\n", gun_index, failCount[gun_index]);
+								DEBUG_WARN("MCU-%d set model name fail...%d\n", gun_index, failCount[gun_index]);
 								if(failCount[gun_index]<1000)
 								{
 									failCount[gun_index]++;
@@ -2512,48 +2502,48 @@ int main(void)
 				{
 					if(stepIndex == 1)
 					{
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("======== Normal priority polling : Case 1 ========\r\n");
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("MCU-%d get input voltage : %f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
-						DEBUG_INFO("MCU-%d get PresentChargingVoltage : %.2f\r\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage);
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("======== Normal priority polling : Case 1 ========\n");
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("MCU-%d get input voltage : %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
+						DEBUG_INFO("MCU-%d get PresentChargingVoltage : %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage);
 					}
 					else if(stepIndex == 3)
 					{
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("======== Normal priority polling : Case 3 ========\r\n");
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("MCU-%d get output current : %f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("======== Normal priority polling : Case 3 ========\n");
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("MCU-%d get output current : %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
 					}
 					else if(stepIndex == 5)
 					{
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("======== Normal priority polling : Case 5 ========\r\n");
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("MCU-%d get gun plugin times : %ld\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("======== Normal priority polling : Case 5 ========\n");
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("MCU-%d get gun plugin times : %ld\n", gun_index, (long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
 					}
 					else if(stepIndex == 7)
 					{
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("======== Normal priority polling : Case 7 ========\r\n");
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("MCU-%d get temperature : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].temperature.point[0]);
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("======== Normal priority polling : Case 7 ========\n");
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("MCU-%d get temperature : %d\n", gun_index, ShmCharger->gun_info[gun_index].temperature.point[0]);
 					}
 					else if(stepIndex == 9)
 					{
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("======== Normal priority polling : Case 9 ========\r\n");
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("MCU-%d set cp pwn duty : %d\r\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("======== Normal priority polling : Case 9 ========\n");
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("MCU-%d set cp pwn duty : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
 					}
 					else if(stepIndex == 11)
 					{
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("======== Normal priority polling : Case 11 =======\r\n");
-						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("======== Normal priority polling : Case 11 =======\n");
+						DEBUG_INFO("==================================================\n");
 						if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin && !ShmOCPP16Data->OcppConnStatus)
 						{
-							DEBUG_INFO("Sync from MCU-%d rtc OK...%04d-%02d-%02d %02d:%02d:%02d\r\n", gun_index,
+							DEBUG_INFO("Sync from MCU-%d rtc OK...%04d-%02d-%02d %02d:%02d:%02d\n", gun_index,
 																											  ShmCharger->gun_info[gun_index].rtc.year,
 																											  ShmCharger->gun_info[gun_index].rtc.month,
 																											  ShmCharger->gun_info[gun_index].rtc.day,
@@ -2565,7 +2555,7 @@ int main(void)
 						}
 						else
 						{
-							DEBUG_INFO("MCU-%d set rtc OK...%04d-%02d-%02d %02d:%02d:%02d\r\n", gun_index,
+							DEBUG_INFO("MCU-%d set rtc OK...%04d-%02d-%02d %02d:%02d:%02d\n", gun_index,
 																										ShmCharger->gun_info[gun_index].rtc.year,
 																										ShmCharger->gun_info[gun_index].rtc.month,
 																										ShmCharger->gun_info[gun_index].rtc.day,
@@ -2576,51 +2566,49 @@ int main(void)
 					}
 					else if(stepIndex == 13)
 					{
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("======== Normal priority polling : Case 13 =======\r\n");
-						DEBUG_INFO("==================================================\r\n");
-						DEBUG_INFO("MCU-%d get power consumption : %f kWh\r\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100));
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("======== Normal priority polling : Case 13 =======\n");
+						DEBUG_INFO("==================================================\n");
+						DEBUG_INFO("MCU-%d get power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100));
 					}
 					else if(stepIndex == 17)
 					{
 						if(ShmCharger->gun_info[gun_index].isSetBreatheLedTiming == ON)
 						{
-							DEBUG_INFO("==================================================\r\n");
-							DEBUG_INFO("======== Normal priority polling : Case 17 =======\r\n");
-							DEBUG_INFO("==================================================\r\n");
-							DEBUG_INFO("MCU-%d set breathe led timing : Authed Fade in [%ld].\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In);
-							DEBUG_INFO("MCU-%d set breathe led timing : Authed Fade out [%ld].\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out);
-							DEBUG_INFO("MCU-%d set breathe led timing : Charging Fade in [%ld].\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In);
-							DEBUG_INFO("MCU-%d set breathe led timing : Charging Fade out [%ld].\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out);
-							DEBUG_INFO("MCU-%d set breathe led timing : Connected Fade in [%ld].\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In);
-							DEBUG_INFO("MCU-%d set breathe led timing : Connected Fade out [%ld].\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out);
+							DEBUG_INFO("==================================================\n");
+							DEBUG_INFO("======== Normal priority polling : Case 17 =======\n");
+							DEBUG_INFO("==================================================\n");
+							DEBUG_INFO("MCU-%d set breathe led timing : Authed Fade in [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In);
+							DEBUG_INFO("MCU-%d set breathe led timing : Authed Fade out [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out);
+							DEBUG_INFO("MCU-%d set breathe led timing : Charging Fade in [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In);
+							DEBUG_INFO("MCU-%d set breathe led timing : Charging Fade out [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out);
+							DEBUG_INFO("MCU-%d set breathe led timing : Connected Fade in [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In);
+							DEBUG_INFO("MCU-%d set breathe led timing : Connected Fade out [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out);
 						}
 					}
 					else if(stepIndex == 19)
 					{
 						if(ShmCharger->gun_info[gun_index].isSetLedBrightness == ON)
 						{
-							DEBUG_INFO("==================================================\r\n");
-							DEBUG_INFO("======== Normal priority polling : Case 19 =======\r\n");
-							DEBUG_INFO("==================================================\r\n");
-							DEBUG_INFO("MCU-%d set led brightness Sector 01 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_1);
-							DEBUG_INFO("MCU-%d set led brightness Sector 02 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_2);
-							DEBUG_INFO("MCU-%d set led brightness Sector 03 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_3);
-							DEBUG_INFO("MCU-%d set led brightness Sector 04 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_4);
-							DEBUG_INFO("MCU-%d set led brightness Sector 05 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_5);
-							DEBUG_INFO("MCU-%d set led brightness Sector 06 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_6);
-							DEBUG_INFO("MCU-%d set led brightness Sector 07 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_7);
-							DEBUG_INFO("MCU-%d set led brightness Sector 08 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_8);
-							DEBUG_INFO("MCU-%d set led brightness Sector 09 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_9);
-							DEBUG_INFO("MCU-%d set led brightness Sector 10 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_10);
-							DEBUG_INFO("MCU-%d set led brightness Sector 11 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_11);
-							DEBUG_INFO("MCU-%d set led brightness Sector 12 : [%x].\r\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_12);
+							DEBUG_INFO("==================================================\n");
+							DEBUG_INFO("======== Normal priority polling : Case 19 =======\n");
+							DEBUG_INFO("==================================================\n");
+							DEBUG_INFO("MCU-%d set led brightness Sector 01 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_1);
+							DEBUG_INFO("MCU-%d set led brightness Sector 02 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_2);
+							DEBUG_INFO("MCU-%d set led brightness Sector 03 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_3);
+							DEBUG_INFO("MCU-%d set led brightness Sector 04 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_4);
+							DEBUG_INFO("MCU-%d set led brightness Sector 05 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_5);
+							DEBUG_INFO("MCU-%d set led brightness Sector 06 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_6);
+							DEBUG_INFO("MCU-%d set led brightness Sector 07 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_7);
+							DEBUG_INFO("MCU-%d set led brightness Sector 08 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_8);
+							DEBUG_INFO("MCU-%d set led brightness Sector 09 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_9);
+							DEBUG_INFO("MCU-%d set led brightness Sector 10 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_10);
+							DEBUG_INFO("MCU-%d set led brightness Sector 11 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_11);
+							DEBUG_INFO("MCU-%d set led brightness Sector 12 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_12);
 						}
 					}
 					else
 					{}
-
-					usleep(100000);
 				}
 			}
 			stepIndex++;
@@ -2631,7 +2619,9 @@ int main(void)
 			if(failCount[gun_index] >= FAIL_SPEC_COMM)
 			{
 				if((0 <= failCount[gun_index]%FAIL_SPEC_COMM) && (failCount[gun_index]%FAIL_SPEC_COMM < 10))
-					sleep(10);
+				{
+					system ("pkill Module_InternalComm");
+				}
 				
 				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == OFF)
 				{
@@ -2647,6 +2637,8 @@ int main(void)
 					ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout = OFF;
 				}
 			}
+
+			usleep(100000);
 		}
 	}
 

+ 13 - 11
EVSE/Projects/Noodoe/Apps/Module_Speaker.c

@@ -71,6 +71,7 @@ int StoreLogMsg(const char *fmt, ...)
 	char buffer[4096];
 	time_t CurrentTime;
 	struct tm *tm;
+	struct timeval tv;
 	va_list args;
 
 	va_start(args, fmt);
@@ -80,11 +81,12 @@ int StoreLogMsg(const char *fmt, ...)
 	memset(Buf,0,sizeof(Buf));
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
 
 	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
 	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
 					buffer,
 					tm->tm_year+1900,tm->tm_mon+1,
 					ShmSysConfigAndInfo->SysConfig.ModelName,
@@ -92,8 +94,8 @@ int StoreLogMsg(const char *fmt, ...)
 	}
 	else
 	{
-		sprintf(Buf,"echo -n \"[%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,
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%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,tv.tv_usec,
 					buffer,
 					tm->tm_year+1900,tm->tm_mon+1);
 	}
@@ -103,7 +105,7 @@ int StoreLogMsg(const char *fmt, ...)
 #endif
 
 #ifdef ConsloePrintLog
-	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
 #endif
 
 	return rc;
@@ -217,14 +219,14 @@ int InitShareMemory()
 	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
 	{
 		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
+		DEBUG_ERROR("shmget ShmChargerKey NG\n");
 		#endif
 		result = FAIL;
 	}
 	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
 	{
 		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
+		DEBUG_ERROR("shmat ShmChargerKey NG\n");
 		#endif
 		result = FAIL;
 	}
@@ -256,7 +258,7 @@ int main(void)
 			switch(ShmCharger->speaker_type)
 			{
 				case SPEAKER_STOP:
-					DEBUG_INFO("SPEAKER_STOP...\r\n");
+					DEBUG_INFO("SPEAKER_STOP...\n");
 					ShmCharger->isSpeakerOn = OFF;
 					break;
 				case SPEAKER_ALWAYS_ON:
@@ -267,7 +269,7 @@ int main(void)
 					system("echo 0 > /sys/class/gpio/gpio65/value");
 
 					ShmCharger->isSpeakerOn = OFF;
-					DEBUG_INFO("SPEAKER_SHORT...\r\n");
+					DEBUG_INFO("SPEAKER_SHORT...\n");
 					break;
 				case SPEAKER_LONG:
 					break;
@@ -279,7 +281,7 @@ int main(void)
 					system("echo 0 > /sys/class/gpio/gpio65/value");
 					
 					ShmCharger->isSpeakerOn = OFF;
-					DEBUG_INFO("SPEAKER_INTERVAL_LONG...\r\n");
+					DEBUG_INFO("SPEAKER_INTERVAL_LONG...\n");
 					break;
 				case SPEAKER_INTERVAL_3COUNT:
 					system("echo 1 > /sys/class/gpio/gpio65/value");
@@ -295,7 +297,7 @@ int main(void)
 					system("echo 0 > /sys/class/gpio/gpio65/value");
 
 					ShmCharger->isSpeakerOn = OFF;
-					DEBUG_INFO("SPEAKER_INTERVAL_3COUNT...\r\n");
+					DEBUG_INFO("SPEAKER_INTERVAL_3COUNT...\n");
 					break;
 			}
 		}

Plik diff jest za duży
+ 186 - 168
EVSE/Projects/Noodoe/Apps/main.c


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

@@ -298,6 +298,7 @@ typedef struct AC_PRIMARY_MCU_CP_PWM_DUTY
 typedef struct LEGACY_REQUEST
 {
 	unsigned char isLegacyRequest:1;
+	uint8_t isRelayOn:1;
 }Legacy_Request;
 
 typedef struct POWER_CONSUMPTION
@@ -410,6 +411,7 @@ typedef struct GUN_INFO
 	Mcu_Reset_Request								mcuResetRequest;
 	Set_Breathe_Led_Timing							setBreatheLedTiming;
 	Set_Led_Brightness								setLedBrightness;
+	uint8_t											chargingMode;
 	uint16_t										targetCurrent;
 	uint16_t										isAuthPassEnd:1;
 	uint16_t										rfidReq:1;

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


BIN
EVSE/Projects/Noodoe/Images/MLO


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


BIN
EVSE/Projects/Noodoe/Images/u-boot-spl.bin


BIN
EVSE/Projects/Noodoe/Images/u-boot.img


BIN
EVSE/Projects/Noodoe/Images/zImage


+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.version

@@ -1 +1 @@
-22
+24

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików