Explorar el Código

2021-09-30 / Simon Xue

Actions
1. Show Replug string when status occur error in prepare,precharging mode.
2. Door Sensor and Emergency Button get 3 times change status and then trigger warming.
3. Lost System task will be detected and auto re-execute task.
4. Add WatchDog function.
5. Not show "023979" (EV Full Charge) message.

Files
1. As follow commit history

Image version : V1.15.XX.XXXX.XX
Simon Xue hace 3 años
padre
commit
673123d562
Se han modificado 53 ficheros con 1812 adiciones y 186 borrados
  1. 184 0
      EVSE/Projects/DD360/Apps/CSU/CheckSystemTask.c
  2. 60 0
      EVSE/Projects/DD360/Apps/CSU/CheckSystemTask.h
  3. 8 0
      EVSE/Projects/DD360/Apps/CSU/UpgradeFW.c
  4. 39 17
      EVSE/Projects/DD360/Apps/CSU/WatchDog.c
  5. 48 0
      EVSE/Projects/DD360/Apps/CSU/WatchDog.c.old
  6. 114 9
      EVSE/Projects/DD360/Apps/CSU/main.c
  7. 1 0
      EVSE/Projects/DD360/Apps/Define/define.h
  8. 4 2
      EVSE/Projects/DD360/Apps/Makefile
  9. 14 7
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  10. 4 2
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalState.c
  11. 3 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  12. 39 0
      EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c
  13. 46 5
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c
  14. 1 0
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.h
  15. 4 0
      EVSE/Projects/DD360/Apps/Script/kill.sh
  16. 31 17
      EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c
  17. BIN
      EVSE/Projects/DD360/Apps/UnsafetyOutputTask
  18. 184 0
      EVSE/Projects/DD360Audi/Apps/CSU/CheckSystemTask.c
  19. 60 0
      EVSE/Projects/DD360Audi/Apps/CSU/CheckSystemTask.h
  20. 8 0
      EVSE/Projects/DD360Audi/Apps/CSU/UpgradeFW.c
  21. 39 17
      EVSE/Projects/DD360Audi/Apps/CSU/WatchDog.c
  22. 48 0
      EVSE/Projects/DD360Audi/Apps/CSU/WatchDog.c.old
  23. 114 9
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  24. 1 0
      EVSE/Projects/DD360Audi/Apps/Define/define.h
  25. 4 2
      EVSE/Projects/DD360Audi/Apps/Makefile
  26. 14 7
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  27. 4 2
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalState.c
  28. 3 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  29. 39 0
      EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c
  30. 46 5
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c
  31. 1 0
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.h
  32. 4 0
      EVSE/Projects/DD360Audi/Apps/Script/kill.sh
  33. 31 17
      EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c
  34. 0 0
      EVSE/Projects/DD360ComBox/Apps/.metadata/.lock
  35. 184 0
      EVSE/Projects/DD360ComBox/Apps/CSU/CheckSystemTask.c
  36. 60 0
      EVSE/Projects/DD360ComBox/Apps/CSU/CheckSystemTask.h
  37. 11 5
      EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c
  38. 8 0
      EVSE/Projects/DD360ComBox/Apps/CSU/UpgradeFW.c
  39. 39 17
      EVSE/Projects/DD360ComBox/Apps/CSU/WatchDog.c
  40. 48 0
      EVSE/Projects/DD360ComBox/Apps/CSU/WatchDog.c.old
  41. 114 9
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  42. 1 0
      EVSE/Projects/DD360ComBox/Apps/Define/define.h
  43. 4 2
      EVSE/Projects/DD360ComBox/Apps/Makefile
  44. 14 7
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c
  45. 4 2
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalState.c
  46. 3 0
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c
  47. 39 0
      EVSE/Projects/DD360ComBox/Apps/ModuleLcmCtrl/Module_LcmControl.c
  48. 46 5
      EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.c
  49. 1 0
      EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.h
  50. 4 0
      EVSE/Projects/DD360ComBox/Apps/Script/kill.sh
  51. 31 17
      EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.c
  52. BIN
      EVSE/Projects/DD360ComBox/Apps/UnsafetyOutputTask
  53. 1 4
      EVSE/Projects/define.h

+ 184 - 0
EVSE/Projects/DD360/Apps/CSU/CheckSystemTask.c

@@ -0,0 +1,184 @@
+/*
+ * CheckTask.c
+ *
+ *  Created on: 2021年9月22日
+ *      Author: 8513
+ */
+
+#include "CheckSystemTask.h"
+
+bool Taskconutstring(char *src, char *taskname)
+{
+    bool result = false;
+
+    if (src == NULL || strlen(src) == 0)
+        return result;
+
+    if (strstr(src, taskname) != NULL &&
+        strstr(src, "grep") == NULL &&
+        strstr(src, "[") == NULL)
+    {
+        result = true;
+    }
+
+    return result;
+}
+
+int GetProcessCount(char *procName)
+{
+	int result = 0;
+	FILE *fp;
+	char cmd[256];
+	char buf[256];
+
+	sprintf(cmd, "ps -ef |grep %s", procName);
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if (Taskconutstring(buf, procName))
+				result++;
+		}
+	}
+
+	pclose(fp);
+
+	return result;
+}
+
+unsigned char CheckSystemTask(unsigned char systemPage)
+{
+	unsigned char result = 0;
+	unsigned char count_main 		= GetProcessCount("main");
+	unsigned char count_evComm 		= GetProcessCount("Module_EvComm");
+	unsigned char count_interComm	= GetProcessCount("Module_InternalComm");
+	unsigned char count_eventComm	= GetProcessCount("Module_EventLogging");
+	unsigned char count_primaryComm	= GetProcessCount("Module_PrimaryComm");
+	unsigned char count_lcmComm	    = GetProcessCount("Module_LcmControl");
+	unsigned char count_doComm	    = GetProcessCount("Module_DoComm");
+	unsigned char count_produceComm	= GetProcessCount("Module_ProduceUtils");
+//	unsigned char count_psuComm 	= GetProcessCount("Module_PsuComm");
+
+//	printf("*************************** \n");
+//	printf("count_main = %d \n", count_main);
+//	printf("count_eventLog = %d \n", count_eventLog);
+//	printf("count_primary = %d \n", count_primary);
+//	printf("count_evComm = %d \n", count_evComm);
+//	printf("count_lcmCtrl = %d \n", count_lcmCtrl);
+//	printf("count_interComm = %d \n", count_interComm);
+//	printf("count_psuComm = %d \n", count_psuComm);
+//	printf("*************************** \n");
+
+//	if (systemPage == 0x09 || systemPage == 0x0A)
+	{
+		if (count_main < _SYSTEM_TASK_COUNT_MAIN )
+		{
+			system("killall Module_EventLogging");
+			system("killall Module_PrimaryComm");
+			system("killall Module_EvComm");
+			system("killall Module_LcmControl");
+			system("killall Module_InternalComm");
+			system("killall Module_DoComm");
+//			system("killall Module_PsuComm");
+//			system("killall OcppBackend &");
+//			system("killall Module_4g &");
+//			system("killall Module_Wifi &");
+			system("killall Module_ProduceUtils &");
+			sleep(3);
+			system("/usr/bin/run_evse_restart.sh");
+		}
+		else
+		{
+			/*
+			if(system("pidof -s Module_EventLogging > /dev/null") != 0)
+				system("/root/Module_EventLogging &");
+
+			if(system("pidof -s Module_PrimaryComm > /dev/null") != 0)
+				system("/root/Module_PrimaryComm &");
+
+			if(system("pidof -s Module_LcmControl > /dev/null") != 0)
+				system("/root/Module_LcmControl &");
+
+            if(system("pidof -s Module_DoComm > /dev/null") != 0)
+                system("/root/Module_DoComm &");
+
+            if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
+                system("/root/Module_ProduceUtils &");
+
+			*/
+			if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM )
+			{
+				system("killall Module_EvComm");
+				sleep(3);
+				system("/root/Module_EvComm &");
+			}
+        	if (count_interComm < _SYSTEM_TASK_COUNT_INTERNALCOMM )
+			{
+				system("killall Module_InternalComm");
+				sleep(3);
+				system("/root/Module_InternalComm &");
+			}
+			if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING )
+			{
+				system("killall Module_EventLogging");
+				sleep(3);
+				system("/root/Module_EventLogging &");
+			}
+			if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM )
+			{
+				system("killall Module_PrimaryComm");
+				sleep(3);
+				system("/root/Module_PrimaryComm &");
+			}
+			if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM )
+			{
+				system("killall Module_LcmControl");
+				sleep(3);
+				system("/root/Module_LcmControl &");
+			}
+			if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM )
+			{
+				system("killall Module_DoComm");
+				sleep(3);
+				system("/root/Module_DoComm &");
+			}
+			if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS )
+			{
+				system("killall Module_ProduceUtils");
+				sleep(3);
+				system("/root/Module_ProduceUtils &");
+			}
+			/*
+			if (count_psuComm < 2)
+			{
+				system("killall Module_PsuComm");
+				sleep(3);
+				system("/root/Module_PsuComm &");
+			}*/
+		}
+
+		sleep(2);
+	}
+
+	if (count_main < _SYSTEM_TASK_COUNT_MAIN)
+		result = _SYSTEM_TASK_LOST_ITEM_MAIN;
+	else if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM)
+		result = _SYSTEM_TASK_LOST_ITEM_EVCOMM;
+/*	else if (count_psuComm < 2)
+		result = 3; */
+    else if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING )
+        result = _SYSTEM_TASK_LOST_ITEM_EVENTLOG;
+    else if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM)
+        result = _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM;
+    else if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM)
+        result = _SYSTEM_TASK_LOST_ITEM_LCMCONTROL;
+    else if (count_interComm < 2 )
+        result = _SYSTEM_TASK_LOST_ITEM_INTERCOMM;
+    else if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM)
+        result = _SYSTEM_TASK_LOST_ITEM_DOCOMM;
+    else if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS)
+        result = _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS;
+
+	return result;
+}

+ 60 - 0
EVSE/Projects/DD360/Apps/CSU/CheckSystemTask.h

@@ -0,0 +1,60 @@
+/*
+ * CheckTask.h
+ *
+ *  Created on: 2021年9月2日
+ *      Author: 7564
+ */
+
+#ifndef CHECKTASK_H_
+#define CHECKTASK_H_
+
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<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 	<string.h>
+#include 	<stdint.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	<stdbool.h>
+#include 	<dirent.h>
+
+#define _SYSTEM_TASK_LOST_ITEM_MAIN         1
+#define _SYSTEM_TASK_LOST_ITEM_EVCOMM       2
+#define _SYSTEM_TASK_LOST_ITEM_EVENTLOG     3
+#define _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM  4
+#define _SYSTEM_TASK_LOST_ITEM_LCMCONTROL   5
+#define _SYSTEM_TASK_LOST_ITEM_INTERCOMM    6
+#define _SYSTEM_TASK_LOST_ITEM_DOCOMM       7
+#define _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS 8
+
+#define _SYSTEM_TASK_COUNT_MAIN             5
+#define _SYSTEM_TASK_COUNT_EVCOMM           2
+#define _SYSTEM_TASK_COUNT_INTERNALCOMM     2
+#define _SYSTEM_TASK_COUNT_EVENTLOGGING     1
+#define _SYSTEM_TASK_COUNT_PRIMARYCOMM      1
+#define _SYSTEM_TASK_COUNT_LCM              1
+#define _SYSTEM_TASK_COUNT_DOCOMM           1
+#define _SYSTEM_TASK_COUNT_PRODUCEUTILS     1
+
+
+unsigned char CheckSystemTask(unsigned char systemPage);
+
+#endif /* CHECKSYSTEMTASK_H_ */

+ 8 - 0
EVSE/Projects/DD360/Apps/CSU/UpgradeFW.c

@@ -12,6 +12,11 @@
 #include "../ShareMemory/shmMem.h"
 
 #include "main.h"
