Browse Source

[Improve][AW-CCS][Module_PowerSharing]

2021.10.07 / Folus Wen

Actions:
1. Module_PowerSharing improve timeout check logic.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 3 years ago
parent
commit
005cb5cd76

+ 71 - 76
EVSE/Projects/AW-CCS/Apps/CCS/Module_CCS.c

@@ -8,7 +8,6 @@
 #include "define_ccs.h"
 #include "main.h"
 
-
 struct SysConfigAndInfo *ShmSysConfigAndInfo;
 struct StatusCodeData *ShmStatusCodeData;
 struct CcsData *ShmCcsData;
@@ -19,7 +18,7 @@ struct appHandEXIDocument ccs_handshake;
 struct dinEXIDocument ccs_exi_doc_DIN;
 struct iso1EXIDocument ccs_exi_doc_ISO1;
 struct iso2EXIDocument ccs_exi_doc_ISO2;
-unsigned char V2GTP_Tx_buf[V2GTP_MSG_TX_BUFFER_SIZE];   //64*1024  65,536 = 65.5KB
+unsigned char V2GTP_Tx_buf[V2GTP_MSG_TX_BUFFER_SIZE];   //64*1024 = 65,536 = 65.5KB
 unsigned char buf_log_evcomm[SIZE_OF_LOG_BUFFER];
 unsigned char buf_log_evcomm_fork1[SIZE_OF_LOG_BUFFER];
 unsigned char buf_log_evcomm_fork2[SIZE_OF_LOG_BUFFER];
@@ -37,7 +36,7 @@ unsigned char V2gtpMsgTxBuf[V2GTP_MSG_TX_BUFFER_SIZE] = {0};
 unsigned short Aag[64];
 struct MmeHeader SendMmePacket;
 int SendMmePacketSize;
-unsigned char CsuMac[6],QcaMac[6],EvMac[6],SlacRunId[8];
+unsigned char CsuMac[6],QcaMac[6],EvMac[6],SlacRunId[8],eth0Mac[6];
 struct sockaddr_ll DestSocketAddress;
 struct ifreq Req;
 unsigned int PwmStartTime=0;
@@ -777,8 +776,8 @@ int GetEthMac(unsigned char *Eth, unsigned char *mac)
     close(fd);
     system("rm -f /mnt/GetEthInfo");
     sscanf((char*)addr, "%02x:%02x:%02x:%02x:%02x:%02x", (uint32_t *)&mac[0], (uint32_t *)&mac[1], (uint32_t *)&mac[2], (uint32_t *)&mac[3], (uint32_t *)&mac[4], (uint32_t *)&mac[5]);    //CsuMac (Eth = eth1)
