SelfTest.c 9.9 KB

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