Module_EvRxComm.c 25 KB

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