12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090 |
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include "Config.h"
- #include <stdbool.h>
- #include "../../define.h"
- #include <dirent.h>
- #include "VCCU.h"
- #include "timeout.h"
- #include "IOComm.h"
- #include <unistd.h> //write, close, usleep, read
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include "Module_EvComm.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h> //write, close, usleep, read
- #include <fcntl.h> //uart
- #define Debug
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define FAIL -1
- #define START 1
- #define STOP 0
- #define BUFFER_SIZE 128
- #define YES 1
- #define NO 0
- #define NORMAL 0
- #define ABNORMAL 1
- #define EQUAL 0
- #define BTN_RELEASE 0
- #define BTN_PRESS 1
- #define MAX_BUF 64
- #define SendDirection 0x08000000
- #define FAIL -1
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct CHAdeMOData *ShmCHAdeMOData;
- struct CcsData *ShmCcsData;
- struct RelayModuleData *ShmRelayModuleData;
- struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb startPlugPresentStatusTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb startDutyCyclTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb endPlugPresentStatusTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb endDutyCyclTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- pid_t CANReceiverPid;
- int CanFd;
- int CanFd2;
- #define VIN_MAX_VOLTAGE 250
- #define VIN_MIN_VOLTAGE 170
- #define VIN_DROP_VOLTAGE 150
- byte gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
- #define btoa(x) ((x)?"true":"false")
- long hexToDec(char *source);
- int getIndexOfSigns(char ch);
- int whileLoopTime = 200000;
- int targetCurrent_Value = 120;
- int targetVoltage_Value = 500;
- int maximumCurrent_value = 200;
- int maximumVoltage_value = 500;
- int linkVoltage = 500;
- int contactorVoltage = 0;
- int maxValue = 950;
- int gbmaxValue = 750;
- int _port;
- #define YES 1
- #define NO 0
- byte flash = NO;
- byte normalStop = 0x01;
- byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- byte evstaus[5] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
- struct Ev_Board_Cmd Ev_Cmd={
- 0,
- 0x00000200,
- 0x00000400,
- 0x00000500,
- 0x00000600,
- 0x00000700,
- 0x00000800,
- 0x00000900,
- 0x00000A00,
- 0x00000C00,
- 0x00000D00,
- 0x00000E00,
- 0x00000F00,
- 0x00001000,
- 0x00001100,
- 0x00001200,
- 0x00001500,
- };
- int CreatShareMemory()
- {
- int MeterSMId;
-
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- return 0;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
-
- #endif
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
-
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0){
- #ifdef SystemLogMessage
-
- #endif
- return 0;
- }
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1){
- #ifdef SystemLogMessage
-
- #endif
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
-
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
-
- #endif
- return 0;
- }
- memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
- return 1;
- }
- unsigned long GetTimeoutValue(struct timeval _sour_time);
- unsigned long GetTimeoutValue(struct timeval _sour_time)
- {
- struct timeval _end_time;
- gettimeofday(&_end_time, NULL);
- return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
- }
- int InitCanBus()
- {
- int s0, nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
-
-
- system("/sbin/ip link set can0 down");
- system("/sbin/ip link set can0 type can bitrate 250000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if(setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- }
- nbytes = 40960;
- if(setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- }
- nbytes = 40960;
- if(setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- }
-
- strcpy(ifr0.ifr_name, "can0" );
- ioctl(s0, SIOCGIFINDEX, &ifr0);
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- int CHROMAInitCanBus()
- {
- int s0,nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
- system("/sbin/ip link set can1 down");
- system("/sbin/ip link set can1 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can1 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- }
- strcpy(ifr0.ifr_name, "can1" );
- ioctl(s0, SIOCGIFINDEX, &ifr0);
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- int DiffTimeb(struct timeb ST, struct timeb ET)
- {
-
- unsigned int StartTime,StopTime;
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
-
- return (StopTime-StartTime);
- }
- void StopGunInfoTimeoutDet(unsigned char gunIndex)
- {
- if (gunIndex < gunCount)
- {
- chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
- }
- }
- void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
- {
- if (gunIndex < gunCount)
- {
- if (chargingInfo[gunIndex]->TimeoutFlag != flag)
- {
- gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
- }
- chargingInfo[gunIndex]->TimeoutFlag = flag;
- }
- }
- unsigned short MaxValue(unsigned short value1, unsigned short value2)
- {
- return value1 >= value2 ? value1 : value2;
- }
- unsigned char isATEChange(unsigned char gun_index)
- {
- unsigned char result = NO;
- if(chargingInfo[gun_index]->ATEState != chargingInfo[gun_index]->PreviousATEState)
- {
- result = YES;
- chargingInfo[gun_index]->PreviousATEState = chargingInfo[gun_index]->ATEState;
- }
- return result;
- }
- unsigned char isModeChange(unsigned char gun_index)
- {
- unsigned char result = NO;
- if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
- {
- result = YES;
- chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
- }
- return result;
- }
- unsigned char checkMode(byte gun_index, byte mode)
- {
- unsigned char result = NO;
- if(chargingInfo[gun_index]->SystemStatus != mode)
- {
- result = YES;
- }
- return result;
- }
- void setChargerMode(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->SystemStatus = mode;
- }
- void setATEMode(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->ATEStatus = mode;
- }
- void setStatusMode(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->ATEStatus = mode;
- }
- unsigned char isStatusChange(unsigned char gun_index)
- {
- unsigned char result = NO;
- if(chargingInfo[gun_index]->ATEStatus != chargingInfo[gun_index]->PreviousATEStatus)
- {
- result = YES;
- chargingInfo[gun_index]->PreviousATEStatus = chargingInfo[gun_index]->ATEStatus;
- }
- return result;
- }
- int PackageIdCmd(int cmd)
- {
- return cmd | 0x80000000;
- }
- void SendCmdToEvboard(int canfd, int cmd, byte *data, byte dataLen)
- {
- struct can_frame frame;
- frame.can_id = PackageIdCmd(cmd);
- frame.can_dlc = dataLen;
- memcpy(frame.data, data, sizeof(frame.data));
- write(canfd, &frame, sizeof(struct can_frame));
-
- }
- void setBootNotification1(){
- byte data[8];
- data[0] = 0x02;
- data[1] = 0x02;
- data[2] = 0x02;
- data[3] = 0x02;
- data[4] = 0x03;
- data[5] = 0x03;
- data[6] = 0x03;
- data[7] = 0x03;
- SendCmdToEvboard(CanFd2, bn1, data, sizeof(data));
- }
- void setBootNotification2(){
- byte data[8];
- data[0] = 0x04;
- data[1] = 0x04;
- data[2] = 0x04;
- data[3] = 0x04;
- data[4] = 0x05;
- data[5] = 0x05;
- data[6] = 0x05;
- data[7] = 0x05;
- SendCmdToEvboard(CanFd2, bn2, data, sizeof(data));
- }
- void setEVStatus1(byte evstatus){
- byte data[1];
- data[0] = evstatus;
- SendCmdToEvboard(CanFd2, EVStatus1, data, sizeof(data));
- }
- void setEVStatus2(byte evstatus){
- byte data[1];
- data[0] = evstatus;
- SendCmdToEvboard(CanFd2, EVStatus2, data, sizeof(data));
- }
- void GetFirmwareVersion(byte gun_index, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.get_firmware_ver + toId);
- byte data[8];
- SendCmdToEvboard(CanFd, id, data, 0);
- }
- void GetHardwareVersion(byte gun_index, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.get_hardware_ver + toId);
- byte data[8];
- SendCmdToEvboard(CanFd, id, data, 0);
- }
- void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.charging_permission + toId);
- byte data[8];
- data[0] = permissionStatus;
- data[1] = aOutputPw & 0xff;
- data[2] = (aOutputPw >> 8) & 0xff;
- data[3] = aOutputCur & 0xff;
- data[4] = (aOutputCur >> 8) & 0xff;
- data[5] = aOutputVol & 0xff;
- data[6] = (aOutputVol >> 8) & 0xff;
- data[7] = 0xff;
-
- SendCmdToEvboard(CanFd, id, data, sizeof(data));
- }
- void GetMiscellaneousInfo(byte gun_index, byte toId, short K1K2Status, short soc)
- {
- int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId);
- byte data[8];
- data[0] = 0x01;
- data[1] = 0x02;
- data[2] = 0x03;
- data[3] = 0x04;
- data[4] = 0x05;
- data[5] = K1K2Status & 0xff;
- data[6] = soc & 0xff;
- data[7] = 0x08;
-
-
- SendCmdToEvboard(CanFd, id, data, sizeof(data));
- }
- void SetPresentInputPower(short outputVol_b1, short outputCur_b1, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.present_input_power + toId);
- byte data[8];
- data[0] = outputVol_b1 & 0xff;
- data[1] = (outputVol_b1 >> 8) & 0xff;
- data[2] = outputCur_b1 & 0xff;
- data[3] = (outputCur_b1 >> 8) & 0xff;
-
-
- SendCmdToEvboard(CanFd, id, data, sizeof(data));
- }
- void SetPresentInputRequirement(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.present_input_requirement + toId );
- byte data[8];
- data[0] = aOutputPw_b1 & 0xff;
- data[1] = (aOutputPw_b1 >> 8) & 0xff;
- data[2] = aOutputCur_b1 & 0xff;
- data[3] = (aOutputCur_b1 >> 8) & 0xff;
- data[4] = aOutputPw_b2 & 0xff;
- data[5] = (aOutputPw_b2 >> 8) & 0xff;
- data[6] = aOutputCur_b2 & 0xff;
- data[7] = 0x01;
-
-
- SendCmdToEvboard(CanFd, id, data, sizeof(data));
- }
- void GetEvseOutputStatus(byte gun_index, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.get_evse_output_status + toId);
- byte data[8];
- SendCmdToEvboard(CanFd, id, data, 0);
- }
- void GetEvseCapacityInfo(byte gun_index, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.get_evse_capacity_info + toId);
- byte data[8];
- SendCmdToEvboard(CanFd, id, data, 0);
- }
- void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.evse_stop_charging + toId);
- byte data[8];
- data[0] = stopResult;
- data[1] = *stopReason;
- data[2] = *(stopReason + 1);
- data[3] = *(stopReason + 2);
- data[4] = *(stopReason + 3);
- data[5] = *(stopReason + 4);
- data[6] = *(stopReason + 5);
- SendCmdToEvboard(CanFd, id, data, sizeof(data));
- }
- void SetIsolationStatus(byte gun_index, byte result, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.isolation_status + toId);
- byte data[8];
- data[0] = result;
- SendCmdToEvboard(CanFd, id, data, 1);
- }
- void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId)
- {
- int id = PackageIdCmd(Ev_Cmd.evse_precharge_info + toId);
- byte data[8];
- data[0] = result;
- SendCmdToEvboard(CanFd, id, data, 1);
- }
- void handleEmulatorFaultStatus(){
- setEVStatus2(evstaus[4]);
- ShmSysConfigAndInfo->ate.Permission = STOP;
- setStatusMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission);
- ShmSysConfigAndInfo->ate.ATEStatus = 0x00;
- SetChargingPermission(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.TotalBatteryCap,
- ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, 1);
- EvseStopChargingEvent(normalStop, stopReason, 1);
- }
- int bitExtracted(byte number, int k, int p)
- {
- return (((1 << k) - 1) & (number >> (p - 1)));
- }
- unsigned short bitextract(unsigned short value, int begin, int end)
- {
- unsigned short mask = (1 << (end - begin)) - 1;
- return (value >> begin) & mask;
- }
- bool CheckUniqNumber(byte value)
- {
- for (byte index = 0; index < gunCount; index++)
- {
- if (chargingInfo[index]->Evboard_id == value)
- {
- struct timeval _end_time;
- gettimeofday(&_end_time, NULL);
- unsigned long diff = 1000000 * (_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
- if (diff >= 3000000)
- {
- gettimeofday(&_id_assign_time, NULL);
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- gettimeofday(&_id_assign_time, NULL);
- return true;
- }
- void SetTargetAddr(byte *target_number, byte index)
- {
- int id = PackageIdCmd(Ev_Cmd.address_assignment + index);
-
-
- byte data[8];
- data[0] = *target_number;
- data[1] = *(target_number + 1);
- data[2] = *(target_number + 2);
- data[3] = *(target_number + 3);
- data[4] = index;
- SendCmdToEvboard(CanFd2, id, data, sizeof(data));
- }
- void AddrAssignment(byte *data)
- {
- byte target_number[8];
- byte index = 0x00;
- memcpy(target_number, data, sizeof(target_number));
- index = *(data + 4);
- if (CheckUniqNumber(index))
- {
- printf("EV board id = %x \n", index);
- if (index < 1)
- return;
- printf("SetTargetAddr \n");
- SetTargetAddr(target_number, index);
- }
- }
- void VCCU_TD(){
- byte data[8];
- data[0] = 0x00;
- data[1] = 0x00;
- data[2] = 0x01;
- data[3] = 0x01;
- data[4] = 0x00;
- data[5] = 0x00;
- data[6] = 0x42;
- data[7] = 0x66;
- SendCmdToEvboard(CanFd, TDId, data, sizeof(data));
- }
- void VCCU_ChargeFromVehicle(int canfd, int linkVoltage, int contactorVoltage,
- int chargePermission, int isolationMeasurem,
- int plugLockPermissio, int plugUnlockPermiss, int contactorStatus){
- struct VCCU_ChargeFromVehicle obj;
- obj.VCCU_Vehicle_LinkVoltage= linkVoltage;
- obj.VCCU_Vehicle_ContactorVoltage = contactorVoltage;
- obj.DATA.bits.VCCU_Vehicle_ChargePermission = chargePermission;
- obj.DATA.bits.VCCU_Vehicle_IsolationMeasurem = isolationMeasurem;
- obj.DATA.bits.VCCU_Vehicle_PlugLockPermissio = plugLockPermissio;
- obj.DATA.bits.VCCU_Vehicle_PlugUnlockPermiss = plugUnlockPermiss;
- obj.bits.VCCU_Vehicle_ContactorStatus = contactorStatus;
- obj.bits.VCCU_Vehicle_StopCharge = 3;
- obj.bits.VCCU_Vehicle_ChargeSelection = 3;
- byte* data1;
- data1 = (byte*) &(*((UWORD *) &obj.VCCU_Vehicle_ContactorVoltage));
- byte* data2;
- data2 = (byte*) &(*((UWORD *) &obj.VCCU_Vehicle_LinkVoltage));
- byte data[6];
- data[0] = data1[0];
- data[1] = data1[1];
- data[2] = data2[0];
- data[3] = data2[1];
- data[4] = *((UBYTE *) &obj.DATA);
- data[5] = *((UBYTE *) &obj.bits);
-
- SendCmdToEvboard(canfd, VCCU_ChargeFromVehicleIds, data, sizeof(data));
- }
- void VCCU_V2G_VehicleStatus(int canfd, int EnergyTra, int EVErrorCode,
- int EVPowerDeliveryParame, int EVRESSSOC,
- int EVRESSConditioningFla, int EVRESSConditionin, int EVReady,
- int BulkChargingCompleteF, int EVCabinConditioningFl, int EVCabinConditioning,
- int ChargingComplete, int FullSOCFlag, int FullSOC,
- int BulkSOCFlag, int BulkSOC, int BulkChargingComplete,
- int BulkChargingCompleteFValue){
- struct VCCU_V2G_VehicleStatus obj;
- obj.DATA4.VCCU_V2G_StateM_EnergyTra_0000 = EnergyTra;
- obj.DATA1.VCCU_V2G_EVErrorCode = EVErrorCode;
- obj.DATA4.VCCU_V2G_EVPowerDeliveryParame = EVPowerDeliveryParame;
- obj.VCCU_V2G_EVRESSSOC.value = EVRESSSOC;
- obj.DATA3.VCCU_V2G_EVRESSConditioningFla = EVRESSConditioningFla;
- obj.DATA3.VCCU_V2G_EVRESSConditioning = EVRESSConditionin;
- obj.DATA3.VCCU_V2G_EVReady = EVReady;
- obj.DATA1.VCCU_V2G_BulkChargingCompleteF = BulkChargingCompleteF;
- obj.DATA3.VCCU_V2G_EVCabinConditioningFl = EVCabinConditioningFl;
- obj.DATA2.VCCU_V2G_EVCabinConditioning = EVCabinConditioning;
- obj.DATA2.VCCU_V2G_ChargingComplete = ChargingComplete;
- obj.DATA2.VCCU_V2G_FullSOCFlag = FullSOCFlag;
- obj.VCCU_V2G_FullSOC.value = FullSOC;
- obj.DATA2.VCCU_V2G_BulkSOCFlag = BulkSOCFlag;
- obj.VCCU_V2G_BulkSOC.value = BulkSOC;
- obj.DATA1.VCCU_V2G_BulkChargingComplete = BulkChargingComplete;
- obj.DATA1.VCCU_V2G_BulkChargingCompleteF = BulkChargingCompleteFValue;
- byte data[7];
- data[0] = *((UBYTE *) &obj.DATA1);
- data[1] = *((UBYTE *) &obj.DATA2);
- data[2] = *((UBYTE *) &obj.DATA3);
- data[3] = *((UBYTE *) &obj.DATA4);
- data[4] = *((UBYTE *) &obj.VCCU_V2G_BulkSOC);
- data[5] = *((UBYTE *) &obj.VCCU_V2G_FullSOC);
- data[6] = *((UBYTE *) &obj.VCCU_V2G_EVRESSSOC);
-
- SendCmdToEvboard(canfd, VCCU_V2G_VehicleStatusIds, data, sizeof(data));
- }
- void VCCU_V2G_EVMaximumVoltageLimit(int VMaximumVoltageLimit,
- int EVMaximumVoltage_0002,
- int EVMaximumVoltage_0000,
- int EVMaximumVoltage_0001,
- int EVMaximumVoltage_0003){
- struct VCCU_V2G_EVMaximumVoltageLimit obj;
- obj.DATA1.VCCU_V2G_EVMaximumVoltageLimit = VMaximumVoltageLimit;
- obj.DATA1.VCCU_V2G_EVMaximumVoltage_0002 = EVMaximumVoltage_0002;
- obj.VCCU_V2G_EVMaximumVoltage_0000.value = EVMaximumVoltage_0000;
- obj.VCCU_V2G_EVMaximumVoltage_0001.value = EVMaximumVoltage_0001;
- obj.VCCU_V2G_EVMaximumVoltage_0003.value = EVMaximumVoltage_0003;
- byte* data1;
- data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVMaximumVoltage_0000));
- byte data[5];
- data[0] = *((UBYTE *) &obj.DATA1);
- data[1] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumVoltage_0003);
- data[2] = data1[0];
- data[3] = data1[1];
- data[4] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumVoltage_0001);
-
- SendCmdToEvboard(CanFd, VCCU_V2G_EVMaximumVoltageLimitIds, data, sizeof(data));
- }
- void VCCU_V2G_EVMaximumCurrentLimit(int EVMaximumCurrentLimit,
- int EVMaximumCurrent_0000,
- int EVMaximumCurrent_0001,
- int EVMaximumCurrent_0002,
- int EVMaximumCurrent_0003){
- struct VCCU_V2G_EVMaximumCurrentLimit obj;
- obj.DATA1.VCCU_V2G_EVMaximumCurrentLimit = EVMaximumCurrentLimit;
- obj.DATA1.VCCU_V2G_EVMaximumCurrent_0000 = EVMaximumCurrent_0000;
- obj.VCCU_V2G_EVMaximumCurrent_0001.value = EVMaximumCurrent_0001;
- obj.VCCU_V2G_EVMaximumCurrent_0002.value = EVMaximumCurrent_0002;
- obj.VCCU_V2G_EVMaximumCurrent_0003.value = EVMaximumCurrent_0003;
- byte* data1;
- data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVMaximumCurrent_0003));
- byte data[5];
- data[0] = *((UBYTE *) &obj.DATA1);
- data[1] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumCurrent_0002);
- data[2] = data1[0];
- data[3] = data1[1];
- data[4] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumCurrent_0001);
-
- SendCmdToEvboard(CanFd, VCCU_V2G_EVMaximumCurrentLimitIds, data, sizeof(data));
- }
- void VCCU_V2G_EVTargetCurrent(int EVTargetCurrent_Unit,
- int EVTargetCurrent_Value,
- int EVTargetCurrent_UnitF,
- int EVTargetCurrent_Multi){
- struct VCCU_V2G_EVTargetCurrent obj;
- obj.VCCU_V2G_EVTargetCurrent_Unit.value = EVTargetCurrent_Unit;
- obj.VCCU_V2G_EVTargetCurrent_Value.value = EVTargetCurrent_Value;
- obj.VCCU_V2G_EVTargetCurrent_UnitF.value = EVTargetCurrent_UnitF;
- obj.VCCU_V2G_EVTargetCurrent_Multi.value = EVTargetCurrent_Multi;
- byte* data1;
- data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVTargetCurrent_Value));
- byte data[5];
- data[0] = data1[0];
- data[1] = data1[1];
- data[2] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_Multi);
- data[3] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_UnitF);
- data[4] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_Unit);
-
- SendCmdToEvboard(CanFd, VCCU_V2G_EVTargetCurrentIds, data, sizeof(data));
- }
- void VCCU_V2G_EVTargetVoltage(int EVTargetVoltage_Value,
- int EVTargetVoltage_Unit,
- int EVTargetVoltage_UnitF,
- int EVTargetVoltage_Multi){
- struct VCCU_V2G_EVTargetVoltage obj;
- obj.VCCU_V2G_EVTargetVoltage_Value.value = EVTargetVoltage_Value;
- obj.VCCU_V2G_EVTargetVoltage_Unit.value = EVTargetVoltage_Unit;
- obj.VCCU_V2G_EVTargetVoltage_UnitF.value = EVTargetVoltage_UnitF;
- obj.VCCU_V2G_EVTargetVoltage_Multi.value = EVTargetVoltage_Multi;
- byte* data1;
- data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVTargetVoltage_Value));
- byte data[5];
- data[0] = data1[0];
- data[1] = data1[1];
- data[2] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_Multi);
- data[3] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_UnitF);
- data[4] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_Unit);
-
-
- SendCmdToEvboard(CanFd, VCCU_V2G_EVTargetVoltageIds, data, sizeof(data));
- }
- void VCCU_Requests(int LED0, int LED1, int LED2,
- int HighSideOut0, int HighSideOut1, int HighSideOut2, int HighSideOut3,
- int HighSideOut4, int RTC_TimerRequest, int PlugLock,
- int RTC_TimerValue,
- int ControlPilot, int ChargeUnit, int Inlet){
- struct VCCU_Requests obj;
- obj.VCCU_LED0_Request = LED0;
- obj.VCCU_LED1_Request = LED1;
- obj.VCCU_LED2_Request = LED2;
- obj.byte3.VCCU_HighSideOut0_Request = HighSideOut0;
- obj.byte3.VCCU_HighSideOut1_Request = HighSideOut1;
- obj.byte3.VCCU_HighSideOut2_Request = HighSideOut2;
- obj.byte3.VCCU_HighSideOut3_Request = HighSideOut3;
- obj.byte4.VCCU_HighSideOut4_Request = HighSideOut4;
- obj.byte4.VCCU_RTC_TimerRequest = RTC_TimerRequest;
- obj.byte4.VCCU_PlugLock_MotorRequest = PlugLock;
- obj.VCCU_RTC_TimerValue= RTC_TimerValue;
- obj.byte6.VCCU_ControlPilot_ChargeModeRe = ControlPilot;
- obj.byte6.VCCU_ChargeUnit_Request = ChargeUnit;
- obj.byte6.VCCU_Inlet_MotorRequest = Inlet;
- byte data[7];
- data[0] = *((UBYTE *) &obj.VCCU_LED0_Request);
- data[1] = *((UBYTE *) &obj.VCCU_LED1_Request);
- data[2] = *((UBYTE *) &obj.VCCU_LED2_Request);
- data[3] = *((UBYTE *) &obj.byte3);
- data[4] = *((UBYTE *) &obj.byte4);
- data[5] = *((UBYTE *) &obj.VCCU_RTC_TimerValue);
- data[6] = *((UBYTE *) &obj.byte6);
-
- SendCmdToEvboard(CanFd, VCCU_RequestsIds, data, sizeof(data));
- }
- bool MatedPlugInletUnlocked_Status(){
- return (ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Connected &&
-
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == ChargeV2G
-
- );
- }
- bool PreCharge_Statue(){
- return ((ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge ) &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC &&
-
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested);
- }
- bool status1(){
- bool result = false;
- result = (ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed
- && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Unlocked );
- return result;
- }
- bool status2(){
- bool result = false;
- result = ((ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_DutyCycle.bits.value >= 5
- && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_DutyCycle.bits.value <= 7)
- && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked
- && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == EVSEStateB2
- && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_DigitalInput_Status == Not_pressed
- && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_S3Switch_Status == Not_pressed);
- return result;
- }
- bool UnmatedPlug(){
- bool result = false;
-
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_Initialized &&
-
-
-
- (ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateA ||
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateE ||
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB1) &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == VCCU_ChargeUnit_Mode_SNA &&
-
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == ForceOpen &&
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Requested ){
-
- result = true;
-
-
- setChargerMode(CCS_QUANTITY, V_UNMATEDPLUG);
- }
- return result;
- }
- bool MatedPlugInletUnlocked(){
- bool result = false;
- if(MatedPlugInletUnlocked_Status() && chargingInfo[CCS_QUANTITY]->SystemStatus == V_IDLE){
-
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_MATED_PLUG_INLET_UNLOCKED);
- }
- return result;
- }
- bool InletLocking(){
- bool result = false;
- if(
- status1() &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving
- ){
- result = true;
-
-
- setChargerMode(CCS_QUANTITY, V_INLETLOCKING);
- }
- return result;
- }
- bool InletLocked(){
- bool result = false;
- if(MatedPlugInletUnlocked_Status() && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked){
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_INLETLOCKED);
- }
- return result;
- }
- bool DC05_Status(){
- return (status1() && status2() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SLAC || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == WaitForIP ||
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SECCDiscoveryProtocol || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == TLConnection ||
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SupportedAppProtocol || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SessionSetup ||
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ServiceDiscovery || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ServiceDetails ||
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentServiceSelection || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CertificateInstallation ||
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CertificateUpdate || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentDetails ||
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentDetails || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == Authorization )
- && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open);
- }
- bool S_SLAC(){
- bool result = false;
- if(MatedPlugInletUnlocked_Status() && DC05_Status()){
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_SLAC);
- }
- return result;
- }
- bool Definition(){
- bool result = false;
- if(MatedPlugInletUnlocked_Status() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ChargeParameterDiscovery ) &&
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open){
- result = true;
- setChargerMode(CCS_QUANTITY, V_DEFINITION);
- }
- return result;
- }
- bool S_CableCheck(){
- bool result = false;
- if(MatedPlugInletUnlocked_Status() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CableCheck )){
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_CABLECHECK);
- }
- return result;
- }
- bool Isolation(){
- bool result = false;
- if(MatedPlugInletUnlocked_Status() && PreCharge_Statue()){
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_ISOLATION);
- }
- return result;
- }
- bool S_PreCharge(){
- bool result = false;
- if(PreCharge_Statue()){
-
-
- setChargerMode(CCS_QUANTITY, V_VOLTAGEDIFFERENCE);
- }
- return result;
- }
- bool Contactors(){
- bool result = false;
- if( PreCharge_Statue()
-
- ){
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_CONTACTORSCLOSED);
- }
- return result;
- }
- bool S_PowerDelivery(){
- bool result = false;
-
- if(ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC &&
- chargingInfo[CCS_QUANTITY]->SystemStatus == V_CONTACTORSCLOSED &&
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PowerDelivery &&
-
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested
- && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Close
- ){
- result = true;
-
-
- setChargerMode(CCS_QUANTITY, V_POWERDELIVERY);
- }
- return result;
- }
- bool S_CurrentDemand(){
- bool result = false;
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CurrentDemand){
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_CURRENTDEMAND);
- }
- return result;
- }
- bool PowerDeliveryFalse(){
- bool result = false;
- if(
- chargingInfo[CCS_QUANTITY]->SystemStatus == V_CURRENTDEMAND &&
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PowerDelivery
- && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open
-
- ){
- result = true;
- setChargerMode(CCS_QUANTITY, V_POWERDELIVERYFALSE);
-
- }
- return result;
- }
- bool S_WeldingDetection(){
- bool result = false;
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == WeldingDetection){
- result = true;
- setChargerMode(CCS_QUANTITY, V_DETECTION);
- }
- return result;
- }
- bool SessionStop(){
- bool result = false;
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_SessionStop &&
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Requested){
- result = true;
- setChargerMode(CCS_QUANTITY, V_SESSION_STOP);
- }
- return result;
- }
- bool StopCommunicationSession(){
- bool result = false;
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_StopCommunicationSession ){
- result = true;
- setChargerMode(CCS_QUANTITY, V_STOP_COMMUNICATION_SESSION);
- }
- return result;
- }
- bool DCFinished(){
- bool result = false;
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_Finished ){
- result = true;
- setChargerMode(CCS_QUANTITY, V_FINISHED);
- }
- return result;
- }
- bool statusCheck(){
- bool result = false;
-
- UnmatedPlug();
- MatedPlugInletUnlocked();
- InletLocking();
- InletLocked();
- S_SLAC();
- Definition();
- S_CableCheck();
- Isolation();
- S_PreCharge();
- Contactors();
- S_PowerDelivery();
- S_CurrentDemand();
- PowerDeliveryFalse();
- S_WeldingDetection();
- SessionStop();
- StopCommunicationSession();
- DCFinished();
- return result;
- }
- bool AcUnmatedPlug(){
- bool result = false;
- if((ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateA ||
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateE ||
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB1) &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == VCCU_ChargeUnit_Mode_SNA ){
-
- result = true;
- setChargerMode(CCS_QUANTITY, V_UNMATEDPLUG);
- }
- return result;
- }
- bool AcMatedPlugInletUnlocked(){
- bool result = false;
- if( (ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Connected &&
-
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == ChargePwm
-
- ) && chargingInfo[CCS_QUANTITY]->SystemStatus == V_IDLE){
-
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_MATED_PLUG_INLET_UNLOCKED);
- }
- return result;
- }
- bool acInletLocking(){
- bool result = false;
- if(
- (ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed
- && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Unlocked &&
- ((chargingInfo[CCS_QUANTITY]->PlugPresentStatusDuration >= 2) &&
- chargingInfo[CCS_QUANTITY]->DutyCycleDuration >= 2)) &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving
- ){
- result = true;
-
-
- setChargerMode(CCS_QUANTITY, V_INLETLOCKING);
- }
- return result;
- }
- bool acStatusCheck(){
- bool result = false;
- AcUnmatedPlug();
- AcMatedPlugInletUnlocked();
- return result;
- }
- long hexToDec(char *source)
- {
- long sum = 0;
- long t = 1;
- int i, len;
- len = strlen(source);
- for(i=len-1; i>=0; i--)
- {
- sum += t * getIndexOfSigns(*(source + i));
- t *= 16;
- }
- return sum;
- }
- int getIndexOfSigns(char ch)
- {
- if(ch >= '0' && ch <= '9')
- {
- return ch - '0';
- }
- if(ch >= 'A' && ch <='F')
- {
- return ch - 'A' + 10;
- }
- if(ch >= 'a' && ch <= 'f')
- {
- return ch - 'a' + 10;
- }
- return -1;
- }
- void Initialization(){
- char *moduleName = "DMYZ30100J01P0";
- memcpy(&ShmSysConfigAndInfo->SysConfig.ModelName, moduleName, strlen(moduleName));
-
- ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY].Index = CCS_QUANTITY;
- ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY].slotsIndex = 1;
- chargingInfo[CCS_QUANTITY] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY];
- chargingInfo[CCS_QUANTITY]->SystemStatus = V_IDLE;
- chargingInfo[CCS_QUANTITY]->Type = _Type_CCS;
- chargingInfo[CCS_QUANTITY]->type_index = CCS_QUANTITY;
- chargingInfo[CCS_QUANTITY]->Evboard_id = 0x01;
- ShmSysConfigAndInfo->ate.ATEStatus = 0;
-
- ShmCcsData->CommProtocol = 0x01;
-
- }
- bool CheckConnectorTypeStatus()
- {
- bool result = true;
- return result;
- }
- void SpawnTask()
- {
- sleep(2);
- system("/root/Module_InternalComm &");
- system("/root/Module_EvComm &");
-
- }
- void KillTask()
- {
- system("killall Module_InternalComm");
- system("killall Module_EvComm");
- }
- int main(void){
-
-
-
- if(CreatShareMemory()==0){
- #ifdef SystemLogMessage
-
- #endif
- if(ShmStatusCodeData!=NULL)
- {
-
- }
- return 0;
- sleep(5);
- system("reboot -f");
- }
-
-
-
- KillTask();
-
-
- Initialization();
- SpawnTask();
-
-
-
-
-
-
-
-
-
-
-
-
- ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status=0x00;
- ShmSysConfigAndInfo->ate.chademo.id0D_req.Soc = 50;
- ShmSysConfigAndInfo->ate.ateMode = 0;
- ShmSysConfigAndInfo->ate.ATEState = 2;
-
-
-
-
-
-
-
-
-
-
- ShmSysConfigAndInfo->ate.targetCurrent_Value = targetCurrent_Value;
- ShmSysConfigAndInfo->ate.targetVoltage_Value = targetVoltage_Value;
- ShmSysConfigAndInfo->ate.maximumCurrent_value = maximumCurrent_value;
- ShmSysConfigAndInfo->ate.maximumVoltage_value = maximumVoltage_value;
- ShmSysConfigAndInfo->ate.linkVoltage = linkVoltage;
- ShmSysConfigAndInfo->ate.contactorVoltage = contactorVoltage;
-
-
- ShmSysConfigAndInfo->ate.PresentBattVoltage = 4700;
- ShmSysConfigAndInfo->ate.MinimumChargeCurrent = 20;
-
- ShmSysConfigAndInfo->ate.RequireVoltage = 4800;
-
- ShmSysConfigAndInfo->ate.RequireCurrent = 600;
- ShmSysConfigAndInfo->ate.chademoTargetVoltage_Value = 4800;
- ShmSysConfigAndInfo->ate.chademoTargetCurrent_Value = 30;
-
- ShmSysConfigAndInfo->ate.Permission = STOP;
- ShmSysConfigAndInfo->ate.TotalBatteryCap = 1000;
- ShmSysConfigAndInfo->ate.MaxBatteryCurrent = 1200;
- ShmSysConfigAndInfo->ate.MaxBatteryVoltage = 5000;
- ShmSysConfigAndInfo->ate.status = 0;
- ShmSysConfigAndInfo->ate.chademo.id03.state = 0;
- ShmSysConfigAndInfo->ate.ATEStatus = 0x00;
- ShmSysConfigAndInfo->ate.cstatus = 0;
- ShmSysConfigAndInfo->ate.chademo.PresentChargedDuration = 0;
- ShmSysConfigAndInfo->ate.chademo.RemainChargingDuration = 0;
- setStatusMode(CCS_QUANTITY, STOP);
- if(ShmSysConfigAndInfo->ate.ATEState == 1){
- }else if(ShmSysConfigAndInfo->ate.ATEState == 2){
- }
- setATEMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.ATEState);
- ftime(&startChargingTime[CCS_QUANTITY]);
- chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
- StopGunInfoTimeoutDet(CCS_QUANTITY);
- StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
-
- printf("version = ....................\n" );
- while(true){
-
- if(ShmSysConfigAndInfo->ate.ATEState == 1){
-
-
- }else if(ShmSysConfigAndInfo->ate.ATEState == 2){
-
-
- }else{
-
- }
- int state = isATEChange(CCS_QUANTITY);
- if(state){
- }
- if(ShmSysConfigAndInfo->ate.ATEState == 1){
-
-
-
-
-
-
-
- statusCheck();
- int status = isModeChange(CCS_QUANTITY);
-
- switch(chargingInfo[CCS_QUANTITY]->SystemStatus){
- case V_IDLE:{
- if (status){
- printf("CCS IDLE Processing 1....................\n");
- }
-
- break;
- }
- case V_UNMATEDPLUG:{
- if (status){
- printf("CCS UNMATEDPLUG Processing 2....................\n");
- }
-
-
- break;
- }
- case V_MATED_PLUG_INLET_UNLOCKED:{
- if (status){
- if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected){
- }
- printf("CCS MATED_PLUG_INLET_UNLOCKED Processing 3....................\n");
- }
-
-
-
- break;
- }
- case V_INLETLOCKING:{
- if (status){
- printf("CCS INLETLOCKING Processing 4....................\n");
- }
-
- break;
- }
- case V_INLETLOCKED:{
- if (status){
- printf("CCS INLETLOCKED Processing 5....................\n");
- }
-
-
- break;
- }
- case V_SLAC:{
- if (status){
- printf("CCS SLAC Processing 6....................\n");
- }
-
-
-
-
- break;
- }
- case V_DEFINITION:{
- if (status){
- printf("CCS DEFINITION Processing 7....................\n");
- }
-
-
-
-
- break;
- }
- case V_CABLECHECK:{
- if (status){
- printf("CCS CABLECHECK Processing 8 ....................\n");
- }
-
- break;
- }
- case V_ISOLATION:{
- if (status){
- printf("CCS ISOLATION Processing 9 %d ....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va );
- ftime(&startChargingTime[CCS_QUANTITY]);
- }
-
- break;
- }
- case V_VOLTAGEDIFFERENCE:{
- if (status){
- printf("CCS VOLTAGEDIFFERENCE Processing 10 ....................\n");
- ftime(&startChargingTime[CCS_QUANTITY]);
- chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
- StopGunInfoTimeoutDet(CCS_QUANTITY);
- StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
- }
- ftime(&endChargingTime[CCS_QUANTITY]);
- chargingInfo[CCS_QUANTITY]->RemainChargingDuration = DiffTimeb(startChargingTime[CCS_QUANTITY], endChargingTime[CCS_QUANTITY]);
-
-
- if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000)
- {
- ftime(&startChargingTime[CCS_QUANTITY]);
- chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
- StopGunInfoTimeoutDet(CCS_QUANTITY);
- StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
- }
-
-
- break;
- }
- case V_CONTACTORSCLOSED:{
- if (status){
- printf("CCS CONTACTORSCLOSED Processing 11 %d %d....................\n",ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va, ShmSysConfigAndInfo->ate.linkVoltage );
- }
-
- break;
- }
- case V_POWERDELIVERY:{
- if (status){
- printf("CCS POWERDELIVERY Processing 12 %d %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va, ShmSysConfigAndInfo->ate.linkVoltage );
- }
-
-
- break;
- }
- case V_CURRENTDEMAND:{
- if (status){
- printf("CCS CURRENTDEMAND Processing 13 %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va );
- 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);
- }
-
-
-
-
-
-
- break;
- }
- case V_POWERDELIVERYFALSE:{
- if (status){
- printf("CCS POWERDELIVERYFALSE Processing 14....................\n");
- }
-
- break;
- }
- case V_DETECTION:{
- if (status){
- printf("CCS DETECTION Processing 15....................\n");
- }
-
- break;
- }
- case V_SESSION_STOP:{
- if (status){
- printf("CCS SESSION_STOP Processing 16....................\n");
- }
-
- break;
- }
- case V_STOP_COMMUNICATION_SESSION:{
- if (status){
- printf("CCS STOP_COMMUNICATION_SESSION Processing 17....................\n");
- }
-
- break;
- }
- case V_FINISHED:{
- if (status){
- printf("CCS FINISHED Processing 18....................\n");
- }
-
- break;
- }
- default:{
- break;
- }
- }
-
- usleep(whileLoopTime);
- }else if(ShmSysConfigAndInfo->ate.ATEState == 2){
- if(ShmSysConfigAndInfo->ate.status == 0){
- }else{
- }
-
-
- }else if(ShmSysConfigAndInfo->ate.ATEState == 3){
- }
- }
- printf("End. \n");
- return FAIL;
- }
|