+//WatchDog.c
+extern void CreateWatchdog(void);
+extern void TryCloseWatchdog(void);
+extern void TryFeedWatchdog(void);
+
 
 //------------------------------------------------------------------------------
 static char *_priPortName = "/dev/ttyS1";
@@ -325,6 +330,8 @@ void CheckFwUpdateFunction(void)
     //log_info("pSysInfo->FirmwareUpdate = %d \n", pSysInfo->FirmwareUpdate);
     if (pSysInfo->FirmwareUpdate == YES) {
         log_info("ftp : update start. \n");
+        TryCloseWatchdog();
+
         for (uint8_t gun_index = 0; gun_index < pSysConfig->TotalConnectorCount; gun_index++) {
             setChargerMode(gun_index, MODE_UPDATE);
         }
@@ -352,6 +359,7 @@ void CheckFwUpdateFunction(void)
 
         if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
             log_info("Backend : update start. \n");
+            TryCloseWatchdog();
             strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
             strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
             ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;

+ 39 - 17
EVSE/Projects/DD360/Apps/CSU/WatchDog.c

@@ -8,41 +8,63 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 
-//------------------------------------------------------------------------------
-static int gWatchDogfd = -1;
+int wtdFd = -1;
+struct StatusCodeData           *ShmStatusCodeData;
 
-//------------------------------------------------------------------------------
-void WriteWatchDogState(char *value)
-{
-    write(gWatchDogfd, value, 1);
-}
+void CreateWatchdog(void);
+void TryCloseWatchdog(void);
+void TryFeedWatchdog(void);
 
-static int initWatchDog(void)
+int InitWatchDog()
 {
     int fd;
+    int timeout = 180;
+
     system("/usr/bin/fuser -k /dev/watchdog");
     sleep(1);
     system("echo V > /dev/watchdog");
     sleep(1);
-    fd = open("/dev/watchdog", O_RDWR);
+    fd=open("/dev/watchdog", O_RDWR);
 
-    if (fd <= 0) {
+    if(fd<=0)
+    {
         log_error("System watch dog initial fail.\r\n");
     }
+    ioctl(fd, _IOWR('W', 6, int), &timeout);
 
     return fd;
 }
 
 void CreateWatchdog(void)
 {
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    wtdFd = InitWatchDog();
+
+    ShmStatusCodeData = (struct StatusCodeData*)GetShmStatusCodeData();
+    if(wtdFd < 0)
+    {
+        log_info("Watchdog Initial Fail");
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+    }
+    else
+    {
+        log_info("Watchdog Initial Success");
+    }
+}
 
-    if (pSysConfig->SwitchDebugFlag == NO) {
-        gWatchDogfd = initWatchDog();
+void TryCloseWatchdog(void)
+{
+    if(wtdFd > 0)
+    {
+        write(wtdFd, "V", 1);
+        close(wtdFd);
+    }
+}
 
-        if (gWatchDogfd < 0) {
-            pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
-        }
+void TryFeedWatchdog(void)
+{
+    if(wtdFd > 0)
+    {
+        write(wtdFd, "a", 1);
     }
 }
+

+ 48 - 0
EVSE/Projects/DD360/Apps/CSU/WatchDog.c.old

@@ -0,0 +1,48 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+static int gWatchDogfd = -1;
+
+//------------------------------------------------------------------------------
+void WriteWatchDogState(char *value)
+{
+    write(gWatchDogfd, value, 1);
+}
+
+static int initWatchDog(void)
+{
+    int fd;
+    system("/usr/bin/fuser -k /dev/watchdog");
+    sleep(1);
+    system("echo V > /dev/watchdog");
+    sleep(1);
+    fd = open("/dev/watchdog", O_RDWR);
+
+    if (fd <= 0) {
+        log_error("System watch dog initial fail.\r\n");
+    }
+
+    return fd;
+}
+
+void CreateWatchdog(void)
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    if (pSysConfig->SwitchDebugFlag == NO) {
+        gWatchDogfd = initWatchDog();
+
+        if (gWatchDogfd < 0) {
+            pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
+        }
+    }
+}

+ 114 - 9
EVSE/Projects/DD360/Apps/CSU/main.c

@@ -29,6 +29,7 @@
 #include <math.h>
 #include <stdbool.h>
 #include <dirent.h>
+#include <signal.h>
 
 #include "../Config.h"
 #include "main.h"
@@ -40,6 +41,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../SelectGun/SelectGun.h"
+#include "CheckSystemTask.h"
 
 //------------------------------------------------------------------------------
 static struct SysInfoData *pSysInfo = NULL;
@@ -71,13 +73,16 @@ static SelectGunInfo *ShmSelectGunInfo = NULL; //Jerry add
 static EvBoardErrMsg gEvBoardErr = {0};
 static ChillerTempErr gChillerTempErr = {0};
 
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+
 // for initial index to check EV board type is correct
 uint8_t bd0_1_status = 0;
 uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V1.14.00.0000.00"; // "V0.16.00.0000.00";
+char *fwVersion = "V1.15.00.0000.00"; // "V0.16.00.0000.00";
 
 //sqlite3 *localDb;
 bool isDb_ready;
@@ -123,7 +128,8 @@ extern void GetMacAddress(void);
 
 //WatchDog.c
 extern void CreateWatchdog(void);
-extern void WriteWatchDogState(char *value);
+extern void TryCloseWatchdog(void);
+extern void TryFeedWatchdog(void);
 
 //ZipFile.c
 extern void zipLogFiles(void);
@@ -1631,7 +1637,11 @@ void _DetectPlugInTimeout(void)
     ClearDetectPluginFlag();
 
     sleep(1); //等待DoComm回報插槍訊號給主櫃
-
+#if defined DD360Audi || DD360 || DD360Combox
+	    //pSysInfo->SystemPage = _LCM_COMPLETE;
+		setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
+	    return;
+#endif
     systemPageRestoreInit();
 }
 
@@ -1661,7 +1671,12 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
     log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
     //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
     {
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
         setChargerMode(gunIndex, MODE_IDLE);
+#endif
         _AutoReturnTimeout();
     }
 }
@@ -1669,7 +1684,12 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
 void _PrepareTimeout(uint8_t gunIndex)
 {
     log_info("*********** _PrepareTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
+     setChargerMode(gunIndex, MODE_IDLE);
+#endif
     pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
     _AutoReturnTimeout();
 }
@@ -1677,9 +1697,76 @@ void _PrepareTimeout(uint8_t gunIndex)
 void _CcsPrechargeTimeout(uint8_t gunIndex)
 {
     log_info("*********** _CcsPrechargeTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
+     setChargerMode(gunIndex, MODE_IDLE);
+#endif
 }
 
+//===============================================
+// Check System Task alive
+// ==============================================
+void CheckSystemTaskAlive()
+{
+    unsigned char lostId = CheckSystemTask(ShmSysConfigAndInfo->SysInfo.SystemPage);
+    if (lostId != 0) {
+        log_info("Check task(%d) lost\n",lostId);
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost == NO) {
+           if (lostId == _SYSTEM_TASK_LOST_ITEM_MAIN)
+               log_info("System task lost (CSU). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVCOMM)
+               log_info("System task lost (EVComm). \n");
+//           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PSUCOMM)
+//               PRINTF_FUNC("System task lost (PSU Task). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVENTLOG)
+               log_info("System task lost (Event log). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM)
+               log_info("System task lost (Primary). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_LCMCONTROL)
+               log_info("System task lost (LCM Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_INTERCOMM)
+               log_info("System task lost (Internal Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_DOCOMM)
+               log_info("System task lost (Do Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS)
+               log_info("System task lost (ProcductUtils Comm). \n");
+           ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = YES;
+        }
+    } else
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = NO;
+}
+
+void CreateCheckSystemTaskFork()
+{
+    pid_t taskPid;
+    taskPid = fork();
+    if (taskPid == 0)
+    {
+        while(true)
+        {
+			/*
+			for (int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo[_index]->SystemStatus == SYS_MODE_UPDATE ||
+						chargingInfo[_index]->Type == 0x09)
+				{
+					stopToDet = true;
+					continue;
+				}
+			}
+			*/
+			for (uint8_t gun = 0; gun < pSysConfig->TotalConnectorCount; gun++) {
+				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
+				if (pDcChargingInfo->SystemStatus == SYS_MODE_UPDATE )
+						continue;
+			}
+			CheckSystemTaskAlive();
+			sleep(5);
+		}
+	}
+}
 //===============================================
 // 取得卡號與卡號驗證
 //===============================================
@@ -2530,6 +2617,7 @@ bool CheckConnectorTypeStatus(void)
             return false;
         }
 
+		pDcChargingInfo->SystemStatus = S_BOOTING;
         switch (gunIndex) {
         case 0:
             if (pSysConfig->TotalConnectorCount == 1) {
@@ -2970,6 +3058,7 @@ void CheckOcppStatus(void)
                 sleep(3);
                 system("killall OcppBackend &");
                 KillAllTask();
+                TryCloseWatchdog();
                 system("/usr/bin/run_evse_restart.sh");
             }
         }
@@ -3349,6 +3438,7 @@ void StopProcessingLoop()
                 log_info("Soft reboot for retry self-tets (Primary). \n");
                 KillAllTask();
                 sleep(3);
+                TryCloseWatchdog();
                 system("/usr/bin/run_evse_restart.sh");
                 return;
             }
@@ -3420,10 +3510,11 @@ void CheckTask()
 #endif //0
 
     /*--- 20200908, vern, disable it for DD360 ---*/
+    /*
     if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
         log_error("Module_ProduceUtils not running, restart it.\r\n");
         system ("/root/Module_ProduceUtils &");
-    }
+    }*/
 }
 
 //==========================================
@@ -4159,6 +4250,9 @@ int main(void)
     ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
     ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
     ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+	
+    ShmSysConfigAndInfo = (struct SysConfigAndInfo *)GetShmSysConfigAndInfo();
+    ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();	
 
     log_info(" ****************  FileSystem Boot up ***************\n");
     if (!InitialSystemDefaultConfig()) {
@@ -4256,8 +4350,6 @@ int main(void)
     // 1. Thernal - 控制風扇轉速
     // 2. ouput fuse - 控制風扇轉速
     CreateRfidFork();
-    // Create Watchdog
-    //CreateWatchdog();
     // Main loop
 
     log_info("===== Charger info ===== ");
@@ -4269,6 +4361,12 @@ int main(void)
 
     GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
+    //signal(SIGCHLD,SIG_IGN);
+
+	CreateCheckSystemTaskFork();
+
+    CreateWatchdog();
+
     for (;;) {
         CheckOcppStatus();
 
@@ -4303,7 +4401,7 @@ int main(void)
         }
 
         if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
-            CheckTask();
+            //CheckTask();
 
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
@@ -4565,6 +4663,9 @@ int main(void)
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
                 }
+#ifdef DD360Audi
+				pDcChargingInfo->Replug_flag = true;
+#endif
             }
             break;
 
@@ -4842,6 +4943,9 @@ int main(void)
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_CHARGING;
                 }
+#ifdef DD360Audi
+				pDcChargingInfo->Replug_flag = false;
+#endif
                 break;
 
             case S_ALARM:
@@ -5071,6 +5175,7 @@ int main(void)
                 }
                 break;
             }//switch
+            TryFeedWatchdog();
         }//for
 
 #if defined DD360Audi

+ 1 - 0
EVSE/Projects/DD360/Apps/Define/define.h

@@ -637,6 +637,7 @@ struct ChargingInfoData
     float               CurrentOffered;                 //0~6553.5 amp
     struct timespec     ConnectorTimeout;
     unsigned char       PantographFlag;                 // 0: normal gun type,  1: pantograph gun type
+	unsigned char 		Replug_flag;
 };
 
 typedef union

+ 4 - 2
EVSE/Projects/DD360/Apps/Makefile

@@ -70,7 +70,8 @@ COMMON_OBJ_FILES = common.o \
 MAIN_OBJ_FILES = $(COMMON_OBJ_FILES) $(DataBaseLib)/DataBase.o \
 					$(CSULib)/main.o  $(CSULib)/Primary.o $(CSULib)/WatchDog.o $(CSULib)/ZipFile.o \
 					$(CSULib)/RFID.o $(CSULib)/SelfTest.o $(CSULib)/UpgradeFW.o \
