Module_EvRxComm.c 33 KB

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