-    SAVE_SYS_LOG_MSG_EVCOMM("EVSE MACAddr(CsuMac): %02x:%02x:%02x:%02x:%02x:%02x\n",
-    						mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+    SAVE_SYS_LOG_MSG_EVCOMM("EVSE MAC address(%s): %02X:%02X:%02X:%02X:%02X:%02X\n",
+    						Eth, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
     return 1;
 }
 
@@ -1146,7 +1145,11 @@ int Check_CP_State_Error_fork1(struct ChargingInfoData *ccs)
     {
         #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
         {
+#ifdef TEST_WITH_ETH0
+        	if((ShmCcsData->EnergyTransferMode == MODE_DC_EXTENDED) && ((ccs->CpState != 2) && (ccs->CpState != 3)))
+#else
             if((ccs->CpState != 2) && (ccs->CpState != 3))
+#endif
             {
                 if (ccs->CpState_err == FALSE)
                 {
@@ -1177,7 +1180,11 @@ int Check_CP_State_Error_fork1(struct ChargingInfoData *ccs)
         if(state >= ChargeParameterDiscoveryRequest &&        //35
            state <= ChargeParameterDiscoveryResponse)         //36
         {
+#ifdef TEST_WITH_ETH0
+        	if((ccs->CpState != 3) && ((ShmCcsData->EnergyTransferMode != MODE_DC_EXTENDED) && (ccs->CpState != 4)))
+#else
             if(ccs->CpState != 3)
+#endif
             {
                 if (ccs->CpState_err == FALSE)
                 {
@@ -3748,7 +3755,7 @@ int MmeProcess(unsigned char *Buffer, int DataLength)
 				memcpy(QcaMac, MmePacket->OSA, 6);
 
 				DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_NW_INFO_CNF ---\n");
-				SAVE_SYS_LOG_MSG_EVCOMM("Got QCA7K MacAddr:%02X:%02X:%02X:%02X:%02X:%02X (comm:OK)\n",
+				SAVE_SYS_LOG_MSG_EVCOMM("EVSE MAC address(QCA7K): %02X:%02X:%02X:%02X:%02X:%02X (comm:OK)\n",
 	                    				QcaMac[0],  QcaMac[1],  QcaMac[2],  QcaMac[3],  QcaMac[4],  QcaMac[5]);
 
 				Update_V2G_Flow_Status(CM_SET_KEY_REQ);
@@ -3903,9 +3910,7 @@ int SlacComm()
                         break;
                     }
                     else
-                    {
-                        //null
-                    }
+                    {}
 
                     //Retry by 3 times
                     if (qca7k_comm_retry >= 3)
@@ -3943,6 +3948,9 @@ int SlacComm()
                             SwitchCpStateE(DISABLE);
                             OutputCpPwmDuty(5);
                             PwmStartTime = time(NULL);
+#ifdef TEST_WITH_ETH0
+                            Update_V2G_Flow_Status(SLACC_SDP_UDP_Connection);
+#endif
                         }
                         else
                         {
@@ -7770,12 +7778,13 @@ int Proc_iso1_ChargeParameterDiscoveryRes(int AcceptFd)
 
     //[TC_SECC_VTB_ChargeParameterDiscovery_005]
     /*+++ 20200808, vern, should check the voltage and current to see if the range of battery parameter is accepted by charger ---*/
+#ifdef TEST_WITH_ETH0
+    if((ShmCcsData->EnergyTransferMode == MODE_DC_EXTENDED) && ((sys->EvBatteryMaxCurrent < 0) || (sys->EvBatteryMaxVoltage<150)))
+#else
     if ((sys->EvBatteryMaxCurrent < 0) ||(sys->EvBatteryMaxVoltage<150))
+#endif
     {
-        sprintf((char*)buf_log_evcomm,
-                "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
-                sys->EvBatteryMaxCurrent);
-        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
+        SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]EvBatteryMaxCurrent is negative(%.02f) or  EvBatteryMaxVoltage is under 150(%.02f)=> End_Process\n", sys->EvBatteryMaxCurrent, sys->EvBatteryMaxVoltage);
 
         res->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter;   //16
         res->EVSEProcessing = Finished_ISO15118_2014;
@@ -13945,7 +13954,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     }
                     else
                     {
-                        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
+                        SAVE_SYS_LOG_MSG_EVCOMM("[Error]supportedAppProtocolResReq: fail\n");
                         Update_V2G_Flow_Status(Other_Fault);
                     }
                 }
@@ -13971,9 +13980,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
                 }
                 else
-                {
-
-                }
+                {}
 
                 break;
             }
@@ -13987,7 +13994,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                 }
                 else
                 {
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionSetupReqRes: fail\n");
                     Update_V2G_Flow_Status(Other_Fault);
                 }
                 req_is_responsed = TRUE;
@@ -14012,9 +14019,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
                 }
                 else
-                {
-
-                }
+                {}
 
                 break;
             }
@@ -14028,7 +14033,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                 }
                 else
                 {
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceDiscoveryReqRes: fail\n");
                     Update_V2G_Flow_Status(Other_Fault);
                 }
                 req_is_responsed = TRUE;
@@ -14053,9 +14058,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
                 }
                 else
-                {
-
-                }
+                {}
 
                 break;
             }
@@ -14069,7 +14072,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                 }
                 else
                 {
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[Error]ServiceAndPaymentSelectionReqRes: fail\n");
                     Update_V2G_Flow_Status(Other_Fault);
                 }
                 req_is_responsed = TRUE;
@@ -14094,9 +14097,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
                 }
                 else
-                {
-
-                }
+                {}
 
                 break;
             }
