Browse Source

2021-03-08 / Jerry Wang

Actions:
1. Debug DoComm report alarm code issue.
2. Debug single gun and EV board can't charge when inserted into the right slot.

Files:
1. As follow commit history.
Jerry_Wang 4 years ago
parent
commit
ce941593fd
37 changed files with 4218 additions and 4398 deletions
  1. 1153 1273
      EVSE/Projects/DD360/Apps/DoComm.c
  2. 266 282
      EVSE/Projects/DD360/Apps/FactoryConfig.c
  3. 3 1
      EVSE/Projects/DD360/Apps/Makefile
  4. 1 1
      EVSE/Projects/DD360/Apps/Module_InternalComm.c
  5. 396 448
      EVSE/Projects/DD360/Apps/Module_PrimaryComm.c
  6. 1 1
      EVSE/Projects/DD360/Apps/PrimaryComm.c
  7. 24 17
      EVSE/Projects/DD360/Apps/ReDoComm.c
  8. 8 2
      EVSE/Projects/DD360/Apps/ReDoComm.h
  9. 181 148
      EVSE/Projects/DD360/Apps/ReMain.c
  10. 4 7
      EVSE/Projects/DD360/Apps/ReModule_EvComm.c
  11. 28 14
      EVSE/Projects/DD360/Apps/ReModule_InternalComm.c
  12. 2 2
      EVSE/Projects/DD360/Apps/ReModule_PrimaryComm.c
  13. BIN
      EVSE/Projects/DD360/Apps/UnsafetyOutputTask
  14. 3 3
      EVSE/Projects/DD360/Apps/main.c
  15. 1153 1273
      EVSE/Projects/DD360Audi/Apps/DoComm.c
  16. 266 282
      EVSE/Projects/DD360Audi/Apps/FactoryConfig.c
  17. 3 1
      EVSE/Projects/DD360Audi/Apps/Makefile
  18. 1 1
      EVSE/Projects/DD360Audi/Apps/Module_InternalComm.c
  19. 396 448
      EVSE/Projects/DD360Audi/Apps/Module_PrimaryComm.c
  20. 1 1
      EVSE/Projects/DD360Audi/Apps/PrimaryComm.c
  21. 24 17
      EVSE/Projects/DD360Audi/Apps/ReDoComm.c
  22. 8 2
      EVSE/Projects/DD360Audi/Apps/ReDoComm.h
  23. 181 148
      EVSE/Projects/DD360Audi/Apps/ReMain.c
  24. 4 7
      EVSE/Projects/DD360Audi/Apps/ReModule_EvComm.c
  25. 28 14
      EVSE/Projects/DD360Audi/Apps/ReModule_InternalComm.c
  26. 2 2
      EVSE/Projects/DD360Audi/Apps/ReModule_PrimaryComm.c
  27. 3 3
      EVSE/Projects/DD360Audi/Apps/main.c
  28. BIN
      EVSE/Projects/DD360Audi/Images/DDYC182V0UE2AD_ramdisk.gz
  29. BIN
      EVSE/Projects/DD360Audi/Images/ramdisk.gz
  30. 39 0
      EVSE/Projects/DD360Audi/output/.tags
  31. 39 0
      EVSE/Projects/DD360Audi/output/.tags_sorted_by_file
  32. BIN
      EVSE/Projects/DD360Audi/output/DoComm
  33. BIN
      EVSE/Projects/DD360Audi/output/FactoryConfig
  34. BIN
      EVSE/Projects/DD360Audi/output/Module_EvComm
  35. BIN
      EVSE/Projects/DD360Audi/output/Module_InternalComm
  36. BIN
      EVSE/Projects/DD360Audi/output/Module_PrimaryComm
  37. BIN
      EVSE/Projects/DD360Audi/output/main

+ 1153 - 1273
EVSE/Projects/DD360/Apps/DoComm.c

@@ -1,1372 +1,1252 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
+#include    <sys/time.h>
+#include    <sys/timeb.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
- #include <signal.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	"../../define.h"
-#include 	"Config.h"
-
-//#define Debug 
-
-#define DoIPAddress	"192.168.100.1"
-#define DoTcpPort		36000
-#define TriggerMsgeNum		20
+#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/can.h>
+#include    <linux/can/raw.h>
+#include    <linux/wireless.h>
+#include    <arpa/inet.h>
+#include    <netinet/in.h>
+#include <signal.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    "../../define.h"
+#include    "Config.h"
+
+//#define Debug
+
+#define DoIPAddress "192.168.100.1"
+#define DoTcpPort       36000
+#define TriggerMsgeNum      20
 
 int StoreLogMsg(const char *fmt, ...);
 #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)
 
-struct ApplicationPacket
-{
-	unsigned char Se;
-	unsigned char Id;
-	unsigned char Op;
-	unsigned char Len;
-	unsigned char RegisterNum;
-	unsigned char Data[250];
+struct ApplicationPacket {
+    unsigned char Se;
+    unsigned char Id;
+    unsigned char Op;
+    unsigned char Len;
+    unsigned char RegisterNum;
+    unsigned char Data[250];
 };
 
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct PsuData 				*ShmPsuData;
-struct OCPP16Data				*ShmOCPP16Data;
-struct PrimaryMcuData			*ShmPrimaryMcuData;
-int 							TcpSock=0;
-unsigned char 					PacketSe;
-struct ChargingInfoData 		*ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];	
-struct timeb  					TriggerTimeUp[2][TriggerMsgeNum];
-struct WARNING_CODE_INFO		PreSysWarningInfo;
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct PsuData              *ShmPsuData;
+struct OCPP16Data               *ShmOCPP16Data;
+struct PrimaryMcuData           *ShmPrimaryMcuData;
+int                             TcpSock = 0;
+unsigned char                   PacketSe;
+struct ChargingInfoData         *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timeb                    TriggerTimeUp[2][TriggerMsgeNum];
+struct WARNING_CODE_INFO        PreSysWarningInfo;
 int DisconnectFlag;
 
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
-
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == 1)
-	{
-		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
-			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
-		printf("%s \n", Buf);
-	}
-	else
-	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-		system(Buf);
-	}
-
-	return rc;
-}	
+    char Buf[4096 + 256];
+    char buffer[4096];
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf, 0, sizeof(Buf));
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == 1) {
+        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
+        printf("%s \n", Buf);
+    } else {
+        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
+                buffer,
+                tm->tm_year + 1900, tm->tm_mon + 1);
+        system(Buf);
+    }
+
+    return rc;
+}
 
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
-	//return milli-second
-	unsigned int StartTime,StopTime;
-	
-	StartTime=(unsigned int)ST.time;
-	StopTime=(unsigned int)ET.time;
-	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
-}	
+    //return milli-second
+    unsigned int StartTime, StopTime;
+
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
+}
 
 int InitShareMemory()
 {
-	int result = 1;
-	int MeterSMId;
-
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		result = 0;
-	}
-	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
-		result = 0;
-	}
-
-	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		result = 0;
-	}
-	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-		result = 0;
-	}
-	//creat ShmPsuData
-	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmPsuData NG \n");
-		result = 0;
-	}
-	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("shmat ShmPsuData NG \n");
-		result = 0;
-	}
-	//creat ShmOCPP16Data
-	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmOCPP16Data NG \n");
-		result = 0;
-	}
-	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
-		result = 0;
-	}
-	
-	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-		result = 0;
-	}
-	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-		result = 0;
-	}
-	return result;
+    int result = 1;
+    int MeterSMId;
+
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
+        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+        result = 0;
+    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+        result = 0;
+    }
+
+    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
+        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+        result = 0;
+    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        result = 0;
+    }
+    //creat ShmPsuData
+    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
+        DEBUG_ERROR("shmget ShmPsuData NG \n");
+        result = 0;
+    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("shmat ShmPsuData NG \n");
+        result = 0;
+    }
+    //creat ShmOCPP16Data
+    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
+        DEBUG_ERROR("shmget ShmOCPP16Data NG \n");
+        result = 0;
+    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
+        result = 0;
+    }
+
+    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
+        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+        result = 0;
+    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+        result = 0;
+    }
+    return result;
 }
 
 int CheckNetworkStatus()
 {
-	//printf("ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress=%s\n",ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);	
-	if(strstr(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,"192.168.100") != NULL)
-		return 1;
-	else
-		return 0;	
+    //printf("ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress=%s\n",ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
+    if (strstr(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, "192.168.100") != NULL) {
+        return 1;
+    } else {
+        return 0;
+    }
 }
 
 int TcpConnected()
 {
-	struct sockaddr_in dest;  
-	struct timeval tv;
-	int flag;
- 
- 	if(TcpSock>0)
- 		close(TcpSock);
- 		
-	if ((TcpSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
-	{  
-        	DEBUG_ERROR("Open TCP socket NG");
-        	return -1;
-        }
-     /*   flag=fcntl (TcpSock, F_GETFL, 0); 
-        if(flag>=0)
-        {
-        	flag |= O_NONBLOCK; 	
-        	fcntl(TcpSock,F_SETFL, flag );
-        }*/
-	tv.tv_sec = 0; 
-    	tv.tv_usec = 100000; 
-    	setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
-    	setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
-    	flag = 1;
-	setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
-    	
-	memset(&dest, 0, sizeof(dest));
-	dest.sin_family = AF_INET;   
-    	dest.sin_port = htons(DoTcpPort); 
-     	inet_aton(DoIPAddress, (struct in_addr *) &dest.sin_addr.s_addr);
- 
-	if (connect(TcpSock, (struct sockaddr *) &dest, sizeof(dest)) != 0) 
-	{
-		close(TcpSock);
-        	return -1;
-    	}
-	return TcpSock;
+    struct sockaddr_in dest;
+    struct timeval tv;
+    int flag;
+
+    if (TcpSock > 0) {
+        close(TcpSock);
+    }
+
+    if ((TcpSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+        DEBUG_ERROR("Open TCP socket NG");
+        return -1;
+    }
+    /*   flag=fcntl (TcpSock, F_GETFL, 0);
+       if(flag>=0)
+       {
+           flag |= O_NONBLOCK;
+           fcntl(TcpSock,F_SETFL, flag );
+       }*/
+    tv.tv_sec = 0;
+    tv.tv_usec = 100000;
+    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
+    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
+    flag = 1;
+    setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
+
+    memset(&dest, 0, sizeof(dest));
+    dest.sin_family = AF_INET;
+    dest.sin_port = htons(DoTcpPort);
+    inet_aton(DoIPAddress, (struct in_addr *) &dest.sin_addr.s_addr);
+
+    if (connect(TcpSock, (struct sockaddr *) &dest, sizeof(dest)) != 0) {
+        close(TcpSock);
+        return -1;
+    }
+    return TcpSock;
 }
 void AddFaultCodeToBuf(unsigned char *Code)
 {
-	if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10)
-	{
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, strlen(Code));
-		ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
-	}
+    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10) {
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, strlen(Code));
+        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
+    }
 }
 
 void RemoveFaultCodeToBuf(unsigned char *Code)
 {
-	unsigned char find = 0x01;
-	char _code[7];
-	sprintf(_code,"%s", Code);
-
-	// 把相關的錯誤碼一次移除,避免重複顯示
-	while(find)
-	{
-		find = 0x00;
-		for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-		{
-			if (find == 0x00)
-			{
-				if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0)
-				{
-					find = 0x01;
-				}
-			}
-			else
-			{
-				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-					&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
-			}
-		}
-
-		if (find)
-		{
-			ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
-		}
-	}
+    unsigned char find = 0x01;
+    char _code[7];
+    sprintf(_code, "%s", Code);
+
+    // �羓㮾�𦦵��航炊蝣潔�甈∠宏�歹��踹��滩�憿舐內
+    while (find) {
+        find = 0x00;
+        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+            if (find == 0x00) {
+                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
+                    find = 0x01;
+                }
+            } else {
+                memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
+                       &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
+            }
+        }
+
+        if (find) {
+            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+        }
+    }
 }
 
 int StatusCodeProcessing(unsigned char *StatusCode)
 {
-	unsigned char Rtn=0;
-	int ByteCount,BitCount;
-	unsigned char tmp, EventCodeTmp[7];
-	
-	if(strlen(StatusCode)!=6)
-		return 0;
-	memset(EventCodeTmp,0,sizeof(EventCodeTmp));	
-	memcpy(EventCodeTmp,StatusCode,strlen(StatusCode));
-	
-	if(*(StatusCode+1)==0x34)//alarm from power cabinet itself	
-	{
-		if(StatusCode[0]==0x30)//trigger
-		{
-			for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-			{
-				if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], EventCodeTmp, 7) == 0)
-				{
-					Rtn=1;	
-					break;
-				}	
-			}
-			if(Rtn==0)
-				AddFaultCodeToBuf(EventCodeTmp);
-			Rtn=1;	
-		}					
-		else if(StatusCode[0]==0x31)//recovery
-		{
-			RemoveFaultCodeToBuf(EventCodeTmp);
-			Rtn=1;	
-		}					
-	}
-	else
-	{		
-		switch(*(StatusCode+2))
-		{
-			case 0x31://Fault
-				for(ByteCount=0;ByteCount<(sizeof(FaultStatusCode)/6);ByteCount++)
-				{
-					if(memcmp(FaultStatusCode[ByteCount]+1, StatusCode+1, 5) == 0)
-					{
-						if(StatusCode[0]==0x30)//trigger
-							ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount/8]|=1<<(ByteCount%8);
-						else if(StatusCode[0]==0x31)//recovery
-							ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount/8]&=0<<(ByteCount%8);
-						Rtn=1;	
-						break;	
-					}	
-				}
-				break;
-			case 0x32://Alarm
-				for(ByteCount=0;ByteCount<(sizeof(AlarmStatusCode)/6);ByteCount++)
-				{
-					if(memcmp(AlarmStatusCode[ByteCount]+1, StatusCode+1, 5) == 0)
-					{
-						
-						if(StatusCode[0]==0x30)//trigger
-							ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount/8]|=1<<(ByteCount%8);
-						else if(StatusCode[0]==0x31)//recovery
-							ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount/8]&=0<<(ByteCount%8);
-						Rtn=1;
-						break;	
-					}	
-				}
-				break;
-			case 0x33://Information
-				for(ByteCount=0;ByteCount<(sizeof(InfoStatusCode)/6);ByteCount++)
-				{
-					if(memcmp(InfoStatusCode[ByteCount]+1, StatusCode+1, 5) == 0)
-					{
-						if(StatusCode[0]==0x30)//trigger
-							ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount/8]|=1<<(ByteCount%8);
-						else if(StatusCode[0]==0x31)//recovery
-							ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount/8]&=0<<(ByteCount%8);
-						Rtn=1;
-						break;	
-					}	
-				}
-				break;		
-			default:
-				break;	
-		}
-	}
-
-	return Rtn;
+    unsigned char Rtn = 0;
+    int ByteCount, BitCount;
+    unsigned char tmp, EventCodeTmp[7];
+
+    if (strlen(StatusCode) != 6) {
+        return 0;
+    }
+    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+    memcpy(EventCodeTmp, StatusCode, strlen(StatusCode));
+
+    if (*(StatusCode + 1) == 0x34) { //alarm from power cabinet itself
+        if (StatusCode[0] == 0x30) { //trigger
+            for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], EventCodeTmp, 7) == 0) {
+                    Rtn = 1;
+                    break;
+                }
+            }
+            if (Rtn == 0) {
+                AddFaultCodeToBuf(EventCodeTmp);
+            }
+            Rtn = 1;
+        } else if (StatusCode[0] == 0x31) { //recovery
+            RemoveFaultCodeToBuf(EventCodeTmp);
+            Rtn = 1;
+        }
+    } else {
+        switch (*(StatusCode + 2)) {
+        case 0x31://Fault
+            for (ByteCount = 0; ByteCount < (sizeof(FaultStatusCode) / 6); ByteCount++) {
+                if (memcmp(FaultStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
+                    if (StatusCode[0] == 0x30) { //trigger
+                        ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount / 8] |= 1 << (ByteCount % 8);
+                    } else if (StatusCode[0] == 0x31) { //recovery
+                        ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount / 8] &= 0 << (ByteCount % 8);
+                    }
+                    Rtn = 1;
+                    break;
+                }
+            }
+            break;
+        case 0x32://Alarm
+            for (ByteCount = 0; ByteCount < (sizeof(AlarmStatusCode) / 6); ByteCount++) {
+                if (memcmp(AlarmStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
+
+                    if (StatusCode[0] == 0x30) { //trigger
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount / 8] |= 1 << (ByteCount % 8);
+                    } else if (StatusCode[0] == 0x31) { //recovery
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount / 8] &= 0 << (ByteCount % 8);
+                    }
+                    Rtn = 1;
+                    break;
+                }
+            }
+            break;
+        case 0x33://Information
+            for (ByteCount = 0; ByteCount < (sizeof(InfoStatusCode) / 6); ByteCount++) {
+                if (memcmp(InfoStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
+                    if (StatusCode[0] == 0x30) { //trigger
+                        ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount / 8] |= 1 << (ByteCount % 8);
+                    } else if (StatusCode[0] == 0x31) { //recovery
+                        ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount / 8] &= 0 << (ByteCount % 8);
+                    }
+                    Rtn = 1;
+                    break;
+                }
+            }
+            break;
+        default:
+            break;
+        }
+    }
+
+    return Rtn;
 }
 
 int SendPacket(unsigned char Id, unsigned char Op, unsigned char RegNum, unsigned char DataLen, unsigned char *Data)
 {
-	int Rtn=0, PacketLen,Tmp;
-	struct ApplicationPacket SendBuffer;		
-	struct timeb ST,ET;
-	
-	memset(&SendBuffer,0,sizeof(struct ApplicationPacket));
-	SendBuffer.Se=(PacketSe++);
-	SendBuffer.Id=Id;
-	SendBuffer.Op=Op;
-	SendBuffer.Len=DataLen+1;
-	SendBuffer.RegisterNum=RegNum;
-	if(DataLen>0)
-		memcpy(SendBuffer.Data,Data,DataLen);
-	PacketLen= SendBuffer.Len+4;
-	ftime(&ST);
-	while(Rtn<PacketLen)
-	{
-		Tmp=send(TcpSock, &SendBuffer+Rtn, PacketLen-Rtn, MSG_NOSIGNAL);
-		if(Tmp>0)
-			Rtn += Tmp;
-		ftime(&ET);
-		if(DiffTimeb(ST,ET)>500)
-		{
-			DisconnectFlag++;
-			if(DisconnectFlag>=10)
-				DisconnectFlag=10;
-			#ifdef Debug
-			printf("Send Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
-			Rtn,PacketLen,PacketSe,Id,Op,RegNum);
-			#endif
-			return 0;
-		}	
-	}
-	return Rtn;
+    int Rtn = 0, PacketLen, Tmp;
+    struct ApplicationPacket SendBuffer;
+    struct timeb ST, ET;
+
+    memset(&SendBuffer, 0, sizeof(struct ApplicationPacket));
+    SendBuffer.Se = (PacketSe++);
+    SendBuffer.Id = Id;
+    SendBuffer.Op = Op;
+    SendBuffer.Len = DataLen + 1;
+    SendBuffer.RegisterNum = RegNum;
+    if (DataLen > 0) {
+        memcpy(SendBuffer.Data, Data, DataLen);
+    }
+    PacketLen = SendBuffer.Len + 4;
+    ftime(&ST);
+    while (Rtn < PacketLen) {
+        Tmp = send(TcpSock, &SendBuffer + Rtn, PacketLen - Rtn, MSG_NOSIGNAL);
+        if (Tmp > 0) {
+            Rtn += Tmp;
+        }
+        ftime(&ET);
+        if (DiffTimeb(ST, ET) > 500) {
+            DisconnectFlag++;
+            if (DisconnectFlag >= 10) {
+                DisconnectFlag = 10;
+            }
+#ifdef Debug
+            printf("Send Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
+                   Rtn, PacketLen, PacketSe, Id, Op, RegNum);
+#endif
+            return 0;
+        }
+    }
+    return Rtn;
 }
 
 int RecvPacket(unsigned char *DataLen, struct ApplicationPacket *Packet)