-					$(CSULib)/Ethernet.o
+					$(CSULib)/Ethernet.o $(CSULib)/CheckSystemTask.o
+					
 MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
@@ -129,7 +130,8 @@ apps: MainTask DoCommTask EvCommTask \
 
 MainTask:
 	$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
-		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) -o main
+		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) \
+		$(CheckSystemTask_H) -o main
 	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
 	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c

+ 14 - 7
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -1987,7 +1987,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;
@@ -2021,7 +2022,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2053,7 +2055,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2062,7 +2065,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CCS_PRECHARGE_ST0:
     case S_CCS_PRECHARGE_ST1:
         writeChargingTarget(fd, plugNum, gunID);
-        writeGroundFaultDetection(fd, 1, gunID);
+		if (pDcChargingInfo->PantographFlag)
+			writeGroundFaultDetection(fd, 1, gunID);
 
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2098,11 +2102,13 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_TERMINATING:
         if(pDcChargingInfo->Type == _Type_GB || pDcChargingInfo->Type == _Type_Chademo)
         {
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
         }
         else
         {
-            writeGroundFaultDetection(fd, 1, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 1, gunID);
         }
 
         ftime(&AuthNowTime);
@@ -2143,7 +2149,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;

+ 4 - 2
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalState.c

@@ -27,8 +27,10 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
     //iflog_info("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
 
     if (strncmp(string, "000000", 6) == EQUAL ||
-            strncmp(string, "012219", 6) == EQUAL
-       ) {
+            strncmp(string, "012219", 6) == EQUAL ||
+            strncmp(string, "023979", 6) == EQUAL )
+    {
+		log_info("NOTIFICATION_EV_STOP : EvCode = %s\n", string);
         return false;
     }
 

+ 3 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -15,6 +15,7 @@
 
 #include <linux/can.h>
 #include <linux/can/raw.h>
+#include <signal.h>
 
 #include "../Config.h"
 #include "../Log/log.h"
@@ -713,6 +714,8 @@ int main(int argc, char *argv[])
 
     FormatVoltageAndCurrent();
 
+    signal(SIGCHLD,SIG_IGN);
+    
     CANReceiver(CanFd);
 
     rtc = GetRtcInfoForEpoch();

+ 39 - 0
EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -223,6 +223,11 @@ uint8_t _right_gun_disable_map  = 68;
 uint8_t _right_gun_enable_map   = 69;
 uint8_t _select_gun_btn         = 70;
 uint8_t _emergency_disable_map  = 72;
+// For replug
+struct timespec showReplugStrTimer;
+short __show_replugString_value = 0x0460;
+uint8_t _showReplugStr_1 = 74;
+uint8_t _showReplugStr_2 = 75;
 
 //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
@@ -853,6 +858,31 @@ bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acCharging
 
     return false;
 }
+int GetTimeoutValue(struct timespec *startTime)
+{
+    struct timespec endTime;
+    clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+    return endTime.tv_sec - startTime->tv_sec;
+}
+void GetTimespecFunc(struct timespec *time)
+{
+    clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
+
+void RunReplugStringFunction(bool isRun)
+{
+    if (isRun) {
+        int time = GetTimeoutValue(&showReplugStrTimer);
+        if (time >=1 && time <2) {
+            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_1);
+        } else if (time < 1) {
+            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_2);
+        } else
+            GetTimespecFunc(&showReplugStrTimer);
+
+    } else
+        ChangeDisplay2Value(__show_replugString_value, _disappear);
+}
 
 /**
  * [ChangeBalanceValue :print balance information]
@@ -2041,6 +2071,15 @@ void ProcessPageInfo()
                     } else {
                         ChangeDisplay2Value(__charging_fee_map, _money_map);
                     }
+#ifdef DD360Audi
+                    // Warming Occur in prepare or precharing state, turn into complete mode
+                    if (pDcChargingInfo->Replug_flag) {
+                        RunReplugStringFunction(true);
+                    } else {
+                        RunReplugStringFunction(false);
+                    }
+#else
+#endif					
                 }
             }
         }

+ 46 - 5
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -48,6 +48,11 @@ static struct PrimaryMcuData *ShmPrimaryMcuData;
 const char *priPortName = "/dev/ttyS1";
 uint8_t gun_count; //DS60-120 add
 
+uint8_t EmgBtn_count = 0;
+uint8_t Door_count = 0;
+uint8_t EmgBtn_flag = 0;
+uint8_t Door_flag = 0;
+
 //struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 //------------------------------------------------------------------------------
@@ -182,11 +187,26 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
 
 #if defined DD360ComBox
-    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
+    if (~gpio_in.Emergency_Btn)
 #else
-    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+    if (gpio_in.Emergency_Btn && (EmgBtn_flag != gpio_in.Emergency_Btn))
 #endif //defined DD360ComBox
-
+    {
+            EmgBtn_count++;
+        if (EmgBtn_count > SensorTrigCount) {
+           EmgBtn_flag = 1;
+           EmgBtn_count = 0; // Avoid Overflow
+       }
+    } else if (EmgBtn_flag != gpio_in.Emergency_Btn) {
+        EmgBtn_count++;
+        if (EmgBtn_count > SensorTrigCount) {
+            EmgBtn_flag = 0;
+            EmgBtn_count = 0;
+        }
+    }
+ 
+    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = EmgBtn_flag;
+ 
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
@@ -219,10 +239,31 @@ void GetInputGpioStatus(int fd)
     }
 
 #if defined DD360ComBox
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
+    if (gpio_in.Door_Open)
 #else
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
+    if (gpio_in.Door_Open == 0 && (Door_flag == gpio_in.Door_Open))
 #endif //defined DD360ComBox
+    {
+        Door_count++;
+        if (Door_count > SensorTrigCount) {
+            Door_flag = 1;
+            Door_count = 0; // Avoid Overflow
+       }
+    } else if (gpio_in.Door_Open && Door_flag) {
+        Door_count++;
+        if (Door_count > SensorTrigCount) {
+            Door_flag = 0;
+            Door_count = 0;
+        }
+    }
+ 
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = Door_flag;
+/*
+    log_info("Emergency Button Count = %d , Emergency flag = %d\n",
+            EmgBtn_count,EmgBtn_flag);
+    log_info("Door Sensor Count = %d , Door Sensor flag = %d\n",
+            Door_count,Door_flag);
+*/
 
     ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
     ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;

+ 1 - 0
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -30,5 +30,6 @@ typedef struct StLedConfig {
 
 //------------------------------------------------------------------------------
 //int StoreLogMsg(const char *fmt, ...);
+#define SensorTrigCount 3
 
 #endif /* _MODULE_PRIMARY_COMM_H_ */

+ 4 - 0
EVSE/Projects/DD360/Apps/Script/kill.sh

@@ -12,6 +12,10 @@ pkill Module_ProduceUtils;
 pkill Module_DoComm;
 pkill main;
 
+sleep 1
+
+echo V > /dev/watchdog
+
 ipcrm -M 0x000003e9;
 ipcrm -M 0x000003ed;
 ipcrm -M 0x000003ea;

+ 31 - 17
EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c

@@ -833,7 +833,7 @@ static int findDcChargingInfoData(uint8_t gunIndex)
     return FAIL;
 }
 
-static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
+static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichtask)
 {
     bool result = true;
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -862,11 +862,14 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pAcChargingInfo->ReservationId = -1;
             pAcChargingInfo->SystemStatus = S_IDLE;
             pAcChargingInfo->Type = _Type_AC;
-            pAcChargingInfo->IsAvailable = YES;
             pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add
             pAcChargingInfo->schedule.isTriggerStop = NO;  //DS60-120 add
-            gGunIndexInfo.AcIndex++;
-            gGunIndexInfo.AcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                gGunIndexInfo.AcIndex++;
+                gGunIndexInfo.AcGunIndex++;
+                pAcChargingInfo->IsAvailable = YES;
+            }
         } else {
             result = false;
         }
@@ -886,13 +889,17 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
+			//pDcChargingInfo->SystemStatus = S_IDLE;
             pDcChargingInfo->Type = _Type_Chademo;
             pDcChargingInfo->type_index = gGunIndexInfo.ChademoIndex;
-            pDcChargingInfo->IsAvailable = YES;
             setAcGunTiggerStatus();
-            gGunIndexInfo.ChademoIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.ChademoIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
         } else {
             result = false;
         }
@@ -914,15 +921,19 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
             pDcChargingInfo->Type = _Type_CCS_2;
             pDcChargingInfo->type_index = gGunIndexInfo.CcsIndex;
-            pDcChargingInfo->IsAvailable = YES;
+
             setAcGunTiggerStatus();
             // 現階段預設為走 DIN70121
             pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
-            gGunIndexInfo.CcsIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.CcsIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
             if(typeValue == 'P')
             {
                 pDcChargingInfo->PantographFlag = YES;
@@ -939,13 +950,16 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
             pDcChargingInfo->Type = _Type_GB;
             pDcChargingInfo->type_index = gGunIndexInfo.GbIndex;
-            pDcChargingInfo->IsAvailable = YES;
             setAcGunTiggerStatus();
-            gGunIndexInfo.GbIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.GbIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
         } else {
             result = false;
         }
@@ -988,7 +1002,7 @@ bool MappingGunChargingInfo(char *whichTask)
 
     //printf("1 CheckConnectorTypeStatus\r\n");
     for (typeIndex = 7; typeIndex <= 9; typeIndex++) {
-        if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots)) {
+        if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots, whichTask)) {
             log_error("%s add gun info failed\r\n", whichTask);
             return false;
         }

BIN
EVSE/Projects/DD360/Apps/UnsafetyOutputTask


+ 184 - 0
EVSE/Projects/DD360Audi/Apps/CSU/CheckSystemTask.c

