123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579 |
- #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 "internalComm.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 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
- #define SYSFS_GPIO_DIR "/sys/class/gpio"
- byte gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
- Ver ver;
- PresentInputVoltage inputVoltage;
- PresentOutputVoltage outputVoltage;
- Relay outputRelay;
- Relay regRelay;
- int Uart5Fd;
- int Uart1Fd;
- Gpio_in gpio_in;
- 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 = 500000;
- int targetCurrent_Value = 60;
- int targetVoltage_Value = 400;
- int maximumCurrent_value = 200;
- int maximumVoltage_value = 500;
- int linkVoltage = 500;
- int contactorVoltage = 0;
- int _port;
- #define YES 1
- #define NO 0
- byte flash = NO;
- struct Address Addr={0x01,0x02,0x03,0x04,0xFF};
- struct Command Cmd={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x81,0x85,0x86,0xe0,0xe1,0xe2,0xe3};
- 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,
- };
- 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 tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
- {
- int len;
-
- tcflush(fd,TCIOFLUSH);
- if(write(fd, cmd, cmd_len) >= cmd_len)
- {
- usleep(5000);
- len = read(fd, rx, 512);
- }
- else
- {
- #ifdef SystemLogMessage
-
- #endif
- }
- return len;
- }
- unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- memcpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
- *(Ret_Buf->Version_FW + 8) = 0x00;
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- memcpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
- *(Ret_Buf->Version_HW + 8) = 0x00;
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetAddr, PresentInputVoltage *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Present_InputVoltage, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->inputType = rx[6];
- Ret_Buf->L1N_L12 =(rx[7] | (rx[8]<<8))/10.0;
- Ret_Buf->L2N_L23 =(rx[9] | (rx[10]<<8))/10.0;
- Ret_Buf->L3N_L31 =(rx[11] | (rx[12]<<8))/10.0;
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char targetAddr, PresentOutputVoltage *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Present_OutputVoltage, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->behindFuse_Voltage_C1 =(rx[6] | (rx[7]<<8));
- Ret_Buf->behindRelay_Voltage_C1 =(rx[8] | (rx[9]<<8));
- if((rx[4] | rx[5]<<8) > 4)
- {
- Ret_Buf->behindFuse_Voltage_C2 =(rx[10] | (rx[11]<<8));
- Ret_Buf->behindRelay_Voltage_C2 =(rx[12] | (rx[13]<<8));
- }
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Fan_Speed, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- for(int idx=0;idx < 4;idx++)
- Ret_Buf->speed[idx] = (rx[6+(2*idx)] | (rx[6+(2*idx)+1]<<8));
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temperature *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Temperature, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- for(int idx=0;idx < 4;idx++)
- Ret_Buf->temperature[idx] = rx[6+idx] - 60;
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr, AuxPower *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Aux_PowerVoltage, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- Ret_Buf->voltage[idx] = rx[6+idx];
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Relay_Output, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->relay_event.bits.AC_Contactor = (rx[6] >> 0) & 0x01;
- Ret_Buf->relay_event.bits.CCS_Precharge = (rx[6] >> 1) & 0x01;
- Ret_Buf->relay_event.bits.Gun1_N = (rx[7] >> 0) & 0x01;
- Ret_Buf->relay_event.bits.Gun1_P = (rx[7] >> 1) & 0x01;
- Ret_Buf->relay_event.bits.Gun1_Parallel_N = (rx[7] >> 2) & 0x01;
- Ret_Buf->relay_event.bits.Gun1_Parallel_P = (rx[7] >> 3) & 0x01;
- Ret_Buf->relay_event.bits.Gun2_N = (rx[8] >> 0) & 0x01;
- Ret_Buf->relay_event.bits.Gun2_P = (rx[8] >> 1) & 0x01;
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gfd_Adc, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- printf("chksum = %d \n", chksum);
- printf("rx[2] == %d tx[1] = %d \n", rx[2], tx[1]);
- printf("rx[1] == %d tx[2] = %d \n", rx[1], tx[2]);
- printf("rx[3] == %d tx[3] = %d \n", rx[3], tx[3]);
- printf("chksum = %d \n", chksum);
- if(
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->Resister = (rx[6] | (rx[7]<<8) | (rx[8]<<16) | (rx[9]<<24));
- Ret_Buf->voltage = rx[10] | (rx[11]<<8);
- Ret_Buf->result = rx[12];
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->AC_Connector = (rx[6] >> 0) & 0x01;
- Ret_Buf->AC_MainBreaker = (rx[6] >> 1) & 0x01;
- Ret_Buf->SPD = (rx[6] >> 2) & 0x01;
- Ret_Buf->Door_Open = (rx[6] >> 3) & 0x01;
- Ret_Buf->GFD[0] = (rx[6] >> 4) & 0x01;
- Ret_Buf->GFD[1] = (rx[6] >> 5) & 0x01;
- Ret_Buf->AC_Drop = (rx[6] >> 6) & 0x01;
- Ret_Buf->Emergency_IO = (rx[7] >> 0) & 0x01;
- Ret_Buf->Button_Emergency_Press = (rx[8] >> 0) & 0x01;
- Ret_Buf->Button_On_Press = (rx[8] >> 1) & 0x01;
- Ret_Buf->Button_Off_Press = (rx[8] >> 2) & 0x01;
- Ret_Buf->Key_1_Press = (rx[8] >> 3) & 0x01;
- Ret_Buf->Key_2_Press = (rx[8] >> 4) & 0x01;
- Ret_Buf->Key_3_Press = (rx[8] >> 5) & 0x01;
- Ret_Buf->Key_4_Press = (rx[8] >> 6) & 0x01;
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Fan_Speed, 0x02, 0x00, Set_Buf->speed[0], Set_Buf->speed[1]};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[9] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[10] = {0xaa, 0x00, targetAddr, Cmd.config_Relay_Output, 0x03, 0x00, Set_Buf->relay_event.relay_status[0], Set_Buf->relay_event.relay_status[1], Set_Buf->relay_event.relay_status[2]};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6 + idx];
- tx[9] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- rx[6] == PASS)
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Gfd_Value(unsigned char fd, unsigned char targetAddr, Gfd_config *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.config_Gfd_Value, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[6] = (unsigned char)(Set_Buf->reqVol) & 0xff;
- tx[7] = ((unsigned char)(Set_Buf->reqVol) >> 8) & 0xff;
- tx[8] = (unsigned char)(Set_Buf->resister) & 0xff;
- tx[9] = ((unsigned char)(Set_Buf->resister) >> 8) & 0xff;
- for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[10] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == tx[6]))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
- {
- unsigned char result = FAIL;
- unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&0xff, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[10] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x00))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x00))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
- {
- unsigned char result = FAIL;
- unsigned char tx[11 + length];
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = Cmd.update_Transfer;
- tx[4] = (4 + length) & 0xff;
- tx[5] = ((4 + length)>>8) & 0xff;
- tx[6] = (startAddr>>0) & 0xff;
- tx[7] = (startAddr>>8) & 0xff;
- tx[8] = (startAddr>>16) & 0xff;
- tx[9] = (startAddr>>24) & 0xff;
- memcpy(tx+10, data, length);
- for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[sizeof(tx)-1] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x00))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if (len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x00))
- {
- result = PASS;
- }
- }
- return result;
- }
- const int System_GPIO_Pin_Table[SYS_GPIO_NUM] =
- {
- PIN_AM_OK_FLAG, PIN_IO_BD1_1, PIN_IO_BD1_2, PIN_IO_BD2_1, PIN_IO_BD2_2, PIN_ID_BD1_1, PIN_ID_BD1_2, PIN_ID_BD2_1,
- PIN_ID_BD2_2, PIN_AM_RFID_RST, PIN_AM_RFID_ICC, PIN_BOARD1_PROXIMITY, PIN_BOARD2_PROXIMITY, PIN_AM_DE_1, PIN_AM_RE_1, PIN_ETHERNET_RESET
- };
- void gpio_export(int pin)
- {
- char buffer[64];
- snprintf(buffer, sizeof(buffer), "echo %d > /sys/class/gpio/export", pin);
- system(buffer);
- }
- void gpio_unexport(int pin)
- {
- char buffer[64];
- snprintf(buffer, sizeof(buffer), "echo %d > /sys/class/gpio/unexport", pin);
- system(buffer);
- }
- void gpio_set_direction(int pin, unsigned char dir)
- {
-
- int fd;
- char buffer[64];
- snprintf(buffer, sizeof(buffer), "/sys/class/gpio/gpio%d/direction", pin);
- fd = open(buffer, O_WRONLY);
- if (fd < 0)
- {
- gpio_export(pin);
- fd = open(buffer, O_WRONLY);
- if(fd < 0)
- {
- printf("\r\nFailed to open gpio%d direction for writing!", pin);
- return;
- }
- }
- write(fd, dir == GPIO_DIR_INPUT ? "in" : "out", dir == GPIO_DIR_INPUT ? 2 : 3);
- close(fd);
- }
- void gpio_write(int pin, unsigned char value)
- {
- char buffer[64];
- snprintf(buffer, sizeof(buffer), "echo %d > /sys/class/gpio/gpio%d/value", value > 0 ? 1 : 0, pin);
- system(buffer);
- }
- int gpio_read(int pin)
- {
- int fd, value = 0;
- char ch;
- char buffer[64];
- snprintf(buffer, sizeof(buffer), "/sys/class/gpio/gpio%d/value", pin);
- fd = open(buffer, O_RDONLY);
- if (fd < 0)
- {
- return -1;
- }
- if (read(fd, &ch, 4) < 0)
- {
- return -1;
- }
- value = atoi(&ch);
- close(fd);
- return value;
- }
- int adc_read(int adc_port)
- {
- int fd, value = 0;
- char ch[5];
- char buffer[64];
- snprintf(buffer,sizeof(buffer), "/sys/bus/iio/devices/iio:device0/in_voltage%d_raw", adc_port);
- fd = open(buffer, O_RDONLY);
- if(fd < 0)
- {
- return -1;
- }
- if(read(fd, ch, 4) < 0)
- {
- return -1;
- }
- value = atoi(ch);
- close(fd);
- return value;
- }
- void InitIO(void)
- {
-
- gpio_set_direction(PIN_ID_BD1_1, GPIO_DIR_INPUT);
-
- gpio_set_direction(PIN_ID_BD1_2, GPIO_DIR_INPUT);
-
- gpio_set_direction(PIN_IO_BD1_1, GPIO_DIR_OUTPUT);
- gpio_write(PIN_IO_BD1_1, 0);
-
- gpio_set_direction(PIN_IO_BD1_2, GPIO_DIR_OUTPUT);
- gpio_write(PIN_IO_BD1_2, 0);
-
- gpio_set_direction(PIN_AM_RFID_RST, GPIO_DIR_OUTPUT);
- gpio_write(PIN_AM_RFID_RST, 0);
-
- gpio_set_direction(PIN_AM_RFID_ICC, GPIO_DIR_OUTPUT);
- gpio_write(PIN_AM_RFID_ICC, 0);
-
- gpio_set_direction(PIN_ID_BD2_1, GPIO_DIR_INPUT);
-
- gpio_set_direction(PIN_ID_BD2_2, GPIO_DIR_INPUT);
-
- gpio_set_direction(PIN_IO_BD2_1, GPIO_DIR_OUTPUT);
- gpio_write(PIN_IO_BD2_1, 0);
-
- gpio_set_direction(PIN_IO_BD2_2, GPIO_DIR_OUTPUT);
- gpio_write(PIN_IO_BD2_2, 0);
-
- gpio_set_direction(PIN_AM_OK_FLAG, GPIO_DIR_OUTPUT);
- gpio_write(PIN_AM_OK_FLAG, 0);
- gpio_set_direction(PIN_BOARD1_PROXIMITY, GPIO_DIR_INPUT);
- gpio_set_direction(PIN_BOARD2_PROXIMITY, GPIO_DIR_INPUT);
- }
- void DeInitIO(void)
- {
- gpio_unexport(PIN_ID_BD1_1);
- gpio_unexport(PIN_ID_BD1_2);
- gpio_unexport(PIN_IO_BD1_1);
- gpio_unexport(PIN_IO_BD1_2);
- gpio_unexport(PIN_AM_RFID_RST);
- gpio_unexport(PIN_AM_RFID_ICC);
- gpio_unexport(PIN_ID_BD2_1);
- gpio_unexport(PIN_ID_BD2_2);
- gpio_unexport(PIN_IO_BD2_1);
- gpio_unexport(PIN_IO_BD2_2);
- gpio_unexport(PIN_AM_OK_FLAG);
- }
- void DoIOTest(void)
- {
- InitIO();
- gpio_write(PIN_IO_BD1_1, 1);
- if(gpio_read(PIN_ID_BD1_1) == 1)
- {
- gpio_write(PIN_IO_BD1_1, 0);
- if(gpio_read(PIN_ID_BD1_1) == 0)
- {
- printf("\r\nID_BD1_1 Test OK");
- }
- else
- {
- printf("\r\nID_BD1_1 Low Test Fail");
- return;
- }
- }
- else
- {
- printf("\r\nID_BD1_1 High Test Fail");
- return;
- }
- gpio_write(PIN_IO_BD1_2, 1);
- if(gpio_read(PIN_ID_BD1_2) == 1)
- {
- gpio_write(PIN_IO_BD1_2, 0);
- if(gpio_read(PIN_ID_BD1_2) == 0)
- {
- printf("\r\nID_BD1_2 Test OK");
- }
- else
- {
- printf("\r\nID_BD1_2 Low Test Fail");
- return;
- }
- }
- else
- {
- printf("\r\nID_BD1_2 High Test Fail");
- return;
- }
- gpio_write(PIN_IO_BD2_1, 1);
- if(gpio_read(PIN_ID_BD2_1) == 1)
- {
- gpio_write(PIN_IO_BD2_1, 0);
- if(gpio_read(PIN_ID_BD2_1) == 0)
- {
- printf("\r\nID_BD2_1 Test OK");
- }
- else
- {
- printf("\r\nID_BD2_1 Low Test Fail");
- return;
- }
- }
- else
- {
- printf("\r\nID_BD2_1 High Test Fail");
- return;
- }
- gpio_write(PIN_IO_BD2_2, 1);
- if(gpio_read(PIN_ID_BD2_2) == 1)
- {
- gpio_write(PIN_IO_BD2_2, 0);
- if(gpio_read(PIN_ID_BD2_2) == 0)
- {
- printf("\r\nID_BD2_2 Test OK");
- }
- else
- {
- printf("\r\nID_BD2_2 Low Test Fail");
- return;
- }
- }
- else
- {
- printf("\r\nID_BD2_2 High Test Fail");
- return;
- }
- gpio_write(PIN_AM_RFID_RST, 1);
- if(gpio_read(PIN_BOARD1_PROXIMITY) == 1 && gpio_read(PIN_BOARD2_PROXIMITY) == 1)
- {
- gpio_write(PIN_AM_RFID_RST, 0);
- if(gpio_read(PIN_BOARD1_PROXIMITY) == 0 && gpio_read(PIN_BOARD2_PROXIMITY) == 0)
- {
- printf("\r\nBoard1 & Board2 Proximity Test OK");
- }
- else
- {
- printf("\r\nBoard1 & Board2 Proximity Low Test Fail");
- return;
- }
- }
- else
- {
- printf("\r\nBoard1 & Board2 Proximity High Test Fail");
- return;
- }
- gpio_write(PIN_AM_RFID_ICC, 1);
- usleep(100000);
- if(adc_read(ADC_AIN0) < 100 && adc_read(ADC_AIN1) < 100 && adc_read(ADC_AIN2) < 100 && adc_read(ADC_AIN3) < 100)
- {
- gpio_write(PIN_AM_RFID_ICC, 0);
- usleep(100000);
- if(adc_read(ADC_AIN0) > 4000 && adc_read(ADC_AIN1) > 4000 && adc_read(ADC_AIN2) > 4000 && adc_read(ADC_AIN3) > 4000)
- {
- printf("\r\nAIN0, AIN1, AIN2, AIN3 Test OK");
- }
- else
- {
- printf("\r\nAIN0, AIN1, AIN2, AIN3 High Test Fail");
- return;
- }
- }
- else
- {
- printf("\r\nAIN0, AIN1, AIN2, AIN3 Low Test Fail");
- return;
- }
- gpio_write(PIN_AM_OK_FLAG, 1);
- printf("\r\nIO Test Done!");
- printf("\r\nSuccess!\r\n");
- }
- 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;
- }
- 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);
- }
- 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]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
- {
- result = YES;
- chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
- }
- return result;
- }
- 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]->ATEState = 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;
- }
- void GetPresentInputVol()
- {
- if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS)
- {
-
- ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
- ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
- ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
-
-
- if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = 0x01;
- }
- if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = 0x01;
- }
- if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = 0x01;
- }
-
-
- if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = 0x01;
- }
- if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = 0x01;
- }
- if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = 0x01;
- }
-
-
- if (inputVoltage.L1N_L12 < VIN_DROP_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = 0x01;
- }
- if (inputVoltage.L2N_L23 < VIN_DROP_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputDrop = 0x01;
- }
- if (inputVoltage.L3N_L31 < VIN_DROP_VOLTAGE)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputDrop = 0x01;
- }
- }
- }
- void GetPersentOutputVol()
- {
- if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS)
- {
- printf("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
- printf("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
- printf("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
- printf("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
- ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
- ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
- ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
- ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
- printf("FuseChargingVoltage 1 = %d \n", ShmRelayModuleData->Gun1FuseOutputVolt);
- printf("FuseChargingVoltage 2 = %d \n", ShmRelayModuleData->Gun1RelayOutputVolt);
- printf("FuseChargingVoltage 1 = %d \n", ShmRelayModuleData->Gun2FuseOutputVolt);
- printf("FuseChargingVoltage 2 = %d \n", ShmRelayModuleData->Gun2RelayOutputVolt);
-
-
-
- }
- }
- bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
- {
- for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
- return true;
- }
- }
- for (byte index = 0; index < CCS_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
- return true;
- }
- }
- for (byte index = 0; index < GB_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
- return true;
- }
- }
- return false;
- }
- void CheckRelayOutput(byte index)
- {
- if (index == 0)
- {
-
- if (chargingInfo[index]->Evboard_id == 0x01)
- {
- if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES)
- chargingInfo[0]->RelayK1K2Status = YES;
- else
- chargingInfo[0]->RelayK1K2Status = NO;
- if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
- chargingInfo[0]->RelayKPK2Status = YES;
- else
- chargingInfo[0]->RelayKPK2Status = NO;
- }
- else if (chargingInfo[index]->Evboard_id == 0x02)
- {
- if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
- chargingInfo[0]->RelayK1K2Status = YES;
- else
- chargingInfo[0]->RelayK1K2Status = NO;
- if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
- chargingInfo[0]->RelayKPK2Status = YES;
- else
- chargingInfo[0]->RelayKPK2Status = NO;
- }
- }
- else if (index == 1)
- {
- if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
- chargingInfo[1]->RelayK1K2Status = YES;
- else
- chargingInfo[1]->RelayK1K2Status = NO;
- if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
- chargingInfo[1]->RelayKPK2Status = YES;
- else
- chargingInfo[1]->RelayKPK2Status = NO;
- }
- }
- void SetOutputGpio(byte flash)
- {
- Gpio_out gpio;
- gpio.Button_LED[0] = 0x00;
- gpio.Button_LED[1] = 0x00;
- gpio.System_LED[0] = flash;
- gpio.System_LED[1] = 0x00;
- gpio.System_LED[2] = 0x00;
- gpio.System_LED[3] = flash;
- gpio.AC_Connector = 0x00;
- gpio.AC_Breaker = 0x00;
- if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS)
- {
-
- }
- else
- {
-
- }
- }
- void SetEvContactorRelayStatus(byte index)
- {
-
-
-
-
-
- if(ShmSysConfigAndInfo->ate.ATEState == 1){
- if(chargingInfo[index]->SystemStatus >= V_ISOLATION){
- if(chargingInfo[index]->Evboard_id == 0x01)
- {
-
- if (outputRelay.relay_event.bits.Gun1_N == 0x00)
- outputRelay.relay_event.bits.Gun1_N = 0x01;
- else
- outputRelay.relay_event.bits.Gun1_P = 0x01;
- if (outputRelay.relay_event.bits.Gun2_N == 0x00)
- outputRelay.relay_event.bits.Gun2_N = 0x01;
- else
- outputRelay.relay_event.bits.Gun2_P = 0x01;
- flash = YES;
- SetOutputGpio(flash);
- }
- }else{
- if (chargingInfo[index]->Evboard_id == 0x01)
- {
-
- if (outputRelay.relay_event.bits.Gun1_P == 0x01)
- outputRelay.relay_event.bits.Gun1_P = 0x00;
- else
- outputRelay.relay_event.bits.Gun1_N = 0x00;
- if (outputRelay.relay_event.bits.Gun2_P == 0x01)
- outputRelay.relay_event.bits.Gun2_P = 0x00;
- else
- outputRelay.relay_event.bits.Gun2_N = 0x00;
- flash = NO;
- SetOutputGpio(flash);
- }
- }
- }else if(ShmSysConfigAndInfo->ate.ATEState == 2){
- if(ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status == 1){
- if(chargingInfo[index]->Evboard_id == 0x01){
- if (outputRelay.relay_event.bits.Gun1_Parallel_N == 0x00)
- outputRelay.relay_event.bits.Gun1_Parallel_N = 0x01;
- else
- outputRelay.relay_event.bits.Gun1_Parallel_P = 0x01;
- flash = YES;
- SetOutputGpio(flash);
- }
- }else{
- if (chargingInfo[index]->Evboard_id == 0x01){
- if (outputRelay.relay_event.bits.Gun1_Parallel_P == 0x01)
- outputRelay.relay_event.bits.Gun1_Parallel_P = 0x00;
- else
- outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
- flash = NO;
- SetOutputGpio(flash);
- }
- }
- }
- }
- 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));
- 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 data[1];
- data[0] = 0x02;
- 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 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;
-
-
- 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;
- EvseStopChargingEvent(normalStop, stopReason, 1);
- SetChargingPermission(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.TotalBatteryCap,
- ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, 1);
- }
- int SpawnTask()
- {
- system("/root/Module_VCCU &");
- return PASS;
- }
- void KillTask()
- {
- system("killall Module_VCCU");
- }
- 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;
- }
- void CANReceiver()
- {
- pid_t canRecPid;
- canRecPid = fork();
- if(canRecPid > 0){
- int nbytes;
- struct can_frame frame;
- int intCmd;
- while (1){
-
- memset(&frame, 0, sizeof(struct can_frame));
-
- nbytes = read(CanFd, &frame, sizeof(struct can_frame));
-
- if (nbytes > 0){
- intCmd = (int) (frame.can_id & CAN_EFF_MASK);
- #ifdef Debug
-
-
- #endif
-
-
- switch (intCmd){
- case VCCU_ChargeFromVehicleId:{
-
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.VCCU_Vehicle_ContactorVoltage = ((short) frame.data[1] << 8) + (short) frame.data[0];
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.VCCU_Vehicle_LinkVoltage = ((short) frame.data[3] << 8) + (short) frame.data[2];
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_IsolationMeasurem = bitextract(frame.data[4],0, 2);
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio = bitextract(frame.data[4],2, 4);
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugUnlockPermiss = bitextract(frame.data[4],4, 6);
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_ChargePermission = bitextract(frame.data[4],6, 8);
- ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.bits.VCCU_Vehicle_ContactorStatus = bitextract(frame.data[5],0, 2);
-
-
- break;
- }
- case VCCU_ControlPilotStatusId:{
-
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_Frequency.bits.VCCU_ControlPilot_Frequency = ((short) frame.data[1] << 8) + (short) frame.data[0];
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_DutyCycle.bits.value = ((short) frame.data[2] ) ;
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_Voltage.bits.value = ((short) frame.data[3] << 8) + (short) frame.data[4];
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ControlPilot_Wakeup = bitextract(((short) (frame.data[5])), 0, 2);
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode = bitextract(frame.data[5],2, 5);
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State = bitextract(((short) (frame.data[5])), 5, 8);
- ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ChargeUnit_MaxCurrent = ((short) frame.data[6] );
-
-
- break;
- }
- case VCCU_V2G_StateMId:{
-
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_EnergyTransfer = (short) frame.data[0];
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineEr = (short) frame.data[1];
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineMe = (short) frame.data[2];
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt = (short) frame.data[3];
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.DATA.bits.VCCU_V2G_StateM_InternetAvaila = bitextract(frame.data[4],0, 1);
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.DATA.bits.VCCU_V2G_Appl_SccChargeModeReq = bitextract(frame.data[4],1, 4);
- ShmSysConfigAndInfo->ate.vccu.v2g_StateM.DATA.bits.VCCU_V2G_Appl_SccFuncModeReq = bitextract(frame.data[4],4, 6);
-
-
- break;
- }
- case VCCU_InletStatusId:{
-
- ShmSysConfigAndInfo->ate.vccu.inletStatus.VCCU_POSFeedback_Voltage = ((short) frame.data[1] << 8) + (short) frame.data[0];
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_SelfDiagnosti = bitextract(frame.data[2],0, 3);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Resistance = bitextract(frame.data[2],3, 6);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status = bitextract(frame.data[2],6, 8);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA3.VCCU_PlugPresent_Wakeup = bitextract(frame.data[3],0, 2);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA3.VCCU_POSFeedback_SelfDiagnosti = bitextract(frame.data[3],2, 5);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA3.VCCU_PlugLock_MotorStatus = bitextract(frame.data[3],5, 8);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA4.VCCU_PlugLock_Output0_SelfDiag = bitextract(frame.data[4],0, 3);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA4.VCCU_PlugLock_Output1_SelfDiag = bitextract(frame.data[4],3, 6);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA4.VCCU_Inlet_HWVariant = bitextract(frame.data[4],6, 8);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_DigitalInput_Status = bitextract(frame.data[5],0, 2);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_DigitalInput_Wakeup = bitextract(frame.data[5],2, 4);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus = bitextract(frame.data[5],4, 7);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.VCCU_Inlet_MaxCurrent = (short) frame.data[6];
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_DigitalInput_DebouncedSta = bitextract(frame.data[7],0, 2);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus = bitextract(frame.data[7],2, 4);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_S3Switch_Status = bitextract(frame.data[7],4, 6);
- ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_S3Switch_DebouncedStatus = bitextract(frame.data[7],6, 8);
-
-
- break;
- }
- case VCCU_ChargeToVehicleId:{
-
-
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 = bitextract(frame.data[0],0, 2);
- ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest = bitextract(frame.data[0],2, 4);
-
-
- break;
- }
- case VCCU_V2G_EVMaximumVoltageLimitId:{
-
-
- break;
- }
- case VCCU_V2G_EVMaximumCurrentLimitId:{
-
-
- break;
- }
- case VCCU_V2G_EVTargetCurrentId:{
-
-
- break;
- }
- case VCCU_V2G_EVTargetVoltageId:{
-
-
- break;
- }case EV_BOARD_STATUS_NOTIFICATION:
- {
- ShmSysConfigAndInfo->ate.chademo.id03.ProximitySignal = frame.data[2];
- ShmSysConfigAndInfo->ate.chademo.id03.state = frame.data[3];
- break;
- }
- case ACK_EV_FW_VERSION:
- {
- break;
- }
- case ACK_EV_HW_VERSION:
- {
- printf("Get EV HW = %s \n", frame.data);
- break;
- }
- case ACK__GET_EVSE_OUTPUT_STATUS:
- {
-
- ShmSysConfigAndInfo->ate.chademo.id09_ack.DcEvState = frame.data[0];
- ShmSysConfigAndInfo->ate.chademo.id09_ack.ChargingMode = frame.data[1];
- ShmSysConfigAndInfo->ate.chademo.id09_ack.EvsePresentOutputVoltage = ((short) frame.data[3] << 8) + (short) frame.data[2];
- ShmSysConfigAndInfo->ate.chademo.id09_ack.EvsePresentOutputCurrent = ((short) frame.data[5] << 8) + (short) frame.data[4];
- ShmSysConfigAndInfo->ate.chademo.id09_ack.RemainingTimeSec = ((short) frame.data[7] << 8) + (short) frame.data[6];
- break;
- }
- case ACK_GET_EVSE_Capacity_INFO:
- {
-
- ShmSysConfigAndInfo->ate.chademo.id0A_ack.EvseMaxChargeVoltage = ((short) frame.data[1] << 8) + (short) frame.data[0];
- ShmSysConfigAndInfo->ate.chademo.id0A_ack.EvseMaxChargeCurrent = ((short) frame.data[3] << 8) + (short) frame.data[2];
- ShmSysConfigAndInfo->ate.chademo.id0A_ack.EvseMinChargeVoltage = ((short) frame.data[5] << 8) + (short) frame.data[4];
- ShmSysConfigAndInfo->ate.chademo.id0A_ack.EvseMinChargeCurrent = ((short) frame.data[7] << 8) + (short) frame.data[6];
- break;
- }
- case ACK_GET_MISCELLANEOUS_INFO:
- {
- ShmSysConfigAndInfo->ate.chademo.id0D_ack.K1K2OnOff = frame.data[5];
- if(ShmSysConfigAndInfo->ate.chademo.relaystatus == 0){
- ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status = ShmSysConfigAndInfo->ate.chademo.id0D_ack.K1K2OnOff;
- }
- break;
- }
- case ACK_EVSE_ISOLATION_STATUS: { break;}
- case ACK_EVSE_PRECHAGE_INFO:
- {
-
- break;
- }
- case NOTIFICATION_EV_STOP:
- {
- ShmSysConfigAndInfo->ate.chademo.id0B.EvStopReason = frame.data[0];
- ShmSysConfigAndInfo->ate.chademo.id0B.AlarmCode1 = frame.data[1];
- ShmSysConfigAndInfo->ate.chademo.id0B.AlarmCode2 = frame.data[2];
- ShmSysConfigAndInfo->ate.chademo.id0B.AlarmCode3 = frame.data[3];
- ShmSysConfigAndInfo->ate.chademo.id0B.AlarmCode4 = frame.data[4];
- ShmSysConfigAndInfo->ate.chademo.id0B.AlarmCode5 = frame.data[5];
- ShmSysConfigAndInfo->ate.chademo.id0B.AlarmCode6 = frame.data[6];
- 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);
- break;
- }
- default:
- break;
- }
- }
- usleep(2000);
-
- }
- }
- }
- int Init407ComPort()
- {
- int fd;
- struct termios tios;
- fd = open(priPortName, O_RDWR);
- if(fd<=0)
- {
- #ifdef SystemLogMessage
-
- #endif
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN]=0;
- tios.c_cc[VTIME]=(unsigned char)1;
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- void CHROMACANReceiver()
- {
- pid_t canRecPid;
- canRecPid = fork();
- if(canRecPid > 0){
- int nbytes;
- struct can_frame frame;
- int intCmd;
- while (1){
-
- memset(&frame, 0, sizeof(struct can_frame));
-
- nbytes = read(CanFd2, &frame, sizeof(struct can_frame));
-
- if (nbytes > 0){
- intCmd = (int) (frame.can_id & CAN_EFF_MASK);
- #ifdef Debug
-
-
- #endif
-
-
- switch (intCmd){
- case bn_res1:{
- ShmSysConfigAndInfo->ate.ATEState = (short) frame.data[0];
- setATEMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.ATEState);
-
- break;
- }
- case bn_res2:{
-
- break;
- }
- case ATE_Connector2:{
-
-
-
- break;
- }
- case ATE_Connector1:{
- if(ShmSysConfigAndInfo->ate.ATEState == 1){
- ShmSysConfigAndInfo->ate.chroma.ate_Connector_1.TargetVoltage = ((short) frame.data[1] << 8) + (short) frame.data[0];
- ShmSysConfigAndInfo->ate.chroma.ate_Connector_1.TargetCurrent = ((short) frame.data[3] << 8) + (short) frame.data[2];
- ShmSysConfigAndInfo->ate.chroma.ate_Connector_1.PresentVoltage = ((short) frame.data[5] << 8) + (short) frame.data[4];
- ShmSysConfigAndInfo->ate.chroma.ate_Connector_1.PresentCurrent = ((short) frame.data[7] << 8) + (short) frame.data[6];
-
- ShmSysConfigAndInfo->ate.targetVoltage_Value = ((short) frame.data[1] << 8) + (short) frame.data[0];
- ShmSysConfigAndInfo->ate.targetCurrent_Value = ((short) frame.data[3] << 8) + (short) frame.data[2];
-
- ShmSysConfigAndInfo->ate.maximumVoltage_value = ShmSysConfigAndInfo->ate.targetVoltage_Value+10;
- ShmSysConfigAndInfo->ate.linkVoltage = ShmSysConfigAndInfo->ate.targetVoltage_Value;
- }else if (ShmSysConfigAndInfo->ate.ATEState == 2){
- }
-
-
- break;
- }
- default:
- break;
- }
- }
- usleep(2000);
-
- }
- }
- }
- 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 = 0;
- obj.bits.VCCU_Vehicle_ChargeSelection = 0;
- 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, int PlugLock,
- int ControlPilot, int ChargeUnit, int Inlet){
- struct VCCU_Requests obj;
- obj.VCCU_LED0_Request.value = LED0;
- obj.VCCU_LED1_Request.value = LED1;
- obj.VCCU_LED2_Request.value = LED2;
- obj.DATA4.VCCU_HighSideOut0_Request = HighSideOut0;
- obj.DATA4.VCCU_HighSideOut1_Request = HighSideOut1;
- obj.DATA4.VCCU_HighSideOut2_Request = HighSideOut2;
- obj.DATA4.VCCU_HighSideOut3_Request = HighSideOut3;
- obj.DATA5.VCCU_HighSideOut4_Request = HighSideOut4;
- obj.DATA5.VCCU_RTC_TimerRequest = RTC;
- obj.DATA5.VCCU_PlugLock_MotorRequest = PlugLock;
- obj.DATA7.VCCU_ControlPilot_ChargeModeRe = ControlPilot;
- obj.DATA7.VCCU_ChargeUnit_Request = ChargeUnit;
- obj.DATA7.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.DATA4);
- data[4] = *((UBYTE *) &obj.DATA5);
- data[5] = *((UBYTE *) &obj.VCCU_RTC_TimerValue);
- data[6] = *((UBYTE *) &obj.DATA7);
- printf("%02x %02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] , data[6]);
-
- }
- 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 &&
- ((chargingInfo[CCS_QUANTITY]->PlugPresentStatusDuration >= 2) && chargingInfo[CCS_QUANTITY]->DutyCycleDuration >= 2));
- 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() && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Close){
- result = true;
-
- setChargerMode(CCS_QUANTITY, V_CONTACTORSCLOSED);
- }
- return result;
- }
- bool S_PowerDelivery(){
- bool result = false;
- if(PreCharge_Statue() && ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PowerDelivery
- && 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(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;
- 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;
- }
- int gpio_get_value(unsigned int gpio, unsigned int *value)
- {
- int fd;
- char buf[MAX_BUF];
- char ch;
- snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
- fd = open(buf, O_RDONLY);
- if (fd < 0) {
- perror("gpio/get-value");
- return fd;
- }
- read(fd, &ch, 1);
- if (ch != '0') {
- *value = 1;
- } else {
- *value = 0;
- }
- close(fd);
- return 0;
- }
- void SelfTestRun()
- {
- }
- 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;
- }
- int InitComPort()
- {
- int fd;
- struct termios tios;
- fd = open(relayRs485PortName, O_RDWR);
- if(fd <= 0)
- {
- #ifdef SystemLogMessage
-
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- return -1;
- }
- ioctl(fd, TCGETS, &tios);
- tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN] = 0;
- tios.c_cc[VTIME]=(byte)0;
-
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl(fd, TCSETS, &tios);
- return fd;
- }
- unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- for (int idx = 0; idx < 2; idx++)
- tx[6] |= (Set_Buf->Button_LED[idx] ? 0x01:0x00) << (0+idx);
- for (int idx = 0; idx < 4; idx++)
- tx[6] |= (Set_Buf->System_LED[idx] ? 0x01:0x00) << (2+idx);
- tx[6] |= (Set_Buf->AC_Connector ? 0x01:0x00) << 6;
- tx[6] |= (Set_Buf->AC_Breaker ? 0x01:0x00) << 7;
- for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
- chksum ^= tx[6+idx];
- tx[7] = chksum;
- if (tranceive(fd, tx, sizeof(tx), rx) > 0)
- {
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == tx[6]))
- {
- result = PASS;
- }
- }
- return result;
- }
- int 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;
- return PASS;
- }
- bool IsNoneMatchRelayStatus()
- {
- bool result = false;
- if ((regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
- (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
- (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
- (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
- (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
- (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N))
- {
- result = true;
- }
- return result;
- }
- void MatchRelayStatus()
- {
-
-
- ShmSysConfigAndInfo->SysInfo.AcContactorStatus = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
- regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
- regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
- regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
- regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
- regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
- }
- bool CheckConnectorTypeStatus()
- {
- bool result = true;
- return result;
- }
- void CloseInternalCommPort()
- {
- close(Uart5Fd);
- }
- void InitRS485DirectionIO(void)
- {
-
- gpio_set_direction(PIN_AM_DE_1, GPIO_DIR_OUTPUT);
- gpio_write(PIN_AM_DE_1, 1);
-
-
-
-
- gpio_set_direction(PIN_AM_RE_1, GPIO_DIR_OUTPUT);
- gpio_write(PIN_AM_RE_1, 0);
-
-
-
- }
- void InitGPIO()
- {
- }
- int main(void){
-
-
-
- if(CreatShareMemory()==0){
- #ifdef SystemLogMessage
-
- #endif
- if(ShmStatusCodeData!=NULL)
- {
-
- }
- return 0;
- sleep(5);
- system("reboot -f");
- }
-
-
-
- CanFd = InitCanBus();
- CanFd2 = CHROMAInitCanBus();
- CANReceiver();
- CHROMACANReceiver();
- printf ("vccu 1===== CanFd2:%d. \n", CanFd2);
-
-
-
- Uart1Fd = Init407ComPort();
-
-
-
-
- Initialization();
- InitRS485DirectionIO();
-
- 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;
-
-
- Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay);
-
- sleep(1);
- if(Uart5Fd < 0){
- printf ("open port error. \n");
- return 0;
- }
-
-
-
- ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status=0x00;
- ShmSysConfigAndInfo->ate.chademo.id0D_req.Soc = 50;
- ShmSysConfigAndInfo->ate.ateMode = 0;
- ShmSysConfigAndInfo->ate.ATEState = 1;
-
-
-
- byte evstaus[5] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
-
-
-
-
- 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 = 3800;
-
- 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);
- while(CanFd){
-
- if(ShmSysConfigAndInfo->ate.ATEState == 1){
-
-
- }else if(ShmSysConfigAndInfo->ate.ATEState == 2){
-
-
- }else{
-
- }
- int state = isATEChange(CCS_QUANTITY);
- if(state){
- }
- if(ShmSysConfigAndInfo->ate.ATEState == 1){
- setBootNotification1();
-
-
-
-
-
- statusCheck();
-
- CheckRelayOutput(CCS_QUANTITY);
-
- SetEvContactorRelayStatus(CCS_QUANTITY);
- int status = isModeChange(CCS_QUANTITY);
-
-
- if(IsNoneMatchRelayStatus())
- {
- if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
- {
- printf("Match Relay............................ \n");
- MatchRelayStatus();
- printf("reg relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x \n",
- regRelay.relay_event.bits.AC_Contactor,
- regRelay.relay_event.bits.Gun1_P,
- regRelay.relay_event.bits.Gun1_N,
- regRelay.relay_event.bits.Gun2_P,
- regRelay.relay_event.bits.Gun2_N,
- regRelay.relay_event.bits.CCS_Precharge);
- }
- }
- 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);
- 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);
- 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);
- 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, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0);
- VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value);
- 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);
- break;
- }
- case V_ISOLATION:{
- if (status){
- printf("CCS ISOLATION Processing 9....................\n");
- }
- setEVStatus1(evstaus[1]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Allowed, Not_Active, Allowed, Not_allowed, Opened);
- break;
- }
- case V_VOLTAGEDIFFERENCE:{
- if (status){
- printf("CCS VOLTAGEDIFFERENCE Processing 10....................\n");
- }
- setEVStatus1(evstaus[1]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Opened);
- VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0);
- break;
- }
- case V_CONTACTORSCLOSED:{
- if (status){
- printf("CCS CONTACTORSCLOSED Processing 11....................\n");
- }
- setEVStatus1(evstaus[1]);
- VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed);
- break;
- }
- case V_POWERDELIVERY:{
- if (status){
- printf("CCS POWERDELIVERY Processing 12....................\n");
- }
- 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);
- }
-
- setEVStatus1(evstaus[1]);
- break;
- }
- case V_CURRENTDEMAND:{
- if (status){
- printf("CCS CURRENTDEMAND Processing 13....................\n");
- }
- setEVStatus1(evstaus[2]);
- 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);
-
- 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, Closed);
- }
- 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(whileLoopTime);
- }else if(ShmSysConfigAndInfo->ate.ATEState == 2){
- if(ShmSysConfigAndInfo->ate.status == 0){
- int status = isStatusChange(CCS_QUANTITY);
-
-
-
- CheckRelayOutput(CCS_QUANTITY);
-
- SetEvContactorRelayStatus(CCS_QUANTITY);
-
-
- if(IsNoneMatchRelayStatus())
- {
- if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
- {
-
- MatchRelayStatus();
- printf("reg relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pn = %x, pp = %x \n",
- regRelay.relay_event.bits.AC_Contactor,
- regRelay.relay_event.bits.Gun1_P,
- regRelay.relay_event.bits.Gun1_N,
- regRelay.relay_event.bits.Gun2_P,
- regRelay.relay_event.bits.Gun2_N,
- regRelay.relay_event.bits.Gun1_Parallel_N,
- regRelay.relay_event.bits.Gun1_Parallel_P);
-
-
- }
- }
- usleep(1000);
- setMisc(1);
- if(ShmSysConfigAndInfo->ate.ATEStatus == 1){
- ShmSysConfigAndInfo->ate.Permission = START;
- setStatusMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission);
-
- }else if(ShmSysConfigAndInfo->ate.ATEStatus == 2){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- setStatusMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission);
-
- ShmSysConfigAndInfo->ate.ATEStatus = 0;
- }else if(ShmSysConfigAndInfo->ate.ATEStatus == 3){
- 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);
- }else{
- }
- if(ShmSysConfigAndInfo->ate.chademo.id03.state == 0 || ShmSysConfigAndInfo->ate.Permission == 0){
-
-
- ShmSysConfigAndInfo->ate.Permission = START;
- setStatusMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission);
- SetChargingPermission(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, 1);
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state ==1){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state ==2){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state ==3){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state ==4){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state == 5){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- setEVStatus2(evstaus[1]);
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state == 6){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- setEVStatus2(evstaus[1]);
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state == 7){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- setEVStatus2(evstaus[2]);
-
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state == 8){
- ShmSysConfigAndInfo->ate.Permission = STOP;
- setEVStatus2(evstaus[2]);
-
- }
- else if(ShmSysConfigAndInfo->ate.chademo.id03.state >= 13 ){
- handleEmulatorFaultStatus();
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state == 14 ){
- handleEmulatorFaultStatus();
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.state == 9 || ShmSysConfigAndInfo->ate.chademo.id03.state == 10
- || ShmSysConfigAndInfo->ate.chademo.id03.state == 11 || ShmSysConfigAndInfo->ate.chademo.id03.state == 12
-
-
- ){
- ShmSysConfigAndInfo->ate.Permission = STOP;
-
- setEVStatus2(evstaus[3]);
- }else{
- setEVStatus2(evstaus[0]);
-
- }
- if(ShmSysConfigAndInfo->ate.chademo.id03.ProximitySignal == 0){
-
- setEVStatus2(evstaus[3]);
- }else if(ShmSysConfigAndInfo->ate.chademo.id03.ProximitySignal == 1 && ShmSysConfigAndInfo->ate.chademo.id03.state != 7 &&
- ShmSysConfigAndInfo->ate.chademo.id03.state != 9 && ShmSysConfigAndInfo->ate.chademo.id03.state != 10
- && ShmSysConfigAndInfo->ate.chademo.id03.state != 11 && ShmSysConfigAndInfo->ate.chademo.id03.state != 12
- && ShmSysConfigAndInfo->ate.chademo.id03.state != 13
- && ShmSysConfigAndInfo->ate.chademo.id03.state != 15){
-
- setEVStatus2(evstaus[1]);
- }
- if(status){
-
- SetChargingPermission(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, 1);
- }else{
- if(ShmSysConfigAndInfo->ate.Permission == STOP ){
- if(ShmSysConfigAndInfo->ate.chademo.id03.state == 0){
-
-
- SetChargingPermission(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, 1);
- }
- }
- }
-
-
- usleep(1000);
-
- SetPresentInputPower(ShmSysConfigAndInfo->ate.chademoTargetVoltage_Value, ShmSysConfigAndInfo->ate.chademoTargetCurrent_Value, 1);
- usleep(1000);
-
- SetPresentInputRequirement(ShmSysConfigAndInfo->ate.RequireVoltage, ShmSysConfigAndInfo->ate.RequireCurrent, ShmSysConfigAndInfo->ate.PresentBattVoltage, ShmSysConfigAndInfo->ate.MinimumChargeCurrent, 1);
- }
- }
- }
- printf("End. \n");
- return FAIL;
- }
|