@@ -14170,7 +14171,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                 }
                 else
                 {
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail\n");
                     Update_V2G_Flow_Status(Other_Fault);
                 }
                 req_is_responsed = TRUE;
@@ -14183,11 +14184,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
     	        ftime(&SeqEndTime);
     	        if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time)  //60 seconds
     	        {
-    	            sprintf((char*)buf_log_evcomm,
-                            "ChargingParameter Timeout - (%.02lf of %d ms)\n",
-    	                    DiffTimeb(SeqStartTime, SeqEndTime),
-    	                    V2G_SECC_ChargingParameter_Performance_Time);
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
+                    SAVE_SYS_LOG_MSG_EVCOMM("ChargingParameter Timeout - (%.02lf of %d ms)\n", DiffTimeb(SeqStartTime, SeqEndTime), V2G_SECC_ChargingParameter_Performance_Time);
     	            Update_V2G_Flow_Status(Sequence_Timeout);
                     break;
     	        }
@@ -14203,7 +14200,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     }
                     else
                     {
-                        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
+                        SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargeParameterDiscoveryReqRes: fail\n");
                         Update_V2G_Flow_Status(Other_Fault);
                     }
                     req_is_responsed = TRUE;
@@ -14218,9 +14215,9 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
 
                     //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
 
-                    #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
+			#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
                     ftime(&SeqStartTime);
-                    #endif
+			#endif
 
                     if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
                     {
@@ -14229,7 +14226,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     }
                     else
                     {
-                        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
+                        SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail\n");
                         Update_V2G_Flow_Status(Other_Fault);
                     }
     		#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
@@ -14263,7 +14260,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                 }
                 else
                 {
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStartReqRes: fail\n");
                     Update_V2G_Flow_Status(Other_Fault);
                 }
                 req_is_responsed = TRUE;
@@ -14272,36 +14269,30 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
             case PowerDeliveryResponsetStart:       //42
             {
                 //STEP 1: Check for Process Timeout
-                #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
+			#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
                 if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
                 {
                     ftime(&SeqEndTime);
                     if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000)  //5 seconds
                     {
-                        sprintf((char*)buf_log_evcomm,
-                                "Wait for ChargingStatusReq Timeout - (%.02lf of %d ms)\n",
-                                DiffTimeb(SeqStartTime, SeqEndTime),
-                                2000);
-                        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
+                        SAVE_SYS_LOG_MSG_EVCOMM("Wait for ChargingStatusReq Timeout - (%.02lf of %d ms)\n", DiffTimeb(SeqStartTime, SeqEndTime), 2000);
                         Update_V2G_Flow_Status(Sequence_Timeout);
                     }
                     break;
                 }
-                #endif
+			#endif
 
                 //STEP 2: Wait for ChargingStatusReq Message
                 if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
                 {
     	            EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
                     Update_V2G_Flow_Status(ChargingStatusRequest);
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]ChargingStatusReq: energy transfering...");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]ChargingStatusReq: energy transfering...\n");
 
                     ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_Start);
                 }
                 else
-                {
-
-                }
+                {}
 
                 break;
             }
@@ -14315,7 +14306,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                 }
                 else
                 {
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargingStatusRes: fail");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingStatusRes: fail\n");
                     Update_V2G_Flow_Status(Other_Fault);
                 }
                 req_is_responsed = TRUE;
@@ -14333,7 +14324,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     }
                     else
                     {
-                        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargingStatusRes: fail");
+                        SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingStatusRes: fail\n");
                         Update_V2G_Flow_Status(Other_Fault);
                     }
                     req_is_responsed = TRUE;
@@ -14347,9 +14338,9 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
 
                     ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_End);
 
-                    #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
+				#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
                     ftime(&SeqStartTime);
-                    #endif
+				#endif
                 }
                 else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
                          EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
@@ -14363,9 +14354,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
                 }
                 else
-                {
-
-                }
+                {}
 
                 break;
             }
@@ -14377,13 +14366,13 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     Update_V2G_Flow_Status(PowerDeliveryResponseStop);
                     ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
 
-                    #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
+				#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
                     ftime(&SeqStartTime);
-                    #endif
+				#endif
                 }
                 else
                 {
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[Error]PowerDeliveryStopReqRes: fail\n");
                     Update_V2G_Flow_Status(Other_Fault);
                 }
                 req_is_responsed = TRUE;