@@ -0,0 +1,184 @@
+/*
+ * CheckTask.c
+ *
+ *  Created on: 2021年9月22日
+ *      Author: 8513
+ */
+
+#include "CheckSystemTask.h"
+
+bool Taskconutstring(char *src, char *taskname)
+{
+    bool result = false;
+
+    if (src == NULL || strlen(src) == 0)
+        return result;
+
+    if (strstr(src, taskname) != NULL &&
+        strstr(src, "grep") == NULL &&
+        strstr(src, "[") == NULL)
+    {
+        result = true;
+    }
+
+    return result;
+}
+
+int GetProcessCount(char *procName)
+{
+	int result = 0;
+	FILE *fp;
+	char cmd[256];
+	char buf[256];
+
+	sprintf(cmd, "ps -ef |grep %s", procName);
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if (Taskconutstring(buf, procName))
+				result++;
+		}
+	}
+
+	pclose(fp);
+
+	return result;
+}
+
+unsigned char CheckSystemTask(unsigned char systemPage)
+{
+	unsigned char result = 0;
+	unsigned char count_main 		= GetProcessCount("main");
+	unsigned char count_evComm 		= GetProcessCount("Module_EvComm");
+	unsigned char count_interComm	= GetProcessCount("Module_InternalComm");
+	unsigned char count_eventComm	= GetProcessCount("Module_EventLogging");
+	unsigned char count_primaryComm	= GetProcessCount("Module_PrimaryComm");
+	unsigned char count_lcmComm	    = GetProcessCount("Module_LcmControl");
+	unsigned char count_doComm	    = GetProcessCount("Module_DoComm");
+	unsigned char count_produceComm	= GetProcessCount("Module_ProduceUtils");
+//	unsigned char count_psuComm 	= GetProcessCount("Module_PsuComm");
+
+//	printf("*************************** \n");
+//	printf("count_main = %d \n", count_main);
+//	printf("count_eventLog = %d \n", count_eventLog);
+//	printf("count_primary = %d \n", count_primary);
+//	printf("count_evComm = %d \n", count_evComm);
+//	printf("count_lcmCtrl = %d \n", count_lcmCtrl);
+//	printf("count_interComm = %d \n", count_interComm);
+//	printf("count_psuComm = %d \n", count_psuComm);
+//	printf("*************************** \n");
+
+//	if (systemPage == 0x09 || systemPage == 0x0A)
+	{
+		if (count_main < _SYSTEM_TASK_COUNT_MAIN )
+		{
+			system("killall Module_EventLogging");
+			system("killall Module_PrimaryComm");
+			system("killall Module_EvComm");
+			system("killall Module_LcmControl");
+			system("killall Module_InternalComm");
+			system("killall Module_DoComm");
+//			system("killall Module_PsuComm");
+//			system("killall OcppBackend &");
+//			system("killall Module_4g &");
+//			system("killall Module_Wifi &");
+			system("killall Module_ProduceUtils &");
+			sleep(3);
+			system("/usr/bin/run_evse_restart.sh");
+		}
+		else
+		{
+			/*
+			if(system("pidof -s Module_EventLogging > /dev/null") != 0)
+				system("/root/Module_EventLogging &");
+
+			if(system("pidof -s Module_PrimaryComm > /dev/null") != 0)
+				system("/root/Module_PrimaryComm &");
+
+			if(system("pidof -s Module_LcmControl > /dev/null") != 0)
+				system("/root/Module_LcmControl &");
+
+            if(system("pidof -s Module_DoComm > /dev/null") != 0)
+                system("/root/Module_DoComm &");
+
+            if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
+                system("/root/Module_ProduceUtils &");
+
+			*/
+			if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM )
+			{
+				system("killall Module_EvComm");
+				sleep(3);
+				system("/root/Module_EvComm &");
+			}
+        	if (count_interComm < _SYSTEM_TASK_COUNT_INTERNALCOMM )
+			{
+				system("killall Module_InternalComm");
+				sleep(3);
+				system("/root/Module_InternalComm &");
+			}
+			if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING )
+			{
+				system("killall Module_EventLogging");
+				sleep(3);
+				system("/root/Module_EventLogging &");
+			}
+			if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM )
+			{
+				system("killall Module_PrimaryComm");
+				sleep(3);
+				system("/root/Module_PrimaryComm &");
+			}
+			if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM )
+			{
+				system("killall Module_LcmControl");
+				sleep(3);
+				system("/root/Module_LcmControl &");
+			}
+			if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM )
+			{
+				system("killall Module_DoComm");
+				sleep(3);
+				system("/root/Module_DoComm &");
+			}
+			if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS )
+			{
+				system("killall Module_ProduceUtils");
+				sleep(3);
+				system("/root/Module_ProduceUtils &");
+			}
+			/*
+			if (count_psuComm < 2)
+			{
+				system("killall Module_PsuComm");
+				sleep(3);
+				system("/root/Module_PsuComm &");
+			}*/
+		}
+
+		sleep(2);
+	}
+
+	if (count_main < _SYSTEM_TASK_COUNT_MAIN)
+		result = _SYSTEM_TASK_LOST_ITEM_MAIN;
+	else if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM)
+		result = _SYSTEM_TASK_LOST_ITEM_EVCOMM;
+/*	else if (count_psuComm < 2)
+		result = 3; */
+    else if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING )
+        result = _SYSTEM_TASK_LOST_ITEM_EVENTLOG;
+    else if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM)
+        result = _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM;
+    else if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM)
+        result = _SYSTEM_TASK_LOST_ITEM_LCMCONTROL;
+    else if (count_interComm < 2 )
+        result = _SYSTEM_TASK_LOST_ITEM_INTERCOMM;
+    else if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM)
+        result = _SYSTEM_TASK_LOST_ITEM_DOCOMM;
+    else if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS)
+        result = _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS;
+
+	return result;
+}

+ 60 - 0
EVSE/Projects/DD360Audi/Apps/CSU/CheckSystemTask.h

@@ -0,0 +1,60 @@
+/*
+ * CheckTask.h
+ *
+ *  Created on: 2021年9月2日
+ *      Author: 7564
+ */
+
+#ifndef CHECKTASK_H_
+#define CHECKTASK_H_
+
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<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 	<string.h>
+#include 	<stdint.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	<stdbool.h>
+#include 	<dirent.h>
+
+#define _SYSTEM_TASK_LOST_ITEM_MAIN         1
+#define _SYSTEM_TASK_LOST_ITEM_EVCOMM       2
+#define _SYSTEM_TASK_LOST_ITEM_EVENTLOG     3
+#define _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM  4
+#define _SYSTEM_TASK_LOST_ITEM_LCMCONTROL   5
+#define _SYSTEM_TASK_LOST_ITEM_INTERCOMM    6
+#define _SYSTEM_TASK_LOST_ITEM_DOCOMM       7
+#define _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS 8
+
+#define _SYSTEM_TASK_COUNT_MAIN             5
+#define _SYSTEM_TASK_COUNT_EVCOMM           2
+#define _SYSTEM_TASK_COUNT_INTERNALCOMM     2
+#define _SYSTEM_TASK_COUNT_EVENTLOGGING     1
+#define _SYSTEM_TASK_COUNT_PRIMARYCOMM      1
+#define _SYSTEM_TASK_COUNT_LCM              1
+#define _SYSTEM_TASK_COUNT_DOCOMM           1
+#define _SYSTEM_TASK_COUNT_PRODUCEUTILS     1
+
+
+unsigned char CheckSystemTask(unsigned char systemPage);
+
+#endif /* CHECKSYSTEMTASK_H_ */

+ 8 - 0
EVSE/Projects/DD360Audi/Apps/CSU/UpgradeFW.c

@@ -12,6 +12,11 @@
 #include "../ShareMemory/shmMem.h"
 
 #include "main.h"
+//WatchDog.c
+extern void CreateWatchdog(void);
+extern void TryCloseWatchdog(void);
+extern void TryFeedWatchdog(void);
+
 
 //------------------------------------------------------------------------------
 static char *_priPortName = "/dev/ttyS1";
@@ -325,6 +330,8 @@ void CheckFwUpdateFunction(void)
     //log_info("pSysInfo->FirmwareUpdate = %d \n", pSysInfo->FirmwareUpdate);
     if (pSysInfo->FirmwareUpdate == YES) {
         log_info("ftp : update start. \n");
+        TryCloseWatchdog();
+
         for (uint8_t gun_index = 0; gun_index < pSysConfig->TotalConnectorCount; gun_index++) {
             setChargerMode(gun_index, MODE_UPDATE);
         }
@@ -352,6 +359,7 @@ void CheckFwUpdateFunction(void)
 
         if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
             log_info("Backend : update start. \n");
+            TryCloseWatchdog();
             strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
             strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
             ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;

+ 39 - 17
EVSE/Projects/DD360Audi/Apps/CSU/WatchDog.c

@@ -8,41 +8,63 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 
-//------------------------------------------------------------------------------
-static int gWatchDogfd = -1;
+int wtdFd = -1;
+struct StatusCodeData           *ShmStatusCodeData;
 
-//------------------------------------------------------------------------------
-void WriteWatchDogState(char *value)
-{
-    write(gWatchDogfd, value, 1);
-}
+void CreateWatchdog(void);
+void TryCloseWatchdog(void);
+void TryFeedWatchdog(void);
 
-static int initWatchDog(void)
+int InitWatchDog()
 {
     int fd;
+    int timeout = 180;
+
     system("/usr/bin/fuser -k /dev/watchdog");
     sleep(1);
     system("echo V > /dev/watchdog");
     sleep(1);
-    fd = open("/dev/watchdog", O_RDWR);
+    fd=open("/dev/watchdog", O_RDWR);
 
-    if (fd <= 0) {
+    if(fd<=0)
+    {
         log_error("System watch dog initial fail.\r\n");
     }
+    ioctl(fd, _IOWR('W', 6, int), &timeout);
 
     return fd;
 }
 
 void CreateWatchdog(void)
 {
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    wtdFd = InitWatchDog();
+
+    ShmStatusCodeData = (struct StatusCodeData*)GetShmStatusCodeData();
+    if(wtdFd < 0)
+    {
+        log_info("Watchdog Initial Fail");
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+    }
+    else
+    {
+        log_info("Watchdog Initial Success");
+    }
+}
 
-    if (pSysConfig->SwitchDebugFlag == NO) {
-        gWatchDogfd = initWatchDog();
+void TryCloseWatchdog(void)
+{
+    if(wtdFd > 0)
+    {
+        write(wtdFd, "V", 1);
+        close(wtdFd);
+    }
+}
 
-        if (gWatchDogfd < 0) {
-            pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
-        }
+void TryFeedWatchdog(void)
+{
+    if(wtdFd > 0)
+    {
+        write(wtdFd, "a", 1);
     }
 }
+

+ 48 - 0
EVSE/Projects/DD360Audi/Apps/CSU/WatchDog.c.old

@@ -0,0 +1,48 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+static int gWatchDogfd = -1;
+
+//------------------------------------------------------------------------------
+void WriteWatchDogState(char *value)
+{
+    write(gWatchDogfd, value, 1);
+}
+
+static int initWatchDog(void)
+{
+    int fd;
+    system("/usr/bin/fuser -k /dev/watchdog");
+    sleep(1);
+    system("echo V > /dev/watchdog");
+    sleep(1);
+    fd = open("/dev/watchdog", O_RDWR);
+
+    if (fd <= 0) {
+        log_error("System watch dog initial fail.\r\n");
+    }
+
+    return fd;
+}
+
+void CreateWatchdog(void)
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    if (pSysConfig->SwitchDebugFlag == NO) {
+        gWatchDogfd = initWatchDog();
+
+        if (gWatchDogfd < 0) {
+            pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
+        }
+    }
+}

+ 114 - 9
EVSE/Projects/DD360Audi/Apps/CSU/main.c

@@ -29,6 +29,7 @@
 #include <math.h>
 #include <stdbool.h>
 #include <dirent.h>
+#include <signal.h>
 
 #include "../Config.h"
 #include "main.h"
@@ -40,6 +41,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../SelectGun/SelectGun.h"
+#include "CheckSystemTask.h"
 
 //------------------------------------------------------------------------------
 static struct SysInfoData *pSysInfo = NULL;
@@ -71,13 +73,16 @@ static SelectGunInfo *ShmSelectGunInfo = NULL; //Jerry add
 static EvBoardErrMsg gEvBoardErr = {0};
 static ChillerTempErr gChillerTempErr = {0};
 
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+
 // for initial index to check EV board type is correct
 uint8_t bd0_1_status = 0;
 uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V1.14.00.0000.00"; // "V0.16.00.0000.00";
+char *fwVersion = "V1.15.00.0000.00"; // "V0.16.00.0000.00";
 
 //sqlite3 *localDb;
 bool isDb_ready;
@@ -123,7 +128,8 @@ extern void GetMacAddress(void);
 
 //WatchDog.c
 extern void CreateWatchdog(void);
-extern void WriteWatchDogState(char *value);
+extern void TryCloseWatchdog(void);
+extern void TryFeedWatchdog(void);
 
 //ZipFile.c
 extern void zipLogFiles(void);
@@ -1631,7 +1637,11 @@ void _DetectPlugInTimeout(void)
     ClearDetectPluginFlag();
 
     sleep(1); //等待DoComm回報插槍訊號給主櫃
-
+#if defined DD360Audi || DD360 || DD360Combox
+	    //pSysInfo->SystemPage = _LCM_COMPLETE;
+		setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
+	    return;
+#endif
     systemPageRestoreInit();
 }
 
@@ -1661,7 +1671,12 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
     log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
     //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
     {
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
         setChargerMode(gunIndex, MODE_IDLE);
+#endif
         _AutoReturnTimeout();
     }
 }