-{	 
-	int Rtn=0, Tmp;
-	unsigned char TmpBuf[250];	
-	struct timeb ST,ET;
-	
-	memset(Packet,0,sizeof(struct ApplicationPacket));
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	ftime(&ST);
-	while(Rtn<5)
-	{
-		Tmp=recv(TcpSock, TmpBuf+Rtn, 5-Rtn, 0);
-		if(Tmp>0)
-			Rtn+=Tmp;
-		ftime(&ET);
-		if(DiffTimeb(ST,ET)>500)
-		{
-			DisconnectFlag++;
-			if(DisconnectFlag>=10)
-				DisconnectFlag=10;
-			#ifdef Debug
-			printf("Recv Packet header Timeout(%d/5)(disconnect count=%d): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
-			Rtn,DisconnectFlag,TmpBuf[0],TmpBuf[1],TmpBuf[2],TmpBuf[3],TmpBuf[4]);
-			#endif
-			return 0;
-		}	
-	}
-	if((TmpBuf[0]>255)/*||(TmpBuf[1]>2)*/||(TmpBuf[2]>3)||(TmpBuf[3]>250))
-	{
-		DEBUG_INFO("Recv Wrong Packet header (%d/5): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
-		Rtn,TmpBuf[0],TmpBuf[1],TmpBuf[2],TmpBuf[3],TmpBuf[4]);
-		return 0;
-	}	
-	memcpy(Packet,TmpBuf,5);
-	*DataLen=Packet->Len -1;
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	Rtn=0;
-	ftime(&ST);
-	while(Rtn<*DataLen)
-	{
-		Tmp=recv(TcpSock, TmpBuf+Rtn, *DataLen-Rtn, 0);
-		if(Tmp>0)
-			Rtn+=Tmp;
-		ftime(&ET);
-		if(DiffTimeb(ST,ET)>500)
-		{
-			DEBUG_INFO("Recv Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
-			Rtn,*DataLen,Packet->Se,Packet->Id,Packet->Op,Packet->RegisterNum);
-			return 0;
-		}	
-	}
-	memcpy(Packet->Data,TmpBuf,*DataLen);
-	DisconnectFlag=0;
-	return Rtn;
+{
+    int Rtn = 0, Tmp;
+    unsigned char TmpBuf[250];
+    struct timeb ST, ET;
+
+    memset(Packet, 0, sizeof(struct ApplicationPacket));
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    ftime(&ST);
+    while (Rtn < 5) {
+        Tmp = recv(TcpSock, TmpBuf + Rtn, 5 - Rtn, 0);
+        if (Tmp > 0) {
+            Rtn += Tmp;
+        }
+        ftime(&ET);
+        if (DiffTimeb(ST, ET) > 500) {
+            DisconnectFlag++;
+            if (DisconnectFlag >= 10) {
+                DisconnectFlag = 10;
+            }
+#ifdef Debug
+            printf("Recv Packet header Timeout(%d/5)(disconnect count=%d): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
+                   Rtn, DisconnectFlag, TmpBuf[0], TmpBuf[1], TmpBuf[2], TmpBuf[3], TmpBuf[4]);
+#endif
+            return 0;
+        }
+    }
+    if ((TmpBuf[0] > 255)/*||(TmpBuf[1]>2)*/ || (TmpBuf[2] > 3) || (TmpBuf[3] > 250)) {
+        DEBUG_INFO("Recv Wrong Packet header (%d/5): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
+                   Rtn, TmpBuf[0], TmpBuf[1], TmpBuf[2], TmpBuf[3], TmpBuf[4]);
+        return 0;
+    }
+    memcpy(Packet, TmpBuf, 5);
+    *DataLen = Packet->Len - 1;
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    Rtn = 0;
+    ftime(&ST);
+    while (Rtn < *DataLen) {
+        Tmp = recv(TcpSock, TmpBuf + Rtn, *DataLen - Rtn, 0);
+        if (Tmp > 0) {
+            Rtn += Tmp;
+        }
+        ftime(&ET);
+        if (DiffTimeb(ST, ET) > 500) {
+            DEBUG_INFO("Recv Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
+                       Rtn, *DataLen, Packet->Se, Packet->Id, Packet->Op, Packet->RegisterNum);
+            return 0;
+        }
+    }
+    memcpy(Packet->Data, TmpBuf, *DataLen);
+    DisconnectFlag = 0;
+    return Rtn;
 }
 
 int WriteModelName()
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	
-	memcpy(TmpBuf, ShmSysConfigAndInfo->SysConfig.ModelName,strlen(ShmSysConfigAndInfo->SysConfig.ModelName));
-	Tmp=(unsigned char)(ShmPrimaryMcuData->InputDet.bits.Key2<<2|ShmPrimaryMcuData->InputDet.bits.Key1<<1|ShmPrimaryMcuData->InputDet.bits.Key0);
-	TmpBuf[strlen(ShmSysConfigAndInfo->SysConfig.ModelName)]=Tmp;//Dispenser switch value
-	#ifdef Debug
-	printf("WriteModelName(%s)(%d) => ",ShmSysConfigAndInfo->SysConfig.ModelName,Tmp);
-	#endif		
-	if(SendPacket(0xFF, 0x02, 0x01,strlen(ShmSysConfigAndInfo->SysConfig.ModelName)+1, TmpBuf)<=0)
-	{	
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif			
-		return -1;	
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{
-		#ifdef Debug
-		printf("NG\n");
-		#endif		
-		return -1;
-	}
-	#ifdef Debug
-	printf("OK\n");
-	#endif	
-	return 1;
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+
+    memcpy(TmpBuf, ShmSysConfigAndInfo->SysConfig.ModelName, strlen(ShmSysConfigAndInfo->SysConfig.ModelName));
+    Tmp = (unsigned char)(ShmPrimaryMcuData->InputDet.bits.Key2 << 2 | ShmPrimaryMcuData->InputDet.bits.Key1 << 1 | ShmPrimaryMcuData->InputDet.bits.Key0);
+    TmpBuf[strlen(ShmSysConfigAndInfo->SysConfig.ModelName)] = Tmp; //Dispenser switch value
+#ifdef Debug
+    printf("WriteModelName(%s)(%d) => ", ShmSysConfigAndInfo->SysConfig.ModelName, Tmp);
+#endif
+    if (SendPacket(0xFF, 0x02, 0x01, strlen(ShmSysConfigAndInfo->SysConfig.ModelName) + 1, TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf("OK\n");
+#endif
+    return 1;
 }
 
 int ReadConnectorID()
 {
-	unsigned char Tmp=0;
-	struct ApplicationPacket PacketData;
-	
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	#ifdef Debug
-	printf("ReadConnectorID => ");	
-	#endif		
-	if(SendPacket(0xFF, 0x01, 0x02,0, PacketData.Data)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;	
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf("OK (Left connector ID = %d, Right connector ID = %d)\n", PacketData.Data[1], PacketData.Data[2]);	
-	#endif			
-	return 1;
+    unsigned char Tmp = 0;
+    struct ApplicationPacket PacketData;
+
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+#ifdef Debug
+    printf("ReadConnectorID => ");
+#endif
+    if (SendPacket(0xFF, 0x01, 0x02, 0, PacketData.Data) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf("OK (Left connector ID = %d, Right connector ID = %d)\n", PacketData.Data[1], PacketData.Data[2]);
+#endif
+    return 1;
 }
 
 int ReadDoStatus()
 {
-	unsigned char Tmp=0, count,Rtn;
-	struct ApplicationPacket PacketData;
-	unsigned char StatusArray[20][6];
-	unsigned char EventCodeTmp[7];
-	
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	memset(StatusArray,0,sizeof(StatusArray));
-	#ifdef Debug
-	printf("ReadDoStatus => ");	
-	#endif	
-	if(SendPacket(0x01, 0x01, 0x03,0, PacketData.Data)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	Tmp--;//decrase OK/NG byte
-	if(Tmp<6)	
-	{
-		if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount>0)
-		{
-			for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-			{
-				if(ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1]>=0x33)//from backend or power cabinet
-				{
-					memset(EventCodeTmp,0,sizeof(EventCodeTmp));	
-					memcpy(EventCodeTmp,ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],sizeof(EventCodeTmp));	
-					RemoveFaultCodeToBuf(EventCodeTmp);
-				}
-			}
-		}
-		#ifdef Debug
-		printf("no alarm (%d)\n",Tmp);
-		#endif		
-		return -1;	
-	}
-	#ifdef Debug
-	printf("OK, (%d) ",Tmp);
-	//printf("PacketData.Se=%d\n",PacketData.Se);
-	//printf("PacketData.Id=%d\n",PacketData.Id);
-	//printf("PacketData.Op=%d\n",PacketData.Op);
-	//printf("PacketData.Len=%d\n",PacketData.Len);
-	//printf("PacketData.RegisterNum=%d\n",PacketData.RegisterNum);
-	//for(Rtn=0;Rtn<=PacketData.Len-1;Rtn++)
-		//printf("PacketData.Data[%d]=0x%x\n",Rtn,PacketData.Data[Rtn]);
-	#endif		
-	for(count=0;count<Tmp;count+=6)	
-	{
-		//if((Tmp-count)<6)
-		strncpy(StatusArray[count/6],(PacketData.Data+1)+count,6);
-		Rtn=0;	
-		for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-		{
-			if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count/6], 6) == 0)
-			{
-				Rtn=1;	
-				break;
-			}	
-		}
-		if(Rtn==0)
-			AddFaultCodeToBuf(StatusArray[count/6]);					
-		//Rtn=StatusCodeProcessing(StatusArray[count/6]);
-		#ifdef Debug
-		printf("(%d)(%s) = %s,  ", count/6,Rtn==1?"Process OK":"Process NG", StatusArray[count/6]);	
-		#endif	
-	}		
-	for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-	{
-		if(ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1]>=0x33)//from backend or power cabinet
-		{
-			Rtn=0;	
-			for(count=0;count<(Tmp/6);count++)	
-			{
-				if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count], 6) == 0)
-				{	
-					Rtn=1;
-					break;
-				}	
-			}
-			if(Rtn==0)
-			{	
-				memset(EventCodeTmp,0,sizeof(EventCodeTmp));	
-				memcpy(EventCodeTmp,ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],sizeof(EventCodeTmp));	
-				RemoveFaultCodeToBuf(EventCodeTmp);
-			}
-		}
-	}
-	#ifdef Debug
-	printf("\n");
-	#endif		
-	return 1;
+    unsigned char Tmp = 0, count, Rtn;
+    struct ApplicationPacket PacketData;
+    unsigned char StatusArray[20][6];
+    unsigned char EventCodeTmp[7];
+
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    memset(StatusArray, 0, sizeof(StatusArray));
+#ifdef Debug
+    printf("ReadDoStatus => ");
+#endif
+    if (SendPacket(0x01, 0x01, 0x03, 0, PacketData.Data) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+    Tmp--;//decrase OK/NG byte
+    if (Tmp < 6) {
+        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
+            for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+                if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
+                    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                    memcpy(EventCodeTmp, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i], sizeof(EventCodeTmp));
+                    RemoveFaultCodeToBuf(EventCodeTmp);
+                }
+            }
+        }
+#ifdef Debug
+        printf("no alarm (%d)\n", Tmp);
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf("OK, (%d) ", Tmp);
+    //printf("PacketData.Se=%d\n",PacketData.Se);
+    //printf("PacketData.Id=%d\n",PacketData.Id);
+    //printf("PacketData.Op=%d\n",PacketData.Op);
+    //printf("PacketData.Len=%d\n",PacketData.Len);
+    //printf("PacketData.RegisterNum=%d\n",PacketData.RegisterNum);
+    //for(Rtn=0;Rtn<=PacketData.Len-1;Rtn++)
+    //printf("PacketData.Data[%d]=0x%x\n",Rtn,PacketData.Data[Rtn]);
+#endif
+    for (count = 0; count < Tmp; count += 6) {
+        //if((Tmp-count)<6)
+        strncpy(StatusArray[count / 6], (PacketData.Data + 1) + count, 6);
+        Rtn = 0;
+        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+            if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count / 6], 6) == 0) {
+                Rtn = 1;
+                break;
+            }
+        }
+        if (Rtn == 0) {
+            AddFaultCodeToBuf(StatusArray[count / 6]);
+        }
+        //Rtn=StatusCodeProcessing(StatusArray[count/6]);
+#ifdef Debug
+        printf("(%d)(%s) = %s,  ", count / 6, Rtn == 1 ? "Process OK" : "Process NG", StatusArray[count / 6]);
+#endif
+    }
+    for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
+            Rtn = 0;
+            for (count = 0; count < (Tmp / 6); count++) {
+                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count], 6) == 0) {
+                    Rtn = 1;
+                    break;
+                }
+            }
+            if (Rtn == 0) {
+                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                memcpy(EventCodeTmp, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i], sizeof(EventCodeTmp));
+                RemoveFaultCodeToBuf(EventCodeTmp);
+            }
+        }
+    }
+#ifdef Debug
+    printf("\n");
+#endif
+    return 1;
 }
 
 int WriteDdStatus()
 {
-	unsigned char Tmp=0,count;
-	unsigned char TmpBuf[255], CurWarnCodeTmp[10][6],PreWarnCodeTmp[10][6];
-	struct ApplicationPacket PacketData;
-	
-	if((ShmSysConfigAndInfo->SysWarningInfo.WarningCount<=0)&&(PreSysWarningInfo.WarningCount<=0))
-		return -1;
-	memset(CurWarnCodeTmp,0,sizeof(CurWarnCodeTmp));	
-	Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;	
-	for(count=0;count<Tmp;count++)
-	{
-		memcpy(CurWarnCodeTmp[count],ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count],6);
-	}		
-	memset(PreWarnCodeTmp,0,sizeof(PreWarnCodeTmp));	
-	Tmp=PreSysWarningInfo.WarningCount;
-	for(count=0;count<Tmp;count++)
-	{
-		memcpy(PreWarnCodeTmp[count],PreSysWarningInfo.WarningCode[count],6);
-	}		
-	if(strcmp(CurWarnCodeTmp,PreWarnCodeTmp)==0)
-		return -1;
-	
-	
-	/*memset(TmpBuf,0,sizeof(TmpBuf));
-	Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-	for(count=0;count<Tmp;count++)
-	{
-		memcpy(TmpBuf+(count*6),ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count],6);
-		#ifdef Debug
-		printf("WriteDdStatus(%d) = %s", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);	
-		#endif	
-	}	
-	if(SendPacket(0x01, 0x02, 0x04,strlen(TmpBuf), TmpBuf)<=0)
-		return -1;
-	*/	
-	#ifdef Debug
-	printf("WriteDdStatus => ");	
-	#endif	
-	if(SendPacket(0x01, 0x02, 0x04,strlen(CurWarnCodeTmp), CurWarnCodeTmp)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	memset(&PreSysWarningInfo,0, sizeof(struct WARNING_CODE_INFO));	
-	memcpy(&PreSysWarningInfo,&(ShmSysConfigAndInfo->SysWarningInfo),sizeof(struct WARNING_CODE_INFO));	
-	#ifdef Debug
-	printf("OK,  ");
-	Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;	
-	for(count=0;count<Tmp;count++)
-	{
-		printf("(%d)%s,  ", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);	
-	}		
-	printf("\n");
-	#endif		
-	return 1;
+    unsigned char Tmp = 0, count;
+    unsigned char TmpBuf[255], CurWarnCodeTmp[10][6], PreWarnCodeTmp[10][6];
+    struct ApplicationPacket PacketData;
+
+    if ((ShmSysConfigAndInfo->SysWarningInfo.WarningCount <= 0) && (PreSysWarningInfo.WarningCount <= 0)) {
+        return -1;
+    }
+    memset(CurWarnCodeTmp, 0, sizeof(CurWarnCodeTmp));
+    Tmp = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    for (count = 0; count < Tmp; count++) {
+        memcpy(CurWarnCodeTmp[count], ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count], 6);
+    }
+    memset(PreWarnCodeTmp, 0, sizeof(PreWarnCodeTmp));
+    Tmp = PreSysWarningInfo.WarningCount;
+    for (count = 0; count < Tmp; count++) {
+        memcpy(PreWarnCodeTmp[count], PreSysWarningInfo.WarningCode[count], 6);
+    }
+    if (strcmp(CurWarnCodeTmp, PreWarnCodeTmp) == 0) {
+        return -1;
+    }
+
+
+    /*memset(TmpBuf,0,sizeof(TmpBuf));
+    Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    for(count=0;count<Tmp;count++)
+    {
+        memcpy(TmpBuf+(count*6),ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count],6);
+        #ifdef Debug
+        printf("WriteDdStatus(%d) = %s", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);
+        #endif
+    }
+    if(SendPacket(0x01, 0x02, 0x04,strlen(TmpBuf), TmpBuf)<=0)
+        return -1;
+    */
+#ifdef Debug
+    printf("WriteDdStatus => ");
+#endif
+    if (SendPacket(0x01, 0x02, 0x04, strlen(CurWarnCodeTmp), CurWarnCodeTmp) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+    memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
+    memcpy(&PreSysWarningInfo, &(ShmSysConfigAndInfo->SysWarningInfo), sizeof(struct WARNING_CODE_INFO));
+#ifdef Debug
+    printf("OK,  ");
+    Tmp = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    for (count = 0; count < Tmp; count++) {
+        printf("(%d)%s,  ", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);
+    }
+    printf("\n");
+#endif
+    return 1;
 }
 
 int ReadChargingCapability(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	struct ApplicationPacket PacketData;
-	float MaxVolt, MaxCurrent, MaxPower;
-	
-	#ifdef Debug
-	printf("Read Charging Capability => ");	
-	#endif		
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	if(SendPacket(PlugNum, 0x01, 0x05,0, PacketData.Data)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	MaxVolt=(float)(PacketData.Data[1]<<8|PacketData.Data[2]);
-	MaxCurrent=(float)(PacketData.Data[3]<<8|PacketData.Data[4]);
-	MaxPower=(float)(PacketData.Data[5]<<8|PacketData.Data[6]);
-	if((MaxVolt>=0)&&(MaxVolt<=10000))
-		ChargingData[PlugNum-1]->MaximumChargingVoltage=MaxVolt;	
-	if((MaxCurrent>=0)&&(MaxCurrent<=5000))
-		ChargingData[PlugNum-1]->AvailableChargingCurrent=MaxCurrent;	
-	if((MaxPower>=0)&&(MaxPower<=3600))
-		ChargingData[PlugNum-1]->AvailableChargingPower=MaxPower;		
-	#ifdef Debug
-	printf(" MaxVolt=%f, MaxCurrent=%f, MaxPower=%f,\n", MaxVolt,MaxCurrent,MaxPower);	
-	#endif			
-	return 1;
+    unsigned char Tmp = 0;
+    struct ApplicationPacket PacketData;
+    float MaxVolt, MaxCurrent, MaxPower;
+
+#ifdef Debug
+    printf("Read Charging Capability => ");
+#endif
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    if (SendPacket(PlugNum, 0x01, 0x05, 0, PacketData.Data) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+    MaxVolt = (float)(PacketData.Data[1] << 8 | PacketData.Data[2]);
+    MaxCurrent = (float)(PacketData.Data[3] << 8 | PacketData.Data[4]);
+    MaxPower = (float)(PacketData.Data[5] << 8 | PacketData.Data[6]);
+    if ((MaxVolt >= 0) && (MaxVolt <= 10000)) {
+        ChargingData[PlugNum - 1]->MaximumChargingVoltage = MaxVolt;
+    }
+    if ((MaxCurrent >= 0) && (MaxCurrent <= 5000)) {
+        ChargingData[PlugNum - 1]->AvailableChargingCurrent = MaxCurrent;
+    }
+    if ((MaxPower >= 0) && (MaxPower <= 3600)) {
+        ChargingData[PlugNum - 1]->AvailableChargingPower = MaxPower;
+    }
+#ifdef Debug
+    printf(" MaxVolt=%f, MaxCurrent=%f, MaxPower=%f,\n", MaxVolt, MaxCurrent, MaxPower);
+#endif
+    return 1;
 }
 
 int WriteChargingTarget(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	float ChargingVolt, ChargingAmp;
-	
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-
-	ChargingVolt=ChargingData[PlugNum-1]->EvBatterytargetVoltage;
-	ChargingAmp=ChargingData[PlugNum-1]->EvBatterytargetCurrent;
-	ChargingVolt*=10;
-	ChargingAmp*=10;
-	TmpBuf[0]=((unsigned short)ChargingVolt>>8)&0xFF;
-	TmpBuf[1]=((unsigned short)ChargingVolt)&0xFF;
-	TmpBuf[2]=((unsigned short)ChargingAmp>>8)&0xFF;
-	TmpBuf[3]=((unsigned short)ChargingAmp)&0xFF;
-	#ifdef Debug
-	printf("WriteChargingTarget(%d), EvBatterytargetVoltage=%f,EvBatteryMaxVoltage=%f => ",
-	PlugNum,ChargingData[PlugNum-1]->EvBatterytargetVoltage,ChargingData[PlugNum-1]->EvBatteryMaxVoltage);	
-	#endif	
-	if(SendPacket(PlugNum, 0x02, 0x06,4, TmpBuf)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf("ChargingVolt=%f, ChargingAmp=%f\n", ChargingVolt/10,ChargingAmp/10);	
-	#endif	
-
-	return 1;
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+    float ChargingVolt, ChargingAmp;
+
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+
+    ChargingVolt = ChargingData[PlugNum - 1]->EvBatterytargetVoltage;
+    ChargingAmp = ChargingData[PlugNum - 1]->EvBatterytargetCurrent;
+    ChargingVolt *= 10;
+    ChargingAmp *= 10;
+    TmpBuf[0] = ((unsigned short)ChargingVolt >> 8) & 0xFF;
+    TmpBuf[1] = ((unsigned short)ChargingVolt) & 0xFF;
+    TmpBuf[2] = ((unsigned short)ChargingAmp >> 8) & 0xFF;
+    TmpBuf[3] = ((unsigned short)ChargingAmp) & 0xFF;
+#ifdef Debug
+    printf("WriteChargingTarget(%d), EvBatterytargetVoltage=%f,EvBatteryMaxVoltage=%f => ",
+           PlugNum, ChargingData[PlugNum - 1]->EvBatterytargetVoltage, ChargingData[PlugNum - 1]->EvBatteryMaxVoltage);
+#endif
+    if (SendPacket(PlugNum, 0x02, 0x06, 4, TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf("ChargingVolt=%f, ChargingAmp=%f\n", ChargingVolt / 10, ChargingAmp / 10);
+#endif
+
+    return 1;
 }
 int ReadSoftwareUpdate()
 {
-	unsigned char Tmp=0;
-	struct ApplicationPacket PacketData;
-	
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-
-	if(SendPacket(0x01, 0x01, 0x07,0, PacketData.Data)<=0)
-		return -1;
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-		return -1;	
-	if(PacketData.Data[0]!=1)//!=OK
-		return -1;		
-	if(PacketData.Data[1]!=0x01)//not update
-		return -1;			
-	return PacketData.Data[1];
+    unsigned char Tmp = 0;
+    struct ApplicationPacket PacketData;
+
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+
+    if (SendPacket(0x01, 0x01, 0x07, 0, PacketData.Data) <= 0) {
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+        return -1;
+    }
+    if (PacketData.Data[1] != 0x01) { //not update
+        return -1;
+    }
+    return PacketData.Data[1];
 }
 int WritePlugInStatus(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	TmpBuf[0]=ChargingData[PlugNum-1]->ConnectorPlugIn;
-	#ifdef Debug
-	printf("WritePlugInStatus(%d) =>",PlugNum);	
-	#endif	
-	if(SendPacket(PlugNum, 0x02, 0x08,1, TmpBuf)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf(" %s\n", TmpBuf[0]==1?"Plug-in":"Un-plug");	
-	#endif		
-
-	return 1;
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    TmpBuf[0] = ChargingData[PlugNum - 1]->ConnectorPlugIn;
+#ifdef Debug
+    printf("WritePlugInStatus(%d) =>", PlugNum);
+#endif
+    if (SendPacket(PlugNum, 0x02, 0x08, 1, TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf(" %s\n", TmpBuf[0] == 1 ? "Plug-in" : "Un-plug");
+#endif
+
+    return 1;
 }
 
 int WriteConnectorState(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	
-
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	
-	if(ChargingData[PlugNum-1]->SystemStatus<=2)
-		TmpBuf[0]=0;//idle
-	else if((ChargingData[PlugNum-1]->SystemStatus<=7)||(ChargingData[PlugNum-1]->SystemStatus==17)||(ChargingData[PlugNum-1]->SystemStatus==18))
-		TmpBuf[0]=1;//preparing 	
-	else if(ChargingData[PlugNum-1]->SystemStatus==8)
-		TmpBuf[0]=2;//charging  		
-	else if(ChargingData[PlugNum-1]->SystemStatus==9)
-		TmpBuf[0]=3;//terminating   		
-		
-	#ifdef Debug
-	printf("WriteConnectorState(%d) SystemStatus=%d,TmpBuf[0]=%d => ",PlugNum,ChargingData[PlugNum-1]->SystemStatus,TmpBuf[0]);	
-	#endif		
-	if(SendPacket(PlugNum, 0x02, 0x09,1, TmpBuf)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf(" %d\n",TmpBuf[0]);	
-	#endif		
-
-	return 1;
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+
+
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+
+    if (ChargingData[PlugNum - 1]->SystemStatus <= 2) {
+        TmpBuf[0] = 0;    //idle
+    } else if ((ChargingData[PlugNum - 1]->SystemStatus <= 7) || (ChargingData[PlugNum - 1]->SystemStatus == 17) || (ChargingData[PlugNum - 1]->SystemStatus == 18)) {
+        TmpBuf[0] = 1;    //preparing
+    } else if (ChargingData[PlugNum - 1]->SystemStatus == 8) {
+        TmpBuf[0] = 2;    //charging
+    } else if (ChargingData[PlugNum - 1]->SystemStatus == 9) {
+        TmpBuf[0] = 3;    //terminating
+    }
+
+#ifdef Debug
+    printf("WriteConnectorState(%d) SystemStatus=%d,TmpBuf[0]=%d => ", PlugNum, ChargingData[PlugNum - 1]->SystemStatus, TmpBuf[0]);
+#endif
+    if (SendPacket(PlugNum, 0x02, 0x09, 1, TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf(" %d\n", TmpBuf[0]);
+#endif
+
+    return 1;
 }
 
 int WriteUserID(unsigned char ConnectorID, unsigned char *UserID)
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	
-	if(strlen(UserID)<=0)
-		return -1;
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	strcpy(TmpBuf,UserID);
-	#ifdef Debug
-	printf("WriteUserID(%d) => ",ConnectorID);	
-	#endif		
-	if(SendPacket(ConnectorID, 0x02, 0x0A,strlen(TmpBuf), TmpBuf)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf(" StartUserId=%s, PacketData.Data[1]=%d\n", TmpBuf,PacketData.Data[1]);	
-	#endif		
-	return PacketData.Data[1];
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+
+    if (strlen(UserID) <= 0) {
+        return -1;
+    }
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    strcpy(TmpBuf, UserID);
+#ifdef Debug
+    printf("WriteUserID(%d) => ", ConnectorID);
+#endif
+    if (SendPacket(ConnectorID, 0x02, 0x0A, strlen(TmpBuf), TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf(" StartUserId=%s, PacketData.Data[1]=%d\n", TmpBuf, PacketData.Data[1]);
+#endif
+    return PacketData.Data[1];
 }
 
 int ReadChargePermission(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	struct ApplicationPacket PacketData;
-	
-
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	#ifdef Debug
-	printf("ReadChargePermission[%d] => ", PlugNum);	
-	#endif		
-	if(SendPacket(PlugNum, 0x01, 0x0B,0, PacketData.Data)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf(" %s\n", PacketData.Data[1]==1?"Permitted": "NOT permitted" );	
-	#endif			
-
-	return PacketData.Data[1];
+    unsigned char Tmp = 0;
+    struct ApplicationPacket PacketData;
+
+
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+#ifdef Debug
+    printf("ReadChargePermission[%d] => ", PlugNum);
+#endif
+    if (SendPacket(PlugNum, 0x01, 0x0B, 0, PacketData.Data) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf(" %s\n", PacketData.Data[1] == 1 ? "Permitted" : "NOT permitted" );
+#endif
+
+    return PacketData.Data[1];
 }
 
 int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
 {
-	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-			return 1;
-		}
-	}
-
-	for (byte index = 0; index < CCS_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-			return 1;
-		}
-	}
-
-	for (byte index = 0; index < GB_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-			return 1;
-		}
-	}
-
-	return 0;
+    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+            return 1;
+        }
+    }
+
+    for (byte index = 0; index < CCS_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+            return 1;
+        }
+    }
+
+    for (byte index = 0; index < GB_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+            return 1;
+        }
+    }
+
+    return 0;
 }
 
 int MessageTrigger(unsigned char connectorID)
 {
-	struct timeb  NowTime;
-	unsigned char Reg;
-	for(Reg=0;Reg<TriggerMsgeNum;Reg++)
-	{
-		ftime(&NowTime);
-		switch(Reg)
-		{
-			case 3://ReadDoStatus
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(ReadDoStatus())
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;
-			case 4://WriteDdStatus
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(WriteDdStatus())
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;
-			/*case 5://ReadChargingCapability
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>200)
-				{
-					if(ReadChargingCapability(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;			
-			case 6://WriteChargingTarget
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>100)
-				{
-					if(WriteChargingTarget(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;*/		
-			case 8://WritePlugInStatus
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(WritePlugInStatus(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;		
-			case 9://WriteConnectorState
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(WriteConnectorState(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;		
-			/*case 0x0B://ReadChargePermission
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(ReadChargePermission(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;*/			
-			default:
-				break;			
-		}
-	}
+    struct timeb  NowTime;
+    unsigned char Reg;
+    for (Reg = 0; Reg < TriggerMsgeNum; Reg++) {
+        ftime(&NowTime);
+        switch (Reg) {
+        case 3://ReadDoStatus
+            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
+                if (ReadDoStatus()) {
+                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
+                }
+            }
+            break;
+        case 4://WriteDdStatus
+            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
+                if (WriteDdStatus()) {
+                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
+                }
+            }
+            break;
+        /*case 5://ReadChargingCapability
+            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>200)
+            {
+                if(ReadChargingCapability(connectorID))
+                {
+                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
+                }
+            }
+            break;
+        case 6://WriteChargingTarget
+            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>100)
+            {
+                if(WriteChargingTarget(connectorID))
+                {
+                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
+                }
+            }
+            break;*/
+        case 8://WritePlugInStatus
+            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
+                if (WritePlugInStatus(connectorID)) {
+                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
+                }
+            }
+            break;
+        case 9://WriteConnectorState
+            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
+                if (WriteConnectorState(connectorID)) {
+                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
+                }
+            }
+            break;
+        /*case 0x0B://ReadChargePermission
+            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
+            {
+                if(ReadChargePermission(connectorID))
+                {
+                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
+                }
+            }
+            break;*/
+        default:
+            break;
+        }
+    }
 }
 
-int main(int argc,char *argv[])
+int main(int argc, char *argv[])
 {
-	unsigned char Tmp,PlugNum;
-	int Rtn;
-	struct timeb  AuthNowTime;
-	
-	/**************** Initialization **********/		
-	if(InitShareMemory()==0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
-		}	
-		sleep(5);
-		return 0;
-	}
-	
-ReConnect:	
-	memset(&PreSysWarningInfo,0,sizeof(struct WARNING_CODE_INFO));
-	PacketSe=0;
-	DisconnectFlag=0;
-	for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
-	{
-		if (!FindChargingInfoData(_index, &ChargingData[0]))
-		{
-			DEBUG_ERROR("FindChargingInfoData false \n");
-			break;
-		}
-	}
-	
-	/**************** Check Network **********/		
-	DEBUG_INFO("Check Dispenser Network Information");
-	while(!CheckNetworkStatus())
-	{
-		sleep(1);
-		if(DisconnectFlag>=10)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-		}
-		else
-			DisconnectFlag++;
-	}
-	DEBUG_INFO("Dispenser Network Information checked: IP=%s Netmask=%s, Gateway=%s",
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-	
-	/**************** Power cabinet connection **********/		
-	DEBUG_INFO("Connect to Power Cabinet");
-	while(TcpConnected()<0)
-	{
-		sleep(1);
-		if(DisconnectFlag>=5)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-		}
-		else
-			DisconnectFlag++;
-	}
-	DEBUG_INFO("Power cabinet connected(TcpSock=%d): IP=%s Netmask=%s, Gateway=%s",
-	TcpSock,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-	
-	/**************** Write Model Name**********/		
-	DEBUG_INFO("Write Model Name");
-	while(WriteModelName()<0)
-	{
-		sleep(1);
-		if(DisconnectFlag>=5)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-		}
-		else
-			DisconnectFlag++;
-	}
-	DEBUG_INFO("Write Model Name OK: %s",ShmSysConfigAndInfo->SysConfig.ModelName);
-	
-	/**************** Get Connector ID**********/		
-	DEBUG_INFO("Get Connector ID");
-	while(ReadConnectorID()<0)
-	{
-		sleep(1);
-		if(DisconnectFlag>=5)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-		}
-		else
-			DisconnectFlag++;
-	}
-	DEBUG_INFO("Get Connector ID OK");
-	/*while(1)
-	{
-		//for self testin main.c
-		if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq >= _STEST_PSU_DETECT)
-		{	
-			ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
-			break;
-		}
-	}*/
-	for(Tmp=0;Tmp<TriggerMsgeNum;Tmp++)
-	{
-		ftime(&TriggerTimeUp[0][Tmp]);
-		ftime(&TriggerTimeUp[1][Tmp]);
-		usleep(50000);
-	}
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=0;
-	DEBUG_INFO("Start Communication");
-	/**************** Data transmission**********/		
-	while(1)
-	{	
-		if((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)||(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag==1))
-		{
-			ftime(&AuthNowTime);
-			if(DiffTimeb(TriggerTimeUp[0][10],AuthNowTime)>1000)
-			{	
-				Rtn=WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected,ShmSysConfigAndInfo->SysConfig.UserId);
-				if(Rtn>=0)
-				{
-					memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,0,sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
-					if(Rtn==0)
-						strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,"Invalid");
-					else
-						strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,"Accepted");	
-					ShmOCPP16Data->SpMsg.bits.AuthorizeConf=1;//isAuthorizedComplete
-					ShmOCPP16Data->SpMsg.bits.AuthorizeReq=0;
-					ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=0;
-					ShmPsuData->SystemAvailablePower=0;
-					ShmPsuData->SystemPresentPsuQuantity=0;
-				}	
-				ftime(&TriggerTimeUp[0][10]);
-			}
-		}	
-		
-		for (PlugNum = 1; PlugNum <= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; PlugNum++)
-		{
-			//printf("ChargingData[PlugNum-1]->SystemStatus=%d\n",ChargingData[PlugNum-1]->SystemStatus);
-			//printf("ShmOCPP16Data->SpMsg.bits.AuthorizeReq=%d\n",ShmOCPP16Data->SpMsg.bits.AuthorizeReq);
-			//printf("ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=%d\n",ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
-			//printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
-			//printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
-			switch(ChargingData[PlugNum-1]->SystemStatus)
-			{
-				case S_IDLE:
-				case S_RESERVATION:
-				case S_MAINTAIN:
-				case S_ALARM:
-				case S_AUTHORIZING:	
-					if((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)||(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag==1))
-					{
-						ftime(&AuthNowTime);
-						if(DiffTimeb(TriggerTimeUp[PlugNum-1][10],AuthNowTime)>1000)
-						{	
-							Rtn=WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected,ShmSysConfigAndInfo->SysConfig.UserId);
-							if(Rtn>=0)
-							{
-								memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,0,sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
-								if(Rtn==0)
-									strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,"Invalid");
-								else
-									strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,"Accepted");	
-								ShmOCPP16Data->SpMsg.bits.AuthorizeConf=1;//isAuthorizedComplete
-								ShmOCPP16Data->SpMsg.bits.AuthorizeReq=0;
-								ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=0;
-								ShmPsuData->SystemAvailablePower=0;
-								ShmPsuData->SystemPresentPsuQuantity=0;
-								ftime(&TriggerTimeUp[PlugNum-1][10]);
-								
-							}
-							ftime(&TriggerTimeUp[PlugNum-1][10]);	
-						}
-					}	
-					/*if(ReadSoftwareUpdate())//0x07
-					{
-						//firmware update
-					}*/	
-					break;
-				case S_PREPARNING: //get permission
-					//printf("S_PREPARNING\n");
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][11],AuthNowTime)>1000)
-					{	
-						if((ReadChargePermission(PlugNum))&&(ReadChargingCapability(PlugNum)))	
-						{
-							ShmPsuData->SystemAvailablePower=ChargingData[0]->AvailableChargingPower+ChargingData[1]->AvailableChargingPower;
-							ShmPsuData->SystemPresentPsuQuantity=ShmPsuData->SystemAvailablePower/30;
-						}	
-						ftime(&TriggerTimeUp[PlugNum-1][11]);
-					}
-					break;
-				case S_PREPARING_FOR_EV://wait connector lock
-					//printf("S_PREPARING_FOR_EV\n");
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][5],AuthNowTime)>1000)
-					{	
-						ReadChargingCapability(PlugNum);
-						ftime(&TriggerTimeUp[PlugNum-1][5]);
-					}
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][11],AuthNowTime)>1000)
-					{	
-						if(ReadChargePermission(PlugNum)==0)
-						{
-							DEBUG_INFO("Stop charging by power cabinet's permission");
-							ChargingData[PlugNum-1]->StopChargeFlag = 1;
-						}	
-						ftime(&TriggerTimeUp[PlugNum-1][11]);
-					}
-					break;	
-				case S_PREPARING_FOR_EVSE: //insaulation test
-				case S_CCS_PRECHARGE_ST0:
-				case S_CCS_PRECHARGE_ST1:	
-					//printf("S_PREPARING_FOR_EVSE\n");
-					WriteChargingTarget(PlugNum);
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][5],AuthNowTime)>1000)
-					{	
-						ReadChargingCapability(PlugNum);
-						ftime(&TriggerTimeUp[PlugNum-1][5]);
-					}
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][11],AuthNowTime)>1000)
-					{	
-						if(ReadChargePermission(PlugNum)==0)
-						{
-							DEBUG_INFO("Stop charging by power cabinet's permission");
-							ChargingData[PlugNum-1]->StopChargeFlag = 1;
-						}	
-						ftime(&TriggerTimeUp[PlugNum-1][11]);
-					}
-					break;	
-				case S_CHARGING: //charging
-				case S_TERMINATING:	
-					//printf("S_CHARGING,S_TERMINATING\n");
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][5],AuthNowTime)>1000)
-					{	
-						ReadChargingCapability(PlugNum);
-						ftime(&TriggerTimeUp[PlugNum-1][5]);
-					}
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][11],AuthNowTime)>1000)
-					{	
-						if(ReadChargePermission(PlugNum)==0)
-						{
-							DEBUG_INFO("Stop charging by power cabinet's permission");
-							ChargingData[PlugNum-1]->StopChargeFlag = 1;
-						}	
-						ftime(&TriggerTimeUp[PlugNum-1][11]);
-					}
-					WriteChargingTarget(PlugNum);
-					//printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
-					//printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
-					break;		
-				default:
-					break;	
-			}//switch	case
-			MessageTrigger(PlugNum);
-		}//for connector #	
-		if(DisconnectFlag>=10)
-		{
-			if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo==0)
-			{	
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-				DEBUG_INFO("Disconnected from power cabinet...re-connecting");
-			}
-			goto ReConnect;
-		}
-	}//while(1)
-}
+    unsigned char Tmp, PlugNum;
+    int Rtn;
+    struct timeb  AuthNowTime;
+
+    /**************** Initialization **********/
+    if (InitShareMemory() == 0) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("InitShareMemory NG\n");
+#endif
+        if (ShmStatusCodeData != NULL) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+        }
+        sleep(5);
+        return 0;
+    }
+
+ReConnect:
+    memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
+    PacketSe = 0;
+    DisconnectFlag = 0;
+    for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+        if (!FindChargingInfoData(_index, &ChargingData[0])) {
+            DEBUG_ERROR("FindChargingInfoData false \n");
+            break;
+        }
+    }
+
+    /**************** Check Network **********/
+    DEBUG_INFO("Check Dispenser Network Information");
+    while (!CheckNetworkStatus()) {
+        sleep(1);
+        if (DisconnectFlag >= 10) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+        } else {
+            DisconnectFlag++;
+        }
+    }
+    DEBUG_INFO("Dispenser Network Information checked: IP=%s Netmask=%s, Gateway=%s",
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+
+    /**************** Power cabinet connection **********/
+    DEBUG_INFO("Connect to Power Cabinet");
+    while (TcpConnected() < 0) {
+        sleep(1);
+        if (DisconnectFlag >= 5) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+        } else {
+            DisconnectFlag++;
+        }
+    }
+    DEBUG_INFO("Power cabinet connected(TcpSock=%d): IP=%s Netmask=%s, Gateway=%s",
+               TcpSock,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+
+    /**************** Write Model Name**********/
+    DEBUG_INFO("Write Model Name");
+    while (WriteModelName() < 0) {
+        sleep(1);
+        if (DisconnectFlag >= 5) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+        } else {
+            DisconnectFlag++;
+        }
+    }
+    DEBUG_INFO("Write Model Name OK: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
+
+    /**************** Get Connector ID**********/
+    DEBUG_INFO("Get Connector ID");
+    while (ReadConnectorID() < 0) {
+        sleep(1);
+        if (DisconnectFlag >= 5) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+        } else {
+            DisconnectFlag++;
+        }
+    }
+    DEBUG_INFO("Get Connector ID OK");
+    /*while(1)
+    {
+        //for self testin main.c
+        if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq >= _STEST_PSU_DETECT)
+        {
+            ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
+            break;
+        }
+    }*/
+    for (Tmp = 0; Tmp < TriggerMsgeNum; Tmp++) {
+        ftime(&TriggerTimeUp[0][Tmp]);
+        ftime(&TriggerTimeUp[1][Tmp]);
+        usleep(50000);
+    }
+    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 0;
+    DEBUG_INFO("Start Communication");
+    /**************** Data transmission**********/
+    while (1) {
+        if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) || (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == 1)) {
+            ftime(&AuthNowTime);
+            if (DiffTimeb(TriggerTimeUp[0][10], AuthNowTime) > 1000) {
+                Rtn = WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected, ShmSysConfigAndInfo->SysConfig.UserId);
+                if (Rtn >= 0) {
+                    memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0, sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
+                    if (Rtn == 0) {
+                        strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
+                    } else {
+                        strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
+                    }
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; //isAuthorizedComplete
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
+                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
+                    ShmPsuData->SystemAvailablePower = 0;
+                    ShmPsuData->SystemPresentPsuQuantity = 0;
+                }
+                ftime(&TriggerTimeUp[0][10]);
+            }
+        }
+
+        for (PlugNum = 1; PlugNum <= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; PlugNum++) {
+            //printf("ChargingData[PlugNum-1]->SystemStatus=%d\n",ChargingData[PlugNum-1]->SystemStatus);
+            //printf("ShmOCPP16Data->SpMsg.bits.AuthorizeReq=%d\n",ShmOCPP16Data->SpMsg.bits.AuthorizeReq);
+            //printf("ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=%d\n",ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
+            //printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
+            //printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
+            switch (ChargingData[PlugNum - 1]->SystemStatus) {
+            case S_IDLE:
+            case S_RESERVATION:
+            case S_MAINTAIN:
+            case S_ALARM:
+            case S_AUTHORIZING:
+                if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) || (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == 1)) {
+                    ftime(&AuthNowTime);
+                    if (DiffTimeb(TriggerTimeUp[PlugNum - 1][10], AuthNowTime) > 1000) {
+                        Rtn = WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected, ShmSysConfigAndInfo->SysConfig.UserId);
+                        if (Rtn >= 0) {
+                            memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0, sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
+                            if (Rtn == 0) {
+                                strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
+                            } else {
+                                strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
+                            }
+                            ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; //isAuthorizedComplete
+                            ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
+                            ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
+                            ShmPsuData->SystemAvailablePower = 0;
+                            ShmPsuData->SystemPresentPsuQuantity = 0;
+                            ftime(&TriggerTimeUp[PlugNum - 1][10]);
+
+                        }
+                        ftime(&TriggerTimeUp[PlugNum - 1][10]);
+                    }
+                }
+                /*if(ReadSoftwareUpdate())//0x07
+                {
+                    //firmware update
+                }*/
+                break;
+            case S_PREPARNING: //get permission
+                //printf("S_PREPARNING\n");
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
+                    if ((ReadChargePermission(PlugNum)) && (ReadChargingCapability(PlugNum))) {
+                        ShmPsuData->SystemAvailablePower = ChargingData[0]->AvailableChargingPower + ChargingData[1]->AvailableChargingPower;
+                        ShmPsuData->SystemPresentPsuQuantity = ShmPsuData->SystemAvailablePower / 30;
+                    }
+                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
+                }
+                break;
+            case S_PREPARING_FOR_EV://wait connector lock
+                //printf("S_PREPARING_FOR_EV\n");
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
+                    ReadChargingCapability(PlugNum);
+                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
+                }
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
+                    if (ReadChargePermission(PlugNum) == 0) {
+                        DEBUG_INFO("Stop charging by power cabinet's permission");
+                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
+                    }
+                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
+                }
+                break;
+            case S_PREPARING_FOR_EVSE: //insaulation test
+            case S_CCS_PRECHARGE_ST0:
+            case S_CCS_PRECHARGE_ST1:
+                //printf("S_PREPARING_FOR_EVSE\n");
+                WriteChargingTarget(PlugNum);
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
+                    ReadChargingCapability(PlugNum);
+                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
+                }
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
+                    if (ReadChargePermission(PlugNum) == 0) {
+                        DEBUG_INFO("Stop charging by power cabinet's permission");
+                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
+                    }
+                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
+                }
+                break;
+            case S_CHARGING: //charging
+            case S_TERMINATING:
+                //printf("S_CHARGING,S_TERMINATING\n");
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
+                    ReadChargingCapability(PlugNum);
+                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
+                }
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
+                    if (ReadChargePermission(PlugNum) == 0) {
+                        DEBUG_INFO("Stop charging by power cabinet's permission");
+                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
+                    }
+                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
+                }
+                WriteChargingTarget(PlugNum);
+                //printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
+                //printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
+                break;
+            default:
+                break;
+            }//switch   case
+            MessageTrigger(PlugNum);
+        }//for connector #
+        if (DisconnectFlag >= 10) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == 0) {
+                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+                DEBUG_INFO("Disconnected from power cabinet...re-connecting");
+            }
+            goto ReConnect;
+        }
+    }//while(1)
+}