@@ -14392,19 +14381,15 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
             case PowerDeliveryResponseStop:         //50
             {
                 //STEP 1: Check for Process Timeout
-                #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
+			#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
                 ftime(&SeqEndTime);
                 if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000)  //2 seconds
                 {
-                    sprintf((char*)buf_log_evcomm,
-                            "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
-                            DiffTimeb(SeqStartTime, SeqEndTime),
-                            2000);
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
+                    SAVE_SYS_LOG_MSG_EVCOMM("Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n", DiffTimeb(SeqStartTime, SeqEndTime), 2000);
                     Update_V2G_Flow_Status(Sequence_Timeout);
                     break;
                 }
-                #endif
+			#endif
 
                 //STEP 3: Check for SessionStopReq Message
                 else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
@@ -14424,13 +14409,10 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                     EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
                 }
                 else
-                {
-
-                }
+                {}
 
                 break;
             }
-            //-------------------------------------------
             case SessionStopRequest:                //53
             {
                 if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
@@ -14440,7 +14422,7 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
                 }
                 else
                 {
-                    SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
+                    SAVE_SYS_LOG_MSG_EVCOMM("[Error]SessionStopReqRes: fail\n");
                     Update_V2G_Flow_Status(Other_Fault);
                 }
                 req_is_responsed = TRUE;
@@ -14450,7 +14432,6 @@ int V2gMsg_Process_iso1_AC(int AcceptFd)
             {
                 break;
             }
