Module_PrimaryComm.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. #include <sys/time.h>
  2. #include <sys/timeb.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/shm.h>
  11. #include <sys/mman.h>
  12. #include <linux/wireless.h>
  13. #include <arpa/inet.h>
  14. #include <netinet/in.h>
  15. #include <stdbool.h>
  16. #include <unistd.h>
  17. #include <stdarg.h>
  18. #include <stdio.h> /*標準輸入輸出定義*/
  19. #include <stdlib.h> /*標準函數庫定義*/
  20. #include <unistd.h> /*Unix 標準函數定義*/
  21. #include <fcntl.h> /*檔控制定義*/
  22. #include <termios.h> /*PPSIX 終端控制定義*/
  23. #include <errno.h> /*錯誤號定義*/
  24. #include <errno.h>
  25. #include <string.h>
  26. #include <time.h>
  27. #include <ctype.h>
  28. #include <ifaddrs.h>
  29. #include <math.h>
  30. #include "../Log/log.h"
  31. #include "../Define/define.h"
  32. #include "../Config.h"
  33. #include "../ShareMemory/shmMem.h"
  34. #include "PrimaryComm.h"
  35. #include "Module_PrimaryComm.h"
  36. //------------------------------------------------------------------------------
  37. //struct SysConfigAndInfo *ShmSysConfigAndInfo;
  38. //struct StatusCodeData *ShmStatusCodeData;
  39. static struct SysConfigData *pSysConfig = NULL;
  40. static struct SysInfoData *pSysInfo = NULL;
  41. static struct AlarmCodeData *pAlarmCode = NULL;
  42. static struct FaultCodeData *pFaultCode = NULL;
  43. static struct PrimaryMcuData *ShmPrimaryMcuData;
  44. static DcCommonInfo *ShmDcCommonData = NULL;
  45. const char *priPortName = "/dev/ttyS1";
  46. uint8_t gun_count; //DS60-120 add
  47. uint8_t EmgBtn_count = 0;
  48. uint8_t Door_count = 0;
  49. uint8_t EmgBtn_flag = 0;
  50. uint8_t Door_flag = 0;
  51. bool _isNeedChkTilt = FALSE;
  52. struct timespec _tilt_time;
  53. uint8_t tilt = NO;
  54. bool _chargeSwitch;
  55. //================================================
  56. // Function
  57. //================================================
  58. bool GetFwAndHwVersion(int fd)
  59. {
  60. Ver ver = {0};
  61. if (Query_FW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS) {
  62. //log_info("Primary FW Rev = %s ", ver.Version_FW);
  63. strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
  64. strcpy((char *) pSysInfo->CsuPrimFwRev, ver.Version_FW);
  65. return TRUE;
  66. }
  67. return FALSE;
  68. //if (Query_HW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS)
  69. // ;//log_info("Primary HW Rev = %s ", ver.Version_HW);
  70. }
  71. void GetInputGpioStatus(int fd)
  72. {
  73. uint8_t dispenserSwTmp = 0;
  74. Gpio_in gpio_in = {0};
  75. static uint8_t dispenserSw = 0;
  76. //log_info("GetInputGpioStatus ");
  77. if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) != PASS) {
  78. return;
  79. }
  80. ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
  81. //log_info("gpio_in.AC_Drop:%d", gpio_in.AC_Drop);
  82. if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
  83. (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
  84. (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
  85. (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)
  86. ) {
  87. ShmPrimaryMcuData->InputDet.bits.Ac_Drop = gpio_in.AC_Drop; // Chiller Alarm ping
  88. }
  89. #ifdef DD360ComBox
  90. EmgBtn_flag = 0;
  91. #else
  92. if (gpio_in.Emergency_Btn && (EmgBtn_flag != gpio_in.Emergency_Btn))
  93. {
  94. EmgBtn_count++;
  95. if (EmgBtn_count > SensorTrigCount) {
  96. EmgBtn_flag = 1;
  97. EmgBtn_count = 0; // Avoid Overflow
  98. }
  99. } else if (EmgBtn_flag != gpio_in.Emergency_Btn ) {
  100. EmgBtn_count++;
  101. if (EmgBtn_count > SensorTrigCount) {
  102. EmgBtn_flag = 0;
  103. EmgBtn_count = 0;
  104. }
  105. }
  106. #endif
  107. ShmPrimaryMcuData->InputDet.bits.EmergencyButton = EmgBtn_flag;
  108. dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
  109. dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
  110. dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
  111. if (dispenserSwTmp != dispenserSw) {
  112. dispenserSw = dispenserSwTmp;
  113. log_info("Dispenser switch number = %d, bit = %d, %d, %d",
  114. dispenserSw,
  115. ShmPrimaryMcuData->InputDet.bits.Key2,
  116. ShmPrimaryMcuData->InputDet.bits.Key1,
  117. ShmPrimaryMcuData->InputDet.bits.Key0);
  118. }
  119. ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
  120. ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
  121. ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3];
  122. //#if defined DD360 || defined DD360Audi || defined DD360ComBox
  123. if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
  124. (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
  125. (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
  126. (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)
  127. ) {
  128. pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
  129. pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
  130. } else {
  131. //pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = gpio_in.AC_Connector;
  132. //pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
  133. }
  134. #if defined DD360ComBox
  135. Door_flag = 0;
  136. #else
  137. if (Door_flag == gpio_in.Door_Open) {
  138. Door_count++;
  139. if (Door_count == 3 ) {
  140. Door_count = 0;
  141. Door_flag = gpio_in.Door_Open;
  142. }
  143. } else {
  144. Door_flag = gpio_in.Door_Open;
  145. Door_count = 0;
  146. }
  147. /*
  148. if (gpio_in.Door_Open == 0 && (Door_flag == gpio_in.Door_Open))
  149. {
  150. Door_count++;
  151. if (Door_count > SensorTrigCount) {
  152. Door_flag = 1;
  153. Door_count = 0; // Avoid Overflow
  154. }
  155. } else if (gpio_in.Door_Open && Door_flag) {
  156. Door_count++;
  157. if (Door_count > SensorTrigCount) {
  158. Door_flag = 0;
  159. Door_count = 0;
  160. }
  161. }
  162. */
  163. #endif
  164. #if defined DD360ComBox
  165. ShmPrimaryMcuData->InputDet.bits.DoorOpen = Door_flag;
  166. #else
  167. ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~Door_flag;
  168. #endif
  169. /*
  170. log_info("Emergency Button Count = %d , Emergency flag = %d",
  171. EmgBtn_count,EmgBtn_flag);
  172. log_info("Door Sensor Count = %d , Door Sensor flag = %d",
  173. Door_count,Door_flag);
  174. */
  175. ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
  176. ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
  177. ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
  178. return;
  179. }
  180. static void checkChillerStatus(Gpio_out *gpio)
  181. {
  182. uint8_t gunIndex = 0;
  183. uint8_t chillerCount = 0;
  184. struct ChargingInfoData *pDcChargingInfo = NULL;
  185. static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
  186. static ChillerInfo _chiller;
  187. struct FanModuleData* ShmFanModuleData = (struct FanModuleData*)GetShmFanModuleData();
  188. DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
  189. Gpio_out *pGpio = (Gpio_out *)gpio;
  190. if ((strncmp((char*)&pSysConfig->ModelName[7], "V", 1) == 0) ||
  191. (strncmp((char*)&pSysConfig->ModelName[7], "F", 1) == 0)) {
  192. chillerCount++;
  193. ShmDcCommonData->pGunInfo[0].withChiller = TRUE;
  194. }
  195. if ((strncmp((char*)&pSysConfig->ModelName[9], "V", 1) == 0) ||
  196. (strncmp((char*)&pSysConfig->ModelName[9], "F", 1) == 0)) {
  197. chillerCount++;
  198. ShmDcCommonData->pGunInfo[1].withChiller = TRUE;
  199. }
  200. if (chillerCount == 0) {
  201. pGpio->AC_Connector = 0x00;
  202. return;
  203. }
  204. // 設定chiller 開關
  205. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  206. if (!ShmDcCommonData->pGunInfo[gunIndex].withChiller)
  207. continue;
  208. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  209. pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
  210. if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
  211. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  212. pChillerInfo->ChillerSwitch = YES;
  213. pChillerInfo->ChillerOnTime = time((time_t *)NULL);
  214. } else {
  215. if(pChillerInfo->ChillerSwitch == YES) {
  216. //10分鐘後停止
  217. if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
  218. pChillerInfo->ChillerSwitch = NO;
  219. ShmDcCommonData->FanOnTime = time((time_t*)NULL);
  220. }
  221. } else {
  222. pChillerInfo->ChillerSwitch = NO;
  223. ShmFanModuleData->SetFan1Speed = 0;
  224. }
  225. }
  226. // 檢查Chiller溫度點,若小於零下時開啟heater,大於10度時關閉heater
  227. if (pDcChargingInfo->ChillerTemp < 70) {
  228. pGpio->AC_Breaker = YES;
  229. } else if(pDcChargingInfo->ChillerTemp > 75) {
  230. pGpio->AC_Breaker = NO;
  231. }
  232. //log_info("Gun%d Set Heater %s", gunIndex, pGpio->AC_Breaker ? "ON" : "OFF");
  233. }
  234. uint8_t _chillerNeedOn = NO;
  235. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
  236. {
  237. pChillerInfo = (ChillerInfo*)&fChillerInfo[gunIndex];
  238. if (pChillerInfo->ChillerSwitch == YES) {
  239. _chillerNeedOn = YES;
  240. ShmFanModuleData->SetFan1Speed = 7000;
  241. }
  242. }
  243. /*
  244. if (ShmDcCommonData->debugflag == YES)
  245. _chillerNeedOn = ShmDcCommonData->chillerCtrl;
  246. */
  247. if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
  248. _chillerNeedOn = NO;
  249. }
  250. if(_chiller.ChillerSwitch != _chillerNeedOn) {
  251. log_info("Chiller Need Turn %s", _chillerNeedOn == YES ? "ON" : "OFF");
  252. }
  253. _chiller.ChillerSwitch = _chillerNeedOn;
  254. pGpio->AC_Connector = _chiller.ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
  255. }
  256. void SetOutputGpio(int fd, uint8_t outputValue)
  257. {
  258. Gpio_out gpio;
  259. LedConfig *pLedConfig = (LedConfig *)&outputValue;
  260. static uint8_t flash = NO;
  261. if (strcmp((char *)pSysInfo->LcmHwRev, " ") == 0x00) {
  262. if (flash == NO) {
  263. flash = YES;
  264. } else {
  265. flash = NO;
  266. }
  267. } else {
  268. if (flash == NO) {
  269. flash = YES;
  270. }
  271. }
  272. pLedConfig->LeftButtonLed = flash;
  273. pLedConfig->RightButtonLed = flash;
  274. gpio.Button_LED[0] = pLedConfig->LeftButtonLed;
  275. gpio.Button_LED[1] = pLedConfig->RightButtonLed;
  276. #if defined DD360ComBox
  277. gpio.System_LED[0] = pLedConfig->GreenLED;
  278. gpio.System_LED[1] = pLedConfig->YellowLED;
  279. gpio.System_LED[2] = pLedConfig->RedLED;
  280. gpio.System_LED[3] = 0x00;
  281. #else
  282. if (_isNeedChkTilt) {
  283. gpio.System_LED[0] = 0x00;
  284. gpio.System_LED[1] = 0x00;
  285. gpio.System_LED[2] = tilt;
  286. gpio.System_LED[3] = tilt;
  287. }
  288. #endif
  289. checkChillerStatus(&gpio);
  290. //gpio.AC_Breaker = 0x01;
  291. Config_Gpio_Output(fd, OP_ADDR_IO_EXTEND, &gpio);
  292. }
  293. void SetRtcData(int fd)
  294. {
  295. Rtc rtc = {0};
  296. struct timeb csuTime;
  297. struct tm *tmCSU;
  298. ftime(&csuTime);
  299. tmCSU = localtime(&csuTime.time);
  300. //log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ",
  301. // tmCSU->tm_year + 1900,
  302. // tmCSU->tm_mon + 1,
  303. // tmCSU->tm_mday,
  304. // tmCSU->tm_hour,
  305. // tmCSU->tm_min,
  306. // tmCSU->tm_sec);
  307. rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
  308. rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
  309. rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
  310. rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
  311. rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
  312. rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
  313. rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
  314. rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
  315. rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
  316. rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
  317. rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
  318. rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
  319. rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
  320. rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
  321. if (Config_Rtc_Data(fd, OP_ADDR_IO_EXTEND, &rtc) == PASS) {
  322. //log_info("SetRtc sucessfully. ");
  323. } else {
  324. //log_info("SetRtc fail. ");
  325. }
  326. }
  327. void SetModelName(int fd)
  328. {
  329. if (Config_Model_Name(fd, OP_ADDR_IO_EXTEND, pSysConfig->ModelName) == PASS) {
  330. }
  331. }
  332. //================================================
  333. // Main process
  334. //================================================
  335. int InitComPort()
  336. {
  337. int fd;
  338. struct termios tios;
  339. fd = open(priPortName, O_RDWR);
  340. if (fd <= 0) {
  341. #ifdef SystemLogMessage
  342. log_error("open 407 Communication port NG ");
  343. #endif
  344. return -1;
  345. }
  346. ioctl (fd, TCGETS, &tios);
  347. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  348. tios.c_lflag = 0;
  349. tios.c_iflag = 0;
  350. tios.c_oflag = 0;
  351. tios.c_cc[VMIN] = 0;
  352. tios.c_cc[VTIME] = (uint8_t)1;
  353. tios.c_lflag = 0;
  354. tcflush(fd, TCIFLUSH);
  355. ioctl (fd, TCSETS, &tios);
  356. return fd;
  357. }
  358. int GetTimeoutValue(struct timespec *startTime)
  359. {
  360. struct timespec endTime;
  361. clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
  362. return endTime.tv_sec - startTime->tv_sec;
  363. }
  364. void GetTimespecFunc(struct timespec *time)
  365. {
  366. clock_gettime(CLOCK_MONOTONIC_COARSE, time);
  367. }
  368. static bool IsPrimaryProcessNeedPause(void)
  369. {
  370. bool _pause = false;
  371. static bool isPause = false;
  372. struct ChargingInfoData *pDcChargingInfo = NULL;
  373. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++)
  374. {
  375. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  376. if(pDcChargingInfo->SystemStatus == S_UPDATE)
  377. {
  378. _pause = true;
  379. }
  380. }
  381. if(isPause != _pause)
  382. {
  383. log_info("Primary Process Now Is %s ", _pause == true ? "Paused" : "Continued");
  384. }
  385. isPause = _pause;
  386. return _pause;
  387. }
  388. bool CheckCustomer()
  389. {
  390. bool result = false;
  391. char _buf[3] = {0};
  392. memcpy(_buf, &pSysConfig->ModelName[12], 2);
  393. if (strcmp(_buf, "OL") == EQUAL)
  394. result = true;
  395. return result;
  396. }
  397. void TiltSensorSwitch(bool _switch)
  398. {
  399. if (tilt != _switch)
  400. tilt = _switch;
  401. }
  402. bool isChargingStatus(unsigned char status)
  403. {
  404. if ((status >= S_REASSIGN_CHECK && status <= S_ALARM) ||
  405. status == S_CCS_PRECHARGE_ST0 || status == S_CCS_PRECHARGE_ST1 ) {
  406. return TRUE;
  407. } else {
  408. return FALSE;
  409. }
  410. }
  411. void ChkTiltSensor(fd)
  412. {
  413. struct ChargingInfoData *pDcChargingInfo = NULL;
  414. bool isCharing = NO;
  415. Gpio_in gpio_in = {0};
  416. if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) != PASS) {
  417. return;
  418. }
  419. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++)
  420. {
  421. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  422. if (isChargingStatus(pDcChargingInfo->SystemStatus) || ShmPrimaryMcuData->SelfTest_Comp != PASS) {
  423. isCharing = YES;
  424. }
  425. }
  426. if (isCharing == YES)
  427. {
  428. if (_chargeSwitch == NO)
  429. {
  430. if (ShmDcCommonData->_tiltSensorStep == _TILT_SENSOR_STEP_NONE)
  431. {
  432. log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_ON ---- ");
  433. ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_ON;
  434. _chargeSwitch = YES;
  435. }
  436. }
  437. else
  438. {
  439. switch (ShmDcCommonData->_tiltSensorStep)
  440. {
  441. case _TILT_SENSOR_STEP_PIN_ON:
  442. {
  443. TiltSensorSwitch(YES);
  444. GetTimespecFunc(&_tilt_time);
  445. log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_WAIT ---- ");
  446. ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_WAIT;
  447. }
  448. break;
  449. case _TILT_SENSOR_STEP_PIN_WAIT:
  450. {
  451. int _time = GetTimeoutValue(&_tilt_time);
  452. if (_time < 0)
  453. GetTimespecFunc(&_tilt_time);
  454. else if (_time > 1)
  455. {
  456. if (gpio_in.Door_Open == NO)
  457. pAlarmCode->AlarmEvents.bits.TiltSensorStestFail = YES;
  458. else
  459. pAlarmCode->AlarmEvents.bits.TiltSensorStestFail = NO;
  460. if (_time > TILTSENSORDET)
  461. {
  462. GetTimespecFunc(&_tilt_time);
  463. log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_OFF ---- ");
  464. log_info("---- Tilt Sensor : _TILT_SENSOR_TEST %s ---- ",
  465. pAlarmCode->AlarmEvents.bits.TiltSensorStestFail ? "FAIL" : "PASS");
  466. ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_OFF;
  467. }
  468. }
  469. }
  470. break;
  471. case _TILT_SENSOR_STEP_PIN_OFF:
  472. {
  473. TiltSensorSwitch(NO);
  474. GetTimespecFunc(&_tilt_time);
  475. log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_FINISH ---- ");
  476. ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_FINISH;
  477. }
  478. break;
  479. case _TILT_SENSOR_STEP_PIN_FINISH :
  480. {
  481. int _time = GetTimeoutValue(&_tilt_time);
  482. if (_time < 0)
  483. GetTimespecFunc(&_tilt_time);
  484. else if (_time > TILTSENSORDET)
  485. {
  486. log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_NONE ---- ");
  487. ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_NONE;
  488. ShmPrimaryMcuData->SelfTest_Comp = PASS;
  489. }
  490. }
  491. break;
  492. }
  493. }
  494. }
  495. else
  496. {
  497. TiltSensorSwitch(NO);
  498. ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_NONE;
  499. _chargeSwitch = NO;
  500. //log_info("ShmPrimaryMcuData->SelfTest_Comp:%d",ShmPrimaryMcuData->SelfTest_Comp);
  501. }
  502. return;
  503. }
  504. int main(void)
  505. {
  506. int Uart1Fd = -1;
  507. //if (InitShareMemory() == FAIL) {
  508. // log_error("InitShareMemory NG");
  509. // if (ShmStatusCodeData != NULL) {
  510. // pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = 1;
  511. // }
  512. // sleep(5);
  513. // return 0;
  514. //}
  515. if (CreateAllCsuShareMemory() == FAIL) {
  516. log_error("create share memory error");
  517. return FAIL;
  518. }
  519. MappingGunChargingInfo("Primary Task");
  520. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  521. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  522. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  523. pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
  524. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  525. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  526. Uart1Fd = InitComPort();
  527. //log_info("407 Port id = %d ", Uart1Fd);
  528. if (Uart1Fd < 0) {
  529. log_error("InitComPort (Uart1 : AM3352 - STM32) NG");
  530. if (pAlarmCode != NULL) {
  531. pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
  532. }
  533. sleep(5);
  534. return 0;
  535. }
  536. SetRtcData(Uart1Fd);
  537. SetModelName(Uart1Fd);
  538. gun_count = pSysConfig->TotalConnectorCount;
  539. //Initialization();
  540. // 需要判斷這個的客戶碼 : OL
  541. //_isNeedChkTilt = CheckCustomer();
  542. for (;;) {
  543. // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
  544. // 模組更新 FW 後,需重新做
  545. if(IsPrimaryProcessNeedPause() == true)
  546. {
  547. sleep(1);
  548. continue;
  549. }
  550. if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
  551. //log_info("(407) Get Fw and Hw Ver. ");
  552. if (GetFwAndHwVersion(Uart1Fd) != PASS ) {
  553. sleep(1);
  554. continue;
  555. }
  556. if (_isNeedChkTilt) {
  557. ChkTiltSensor(Uart1Fd);
  558. } else {
  559. ShmPrimaryMcuData->SelfTest_Comp = PASS;
  560. }
  561. } else {
  562. if (_isNeedChkTilt) {
  563. ChkTiltSensor(Uart1Fd);
  564. }
  565. SetOutputGpio(Uart1Fd, ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
  566. GetInputGpioStatus(Uart1Fd);
  567. }
  568. usleep(50000);
  569. }
  570. return FAIL;
  571. }