+ 266 - 282
EVSE/Projects/DD360/Apps/FactoryConfig.c

@@ -1,323 +1,307 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
+#include    <sys/time.h>
+#include    <sys/timeb.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.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/can.h>
+#include    <linux/can/raw.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>     /*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	"../../define.h"
-#include 	"Config.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    "../../define.h"
+#include    "Config.h"
 
 #define Debug
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define OUTPUT_FLASH		0x01
-#define OUTPUT_FILE			0x02
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define OUTPUT_FLASH        0x01
+#define OUTPUT_FILE         0x02
 
-struct SysConfigData 			SysConfig;
+struct SysConfigData            SysConfig;
 
 int StoreLogMsg(const char *fmt, ...);
 
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
+    char Buf[4096 + 256];
+    char buffer[4096];
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
 
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
 
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
+    memset(Buf, 0, sizeof(Buf));
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
 
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
+    sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+            tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
+            buffer,
+            tm->tm_year + 1900, tm->tm_mon + 1);
+    system(Buf);
 
-	return rc;
+    return rc;
 }
 
 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]...\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");
 }
 
 /**************************************************************************************/
 /************This task will create Factory default confgiuration file *****************/
- /***********and store it into mtdblock 10,11,12                               ****************/
+/***********and store it into mtdblock 10,11,12                               ****************/
 /**************************************************************************************/
-int main(int argc,char *argv[])
+int main(int argc, char *argv[])
 {
-	unsigned char outType=0;
-	unsigned int i,Chk, MtdBlockSize=0x600000;
-	unsigned char *ptr;
-	int fd,wrd;
+    unsigned char outType = 0;
+    unsigned int i, Chk, MtdBlockSize = 0x600000;
+    unsigned char *ptr;
+    int fd, wrd;
 
-	ptr=malloc(MtdBlockSize);
-	if(ptr==NULL)
-	{
-		#ifdef SystemLogMessage
-		StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
-		#endif
-		return 0;
-	}
-	memset(ptr, 0, MtdBlockSize);
-	memset(&SysConfig, 0, sizeof(struct SysConfigData));
+    ptr = malloc(MtdBlockSize);
+    if (ptr == NULL) {
+#ifdef SystemLogMessage
+        StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
+#endif
+        return 0;
+    }
+    memset(ptr, 0, MtdBlockSize);
+    memset(&SysConfig, 0, sizeof(struct SysConfigData));
 
-	/*
-	 * TODO: Set factory default configuration
-	*/
-	//********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
-	//
-	strcpy((char *)SysConfig.ModelName, "DDYE182V0UD2AU");
-	strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
+    /*
+     * TODO: Set factory default configuration
+    */
+    //********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
+    //
+    strcpy((char *)SysConfig.ModelName, "DDYC182V0UE2AD");
+    strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
 
-	memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
-	char Dash = '-';
+    memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
+    char Dash = '-';
 
-	strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName);
-	strncat((char *)SysConfig.SystemId, &Dash, 1);
-	strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber);
+    strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName);
+    strncat((char *)SysConfig.SystemId, &Dash, 1);
+    strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber);
 
-	strcpy((char *)SysConfig.SystemDateTime, "");
-	SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
-	SysConfig.DefaultLanguage = 0;
-	SysConfig.RfidCardNumEndian = 0;
-	SysConfig.AcPlugInTimes = 0;
-	SysConfig.GbPlugInTimes = 0;
-	SysConfig.Ccs1PlugInTime = 0;
-	SysConfig.Ccs2PlugInTimes = 0;
-	SysConfig.ChademoPlugInTimes = 0;
-	SysConfig.BillingData.isBilling = 0;
-	SysConfig.isAPP = 1;
-	SysConfig.isQRCode = 1;
-	SysConfig.isRFID = 1;
-	//********** Charging **********//
-	SysConfig.MaxChargingEnergy = 0;
-	SysConfig.MaxChargingCurrent = 500;		// 最大可輸出電流 (整樁)
-	SysConfig.MaxChargingDuration = 0;
-	SysConfig.AcMaxChargingCurrent = 0;
-	SysConfig.PhaseLossPolicy = 0;
-	/*+++ 20200908, vern, modify it +++*/
-	/*for(unsigned char i = 0; i < 10; i++)
-		strcpy((char *)SysConfig.LocalWhiteCard, "");*/
-	memset(SysConfig.LocalWhiteCard,0,sizeof(SysConfig.LocalWhiteCard));	
-	/*--- 20200908, vern, modify it ---*/
-	strcpy((char *)SysConfig.UserId, "");
-	//********** Network **********//
-	strcpy((char *)SysConfig.FtpServer, "");
-	SysConfig.Eth0Interface.EthDhcpClient = 0;
-	strcpy((char *) SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
-	strcpy((char *) SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0");
-	strcpy((char *) SysConfig.Eth0Interface.EthGatewayAddress, "192.168.1.254");
-	SysConfig.Eth1Interface.EthDhcpClient = 0;
-	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
-	strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
-	strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
-	if(SysConfig.ModelName[10] == 'W')
-		SysConfig.AthInterface.WifiMode = 2;
-	else
-		SysConfig.AthInterface.WifiMode = 0;
-	strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
-	strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
-	SysConfig.AthInterface.WifiRssi = 0;
-	SysConfig.AthInterface.WifiDhcpServer = 0;
-	SysConfig.AthInterface.WifiDhcpClient = 0;
-	strcpy((char *) SysConfig.AthInterface.WifiMacAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiIpAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiSubmaskAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiGatewayAddress, "");
-	SysConfig.AthInterface.WifiNetworkConn = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomModelName, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSoftwareVer, "");
-	//strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "Internet");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "");
-	SysConfig.TelecomInterface.TelcomRssi = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, " ");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, "");
-	SysConfig.TelecomInterface.TelcomSimStatus = 0;
-	SysConfig.TelecomInterface.TelcomModemMode = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomIpAddress, "");
-	SysConfig.TelecomInterface.TelcomNetworkConn = 0;
-	strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
-	//********** Backend **********//
-	SysConfig.BackendConnTimeout = 300; //300 seconds
-	SysConfig.OfflinePolicy = 2;
-	SysConfig.OfflineMaxChargeEnergy = 0;
-	SysConfig.OfflineMaxChargeDuration = 0;
-	strcpy((char *) SysConfig.OcppServerURL, "");
-	strcpy((char *) SysConfig.ChargeBoxId, "");
-	SysConfig.LedInfo.Intensity = 2;
+    strcpy((char *)SysConfig.SystemDateTime, "");
+    SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
+    SysConfig.DefaultLanguage = 0;
+    SysConfig.RfidCardNumEndian = 0;
+    SysConfig.AcPlugInTimes = 0;
+    SysConfig.GbPlugInTimes = 0;
+    SysConfig.Ccs1PlugInTime = 0;
+    SysConfig.Ccs2PlugInTimes = 0;
+    SysConfig.ChademoPlugInTimes = 0;
+    SysConfig.BillingData.isBilling = 0;
+    SysConfig.isAPP = 1;
+    SysConfig.isQRCode = 1;
+    SysConfig.isRFID = 1;
+    //********** Charging **********//
+    SysConfig.MaxChargingEnergy = 0;
+    SysConfig.MaxChargingCurrent = 500;     // ��憭批虾頛詨枂�餅� (�湔�)
+    SysConfig.MaxChargingDuration = 0;
+    SysConfig.AcMaxChargingCurrent = 0;
+    SysConfig.PhaseLossPolicy = 0;
+    /*+++ 20200908, vern, modify it +++*/
+    /*for(unsigned char i = 0; i < 10; i++)
+        strcpy((char *)SysConfig.LocalWhiteCard, "");*/
+    memset(SysConfig.LocalWhiteCard, 0, sizeof(SysConfig.LocalWhiteCard));
+    /*--- 20200908, vern, modify it ---*/
+    strcpy((char *)SysConfig.UserId, "");
+    //********** Network **********//
+    strcpy((char *)SysConfig.FtpServer, "");
+    SysConfig.Eth0Interface.EthDhcpClient = 0;
+    strcpy((char *) SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
+    strcpy((char *) SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0");
+    strcpy((char *) SysConfig.Eth0Interface.EthGatewayAddress, "192.168.1.254");
+    SysConfig.Eth1Interface.EthDhcpClient = 0;
+    strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
+    strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
+    strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
+    if (SysConfig.ModelName[10] == 'W') {
+        SysConfig.AthInterface.WifiMode = 2;
+    } else {
+        SysConfig.AthInterface.WifiMode = 0;
+    }
+    strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
+    strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
+    SysConfig.AthInterface.WifiRssi = 0;
+    SysConfig.AthInterface.WifiDhcpServer = 0;
+    SysConfig.AthInterface.WifiDhcpClient = 0;
+    strcpy((char *) SysConfig.AthInterface.WifiMacAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiIpAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiSubmaskAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiGatewayAddress, "");
+    SysConfig.AthInterface.WifiNetworkConn = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomModelName, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSoftwareVer, "");
+    //strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "Internet");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "");
+    SysConfig.TelecomInterface.TelcomRssi = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, " ");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, "");
+    SysConfig.TelecomInterface.TelcomSimStatus = 0;
+    SysConfig.TelecomInterface.TelcomModemMode = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomIpAddress, "");
+    SysConfig.TelecomInterface.TelcomNetworkConn = 0;
+    strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
+    //********** Backend **********//
+    SysConfig.BackendConnTimeout = 300; //300 seconds
+    SysConfig.OfflinePolicy = 2;
+    SysConfig.OfflineMaxChargeEnergy = 0;
+    SysConfig.OfflineMaxChargeDuration = 0;
+    strcpy((char *) SysConfig.OcppServerURL, "");
+    strcpy((char *) SysConfig.ChargeBoxId, "");
+    SysConfig.LedInfo.Intensity = 2;
 
-	//copy default configuration to pointer
-	memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
+    //copy default configuration to pointer
+    memcpy(ptr, &SysConfig, sizeof(struct SysConfigData));
 
-	//calculate CRC
-	Chk=0;
-	for(i=0;i<(MtdBlockSize-4);i++)
-	{
-		Chk+=*(ptr+i);
-	}
-	memcpy(	ptr+MtdBlockSize-4,&Chk,4);
+    //calculate CRC
+    Chk = 0;
+    for (i = 0; i < (MtdBlockSize - 4); i++) {
+        Chk += *(ptr + i);
+    }
+    memcpy( ptr + MtdBlockSize - 4, &Chk, 4);
 
-	/*
-	* Parameter process
-	*/
-	if (argc > 1)
-	{
-		char *arg = argv[1];
-		switch (arg[0])
-		{
-		case '-':
-			switch (arg[1])
-			{
-				case 'a':
-					outType |= OUTPUT_FILE;
-					outType |= OUTPUT_FLASH;
-					break;
-				case 'f':
-					outType |= OUTPUT_FILE;
-					break;
-				case 'm':
-					outType |= OUTPUT_FLASH;
-					break;
-				default:
-					helpOutput();
-					break;
-			}
-				break;
-			default:
-				helpOutput();
-				break;
-		}
-	}
-	else
-	{
-		helpOutput();
-	}
+    /*
+    * Parameter process
+    */
+    if (argc > 1) {
+        char *arg = argv[1];
+        switch (arg[0]) {
+        case '-':
+            switch (arg[1]) {
+            case 'a':
+                outType |= OUTPUT_FILE;
+                outType |= OUTPUT_FLASH;
+                break;
+            case 'f':
+                outType |= OUTPUT_FILE;
+                break;
+            case 'm':
+                outType |= OUTPUT_FLASH;
+                break;
+            default:
+                helpOutput();
+                break;
+            }
+            break;
+        default:
+            helpOutput();
+            break;
+        }
+    } else {
+        helpOutput();
+    }
 
-	/*
-	 * Configuration bin file generate
-	*/
-	if((outType&OUTPUT_FILE)>0)
-	{
-		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
-		if (fd < 0)
-		{
-			StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
-	}
+    /*
+     * Configuration bin file generate
+    */
+    if ((outType & OUTPUT_FILE) > 0) {
+        fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
+        if (fd < 0) {
+            StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
+            free(ptr);
+            return 0;
+        }
+        wrd = write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if (wrd < MtdBlockSize) {
+            StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\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)
-		{
-			StoreLogMsg("open /dev/mtdblock12 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock12 NG\r\n");
-			free(ptr);
-			return 0;
-		}
+    /*
+    * 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) {
+            StoreLogMsg("open /dev/mtdblock12 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd = write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if (wrd < MtdBlockSize) {
+            StoreLogMsg("write /dev/mtdblock12 NG\r\n");
+            free(ptr);
+            return 0;
+        }
 
-		// Save factory default setting value to flash backup setting block
-		fd = open("/dev/mtdblock11", O_RDWR);
-		if (fd < 0)
-		{
-			StoreLogMsg("open /dev/mtdblock11 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock11 NG\r\n");
-			free(ptr);
-			return 0;
-		}
+        // Save factory default setting value to flash backup setting block
+        fd = open("/dev/mtdblock11", O_RDWR);
+        if (fd < 0) {
+            StoreLogMsg("open /dev/mtdblock11 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd = write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if (wrd < MtdBlockSize) {
+            StoreLogMsg("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)
-		{
-			StoreLogMsg("open /dev/mtdblock10 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock10 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		StoreLogMsg("FactoryConfig write to flash OK\r\n");
-	}
+        // Save factory default setting value to flash setting block
+        fd = open("/dev/mtdblock10", O_RDWR);
+        if (fd < 0) {
+            StoreLogMsg("open /dev/mtdblock10 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd = write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if (wrd < MtdBlockSize) {
+            StoreLogMsg("write /dev/mtdblock10 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        StoreLogMsg("FactoryConfig write to flash OK\r\n");
+    }
 
-	free(ptr);
+    free(ptr);
 
-	return FAIL;
+    return FAIL;
 }
 

+ 3 - 1
EVSE/Projects/DD360/Apps/Makefile

@@ -18,10 +18,12 @@ Internal485ProtocolLib = -L $(ModularizationPath)/Internal485Protocol -lInternal
 Lib_Module_RFID = "-L$(ModularizationPath)" -lModule_RFID
 Lib_Module_Upgrade = "-L$(ModularizationPath)" -lModule_Upgrade
 Lib_SQLite3 = "-L$(ModularizationPath)/ocppfiles" -lsqlite3
+#Lib_Module_RatingCurrent = "-L$(ModularizationPath)" -lModule_RatingCurrent
 
 SQLite3_H = -include$(ModularizationPath)/ocppfiles/sqlite3.h
 ModuleUpgrade_H = -include$(ModularizationPath)/Module_Upgrade.h
 RFID_H = -include$(ModularizationPath)/Module_RFID.h
+#RatingCurrent_H = -include$(ModularizationPath)/Module_RatingCurrent.h
 
 InfypwrPsuComm_H = -include$(ModularizationPath)/Infypwr_PsuCommObj.h
 InfypwrPsuComm_A = $(ModularizationPath)/libInfypwr_PsuCommObj.a
@@ -39,7 +41,7 @@ LOG_INC = Log
 MainTask:
 	$(CC) -D $(Project) -includeConfig.h $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(CFLAGS) -o main.o ReMain.c
 	$(CC) -D $(Project) -includeConfig.h $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(CFLAGS) -o timeout.o timeout.c
-	$(CC) $(TFLAGS) -o main main.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3}
+	$(CC) $(TFLAGS) -o main main.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatingCurrent)
 
 DoCommTask:
 	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o DoComm.o ReDoComm.c

+ 1 - 1
EVSE/Projects/DD360/Apps/Module_InternalComm.c

@@ -1374,7 +1374,7 @@ int InitComPort()
     tios.c_iflag = 0;
     tios.c_oflag = 0;
     tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (byte)5;     // timeout 0.5 second
+    tios.c_cc[VTIME] = (byte)0;     // timeout 0.5 second
     tios.c_lflag = 0;
     tcflush(fd, TCIFLUSH);
     ioctl (fd, TCSETS, &tios);

+ 396 - 448
EVSE/Projects/DD360/Apps/Module_PrimaryComm.c

@@ -1,51 +1,51 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
+#include    <sys/time.h>
+#include    <sys/timeb.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.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 	<math.h>
-#include	"../../define.h"
-#include	"PrimaryComm.h"
-#include 	<stdbool.h>
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-typedef unsigned char 		byte;
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct PrimaryMcuData			*ShmPrimaryMcuData;
+#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>     /*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    <math.h>
+#include    "../../define.h"
+#include    "PrimaryComm.h"
+#include    <stdbool.h>
+
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define YES                 1
+#define NO                  0
+
+typedef unsigned char       byte;
+
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct PrimaryMcuData           *ShmPrimaryMcuData;
 
 void trim(char *s);
-int mystrcmp(char *p1,char *p2);
-void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
+int mystrcmp(char *p1, char *p2);
+void substr(char *dest, const char *src, unsigned int start, unsigned int cnt);
 void split(char **arr, char *str, const char *del);
 
 int Uart1Fd;
@@ -56,7 +56,7 @@ Rtc rtc;
 
 struct timeval _flash_time;
 byte flash = NO;
-struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];	
+struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 unsigned char ChillerSwitch;
 unsigned int ChillerOnTime;
 
@@ -69,124 +69,123 @@ int StoreLogMsg(const char *fmt, ...);
 
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
-
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-	{
-		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
-			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
-		printf("%s \n", Buf);
-	}
-	else
-	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-		system(Buf);
-	}
-
-	return rc;
+    char Buf[4096 + 256];
+    char buffer[4096];
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf, 0, sizeof(Buf));
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
+        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
+        printf("%s \n", Buf);
+    } else {
+        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
+                buffer,
+                tm->tm_year + 1900, tm->tm_mon + 1);
+        system(Buf);
+    }
+
+    return rc;
 }
 
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
-	//return milli-second
-	unsigned int StartTime,StopTime;
+    //return milli-second
+    unsigned int StartTime, StopTime;
 
-	StartTime=(unsigned int)ST.time;
-	StopTime=(unsigned int)ET.time;
-	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
 }
 
 void PRINTF_FUNC(char *string, ...)
 {
-	va_list args;
-	char buffer[4096];
-	va_start(args, string);
-	vsnprintf(buffer, sizeof(buffer), string, args);
-	va_end(args);
+    va_list args;
+    char buffer[4096];
+    va_start(args, string);
+    vsnprintf(buffer, sizeof(buffer), string, args);
+    va_end(args);
 
-	DEBUG_INFO("%s \n", buffer);
+    DEBUG_INFO("%s \n", buffer);
 }
 //=================================
 // Common routine
 //=================================
-char* getTimeString(void)
+char *getTimeString(void)
 {
-	char *result=malloc(21);
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
+    char *result = malloc(21);
+    time_t timep;
+    struct tm *p;
+    time(&timep);
+    p = gmtime(&timep);
 
-	sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
 
-	return result;
+    return result;
 }
 
 void trim(char *s)
 {
-    int i=0, j, k, l=0;
+    int i = 0, j, k, l = 0;
 
-    while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
+    while ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')) {
         i++;
+    }
 
-    j = strlen(s)-1;
-    while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
+    j = strlen(s) - 1;
+    while ((s[j] == ' ') || (s[j] == '\t') || (s[j] == '\n')) {
         j--;
+    }
 
-    if(i==0 && j==strlen(s)-1) { }
-    else if(i==0) s[j+1] = '\0';
+    if (i == 0 && j == strlen(s) - 1) { }
+    else if (i == 0) { s[j + 1] = '\0'; }
     else {
-        for(k=i; k<=j; k++) s[l++] = s[k];
+        for (k = i; k <= j; k++) { s[l++] = s[k]; }
         s[l] = '\0';
     }
 }
 
-int mystrcmp(char *p1,char *p2)
+int mystrcmp(char *p1, char *p2)
 {
-    while(*p1==*p2)
-    {
-        if(*p1=='\0' || *p2=='\0')
+    while (*p1 == *p2) {
+        if (*p1 == '\0' || *p2 == '\0') {
             break;
+        }
         p1++;
         p2++;
     }
-    if(*p1=='\0' && *p2=='\0')
-        return(PASS);
-    else
-        return(FAIL);
+    if (*p1 == '\0' && *p2 == '\0') {
+        return (PASS);
+    } else {
+        return (FAIL);
+    }
 }
 
-void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
 {
-	strncpy(dest, src + start, cnt);
-	dest[cnt] = 0;
+    strncpy(dest, src + start, cnt);
+    dest[cnt] = 0;
 }
 
 void split(char **arr, char *str, const char *del)
 {
-	char *s = strtok(str, del);
+    char *s = strtok(str, del);
 
-	while(s != NULL)
-	{
-		*arr++ = s;
-		s = strtok(NULL, del);
-	}
+    while (s != NULL) {
+        *arr++ = s;
+        s = strtok(NULL, del);
+    }
 }
 
 //==========================================
@@ -194,56 +193,47 @@ void split(char **arr, char *str, const char *del)
 //==========================================
 int InitShareMemory()
 {
-	int result = PASS;
-	int MeterSMId;
-
-	//creat 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;
-   	 }
-
-   	 //creat 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;
-   	}
-
-	//creat ShmStatusCodeData
-	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-		#endif
-		result = FAIL;
-	}
-	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef ShmPrimaryMcuData
-		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-		#endif
-		result = FAIL;
-	}
+    int result = PASS;
+    int MeterSMId;
+
+    //creat 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;
+    }
+
+    //creat 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;
+    }
+
+    //creat ShmStatusCodeData
+    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+#endif
+        result = FAIL;
+    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+#ifdef ShmPrimaryMcuData
+        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+#endif
+        result = FAIL;
+    }
 
     return result;
 }
@@ -253,156 +243,138 @@ int InitShareMemory()
 //================================================
 void GetFwAndHwVersion()
 {
-	if(Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-	{
-		//PRINTF_FUNC("Primary FW Rev = %s \n", ver.Version_FW);
-		strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
-		strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
-	}
-
-	if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-		;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
+    if (Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS) {
+        //PRINTF_FUNC("Primary FW Rev = %s \n", ver.Version_FW);
+        strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
+        strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
+    }
+
+    if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+        ;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
 }
 
 void GetInputGpioStatus()
 {
-	//PRINTF_FUNC("GetInputGpioStatus \n");
-	if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS)
-	{
-		#ifndef DD360
-		ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-		ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-		#else
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
-		ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
-		#endif
-		
-		ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-		ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
-
-		ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
-		ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
-		ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
-		ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0]&0x01;	
-		ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1]&0x01;
-		ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2]&0x01;
-		ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3]&0x01;
-		/*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n", 
-		ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-		ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-		printf("ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-		printf("ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-		*/
-		//PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
-		//PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
-		//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
-		#ifndef DD360
-		if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES)
-			DEBUG_ERROR("AC Mainbreaker occur. \n");
-		#endif	
-	}
+    //PRINTF_FUNC("GetInputGpioStatus \n");
+    if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS) {
+#if !defined DD360 && !defined DD360Audi
+        ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
+        ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+#else
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
+#endif //!defined DD360 && !defined DD360Audi
+
+        ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
+        ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
+
+        ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
+        ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
+        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+        ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
+        ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
+        ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
+        ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
+        /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n",
+        ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
+        ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
+        printf("ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
+        printf("ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
+        */
+        //PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
+        //PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
+        //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
+#if !defined DD360 && !defined DD360Audi
+        if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
+            DEBUG_ERROR("AC Mainbreaker occur. \n");
+        }
+#endif //!defined DD360 && !defined DD360Audi
+    }
 }
 
 void SetOutputGpio(byte flash)
 {
-	Gpio_out gpio;
-	gpio.Button_LED[0] = flash;
-	gpio.Button_LED[1] = flash;
-
-	gpio.System_LED[0] = 0x00;
-	gpio.System_LED[1] = 0x00;
-	gpio.System_LED[2] = 0x00;
-	gpio.System_LED[3] = 0x00;
-	
-	#ifdef DD360
-	if((ChargingData[0]->PresentChargingCurrent)>=150)
-	{	
-		ChillerSwitch=1;
-		ChillerOnTime=time((time_t*)NULL);
-	}
-	else
-	{
-		if(ChillerSwitch==1)
-		{
-			if((ChargingData[0]->PresentChargingCurrent)>=100)
-			{	
-				ChillerSwitch=1;
-				ChillerOnTime=time((time_t*)NULL);
-			}
-			else
-			{
-				if((time((time_t*)NULL)-ChillerOnTime)>=600)
-				{
-					ChillerSwitch=0;
-				}
-				else
-				{
-					ChillerSwitch=1;	
-				}
-			}		
-		}	
-		else
-		{
-			ChillerSwitch=0;
-		}
-	}	
-	gpio.AC_Connector = ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
-	
-	//printf("ChargingData[0]->PresentChargingCurrent=%f,ChargingData[1]->PresentChargingCurrent=%f,ChillerSwitch=%d\n",ChargingData[0]->PresentChargingCurrent,ChargingData[1]->PresentChargingCurrent,ChillerSwitch);
-	#else
-	gpio.AC_Connector = 0x00;
-	#endif
-	gpio.AC_Breaker = 0x00;
-
-	if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS)
-	{
-		//PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash);
-	}
-	else
-	{
-		//PRINTF_FUNC("SetOutputGpio fail. \n");
-	}
+    Gpio_out gpio;
+    gpio.Button_LED[0] = flash;
+    gpio.Button_LED[1] = flash;
+
+    gpio.System_LED[0] = 0x00;
+    gpio.System_LED[1] = 0x00;
+    gpio.System_LED[2] = 0x00;
+    gpio.System_LED[3] = 0x00;
+
+#if defined DD360 || defined DD360Audi
+    if ((ChargingData[0]->PresentChargingCurrent) >= 150) {
+        ChillerSwitch = 1;
+        ChillerOnTime = time((time_t *)NULL);
+    } else {
+        if (ChillerSwitch == 1) {
+            if ((ChargingData[0]->PresentChargingCurrent) >= 100) {
+                ChillerSwitch = 1;
+                ChillerOnTime = time((time_t *)NULL);
+            } else {
+                if ((time((time_t *)NULL) - ChillerOnTime) >= 600) {
+                    ChillerSwitch = 0;
+                } else {
+                    ChillerSwitch = 1;
+                }
+            }
+        } else {
+            ChillerSwitch = 0;
+        }
+    }
+    gpio.AC_Connector = ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
+
+    //printf("ChargingData[0]->PresentChargingCurrent=%f,ChargingData[1]->PresentChargingCurrent=%f,ChillerSwitch=%d\n",ChargingData[0]->PresentChargingCurrent,ChargingData[1]->PresentChargingCurrent,ChillerSwitch);
+#else
+    gpio.AC_Connector = 0x00;
+#endif //defined DD360 || DD360Audi
+
+    gpio.AC_Breaker = 0x00;
+
+    if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS) {
+        //PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash);
+    } else {
+        //PRINTF_FUNC("SetOutputGpio fail. \n");
+    }
 }
 
 void SetRtcData()
 {
-	struct timeb csuTime;
-	struct tm *tmCSU;
-
-	ftime(&csuTime);
-	tmCSU = localtime(&csuTime.time);
-//	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//			tmCSU->tm_sec);
-
-	rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-	rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-	rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-	rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
-
-	rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-	rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
-
-	rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-	rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
-
-	rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-	rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
-
-	rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-	rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
-
-	rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-	rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
-
-	if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS)
-	{
-		//PRINTF_FUNC("SetRtc sucessfully. \n");
-	}
-	else
-	{
-		//PRINTF_FUNC("SetRtc fail. \n");
-	}
+    struct timeb csuTime;
+    struct tm *tmCSU;
+
+    ftime(&csuTime);
+    tmCSU = localtime(&csuTime.time);
+//  PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+//          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+//          tmCSU->tm_sec);
+
+    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
+    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
+    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
+    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
+
+    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
+    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
+
+    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
+    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
+
+    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
+    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
+
+    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
+    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
+
+    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
+    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
+
+    if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS) {
+        //PRINTF_FUNC("SetRtc sucessfully. \n");
+    } else {
+        //PRINTF_FUNC("SetRtc fail. \n");
+    }
 }
 
 //================================================