-            //-------------------------------------------
             default:
             {
                 break;
@@ -15649,7 +15630,19 @@ int SdpUdpConnected()
             // MAC address[0:2] + FFFE + MAC address[3:5]
             payload[0] = (IPV6_LINK_LOCAL_PREFIX>>8) & 0xFF;
             payload[1] = IPV6_LINK_LOCAL_PREFIX & 0xFF;
-            payload[8 ]= CsuMac[0];
+#ifdef TEST_WITH_ETH0
+            payload[8] = eth0Mac[0];
+			payload[8] ^= 0x02;// bit 1 should complemented.
+			payload[9] = eth0Mac[1];
+			payload[10] = eth0Mac[2];
+			payload[11] = 0xFF;
+			payload[12] = 0xFE;
+			payload[13] = eth0Mac[3];
+			payload[14] = eth0Mac[4];
+			payload[15] = eth0Mac[5];
+#else
+
+            payload[8] = CsuMac[0];
             payload[8] ^= 0x02;// bit 1 should complemented.
             payload[9] = CsuMac[1];
             payload[10] = CsuMac[2];
@@ -15658,6 +15651,7 @@ int SdpUdpConnected()
             payload[13] = CsuMac[3];
             payload[14] = CsuMac[4];
             payload[15] = CsuMac[5];
+#endif
             //TCP port
             payload[16] = (EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active>>8) & 0xFF;
             payload[17] = EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active & 0xFF;
@@ -16034,7 +16028,7 @@ GLOBAL VARIABLES:
 =============================================================================*/
 int SyncAcShreaMemory()
 {
-#if (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE)
+#if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
 	pid_t pid;
 
 	pid = fork();
@@ -16165,6 +16159,7 @@ int main(int argc, char *argv[])
 
     //Init communication parameters
     GetEthMac((uint8_t*)QcaInterface, CsuMac);
+    GetEthMac((uint8_t*)"eth0", eth0Mac);
 
     AttenProfileCnt = 0;
     init_appHandEXIDocument(&ccs_handshake);

+ 1 - 0
EVSE/Projects/AW-CCS/Apps/CCS/Module_CCS.h

@@ -38,6 +38,7 @@
 #include	"v2g/api/api.h"
 #include	"v2g/transport/v2gtp.h"
 
+//#define TEST_WITH_ETH0
 
 #define SAVE_SYS_LOG_MSG_EVCOMM_SWITCH		ENABLE
 #define DEBUG_PRINTF_EVCOMM_SHOW			ENABLE

+ 18 - 6
EVSE/Projects/AW-CCS/Apps/Module_PowerSharing.c

@@ -555,7 +555,7 @@ int tcpSocketServerStart(void)
 							switch(idxStep)
 							{
 								case 0:
-									if(difftime(time((time_t*)NULL), conn_getStatusStarttime(dupFd)) >= 3)
+									if((difftime(time((time_t*)NULL), conn_getStatusStarttime(dupFd)) >= 3) || (difftime(time((time_t*)NULL), conn_getStatusStarttime(dupFd)) < 0))
 									{
 										create_cmd_getStatus(&output);
 										conn_getStatusStarttimeUpdate(dupFd);
@@ -565,7 +565,7 @@ int tcpSocketServerStart(void)
 									idxStep++;
 									break;
 								default:
-									if((difftime(time((time_t*)NULL), conn_setCapacityStarttime(dupFd)) >= 1))
+									if((difftime(time((time_t*)NULL), conn_setCapacityStarttime(dupFd)) >= 1) || (difftime(time((time_t*)NULL), conn_setCapacityStarttime(dupFd)) < 0))
 									{
 										create_cmd_SetAvailableCurrent(&output, dupFd);
 										conn_setCapacityStarttimeUpdate(dupFd);
@@ -616,6 +616,7 @@ int tcpSocketClientStart(void)
 	struct hostent 		*ghbn;
 	struct timeval 		tv;
 	uint8_t 			socketEnable;
+	uint8_t				cntSocketErr;
 
 	struct Message		input;
 	struct Message		output;
@@ -648,6 +649,7 @@ int tcpSocketClientStart(void)
 		tv.tv_usec = 500000;
 		setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
 		socketEnable = ON;
+		cntSocketErr = 0;
 		ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer = ON;
 	}
 
@@ -722,7 +724,17 @@ int tcpSocketClientStart(void)
 			ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer = OFF;
 		}
 		else if(input.size == -1)
-		{}
+		{
+			if(cntSocketErr > 5)
+			{
+				socketEnable = OFF;
+				DEBUG_ERROR("Socket error occur\n");
+			}
+			else
+			{
+				cntSocketErr++;
+			}
+		}
 		usleep(1000000);
 	}
 	close(sockfd);
@@ -741,9 +753,9 @@ int balance_check_loop(void)
 		for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 		{
 			if(ShmPowerSharing->Connection_Info[idx].isSocketConnected &&
-			   (difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastHeartBeatTime) > 300))
+			   ((difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastHeartBeatTime) > TIMEOUT_SPEC_HEARTBEAT) || (difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastHeartBeatTime) < 0)))
 			{
-				DEBUG_INFO("SocketFd-%d heart beat is over 300 seconds.\n", ShmPowerSharing->Connection_Info[idx].socketFd);
+				DEBUG_INFO("SocketFd-%d heart beat is over %d seconds.\n", ShmPowerSharing->Connection_Info[idx].socketFd, TIMEOUT_SPEC_HEARTBEAT);
 				ShmPowerSharing->Connection_Info[idx].isGunConnected = FALSE;
 				ShmPowerSharing->Connection_Info[idx].isSocketConnected = FALSE;
 			}
@@ -775,7 +787,7 @@ int balance_check_loop(void)
 			if(ShmPowerSharing->Connection_Info[idx].isSocketConnected &&
 			   ShmPowerSharing->Connection_Info[idx].isGunConnected)
 			{
-				if((difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastCheckCapacityTime) > 10))
+				if((difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastCheckCapacityTime) > TIMEOUT_SPEC_CHECK_CAPACITY) || (difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastCheckCapacityTime) < 0))
 				{
 					if(ShmPowerSharing->Connection_Info[idx].availableSharingCurrent >= (ShmPowerSharing->Connection_Info[idx].presentOutputCurrent+2))
 					{

+ 2 - 0
EVSE/Projects/AW-CCS/Apps/Module_PowerSharing.h

@@ -59,6 +59,8 @@
 
 #define LISTEN_PORT_TCP				118
 #define	CONNECTION_LIMIT			5
+#define TIMEOUT_SPEC_HEARTBEAT		180
+#define TIMEOUT_SPEC_CHECK_CAPACITY	10
 
 #define ShmPowerShargingKey			LISTEN_PORT_TCP+8000