123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690 |
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <stdlib.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/sockios.h>
- #include <linux/socket.h>
- #include <linux/can.h>
- #include <linux/can/raw.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <math.h>//for pow
- #include <net/if.h>
- #include <unistd.h>
- #include "define.h"
- #include "CsuComm.h"
- #include "SeccComm.h"
- #include "exi_engine/api/api.h"
- #ifdef AWCCS
- #include "../main.h"
- #endif
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct CcsData *ShmCcsData;
- struct InternalComm *ShmInternalComm;
- #ifdef AWCCS
- struct Charger *ShmCharger;
- #endif
- pid_t PID_CAN_Rx_Task;
- pid_t PID_CsuComm_Error_Monitor_Task;
- int FD_CAN_Socket;
- unsigned char buf_log_csucomm[SIZE_OF_LOG_BUFFER];
- unsigned char buf_log_csucomm_fork1[SIZE_OF_LOG_BUFFER];
- unsigned char buf_log_csucomm_fork2[SIZE_OF_LOG_BUFFER];
- void PrintTimeStamp()
- {
-
-
- static struct timeval tv;
-
-
- gettimeofday(&tv, NULL);
-
-
- DEBUG_PRINTF_CSUCOMM_DETAIL("[%05d.%06d]", tv.tv_sec, tv.tv_usec);
- }
- unsigned char Check_V2G_Flow_Status()
- {
- unsigned char result = 0;
- switch (ShmCcsData->CommProtocol)
- {
- case V2GT_MSG_PROTOCOL_DIN70121:
- {
- result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
- break;
- }
- case V2GT_MSG_PROTOCOL_ISO15118_2014:
- {
- result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
- break;
- }
- case V2GT_MSG_PROTOCOL_ISO15118_2018:
- {
- result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
- break;
- }
- default:
- break;
- }
- return result;
- }
- #if SAVE_SYS_LOG_MSG_CSUCOMM_SWITCH == ENABLE
- int StoreLogMsg2(unsigned char *DataString)
- {
- static unsigned char Buf[256*2];
- static time_t CurrentTime;
- static struct tm *tm;
- static struct timeval tv;
- memset(Buf, 0, sizeof(Buf));
- CurrentTime = time(NULL);
- tm = localtime(&CurrentTime);
- gettimeofday(&tv, NULL);
- #ifdef AWCCS
- sprintf(Buf, "echo \"[%04d%02d%02d: %02d:%02d:%02d.%06d][CsuComm][%d][%02d]%s\" >> /Storage/SystemLog/[%04d.%02d]CCS-SystemLog",
- tm->tm_year + 1900,
- tm->tm_mon + 1,
- tm->tm_mday,
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- tv.tv_usec,
- EVCOMM_SYS_INFO.CpState,
- Check_V2G_Flow_Status(),
- DataString,
- tm->tm_year + 1900,
- tm->tm_mon + 1);
- #else
- sprintf(Buf, "echo \"[%04d%02d%02d: %02d:%02d:%02d.%06d][CsuComm][%d][%02d]%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
- tm->tm_year + 1900,
- tm->tm_mon + 1,
- tm->tm_mday,
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- tv.tv_usec,
- EVCOMM_SYS_INFO.CpState,
- Check_V2G_Flow_Status(),
- DataString,
- tm->tm_year + 1900,
- tm->tm_mon + 1);
- #endif
- system(Buf);
- DEBUG_PRINTF_CSUCOMM_SYSTEM_LOG("[%02d:%02d:%02d.%06d][CsuComm][%d][%02d]%s \n",
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- tv.tv_usec,
- EVCOMM_SYS_INFO.CpState,
- Check_V2G_Flow_Status(),
- DataString);
-
- memset(buf_log_csucomm, 0, SIZE_OF_LOG_BUFFER);
- }
- #endif
- int Array_Check_All_Zero(unsigned char *ptr, int size)
- {
- int result = TRUE;
- int i = 0;
- for (i = 0; i < size; i++)
- {
- if (ptr[i] != 0)
- {
- result = FALSE;
- break;
- }
- }
- return result;
- }
- int Array_Compare_Identity(unsigned char *ptrA, unsigned char *ptrB, int size)
- {
- int result = TRUE;
- int i = 0;
- for (i = 0; i < size; i++)
- {
- if (ptrA[i] != ptrB[i])
- {
- result = FALSE;
- #if 0
- sprintf(buf_log_evcomm,
- "[Array_Compare_Identity]%02X%02X%02X%02X%02X%02X,%02X%02X%02X%02X%02X%02X(%d)\n",
- ptrA[0], ptrA[1], ptrA[2], ptrA[3], ptrA[4], ptrA[5],
- ptrB[0], ptrB[1], ptrB[2], ptrB[3], ptrB[4], ptrB[5],
- result);
- SAVE_SYS_LOG_MSG_EVCOMM(buf_log_evcomm);
- #endif
- break;
- }
- }
- return result;
- }
- int CAN_Tx_MSG(int Fd, unsigned int MsgId, unsigned char SlaveAddress, unsigned char DataLength, unsigned char *SendData)
- {
- struct can_frame frame;
- unsigned int tmp = 0;
- int nbytes = 0;
- int i = 0;
-
- if (DataLength > 8)
- {
- DataLength = 8;
- }
- memset(&frame, 0, sizeof(struct can_frame));
- frame.can_id = 0x80000000 | CAN_SEND_DIRECTION | MsgId | SlaveAddress;
- frame.can_dlc = DataLength;
- memcpy(frame.data, SendData, DataLength);
- nbytes = write(Fd, &frame, sizeof(struct can_frame));
- #if 0
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][CAN_Tx_MSG] <%X> ", frame.can_id);
- for (i = 0; i < frame.can_dlc; i++)
- {
- DEBUG_PRINTF_CSUCOMM_DETAIL("%02X ", frame.data[i]);
- }
- DEBUG_PRINTF_CSUCOMM_DETAIL("(%d Bytes)\n", frame.can_dlc);
- #endif
- return nbytes;
- }
- int Sniffer_Candump(char cmd)
- {
- #if (CANDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
- if (cmd == ENABLE)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[candump]init");
- system("cd /mnt/;rm -rf candump/");
- system("cd /mnt/;mkdir candump");
- SAVE_SYS_LOG_MSG_CSUCOMM("[candump]on");
- system("cd /mnt/candump;candump -l can0 &");
- return 0;
- }
- else if (cmd == DISABLE)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[candump]off");
- system("killall candump");
- SAVE_SYS_LOG_MSG_CSUCOMM("[candump]save");
- system("cd /;cp -rfv /mnt/candump /Storage/SystemLog/");
- return 0;
- }
- else
- {
- sprintf(buf_log_csucomm, "[candump]unexpected cmd(%d)", cmd);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- return -1;
- }
- #endif
- }
- unsigned char Checksum_Generator(unsigned int StartAdress, unsigned int length, unsigned char Data[])
- {
- unsigned char checksum = 0x00;
- for(unsigned int i = 0; i < length; i++)
- {
-
- checksum ^= Data[StartAdress + i];
-
- }
- return checksum;
- }
- unsigned int CRC32_Generator(unsigned char *data, unsigned int length)
- {
- unsigned char i;
- unsigned int cnt = 0;
- unsigned int crc = 0xffffffff;
- while(length--)
- {
- if(cnt > 33 && cnt < 48)
- {
- data++;
- }
- else
- {
- crc ^= *data++;
- for (i = 0; i < 8; ++i)
- {
- if (crc & 1)
- {
- crc = (crc >> 1) ^ 0xEDB88320;
- }
- else
- {
- crc = (crc >> 1);
- }
- }
- }
- cnt++;
- }
- return ~crc;
- }
- int Get_GPIO_Value(unsigned int gpio)
- {
- int fd;
- char buf[32];
- char ch;
- snprintf(buf, sizeof(buf), GPIO_SYS_DIR"/gpio%d/value", gpio);
- fd = open(buf, O_RDONLY);
- if (fd < 0)
- {
- perror("gpio/get-value");
- return fd;
- }
- read(fd, &ch, 1);
- close(fd);
- if (ch != '0')
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- double DiffTimeb(struct timeb ST, struct timeb ET)
- {
-
- double StartTime, EndTime;
- double t_diff;
- StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
- EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
- t_diff = EndTime - StartTime;
-
- if (t_diff < 0)
- {
- #if 0
- if (t_diff < -1000)
- {
- sprintf(buf_log_csucomm,
- "[Warning]StartTime(%.02lf) > EndTime(%.02lf), d(%.02lf)",
- StartTime,
- EndTime,
- t_diff);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- #endif
- return -1;
- }
- return t_diff;
- }
- double DiffTimeb_CsuComm_fork1(struct timeb ST, struct timeb ET)
- {
-
- double StartTime, EndTime;
- double t_diff;
- StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
- EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
- t_diff = EndTime - StartTime;
- if (t_diff < 0)
- {
- #if 0
- if (t_diff < -1000)
- {
- sprintf(buf_log_csucomm_fork1,
- "[fork1][Warning]StartTime(%.02lf) > EndTime(%.02lf), d(%.02lf)",
- StartTime,
- EndTime,
- t_diff);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm_fork1);
- }
- #endif
- return -1;
- }
- return t_diff;
- }
- int ShareMemory_Init()
- {
- int MeterSMId;
-
- #ifdef AWCCS
-
- if((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmSysConfigAndInfo NG");
- return 0;
- }
- else if((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmSysConfigAndInfo NG");
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
-
-
- if((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT |0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmStatusCodeData NG");
- return 0;
- }
- else if((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmStatusCodeData NG");
- return 0;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
-
-
- if((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT |0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmCcsData NG");
- return 0;
- }
- else if((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmCcsData NG");
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
-
-
- if((MeterSMId = shmget(ShmInternalCommKey, sizeof(struct InternalComm), IPC_CREAT | 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmInternalComm NG");
- return 0;
- }
- else if((ShmInternalComm = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmInternalComm NG");
- return 0;
- }
- memset(ShmInternalComm, 0, sizeof(struct InternalComm));
- #if 0
-
- if((MeterSMId = shmget(ShmInternalCommACKey, sizeof(struct InternalCommAC), IPC_CREAT | 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmInternalCommAC NG");
- return 0;
- }
- else if((ShmInternalCommAC = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmInternalCommAC NG");
- return 0;
- }
-
- #endif
-
-
- if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("shmget ShmCharger NG\n");
- return 0;
- }
- else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("shmat ShmCharger NG\n");
- return 0;
- }
-
- #else
-
- if((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmSysConfigAndInfo NG");
- return 0;
- }
- else if((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmSysConfigAndInfo NG");
- return 0;
- }
-
- if((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmStatusCodeData NG");
- return 0;
- }
- else if((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmStatusCodeData NG");
- return 0;
- }
-
- if((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmCcsData NG");
- return 0;
- }
- else if((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmCcsData NG");
- return 0;
- }
-
- if((MeterSMId = shmget(ShmInternalCommKey, sizeof(struct InternalComm), 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmget ShmInternalComm NG");
- return 0;
- }
- else if((ShmInternalComm = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("ShareMemory_Init:shmat ShmInternalComm NG");
- return 0;
- }
-
- #endif
- return 1;
- }
- int CANBus_Init()
- {
- int s0, nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- if (s0 < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[ERROR] Fail on initializing CAN Bus socket");
- }
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if(setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("CANBus_Init:Set SO_RCVTIMEO NG");
- }
- nbytes = 40960;
- if(setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("CANBus_Init:Set SO_RCVBUF NG");
- }
- nbytes = 40960;
- if(setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("CANBus_Init:Set SO_SNDBUF NG");
- }
- 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;
- }
- void Update_EVSE_INFO_to_SHMs()
- {
- int I_now = 0;
- int V_now = 0;
- int P_now = 0;
- int I_max = 0;
- int V_max = 0;
- int P_max = 0;
-
-
- if (ShmInternalComm->ChargingPermission_new != ShmInternalComm->ChargingPermission)
- {
- sprintf(buf_log_csucomm, "Permission: %d >> %d",
- ShmInternalComm->ChargingPermission,
- ShmInternalComm->ChargingPermission_new
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->ChargingPermission_pre = ShmInternalComm->ChargingPermission;
- ShmInternalComm->ChargingPermission = ShmInternalComm->ChargingPermission_new;
- }
-
- V_now = ShmInternalComm->PresentChargingVoltage;
- EVCOMM_SYS_INFO.PresentChargingVoltage = V_now / 10.0;
- if (ShmInternalComm->PresentChargingVoltage_pre != ShmInternalComm->PresentChargingVoltage)
- {
- if (abs(ShmInternalComm->PresentChargingVoltage_pre - ShmInternalComm->PresentChargingVoltage) > 10)
- {
- unsigned char state = 0;
- state = Check_V2G_Flow_Status();
- if(state == CableCheckRequest || state == CableCheckResponse ||
- state == PreChargeRequest || state == PreChargeResponse ||
- state == CurrentDemandRequest || state == CurrentDemandResponse)
- {
- if ((ShmInternalComm->PresentChargingVoltage <= 600) ||
- (ShmInternalComm->PresentChargingVoltage >= 1500)
- )
- {
- sprintf(buf_log_csucomm, "V_now(EVSE): %d >> %d (0.1V, DEC)",
- ShmInternalComm->PresentChargingVoltage_pre,
- ShmInternalComm->PresentChargingVoltage
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- }
- else
- {
- sprintf(buf_log_csucomm, "V_now(EVSE): %d >> %d (0.1V, DEC)",
- ShmInternalComm->PresentChargingVoltage_pre,
- ShmInternalComm->PresentChargingVoltage
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- }
- ShmInternalComm->PresentChargingVoltage_pre = ShmInternalComm->PresentChargingVoltage;
- }
-
- I_now = ShmInternalComm->PresentChargingCurrent;
- EVCOMM_SYS_INFO.PresentChargingCurrent = I_now / 10.0;
- if (ShmInternalComm->PresentChargingCurrent_pre != ShmInternalComm->PresentChargingCurrent)
- {
- if ((abs(ShmInternalComm->PresentChargingCurrent_pre - ShmInternalComm->PresentChargingCurrent) > 20)&&
- (ShmInternalComm->PresentChargingVoltage >= 100))
- {
-
- sprintf(buf_log_csucomm, "I_now(EVSE): %d >> %d (0.1A, DEC)",
- ShmInternalComm->PresentChargingCurrent_pre,
- ShmInternalComm->PresentChargingCurrent
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- ShmInternalComm->PresentChargingCurrent_pre = ShmInternalComm->PresentChargingCurrent;
- }
-
- ShmInternalComm->PresentChargingPower = (int)(((I_now/10) * (V_now/10)) / 100);
- P_now = ShmInternalComm->PresentChargingPower;
- EVCOMM_SYS_INFO.PresentChargingPower = P_now * 10.0;
- if (ShmInternalComm->PresentChargingPower_pre != ShmInternalComm->PresentChargingPower)
- {
- sprintf(buf_log_csucomm, "P_now(EVSE): %d >> %d (0.1KW, DEC)",
- ShmInternalComm->PresentChargingPower_pre,
- ShmInternalComm->PresentChargingPower);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->PresentChargingPower_pre = ShmInternalComm->PresentChargingPower;
- }
-
- I_max = ShmInternalComm->AvailableChargingCurrent;
- EVCOMM_SYS_INFO.AvailableChargingCurrent = I_max / 10.0;
- if (ShmInternalComm->AvailableChargingCurrent_pre != ShmInternalComm->AvailableChargingCurrent)
- {
- sprintf(buf_log_csucomm, "I_max(EVSE): %d >> %d (0.1A, DEC)",
- ShmInternalComm->AvailableChargingCurrent_pre,
- ShmInternalComm->AvailableChargingCurrent);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AvailableChargingCurrent_pre = ShmInternalComm->AvailableChargingCurrent;
- }
-
- V_max = ShmInternalComm->MaximumChargingVoltage;
- EVCOMM_SYS_INFO.MaximumChargingVoltage = V_max / 10.0;
- if (ShmInternalComm->MaximumChargingVoltage_pre != ShmInternalComm->MaximumChargingVoltage)
- {
- sprintf(buf_log_csucomm, "V_max(EVSE): %d >> %d (0.1V, DEC)",
- ShmInternalComm->MaximumChargingVoltage_pre,
- ShmInternalComm->MaximumChargingVoltage
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->MaximumChargingVoltage_pre = ShmInternalComm->MaximumChargingVoltage;
- }
-
- P_max = ShmInternalComm->AvailableChargingPower;
- EVCOMM_SYS_INFO.AvailableChargingPower = P_max / 10.0;
- if (ShmInternalComm->AvailableChargingPower_pre != ShmInternalComm->AvailableChargingPower)
- {
- sprintf(buf_log_csucomm, "P_max(EVSE): %d >> %d (0.1KW, DEC)",
- ShmInternalComm->AvailableChargingPower_pre,
- ShmInternalComm->AvailableChargingPower);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AvailableChargingPower_pre = ShmInternalComm->AvailableChargingPower;
- }
- }
- int Proc_EVBoardStatusRes(int Fd)
- {
- int nbytes;
- unsigned char Buffer[8];
- memset(Buffer, 0, sizeof(Buffer));
- Buffer[0] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].ConnectorPlugIn;
- Buffer[1] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].CpState;
-
- Buffer[2] = ShmStatusCodeData->PresentStatusCode[0][0];
- Buffer[3] = ShmStatusCodeData->PresentStatusCode[0][1];
- Buffer[4] = ShmStatusCodeData->PresentStatusCode[0][2];
- Buffer[5] = ShmStatusCodeData->PresentStatusCode[0][3];
- Buffer[6] = ShmStatusCodeData->PresentStatusCode[0][4];
- Buffer[7] = ShmStatusCodeData->PresentStatusCode[0][5];
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EV_BOARD_STATUS, ShmInternalComm->SlaveAddress, 8, Buffer);
- CSUCOMMDC_TASK_FLAG.Send_EVBoardStatus = FALSE;
- return nbytes;
- }
- void Proc_AddressAssignRes(int Fd)
- {
- }
- void Proc_AddressAssignReq(struct can_frame *frame)
- {
-
-
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][Proc_AddressAssignReq] Unexpected message of address assignment from CSU.\n");
- ShmInternalComm->SlaveAddress = frame->can_id & 0x000000FF;
- CSUCOMMDC_TASK_FLAG.Got_AssignedAddress = TRUE;
- }
- int Proc_GetFirmwareVersionRes(int Fd)
- {
- int i = 0, j = 0, nbytes = 0;
- unsigned char str[FIRMWARE_VERSION_LENGTH + 1];
- unsigned char buf[FIRMWARE_VERSION_LENGTH];
- memset(buf, 0, sizeof(buf));
- strcpy(str, FIRMWARE_VERSION);
- for(i = 0; i < FIRMWARE_VERSION_LENGTH + 3; i++)
- {
- if (str[i] != '_')
- {
- buf[j] = str[i];
- j++;
- }
- }
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_GET_FW_VERSION, ShmInternalComm->SlaveAddress, FIRMWARE_VERSION_LENGTH, buf);
- CSUCOMMDC_TASK_FLAG.Got_FWVersionReq = FALSE;
- return nbytes;
- }
- void Proc_GetFirmwareVersionReq(struct can_frame *frame)
- {
- CSUCOMMDC_TASK_FLAG.Got_FWVersionReq = TRUE;
- }
- int Proc_HardwareVersionRes(int Fd)
- {
- int i = 0, nbytes = 0;
- unsigned char str[HARDWARE_VERSION_LENGTH + 1];
- unsigned char buf[HARDWARE_VERSION_LENGTH];
- memset(buf, 0, sizeof(buf));
- strcpy(str, HARDWARE_VERSION);
- for(i = 0; i < HARDWARE_VERSION_LENGTH; i++)
- {
- buf[i] = str[i];
- }
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_GET_HW_VERSION, ShmInternalComm->SlaveAddress, HARDWARE_VERSION_LENGTH, buf);
- CSUCOMMDC_TASK_FLAG.Got_HWVersionReq = FALSE;
- return nbytes;
- }
- void Proc_HardwareVersionReq(struct can_frame *frame)
- {
- CSUCOMMDC_TASK_FLAG.Got_HWVersionReq = TRUE;
- }
- int Proc_GetMiscellaneousInfoRes(int Fd)
- {
-
- int nbytes;
- unsigned char Buffer[8];
- unsigned short TmpValue;
- memset(Buffer, 0, sizeof(Buffer));
- Buffer[0] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].ConnectorLocked;
- Buffer[1] =ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp&0xFF;
- Buffer[2] =(ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp>>8)&0xFF;
- Buffer[3] = (unsigned char)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].CpVoltage * 10);
- Buffer[4] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].CpState;
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_GET_MISC_INFO, ShmInternalComm->SlaveAddress, 7, Buffer);
- CSUCOMMDC_TASK_FLAG.Got_MiscellaneousInfoReq = FALSE;
- return nbytes;
- }
- void Proc_GetMiscellaneousInfoReq(struct can_frame *frame)
- {
- CSUCOMMDC_TASK_FLAG.Got_MiscellaneousInfoReq = TRUE;
- }
- int Proc_ChargingPermissionRes(int Fd)
- {
-
-
- Update_EVSE_INFO_to_SHMs();
-
- if ((EVCOMM_SYS_INFO.End_Process_inused == TRUE) ||
- (EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE))
- {
- if (ShmInternalComm->ChargingPermission == TRUE)
- {
-
-
- ShmStatusCodeData->PresentStatusCode[0][0] = 0;
- ShmStatusCodeData->PresentStatusCode[0][1] = 2;
- ShmStatusCodeData->PresentStatusCode[0][2] = 3;
- ShmStatusCodeData->PresentStatusCode[0][3] = 8;
- ShmStatusCodeData->PresentStatusCode[0][4] = 9;
- ShmStatusCodeData->PresentStatusCode[0][5] = 1;
- CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
-
-
- }
- }
- CSUCOMMDC_TASK_FLAG.Got_ChargingPermission = FALSE;
- }
- void Proc_ChargingPermissionReq(struct can_frame *frame)
- {
- ShmInternalComm->ChargingPermission_new = frame->data[0];
- ShmInternalComm->AvailableChargingPower = (unsigned int) ((frame->data[2] << 8) | frame->data[1]);
- ShmInternalComm->AvailableChargingCurrent = (unsigned int) ((frame->data[4] << 8) | frame->data[3]);
- ShmInternalComm->MaximumChargingVoltage = (unsigned int) ((frame->data[6] << 8) | frame->data[5]);
- ShmInternalComm->MaximumAllowedChargingTime = frame->data[7];
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][CAN_Rx]\n\
- \t - AvailableChargingPower = (%d, %02X, %02X)\n\
- \t - AvailableChargingCurrent = (%d, %02X, %02X)\n\
- \t - MaximumChargingVoltage = (%d, %02X, %02X)\n",
- ShmInternalComm->AvailableChargingPower, frame->data[2], frame->data[1],
- ShmInternalComm->AvailableChargingCurrent, frame->data[4], frame->data[3],
- ShmInternalComm->MaximumChargingVoltage, frame->data[6], frame->data[5]
- );
-
- CSUCOMMDC_TASK_FLAG.Got_ChargingPermission = TRUE;
- }
- int Proc_EVSEOutputStatusUpdateRes(int Fd)
- {
- Update_EVSE_INFO_to_SHMs();
-
- CSUCOMMDC_TASK_FLAG.Got_EVSEOutputStatus = FALSE;
- }
- void Proc_EVSEOutputStatusUpdateReq(struct can_frame *frame)
- {
- if(ShmInternalComm->SlaveAddress == 1)
- {
- ShmInternalComm->PresentChargingVoltage = ((unsigned int)frame->data[1] << 8 | frame->data[0]);
- ShmInternalComm->PresentChargingCurrent = ((unsigned int)frame->data[3] << 8 | frame->data[2]);
- }
- else
- {
- ShmInternalComm->PresentChargingVoltage = ((unsigned int)frame->data[5] << 8 | frame->data[4]);
- ShmInternalComm->PresentChargingCurrent = ((unsigned int)frame->data[7] << 8 | frame->data[6]);
- }
-
- CSUCOMMDC_TASK_FLAG.Got_EVSEOutputStatus = TRUE;
- }
- int Proc_EVSECapacityUpdateRes(int Fd)
- {
- Update_EVSE_INFO_to_SHMs();
- CSUCOMMDC_TASK_FLAG.Got_EnergyCapacity = FALSE;
- }
- void Proc_EVSECapacityUpdateReq(struct can_frame *frame)
- {
- if(ShmInternalComm->SlaveAddress == 1)
- {
- ShmInternalComm->AvailableChargingPower = ((unsigned int)frame->data[1] << 8 | frame->data[0]);
- ShmInternalComm->AvailableChargingCurrent = ((unsigned int)frame->data[3] << 8 | frame->data[2]);
- }
- else
- {
- ShmInternalComm->AvailableChargingPower = ((unsigned int)frame->data[5] << 8 | frame->data[4]);
- ShmInternalComm->AvailableChargingCurrent = ((unsigned int)frame->data[7] << 8 | frame->data[6]);
- }
-
- CSUCOMMDC_TASK_FLAG.Got_EnergyCapacity = TRUE;
- }
- int Proc_GetEVTargetRes(int Fd)
- {
-
- int nbytes;
- unsigned char Buffer[8];
- unsigned short TmpValue;
- static struct ChargingInfoData *sys;
- sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
- memset(Buffer, 0, sizeof(Buffer));
- Buffer[0] = Check_V2G_Flow_Status();
-
- if (sys->EvBatterySoc_pre != sys->EvBatterySoc)
- {
-
- sprintf(buf_log_csucomm, "SOC = %d >> %d",
- sys->EvBatterySoc_pre,
- sys->EvBatterySoc
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- sys->EvBatterySoc_pre = sys->EvBatterySoc;
- }
- Buffer[1] = sys->EvBatterySoc;
-
-
- if (sys->EvBatterytargetVoltage_pre != sys->EvBatterytargetVoltage)
- {
-
- sprintf(buf_log_csucomm, "V_target = %.02f >> %.02f (1V, DEC)",
- sys->EvBatterytargetVoltage_pre,
- sys->EvBatterytargetVoltage
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- sys->EvBatterytargetVoltage_pre = sys->EvBatterytargetVoltage;
- }
- TmpValue = (unsigned short) (sys->EvBatterytargetVoltage * 10);
- memcpy(Buffer + 2, &TmpValue, 2);
-
- if (sys->EvBatterytargetCurrent_pre != sys->EvBatterytargetCurrent)
- {
-
- sprintf(buf_log_csucomm, "I_target = %.02f >> %.02f (1A, DEC)",
- sys->EvBatterytargetCurrent_pre,
- sys->EvBatterytargetCurrent
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- sys->EvBatterytargetCurrent_pre = sys->EvBatterytargetCurrent;
- }
- TmpValue = (unsigned short) (sys->EvBatterytargetCurrent * 10);
- memcpy(Buffer + 4, &TmpValue, 2);
-
- TmpValue = (unsigned short) sys->RemainChargingDuration;
- memcpy(Buffer + 6, &TmpValue, 2);
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_GET_EV_TARGET_INFO, ShmInternalComm->SlaveAddress, 8, Buffer);
- CSUCOMMDC_TASK_FLAG.Got_EVTargetReq = FALSE;
- return nbytes;
- }
- void Proc_GetEVTargetReq(struct can_frame *frame)
- {
- CSUCOMMDC_TASK_FLAG.Got_EVTargetReq = TRUE;
- }
- int Proc_GetEVBatteryInfoRes(int Fd)
- {
- int nbytes;
- unsigned char Buffer[8];
- unsigned short TmpValue;
- memset(Buffer, 0, sizeof(Buffer));
-
- if((ShmCcsData->CommProtocol == V2GT_MSG_PROTOCOL_ISO15118_2014) &&
- (ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.RequestedEnergyTransferMode <= 1))
- {
- Buffer[0] = 1;
- }
- else
- {
- Buffer[0] = 0;
- }
- if(ShmCcsData->CommProtocol == V2GT_MSG_PROTOCOL_DIN70121)
- {
-
- TmpValue = DIN70121PhyValDecode(ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.EVEnergyCapacity) * 10;
- memcpy(Buffer + 1, &TmpValue, 2);
- TmpValue = DIN70121PhyValDecode(ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.EVMaximumVoltageLimit) * 10;
- memcpy(Buffer + 3, &TmpValue, 2);
- TmpValue = DIN70121PhyValDecode(ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.EVMaximumCurrentLimit) * 10;
- memcpy(Buffer + 5, &TmpValue, 2);
- }
- else if(ShmCcsData->CommProtocol == V2GT_MSG_PROTOCOL_ISO15118_2014)
- {
-
- if(Buffer[0] == 0)
- {
-
- TmpValue = ISO151182014PhyValDecode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.EVEnergyCapacity) * 10;
- memcpy(Buffer + 1, &TmpValue, 2);
- TmpValue = ISO151182014PhyValDecode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.EVMaximumVoltageLimit) * 10;
- memcpy(Buffer + 3, &TmpValue, 2);
- TmpValue = ISO151182014PhyValDecode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.EVMaximumCurrentLimit) * 10;
- memcpy(Buffer + 5, &TmpValue, 2);
- }
- else
- {
-
- TmpValue = ISO151182014PhyValDecode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.AC_EVChargeParameter.EAmount) * 10;
- memcpy(Buffer + 1, &TmpValue, 2);
- TmpValue = ISO151182014PhyValDecode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.AC_EVChargeParameter.EVMaxVoltage) * 10;
- memcpy(Buffer + 3, &TmpValue, 2);
- TmpValue = ISO151182014PhyValDecode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.AC_EVChargeParameter.EVMaxCurrent) * 10;
- memcpy(Buffer + 5, &TmpValue, 2);
- }
- }
- else if(ShmCcsData->CommProtocol == V2GT_MSG_PROTOCOL_ISO15118_2018)
- {
-
- }
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_GET_EV_BATTERY_INFO, ShmInternalComm->SlaveAddress, 7, Buffer);
- CSUCOMMDC_TASK_FLAG.Got_EVBatteryInfoReq = FALSE;
- return nbytes;
- }
- void Proc_GetEVBatteryInfoReq()
- {
- CSUCOMMDC_TASK_FLAG.Got_EVBatteryInfoReq = TRUE;
- }
- int Proc_IsolationStatusAnnounceRes(int Fd)
- {
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][Proc_IsolationStatusAnnounceRes] %d (DEC, 0:ongoing, 1:valid, 2:warning/fault)\n",
- ShmInternalComm->IsolationStatus);
- if (ShmInternalComm->IsolationStatus_pre != ShmInternalComm->IsolationStatus)
- {
-
- sprintf(buf_log_csucomm, "Isolation: %d >> %d",
- ShmInternalComm->IsolationStatus_pre,
- ShmInternalComm->IsolationStatus);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->IsolationStatus_pre = ShmInternalComm->IsolationStatus;
- }
-
-
-
-
-
- CSUCOMMDC_TASK_FLAG.Got_IsolationStatus = FALSE;
- }
- void Proc_IsolationStatusAnnounceReq(struct can_frame *frame)
- {
- unsigned char gfd_rx = 0;
- gfd_rx = (unsigned char) frame->data[0];
- if (gfd_rx >= GFD_Invalid && gfd_rx <= GFD_No_IMD)
- {
-
- if (gfd_rx == GFD_Warning)
- {
- gfd_rx = GFD_Fault;
- }
- else if (gfd_rx == GFD_Fault)
- {
- gfd_rx = GFD_Warning;
- }
- else
- {
-
- }
- ShmInternalComm->IsolationStatus = gfd_rx;
- EVCOMM_SYS_INFO.IsolationStatus = ShmInternalComm->IsolationStatus;
- CSUCOMMDC_TASK_FLAG.Got_IsolationStatus = TRUE;
- }
- else
- {
- sprintf(buf_log_csucomm,
- "[WARNING]unexpected isolation status(%d)",
- frame->data[0]);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- }
- int Proc_CCSConnectorTypeSetRes(int Fd)
- {
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][Proc_CCSConnectorTypeSetRes] To-be implemented. (checking for PP or not)\n");
- CSUCOMMDC_TASK_FLAG.Got_CCSConnectorReq = FALSE;
- }
- void Proc_CCSConnectorTypeSetReq(struct can_frame *frame)
- {
- ShmInternalComm->CCSConnectorType = (unsigned char) frame->data[0];
- CSUCOMMDC_TASK_FLAG.Got_CCSConnectorReq = TRUE;
- }
- int Proc_RTCSetRes(int Fd)
- {
- int nbytes;
- unsigned char Buffer[1];
- memset(Buffer, 0, sizeof(Buffer));
- if (ShmInternalComm->RTC != 0)
- {
-
-
- sprintf(buf_log_csucomm, "[Proc_RTCSetRes] Got RTC Message: %lu (DEC)", ShmInternalComm->RTC);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- system("date");
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_RTCSetRes] RTC is updating...");
- #if 1
- time_t rtc_new;
- rtc_new = ShmInternalComm->RTC;
- stime(&rtc_new);
- ftime(&ShmInternalComm->Start_Time);
- ftime(&ShmInternalComm->End_Time);
- ftime(&ShmInternalComm->CAN_Rx_Timer_Start);
- ftime(&ShmInternalComm->CAN_Rx_Timer_End);
- #else
- char buf[64];
- sprintf(buf, "date +%%s -s @%u", ShmInternalComm->RTC);
- system(buf);
- ftime(&ShmInternalComm->Start_Time);
- ftime(&ShmInternalComm->End_Time);
- ftime(&ShmInternalComm->CAN_Rx_Timer_Start);
- ftime(&ShmInternalComm->CAN_Rx_Timer_End);
- #endif
- system("date");
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_RTCSetRes] RTC is updated.\n");
- Buffer[0] = 1;
- }
- else
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_RTCSetRes] Reject.\n");
- Buffer[0] = 0;
- }
- CSUCOMMDC_TASK_FLAG.Got_RTC = FALSE;
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_RTC_INFO, ShmInternalComm->SlaveAddress, 1, Buffer);
- return nbytes;
- }
- void Proc_RTCSetReq(struct can_frame *frame)
- {
-
-
- long int rtc_tmp = 0;
- memcpy(&rtc_tmp, &frame->data[0], 4);
- if (rtc_tmp < RTC_DEFAULT_TIME)
- {
- sprintf(buf_log_csucomm,
- "[WARNING] RTC time from CSU(%lu) is older than CCS(%lu): ignored",
- rtc_tmp,
- RTC_DEFAULT_TIME);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- return;
- }
-
- if (Check_V2G_Flow_Status() == IDLE &&
- ShmInternalComm->DownloadImageInfo.active == FALSE &&
- EVCOMM_SYS_INFO.End_Process_inused == FALSE)
- {
- #if 1
-
- memcpy(&ShmInternalComm->RTC, &frame->data[0], 4);
- #else
-
- unsigned char rtc[4], tmp;
- memcpy(&rtc[0], &frame->data[0], 4);
- tmp = rtc[0];
- rtc[0] = rtc[3];
- rtc[3] = tmp;
- tmp = rtc[1];
- rtc[1] = rtc[2];
- rtc[2] = tmp;
- memcpy(&ShmInternalComm->RTC, &rtc[0], 4);
- #endif
- }
- else
- {
- ShmInternalComm->RTC = 0;
- }
-
- CSUCOMMDC_TASK_FLAG.Got_RTC = TRUE;
- }
- int Proc_EVSEPrechargeInfoUpdateRes(int Fd)
- {
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][Proc_EVSEPrechargeInfoUpdateRes]\n");
- int nbytes;
- unsigned char Buffer[8];
- unsigned short TmpValue;
- memset(Buffer, 0, sizeof(Buffer));
-
- Buffer[0] = ShmInternalComm->EVSEPrechargeStatus;
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EVSE_PRECHARGE_INFO, ShmInternalComm->SlaveAddress, 1, Buffer);
- CSUCOMMDC_TASK_FLAG.Got_EVSE_Precharge_Info = FALSE;
- return nbytes;
- }
- void Proc_EVSEPrechargeInfoUpdateReq(struct can_frame *frame)
- {
- static struct ChargingInfoData *sys;
- sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
- ShmInternalComm->EVSEPrechargeStatus = frame->data[0];
- sys->EVSEPrechargeStatus = ShmInternalComm->EVSEPrechargeStatus;
- if (sys->EVSEPrechargeStatus_pre != sys->EVSEPrechargeStatus)
- {
-
- sprintf(buf_log_csucomm, "Precharge Status: %d >> %d",
- sys->EVSEPrechargeStatus_pre,
- sys->EVSEPrechargeStatus
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- sys->EVSEPrechargeStatus_pre = sys->EVSEPrechargeStatus;
- }
- CSUCOMMDC_TASK_FLAG.Got_EVSE_Precharge_Info = TRUE;
- }
- int Proc_EVCCIDRes(int Fd)
- {
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][Proc_EVCCIDRes]\n");
- int i = 0;
- int nbytes = 0;
- unsigned char Buffer[8];
-
- memset(Buffer, 0, sizeof(Buffer));
-
- if(EVCOMM_SYS_INFO.EVCCID_length>=8)
- {
- EVCOMM_SYS_INFO.EVCCID_length=8;
- if((EVCOMM_SYS_INFO.EVCCID[0]==0)&&(EVCOMM_SYS_INFO.EVCCID[1]==0))
- memcpy(EVCOMM_SYS_INFO.EVCCID,EVCOMM_SYS_INFO.EVCCID+2,6);
- EVCOMM_SYS_INFO.EVCCID_length=6;
- }
- memcpy(Buffer,EVCOMM_SYS_INFO.EVCCID,EVCOMM_SYS_INFO.EVCCID_length);
-
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EVCCID_REQUEST, ShmInternalComm->SlaveAddress, EVCOMM_SYS_INFO.EVCCID_length, Buffer);
- CSUCOMMDC_TASK_FLAG.Got_EVCCID_Req = FALSE;
- return nbytes;
- }
- void Proc_EVCCIDReq(struct can_frame *frame)
- {
- CSUCOMMDC_TASK_FLAG.Got_EVCCID_Req = TRUE;
- }
- int Proc_EVStopRes(int Fd)
- {
- int nbytes;
- unsigned char Buffer[8];
- memset(Buffer, 0, sizeof(Buffer));
-
- Buffer[1] = ShmStatusCodeData->PresentStatusCode[0][0];
- Buffer[2] = ShmStatusCodeData->PresentStatusCode[0][1];
- Buffer[3] = ShmStatusCodeData->PresentStatusCode[0][2];
- Buffer[4] = ShmStatusCodeData->PresentStatusCode[0][3];
- Buffer[5] = ShmStatusCodeData->PresentStatusCode[0][4];
- Buffer[6] = ShmStatusCodeData->PresentStatusCode[0][5];
-
- if(( Buffer[1]== 0)&&( Buffer[2]== 2)&&( Buffer[3]== 3)&&( Buffer[4]== 9)&&( Buffer[5]== 7)&&( Buffer[6]== 9))
- CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
- else
- CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
-
- if (CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency == TRUE)
- {
- Buffer[0] = EV_EMERGENCY_STOP;
- }
- else
- {
- Buffer[0] = EV_NORMAL_STOP;
- }
-
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EV_STOP_EVENT, ShmInternalComm->SlaveAddress, 7, Buffer);
-
-
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_EVStopRes] Sending STOP Command to CSU");
- CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
- CSUCOMMDC_TASK_FLAG.Send_EVStopReq = FALSE;
- return nbytes;
- }
- int Proc_EVSEStopRes(int Fd)
- {
- if (EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_Shutdown &&
- EVCOMM_SYS_INFO.DC_EVSEStatus != EVSE_EmergencyShutdown)
- {
-
-
- sprintf(buf_log_csucomm,
- "[Proc_EVSEStopRes] CSU Requests for STOP (Stop by EVSE: %d)",
- ShmInternalComm->EVSEStopChargingReq.type);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
-
-
- if (ShmInternalComm->EVSEStopChargingReq.type == 1)
- {
- EVCOMM_SYS_INFO.DC_EVSEStatus = EVSE_Shutdown;
- }
- else if (ShmInternalComm->EVSEStopChargingReq.type == 2)
- {
- EVCOMM_SYS_INFO.DC_EVSEStatus = EVSE_EmergencyShutdown;
- }
- else
- {
- EVCOMM_SYS_INFO.DC_EVSEStatus = EVSE_Ready;
- }
- }
- CSUCOMMDC_TASK_FLAG.Got_EVSEStopReq = FALSE;
- }
- void Proc_EVSEStopReq(struct can_frame *frame)
- {
- ShmInternalComm->EVSEStopChargingReq.type = frame->data[0];
- memcpy(&ShmInternalComm->EVSEStopChargingReq.alarmcode, &frame->data[1], 6);
- CSUCOMMDC_TASK_FLAG.Got_EVSEStopReq = TRUE;
- }
- int Check_DwnldImgParameter()
- {
- int image_size = 0;
- int total_can_packets = 0;
- unsigned char block_quantity = 0;
- unsigned char block_size_KByte = 0;
- unsigned char final_canmsg_size = 0;
- image_size = ShmInternalComm->DownloadImageInfo.image_size;
- block_quantity = ShmInternalComm->DownloadImageInfo.block_quantity;
- block_size_KByte = ShmInternalComm->DownloadImageInfo.block_size_KByte;
-
- final_canmsg_size = image_size % 8;
- total_can_packets = image_size / 8;
- if (final_canmsg_size != 0)
- {
- total_can_packets += 1;
- }
- ShmInternalComm->DownloadImageInfo.final_canmsg_size = final_canmsg_size;
- ShmInternalComm->DownloadImageInfo.total_can_packets = total_can_packets;
- DEBUG_PRINTF_CSUCOMM_DETAIL("[Check_DwnldImgParameter]\n");
- DEBUG_PRINTF_CSUCOMM_DETAIL("\t - final_canmsg_size = %d (DEC)\n\
- \t - total_can_packets = %d (DEC)\n\n",
- ShmInternalComm->DownloadImageInfo.final_canmsg_size,
- ShmInternalComm->DownloadImageInfo.total_can_packets
- );
-
-
-
- if (ShmInternalComm->DownloadImageInfo.type <= IMAGE_TYPE_USER_CONFIGURATION)
- {
- return TRUE;
- }
- else
- {
- sprintf(buf_log_csucomm,
- "[Check_DwnldImgParameter] type(%d) is not allowed, yet.",
- ShmInternalComm->DownloadImageInfo.type
- );
- SAVE_SYS_LOG_MSG_CSUCOMM("buf_log_csucomm");
- return FALSE;
- }
- }
- int Proc_DownloadImageRes(int Fd)
- {
- int nbytes;
- unsigned char Buffer[1];
- memset(Buffer, 0, sizeof(Buffer));
- if (ShmInternalComm->DownloadImageInfo.active == TRUE)
- {
-
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_DownloadImageRes] closing SeccComm...");
- system("killall SeccComm");
- system("rm -f /Storage/tmp");
- system("touch /Storage/tmp");
- #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_DownloadImageRes]sync...");
- system("sync");
- }
- #endif
- Buffer[0] = 1;
- }
- else
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_DownloadImageRes] Fail");
- Buffer[0] = 0;
-
- }
- DEBUG_PRINTF_CSUCOMM_DETAIL("[Proc_DownloadImageRes] %d (DEC)\n", Buffer[0]);
- CSUCOMMDC_TASK_FLAG.Got_DownloadImageReq = FALSE;
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_DOWNLOAD_REQUEST, ShmInternalComm->SlaveAddress, 1, Buffer);
- return nbytes;
- }
- void Proc_DownloadImageReq(struct can_frame *frame)
- {
- if (Check_V2G_Flow_Status() == IDLE)
- {
- ShmInternalComm->DownloadImageInfo.type = frame->data[0];
- memcpy(&ShmInternalComm->DownloadImageInfo.image_size, &frame->data[1], 4);
- ShmInternalComm->DownloadImageInfo.image_size_received = 0;
- ShmInternalComm->DownloadImageInfo.block_quantity = frame->data[5];
- ShmInternalComm->DownloadImageInfo.block_sequence_number = 0;
- ShmInternalComm->DownloadImageInfo.block_size_KByte = frame->data[6];
- ShmInternalComm->DownloadImageInfo.block_sequence_number = 0;
- ShmInternalComm->DownloadImageInfo.block_checksum = 0;
- ShmInternalComm->DownloadImageInfo.total_can_packets = 0;
- ShmInternalComm->DownloadImageInfo.image_rx_cnt = 0;
- ShmInternalComm->DownloadImageInfo.downlaod_percentage = 0;
- ShmInternalComm->DownloadImageInfo.downlaod_percentage_pre = 0;
- ShmInternalComm->DownloadImageInfo.active = FALSE;
- if (ShmInternalComm->DownloadImageInfo.image_size == 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_DownloadImageReq][Warning] image_size cannot be 0\n");
- }
- else if (ShmInternalComm->DownloadImageInfo.block_quantity == 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_DownloadImageReq][Warning] block_quantity cannot be 0\n");
- }
- else if (ShmInternalComm->DownloadImageInfo.block_size_KByte == 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_DownloadImageReq][Warning] block_size_KByte cannot be 0\n");
- }
- else if (Check_DwnldImgParameter() == FALSE)
- {
- sprintf(buf_log_csucomm, "[Proc_DownloadImageReq][Warning] nonlogical image_size(%d bytes, DEC), block_quantity(%d, DEC), block_size_KByte(%d, DEC)\n",
- ShmInternalComm->DownloadImageInfo.image_size,
- ShmInternalComm->DownloadImageInfo.block_quantity,
- ShmInternalComm->DownloadImageInfo.block_size_KByte
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- else
- {
- ShmInternalComm->DownloadImageInfo.active = TRUE;
- }
- }
- else
- {
- ShmInternalComm->DownloadImageInfo.active = FALSE;
- sprintf(buf_log_csucomm,
- "[Proc_BlockTransferStartReq] PresentMsgFlowStatus (%d, DEC) is not in IDLE\n",
- Check_V2G_Flow_Status()
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_DownloadImageReq] Got Request from CSU\n");
- sprintf(buf_log_csucomm, "\t - type = %d (DEC)\n\
- \t - image size = %d (DEC, bytes)\n\
- \t - block quantity = %d (DEC)\n\
- \t - block size = %d (DEC, KBytes)\n\n",
- ShmInternalComm->DownloadImageInfo.type,
- ShmInternalComm->DownloadImageInfo.image_size,
- ShmInternalComm->DownloadImageInfo.block_quantity,
- ShmInternalComm->DownloadImageInfo.block_size_KByte
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- CSUCOMMDC_TASK_FLAG.Got_DownloadImageReq = TRUE;
- }
- int Proc_BlockTransferStartRes(int Fd)
- {
- int nbytes;
- unsigned char Buffer[1];
- memset(Buffer, 0, sizeof(Buffer));
- if (ShmInternalComm->DownloadImageInfo.active == TRUE)
- {
- Buffer[0] = 1;
- }
- else
- {
- fclose(ShmInternalComm->DownloadImageInfo.file);
- Buffer[0] = 0;
-
- }
- DEBUG_PRINTF_CSUCOMM_DETAIL("[Proc_BlockTransferStartRes] %d (DEC)\n", Buffer[0]);
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_START_BLOCK_TRANSFER, ShmInternalComm->SlaveAddress, 1, Buffer);
- CSUCOMMDC_TASK_FLAG.Got_BlockTransferStartReq = FALSE;
- return nbytes;
- }
- void Proc_BlockTransferStartReq(struct can_frame *frame)
- {
- if (Check_V2G_Flow_Status() == IDLE)
- {
- ShmInternalComm->DownloadImageInfo.block_sequence_number += 1;
-
- if (frame->data[0] >= 1 &&
- frame->data[0] <= 255 &&
- ShmInternalComm->DownloadImageInfo.block_sequence_number == frame->data[0] &&
- ShmInternalComm->DownloadImageInfo.block_sequence_number >= 1 &&
- ShmInternalComm->DownloadImageInfo.block_sequence_number <= 255
- )
- {
- ShmInternalComm->DownloadImageInfo.active = TRUE;
- }
- else
- {
- sprintf(buf_log_csucomm, "[Proc_BlockTransferStartReq][Warning] Unexpected block_sequence_number (%d, %d, DEC)\n",
- frame->data[0],
- ShmInternalComm->DownloadImageInfo.block_sequence_number
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->DownloadImageInfo.active = FALSE;
- }
- ShmInternalComm->DownloadImageInfo.block_checksum = frame->data[1];
- }
- else
- {
- ShmInternalComm->DownloadImageInfo.active = FALSE;
- sprintf(buf_log_csucomm,
- "[Proc_BlockTransferStartReq] PresentMsgFlowStatus (%d, DEC) is not in IDLE\n",
- Check_V2G_Flow_Status()
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- DEBUG_PRINTF_CSUCOMM_DETAIL("\n[Proc_BlockTransferStartReq] Got Request from CSU\n");
- sprintf(buf_log_csucomm, "\t - block_sequence_number = %d (DEC)\n\
- \t - block_checksum = %02X (HEX, bytes)\n\n",
- ShmInternalComm->DownloadImageInfo.block_sequence_number,
- ShmInternalComm->DownloadImageInfo.block_checksum
- );
- DEBUG_PRINTF_CSUCOMM_DETAIL(buf_log_csucomm);
- CSUCOMMDC_TASK_FLAG.Got_BlockTransferStartReq = TRUE;
- }
- int Proc_DataTransferRes(int Fd)
- {
-
-
- CSUCOMMDC_TASK_FLAG.Got_DataTransferReq = FALSE;
- }
- void Proc_DataTransferReq(struct can_frame *frame)
- {
- if (Check_V2G_Flow_Status() == IDLE &&
- ShmInternalComm->DownloadImageInfo.active == 1)
- {
- if ((ShmInternalComm->DownloadImageInfo.image_rx_cnt + frame->can_dlc) <= ShmInternalComm->DownloadImageInfo.image_size)
- {
-
- FILE *file;
- file = fopen("/Storage/tmp", "ab+");
- int rlen = 0;
- DEBUG_PRINTF_CSUCOMM_DETAIL("[Proc_DataTransferReq] saving data... (%d bytes, DEC)\n", frame->can_dlc);
-
- rlen = fwrite(&frame->data[0], sizeof(unsigned char), frame->can_dlc, file);
- if (rlen == frame->can_dlc)
- {
- fflush(ShmInternalComm->DownloadImageInfo.file);
- DEBUG_PRINTF_CSUCOMM_DETAIL("[Proc_DataTransferReq] fwrite: OK (rlen = %d)\n", rlen);
- ShmInternalComm->DownloadImageInfo.image_rx_cnt += frame->can_dlc;
- }
- else
- {
- DEBUG_PRINTF_CSUCOMM_DETAIL("[Proc_DataTransferReq] fwrite: FAIL (rlen = %d)\n", rlen);
- ShmInternalComm->DownloadImageInfo.active = FALSE;
- }
- fflush(file);
- fclose(file);
- DEBUG_PRINTF_CSUCOMM_DETAIL("\n", ShmInternalComm->DownloadImageInfo.image_rx_cnt);
-
- ShmInternalComm->DownloadImageInfo.downlaod_percentage = (ShmInternalComm->DownloadImageInfo.image_rx_cnt*100)/ShmInternalComm->DownloadImageInfo.image_size;
- if (ShmInternalComm->DownloadImageInfo.downlaod_percentage != ShmInternalComm->DownloadImageInfo.downlaod_percentage_pre)
- {
- sprintf(buf_log_csucomm,
- "[Proc_DataTransferReq] rx: %d\% (%d of %d bytes)\n",
- ShmInternalComm->DownloadImageInfo.downlaod_percentage,
- ShmInternalComm->DownloadImageInfo.image_rx_cnt,
- ShmInternalComm->DownloadImageInfo.image_size
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->DownloadImageInfo.downlaod_percentage_pre = ShmInternalComm->DownloadImageInfo.downlaod_percentage;
- }
- }
- else
- {
- ShmInternalComm->DownloadImageInfo.active = FALSE;
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_BlockTransferStartReq] unexpected extra packets\n");
- }
- }
- else
- {
- ShmInternalComm->DownloadImageInfo.active = FALSE;
- sprintf(buf_log_csucomm, "[Proc_BlockTransferStartReq] PresentMsgFlowStatus (%d, DEC) \
- is not in IDLE or active flag (%d, DEC) is canceled\n",
- Check_V2G_Flow_Status(),
- ShmInternalComm->DownloadImageInfo.active
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
-
-
-
- }
- CSUCOMMDC_TASK_FLAG.Got_DataTransferReq = TRUE;
- }
- int Proc_DownloadFinishRes(int Fd)
- {
- int nbytes;
- unsigned char Buffer[1];
- memset(Buffer, 0, sizeof(Buffer));
-
- if (Check_V2G_Flow_Status() != IDLE)
- {
- if (CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused == FALSE)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Warning]FW update Req: ignored (only for idle mode)");
- Buffer[0] = FAIL;
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_DOWNLOAD_FINISH, ShmInternalComm->SlaveAddress, 1, Buffer);
- if (nbytes > 0)
- {
- sprintf(buf_log_csucomm, "[Proc_DownloadFinishRes]Tx:ok(%d)", Buffer[0]);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- else
- {
- sprintf(buf_log_csucomm, "[Proc_DownloadFinishRes]Tx:fail(%d)", nbytes);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- return FAIL;
- }
- else if (CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused == TRUE)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Warning]FW update Req: ignored (in used, already)");
-
- return FAIL;
- }
- else
- {
- sprintf(buf_log_csucomm,
- "[Warning]unexpected FW_Update_Task_inused value(%d)",
- CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- return FAIL;
- }
- }
-
- if (CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused == FALSE)
- {
- CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused = TRUE;
-
- SAVE_SYS_LOG_MSG_CSUCOMM("[Proc_DownloadFinishRes] closing SeccComm...");
- system("killall SeccComm");
- system("cd /root;./FWUpdate -w &");
- }
-
- if (CSUCOMMDC_TASK_FLAG.FW_Update_Done == TRUE)
- {
- if (CSUCOMMDC_TASK_FLAG.FW_Update_result == PASS)
- {
- Buffer[0] = PASS;
- }
- else
- {
- Buffer[0] = FAIL;
- }
- nbytes = CAN_Tx_MSG(Fd, CAN_CMD_DOWNLOAD_FINISH, ShmInternalComm->SlaveAddress, 1, Buffer);
- if (nbytes > 0)
- {
- sprintf(buf_log_csucomm, "[Proc_DownloadFinishRes]Tx:ok(%d)", Buffer[0]);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- else
- {
- sprintf(buf_log_csucomm, "[Proc_DownloadFinishRes]Tx:fail(%d)", nbytes);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- sleep(2);
-
- CSUCOMMDC_TASK_FLAG.Got_DownloadFinishReq = FALSE;
-
- Reboot_Process();
-
- return nbytes;
- }
- }
- void Proc_DownloadFinishReq(struct can_frame *frame)
- {
- CSUCOMMDC_TASK_FLAG.Got_DownloadFinishReq = TRUE;
- }
- void PRINT_CAN_FRAME(struct can_frame *frame)
- {
- if (frame->can_dlc != 0)
- {
- int i = 0;
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm] Got CAN Message: \n\
- \t - Length: %d (Bytes, DEC)\n\
- \t - ID: %08X\n\
- \t - Payload: ",
- frame->can_dlc,
- frame->can_id
- );
- for (i = 0; i< frame->can_dlc; i++)
- {
- DEBUG_PRINTF_CSUCOMM_DETAIL("%02X ", frame->data[i]);
- }
- DEBUG_PRINTF_CSUCOMM_DETAIL("\n");
- }
- }
- int CANRxTimeoutHandler()
- {
- #if (CAN_RX_TIMEOUT_MECHANISM == ENABLE)
-
- if (CSUCOMMDC_TASK_FLAG.matched == TRUE &&
- CSUCOMMDC_TASK_FLAG.CAN_Rx_Timeout == FALSE)
- {
- long int time_diff = 0;
- ftime(&ShmInternalComm->CAN_Rx_Timer_End);
- time_diff = DiffTimeb_CsuComm_fork1(ShmInternalComm->CAN_Rx_Timer_Start, ShmInternalComm->CAN_Rx_Timer_End);
- if(time_diff >= CSUCOMM_CAN_RX_TIMEOUT)
- {
- sprintf(buf_log_csucomm_fork1,
- "[fork1][Rx]CAN timeout(%ld of %dms) => reboot",
- time_diff,
- CSUCOMM_CAN_RX_TIMEOUT
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm_fork1);
-
-
-
- ShmStatusCodeData->PresentStatusCode[0][0] = 0;
- ShmStatusCodeData->PresentStatusCode[0][1] = 1;
- ShmStatusCodeData->PresentStatusCode[0][2] = 2;
- ShmStatusCodeData->PresentStatusCode[0][3] = 2;
- ShmStatusCodeData->PresentStatusCode[0][4] = 4;
- ShmStatusCodeData->PresentStatusCode[0][5] = 8;
- CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
- CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
- CSUCOMMDC_TASK_FLAG.CAN_Rx_Timeout = TRUE;
- Reboot_Process();
- }
- }
- #endif
- }
- void Error_Monitor_CsuComm()
- {
- pid_t tmp = 0;
- if(PID_CsuComm_Error_Monitor_Task == 0)
- {
- tmp = fork();
- if(tmp > 0)
- {
- PID_CsuComm_Error_Monitor_Task = tmp;
- sprintf(buf_log_csucomm_fork1,
- "[fork2][Error_Monitor]created(%d)",
- PID_CsuComm_Error_Monitor_Task);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm_fork1);
- #if 0
- unsigned char buf[64];
- memset(buf, 0, sizeof(buf));
- sprintf(buf, "renice -20 -p %d", tmp);
- system(buf);
- #endif
- return;
- }
- }
- while(1)
- {
-
- CANRxTimeoutHandler();
- usleep(1000);
-
-
- }
- }
- void CAN_Rx(int fd)
- {
- pid_t tmp = 0;
- struct can_frame frame;
- int nbytes;
- if(PID_CAN_Rx_Task == 0)
- {
- tmp = fork();
- if(tmp > 0)
- {
- PID_CAN_Rx_Task = tmp;
- sprintf(buf_log_csucomm_fork2,
- "[fork2][Error_Monitor]created(%d)",
- PID_CAN_Rx_Task);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm_fork2);
- #if 0
- unsigned char buf[64];
- memset(buf, 0, sizeof(buf));
- sprintf(buf, "renice -20 -p %d", tmp);
- system(buf);
- #endif
- return;
- }
- }
- ftime(&ShmInternalComm->CAN_Rx_Timer_Start);
- while(1)
- {
- memset(&frame, 0, sizeof(struct can_frame));
- nbytes = read(fd, &frame, sizeof(struct can_frame));
-
-
-
- if((frame.can_id == 0) ||
- ((frame.can_id & 0x08000000) == 1) ||
- (((frame.can_id & 0x000000FF) != ShmInternalComm->SlaveAddress) && ((frame.can_id & 0x000000FF) != 0)))
- {
- continue;
- }
-
-
- ftime(&ShmInternalComm->CAN_Rx_Timer_Start);
-
- switch(frame.can_id & 0x0000FF00)
- {
- case CAN_CMD_ADDRESS_ASSIGN:
- {
- Proc_AddressAssignReq(&frame);
- break;
- }
- case CAN_CMD_GET_FW_VERSION:
- {
- Proc_GetFirmwareVersionReq(&frame);
- break;
- }
- case CAN_CMD_GET_HW_VERSION:
- {
- Proc_HardwareVersionReq(&frame);
- break;
- }
- case CAN_CMD_CHARGING_PERMISSION:
- {
- Proc_ChargingPermissionReq(&frame);
- break;
- }
- case CAN_CMD_EVSE_OUTPUT_STATUS_ANNOUNCEMENT:
- {
- Proc_EVSEOutputStatusUpdateReq(&frame);
- break;
- }
- case CAN_CMD_EVSE_CAPACITY_ANNOUNCEMENT:
- {
- Proc_EVSECapacityUpdateReq(&frame);
- break;
- }
- case CAN_CMD_GET_EV_TARGET_INFO:
- {
- Proc_GetEVTargetReq(&frame);
- break;
- }
- case CAN_CMD_GET_EV_BATTERY_INFO:
- {
- Proc_GetEVBatteryInfoReq(&frame);
- break;
- }
- case CAN_CMD_EVSE_STOP_EVENT:
- {
- Proc_EVSEStopReq(&frame);
- break;
- }
- case CAN_CMD_GET_MISC_INFO:
- {
- Proc_GetMiscellaneousInfoReq(&frame);
- break;
- }
- case CAN_CMD_DOWNLOAD_REQUEST:
- {
-
- break;
- }
- case CAN_CMD_START_BLOCK_TRANSFER:
- {
-
- break;
- }
- case CAN_CMD_DATA_TRANSFER:
- {
-
- break;
- }
- case CAN_CMD_DOWNLOAD_FINISH:
- {
- Proc_DownloadFinishReq(&frame);
- break;
- }
- case CAN_CMD_ISOLATION_STATUS:
- {
- Proc_IsolationStatusAnnounceReq(&frame);
- break;
- }
- case CAN_CMD_CCS_CONNECTOR_INFO:
- {
- Proc_CCSConnectorTypeSetReq(&frame);
- break;
- }
- case CAN_CMD_RTC_INFO:
- {
- Proc_RTCSetReq(&frame);
- break;
- }
- case CAN_CMD_EVSE_PRECHARGE_INFO:
- {
- Proc_EVSEPrechargeInfoUpdateReq(&frame);
- break;
- }
- case CAN_CMD_EVCCID_REQUEST:
- {
- Proc_EVCCIDReq(&frame);
- break;
- }
- default:
- {
- sprintf(buf_log_csucomm_fork2,
- "[fork2][ERROR]Unexpected CAN Command ID: %d (DEC)",
- (frame.can_id & 0x0000FF00));
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm_fork2);
- break;
- }
- }
- }
- }
- int Eth0_PortSetting_Add(unsigned char addr)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Eth0_PortSetting_Add]start");
- unsigned char cmd[128];
- if ((addr >= 1) && (addr <= 20))
- {
- addr = 20 + addr;
-
- #if 0
- SAVE_SYS_LOG_MSG_CSUCOMM("[Eth0_PortSetting][eth0:0]down");
- system("/sbin/ifconfig eth0:0 down");
- sleep(1);
- #endif
-
- sprintf(buf_log_csucomm,
- "[Eth0_PortSetting_Add][eth0:0]IP >> 192.168.0.%d(up))",
- addr);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- sprintf(cmd, "/sbin/ifconfig eth0:0 192.168.0.%d netmask 255.255.255.0 up", addr);
- system(cmd);
- memset(cmd, 0, sizeof(cmd));
- sleep(1);
- sprintf(buf_log_csucomm,
- "[Eth0_PortSetting_Add][eth0:0]done",
- addr);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- return PASS;
- }
- else
- {
- sprintf(buf_log_csucomm,
- "[Eth0_PortSetting_Add][Error]addr(%d) is out of range(1~20)",
- addr);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- return FAIL;
- }
- }
- int Reboot_Process()
- {
- if (CSUCOMMDC_TASK_FLAG.Reboot_Process_inused == FALSE)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Reboot_Process]entered");
- CSUCOMMDC_TASK_FLAG.Reboot_Process_inused = TRUE;
- #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[Reboot_Process]sync...");
- system("sync");
- }
- #endif
- system("sleep 2");
- system("cd /root;./reboot.sh");
- }
- }
- int CsuCommAC_GetCcsFirmwareVersion(unsigned char *buf)
- {
- int i = 0, j = 0, err = PASS, leng = 0;
- unsigned char str[FIRMWARE_VERSION_LENGTH + 1];
- memset(buf, 0, sizeof(buf));
- strcpy(str, FIRMWARE_VERSION);
- leng = FIRMWARE_VERSION_LENGTH + 3;
- if (sizeof(buf) < leng)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[WARNING][CsuCommAC_GetCcsFirmwareVersion]ver size: too long");
- leng = sizeof(buf);
- }
- for(i = 0; i < leng; i++)
- {
- if (str[i] != '_')
- {
- buf[j] = str[i];
- j++;
- }
- }
- return err;
- }
- #ifdef AWCCS
- int CsuCommAC_SHM_Rx_Update()
- {
- int gun_index=0;
-
- ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus=Check_V2G_Flow_Status();
- ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.ChargeProgress;
- ShmCharger->gun_info[gun_index].acCcsInfo.CpSetPWMDuty=ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].CpDuty;
-
-
- ShmInternalComm->ChargingPermission_new=ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission;
- if (ShmInternalComm->ChargingPermission_new != ShmInternalComm->ChargingPermission)
- {
- sprintf(buf_log_csucomm, "Permission: %d >> %d",
- ShmInternalComm->ChargingPermission,
- ShmInternalComm->ChargingPermission_new
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->ChargingPermission_pre = ShmInternalComm->ChargingPermission;
- ShmInternalComm->ChargingPermission = ShmInternalComm->ChargingPermission_new;
- }
- #if 1
-
- ShmInternalComm->AC_CpPresentPWMDuty = ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current;
- if (ShmInternalComm->AC_CpPresentPWMDuty_pre != ShmInternalComm->AC_CpPresentPWMDuty)
- {
- sprintf(buf_log_csucomm, "CP Duty(real): %d >> %d (1\%)",
- ShmInternalComm->AC_CpPresentPWMDuty_pre,
- ShmInternalComm->AC_CpPresentPWMDuty
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_CpPresentPWMDuty_pre = ShmInternalComm->AC_CpPresentPWMDuty;
- }
- #endif
-
-
-
- ShmInternalComm->AC_CpPresentState=ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState;
- if (ShmInternalComm->AC_CpPresentState_pre != ShmInternalComm->AC_CpPresentState)
- {
- sprintf(buf_log_csucomm, "CP State: %d >> %d",
- ShmInternalComm->AC_CpPresentState_pre,
- ShmInternalComm->AC_CpPresentState
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_CpPresentState_pre = ShmInternalComm->AC_CpPresentState;
- }
- #if 0
-
- ShmInternalComm->AC_ChargingRemainTime = CSUCOMMAC_SHM.ChargingRemainTime;
- if (ShmInternalComm->AC_ChargingRemainTime_pre != ShmInternalComm->AC_ChargingRemainTime)
- {
- sprintf(buf_log_csucomm, "ChargingRemainTime: %d >> %d (1 sec)",
- ShmInternalComm->AC_ChargingRemainTime_pre,
- ShmInternalComm->AC_ChargingRemainTime
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_ChargingRemainTime_pre = ShmInternalComm->AC_ChargingRemainTime;
- }
- #endif
-
-
- ShmInternalComm->AC_CSUAlarmStatusCode = ShmCharger->gun_info[gun_index].acCcsInfo.CSUAlarmStatusCode;
- if (ShmInternalComm->AC_CSUAlarmStatusCode_pre != ShmInternalComm->AC_CSUAlarmStatusCode)
- {
- sprintf(buf_log_csucomm, "CSUAlarmStatusCode: %X >> %X (1V)",
- ShmInternalComm->AC_CSUAlarmStatusCode_pre,
- ShmInternalComm->AC_CSUAlarmStatusCode
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_CSUAlarmStatusCode_pre = ShmInternalComm->AC_CSUAlarmStatusCode;
- }
-
-
- ShmInternalComm->AC_MeterReadingValue=((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10.0);
-
-
-
- ShmInternalComm->AC_CpPositiveVoltage=ShmCharger->gun_info[gun_index].acCcsInfo.CpPositiveVoltage;
-
- if (abs(ShmInternalComm->AC_CpPositiveVoltage_pre - ShmInternalComm->AC_CpPositiveVoltage)>=0.5)
- {
- sprintf(buf_log_csucomm, "CP_P_V: %.02f >> %.02f (1V)",
- ShmInternalComm->AC_CpPositiveVoltage_pre,
- ShmInternalComm->AC_CpPositiveVoltage
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_CpPositiveVoltage_pre = ShmInternalComm->AC_CpPositiveVoltage;
- }
-
-
- ShmInternalComm->AC_CpNegativeVoltage = ShmCharger->gun_info[gun_index].acCcsInfo.CpNegativeVoltage;
- if (abs(ShmInternalComm->AC_CpNegativeVoltage_pre - ShmInternalComm->AC_CpNegativeVoltage>=0.5))
- {
- sprintf(buf_log_csucomm, "CP_N_V: - %.02f >> - %.02f (1V)",
- ShmInternalComm->AC_CpNegativeVoltage_pre,
- ShmInternalComm->AC_CpNegativeVoltage
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_CpNegativeVoltage_pre = ShmInternalComm->AC_CpNegativeVoltage;
- }
-
-
-
-
- EVCOMM_SYS_INFO.PresentChargingCurrent = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- ShmInternalComm->PresentChargingCurrent = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0] * 10;
- ShmInternalComm->AC_EVSEPresentCurrent[0] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- ShmInternalComm->AC_EVSEPresentCurrent[1] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
- ShmInternalComm->AC_EVSEPresentCurrent[2] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
- if ((ShmInternalComm->AC_EVSEPresentCurrent[0] != ShmInternalComm->AC_EVSEPresentCurrent[0]) ||
- (ShmInternalComm->AC_EVSEPresentCurrent[1] != ShmInternalComm->AC_EVSEPresentCurrent[1]) ||
- (ShmInternalComm->AC_EVSEPresentCurrent[2] != ShmInternalComm->AC_EVSEPresentCurrent[2])
- )
- {
- if ((abs(ShmInternalComm->AC_EVSEPresentCurrent_pre[0] - ShmInternalComm->AC_EVSEPresentCurrent[0]) > 10) ||
- (abs(ShmInternalComm->AC_EVSEPresentCurrent_pre[1] - ShmInternalComm->AC_EVSEPresentCurrent[1]) > 10) ||
- (abs(ShmInternalComm->AC_EVSEPresentCurrent_pre[2] - ShmInternalComm->AC_EVSEPresentCurrent[2]) > 10)
- )
- {
- sprintf(buf_log_csucomm, "I_now(EVSE): (%.02f,%.02f,%.02f) >> (%.02f,%.02f,%.02f) (1A)",
- ShmInternalComm->AC_EVSEPresentCurrent_pre[0],
- ShmInternalComm->AC_EVSEPresentCurrent_pre[1],
- ShmInternalComm->AC_EVSEPresentCurrent_pre[2],
- ShmInternalComm->AC_EVSEPresentCurrent[0],
- ShmInternalComm->AC_EVSEPresentCurrent[1],
- ShmInternalComm->AC_EVSEPresentCurrent[2]
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- ShmInternalComm->PresentChargingCurrent_pre = ShmInternalComm->PresentChargingCurrent;
- memcpy(ShmInternalComm->AC_EVSEPresentCurrent_pre, ShmInternalComm->AC_EVSEPresentCurrent, sizeof(ShmInternalComm->AC_EVSEPresentCurrent));
- }
-
-
- ShmInternalComm->AC_OutputRelayStatus= ShmCharger->gun_info[gun_index].acCcsInfo.OutputRelayStatus;
- if (ShmInternalComm->AC_OutputRelayStatus_pre != ShmInternalComm->AC_OutputRelayStatus)
- {
- sprintf(buf_log_csucomm, "RelayON: %d >> %d",
- ShmInternalComm->AC_OutputRelayStatus_pre,
- ShmInternalComm->AC_OutputRelayStatus
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_OutputRelayStatus_pre = ShmInternalComm->AC_OutputRelayStatus;
- }
-
-
-
-
- EVCOMM_SYS_INFO.AC_EVSENominalVoltage = ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[0] ;
- ShmInternalComm->AC_GridVoltage[0]=ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[0];
- ShmInternalComm->AC_GridVoltage[1]=ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[1] ;
- ShmInternalComm->AC_GridVoltage[2]=ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[2] ;
- if ((abs(ShmInternalComm->AC_GridVoltage_pre[0] - ShmInternalComm->AC_GridVoltage[0])>=10) ||
- (abs(ShmInternalComm->AC_GridVoltage_pre[0] - ShmInternalComm->AC_GridVoltage[0])>=10) ||
- (abs(ShmInternalComm->AC_GridVoltage_pre[0] - ShmInternalComm->AC_GridVoltage[0])>=10)
- )
- {
- sprintf(buf_log_csucomm, "V_grid: (%.02f,%.02f,%.02f) >> (%.02f,%.02f,%.02f) (1V)",
- ShmInternalComm->AC_GridVoltage_pre[0],
- ShmInternalComm->AC_GridVoltage_pre[1],
- ShmInternalComm->AC_GridVoltage_pre[2],
- ShmInternalComm->AC_GridVoltage[0],
- ShmInternalComm->AC_GridVoltage[1],
- ShmInternalComm->AC_GridVoltage[2]
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- memcpy(ShmInternalComm->AC_GridVoltage_pre, ShmInternalComm->AC_GridVoltage, sizeof(ShmInternalComm->AC_GridVoltage));
- }
-
- if (ShmInternalComm->AC_OutputRelayStatus == ENABLE)
- {
- EVCOMM_SYS_INFO.PresentChargingVoltage = ShmInternalComm->AC_GridVoltage[0];
- ShmInternalComm->PresentChargingVoltage = (int)(ShmInternalComm->AC_GridVoltage[0] * 10);
- }
- else
- {
- EVCOMM_SYS_INFO.PresentChargingVoltage = 0;
- ShmInternalComm->PresentChargingVoltage = 0;
- }
-
- if (ShmInternalComm->PresentChargingVoltage_pre != ShmInternalComm->PresentChargingVoltage)
- {
- if (abs(ShmInternalComm->PresentChargingVoltage_pre - ShmInternalComm->PresentChargingVoltage) >= 10)
- {
- sprintf(buf_log_csucomm, "V_now(EVSE): %d >> %d (0.1V, DEC)",
- ShmInternalComm->PresentChargingVoltage_pre,
- ShmInternalComm->PresentChargingVoltage
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- }
- ShmInternalComm->PresentChargingVoltage_pre = ShmInternalComm->PresentChargingVoltage;
- }
-
- EVCOMM_SYS_INFO.PresentChargingPower = (EVCOMM_SYS_INFO.PresentChargingVoltage * EVCOMM_SYS_INFO.PresentChargingCurrent)/1000;
- ShmInternalComm->PresentChargingPower = (int)(EVCOMM_SYS_INFO.PresentChargingPower * 10);
- if (ShmInternalComm->PresentChargingPower_pre != ShmInternalComm->PresentChargingPower)
- {
- sprintf(buf_log_csucomm, "P_now(EVSE): %d >> %d (0.1KW)",
- ShmInternalComm->PresentChargingPower_pre,
- ShmInternalComm->PresentChargingPower);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->PresentChargingPower_pre = ShmInternalComm->PresentChargingPower;
- }
-
-
-
- EVCOMM_SYS_INFO.AvailableChargingCurrent = ShmCharger->gun_info[gun_index].targetCurrent;;
- ShmInternalComm->AvailableChargingCurrent = (int)(ShmCharger->gun_info[gun_index].targetCurrent*10);
- ShmInternalComm->AC_EVSEMaxCurrent=ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
- if (ShmInternalComm->AvailableChargingCurrent_pre != ShmInternalComm->AvailableChargingCurrent)
- {
- sprintf(buf_log_csucomm, "I_max(EVSE): %d >> %d (0.1A)",
- ShmInternalComm->AvailableChargingCurrent_pre,
- ShmInternalComm->AvailableChargingCurrent);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AvailableChargingCurrent_pre = ShmInternalComm->AvailableChargingCurrent;
- }
- #if 0
-
- ShmInternalComm->AC_EVSEMinCurrent = CSUCOMMAC_SHM.EVSEMinCurrent;
- if (ShmInternalComm->AC_EVSEMinCurrent_pre != ShmInternalComm->AC_EVSEMinCurrent)
- {
- sprintf(buf_log_csucomm, "I_min(EVSE): %.02f >> %.02f (1A)",
- ShmInternalComm->AC_EVSEMinCurrent_pre,
- ShmInternalComm->AC_EVSEMinCurrent);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_EVSEMinCurrent_pre = ShmInternalComm->AC_EVSEMinCurrent;
- }
-
-
-
-
- EVCOMM_SYS_INFO.MaximumChargingVoltage =ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[0];
- ShmInternalComm->MaximumChargingVoltage = (int)(ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[0]* 10);
- if (ShmInternalComm->MaximumChargingVoltage_pre != ShmInternalComm->MaximumChargingVoltage)
- {
- sprintf(buf_log_csucomm, "V_max(EVSE): %d >> %d (0.1V, DEC)",
- ShmInternalComm->MaximumChargingVoltage_pre,
- ShmInternalComm->MaximumChargingVoltage
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->MaximumChargingVoltage_pre = ShmInternalComm->MaximumChargingVoltage;
- }
-
-
- ShmInternalComm->AC_AvailableChargingPower = CSUCOMMAC_SHM.AvailableChargingPower;
- EVCOMM_SYS_INFO.AvailableChargingPower = ShmInternalComm->AC_AvailableChargingPower;
- ShmInternalComm->AvailableChargingPower = (int)(ShmInternalComm->AC_AvailableChargingPower * 10);
- if (ShmInternalComm->AvailableChargingPower_pre != ShmInternalComm->AvailableChargingPower)
- {
- sprintf(buf_log_csucomm, "P_max(EVSE): %d >> %d (0.1KW)",
- ShmInternalComm->AvailableChargingPower_pre,
- ShmInternalComm->AvailableChargingPower);
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AvailableChargingPower_pre = ShmInternalComm->AvailableChargingPower;
- }
-
-
- memcpy(ShmInternalComm->AC_EVSEID, CSUCOMMAC_SHM.EVSEID, 40);
- if (Array_Compare_Identity(ShmInternalComm->AC_EVSEID, CSUCOMMAC_SHM.EVSEID, 40) == FALSE)
- {
- sprintf(buf_log_csucomm, "EVSEID: [%02X %02X %02X %02X %02X %02X...] >> [%02X %02X %02X %02X %02X %02X...]",
- ShmInternalComm->AC_EVSEID_pre[0],
- ShmInternalComm->AC_EVSEID_pre[1],
- ShmInternalComm->AC_EVSEID_pre[2],
- ShmInternalComm->AC_EVSEID_pre[3],
- ShmInternalComm->AC_EVSEID_pre[4],
- ShmInternalComm->AC_EVSEID_pre[5],
- ShmInternalComm->AC_EVSEID[0],
- ShmInternalComm->AC_EVSEID[1],
- ShmInternalComm->AC_EVSEID[2],
- ShmInternalComm->AC_EVSEID[3],
- ShmInternalComm->AC_EVSEID[4],
- ShmInternalComm->AC_EVSEID[5]
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- memcpy(ShmInternalComm->AC_EVSEID_pre, ShmInternalComm->AC_EVSEID, 40);
- }
- #endif
-
-
- if(strlen(ShmInternalComm->AC_MeterID)<=1)
- {
-
- memset(ShmInternalComm->AC_MeterID, 0, sizeof(ShmInternalComm->AC_MeterID));
- sprintf(ShmInternalComm->AC_MeterID,"%s_%s",ShmCharger->evseId.model_name,ShmCharger->evseId.serial_number);
-
- }
-
- if(strlen(ShmInternalComm->AC_EVSEModelName)<=1)
- {
-
- memset(ShmInternalComm->AC_EVSEModelName, 0, sizeof(ShmInternalComm->AC_EVSEModelName));
- strcpy(ShmInternalComm->AC_EVSEModelName,ShmCharger->evseId.model_name);
-
- }
- #if 0
-
- ShmInternalComm->AC_BatteryChargeType = CSUCOMMAC_SHM.BatteryChargeType;
- if (ShmInternalComm->AC_BatteryChargeType_pre != ShmInternalComm->AC_BatteryChargeType)
- {
- sprintf(buf_log_csucomm, "BatteryChargeType: %d >> %d",
- ShmInternalComm->AC_BatteryChargeType_pre,
- ShmInternalComm->AC_BatteryChargeType
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_BatteryChargeType_pre = ShmInternalComm->AC_BatteryChargeType;
- }
- #endif
-
-
- ShmInternalComm->AC_RcdStatus=ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage;
- if (ShmInternalComm->AC_RcdStatus_pre != ShmInternalComm->AC_RcdStatus)
- {
- sprintf(buf_log_csucomm, "RCDStatus: %d >> %d",
- ShmInternalComm->AC_RcdStatus_pre,
- ShmInternalComm->AC_RcdStatus
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_RcdStatus_pre = ShmInternalComm->AC_RcdStatus;
- }
- #if 0
-
- ShmInternalComm->AC_EVSENotification = CSUCOMMAC_SHM.EVSENotification;
- if (ShmInternalComm->AC_EVSENotification_pre != ShmInternalComm->AC_EVSENotification)
- {
- sprintf(buf_log_csucomm, "AC_EVSENotification: %d >> %d",
- ShmInternalComm->AC_EVSENotification_pre,
- ShmInternalComm->AC_EVSENotification
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- ShmInternalComm->AC_EVSENotification_pre = ShmInternalComm->AC_EVSENotification;
- }
- #endif
- }
- #endif
- #ifdef AWCCS
- int CsuCommAC_Proc()
- {
-
-
- while(1)
- {
- CsuCommAC_SHM_Rx_Update();
- usleep(100000);
- }
- }
- #endif
- void CheckID()
- {
- unsigned char BoardId;
- unsigned char buf[64];
-
- BoardId=(Get_GPIO_Value(GPIO_2_23_AM_IO_1) + 1) & 0x000000FF;
- if(ShmInternalComm->SlaveAddress == BoardId)
- return;
-
- memset(buf,0,sizeof(buf));
- sprintf(buf,"SlaveAddress from %d to %d\n",ShmInternalComm->SlaveAddress,BoardId);
- ShmInternalComm->SlaveAddress = BoardId;
- SAVE_SYS_LOG_MSG_CSUCOMM(buf);
- CSUCOMMDC_TASK_FLAG.matched = TRUE;
-
-
- #if (DYNAMIC_ETH0_IP_MECHANISM == ENABLE)
- Eth0_PortSetting_Add(ShmInternalComm->SlaveAddress);
- #endif
- }
- int main(int argc, char *argv[])
- {
-
- if(ShareMemory_Init() == 0)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("[main]ShareMemory_Init NG");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- return 0;
- }
- #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
- {
- sprintf(buf_log_csucomm,
- "========= CCS: AC (%d)=========",
- CCS_ENERGY_TRANSFER_MODE
- );
- SAVE_SYS_LOG_MSG_CSUCOMM(buf_log_csucomm);
- CsuCommAC_Proc();
-
- while (1)
- {
-
- }
- }
- #endif
- int FD_CAN_Socket;
- struct can_frame frame;
- unsigned int value_random;
- unsigned char can_tx_payload[8];
-
- FD_CAN_Socket = CANBus_Init();
- ShmInternalComm->FD_CAN_Socket = FD_CAN_Socket;
- PID_CAN_Rx_Task = 0;
- ShmInternalComm->SlaveAddress = 0xFF;
- CSUCOMMDC_TASK_FLAG.matched = FALSE;
-
- Sniffer_Candump(ENABLE);
- Error_Monitor_CsuComm();
- #if 0
- ftime(&ShmInternalComm->Start_Time);
- srandom(ShmInternalComm->Start_Time.millitm);
- value_random = random();
- value_random &= 0xFFFFFF00;
- value_random |= 0x000000CC;
-
- while(ShmInternalComm->SlaveAddress == 0xFF)
- {
- ftime(&ShmInternalComm->Start_Time);
-
-
-
-
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][main] value_random = %08X (4 Bytes, HEX)\n", value_random);
- memset(can_tx_payload, 0, sizeof(can_tx_payload));
- memcpy(can_tx_payload, &value_random, sizeof(int));
-
- #if (CAN_RAMDOM_MATCHING_ID_MECHANISM == DISABLE)
- value_random = 0xC3B2A1CC;
- memset(can_tx_payload, 0, sizeof(can_tx_payload));
- memcpy(can_tx_payload, &value_random, sizeof(int));
-
-
-
-
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][main] replaced random number = %02X %02X %02X %02X (4 Bytes, HEX)\n",
- can_tx_payload[0],
- can_tx_payload[1],
- can_tx_payload[2],
- can_tx_payload[3],
- can_tx_payload[4]);
- #endif
- can_tx_payload[4] = Get_GPIO_Value(GPIO_2_23_AM_IO_1) + 1;
-
-
-
- CAN_Tx_MSG(FD_CAN_Socket, CAN_CMD_ADDRESS_REQUEST, ShmInternalComm->SlaveAddress, 5, can_tx_payload);
- ftime(&ShmInternalComm->End_Time);
-
- while(DiffTimeb(ShmInternalComm->Start_Time, ShmInternalComm->End_Time) < 1000)
- {
- unsigned int value_random_return = 0;
-
- memset(&frame, 0, sizeof(struct can_frame));
- read(FD_CAN_Socket, &frame, sizeof(struct can_frame));
- ftime(&ShmInternalComm->End_Time);
- PRINT_CAN_FRAME(&frame);
- if( (frame.can_id == 0) ||
- (frame.can_id & 0x08000000) ||
- ((frame.can_id & 0x0000FF00) != CAN_CMD_ADDRESS_ASSIGN) ||
- (frame.can_dlc != 5))
- {
- continue;
- }
- memcpy(&value_random_return, frame.data, sizeof(int));
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][main] ori = %X, return = %X (HEX)\n", value_random, value_random_return);
- if(value_random_return == value_random)
- {
-
- ShmInternalComm->SlaveAddress = frame.can_id & 0x000000FF;
- CSUCOMMDC_TASK_FLAG.matched = TRUE;
- #if (SAVE_SYS_LOG_MSG_CSUCOMM_SWITCH == ENABLE)
- {
- SAVE_SYS_LOG_MSG_CSUCOMM("Matched");
- }
- #endif
- DEBUG_PRINTF_CSUCOMM_DETAIL("[CsuComm][main] ShmInternalComm->SlaveAddres = %02X (1 Byte, HEX)\t(Matched NOW.)\n", ShmInternalComm->SlaveAddress);
-
- #if (DYNAMIC_ETH0_IP_MECHANISM == ENABLE)
- Eth0_PortSetting_Add(ShmInternalComm->SlaveAddress);
- #endif
- break;
- }
- }
- }
- #else
- sleep(5);
- CheckID();
- #endif
-
- CAN_Rx(FD_CAN_Socket);
-
-
-
- ftime(&ShmInternalComm->Start_Time);
- while(1)
- {
-
-
- ftime(&ShmInternalComm->End_Time);
- if(DiffTimeb(ShmInternalComm->Start_Time, ShmInternalComm->End_Time) >= 1000)
- {
-
- CSUCOMMDC_TASK_FLAG.Send_EVBoardStatus = TRUE;
- CheckID();
- }
- if (CSUCOMMDC_TASK_FLAG.Send_EVBoardStatus == TRUE)
- {
-
- Proc_EVBoardStatusRes(FD_CAN_Socket);
- ftime(&ShmInternalComm->Start_Time);
- }
-
- if(CSUCOMMDC_TASK_FLAG.Got_FWVersionReq == TRUE)
- {
- Proc_GetFirmwareVersionRes(FD_CAN_Socket);
- }
-
- if(CSUCOMMDC_TASK_FLAG.Got_HWVersionReq == TRUE)
- {
- Proc_HardwareVersionRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_ChargingPermission == TRUE)
- {
- Proc_ChargingPermissionRes(FD_CAN_Socket);
- }
-
- if(CSUCOMMDC_TASK_FLAG.Got_EVSEOutputStatus == TRUE)
- {
- Proc_EVSEOutputStatusUpdateRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_EnergyCapacity == TRUE)
- {
- Proc_EVSECapacityUpdateRes(FD_CAN_Socket);
- }
-
- if(CSUCOMMDC_TASK_FLAG.Got_EVTargetReq == TRUE)
- {
- Proc_GetEVTargetRes(FD_CAN_Socket);
- }
-
- if(CSUCOMMDC_TASK_FLAG.Got_EVBatteryInfoReq == TRUE)
- {
- Proc_GetEVBatteryInfoRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Send_EVStopReq == TRUE)
- {
- Proc_EVStopRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_EVSEStopReq == TRUE)
- {
- Proc_EVSEStopRes(FD_CAN_Socket);
- }
-
- if(CSUCOMMDC_TASK_FLAG.Got_MiscellaneousInfoReq == TRUE)
- {
- Proc_GetMiscellaneousInfoRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_DownloadImageReq == TRUE)
- {
- Proc_DownloadImageRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_BlockTransferStartReq == TRUE)
- {
- Proc_BlockTransferStartRes(FD_CAN_Socket);
- }
-
- if(CSUCOMMDC_TASK_FLAG.Got_DataTransferReq == TRUE)
- {
- Proc_DataTransferRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_DownloadFinishReq == TRUE)
- {
- Proc_DownloadFinishRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_IsolationStatus == TRUE)
- {
- Proc_IsolationStatusAnnounceRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_CCSConnectorReq == TRUE)
- {
- Proc_CCSConnectorTypeSetRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_RTC == TRUE)
- {
- Proc_RTCSetRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_EVSE_Precharge_Info == TRUE)
- {
- Proc_EVSEPrechargeInfoUpdateRes(FD_CAN_Socket);
- }
-
- if (CSUCOMMDC_TASK_FLAG.Got_EVCCID_Req == TRUE)
- {
- Proc_EVCCIDRes(FD_CAN_Socket);
- }
- usleep(1000);
- }
- EndProcess:
- if(PID_CAN_Rx_Task > 0)
- {
- char Buf[32];
- memset(Buf, 0, 32);
- sprintf(Buf, "kill %d", PID_CAN_Rx_Task);
- system(Buf);
- }
- close(FD_CAN_Socket);
- system("/sbin/ip link set can0 down");
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- system("/sbin/ip link set can0 down");
- system("killall CsuComm");
- }
|