@@ -410,160 +382,136 @@ void SetRtcData()
 //================================================
 int InitComPort()
 {
-	int fd;
-	struct termios tios;
-
-	fd = open(priPortName, O_RDWR);
-	if(fd<=0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("open 407 Communication port NG \n");
-		#endif
-		return -1;
-	}
-	ioctl (fd, TCGETS, &tios);
-	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
-	tios.c_lflag = 0;
-	tios.c_iflag = 0;
-	tios.c_oflag = 0;
-	tios.c_cc[VMIN]=0;
-	tios.c_cc[VTIME]=(unsigned char)1;
-	tios.c_lflag=0;
-	tcflush(fd, TCIFLUSH);
-	ioctl (fd, TCSETS, &tios);
-
-	return fd;
+    int fd;
+    struct termios tios;
+
+    fd = open(priPortName, O_RDWR);
+    if (fd <= 0) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("open 407 Communication port NG \n");
+#endif
+        return -1;
+    }
+    ioctl (fd, TCGETS, &tios);
+    tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
+    tios.c_lflag = 0;
+    tios.c_iflag = 0;
+    tios.c_oflag = 0;
+    tios.c_cc[VMIN] = 0;
+    tios.c_cc[VTIME] = (unsigned char)1;
+    tios.c_lflag = 0;
+    tcflush(fd, TCIFLUSH);
+    ioctl (fd, TCSETS, &tios);
+
+    return fd;
 }
 
 unsigned long GetTimeoutValue(struct timeval _sour_time)
 {
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
+    struct timeval _end_time;
+    gettimeofday(&_end_time, NULL);
 
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
 int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
 {
-	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-			return 1;
-		}
-	}
-
-	for (byte index = 0; index < CCS_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-			return 1;
-		}
-	}
-
-	for (byte index = 0; index < GB_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-			return 1;
-		}
-	}
-
-	return 0;
+    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+            return 1;
+        }
+    }
+
+    for (byte index = 0; index < CCS_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+            return 1;
+        }
+    }
+
+    for (byte index = 0; index < GB_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+            return 1;
+        }
+    }
+
+    return 0;
 }
 
 int main(void)
 {
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-		}
-		sleep(5);
-		return 0;
-	}
-	
-	for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
-	{
-		if (!FindChargingInfoData(_index, &ChargingData[0]))
-		{
-			DEBUG_ERROR("FindChargingInfoData false \n");
-			break;
-		}
-	}
-	ChillerSwitch=0;
-	Uart1Fd = InitComPort();
-	//PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
-
-	if(Uart1Fd < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
-		#endif
-
-		if (ShmStatusCodeData != NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	SetRtcData();
-	gettimeofday(&_flash_time, NULL);
-	for(;;)
-	{
-		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00)
-		{
-			if ((GetTimeoutValue(_flash_time) / 1000) > 1000)
-			{
-				if (flash == NO)
-					flash = YES;
-				else
-					flash = NO;
-				SetOutputGpio(flash);
-				gettimeofday(&_flash_time, NULL);
-			}
-		}
-		else
-		{
-			if ((GetTimeoutValue(_flash_time) / 1000) > 5000)
-			{
-				if (flash == NO)
-					flash = YES;
-
-				SetOutputGpio(flash);
-				gettimeofday(&_flash_time, NULL);
-			}
-		}
-
-		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-		// 模組更新 FW 後,需重新做
-		if(ShmPrimaryMcuData->SelfTest_Comp != PASS)
-		{
-			//PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
-			GetFwAndHwVersion();
-			sleep(1);
-			ShmPrimaryMcuData->SelfTest_Comp = PASS;
-		}
-		else
-		{
-			GetInputGpioStatus();
-		}
-
-		usleep(100000);
-	}
-
-	return FAIL;
-}
-
+    if (InitShareMemory() == FAIL) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("InitShareMemory NG\n");
+#endif
+        if (ShmStatusCodeData != NULL) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+        }
+        sleep(5);
+        return 0;
+    }
 
+    for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+        if (!FindChargingInfoData(_index, &ChargingData[0])) {
+            DEBUG_ERROR("FindChargingInfoData false \n");
+            break;
+        }
+    }
+    ChillerSwitch = 0;
+    Uart1Fd = InitComPort();
+    //PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
+
+    if (Uart1Fd < 0) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
+#endif
+
+        if (ShmStatusCodeData != NULL) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+        }
+        sleep(5);
+        return 0;
+    }
 
+    SetRtcData();
+    gettimeofday(&_flash_time, NULL);
+    for (;;) {
+        if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00) {
+            if ((GetTimeoutValue(_flash_time) / 1000) > 1000) {
+                if (flash == NO) {
+                    flash = YES;
+                } else {
+                    flash = NO;
+                }
+                SetOutputGpio(flash);
+                gettimeofday(&_flash_time, NULL);
+            }
+        } else {
+            if ((GetTimeoutValue(_flash_time) / 1000) > 5000) {
+                if (flash == NO) {
+                    flash = YES;
+                }
+
+                SetOutputGpio(flash);
+                gettimeofday(&_flash_time, NULL);
+            }
+        }
+
+        // 蝔见��见�銋见�~ 敹����Ⅱ摰� FW ��𧋦��′擃𠉛��穿�蝣箄�敺�!!~ 閰脫芋蝯��蝞埈糓��迤�� Initial Comp.
+        // 璅∠��湔鰵 FW 敺䕘����齿鰵��
+        if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
+            //PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
+            GetFwAndHwVersion();
+            sleep(1);
+            ShmPrimaryMcuData->SelfTest_Comp = PASS;
+        } else {
+            GetInputGpioStatus();
+        }
+
+        usleep(100000);
+    }
 
+    return FAIL;
+}

+ 1 - 1
EVSE/Projects/DD360/Apps/PrimaryComm.c

@@ -33,7 +33,7 @@
 #define FAIL                -1
 
 struct Address Addr = {0x01, 0x02, 0x03, 0x04, 0xFF};
-struct Command Cmd = {0x01, 0x02, 0x0a, 0x86, 0x87, 0xe0, 0xe1, 0xe2, 0xe3};
+struct Command Cmd = {0x01, 0x02, 0x0a, 0x2C, 0x83, 0x86, 0x87, 0xe0, 0xe1, 0xe2, 0xe3};
 
 int tranceive(int fd, unsigned char *cmd, unsigned char cmd_len, unsigned char *rx)
 {

+ 24 - 17
EVSE/Projects/DD360/Apps/ReDoComm.c

@@ -682,10 +682,6 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             DEBUG_INFO("Remote start charging plugNum = %d\r\n", plugNum);
 
-            //if (getConfirmSelectedGun(plugNum - 1) == FAIL) {
-            //    DEBUG_INFO("Remote start not select gun\r\n");
-            //    break;
-            //}
 #if defined DD360Audi
             if (getSelGunWaitToAuthor(plugNum) == FAIL) {
                 DEBUG_ERROR("Remote start gun already charging\r\n");
@@ -693,7 +689,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 
             if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (plugNum)) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == LEFT_GUN_NUM &&
+                if (plugNum == LEFT_GUN_NUM &&
                         (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
                          gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
                     gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
@@ -705,7 +701,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
                 }
 
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == RIGHT_GUN_NUM &&
+                if (plugNum == RIGHT_GUN_NUM &&
                         (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
                          gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
                     gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
@@ -1358,26 +1354,38 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 {
-    uint8_t dataBuf[8] = {0};
+    uint8_t dataBuf[8] = {'\0'};
+    ConnectorState *pConnState = (ConnectorState *)dataBuf;
+    static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
 
     if (ChargingData[plugNum]->SystemStatus <= S_AUTHORIZING) {
-        dataBuf[0] = CONN_ST_IDLE;    //idle
+        pConnState->State = CONN_ST_IDLE;    //idle
         strcpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, "");
+        //strcpy(&vendorErrorCodeTmp[plugNum][0], "");
     } else if ((ChargingData[plugNum]->SystemStatus <= S_PREPARING_FOR_EVSE) ||
                (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST0) ||
                (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST1)) {
-        dataBuf[0] = CONN_ST_PREPARING;    //preparing
+        pConnState->State = CONN_ST_PREPARING;    //preparing
     } else if (ChargingData[plugNum]->SystemStatus == S_CHARGING) {
-        dataBuf[0] = CONN_ST_CHARGING;    //charging
+        pConnState->State = CONN_ST_CHARGING;    //charging
     } else if (ChargingData[plugNum]->SystemStatus == S_TERMINATING) {
-        dataBuf[0] = CONN_ST_TERMINATING;    //terminating
+        pConnState->State = CONN_ST_TERMINATING;    //terminating
     } else if ((ChargingData[plugNum]->SystemStatus == S_ALARM) ||
                (ChargingData[plugNum]->SystemStatus == S_FAULT)) {
-        dataBuf[0] = CONN_ST_ALARM;
-        if (strcmp((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, "") != 0) {
-            strncpy((char *)&dataBuf[1], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
-            DEBUG_INFO("ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+        pConnState->State = CONN_ST_ALARM;
+        strncpy((char *)pConnState->WarningCode, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
+
+        if (strcmp(&vendorErrorCodeTmp[plugNum][0], "") == 0) {
+            strncpy(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
+            vendorErrorCodeTmp[plugNum][6] = '\0';
+            DEBUG_INFO("1 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+        } else {
+            if (strncmp(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE) != 0) {
+                strncpy(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
+                vendorErrorCodeTmp[plugNum][6] = '\0';
+                DEBUG_INFO("2 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+            }
         }
     }
 
@@ -2159,11 +2167,10 @@ int main(int argc, char *argv[])
 
             initDone = messageTrigger(fd, 0, 0, REG_MODEL_NAME); //first trigger model name and connector id
         } else {
-            //checkAuthorProcess(fd, 0);
-
             plugNum = 0;
             gunID = 0;
             for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
+                checkAuthorProcess(fd, plugNum);
                 //plugNum = setup chargingData value for bottom layer
                 //gunID = (plugNum  + 1); //connector Id, 1 = left gun, 2 = right gun
                 gunID = gDoCommGblData.ConnectorID[plugNum];

+ 8 - 2
EVSE/Projects/DD360/Apps/ReDoComm.h

@@ -15,8 +15,8 @@
 
 #define MAX_REGISTER_NUM                        30
 
-#define CHECK_NETWORK_FAIL_COUNT                10
-#define CONNECT_SERVER_FAIL_COUNT               5
+#define CHECK_NETWORK_FAIL_COUNT                3//10
+#define CONNECT_SERVER_FAIL_COUNT               3//5
 #define WARNING_CODE_SIZE                       6
 
 #define MAX_VOLTAGE                             10000
@@ -128,6 +128,12 @@
 #pragma pack(push)
 #pragma pack(1)
 
+typedef struct StConnectorState {
+    uint8_t State;
+    uint8_t WarningCode[6];
+    uint8_t Reserved;
+} ConnectorState;
+
 typedef struct StConnectorIDTable {
     uint8_t DcConnID1;
     uint8_t DcConnID2;

File diff suppressed because it is too large
+ 181 - 148
EVSE/Projects/DD360/Apps/ReMain.c


+ 4 - 7
EVSE/Projects/DD360/Apps/ReModule_EvComm.c

@@ -2527,11 +2527,9 @@ void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, stru
         (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] >= vol2 + CHK_VOL_RANGE) || (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] <= vol2 - CHK_VOL_RANGE) ||
         (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) || (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
     ) {
-        PRINTF_FUNC("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f \n",
+        PRINTF_FUNC("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f\r\n",
                     vol1 / 10, cur1 / 10, vol2 / 10, cur2 / 10);
 
-
-
         LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
         LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
         LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] = vol2;
@@ -2614,11 +2612,10 @@ void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct
             (LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] <= cur1 - 5 || LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] >= cur1 + 5) ||
             (LogInfo[1][EV_LOG_OUTPUT_CAP_POW] <= pow2 - 5 || LogInfo[1][EV_LOG_OUTPUT_CAP_POW] >= pow2 + 5) ||
             (LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] <= cur2 - 5 || LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >= cur2 + 5)) {
-        PRINTF_FUNC("----------------------------------------------------- \n");
-        PRINTF_FUNC("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f \n",
+        //PRINTF_FUNC("----------------------------------------------------- \n");
+        PRINTF_FUNC("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f\r\n",
                     pow1 / 10, cur1 / 10, pow2 / 10, cur2 / 10);
-
-        PRINTF_FUNC("----------------------------------------------------- \n");
+        //PRINTF_FUNC("----------------------------------------------------- \n");
 
         LogInfo[0][EV_LOG_OUTPUT_CAP_POW] = pow1;
         LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] = cur1;

+ 28 - 14
EVSE/Projects/DD360/Apps/ReModule_InternalComm.c

@@ -671,7 +671,8 @@ void GetPersentOutputVol()
 
         for (int index = 0; index < gunCount; index++) {
             if (index == 0) {
-                if (_chargingData[index]->Evboard_id == 0x01) {
+                //if (_chargingData[index]->Evboard_id == 0x01) {
+                if (index == 0) {
 #if !defined DD360 && !defined DD360Audi
                     _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
 #else
@@ -681,7 +682,8 @@ void GetPersentOutputVol()
 #endif //!defined DD360 && !defined DD360Audi
                     _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
 
-                } else if (_chargingData[index]->Evboard_id == 0x02) {
+                    //} else if (_chargingData[index]->Evboard_id == 0x02) {
+                } else if (index == 1) {
 #if !defined DD360 && !defined DD360Audi
                     _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
 #else
@@ -748,7 +750,8 @@ void GetRelayOutputStatus()
 void CheckK1K2RelayOutput(byte index)
 {
     if (index == 0) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
+        //if (_chargingData[index]->Evboard_id == 0x01) {
+        if (index == 0) {
             if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES) {
                 _chargingData[index]->RelayK1K2Status = YES;
             } else {
@@ -778,7 +781,8 @@ void CheckK1K2RelayOutput(byte index)
                     }
                 }
             }
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
+            //} else if (_chargingData[index]->Evboard_id == 0x02) {
+        } else if (index == 1) {
             if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES) {
                 _chargingData[index]->RelayK1K2Status = YES;
             } else {
@@ -1019,7 +1023,8 @@ void SetK1K2RelayStatus(byte index)
     }
 
     if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
+        //if (_chargingData[index]->Evboard_id == 0x01) {
+        if (index == 0) {
             if (regRelay.relay_event.bits.Gun1_P == YES) {
                 outputRelay.relay_event.bits.Gun1_P = NO;
             } else if (regRelay.relay_event.bits.Gun1_N == YES) {
@@ -1031,7 +1036,8 @@ void SetK1K2RelayStatus(byte index)
                     outputRelay.relay_event.bits.CCS_Precharge = NO;
                 }
             }
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
+            //} else if (_chargingData[index]->Evboard_id == 0x02) {
+        } else if (index == 1) {
             if (regRelay.relay_event.bits.Gun2_P == YES) {
                 outputRelay.relay_event.bits.Gun2_P = NO;
             } else if (regRelay.relay_event.bits.Gun2_N == YES) {
@@ -1050,13 +1056,15 @@ void SetK1K2RelayStatus(byte index)
         if (_chargingData[index]->RelayWeldingCheck == YES)
 #endif //!defined METER_ENABLE
         {
-            if (_chargingData[index]->Evboard_id == 0x01) {
+            //if (_chargingData[index]->Evboard_id == 0x01) {
+            if (index == 0) {
                 if (regRelay.relay_event.bits.Gun1_N == NO) {
                     outputRelay.relay_event.bits.Gun1_N = YES;
                 } else if (regRelay.relay_event.bits.Gun1_P == NO) {
                     outputRelay.relay_event.bits.Gun1_P = YES;
                 }
-            } else if (_chargingData[index]->Evboard_id == 0x02) {
+                //} else if (_chargingData[index]->Evboard_id == 0x02) {
+            } else if (index == 1) {
                 if (regRelay.relay_event.bits.Gun2_N == NO) {
                     outputRelay.relay_event.bits.Gun2_N = YES;
                 } else if (regRelay.relay_event.bits.Gun2_P == NO) {
@@ -1068,13 +1076,15 @@ void SetK1K2RelayStatus(byte index)
                 _chargingData[index]->SystemStatus <= S_COMPLETE) ||
                _chargingData[index]->SystemStatus == S_ALARM) {
         if ((_chargingData[index]->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
-            if (_chargingData[index]->Evboard_id == 0x01) {
+            //if (_chargingData[index]->Evboard_id == 0x01) {
+            if (index == 0) {
                 if (regRelay.relay_event.bits.Gun1_P == YES) {
                     outputRelay.relay_event.bits.Gun1_P = NO;
                 } else if (regRelay.relay_event.bits.Gun1_N == YES) {
                     outputRelay.relay_event.bits.Gun1_N = NO;
                 }
-            } else if (_chargingData[index]->Evboard_id == 0x02) {
+                //} else if (_chargingData[index]->Evboard_id == 0x02) {
+            } else if (index == 1) {
                 if (regRelay.relay_event.bits.Gun2_P == YES) {
                     outputRelay.relay_event.bits.Gun2_P = NO;
                 } else if (regRelay.relay_event.bits.Gun2_N == YES) {
@@ -1083,7 +1093,8 @@ void SetK1K2RelayStatus(byte index)
             }
         }
     } else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
+        //if (_chargingData[index]->Evboard_id == 0x01) {
+        if (index == 0) {
 #if !defined DD360 && !defined DD360Audi
             if (_chargingData[index]->Type == _Type_CCS_2) {
                 if (gunCount == 1) {
@@ -1095,7 +1106,8 @@ void SetK1K2RelayStatus(byte index)
                 }
             }
 #endif //!defined DD360 && !defined DD360Audi
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
+            //} else if (_chargingData[index]->Evboard_id == 0x02) {
+        } else if (index == 1) {
 #if !defined DD360 && !defined DD360Audi
             if (_chargingData[index]->Type == _Type_CCS_2) {
                 if (regRelay.relay_event.bits.CCS_Precharge == NO) {
@@ -1107,7 +1119,8 @@ void SetK1K2RelayStatus(byte index)
 #endif //!defined DD360 && !defined DD360Audi
         }
     } else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST1) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
+        //if (_chargingData[index]->Evboard_id == 0x01) {
+        if (index == 0) {
 #if !defined DD360 && !defined DD360Audi
             if (_chargingData[index]->Type == _Type_CCS_2) {
                 if (gunCount == 1) {
@@ -1119,7 +1132,8 @@ void SetK1K2RelayStatus(byte index)
                 }
             }
 #endif //!defined DD360 && !defined DD360Audi
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
+            //} else if (_chargingData[index]->Evboard_id == 0x02) {
+        } else if (index == 1) {
 #if !defined DD360 && !defined DD360Audi
             if (_chargingData[index]->Type == _Type_CCS_2) {
                 if (regRelay.relay_event.bits.Gun2_P == NO) {

+ 2 - 2
EVSE/Projects/DD360/Apps/ReModule_PrimaryComm.c

@@ -249,8 +249,8 @@ void GetFwAndHwVersion()
         strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
     }
 
-    if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-        ;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
+    //if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+    //    ;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
 }
 
 void GetInputGpioStatus()

BIN
EVSE/Projects/DD360/Apps/UnsafetyOutputTask


+ 3 - 3
EVSE/Projects/DD360/Apps/main.c

@@ -4795,7 +4795,7 @@ int main(void)
                         // GFD 錯誤停止
                         RecordAlarmCode(gun_index, "012234");
                     } else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-                        (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
+                    (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
                         // UVP
                         RecordAlarmCode(gun_index, "012289");
                         ChargingTerminalProcess(gun_index);
@@ -4809,7 +4809,7 @@ int main(void)
                         RecordAlarmCode(gun_index, "012236");
                     } else if (isPrechargeStatus_gb(gun_index) == 10 &&
                                (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-                        (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/)) {
+                    (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/)) {
                         // UVP
                         RecordAlarmCode(gun_index, "012290");
                         ChargingTerminalProcess(gun_index);
@@ -4822,7 +4822,7 @@ int main(void)
                         // GFD 錯誤停止
                         RecordAlarmCode(gun_index, "012235");
                     } else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-                        (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
+                    (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
                         // UVP
                         RecordAlarmCode(gun_index, "012288");
                         ChargingTerminalProcess(gun_index);

+ 1153 - 1273
EVSE/Projects/DD360Audi/Apps/DoComm.c

@@ -1,1372 +1,1252 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
+#include    <sys/time.h>
+#include    <sys/timeb.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
- #include <signal.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	"../../define.h"
-#include 	"Config.h"
-
-//#define Debug 
-
-#define DoIPAddress	"192.168.100.1"
-#define DoTcpPort		36000
-#define TriggerMsgeNum		20
+#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/can.h>
+#include    <linux/can/raw.h>
+#include    <linux/wireless.h>
+#include    <arpa/inet.h>
+#include    <netinet/in.h>
+#include <signal.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    "../../define.h"
+#include    "Config.h"
+
+//#define Debug
+
+#define DoIPAddress "192.168.100.1"
+#define DoTcpPort       36000
+#define TriggerMsgeNum      20
 
 int StoreLogMsg(const char *fmt, ...);
 #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)
 
-struct ApplicationPacket
-{
-	unsigned char Se;
-	unsigned char Id;
-	unsigned char Op;
-	unsigned char Len;
-	unsigned char RegisterNum;
-	unsigned char Data[250];
+struct ApplicationPacket {
+    unsigned char Se;
+    unsigned char Id;
+    unsigned char Op;
+    unsigned char Len;
+    unsigned char RegisterNum;
+    unsigned char Data[250];
 };
 
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct PsuData 				*ShmPsuData;
-struct OCPP16Data				*ShmOCPP16Data;
-struct PrimaryMcuData			*ShmPrimaryMcuData;
-int 							TcpSock=0;
-unsigned char 					PacketSe;
-struct ChargingInfoData 		*ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];	
-struct timeb  					TriggerTimeUp[2][TriggerMsgeNum];
-struct WARNING_CODE_INFO		PreSysWarningInfo;
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct PsuData              *ShmPsuData;
+struct OCPP16Data               *ShmOCPP16Data;
+struct PrimaryMcuData           *ShmPrimaryMcuData;
+int                             TcpSock = 0;
+unsigned char                   PacketSe;
+struct ChargingInfoData         *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timeb                    TriggerTimeUp[2][TriggerMsgeNum];
+struct WARNING_CODE_INFO        PreSysWarningInfo;
 int DisconnectFlag;
 
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
-
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == 1)
-	{
-		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
-			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
-		printf("%s \n", Buf);
-	}
-	else
-	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-		system(Buf);
-	}
-
-	return rc;
-}	
+    char Buf[4096 + 256];
+    char buffer[4096];
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf, 0, sizeof(Buf));
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == 1) {
+        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
+        printf("%s \n", Buf);
+    } else {
+        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
+                buffer,
+                tm->tm_year + 1900, tm->tm_mon + 1);
+        system(Buf);
+    }
+
+    return rc;
+}
 
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
-	//return milli-second
-	unsigned int StartTime,StopTime;
-	
-	StartTime=(unsigned int)ST.time;
-	StopTime=(unsigned int)ET.time;
-	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
-}	
+    //return milli-second
+    unsigned int StartTime, StopTime;
+
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
+}
 
 int InitShareMemory()
 {
-	int result = 1;
-	int MeterSMId;
-
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		result = 0;
-	}
-	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
-		result = 0;
-	}
-
-	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		result = 0;
-	}
-	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-		result = 0;
-	}
-	//creat ShmPsuData
-	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmPsuData NG \n");
-		result = 0;
-	}
-	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("shmat ShmPsuData NG \n");
-		result = 0;
-	}
-	//creat ShmOCPP16Data
-	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmOCPP16Data NG \n");
-		result = 0;
-	}
-	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
-		result = 0;
-	}
-	
-	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
-	{
-		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-		result = 0;
-	}
-	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-		result = 0;
-	}
-	return result;
+    int result = 1;
+    int MeterSMId;
+
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
+        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+        result = 0;
+    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+        result = 0;
+    }
+
+    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
+        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+        result = 0;
+    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        result = 0;
+    }
+    //creat ShmPsuData
+    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
+        DEBUG_ERROR("shmget ShmPsuData NG \n");
+        result = 0;
+    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("shmat ShmPsuData NG \n");
+        result = 0;
+    }
+    //creat ShmOCPP16Data
+    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
+        DEBUG_ERROR("shmget ShmOCPP16Data NG \n");
+        result = 0;
+    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
+        result = 0;
+    }
+
+    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
+        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+        result = 0;
+    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+        result = 0;
+    }
+    return result;
 }
 
 int CheckNetworkStatus()
 {
-	//printf("ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress=%s\n",ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);	
-	if(strstr(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,"192.168.100") != NULL)
-		return 1;
-	else
-		return 0;	
+    //printf("ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress=%s\n",ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
+    if (strstr(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, "192.168.100") != NULL) {
+        return 1;
+    } else {
+        return 0;
+    }
 }
 
 int TcpConnected()
 {
-	struct sockaddr_in dest;  
-	struct timeval tv;
-	int flag;
- 
- 	if(TcpSock>0)
- 		close(TcpSock);
- 		
-	if ((TcpSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
-	{  
-        	DEBUG_ERROR("Open TCP socket NG");
-        	return -1;
-        }
-     /*   flag=fcntl (TcpSock, F_GETFL, 0); 
-        if(flag>=0)
-        {
-        	flag |= O_NONBLOCK; 	
-        	fcntl(TcpSock,F_SETFL, flag );
-        }*/
-	tv.tv_sec = 0; 
-    	tv.tv_usec = 100000; 
-    	setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
-    	setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
-    	flag = 1;
-	setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
-    	
-	memset(&dest, 0, sizeof(dest));
-	dest.sin_family = AF_INET;   
-    	dest.sin_port = htons(DoTcpPort); 
-     	inet_aton(DoIPAddress, (struct in_addr *) &dest.sin_addr.s_addr);
- 
-	if (connect(TcpSock, (struct sockaddr *) &dest, sizeof(dest)) != 0) 
-	{
-		close(TcpSock);
-        	return -1;
-    	}
-	return TcpSock;
+    struct sockaddr_in dest;
+    struct timeval tv;
+    int flag;
+
+    if (TcpSock > 0) {
+        close(TcpSock);
+    }
+
+    if ((TcpSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+        DEBUG_ERROR("Open TCP socket NG");
+        return -1;
+    }
+    /*   flag=fcntl (TcpSock, F_GETFL, 0);
+       if(flag>=0)
+       {
+           flag |= O_NONBLOCK;
+           fcntl(TcpSock,F_SETFL, flag );
+       }*/
+    tv.tv_sec = 0;
+    tv.tv_usec = 100000;
+    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
+    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
+    flag = 1;
+    setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
+
+    memset(&dest, 0, sizeof(dest));
+    dest.sin_family = AF_INET;
+    dest.sin_port = htons(DoTcpPort);
+    inet_aton(DoIPAddress, (struct in_addr *) &dest.sin_addr.s_addr);
+
+    if (connect(TcpSock, (struct sockaddr *) &dest, sizeof(dest)) != 0) {
+        close(TcpSock);
+        return -1;
+    }
+    return TcpSock;
 }
 void AddFaultCodeToBuf(unsigned char *Code)
 {
-	if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10)
-	{
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, strlen(Code));
-		ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
-	}
+    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10) {
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, strlen(Code));
+        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
+    }
 }
 
 void RemoveFaultCodeToBuf(unsigned char *Code)
 {
-	unsigned char find = 0x01;
-	char _code[7];
-	sprintf(_code,"%s", Code);
-
-	// 把相關的錯誤碼一次移除,避免重複顯示
-	while(find)
-	{
-		find = 0x00;
-		for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-		{
-			if (find == 0x00)
-			{
-				if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0)
-				{
-					find = 0x01;
-				}
-			}
-			else
-			{
-				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-					&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
-			}
-		}
-
-		if (find)
-		{
-			ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
-		}
-	}
+    unsigned char find = 0x01;
+    char _code[7];
+    sprintf(_code, "%s", Code);
+
+    // �羓㮾�𦦵��航炊蝣潔�甈∠宏�歹��踹��滩�憿舐內
+    while (find) {
+        find = 0x00;
+        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+            if (find == 0x00) {
+                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
+                    find = 0x01;
+                }
+            } else {
+                memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
+                       &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
+            }
+        }
+
+        if (find) {
+            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+        }
+    }
 }
 
 int StatusCodeProcessing(unsigned char *StatusCode)
 {
-	unsigned char Rtn=0;
-	int ByteCount,BitCount;
-	unsigned char tmp, EventCodeTmp[7];
-	
-	if(strlen(StatusCode)!=6)
-		return 0;
-	memset(EventCodeTmp,0,sizeof(EventCodeTmp));	
-	memcpy(EventCodeTmp,StatusCode,strlen(StatusCode));
-	
-	if(*(StatusCode+1)==0x34)//alarm from power cabinet itself	
-	{
-		if(StatusCode[0]==0x30)//trigger
-		{
-			for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-			{
-				if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], EventCodeTmp, 7) == 0)
-				{
-					Rtn=1;	
-					break;
-				}	
-			}
-			if(Rtn==0)
-				AddFaultCodeToBuf(EventCodeTmp);
-			Rtn=1;	
-		}					
-		else if(StatusCode[0]==0x31)//recovery
-		{
-			RemoveFaultCodeToBuf(EventCodeTmp);
-			Rtn=1;	
-		}					
-	}
-	else
-	{		
-		switch(*(StatusCode+2))
-		{
-			case 0x31://Fault
-				for(ByteCount=0;ByteCount<(sizeof(FaultStatusCode)/6);ByteCount++)
-				{
-					if(memcmp(FaultStatusCode[ByteCount]+1, StatusCode+1, 5) == 0)
-					{
-						if(StatusCode[0]==0x30)//trigger
-							ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount/8]|=1<<(ByteCount%8);
-						else if(StatusCode[0]==0x31)//recovery
-							ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount/8]&=0<<(ByteCount%8);
-						Rtn=1;	
-						break;	
-					}	
-				}
-				break;
-			case 0x32://Alarm
-				for(ByteCount=0;ByteCount<(sizeof(AlarmStatusCode)/6);ByteCount++)
-				{
-					if(memcmp(AlarmStatusCode[ByteCount]+1, StatusCode+1, 5) == 0)
-					{
-						
-						if(StatusCode[0]==0x30)//trigger
-							ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount/8]|=1<<(ByteCount%8);
-						else if(StatusCode[0]==0x31)//recovery
-							ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount/8]&=0<<(ByteCount%8);
-						Rtn=1;
-						break;	
-					}	
-				}
-				break;
-			case 0x33://Information
-				for(ByteCount=0;ByteCount<(sizeof(InfoStatusCode)/6);ByteCount++)
-				{
-					if(memcmp(InfoStatusCode[ByteCount]+1, StatusCode+1, 5) == 0)
-					{
-						if(StatusCode[0]==0x30)//trigger
-							ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount/8]|=1<<(ByteCount%8);
-						else if(StatusCode[0]==0x31)//recovery
-							ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount/8]&=0<<(ByteCount%8);
-						Rtn=1;
-						break;	
-					}	
-				}
-				break;		
-			default:
-				break;	
-		}
-	}
-
-	return Rtn;
+    unsigned char Rtn = 0;
+    int ByteCount, BitCount;
+    unsigned char tmp, EventCodeTmp[7];
+
+    if (strlen(StatusCode) != 6) {
+        return 0;
+    }
+    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+    memcpy(EventCodeTmp, StatusCode, strlen(StatusCode));
+
+    if (*(StatusCode + 1) == 0x34) { //alarm from power cabinet itself
+        if (StatusCode[0] == 0x30) { //trigger
+            for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], EventCodeTmp, 7) == 0) {
+                    Rtn = 1;
+                    break;
+                }
+            }
+            if (Rtn == 0) {
+                AddFaultCodeToBuf(EventCodeTmp);
+            }
+            Rtn = 1;
+        } else if (StatusCode[0] == 0x31) { //recovery
+            RemoveFaultCodeToBuf(EventCodeTmp);
+            Rtn = 1;
+        }
+    } else {
+        switch (*(StatusCode + 2)) {
+        case 0x31://Fault
+            for (ByteCount = 0; ByteCount < (sizeof(FaultStatusCode) / 6); ByteCount++) {
+                if (memcmp(FaultStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
+                    if (StatusCode[0] == 0x30) { //trigger
+                        ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount / 8] |= 1 << (ByteCount % 8);
+                    } else if (StatusCode[0] == 0x31) { //recovery
+                        ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount / 8] &= 0 << (ByteCount % 8);
+                    }
+                    Rtn = 1;
+                    break;
+                }
+            }
+            break;
+        case 0x32://Alarm
+            for (ByteCount = 0; ByteCount < (sizeof(AlarmStatusCode) / 6); ByteCount++) {
+                if (memcmp(AlarmStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
+
+                    if (StatusCode[0] == 0x30) { //trigger
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount / 8] |= 1 << (ByteCount % 8);
+                    } else if (StatusCode[0] == 0x31) { //recovery
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount / 8] &= 0 << (ByteCount % 8);
+                    }
+                    Rtn = 1;
+                    break;
+                }
+            }
+            break;
+        case 0x33://Information
+            for (ByteCount = 0; ByteCount < (sizeof(InfoStatusCode) / 6); ByteCount++) {
+                if (memcmp(InfoStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
+                    if (StatusCode[0] == 0x30) { //trigger
+                        ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount / 8] |= 1 << (ByteCount % 8);
+                    } else if (StatusCode[0] == 0x31) { //recovery
+                        ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount / 8] &= 0 << (ByteCount % 8);
+                    }
+                    Rtn = 1;
+                    break;
+                }
+            }
+            break;
+        default:
+            break;
+        }
+    }
+
+    return Rtn;
 }
 
 int SendPacket(unsigned char Id, unsigned char Op, unsigned char RegNum, unsigned char DataLen, unsigned char *Data)
 {
-	int Rtn=0, PacketLen,Tmp;
-	struct ApplicationPacket SendBuffer;		
-	struct timeb ST,ET;
-	
-	memset(&SendBuffer,0,sizeof(struct ApplicationPacket));
-	SendBuffer.Se=(PacketSe++);
-	SendBuffer.Id=Id;
-	SendBuffer.Op=Op;
-	SendBuffer.Len=DataLen+1;
-	SendBuffer.RegisterNum=RegNum;
-	if(DataLen>0)
-		memcpy(SendBuffer.Data,Data,DataLen);
-	PacketLen= SendBuffer.Len+4;
-	ftime(&ST);
-	while(Rtn<PacketLen)
-	{
-		Tmp=send(TcpSock, &SendBuffer+Rtn, PacketLen-Rtn, MSG_NOSIGNAL);
-		if(Tmp>0)
-			Rtn += Tmp;
-		ftime(&ET);
-		if(DiffTimeb(ST,ET)>500)
-		{
-			DisconnectFlag++;
-			if(DisconnectFlag>=10)
-				DisconnectFlag=10;
-			#ifdef Debug
-			printf("Send Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
-			Rtn,PacketLen,PacketSe,Id,Op,RegNum);
-			#endif
-			return 0;
-		}	
-	}
-	return Rtn;
+    int Rtn = 0, PacketLen, Tmp;
+    struct ApplicationPacket SendBuffer;
+    struct timeb ST, ET;
+
+    memset(&SendBuffer, 0, sizeof(struct ApplicationPacket));
+    SendBuffer.Se = (PacketSe++);
+    SendBuffer.Id = Id;
+    SendBuffer.Op = Op;
+    SendBuffer.Len = DataLen + 1;
+    SendBuffer.RegisterNum = RegNum;
+    if (DataLen > 0) {
+        memcpy(SendBuffer.Data, Data, DataLen);
+    }
+    PacketLen = SendBuffer.Len + 4;
+    ftime(&ST);
+    while (Rtn < PacketLen) {
+        Tmp = send(TcpSock, &SendBuffer + Rtn, PacketLen - Rtn, MSG_NOSIGNAL);
+        if (Tmp > 0) {
+            Rtn += Tmp;
+        }
+        ftime(&ET);
+        if (DiffTimeb(ST, ET) > 500) {
+            DisconnectFlag++;
+            if (DisconnectFlag >= 10) {
+                DisconnectFlag = 10;
+            }
+#ifdef Debug
+            printf("Send Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
+                   Rtn, PacketLen, PacketSe, Id, Op, RegNum);
+#endif
+            return 0;
+        }
+    }
+    return Rtn;
 }
 
 int RecvPacket(unsigned char *DataLen, struct ApplicationPacket *Packet)