@@ -1669,7 +1684,12 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
 void _PrepareTimeout(uint8_t gunIndex)
 {
     log_info("*********** _PrepareTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
+     setChargerMode(gunIndex, MODE_IDLE);
+#endif
     pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
     _AutoReturnTimeout();
 }
@@ -1677,9 +1697,76 @@ void _PrepareTimeout(uint8_t gunIndex)
 void _CcsPrechargeTimeout(uint8_t gunIndex)
 {
     log_info("*********** _CcsPrechargeTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
+     setChargerMode(gunIndex, MODE_IDLE);
+#endif
 }
 
+//===============================================
+// Check System Task alive
+// ==============================================
+void CheckSystemTaskAlive()
+{
+    unsigned char lostId = CheckSystemTask(ShmSysConfigAndInfo->SysInfo.SystemPage);
+    if (lostId != 0) {
+        log_info("Check task(%d) lost\n",lostId);
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost == NO) {
+           if (lostId == _SYSTEM_TASK_LOST_ITEM_MAIN)
+               log_info("System task lost (CSU). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVCOMM)
+               log_info("System task lost (EVComm). \n");
+//           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PSUCOMM)
+//               PRINTF_FUNC("System task lost (PSU Task). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVENTLOG)
+               log_info("System task lost (Event log). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM)
+               log_info("System task lost (Primary). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_LCMCONTROL)
+               log_info("System task lost (LCM Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_INTERCOMM)
+               log_info("System task lost (Internal Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_DOCOMM)
+               log_info("System task lost (Do Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS)
+               log_info("System task lost (ProcductUtils Comm). \n");
+           ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = YES;
+        }
+    } else
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = NO;
+}
+
+void CreateCheckSystemTaskFork()
+{
+    pid_t taskPid;
+    taskPid = fork();
+    if (taskPid == 0)
+    {
+        while(true)
+        {
+			/*
+			for (int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo[_index]->SystemStatus == SYS_MODE_UPDATE ||
+						chargingInfo[_index]->Type == 0x09)
+				{
+					stopToDet = true;
+					continue;
+				}
+			}
+			*/
+			for (uint8_t gun = 0; gun < pSysConfig->TotalConnectorCount; gun++) {
+				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
+				if (pDcChargingInfo->SystemStatus == SYS_MODE_UPDATE )
+						continue;
+			}
+			CheckSystemTaskAlive();
+			sleep(5);
+		}
+	}
+}
 //===============================================
 // 取得卡號與卡號驗證
 //===============================================
@@ -2530,6 +2617,7 @@ bool CheckConnectorTypeStatus(void)
             return false;
         }
 
+		pDcChargingInfo->SystemStatus = S_BOOTING;
         switch (gunIndex) {
         case 0:
             if (pSysConfig->TotalConnectorCount == 1) {
@@ -2970,6 +3058,7 @@ void CheckOcppStatus(void)
                 sleep(3);
                 system("killall OcppBackend &");
                 KillAllTask();
+                TryCloseWatchdog();
                 system("/usr/bin/run_evse_restart.sh");
             }
         }
@@ -3349,6 +3438,7 @@ void StopProcessingLoop()
                 log_info("Soft reboot for retry self-tets (Primary). \n");
                 KillAllTask();
                 sleep(3);
+                TryCloseWatchdog();
                 system("/usr/bin/run_evse_restart.sh");
                 return;
             }
@@ -3420,10 +3510,11 @@ void CheckTask()
 #endif //0
 
     /*--- 20200908, vern, disable it for DD360 ---*/
+    /*
     if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
         log_error("Module_ProduceUtils not running, restart it.\r\n");
         system ("/root/Module_ProduceUtils &");
-    }
+    }*/
 }
 
 //==========================================
@@ -4159,6 +4250,9 @@ int main(void)
     ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
     ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
     ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+	
+    ShmSysConfigAndInfo = (struct SysConfigAndInfo *)GetShmSysConfigAndInfo();
+    ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();	
 
     log_info(" ****************  FileSystem Boot up ***************\n");
     if (!InitialSystemDefaultConfig()) {
@@ -4256,8 +4350,6 @@ int main(void)
     // 1. Thernal - 控制風扇轉速
     // 2. ouput fuse - 控制風扇轉速
     CreateRfidFork();
-    // Create Watchdog
-    //CreateWatchdog();
     // Main loop
 
     log_info("===== Charger info ===== ");
@@ -4269,6 +4361,12 @@ int main(void)
 
     GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
+    //signal(SIGCHLD,SIG_IGN);
+
+	CreateCheckSystemTaskFork();
+
+    CreateWatchdog();
+
     for (;;) {
         CheckOcppStatus();
 
@@ -4303,7 +4401,7 @@ int main(void)
         }
 
         if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
-            CheckTask();
+            //CheckTask();
 
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
@@ -4565,6 +4663,9 @@ int main(void)
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
                 }
+#ifdef DD360Audi
+				pDcChargingInfo->Replug_flag = true;
+#endif
             }
             break;
 
@@ -4842,6 +4943,9 @@ int main(void)
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_CHARGING;
                 }
+#ifdef DD360Audi
+				pDcChargingInfo->Replug_flag = false;
+#endif
                 break;
 
             case S_ALARM:
@@ -5071,6 +5175,7 @@ int main(void)
                 }
                 break;
             }//switch
+            TryFeedWatchdog();
         }//for
 
 #if defined DD360Audi

+ 1 - 0
EVSE/Projects/DD360Audi/Apps/Define/define.h

@@ -637,6 +637,7 @@ struct ChargingInfoData
     float               CurrentOffered;                 //0~6553.5 amp
     struct timespec     ConnectorTimeout;
     unsigned char       PantographFlag;                 // 0: normal gun type,  1: pantograph gun type
+	unsigned char 		Replug_flag;
 };
 
 typedef union

+ 4 - 2
EVSE/Projects/DD360Audi/Apps/Makefile

@@ -70,7 +70,8 @@ COMMON_OBJ_FILES = common.o \
 MAIN_OBJ_FILES = $(COMMON_OBJ_FILES) $(DataBaseLib)/DataBase.o \
 					$(CSULib)/main.o  $(CSULib)/Primary.o $(CSULib)/WatchDog.o $(CSULib)/ZipFile.o \
 					$(CSULib)/RFID.o $(CSULib)/SelfTest.o $(CSULib)/UpgradeFW.o \
-					$(CSULib)/Ethernet.o
+					$(CSULib)/Ethernet.o $(CSULib)/CheckSystemTask.o
+					
 MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
@@ -129,7 +130,8 @@ apps: MainTask DoCommTask EvCommTask \
 
 MainTask:
 	$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
-		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) -o main
+		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) \
+		$(CheckSystemTask_H) -o main
 	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
 	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c

+ 14 - 7
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -1987,7 +1987,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;
@@ -2021,7 +2022,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2053,7 +2055,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2062,7 +2065,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CCS_PRECHARGE_ST0:
     case S_CCS_PRECHARGE_ST1:
         writeChargingTarget(fd, plugNum, gunID);
-        writeGroundFaultDetection(fd, 1, gunID);
+		if (pDcChargingInfo->PantographFlag)
+			writeGroundFaultDetection(fd, 1, gunID);
 
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2098,11 +2102,13 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_TERMINATING:
         if(pDcChargingInfo->Type == _Type_GB || pDcChargingInfo->Type == _Type_Chademo)
         {
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
         }
         else
         {
-            writeGroundFaultDetection(fd, 1, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 1, gunID);
         }
 
         ftime(&AuthNowTime);
@@ -2143,7 +2149,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;

+ 4 - 2
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalState.c

@@ -27,8 +27,10 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
     //iflog_info("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
 
     if (strncmp(string, "000000", 6) == EQUAL ||
-            strncmp(string, "012219", 6) == EQUAL
-       ) {
+            strncmp(string, "012219", 6) == EQUAL ||
+            strncmp(string, "023979", 6) == EQUAL )
+    {
+		log_info("NOTIFICATION_EV_STOP : EvCode = %s\n", string);
         return false;
     }
 

+ 3 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -15,6 +15,7 @@
 
 #include <linux/can.h>
 #include <linux/can/raw.h>
+#include <signal.h>
 
 #include "../Config.h"
 #include "../Log/log.h"
@@ -713,6 +714,8 @@ int main(int argc, char *argv[])
 
     FormatVoltageAndCurrent();
 
+    signal(SIGCHLD,SIG_IGN);
+    
     CANReceiver(CanFd);
 
     rtc = GetRtcInfoForEpoch();

+ 39 - 0
EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -223,6 +223,11 @@ uint8_t _right_gun_disable_map  = 68;
 uint8_t _right_gun_enable_map   = 69;
 uint8_t _select_gun_btn         = 70;
 uint8_t _emergency_disable_map  = 72;
+// For replug
+struct timespec showReplugStrTimer;
+short __show_replugString_value = 0x0460;
+uint8_t _showReplugStr_1 = 74;
+uint8_t _showReplugStr_2 = 75;
 
 //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
@@ -853,6 +858,31 @@ bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acCharging
 
     return false;
 }
+int GetTimeoutValue(struct timespec *startTime)
+{
+    struct timespec endTime;
+    clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+    return endTime.tv_sec - startTime->tv_sec;
+}
+void GetTimespecFunc(struct timespec *time)
+{
+    clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
+
+void RunReplugStringFunction(bool isRun)
+{
+    if (isRun) {
+        int time = GetTimeoutValue(&showReplugStrTimer);
+        if (time >=1 && time <2) {
+            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_1);
+        } else if (time < 1) {
+            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_2);
+        } else
+            GetTimespecFunc(&showReplugStrTimer);
+
+    } else
+        ChangeDisplay2Value(__show_replugString_value, _disappear);
+}
 
 /**
  * [ChangeBalanceValue :print balance information]
@@ -2041,6 +2071,15 @@ void ProcessPageInfo()
                     } else {
                         ChangeDisplay2Value(__charging_fee_map, _money_map);
                     }
+#ifdef DD360Audi
+                    // Warming Occur in prepare or precharing state, turn into complete mode
+                    if (pDcChargingInfo->Replug_flag) {
+                        RunReplugStringFunction(true);
+                    } else {
+                        RunReplugStringFunction(false);
+                    }
+#else
+#endif					
                 }
             }
         }

+ 46 - 5
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -48,6 +48,11 @@ static struct PrimaryMcuData *ShmPrimaryMcuData;
 const char *priPortName = "/dev/ttyS1";
 uint8_t gun_count; //DS60-120 add
 
+uint8_t EmgBtn_count = 0;
+uint8_t Door_count = 0;
+uint8_t EmgBtn_flag = 0;
+uint8_t Door_flag = 0;
+
 //struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 //------------------------------------------------------------------------------
@@ -182,11 +187,26 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
 
 #if defined DD360ComBox
-    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
+    if (~gpio_in.Emergency_Btn)
 #else
-    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+    if (gpio_in.Emergency_Btn && (EmgBtn_flag != gpio_in.Emergency_Btn))
 #endif //defined DD360ComBox
-
+    {
+            EmgBtn_count++;
+        if (EmgBtn_count > SensorTrigCount) {
+           EmgBtn_flag = 1;
+           EmgBtn_count = 0; // Avoid Overflow
+       }
+    } else if (EmgBtn_flag != gpio_in.Emergency_Btn) {
+        EmgBtn_count++;
+        if (EmgBtn_count > SensorTrigCount) {
+            EmgBtn_flag = 0;
+            EmgBtn_count = 0;
+        }
+    }
+ 
+    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = EmgBtn_flag;
+ 
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
@@ -219,10 +239,31 @@ void GetInputGpioStatus(int fd)
     }
 
 #if defined DD360ComBox
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
+    if (gpio_in.Door_Open)
 #else
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
+    if (gpio_in.Door_Open == 0 && (Door_flag == gpio_in.Door_Open))
 #endif //defined DD360ComBox
+    {
+        Door_count++;
+        if (Door_count > SensorTrigCount) {
+            Door_flag = 1;
+            Door_count = 0; // Avoid Overflow
+       }
+    } else if (gpio_in.Door_Open && Door_flag) {
+        Door_count++;
+        if (Door_count > SensorTrigCount) {
+            Door_flag = 0;
+            Door_count = 0;
+        }
+    }
+ 
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = Door_flag;
+/*
+    log_info("Emergency Button Count = %d , Emergency flag = %d\n",
+            EmgBtn_count,EmgBtn_flag);
+    log_info("Door Sensor Count = %d , Door Sensor flag = %d\n",
+            Door_count,Door_flag);
+*/
 
     ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
     ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;

