Module_EvRxComm.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <sys/stat.h>
  8. #include <linux/can.h>
  9. #include <linux/can/raw.h>
  10. #include "../Config.h"
  11. #include "../Log/log.h"
  12. #include "../Define/define.h"
  13. #include "../ShareMemory/shmMem.h"
  14. #include "Ev_Comm.h"
  15. #include "Module_EvComm.h"
  16. //------------------------------------------------------------------------------
  17. static struct SysConfigData *pSysConfig = NULL;
  18. static struct SysInfoData *pSysInfo = NULL;
  19. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  20. static struct AlarmCodeData *pAlarmCode = NULL;
  21. static struct CHAdeMOData *ShmCHAdeMOData = NULL;
  22. static struct GBTData *ShmGBTData = NULL;
  23. static struct CcsData *ShmCcsData = NULL;
  24. static struct FanModuleData *ShmFanModuleData = NULL;
  25. static DcCommonInfo *ShmDcCommonData = NULL;
  26. #define TempArraySize 10
  27. uint8_t TempArray_1[TempArraySize]={0};
  28. uint8_t TempArray_2[TempArraySize]={0};
  29. uint8_t ptemp_1 = 0;
  30. uint8_t ptemp_2 = 0;
  31. bool firstcircule = true;
  32. float EvTargetVolt[2] = { 0 };
  33. float EvTargetCur[2] = { 0 };
  34. //------------------------------------------------------------------------------
  35. extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
  36. //------------------------------------------------------------------------------
  37. /*static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
  38. uint8_t chillerTemp1, uint8_t chillerTemp2)
  39. {
  40. uint8_t i = 0;
  41. uint8_t tempSource[4] = {headTemp1, headTemp2, chillerTemp1, chillerTemp2};
  42. uint8_t maxTemp = 0;
  43. if (headTemp1 == UNDEFINED_TEMP &&
  44. headTemp2 == UNDEFINED_TEMP &&
  45. chillerTemp1 == UNDEFINED_TEMP &&
  46. chillerTemp2 == UNDEFINED_TEMP) {
  47. return UNDEFINED_TEMP;
  48. }
  49. //先取得第一個非UNDEFINED_TEMP的值
  50. for (i = 0; i < (sizeof(tempSource) / sizeof(uint8_t)); i++) {
  51. if (tempSource[i] != UNDEFINED_TEMP) {
  52. maxTemp = tempSource[i];
  53. break;
  54. }
  55. }
  56. //找最大的溫度值
  57. for (i = 0; i < (sizeof(tempSource) / sizeof(uint8_t)); i++) {
  58. if (tempSource[i] != UNDEFINED_TEMP) {
  59. if (maxTemp < tempSource[i]) {
  60. maxTemp = tempSource[i];
  61. }
  62. }
  63. }
  64. return maxTemp;
  65. }
  66. */
  67. static uint8_t getAvageTemp(uint8_t value,uint8_t gun)
  68. {
  69. uint16_t avagetemp = 0;
  70. int i;
  71. uint8_t ptr = 0;
  72. uint8_t *pArray;
  73. if(gun == 0) {
  74. pArray = &TempArray_1;
  75. ptr = ptemp_1;
  76. } else {
  77. pArray = &TempArray_2;
  78. ptr = ptemp_2;
  79. }
  80. pArray[ptr] = value;
  81. for(i=0;i<TempArraySize;i++)
  82. avagetemp+=pArray[i];
  83. if (firstcircule) {
  84. avagetemp/=(ptr+1);
  85. } else {
  86. avagetemp/=TempArraySize;
  87. }
  88. ptr++;
  89. if(ptr >= TempArraySize){
  90. ptr = 0;
  91. firstcircule = false;
  92. }
  93. if(gun == 0 )
  94. ptemp_1 = ptr;
  95. else
  96. ptemp_2 = ptr;
  97. if(avagetemp > TEMP_BOUNDARY)
  98. return UNDEFINED_TEMP;
  99. return avagetemp;
  100. }
  101. static uint8_t getMaxConnectTemp(uint8_t headTemp1, uint8_t headTemp2)
  102. {
  103. uint8_t maxTemp = 0;
  104. if (headTemp1 > TEMP_BOUNDARY &&
  105. headTemp2 > TEMP_BOUNDARY) {
  106. return UNDEFINED_TEMP;
  107. }
  108. if (headTemp1 <= TEMP_BOUNDARY) {
  109. maxTemp = headTemp1;
  110. }
  111. if (headTemp2 <= TEMP_BOUNDARY) {
  112. if (headTemp2 > maxTemp) {
  113. maxTemp = headTemp2;
  114. }
  115. }
  116. return maxTemp;
  117. }
  118. static float ReadAdcVolt(uint8_t AdcChannel)
  119. {
  120. //AIN0=CCS GUN Temp 1
  121. //AIN1=CCS GUN Temp 2
  122. //AIN2=CCS_Proximity/2
  123. //AIN3=pilot voltage
  124. int fd = -1;
  125. uint8_t str[64] = {0};
  126. uint8_t AdcValue[8] = {'\0'};
  127. if (AdcChannel > 7) {
  128. return -1;
  129. }
  130. sprintf((char *)str, "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw", AdcChannel);
  131. fd = open((char *)str, O_RDONLY);
  132. read(fd, AdcValue, 4);
  133. close(fd);
  134. return (1.8 * atoi((char *)&AdcValue[0])) / 4095;
  135. //return (1.8 * atoi((char *)&AdcValue)) / 4095;
  136. }
  137. static void getChillerTemperature(ChillerTemp *chillerTemp)
  138. {
  139. uint8_t i = 0;
  140. float adcVoltage = 0.0;
  141. ChillerTemp *pChillerTemp = (ChillerTemp *)chillerTemp;
  142. for (i = 0; i < 4; i++) {
  143. adcVoltage = 0.0;
  144. adcVoltage = ReadAdcVolt(i);
  145. if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
  146. pChillerTemp->Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
  147. //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
  148. } else if ((adcVoltage <= 1.07) && (adcVoltage > 0.9)) {
  149. pChillerTemp->Temp[i] = ((adcVoltage - 0.91) * 705.88) + 60;
  150. //log_info("2 adcVoltage = %f", (adcVoltage - 0.9) * 500);
  151. } else {
  152. pChillerTemp->Temp[i] = UNDEFINED_TEMP;
  153. }
  154. /*CcsConnectorTemp1 = ReadAdcVolt(i);
  155. if ((CcsConnectorTemp1 <= 0.9) && (CcsConnectorTemp1 >= 0.8)) { //0 ~ -40
  156. CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 500;
  157. } else if ((CcsConnectorTemp1 <= 1.07) && (CcsConnectorTemp1 > 0.9)) {
  158. CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 705.88;
  159. } else {
  160. CcsConnectorTemp1 = 195; //not available
  161. }
  162. CcsConnectorTemp |= ((unsigned int)(CcsConnectorTemp1 + 60) & 0xFF) << (i * 8); //0x00(-60)~0xFE(194)
  163. */
  164. }
  165. }
  166. static void AddrAssignment(uint8_t *data)
  167. {
  168. uint8_t target_number[8];
  169. uint8_t index = 0x00;
  170. struct ChargingInfoData *pDcChargingInfo = NULL;
  171. memcpy(target_number, data, sizeof(target_number));
  172. index = *(data + 4);
  173. if (pSysConfig->TotalConnectorCount == 1) {
  174. index = 0x01;
  175. }
  176. //if (CheckUniqNumber(index)) {
  177. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index - 1);
  178. //DS60-120 add
  179. if (pDcChargingInfo->Type == _Type_Chademo) {
  180. log_info("Set EV board info : (Chademo) TargetAddr = %d ", index);
  181. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  182. log_info("Set EV board info : (CCS) TargetAddr = %d ", index);
  183. } else if (pDcChargingInfo->Type == _Type_GB) {
  184. log_info("Set EV board info : (GB) TargetAddr = %d ", index);
  185. }
  186. //log_info("EV board id = %x ", index); //DS60-120 remove
  187. //log_info("target_number[0] = %x ", target_number[0]);
  188. //log_info("target_number[1] = %x ", target_number[1]);
  189. //log_info("target_number[2] = %x ", target_number[2]);
  190. //log_info("target_number[3] = %x ", target_number[3]);
  191. //log_info("target_number[4] = %x ", target_number[4]);
  192. log_info("SetTargetAddr = %d, type = %d ", index, pDcChargingInfo->Type);
  193. SetTargetAddr(target_number, index);
  194. //}
  195. }
  196. void CheckEvConnect(int gunIndex)
  197. {
  198. int isSameType = FALSE;
  199. int isDisconnect = FALSE;
  200. int gunType = _Type_CCS_2;
  201. struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
  202. struct InfoCodeData* pInfoCode = (struct InfoCodeData*)GetShmInfoCodeData();
  203. struct ChargingInfoData* pDcChargingInfo_0 = (struct ChargingInfoData*)GetDcChargingInfoData(0);
  204. struct ChargingInfoData* pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(1);
  205. if (pDcChargingInfo_0->Type == pDcChargingInfo_1->Type) {
  206. isSameType = TRUE;
  207. isDisconnect = ShmDcCommonData->pGunInfo[0].EVLoseFlag | ShmDcCommonData->pGunInfo[1].EVLoseFlag;
  208. gunType = pDcChargingInfo_0->Type;
  209. } else {
  210. isDisconnect = ShmDcCommonData->pGunInfo[gunIndex].EVLoseFlag;
  211. gunType = pDcChargingInfo->Type;
  212. }
  213. //log_info("ShmDcCommonData->EVDisconnectFlag[%d]:%d", gunIndex, ShmDcCommonData->EVDisconnectFlag[gunIndex]);
  214. if (isDisconnect) {
  215. switch (gunType) {
  216. case _Type_Chademo:
  217. pInfoCode->InfoEvents.bits.ChademoEvCommFail = YES;
  218. break;
  219. case _Type_CCS_2:
  220. pInfoCode->InfoEvents.bits.CcsEvCommFail = YES;
  221. break;
  222. case _Type_GB:
  223. pInfoCode->InfoEvents.bits.GbEvCommFail = YES;
  224. break;
  225. }
  226. } else {
  227. switch (gunType) {
  228. case _Type_Chademo:
  229. pInfoCode->InfoEvents.bits.ChademoEvCommFail = NO;
  230. break;
  231. case _Type_CCS_2:
  232. pInfoCode->InfoEvents.bits.CcsEvCommFail = NO;
  233. break;
  234. case _Type_GB:
  235. pInfoCode->InfoEvents.bits.GbEvCommFail = NO;
  236. break;
  237. }
  238. }
  239. }
  240. void CANReceiver(int fd)
  241. {
  242. pid_t canRecPid;
  243. canRecPid = fork();
  244. if (canRecPid < 0) {
  245. log_error("Create CAN Bus receive task failed");
  246. return;
  247. }
  248. if (canRecPid == 0) {
  249. int isContinue = 1;
  250. int nbytes;
  251. int intCmd;
  252. uint8_t _index = 0;
  253. uint8_t recvID = 0;
  254. uint8_t targetGun = 0x00;
  255. uint8_t gunTypeIndex = 0;
  256. uint8_t ver[16] = {0};
  257. uint8_t printChillerTemp = NO;
  258. uint8_t printConnTemp = NO;
  259. uint8_t chillerTemp[2] = {0, 0};
  260. uint8_t maxChillerTemp = 0;
  261. uint8_t lastChillerTemp = 0;
  262. uint8_t maxConnTemp = 0;
  263. uint8_t lastConnTemp[2] = {0, 0};
  264. struct can_frame frame;
  265. ChillerTemp chiilerTemp = {0};
  266. time_t CCS_PlugoutTimer[2] = { 0 };
  267. struct ChargingInfoData *pDcChargingInfo = NULL;
  268. int len = 0;
  269. char _info[1024];
  270. int i;
  271. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  272. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  273. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  274. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  275. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  276. ShmGBTData = (struct GBTData *)GetShmGBTData();
  277. ShmCcsData = (struct CcsData *)GetShmCcsData();
  278. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  279. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  280. ShmDcCommonData->pGunInfo[0].EVLoseTimer = time((time_t*)NULL);
  281. ShmDcCommonData->pGunInfo[1].EVLoseTimer = time((time_t*)NULL);
  282. //log_info("Module_EvRXComm Child's PID is %d", getpid());
  283. CCS_PlugoutTimer[0] = time((time_t*)NULL);
  284. CCS_PlugoutTimer[1] = time((time_t*)NULL);
  285. while (isContinue) {
  286. memset(&frame, 0, sizeof(struct can_frame));
  287. for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  288. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
  289. // 檢查是否有收到EV小板訊號
  290. if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
  291. if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 5) &&
  292. !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
  293. pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
  294. ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
  295. ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
  296. system("/sbin/ip link set can0 down");
  297. sleep(1);
  298. system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
  299. system("/sbin/ip link set can0 up");
  300. }
  301. CheckEvConnect(_index);
  302. } else {
  303. ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
  304. ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
  305. }
  306. }
  307. nbytes = read(fd, &frame, sizeof(struct can_frame));
  308. if (nbytes <= 0) {
  309. usleep(10000);
  310. continue;
  311. }
  312. recvID = 0;
  313. targetGun = 0x00;
  314. intCmd = (int) (frame.can_id & CAN_EFF_MASK);
  315. if (intCmd == ADDRESS_REQ) {
  316. //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
  317. AddrAssignment(frame.data);
  318. continue;
  319. }
  320. intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
  321. recvID = ((uint8_t) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
  322. if (ShmDcCommonData->showCanPackage) {
  323. len = 0;
  324. len += sprintf(&_info[len], "CAN Dispenser <= EV Rx:\t[0x%X] ", frame.can_id);
  325. for (i = 0; i < nbytes; i++) {
  326. len += sprintf(&_info[len], "%X ", frame.data[i]);
  327. }
  328. len += sprintf(&_info[len], "\n");
  329. printf("%s", _info);
  330. }
  331. for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) { // 假設有找到回應的 Index
  332. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  333. //if (gun_count == 1 &&
  334. // _chargingData[_index]->Type == _Type_CCS_2 &&
  335. // ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
  336. // target -= 1;
  337. //}
  338. if (pDcChargingInfo->Evboard_id == recvID) {
  339. targetGun = _index;
  340. break;
  341. }
  342. }
  343. if ((targetGun < 0) || (targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)) {
  344. log_info("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY ", targetGun);
  345. usleep(10000);
  346. continue;
  347. }
  348. //else if (gun_count == 1 && targetGun == 0 && findIndex == 1 &&
  349. // ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
  350. // // 這樣的條件下~ 也是單槍 CCS 舊版本的狀況 : 因為舊版 CCS 不會 timeout, then send request id
  351. // ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
  352. //}
  353. if (intCmd == 256) {
  354. log_info("EvComm command = 256");
  355. usleep(10000);
  356. continue;
  357. }
  358. // Reset Connect Timer
  359. ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
  360. ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
  361. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
  362. gunTypeIndex = pDcChargingInfo->type_index;
  363. switch (intCmd) {
  364. case NOTIFICATION_EV_STATUS:
  365. if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) {
  366. if (frame.data[0] == PLUG) {
  367. log_info("Conn %d, Plugin. ", targetGun);
  368. pDcChargingInfo->isEVCCIDVerify = false;
  369. #ifdef DD360Audi
  370. if (pSysConfig->isAuthrizeByEVCCID)
  371. pSysInfo->CurGunSelected = targetGun;
  372. #endif
  373. } else if (frame.data[0] == UNPLUG) {
  374. if (pDcChargingInfo->Type != _Type_CCS_2)
  375. log_info("Conn %d, Unplug. ", targetGun);
  376. strcpy( (char *) pDcChargingInfo->EVCCID, "");
  377. } else {
  378. log_info("Conn %d, None Check. (%d) ", targetGun, frame.data[0]);
  379. }
  380. if(pDcChargingInfo->RemoteStartFlag == YES) {
  381. pSysInfo->CurGunSelected = targetGun;
  382. }
  383. }
  384. pDcChargingInfo->PilotVoltage = frame.data[1];
  385. // CCS 小板確認Pilot Voltage != 0
  386. if (pDcChargingInfo->Type == _Type_CCS_2 && pDcChargingInfo->PilotVoltage != 0) {
  387. if (frame.data[0] == UNPLUG && pDcChargingInfo->ConnectorPlugIn != frame.data[0])
  388. log_info("Conn %d, Unplug. ", targetGun);
  389. pDcChargingInfo->ConnectorPlugIn = frame.data[0];
  390. } else {
  391. pDcChargingInfo->ConnectorPlugIn = frame.data[0];
  392. }
  393. //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x ",
  394. // targetGun,
  395. // pDcChargingInfo->ConnectorPlugIn,
  396. // frame.data[0]);
  397. //log_info("ConnectorPlugIn = %x ", (-120 + frame.data[1]) / 10);
  398. break;
  399. case ACK_EV_FW_VERSION:
  400. memset(ver, 0, sizeof(ver));
  401. if (pDcChargingInfo->Type == _Type_Chademo) {
  402. memcpy(ver, frame.data, frame.can_dlc);
  403. memcpy(ShmCHAdeMOData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  404. ShmCHAdeMOData->evse[gunTypeIndex].SelfTest_Comp = PASS;
  405. log_info("chademo ver. : %s", ShmCHAdeMOData->evse[gunTypeIndex].version);
  406. } else if (pDcChargingInfo->Type == _Type_GB) {
  407. memcpy(ver, frame.data, frame.can_dlc);
  408. memcpy(ShmGBTData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  409. ShmGBTData->evse[gunTypeIndex].SelfTest_Comp = PASS;
  410. log_info("gbt ver. : %s", ShmGBTData->evse[gunTypeIndex].version);
  411. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  412. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  413. memcpy(ver, frame.data, frame.can_dlc); //DS60-120 add
  414. //for (uint8_t _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++) {//DS60-120 remove
  415. /*if (_vCount % 2 == 0 && _vCount != 0)
  416. {
  417. ver[_vCount + _vPoint] = 0x2E;
  418. _vPoint++;
  419. }*/
  420. //ver[_vCount + _vPoint] = frame.data[_vCount];
  421. //}
  422. memcpy(&ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  423. ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].SelfTest_Comp = PASS;
  424. log_info("CCS FW = %s ", ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version);
  425. }
  426. }
  427. if (targetGun == 0) {
  428. memset(pSysInfo->Connector1FwRev,
  429. 0,
  430. sizeof(pSysInfo->Connector1FwRev));
  431. memcpy(pSysInfo->Connector1FwRev, ver, ARRAY_SIZE(ver));
  432. } else if (targetGun == 1) {
  433. memset(pSysInfo->Connector2FwRev,
  434. 0,
  435. sizeof(pSysInfo->Connector2FwRev));
  436. memcpy(pSysInfo->Connector2FwRev, ver, ARRAY_SIZE(ver));
  437. }
  438. break;
  439. case ACK_EV_HW_VERSION:
  440. //log_info("Get EV HW = %s ", frame.data);
  441. break;
  442. case ACK_GET_OUTPUT_REQ:
  443. //DS60-120 add
  444. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
  445. pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  446. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  447. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  448. ) {
  449. if (pDcChargingInfo->EvBatteryStartSoc <= 0 &&
  450. pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE) {
  451. pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
  452. }
  453. if (frame.data[1] > pDcChargingInfo->EvBatterySoc) {
  454. pDcChargingInfo->EvBatterySoc = frame.data[1];
  455. log_info("Gun%d SOC:%d", targetGun,pDcChargingInfo->EvBatterySoc);
  456. }
  457. }
  458. //pDcChargingInfo->EvBatterySoc = frame.data[1]; //DS60-120 remove
  459. //Jerry add set voltage limit
  460. pDcChargingInfo->EvBatterytargetVoltage = (float)((frame.data[3] << 8) + frame.data[2]) / 10;
  461. if (pDcChargingInfo->EvBatterytargetVoltage > (GetMaxChargingVol(targetGun) * 0.1)) {
  462. pDcChargingInfo->EvBatterytargetVoltage = (GetMaxChargingVol(targetGun) * 0.1);
  463. }
  464. //printf("id = %d, EvBatterytargetVoltage = %.2f", targetGun, pDcChargingInfo->EvBatterytargetVoltage);
  465. //Jerry add set currency limit
  466. pDcChargingInfo->EvBatterytargetCurrent = (float)((frame.data[5] << 8) + frame.data[4]) / 10;
  467. if (pDcChargingInfo->EvBatterytargetCurrent > (GetMaxCharginigCur(targetGun) * 0.1)) {
  468. pDcChargingInfo->EvBatterytargetCurrent = (GetMaxCharginigCur(targetGun) * 0.1);
  469. }
  470. //printf("id = %d, EvBatterytargetCurrent = %.2f", targetGun, pDcChargingInfo->EvBatterytargetCurrent);
  471. pDcChargingInfo->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
  472. //printf("RemainChargingDuration = %d", pDcChargingInfo->RemainChargingDuration);
  473. if (pDcChargingInfo->Type == _Type_Chademo) {
  474. if (ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
  475. log_info("Gun%d CHAdeMO board status = %d ", targetGun, ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus);
  476. ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  477. }
  478. ShmCHAdeMOData->ev[gunTypeIndex].EvDetection = frame.data[0];
  479. ShmCHAdeMOData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
  480. ShmCHAdeMOData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
  481. ShmCHAdeMOData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
  482. } else if (pDcChargingInfo->Type == _Type_GB) {
  483. if (ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
  484. log_info("Gun%d GB Board status = %d ", targetGun, ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
  485. ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  486. }
  487. ShmGBTData->ev[gunTypeIndex].EvDetection = frame.data[0];
  488. ShmGBTData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
  489. ShmGBTData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
  490. ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
  491. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  492. if (ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus != frame.data[0] && frame.data[0] != 0xFF) {
  493. log_info("Gun%d CCS board status = %d ", targetGun, ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus);
  494. ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  495. }
  496. }
  497. if (pDcChargingInfo->EvBatterytargetVoltage > (EvTargetVolt[targetGun] + 5) ||
  498. pDcChargingInfo->EvBatterytargetVoltage < (EvTargetVolt[targetGun] - 5) ||
  499. pDcChargingInfo->EvBatterytargetCurrent >(EvTargetCur[targetGun] + 2) ||
  500. pDcChargingInfo->EvBatterytargetCurrent < (EvTargetCur[targetGun] - 2)) {
  501. log_info("Gun%d TargetVoltage = %f , TargetCurrent = %f",
  502. targetGun, pDcChargingInfo->EvBatterytargetVoltage, pDcChargingInfo->EvBatterytargetCurrent);
  503. EvTargetVolt[targetGun] = pDcChargingInfo->EvBatterytargetVoltage;
  504. EvTargetCur[targetGun] = pDcChargingInfo->EvBatterytargetCurrent;
  505. }
  506. //log_info("EvBatterytargetVoltage = %f ", pDcChargingInfo->EvBatterytargetVoltage);
  507. //log_info("EvBatterytargetCurrent = %f ", pDcChargingInfo->EvBatterytargetCurrent);
  508. //log_info("BatteryVoltage = %d ",
  509. // ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
  510. //log_info("CurrentRequest = %d ",
  511. // ShmCHAdeMOData->ev[_chargingData[target]->type_index].ChargingCurrentRequest);
  512. break;
  513. case ACK_GET_EV_BATTERY_INFO:
  514. //_chargingData[target].EvACorDCcharging = frame.data[0];
  515. //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
  516. pDcChargingInfo->EvBatteryMaxVoltage = ((float)(((uint16_t)frame.data[4] << 8) + (uint16_t)frame.data[3])) / 10;
  517. //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
  518. //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
  519. if (pDcChargingInfo->Type == _Type_Chademo) {
  520. ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
  521. ShmCHAdeMOData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
  522. //log_info("EvBatteryMaxVoltage = %f ", _chargingData[target]->EvBatteryMaxVoltage);
  523. //log_info("TotalBatteryCapacity = %d ", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
  524. //log_info("MaxiBatteryVoltage = %d ", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
  525. } else if (pDcChargingInfo->Type == _Type_GB) {
  526. ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
  527. ShmGBTData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
  528. }
  529. //else if (pDcChargingInfo->Type == _Type_CCS_2) {
  530. //}
  531. break;
  532. case ACK_GET_MISCELLANEOUS_INFO:
  533. pDcChargingInfo->GunLocked = frame.data[0];
  534. pDcChargingInfo->PilotVoltage = ((float)(-120 + frame.data[3])) / 10;
  535. if (pDcChargingInfo->Type == _Type_Chademo) {
  536. ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
  537. ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
  538. ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
  539. } else if (pDcChargingInfo->Type == _Type_GB) {
  540. ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
  541. ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
  542. ShmGBTData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
  543. }
  544. /*else if (pDcChargingInfo->Type == _Type_CCS_2) {
  545. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  546. //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureP = frame.data[1];
  547. //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureN = frame.data[2];
  548. }
  549. }*/
  550. ShmDcCommonData->ConnectorTemp[gunTypeIndex][0] = frame.data[1];
  551. ShmDcCommonData->ConnectorTemp[gunTypeIndex][1] = frame.data[2];
  552. if (ShmDcCommonData->TestTemperature == YES) { //ReadCmdline test
  553. break;
  554. }
  555. printChillerTemp = NO;
  556. printConnTemp = NO;
  557. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  558. getChillerTemperature(&chiilerTemp);
  559. memcpy((char *)ShmDcCommonData->SystemTemp, (char *)chiilerTemp.Temp, sizeof(ChillerTemp));
  560. chillerTemp[0] = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
  561. chillerTemp[1] = getMaxConnectTemp(chiilerTemp.Temp[2], chiilerTemp.Temp[3]);
  562. maxChillerTemp = getMaxConnectTemp(chillerTemp[0], chillerTemp[1]);
  563. //if ((maxChillerTemp - 3) >= pDcChargingInfo->ChillerTemp) {
  564. // printChillerTemp = YES;
  565. //}
  566. if(maxChillerTemp > (lastChillerTemp + 2) || maxChillerTemp < (lastChillerTemp - 2))
  567. {
  568. lastChillerTemp = maxChillerTemp;
  569. printChillerTemp = YES;
  570. }
  571. pDcChargingInfo->ChillerTemp = maxChillerTemp;
  572. }
  573. if (ShmDcCommonData->ConnectorTemp[gunTypeIndex][0] != 0 && ShmDcCommonData->ConnectorTemp[gunTypeIndex][1] != 0) {
  574. maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
  575. //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
  576. // printConnTemp = YES;
  577. //}
  578. maxConnTemp = getAvageTemp(maxConnTemp, targetGun);
  579. if (maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
  580. {
  581. lastConnTemp[targetGun] = maxConnTemp;
  582. printConnTemp = YES;
  583. }
  584. pDcChargingInfo->ConnectorTemp = maxConnTemp;
  585. } else {
  586. //log_info("Connector%d Tmep is zero:[%d,%d]", gunTypeIndex, ShmDcCommonData->ConnectorTemp[gunTypeIndex][0],
  587. // ShmDcCommonData->ConnectorTemp[gunTypeIndex][1]);
  588. }
  589. //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
  590. if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
  591. (printConnTemp == YES) ||
  592. (printChillerTemp == YES) //&&
  593. //(((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
  594. // (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
  595. // ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
  596. // (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
  597. ) {
  598. ShmDcCommonData->SystemModeChange[targetGun] = NO;
  599. log_info("Conn %d max temp = %d, chiller = [%d %d], chiller2 = [%d %d]",
  600. targetGun,
  601. pDcChargingInfo->ConnectorTemp,
  602. chiilerTemp.Temp[0],
  603. chiilerTemp.Temp[1],
  604. chiilerTemp.Temp[2],
  605. chiilerTemp.Temp[3]);
  606. }
  607. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  608. //沒有水冷槍
  609. break;
  610. }
  611. if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
  612. //單一水冷槍,不需要切換水冷機油閥
  613. //ShmFanModuleData-> ? = YES; //尚未定義
  614. break;
  615. }
  616. //紀錄槍頭溫度
  617. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  618. if (targetGun == 0) {
  619. ShmDcCommonData->ChillerValve.LeftTemp = pDcChargingInfo->ConnectorTemp;
  620. } else if (targetGun == 1) {
  621. ShmDcCommonData->ChillerValve.RightTemp = pDcChargingInfo->ConnectorTemp;
  622. }
  623. }
  624. //有兩把水冷槍,判斷兩把槍頭溫度,將水冷機節流閥導向溫度高的那一把槍
  625. if (ShmDcCommonData->ChillerValve.LeftTemp > ShmDcCommonData->ChillerValve.RightTemp) {
  626. //ShmFanModuleData->? = YES; //尚未定義
  627. } else {
  628. //ShmFanModuleData->? = NO; //尚未定義
  629. }
  630. //log_info("EvboardStatus = %x ",
  631. // ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
  632. //log_info("ConnectorPlug locked = %x ",
  633. // frame.data[0]);
  634. //log_info("PilotVoltage = %x ", (-120 + frame.data[3]) / 10);
  635. break;
  636. case ACK_EVSE_ISOLATION_STATUS:
  637. break;
  638. case ACK_EVSE_PRECHAGE_INFO:
  639. pDcChargingInfo->PrechargeStatus = frame.data[0];
  640. break;
  641. case NOTIFICATION_EV_STOP:
  642. // 車端要求停止
  643. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && //DS60-120 add
  644. pDcChargingInfo->SystemStatus <= S_TERMINATING) ||
  645. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  646. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  647. // frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
  648. log_info("----------------------------- (%d) NOTIFICATION_EV_STOP err level = %d -----------------------------",
  649. targetGun,
  650. frame.data[0]);
  651. if (frame.data[0] == 0x02) {
  652. if (AbnormalStopAnalysis(targetGun, frame.data + 1) == true) {
  653. pDcChargingInfo->StopChargeFlag = YES;
  654. } else {
  655. pDcChargingInfo->NormalStopChargeFlag = YES;
  656. }
  657. } else {
  658. AbnormalStopAnalysis(targetGun, frame.data + 1);
  659. pDcChargingInfo->NormalStopChargeFlag = YES;
  660. }
  661. }
  662. break;
  663. case ACK_EVCCID_REQ:
  664. if (frame.can_dlc > 0 && strcmp ( (char *)pDcChargingInfo->EVCCID, "" ) == EQUAL &&
  665. pDcChargingInfo->Type == _Type_CCS_2)
  666. {
  667. {
  668. memset (
  669. ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID,
  670. 0,
  671. sizeof(ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID) );
  672. memcpy (
  673. ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID,
  674. frame.data, frame.can_dlc );
  675. }
  676. sprintf ( (char *) pDcChargingInfo->EVCCID, "%.2x%.2x%.2x%.2x%.2x%.2x", frame.data [0],
  677. frame.data [1], frame.data [2], frame.data [3], frame.data [4], frame.data [5] );
  678. pDcChargingInfo->EVCCID [17] = '\0';
  679. log_info( "Gun %d->EVCCID = %s ", targetGun, pDcChargingInfo->EVCCID );
  680. }
  681. break;
  682. default:
  683. log_info("EV board = %d, Ack none defined. intCmd = %d ", targetGun, intCmd);
  684. break;
  685. }//switch
  686. usleep(10000);
  687. }//while
  688. }
  689. }