-{	 
-	int Rtn=0, Tmp;
-	unsigned char TmpBuf[250];	
-	struct timeb ST,ET;
-	
-	memset(Packet,0,sizeof(struct ApplicationPacket));
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	ftime(&ST);
-	while(Rtn<5)
-	{
-		Tmp=recv(TcpSock, TmpBuf+Rtn, 5-Rtn, 0);
-		if(Tmp>0)
-			Rtn+=Tmp;
-		ftime(&ET);
-		if(DiffTimeb(ST,ET)>500)
-		{
-			DisconnectFlag++;
-			if(DisconnectFlag>=10)
-				DisconnectFlag=10;
-			#ifdef Debug
-			printf("Recv Packet header Timeout(%d/5)(disconnect count=%d): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
-			Rtn,DisconnectFlag,TmpBuf[0],TmpBuf[1],TmpBuf[2],TmpBuf[3],TmpBuf[4]);
-			#endif
-			return 0;
-		}	
-	}
-	if((TmpBuf[0]>255)/*||(TmpBuf[1]>2)*/||(TmpBuf[2]>3)||(TmpBuf[3]>250))
-	{
-		DEBUG_INFO("Recv Wrong Packet header (%d/5): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
-		Rtn,TmpBuf[0],TmpBuf[1],TmpBuf[2],TmpBuf[3],TmpBuf[4]);
-		return 0;
-	}	
-	memcpy(Packet,TmpBuf,5);
-	*DataLen=Packet->Len -1;
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	Rtn=0;
-	ftime(&ST);
-	while(Rtn<*DataLen)
-	{
-		Tmp=recv(TcpSock, TmpBuf+Rtn, *DataLen-Rtn, 0);
-		if(Tmp>0)
-			Rtn+=Tmp;
-		ftime(&ET);
-		if(DiffTimeb(ST,ET)>500)
-		{
-			DEBUG_INFO("Recv Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
-			Rtn,*DataLen,Packet->Se,Packet->Id,Packet->Op,Packet->RegisterNum);
-			return 0;
-		}	
-	}
-	memcpy(Packet->Data,TmpBuf,*DataLen);
-	DisconnectFlag=0;
-	return Rtn;
+{
+    int Rtn = 0, Tmp;
+    unsigned char TmpBuf[250];
+    struct timeb ST, ET;
+
+    memset(Packet, 0, sizeof(struct ApplicationPacket));
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    ftime(&ST);
+    while (Rtn < 5) {
+        Tmp = recv(TcpSock, TmpBuf + Rtn, 5 - Rtn, 0);
+        if (Tmp > 0) {
+            Rtn += Tmp;
+        }
+        ftime(&ET);
+        if (DiffTimeb(ST, ET) > 500) {
+            DisconnectFlag++;
+            if (DisconnectFlag >= 10) {
+                DisconnectFlag = 10;
+            }
+#ifdef Debug
+            printf("Recv Packet header Timeout(%d/5)(disconnect count=%d): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
+                   Rtn, DisconnectFlag, TmpBuf[0], TmpBuf[1], TmpBuf[2], TmpBuf[3], TmpBuf[4]);
+#endif
+            return 0;
+        }
+    }
+    if ((TmpBuf[0] > 255)/*||(TmpBuf[1]>2)*/ || (TmpBuf[2] > 3) || (TmpBuf[3] > 250)) {
+        DEBUG_INFO("Recv Wrong Packet header (%d/5): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
+                   Rtn, TmpBuf[0], TmpBuf[1], TmpBuf[2], TmpBuf[3], TmpBuf[4]);
+        return 0;
+    }
+    memcpy(Packet, TmpBuf, 5);
+    *DataLen = Packet->Len - 1;
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    Rtn = 0;
+    ftime(&ST);
+    while (Rtn < *DataLen) {
+        Tmp = recv(TcpSock, TmpBuf + Rtn, *DataLen - Rtn, 0);
+        if (Tmp > 0) {
+            Rtn += Tmp;
+        }
+        ftime(&ET);
+        if (DiffTimeb(ST, ET) > 500) {
+            DEBUG_INFO("Recv Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
+                       Rtn, *DataLen, Packet->Se, Packet->Id, Packet->Op, Packet->RegisterNum);
+            return 0;
+        }
+    }
+    memcpy(Packet->Data, TmpBuf, *DataLen);
+    DisconnectFlag = 0;
+    return Rtn;
 }
 
 int WriteModelName()
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	
-	memcpy(TmpBuf, ShmSysConfigAndInfo->SysConfig.ModelName,strlen(ShmSysConfigAndInfo->SysConfig.ModelName));
-	Tmp=(unsigned char)(ShmPrimaryMcuData->InputDet.bits.Key2<<2|ShmPrimaryMcuData->InputDet.bits.Key1<<1|ShmPrimaryMcuData->InputDet.bits.Key0);
-	TmpBuf[strlen(ShmSysConfigAndInfo->SysConfig.ModelName)]=Tmp;//Dispenser switch value
-	#ifdef Debug
-	printf("WriteModelName(%s)(%d) => ",ShmSysConfigAndInfo->SysConfig.ModelName,Tmp);
-	#endif		
-	if(SendPacket(0xFF, 0x02, 0x01,strlen(ShmSysConfigAndInfo->SysConfig.ModelName)+1, TmpBuf)<=0)
-	{	
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif			
-		return -1;	
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{
-		#ifdef Debug
-		printf("NG\n");
-		#endif		
-		return -1;
-	}
-	#ifdef Debug
-	printf("OK\n");
-	#endif	
-	return 1;
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+
+    memcpy(TmpBuf, ShmSysConfigAndInfo->SysConfig.ModelName, strlen(ShmSysConfigAndInfo->SysConfig.ModelName));
+    Tmp = (unsigned char)(ShmPrimaryMcuData->InputDet.bits.Key2 << 2 | ShmPrimaryMcuData->InputDet.bits.Key1 << 1 | ShmPrimaryMcuData->InputDet.bits.Key0);
+    TmpBuf[strlen(ShmSysConfigAndInfo->SysConfig.ModelName)] = Tmp; //Dispenser switch value
+#ifdef Debug
+    printf("WriteModelName(%s)(%d) => ", ShmSysConfigAndInfo->SysConfig.ModelName, Tmp);
+#endif
+    if (SendPacket(0xFF, 0x02, 0x01, strlen(ShmSysConfigAndInfo->SysConfig.ModelName) + 1, TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf("OK\n");
+#endif
+    return 1;
 }
 
 int ReadConnectorID()
 {
-	unsigned char Tmp=0;
-	struct ApplicationPacket PacketData;
-	
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	#ifdef Debug
-	printf("ReadConnectorID => ");	
-	#endif		
-	if(SendPacket(0xFF, 0x01, 0x02,0, PacketData.Data)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;	
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf("OK (Left connector ID = %d, Right connector ID = %d)\n", PacketData.Data[1], PacketData.Data[2]);	
-	#endif			
-	return 1;
+    unsigned char Tmp = 0;
+    struct ApplicationPacket PacketData;
+
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+#ifdef Debug
+    printf("ReadConnectorID => ");
+#endif
+    if (SendPacket(0xFF, 0x01, 0x02, 0, PacketData.Data) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf("OK (Left connector ID = %d, Right connector ID = %d)\n", PacketData.Data[1], PacketData.Data[2]);
+#endif
+    return 1;
 }
 
 int ReadDoStatus()
 {
-	unsigned char Tmp=0, count,Rtn;
-	struct ApplicationPacket PacketData;
-	unsigned char StatusArray[20][6];
-	unsigned char EventCodeTmp[7];
-	
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	memset(StatusArray,0,sizeof(StatusArray));
-	#ifdef Debug
-	printf("ReadDoStatus => ");	
-	#endif	
-	if(SendPacket(0x01, 0x01, 0x03,0, PacketData.Data)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	Tmp--;//decrase OK/NG byte
-	if(Tmp<6)	
-	{
-		if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount>0)
-		{
-			for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-			{
-				if(ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1]>=0x33)//from backend or power cabinet
-				{
-					memset(EventCodeTmp,0,sizeof(EventCodeTmp));	
-					memcpy(EventCodeTmp,ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],sizeof(EventCodeTmp));	
-					RemoveFaultCodeToBuf(EventCodeTmp);
-				}
-			}
-		}
-		#ifdef Debug
-		printf("no alarm (%d)\n",Tmp);
-		#endif		
-		return -1;	
-	}
-	#ifdef Debug
-	printf("OK, (%d) ",Tmp);
-	//printf("PacketData.Se=%d\n",PacketData.Se);
-	//printf("PacketData.Id=%d\n",PacketData.Id);
-	//printf("PacketData.Op=%d\n",PacketData.Op);
-	//printf("PacketData.Len=%d\n",PacketData.Len);
-	//printf("PacketData.RegisterNum=%d\n",PacketData.RegisterNum);
-	//for(Rtn=0;Rtn<=PacketData.Len-1;Rtn++)
-		//printf("PacketData.Data[%d]=0x%x\n",Rtn,PacketData.Data[Rtn]);
-	#endif		
-	for(count=0;count<Tmp;count+=6)	
-	{
-		//if((Tmp-count)<6)
-		strncpy(StatusArray[count/6],(PacketData.Data+1)+count,6);
-		Rtn=0;	
-		for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-		{
-			if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count/6], 6) == 0)
-			{
-				Rtn=1;	
-				break;
-			}	
-		}
-		if(Rtn==0)
-			AddFaultCodeToBuf(StatusArray[count/6]);					
-		//Rtn=StatusCodeProcessing(StatusArray[count/6]);
-		#ifdef Debug
-		printf("(%d)(%s) = %s,  ", count/6,Rtn==1?"Process OK":"Process NG", StatusArray[count/6]);	
-		#endif	
-	}		
-	for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-	{
-		if(ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1]>=0x33)//from backend or power cabinet
-		{
-			Rtn=0;	
-			for(count=0;count<(Tmp/6);count++)	
-			{
-				if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count], 6) == 0)
-				{	
-					Rtn=1;
-					break;
-				}	
-			}
-			if(Rtn==0)
-			{	
-				memset(EventCodeTmp,0,sizeof(EventCodeTmp));	
-				memcpy(EventCodeTmp,ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],sizeof(EventCodeTmp));	
-				RemoveFaultCodeToBuf(EventCodeTmp);
-			}
-		}
-	}
-	#ifdef Debug
-	printf("\n");
-	#endif		
-	return 1;
+    unsigned char Tmp = 0, count, Rtn;
+    struct ApplicationPacket PacketData;
+    unsigned char StatusArray[20][6];
+    unsigned char EventCodeTmp[7];
+
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    memset(StatusArray, 0, sizeof(StatusArray));
+#ifdef Debug
+    printf("ReadDoStatus => ");
+#endif
+    if (SendPacket(0x01, 0x01, 0x03, 0, PacketData.Data) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+    Tmp--;//decrase OK/NG byte
+    if (Tmp < 6) {
+        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
+            for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+                if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
+                    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                    memcpy(EventCodeTmp, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i], sizeof(EventCodeTmp));
+                    RemoveFaultCodeToBuf(EventCodeTmp);
+                }
+            }
+        }
+#ifdef Debug
+        printf("no alarm (%d)\n", Tmp);
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf("OK, (%d) ", Tmp);
+    //printf("PacketData.Se=%d\n",PacketData.Se);
+    //printf("PacketData.Id=%d\n",PacketData.Id);
+    //printf("PacketData.Op=%d\n",PacketData.Op);
+    //printf("PacketData.Len=%d\n",PacketData.Len);
+    //printf("PacketData.RegisterNum=%d\n",PacketData.RegisterNum);
+    //for(Rtn=0;Rtn<=PacketData.Len-1;Rtn++)
+    //printf("PacketData.Data[%d]=0x%x\n",Rtn,PacketData.Data[Rtn]);
+#endif
+    for (count = 0; count < Tmp; count += 6) {
+        //if((Tmp-count)<6)
+        strncpy(StatusArray[count / 6], (PacketData.Data + 1) + count, 6);
+        Rtn = 0;
+        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+            if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count / 6], 6) == 0) {
+                Rtn = 1;
+                break;
+            }
+        }
+        if (Rtn == 0) {
+            AddFaultCodeToBuf(StatusArray[count / 6]);
+        }
+        //Rtn=StatusCodeProcessing(StatusArray[count/6]);
+#ifdef Debug
+        printf("(%d)(%s) = %s,  ", count / 6, Rtn == 1 ? "Process OK" : "Process NG", StatusArray[count / 6]);
+#endif
+    }
+    for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
+            Rtn = 0;
+            for (count = 0; count < (Tmp / 6); count++) {
+                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count], 6) == 0) {
+                    Rtn = 1;
+                    break;
+                }
+            }
+            if (Rtn == 0) {
+                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                memcpy(EventCodeTmp, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i], sizeof(EventCodeTmp));
+                RemoveFaultCodeToBuf(EventCodeTmp);
+            }
+        }
+    }
+#ifdef Debug
+    printf("\n");
+#endif
+    return 1;
 }
 
 int WriteDdStatus()
 {
-	unsigned char Tmp=0,count;
-	unsigned char TmpBuf[255], CurWarnCodeTmp[10][6],PreWarnCodeTmp[10][6];
-	struct ApplicationPacket PacketData;
-	
-	if((ShmSysConfigAndInfo->SysWarningInfo.WarningCount<=0)&&(PreSysWarningInfo.WarningCount<=0))
-		return -1;
-	memset(CurWarnCodeTmp,0,sizeof(CurWarnCodeTmp));	
-	Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;	
-	for(count=0;count<Tmp;count++)
-	{
-		memcpy(CurWarnCodeTmp[count],ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count],6);
-	}		
-	memset(PreWarnCodeTmp,0,sizeof(PreWarnCodeTmp));	
-	Tmp=PreSysWarningInfo.WarningCount;
-	for(count=0;count<Tmp;count++)
-	{
-		memcpy(PreWarnCodeTmp[count],PreSysWarningInfo.WarningCode[count],6);
-	}		
-	if(strcmp(CurWarnCodeTmp,PreWarnCodeTmp)==0)
-		return -1;
-	
-	
-	/*memset(TmpBuf,0,sizeof(TmpBuf));
-	Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-	for(count=0;count<Tmp;count++)
-	{
-		memcpy(TmpBuf+(count*6),ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count],6);
-		#ifdef Debug
-		printf("WriteDdStatus(%d) = %s", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);	
-		#endif	
-	}	
-	if(SendPacket(0x01, 0x02, 0x04,strlen(TmpBuf), TmpBuf)<=0)
-		return -1;
-	*/	
-	#ifdef Debug
-	printf("WriteDdStatus => ");	
-	#endif	
-	if(SendPacket(0x01, 0x02, 0x04,strlen(CurWarnCodeTmp), CurWarnCodeTmp)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	memset(&PreSysWarningInfo,0, sizeof(struct WARNING_CODE_INFO));	
-	memcpy(&PreSysWarningInfo,&(ShmSysConfigAndInfo->SysWarningInfo),sizeof(struct WARNING_CODE_INFO));	
-	#ifdef Debug
-	printf("OK,  ");
-	Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;	
-	for(count=0;count<Tmp;count++)
-	{
-		printf("(%d)%s,  ", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);	
-	}		
-	printf("\n");
-	#endif		
-	return 1;
+    unsigned char Tmp = 0, count;
+    unsigned char TmpBuf[255], CurWarnCodeTmp[10][6], PreWarnCodeTmp[10][6];
+    struct ApplicationPacket PacketData;
+
+    if ((ShmSysConfigAndInfo->SysWarningInfo.WarningCount <= 0) && (PreSysWarningInfo.WarningCount <= 0)) {
+        return -1;
+    }
+    memset(CurWarnCodeTmp, 0, sizeof(CurWarnCodeTmp));
+    Tmp = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    for (count = 0; count < Tmp; count++) {
+        memcpy(CurWarnCodeTmp[count], ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count], 6);
+    }
+    memset(PreWarnCodeTmp, 0, sizeof(PreWarnCodeTmp));
+    Tmp = PreSysWarningInfo.WarningCount;
+    for (count = 0; count < Tmp; count++) {
+        memcpy(PreWarnCodeTmp[count], PreSysWarningInfo.WarningCode[count], 6);
+    }
+    if (strcmp(CurWarnCodeTmp, PreWarnCodeTmp) == 0) {
+        return -1;
+    }
+
+
+    /*memset(TmpBuf,0,sizeof(TmpBuf));
+    Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    for(count=0;count<Tmp;count++)
+    {
+        memcpy(TmpBuf+(count*6),ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count],6);
+        #ifdef Debug
+        printf("WriteDdStatus(%d) = %s", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);
+        #endif
+    }
+    if(SendPacket(0x01, 0x02, 0x04,strlen(TmpBuf), TmpBuf)<=0)
+        return -1;
+    */
+#ifdef Debug
+    printf("WriteDdStatus => ");
+#endif
+    if (SendPacket(0x01, 0x02, 0x04, strlen(CurWarnCodeTmp), CurWarnCodeTmp) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+    memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
+    memcpy(&PreSysWarningInfo, &(ShmSysConfigAndInfo->SysWarningInfo), sizeof(struct WARNING_CODE_INFO));
+#ifdef Debug
+    printf("OK,  ");
+    Tmp = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    for (count = 0; count < Tmp; count++) {
+        printf("(%d)%s,  ", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);
+    }
+    printf("\n");
+#endif
+    return 1;
 }
 
 int ReadChargingCapability(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	struct ApplicationPacket PacketData;
-	float MaxVolt, MaxCurrent, MaxPower;
-	
-	#ifdef Debug
-	printf("Read Charging Capability => ");	
-	#endif		
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	if(SendPacket(PlugNum, 0x01, 0x05,0, PacketData.Data)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	MaxVolt=(float)(PacketData.Data[1]<<8|PacketData.Data[2]);
-	MaxCurrent=(float)(PacketData.Data[3]<<8|PacketData.Data[4]);
-	MaxPower=(float)(PacketData.Data[5]<<8|PacketData.Data[6]);
-	if((MaxVolt>=0)&&(MaxVolt<=10000))
-		ChargingData[PlugNum-1]->MaximumChargingVoltage=MaxVolt;	
-	if((MaxCurrent>=0)&&(MaxCurrent<=5000))
-		ChargingData[PlugNum-1]->AvailableChargingCurrent=MaxCurrent;	
-	if((MaxPower>=0)&&(MaxPower<=3600))
-		ChargingData[PlugNum-1]->AvailableChargingPower=MaxPower;		
-	#ifdef Debug
-	printf(" MaxVolt=%f, MaxCurrent=%f, MaxPower=%f,\n", MaxVolt,MaxCurrent,MaxPower);	
-	#endif			
-	return 1;
+    unsigned char Tmp = 0;
+    struct ApplicationPacket PacketData;
+    float MaxVolt, MaxCurrent, MaxPower;
+
+#ifdef Debug
+    printf("Read Charging Capability => ");
+#endif
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    if (SendPacket(PlugNum, 0x01, 0x05, 0, PacketData.Data) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+    MaxVolt = (float)(PacketData.Data[1] << 8 | PacketData.Data[2]);
+    MaxCurrent = (float)(PacketData.Data[3] << 8 | PacketData.Data[4]);
+    MaxPower = (float)(PacketData.Data[5] << 8 | PacketData.Data[6]);
+    if ((MaxVolt >= 0) && (MaxVolt <= 10000)) {
+        ChargingData[PlugNum - 1]->MaximumChargingVoltage = MaxVolt;
+    }
+    if ((MaxCurrent >= 0) && (MaxCurrent <= 5000)) {
+        ChargingData[PlugNum - 1]->AvailableChargingCurrent = MaxCurrent;
+    }
+    if ((MaxPower >= 0) && (MaxPower <= 3600)) {
+        ChargingData[PlugNum - 1]->AvailableChargingPower = MaxPower;
+    }
+#ifdef Debug
+    printf(" MaxVolt=%f, MaxCurrent=%f, MaxPower=%f,\n", MaxVolt, MaxCurrent, MaxPower);
+#endif
+    return 1;
 }
 
 int WriteChargingTarget(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	float ChargingVolt, ChargingAmp;
-	
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-
-	ChargingVolt=ChargingData[PlugNum-1]->EvBatterytargetVoltage;
-	ChargingAmp=ChargingData[PlugNum-1]->EvBatterytargetCurrent;
-	ChargingVolt*=10;
-	ChargingAmp*=10;
-	TmpBuf[0]=((unsigned short)ChargingVolt>>8)&0xFF;
-	TmpBuf[1]=((unsigned short)ChargingVolt)&0xFF;
-	TmpBuf[2]=((unsigned short)ChargingAmp>>8)&0xFF;
-	TmpBuf[3]=((unsigned short)ChargingAmp)&0xFF;
-	#ifdef Debug
-	printf("WriteChargingTarget(%d), EvBatterytargetVoltage=%f,EvBatteryMaxVoltage=%f => ",
-	PlugNum,ChargingData[PlugNum-1]->EvBatterytargetVoltage,ChargingData[PlugNum-1]->EvBatteryMaxVoltage);	
-	#endif	
-	if(SendPacket(PlugNum, 0x02, 0x06,4, TmpBuf)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf("ChargingVolt=%f, ChargingAmp=%f\n", ChargingVolt/10,ChargingAmp/10);	
-	#endif	
-
-	return 1;
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+    float ChargingVolt, ChargingAmp;
+
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+
+    ChargingVolt = ChargingData[PlugNum - 1]->EvBatterytargetVoltage;
+    ChargingAmp = ChargingData[PlugNum - 1]->EvBatterytargetCurrent;
+    ChargingVolt *= 10;
+    ChargingAmp *= 10;
+    TmpBuf[0] = ((unsigned short)ChargingVolt >> 8) & 0xFF;
+    TmpBuf[1] = ((unsigned short)ChargingVolt) & 0xFF;
+    TmpBuf[2] = ((unsigned short)ChargingAmp >> 8) & 0xFF;
+    TmpBuf[3] = ((unsigned short)ChargingAmp) & 0xFF;
+#ifdef Debug
+    printf("WriteChargingTarget(%d), EvBatterytargetVoltage=%f,EvBatteryMaxVoltage=%f => ",
+           PlugNum, ChargingData[PlugNum - 1]->EvBatterytargetVoltage, ChargingData[PlugNum - 1]->EvBatteryMaxVoltage);
+#endif
+    if (SendPacket(PlugNum, 0x02, 0x06, 4, TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf("ChargingVolt=%f, ChargingAmp=%f\n", ChargingVolt / 10, ChargingAmp / 10);
+#endif
+
+    return 1;
 }
 int ReadSoftwareUpdate()
 {
-	unsigned char Tmp=0;
-	struct ApplicationPacket PacketData;
-	
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-
-	if(SendPacket(0x01, 0x01, 0x07,0, PacketData.Data)<=0)
-		return -1;
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-		return -1;	
-	if(PacketData.Data[0]!=1)//!=OK
-		return -1;		
-	if(PacketData.Data[1]!=0x01)//not update
-		return -1;			
-	return PacketData.Data[1];
+    unsigned char Tmp = 0;
+    struct ApplicationPacket PacketData;
+
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+
+    if (SendPacket(0x01, 0x01, 0x07, 0, PacketData.Data) <= 0) {
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+        return -1;
+    }
+    if (PacketData.Data[1] != 0x01) { //not update
+        return -1;
+    }
+    return PacketData.Data[1];
 }
 int WritePlugInStatus(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	TmpBuf[0]=ChargingData[PlugNum-1]->ConnectorPlugIn;
-	#ifdef Debug
-	printf("WritePlugInStatus(%d) =>",PlugNum);	
-	#endif	
-	if(SendPacket(PlugNum, 0x02, 0x08,1, TmpBuf)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf(" %s\n", TmpBuf[0]==1?"Plug-in":"Un-plug");	
-	#endif		
-
-	return 1;
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    TmpBuf[0] = ChargingData[PlugNum - 1]->ConnectorPlugIn;
+#ifdef Debug
+    printf("WritePlugInStatus(%d) =>", PlugNum);
+#endif
+    if (SendPacket(PlugNum, 0x02, 0x08, 1, TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf(" %s\n", TmpBuf[0] == 1 ? "Plug-in" : "Un-plug");
+#endif
+
+    return 1;
 }
 
 int WriteConnectorState(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	
-
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	
-	if(ChargingData[PlugNum-1]->SystemStatus<=2)
-		TmpBuf[0]=0;//idle
-	else if((ChargingData[PlugNum-1]->SystemStatus<=7)||(ChargingData[PlugNum-1]->SystemStatus==17)||(ChargingData[PlugNum-1]->SystemStatus==18))
-		TmpBuf[0]=1;//preparing 	
-	else if(ChargingData[PlugNum-1]->SystemStatus==8)
-		TmpBuf[0]=2;//charging  		
-	else if(ChargingData[PlugNum-1]->SystemStatus==9)
-		TmpBuf[0]=3;//terminating   		
-		
-	#ifdef Debug
-	printf("WriteConnectorState(%d) SystemStatus=%d,TmpBuf[0]=%d => ",PlugNum,ChargingData[PlugNum-1]->SystemStatus,TmpBuf[0]);	
-	#endif		
-	if(SendPacket(PlugNum, 0x02, 0x09,1, TmpBuf)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf(" %d\n",TmpBuf[0]);	
-	#endif		
-
-	return 1;
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+
+
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+
+    if (ChargingData[PlugNum - 1]->SystemStatus <= 2) {
+        TmpBuf[0] = 0;    //idle
+    } else if ((ChargingData[PlugNum - 1]->SystemStatus <= 7) || (ChargingData[PlugNum - 1]->SystemStatus == 17) || (ChargingData[PlugNum - 1]->SystemStatus == 18)) {
+        TmpBuf[0] = 1;    //preparing
+    } else if (ChargingData[PlugNum - 1]->SystemStatus == 8) {
+        TmpBuf[0] = 2;    //charging
+    } else if (ChargingData[PlugNum - 1]->SystemStatus == 9) {
+        TmpBuf[0] = 3;    //terminating
+    }
+
+#ifdef Debug
+    printf("WriteConnectorState(%d) SystemStatus=%d,TmpBuf[0]=%d => ", PlugNum, ChargingData[PlugNum - 1]->SystemStatus, TmpBuf[0]);
+#endif
+    if (SendPacket(PlugNum, 0x02, 0x09, 1, TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf(" %d\n", TmpBuf[0]);
+#endif
+
+    return 1;
 }
 
 int WriteUserID(unsigned char ConnectorID, unsigned char *UserID)
 {
-	unsigned char Tmp=0;
-	unsigned char TmpBuf[255];
-	struct ApplicationPacket PacketData;
-	
-	if(strlen(UserID)<=0)
-		return -1;
-	memset(TmpBuf,0,sizeof(TmpBuf));
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	strcpy(TmpBuf,UserID);
-	#ifdef Debug
-	printf("WriteUserID(%d) => ",ConnectorID);	
-	#endif		
-	if(SendPacket(ConnectorID, 0x02, 0x0A,strlen(TmpBuf), TmpBuf)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf(" StartUserId=%s, PacketData.Data[1]=%d\n", TmpBuf,PacketData.Data[1]);	
-	#endif		
-	return PacketData.Data[1];
+    unsigned char Tmp = 0;
+    unsigned char TmpBuf[255];
+    struct ApplicationPacket PacketData;
+
+    if (strlen(UserID) <= 0) {
+        return -1;
+    }
+    memset(TmpBuf, 0, sizeof(TmpBuf));
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+    strcpy(TmpBuf, UserID);
+#ifdef Debug
+    printf("WriteUserID(%d) => ", ConnectorID);
+#endif
+    if (SendPacket(ConnectorID, 0x02, 0x0A, strlen(TmpBuf), TmpBuf) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf(" StartUserId=%s, PacketData.Data[1]=%d\n", TmpBuf, PacketData.Data[1]);
+#endif
+    return PacketData.Data[1];
 }
 
 int ReadChargePermission(unsigned char PlugNum)
 {
-	unsigned char Tmp=0;
-	struct ApplicationPacket PacketData;
-	
-
-	memset(&PacketData,0,sizeof(struct ApplicationPacket));
-	#ifdef Debug
-	printf("ReadChargePermission[%d] => ", PlugNum);	
-	#endif		
-	if(SendPacket(PlugNum, 0x01, 0x0B,0, PacketData.Data)<=0)
-	{
-		#ifdef Debug
-		printf("SendPacket Fail\n");
-		#endif		
-		return -1;
-	}
-	if(RecvPacket(&Tmp, &PacketData)<=0)
-	{	
-		#ifdef Debug
-		printf("RecvPacket Fail\n");
-		#endif	
-		return -1;		
-	}
-	if(PacketData.Data[0]!=1)//!=OK
-	{	
-		#ifdef Debug
-		printf("NG\n");
-		#endif	
-		return -1;	
-	}
-	#ifdef Debug
-	printf(" %s\n", PacketData.Data[1]==1?"Permitted": "NOT permitted" );	
-	#endif			
-
-	return PacketData.Data[1];
+    unsigned char Tmp = 0;
+    struct ApplicationPacket PacketData;
+
+
+    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
+#ifdef Debug
+    printf("ReadChargePermission[%d] => ", PlugNum);
+#endif
+    if (SendPacket(PlugNum, 0x01, 0x0B, 0, PacketData.Data) <= 0) {
+#ifdef Debug
+        printf("SendPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (RecvPacket(&Tmp, &PacketData) <= 0) {
+#ifdef Debug
+        printf("RecvPacket Fail\n");
+#endif
+        return -1;
+    }
+    if (PacketData.Data[0] != 1) { //!=OK
+#ifdef Debug
+        printf("NG\n");
+#endif
+        return -1;
+    }
+#ifdef Debug
+    printf(" %s\n", PacketData.Data[1] == 1 ? "Permitted" : "NOT permitted" );
+#endif
+
+    return PacketData.Data[1];
 }
 
 int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
 {
-	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-			return 1;
-		}
-	}
-
-	for (byte index = 0; index < CCS_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-			return 1;
-		}
-	}
-
-	for (byte index = 0; index < GB_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-			return 1;
-		}
-	}
-
-	return 0;
+    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+            return 1;
+        }
+    }
+
+    for (byte index = 0; index < CCS_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+            return 1;
+        }
+    }
+
+    for (byte index = 0; index < GB_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+            return 1;
+        }
+    }
+
+    return 0;
 }
 
 int MessageTrigger(unsigned char connectorID)
 {
-	struct timeb  NowTime;
-	unsigned char Reg;
-	for(Reg=0;Reg<TriggerMsgeNum;Reg++)
-	{
-		ftime(&NowTime);
-		switch(Reg)
-		{
-			case 3://ReadDoStatus
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(ReadDoStatus())
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;
-			case 4://WriteDdStatus
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(WriteDdStatus())
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;
-			/*case 5://ReadChargingCapability
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>200)
-				{
-					if(ReadChargingCapability(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;			
-			case 6://WriteChargingTarget
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>100)
-				{
-					if(WriteChargingTarget(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;*/		
-			case 8://WritePlugInStatus
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(WritePlugInStatus(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;		
-			case 9://WriteConnectorState
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(WriteConnectorState(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;		
-			/*case 0x0B://ReadChargePermission
-				if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-				{
-					if(ReadChargePermission(connectorID))
-					{
-						ftime(&TriggerTimeUp[connectorID-1][Reg]);
-					}	
-				}
-				break;*/			
-			default:
-				break;			
-		}
-	}
+    struct timeb  NowTime;
+    unsigned char Reg;
+    for (Reg = 0; Reg < TriggerMsgeNum; Reg++) {
+        ftime(&NowTime);
+        switch (Reg) {
+        case 3://ReadDoStatus
+            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
+                if (ReadDoStatus()) {
+                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
+                }
+            }
+            break;
+        case 4://WriteDdStatus
+            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
+                if (WriteDdStatus()) {
+                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
+                }
+            }
+            break;
+        /*case 5://ReadChargingCapability
+            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>200)
+            {
+                if(ReadChargingCapability(connectorID))
+                {
+                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
+                }
+            }
+            break;
+        case 6://WriteChargingTarget
+            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>100)
+            {
+                if(WriteChargingTarget(connectorID))
+                {
+                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
+                }
+            }
+            break;*/
+        case 8://WritePlugInStatus
+            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
+                if (WritePlugInStatus(connectorID)) {
+                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
+                }
+            }
+            break;
+        case 9://WriteConnectorState
+            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
+                if (WriteConnectorState(connectorID)) {
+                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
+                }
+            }
+            break;
+        /*case 0x0B://ReadChargePermission
+            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
+            {
+                if(ReadChargePermission(connectorID))
+                {
+                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
+                }
+            }
+            break;*/
+        default:
+            break;
+        }
+    }
 }
 
-int main(int argc,char *argv[])
+int main(int argc, char *argv[])
 {
-	unsigned char Tmp,PlugNum;
-	int Rtn;
-	struct timeb  AuthNowTime;
-	
-	/**************** Initialization **********/		
-	if(InitShareMemory()==0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
-		}	
-		sleep(5);
-		return 0;
-	}
-	
-ReConnect:	
-	memset(&PreSysWarningInfo,0,sizeof(struct WARNING_CODE_INFO));
-	PacketSe=0;
-	DisconnectFlag=0;
-	for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
-	{
-		if (!FindChargingInfoData(_index, &ChargingData[0]))
-		{
-			DEBUG_ERROR("FindChargingInfoData false \n");
-			break;
-		}
-	}
-	
-	/**************** Check Network **********/		
-	DEBUG_INFO("Check Dispenser Network Information");
-	while(!CheckNetworkStatus())
-	{
-		sleep(1);
-		if(DisconnectFlag>=10)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-		}
-		else
-			DisconnectFlag++;
-	}
-	DEBUG_INFO("Dispenser Network Information checked: IP=%s Netmask=%s, Gateway=%s",
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-	
-	/**************** Power cabinet connection **********/		
-	DEBUG_INFO("Connect to Power Cabinet");
-	while(TcpConnected()<0)
-	{
-		sleep(1);
-		if(DisconnectFlag>=5)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-		}
-		else
-			DisconnectFlag++;
-	}
-	DEBUG_INFO("Power cabinet connected(TcpSock=%d): IP=%s Netmask=%s, Gateway=%s",
-	TcpSock,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-	
-	/**************** Write Model Name**********/		
-	DEBUG_INFO("Write Model Name");
-	while(WriteModelName()<0)
-	{
-		sleep(1);
-		if(DisconnectFlag>=5)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-		}
-		else
-			DisconnectFlag++;
-	}
-	DEBUG_INFO("Write Model Name OK: %s",ShmSysConfigAndInfo->SysConfig.ModelName);
-	
-	/**************** Get Connector ID**********/		
-	DEBUG_INFO("Get Connector ID");
-	while(ReadConnectorID()<0)
-	{
-		sleep(1);
-		if(DisconnectFlag>=5)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-		}
-		else
-			DisconnectFlag++;
-	}
-	DEBUG_INFO("Get Connector ID OK");
-	/*while(1)
-	{
-		//for self testin main.c
-		if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq >= _STEST_PSU_DETECT)
-		{	
-			ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
-			break;
-		}
-	}*/
-	for(Tmp=0;Tmp<TriggerMsgeNum;Tmp++)
-	{
-		ftime(&TriggerTimeUp[0][Tmp]);
-		ftime(&TriggerTimeUp[1][Tmp]);
-		usleep(50000);
-	}
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=0;
-	DEBUG_INFO("Start Communication");
-	/**************** Data transmission**********/		
-	while(1)
-	{	
-		if((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)||(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag==1))
-		{
-			ftime(&AuthNowTime);
-			if(DiffTimeb(TriggerTimeUp[0][10],AuthNowTime)>1000)
-			{	
-				Rtn=WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected,ShmSysConfigAndInfo->SysConfig.UserId);
-				if(Rtn>=0)
-				{
-					memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,0,sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
-					if(Rtn==0)
-						strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,"Invalid");
-					else
-						strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,"Accepted");	
-					ShmOCPP16Data->SpMsg.bits.AuthorizeConf=1;//isAuthorizedComplete
-					ShmOCPP16Data->SpMsg.bits.AuthorizeReq=0;
-					ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=0;
-					ShmPsuData->SystemAvailablePower=0;
-					ShmPsuData->SystemPresentPsuQuantity=0;
-				}	
-				ftime(&TriggerTimeUp[0][10]);
-			}
-		}	
-		
-		for (PlugNum = 1; PlugNum <= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; PlugNum++)
-		{
-			//printf("ChargingData[PlugNum-1]->SystemStatus=%d\n",ChargingData[PlugNum-1]->SystemStatus);
-			//printf("ShmOCPP16Data->SpMsg.bits.AuthorizeReq=%d\n",ShmOCPP16Data->SpMsg.bits.AuthorizeReq);
-			//printf("ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=%d\n",ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
-			//printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
-			//printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
-			switch(ChargingData[PlugNum-1]->SystemStatus)
-			{
-				case S_IDLE:
-				case S_RESERVATION:
-				case S_MAINTAIN:
-				case S_ALARM:
-				case S_AUTHORIZING:	
-					if((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)||(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag==1))
-					{
-						ftime(&AuthNowTime);
-						if(DiffTimeb(TriggerTimeUp[PlugNum-1][10],AuthNowTime)>1000)
-						{	
-							Rtn=WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected,ShmSysConfigAndInfo->SysConfig.UserId);
-							if(Rtn>=0)
-							{
-								memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,0,sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
-								if(Rtn==0)
-									strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,"Invalid");
-								else
-									strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,"Accepted");	
-								ShmOCPP16Data->SpMsg.bits.AuthorizeConf=1;//isAuthorizedComplete
-								ShmOCPP16Data->SpMsg.bits.AuthorizeReq=0;
-								ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=0;
-								ShmPsuData->SystemAvailablePower=0;
-								ShmPsuData->SystemPresentPsuQuantity=0;
-								ftime(&TriggerTimeUp[PlugNum-1][10]);
-								
-							}
-							ftime(&TriggerTimeUp[PlugNum-1][10]);	
-						}
-					}	
-					/*if(ReadSoftwareUpdate())//0x07
-					{
-						//firmware update
-					}*/	
-					break;
-				case S_PREPARNING: //get permission
-					//printf("S_PREPARNING\n");
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][11],AuthNowTime)>1000)
-					{	
-						if((ReadChargePermission(PlugNum))&&(ReadChargingCapability(PlugNum)))	
-						{
-							ShmPsuData->SystemAvailablePower=ChargingData[0]->AvailableChargingPower+ChargingData[1]->AvailableChargingPower;
-							ShmPsuData->SystemPresentPsuQuantity=ShmPsuData->SystemAvailablePower/30;
-						}	
-						ftime(&TriggerTimeUp[PlugNum-1][11]);
-					}
-					break;
-				case S_PREPARING_FOR_EV://wait connector lock
-					//printf("S_PREPARING_FOR_EV\n");
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][5],AuthNowTime)>1000)
-					{	
-						ReadChargingCapability(PlugNum);
-						ftime(&TriggerTimeUp[PlugNum-1][5]);
-					}
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][11],AuthNowTime)>1000)
-					{	
-						if(ReadChargePermission(PlugNum)==0)
-						{
-							DEBUG_INFO("Stop charging by power cabinet's permission");
-							ChargingData[PlugNum-1]->StopChargeFlag = 1;
-						}	
-						ftime(&TriggerTimeUp[PlugNum-1][11]);
-					}
-					break;	
-				case S_PREPARING_FOR_EVSE: //insaulation test
-				case S_CCS_PRECHARGE_ST0:
-				case S_CCS_PRECHARGE_ST1:	
-					//printf("S_PREPARING_FOR_EVSE\n");
-					WriteChargingTarget(PlugNum);
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][5],AuthNowTime)>1000)
-					{	
-						ReadChargingCapability(PlugNum);
-						ftime(&TriggerTimeUp[PlugNum-1][5]);
-					}
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][11],AuthNowTime)>1000)
-					{	
-						if(ReadChargePermission(PlugNum)==0)
-						{
-							DEBUG_INFO("Stop charging by power cabinet's permission");
-							ChargingData[PlugNum-1]->StopChargeFlag = 1;
-						}	
-						ftime(&TriggerTimeUp[PlugNum-1][11]);
-					}
-					break;	
-				case S_CHARGING: //charging
-				case S_TERMINATING:	
-					//printf("S_CHARGING,S_TERMINATING\n");
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][5],AuthNowTime)>1000)
-					{	
-						ReadChargingCapability(PlugNum);
-						ftime(&TriggerTimeUp[PlugNum-1][5]);
-					}
-					ftime(&AuthNowTime);
-					if(DiffTimeb(TriggerTimeUp[PlugNum-1][11],AuthNowTime)>1000)
-					{	
-						if(ReadChargePermission(PlugNum)==0)
-						{
-							DEBUG_INFO("Stop charging by power cabinet's permission");
-							ChargingData[PlugNum-1]->StopChargeFlag = 1;
-						}	
-						ftime(&TriggerTimeUp[PlugNum-1][11]);
-					}
-					WriteChargingTarget(PlugNum);
-					//printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
-					//printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
-					break;		
-				default:
-					break;	
-			}//switch	case
-			MessageTrigger(PlugNum);
-		}//for connector #	
-		if(DisconnectFlag>=10)
-		{
-			if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo==0)
-			{	
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo=1;
-				DEBUG_INFO("Disconnected from power cabinet...re-connecting");
-			}
-			goto ReConnect;
-		}
-	}//while(1)
-}
+    unsigned char Tmp, PlugNum;
+    int Rtn;
+    struct timeb  AuthNowTime;
+
+    /**************** Initialization **********/
+    if (InitShareMemory() == 0) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("InitShareMemory NG\n");
+#endif
+        if (ShmStatusCodeData != NULL) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+        }
+        sleep(5);
+        return 0;
+    }
+
+ReConnect:
+    memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
+    PacketSe = 0;
+    DisconnectFlag = 0;
+    for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+        if (!FindChargingInfoData(_index, &ChargingData[0])) {
+            DEBUG_ERROR("FindChargingInfoData false \n");
+            break;
+        }
+    }
+
+    /**************** Check Network **********/
+    DEBUG_INFO("Check Dispenser Network Information");
+    while (!CheckNetworkStatus()) {
+        sleep(1);
+        if (DisconnectFlag >= 10) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+        } else {
+            DisconnectFlag++;
+        }
+    }
+    DEBUG_INFO("Dispenser Network Information checked: IP=%s Netmask=%s, Gateway=%s",
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+
+    /**************** Power cabinet connection **********/
+    DEBUG_INFO("Connect to Power Cabinet");
+    while (TcpConnected() < 0) {
+        sleep(1);
+        if (DisconnectFlag >= 5) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+        } else {
+            DisconnectFlag++;
+        }
+    }
+    DEBUG_INFO("Power cabinet connected(TcpSock=%d): IP=%s Netmask=%s, Gateway=%s",
+               TcpSock,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
+               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+
+    /**************** Write Model Name**********/
+    DEBUG_INFO("Write Model Name");
+    while (WriteModelName() < 0) {
+        sleep(1);
+        if (DisconnectFlag >= 5) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+        } else {
+            DisconnectFlag++;
+        }
+    }
+    DEBUG_INFO("Write Model Name OK: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
+
+    /**************** Get Connector ID**********/
+    DEBUG_INFO("Get Connector ID");
+    while (ReadConnectorID() < 0) {
+        sleep(1);
+        if (DisconnectFlag >= 5) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+        } else {
+            DisconnectFlag++;
+        }
+    }
+    DEBUG_INFO("Get Connector ID OK");
+    /*while(1)
+    {
+        //for self testin main.c
+        if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq >= _STEST_PSU_DETECT)
+        {
+            ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
+            break;
+        }
+    }*/
+    for (Tmp = 0; Tmp < TriggerMsgeNum; Tmp++) {
+        ftime(&TriggerTimeUp[0][Tmp]);
+        ftime(&TriggerTimeUp[1][Tmp]);
+        usleep(50000);
+    }
+    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 0;
+    DEBUG_INFO("Start Communication");
+    /**************** Data transmission**********/
+    while (1) {
+        if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) || (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == 1)) {
+            ftime(&AuthNowTime);
+            if (DiffTimeb(TriggerTimeUp[0][10], AuthNowTime) > 1000) {
+                Rtn = WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected, ShmSysConfigAndInfo->SysConfig.UserId);
+                if (Rtn >= 0) {
+                    memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0, sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
+                    if (Rtn == 0) {
+                        strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
+                    } else {
+                        strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
+                    }
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; //isAuthorizedComplete
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
+                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
+                    ShmPsuData->SystemAvailablePower = 0;
+                    ShmPsuData->SystemPresentPsuQuantity = 0;
+                }
+                ftime(&TriggerTimeUp[0][10]);
+            }
+        }
+
+        for (PlugNum = 1; PlugNum <= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; PlugNum++) {
+            //printf("ChargingData[PlugNum-1]->SystemStatus=%d\n",ChargingData[PlugNum-1]->SystemStatus);
+            //printf("ShmOCPP16Data->SpMsg.bits.AuthorizeReq=%d\n",ShmOCPP16Data->SpMsg.bits.AuthorizeReq);
+            //printf("ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=%d\n",ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
+            //printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
+            //printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
+            switch (ChargingData[PlugNum - 1]->SystemStatus) {
+            case S_IDLE:
+            case S_RESERVATION:
+            case S_MAINTAIN:
+            case S_ALARM:
+            case S_AUTHORIZING:
+                if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) || (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == 1)) {
+                    ftime(&AuthNowTime);
+                    if (DiffTimeb(TriggerTimeUp[PlugNum - 1][10], AuthNowTime) > 1000) {
+                        Rtn = WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected, ShmSysConfigAndInfo->SysConfig.UserId);
+                        if (Rtn >= 0) {
+                            memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0, sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
+                            if (Rtn == 0) {
+                                strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
+                            } else {
+                                strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
+                            }
+                            ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; //isAuthorizedComplete
+                            ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
+                            ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
+                            ShmPsuData->SystemAvailablePower = 0;
+                            ShmPsuData->SystemPresentPsuQuantity = 0;
+                            ftime(&TriggerTimeUp[PlugNum - 1][10]);
+
+                        }
+                        ftime(&TriggerTimeUp[PlugNum - 1][10]);
+                    }
+                }
+                /*if(ReadSoftwareUpdate())//0x07
+                {
+                    //firmware update
+                }*/
+                break;
+            case S_PREPARNING: //get permission
+                //printf("S_PREPARNING\n");
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
+                    if ((ReadChargePermission(PlugNum)) && (ReadChargingCapability(PlugNum))) {
+                        ShmPsuData->SystemAvailablePower = ChargingData[0]->AvailableChargingPower + ChargingData[1]->AvailableChargingPower;
+                        ShmPsuData->SystemPresentPsuQuantity = ShmPsuData->SystemAvailablePower / 30;
+                    }
+                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
+                }
+                break;
+            case S_PREPARING_FOR_EV://wait connector lock
+                //printf("S_PREPARING_FOR_EV\n");
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
+                    ReadChargingCapability(PlugNum);
+                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
+                }
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
+                    if (ReadChargePermission(PlugNum) == 0) {
+                        DEBUG_INFO("Stop charging by power cabinet's permission");
+                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
+                    }
+                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
+                }
+                break;
+            case S_PREPARING_FOR_EVSE: //insaulation test
+            case S_CCS_PRECHARGE_ST0:
+            case S_CCS_PRECHARGE_ST1:
+                //printf("S_PREPARING_FOR_EVSE\n");
+                WriteChargingTarget(PlugNum);
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
+                    ReadChargingCapability(PlugNum);
+                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
+                }
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
+                    if (ReadChargePermission(PlugNum) == 0) {
+                        DEBUG_INFO("Stop charging by power cabinet's permission");
+                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
+                    }
+                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
+                }
+                break;
+            case S_CHARGING: //charging
+            case S_TERMINATING:
+                //printf("S_CHARGING,S_TERMINATING\n");
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
+                    ReadChargingCapability(PlugNum);
+                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
+                }
+                ftime(&AuthNowTime);
+                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
+                    if (ReadChargePermission(PlugNum) == 0) {
+                        DEBUG_INFO("Stop charging by power cabinet's permission");
+                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
+                    }
+                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
+                }
+                WriteChargingTarget(PlugNum);
+                //printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
+                //printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
+                break;
+            default:
+                break;
+            }//switch   case
+            MessageTrigger(PlugNum);
+        }//for connector #
+        if (DisconnectFlag >= 10) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == 0) {
+                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
+                DEBUG_INFO("Disconnected from power cabinet...re-connecting");
+            }
+            goto ReConnect;
+        }
+    }//while(1)
+}