+ 1 - 0
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -30,5 +30,6 @@ typedef struct StLedConfig {
 
 //------------------------------------------------------------------------------
 //int StoreLogMsg(const char *fmt, ...);
+#define SensorTrigCount 3
 
 #endif /* _MODULE_PRIMARY_COMM_H_ */

+ 4 - 0
EVSE/Projects/DD360Audi/Apps/Script/kill.sh

@@ -12,6 +12,10 @@ pkill Module_ProduceUtils;
 pkill Module_DoComm;
 pkill main;
 
+sleep 1
+
+echo V > /dev/watchdog
+
 ipcrm -M 0x000003e9;
 ipcrm -M 0x000003ed;
 ipcrm -M 0x000003ea;

+ 31 - 17
EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c

@@ -833,7 +833,7 @@ static int findDcChargingInfoData(uint8_t gunIndex)
     return FAIL;
 }
 
-static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
+static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichtask)
 {
     bool result = true;
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -862,11 +862,14 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pAcChargingInfo->ReservationId = -1;
             pAcChargingInfo->SystemStatus = S_IDLE;
             pAcChargingInfo->Type = _Type_AC;
-            pAcChargingInfo->IsAvailable = YES;
             pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add
             pAcChargingInfo->schedule.isTriggerStop = NO;  //DS60-120 add
-            gGunIndexInfo.AcIndex++;
-            gGunIndexInfo.AcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                gGunIndexInfo.AcIndex++;
+                gGunIndexInfo.AcGunIndex++;
+                pAcChargingInfo->IsAvailable = YES;
+            }
         } else {
             result = false;
         }
@@ -886,13 +889,17 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
+			//pDcChargingInfo->SystemStatus = S_IDLE;
             pDcChargingInfo->Type = _Type_Chademo;
             pDcChargingInfo->type_index = gGunIndexInfo.ChademoIndex;
-            pDcChargingInfo->IsAvailable = YES;
             setAcGunTiggerStatus();
-            gGunIndexInfo.ChademoIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.ChademoIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
         } else {
             result = false;
         }
@@ -914,15 +921,19 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
             pDcChargingInfo->Type = _Type_CCS_2;
             pDcChargingInfo->type_index = gGunIndexInfo.CcsIndex;
-            pDcChargingInfo->IsAvailable = YES;
+
             setAcGunTiggerStatus();
             // 現階段預設為走 DIN70121
             pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
-            gGunIndexInfo.CcsIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.CcsIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
             if(typeValue == 'P')
             {
                 pDcChargingInfo->PantographFlag = YES;
@@ -939,13 +950,16 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
             pDcChargingInfo->Type = _Type_GB;
             pDcChargingInfo->type_index = gGunIndexInfo.GbIndex;
-            pDcChargingInfo->IsAvailable = YES;
             setAcGunTiggerStatus();
-            gGunIndexInfo.GbIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.GbIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
         } else {
             result = false;
         }
@@ -988,7 +1002,7 @@ bool MappingGunChargingInfo(char *whichTask)
 
     //printf("1 CheckConnectorTypeStatus\r\n");
     for (typeIndex = 7; typeIndex <= 9; typeIndex++) {
-        if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots)) {
+        if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots, whichTask)) {
             log_error("%s add gun info failed\r\n", whichTask);
             return false;
         }

+ 0 - 0
EVSE/Projects/DD360ComBox/Apps/.metadata/.lock


+ 184 - 0
EVSE/Projects/DD360ComBox/Apps/CSU/CheckSystemTask.c

@@ -0,0 +1,184 @@
+/*
+ * CheckTask.c
+ *
+ *  Created on: 2021年9月22日
+ *      Author: 8513
+ */
+
+#include "CheckSystemTask.h"
+
+bool Taskconutstring(char *src, char *taskname)
+{
+    bool result = false;
+
+    if (src == NULL || strlen(src) == 0)
+        return result;
+
+    if (strstr(src, taskname) != NULL &&
+        strstr(src, "grep") == NULL &&
+        strstr(src, "[") == NULL)
+    {
+        result = true;
+    }
+
+    return result;
+}
+
+int GetProcessCount(char *procName)
+{
+	int result = 0;
+	FILE *fp;
+	char cmd[256];
+	char buf[256];
+
+	sprintf(cmd, "ps -ef |grep %s", procName);
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if (Taskconutstring(buf, procName))
+				result++;
+		}
+	}
+
+	pclose(fp);
+
+	return result;
+}
+
+unsigned char CheckSystemTask(unsigned char systemPage)
+{
+	unsigned char result = 0;
+	unsigned char count_main 		= GetProcessCount("main");
+	unsigned char count_evComm 		= GetProcessCount("Module_EvComm");
+	unsigned char count_interComm	= GetProcessCount("Module_InternalComm");
+	unsigned char count_eventComm	= GetProcessCount("Module_EventLogging");
+	unsigned char count_primaryComm	= GetProcessCount("Module_PrimaryComm");
+	unsigned char count_lcmComm	    = GetProcessCount("Module_LcmControl");
+	unsigned char count_doComm	    = GetProcessCount("Module_DoComm");
+	unsigned char count_produceComm	= GetProcessCount("Module_ProduceUtils");
+//	unsigned char count_psuComm 	= GetProcessCount("Module_PsuComm");
+
+//	printf("*************************** \n");
+//	printf("count_main = %d \n", count_main);
+//	printf("count_eventLog = %d \n", count_eventLog);
+//	printf("count_primary = %d \n", count_primary);
+//	printf("count_evComm = %d \n", count_evComm);
+//	printf("count_lcmCtrl = %d \n", count_lcmCtrl);
+//	printf("count_interComm = %d \n", count_interComm);
+//	printf("count_psuComm = %d \n", count_psuComm);
+//	printf("*************************** \n");
+
+//	if (systemPage == 0x09 || systemPage == 0x0A)
+	{
+		if (count_main < _SYSTEM_TASK_COUNT_MAIN )
+		{
+			system("killall Module_EventLogging");
+			system("killall Module_PrimaryComm");
+			system("killall Module_EvComm");
+			system("killall Module_LcmControl");
+			system("killall Module_InternalComm");
+			system("killall Module_DoComm");
+//			system("killall Module_PsuComm");
+//			system("killall OcppBackend &");
+//			system("killall Module_4g &");
+//			system("killall Module_Wifi &");
+			system("killall Module_ProduceUtils &");
+			sleep(3);
+			system("/usr/bin/run_evse_restart.sh");
+		}
+		else
+		{
+			/*
+			if(system("pidof -s Module_EventLogging > /dev/null") != 0)
+				system("/root/Module_EventLogging &");
+
+			if(system("pidof -s Module_PrimaryComm > /dev/null") != 0)
+				system("/root/Module_PrimaryComm &");
+
+			if(system("pidof -s Module_LcmControl > /dev/null") != 0)
+				system("/root/Module_LcmControl &");
+
+            if(system("pidof -s Module_DoComm > /dev/null") != 0)
+                system("/root/Module_DoComm &");
+
+            if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
+                system("/root/Module_ProduceUtils &");
+
+			*/
+			if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM )
+			{
+				system("killall Module_EvComm");
+				sleep(3);
+				system("/root/Module_EvComm &");
+			}
+        	if (count_interComm < _SYSTEM_TASK_COUNT_INTERNALCOMM )
+			{
+				system("killall Module_InternalComm");
+				sleep(3);
+				system("/root/Module_InternalComm &");
+			}
+			if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING )
+			{
+				system("killall Module_EventLogging");
+				sleep(3);
+				system("/root/Module_EventLogging &");
+			}
+			if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM )
+			{
+				system("killall Module_PrimaryComm");
+				sleep(3);
+				system("/root/Module_PrimaryComm &");
+			}
+			if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM )
+			{
+				system("killall Module_LcmControl");
+				sleep(3);
+				system("/root/Module_LcmControl &");
+			}
+			if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM )
+			{
+				system("killall Module_DoComm");
+				sleep(3);
+				system("/root/Module_DoComm &");
+			}
+			if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS )
+			{
+				system("killall Module_ProduceUtils");
+				sleep(3);
+				system("/root/Module_ProduceUtils &");
+			}
+			/*
+			if (count_psuComm < 2)
+			{
+				system("killall Module_PsuComm");
+				sleep(3);
+				system("/root/Module_PsuComm &");
+			}*/
+		}
+
+		sleep(2);
+	}
+
+	if (count_main < _SYSTEM_TASK_COUNT_MAIN)
+		result = _SYSTEM_TASK_LOST_ITEM_MAIN;
+	else if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM)
+		result = _SYSTEM_TASK_LOST_ITEM_EVCOMM;
+/*	else if (count_psuComm < 2)
+		result = 3; */
+    else if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING )
+        result = _SYSTEM_TASK_LOST_ITEM_EVENTLOG;
+    else if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM)
+        result = _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM;
+    else if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM)
+        result = _SYSTEM_TASK_LOST_ITEM_LCMCONTROL;
+    else if (count_interComm < 2 )
+        result = _SYSTEM_TASK_LOST_ITEM_INTERCOMM;
+    else if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM)
+        result = _SYSTEM_TASK_LOST_ITEM_DOCOMM;
+    else if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS)
+        result = _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS;
+
+	return result;
+}

+ 60 - 0
EVSE/Projects/DD360ComBox/Apps/CSU/CheckSystemTask.h

@@ -0,0 +1,60 @@
+/*
+ * CheckTask.h
+ *
+ *  Created on: 2021年9月2日
+ *      Author: 7564
+ */
+
+#ifndef CHECKTASK_H_
+#define CHECKTASK_H_
+
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<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 	<string.h>
+#include 	<stdint.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	<stdbool.h>
+#include 	<dirent.h>
+
+#define _SYSTEM_TASK_LOST_ITEM_MAIN         1
+#define _SYSTEM_TASK_LOST_ITEM_EVCOMM       2
+#define _SYSTEM_TASK_LOST_ITEM_EVENTLOG     3
+#define _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM  4
+#define _SYSTEM_TASK_LOST_ITEM_LCMCONTROL   5
+#define _SYSTEM_TASK_LOST_ITEM_INTERCOMM    6
+#define _SYSTEM_TASK_LOST_ITEM_DOCOMM       7
+#define _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS 8
+
+#define _SYSTEM_TASK_COUNT_MAIN             5
+#define _SYSTEM_TASK_COUNT_EVCOMM           2
+#define _SYSTEM_TASK_COUNT_INTERNALCOMM     2
+#define _SYSTEM_TASK_COUNT_EVENTLOGGING     1
+#define _SYSTEM_TASK_COUNT_PRIMARYCOMM      1
+#define _SYSTEM_TASK_COUNT_LCM              1
+#define _SYSTEM_TASK_COUNT_DOCOMM           1
+#define _SYSTEM_TASK_COUNT_PRODUCEUTILS     1
+
+
+unsigned char CheckSystemTask(unsigned char systemPage);
+
+#endif /* CHECKSYSTEMTASK_H_ */

+ 11 - 5
EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c

@@ -136,11 +136,11 @@ void PrimaryLedIndicatorCtrlFork(void)
 
                 case S_CHARGING:
                     pLedConfig->RedLED = NO;
-                    if (pLedConfig->YellowLED == YES) {
-                        pLedConfig->YellowLED = NO;
-                    } else {
+                    //if (pLedConfig->YellowLED == YES) {
+                    //    pLedConfig->YellowLED = NO;
+                    //} else {
                         pLedConfig->YellowLED = YES;
-                    }
+                    //}
                     pLedConfig->GreenLED = NO;
                     break;
 
@@ -166,7 +166,13 @@ void PrimaryLedIndicatorCtrlFork(void)
                     //    pLedConfig->RedLED = YES;
                     //} else {
                     pLedConfig->RedLED = NO;
