123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #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_psuComm = GetProcessCount("Module_PsuComm");
- if (systemPage == 0x09 || systemPage == 0x0A)
- {
- if (count_main < 5 || count_psuComm < 2)
- {
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- system("killall Module_PsuComm");
- system("killall OcppBackend &");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- system("killall Module_DcMeter &");
- 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_InternalComm > /dev/null") != 0)
- system("/root/Module_InternalComm &");
- if (count_evComm < 2)
- {
- system("killall Module_EvComm");
- sleep(3);
- system("/root/Module_EvComm &");
- }
- }
- sleep(2);
- }
- if (count_main < 5)
- result = 1;
- else if (count_evComm < 2)
- result = 2;
- else if (count_psuComm < 2)
- result = 3;
- else if (system("pidof -s Module_EventLogging > /dev/null") != 0)
- result = 4;
- else if (system("pidof -s Module_PrimaryComm > /dev/null") != 0)
- result = 5;
- else if (system("pidof -s Module_LcmControl > /dev/null") != 0)
- result = 6;
- else if (system("pidof -s Module_InternalComm > /dev/null") != 0)
- result = 7;
- return result;
- }
|