+ 266 - 282
EVSE/Projects/DD360Audi/Apps/FactoryConfig.c

@@ -1,323 +1,307 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
+#include    <sys/time.h>
+#include    <sys/timeb.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.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/can.h>
+#include    <linux/can/raw.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>     /*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	"../../define.h"
-#include 	"Config.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    "../../define.h"
+#include    "Config.h"
 
 #define Debug
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define OUTPUT_FLASH		0x01
-#define OUTPUT_FILE			0x02
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define OUTPUT_FLASH        0x01
+#define OUTPUT_FILE         0x02
 
-struct SysConfigData 			SysConfig;
+struct SysConfigData            SysConfig;
 
 int StoreLogMsg(const char *fmt, ...);
 
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
+    char Buf[4096 + 256];
+    char buffer[4096];
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
 
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
 
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
+    memset(Buf, 0, sizeof(Buf));
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
 
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
+    sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+            tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
+            buffer,
+            tm->tm_year + 1900, tm->tm_mon + 1);
+    system(Buf);
 
-	return rc;
+    return rc;
 }
 
 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]...\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");
 }
 
 /**************************************************************************************/
 /************This task will create Factory default confgiuration file *****************/
- /***********and store it into mtdblock 10,11,12                               ****************/
+/***********and store it into mtdblock 10,11,12                               ****************/
 /**************************************************************************************/
