SelfTest.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include "../Config.h"
  6. #include "../Log/log.h"
  7. #include "../Define/define.h"
  8. #include "../ShareMemory/shmMem.h"
  9. #include "main.h"
  10. #include "../timeout.h"
  11. //------------------------------------------------------------------------------
  12. extern void ChkPrimaryStatus(void);
  13. //------------------------------------------------------------------------------
  14. void SelfTestRun(void)
  15. {
  16. bool evInitFlag = false;
  17. uint8_t index = 0;
  18. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  19. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  20. struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  21. struct PsuData *ShmPsuData = (struct PsuData *)GetShmPsuData();
  22. struct CHAdeMOData *ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  23. struct GBTData *ShmGBTData = (struct GBTData *)GetShmGBTData();
  24. struct CcsData *ShmCcsData = (struct CcsData *)GetShmCcsData();
  25. struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  26. struct FanModuleData *ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  27. struct RelayModuleData *ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  28. struct ChargingInfoData *pDcChargingInfo = NULL;
  29. struct ChargingInfoData *pAcChargingInfo = NULL;
  30. StartSystemTimeoutDet(Timeout_SelftestChk);
  31. pSysInfo->SelfTestSeq = _STEST_VERSION;
  32. while (pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
  33. if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) { //自檢完成
  34. return;
  35. }
  36. ChkPrimaryStatus(); //確認硬體有無錯誤,如急停按鈕或門有打開
  37. if (pSysWarning->Level == WARN_LV_ER) {
  38. pSysInfo->SelfTestSeq = _STEST_FAIL;
  39. return;
  40. }
  41. if (pSysConfig->TotalConnectorCount <= 0) {
  42. pSysInfo->SelfTestSeq = _STEST_FAIL;
  43. return;
  44. }
  45. if (ShmPsuData->Work_Step == _NO_WORKING ||
  46. pSysInfo->SelfTestSeq == _STEST_FAIL) {
  47. pSysInfo->SelfTestSeq = _STEST_FAIL;
  48. return;
  49. }
  50. switch (pSysInfo->SelfTestSeq) {
  51. case _STEST_VERSION:
  52. if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
  53. pSysInfo->RelayModuleFwRev[0] != '\0') &&
  54. (ShmRelayModuleData->SelfTest_Comp != YES)
  55. ) {
  56. log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
  57. ShmRelayModuleData->SelfTest_Comp = YES;
  58. }
  59. #if !defined NO_FAN_BOARD && !defined DD360ComBox
  60. if ((strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
  61. pSysInfo->FanModuleFwRev[0] != '\0') &&
  62. (ShmFanModuleData->SelfTest_Comp != YES)
  63. ) {
  64. log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
  65. ShmFanModuleData->SelfTest_Comp = YES;
  66. }
  67. #else
  68. ShmFanModuleData->SelfTest_Comp = YES;
  69. #endif //NO_FAN_BOARD
  70. if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
  71. ShmPrimaryMcuData->version[0] != '\0') &&
  72. (ShmPrimaryMcuData->SelfTest_Comp != YES)
  73. ) {
  74. log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
  75. ShmPrimaryMcuData->SelfTest_Comp = YES;
  76. }
  77. // EV 小板
  78. if (!evInitFlag) {
  79. evInitFlag = YES;
  80. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  81. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  82. //log_info("index = %d, charging index = %d, type = %d\r\n",
  83. // index,
  84. // chargingInfo[index]->type_index,
  85. // chargingInfo[index]->Type);
  86. if (pDcChargingInfo->Type == _Type_Chademo) {
  87. if ((strlen((char *)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version) != 0 ||
  88. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version[0] != '\0')
  89. //&& (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
  90. ) {
  91. log_info("CHAdeMO[%d] FW Rev = %s",
  92. pDcChargingInfo->type_index,
  93. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
  94. ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
  95. } else {
  96. //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
  97. evInitFlag = NO;
  98. }
  99. } else if (pDcChargingInfo->Type == _Type_GB) {
  100. if ((strlen((char *)ShmGBTData->evse[pDcChargingInfo->type_index].version) != 0 ||
  101. ShmGBTData->evse[pDcChargingInfo->type_index].version[0] != '\0')
  102. //&& (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
  103. ) {
  104. log_info("GBT[%d] FW Rev = %s",
  105. pDcChargingInfo->type_index,
  106. ShmGBTData->evse[pDcChargingInfo->type_index].version);
  107. ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
  108. } else {
  109. //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
  110. evInitFlag = NO;
  111. }
  112. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  113. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  114. if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version) != 0 ||
  115. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
  116. /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
  117. ) {
  118. log_info("CCS[%d] FW Rev = %s",
  119. pDcChargingInfo->type_index,
  120. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
  121. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
  122. } else {
  123. //log_info("CCS[%d] ccs fw lose...... %s \n",
  124. // chargingInfo[index]->type_index,
  125. // ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
  126. evInitFlag = NO;
  127. }
  128. }
  129. }
  130. }
  131. for (index = 0; index < pSysConfig->AcConnectorCount; index++) {
  132. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
  133. if (pAcChargingInfo->Type == _Type_AC) {
  134. if ((strlen((char *)pAcChargingInfo->version) != 0 ||
  135. pAcChargingInfo->version[0] != '\0')
  136. && (pAcChargingInfo->SelfTest_Comp != YES)
  137. ) {
  138. log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
  139. pAcChargingInfo->SelfTest_Comp = YES;
  140. } else {
  141. evInitFlag = NO;
  142. }
  143. }
  144. }
  145. }
  146. if (ShmFanModuleData->SelfTest_Comp &&
  147. ShmRelayModuleData->SelfTest_Comp &&
  148. ShmPrimaryMcuData->SelfTest_Comp &&
  149. evInitFlag
  150. ) {
  151. pSysInfo->SelfTestSeq = _STEST_AC_CONTACTOR;
  152. }
  153. break;
  154. case _STEST_AC_CONTACTOR:
  155. //ShmPsuData->Work_Step = _TEST_COMPLETE;
  156. // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
  157. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  158. pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
  159. log_info("Waiting for DO communication");
  160. break;
  161. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  162. if (pSysInfo->AcContactorStatus == YES) {
  163. pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
  164. log_info("AC contactor self test OK");
  165. }
  166. break;
  167. case _STEST_PSU_DETECT:
  168. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  169. pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
  170. break;
  171. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  172. if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
  173. pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
  174. }
  175. break;
  176. case _STEST_PSU_CAP:
  177. // 此測試是要確認當前總輸出能力
  178. // 如果沒有 PSU 模組請 bypass
  179. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  180. //check the power limit from DO
  181. pSysInfo->SelfTestSeq = _STEST_COMPLETE;
  182. pSysInfo->BootingStatus = BOOT_COMPLETE;
  183. log_info("Successful Self Test");
  184. break;
  185. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  186. if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
  187. sleep(1);
  188. pSysInfo->SelfTestSeq = _STEST_COMPLETE;
  189. pSysInfo->BootingStatus = BOOT_COMPLETE;
  190. }
  191. break;
  192. }
  193. usleep(100000);
  194. }
  195. }