main.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <sys/time.h>
  4. #include <sys/timeb.h>
  5. #include <sys/ioctl.h>
  6. #include <sys/socket.h>
  7. #include <sys/ipc.h>
  8. #include <sys/shm.h>
  9. #include <sys/mman.h>
  10. #include <linux/wireless.h>
  11. #include <arpa/inet.h>
  12. #include <netinet/in.h>
  13. #include <unistd.h>
  14. #include <stdarg.h>
  15. #include <stdio.h> /*標準輸入輸出定義*/
  16. #include <stdlib.h> /*標準函數庫定義*/
  17. #include <unistd.h> /*Unix 標準函數定義*/
  18. #include <fcntl.h> /*檔控制定義*/
  19. #include <termios.h> /*PPSIX 終端控制定義*/
  20. #include <errno.h> /*錯誤號定義*/
  21. #include <errno.h>
  22. #include <string.h>
  23. #include <time.h>
  24. #include <ctype.h>
  25. #include <ifaddrs.h>
  26. #include <math.h>
  27. #include "Config.h"
  28. #include <stdbool.h>
  29. #include "../../define.h"
  30. #include <dirent.h>
  31. #include "VCCU.h"
  32. #include "timeout.h"
  33. #include "IOComm.h"
  34. #include <unistd.h> //write, close, usleep, read
  35. #include <sys/time.h>
  36. #include <sys/timeb.h>
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include <sys/types.h>
  40. #include <sys/ioctl.h>
  41. #include <sys/socket.h>
  42. #include <sys/ipc.h>
  43. #include <sys/shm.h>
  44. #include <sys/shm.h>
  45. #include <sys/mman.h>
  46. #include <linux/wireless.h>
  47. #include <arpa/inet.h>
  48. #include <netinet/in.h>
  49. #include <unistd.h>
  50. #include <stdarg.h>
  51. #include <stdio.h> /*標準輸入輸出定義*/
  52. #include <stdlib.h> /*標準函數庫定義*/
  53. #include <unistd.h> /*Unix 標準函數定義*/
  54. #include <fcntl.h> /*檔控制定義*/
  55. #include <termios.h> /*PPSIX 終端控制定義*/
  56. #include <errno.h> /*錯誤號定義*/
  57. #include <errno.h>
  58. #include <string.h>
  59. #include <time.h>
  60. #include <ctype.h>
  61. #include <ifaddrs.h>
  62. #include <math.h>
  63. #include "Module_EvComm.h"
  64. #include <stdlib.h>
  65. #include <stdio.h>
  66. #include <unistd.h> //write, close, usleep, read
  67. #include <fcntl.h> //uart
  68. #define Debug
  69. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  70. //#define PASS 1
  71. #define FAIL -1
  72. #define START 1
  73. #define STOP 0
  74. #define BUFFER_SIZE 128
  75. #define YES 1
  76. #define NO 0
  77. #define NORMAL 0
  78. #define ABNORMAL 1
  79. #define EQUAL 0
  80. #define BTN_RELEASE 0
  81. #define BTN_PRESS 1
  82. #define MAX_BUF 64
  83. //#define SYSFS_GPIO_DIR "/sys/class/gpio"
  84. #define SendDirection 0x08000000
  85. #define FAIL -1
  86. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  87. struct StatusCodeData *ShmStatusCodeData;
  88. struct CHAdeMOData *ShmCHAdeMOData;
  89. struct CcsData *ShmCcsData;
  90. struct RelayModuleData *ShmRelayModuleData;
  91. //struct ATE *ate;
  92. struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  93. struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  94. struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  95. struct timeb startPlugPresentStatusTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  96. struct timeb startDutyCyclTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  97. struct timeb endPlugPresentStatusTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  98. struct timeb endDutyCyclTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  99. //VCCU_ChargeFromVehicle_DATA chargeFromVehicle;
  100. pid_t CANReceiverPid;
  101. int CanFd;
  102. int CanFd2;
  103. #define VIN_MAX_VOLTAGE 250 // 大於該值 : OVP
  104. #define VIN_MIN_VOLTAGE 170 // 小於該值 : UVP
  105. #define VIN_DROP_VOLTAGE 150 // 小於該值 : ac drop
  106. //#define SYSFS_GPIO_DIR "/sys/class/gpio"
  107. byte gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  108. // for initial index to check EV board type is correct
  109. //char *relayRs485PortName = "/dev/ttyS5";
  110. //char* pPortName = "/dev/ttyS3";
  111. //char *priPortName = "/dev/ttyS1";
  112. #define btoa(x) ((x)?"true":"false")
  113. long hexToDec(char *source);
  114. int getIndexOfSigns(char ch);
  115. int whileLoopTime = 200000;//500ms//10000; // 10 ms
  116. int targetCurrent_Value = 120;//2;
  117. int targetVoltage_Value = 500;
  118. int maximumCurrent_value = 200;//10;
  119. int maximumVoltage_value = 500;
  120. int linkVoltage = 500;
  121. int contactorVoltage = 0;//要用電池載的電壓
  122. int maxValue = 950;
  123. int gbmaxValue = 750;
  124. int _port;
  125. #define YES 1
  126. #define NO 0
  127. byte flash = NO;
  128. //=================================
  129. // Create all share memory
  130. //=================================
  131. byte normalStop = 0x01;
  132. byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  133. byte evstaus[5] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  134. struct Ev_Board_Cmd Ev_Cmd={
  135. 0,
  136. 0x00000200,
  137. 0x00000400,
  138. 0x00000500,
  139. 0x00000600,
  140. 0x00000700,
  141. 0x00000800,
  142. 0x00000900,
  143. 0x00000A00,
  144. 0x00000C00,
  145. 0x00000D00,
  146. 0x00000E00,
  147. 0x00000F00,
  148. 0x00001000,
  149. 0x00001100,
  150. 0x00001200,
  151. 0x00001500,
  152. };
  153. int CreatShareMemory()
  154. {
  155. int MeterSMId;
  156. //creat ShmSysConfigAndInfo
  157. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
  158. {
  159. #ifdef SystemLogMessage
  160. //StoreLogMsg("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
  161. #endif
  162. return 0;
  163. }
  164. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  165. {
  166. #ifdef SystemLogMessage
  167. //StoreLogMsg("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
  168. #endif
  169. return 0;
  170. }
  171. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  172. //creat ShmCcsData
  173. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0){
  174. #ifdef SystemLogMessage
  175. //StoreLogMsg("[main]CreatShareMemory:shmget ShmCcsData NG \n");
  176. #endif
  177. return 0;
  178. }
  179. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1){
  180. #ifdef SystemLogMessage
  181. //StoreLogMsg("[main]CreatShareMemory:shmat ShmCcsData NG \n");
  182. #endif
  183. return 0;
  184. }
  185. memset(ShmCcsData, 0, sizeof(struct CcsData));
  186. //creat ShmRelayModuleData
  187. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  188. {
  189. #ifdef SystemLogMessage
  190. //StoreLogMsg("shmget ShmRelayModuleData NG\n");
  191. #endif
  192. return 0;
  193. }
  194. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  195. {
  196. #ifdef SystemLogMessage
  197. //StoreLogMsg("shmat ShmRelayModuleData NG\n");
  198. #endif
  199. return 0;
  200. }
  201. memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
  202. return 1;
  203. }
  204. unsigned long GetTimeoutValue(struct timeval _sour_time);
  205. unsigned long GetTimeoutValue(struct timeval _sour_time)
  206. {
  207. struct timeval _end_time;
  208. gettimeofday(&_end_time, NULL);
  209. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  210. }
  211. int InitCanBus()
  212. {
  213. int s0, nbytes;
  214. struct timeval tv;
  215. struct ifreq ifr0;
  216. struct sockaddr_can addr0;
  217. /*
  218. //can0
  219. system("/sbin/ip link set can0 down");//先將interface disable
  220. system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
  221. system("/sbin/ip link set can0 up");
  222. */
  223. //can1
  224. system("/sbin/ip link set can0 down");//先將interface disable
  225. system("/sbin/ip link set can0 type can bitrate 250000 restart-ms 100");
  226. system("/sbin/ip link set can0 up");
  227. s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  228. tv.tv_sec = 0;
  229. tv.tv_usec = 10000;
  230. if(setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  231. {
  232. #ifdef SystemLogMessage
  233. //StoreLogMsg("[CsuComm]InitCanBus:Set SO_RCVTIMEO NG");
  234. #endif
  235. }
  236. nbytes = 40960;
  237. if(setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
  238. {
  239. #ifdef SystemLogMessage
  240. //StoreLogMsg("[CsuComm]InitCanBus:Set SO_RCVBUF NG");
  241. #endif
  242. }
  243. nbytes = 40960;
  244. if(setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
  245. {
  246. #ifdef SystemLogMessage
  247. //StoreLogMsg("[CsuComm]InitCanBus:Set SO_SNDBUF NG");
  248. #endif
  249. }
  250. //strcpy(ifr0.ifr_name, "can0" );
  251. strcpy(ifr0.ifr_name, "can0" );
  252. ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
  253. addr0.can_family = AF_CAN;
  254. addr0.can_ifindex = ifr0.ifr_ifindex;
  255. bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
  256. return s0;
  257. }
  258. int CHROMAInitCanBus()
  259. {
  260. int s0,nbytes;
  261. struct timeval tv;
  262. struct ifreq ifr0;
  263. struct sockaddr_can addr0;
  264. system("/sbin/ip link set can1 down");
  265. system("/sbin/ip link set can1 type can bitrate 500000 restart-ms 100");
  266. system("/sbin/ip link set can1 up");
  267. s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  268. tv.tv_sec = 0;
  269. tv.tv_usec = 10000;
  270. if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  271. {
  272. #ifdef SystemLogMessage
  273. //DEBUG_ERROR("Set SO_RCVTIMEO NG");
  274. #endif
  275. }
  276. nbytes=40960;
  277. if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
  278. {
  279. #ifdef SystemLogMessage
  280. //DEBUG_ERROR("Set SO_RCVBUF NG");
  281. #endif
  282. }
  283. nbytes=40960;
  284. if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
  285. {
  286. #ifdef SystemLogMessage
  287. //DEBUG_ERROR("Set SO_SNDBUF NG");
  288. #endif
  289. }
  290. strcpy(ifr0.ifr_name, "can1" );
  291. ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
  292. addr0.can_family = AF_CAN;
  293. addr0.can_ifindex = ifr0.ifr_ifindex;
  294. bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
  295. return s0;
  296. }
  297. int DiffTimeb(struct timeb ST, struct timeb ET)
  298. {
  299. //return milli-second
  300. unsigned int StartTime,StopTime;
  301. StartTime=(unsigned int)ST.time;
  302. StopTime=(unsigned int)ET.time;
  303. //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  304. return (StopTime-StartTime);
  305. }
  306. void StopGunInfoTimeoutDet(unsigned char gunIndex)
  307. {
  308. if (gunIndex < gunCount)
  309. {
  310. chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
  311. }
  312. }
  313. void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
  314. {
  315. if (gunIndex < gunCount)
  316. {
  317. if (chargingInfo[gunIndex]->TimeoutFlag != flag)
  318. {
  319. gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
  320. }
  321. chargingInfo[gunIndex]->TimeoutFlag = flag;
  322. }
  323. }
  324. unsigned short MaxValue(unsigned short value1, unsigned short value2)
  325. {
  326. return value1 >= value2 ? value1 : value2;
  327. }
  328. unsigned char isATEChange(unsigned char gun_index)
  329. {
  330. unsigned char result = NO;
  331. if(chargingInfo[gun_index]->ATEState != chargingInfo[gun_index]->PreviousATEState)
  332. {
  333. result = YES;
  334. chargingInfo[gun_index]->PreviousATEState = chargingInfo[gun_index]->ATEState;
  335. }
  336. return result;
  337. }
  338. unsigned char isModeChange(unsigned char gun_index)
  339. {
  340. unsigned char result = NO;
  341. if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
  342. {
  343. result = YES;
  344. chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
  345. }
  346. return result;
  347. }
  348. unsigned char checkMode(byte gun_index, byte mode)
  349. {
  350. unsigned char result = NO;
  351. if(chargingInfo[gun_index]->SystemStatus != mode)
  352. {
  353. result = YES;
  354. }
  355. return result;
  356. }
  357. void setChargerMode(byte gun_index, byte mode)
  358. {
  359. chargingInfo[gun_index]->SystemStatus = mode;
  360. }
  361. void setATEMode(byte gun_index, byte mode)
  362. {
  363. chargingInfo[gun_index]->ATEStatus = mode;
  364. }
  365. void setStatusMode(byte gun_index, byte mode)
  366. {
  367. chargingInfo[gun_index]->ATEStatus = mode;
  368. }
  369. unsigned char isStatusChange(unsigned char gun_index)
  370. {
  371. unsigned char result = NO;
  372. if(chargingInfo[gun_index]->ATEStatus != chargingInfo[gun_index]->PreviousATEStatus)
  373. {
  374. result = YES;
  375. chargingInfo[gun_index]->PreviousATEStatus = chargingInfo[gun_index]->ATEStatus;
  376. }
  377. return result;
  378. }
  379. //==========================================
  380. // Common Function
  381. //==========================================
  382. int PackageIdCmd(int cmd)
  383. {
  384. return cmd | 0x80000000;
  385. }
  386. void SendCmdToEvboard(int canfd, int cmd, byte *data, byte dataLen)
  387. {
  388. struct can_frame frame;
  389. frame.can_id = PackageIdCmd(cmd);//(0x00001000 + cmd) | 0x80000000;//(cmd | 0x80000000);
  390. frame.can_dlc = dataLen;
  391. memcpy(frame.data, data, sizeof(frame.data));
  392. write(canfd, &frame, sizeof(struct can_frame));
  393. //usleep(2000);
  394. }
  395. void setBootNotification1(){
  396. byte data[8];
  397. data[0] = 0x02;
  398. data[1] = 0x02;
  399. data[2] = 0x02;
  400. data[3] = 0x02;
  401. data[4] = 0x03;
  402. data[5] = 0x03;
  403. data[6] = 0x03;
  404. data[7] = 0x03;
  405. SendCmdToEvboard(CanFd2, bn1, data, sizeof(data));
  406. }
  407. void setBootNotification2(){
  408. byte data[8];
  409. data[0] = 0x04;
  410. data[1] = 0x04;
  411. data[2] = 0x04;
  412. data[3] = 0x04;
  413. data[4] = 0x05;
  414. data[5] = 0x05;
  415. data[6] = 0x05;
  416. data[7] = 0x05;
  417. SendCmdToEvboard(CanFd2, bn2, data, sizeof(data));
  418. }
  419. void setEVStatus1(byte evstatus){
  420. byte data[1];
  421. data[0] = evstatus;
  422. SendCmdToEvboard(CanFd2, EVStatus1, data, sizeof(data));
  423. }
  424. void setEVStatus2(byte evstatus){
  425. byte data[1];
  426. data[0] = evstatus;
  427. SendCmdToEvboard(CanFd2, EVStatus2, data, sizeof(data));
  428. }
  429. void GetFirmwareVersion(byte gun_index, byte toId)
  430. {
  431. int id = PackageIdCmd(Ev_Cmd.get_firmware_ver + toId);
  432. byte data[8];
  433. SendCmdToEvboard(CanFd, id, data, 0);
  434. }
  435. void GetHardwareVersion(byte gun_index, byte toId)
  436. {
  437. int id = PackageIdCmd(Ev_Cmd.get_hardware_ver + toId);
  438. byte data[8];
  439. SendCmdToEvboard(CanFd, id, data, 0);
  440. }
  441. void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId)
  442. {
  443. int id = PackageIdCmd(Ev_Cmd.charging_permission + toId);
  444. byte data[8];
  445. data[0] = permissionStatus;
  446. data[1] = aOutputPw & 0xff;
  447. data[2] = (aOutputPw >> 8) & 0xff;
  448. data[3] = aOutputCur & 0xff;
  449. data[4] = (aOutputCur >> 8) & 0xff;
  450. data[5] = aOutputVol & 0xff;
  451. data[6] = (aOutputVol >> 8) & 0xff;
  452. data[7] = 0xff;
  453. //printf(" ChargingPermission Get-Msg : %08X - %02x %02x %02x %02x %02x %02x %02x %02x\n ",(Ev_Cmd.charging_permission + toId), data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] );
  454. SendCmdToEvboard(CanFd, id, data, sizeof(data));
  455. }
  456. void GetMiscellaneousInfo(byte gun_index, byte toId, short K1K2Status, short soc)
  457. {
  458. int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId);
  459. byte data[8];
  460. data[0] = 0x01;
  461. data[1] = 0x02;
  462. data[2] = 0x03;
  463. data[3] = 0x04;
  464. data[4] = 0x05;
  465. data[5] = K1K2Status & 0xff;
  466. data[6] = soc & 0xff;
  467. data[7] = 0x08;
  468. //printf(" Miscellaneous Info Get-Msg : %08X - %02x %02x %02x %02x %02x %02x %02x %02x\n ",Ev_Cmd.get_miscellaneous_info, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] );
  469. /*
  470. data[1] = 0x0001;
  471. data[2] = 0x0001;
  472. data[3] = 0x10;
  473. data[4] = 0x10;
  474. */
  475. SendCmdToEvboard(CanFd, id, data, sizeof(data));
  476. }
  477. /*
  478. void setMisc(byte toId){
  479. float K1K2Status = 0;
  480. float soc = 0;
  481. K1K2Status = ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status;
  482. soc = ShmSysConfigAndInfo->ate.chademo.id0D_req.Soc;
  483. GetMiscellaneousInfo(0, toId, K1K2Status, soc);
  484. }
  485. */
  486. void SetPresentInputPower(short outputVol_b1, short outputCur_b1, byte toId)
  487. {
  488. int id = PackageIdCmd(Ev_Cmd.present_input_power + toId);
  489. byte data[8];
  490. data[0] = outputVol_b1 & 0xff;
  491. data[1] = (outputVol_b1 >> 8) & 0xff;
  492. data[2] = outputCur_b1 & 0xff;
  493. data[3] = (outputCur_b1 >> 8) & 0xff;
  494. /*
  495. data[4] = outputVol_b2 & 0xff;
  496. data[5] = (outputVol_b2 >> 8) & 0xff;
  497. data[6] = outputCur_b2 & 0xff;
  498. data[7] = (outputCur_b2 >> 8) & 0xff;
  499. */
  500. //printf(" PresentInputPower Get-Msg : %08X - %02x %02x %02x %02x %02x %02x %02x %02x\n ",Ev_Cmd.present_input_power, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] );
  501. SendCmdToEvboard(CanFd, id, data, sizeof(data));
  502. }
  503. void SetPresentInputRequirement(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2, byte toId)
  504. {
  505. int id = PackageIdCmd(Ev_Cmd.present_input_requirement + toId );
  506. byte data[8];
  507. data[0] = aOutputPw_b1 & 0xff;
  508. data[1] = (aOutputPw_b1 >> 8) & 0xff;
  509. data[2] = aOutputCur_b1 & 0xff;
  510. data[3] = (aOutputCur_b1 >> 8) & 0xff;
  511. data[4] = aOutputPw_b2 & 0xff;
  512. data[5] = (aOutputPw_b2 >> 8) & 0xff;
  513. data[6] = aOutputCur_b2 & 0xff;
  514. data[7] = 0x01;
  515. /*
  516. data[6] = aOutputCur_b2 & 0xff;
  517. data[7] = (aOutputCur_b2 >> 8) & 0xff;
  518. */
  519. //printf(" Present Input Requirement Get-Msg : %08X - %02x %02x %02x %02x %02x %02x %02x %02x\n ",Ev_Cmd.present_input_requirement, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] );
  520. SendCmdToEvboard(CanFd, id, data, sizeof(data));
  521. }
  522. void GetEvseOutputStatus(byte gun_index, byte toId)
  523. {
  524. int id = PackageIdCmd(Ev_Cmd.get_evse_output_status + toId);
  525. byte data[8];
  526. SendCmdToEvboard(CanFd, id, data, 0);
  527. }
  528. void GetEvseCapacityInfo(byte gun_index, byte toId)
  529. {
  530. int id = PackageIdCmd(Ev_Cmd.get_evse_capacity_info + toId);
  531. byte data[8];
  532. SendCmdToEvboard(CanFd, id, data, 0);
  533. }
  534. void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId)
  535. {
  536. int id = PackageIdCmd(Ev_Cmd.evse_stop_charging + toId);
  537. byte data[8];
  538. data[0] = stopResult;
  539. data[1] = *stopReason;
  540. data[2] = *(stopReason + 1);
  541. data[3] = *(stopReason + 2);
  542. data[4] = *(stopReason + 3);
  543. data[5] = *(stopReason + 4);
  544. data[6] = *(stopReason + 5);
  545. SendCmdToEvboard(CanFd, id, data, sizeof(data));
  546. }
  547. void SetIsolationStatus(byte gun_index, byte result, byte toId)
  548. {
  549. int id = PackageIdCmd(Ev_Cmd.isolation_status + toId);
  550. byte data[8];
  551. data[0] = result;
  552. SendCmdToEvboard(CanFd, id, data, 1);
  553. }
  554. void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId)
  555. {
  556. int id = PackageIdCmd(Ev_Cmd.evse_precharge_info + toId);
  557. byte data[8];
  558. data[0] = result;
  559. SendCmdToEvboard(CanFd, id, data, 1);
  560. }
  561. void handleEmulatorFaultStatus(){
  562. setEVStatus2(evstaus[4]);
  563. ShmSysConfigAndInfo->ate.Permission = STOP;
  564. setStatusMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission);
  565. ShmSysConfigAndInfo->ate.ATEStatus = 0x00;
  566. SetChargingPermission(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.TotalBatteryCap,
  567. ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, 1);
  568. EvseStopChargingEvent(normalStop, stopReason, 1);
  569. }
  570. int bitExtracted(byte number, int k, int p)
  571. {
  572. return (((1 << k) - 1) & (number >> (p - 1)));
  573. }
  574. unsigned short bitextract(unsigned short value, int begin, int end)
  575. {
  576. unsigned short mask = (1 << (end - begin)) - 1;
  577. return (value >> begin) & mask;
  578. }
  579. bool CheckUniqNumber(byte value)
  580. {
  581. for (byte index = 0; index < gunCount; index++)
  582. {
  583. if (chargingInfo[index]->Evboard_id == value)
  584. {
  585. struct timeval _end_time;
  586. gettimeofday(&_end_time, NULL);
  587. unsigned long diff = 1000000 * (_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
  588. if (diff >= 3000000)
  589. {
  590. gettimeofday(&_id_assign_time, NULL);
  591. return true;
  592. }
  593. else
  594. {
  595. return false;
  596. }
  597. }
  598. }
  599. gettimeofday(&_id_assign_time, NULL);
  600. return true;
  601. }
  602. void SetTargetAddr(byte *target_number, byte index)
  603. {
  604. int id = PackageIdCmd(Ev_Cmd.address_assignment + index);
  605. //printf("intCmd = %x \n", cmd & CAN_EFF_MASK);
  606. //cmd = cmd & CAN_EFF_MASK;
  607. byte data[8];
  608. data[0] = *target_number;
  609. data[1] = *(target_number + 1);
  610. data[2] = *(target_number + 2);
  611. data[3] = *(target_number + 3);
  612. data[4] = index;
  613. SendCmdToEvboard(CanFd2, id, data, sizeof(data));
  614. }
  615. void AddrAssignment(byte *data)
  616. {
  617. byte target_number[8];
  618. byte index = 0x00;
  619. memcpy(target_number, data, sizeof(target_number));
  620. index = *(data + 4);
  621. if (CheckUniqNumber(index))
  622. {
  623. printf("EV board id = %x \n", index);
  624. // printf("target_number[0] = %x \n", target_number[0]);
  625. // printf("target_number[1] = %x \n", target_number[1]);
  626. // printf("target_number[2] = %x \n", target_number[2]);
  627. // printf("target_number[3] = %x \n", target_number[3]);
  628. // printf("target_number[4] = %x \n", target_number[4]);
  629. if (index < 1)
  630. return;
  631. printf("SetTargetAddr \n");
  632. SetTargetAddr(target_number, index);
  633. }
  634. }
  635. void VCCU_TD(){
  636. byte data[8];
  637. data[0] = 0x00;
  638. data[1] = 0x00;
  639. data[2] = 0x01;
  640. data[3] = 0x01;
  641. data[4] = 0x00;
  642. data[5] = 0x00;
  643. data[6] = 0x42;
  644. data[7] = 0x66;
  645. SendCmdToEvboard(CanFd, TDId, data, sizeof(data));
  646. }
  647. void VCCU_ChargeFromVehicle(int canfd, int linkVoltage, int contactorVoltage,
  648. int chargePermission, int isolationMeasurem,
  649. int plugLockPermissio, int plugUnlockPermiss, int contactorStatus){
  650. struct VCCU_ChargeFromVehicle obj;
  651. obj.VCCU_Vehicle_LinkVoltage= linkVoltage;//500
  652. obj.VCCU_Vehicle_ContactorVoltage = contactorVoltage;//0
  653. obj.DATA.bits.VCCU_Vehicle_ChargePermission = chargePermission;//Not_allowed
  654. obj.DATA.bits.VCCU_Vehicle_IsolationMeasurem = isolationMeasurem;//Active
  655. obj.DATA.bits.VCCU_Vehicle_PlugLockPermissio = plugLockPermissio;//Allowed//Not_allowed;
  656. obj.DATA.bits.VCCU_Vehicle_PlugUnlockPermiss = plugUnlockPermiss;//Not_allowed
  657. obj.bits.VCCU_Vehicle_ContactorStatus = contactorStatus;//Open
  658. obj.bits.VCCU_Vehicle_StopCharge = 3;//Open
  659. obj.bits.VCCU_Vehicle_ChargeSelection = 3;//Open
  660. byte* data1;
  661. data1 = (byte*) &(*((UWORD *) &obj.VCCU_Vehicle_ContactorVoltage));
  662. byte* data2;
  663. data2 = (byte*) &(*((UWORD *) &obj.VCCU_Vehicle_LinkVoltage));
  664. byte data[6];
  665. data[0] = data1[0];
  666. data[1] = data1[1];
  667. data[2] = data2[0];
  668. data[3] = data2[1];
  669. data[4] = *((UBYTE *) &obj.DATA);
  670. data[5] = *((UBYTE *) &obj.bits);
  671. //printf("%02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] );
  672. SendCmdToEvboard(canfd, VCCU_ChargeFromVehicleIds, data, sizeof(data));
  673. }
  674. //0x18FF3082
  675. void VCCU_V2G_VehicleStatus(int canfd, int EnergyTra, int EVErrorCode,
  676. int EVPowerDeliveryParame, int EVRESSSOC,
  677. int EVRESSConditioningFla, int EVRESSConditionin, int EVReady,
  678. int BulkChargingCompleteF, int EVCabinConditioningFl, int EVCabinConditioning,
  679. int ChargingComplete, int FullSOCFlag, int FullSOC,
  680. int BulkSOCFlag, int BulkSOC, int BulkChargingComplete,
  681. int BulkChargingCompleteFValue){
  682. struct VCCU_V2G_VehicleStatus obj;
  683. obj.DATA4.VCCU_V2G_StateM_EnergyTra_0000 = EnergyTra;//VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended;
  684. obj.DATA1.VCCU_V2G_EVErrorCode = EVErrorCode;//0;
  685. obj.DATA4.VCCU_V2G_EVPowerDeliveryParame = EVPowerDeliveryParame;//3;
  686. obj.VCCU_V2G_EVRESSSOC.value = EVRESSSOC;//0;
  687. obj.DATA3.VCCU_V2G_EVRESSConditioningFla = EVRESSConditioningFla;//3;
  688. obj.DATA3.VCCU_V2G_EVRESSConditioning = EVRESSConditionin;//3;
  689. obj.DATA3.VCCU_V2G_EVReady = EVReady;//3;
  690. obj.DATA1.VCCU_V2G_BulkChargingCompleteF = BulkChargingCompleteF;//3;
  691. obj.DATA3.VCCU_V2G_EVCabinConditioningFl = EVCabinConditioningFl;//3;
  692. obj.DATA2.VCCU_V2G_EVCabinConditioning = EVCabinConditioning;//3;
  693. obj.DATA2.VCCU_V2G_ChargingComplete = ChargingComplete;//3;
  694. obj.DATA2.VCCU_V2G_FullSOCFlag = FullSOCFlag;//0;
  695. obj.VCCU_V2G_FullSOC.value = FullSOC;//3;
  696. obj.DATA2.VCCU_V2G_BulkSOCFlag = BulkSOCFlag;//3;
  697. obj.VCCU_V2G_BulkSOC.value = BulkSOC;//0;
  698. obj.DATA1.VCCU_V2G_BulkChargingComplete = BulkChargingComplete;//3;
  699. obj.DATA1.VCCU_V2G_BulkChargingCompleteF = BulkChargingCompleteFValue;//3;
  700. byte data[7];
  701. data[0] = *((UBYTE *) &obj.DATA1);
  702. data[1] = *((UBYTE *) &obj.DATA2);
  703. data[2] = *((UBYTE *) &obj.DATA3);
  704. data[3] = *((UBYTE *) &obj.DATA4);
  705. data[4] = *((UBYTE *) &obj.VCCU_V2G_BulkSOC);
  706. data[5] = *((UBYTE *) &obj.VCCU_V2G_FullSOC);
  707. data[6] = *((UBYTE *) &obj.VCCU_V2G_EVRESSSOC);
  708. //printf("%02x %02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] , data[6]);
  709. SendCmdToEvboard(canfd, VCCU_V2G_VehicleStatusIds, data, sizeof(data));
  710. }
  711. void VCCU_V2G_EVMaximumVoltageLimit(int VMaximumVoltageLimit,
  712. int EVMaximumVoltage_0002,
  713. int EVMaximumVoltage_0000,
  714. int EVMaximumVoltage_0001,
  715. int EVMaximumVoltage_0003){
  716. struct VCCU_V2G_EVMaximumVoltageLimit obj;
  717. obj.DATA1.VCCU_V2G_EVMaximumVoltageLimit = VMaximumVoltageLimit;//1
  718. obj.DATA1.VCCU_V2G_EVMaximumVoltage_0002 = EVMaximumVoltage_0002;//5
  719. obj.VCCU_V2G_EVMaximumVoltage_0000.value = EVMaximumVoltage_0000;//520
  720. obj.VCCU_V2G_EVMaximumVoltage_0001.value = EVMaximumVoltage_0001;//1
  721. obj.VCCU_V2G_EVMaximumVoltage_0003.value = EVMaximumVoltage_0003;//0
  722. byte* data1;
  723. data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVMaximumVoltage_0000));
  724. byte data[5];
  725. data[0] = *((UBYTE *) &obj.DATA1);
  726. data[1] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumVoltage_0003);
  727. data[2] = data1[0];
  728. data[3] = data1[1];
  729. data[4] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumVoltage_0001);
  730. //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]);
  731. SendCmdToEvboard(CanFd, VCCU_V2G_EVMaximumVoltageLimitIds, data, sizeof(data));
  732. }
  733. void VCCU_V2G_EVMaximumCurrentLimit(int EVMaximumCurrentLimit,
  734. int EVMaximumCurrent_0000,
  735. int EVMaximumCurrent_0001,
  736. int EVMaximumCurrent_0002,
  737. int EVMaximumCurrent_0003){
  738. struct VCCU_V2G_EVMaximumCurrentLimit obj;
  739. obj.DATA1.VCCU_V2G_EVMaximumCurrentLimit = EVMaximumCurrentLimit;//1
  740. obj.DATA1.VCCU_V2G_EVMaximumCurrent_0000 = EVMaximumCurrent_0000;//3
  741. obj.VCCU_V2G_EVMaximumCurrent_0001.value = EVMaximumCurrent_0001;//1
  742. obj.VCCU_V2G_EVMaximumCurrent_0002.value = EVMaximumCurrent_0002;//0
  743. obj.VCCU_V2G_EVMaximumCurrent_0003.value = EVMaximumCurrent_0003;//10
  744. byte* data1;
  745. data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVMaximumCurrent_0003));
  746. byte data[5];
  747. data[0] = *((UBYTE *) &obj.DATA1);
  748. data[1] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumCurrent_0002);
  749. data[2] = data1[0];
  750. data[3] = data1[1];
  751. data[4] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumCurrent_0001);
  752. //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]);
  753. SendCmdToEvboard(CanFd, VCCU_V2G_EVMaximumCurrentLimitIds, data, sizeof(data));
  754. }
  755. void VCCU_V2G_EVTargetCurrent(int EVTargetCurrent_Unit,
  756. int EVTargetCurrent_Value,
  757. int EVTargetCurrent_UnitF,
  758. int EVTargetCurrent_Multi){//05 00 00 01 03
  759. struct VCCU_V2G_EVTargetCurrent obj;
  760. obj.VCCU_V2G_EVTargetCurrent_Unit.value = EVTargetCurrent_Unit;//3
  761. obj.VCCU_V2G_EVTargetCurrent_Value.value = EVTargetCurrent_Value;//5
  762. obj.VCCU_V2G_EVTargetCurrent_UnitF.value = EVTargetCurrent_UnitF;//1
  763. obj.VCCU_V2G_EVTargetCurrent_Multi.value = EVTargetCurrent_Multi;//0
  764. byte* data1;
  765. data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVTargetCurrent_Value));
  766. byte data[5];
  767. data[0] = data1[0];
  768. data[1] = data1[1];
  769. data[2] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_Multi);
  770. data[3] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_UnitF);
  771. data[4] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_Unit);
  772. //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]);
  773. SendCmdToEvboard(CanFd, VCCU_V2G_EVTargetCurrentIds, data, sizeof(data));
  774. }
  775. void VCCU_V2G_EVTargetVoltage(int EVTargetVoltage_Value,
  776. int EVTargetVoltage_Unit,
  777. int EVTargetVoltage_UnitF,
  778. int EVTargetVoltage_Multi){//C2 01 00 01 05
  779. struct VCCU_V2G_EVTargetVoltage obj;
  780. obj.VCCU_V2G_EVTargetVoltage_Value.value = EVTargetVoltage_Value;//450
  781. obj.VCCU_V2G_EVTargetVoltage_Unit.value = EVTargetVoltage_Unit;//5
  782. obj.VCCU_V2G_EVTargetVoltage_UnitF.value = EVTargetVoltage_UnitF;//1
  783. obj.VCCU_V2G_EVTargetVoltage_Multi.value = EVTargetVoltage_Multi;//0
  784. byte* data1;
  785. data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVTargetVoltage_Value));
  786. byte data[5];
  787. data[0] = data1[0];
  788. data[1] = data1[1];
  789. data[2] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_Multi);
  790. data[3] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_UnitF);
  791. data[4] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_Unit);
  792. //printf("%d %02x %02x \n",obj.VCCU_V2G_EVTargetVoltage_Value.value, data[0], data[1]);
  793. //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]);
  794. SendCmdToEvboard(CanFd, VCCU_V2G_EVTargetVoltageIds, data, sizeof(data));
  795. }
  796. void VCCU_Requests(int LED0, int LED1, int LED2,
  797. int HighSideOut0, int HighSideOut1, int HighSideOut2, int HighSideOut3,
  798. int HighSideOut4, int RTC_TimerRequest, int PlugLock,
  799. int RTC_TimerValue,
  800. int ControlPilot, int ChargeUnit, int Inlet){
  801. struct VCCU_Requests obj;
  802. obj.VCCU_LED0_Request = LED0;//0.0
  803. obj.VCCU_LED1_Request = LED1;//0.0
  804. obj.VCCU_LED2_Request = LED2;//0.0
  805. obj.byte3.VCCU_HighSideOut0_Request = HighSideOut0;//3
  806. obj.byte3.VCCU_HighSideOut1_Request = HighSideOut1;//3
  807. obj.byte3.VCCU_HighSideOut2_Request = HighSideOut2;//3
  808. obj.byte3.VCCU_HighSideOut3_Request = HighSideOut3;//3
  809. obj.byte4.VCCU_HighSideOut4_Request = HighSideOut4;//3
  810. obj.byte4.VCCU_RTC_TimerRequest = RTC_TimerRequest;//3
  811. obj.byte4.VCCU_PlugLock_MotorRequest = PlugLock;//7
  812. obj.VCCU_RTC_TimerValue= RTC_TimerValue;//0
  813. obj.byte6.VCCU_ControlPilot_ChargeModeRe = ControlPilot;//7
  814. obj.byte6.VCCU_ChargeUnit_Request = ChargeUnit;//3
  815. obj.byte6.VCCU_Inlet_MotorRequest = Inlet;//3
  816. byte data[7];
  817. data[0] = *((UBYTE *) &obj.VCCU_LED0_Request);
  818. data[1] = *((UBYTE *) &obj.VCCU_LED1_Request);
  819. data[2] = *((UBYTE *) &obj.VCCU_LED2_Request);
  820. data[3] = *((UBYTE *) &obj.byte3);
  821. data[4] = *((UBYTE *) &obj.byte4);
  822. data[5] = *((UBYTE *) &obj.VCCU_RTC_TimerValue);
  823. data[6] = *((UBYTE *) &obj.byte6);
  824. //printf("%02x %02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] , data[6]);
  825. SendCmdToEvboard(CanFd, VCCU_RequestsIds, data, sizeof(data));
  826. }
  827. bool MatedPlugInletUnlocked_Status(){
  828. return (ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&
  829. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Connected &&
  830. //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked &&
  831. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 &&
  832. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == ChargeV2G
  833. //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_Voltage - 32000 == 9
  834. );
  835. }
  836. bool PreCharge_Statue(){
  837. return ((ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge ) &&
  838. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC &&
  839. //(ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_Voltage.bits.value / 2) == 6 &&
  840. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested);
  841. }
  842. bool status1(){
  843. bool result = false;
  844. result = (ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed
  845. && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Unlocked );
  846. return result;
  847. }
  848. bool status2(){
  849. bool result = false;
  850. result = ((ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_DutyCycle.bits.value >= 5
  851. && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_DutyCycle.bits.value <= 7)
  852. && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked
  853. && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == EVSEStateB2
  854. && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_DigitalInput_Status == Not_pressed
  855. && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_S3Switch_Status == Not_pressed);
  856. return result;
  857. }
  858. bool UnmatedPlug(){
  859. bool result = false;
  860. /*
  861. printf("VCCU_V2G_StateM_StateMachineSt = %d VCCU_ChargeUnit_State = %d VCCU_ChargeUnit_Mode = %d VCCU_Vehicle_ContactorRequest = %d VCCU_Vehicle_IsolationMea_0000 = %d \n", ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt,
  862. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State,
  863. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode,
  864. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.Data.bits.VCCU_Vehicle_ContactorRequest,
  865. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.Data.bits.VCCU_Vehicle_IsolationMea_0000);
  866. */
  867. if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_Initialized &&
  868. //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Not_connected &&
  869. //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Not_connected &&
  870. //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked &&
  871. (ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateA ||
  872. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateE ||
  873. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB1) &&
  874. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == VCCU_ChargeUnit_Mode_SNA &&
  875. //ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_Voltage == 0 &&
  876. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == ForceOpen &&
  877. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Requested ){
  878. //TODO
  879. result = true;
  880. //printf("CCS DC01....................\n");
  881. //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Not_allowed, Not_allowed, Opened);
  882. setChargerMode(CCS_QUANTITY, V_UNMATEDPLUG);
  883. }
  884. return result;
  885. }
  886. bool MatedPlugInletUnlocked(){
  887. bool result = false;
  888. if(MatedPlugInletUnlocked_Status() && chargingInfo[CCS_QUANTITY]->SystemStatus == V_IDLE){//(DC02) Mated Plug - Inlet Unlocked
  889. //TODO
  890. result = true;
  891. //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  892. setChargerMode(CCS_QUANTITY, V_MATED_PLUG_INLET_UNLOCKED);
  893. }
  894. return result;
  895. }
  896. bool InletLocking(){
  897. bool result = false;
  898. if(//ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2
  899. status1() &&
  900. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving
  901. ){//(DC03) Inlet Locking
  902. result = true;
  903. //printf("CCS DC03....................\n");
  904. /*
  905. if(ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed &&
  906. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&//PlugPresent_Status == Connected for >=2s
  907. //ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle && //ControlPilot_DutyCycle == valid for >= 2s
  908. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked){
  909. }*/
  910. setChargerMode(CCS_QUANTITY, V_INLETLOCKING);
  911. }
  912. return result;
  913. }
  914. bool InletLocked(){
  915. bool result = false;
  916. if(MatedPlugInletUnlocked_Status() && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked){//DC04) Inlet Locked
  917. result = true;
  918. /*
  919. if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving){
  920. }*/
  921. setChargerMode(CCS_QUANTITY, V_INLETLOCKED);
  922. }
  923. return result;
  924. }
  925. bool DC05_Status(){
  926. return (status1() && status2() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SLAC || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == WaitForIP ||
  927. ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SECCDiscoveryProtocol || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == TLConnection ||
  928. ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SupportedAppProtocol || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SessionSetup ||
  929. ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ServiceDiscovery || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ServiceDetails ||
  930. ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentServiceSelection || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CertificateInstallation ||
  931. ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CertificateUpdate || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentDetails ||
  932. ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentDetails || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == Authorization )
  933. && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open);
  934. }
  935. bool S_SLAC(){
  936. bool result = false;
  937. if(MatedPlugInletUnlocked_Status() && DC05_Status()){
  938. result = true;
  939. /*
  940. if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked &&
  941. (ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle >= 5 || ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle <= 7) &&
  942. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 &&
  943. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_DigitalInput_Status == Not_pressed &&
  944. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_S3Switch_Status == Not_pressed&&
  945. ShmSysConfigAndInfo->ate.vccu.ptc1.VCCU_PTC1_Temperature < 90){
  946. }*/
  947. setChargerMode(CCS_QUANTITY, V_SLAC);
  948. }
  949. return result;
  950. }
  951. bool Definition(){
  952. bool result = false;
  953. if(MatedPlugInletUnlocked_Status() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ChargeParameterDiscovery ) &&
  954. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open){
  955. result = true;
  956. /*
  957. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  958. 3, 0,
  959. 3, 3, TRUE,
  960. 3, 3, 3,
  961. 3, 3, 0,
  962. 3, 0, 3,
  963. 3);
  964. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 520, TRUE, 0);
  965. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10);
  966. */
  967. setChargerMode(CCS_QUANTITY, V_DEFINITION);
  968. }
  969. return result;
  970. }
  971. bool S_CableCheck(){
  972. bool result = false;
  973. if(MatedPlugInletUnlocked_Status() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CableCheck )){
  974. result = true;
  975. //VCCU_ChargeFromVehicle(CanFd, 500, 0, Allowed, Active, Allowed, Not_allowed, Opened);
  976. setChargerMode(CCS_QUANTITY, V_CABLECHECK);
  977. }
  978. return result;
  979. }
  980. bool Isolation(){
  981. bool result = false;
  982. if(MatedPlugInletUnlocked_Status() && PreCharge_Statue()){
  983. result = true;
  984. //VCCU_ChargeFromVehicle(CanFd, 500, 0, Allowed, Not_Active, Allowed, Not_allowed, Opened);
  985. setChargerMode(CCS_QUANTITY, V_ISOLATION);
  986. }
  987. return result;
  988. }
  989. bool S_PreCharge(){
  990. bool result = false;
  991. if(PreCharge_Statue()){
  992. //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Opened);
  993. //VCCU_V2G_EVTargetCurrent(U_A, 5, TRUE, 0);
  994. setChargerMode(CCS_QUANTITY, V_VOLTAGEDIFFERENCE);
  995. }
  996. return result;
  997. }
  998. bool Contactors(){
  999. bool result = false;
  1000. if( PreCharge_Statue()
  1001. //&& ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Close
  1002. ){
  1003. result = true;
  1004. //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1005. setChargerMode(CCS_QUANTITY, V_CONTACTORSCLOSED);
  1006. /*
  1007. if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000)
  1008. {
  1009. ftime(&startChargingTime[CCS_QUANTITY]);
  1010. chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
  1011. StopGunInfoTimeoutDet(CCS_QUANTITY);
  1012. StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
  1013. }
  1014. */
  1015. }
  1016. return result;
  1017. }
  1018. bool S_PowerDelivery(){
  1019. bool result = false;
  1020. /*
  1021. * ((ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge ) &&
  1022. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC &&
  1023. //(ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_Voltage.bits.value / 2) == 6 &&
  1024. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested)
  1025. ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_ChargePermission
  1026. ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.bits.VCCU_Vehicle_ContactorStatus
  1027. * */
  1028. if(ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC &&
  1029. chargingInfo[CCS_QUANTITY]->SystemStatus == V_CONTACTORSCLOSED &&
  1030. ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PowerDelivery &&
  1031. //ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge &&
  1032. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested
  1033. && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Close
  1034. ){
  1035. result = true;
  1036. //printf("status CCS PowerDelivery %d %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest);
  1037. //VCCU_V2G_EVTargetVoltage(450, U_V, TRUE, 0);
  1038. setChargerMode(CCS_QUANTITY, V_POWERDELIVERY);
  1039. }
  1040. return result;
  1041. }
  1042. bool S_CurrentDemand(){
  1043. bool result = false;
  1044. if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CurrentDemand){//(DC12) Current Demand
  1045. result = true;
  1046. //TODO stop
  1047. setChargerMode(CCS_QUANTITY, V_CURRENTDEMAND);
  1048. }
  1049. return result;
  1050. }
  1051. bool PowerDeliveryFalse(){
  1052. bool result = false;
  1053. if(
  1054. chargingInfo[CCS_QUANTITY]->SystemStatus == V_CURRENTDEMAND &&
  1055. ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PowerDelivery
  1056. && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open
  1057. //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State != EVSEStateC
  1058. ){//(DC13) PowerDelivery
  1059. result = true;
  1060. setChargerMode(CCS_QUANTITY, V_POWERDELIVERYFALSE);
  1061. //printf("CCS POWERDELIVERYFALSE Processing 14 VCCU_V2G_StateM_StateMachineSt = %d VCCU_ChargeUnit_State = %d VCCU_Vehicle_IsolationMea_0000 = %d ....................\n" , ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt, ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000);
  1062. }
  1063. return result;
  1064. }
  1065. bool S_WeldingDetection(){
  1066. bool result = false;
  1067. if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == WeldingDetection){//(DC14) Welding Detection
  1068. result = true;
  1069. setChargerMode(CCS_QUANTITY, V_DETECTION);
  1070. }
  1071. return result;
  1072. }
  1073. bool SessionStop(){
  1074. bool result = false;
  1075. if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_SessionStop &&
  1076. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Requested){//Session Stop
  1077. result = true;
  1078. setChargerMode(CCS_QUANTITY, V_SESSION_STOP);
  1079. }
  1080. return result;
  1081. }
  1082. bool StopCommunicationSession(){
  1083. bool result = false;
  1084. if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_StopCommunicationSession ){//Stop Communication Session
  1085. result = true;
  1086. setChargerMode(CCS_QUANTITY, V_STOP_COMMUNICATION_SESSION);
  1087. }
  1088. return result;
  1089. }
  1090. bool DCFinished(){
  1091. bool result = false;
  1092. if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_Finished ){//Finished
  1093. result = true;
  1094. setChargerMode(CCS_QUANTITY, V_FINISHED);
  1095. }
  1096. return result;
  1097. }
  1098. bool statusCheck(){
  1099. bool result = false;
  1100. //VCCU_TD();
  1101. UnmatedPlug();
  1102. MatedPlugInletUnlocked();
  1103. InletLocking();
  1104. InletLocked();
  1105. S_SLAC();
  1106. Definition();
  1107. S_CableCheck();
  1108. Isolation();
  1109. S_PreCharge();
  1110. Contactors();
  1111. S_PowerDelivery();
  1112. S_CurrentDemand();
  1113. PowerDeliveryFalse();
  1114. S_WeldingDetection();
  1115. SessionStop();
  1116. StopCommunicationSession();
  1117. DCFinished();
  1118. return result;
  1119. }
  1120. bool AcUnmatedPlug(){
  1121. bool result = false;
  1122. if((ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateA ||
  1123. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateE ||
  1124. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB1) &&
  1125. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == VCCU_ChargeUnit_Mode_SNA ){
  1126. //TODO
  1127. result = true;
  1128. setChargerMode(CCS_QUANTITY, V_UNMATEDPLUG);
  1129. }
  1130. return result;
  1131. }
  1132. bool AcMatedPlugInletUnlocked(){
  1133. bool result = false;
  1134. if( (ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&
  1135. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Connected &&
  1136. //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked &&
  1137. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 &&
  1138. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == ChargePwm
  1139. //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_Voltage - 32000 == 9
  1140. ) && chargingInfo[CCS_QUANTITY]->SystemStatus == V_IDLE){//(DC02) Mated Plug - Inlet Unlocked
  1141. //TODO
  1142. result = true;
  1143. //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1144. setChargerMode(CCS_QUANTITY, V_MATED_PLUG_INLET_UNLOCKED);
  1145. }
  1146. return result;
  1147. }
  1148. bool acInletLocking(){
  1149. bool result = false;
  1150. if(//ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2
  1151. (ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed
  1152. && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Unlocked &&
  1153. ((chargingInfo[CCS_QUANTITY]->PlugPresentStatusDuration >= 2) &&
  1154. chargingInfo[CCS_QUANTITY]->DutyCycleDuration >= 2)) &&
  1155. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving
  1156. ){//(DC03) Inlet Locking
  1157. result = true;
  1158. //printf("CCS DC03....................\n");
  1159. /*
  1160. if(ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed &&
  1161. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&//PlugPresent_Status == Connected for >=2s
  1162. //ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle && //ControlPilot_DutyCycle == valid for >= 2s
  1163. ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked){
  1164. }*/
  1165. setChargerMode(CCS_QUANTITY, V_INLETLOCKING);
  1166. }
  1167. return result;
  1168. }
  1169. bool acStatusCheck(){
  1170. bool result = false;
  1171. AcUnmatedPlug();
  1172. AcMatedPlugInletUnlocked();
  1173. return result;
  1174. }
  1175. long hexToDec(char *source)
  1176. {
  1177. long sum = 0;
  1178. long t = 1;
  1179. int i, len;
  1180. len = strlen(source);
  1181. for(i=len-1; i>=0; i--)
  1182. {
  1183. sum += t * getIndexOfSigns(*(source + i));
  1184. t *= 16;
  1185. }
  1186. return sum;
  1187. }
  1188. int getIndexOfSigns(char ch)
  1189. {
  1190. if(ch >= '0' && ch <= '9')
  1191. {
  1192. return ch - '0';
  1193. }
  1194. if(ch >= 'A' && ch <='F')
  1195. {
  1196. return ch - 'A' + 10;
  1197. }
  1198. if(ch >= 'a' && ch <= 'f')
  1199. {
  1200. return ch - 'a' + 10;
  1201. }
  1202. return -1;
  1203. }
  1204. void Initialization(){
  1205. char *moduleName = "DMYZ30100J01P0";
  1206. memcpy(&ShmSysConfigAndInfo->SysConfig.ModelName, moduleName, strlen(moduleName));
  1207. //printf("%s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  1208. ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY].Index = CCS_QUANTITY;
  1209. ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY].slotsIndex = 1;
  1210. chargingInfo[CCS_QUANTITY] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY];
  1211. chargingInfo[CCS_QUANTITY]->SystemStatus = V_IDLE;
  1212. chargingInfo[CCS_QUANTITY]->Type = _Type_CCS;
  1213. chargingInfo[CCS_QUANTITY]->type_index = CCS_QUANTITY;
  1214. chargingInfo[CCS_QUANTITY]->Evboard_id = 0x01;
  1215. ShmSysConfigAndInfo->ate.ATEStatus = 0;
  1216. // 現階段預設為走 DIN70121
  1217. ShmCcsData->CommProtocol = 0x01;
  1218. //return PASS;
  1219. }
  1220. bool CheckConnectorTypeStatus()
  1221. {
  1222. bool result = true;
  1223. return result;
  1224. }
  1225. void SpawnTask()
  1226. {
  1227. sleep(2);
  1228. system("/root/Module_InternalComm &");
  1229. system("/root/Module_EvComm &");
  1230. //return PASS;
  1231. }
  1232. void KillTask()
  1233. {
  1234. system("killall Module_InternalComm");
  1235. system("killall Module_EvComm");
  1236. }
  1237. int main(void){
  1238. //Create all share memory
  1239. //printf("=====Initializing. \n");
  1240. //ate = malloc( sizeof(ate) );
  1241. if(CreatShareMemory()==0){
  1242. #ifdef SystemLogMessage
  1243. //DEBUG_ERROR("CreatShareMemory NG \n");
  1244. #endif
  1245. if(ShmStatusCodeData!=NULL)
  1246. {
  1247. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1248. }
  1249. return 0;
  1250. sleep(5);
  1251. system("reboot -f");
  1252. }
  1253. /*
  1254. int a=2;
  1255. int *b;
  1256. b = &a;
  1257. printf("%p\n", &a);
  1258. printf("%d\n", *b);
  1259. printf("%p\n", b);
  1260. printf("%p\n", &b);
  1261. *//*
  1262. int a = 2;
  1263. int b = 3;
  1264. a = a^b;
  1265. b = a^b;
  1266. a = a^b;
  1267. printf("%d %d", a, b);
  1268. const char *SystemId="0101";
  1269. printf("%c %p =====\n", *SystemId, &SystemId);
  1270. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.SystemId,SystemId);
  1271. char *SystemIdStr = (char *)&ShmSysConfigAndInfo->SysConfig.SystemId;
  1272. printf("%s =====\n", SystemIdStr);*/
  1273. //SpawnTask();
  1274. //KillTask();
  1275. KillTask();
  1276. ///CanFd = InitCanBus();
  1277. //CanFd2 = CHROMAInitCanBus();
  1278. Initialization();
  1279. SpawnTask();
  1280. //CANReceiver();
  1281. //CHROMACANReceiver();
  1282. //printf ("vccu 1===== CanFd2:%d. \n", CanFd2);
  1283. //setChargerMode(CCS_QUANTITY, V_IDLE);
  1284. /*
  1285. struct timeb tp;
  1286. unsigned int StartTime,StopTime;
  1287. //ftime(&tp);
  1288. ftime(&startChargingTime[CCS_QUANTITY]);
  1289. //
  1290. StartTime = (int)startChargingTime[CCS_QUANTITY].time;
  1291. printf("%u\n", StartTime);
  1292. sleep(2);
  1293. ftime(&tp);
  1294. ftime(&endChargingTime[CCS_QUANTITY]);
  1295. StopTime = (int)endChargingTime[CCS_QUANTITY].time;
  1296. printf("%u\n", StopTime);
  1297. */
  1298. /*
  1299. gpio_set_direction(1, GPIO_DIR_INPUT);
  1300. gpio_set_direction(2, GPIO_DIR_INPUT);
  1301. gpio_set_direction(3, GPIO_DIR_INPUT);
  1302. gpio_write(1, 0);
  1303. gpio_write(3, 0);
  1304. gpio_write(3, 1);
  1305. gpio_write(3, 1);
  1306. */
  1307. /*
  1308. int pinIn[2] = { 1, 3 };
  1309. system("echo 1 > /sys/class/gpio/export");
  1310. system("echo \"out\" > /sys/class/gpio/gpio1/direction");
  1311. system("echo 1 > /sys/class/gpio/gpio1/value");
  1312. system("echo 3 > /sys/class/gpio/export");
  1313. system("echo \"out\" > /sys/class/gpio/gpio3/direction");
  1314. system("echo 1 > /sys/class/gpio/gpio3/value");
  1315. gpio_set_direction(1, GPIO_DIR_OUTPUT);
  1316. gpio_set_direction(4, GPIO_DIR_OUTPUT);
  1317. gpio_write(1, 0);
  1318. gpio_write(4, 0);
  1319. for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
  1320. {
  1321. }*/
  1322. //Uart1Fd = Init407ComPort();
  1323. //printf("407 Port id = %d \n", Uart1Fd);
  1324. //int led = gpio_read(3);
  1325. //printf("led === %d \n", led);
  1326. //printf("%d %d %d %d %d %d \n", ShmSysConfigAndInfo->ate.targetCurrent_Value, ShmSysConfigAndInfo->ate.targetVoltage_Value, ShmSysConfigAndInfo->ate.maximumCurrent_value, ShmSysConfigAndInfo->ate.maximumVoltage_value, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.contactorVoltage);
  1327. /*
  1328. InitRS485DirectionIO();
  1329. // Open Uart5 for RB
  1330. Uart5Fd = InitComPort();
  1331. for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++)
  1332. {
  1333. outputRelay.relay_event.relay_status[index] = 0x00;
  1334. }
  1335. memset(&regRelay, 0xFF,sizeof(Relay));
  1336. outputRelay.relay_event.bits.AC_Contactor = 0x00;
  1337. outputRelay.relay_event.bits.CCS_Precharge = 0x00;
  1338. outputRelay.relay_event.bits.Gun1_P = 0x00;
  1339. outputRelay.relay_event.bits.Gun1_N = 0x00;
  1340. outputRelay.relay_event.bits.Gun2_P = 0x00;
  1341. outputRelay.relay_event.bits.Gun2_N = 0x00;
  1342. //outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
  1343. //outputRelay.relay_event.bits.Gun1_Parallel_P = 0x01;
  1344. sleep(1);
  1345. if(Uart5Fd < 0){
  1346. printf ("open port error. \n");
  1347. return 0;
  1348. }*/
  1349. //usleep(300000);
  1350. ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status=0x00;
  1351. ShmSysConfigAndInfo->ate.chademo.id0D_req.Soc = 50;
  1352. ShmSysConfigAndInfo->ate.ateMode = 0;
  1353. ShmSysConfigAndInfo->ate.ATEState = 2;//1:ccs 2:gb
  1354. /*
  1355. outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
  1356. outputRelay.relay_event.bits.Gun1_Parallel_P = 0x00;
  1357. flash = YES;
  1358. SetOutputGpio(!flash);
  1359. return 0;
  1360. */
  1361. /**/
  1362. //byte priorityLow = 1;
  1363. /**/
  1364. //byte normalStop = 0x01;
  1365. //byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1366. //byte evstaus[5] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  1367. //PresentInputRequirement
  1368. /*
  1369. typedef enum
  1370. {
  1371. ESIdle = 0x01;
  1372. ESPreparing = 0x02;
  1373. ESCharging = 0x03;
  1374. ESChargingTerminating = 0x04;
  1375. ESFault = 0x05;
  1376. }EmulatorStatus;
  1377. */
  1378. //setStatusMode(CCS_QUANTITY, STOP);
  1379. //CCS
  1380. ShmSysConfigAndInfo->ate.targetCurrent_Value = targetCurrent_Value;
  1381. ShmSysConfigAndInfo->ate.targetVoltage_Value = targetVoltage_Value;
  1382. ShmSysConfigAndInfo->ate.maximumCurrent_value = maximumCurrent_value;
  1383. ShmSysConfigAndInfo->ate.maximumVoltage_value = maximumVoltage_value;
  1384. ShmSysConfigAndInfo->ate.linkVoltage = linkVoltage;
  1385. ShmSysConfigAndInfo->ate.contactorVoltage = contactorVoltage;//contactorVoltage;
  1386. //GB
  1387. //ShmSysConfigAndInfo->ate.PresentBattVoltage = 4700;
  1388. ShmSysConfigAndInfo->ate.PresentBattVoltage = 4700;
  1389. ShmSysConfigAndInfo->ate.MinimumChargeCurrent = 20;
  1390. //ShmSysConfigAndInfo->ate.RequireVoltage = 4800;
  1391. ShmSysConfigAndInfo->ate.RequireVoltage = 4800;
  1392. //ShmSysConfigAndInfo->ate.RequireVoltage = 4700;
  1393. ShmSysConfigAndInfo->ate.RequireCurrent = 600;
  1394. ShmSysConfigAndInfo->ate.chademoTargetVoltage_Value = 4800;
  1395. ShmSysConfigAndInfo->ate.chademoTargetCurrent_Value = 30;
  1396. //ShmSysConfigAndInfo->ate.targetCurrent_Value = 1200;
  1397. ShmSysConfigAndInfo->ate.Permission = STOP;
  1398. ShmSysConfigAndInfo->ate.TotalBatteryCap = 1000; //0.1
  1399. ShmSysConfigAndInfo->ate.MaxBatteryCurrent = 1200; //0.1
  1400. ShmSysConfigAndInfo->ate.MaxBatteryVoltage = 5000; //0.1
  1401. ShmSysConfigAndInfo->ate.status = 0;
  1402. ShmSysConfigAndInfo->ate.chademo.id03.state = 0;
  1403. ShmSysConfigAndInfo->ate.ATEStatus = 0x00;
  1404. ShmSysConfigAndInfo->ate.cstatus = 0;
  1405. ShmSysConfigAndInfo->ate.chademo.PresentChargedDuration = 0;
  1406. ShmSysConfigAndInfo->ate.chademo.RemainChargingDuration = 0;
  1407. setStatusMode(CCS_QUANTITY, STOP);
  1408. if(ShmSysConfigAndInfo->ate.ATEState == 1){
  1409. }else if(ShmSysConfigAndInfo->ate.ATEState == 2){
  1410. }
  1411. setATEMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.ATEState);
  1412. ftime(&startChargingTime[CCS_QUANTITY]);
  1413. chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
  1414. StopGunInfoTimeoutDet(CCS_QUANTITY);
  1415. StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
  1416. //
  1417. printf("version = ....................\n" );
  1418. while(true){
  1419. //ShmSysConfigAndInfo->ate.ATEState
  1420. if(ShmSysConfigAndInfo->ate.ATEState == 1){//VCCU
  1421. //TODO
  1422. //ShmSysConfigAndInfo->ate.ateMode = 0;
  1423. }else if(ShmSysConfigAndInfo->ate.ATEState == 2){//GB
  1424. //TODO
  1425. //ShmSysConfigAndInfo->ate.ateMode = 0;
  1426. }else{//none
  1427. // init
  1428. }
  1429. int state = isATEChange(CCS_QUANTITY);
  1430. if(state){
  1431. //TODO
  1432. }
  1433. if(ShmSysConfigAndInfo->ate.ATEState == 1){//VCCU
  1434. /*
  1435. ftime(&endChargingTime[CCS_QUANTITY]);
  1436. chargingInfo[CCS_QUANTITY]->RemainChargingDuration = DiffTimeb(startChargingTime[CCS_QUANTITY], endChargingTime[CCS_QUANTITY]);
  1437. //GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer);
  1438. printf("%d %d ....................\n",chargingInfo[CCS_QUANTITY]->RemainChargingDuration, chargingInfo[CCS_QUANTITY]->TimeoutFlag);
  1439. if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000)
  1440. {
  1441. ftime(&startChargingTime[CCS_QUANTITY]);
  1442. chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
  1443. StopGunInfoTimeoutDet(CCS_QUANTITY);
  1444. StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
  1445. }
  1446. */
  1447. //setBootNotification1();
  1448. // 輸出電壓
  1449. //測試value
  1450. //GetPersentOutputVol();
  1451. // 三相輸入電壓
  1452. //GetPresentInputVol();
  1453. statusCheck();
  1454. int status = isModeChange(CCS_QUANTITY);
  1455. /*
  1456. * VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1457. 3, 0,
  1458. 3, 3, TRUE,
  1459. 3, 3, 3,
  1460. 3, 3, 0,
  1461. 3, 0, 3,
  1462. 3);
  1463. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1464. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1465. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1466. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1467. */
  1468. /*
  1469. VCCU_Requests(0, 0, 0,
  1470. 3, 3, 3, 3,
  1471. 3, 3, 7,
  1472. 0,
  1473. 7, 3, 3);*/
  1474. switch(chargingInfo[CCS_QUANTITY]->SystemStatus){
  1475. case V_IDLE:{
  1476. if (status){
  1477. printf("CCS IDLE Processing 1....................\n");
  1478. }
  1479. //setEVStatus1(evstaus[0]);
  1480. break;
  1481. }
  1482. case V_UNMATEDPLUG:{
  1483. if (status){
  1484. printf("CCS UNMATEDPLUG Processing 2....................\n");
  1485. }
  1486. //setEVStatus1(evstaus[0]);
  1487. //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Not_allowed, Not_allowed, Opened);
  1488. break;
  1489. }
  1490. case V_MATED_PLUG_INLET_UNLOCKED:{
  1491. if (status){
  1492. if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected){
  1493. }
  1494. printf("CCS MATED_PLUG_INLET_UNLOCKED Processing 3....................\n");
  1495. }
  1496. //setEVStatus1(evstaus[0]);
  1497. //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1498. //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1499. break;
  1500. }
  1501. case V_INLETLOCKING:{
  1502. if (status){
  1503. printf("CCS INLETLOCKING Processing 4....................\n");
  1504. }
  1505. //setEVStatus1(evstaus[0]);
  1506. break;
  1507. }
  1508. case V_INLETLOCKED:{
  1509. if (status){
  1510. printf("CCS INLETLOCKED Processing 5....................\n");
  1511. }
  1512. /*
  1513. setEVStatus1(evstaus[1]);
  1514. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1515. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1516. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1517. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1518. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1519. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1520. 3, 0,
  1521. 3, 3, TRUE,
  1522. 3, 3, 3,
  1523. 3, 3, 0,
  1524. 3, 0, 3,
  1525. 3);
  1526. */
  1527. /*
  1528. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1529. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1530. */
  1531. break;
  1532. }
  1533. case V_SLAC:{
  1534. if (status){
  1535. printf("CCS SLAC Processing 6....................\n");
  1536. }
  1537. //setEVStatus1(evstaus[1]);
  1538. //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1539. /*
  1540. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1541. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1542. */
  1543. /*
  1544. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1545. 3, 0,
  1546. 3, 3, TRUE,
  1547. 3, 3, 3,
  1548. 3, 3, 0,
  1549. 3, 0, 3,
  1550. 3);
  1551. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1552. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1553. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1554. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1555. */
  1556. break;
  1557. }
  1558. case V_DEFINITION:{
  1559. if (status){
  1560. printf("CCS DEFINITION Processing 7....................\n");
  1561. }
  1562. //setEVStatus1(evstaus[1]);
  1563. /*
  1564. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0,
  1565. 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3);
  1566. */
  1567. /*
  1568. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 500, TRUE, 0);
  1569. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10);
  1570. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1571. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1572. */
  1573. /*
  1574. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1575. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1576. 3, 0,
  1577. 3, 3, TRUE,
  1578. 3, 3, 3,
  1579. 3, 3, 0,
  1580. 3, 0, 3,
  1581. 3);
  1582. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1583. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1584. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1585. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1586. */
  1587. break;
  1588. }
  1589. case V_CABLECHECK:{
  1590. if (status){
  1591. printf("CCS CABLECHECK Processing 8 ....................\n");
  1592. }
  1593. /*
  1594. setEVStatus1(evstaus[1]);
  1595. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Allowed, Active, Allowed, Not_allowed, Opened);
  1596. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1597. 3, 0,
  1598. 3, 3, TRUE,
  1599. 3, 3, 3,
  1600. 3, 3, 0,
  1601. 3, 0, 3,
  1602. 3);
  1603. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1604. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1605. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1606. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1607. */
  1608. break;
  1609. }
  1610. case V_ISOLATION:{
  1611. if (status){
  1612. printf("CCS ISOLATION Processing 9 %d ....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va );
  1613. ftime(&startChargingTime[CCS_QUANTITY]);
  1614. }
  1615. /*
  1616. setEVStatus1(evstaus[1]);
  1617. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Allowed, Not_Active, Allowed, Not_allowed, Opened);
  1618. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1619. 3, 0,
  1620. 3, 3, TRUE,
  1621. 3, 3, 3,
  1622. 3, 3, 0,
  1623. 3, 0, 3,
  1624. 3);
  1625. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1626. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1627. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1628. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1629. */
  1630. break;
  1631. }
  1632. case V_VOLTAGEDIFFERENCE:{
  1633. if (status){
  1634. printf("CCS VOLTAGEDIFFERENCE Processing 10 ....................\n");
  1635. ftime(&startChargingTime[CCS_QUANTITY]);
  1636. chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
  1637. StopGunInfoTimeoutDet(CCS_QUANTITY);
  1638. StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
  1639. }
  1640. ftime(&endChargingTime[CCS_QUANTITY]);
  1641. chargingInfo[CCS_QUANTITY]->RemainChargingDuration = DiffTimeb(startChargingTime[CCS_QUANTITY], endChargingTime[CCS_QUANTITY]);
  1642. //GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer);
  1643. //printf("%d %ld ....................\n",chargingInfo[CCS_QUANTITY]->RemainChargingDuration, val);
  1644. if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000)
  1645. {
  1646. ftime(&startChargingTime[CCS_QUANTITY]);
  1647. chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
  1648. StopGunInfoTimeoutDet(CCS_QUANTITY);
  1649. StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
  1650. }
  1651. /*printf("VCCU_V2G_StateM_StateMachineSt = %d VCCU_ChargeUnit_State = %d VCCU_Vehicle_IsolationMea_0000 = %d VCCU_Vehicle_ContactorRequest = %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt,
  1652. ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State,
  1653. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000,
  1654. ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest);
  1655. */
  1656. /*
  1657. setEVStatus1(evstaus[1]);
  1658. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1659. //VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1660. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1661. 3, 0,
  1662. 3, 3, TRUE,
  1663. 3, 3, 3,
  1664. 3, 3, 0,
  1665. 3, 0, 3,
  1666. 3);
  1667. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1668. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1669. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1670. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1671. */
  1672. break;
  1673. }
  1674. case V_CONTACTORSCLOSED:{
  1675. if (status){
  1676. printf("CCS CONTACTORSCLOSED Processing 11 %d %d....................\n",ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va, ShmSysConfigAndInfo->ate.linkVoltage );
  1677. }
  1678. /*
  1679. setEVStatus1(evstaus[1]);
  1680. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1681. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1682. 3, 0,
  1683. 3, 3, TRUE,
  1684. 3, 3, 3,
  1685. 3, 3, 0,
  1686. 3, 0, 3,
  1687. 3);
  1688. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1689. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1690. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1691. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1692. */
  1693. break;
  1694. }
  1695. case V_POWERDELIVERY:{
  1696. if (status){
  1697. printf("CCS POWERDELIVERY Processing 12 %d %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va, ShmSysConfigAndInfo->ate.linkVoltage );
  1698. }
  1699. //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1700. /*
  1701. if(ShmSysConfigAndInfo->ate.ATEStatus == 0){
  1702. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1703. }else{
  1704. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Opened);
  1705. }
  1706. //VCCU_V2G_EVTargetVoltage(400, U_V, TRUE, 0);
  1707. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1708. 3, 0,
  1709. 3, 3, TRUE,
  1710. 3, 3, 3,
  1711. 3, 3, 0,
  1712. 3, 0, 3,
  1713. 3);
  1714. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1715. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1716. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1717. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1718. setEVStatus1(evstaus[1]);
  1719. */
  1720. break;
  1721. }
  1722. case V_CURRENTDEMAND:{
  1723. if (status){
  1724. printf("CCS CURRENTDEMAND Processing 13 %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va );
  1725. printf("maximumVoltage_value = %d Voltage = %d maximumCurrent_value = %d Current = %d....................\n", ShmSysConfigAndInfo->ate.maximumVoltage_value, ShmSysConfigAndInfo->ate.targetVoltage_Value, ShmSysConfigAndInfo->ate.maximumCurrent_value, ShmSysConfigAndInfo->ate.targetCurrent_Value);
  1726. }
  1727. //setEVStatus1(evstaus[2]);
  1728. //printf("targetVoltage_Value= %d targetCurrent_Value =%d maximumVoltage_value = %d maximumCurrent_value = %d linkVoltage = %d \n",ShmSysConfigAndInfo->ate.targetVoltage_Value, ShmSysConfigAndInfo->ate.targetCurrent_Value, ShmSysConfigAndInfo->ate.maximumVoltage_value, ShmSysConfigAndInfo->ate.maximumCurrent_value, ShmSysConfigAndInfo->ate.linkVoltage);
  1729. /*
  1730. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 500, TRUE, 0);
  1731. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10);
  1732. VCCU_V2G_EVTargetVoltage(400, U_V, TRUE, 0);
  1733. VCCU_V2G_EVTargetCurrent(U_A, 2, TRUE, 0);
  1734. VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1735. */
  1736. /*
  1737. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1738. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1739. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1740. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1741. */
  1742. //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1743. /*
  1744. if(ShmSysConfigAndInfo->ate.ATEStatus == 0){
  1745. //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1746. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
  1747. }else{
  1748. //VCCU_ChargeFromVehicle(CanFd, 500, 500, Not_allowed, Not_Active, Allowed, Not_allowed, Closed);
  1749. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Closed);
  1750. }
  1751. VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
  1752. 3, 0,
  1753. 3, 3, TRUE,
  1754. 3, 3, 3,
  1755. 3, 3, 0,
  1756. 3, 0, 3,
  1757. 3);
  1758. VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
  1759. VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
  1760. VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
  1761. VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
  1762. */
  1763. break;
  1764. }
  1765. case V_POWERDELIVERYFALSE:{
  1766. if (status){
  1767. printf("CCS POWERDELIVERYFALSE Processing 14....................\n");
  1768. }
  1769. /*
  1770. setEVStatus1(evstaus[3]);
  1771. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Opened);
  1772. */
  1773. break;
  1774. }
  1775. case V_DETECTION:{
  1776. if (status){
  1777. printf("CCS DETECTION Processing 15....................\n");
  1778. }
  1779. /*
  1780. setEVStatus1(evstaus[3]);
  1781. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1782. */
  1783. break;
  1784. }
  1785. case V_SESSION_STOP:{
  1786. if (status){
  1787. printf("CCS SESSION_STOP Processing 16....................\n");
  1788. }
  1789. /*
  1790. setEVStatus1(evstaus[3]);
  1791. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1792. */
  1793. break;
  1794. }
  1795. case V_STOP_COMMUNICATION_SESSION:{
  1796. if (status){
  1797. printf("CCS STOP_COMMUNICATION_SESSION Processing 17....................\n");
  1798. }
  1799. /*
  1800. setEVStatus1(evstaus[3]);
  1801. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1802. */
  1803. break;
  1804. }
  1805. case V_FINISHED:{
  1806. if (status){
  1807. printf("CCS FINISHED Processing 18....................\n");
  1808. }
  1809. /*
  1810. setEVStatus1(evstaus[3]);
  1811. VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
  1812. */
  1813. break;
  1814. }
  1815. default:{
  1816. break;
  1817. }
  1818. }
  1819. //usleep(100000);
  1820. usleep(whileLoopTime);
  1821. }else if(ShmSysConfigAndInfo->ate.ATEState == 2){//GB
  1822. if(ShmSysConfigAndInfo->ate.status == 0){
  1823. }else{
  1824. }
  1825. /*
  1826. printf("ProximitySignal = %d, state = %d Permission = %d TotalBatteryCap = %d MaxBatteryCurrent = %d MaxBatteryVoltage = %d ATEStatus = %d....................\n", ShmSysConfigAndInfo->ate.chademo.id03.state ,ShmSysConfigAndInfo->ate.Permission,
  1827. ShmSysConfigAndInfo->ate.chademo.id03.ProximitySignal, ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent,
  1828. ShmSysConfigAndInfo->ate.MaxBatteryVoltage, ShmSysConfigAndInfo->ate.ATEStatus);
  1829. printf("state = %d Permission = %d TotalBatteryCap = %d MaxBatteryCurrent = %d MaxBatteryVoltage = %d ATEStatus = %d K1K2Status = %d PresentBattVoltage = %d RequireVoltage = %d....................\n",
  1830. ShmSysConfigAndInfo->ate.chademo.id03.state ,
  1831. ShmSysConfigAndInfo->ate.Permission,
  1832. ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent,
  1833. ShmSysConfigAndInfo->ate.MaxBatteryVoltage, ShmSysConfigAndInfo->ate.ATEStatus,
  1834. ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status, ShmSysConfigAndInfo->ate.PresentBattVoltage, ShmSysConfigAndInfo->ate.RequireVoltage);
  1835. usleep(whileLoopTime);
  1836. */
  1837. //usleep(whileLoopTime);
  1838. }else if(ShmSysConfigAndInfo->ate.ATEState == 3){//chademo
  1839. }
  1840. }
  1841. printf("End. \n");
  1842. return FAIL;
  1843. }