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 PASS 1
- #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 SYSFS_GPIO_DIR "/sys/class/gpio"
- #define SendDirection 0x08000000
- #define FAIL -1
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct CHAdeMOData *ShmCHAdeMOData;
- struct CcsData *ShmCcsData;
- struct RelayModuleData *ShmRelayModuleData;
- //struct ATE *ate;
- 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];
- //VCCU_ChargeFromVehicle_DATA chargeFromVehicle;
- pid_t CANReceiverPid;
- int CanFd;
- int CanFd2;
- #define VIN_MAX_VOLTAGE 250 // 大於該值 : OVP
- #define VIN_MIN_VOLTAGE 170 // 小於該值 : UVP
- #define VIN_DROP_VOLTAGE 150 // 小於該值 : ac drop
- //#define SYSFS_GPIO_DIR "/sys/class/gpio"
- byte gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
- // for initial index to check EV board type is correct
- //char *relayRs485PortName = "/dev/ttyS5";
- //char* pPortName = "/dev/ttyS3";
- //char *priPortName = "/dev/ttyS1";
- #define btoa(x) ((x)?"true":"false")
- long hexToDec(char *source);
- int getIndexOfSigns(char ch);
- int whileLoopTime = 200000;//500ms//10000; // 10 ms
- int targetCurrent_Value = 120;//2;
- int targetVoltage_Value = 500;
- int maximumCurrent_value = 200;//10;
- 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;
- //=================================
- // Create all share memory
- //=================================
- 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;
- //creat ShmSysConfigAndInfo
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- //StoreLogMsg("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
- #endif
- return 0;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- //StoreLogMsg("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
- #endif
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
- //creat ShmCcsData
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0){
- #ifdef SystemLogMessage
- //StoreLogMsg("[main]CreatShareMemory:shmget ShmCcsData NG \n");
- #endif
- return 0;
- }
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1){
- #ifdef SystemLogMessage
- //StoreLogMsg("[main]CreatShareMemory:shmat ShmCcsData NG \n");
- #endif
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
- //creat ShmRelayModuleData
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- //StoreLogMsg("shmget ShmRelayModuleData NG\n");
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- //StoreLogMsg("shmat ShmRelayModuleData NG\n");
- #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;
- /*
- //can0
- system("/sbin/ip link set can0 down");//先將interface disable
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- */
- //can1
- system("/sbin/ip link set can0 down");//先將interface disable
- 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
- //StoreLogMsg("[CsuComm]InitCanBus:Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes = 40960;
- if(setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- //StoreLogMsg("[CsuComm]InitCanBus:Set SO_RCVBUF NG");
- #endif
- }
- nbytes = 40960;
- if(setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- //StoreLogMsg("[CsuComm]InitCanBus:Set SO_SNDBUF NG");
- #endif
- }
- //strcpy(ifr0.ifr_name, "can0" );
- strcpy(ifr0.ifr_name, "can0" );
- ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
- 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
- //DEBUG_ERROR("Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- //DEBUG_ERROR("Set SO_RCVBUF NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- //DEBUG_ERROR("Set SO_SNDBUF NG");
- #endif
- }
- strcpy(ifr0.ifr_name, "can1" );
- ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
- 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)
- {
- //return milli-second
- unsigned int StartTime,StopTime;
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
- //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
- 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;
- }
- //==========================================
- // Common Function
- //==========================================
- 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);//(0x00001000 + cmd) | 0x80000000;//(cmd | 0x80000000);
- frame.can_dlc = dataLen;
- memcpy(frame.data, data, sizeof(frame.data));
- write(canfd, &frame, sizeof(struct can_frame));
- //usleep(2000);
- }
- 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;
- //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] );
- 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;
- //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] );
- /*
- data[1] = 0x0001;
- data[2] = 0x0001;
- data[3] = 0x10;
- data[4] = 0x10;
- */
- SendCmdToEvboard(CanFd, id, data, sizeof(data));
- }
- /*
- void setMisc(byte toId){
- float K1K2Status = 0;
- float soc = 0;
- K1K2Status = ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status;
- soc = ShmSysConfigAndInfo->ate.chademo.id0D_req.Soc;
- GetMiscellaneousInfo(0, toId, K1K2Status, soc);
- }
- */
- 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;
- /*
- data[4] = outputVol_b2 & 0xff;
- data[5] = (outputVol_b2 >> 8) & 0xff;
- data[6] = outputCur_b2 & 0xff;
- data[7] = (outputCur_b2 >> 8) & 0xff;
- */
- //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] );
- 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;
- /*
- data[6] = aOutputCur_b2 & 0xff;
- data[7] = (aOutputCur_b2 >> 8) & 0xff;
- */
- //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] );
- 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);
- //printf("intCmd = %x \n", cmd & CAN_EFF_MASK);
- //cmd = cmd & CAN_EFF_MASK;
- 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);
- // printf("target_number[0] = %x \n", target_number[0]);
- // printf("target_number[1] = %x \n", target_number[1]);
- // printf("target_number[2] = %x \n", target_number[2]);
- // printf("target_number[3] = %x \n", target_number[3]);
- // printf("target_number[4] = %x \n", target_number[4]);
- 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;//500
- obj.VCCU_Vehicle_ContactorVoltage = contactorVoltage;//0
- obj.DATA.bits.VCCU_Vehicle_ChargePermission = chargePermission;//Not_allowed
- obj.DATA.bits.VCCU_Vehicle_IsolationMeasurem = isolationMeasurem;//Active
- obj.DATA.bits.VCCU_Vehicle_PlugLockPermissio = plugLockPermissio;//Allowed//Not_allowed;
- obj.DATA.bits.VCCU_Vehicle_PlugUnlockPermiss = plugUnlockPermiss;//Not_allowed
- obj.bits.VCCU_Vehicle_ContactorStatus = contactorStatus;//Open
- obj.bits.VCCU_Vehicle_StopCharge = 3;//Open
- obj.bits.VCCU_Vehicle_ChargeSelection = 3;//Open
- 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);
- //printf("%02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] );
- SendCmdToEvboard(canfd, VCCU_ChargeFromVehicleIds, data, sizeof(data));
- }
- //0x18FF3082
- 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;//VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended;
- obj.DATA1.VCCU_V2G_EVErrorCode = EVErrorCode;//0;
- obj.DATA4.VCCU_V2G_EVPowerDeliveryParame = EVPowerDeliveryParame;//3;
- obj.VCCU_V2G_EVRESSSOC.value = EVRESSSOC;//0;
- obj.DATA3.VCCU_V2G_EVRESSConditioningFla = EVRESSConditioningFla;//3;
- obj.DATA3.VCCU_V2G_EVRESSConditioning = EVRESSConditionin;//3;
- obj.DATA3.VCCU_V2G_EVReady = EVReady;//3;
- obj.DATA1.VCCU_V2G_BulkChargingCompleteF = BulkChargingCompleteF;//3;
- obj.DATA3.VCCU_V2G_EVCabinConditioningFl = EVCabinConditioningFl;//3;
- obj.DATA2.VCCU_V2G_EVCabinConditioning = EVCabinConditioning;//3;
- obj.DATA2.VCCU_V2G_ChargingComplete = ChargingComplete;//3;
- obj.DATA2.VCCU_V2G_FullSOCFlag = FullSOCFlag;//0;
- obj.VCCU_V2G_FullSOC.value = FullSOC;//3;
- obj.DATA2.VCCU_V2G_BulkSOCFlag = BulkSOCFlag;//3;
- obj.VCCU_V2G_BulkSOC.value = BulkSOC;//0;
- obj.DATA1.VCCU_V2G_BulkChargingComplete = BulkChargingComplete;//3;
- obj.DATA1.VCCU_V2G_BulkChargingCompleteF = BulkChargingCompleteFValue;//3;
- 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);
- //printf("%02x %02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] , data[6]);
- 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;//1
- obj.DATA1.VCCU_V2G_EVMaximumVoltage_0002 = EVMaximumVoltage_0002;//5
- obj.VCCU_V2G_EVMaximumVoltage_0000.value = EVMaximumVoltage_0000;//520
- obj.VCCU_V2G_EVMaximumVoltage_0001.value = EVMaximumVoltage_0001;//1
- obj.VCCU_V2G_EVMaximumVoltage_0003.value = EVMaximumVoltage_0003;//0
- 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);
- //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]);
- 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;//1
- obj.DATA1.VCCU_V2G_EVMaximumCurrent_0000 = EVMaximumCurrent_0000;//3
- obj.VCCU_V2G_EVMaximumCurrent_0001.value = EVMaximumCurrent_0001;//1
- obj.VCCU_V2G_EVMaximumCurrent_0002.value = EVMaximumCurrent_0002;//0
- obj.VCCU_V2G_EVMaximumCurrent_0003.value = EVMaximumCurrent_0003;//10
- 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);
- //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]);
- SendCmdToEvboard(CanFd, VCCU_V2G_EVMaximumCurrentLimitIds, data, sizeof(data));
- }
- void VCCU_V2G_EVTargetCurrent(int EVTargetCurrent_Unit,
- int EVTargetCurrent_Value,
- int EVTargetCurrent_UnitF,
- int EVTargetCurrent_Multi){//05 00 00 01 03
- struct VCCU_V2G_EVTargetCurrent obj;
- obj.VCCU_V2G_EVTargetCurrent_Unit.value = EVTargetCurrent_Unit;//3
- obj.VCCU_V2G_EVTargetCurrent_Value.value = EVTargetCurrent_Value;//5
- obj.VCCU_V2G_EVTargetCurrent_UnitF.value = EVTargetCurrent_UnitF;//1
- obj.VCCU_V2G_EVTargetCurrent_Multi.value = EVTargetCurrent_Multi;//0
- 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);
- //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]);
- SendCmdToEvboard(CanFd, VCCU_V2G_EVTargetCurrentIds, data, sizeof(data));
- }
- void VCCU_V2G_EVTargetVoltage(int EVTargetVoltage_Value,
- int EVTargetVoltage_Unit,
- int EVTargetVoltage_UnitF,
- int EVTargetVoltage_Multi){//C2 01 00 01 05
- struct VCCU_V2G_EVTargetVoltage obj;
- obj.VCCU_V2G_EVTargetVoltage_Value.value = EVTargetVoltage_Value;//450
- obj.VCCU_V2G_EVTargetVoltage_Unit.value = EVTargetVoltage_Unit;//5
- obj.VCCU_V2G_EVTargetVoltage_UnitF.value = EVTargetVoltage_UnitF;//1
- obj.VCCU_V2G_EVTargetVoltage_Multi.value = EVTargetVoltage_Multi;//0
- 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);
- //printf("%d %02x %02x \n",obj.VCCU_V2G_EVTargetVoltage_Value.value, data[0], data[1]);
- //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]);
- 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;//0.0
- obj.VCCU_LED1_Request = LED1;//0.0
- obj.VCCU_LED2_Request = LED2;//0.0
- obj.byte3.VCCU_HighSideOut0_Request = HighSideOut0;//3
- obj.byte3.VCCU_HighSideOut1_Request = HighSideOut1;//3
- obj.byte3.VCCU_HighSideOut2_Request = HighSideOut2;//3
- obj.byte3.VCCU_HighSideOut3_Request = HighSideOut3;//3
- obj.byte4.VCCU_HighSideOut4_Request = HighSideOut4;//3
- obj.byte4.VCCU_RTC_TimerRequest = RTC_TimerRequest;//3
- obj.byte4.VCCU_PlugLock_MotorRequest = PlugLock;//7
- obj.VCCU_RTC_TimerValue= RTC_TimerValue;//0
- obj.byte6.VCCU_ControlPilot_ChargeModeRe = ControlPilot;//7
- obj.byte6.VCCU_ChargeUnit_Request = ChargeUnit;//3
- obj.byte6.VCCU_Inlet_MotorRequest = Inlet;//3
- 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);
- //printf("%02x %02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] , data[6]);
- 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.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == ChargeV2G
- //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_Voltage - 32000 == 9
- );
- }
- 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.controlPilotStatus.ControlPilot_Voltage.bits.value / 2) == 6 &&
- 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;
- /*
- 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,
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State,
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode,
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.Data.bits.VCCU_Vehicle_ContactorRequest,
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.Data.bits.VCCU_Vehicle_IsolationMea_0000);
- */
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_Initialized &&
- //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Not_connected &&
- //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Not_connected &&
- //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked &&
- (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.controlPilotStatus.VCCU_ControlPilot_Voltage == 0 &&
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == ForceOpen &&
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Requested ){
- //TODO
- result = true;
- //printf("CCS DC01....................\n");
- //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Not_allowed, Not_allowed, Opened);
- setChargerMode(CCS_QUANTITY, V_UNMATEDPLUG);
- }
- return result;
- }
- bool MatedPlugInletUnlocked(){
- bool result = false;
- if(MatedPlugInletUnlocked_Status() && chargingInfo[CCS_QUANTITY]->SystemStatus == V_IDLE){//(DC02) Mated Plug - Inlet Unlocked
- //TODO
- result = true;
- //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- setChargerMode(CCS_QUANTITY, V_MATED_PLUG_INLET_UNLOCKED);
- }
- return result;
- }
- bool InletLocking(){
- bool result = false;
- if(//ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2
- status1() &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving
- ){//(DC03) Inlet Locking
- result = true;
- //printf("CCS DC03....................\n");
- /*
- if(ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&//PlugPresent_Status == Connected for >=2s
- //ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle && //ControlPilot_DutyCycle == valid for >= 2s
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked){
- }*/
- 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){//DC04) Inlet Locked
- result = true;
- /*
- if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving){
- }*/
- 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;
- /*
- if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked &&
- (ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle >= 5 || ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle <= 7) &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_DigitalInput_Status == Not_pressed &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_S3Switch_Status == Not_pressed&&
- ShmSysConfigAndInfo->ate.vccu.ptc1.VCCU_PTC1_Temperature < 90){
- }*/
- 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;
- /*
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 520, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10);
- */
- 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;
- //VCCU_ChargeFromVehicle(CanFd, 500, 0, Allowed, Active, Allowed, Not_allowed, Opened);
- setChargerMode(CCS_QUANTITY, V_CABLECHECK);
- }
- return result;
- }
- bool Isolation(){
- bool result = false;
- if(MatedPlugInletUnlocked_Status() && PreCharge_Statue()){
- result = true;
- //VCCU_ChargeFromVehicle(CanFd, 500, 0, Allowed, Not_Active, Allowed, Not_allowed, Opened);
- setChargerMode(CCS_QUANTITY, V_ISOLATION);
- }
- return result;
- }
- bool S_PreCharge(){
- bool result = false;
- if(PreCharge_Statue()){
- //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Opened);
- //VCCU_V2G_EVTargetCurrent(U_A, 5, TRUE, 0);
- setChargerMode(CCS_QUANTITY, V_VOLTAGEDIFFERENCE);
- }
- return result;
- }
- bool Contactors(){
- bool result = false;
- if( PreCharge_Statue()
- //&& ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Close
- ){
- result = true;
- //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- setChargerMode(CCS_QUANTITY, V_CONTACTORSCLOSED);
- /*
- if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000)
- {
- ftime(&startChargingTime[CCS_QUANTITY]);
- chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
- StopGunInfoTimeoutDet(CCS_QUANTITY);
- StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
- }
- */
- }
- return result;
- }
- bool S_PowerDelivery(){
- bool result = false;
- /*
- * ((ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge ) &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC &&
- //(ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_Voltage.bits.value / 2) == 6 &&
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested)
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_ChargePermission
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.bits.VCCU_Vehicle_ContactorStatus
- * */
- 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.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge &&
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested
- && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Close
- ){
- result = true;
- //printf("status CCS PowerDelivery %d %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest);
- //VCCU_V2G_EVTargetVoltage(450, U_V, TRUE, 0);
- setChargerMode(CCS_QUANTITY, V_POWERDELIVERY);
- }
- return result;
- }
- bool S_CurrentDemand(){
- bool result = false;
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CurrentDemand){//(DC12) Current Demand
- result = true;
- //TODO stop
- 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
- //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State != EVSEStateC
- ){//(DC13) PowerDelivery
- result = true;
- setChargerMode(CCS_QUANTITY, V_POWERDELIVERYFALSE);
- //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);
- }
- return result;
- }
- bool S_WeldingDetection(){
- bool result = false;
- if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == WeldingDetection){//(DC14) Welding Detection
- 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){//Session Stop
- 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 ){//Stop Communication Session
- 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 ){//Finished
- result = true;
- setChargerMode(CCS_QUANTITY, V_FINISHED);
- }
- return result;
- }
- bool statusCheck(){
- bool result = false;
- //VCCU_TD();
- 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 ){
- //TODO
- 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.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 &&
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == ChargePwm
- //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_Voltage - 32000 == 9
- ) && chargingInfo[CCS_QUANTITY]->SystemStatus == V_IDLE){//(DC02) Mated Plug - Inlet Unlocked
- //TODO
- result = true;
- //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- setChargerMode(CCS_QUANTITY, V_MATED_PLUG_INLET_UNLOCKED);
- }
- return result;
- }
- bool acInletLocking(){
- bool result = false;
- if(//ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2
- (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
- ){//(DC03) Inlet Locking
- result = true;
- //printf("CCS DC03....................\n");
- /*
- if(ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed &&
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&//PlugPresent_Status == Connected for >=2s
- //ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle && //ControlPilot_DutyCycle == valid for >= 2s
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked){
- }*/
- 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));
- //printf("%s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
- 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;
- // 現階段預設為走 DIN70121
- ShmCcsData->CommProtocol = 0x01;
- //return PASS;
- }
- bool CheckConnectorTypeStatus()
- {
- bool result = true;
- return result;
- }
- void SpawnTask()
- {
- sleep(2);
- system("/root/Module_InternalComm &");
- system("/root/Module_EvComm &");
- //return PASS;
- }
- void KillTask()
- {
- system("killall Module_InternalComm");
- system("killall Module_EvComm");
- }
- int main(void){
- //Create all share memory
- //printf("=====Initializing. \n");
- //ate = malloc( sizeof(ate) );
- if(CreatShareMemory()==0){
- #ifdef SystemLogMessage
- //DEBUG_ERROR("CreatShareMemory NG \n");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
- }
- return 0;
- sleep(5);
- system("reboot -f");
- }
- /*
- int a=2;
- int *b;
- b = &a;
- printf("%p\n", &a);
- printf("%d\n", *b);
- printf("%p\n", b);
- printf("%p\n", &b);
- *//*
- int a = 2;
- int b = 3;
- a = a^b;
- b = a^b;
- a = a^b;
- printf("%d %d", a, b);
- const char *SystemId="0101";
- printf("%c %p =====\n", *SystemId, &SystemId);
- strcpy((char *)&ShmSysConfigAndInfo->SysConfig.SystemId,SystemId);
- char *SystemIdStr = (char *)&ShmSysConfigAndInfo->SysConfig.SystemId;
- printf("%s =====\n", SystemIdStr);*/
- //SpawnTask();
- //KillTask();
- KillTask();
- ///CanFd = InitCanBus();
- //CanFd2 = CHROMAInitCanBus();
- Initialization();
- SpawnTask();
- //CANReceiver();
- //CHROMACANReceiver();
- //printf ("vccu 1===== CanFd2:%d. \n", CanFd2);
- //setChargerMode(CCS_QUANTITY, V_IDLE);
- /*
- struct timeb tp;
- unsigned int StartTime,StopTime;
- //ftime(&tp);
- ftime(&startChargingTime[CCS_QUANTITY]);
- //
- StartTime = (int)startChargingTime[CCS_QUANTITY].time;
- printf("%u\n", StartTime);
- sleep(2);
- ftime(&tp);
- ftime(&endChargingTime[CCS_QUANTITY]);
- StopTime = (int)endChargingTime[CCS_QUANTITY].time;
- printf("%u\n", StopTime);
- */
- /*
- gpio_set_direction(1, GPIO_DIR_INPUT);
- gpio_set_direction(2, GPIO_DIR_INPUT);
- gpio_set_direction(3, GPIO_DIR_INPUT);
- gpio_write(1, 0);
- gpio_write(3, 0);
- gpio_write(3, 1);
- gpio_write(3, 1);
- */
- /*
- int pinIn[2] = { 1, 3 };
- system("echo 1 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio1/direction");
- system("echo 1 > /sys/class/gpio/gpio1/value");
- system("echo 3 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio3/direction");
- system("echo 1 > /sys/class/gpio/gpio3/value");
- gpio_set_direction(1, GPIO_DIR_OUTPUT);
- gpio_set_direction(4, GPIO_DIR_OUTPUT);
- gpio_write(1, 0);
- gpio_write(4, 0);
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
- {
- }*/
- //Uart1Fd = Init407ComPort();
- //printf("407 Port id = %d \n", Uart1Fd);
- //int led = gpio_read(3);
- //printf("led === %d \n", led);
- //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);
- /*
- InitRS485DirectionIO();
- // Open Uart5 for RB
- Uart5Fd = InitComPort();
- for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++)
- {
- outputRelay.relay_event.relay_status[index] = 0x00;
- }
- memset(®Relay, 0xFF,sizeof(Relay));
- outputRelay.relay_event.bits.AC_Contactor = 0x00;
- outputRelay.relay_event.bits.CCS_Precharge = 0x00;
- outputRelay.relay_event.bits.Gun1_P = 0x00;
- outputRelay.relay_event.bits.Gun1_N = 0x00;
- outputRelay.relay_event.bits.Gun2_P = 0x00;
- outputRelay.relay_event.bits.Gun2_N = 0x00;
- //outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
- //outputRelay.relay_event.bits.Gun1_Parallel_P = 0x01;
- sleep(1);
- if(Uart5Fd < 0){
- printf ("open port error. \n");
- return 0;
- }*/
- //usleep(300000);
- ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status=0x00;
- ShmSysConfigAndInfo->ate.chademo.id0D_req.Soc = 50;
- ShmSysConfigAndInfo->ate.ateMode = 0;
- ShmSysConfigAndInfo->ate.ATEState = 2;//1:ccs 2:gb
- /*
- outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
- outputRelay.relay_event.bits.Gun1_Parallel_P = 0x00;
- flash = YES;
- SetOutputGpio(!flash);
- return 0;
- */
- /**/
- //byte priorityLow = 1;
- /**/
- //byte normalStop = 0x01;
- //byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- //byte evstaus[5] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
- //PresentInputRequirement
- /*
- typedef enum
- {
- ESIdle = 0x01;
- ESPreparing = 0x02;
- ESCharging = 0x03;
- ESChargingTerminating = 0x04;
- ESFault = 0x05;
- }EmulatorStatus;
- */
- //setStatusMode(CCS_QUANTITY, STOP);
- //CCS
- 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;//contactorVoltage;
- //GB
- //ShmSysConfigAndInfo->ate.PresentBattVoltage = 4700;
- ShmSysConfigAndInfo->ate.PresentBattVoltage = 4700;
- ShmSysConfigAndInfo->ate.MinimumChargeCurrent = 20;
- //ShmSysConfigAndInfo->ate.RequireVoltage = 4800;
- ShmSysConfigAndInfo->ate.RequireVoltage = 4800;
- //ShmSysConfigAndInfo->ate.RequireVoltage = 4700;
- ShmSysConfigAndInfo->ate.RequireCurrent = 600;
- ShmSysConfigAndInfo->ate.chademoTargetVoltage_Value = 4800;
- ShmSysConfigAndInfo->ate.chademoTargetCurrent_Value = 30;
- //ShmSysConfigAndInfo->ate.targetCurrent_Value = 1200;
- ShmSysConfigAndInfo->ate.Permission = STOP;
- ShmSysConfigAndInfo->ate.TotalBatteryCap = 1000; //0.1
- ShmSysConfigAndInfo->ate.MaxBatteryCurrent = 1200; //0.1
- ShmSysConfigAndInfo->ate.MaxBatteryVoltage = 5000; //0.1
- 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){
- //ShmSysConfigAndInfo->ate.ATEState
- if(ShmSysConfigAndInfo->ate.ATEState == 1){//VCCU
- //TODO
- //ShmSysConfigAndInfo->ate.ateMode = 0;
- }else if(ShmSysConfigAndInfo->ate.ATEState == 2){//GB
- //TODO
- //ShmSysConfigAndInfo->ate.ateMode = 0;
- }else{//none
- // init
- }
- int state = isATEChange(CCS_QUANTITY);
- if(state){
- //TODO
- }
- if(ShmSysConfigAndInfo->ate.ATEState == 1){//VCCU
- /*
- ftime(&endChargingTime[CCS_QUANTITY]);
- chargingInfo[CCS_QUANTITY]->RemainChargingDuration = DiffTimeb(startChargingTime[CCS_QUANTITY], endChargingTime[CCS_QUANTITY]);
- //GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer);
- printf("%d %d ....................\n",chargingInfo[CCS_QUANTITY]->RemainChargingDuration, chargingInfo[CCS_QUANTITY]->TimeoutFlag);
- if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000)
- {
- ftime(&startChargingTime[CCS_QUANTITY]);
- chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
- StopGunInfoTimeoutDet(CCS_QUANTITY);
- StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
- }
- */
- //setBootNotification1();
- // 輸出電壓
- //測試value
- //GetPersentOutputVol();
- // 三相輸入電壓
- //GetPresentInputVol();
- statusCheck();
- int status = isModeChange(CCS_QUANTITY);
- /*
- * VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- /*
- VCCU_Requests(0, 0, 0,
- 3, 3, 3, 3,
- 3, 3, 7,
- 0,
- 7, 3, 3);*/
- switch(chargingInfo[CCS_QUANTITY]->SystemStatus){
- case V_IDLE:{
- if (status){
- printf("CCS IDLE Processing 1....................\n");
- }
- //setEVStatus1(evstaus[0]);
- break;
- }
- case V_UNMATEDPLUG:{
- if (status){
- printf("CCS UNMATEDPLUG Processing 2....................\n");
- }
- //setEVStatus1(evstaus[0]);
- //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Not_allowed, Not_allowed, Opened);
- 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");
- }
- //setEVStatus1(evstaus[0]);
- //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- break;
- }
- case V_INLETLOCKING:{
- if (status){
- printf("CCS INLETLOCKING Processing 4....................\n");
- }
- //setEVStatus1(evstaus[0]);
- break;
- }
- case V_INLETLOCKED:{
- if (status){
- printf("CCS INLETLOCKED Processing 5....................\n");
- }
- /*
- setEVStatus1(evstaus[1]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- */
- /*
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- */
- break;
- }
- case V_SLAC:{
- if (status){
- printf("CCS SLAC Processing 6....................\n");
- }
- //setEVStatus1(evstaus[1]);
- //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- /*
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- */
- /*
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- break;
- }
- case V_DEFINITION:{
- if (status){
- printf("CCS DEFINITION Processing 7....................\n");
- }
- //setEVStatus1(evstaus[1]);
- /*
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0,
- 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3);
- */
- /*
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 500, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- */
- /*
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- break;
- }
- case V_CABLECHECK:{
- if (status){
- printf("CCS CABLECHECK Processing 8 ....................\n");
- }
- /*
- setEVStatus1(evstaus[1]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Allowed, Active, Allowed, Not_allowed, Opened);
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- 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]);
- }
- /*
- setEVStatus1(evstaus[1]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Allowed, Not_Active, Allowed, Not_allowed, Opened);
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- 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]);
- //GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer);
- //printf("%d %ld ....................\n",chargingInfo[CCS_QUANTITY]->RemainChargingDuration, val);
- if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000)
- {
- ftime(&startChargingTime[CCS_QUANTITY]);
- chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0;
- StopGunInfoTimeoutDet(CCS_QUANTITY);
- StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing);
- }
- /*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,
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State,
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000,
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest);
- */
- /*
- setEVStatus1(evstaus[1]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- //VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- 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 );
- }
- /*
- setEVStatus1(evstaus[1]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- 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 );
- }
- //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- /*
- if(ShmSysConfigAndInfo->ate.ATEStatus == 0){
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- }else{
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Opened);
- }
- //VCCU_V2G_EVTargetVoltage(400, U_V, TRUE, 0);
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- setEVStatus1(evstaus[1]);
- */
- 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);
- }
- //setEVStatus1(evstaus[2]);
- //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);
- /*
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 500, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10);
- VCCU_V2G_EVTargetVoltage(400, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, 2, TRUE, 0);
- VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- */
- /*
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- /*
- if(ShmSysConfigAndInfo->ate.ATEStatus == 0){
- //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- }else{
- //VCCU_ChargeFromVehicle(CanFd, 500, 500, Not_allowed, Not_Active, Allowed, Not_allowed, Closed);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Closed);
- }
- VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0,
- 3, 0,
- 3, 3, TRUE,
- 3, 3, 3,
- 3, 3, 0,
- 3, 0, 3,
- 3);
- VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- */
- break;
- }
- case V_POWERDELIVERYFALSE:{
- if (status){
- printf("CCS POWERDELIVERYFALSE Processing 14....................\n");
- }
- /*
- setEVStatus1(evstaus[3]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Opened);
- */
- break;
- }
- case V_DETECTION:{
- if (status){
- printf("CCS DETECTION Processing 15....................\n");
- }
- /*
- setEVStatus1(evstaus[3]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- */
- break;
- }
- case V_SESSION_STOP:{
- if (status){
- printf("CCS SESSION_STOP Processing 16....................\n");
- }
- /*
- setEVStatus1(evstaus[3]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- */
- break;
- }
- case V_STOP_COMMUNICATION_SESSION:{
- if (status){
- printf("CCS STOP_COMMUNICATION_SESSION Processing 17....................\n");
- }
- /*
- setEVStatus1(evstaus[3]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- */
- break;
- }
- case V_FINISHED:{
- if (status){
- printf("CCS FINISHED Processing 18....................\n");
- }
- /*
- setEVStatus1(evstaus[3]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened);
- */
- break;
- }
- default:{
- break;
- }
- }
- //usleep(100000);
- usleep(whileLoopTime);
- }else if(ShmSysConfigAndInfo->ate.ATEState == 2){//GB
- if(ShmSysConfigAndInfo->ate.status == 0){
- }else{
- }
- /*
- printf("ProximitySignal = %d, state = %d Permission = %d TotalBatteryCap = %d MaxBatteryCurrent = %d MaxBatteryVoltage = %d ATEStatus = %d....................\n", ShmSysConfigAndInfo->ate.chademo.id03.state ,ShmSysConfigAndInfo->ate.Permission,
- ShmSysConfigAndInfo->ate.chademo.id03.ProximitySignal, ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent,
- ShmSysConfigAndInfo->ate.MaxBatteryVoltage, ShmSysConfigAndInfo->ate.ATEStatus);
- printf("state = %d Permission = %d TotalBatteryCap = %d MaxBatteryCurrent = %d MaxBatteryVoltage = %d ATEStatus = %d K1K2Status = %d PresentBattVoltage = %d RequireVoltage = %d....................\n",
- ShmSysConfigAndInfo->ate.chademo.id03.state ,
- ShmSysConfigAndInfo->ate.Permission,
- ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent,
- ShmSysConfigAndInfo->ate.MaxBatteryVoltage, ShmSysConfigAndInfo->ate.ATEStatus,
- ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status, ShmSysConfigAndInfo->ate.PresentBattVoltage, ShmSysConfigAndInfo->ate.RequireVoltage);
- usleep(whileLoopTime);
- */
- //usleep(whileLoopTime);
- }else if(ShmSysConfigAndInfo->ate.ATEState == 3){//chademo
- }
- }
- printf("End. \n");
- return FAIL;
- }
|