-int main(int argc,char *argv[])
+int main(int argc, char *argv[])
 {
-	unsigned char outType=0;
-	unsigned int i,Chk, MtdBlockSize=0x600000;
-	unsigned char *ptr;
-	int fd,wrd;
+    unsigned char outType = 0;
+    unsigned int i, Chk, MtdBlockSize = 0x600000;
+    unsigned char *ptr;
+    int fd, wrd;
 
-	ptr=malloc(MtdBlockSize);
-	if(ptr==NULL)
-	{
-		#ifdef SystemLogMessage
-		StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
-		#endif
-		return 0;
-	}
-	memset(ptr, 0, MtdBlockSize);
-	memset(&SysConfig, 0, sizeof(struct SysConfigData));
+    ptr = malloc(MtdBlockSize);
+    if (ptr == NULL) {
+#ifdef SystemLogMessage
+        StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
+#endif
+        return 0;
+    }
+    memset(ptr, 0, MtdBlockSize);
+    memset(&SysConfig, 0, sizeof(struct SysConfigData));
 
-	/*
-	 * TODO: Set factory default configuration
-	*/
-	//********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
-	//
-	strcpy((char *)SysConfig.ModelName, "DDYE182V0UD2AU");
-	strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
+    /*
+     * TODO: Set factory default configuration
+    */
+    //********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
+    //
+    strcpy((char *)SysConfig.ModelName, "DDYC182V0UE2AD");
+    strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
 
-	memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
-	char Dash = '-';
+    memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
+    char Dash = '-';
 
-	strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName);
-	strncat((char *)SysConfig.SystemId, &Dash, 1);
-	strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber);
+    strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName);
+    strncat((char *)SysConfig.SystemId, &Dash, 1);
+    strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber);
 
-	strcpy((char *)SysConfig.SystemDateTime, "");
-	SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
-	SysConfig.DefaultLanguage = 0;
-	SysConfig.RfidCardNumEndian = 0;
-	SysConfig.AcPlugInTimes = 0;
-	SysConfig.GbPlugInTimes = 0;
-	SysConfig.Ccs1PlugInTime = 0;
-	SysConfig.Ccs2PlugInTimes = 0;
-	SysConfig.ChademoPlugInTimes = 0;
-	SysConfig.BillingData.isBilling = 0;
-	SysConfig.isAPP = 1;
-	SysConfig.isQRCode = 1;
-	SysConfig.isRFID = 1;
-	//********** Charging **********//
-	SysConfig.MaxChargingEnergy = 0;
-	SysConfig.MaxChargingCurrent = 500;		// 最大可輸出電流 (整樁)
-	SysConfig.MaxChargingDuration = 0;
-	SysConfig.AcMaxChargingCurrent = 0;
-	SysConfig.PhaseLossPolicy = 0;
-	/*+++ 20200908, vern, modify it +++*/
-	/*for(unsigned char i = 0; i < 10; i++)
-		strcpy((char *)SysConfig.LocalWhiteCard, "");*/
-	memset(SysConfig.LocalWhiteCard,0,sizeof(SysConfig.LocalWhiteCard));	
-	/*--- 20200908, vern, modify it ---*/
-	strcpy((char *)SysConfig.UserId, "");
-	//********** Network **********//
-	strcpy((char *)SysConfig.FtpServer, "");
-	SysConfig.Eth0Interface.EthDhcpClient = 0;
-	strcpy((char *) SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
-	strcpy((char *) SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0");
-	strcpy((char *) SysConfig.Eth0Interface.EthGatewayAddress, "192.168.1.254");
-	SysConfig.Eth1Interface.EthDhcpClient = 0;
-	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
-	strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
-	strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
-	if(SysConfig.ModelName[10] == 'W')
-		SysConfig.AthInterface.WifiMode = 2;
-	else
-		SysConfig.AthInterface.WifiMode = 0;
-	strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
-	strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
-	SysConfig.AthInterface.WifiRssi = 0;
-	SysConfig.AthInterface.WifiDhcpServer = 0;
-	SysConfig.AthInterface.WifiDhcpClient = 0;
-	strcpy((char *) SysConfig.AthInterface.WifiMacAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiIpAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiSubmaskAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiGatewayAddress, "");
-	SysConfig.AthInterface.WifiNetworkConn = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomModelName, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSoftwareVer, "");
-	//strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "Internet");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "");
-	SysConfig.TelecomInterface.TelcomRssi = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, " ");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, "");
-	SysConfig.TelecomInterface.TelcomSimStatus = 0;
-	SysConfig.TelecomInterface.TelcomModemMode = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomIpAddress, "");
-	SysConfig.TelecomInterface.TelcomNetworkConn = 0;
-	strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
-	//********** Backend **********//
-	SysConfig.BackendConnTimeout = 300; //300 seconds
-	SysConfig.OfflinePolicy = 2;
-	SysConfig.OfflineMaxChargeEnergy = 0;
-	SysConfig.OfflineMaxChargeDuration = 0;
-	strcpy((char *) SysConfig.OcppServerURL, "");
-	strcpy((char *) SysConfig.ChargeBoxId, "");
-	SysConfig.LedInfo.Intensity = 2;
+    strcpy((char *)SysConfig.SystemDateTime, "");
+    SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
+    SysConfig.DefaultLanguage = 0;
+    SysConfig.RfidCardNumEndian = 0;
+    SysConfig.AcPlugInTimes = 0;
+    SysConfig.GbPlugInTimes = 0;
+    SysConfig.Ccs1PlugInTime = 0;
+    SysConfig.Ccs2PlugInTimes = 0;
+    SysConfig.ChademoPlugInTimes = 0;
+    SysConfig.BillingData.isBilling = 0;
+    SysConfig.isAPP = 1;
+    SysConfig.isQRCode = 1;
+    SysConfig.isRFID = 1;
+    //********** Charging **********//
+    SysConfig.MaxChargingEnergy = 0;
+    SysConfig.MaxChargingCurrent = 500;     // ��憭批虾頛詨枂�餅� (�湔�)
+    SysConfig.MaxChargingDuration = 0;
+    SysConfig.AcMaxChargingCurrent = 0;
+    SysConfig.PhaseLossPolicy = 0;
+    /*+++ 20200908, vern, modify it +++*/
+    /*for(unsigned char i = 0; i < 10; i++)
+        strcpy((char *)SysConfig.LocalWhiteCard, "");*/
+    memset(SysConfig.LocalWhiteCard, 0, sizeof(SysConfig.LocalWhiteCard));
+    /*--- 20200908, vern, modify it ---*/
+    strcpy((char *)SysConfig.UserId, "");
+    //********** Network **********//
+    strcpy((char *)SysConfig.FtpServer, "");
+    SysConfig.Eth0Interface.EthDhcpClient = 0;
+    strcpy((char *) SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
+    strcpy((char *) SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0");
+    strcpy((char *) SysConfig.Eth0Interface.EthGatewayAddress, "192.168.1.254");
+    SysConfig.Eth1Interface.EthDhcpClient = 0;
+    strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
+    strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
+    strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
+    if (SysConfig.ModelName[10] == 'W') {
+        SysConfig.AthInterface.WifiMode = 2;
+    } else {
+        SysConfig.AthInterface.WifiMode = 0;
+    }
+    strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
+    strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
+    SysConfig.AthInterface.WifiRssi = 0;
+    SysConfig.AthInterface.WifiDhcpServer = 0;
+    SysConfig.AthInterface.WifiDhcpClient = 0;
+    strcpy((char *) SysConfig.AthInterface.WifiMacAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiIpAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiSubmaskAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiGatewayAddress, "");
+    SysConfig.AthInterface.WifiNetworkConn = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomModelName, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSoftwareVer, "");
+    //strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "Internet");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "");
+    SysConfig.TelecomInterface.TelcomRssi = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, " ");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, "");
+    SysConfig.TelecomInterface.TelcomSimStatus = 0;
+    SysConfig.TelecomInterface.TelcomModemMode = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomIpAddress, "");
+    SysConfig.TelecomInterface.TelcomNetworkConn = 0;
+    strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
+    //********** Backend **********//
+    SysConfig.BackendConnTimeout = 300; //300 seconds
+    SysConfig.OfflinePolicy = 2;
+    SysConfig.OfflineMaxChargeEnergy = 0;
+    SysConfig.OfflineMaxChargeDuration = 0;
+    strcpy((char *) SysConfig.OcppServerURL, "");
+    strcpy((char *) SysConfig.ChargeBoxId, "");
+    SysConfig.LedInfo.Intensity = 2;
 
-	//copy default configuration to pointer
-	memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
+    //copy default configuration to pointer
+    memcpy(ptr, &SysConfig, sizeof(struct SysConfigData));
 
-	//calculate CRC
-	Chk=0;
-	for(i=0;i<(MtdBlockSize-4);i++)
-	{
-		Chk+=*(ptr+i);
-	}
-	memcpy(	ptr+MtdBlockSize-4,&Chk,4);
+    //calculate CRC
+    Chk = 0;
+    for (i = 0; i < (MtdBlockSize - 4); i++) {
+        Chk += *(ptr + i);
+    }
+    memcpy( ptr + MtdBlockSize - 4, &Chk, 4);
 
-	/*
-	* Parameter process
-	*/
-	if (argc > 1)
-	{
-		char *arg = argv[1];
-		switch (arg[0])
-		{
-		case '-':
-			switch (arg[1])
-			{
-				case 'a':
-					outType |= OUTPUT_FILE;
-					outType |= OUTPUT_FLASH;
-					break;
-				case 'f':
-					outType |= OUTPUT_FILE;
-					break;
-				case 'm':
-					outType |= OUTPUT_FLASH;
-					break;
-				default:
-					helpOutput();
-					break;
-			}
-				break;
-			default:
-				helpOutput();
-				break;
-		}
-	}
-	else
-	{
-		helpOutput();
-	}
+    /*
+    * Parameter process
+    */
+    if (argc > 1) {
+        char *arg = argv[1];
+        switch (arg[0]) {
+        case '-':
+            switch (arg[1]) {
+            case 'a':
+                outType |= OUTPUT_FILE;
+                outType |= OUTPUT_FLASH;
+                break;
+            case 'f':
+                outType |= OUTPUT_FILE;
+                break;
+            case 'm':
+                outType |= OUTPUT_FLASH;
+                break;
+            default:
+                helpOutput();
+                break;
+            }
+            break;
+        default:
+            helpOutput();
+            break;
+        }
+    } else {
+        helpOutput();
+    }
 
-	/*
-	 * Configuration bin file generate
-	*/
-	if((outType&OUTPUT_FILE)>0)
-	{
-		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
-		if (fd < 0)
-		{
-			StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
-	}
+    /*
+     * Configuration bin file generate
+    */
+    if ((outType & OUTPUT_FILE) > 0) {
+        fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
+        if (fd < 0) {
+            StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
+            free(ptr);
+            return 0;
+        }
+        wrd = write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if (wrd < MtdBlockSize) {
+            StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\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)
-		{
-			StoreLogMsg("open /dev/mtdblock12 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock12 NG\r\n");
-			free(ptr);
-			return 0;
-		}
+    /*
+    * 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) {
+            StoreLogMsg("open /dev/mtdblock12 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd = write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if (wrd < MtdBlockSize) {
+            StoreLogMsg("write /dev/mtdblock12 NG\r\n");
+            free(ptr);
+            return 0;
+        }
 
-		// Save factory default setting value to flash backup setting block
-		fd = open("/dev/mtdblock11", O_RDWR);
-		if (fd < 0)
-		{
-			StoreLogMsg("open /dev/mtdblock11 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock11 NG\r\n");
-			free(ptr);
-			return 0;
-		}
+        // Save factory default setting value to flash backup setting block
+        fd = open("/dev/mtdblock11", O_RDWR);
+        if (fd < 0) {
+            StoreLogMsg("open /dev/mtdblock11 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd = write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if (wrd < MtdBlockSize) {
+            StoreLogMsg("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)
-		{
-			StoreLogMsg("open /dev/mtdblock10 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock10 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		StoreLogMsg("FactoryConfig write to flash OK\r\n");
-	}
+        // Save factory default setting value to flash setting block
+        fd = open("/dev/mtdblock10", O_RDWR);
+        if (fd < 0) {
+            StoreLogMsg("open /dev/mtdblock10 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd = write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if (wrd < MtdBlockSize) {
+            StoreLogMsg("write /dev/mtdblock10 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        StoreLogMsg("FactoryConfig write to flash OK\r\n");
+    }
 
-	free(ptr);
+    free(ptr);
 
-	return FAIL;
+    return FAIL;
 }
 

+ 3 - 1
EVSE/Projects/DD360Audi/Apps/Makefile

@@ -18,10 +18,12 @@ Internal485ProtocolLib = -L $(ModularizationPath)/Internal485Protocol -lInternal
 Lib_Module_RFID = "-L$(ModularizationPath)" -lModule_RFID
 Lib_Module_Upgrade = "-L$(ModularizationPath)" -lModule_Upgrade
 Lib_SQLite3 = "-L$(ModularizationPath)/ocppfiles" -lsqlite3
+#Lib_Module_RatingCurrent = "-L$(ModularizationPath)" -lModule_RatingCurrent
 
 SQLite3_H = -include$(ModularizationPath)/ocppfiles/sqlite3.h
 ModuleUpgrade_H = -include$(ModularizationPath)/Module_Upgrade.h
 RFID_H = -include$(ModularizationPath)/Module_RFID.h
+#RatingCurrent_H = -include$(ModularizationPath)/Module_RatingCurrent.h
 
 InfypwrPsuComm_H = -include$(ModularizationPath)/Infypwr_PsuCommObj.h
 InfypwrPsuComm_A = $(ModularizationPath)/libInfypwr_PsuCommObj.a
@@ -39,7 +41,7 @@ LOG_INC = Log
 MainTask:
 	$(CC) -D $(Project) -includeConfig.h $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(CFLAGS) -o main.o ReMain.c
 	$(CC) -D $(Project) -includeConfig.h $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(CFLAGS) -o timeout.o timeout.c
-	$(CC) $(TFLAGS) -o main main.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3}
+	$(CC) $(TFLAGS) -o main main.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatingCurrent)
 
 DoCommTask:
 	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o DoComm.o ReDoComm.c

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/Module_InternalComm.c

@@ -1374,7 +1374,7 @@ int InitComPort()
     tios.c_iflag = 0;
     tios.c_oflag = 0;
     tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (byte)5;     // timeout 0.5 second
+    tios.c_cc[VTIME] = (byte)0;     // timeout 0.5 second
     tios.c_lflag = 0;
     tcflush(fd, TCIFLUSH);
     ioctl (fd, TCSETS, &tios);

+ 396 - 448
EVSE/Projects/DD360Audi/Apps/Module_PrimaryComm.c

@@ -1,51 +1,51 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
+#include    <sys/time.h>
+#include    <sys/timeb.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.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 	<math.h>
-#include	"../../define.h"
-#include	"PrimaryComm.h"
-#include 	<stdbool.h>
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-typedef unsigned char 		byte;
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct PrimaryMcuData			*ShmPrimaryMcuData;
+#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>     /*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    <math.h>
+#include    "../../define.h"
+#include    "PrimaryComm.h"
+#include    <stdbool.h>
+
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define YES                 1
+#define NO                  0
+
+typedef unsigned char       byte;
+
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct PrimaryMcuData           *ShmPrimaryMcuData;
 
 void trim(char *s);
-int mystrcmp(char *p1,char *p2);
-void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
+int mystrcmp(char *p1, char *p2);
+void substr(char *dest, const char *src, unsigned int start, unsigned int cnt);
 void split(char **arr, char *str, const char *del);
 
 int Uart1Fd;
@@ -56,7 +56,7 @@ Rtc rtc;
 
 struct timeval _flash_time;
 byte flash = NO;
-struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];	
+struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 unsigned char ChillerSwitch;
 unsigned int ChillerOnTime;
 
@@ -69,124 +69,123 @@ int StoreLogMsg(const char *fmt, ...);
 
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
-
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-	{
-		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
-			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
-		printf("%s \n", Buf);
-	}
-	else
-	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-		system(Buf);
-	}
-
-	return rc;
+    char Buf[4096 + 256];
+    char buffer[4096];
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf, 0, sizeof(Buf));
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
+        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
+        printf("%s \n", Buf);
+    } else {
+        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
+                buffer,
+                tm->tm_year + 1900, tm->tm_mon + 1);
+        system(Buf);
+    }
+
+    return rc;
 }
 
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
-	//return milli-second
-	unsigned int StartTime,StopTime;
+    //return milli-second
+    unsigned int StartTime, StopTime;
 
-	StartTime=(unsigned int)ST.time;
-	StopTime=(unsigned int)ET.time;
-	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+    StartTime = (unsigned int)ST.time;
+    StopTime = (unsigned int)ET.time;
+    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
 }
 
 void PRINTF_FUNC(char *string, ...)
 {
-	va_list args;
-	char buffer[4096];
-	va_start(args, string);
-	vsnprintf(buffer, sizeof(buffer), string, args);
-	va_end(args);
+    va_list args;
+    char buffer[4096];
+    va_start(args, string);
+    vsnprintf(buffer, sizeof(buffer), string, args);
+    va_end(args);
 
-	DEBUG_INFO("%s \n", buffer);
+    DEBUG_INFO("%s \n", buffer);
 }
 //=================================
 // Common routine
 //=================================
-char* getTimeString(void)
+char *getTimeString(void)
 {
-	char *result=malloc(21);
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
+    char *result = malloc(21);
+    time_t timep;
+    struct tm *p;
+    time(&timep);
+    p = gmtime(&timep);
 
-	sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
 
-	return result;
+    return result;
 }
 
 void trim(char *s)
 {
-    int i=0, j, k, l=0;
+    int i = 0, j, k, l = 0;
 
-    while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
+    while ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')) {
         i++;
+    }
 
-    j = strlen(s)-1;
-    while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
+    j = strlen(s) - 1;
+    while ((s[j] == ' ') || (s[j] == '\t') || (s[j] == '\n')) {
         j--;
+    }
 
-    if(i==0 && j==strlen(s)-1) { }
-    else if(i==0) s[j+1] = '\0';
+    if (i == 0 && j == strlen(s) - 1) { }
+    else if (i == 0) { s[j + 1] = '\0'; }
     else {
-        for(k=i; k<=j; k++) s[l++] = s[k];
+        for (k = i; k <= j; k++) { s[l++] = s[k]; }
         s[l] = '\0';
     }
 }
 
-int mystrcmp(char *p1,char *p2)
+int mystrcmp(char *p1, char *p2)
 {
-    while(*p1==*p2)
-    {
-        if(*p1=='\0' || *p2=='\0')
+    while (*p1 == *p2) {
+        if (*p1 == '\0' || *p2 == '\0') {
             break;
+        }
         p1++;
         p2++;
     }
-    if(*p1=='\0' && *p2=='\0')
-        return(PASS);
-    else
-        return(FAIL);
+    if (*p1 == '\0' && *p2 == '\0') {
+        return (PASS);
+    } else {
+        return (FAIL);
+    }
 }
 
-void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
 {
-	strncpy(dest, src + start, cnt);
-	dest[cnt] = 0;
+    strncpy(dest, src + start, cnt);
+    dest[cnt] = 0;
 }
 
 void split(char **arr, char *str, const char *del)
 {
-	char *s = strtok(str, del);
+    char *s = strtok(str, del);
 
-	while(s != NULL)
-	{
-		*arr++ = s;
-		s = strtok(NULL, del);
-	}
+    while (s != NULL) {
+        *arr++ = s;
+        s = strtok(NULL, del);
+    }
 }
 
 //==========================================
@@ -194,56 +193,47 @@ void split(char **arr, char *str, const char *del)
 //==========================================
 int InitShareMemory()
 {
-	int result = PASS;
-	int MeterSMId;
-
-	//creat 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;
-   	 }
-
-   	 //creat 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;
-   	}
-
-	//creat ShmStatusCodeData
-	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-		#endif
-		result = FAIL;
-	}
-	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef ShmPrimaryMcuData
-		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-		#endif
-		result = FAIL;
-	}
+    int result = PASS;
+    int MeterSMId;
+
+    //creat 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;
+    }
+
+    //creat 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;
+    }
+
+    //creat ShmStatusCodeData
+    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+#endif
+        result = FAIL;
+    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+#ifdef ShmPrimaryMcuData
+        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+#endif
+        result = FAIL;
+    }
 
     return result;
 }
@@ -253,156 +243,138 @@ int InitShareMemory()
 //================================================
 void GetFwAndHwVersion()
 {
-	if(Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-	{
-		//PRINTF_FUNC("Primary FW Rev = %s \n", ver.Version_FW);
-		strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
-		strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
-	}
-
-	if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-		;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
+    if (Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS) {
+        //PRINTF_FUNC("Primary FW Rev = %s \n", ver.Version_FW);
+        strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
+        strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
+    }
+
+    if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+        ;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
 }
 
 void GetInputGpioStatus()
 {
-	//PRINTF_FUNC("GetInputGpioStatus \n");
-	if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS)
-	{
-		#ifndef DD360
-		ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-		ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-		#else
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
-		ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
-		#endif
-		
-		ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-		ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
-
-		ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
-		ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
-		ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
-		ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0]&0x01;	
-		ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1]&0x01;
-		ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2]&0x01;
-		ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3]&0x01;
-		/*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n", 
-		ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-		ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-		printf("ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-		printf("ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-		*/
-		//PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
-		//PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
-		//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
-		#ifndef DD360
-		if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES)
-			DEBUG_ERROR("AC Mainbreaker occur. \n");
-		#endif	
-	}
+    //PRINTF_FUNC("GetInputGpioStatus \n");
+    if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS) {
+#if !defined DD360 && !defined DD360Audi
+        ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
+        ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+#else
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
+#endif //!defined DD360 && !defined DD360Audi
+
+        ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
+        ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
+
+        ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
+        ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
+        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+        ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
+        ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
+        ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
+        ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
+        /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n",
+        ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
+        ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
+        printf("ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
+        printf("ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
+        */
+        //PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
+        //PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
+        //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
+#if !defined DD360 && !defined DD360Audi
+        if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
+            DEBUG_ERROR("AC Mainbreaker occur. \n");
+        }
+#endif //!defined DD360 && !defined DD360Audi
+    }
 }
 
 void SetOutputGpio(byte flash)
 {
-	Gpio_out gpio;
-	gpio.Button_LED[0] = flash;
-	gpio.Button_LED[1] = flash;
-
-	gpio.System_LED[0] = 0x00;
-	gpio.System_LED[1] = 0x00;
-	gpio.System_LED[2] = 0x00;
-	gpio.System_LED[3] = 0x00;
-	
-	#ifdef DD360
-	if((ChargingData[0]->PresentChargingCurrent)>=150)
-	{	
-		ChillerSwitch=1;
-		ChillerOnTime=time((time_t*)NULL);
-	}
-	else
-	{
-		if(ChillerSwitch==1)
-		{
-			if((ChargingData[0]->PresentChargingCurrent)>=100)
-			{	
-				ChillerSwitch=1;
-				ChillerOnTime=time((time_t*)NULL);
-			}
-			else
-			{
-				if((time((time_t*)NULL)-ChillerOnTime)>=600)
-				{
-					ChillerSwitch=0;
-				}
-				else
-				{
-					ChillerSwitch=1;	
-				}
-			}		
-		}	
-		else
-		{
-			ChillerSwitch=0;
-		}
-	}	
-	gpio.AC_Connector = ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
-	
-	//printf("ChargingData[0]->PresentChargingCurrent=%f,ChargingData[1]->PresentChargingCurrent=%f,ChillerSwitch=%d\n",ChargingData[0]->PresentChargingCurrent,ChargingData[1]->PresentChargingCurrent,ChillerSwitch);
-	#else
-	gpio.AC_Connector = 0x00;
-	#endif
-	gpio.AC_Breaker = 0x00;
-
-	if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS)
-	{
-		//PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash);
-	}
-	else
-	{
-		//PRINTF_FUNC("SetOutputGpio fail. \n");
-	}
+    Gpio_out gpio;
+    gpio.Button_LED[0] = flash;
+    gpio.Button_LED[1] = flash;
+
+    gpio.System_LED[0] = 0x00;
+    gpio.System_LED[1] = 0x00;
+    gpio.System_LED[2] = 0x00;
+    gpio.System_LED[3] = 0x00;
+
+#if defined DD360 || defined DD360Audi
+    if ((ChargingData[0]->PresentChargingCurrent) >= 150) {
+        ChillerSwitch = 1;
+        ChillerOnTime = time((time_t *)NULL);
+    } else {
+        if (ChillerSwitch == 1) {
+            if ((ChargingData[0]->PresentChargingCurrent) >= 100) {
+                ChillerSwitch = 1;
+                ChillerOnTime = time((time_t *)NULL);
+            } else {
+                if ((time((time_t *)NULL) - ChillerOnTime) >= 600) {
+                    ChillerSwitch = 0;
+                } else {
+                    ChillerSwitch = 1;
+                }
+            }
+        } else {
+            ChillerSwitch = 0;
+        }
+    }
+    gpio.AC_Connector = ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
+
+    //printf("ChargingData[0]->PresentChargingCurrent=%f,ChargingData[1]->PresentChargingCurrent=%f,ChillerSwitch=%d\n",ChargingData[0]->PresentChargingCurrent,ChargingData[1]->PresentChargingCurrent,ChillerSwitch);
+#else
+    gpio.AC_Connector = 0x00;
+#endif //defined DD360 || DD360Audi
+
+    gpio.AC_Breaker = 0x00;
+
+    if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS) {
+        //PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash);
+    } else {
+        //PRINTF_FUNC("SetOutputGpio fail. \n");
+    }
 }
 
 void SetRtcData()
 {
-	struct timeb csuTime;
-	struct tm *tmCSU;
-
-	ftime(&csuTime);
-	tmCSU = localtime(&csuTime.time);
-//	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//			tmCSU->tm_sec);
-
-	rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-	rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-	rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-	rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
-
-	rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-	rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
-
-	rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-	rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
-
-	rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-	rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
-
-	rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-	rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
-
-	rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-	rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
-
-	if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS)
-	{
-		//PRINTF_FUNC("SetRtc sucessfully. \n");
-	}
-	else
-	{
-		//PRINTF_FUNC("SetRtc fail. \n");
-	}
+    struct timeb csuTime;
+    struct tm *tmCSU;
+
+    ftime(&csuTime);
+    tmCSU = localtime(&csuTime.time);
+//  PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+//          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+//          tmCSU->tm_sec);
+
+    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
+    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
+    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
+    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
+
+    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
+    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
+
+    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
+    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
+
+    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
+    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
+
+    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
+    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
+
+    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
+    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
+
+    if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS) {
+        //PRINTF_FUNC("SetRtc sucessfully. \n");
+    } else {
+        //PRINTF_FUNC("SetRtc fail. \n");
+    }
 }
 
 //================================================