-                    pLedConfig->YellowLED = YES;
+                    //pLedConfig->YellowLED = YES;
+                    if (pLedConfig->YellowLED == YES) {
+                        pLedConfig->YellowLED = NO;
+                    } else {
+                        pLedConfig->YellowLED = YES;
+                    }
+
                     pLedConfig->GreenLED = NO;
                     //}
                     break;

+ 8 - 0
EVSE/Projects/DD360ComBox/Apps/CSU/UpgradeFW.c

@@ -12,6 +12,11 @@
 #include "../ShareMemory/shmMem.h"
 
 #include "main.h"
+//WatchDog.c
+extern void CreateWatchdog(void);
+extern void TryCloseWatchdog(void);
+extern void TryFeedWatchdog(void);
+
 
 //------------------------------------------------------------------------------
 static char *_priPortName = "/dev/ttyS1";
@@ -325,6 +330,8 @@ void CheckFwUpdateFunction(void)
     //log_info("pSysInfo->FirmwareUpdate = %d \n", pSysInfo->FirmwareUpdate);
     if (pSysInfo->FirmwareUpdate == YES) {
         log_info("ftp : update start. \n");
+        TryCloseWatchdog();
+
         for (uint8_t gun_index = 0; gun_index < pSysConfig->TotalConnectorCount; gun_index++) {
             setChargerMode(gun_index, MODE_UPDATE);
         }
@@ -352,6 +359,7 @@ void CheckFwUpdateFunction(void)
 
         if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
             log_info("Backend : update start. \n");
+            TryCloseWatchdog();
             strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
             strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
             ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;

+ 39 - 17
EVSE/Projects/DD360ComBox/Apps/CSU/WatchDog.c

@@ -8,41 +8,63 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 
-//------------------------------------------------------------------------------
-static int gWatchDogfd = -1;
+int wtdFd = -1;
+struct StatusCodeData           *ShmStatusCodeData;
 
-//------------------------------------------------------------------------------
-void WriteWatchDogState(char *value)
-{
-    write(gWatchDogfd, value, 1);
-}
+void CreateWatchdog(void);
+void TryCloseWatchdog(void);
+void TryFeedWatchdog(void);
 
-static int initWatchDog(void)
+int InitWatchDog()
 {
     int fd;
+    int timeout = 180;
+
     system("/usr/bin/fuser -k /dev/watchdog");
     sleep(1);
     system("echo V > /dev/watchdog");
     sleep(1);
-    fd = open("/dev/watchdog", O_RDWR);
+    fd=open("/dev/watchdog", O_RDWR);
 
-    if (fd <= 0) {
+    if(fd<=0)
+    {
         log_error("System watch dog initial fail.\r\n");
     }
+    ioctl(fd, _IOWR('W', 6, int), &timeout);
 
     return fd;
 }
 
 void CreateWatchdog(void)
 {
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    wtdFd = InitWatchDog();
+
+    ShmStatusCodeData = (struct StatusCodeData*)GetShmStatusCodeData();
+    if(wtdFd < 0)
+    {
+        log_info("Watchdog Initial Fail");
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+    }
+    else
+    {
+        log_info("Watchdog Initial Success");
+    }
+}
 
-    if (pSysConfig->SwitchDebugFlag == NO) {
-        gWatchDogfd = initWatchDog();
+void TryCloseWatchdog(void)
+{
+    if(wtdFd > 0)
+    {
+        write(wtdFd, "V", 1);
+        close(wtdFd);
+    }
+}
 
-        if (gWatchDogfd < 0) {
-            pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
-        }
+void TryFeedWatchdog(void)
+{
+    if(wtdFd > 0)
+    {
+        write(wtdFd, "a", 1);
     }
 }
+

+ 48 - 0
EVSE/Projects/DD360ComBox/Apps/CSU/WatchDog.c.old

@@ -0,0 +1,48 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+static int gWatchDogfd = -1;
+
+//------------------------------------------------------------------------------
+void WriteWatchDogState(char *value)
+{
+    write(gWatchDogfd, value, 1);
+}
+
+static int initWatchDog(void)
+{
+    int fd;
+    system("/usr/bin/fuser -k /dev/watchdog");
+    sleep(1);
+    system("echo V > /dev/watchdog");
+    sleep(1);
+    fd = open("/dev/watchdog", O_RDWR);
+
+    if (fd <= 0) {
+        log_error("System watch dog initial fail.\r\n");
+    }
+
+    return fd;
+}
+
+void CreateWatchdog(void)
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    if (pSysConfig->SwitchDebugFlag == NO) {
+        gWatchDogfd = initWatchDog();
+
+        if (gWatchDogfd < 0) {
+            pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
+        }
+    }
+}

+ 114 - 9
EVSE/Projects/DD360ComBox/Apps/CSU/main.c

@@ -29,6 +29,7 @@
 #include <math.h>
 #include <stdbool.h>
 #include <dirent.h>
+#include <signal.h>
 
 #include "../Config.h"
 #include "main.h"
@@ -40,6 +41,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../SelectGun/SelectGun.h"
+#include "CheckSystemTask.h"
 
 //------------------------------------------------------------------------------
 static struct SysInfoData *pSysInfo = NULL;
@@ -71,13 +73,16 @@ static SelectGunInfo *ShmSelectGunInfo = NULL; //Jerry add
 static EvBoardErrMsg gEvBoardErr = {0};
 static ChillerTempErr gChillerTempErr = {0};
 
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+
 // for initial index to check EV board type is correct
 uint8_t bd0_1_status = 0;
 uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V1.14.00.0000.00"; // "V0.16.00.0000.00";
+char *fwVersion = "V1.15.00.0000.00"; // "V0.16.00.0000.00";
 
 //sqlite3 *localDb;
 bool isDb_ready;
@@ -123,7 +128,8 @@ extern void GetMacAddress(void);
 
 //WatchDog.c
 extern void CreateWatchdog(void);
-extern void WriteWatchDogState(char *value);
+extern void TryCloseWatchdog(void);
+extern void TryFeedWatchdog(void);
 
 //ZipFile.c
 extern void zipLogFiles(void);
@@ -1631,7 +1637,11 @@ void _DetectPlugInTimeout(void)
     ClearDetectPluginFlag();
 
     sleep(1); //等待DoComm回報插槍訊號給主櫃
-
+#if defined DD360Audi || DD360 || DD360Combox
+	    //pSysInfo->SystemPage = _LCM_COMPLETE;
+		setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
+	    return;
+#endif
     systemPageRestoreInit();
 }
 
@@ -1661,7 +1671,12 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
     log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
     //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
     {
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
         setChargerMode(gunIndex, MODE_IDLE);
+#endif
         _AutoReturnTimeout();
     }
 }
@@ -1669,7 +1684,12 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
 void _PrepareTimeout(uint8_t gunIndex)
 {
     log_info("*********** _PrepareTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
+     setChargerMode(gunIndex, MODE_IDLE);
+#endif
     pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
     _AutoReturnTimeout();
 }
@@ -1677,9 +1697,76 @@ void _PrepareTimeout(uint8_t gunIndex)
 void _CcsPrechargeTimeout(uint8_t gunIndex)
 {
     log_info("*********** _CcsPrechargeTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
+#if defined DD360Audi || DD360 || DD360Combox
+        pSysInfo->SystemPage = _LCM_COMPLETE;
+        setChargerMode(gunIndex, S_TERMINATING);
+#else
+     setChargerMode(gunIndex, MODE_IDLE);
+#endif
 }
 
+//===============================================
+// Check System Task alive
+// ==============================================
+void CheckSystemTaskAlive()
+{
+    unsigned char lostId = CheckSystemTask(ShmSysConfigAndInfo->SysInfo.SystemPage);
+    if (lostId != 0) {
+        log_info("Check task(%d) lost\n",lostId);
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost == NO) {
+           if (lostId == _SYSTEM_TASK_LOST_ITEM_MAIN)
+               log_info("System task lost (CSU). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVCOMM)
+               log_info("System task lost (EVComm). \n");
+//           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PSUCOMM)
+//               PRINTF_FUNC("System task lost (PSU Task). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVENTLOG)
+               log_info("System task lost (Event log). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM)
+               log_info("System task lost (Primary). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_LCMCONTROL)
+               log_info("System task lost (LCM Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_INTERCOMM)
+               log_info("System task lost (Internal Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_DOCOMM)
+               log_info("System task lost (Do Comm). \n");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS)
+               log_info("System task lost (ProcductUtils Comm). \n");
+           ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = YES;
+        }
+    } else
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = NO;
+}
+
+void CreateCheckSystemTaskFork()
+{
+    pid_t taskPid;
+    taskPid = fork();
+    if (taskPid == 0)
+    {
+        while(true)
+        {
+			/*
+			for (int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo[_index]->SystemStatus == SYS_MODE_UPDATE ||
+						chargingInfo[_index]->Type == 0x09)
+				{
+					stopToDet = true;
+					continue;
+				}
+			}
+			*/
+			for (uint8_t gun = 0; gun < pSysConfig->TotalConnectorCount; gun++) {
+				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
+				if (pDcChargingInfo->SystemStatus == SYS_MODE_UPDATE )
+						continue;
+			}
+			CheckSystemTaskAlive();
+			sleep(5);
+		}
+	}
+}
 //===============================================
 // 取得卡號與卡號驗證
 //===============================================
@@ -2530,6 +2617,7 @@ bool CheckConnectorTypeStatus(void)
             return false;
         }
 
+		pDcChargingInfo->SystemStatus = S_BOOTING;
         switch (gunIndex) {
         case 0:
             if (pSysConfig->TotalConnectorCount == 1) {
@@ -2970,6 +3058,7 @@ void CheckOcppStatus(void)
                 sleep(3);
                 system("killall OcppBackend &");
                 KillAllTask();
+                TryCloseWatchdog();
                 system("/usr/bin/run_evse_restart.sh");
             }
         }
@@ -3349,6 +3438,7 @@ void StopProcessingLoop()
                 log_info("Soft reboot for retry self-tets (Primary). \n");
                 KillAllTask();
                 sleep(3);
+                TryCloseWatchdog();
                 system("/usr/bin/run_evse_restart.sh");
                 return;
             }
@@ -3420,10 +3510,11 @@ void CheckTask()
 #endif //0
 
     /*--- 20200908, vern, disable it for DD360 ---*/
+    /*
     if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
         log_error("Module_ProduceUtils not running, restart it.\r\n");
         system ("/root/Module_ProduceUtils &");
-    }
+    }*/
 }
 
 //==========================================
@@ -4159,6 +4250,9 @@ int main(void)
     ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
     ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
     ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+	
+    ShmSysConfigAndInfo = (struct SysConfigAndInfo *)GetShmSysConfigAndInfo();
+    ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();	
 
     log_info(" ****************  FileSystem Boot up ***************\n");
     if (!InitialSystemDefaultConfig()) {
@@ -4256,8 +4350,6 @@ int main(void)
     // 1. Thernal - 控制風扇轉速
     // 2. ouput fuse - 控制風扇轉速
     CreateRfidFork();
-    // Create Watchdog
-    //CreateWatchdog();
     // Main loop
 
     log_info("===== Charger info ===== ");
@@ -4269,6 +4361,12 @@ int main(void)
 
     GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
+    //signal(SIGCHLD,SIG_IGN);
+
+	CreateCheckSystemTaskFork();
+
+    CreateWatchdog();
+
     for (;;) {
         CheckOcppStatus();
 
@@ -4303,7 +4401,7 @@ int main(void)
         }
 
         if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
-            CheckTask();
+            //CheckTask();
 
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
@@ -4565,6 +4663,9 @@ int main(void)
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
                 }
+#ifdef DD360Audi
+				pDcChargingInfo->Replug_flag = true;
+#endif
             }
             break;
 
@@ -4842,6 +4943,9 @@ int main(void)
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_CHARGING;
                 }
+#ifdef DD360Audi
+				pDcChargingInfo->Replug_flag = false;
+#endif
                 break;
 
             case S_ALARM:
