RelayBoard.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include "../ShareMemory/shmMem.h"
  10. #include "../Config.h"
  11. #include "../Log/log.h"
  12. #include "Module_InternalComm.h"
  13. #include "internalComm.h"
  14. //------------------------------------------------------------------------------
  15. static struct SysConfigData *pSysConfig = NULL;
  16. static struct SysInfoData *pSysInfo = NULL;
  17. static struct AlarmCodeData *pAlarmCode = NULL;
  18. static struct RelayModuleData *ShmRelayModuleData = NULL;
  19. static struct PsuData *ShmPsuData = NULL;
  20. static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
  21. static DcCommonInfo *ShmDcCommonData = NULL;
  22. static Relay outputRelay = {0};
  23. static Relay regRelay = {0};
  24. static int Uart5Fd = 0;
  25. //static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  26. //static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  27. //static bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  28. //static struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  29. static bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
  30. static struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
  31. static struct timeval _close_ac_contactor;
  32. //------------------------------------------------------------------------------
  33. static void RunForceStopProcess(void)
  34. {
  35. static bool isCriticalStop = NO;
  36. static struct timeval _psuCriticalStop;
  37. uint32_t _timebuf;
  38. if (isCriticalStop == NO) {
  39. isCriticalStop = YES;
  40. gettimeofday(&_psuCriticalStop, NULL);
  41. } else {
  42. _timebuf = GetTimeoutValue(_psuCriticalStop);
  43. if (_timebuf < 0) {
  44. gettimeofday(&_psuCriticalStop, NULL);
  45. } else {
  46. if (_timebuf / 1000 >= (FORCE_STOP_TIME * 1000)) {
  47. isCriticalStop = NO;
  48. pAlarmCode->AlarmEvents.bits.PsuFailureAlarm = NORMAL;
  49. }
  50. }
  51. }
  52. }
  53. static void StopCheckRelayInfo(uint8_t _chkIndex)
  54. {
  55. if (ShmDcCommonData->CheckRelayStatus[_chkIndex] != STOP) {
  56. ShmDcCommonData->CheckRelayStatus[_chkIndex] = STOP;
  57. }
  58. }
  59. static void StartCheckRelayInfo(uint8_t _chkIndex, uint8_t toState)
  60. {
  61. // SMR1 *2 + SMR2 * 2 + Parallel * 2
  62. static time_t lastCheckRelayStateTimer[6] = {0};
  63. time_t nowTime = {0};
  64. //uint8_t *pCheckRelayState = (uint8_t *)ShmDcCommonData->CheckRelayStatus[_chkIndex];
  65. if (ShmDcCommonData->CheckRelayStatus[_chkIndex] == STOP) {
  66. time(&lastCheckRelayStateTimer[_chkIndex]);
  67. ShmDcCommonData->CheckRelayStatus[_chkIndex] = START;
  68. } else {
  69. time(&nowTime);
  70. if (nowTime - lastCheckRelayStateTimer[_chkIndex] >= 1) {
  71. //log_info("relay welding or driving fault = %d \n", _chkIndex);
  72. if (toState == 1) {
  73. ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
  74. } else {
  75. ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
  76. }
  77. lastCheckRelayStateTimer[_chkIndex] = nowTime;
  78. }
  79. }
  80. }
  81. static uint8_t getCommTargetID(uint8_t index)
  82. {
  83. uint8_t targetID = 0;
  84. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  85. if (pSysConfig->TotalConnectorCount == 1) {
  86. if (strncmp((char *)&pSysConfig->ModelName[7], "0", 1) != 0) {
  87. targetID = 0x01;
  88. } else if (strncmp((char *)&pSysConfig->ModelName[9], "0", 1) != 0) {
  89. targetID = 0x02;
  90. }
  91. } else {
  92. targetID = pDcChargingInfo->Evboard_id;
  93. }
  94. return targetID;
  95. }
  96. /*static void MatchRelayStatus(void)
  97. {
  98. // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
  99. //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
  100. //pSysInfo->AcContactorStatus =
  101. // regRelay.relay_event.bits.AC_Contactor =
  102. // outputRelay.relay_event.bits.AC_Contactor;
  103. regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  104. regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  105. regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  106. regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  107. regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  108. regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  109. regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  110. }
  111. */
  112. static bool IsNoneMatchRelayStatus(void)
  113. {
  114. bool result = false;
  115. if (
  116. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  117. (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
  118. (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
  119. #endif //!defined DD360 && !defined DD360Audi
  120. (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
  121. (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
  122. (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
  123. (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N)
  124. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  125. ||
  126. (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) ||
  127. (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N)
  128. #endif //!defined DD360 && !defined DD360Audi
  129. ) {
  130. result = true;
  131. }
  132. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  133. if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
  134. log_info("AC Contact Relay none match. \n");
  135. }
  136. if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
  137. log_info("CCS Precharge Relay none match. \n");
  138. }
  139. #endif //
  140. if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
  141. //log_info("SMR1:D+ Relay none match. \n");
  142. StartCheckRelayInfo(RELAY_SMR1_P_STATUS, outputRelay.relay_event.bits.Gun1_P);
  143. } else {
  144. StopCheckRelayInfo(RELAY_SMR1_P_STATUS);
  145. }
  146. if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
  147. //log_info("SMR1:D- Relay none match. \n");
  148. StartCheckRelayInfo(RELAY_SMR1_N_STATUS, outputRelay.relay_event.bits.Gun1_N);
  149. } else {
  150. StopCheckRelayInfo(RELAY_SMR1_N_STATUS);
  151. }
  152. if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
  153. //log_info("SMR2:D+ Relay none match. \n");
  154. StartCheckRelayInfo(RELAY_SMR2_P_STATUS, outputRelay.relay_event.bits.Gun2_P);
  155. } else {
  156. StopCheckRelayInfo(RELAY_SMR2_P_STATUS);
  157. }
  158. if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
  159. //log_info("SMR2:D- Relay none match. \n");
  160. StartCheckRelayInfo(RELAY_SMR2_N_STATUS, outputRelay.relay_event.bits.Gun2_N);
  161. } else {
  162. StopCheckRelayInfo(RELAY_SMR2_N_STATUS);
  163. }
  164. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  165. if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
  166. //log_info("Parallel:D+ Relay none match. \n");
  167. StartCheckRelayInfo(RELAY_PARA_P_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_P);
  168. } else {
  169. StopCheckRelayInfo(RELAY_PARA_P_STATUS);
  170. }
  171. if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
  172. //log_info("Parallel:D- Relay none match. \n");
  173. StartCheckRelayInfo(RELAY_PARA_N_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_N);
  174. } else {
  175. StopCheckRelayInfo(RELAY_PARA_N_STATUS);
  176. }
  177. #endif //
  178. return result;
  179. }
  180. static void SetParalleRelayStatus(void)
  181. {
  182. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  183. return;
  184. #endif //!defined DD360 || !defined DD360Audi || !defined DD360ComBox
  185. struct ChargingInfoData *pDcChargingInfo0 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  186. struct ChargingInfoData *pDcChargingInfo1 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
  187. // 之後雙槍單模機種,橋接都會上
  188. if (pSysConfig->TotalConnectorCount >= 2) {
  189. if (pDcChargingInfo0->SystemStatus == S_BOOTING || pDcChargingInfo1->SystemStatus == S_BOOTING ||
  190. (pDcChargingInfo0->SystemStatus == S_IDLE && pDcChargingInfo1->SystemStatus == S_IDLE)) {
  191. // 初始化~ 不搭橋接
  192. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  193. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  194. } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
  195. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  196. }
  197. } else {
  198. if (pDcChargingInfo0->IsReadyToCharging == YES ||
  199. pDcChargingInfo1->IsReadyToCharging == YES) {
  200. // ************需考慮在切換中 - 切開 relay 與搭回 relay 的時機點************
  201. if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
  202. if (pSysInfo->ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A) {
  203. // 最大充 - 搭上橋接
  204. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
  205. outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
  206. } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
  207. outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
  208. }
  209. } else {
  210. // 平均充 - 不搭
  211. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  212. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  213. } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
  214. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  215. }
  216. }
  217. } else if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
  218. if (pSysInfo->ReAssignedFlag < _REASSIGNED_RELAY_A_TO_M) {
  219. // 平均充 - 不搭
  220. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  221. outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
  222. } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
  223. outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
  224. }
  225. } else {
  226. // 最大充 - 搭上橋接
  227. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
  228. outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
  229. } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
  230. outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. static void GetGfdAdc(void)
  239. {
  240. int gunIndex = 0;
  241. uint8_t targetID = 0;
  242. struct ChargingInfoData *pDcChargingInfo = NULL;
  243. Gfd gfd_adc = {0};
  244. // define : 每 0.2 ~ 1 秒一次
  245. // occur : <= 75k 歐姆 @ 150 - 750 Vdc
  246. // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
  247. if (Query_Gfd_Adc(Uart5Fd, ADDR_RELAY, &gfd_adc) == PASS) {
  248. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  249. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  250. if (pDcChargingInfo->Type == 0x09 &&
  251. !pSysConfig->AlwaysGfdFlag
  252. ) {
  253. if ((pDcChargingInfo->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE) {
  254. pDcChargingInfo->GroundFaultStatus = GFD_PASS;
  255. }
  256. continue;
  257. }
  258. targetID = getCommTargetID(gunIndex);
  259. if (targetID == 0x01) {
  260. //if (gfd_adc.result_conn1 == GFD_WARNING) {
  261. // gfd_adc.result_conn1 = GFD_PASS;
  262. //}
  263. pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn1;
  264. //log_info("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
  265. // pDcChargingInfo->GroundFaultStatus,
  266. // gfd_adc.rb_step_1,
  267. // gfd_adc.Resister_conn1,
  268. // gfd_adc.voltage_conn1);
  269. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  270. log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
  271. gunIndex,
  272. gfd_adc.rb_step_1,
  273. gfd_adc.Resister_conn1,
  274. gfd_adc.voltage_conn1);
  275. } else if (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
  276. pDcChargingInfo->GroundFaultStatus == GFD_WARNING
  277. ) {
  278. if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  279. log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
  280. gunIndex,
  281. pDcChargingInfo->GroundFaultStatus,
  282. gfd_adc.Resister_conn1,
  283. gfd_adc.voltage_conn1);
  284. }
  285. }
  286. } else if (targetID == 0x02) {
  287. //if (gfd_adc.result_conn2 == GFD_WARNING) {
  288. // gfd_adc.result_conn2 = GFD_PASS;
  289. //}
  290. pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn2;
  291. if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
  292. log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
  293. gunIndex,
  294. gfd_adc.rb_step_2,
  295. gfd_adc.Resister_conn2,
  296. gfd_adc.voltage_conn2);
  297. } else if (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
  298. pDcChargingInfo->GroundFaultStatus == GFD_WARNING
  299. ) {
  300. if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
  301. log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
  302. gunIndex,
  303. pDcChargingInfo->GroundFaultStatus,
  304. gfd_adc.Resister_conn1,
  305. gfd_adc.voltage_conn1);
  306. }
  307. }
  308. }
  309. }
  310. }
  311. }
  312. void CheckOutputPowerOverCarReq(uint8_t index)
  313. {
  314. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  315. float fireV = pDcChargingInfo->FireChargingVoltage;
  316. float carV = pDcChargingInfo->EvBatteryMaxVoltage * 10;
  317. if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
  318. (pDcChargingInfo->Type == _Type_Chademo ||
  319. pDcChargingInfo->Type == _Type_CCS_2 ||
  320. pDcChargingInfo->Type == _Type_GB)) {
  321. if (fireV >= (carV + (carV * 0.02))) {
  322. if (!_isOvpChkTimeFlag[index]) {
  323. if ((pDcChargingInfo->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
  324. gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
  325. _isOvpChkTimeFlag[index] = YES;
  326. }
  327. } else {
  328. log_info("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
  329. pDcChargingInfo->FireChargingVoltage, (pDcChargingInfo->EvBatterytargetVoltage * 10));
  330. log_error("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
  331. pDcChargingInfo->FireChargingVoltage, (pDcChargingInfo->EvBatterytargetVoltage * 10));
  332. if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME) {
  333. if (pDcChargingInfo->Type == _Type_Chademo) {
  334. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
  335. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  336. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES;
  337. } else if (pDcChargingInfo->Type == _Type_GB) {
  338. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES;
  339. }
  340. pDcChargingInfo->StopChargeFlag = YES;
  341. }
  342. }
  343. } else {
  344. if (_isOvpChkTimeFlag[index] == YES) {
  345. _isOvpChkTimeFlag[index] = NO;
  346. }
  347. }
  348. }
  349. }
  350. void ResetDetAlarmStatus(uint8_t gun)
  351. {
  352. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
  353. if (pDcChargingInfo->Type == _Type_Chademo) {
  354. if (pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP == YES) {
  355. pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
  356. }
  357. } else if (pDcChargingInfo->Type == _Type_GB) {
  358. if (pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP == YES) {
  359. pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
  360. }
  361. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  362. if (pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
  363. pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
  364. }
  365. }
  366. }
  367. void CheckAcInputOvpStatus(uint8_t index)
  368. {
  369. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  370. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
  371. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
  372. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
  373. // if ((pDcChargingInfo->SystemStatus >= S_PREPARNING && pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  374. // (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
  375. // {
  376. // if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC)
  377. // {
  378. // if (_psuInputVolR > VIN_MAX_VOLTAGE_IEC ||
  379. // _psuInputVolS > VIN_MAX_VOLTAGE_IEC ||
  380. // _psuInputVolT > VIN_MAX_VOLTAGE_IEC)
  381. // {
  382. // log_info("IEC _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
  383. // _psuInputVolR, _psuInputVolS, _psuInputVolT);
  384. // pDcChargingInfo->StopChargeFlag = YES;
  385. // }
  386. //
  387. // }
  388. // else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL)
  389. // {
  390. // if (_psuInputVolR > VIN_MAX_VOLTAGE_UL ||
  391. // _psuInputVolS > VIN_MAX_VOLTAGE_UL ||
  392. // _psuInputVolT > VIN_MAX_VOLTAGE_UL)
  393. // {
  394. // log_info("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
  395. // _psuInputVolR, _psuInputVolS, _psuInputVolT);
  396. // pDcChargingInfo->StopChargeFlag = YES;
  397. // }
  398. // }
  399. // }
  400. // else
  401. //log_info("CheckAcInputOvpStatus\r\n");
  402. pDcChargingInfo->StopChargeFlag = YES;
  403. }
  404. }
  405. //void CheckOutputVolNoneMatchFire(uint8_t index)
  406. //{
  407. // struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  408. //
  409. // if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
  410. // (pDcChargingInfo->Type == _Type_Chademo ||
  411. // pDcChargingInfo->Type == _Type_CCS_2 ||
  412. // pDcChargingInfo->Type == _Type_GB)) {
  413. // if (((pDcChargingInfo->PresentChargingVoltage * 10) < pDcChargingInfo->FireChargingVoltage - 300) ||
  414. // ((pDcChargingInfo->PresentChargingVoltage * 10) > pDcChargingInfo->FireChargingVoltage + 300)) {
  415. // if (!_isOutputNoneMatch[index]) {
  416. // _isOutputNoneMatch[index] = YES;
  417. // gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
  418. // } else {
  419. // if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000) {
  420. // /*log_info("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
  421. // index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
  422. // log_error("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f \n",
  423. // index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
  424. // pDcChargingInfo->StopChargeFlag = YES;*/
  425. // }
  426. // }
  427. // } else {
  428. // _isOutputNoneMatch[index] = NO;
  429. // }
  430. // }
  431. //}
  432. void CheckPhaseLossStatus(uint8_t index)
  433. {
  434. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  435. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES ||
  436. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES ||
  437. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
  438. //log_info("CheckPhaseLossStatus\r\n");
  439. pDcChargingInfo->StopChargeFlag = YES;
  440. }
  441. }
  442. void SetK1K2RelayStatus(uint8_t index)
  443. {
  444. uint8_t targetID = 0;
  445. PreChargingState *pRegPreChargingState = NULL;
  446. PreChargingState *pOutputPreChargingState = NULL;
  447. GunPNState *pRegGunPNState = NULL;
  448. GunPNState *pOutputGunPNState = NULL;
  449. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  450. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
  451. if (regRelay.relay_event.bits.Gun1_N == NO) {
  452. outputRelay.relay_event.bits.Gun1_N = YES;
  453. } else if (regRelay.relay_event.bits.Gun1_P == NO) {
  454. outputRelay.relay_event.bits.Gun1_P = YES;
  455. }
  456. return;
  457. }
  458. targetID = getCommTargetID(index);
  459. pRegPreChargingState = (PreChargingState *)&regRelay.relay_event.relay_status[0];
  460. pOutputPreChargingState = (PreChargingState *)&outputRelay.relay_event.relay_status[0];
  461. if (targetID == 0x01) {
  462. pRegGunPNState = (GunPNState *)&regRelay.relay_event.relay_status[1];
  463. pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[1];
  464. } else if (targetID == 0x02) {
  465. pRegGunPNState = (GunPNState *)&regRelay.relay_event.relay_status[2];
  466. pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[2];
  467. }
  468. switch (pDcChargingInfo->SystemStatus) {
  469. case S_BOOTING:
  470. case S_IDLE:
  471. case S_AUTHORIZING:
  472. case S_REASSIGN_CHECK:
  473. case S_REASSIGN:
  474. case S_PREPARNING:
  475. case S_PREPARING_FOR_EV:
  476. if (pRegGunPNState->GunP == YES) {
  477. pOutputGunPNState->GunP = NO;
  478. } else if (pRegGunPNState->GunN == YES) {
  479. pOutputGunPNState->GunN = NO;
  480. }
  481. if (targetID == 0x02 && pDcChargingInfo->Type == _Type_CCS_2) {
  482. if (pRegPreChargingState->CcsPrecharge == YES) {
  483. pOutputPreChargingState->CcsPrecharge = NO;
  484. }
  485. }
  486. break;
  487. case S_PREPARING_FOR_EVSE:
  488. case S_CHARGING:
  489. //if (pDcChargingInfo->RelayWeldingCheck != YES) {
  490. // break;
  491. //}
  492. if (pRegGunPNState->GunN == NO) {
  493. pOutputGunPNState->GunN = YES;
  494. } else if (pRegGunPNState->GunP == NO) {
  495. pOutputGunPNState->GunP = YES;
  496. }
  497. break;
  498. case S_TERMINATING:
  499. case S_COMPLETE:
  500. case S_ALARM:
  501. if ((pDcChargingInfo->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
  502. if (pRegGunPNState->GunP == YES) {
  503. pOutputGunPNState->GunP = NO;
  504. } else if (pRegGunPNState->GunN == YES) {
  505. pOutputGunPNState->GunN = NO;
  506. }
  507. }
  508. break;
  509. case S_CCS_PRECHARGE_ST0:
  510. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  511. break;
  512. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  513. //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
  514. // if (pRegPreChargingState->CcsPrecharge == NO) {
  515. // pOutputPreChargingState->CcsPrecharge = YES;
  516. // } else if (pRegPreChargingState->CcsPrecharge == YES) {
  517. // pRegGunPNState->GunP = NO;
  518. // }
  519. //}
  520. break;
  521. case S_CCS_PRECHARGE_ST1:
  522. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  523. break;
  524. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  525. //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
  526. // if (pRegGunPNState->GunP == NO) {
  527. // pOutputGunPNState->GunP = YES;
  528. // } else if (pRegGunPNState->GunP == YES) {
  529. // pOutputPreChargingState->CcsPrecharge = NO;
  530. // }
  531. //}
  532. break;
  533. }
  534. }
  535. // 確認 K1 K2 relay 的狀態
  536. void CheckK1K2RelayOutput(uint8_t index)
  537. {
  538. uint8_t targetID = 0;
  539. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  540. targetID = getCommTargetID(index);
  541. switch (targetID) {
  542. case 0x01:
  543. if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES) {
  544. pDcChargingInfo->RelayK1K2Status = YES;
  545. } else {
  546. pDcChargingInfo->RelayK1K2Status = NO;
  547. }
  548. if (pDcChargingInfo->Type == _Type_CCS_2) {
  549. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  550. if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
  551. pDcChargingInfo->RelayKPK2Status = YES;
  552. } else {
  553. pDcChargingInfo->RelayKPK2Status = NO;
  554. }
  555. #else
  556. if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) {
  557. pDcChargingInfo->RelayKPK2Status = YES;
  558. } else {
  559. pDcChargingInfo->RelayKPK2Status = NO;
  560. }
  561. #endif //!defined DD360 && !defined DD360Audi
  562. }
  563. break;
  564. case 0x02:
  565. if (regRelay.relay_event.bits.Gun2_N == YES &&
  566. regRelay.relay_event.bits.Gun2_P == YES) {
  567. pDcChargingInfo->RelayK1K2Status = YES;
  568. } else {
  569. pDcChargingInfo->RelayK1K2Status = NO;
  570. }
  571. if (pDcChargingInfo->Type == _Type_CCS_2) {
  572. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  573. if (regRelay.relay_event.bits.Gun2_N == YES &&
  574. regRelay.relay_event.bits.CCS_Precharge == YES) {
  575. pDcChargingInfo->RelayKPK2Status = YES;
  576. } else {
  577. pDcChargingInfo->RelayKPK2Status = NO;
  578. }
  579. #else
  580. if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) {
  581. pDcChargingInfo->RelayKPK2Status = YES;
  582. } else {
  583. pDcChargingInfo->RelayKPK2Status = NO;
  584. }
  585. #endif //!defined DD360 && !defined DD360Audi
  586. }
  587. break;
  588. }
  589. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  590. //DS60-120 add
  591. if (pSysInfo->BridgeRelayStatus == YES) {
  592. if (regRelay.relay_event.bits.Gun1_Parallel_N == NO &&
  593. regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
  594. pSysInfo->BridgeRelayStatus = NO;
  595. }
  596. } else if (pSysInfo->BridgeRelayStatus == NO) {
  597. if (regRelay.relay_event.bits.Gun1_Parallel_N == YES &&
  598. regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  599. pSysInfo->BridgeRelayStatus = YES;
  600. }
  601. }
  602. #else
  603. pSysInfo->BridgeRelayStatus = YES;
  604. #endif //!defined DD360 && !defined DD360Audi
  605. }
  606. void SetGfdConfig(uint8_t index, uint8_t resister)
  607. {
  608. Gfd_config gfd_config = {
  609. .index = index,
  610. .state = resister,
  611. };
  612. //log_info("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
  613. if (Config_Gfd_Value(Uart5Fd, ADDR_RELAY, &gfd_config) == PASS) {
  614. // log_info("Set reqVol = %f, resister = %d \n",
  615. // gfd_config.reqVol,
  616. // gfd_config.resister);
  617. }
  618. }
  619. void CableCheckDetected(uint8_t index)
  620. {
  621. uint8_t targetID = 0;
  622. struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  623. // Cable Check
  624. // 當火線上的電壓 = 車端要求的電壓電流
  625. // _chargingData[targetGun]->EvBatterytargetVoltage
  626. // 才可以開始偵測 1s
  627. // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
  628. // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
  629. // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
  630. if (pSysConfig->TotalConnectorCount == 1) {
  631. if (strncmp((char *)&pSysConfig->ModelName[7], "0", 1) != 0) {
  632. targetID = 0;
  633. } else if (strncmp((char *)&pSysConfig->ModelName[9], "0", 1) != 0) {
  634. targetID = 1;
  635. }
  636. } else {
  637. targetID = index;
  638. }
  639. if ((pDcChargingInfo->Type >= _Type_Chademo &&
  640. pDcChargingInfo->Type <= _Type_GB) ||
  641. (pDcChargingInfo->Type == 0x09 &&
  642. pSysConfig->AlwaysGfdFlag)
  643. ) {
  644. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  645. pDcChargingInfo->SystemStatus <= S_TERMINATING) ||
  646. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  647. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  648. ) {
  649. //if ((pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) &&
  650. // (pDcChargingInfo->RelayWeldingCheck == YES)
  651. // ) {
  652. if (pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) {
  653. SetGfdConfig(targetID, GFD_CABLECHK);
  654. } else if ((pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0) &&
  655. (pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  656. ) {
  657. SetGfdConfig(targetID, GFD_PRECHARGE);
  658. } else if ((pDcChargingInfo->SystemStatus >= S_CHARGING) &&
  659. (pDcChargingInfo->SystemStatus <= S_TERMINATING)
  660. ) {
  661. if ((pDcChargingInfo->Type == _Type_GB) ||
  662. (pDcChargingInfo->Type == _Type_Chademo)
  663. ) {
  664. SetGfdConfig(targetID, GFD_IDLE);
  665. } else {
  666. SetGfdConfig(targetID, GFD_CHARGING);
  667. }
  668. }
  669. } else if (pDcChargingInfo->SystemStatus == S_COMPLETE ||
  670. pDcChargingInfo->SystemStatus == S_PREPARNING ||
  671. pDcChargingInfo->SystemStatus == S_IDLE) {
  672. SetGfdConfig(targetID, GFD_IDLE);
  673. }
  674. }
  675. }
  676. // 讀取 Relay 狀態
  677. void GetRelayOutputStatus(void)
  678. {
  679. if (Query_Relay_Output(Uart5Fd, ADDR_RELAY, &regRelay) == PASS) {
  680. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  681. regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  682. #endif //!defined DD360 && !defined DD360Audi
  683. }
  684. }
  685. // AC 三相輸入電壓
  686. void GetPresentInputVol(void)
  687. {
  688. static uint8_t _threePhaseOvp[3] = {0, 0, 0}; //DS60-120 add
  689. static uint8_t _threePhaseUvp[3] = {0, 0, 0}; //DS60-120 add
  690. PresentInputVoltage inputVoltage = {0};
  691. if (Query_Present_InputVoltage(Uart5Fd, ADDR_RELAY, &inputVoltage) == PASS) {
  692. // resolution : 0.1
  693. pSysInfo->InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
  694. pSysInfo->InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
  695. pSysInfo->InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
  696. //********************************************************************************************************//
  697. // Vin (UVP)
  698. if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC) {
  699. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == NO) {
  700. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC) {
  701. log_info("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  702. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
  703. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = YES;
  704. } else {
  705. _threePhaseUvp[0] += 1;
  706. }
  707. }
  708. } else {
  709. if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_IEC) {
  710. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = NO;
  711. _threePhaseUvp[0] = 0;
  712. }
  713. }
  714. if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == NO) {
  715. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC) {
  716. log_info("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  717. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
  718. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = YES;
  719. } else {
  720. _threePhaseUvp[1] += 1;
  721. }
  722. }
  723. } else {
  724. if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_IEC) {
  725. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = NO;
  726. _threePhaseUvp[1] = 0;
  727. }
  728. }
  729. if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == NO) {
  730. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC) {
  731. log_info("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  732. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
  733. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = YES;
  734. } else {
  735. _threePhaseUvp[2] += 1;
  736. }
  737. }
  738. } else {
  739. if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_IEC) {
  740. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = NO;
  741. _threePhaseUvp[2] = 0;
  742. }
  743. }
  744. } else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL) {
  745. if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == NO) {
  746. if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL) {
  747. log_info("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  748. if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
  749. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = YES;
  750. } else {
  751. _threePhaseUvp[0] += 1;
  752. }
  753. }
  754. } else {
  755. if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_UL) {
  756. pAlarmCode->AlarmEvents.bits.SystemL1InputUVP = NO;
  757. _threePhaseUvp[0] = 0;
  758. }
  759. }
  760. if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == NO) {
  761. if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL) {
  762. log_info("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  763. if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
  764. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = YES;
  765. } else {
  766. _threePhaseUvp[1] += 1;
  767. }
  768. }
  769. } else {
  770. if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_UL) {
  771. pAlarmCode->AlarmEvents.bits.SystemL2InputUVP = NO;
  772. _threePhaseUvp[1] = 0;
  773. }
  774. }
  775. if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == NO) {
  776. if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL) {
  777. log_info("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  778. if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
  779. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = YES;
  780. } else {
  781. _threePhaseUvp[2] += 1;
  782. }
  783. }
  784. } else {
  785. if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_UL) {
  786. pAlarmCode->AlarmEvents.bits.SystemL3InputUVP = NO;
  787. _threePhaseUvp[2] = 0;
  788. }
  789. }
  790. }
  791. //********************************************************************************************************//
  792. // Vin (OVP)
  793. if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC) {
  794. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == NO) {
  795. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC) {
  796. log_info("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  797. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
  798. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = YES;
  799. } else {
  800. _threePhaseOvp[0] += 1;
  801. }
  802. }
  803. } else {
  804. if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_IEC) {
  805. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = NO;
  806. _threePhaseOvp[0] = 0;
  807. }
  808. }
  809. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  810. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC) {
  811. log_info("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  812. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
  813. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = YES;
  814. } else {
  815. _threePhaseOvp[1] += 1;
  816. }
  817. }
  818. } else {
  819. if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_IEC) {
  820. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = NO;
  821. _threePhaseOvp[1] = 0;
  822. }
  823. }
  824. if (pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == NO) {
  825. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC) {
  826. log_info("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  827. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
  828. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = YES;
  829. } else {
  830. _threePhaseOvp[2] += 1;
  831. }
  832. }
  833. } else {
  834. if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_IEC) {
  835. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = NO;
  836. _threePhaseOvp[2] = 0;
  837. }
  838. }
  839. } else if (pSysInfo->ChargerType == _CHARGER_TYPE_UL) {
  840. if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == NO) {
  841. if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL) {
  842. log_info("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
  843. if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
  844. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = YES;
  845. } else {
  846. _threePhaseOvp[0] += 0;
  847. }
  848. }
  849. } else {
  850. if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_UL) {
  851. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = NO;
  852. _threePhaseOvp[0] = 0;
  853. }
  854. }
  855. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  856. if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL) {
  857. log_info("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
  858. if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
  859. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = YES;
  860. } else {
  861. _threePhaseOvp[1] += 0;
  862. }
  863. }
  864. } else {
  865. if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_UL) {
  866. pAlarmCode->AlarmEvents.bits.SystemL2InputOVP = NO;
  867. _threePhaseOvp[1] = 0;
  868. }
  869. }
  870. if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == NO) {
  871. if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL) {
  872. log_info("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
  873. if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
  874. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = YES;
  875. } else {
  876. _threePhaseOvp[2] += 1;
  877. }
  878. }
  879. } else {
  880. if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_UL) {
  881. pAlarmCode->AlarmEvents.bits.SystemL3InputOVP = NO;
  882. _threePhaseOvp[2] = 0;
  883. }
  884. }
  885. }
  886. }
  887. }
  888. // 左右槍的 Relay 前後的輸出電壓
  889. void GetPersentOutputVol(void)
  890. {
  891. uint8_t index = 0;
  892. uint8_t targetID = 0;
  893. struct ChargingInfoData *pDcChargingInfo = NULL;
  894. PresentOutputVoltage outputVoltage = {0};
  895. if (Query_Present_OutputVoltage(Uart5Fd, ADDR_RELAY, &outputVoltage) != PASS) {
  896. return;
  897. }
  898. //log_info("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
  899. //log_info("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
  900. //log_info("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
  901. //log_info("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
  902. //log_info("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
  903. //log_info("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
  904. ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
  905. ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
  906. ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
  907. ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
  908. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  909. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  910. targetID = getCommTargetID(index);
  911. switch (targetID) {
  912. case 0x01:
  913. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  914. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  915. pDcChargingInfo->PresentChargingCurrent = ShmRelayModuleData->Gun1FuseOutputVolt / 10;
  916. pDcChargingInfo->PresentChargingVoltage = pDcChargingInfo->FireChargingVoltage / 10;
  917. pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
  918. break;
  919. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  920. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
  921. pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
  922. break;
  923. case 0x02:
  924. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  925. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  926. pDcChargingInfo->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
  927. pDcChargingInfo->PresentChargingVoltage = pDcChargingInfo->FireChargingVoltage / 10;
  928. pDcChargingInfo->FuseChargingVoltage = pDcChargingInfo->FireChargingVoltage;
  929. break;
  930. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  931. pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
  932. pDcChargingInfo->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
  933. break;
  934. }
  935. //unsigned short Ovp = 0;
  936. //unsigned short Ocp = 0;
  937. //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] // 最大輸出電壓與電池電壓最大值
  938. //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ] // 最大輸出電流與需求電流最小值
  939. //if (pDcChargingInfo->Type == _Type_Chademo) {
  940. // //Ovp = MaxValue(pDcChargingInfo->MaximumChargingVoltage, pDcChargingInfo->EvBatteryMaxVoltage);
  941. // //Ocp = MaxValue(pDcChargingInfo->PresentChargingCurrent, ShmCHAdeMOData->ev[pDcChargingInfo->type_index].ChargingCurrentRequest);
  942. //} else if (pDcChargingInfo->Type == _Type_CCS_2) {
  943. //}
  944. }
  945. }
  946. void SetRtcData_Relay(void)
  947. {
  948. struct timeb csuTime;
  949. struct tm *tmCSU;
  950. Rtc rtc = {0};
  951. ftime(&csuTime);
  952. tmCSU = localtime(&csuTime.time);
  953. // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
  954. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  955. // tmCSU->tm_sec);
  956. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  957. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  958. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  959. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  960. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  961. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  962. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  963. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  964. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  965. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  966. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  967. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  968. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  969. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  970. if (Config_Rtc_Data(Uart5Fd, ADDR_RELAY, &rtc) == PASS) {
  971. //log_info("SetRtc (RB) sucessfully. \n");
  972. }
  973. }
  974. void SetModelName_Relay(void)
  975. {
  976. if (Config_Model_Name(Uart5Fd, ADDR_RELAY, pSysConfig->ModelName) == PASS) {
  977. //log_info("Set Model name (RB) PASS = %s \n", pSysConfig->ModelName);
  978. }
  979. }
  980. void GetFwAndHwVersion_Relay(void)
  981. {
  982. Ver ver = {0};
  983. if (Query_FW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
  984. // RelayModuleData
  985. strcpy((char *)ShmRelayModuleData->version, ver.Version_FW);
  986. // SystemInfo
  987. strcpy((char *)pSysInfo->RelayModuleFwRev, ver.Version_FW);
  988. //log_info("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
  989. }
  990. if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
  991. // SystemInfo
  992. strcpy((char *)pSysInfo->RelayModuleHwRev, ver.Version_FW);
  993. //log_info("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
  994. }
  995. }
  996. static void outputRelayInit(int fd)
  997. {
  998. memset((uint8_t *)&outputRelay, 0, sizeof(Relay));
  999. if (Config_Relay_Output(fd, ADDR_RELAY, &outputRelay) != PASS) {
  1000. log_info("Config_Relay_Output fail \n");
  1001. }
  1002. }
  1003. void RelayBoardTask(int uartFD)
  1004. {
  1005. pid_t pid = fork();
  1006. if (pid == 0) {
  1007. bool isCharging = false;
  1008. bool isStopChargingCount = false;
  1009. uint8_t i = 0;
  1010. int isContinue = 1;
  1011. struct ChargingInfoData *pDcChargingInfo = NULL;
  1012. //share memory mapping
  1013. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1014. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1015. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1016. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  1017. ShmPsuData = (struct PsuData *)GetShmPsuData();
  1018. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1019. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1020. Uart5Fd = uartFD;
  1021. //relay init
  1022. outputRelayInit(uartFD);
  1023. while (isContinue) {
  1024. // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
  1025. if (ShmRelayModuleData->SelfTest_Comp == NO) {
  1026. GetFwAndHwVersion_Relay();
  1027. SetModelName_Relay(); //DS60-120 add
  1028. SetRtcData_Relay();
  1029. sleep(1);
  1030. continue;
  1031. }
  1032. // ==============優先權最高 10 ms ==============
  1033. // 輸出電壓
  1034. GetPersentOutputVol();
  1035. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1036. // 三相輸入電壓
  1037. GetPresentInputVol();
  1038. #endif //!defined DD360 && !defined DD360Audi
  1039. // 讀取當前 AC relay 狀態
  1040. regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  1041. GetRelayOutputStatus();
  1042. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1043. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1044. // Cable check (Set)
  1045. CableCheckDetected(i);
  1046. // check k1 k2 relay 狀態
  1047. CheckK1K2RelayOutput(i);
  1048. // 依據當前各槍的狀態選擇 搭上/放開 Relay
  1049. SetK1K2RelayStatus(i);
  1050. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1051. if (pSysConfig->PhaseLossPolicy == YES) {
  1052. CheckPhaseLossStatus(i);
  1053. }
  1054. CheckAcInputOvpStatus(i);
  1055. #endif //!defined DD360 && !defined DD360Audi
  1056. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  1057. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  1058. pDcChargingInfo->SystemStatus == S_MAINTAIN) {
  1059. //pDcChargingInfo->RelayWeldingCheck = NO;
  1060. //_isRelayWelding[i] = NO;
  1061. _isOvpChkTimeFlag[i] = NO;
  1062. //ResetDetAlarmStatus(i); //DS60-120 add
  1063. }
  1064. if (pDcChargingInfo->SystemStatus == S_BOOTING ||
  1065. (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  1066. pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
  1067. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  1068. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
  1069. pSysInfo->WaitForPlugit == YES ||
  1070. (pSysInfo->PageIndex >= _LCM_AUTHORIZING &&
  1071. pSysInfo->PageIndex <= _LCM_WAIT_FOR_PLUG)
  1072. ) {
  1073. pDcChargingInfo->IsReadyToCharging = YES;
  1074. isCharging = true;
  1075. // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
  1076. //if (pDcChargingInfo->Type == _Type_GB) {
  1077. // if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
  1078. // pDcChargingInfo->RelayWeldingCheck == NO) {
  1079. // CheckRelayWeldingStatus(i);
  1080. // }
  1081. //} else {
  1082. //pDcChargingInfo->RelayWeldingCheck = YES;
  1083. //}
  1084. if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  1085. CheckOutputPowerOverCarReq(i);
  1086. //CheckOutputVolNoneMatchFire(i);
  1087. }
  1088. /*else {
  1089. _isOutputNoneMatch[i] = NO;
  1090. }*/
  1091. } else {
  1092. pDcChargingInfo->IsReadyToCharging = NO;
  1093. }
  1094. }
  1095. // Cable check (Get)
  1096. GetGfdAdc();
  1097. // 橋接 relay
  1098. SetParalleRelayStatus();
  1099. // 搭上 AC Contactor
  1100. //if (isCharging) {
  1101. // outputRelay.relay_event.bits.AC_Contactor = YES;
  1102. //} else {
  1103. // outputRelay.relay_event.bits.AC_Contactor = NO;
  1104. //}
  1105. if (isCharging ||
  1106. (ShmPsuData->Work_Step >= _TEST_MODE &&
  1107. ShmPsuData->Work_Step <= _TEST_MODE)) {
  1108. isStopChargingCount = false;
  1109. outputRelay.relay_event.bits.AC_Contactor = YES;
  1110. } else {
  1111. if (!isStopChargingCount) {
  1112. gettimeofday(&_close_ac_contactor, NULL);
  1113. isStopChargingCount = true;
  1114. } else {
  1115. if ((outputRelay.relay_event.bits.AC_Contactor == YES &&
  1116. GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
  1117. outputRelay.relay_event.bits.AC_Contactor = NO;
  1118. }
  1119. }
  1120. }
  1121. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
  1122. outputRelay.relay_event.bits.AC_Contactor = NO;
  1123. }
  1124. if (pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == ABNORMAL) {
  1125. RunForceStopProcess();
  1126. outputRelay.relay_event.bits.AC_Contactor = NO;
  1127. }
  1128. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
  1129. outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
  1130. }
  1131. // 搭上/鬆開 Relay
  1132. if (IsNoneMatchRelayStatus()) {
  1133. if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
  1134. //regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
  1135. //regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
  1136. //regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
  1137. //regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
  1138. //regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
  1139. //regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
  1140. //regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
  1141. //regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
  1142. //MatchRelayStatus();
  1143. //log_info("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
  1144. // regRelay.relay_event.bits.AC_Contactor,
  1145. // regRelay.relay_event.bits.Gun1_P,
  1146. // regRelay.relay_event.bits.Gun1_N,
  1147. // regRelay.relay_event.bits.Gun2_P,
  1148. // regRelay.relay_event.bits.Gun2_N,
  1149. // regRelay.relay_event.bits.CCS_Precharge,
  1150. // regRelay.relay_event.bits.Gun1_Parallel_P,
  1151. // regRelay.relay_event.bits.Gun1_Parallel_N);
  1152. }
  1153. } /*else {
  1154. log_info("======== Relay Status Start========\n");
  1155. if (regRelay.relay_event.bits.AC_Contactor == YES) {
  1156. log_info("AC Power : ON \n");
  1157. } else {
  1158. log_info("AC Power : OFF \n");
  1159. }
  1160. if (regRelay.relay_event.bits.Gun1_P == YES) {
  1161. log_info("Conn1(+) : ON \n");
  1162. } else {
  1163. log_info("Conn1(+) : OFF \n");
  1164. }
  1165. if (regRelay.relay_event.bits.Gun1_N == YES) {
  1166. log_info("Conn1(-) : ON \n");
  1167. } else {
  1168. log_info("Conn1(-) : OFF \n");
  1169. }
  1170. if (regRelay.relay_event.bits.Gun2_P == YES) {
  1171. log_info("Conn2(+) : ON \n");
  1172. } else {
  1173. log_info("Conn2(+) : OFF \n");
  1174. }
  1175. if (regRelay.relay_event.bits.Gun2_N == YES) {
  1176. log_info("Conn2(-) : ON \n");
  1177. } else {
  1178. log_info("Conn2(-) : OFF \n");
  1179. }
  1180. if (regRelay.relay_event.bits.CCS_Precharge == YES) {
  1181. log_info("Precharge : ON \n");
  1182. } else {
  1183. log_info("Precharge : OFF \n");
  1184. }
  1185. if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
  1186. log_info("Parallel(+) : ON \n");
  1187. } else {
  1188. log_info("Parallel(+) : OFF \n");
  1189. }
  1190. if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
  1191. log_info("Parallel(-) : ON \n");
  1192. } else {
  1193. log_info("Parallel(-) : OFF \n");
  1194. }
  1195. log_info("======== Relay Status End========\n");
  1196. }*/
  1197. }
  1198. usleep(100000);
  1199. }
  1200. }