@@ -410,160 +382,136 @@ void SetRtcData()
 //================================================
 int InitComPort()
 {
-	int fd;
-	struct termios tios;
-
-	fd = open(priPortName, O_RDWR);
-	if(fd<=0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("open 407 Communication port NG \n");
-		#endif
-		return -1;
-	}
-	ioctl (fd, TCGETS, &tios);
-	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
-	tios.c_lflag = 0;
-	tios.c_iflag = 0;
-	tios.c_oflag = 0;
-	tios.c_cc[VMIN]=0;
-	tios.c_cc[VTIME]=(unsigned char)1;
-	tios.c_lflag=0;
-	tcflush(fd, TCIFLUSH);
-	ioctl (fd, TCSETS, &tios);
-
-	return fd;
+    int fd;
+    struct termios tios;
+
+    fd = open(priPortName, O_RDWR);
+    if (fd <= 0) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("open 407 Communication port NG \n");
+#endif
+        return -1;
+    }
+    ioctl (fd, TCGETS, &tios);
+    tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
+    tios.c_lflag = 0;
+    tios.c_iflag = 0;
+    tios.c_oflag = 0;
+    tios.c_cc[VMIN] = 0;
+    tios.c_cc[VTIME] = (unsigned char)1;
+    tios.c_lflag = 0;
+    tcflush(fd, TCIFLUSH);
+    ioctl (fd, TCSETS, &tios);
+
+    return fd;
 }
 
 unsigned long GetTimeoutValue(struct timeval _sour_time)
 {
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
+    struct timeval _end_time;
+    gettimeofday(&_end_time, NULL);
 
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
 int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
 {
-	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-			return 1;
-		}
-	}
-
-	for (byte index = 0; index < CCS_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-			return 1;
-		}
-	}
-
-	for (byte index = 0; index < GB_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-			return 1;
-		}
-	}
-
-	return 0;
+    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+            return 1;
+        }
+    }
+
+    for (byte index = 0; index < CCS_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+            return 1;
+        }
+    }
+
+    for (byte index = 0; index < GB_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
+            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+            return 1;
+        }
+    }
+
+    return 0;
 }
 
 int main(void)
 {
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-		}
-		sleep(5);
-		return 0;
-	}
-	
-	for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
-	{
-		if (!FindChargingInfoData(_index, &ChargingData[0]))
-		{
-			DEBUG_ERROR("FindChargingInfoData false \n");
-			break;
-		}
-	}
-	ChillerSwitch=0;
-	Uart1Fd = InitComPort();
-	//PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
-
-	if(Uart1Fd < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
-		#endif
-
-		if (ShmStatusCodeData != NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	SetRtcData();
-	gettimeofday(&_flash_time, NULL);
-	for(;;)
-	{
-		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00)
-		{
-			if ((GetTimeoutValue(_flash_time) / 1000) > 1000)
-			{
-				if (flash == NO)
-					flash = YES;
-				else
-					flash = NO;
-				SetOutputGpio(flash);
-				gettimeofday(&_flash_time, NULL);
-			}
-		}
-		else
-		{
-			if ((GetTimeoutValue(_flash_time) / 1000) > 5000)
-			{
-				if (flash == NO)
-					flash = YES;
-
-				SetOutputGpio(flash);
-				gettimeofday(&_flash_time, NULL);
-			}
-		}
-
-		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-		// 模組更新 FW 後,需重新做
-		if(ShmPrimaryMcuData->SelfTest_Comp != PASS)
-		{
-			//PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
-			GetFwAndHwVersion();
-			sleep(1);
-			ShmPrimaryMcuData->SelfTest_Comp = PASS;
-		}
-		else
-		{
-			GetInputGpioStatus();
-		}
-
-		usleep(100000);
-	}
-
-	return FAIL;
-}
-
+    if (InitShareMemory() == FAIL) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("InitShareMemory NG\n");
+#endif
+        if (ShmStatusCodeData != NULL) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+        }
+        sleep(5);
+        return 0;
+    }
 
+    for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+        if (!FindChargingInfoData(_index, &ChargingData[0])) {
+            DEBUG_ERROR("FindChargingInfoData false \n");
+            break;
+        }
+    }
+    ChillerSwitch = 0;
+    Uart1Fd = InitComPort();
+    //PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
+
+    if (Uart1Fd < 0) {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
+#endif
+
+        if (ShmStatusCodeData != NULL) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+        }
+        sleep(5);
+        return 0;
+    }
 
+    SetRtcData();
+    gettimeofday(&_flash_time, NULL);
+    for (;;) {
+        if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00) {
+            if ((GetTimeoutValue(_flash_time) / 1000) > 1000) {
+                if (flash == NO) {
+                    flash = YES;
+                } else {
+                    flash = NO;
+                }
+                SetOutputGpio(flash);
+                gettimeofday(&_flash_time, NULL);
+            }
+        } else {
+            if ((GetTimeoutValue(_flash_time) / 1000) > 5000) {
+                if (flash == NO) {
+                    flash = YES;
+                }
+
+                SetOutputGpio(flash);
+                gettimeofday(&_flash_time, NULL);
+            }
+        }
+
+        // 蝔见��见�銋见�~ 敹����Ⅱ摰� FW ��𧋦��′擃𠉛��穿�蝣箄�敺�!!~ 閰脫芋蝯��蝞埈糓��迤�� Initial Comp.
+        // 璅∠��湔鰵 FW 敺䕘����齿鰵��
+        if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
+            //PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
+            GetFwAndHwVersion();
+            sleep(1);
+            ShmPrimaryMcuData->SelfTest_Comp = PASS;
+        } else {
+            GetInputGpioStatus();
+        }
+
+        usleep(100000);
+    }
 
+    return FAIL;
+}

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/PrimaryComm.c

@@ -33,7 +33,7 @@
 #define FAIL                -1
 
 struct Address Addr = {0x01, 0x02, 0x03, 0x04, 0xFF};
-struct Command Cmd = {0x01, 0x02, 0x0a, 0x86, 0x87, 0xe0, 0xe1, 0xe2, 0xe3};
+struct Command Cmd = {0x01, 0x02, 0x0a, 0x2C, 0x83, 0x86, 0x87, 0xe0, 0xe1, 0xe2, 0xe3};
 
 int tranceive(int fd, unsigned char *cmd, unsigned char cmd_len, unsigned char *rx)
 {

+ 24 - 17
EVSE/Projects/DD360Audi/Apps/ReDoComm.c

@@ -682,10 +682,6 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             DEBUG_INFO("Remote start charging plugNum = %d\r\n", plugNum);
 
-            //if (getConfirmSelectedGun(plugNum - 1) == FAIL) {
-            //    DEBUG_INFO("Remote start not select gun\r\n");
-            //    break;
-            //}
 #if defined DD360Audi
             if (getSelGunWaitToAuthor(plugNum) == FAIL) {
                 DEBUG_ERROR("Remote start gun already charging\r\n");
@@ -693,7 +689,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 
             if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (plugNum)) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == LEFT_GUN_NUM &&
+                if (plugNum == LEFT_GUN_NUM &&
                         (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
                          gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
                     gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
@@ -705,7 +701,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
                 }
 
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == RIGHT_GUN_NUM &&
+                if (plugNum == RIGHT_GUN_NUM &&
                         (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
                          gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
                     gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
@@ -1358,26 +1354,38 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 {
-    uint8_t dataBuf[8] = {0};
+    uint8_t dataBuf[8] = {'\0'};
+    ConnectorState *pConnState = (ConnectorState *)dataBuf;
+    static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
 
     if (ChargingData[plugNum]->SystemStatus <= S_AUTHORIZING) {
-        dataBuf[0] = CONN_ST_IDLE;    //idle
+        pConnState->State = CONN_ST_IDLE;    //idle
         strcpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, "");
+        //strcpy(&vendorErrorCodeTmp[plugNum][0], "");
     } else if ((ChargingData[plugNum]->SystemStatus <= S_PREPARING_FOR_EVSE) ||
                (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST0) ||
                (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST1)) {
-        dataBuf[0] = CONN_ST_PREPARING;    //preparing
+        pConnState->State = CONN_ST_PREPARING;    //preparing
     } else if (ChargingData[plugNum]->SystemStatus == S_CHARGING) {
-        dataBuf[0] = CONN_ST_CHARGING;    //charging
+        pConnState->State = CONN_ST_CHARGING;    //charging
     } else if (ChargingData[plugNum]->SystemStatus == S_TERMINATING) {
-        dataBuf[0] = CONN_ST_TERMINATING;    //terminating
+        pConnState->State = CONN_ST_TERMINATING;    //terminating
     } else if ((ChargingData[plugNum]->SystemStatus == S_ALARM) ||
                (ChargingData[plugNum]->SystemStatus == S_FAULT)) {
-        dataBuf[0] = CONN_ST_ALARM;
-        if (strcmp((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, "") != 0) {
-            strncpy((char *)&dataBuf[1], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
-            DEBUG_INFO("ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+        pConnState->State = CONN_ST_ALARM;
+        strncpy((char *)pConnState->WarningCode, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
+
+        if (strcmp(&vendorErrorCodeTmp[plugNum][0], "") == 0) {
+            strncpy(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
+            vendorErrorCodeTmp[plugNum][6] = '\0';
+            DEBUG_INFO("1 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+        } else {
+            if (strncmp(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE) != 0) {
+                strncpy(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
+                vendorErrorCodeTmp[plugNum][6] = '\0';
+                DEBUG_INFO("2 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+            }
         }
     }
 
@@ -2159,11 +2167,10 @@ int main(int argc, char *argv[])
 
             initDone = messageTrigger(fd, 0, 0, REG_MODEL_NAME); //first trigger model name and connector id
         } else {
-            //checkAuthorProcess(fd, 0);
-
             plugNum = 0;
             gunID = 0;
             for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
+                checkAuthorProcess(fd, plugNum);
                 //plugNum = setup chargingData value for bottom layer
                 //gunID = (plugNum  + 1); //connector Id, 1 = left gun, 2 = right gun
                 gunID = gDoCommGblData.ConnectorID[plugNum];

+ 8 - 2
EVSE/Projects/DD360Audi/Apps/ReDoComm.h

@@ -15,8 +15,8 @@
 
 #define MAX_REGISTER_NUM                        30
 
-#define CHECK_NETWORK_FAIL_COUNT                10
-#define CONNECT_SERVER_FAIL_COUNT               5
+#define CHECK_NETWORK_FAIL_COUNT                3//10
+#define CONNECT_SERVER_FAIL_COUNT               3//5
 #define WARNING_CODE_SIZE                       6
 
 #define MAX_VOLTAGE                             10000
@@ -128,6 +128,12 @@
 #pragma pack(push)
 #pragma pack(1)
 
+typedef struct StConnectorState {
+    uint8_t State;
+    uint8_t WarningCode[6];
+    uint8_t Reserved;
+} ConnectorState;
+
 typedef struct StConnectorIDTable {
     uint8_t DcConnID1;
     uint8_t DcConnID2;

File diff suppressed because it is too large
+ 181 - 148
EVSE/Projects/DD360Audi/Apps/ReMain.c


+ 4 - 7
EVSE/Projects/DD360Audi/Apps/ReModule_EvComm.c

@@ -2527,11 +2527,9 @@ void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, stru
         (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] >= vol2 + CHK_VOL_RANGE) || (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] <= vol2 - CHK_VOL_RANGE) ||
         (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) || (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
     ) {
-        PRINTF_FUNC("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f \n",
+        PRINTF_FUNC("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f\r\n",
                     vol1 / 10, cur1 / 10, vol2 / 10, cur2 / 10);
 
-
-
         LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
         LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
         LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] = vol2;
@@ -2614,11 +2612,10 @@ void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct
             (LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] <= cur1 - 5 || LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] >= cur1 + 5) ||
             (LogInfo[1][EV_LOG_OUTPUT_CAP_POW] <= pow2 - 5 || LogInfo[1][EV_LOG_OUTPUT_CAP_POW] >= pow2 + 5) ||
             (LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] <= cur2 - 5 || LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >= cur2 + 5)) {
-        PRINTF_FUNC("----------------------------------------------------- \n");
-        PRINTF_FUNC("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f \n",
+        //PRINTF_FUNC("----------------------------------------------------- \n");
+        PRINTF_FUNC("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f\r\n",
                     pow1 / 10, cur1 / 10, pow2 / 10, cur2 / 10);
-
-        PRINTF_FUNC("----------------------------------------------------- \n");
+        //PRINTF_FUNC("----------------------------------------------------- \n");
 
         LogInfo[0][EV_LOG_OUTPUT_CAP_POW] = pow1;
         LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] = cur1;

+ 28 - 14
EVSE/Projects/DD360Audi/Apps/ReModule_InternalComm.c

@@ -671,7 +671,8 @@ void GetPersentOutputVol()
 
         for (int index = 0; index < gunCount; index++) {
             if (index == 0) {
-                if (_chargingData[index]->Evboard_id == 0x01) {
+                //if (_chargingData[index]->Evboard_id == 0x01) {
+                if (index == 0) {
 #if !defined DD360 && !defined DD360Audi
                     _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
 #else
@@ -681,7 +682,8 @@ void GetPersentOutputVol()
 #endif //!defined DD360 && !defined DD360Audi
                     _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
 
-                } else if (_chargingData[index]->Evboard_id == 0x02) {
+                    //} else if (_chargingData[index]->Evboard_id == 0x02) {
+                } else if (index == 1) {
 #if !defined DD360 && !defined DD360Audi
                     _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
 #else
@@ -748,7 +750,8 @@ void GetRelayOutputStatus()
 void CheckK1K2RelayOutput(byte index)
 {
     if (index == 0) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
+        //if (_chargingData[index]->Evboard_id == 0x01) {
+        if (index == 0) {
             if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES) {
                 _chargingData[index]->RelayK1K2Status = YES;
             } else {
@@ -778,7 +781,8 @@ void CheckK1K2RelayOutput(byte index)
                     }
                 }
             }
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
+            //} else if (_chargingData[index]->Evboard_id == 0x02) {
+        } else if (index == 1) {
             if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES) {
                 _chargingData[index]->RelayK1K2Status = YES;
             } else {
@@ -1019,7 +1023,8 @@ void SetK1K2RelayStatus(byte index)
     }
 
     if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
+        //if (_chargingData[index]->Evboard_id == 0x01) {
+        if (index == 0) {
             if (regRelay.relay_event.bits.Gun1_P == YES) {
                 outputRelay.relay_event.bits.Gun1_P = NO;
             } else if (regRelay.relay_event.bits.Gun1_N == YES) {
@@ -1031,7 +1036,8 @@ void SetK1K2RelayStatus(byte index)
                     outputRelay.relay_event.bits.CCS_Precharge = NO;
                 }
             }
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
+            //} else if (_chargingData[index]->Evboard_id == 0x02) {
+        } else if (index == 1) {
             if (regRelay.relay_event.bits.Gun2_P == YES) {
                 outputRelay.relay_event.bits.Gun2_P = NO;
             } else if (regRelay.relay_event.bits.Gun2_N == YES) {
@@ -1050,13 +1056,15 @@ void SetK1K2RelayStatus(byte index)
         if (_chargingData[index]->RelayWeldingCheck == YES)
 #endif //!defined METER_ENABLE
         {
-            if (_chargingData[index]->Evboard_id == 0x01) {
+            //if (_chargingData[index]->Evboard_id == 0x01) {
+            if (index == 0) {
                 if (regRelay.relay_event.bits.Gun1_N == NO) {
                     outputRelay.relay_event.bits.Gun1_N = YES;
                 } else if (regRelay.relay_event.bits.Gun1_P == NO) {
                     outputRelay.relay_event.bits.Gun1_P = YES;
                 }
-            } else if (_chargingData[index]->Evboard_id == 0x02) {
+                //} else if (_chargingData[index]->Evboard_id == 0x02) {
+            } else if (index == 1) {
                 if (regRelay.relay_event.bits.Gun2_N == NO) {
                     outputRelay.relay_event.bits.Gun2_N = YES;
                 } else if (regRelay.relay_event.bits.Gun2_P == NO) {
@@ -1068,13 +1076,15 @@ void SetK1K2RelayStatus(byte index)
                 _chargingData[index]->SystemStatus <= S_COMPLETE) ||
                _chargingData[index]->SystemStatus == S_ALARM) {
         if ((_chargingData[index]->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
-            if (_chargingData[index]->Evboard_id == 0x01) {
+            //if (_chargingData[index]->Evboard_id == 0x01) {
+            if (index == 0) {
                 if (regRelay.relay_event.bits.Gun1_P == YES) {
                     outputRelay.relay_event.bits.Gun1_P = NO;
                 } else if (regRelay.relay_event.bits.Gun1_N == YES) {
                     outputRelay.relay_event.bits.Gun1_N = NO;
                 }
-            } else if (_chargingData[index]->Evboard_id == 0x02) {
+                //} else if (_chargingData[index]->Evboard_id == 0x02) {
+            } else if (index == 1) {
                 if (regRelay.relay_event.bits.Gun2_P == YES) {
                     outputRelay.relay_event.bits.Gun2_P = NO;
                 } else if (regRelay.relay_event.bits.Gun2_N == YES) {
@@ -1083,7 +1093,8 @@ void SetK1K2RelayStatus(byte index)
             }
         }
     } else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
+        //if (_chargingData[index]->Evboard_id == 0x01) {
+        if (index == 0) {
 #if !defined DD360 && !defined DD360Audi
             if (_chargingData[index]->Type == _Type_CCS_2) {
                 if (gunCount == 1) {
@@ -1095,7 +1106,8 @@ void SetK1K2RelayStatus(byte index)
                 }
             }
 #endif //!defined DD360 && !defined DD360Audi
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
+            //} else if (_chargingData[index]->Evboard_id == 0x02) {
+        } else if (index == 1) {
 #if !defined DD360 && !defined DD360Audi
             if (_chargingData[index]->Type == _Type_CCS_2) {
                 if (regRelay.relay_event.bits.CCS_Precharge == NO) {
@@ -1107,7 +1119,8 @@ void SetK1K2RelayStatus(byte index)
 #endif //!defined DD360 && !defined DD360Audi
         }
     } else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST1) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
+        //if (_chargingData[index]->Evboard_id == 0x01) {
+        if (index == 0) {
 #if !defined DD360 && !defined DD360Audi
             if (_chargingData[index]->Type == _Type_CCS_2) {
                 if (gunCount == 1) {
@@ -1119,7 +1132,8 @@ void SetK1K2RelayStatus(byte index)
                 }
             }
 #endif //!defined DD360 && !defined DD360Audi
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
+            //} else if (_chargingData[index]->Evboard_id == 0x02) {
+        } else if (index == 1) {
 #if !defined DD360 && !defined DD360Audi
             if (_chargingData[index]->Type == _Type_CCS_2) {
                 if (regRelay.relay_event.bits.Gun2_P == NO) {

+ 2 - 2
EVSE/Projects/DD360Audi/Apps/ReModule_PrimaryComm.c

@@ -249,8 +249,8 @@ void GetFwAndHwVersion()
         strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
     }
 
-    if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-        ;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
+    //if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+    //    ;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
 }
 
 void GetInputGpioStatus()

+ 3 - 3
EVSE/Projects/DD360Audi/Apps/main.c

@@ -4795,7 +4795,7 @@ int main(void)
                         // GFD 錯誤停止
                         RecordAlarmCode(gun_index, "012234");
                     } else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-                        (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
+                    (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
                         // UVP
                         RecordAlarmCode(gun_index, "012289");
                         ChargingTerminalProcess(gun_index);
@@ -4809,7 +4809,7 @@ int main(void)
                         RecordAlarmCode(gun_index, "012236");
                     } else if (isPrechargeStatus_gb(gun_index) == 10 &&
                                (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-                        (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/)) {
+                    (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/)) {
                         // UVP
                         RecordAlarmCode(gun_index, "012290");
                         ChargingTerminalProcess(gun_index);
@@ -4822,7 +4822,7 @@ int main(void)
                         // GFD 錯誤停止
                         RecordAlarmCode(gun_index, "012235");
                     } else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-                        (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
+                    (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
                         // UVP
                         RecordAlarmCode(gun_index, "012288");
                         ChargingTerminalProcess(gun_index);

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


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


+ 39 - 0
EVSE/Projects/DD360Audi/output/.tags

@@ -0,0 +1,39 @@
+!_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/
+!_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/
+!_TAG_OUTPUT_EXCMD	mixed	/number, pattern, mixed, or combineV2/
+!_TAG_OUTPUT_FILESEP	slash	/slash or backslash/
+!_TAG_OUTPUT_MODE	u-ctags	/u-ctags or e-ctags/
+!_TAG_PATTERN_LENGTH_LIMIT	96	/0 for no limit/
+!_TAG_PROC_CWD	/home/jf7686/Workspaces/Phihong/CSU3_AM335x/EVSE/Projects/DD360Audi/output/	//
+!_TAG_PROGRAM_AUTHOR	Universal Ctags Team	//
+!_TAG_PROGRAM_NAME	Universal Ctags	/Derived from Exuberant Ctags/
+!_TAG_PROGRAM_URL	https://ctags.io/	/official site/
+!_TAG_PROGRAM_VERSION	5.9.0	/p5.9.20210110.0/
+0	sftp-config.json	/^        "\\\\.sublime-(project|workspace)", "sftp-config(-alt\\\\d?)?\\\\.json",$/;"	s	array:ignore_regexes
+1	sftp-config.json	/^        "\\\\.sublime-(project|workspace)", "sftp-config(-alt\\\\d?)?\\\\.json",$/;"	s	array:ignore_regexes
+10	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+11	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+12	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+2	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+3	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+4	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+5	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+6	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+7	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+8	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+9	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+confirm_downloads	sftp-config.json	/^    "confirm_downloads": false,$/;"	b
+confirm_overwrite_newer	sftp-config.json	/^    "confirm_overwrite_newer": false,$/;"	b
+confirm_sync	sftp-config.json	/^    "confirm_sync": true,$/;"	b
+connect_timeout	sftp-config.json	/^    "connect_timeout": 30,$/;"	n
+host	sftp-config.json	/^    "host": "192.168.0.10",$/;"	s
+ignore_regexes	sftp-config.json	/^    "ignore_regexes": [$/;"	a
+password	sftp-config.json	/^    "password": "y42j\/4cj84",$/;"	s
+port	sftp-config.json	/^    "port": "21",$/;"	s
+remote_path	sftp-config.json	/^    "remote_path": "\/root\/",$/;"	s
+save_before_upload	sftp-config.json	/^    "save_before_upload": true,$/;"	b
+sync_down_on_open	sftp-config.json	/^    "sync_down_on_open": false,$/;"	b
+sync_same_age	sftp-config.json	/^    "sync_same_age": true,$/;"	b
+sync_skip_deletes	sftp-config.json	/^    "sync_skip_deletes": false,$/;"	b
+upload_on_save	sftp-config.json	/^    "upload_on_save": false,$/;"	b
+user	sftp-config.json	/^    "user": "root",$/;"	s

+ 39 - 0
EVSE/Projects/DD360Audi/output/.tags_sorted_by_file

@@ -0,0 +1,39 @@
+!_TAG_PROC_CWD	/home/jf7686/Workspaces/Phihong/CSU3_AM335x/EVSE/Projects/DD360Audi/output/	//
+!_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/
+!_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/
+!_TAG_PROGRAM_VERSION	5.9.0	/p5.9.20210110.0/
+!_TAG_PATTERN_LENGTH_LIMIT	96	/0 for no limit/
+!_TAG_PROGRAM_NAME	Universal Ctags	/Derived from Exuberant Ctags/
+!_TAG_PROGRAM_AUTHOR	Universal Ctags Team	//
+!_TAG_PROGRAM_URL	https://ctags.io/	/official site/
+!_TAG_OUTPUT_EXCMD	mixed	/number, pattern, mixed, or combineV2/
+0	sftp-config.json	/^        "\\\\.sublime-(project|workspace)", "sftp-config(-alt\\\\d?)?\\\\.json",$/;"	s	array:ignore_regexes
+1	sftp-config.json	/^        "\\\\.sublime-(project|workspace)", "sftp-config(-alt\\\\d?)?\\\\.json",$/;"	s	array:ignore_regexes
+10	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+11	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+12	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+2	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+3	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+4	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+5	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+6	sftp-config.json	/^        "sftp-settings\\\\.json", "\/venv\/", "\\\\.svn\/", "\\\\.hg\/", "\\\\.git\/",$/;"	s	array:ignore_regexes
+7	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+8	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+9	sftp-config.json	/^        "\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini"$/;"	s	array:ignore_regexes
+confirm_downloads	sftp-config.json	/^    "confirm_downloads": false,$/;"	b
+confirm_overwrite_newer	sftp-config.json	/^    "confirm_overwrite_newer": false,$/;"	b
+confirm_sync	sftp-config.json	/^    "confirm_sync": true,$/;"	b
+connect_timeout	sftp-config.json	/^    "connect_timeout": 30,$/;"	n
+host	sftp-config.json	/^    "host": "192.168.0.10",$/;"	s
+ignore_regexes	sftp-config.json	/^    "ignore_regexes": [$/;"	a
+password	sftp-config.json	/^    "password": "y42j\/4cj84",$/;"	s
+port	sftp-config.json	/^    "port": "21",$/;"	s
+remote_path	sftp-config.json	/^    "remote_path": "\/root\/",$/;"	s
+save_before_upload	sftp-config.json	/^    "save_before_upload": true,$/;"	b
+sync_down_on_open	sftp-config.json	/^    "sync_down_on_open": false,$/;"	b
+sync_same_age	sftp-config.json	/^    "sync_same_age": true,$/;"	b
+sync_skip_deletes	sftp-config.json	/^    "sync_skip_deletes": false,$/;"	b
+upload_on_save	sftp-config.json	/^    "upload_on_save": false,$/;"	b
+user	sftp-config.json	/^    "user": "root",$/;"	s
+!_TAG_OUTPUT_FILESEP	slash	/slash or backslash/
+!_TAG_OUTPUT_MODE	u-ctags	/u-ctags or e-ctags/

BIN
EVSE/Projects/DD360Audi/output/DoComm


BIN
EVSE/Projects/DD360Audi/output/FactoryConfig


BIN
EVSE/Projects/DD360Audi/output/Module_EvComm


BIN
EVSE/Projects/DD360Audi/output/Module_InternalComm


BIN
EVSE/Projects/DD360Audi/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Audi/output/main


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