Module_EvRxComm.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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. //------------------------------------------------------------------------------
  27. extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
  28. //------------------------------------------------------------------------------
  29. /*static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
  30. uint8_t chillerTemp1, uint8_t chillerTemp2)
  31. {
  32. uint8_t i = 0;
  33. uint8_t tempSource[4] = {headTemp1, headTemp2, chillerTemp1, chillerTemp2};
  34. uint8_t maxTemp = 0;
  35. if (headTemp1 == UNDEFINED_TEMP &&
  36. headTemp2 == UNDEFINED_TEMP &&
  37. chillerTemp1 == UNDEFINED_TEMP &&
  38. chillerTemp2 == UNDEFINED_TEMP) {
  39. return UNDEFINED_TEMP;
  40. }
  41. //先取得第一個非UNDEFINED_TEMP的值
  42. for (i = 0; i < (sizeof(tempSource) / sizeof(uint8_t)); i++) {
  43. if (tempSource[i] != UNDEFINED_TEMP) {
  44. maxTemp = tempSource[i];
  45. break;
  46. }
  47. }
  48. //找最大的溫度值
  49. for (i = 0; i < (sizeof(tempSource) / sizeof(uint8_t)); i++) {
  50. if (tempSource[i] != UNDEFINED_TEMP) {
  51. if (maxTemp < tempSource[i]) {
  52. maxTemp = tempSource[i];
  53. }
  54. }
  55. }
  56. return maxTemp;
  57. }
  58. */
  59. static uint8_t getMaxConnectTemp(uint8_t headTemp1, uint8_t headTemp2)
  60. {
  61. uint8_t maxTemp = 0;
  62. if (headTemp1 > TEMP_BOUNDARY &&
  63. headTemp2 > TEMP_BOUNDARY) {
  64. return UNDEFINED_TEMP;
  65. }
  66. if (headTemp1 <= TEMP_BOUNDARY) {
  67. maxTemp = headTemp1;
  68. }
  69. if (headTemp2 <= TEMP_BOUNDARY) {
  70. if (headTemp2 > maxTemp) {
  71. maxTemp = headTemp2;
  72. }
  73. }
  74. return maxTemp;
  75. }
  76. static float ReadAdcVolt(uint8_t AdcChannel)
  77. {
  78. //AIN0=CCS GUN Temp 1
  79. //AIN1=CCS GUN Temp 2
  80. //AIN2=CCS_Proximity/2
  81. //AIN3=pilot voltage
  82. int fd = -1;
  83. uint8_t str[64] = {0};
  84. uint8_t AdcValue[8] = {'\0'};
  85. if (AdcChannel > 7) {
  86. return -1;
  87. }
  88. sprintf((char *)str, "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw", AdcChannel);
  89. fd = open((char *)str, O_RDONLY);
  90. read(fd, AdcValue, 4);
  91. close(fd);
  92. return (1.8 * atoi((char *)&AdcValue[0])) / 4095;
  93. //return (1.8 * atoi((char *)&AdcValue)) / 4095;
  94. }
  95. static void getChillerTemperature(ChillerTemp *chillerTemp)
  96. {
  97. uint8_t i = 0;
  98. float adcVoltage = 0.0;
  99. ChillerTemp *pChillerTemp = (ChillerTemp *)chillerTemp;
  100. for (i = 0; i < 4; i++) {
  101. adcVoltage = 0.0;
  102. adcVoltage = ReadAdcVolt(i);
  103. if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
  104. pChillerTemp->Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
  105. //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
  106. } else if ((adcVoltage <= 1.07) && (adcVoltage > 0.9)) {
  107. pChillerTemp->Temp[i] = ((adcVoltage - 0.91) * 705.88) + 60;
  108. //log_info("2 adcVoltage = %f", (adcVoltage - 0.9) * 500);
  109. } else {
  110. pChillerTemp->Temp[i] = UNDEFINED_TEMP;
  111. }
  112. /*CcsConnectorTemp1 = ReadAdcVolt(i);
  113. if ((CcsConnectorTemp1 <= 0.9) && (CcsConnectorTemp1 >= 0.8)) { //0 ~ -40
  114. CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 500;
  115. } else if ((CcsConnectorTemp1 <= 1.07) && (CcsConnectorTemp1 > 0.9)) {
  116. CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 705.88;
  117. } else {
  118. CcsConnectorTemp1 = 195; //not available
  119. }
  120. CcsConnectorTemp |= ((unsigned int)(CcsConnectorTemp1 + 60) & 0xFF) << (i * 8); //0x00(-60)~0xFE(194)
  121. */
  122. }
  123. }
  124. static void AddrAssignment(uint8_t *data)
  125. {
  126. uint8_t target_number[8];
  127. uint8_t index = 0x00;
  128. struct ChargingInfoData *pDcChargingInfo = NULL;
  129. memcpy(target_number, data, sizeof(target_number));
  130. index = *(data + 4);
  131. if (pSysConfig->TotalConnectorCount == 1) {
  132. index = 0x01;
  133. }
  134. //if (CheckUniqNumber(index)) {
  135. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index - 1);
  136. //DS60-120 add
  137. if (pDcChargingInfo->Type == _Type_Chademo) {
  138. log_info("Set EV board info : (Chademo) TargetAddr = %d \n", index);
  139. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  140. log_info("Set EV board info : (CCS) TargetAddr = %d \n", index);
  141. } else if (pDcChargingInfo->Type == _Type_GB) {
  142. log_info("Set EV board info : (GB) TargetAddr = %d \n", index);
  143. }
  144. //log_info("EV board id = %x \n", index); //DS60-120 remove
  145. //log_info("target_number[0] = %x \n", target_number[0]);
  146. //log_info("target_number[1] = %x \n", target_number[1]);
  147. //log_info("target_number[2] = %x \n", target_number[2]);
  148. //log_info("target_number[3] = %x \n", target_number[3]);
  149. //log_info("target_number[4] = %x \n", target_number[4]);
  150. log_info("SetTargetAddr = %d, type = %d \n", index, pDcChargingInfo->Type);
  151. SetTargetAddr(target_number, index);
  152. //}
  153. }
  154. void CANReceiver(int fd)
  155. {
  156. pid_t canRecPid;
  157. canRecPid = fork();
  158. if (canRecPid < 0) {
  159. log_error("Create CAN Bus receive task failed\r\n");
  160. return;
  161. }
  162. if (canRecPid == 0) {
  163. int isContinue = 1;
  164. int nbytes;
  165. int intCmd;
  166. uint8_t _index = 0;
  167. uint8_t recvID = 0;
  168. uint8_t targetGun = 0x00;
  169. uint8_t gunTypeIndex = 0;
  170. uint8_t ver[16] = {0};
  171. uint8_t printChillerTemp = NO;
  172. uint8_t printConnTemp = NO;
  173. uint8_t chillerTemp[2] = {0, 0};
  174. uint8_t maxChillerTemp = 0;
  175. uint8_t lastChillerTemp = 0;
  176. uint8_t maxConnTemp = 0;
  177. uint8_t lastConnTemp[2] = {0, 0};
  178. struct can_frame frame;
  179. ChillerTemp chiilerTemp = {0};
  180. struct ChargingInfoData *pDcChargingInfo = NULL;
  181. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  182. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  183. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  184. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  185. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  186. ShmGBTData = (struct GBTData *)GetShmGBTData();
  187. ShmCcsData = (struct CcsData *)GetShmCcsData();
  188. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  189. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  190. log_info("Module_EvRXComm Child's PID is %d\r\n", getpid());
  191. while (isContinue) {
  192. memset(&frame, 0, sizeof(struct can_frame));
  193. nbytes = read(fd, &frame, sizeof(struct can_frame));
  194. if (nbytes <= 0) {
  195. usleep(10000);
  196. continue;
  197. }
  198. recvID = 0;
  199. targetGun = 0x00;
  200. intCmd = (int) (frame.can_id & CAN_EFF_MASK);
  201. if (intCmd == ADDRESS_REQ) {
  202. //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
  203. AddrAssignment(frame.data);
  204. continue;
  205. }
  206. intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
  207. recvID = ((uint8_t) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
  208. for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) { // 假設有找到回應的 Index
  209. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  210. //if (gun_count == 1 &&
  211. // _chargingData[_index]->Type == _Type_CCS_2 &&
  212. // ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
  213. // target -= 1;
  214. //}
  215. if (pDcChargingInfo->Evboard_id == recvID) {
  216. targetGun = _index;
  217. break;
  218. }
  219. }
  220. if ((targetGun < 0) || (targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)) {
  221. log_info("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
  222. usleep(10000);
  223. continue;
  224. }
  225. //else if (gun_count == 1 && targetGun == 0 && findIndex == 1 &&
  226. // ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
  227. // // 這樣的條件下~ 也是單槍 CCS 舊版本的狀況 : 因為舊版 CCS 不會 timeout, then send request id
  228. // ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
  229. //}
  230. if (intCmd == 256) {
  231. log_info("EvComm command = 256");
  232. usleep(10000);
  233. continue;
  234. }
  235. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
  236. gunTypeIndex = pDcChargingInfo->type_index;
  237. switch (intCmd) {
  238. case NOTIFICATION_EV_STATUS:
  239. if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) {
  240. if (frame.data[0] == PLUG) {
  241. log_info("Conn %d, Plugin. \n", targetGun);
  242. } else if (frame.data[0] == UNPLUG) {
  243. log_info("Conn %d, Unplug. \n", targetGun);
  244. } else {
  245. log_info("Conn %d, None Check. (%d) \n", targetGun, frame.data[0]);
  246. }
  247. }
  248. pDcChargingInfo->ConnectorPlugIn = frame.data[0];
  249. pDcChargingInfo->PilotVoltage = frame.data[1];
  250. //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x \n",
  251. // targetGun,
  252. // pDcChargingInfo->ConnectorPlugIn,
  253. // frame.data[0]);
  254. //log_info("ConnectorPlugIn = %x \n", (-120 + frame.data[1]) / 10);
  255. break;
  256. case ACK_EV_FW_VERSION:
  257. memset(ver, 0, sizeof(ver));
  258. if (pDcChargingInfo->Type == _Type_Chademo) {
  259. memcpy(ver, frame.data, frame.can_dlc);
  260. memcpy(ShmCHAdeMOData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  261. ShmCHAdeMOData->evse[gunTypeIndex].SelfTest_Comp = PASS;
  262. //log_info("chademo ver. : %s\n", ShmCHAdeMOData->evse[gunTypeIndex].version);
  263. } else if (pDcChargingInfo->Type == _Type_GB) {
  264. memcpy(ver, frame.data, frame.can_dlc);
  265. memcpy(ShmGBTData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  266. ShmGBTData->evse[gunTypeIndex].SelfTest_Comp = PASS;
  267. //log_info("gbt ver. : %s\n", ShmGBTData->evse[gunTypeIndex].version);
  268. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  269. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  270. memcpy(ver, frame.data, frame.can_dlc); //DS60-120 add
  271. //for (uint8_t _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++) {//DS60-120 remove
  272. /*if (_vCount % 2 == 0 && _vCount != 0)
  273. {
  274. ver[_vCount + _vPoint] = 0x2E;
  275. _vPoint++;
  276. }*/
  277. //ver[_vCount + _vPoint] = frame.data[_vCount];
  278. //}
  279. memcpy(&ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
  280. ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].SelfTest_Comp = PASS;
  281. //log_info("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version);
  282. }
  283. }
  284. if (targetGun == 0) {
  285. memset(pSysInfo->Connector1FwRev,
  286. 0,
  287. sizeof(pSysInfo->Connector1FwRev));
  288. memcpy(pSysInfo->Connector1FwRev, ver, ARRAY_SIZE(ver));
  289. } else if (targetGun == 1) {
  290. memset(pSysInfo->Connector2FwRev,
  291. 0,
  292. sizeof(pSysInfo->Connector2FwRev));
  293. memcpy(pSysInfo->Connector2FwRev, ver, ARRAY_SIZE(ver));
  294. }
  295. break;
  296. case ACK_EV_HW_VERSION:
  297. //log_info("Get EV HW = %s \n", frame.data);
  298. break;
  299. case ACK_GET_OUTPUT_REQ:
  300. //DS60-120 add
  301. if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
  302. pDcChargingInfo->SystemStatus <= S_CHARGING) ||
  303. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  304. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
  305. ) {
  306. if (pDcChargingInfo->EvBatteryStartSoc <= 0) {
  307. pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
  308. }
  309. if (frame.data[1] > pDcChargingInfo->EvBatterySoc) {
  310. pDcChargingInfo->EvBatterySoc = frame.data[1];
  311. }
  312. }
  313. //pDcChargingInfo->EvBatterySoc = frame.data[1]; //DS60-120 remove
  314. //Jerry add set voltage limit
  315. pDcChargingInfo->EvBatterytargetVoltage = (float)((frame.data[3] << 8) + frame.data[2]) / 10;
  316. if (pDcChargingInfo->EvBatterytargetVoltage > (GetMaxChargingVol(targetGun) * 0.1)) {
  317. pDcChargingInfo->EvBatterytargetVoltage = (GetMaxChargingVol(targetGun) * 0.1);
  318. }
  319. //printf("id = %d, EvBatterytargetVoltage = %.2f\r\n", targetGun, pDcChargingInfo->EvBatterytargetVoltage);
  320. //Jerry add set currency limit
  321. pDcChargingInfo->EvBatterytargetCurrent = (float)((frame.data[5] << 8) + frame.data[4]) / 10;
  322. if (pDcChargingInfo->EvBatterytargetCurrent > (GetMaxCharginigCur(targetGun) * 0.1)) {
  323. pDcChargingInfo->EvBatterytargetCurrent = (GetMaxCharginigCur(targetGun) * 0.1);
  324. }
  325. //printf("id = %d, EvBatterytargetCurrent = %.2f\r\n", targetGun, pDcChargingInfo->EvBatterytargetCurrent);
  326. pDcChargingInfo->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
  327. //printf("RemainChargingDuration = %d\r\n", pDcChargingInfo->RemainChargingDuration);
  328. if (pDcChargingInfo->Type == _Type_Chademo) {
  329. //if (ShmCHAdeMOData->ev[gunTypeIndex].EvDetection != frame.data[0])
  330. {
  331. ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  332. }
  333. ShmCHAdeMOData->ev[gunTypeIndex].EvDetection = frame.data[0];
  334. ShmCHAdeMOData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
  335. ShmCHAdeMOData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
  336. ShmCHAdeMOData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
  337. } else if (pDcChargingInfo->Type == _Type_GB) {
  338. //if (ShmGBTData->ev[gunTypeIndex].EvDetection != frame.data[0])
  339. {
  340. ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  341. }
  342. ShmGBTData->ev[gunTypeIndex].EvDetection = frame.data[0];
  343. ShmGBTData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
  344. ShmGBTData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
  345. ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
  346. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  347. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  348. ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
  349. }
  350. }
  351. //log_info("EvBatterytargetVoltage = %f \n", pDcChargingInfo->EvBatterytargetVoltage);
  352. //log_info("EvBatterytargetCurrent = %f \n", pDcChargingInfo->EvBatterytargetCurrent);
  353. //log_info("BatteryVoltage = %d \n",
  354. // ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
  355. //log_info("CurrentRequest = %d \n",
  356. // ShmCHAdeMOData->ev[_chargingData[target]->type_index].ChargingCurrentRequest);
  357. break;
  358. case ACK_GET_EV_BATTERY_INFO:
  359. //_chargingData[target].EvACorDCcharging = frame.data[0];
  360. //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
  361. pDcChargingInfo->EvBatteryMaxVoltage = ((float)(((uint16_t)frame.data[4] << 8) + (uint16_t)frame.data[3])) / 10;
  362. //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
  363. //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
  364. if (pDcChargingInfo->Type == _Type_Chademo) {
  365. ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
  366. ShmCHAdeMOData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
  367. //log_info("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
  368. //log_info("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
  369. //log_info("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
  370. } else if (pDcChargingInfo->Type == _Type_GB) {
  371. ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((uint16_t)frame.data[2] << 8) + (uint16_t)frame.data[1];
  372. ShmGBTData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
  373. }
  374. //else if (pDcChargingInfo->Type == _Type_CCS_2) {
  375. //}
  376. break;
  377. case ACK_GET_MISCELLANEOUS_INFO:
  378. pDcChargingInfo->GunLocked = frame.data[0];
  379. pDcChargingInfo->PilotVoltage = ((float)(-120 + frame.data[3])) / 10;
  380. if (pDcChargingInfo->Type == _Type_Chademo) {
  381. ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
  382. ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
  383. ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
  384. } else if (pDcChargingInfo->Type == _Type_GB) {
  385. ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
  386. ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
  387. ShmGBTData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
  388. }
  389. /*else if (pDcChargingInfo->Type == _Type_CCS_2) {
  390. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  391. //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureP = frame.data[1];
  392. //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureN = frame.data[2];
  393. }
  394. }*/
  395. ShmDcCommonData->ConnectorTemp[gunTypeIndex][0] = frame.data[1];
  396. ShmDcCommonData->ConnectorTemp[gunTypeIndex][1] = frame.data[2];
  397. if (ShmDcCommonData->TestTemperature == YES) { //ReadCmdline test
  398. break;
  399. }
  400. printChillerTemp = NO;
  401. printConnTemp = NO;
  402. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  403. getChillerTemperature(&chiilerTemp);
  404. memcpy((char *)ShmDcCommonData->SystemTemp, (char *)chiilerTemp.Temp, sizeof(ChillerTemp));
  405. chillerTemp[0] = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
  406. chillerTemp[1] = getMaxConnectTemp(chiilerTemp.Temp[2], chiilerTemp.Temp[3]);
  407. maxChillerTemp = getMaxConnectTemp(chillerTemp[0], chillerTemp[1]);
  408. //if ((maxChillerTemp - 3) >= pDcChargingInfo->ChillerTemp) {
  409. // printChillerTemp = YES;
  410. //}
  411. if(maxChillerTemp > (lastChillerTemp + 2) || maxChillerTemp < (lastChillerTemp - 2))
  412. {
  413. lastChillerTemp = maxChillerTemp;
  414. printChillerTemp = YES;
  415. }
  416. pDcChargingInfo->ChillerTemp = maxChillerTemp;
  417. }
  418. maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
  419. //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
  420. // printConnTemp = YES;
  421. //}
  422. if(maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
  423. {
  424. lastConnTemp[targetGun] = maxConnTemp;
  425. printConnTemp = YES;
  426. }
  427. pDcChargingInfo->ConnectorTemp = maxConnTemp;
  428. //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
  429. if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
  430. (printConnTemp == YES) ||
  431. (printChillerTemp == YES) //&&
  432. //(((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
  433. // (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
  434. // ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
  435. // (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
  436. ) {
  437. ShmDcCommonData->SystemModeChange[targetGun] = NO;
  438. log_info("Conn %d max head temp = %d, max chiller = %d, max chiller2 = %d\r\n",
  439. targetGun,
  440. maxConnTemp,
  441. chillerTemp[0],
  442. chillerTemp[1]);
  443. }
  444. if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
  445. //沒有水冷槍
  446. break;
  447. }
  448. if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
  449. //單一水冷槍,不需要切換水冷機油閥
  450. //ShmFanModuleData-> ? = YES; //尚未定義
  451. break;
  452. }
  453. //紀錄槍頭溫度
  454. if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
  455. if (targetGun == 0) {
  456. ShmDcCommonData->ChillerValve.LeftTemp = pDcChargingInfo->ConnectorTemp;
  457. } else if (targetGun == 1) {
  458. ShmDcCommonData->ChillerValve.RightTemp = pDcChargingInfo->ConnectorTemp;
  459. }
  460. }
  461. //有兩把水冷槍,判斷兩把槍頭溫度,將水冷機節流閥導向溫度高的那一把槍
  462. if (ShmDcCommonData->ChillerValve.LeftTemp > ShmDcCommonData->ChillerValve.RightTemp) {
  463. //ShmFanModuleData->? = YES; //尚未定義
  464. } else {
  465. //ShmFanModuleData->? = NO; //尚未定義
  466. }
  467. //log_info("EvboardStatus = %x \n",
  468. // ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
  469. //log_info("ConnectorPlug locked = %x \n",
  470. // frame.data[0]);
  471. //log_info("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
  472. break;
  473. case ACK_EVSE_ISOLATION_STATUS:
  474. break;
  475. case ACK_EVSE_PRECHAGE_INFO:
  476. pDcChargingInfo->PrechargeStatus = frame.data[0];
  477. break;
  478. case NOTIFICATION_EV_STOP:
  479. // 車端要求停止
  480. if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && //DS60-120 add
  481. pDcChargingInfo->SystemStatus <= S_TERMINATING) ||
  482. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  483. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  484. // frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
  485. log_info("(%d) NOTIFICATION_EV_STOP err level = %d-----------------------------\n",
  486. targetGun,
  487. frame.data[0]);
  488. if (frame.data[0] == 0x02) {
  489. if (AbnormalStopAnalysis(targetGun, frame.data + 1) == true) {
  490. pDcChargingInfo->StopChargeFlag = YES;
  491. } else {
  492. pDcChargingInfo->NormalStopChargeFlag = YES;
  493. }
  494. } else {
  495. AbnormalStopAnalysis(targetGun, frame.data + 1);
  496. pDcChargingInfo->NormalStopChargeFlag = YES;
  497. }
  498. }
  499. break;
  500. default:
  501. log_info("EV board = %d, Ack none defined. intCmd = %d \n", targetGun, intCmd);
  502. break;
  503. }//switch
  504. usleep(10000);
  505. }//while
  506. }
  507. }