CheckSystemTask.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * CheckTask.c
  3. *
  4. * Created on: 2021年9月22日
  5. * Author: 8513
  6. */
  7. #include "CheckSystemTask.h"
  8. bool Taskconutstring(char *src, char *taskname)
  9. {
  10. bool result = false;
  11. if (src == NULL || strlen(src) == 0)
  12. return result;
  13. if (strstr(src, taskname) != NULL &&
  14. strstr(src, "grep") == NULL &&
  15. strstr(src, "[") == NULL)
  16. {
  17. result = true;
  18. }
  19. return result;
  20. }
  21. int GetProcessCount(char *procName)
  22. {
  23. int result = 0;
  24. FILE *fp;
  25. char cmd[256];
  26. char buf[256];
  27. sprintf(cmd, "ps -ef |grep %s", procName);
  28. fp = popen(cmd, "r");
  29. if(fp != NULL)
  30. {
  31. while(fgets(buf, sizeof(buf), fp) != NULL)
  32. {
  33. if (Taskconutstring(buf, procName))
  34. result++;
  35. }
  36. }
  37. pclose(fp);
  38. return result;
  39. }
  40. unsigned char CheckSystemTask(unsigned char systemPage)
  41. {
  42. unsigned char result = 0;
  43. unsigned char count_main = GetProcessCount("main");
  44. unsigned char count_evComm = GetProcessCount("Module_EvComm");
  45. unsigned char count_interComm = GetProcessCount("Module_InternalComm");
  46. unsigned char count_eventComm = GetProcessCount("Module_EventLogging");
  47. unsigned char count_primaryComm = GetProcessCount("Module_PrimaryComm");
  48. unsigned char count_lcmComm = GetProcessCount("Module_LcmControl");
  49. unsigned char count_doComm = GetProcessCount("Module_DoComm");
  50. unsigned char count_produceComm = GetProcessCount("Module_ProduceUtils");
  51. // unsigned char count_psuComm = GetProcessCount("Module_PsuComm");
  52. // printf("*************************** \n");
  53. // printf("count_main = %d \n", count_main);
  54. // printf("count_eventLog = %d \n", count_eventLog);
  55. // printf("count_primary = %d \n", count_primary);
  56. // printf("count_evComm = %d \n", count_evComm);
  57. // printf("count_lcmCtrl = %d \n", count_lcmCtrl);
  58. // printf("count_interComm = %d \n", count_interComm);
  59. // printf("count_psuComm = %d \n", count_psuComm);
  60. // printf("*************************** \n");
  61. // if (systemPage == 0x09 || systemPage == 0x0A)
  62. {
  63. if (count_main < _SYSTEM_TASK_COUNT_MAIN )
  64. {
  65. system("killall Module_EventLogging");
  66. system("killall Module_PrimaryComm");
  67. system("killall Module_EvComm");
  68. system("killall Module_LcmControl");
  69. system("killall Module_InternalComm");
  70. system("killall Module_DoComm");
  71. // system("killall Module_PsuComm");
  72. // system("killall OcppBackend &");
  73. // system("killall Module_4g &");
  74. // system("killall Module_Wifi &");
  75. system("killall Module_ProduceUtils &");
  76. sleep(3);
  77. system("/usr/bin/run_evse_restart.sh");
  78. }
  79. else
  80. {
  81. /*
  82. if(system("pidof -s Module_EventLogging > /dev/null") != 0)
  83. system("/root/Module_EventLogging &");
  84. if(system("pidof -s Module_PrimaryComm > /dev/null") != 0)
  85. system("/root/Module_PrimaryComm &");
  86. if(system("pidof -s Module_LcmControl > /dev/null") != 0)
  87. system("/root/Module_LcmControl &");
  88. if(system("pidof -s Module_DoComm > /dev/null") != 0)
  89. system("/root/Module_DoComm &");
  90. if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
  91. system("/root/Module_ProduceUtils &");
  92. */
  93. if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM )
  94. {
  95. system("killall Module_EvComm");
  96. sleep(3);
  97. system("/root/Module_EvComm &");
  98. }
  99. if (count_interComm < _SYSTEM_TASK_COUNT_INTERNALCOMM )
  100. {
  101. system("killall Module_InternalComm");
  102. sleep(3);
  103. system("/root/Module_InternalComm &");
  104. }
  105. if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING )
  106. {
  107. system("killall Module_EventLogging");
  108. sleep(3);
  109. system("/root/Module_EventLogging &");
  110. }
  111. if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM )
  112. {
  113. system("killall Module_PrimaryComm");
  114. sleep(3);
  115. system("/root/Module_PrimaryComm &");
  116. }
  117. if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM )
  118. {
  119. system("killall Module_LcmControl");
  120. sleep(3);
  121. system("/root/Module_LcmControl &");
  122. }
  123. if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM )
  124. {
  125. system("killall Module_DoComm");
  126. sleep(3);
  127. system("/root/Module_DoComm &");
  128. }
  129. if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS )
  130. {
  131. system("killall Module_ProduceUtils");
  132. sleep(3);
  133. system("/root/Module_ProduceUtils &");
  134. }
  135. /*
  136. if (count_psuComm < 2)
  137. {
  138. system("killall Module_PsuComm");
  139. sleep(3);
  140. system("/root/Module_PsuComm &");
  141. }*/
  142. }
  143. sleep(2);
  144. }
  145. if (count_main < _SYSTEM_TASK_COUNT_MAIN)
  146. result = _SYSTEM_TASK_LOST_ITEM_MAIN;
  147. else if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM)
  148. result = _SYSTEM_TASK_LOST_ITEM_EVCOMM;
  149. /* else if (count_psuComm < 2)
  150. result = 3; */
  151. else if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING )
  152. result = _SYSTEM_TASK_LOST_ITEM_EVENTLOG;
  153. else if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM)
  154. result = _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM;
  155. else if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM)
  156. result = _SYSTEM_TASK_LOST_ITEM_LCMCONTROL;
  157. else if (count_interComm < 2 )
  158. result = _SYSTEM_TASK_LOST_ITEM_INTERCOMM;
  159. else if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM)
  160. result = _SYSTEM_TASK_LOST_ITEM_DOCOMM;
  161. else if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS)
  162. result = _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS;
  163. return result;
  164. }