@@ -5071,6 +5175,7 @@ int main(void)
                 }
                 break;
             }//switch
+            TryFeedWatchdog();
         }//for
 
 #if defined DD360Audi

+ 1 - 0
EVSE/Projects/DD360ComBox/Apps/Define/define.h

@@ -637,6 +637,7 @@ struct ChargingInfoData
     float               CurrentOffered;                 //0~6553.5 amp
     struct timespec     ConnectorTimeout;
     unsigned char       PantographFlag;                 // 0: normal gun type,  1: pantograph gun type
+	unsigned char 		Replug_flag;
 };
 
 typedef union

+ 4 - 2
EVSE/Projects/DD360ComBox/Apps/Makefile

@@ -70,7 +70,8 @@ COMMON_OBJ_FILES = common.o \
 MAIN_OBJ_FILES = $(COMMON_OBJ_FILES) $(DataBaseLib)/DataBase.o \
 					$(CSULib)/main.o  $(CSULib)/Primary.o $(CSULib)/WatchDog.o $(CSULib)/ZipFile.o \
 					$(CSULib)/RFID.o $(CSULib)/SelfTest.o $(CSULib)/UpgradeFW.o \
-					$(CSULib)/Ethernet.o
+					$(CSULib)/Ethernet.o $(CSULib)/CheckSystemTask.o
+					
 MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
@@ -129,7 +130,8 @@ apps: MainTask DoCommTask EvCommTask \
 
 MainTask:
 	$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
-		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) -o main
+		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) \
+		$(CheckSystemTask_H) -o main
 	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
 	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c

+ 14 - 7
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c

@@ -1987,7 +1987,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;
@@ -2021,7 +2022,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2053,7 +2055,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2062,7 +2065,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CCS_PRECHARGE_ST0:
     case S_CCS_PRECHARGE_ST1:
         writeChargingTarget(fd, plugNum, gunID);
-        writeGroundFaultDetection(fd, 1, gunID);
+		if (pDcChargingInfo->PantographFlag)
+			writeGroundFaultDetection(fd, 1, gunID);
 
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2098,11 +2102,13 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_TERMINATING:
         if(pDcChargingInfo->Type == _Type_GB || pDcChargingInfo->Type == _Type_Chademo)
         {
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
         }
         else
         {
-            writeGroundFaultDetection(fd, 1, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 1, gunID);
         }
 
         ftime(&AuthNowTime);
@@ -2143,7 +2149,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
-            writeGroundFaultDetection(fd, 0, gunID);
+			if (pDcChargingInfo->PantographFlag)
+				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;

+ 4 - 2
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalState.c

@@ -27,8 +27,10 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
     //iflog_info("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
 
     if (strncmp(string, "000000", 6) == EQUAL ||
-            strncmp(string, "012219", 6) == EQUAL
-       ) {
+            strncmp(string, "012219", 6) == EQUAL ||
+            strncmp(string, "023979", 6) == EQUAL )
+    {
+		log_info("NOTIFICATION_EV_STOP : EvCode = %s\n", string);
         return false;
     }
 

+ 3 - 0
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -15,6 +15,7 @@
 
 #include <linux/can.h>
 #include <linux/can/raw.h>
+#include <signal.h>
 
 #include "../Config.h"
 #include "../Log/log.h"
@@ -713,6 +714,8 @@ int main(int argc, char *argv[])
 
     FormatVoltageAndCurrent();
 
+    signal(SIGCHLD,SIG_IGN);
+    
     CANReceiver(CanFd);
 
     rtc = GetRtcInfoForEpoch();

+ 39 - 0
EVSE/Projects/DD360ComBox/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -223,6 +223,11 @@ uint8_t _right_gun_disable_map  = 68;
 uint8_t _right_gun_enable_map   = 69;
 uint8_t _select_gun_btn         = 70;
 uint8_t _emergency_disable_map  = 72;
+// For replug
+struct timespec showReplugStrTimer;
+short __show_replugString_value = 0x0460;
+uint8_t _showReplugStr_1 = 74;
+uint8_t _showReplugStr_2 = 75;
 
 //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
@@ -853,6 +858,31 @@ bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acCharging
 
     return false;
 }
+int GetTimeoutValue(struct timespec *startTime)
+{
+    struct timespec endTime;
+    clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+    return endTime.tv_sec - startTime->tv_sec;
+}
+void GetTimespecFunc(struct timespec *time)
+{
+    clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
+
+void RunReplugStringFunction(bool isRun)
+{
+    if (isRun) {
+        int time = GetTimeoutValue(&showReplugStrTimer);
+        if (time >=1 && time <2) {
+            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_1);
+        } else if (time < 1) {
+            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_2);
+        } else
+            GetTimespecFunc(&showReplugStrTimer);
+
+    } else
+        ChangeDisplay2Value(__show_replugString_value, _disappear);
+}
 
 /**
  * [ChangeBalanceValue :print balance information]
@@ -2041,6 +2071,15 @@ void ProcessPageInfo()
                     } else {
                         ChangeDisplay2Value(__charging_fee_map, _money_map);
                     }
+#ifdef DD360Audi
+                    // Warming Occur in prepare or precharing state, turn into complete mode
+                    if (pDcChargingInfo->Replug_flag) {
+                        RunReplugStringFunction(true);
+                    } else {
+                        RunReplugStringFunction(false);
+                    }
+#else
+#endif					
                 }
             }
         }

+ 46 - 5
EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -48,6 +48,11 @@ static struct PrimaryMcuData *ShmPrimaryMcuData;
 const char *priPortName = "/dev/ttyS1";
 uint8_t gun_count; //DS60-120 add
 
+uint8_t EmgBtn_count = 0;
+uint8_t Door_count = 0;
+uint8_t EmgBtn_flag = 0;
+uint8_t Door_flag = 0;
+
 //struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 //------------------------------------------------------------------------------
@@ -182,11 +187,26 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
 
 #if defined DD360ComBox
-    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
+    if (~gpio_in.Emergency_Btn)
 #else
-    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+    if (gpio_in.Emergency_Btn && (EmgBtn_flag != gpio_in.Emergency_Btn))
 #endif //defined DD360ComBox
-
+    {
+            EmgBtn_count++;
+        if (EmgBtn_count > SensorTrigCount) {
+           EmgBtn_flag = 1;
+           EmgBtn_count = 0; // Avoid Overflow
+       }
+    } else if (EmgBtn_flag != gpio_in.Emergency_Btn) {
+        EmgBtn_count++;
+        if (EmgBtn_count > SensorTrigCount) {
+            EmgBtn_flag = 0;
+            EmgBtn_count = 0;
+        }
+    }
+ 
+    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = EmgBtn_flag;
+ 
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
@@ -219,10 +239,31 @@ void GetInputGpioStatus(int fd)
     }
 
 #if defined DD360ComBox
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
+    if (gpio_in.Door_Open)
 #else
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
+    if (gpio_in.Door_Open == 0 && (Door_flag == gpio_in.Door_Open))
 #endif //defined DD360ComBox
+    {
+        Door_count++;
+        if (Door_count > SensorTrigCount) {
+            Door_flag = 1;
+            Door_count = 0; // Avoid Overflow
+       }
+    } else if (gpio_in.Door_Open && Door_flag) {
+        Door_count++;
+        if (Door_count > SensorTrigCount) {
+            Door_flag = 0;
+            Door_count = 0;
+        }
+    }
+ 
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = Door_flag;
+/*
+    log_info("Emergency Button Count = %d , Emergency flag = %d\n",
+            EmgBtn_count,EmgBtn_flag);
+    log_info("Door Sensor Count = %d , Door Sensor flag = %d\n",
+            Door_count,Door_flag);
+*/
 
     ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
     ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;

+ 1 - 0
EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -30,5 +30,6 @@ typedef struct StLedConfig {
 
 //------------------------------------------------------------------------------
 //int StoreLogMsg(const char *fmt, ...);
+#define SensorTrigCount 3
 
 #endif /* _MODULE_PRIMARY_COMM_H_ */

+ 4 - 0
EVSE/Projects/DD360ComBox/Apps/Script/kill.sh

@@ -12,6 +12,10 @@ pkill Module_ProduceUtils;
 pkill Module_DoComm;
 pkill main;
 
+sleep 1
+
+echo V > /dev/watchdog
+
 ipcrm -M 0x000003e9;
 ipcrm -M 0x000003ed;
 ipcrm -M 0x000003ea;

+ 31 - 17
EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.c

@@ -833,7 +833,7 @@ static int findDcChargingInfoData(uint8_t gunIndex)
     return FAIL;
 }
 
-static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
+static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichtask)
 {
     bool result = true;
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -862,11 +862,14 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pAcChargingInfo->ReservationId = -1;
             pAcChargingInfo->SystemStatus = S_IDLE;
             pAcChargingInfo->Type = _Type_AC;
-            pAcChargingInfo->IsAvailable = YES;
             pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add
             pAcChargingInfo->schedule.isTriggerStop = NO;  //DS60-120 add
-            gGunIndexInfo.AcIndex++;
-            gGunIndexInfo.AcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                gGunIndexInfo.AcIndex++;
+                gGunIndexInfo.AcGunIndex++;
+                pAcChargingInfo->IsAvailable = YES;
+            }
         } else {
             result = false;
         }
@@ -886,13 +889,17 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
+			//pDcChargingInfo->SystemStatus = S_IDLE;
             pDcChargingInfo->Type = _Type_Chademo;
             pDcChargingInfo->type_index = gGunIndexInfo.ChademoIndex;
-            pDcChargingInfo->IsAvailable = YES;
             setAcGunTiggerStatus();
-            gGunIndexInfo.ChademoIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.ChademoIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
         } else {
             result = false;
         }
@@ -914,15 +921,19 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
             pDcChargingInfo->Type = _Type_CCS_2;
             pDcChargingInfo->type_index = gGunIndexInfo.CcsIndex;
-            pDcChargingInfo->IsAvailable = YES;
+
             setAcGunTiggerStatus();
             // 現階段預設為走 DIN70121
             pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
-            gGunIndexInfo.CcsIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.CcsIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
             if(typeValue == 'P')
             {
                 pDcChargingInfo->PantographFlag = YES;
@@ -939,13 +950,16 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
             pDcChargingInfo->ReservationId = -1;
             pDcChargingInfo->slotsIndex = slots;
-            pDcChargingInfo->SystemStatus = S_BOOTING;
+            //pDcChargingInfo->SystemStatus = S_BOOTING;
             pDcChargingInfo->Type = _Type_GB;
             pDcChargingInfo->type_index = gGunIndexInfo.GbIndex;
-            pDcChargingInfo->IsAvailable = YES;
             setAcGunTiggerStatus();
-            gGunIndexInfo.GbIndex++;
-            gGunIndexInfo.DcGunIndex++;
+            //if( strcmp(whichtask,"CSU task") == EQUAL ) 
+            {
+                pDcChargingInfo->IsAvailable = YES;
+                gGunIndexInfo.GbIndex++;
+                gGunIndexInfo.DcGunIndex++;
+            }
         } else {
             result = false;
         }
@@ -988,7 +1002,7 @@ bool MappingGunChargingInfo(char *whichTask)
 
     //printf("1 CheckConnectorTypeStatus\r\n");
     for (typeIndex = 7; typeIndex <= 9; typeIndex++) {
-        if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots)) {
+        if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots, whichTask)) {
             log_error("%s add gun info failed\r\n", whichTask);
             return false;
         }

BIN
EVSE/Projects/DD360ComBox/Apps/UnsafetyOutputTask


+ 1 - 4
EVSE/Projects/define.h

@@ -637,6 +637,7 @@ struct ChargingInfoData
     float               CurrentOffered;                 //0~6553.5 amp
     struct timespec     ConnectorTimeout;
     unsigned char       PantographFlag;                 // 0: normal gun type,  1: pantograph gun type
+	unsigned char 		Replug_flag;
 };
 
 typedef union
@@ -6051,7 +6052,3 @@ struct OCPP20Data
 };
 
 #endif // DEFINE_H_
-
-
-
-