Module_EvRxComm.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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[0];
  75. ptr = ptemp_1;
  76. } else {
  77. pArray = &TempArray_2[0];
  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 isDisconnect = FALSE;
  199. int gunType = _Type_CCS_2;
  200. int isSameType = FALSE;
  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->EVDisconnectFlag[0] | ShmDcCommonData->EVDisconnectFlag[1];
  208. gunType = pDcChargingInfo_0->Type;
  209. } else {
  210. isDisconnect = ShmDcCommonData->EVDisconnectFlag[gunIndex];
  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. struct ChargingInfoData *pDcChargingInfo = NULL;
  267. time_t CCS_PlugoutTimer[2];
  268. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  269. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  270. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  271. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  272. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  273. ShmGBTData = (struct GBTData *)GetShmGBTData();
  274. ShmCcsData = (struct CcsData *)GetShmCcsData();
  275. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  276. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  277. //log_info("Module_EvRXComm Child's PID is %d", getpid());
  278. CCS_PlugoutTimer[0] = time((time_t*)NULL);
  279. CCS_PlugoutTimer[1] = time((time_t*)NULL);
  280. while (isContinue) {
  281. memset(&frame, 0, sizeof(struct can_frame));
  282. for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  283. // 檢查是否有收到EV小板訊號
  284. if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
  285. if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 5) &&
  286. !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
  287. pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->DebugFlag) {
  288. ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
  289. ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
  290. system("/sbin/ip link set can0 down");
  291. sleep(1);
  292. system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
  293. system("/sbin/ip link set can0 up");
  294. }
  295. CheckEvConnect(_index);
  296. } else {
  297. ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
  298. ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
  299. }
  300. }
  301. nbytes = read(fd, &frame, sizeof(struct can_frame));
  302. if (nbytes <= 0) {
  303. usleep(10000);
  304. continue;
  305. }
  306. recvID = 0;
  307. targetGun = 0x00;
  308. intCmd = (int) (frame.can_id & CAN_EFF_MASK);
  309. if (intCmd == ADDRESS_REQ) {
  310. //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
  311. AddrAssignment(frame.data);
  312. continue;
  313. }
  314. intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
  315. recvID = ((uint8_t) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
  316. for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) { // 假設有找到回應的 Index
  317. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  318. //if (gun_count == 1 &&
  319. // _chargingData[_index]->Type == _Type_CCS_2 &&
  320. // ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
  321. // target -= 1;
  322. //}
  323. if (pDcChargingInfo->Evboard_id == recvID) {
  324. targetGun = _index;
  325. break;
  326. }
  327. }
  328. if ((targetGun < 0) || (targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)) {
  329. log_info("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY ", targetGun);
  330. usleep(10000);
  331. continue;
  332. }
  333. //else if (gun_count == 1 && targetGun == 0 && findIndex == 1 &&
  334. // ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
  335. // // 這樣的條件下~ 也是單槍 CCS 舊版本的狀況 : 因為舊版 CCS 不會 timeout, then send request id
  336. // ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
  337. //}
  338. if (intCmd == 256) {
  339. log_info("EvComm command = 256");
  340. usleep(10000);
  341. continue;
  342. }
  343. // Reset Connect Timer
  344. ShmDcCommonData->EVDisconnectTime[targetGun] = time((time_t*)NULL);
  345. ShmDcCommonData->EVDisconnectFlag[targetGun] = FALSE;
  346. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
  347. gunTypeIndex = pDcChargingInfo->type_index;
  348. switch (intCmd) {
  349. case NOTIFICATION_EV_STATUS:
  350. if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) {
  351. if (frame.data[0] == PLUG) {
  352. log_info("Conn %d, Plugin. ", targetGun);
  353. pDcChargingInfo->isEVCCIDVerify = false;
  354. #ifdef DD360Audi
  355. if (pSysConfig->EVCCID_Authorize)
  356. pSysInfo->CurGunSelected = targetGun;
  357. #endif
  358. } else if (frame.data[0] == UNPLUG) {
  359. if (pDcChargingInfo->Type != _Type_CCS_2)
  360. log_info("Conn %d, Unplug. ", targetGun);
  361. strcpy( (char *) pDcChargingInfo->EVCCID, "");
  362. } else {
  363. log_info("Conn %d, None Check. (%d) ", targetGun, frame.data[0]);
  364. }
  365. if(pDcChargingInfo->RemoteStartFlag == YES) {
  366. pSysInfo->CurGunSelected = targetGun;
  367. }
  368. }
  369. pDcChargingInfo->PilotVoltage = frame.data[1];
  370. // CCS 小板確認Pilot Voltage != 0
  371. if (pDcChargingInfo->Type == _Type_CCS_2 && pDcChargingInfo->PilotVoltage != 0) {
  372. if (frame.data[0] == UNPLUG && pDcChargingInfo->ConnectorPlugIn != frame.data[0])
  373. log_info("Conn %d, Unplug. ", targetGun);
  374. pDcChargingInfo->ConnectorPlugIn = frame.data[0];
  375. } else {
  376. pDcChargingInfo->ConnectorPlugIn = frame.data[0];
  377. }
  378. //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x ",
  379. // targetGun,
  380. // pDcChargingInfo->ConnectorPlugIn,
  381. // frame.data[0]);
  382. //log_info("ConnectorPlugIn = %x ", (-120 + frame.data[1]) / 10);
  383. break;
  384. case ACK_EV_FW_VERSION:
  385. memset(ver, 0, sizeof(ver));
  386. if (pDcChargingInfo->Type == _Type_Chademo) {
  387. memcpy(ver, frame.data, frame.can_dlc);
  388. memcpy(ShmCHAdeMOData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  389. ShmCHAdeMOData->evse[gunTypeIndex].SelfTest_Comp = PASS;
  390. log_info("chademo ver. : %s", ShmCHAdeMOData->evse[gunTypeIndex].version);
  391. } else if (pDcChargingInfo->Type == _Type_GB) {
  392. memcpy(ver, frame.data, frame.can_dlc);
  393. memcpy(ShmGBTData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  394. ShmGBTData->evse[gunTypeIndex].SelfTest_Comp = PASS;
  395. log_info("gbt ver. : %s", ShmGBTData->evse[gunTypeIndex].version);
  396. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  397. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  398. memcpy(ver, frame.data, frame.can_dlc); //DS60-120 add
  399. memcpy(&ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  400. ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].SelfTest_Comp = PASS;
  401. log_info("CCS FW = %s ", ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version);
  402. }
  403. }
  404. if (targetGun == 0) {
  405. memset(pSysInfo->Connector1FwRev,
  406. 0,
  407. sizeof(pSysInfo->Connector1FwRev));
  408. memcpy(pSysInfo->Connector1FwRev, ver, ARRAY_SIZE(ver));
  409. } else if (targetGun == 1) {
  410. memset(pSysInfo->Connector2FwRev,
  411. 0,
  412. sizeof(pSysInfo->Connector2FwRev));
  413. memcpy(pSysInfo->Connector2FwRev, ver, ARRAY_SIZE(ver));
  414. }
  415. break;
  416. case ACK_EV_HW_VERSION:
  417. //log_info("Get EV HW = %s ", frame.data);
  418. break;
  419. case ACK_GET_OUTPUT_REQ:
  420. //DS60-120 add
  421. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
  422. pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  423. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  424. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  425. ) {
  426. if (pDcChargingInfo->EvBatteryStartSoc <= 0 &&
  427. pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE) {
  428. pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
  429. }
  430. if (frame.data[1] > pDcChargingInfo->EvBatterySoc) {
  431. pDcChargingInfo->EvBatterySoc = frame.data[1];
  432. log_info("Gun%d SOC:%d", targetGun,pDcChargingInfo->EvBatterySoc);
  433. }
  434. }
  435. //pDcChargingInfo->EvBatterySoc = frame.data[1]; //DS60-120 remove
  436. //Jerry add set voltage limit
  437. pDcChargingInfo->EvBatterytargetVoltage = (float)((frame.data[3] << 8) + frame.data[2]) / 10;
  438. if (pDcChargingInfo->EvBatterytargetVoltage > (GetMaxChargingVol(targetGun) * 0.1)) {
  439. pDcChargingInfo->EvBatterytargetVoltage = (GetMaxChargingVol(targetGun) * 0.1);
  440. }
  441. //printf("id = %d, EvBatterytargetVoltage = %.2f", targetGun, pDcChargingInfo->EvBatterytargetVoltage);
  442. //Jerry add set currency limit
  443. pDcChargingInfo->EvBatterytargetCurrent = (float)((frame.data[5] << 8) + frame.data[4]) / 10;
  444. if (pDcChargingInfo->EvBatterytargetCurrent > (GetMaxCharginigCur(targetGun) * 0.1)) {
  445. pDcChargingInfo->EvBatterytargetCurrent = (GetMaxCharginigCur(targetGun) * 0.1);
  446. }
  447. //printf("id = %d, EvBatterytargetCurrent = %.2f", targetGun, pDcChargingInfo->EvBatterytargetCurrent);
  448. pDcChargingInfo->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
  449. //log_info("RemainChargingDuration = %d", pDcChargingInfo->RemainChargingDuration);
  450. if (pDcChargingInfo->Type == _Type_Chademo) {
  451. if (ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0])
  452. {
  453. log_info("Gun%d CHAdeMO board status = %d ", targetGun, ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus);
  454. ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  455. }
  456. ShmCHAdeMOData->ev[gunTypeIndex].EvDetection = frame.data[0];
  457. ShmCHAdeMOData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
  458. ShmCHAdeMOData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
  459. ShmCHAdeMOData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
  460. } else if (pDcChargingInfo->Type == _Type_GB) {
  461. if (ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
  462. log_info("Gun%d GB Board status = %d ", targetGun, ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
  463. ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  464. }
  465. ShmGBTData->ev[gunTypeIndex].EvDetection = frame.data[0];
  466. ShmGBTData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
  467. ShmGBTData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
  468. ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
  469. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  470. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  471. if (ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus != frame.data[0] && frame.data[0] != 0xFF) {
  472. log_info("Gun%d CCS board status = %d ", targetGun, ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus);
  473. ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  474. }
  475. }
  476. }
  477. if (pDcChargingInfo->EvBatterytargetVoltage > (EvTargetVolt[targetGun] + 3) ||
  478. pDcChargingInfo->EvBatterytargetVoltage < (EvTargetVolt[targetGun] - 3) ||
  479. pDcChargingInfo->EvBatterytargetCurrent > (EvTargetCur[targetGun] + 1) ||
  480. pDcChargingInfo->EvBatterytargetCurrent < (EvTargetCur[targetGun] - 1)) {
  481. log_info("Gun%d Battery TargetVoltage = %.1f , TargetCurrent = %.1f",
  482. targetGun,pDcChargingInfo->EvBatterytargetVoltage, pDcChargingInfo->EvBatterytargetCurrent);
  483. EvTargetVolt[targetGun] = pDcChargingInfo->EvBatterytargetVoltage;
  484. EvTargetCur[targetGun] = pDcChargingInfo->EvBatterytargetCurrent;
  485. }
  486. //log_info("EvBatterytargetVoltage = %f ", pDcChargingInfo->EvBatterytargetVoltage);
  487. //log_info("EvBatterytargetCurrent = %f ", pDcChargingInfo->EvBatterytargetCurrent);
  488. //log_info("BatteryVoltage = %d ",
  489. // ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
  490. //log_info("CurrentRequest = %d ",
  491. // ShmCHAdeMOData->ev[_chargingData[target]->type_index].ChargingCurrentRequest);
  492. break;
  493. case ACK_GET_EV_BATTERY_INFO:
  494. //_chargingData[target].EvACorDCcharging = frame.data[0];
  495. //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
  496. pDcChargingInfo->EvBatteryMaxVoltage = ((float)(((uint16_t)frame.data[4] << 8) + (uint16_t)frame.data[3])) / 10;
  497. //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
  498. //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
  499. if (pDcChargingInfo->Type == _Type_Chademo) {
  500. ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
  501. ShmCHAdeMOData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
  502. //log_info("EvBatteryMaxVoltage = %f ", _chargingData[target]->EvBatteryMaxVoltage);
  503. //log_info("TotalBatteryCapacity = %d ", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
  504. //log_info("MaxiBatteryVoltage = %d ", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
  505. } else if (pDcChargingInfo->Type == _Type_GB) {
  506. ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
  507. ShmGBTData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
  508. }
  509. //else if (pDcChargingInfo->Type == _Type_CCS_2) {
  510. //}
  511. break;
  512. case ACK_GET_MISCELLANEOUS_INFO:
  513. pDcChargingInfo->GunLocked = frame.data[0];
  514. pDcChargingInfo->PilotVoltage = ((float)(-120 + frame.data[3])) / 10;
  515. if (pDcChargingInfo->Type == _Type_Chademo) {
  516. ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
  517. ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
  518. ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
  519. } else if (pDcChargingInfo->Type == _Type_GB) {
  520. ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
  521. ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
  522. ShmGBTData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
  523. }
  524. /*else if (pDcChargingInfo->Type == _Type_CCS_2) {
  525. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  526. //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureP = frame.data[1];
  527. //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureN = frame.data[2];
  528. }
  529. }*/
  530. ShmDcCommonData->ConnectorTemp[gunTypeIndex][0] = frame.data[1];
  531. ShmDcCommonData->ConnectorTemp[gunTypeIndex][1] = frame.data[2];
  532. if (ShmDcCommonData->TestTemperature == YES) { //ReadCmdline test
  533. break;
  534. }
  535. printChillerTemp = NO;
  536. printConnTemp = NO;
  537. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  538. getChillerTemperature(&chiilerTemp);
  539. memcpy((char *)ShmDcCommonData->SystemTemp, (char *)chiilerTemp.Temp, sizeof(ChillerTemp));
  540. chillerTemp[0] = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
  541. chillerTemp[1] = getMaxConnectTemp(chiilerTemp.Temp[2], chiilerTemp.Temp[3]);
  542. maxChillerTemp = getMaxConnectTemp(chillerTemp[0], chillerTemp[1]);
  543. //if ((maxChillerTemp - 3) >= pDcChargingInfo->ChillerTemp) {
  544. // printChillerTemp = YES;
  545. //}
  546. if(maxChillerTemp > (lastChillerTemp + 2) || maxChillerTemp < (lastChillerTemp - 2))
  547. {
  548. lastChillerTemp = maxChillerTemp;
  549. printChillerTemp = YES;
  550. }
  551. pDcChargingInfo->ChillerTemp = maxChillerTemp;
  552. }
  553. if (frame.data[1] != 0 || frame.data[2] != 0) {
  554. maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
  555. maxConnTemp = getAvageTemp(maxConnTemp, targetGun);
  556. }
  557. if(maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
  558. {
  559. lastConnTemp[targetGun] = maxConnTemp;
  560. printConnTemp = YES;
  561. }
  562. pDcChargingInfo->ConnectorTemp = maxConnTemp;
  563. //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
  564. if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
  565. (printConnTemp == YES) ||
  566. (printChillerTemp == YES) //&&
  567. //(((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
  568. // (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
  569. // ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
  570. // (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
  571. ) {
  572. ShmDcCommonData->SystemModeChange[targetGun] = NO;
  573. log_info("Conn %d max head temp = %d, max chiller = %d, max chiller2 = %d",
  574. targetGun,
  575. maxConnTemp,
  576. chillerTemp[0],
  577. chillerTemp[1]);
  578. }
  579. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  580. //沒有水冷槍
  581. break;
  582. }
  583. if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
  584. //單一水冷槍,不需要切換水冷機油閥
  585. //ShmFanModuleData-> ? = YES; //尚未定義
  586. break;
  587. }
  588. //紀錄槍頭溫度
  589. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  590. if (targetGun == 0) {
  591. ShmDcCommonData->ChillerValve.LeftTemp = pDcChargingInfo->ConnectorTemp;
  592. } else if (targetGun == 1) {
  593. ShmDcCommonData->ChillerValve.RightTemp = pDcChargingInfo->ConnectorTemp;
  594. }
  595. }
  596. //有兩把水冷槍,判斷兩把槍頭溫度,將水冷機節流閥導向溫度高的那一把槍
  597. if (ShmDcCommonData->ChillerValve.LeftTemp > ShmDcCommonData->ChillerValve.RightTemp) {
  598. //ShmFanModuleData->? = YES; //尚未定義
  599. } else {
  600. //ShmFanModuleData->? = NO; //尚未定義
  601. }
  602. //log_info("EvboardStatus = %x ",
  603. // ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
  604. //log_info("ConnectorPlug locked = %x ",
  605. // frame.data[0]);
  606. //log_info("PilotVoltage = %x ", (-120 + frame.data[3]) / 10);
  607. break;
  608. case ACK_EVSE_ISOLATION_STATUS:
  609. break;
  610. case ACK_EVSE_PRECHAGE_INFO:
  611. pDcChargingInfo->PrechargeStatus = frame.data[0];
  612. break;
  613. case NOTIFICATION_EV_STOP:
  614. // 車端要求停止
  615. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && //DS60-120 add
  616. pDcChargingInfo->SystemStatus <= S_TERMINATING) ||
  617. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  618. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  619. // frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
  620. log_info("----------------------------- (%d) NOTIFICATION_EV_STOP err level = %d -----------------------------",
  621. targetGun,
  622. frame.data[0]);
  623. if (frame.data[0] == 0x02) {
  624. if (AbnormalStopAnalysis(targetGun, frame.data + 1) == true) {
  625. pDcChargingInfo->StopChargeFlag = YES;
  626. } else {
  627. pDcChargingInfo->NormalStopChargeFlag = YES;
  628. }
  629. } else {
  630. AbnormalStopAnalysis(targetGun, frame.data + 1);
  631. pDcChargingInfo->NormalStopChargeFlag = YES;
  632. }
  633. }
  634. break;
  635. case ACK_EVCCID_REQ:
  636. if (frame.can_dlc > 0 && strcmp ( (char *)pDcChargingInfo->EVCCID, "" ) == EQUAL &&
  637. pDcChargingInfo->Type == _Type_CCS_2)
  638. {
  639. {
  640. memset (
  641. ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID,
  642. 0,
  643. sizeof(ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID) );
  644. memcpy (
  645. ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID,
  646. frame.data, frame.can_dlc );
  647. }
  648. sprintf ( (char *) pDcChargingInfo->EVCCID, "%.2x%.2x%.2x%.2x%.2x%.2x", frame.data [0],
  649. frame.data [1], frame.data [2], frame.data [3], frame.data [4], frame.data [5] );
  650. pDcChargingInfo->EVCCID [17] = '\0';
  651. log_info( "Gun %d->EVCCID = %s ", targetGun, pDcChargingInfo->EVCCID );
  652. }
  653. break;
  654. default:
  655. log_info("EV board = %d, Ack none defined. intCmd = %d ", targetGun, intCmd);
  656. break;
  657. }//switch
  658. usleep(10000);
  659. }//while
  660. }
  661. }