Module_EvComm.c 195 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004
  1. /*
  2. * Module_EvComm.c
  3. *
  4. * Created on: 2020年9月14日
  5. * Author: Wendell
  6. */
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <sys/ioctl.h>
  13. #include <sys/socket.h>
  14. #include <sys/ipc.h>
  15. #include <sys/shm.h>
  16. #include <sys/shm.h>
  17. #include <sys/mman.h>
  18. #include <linux/can.h>
  19. #include <linux/can/raw.h>
  20. #include <linux/wireless.h>
  21. #include <arpa/inet.h>
  22. #include <netinet/in.h>
  23. #include <unistd.h>
  24. #include <stdarg.h>
  25. #include <stdio.h> /*標準輸入輸出定義*/
  26. #include <stdlib.h> /*標準函數庫定義*/
  27. #include <unistd.h> /*Unix 標準函數定義*/
  28. #include <fcntl.h> /*檔控制定義*/
  29. #include <termios.h> /*PPSIX 終端控制定義*/
  30. #include <errno.h> /*錯誤號定義*/
  31. #include <errno.h>
  32. #include <string.h>
  33. #include <time.h>
  34. #include <ctype.h>
  35. #include <ifaddrs.h>
  36. #include <signal.h>
  37. #include <net/if_arp.h>
  38. #include "../../define.h"
  39. #include "Module_EvComm.h"
  40. #include "Config.h"
  41. #include "Common.h"
  42. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  43. ChargerInfoData *ShmChargerInfo;
  44. struct ChargingInfoData *chargingInfo[CONNECTOR_QUANTITY];
  45. struct PsuData *ShmPsuData;
  46. ChargingCapabilityResponseInfo ConnectorCapability[GENERAL_GUN_QUANTITY];
  47. RefundResponse ConnectorRefund[GENERAL_GUN_QUANTITY];
  48. PrepaymentResponseInfo ConnectorPrepayment[GENERAL_GUN_QUANTITY];
  49. PaymentFailResponse ConnectorPaymentFailReason[GENERAL_GUN_QUANTITY];
  50. char _ConnectorQRCode[GENERAL_GUN_QUANTITY][128];
  51. StationInfoData _stationInfo[GENERAL_GUN_QUANTITY];
  52. DeductResultInfoData _deductResult[GENERAL_GUN_QUANTITY];
  53. unsigned char _GunSystemStatus[GENERAL_GUN_QUANTITY];
  54. void ShowSocketData(struct PACKET_STRUCTURE *packet)
  55. {
  56. printf("se: %02X, id: %02X, op: %d, len: %3d, reg: %02X",
  57. packet->Header.se, packet->Header.id, packet->Header.op, packet->Header.len, packet->Payload.reg);
  58. if(packet->Header.len > 1)
  59. {
  60. printf(", Data:");
  61. for(int i = 0; i < packet->Header.len - 1; i++)
  62. {
  63. printf(" %02X", packet->Payload.data[i]);
  64. }
  65. }
  66. printf("\n");
  67. }
  68. void CheckEvRxCommMsg(struct PACKET_STRUCTURE *packet)
  69. {
  70. if(ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  71. {
  72. int regValCnt = 0, regBitCnt = 0;
  73. regValCnt = packet->Payload.reg / 32;
  74. regBitCnt = packet->Payload.reg % 32;
  75. if(((ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[regValCnt] & (1 << regBitCnt)) || ShmChargerInfo->Control.EvCommCtrl.MsgFlag.bits.RegDbg_All) &&
  76. ((ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal & (1 << packet->Header.id)) || ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal == 0))
  77. {
  78. int len = 0;
  79. char msg[1024];
  80. sprintf(msg, "Rx: SE: %02X, ID: %02X, OP: %d, Len: %3d, Reg: %02X",
  81. packet->Header.se, packet->Header.id, packet->Header.op, packet->Header.len, packet->Payload.reg);
  82. if(packet->Header.len > 1)
  83. {
  84. len = strlen(msg);
  85. sprintf(&msg[len], ", Data:");
  86. for(int i = 0; i < packet->Header.len - 1; i++)
  87. {
  88. len = strlen(msg);
  89. sprintf(&msg[len], " %02X", packet->Payload.data[i]);
  90. }
  91. }
  92. EvMsg_INFO("%s", msg);
  93. }
  94. }
  95. }
  96. void CheckTvRxCommMsg(struct PACKET_STRUCTURE *packet)
  97. {
  98. if(ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  99. {
  100. int regValCnt = 0, regBitCnt = 0;
  101. regValCnt = packet->Payload.reg / 32;
  102. regBitCnt = packet->Payload.reg % 32;
  103. if(((ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[regValCnt] & (1 << regBitCnt)) || ShmChargerInfo->Control.EvCommCtrl.MsgFlag.bits.RegDbg_All) &&
  104. ((ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal & (1 << packet->Header.id)) || ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal == 0))
  105. {
  106. int len = 0;
  107. char msg[1024];
  108. sprintf(msg, "Tx: SE: %02X, ID: %02X, OP: %d, Len: %d, Reg: %02X",
  109. packet->Header.se, packet->Header.id, packet->Header.op, packet->Header.len, packet->Payload.reg);
  110. if(packet->Header.len > 1)
  111. {
  112. len = strlen(msg);
  113. sprintf(&msg[len], ", Data:");
  114. for(int i = 0; i < packet->Header.len - 1; i++)
  115. {
  116. len = strlen(msg);
  117. sprintf(&msg[len], " %02X", packet->Payload.data[i]);
  118. }
  119. }
  120. EvMsg_INFO("%s", msg);
  121. }
  122. }
  123. }
  124. //==========================================
  125. // Init all share memory
  126. //==========================================
  127. int InitShareMemory()
  128. {
  129. int result = PASS;
  130. int MeterSMId;
  131. //creat ShmSysConfigAndInfo
  132. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  133. {
  134. #ifdef SystemLogMessage
  135. LOG_ERROR("shmget ShmSysConfigAndInfo NG");
  136. #endif
  137. result = FAIL;
  138. }
  139. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  140. {
  141. #ifdef SystemLogMessage
  142. LOG_ERROR("shmat ShmSysConfigAndInfo NG");
  143. #endif
  144. result = FAIL;
  145. }
  146. else
  147. {
  148. }
  149. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), 0777)) < 0)
  150. {
  151. #ifdef SystemLogMessage
  152. LOG_ERROR("shmat ChargerInfoData NG");
  153. #endif
  154. result = FAIL;
  155. }
  156. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  157. {
  158. #ifdef SystemLogMessage
  159. LOG_ERROR("shmat ChargerInfoData NG");
  160. #endif
  161. result = FAIL;
  162. }
  163. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  164. {
  165. #ifdef SystemLogMessage
  166. LOG_ERROR("shmget ShmPsuData NG");
  167. #endif
  168. result = FAIL;
  169. }
  170. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  171. {
  172. #ifdef SystemLogMessage
  173. LOG_ERROR("shmat ShmPsuData NG");
  174. #endif
  175. result = FAIL;
  176. }
  177. return result;
  178. }
  179. //-------------------------------------------Socket Client Start-------------------------------------------
  180. unsigned char seqNum = 0;
  181. void sendCmdDispenserModelName(int socket, unsigned char se)
  182. {
  183. struct PACKET_STRUCTURE sendBuffer;
  184. char *modelName = "DSYE601J0EW2PH";
  185. //char *modelName = "DSYE601J00W2PH";
  186. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  187. sendBuffer.Header.se = se;
  188. sendBuffer.Header.id = 0xFF;
  189. sendBuffer.Header.op = _Header_Write;
  190. sendBuffer.Header.len = strlen(modelName) + 2;
  191. sendBuffer.Payload.reg = _Reg_Dispenser_Model_Name;
  192. memcpy(&sendBuffer.Payload.data[0], modelName, strlen(modelName));
  193. sendBuffer.Payload.data[strlen(modelName)] = 1;
  194. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  195. }
  196. void sendCmdDispenserConnectorIDRequest(int socket, unsigned char se)
  197. {
  198. struct PACKET_STRUCTURE sendBuffer;
  199. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  200. sendBuffer.Header.se = se;
  201. sendBuffer.Header.id = 0xFF;
  202. sendBuffer.Header.op = _Header_Read;
  203. sendBuffer.Header.len = 1;
  204. sendBuffer.Payload.reg = _Reg_Connector_ID;
  205. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  206. }
  207. void sendCmdPowerCabinetStatusRequest(int socket, unsigned char connector, unsigned char se)
  208. {
  209. struct PACKET_STRUCTURE sendBuffer;
  210. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  211. sendBuffer.Header.se = se;
  212. sendBuffer.Header.id = connector;
  213. sendBuffer.Header.op = _Header_Read;
  214. sendBuffer.Header.len = 1;
  215. sendBuffer.Payload.reg = _Reg_Power_Cabinet_Status;
  216. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  217. }
  218. void sendCmdWriteDispenserStatus(int socket, unsigned char connector, unsigned char se)
  219. {
  220. struct PACKET_STRUCTURE sendBuffer;
  221. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  222. sendBuffer.Header.se = se;
  223. sendBuffer.Header.id = connector;
  224. sendBuffer.Header.op = _Header_Write;
  225. sendBuffer.Header.len = 1;
  226. sendBuffer.Payload.reg = _Reg_Dispenser_Status;
  227. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  228. }
  229. void sendCmdReadChargingCapability(int socket, unsigned char connector, unsigned char se)
  230. {
  231. struct PACKET_STRUCTURE sendBuffer;
  232. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  233. sendBuffer.Header.se = se;
  234. sendBuffer.Header.id = connector;
  235. sendBuffer.Header.op = _Header_Read;
  236. sendBuffer.Header.len = 1;
  237. sendBuffer.Payload.reg = _Reg_Charging_Capability;
  238. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  239. }
  240. void sendCmdWriteChargingTarget(int socket, unsigned char connector, unsigned char se, unsigned short voltage, unsigned short current)
  241. {
  242. struct PACKET_STRUCTURE sendBuffer;
  243. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  244. sendBuffer.Header.se = se;
  245. sendBuffer.Header.id = connector;
  246. sendBuffer.Header.op = _Header_Write;
  247. sendBuffer.Header.len = 5;
  248. sendBuffer.Payload.reg = _Reg_Charging_Target;
  249. sendBuffer.Payload.data[0] = (voltage >> 8) & 0xFF;
  250. sendBuffer.Payload.data[1] = voltage & 0xFF;
  251. sendBuffer.Payload.data[2] = (current >> 8) & 0xFF;
  252. sendBuffer.Payload.data[3] = current & 0xFF;
  253. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  254. }
  255. void sendCmdWritePlugInStatus(int socket, unsigned char connector, unsigned char se)
  256. {
  257. struct PACKET_STRUCTURE sendBuffer;
  258. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  259. sendBuffer.Header.se = se;
  260. sendBuffer.Header.id = connector;
  261. sendBuffer.Header.op = _Header_Write;
  262. sendBuffer.Header.len = 2;
  263. sendBuffer.Payload.reg = _Reg_Plug_In_Status;
  264. sendBuffer.Payload.data[0] = se % 2 == 0 ?_PIS_UnPlugged : _PIS_PluggedIn;
  265. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  266. }
  267. void sendCmdWriteConnectorState(int socket, unsigned char connector, unsigned char se)
  268. {
  269. struct PACKET_STRUCTURE sendBuffer;
  270. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  271. sendBuffer.Header.se = se;
  272. sendBuffer.Header.id = connector;
  273. sendBuffer.Header.op = _Header_Write;
  274. sendBuffer.Header.len = 2;
  275. sendBuffer.Payload.reg = _Reg_Connector_State;
  276. sendBuffer.Payload.data[0] = _CRS_Idle;
  277. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  278. }
  279. void sendCmdWriteUserID(int socket, unsigned char connector, unsigned char se)
  280. {
  281. struct PACKET_STRUCTURE sendBuffer;
  282. char *userID = "010203040506";
  283. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  284. sendBuffer.Header.se = se;
  285. sendBuffer.Header.id = connector;
  286. sendBuffer.Header.op = _Header_Write;
  287. sendBuffer.Header.len = strlen(userID) + 1;
  288. sendBuffer.Payload.reg = _Reg_User_ID;
  289. memcpy(sendBuffer.Payload.data, userID, strlen(userID));
  290. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  291. }
  292. void sendCmdReadChargingPermission(int socket, unsigned char connector, unsigned char se)
  293. {
  294. struct PACKET_STRUCTURE sendBuffer;
  295. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  296. sendBuffer.Header.se = se;
  297. sendBuffer.Header.id = connector;
  298. sendBuffer.Header.op = _Header_Read;
  299. sendBuffer.Header.len = 1;
  300. sendBuffer.Payload.reg = _Reg_Charging_Permission;
  301. send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
  302. }
  303. int DispenserModelNameCheckIn(int socket, unsigned char se)
  304. {
  305. int rxLen = 0, timeout = 0;
  306. struct PACKET_STRUCTURE receiveBuffer;
  307. int result = FAIL;
  308. sendCmdDispenserModelName(socket, se);
  309. while(1)
  310. {
  311. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  312. {
  313. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  314. {
  315. ShowSocketData(&receiveBuffer);
  316. if(receiveBuffer.Header.len == 2)
  317. {
  318. if(receiveBuffer.Payload.reg == _Reg_Dispenser_Model_Name && receiveBuffer.Payload.data[0] == _R_OK)
  319. {
  320. LOG_INFO("Write Model Name OK");
  321. result = PASS;
  322. break;
  323. }
  324. }
  325. }
  326. }
  327. timeout += SOCKET_RECEIVE_INTERVAL;
  328. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  329. if(timeout >= DISPENSER_MODEL_NAME_RESEND)
  330. {
  331. //timeout
  332. break;
  333. }
  334. }
  335. return result;
  336. }
  337. int DispenserConnectorRequest(int socket, unsigned char se)
  338. {
  339. int rxLen = 0, timeout = 0;
  340. struct PACKET_STRUCTURE receiveBuffer;
  341. int result = FAIL;
  342. sendCmdDispenserConnectorIDRequest(socket, se);
  343. while(1)
  344. {
  345. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  346. {
  347. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  348. {
  349. ShowSocketData(&receiveBuffer);
  350. if(receiveBuffer.Header.len == 4)
  351. {
  352. if(receiveBuffer.Payload.reg == _Reg_Connector_ID && receiveBuffer.Payload.data[0] == _R_OK)
  353. {
  354. LOG_INFO("Get Connector ID: %02X, %02X", receiveBuffer.Payload.data[1], receiveBuffer.Payload.data[2]);
  355. result = PASS;
  356. break;
  357. }
  358. }
  359. }
  360. }
  361. timeout += SOCKET_RECEIVE_INTERVAL;
  362. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  363. if(timeout >= DISPENSER_CONNECTOR_RESEND)
  364. {
  365. //timeout
  366. break;
  367. }
  368. }
  369. return result;
  370. }
  371. int DispenserReadPowerCabinetStatus(int socket, unsigned char connector, unsigned char se)
  372. {
  373. int rxLen = 0, timeout = 0;
  374. struct PACKET_STRUCTURE receiveBuffer;
  375. int result = FAIL;
  376. sendCmdPowerCabinetStatusRequest(socket, connector, se);
  377. while(1)
  378. {
  379. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  380. {
  381. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  382. {
  383. ShowSocketData(&receiveBuffer);
  384. if(receiveBuffer.Payload.reg == _Reg_Power_Cabinet_Status && receiveBuffer.Payload.data[0] == _R_OK)
  385. {
  386. LOG_INFO("Get Cabinet Status Code, Len: %d", (receiveBuffer.Header.len - 2) / 6);
  387. result = PASS;
  388. }
  389. }
  390. }
  391. timeout += SOCKET_RECEIVE_INTERVAL;
  392. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  393. if(timeout >= CABINET_STATUS_REQUEST_RESEND)
  394. {
  395. //timeout
  396. break;
  397. }
  398. }
  399. return result;
  400. }
  401. int DispenserWriteStatusCode(int socket, unsigned char connector, unsigned char se)
  402. {
  403. int rxLen = 0, timeout = 0;
  404. struct PACKET_STRUCTURE receiveBuffer;
  405. int result = FAIL;
  406. sendCmdWriteDispenserStatus(socket, connector, se);
  407. while(1)
  408. {
  409. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  410. {
  411. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  412. {
  413. ShowSocketData(&receiveBuffer);
  414. if(receiveBuffer.Header.len == 2)
  415. {
  416. if(receiveBuffer.Payload.reg == _Reg_Dispenser_Status && receiveBuffer.Payload.data[0] == _R_OK)
  417. {
  418. LOG_INFO("Write Dispenser Status Code OK");
  419. result = PASS;
  420. }
  421. }
  422. }
  423. }
  424. timeout += SOCKET_RECEIVE_INTERVAL;
  425. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  426. if(timeout >= CABINET_STATUS_REQUEST_RESEND)
  427. {
  428. //timeout
  429. break;
  430. }
  431. }
  432. return result;
  433. }
  434. int DispenserReadChargingCapability(int socket, unsigned char connector, unsigned char se)
  435. {
  436. int rxLen = 0, timeout = 0;
  437. struct PACKET_STRUCTURE receiveBuffer;
  438. int result = FAIL;
  439. unsigned short voltage = 0, current = 0, power = 0;
  440. sendCmdReadChargingCapability(socket, connector, se);
  441. while(1)
  442. {
  443. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  444. {
  445. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  446. {
  447. ShowSocketData(&receiveBuffer);
  448. if(receiveBuffer.Header.len == 8)
  449. {
  450. if(receiveBuffer.Payload.reg == _Reg_Charging_Capability && receiveBuffer.Payload.data[0] == _R_OK)
  451. {
  452. voltage = (receiveBuffer.Payload.data[1] << 8) + receiveBuffer.Payload.data[2];
  453. current = (receiveBuffer.Payload.data[3] << 8) + receiveBuffer.Payload.data[4];
  454. power = (receiveBuffer.Payload.data[5] << 8) + receiveBuffer.Payload.data[6];
  455. LOG_INFO("Capability Voltage: %d.%dV, Current: %d.%dA, Power: %d.%dkW",
  456. voltage / 10, voltage % 10, current / 10, current % 10, power / 10, power % 10);
  457. result = PASS;
  458. }
  459. }
  460. }
  461. }
  462. timeout += SOCKET_RECEIVE_INTERVAL;
  463. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  464. if(timeout >= CHARGING_CAPABILITY_RESEND)
  465. {
  466. //timeout
  467. break;
  468. }
  469. }
  470. return result;
  471. }
  472. int DispenserWriteChargingTarget(int socket, unsigned char connector, unsigned char se)
  473. {
  474. int rxLen = 0, timeout = 0;
  475. struct PACKET_STRUCTURE receiveBuffer;
  476. int result = FAIL;
  477. sendCmdWriteChargingTarget(socket, connector, se, 7505, 406);
  478. while(1)
  479. {
  480. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  481. {
  482. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  483. {
  484. ShowSocketData(&receiveBuffer);
  485. if(receiveBuffer.Header.len == 2)
  486. {
  487. if(receiveBuffer.Payload.reg == _Reg_Charging_Target && receiveBuffer.Payload.data[0] == _R_OK)
  488. {
  489. LOG_INFO("Write Charging Target OK");
  490. result = PASS;
  491. }
  492. }
  493. }
  494. }
  495. timeout += SOCKET_RECEIVE_INTERVAL;
  496. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  497. if(timeout >= CHARGING_CAPABILITY_RESEND)
  498. {
  499. //timeout
  500. break;
  501. }
  502. }
  503. return result;
  504. }
  505. int DispenserWritePlugInStatus(int socket, unsigned char connector, unsigned char se)
  506. {
  507. int rxLen = 0, timeout = 0;
  508. struct PACKET_STRUCTURE receiveBuffer;
  509. int result = FAIL;
  510. sendCmdWritePlugInStatus(socket, connector, se);
  511. while(1)
  512. {
  513. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  514. {
  515. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  516. {
  517. ShowSocketData(&receiveBuffer);
  518. if(receiveBuffer.Header.len == 2)
  519. {
  520. if(receiveBuffer.Payload.reg == _Reg_Plug_In_Status && receiveBuffer.Payload.data[0] == _R_OK)
  521. {
  522. LOG_INFO("Write Plug In Status OK");
  523. result = PASS;
  524. }
  525. }
  526. }
  527. }
  528. timeout += SOCKET_RECEIVE_INTERVAL;
  529. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  530. if(timeout >= CHARGING_CAPABILITY_RESEND)
  531. {
  532. //timeout
  533. break;
  534. }
  535. }
  536. return result;
  537. }
  538. int DispenserWriteConnectorState(int socket, unsigned char connector, unsigned char se)
  539. {
  540. int rxLen = 0, timeout = 0;
  541. struct PACKET_STRUCTURE receiveBuffer;
  542. int result = FAIL;
  543. sendCmdWriteConnectorState(socket, connector, se);
  544. while(1)
  545. {
  546. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  547. {
  548. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  549. {
  550. ShowSocketData(&receiveBuffer);
  551. if(receiveBuffer.Header.len == 2)
  552. {
  553. if(receiveBuffer.Payload.reg == _Reg_Connector_State && receiveBuffer.Payload.data[0] == _R_OK)
  554. {
  555. LOG_INFO("Write Connector State OK");
  556. result = PASS;
  557. }
  558. }
  559. }
  560. }
  561. timeout += SOCKET_RECEIVE_INTERVAL;
  562. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  563. if(timeout >= CHARGING_CAPABILITY_RESEND)
  564. {
  565. //timeout
  566. break;
  567. }
  568. }
  569. return result;
  570. }
  571. int DispenserWriteUserID(int socket, unsigned char connector, unsigned char se)
  572. {
  573. int rxLen = 0, timeout = 0;
  574. struct PACKET_STRUCTURE receiveBuffer;
  575. int result = FAIL;
  576. sendCmdWriteUserID(socket, connector, se);
  577. while(1)
  578. {
  579. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  580. {
  581. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  582. {
  583. ShowSocketData(&receiveBuffer);
  584. if(receiveBuffer.Header.len == 2)
  585. {
  586. if(receiveBuffer.Payload.reg == _Reg_User_ID && receiveBuffer.Payload.data[0] == _R_OK)
  587. {
  588. LOG_INFO("Write User ID OK");
  589. result = PASS;
  590. }
  591. }
  592. }
  593. }
  594. timeout += SOCKET_RECEIVE_INTERVAL;
  595. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  596. if(timeout >= CHARGING_CAPABILITY_RESEND)
  597. {
  598. //timeout
  599. break;
  600. }
  601. }
  602. return result;
  603. }
  604. int DispenserReadChargingPermission(int socket, unsigned char connector, unsigned char se)
  605. {
  606. int rxLen = 0, timeout = 0;
  607. struct PACKET_STRUCTURE receiveBuffer;
  608. int result = FAIL;
  609. sendCmdReadChargingPermission(socket, connector, se);
  610. while(1)
  611. {
  612. if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  613. {
  614. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  615. {
  616. ShowSocketData(&receiveBuffer);
  617. if(receiveBuffer.Header.len == 3)
  618. {
  619. if(receiveBuffer.Payload.reg == _Reg_Charging_Permission && receiveBuffer.Payload.data[0] == _R_OK)
  620. {
  621. LOG_INFO("Charging Permission: %s", receiveBuffer.Payload.data[1] == _PS_Permitted ? "Permitted" : "Not Permitted");
  622. result = PASS;
  623. }
  624. }
  625. }
  626. }
  627. timeout += SOCKET_RECEIVE_INTERVAL;
  628. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  629. if(timeout >= CHARGING_CAPABILITY_RESEND)
  630. {
  631. //timeout
  632. break;
  633. }
  634. }
  635. return result;
  636. }
  637. void tcpSocketClientStart(void)
  638. {
  639. struct sockaddr_in info;
  640. struct timeval tv;
  641. uint8_t socketEnable;
  642. int sockfd = 0;
  643. unsigned char clientStatus = 0;
  644. unsigned char se = 0;
  645. //start dhcp client
  646. //udhcpc -i eth1 --script /root/dhcp_script/eth1.script
  647. //udhcpc -i eth1 -s /root/dhcp_script/eth1.script &
  648. //udhcpc -i eth0 -x hostname CSU3_DSYE601J0EW2PH-SERIALFORRD -s /root/dhcp_script/eth0.script
  649. for(;;)
  650. {
  651. bzero(&info,sizeof(info));
  652. info.sin_family = PF_INET;
  653. info.sin_addr.s_addr = inet_addr(SOCKET_SERVER_IP);
  654. info.sin_port = htons(TCP_LISTEN_PORT);
  655. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  656. if (sockfd == -1)
  657. {
  658. LOG_INFO("Fail to create a socket.");
  659. return;
  660. }
  661. LOG_INFO("TCP Client Start");
  662. if(connect(sockfd, (struct sockaddr *)&info, sizeof(info)) == -1)
  663. {
  664. LOG_INFO("Connection error");
  665. }
  666. else
  667. {
  668. LOG_INFO("Connect to %s success", inet_ntoa(info.sin_addr));
  669. tv.tv_sec = 0;
  670. tv.tv_usec = 500000;
  671. setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
  672. socketEnable = ON;
  673. }
  674. while(socketEnable)
  675. {
  676. switch(clientStatus)
  677. {
  678. case 0:
  679. //5.1 Dispenser model name
  680. if(DispenserModelNameCheckIn(sockfd, se++) == PASS)
  681. {
  682. clientStatus = 1;
  683. }
  684. break;
  685. case 1:
  686. if(DispenserConnectorRequest(sockfd, se++) == PASS)
  687. {
  688. clientStatus = 2;
  689. }
  690. break;
  691. case 2:
  692. if(DispenserReadPowerCabinetStatus(sockfd, 0x01, se++) == PASS)
  693. {
  694. if(DispenserWriteStatusCode(sockfd, 0x01, se++) == PASS)
  695. {
  696. clientStatus = 3;
  697. }
  698. }
  699. break;
  700. case 3:
  701. if(DispenserWriteUserID(sockfd, 0x01, se++) == PASS)
  702. {
  703. clientStatus = 4;
  704. }
  705. break;
  706. case 4:
  707. if(DispenserReadChargingCapability(sockfd, 0x01, se++) == PASS)
  708. {
  709. }
  710. if(DispenserWriteChargingTarget(sockfd, 0x01, se++) == PASS)
  711. {
  712. }
  713. if(DispenserWritePlugInStatus(sockfd, 0x01, se++) == PASS)
  714. {
  715. }
  716. if(DispenserWriteConnectorState(sockfd, 0x01, se++) == PASS)
  717. {
  718. }
  719. if(DispenserReadChargingPermission(sockfd, 0x01, se++) == PASS)
  720. {
  721. }
  722. break;
  723. default:
  724. break;
  725. }
  726. }
  727. close(sockfd);
  728. sleep(5);
  729. return;
  730. }
  731. }
  732. //--------------------------------------------Socket Client End--------------------------------------------
  733. BOOL IsAvalibleGunType(char name, unsigned char *type)
  734. {
  735. // 20210817 remove type "R"
  736. char modelList[10] = {'J', 'U', 'V', 'E', 'F', 'G', 'T', 'D', 'K', 'P'};
  737. unsigned char typeList[10] = { 0, 1, 1, 1, 1, 2, 1, 1, 0, 1}; // 0 : Chademo, 1: CCS, 2: GB
  738. for(int i = 0; i < 11; i++)
  739. {
  740. if(name == modelList[i])
  741. {
  742. *type = typeList[i];
  743. return true;
  744. }
  745. }
  746. return false;
  747. }
  748. unsigned char ConnectorQuantityTypeParsing(unsigned char *modelName, unsigned char *type, unsigned char *physical, unsigned char *safety)
  749. {
  750. unsigned char quantity = 0;
  751. for(int i = 0; i < 3; i++)
  752. {
  753. if(IsAvalibleGunType(modelName[7 + i], &type[quantity]))
  754. {
  755. physical[quantity] = modelName[7 + i];
  756. if(quantity < 2)
  757. {
  758. quantity++;
  759. }
  760. else
  761. {
  762. quantity = 0;
  763. break;
  764. }
  765. }
  766. }
  767. *safety = modelName[3];
  768. return quantity;
  769. }
  770. void SendPacket(int socket, struct PACKET_STRUCTURE *packet)
  771. {
  772. //ShowSocketData(packet);
  773. send(socket, packet, packet->Header.len + 4, 0);
  774. CheckTvRxCommMsg(packet);
  775. }
  776. void ModelNameResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  777. {
  778. struct PACKET_STRUCTURE sendBuffer;
  779. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  780. sendBuffer.Header.se = packet->Header.se;
  781. sendBuffer.Header.id = 0xFF;
  782. sendBuffer.Header.op = _Header_Response;
  783. sendBuffer.Header.len = 2;
  784. sendBuffer.Payload.reg = _Reg_Dispenser_Model_Name;
  785. sendBuffer.Payload.data[0] = result;
  786. SendPacket(socket, &sendBuffer);
  787. }
  788. void ConnectorIDResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result, unsigned char dispenserIndex)
  789. {
  790. struct PACKET_STRUCTURE sendBuffer;
  791. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  792. sendBuffer.Header.se = packet->Header.se;
  793. sendBuffer.Header.id = 0xFF;
  794. sendBuffer.Header.op = _Header_Response;
  795. sendBuffer.Header.len = 4;
  796. sendBuffer.Payload.reg = _Reg_Connector_ID;
  797. sendBuffer.Payload.data[0] = result;
  798. sendBuffer.Payload.data[1] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0];
  799. sendBuffer.Payload.data[2] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[1];
  800. SendPacket(socket, &sendBuffer);
  801. }
  802. // more message for debug
  803. struct PACKET_STRUCTURE CabinetStatusToDispenser[4];
  804. void PowerCabinetStatusResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  805. {
  806. struct PACKET_STRUCTURE sendBuffer;
  807. unsigned char MiscEventCode[7];
  808. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  809. sendBuffer.Header.se = packet->Header.se;
  810. sendBuffer.Header.id = packet->Header.id;
  811. sendBuffer.Header.op = _Header_Response;
  812. sendBuffer.Header.len = 2;
  813. sendBuffer.Payload.reg = _Reg_Power_Cabinet_Status;
  814. sendBuffer.Payload.data[0] = _R_OK;
  815. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  816. {
  817. sendBuffer.Header.len += (ShmSysConfigAndInfo->SysWarningInfo.WarningCount * 6);
  818. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  819. {
  820. memcpy(&sendBuffer.Payload.data[1 + (i * 6)], &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 6);
  821. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] == '1')
  822. {
  823. sendBuffer.Payload.data[1 + (i * 6) + 1] = '4';
  824. }
  825. }
  826. }
  827. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.MiscNeedAnnouncement)
  828. {
  829. sendBuffer.Header.len += 6;
  830. memset(MiscEventCode, 0, sizeof(MiscEventCode));
  831. memcpy(MiscEventCode, "B40001", sizeof(MiscEventCode) - 1);
  832. memcpy(&sendBuffer.Payload.data[1 + (ShmSysConfigAndInfo->SysWarningInfo.WarningCount * 6)], &MiscEventCode[0], 6);
  833. }
  834. bool need_copy = false;
  835. if(sendBuffer.Header.len != CabinetStatusToDispenser[dispenserIndex].Header.len ||
  836. sendBuffer.Header.op != CabinetStatusToDispenser[dispenserIndex].Header.op ||
  837. sendBuffer.Payload.reg != CabinetStatusToDispenser[dispenserIndex].Payload.reg ||
  838. sendBuffer.Payload.data[0] != CabinetStatusToDispenser[dispenserIndex].Payload.data[0])
  839. {
  840. need_copy = true;
  841. }
  842. else
  843. {
  844. for(int i = 0; i < sendBuffer.Header.len - 2; i++)
  845. {
  846. if(sendBuffer.Payload.data[1 + i] != CabinetStatusToDispenser[dispenserIndex].Payload.data[1 + i])
  847. {
  848. need_copy = true;
  849. }
  850. }
  851. }
  852. if(need_copy)
  853. {
  854. char str[256];
  855. memcpy(&CabinetStatusToDispenser[dispenserIndex], &sendBuffer, sizeof(struct PACKET_STRUCTURE));
  856. if(CabinetStatusToDispenser[dispenserIndex].Header.len > 2)
  857. {
  858. sprintf(str, "Cabinet >> Dispenser %d Status Code:", dispenserIndex + 1);
  859. for(int i = 0; i < CabinetStatusToDispenser[dispenserIndex].Header.len - 2; i += 6)
  860. {
  861. char status[7];
  862. char temp[8];
  863. memset(status, 0x00, sizeof(status));
  864. memcpy(status, (char *)&CabinetStatusToDispenser[dispenserIndex].Payload.data[1 + i], 6);
  865. sprintf(temp, " %s", status);
  866. strcat(str, temp);
  867. }
  868. LOG_INFO("%s", str);
  869. }
  870. else
  871. {
  872. LOG_INFO("Cabinet >> Dispenser %d Status Code Clear", dispenserIndex + 1);
  873. }
  874. }
  875. SendPacket(socket, &sendBuffer);
  876. }
  877. void DispenserStatusResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  878. {
  879. struct PACKET_STRUCTURE sendBuffer;
  880. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  881. sendBuffer.Header.se = packet->Header.se;
  882. sendBuffer.Header.id = packet->Header.id;
  883. sendBuffer.Header.op = _Header_Response;
  884. sendBuffer.Header.len = 2;
  885. sendBuffer.Payload.reg = _Reg_Dispenser_Status;
  886. sendBuffer.Payload.data[0] = result;
  887. SendPacket(socket, &sendBuffer);
  888. }
  889. void RestrictAbsoluteLimit(int gunIndex, unsigned short *power, unsigned short *voltage, unsigned short *current)
  890. {
  891. unsigned short limitPower = 0;
  892. if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxPower[gunIndex] != 0)
  893. {
  894. limitPower = ShmChargerInfo->OutputLimit.GunAbsoluteMaxPower[gunIndex] / 100;
  895. if(limitPower != 0 && limitPower <= *power)
  896. {
  897. *power = limitPower;
  898. }
  899. }
  900. if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex] != 0 &&
  901. ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex] < *voltage)
  902. {
  903. *voltage = ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex];
  904. }
  905. if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex] != 0 &&
  906. ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex] < *current)
  907. {
  908. *current = ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex];
  909. }
  910. }
  911. void ChargingCapabilityResponse(int socket, struct PACKET_STRUCTURE *packet)
  912. {
  913. struct PACKET_STRUCTURE sendBuffer;
  914. unsigned short voltage = 0, current = 0, power = 0;
  915. unsigned char currency = 0;
  916. float fPrice = 0, fCost = 0, fBalance = 0, fDiscount = 0, fEnergyCost = 0, fParkingFee = 0, fRemainAmount = 0;
  917. unsigned int lPrice = 0, lCost = 0, lBalance = 0, lDiscount = 0;
  918. int transaction = 0;
  919. int energyCost = 0, parkingFee = 0, remainAmount = 0;
  920. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  921. voltage = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].CapabilityVoltage;
  922. current = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].CapabilityCurrent;
  923. power = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].CapabilityPower;
  924. currency = ShmChargerInfo->CabinetMiscValue.Currency;
  925. fPrice = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].UserPrice;
  926. fCost = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].TotalCost;
  927. fBalance = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].AccountBalance;
  928. transaction = ShmChargerInfo->UserTransaction[packet->Header.id - 1].TransactionId;
  929. fDiscount = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].CostDiscount;
  930. fEnergyCost = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].EnergyCost;
  931. fParkingFee = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].ParkingFee;
  932. fRemainAmount = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemainAmount;
  933. lPrice = (unsigned int)(fPrice * 100);
  934. lCost = (unsigned int)(fCost * 100);
  935. lBalance = (int)(fBalance * 100);
  936. lDiscount = (int)(fDiscount * 100);
  937. energyCost = fEnergyCost >= 0 ? (int)(fEnergyCost * 100) : -1;
  938. parkingFee = fParkingFee >= 0 ? (int)(fParkingFee * 100) : -1;
  939. remainAmount = fRemainAmount >= 0 ? (int)(fRemainAmount * 100) : -1;
  940. if((ConnectorCapability[packet->Header.id - 1].MaxOuputVoltage / 10) != (voltage / 10) ||
  941. (ConnectorCapability[packet->Header.id - 1].MaxOuputCurrent / 10) != (current / 10) ||
  942. (ConnectorCapability[packet->Header.id - 1].MaxOuputPower / 10) != (power / 10))
  943. {
  944. LOG_INFO("Gun %d Capability Voltage: %4d.%d V, Current: %3d.%d A, Power: %d kW", packet->Header.id,
  945. (voltage / 10), (voltage % 10), (current / 10), (current % 10), (power / 10));
  946. }
  947. if(ConnectorCapability[packet->Header.id - 1].Currency != currency)
  948. {
  949. memset(ConnectorCapability[packet->Header.id - 1].CurrencyString, 0x00, sizeof(ConnectorCapability[packet->Header.id - 1].CurrencyString));
  950. if(currency < 54)
  951. {
  952. memcpy(ConnectorCapability[packet->Header.id - 1].CurrencyString, (char *)&Currency[currency][0], 3);
  953. }
  954. else
  955. {
  956. LOG_INFO("Gun %d unknown currency: %d", packet->Header.id, (int)(currency));
  957. memcpy(ConnectorCapability[packet->Header.id - 1].CurrencyString, "???", 3);
  958. }
  959. }
  960. if(ConnectorCapability[packet->Header.id - 1].Currency != currency ||
  961. ConnectorCapability[packet->Header.id - 1].UserPrice != lPrice ||
  962. ConnectorCapability[packet->Header.id - 1].TotalCost != lCost ||
  963. ConnectorCapability[packet->Header.id - 1].TransactionId != transaction ||
  964. ConnectorCapability[packet->Header.id - 1].EnergyCost != energyCost ||
  965. ConnectorCapability[packet->Header.id - 1].ParkingFee != parkingFee)
  966. {
  967. LOG_INFO("Gun %d TxId: %d UserPrice: %6.2f, Cost: %.2f, EnergyCost: %.2f, ParkingFee: %.2f [%s]",
  968. packet->Header.id, transaction, fPrice, fCost, fEnergyCost, fParkingFee, ConnectorCapability[packet->Header.id - 1].CurrencyString);
  969. }
  970. if(ConnectorCapability[packet->Header.id - 1].AccountBalance != lBalance ||
  971. ConnectorCapability[packet->Header.id - 1].RemainAmount != remainAmount ||
  972. ConnectorCapability[packet->Header.id - 1].CostDiscount != lDiscount)
  973. {
  974. LOG_INFO("Gun %d TxId: %d Account: %8.2f, Remain: %8.2f, Discount: %.2f [%s]",
  975. packet->Header.id, transaction, fBalance, fDiscount, fRemainAmount, ConnectorCapability[packet->Header.id - 1].CurrencyString);
  976. }
  977. ConnectorCapability[packet->Header.id - 1].MaxOuputVoltage = voltage;
  978. ConnectorCapability[packet->Header.id - 1].MaxOuputCurrent = current;
  979. ConnectorCapability[packet->Header.id - 1].MaxOuputPower = power;
  980. ConnectorCapability[packet->Header.id - 1].Currency = currency;
  981. ConnectorCapability[packet->Header.id - 1].UserPrice = lPrice;
  982. ConnectorCapability[packet->Header.id - 1].TotalCost = lCost;
  983. ConnectorCapability[packet->Header.id - 1].AccountBalance = lBalance;
  984. ConnectorCapability[packet->Header.id - 1].CostDiscount = lDiscount;
  985. ConnectorCapability[packet->Header.id - 1].TransactionId = transaction;
  986. ConnectorCapability[packet->Header.id - 1].EnergyCost = energyCost;
  987. ConnectorCapability[packet->Header.id - 1].ParkingFee = parkingFee;
  988. ConnectorCapability[packet->Header.id - 1].RemainAmount = remainAmount;
  989. sendBuffer.Header.se = packet->Header.se;
  990. sendBuffer.Header.id = packet->Header.id;
  991. sendBuffer.Header.op = _Header_Response;
  992. sendBuffer.Header.len = 41;
  993. sendBuffer.Payload.reg = _Reg_Charging_Capability;
  994. sendBuffer.Payload.data[0] = _R_OK;
  995. sendBuffer.Payload.data[1] = ((voltage >> 8) & 0xFF);
  996. sendBuffer.Payload.data[2] = (voltage & 0xFF);
  997. sendBuffer.Payload.data[3] = ((current >> 8) & 0xFF);
  998. sendBuffer.Payload.data[4] = (current & 0xFF);
  999. sendBuffer.Payload.data[5] = ((power >> 8) & 0xFF);
  1000. sendBuffer.Payload.data[6] = (power & 0xFF);
  1001. sendBuffer.Payload.data[7] = currency;
  1002. sendBuffer.Payload.data[8] = ((lPrice >> 24) & 0xFF);
  1003. sendBuffer.Payload.data[9] = ((lPrice >> 16) & 0xFF);
  1004. sendBuffer.Payload.data[10] = ((lPrice >> 8) & 0xFF);
  1005. sendBuffer.Payload.data[11] = (lPrice & 0xFF);
  1006. sendBuffer.Payload.data[12] = ((lCost >> 24) & 0xFF);
  1007. sendBuffer.Payload.data[13] = ((lCost >> 16) & 0xFF);
  1008. sendBuffer.Payload.data[14] = ((lCost >> 8) & 0xFF);
  1009. sendBuffer.Payload.data[15] = (lCost & 0xFF);
  1010. sendBuffer.Payload.data[16] = ((lBalance >> 24) & 0xFF);
  1011. sendBuffer.Payload.data[17] = ((lBalance >> 16) & 0xFF);
  1012. sendBuffer.Payload.data[18] = ((lBalance >> 8) & 0xFF);
  1013. sendBuffer.Payload.data[19] = (lBalance & 0xFF);
  1014. sendBuffer.Payload.data[20] = ((lDiscount >> 24) & 0xFF);
  1015. sendBuffer.Payload.data[21] = ((lDiscount >> 16) & 0xFF);
  1016. sendBuffer.Payload.data[22] = ((lDiscount >> 8) & 0xFF);
  1017. sendBuffer.Payload.data[23] = (lDiscount & 0xFF);
  1018. sendBuffer.Payload.data[24] = ((transaction >> 24) & 0xFF);
  1019. sendBuffer.Payload.data[25] = ((transaction >> 16) & 0xFF);
  1020. sendBuffer.Payload.data[26] = ((transaction >> 8) & 0xFF);
  1021. sendBuffer.Payload.data[27] = (transaction & 0xFF);
  1022. sendBuffer.Payload.data[28] = ((energyCost >> 24) & 0xFF);
  1023. sendBuffer.Payload.data[29] = ((energyCost >> 16) & 0xFF);
  1024. sendBuffer.Payload.data[30] = ((energyCost >> 8) & 0xFF);
  1025. sendBuffer.Payload.data[31] = (energyCost & 0xFF);
  1026. sendBuffer.Payload.data[32] = ((parkingFee >> 24) & 0xFF);
  1027. sendBuffer.Payload.data[33] = ((parkingFee >> 16) & 0xFF);
  1028. sendBuffer.Payload.data[34] = ((parkingFee >> 8) & 0xFF);
  1029. sendBuffer.Payload.data[35] = (parkingFee & 0xFF);
  1030. char temp[4];
  1031. memcpy(temp, (char *)&fRemainAmount, sizeof(fRemainAmount));
  1032. sendBuffer.Payload.data[36] = temp[3];
  1033. sendBuffer.Payload.data[37] = temp[2];
  1034. sendBuffer.Payload.data[38] = temp[1];
  1035. sendBuffer.Payload.data[39] = temp[0];
  1036. SendPacket(socket, &sendBuffer);
  1037. }
  1038. void ChargingTargetResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1039. {
  1040. struct PACKET_STRUCTURE sendBuffer;
  1041. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1042. sendBuffer.Header.se = packet->Header.se;
  1043. sendBuffer.Header.id = packet->Header.id;
  1044. sendBuffer.Header.op = _Header_Response;
  1045. sendBuffer.Header.len = 2;
  1046. sendBuffer.Payload.reg = _Reg_Charging_Target;
  1047. sendBuffer.Payload.data[0] = result;
  1048. SendPacket(socket, &sendBuffer);
  1049. }
  1050. void FirmwareUpgradeResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex, unsigned char result)
  1051. {
  1052. struct PACKET_STRUCTURE sendBuffer;
  1053. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1054. sendBuffer.Header.se = packet->Header.se;
  1055. sendBuffer.Header.id = packet->Header.id;
  1056. sendBuffer.Header.op = _Header_Response;
  1057. sendBuffer.Header.len = 3;
  1058. sendBuffer.Payload.reg = _Reg_Software_Update;
  1059. sendBuffer.Payload.data[0] = _R_OK;
  1060. sendBuffer.Payload.data[1] = result;
  1061. if(result == _R_NeedUpgrade)
  1062. {
  1063. int length = strlen(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].FwFileName);
  1064. memcpy(&sendBuffer.Payload.data[2], ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].FwFileName, length);
  1065. sendBuffer.Header.len += length;
  1066. }
  1067. SendPacket(socket, &sendBuffer);
  1068. }
  1069. void PlugInStatusResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1070. {
  1071. struct PACKET_STRUCTURE sendBuffer;
  1072. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1073. sendBuffer.Header.se = packet->Header.se;
  1074. sendBuffer.Header.id = packet->Header.id;
  1075. sendBuffer.Header.op = _Header_Response;
  1076. sendBuffer.Header.len = 2;
  1077. sendBuffer.Payload.reg = _Reg_Plug_In_Status;
  1078. sendBuffer.Payload.data[0] = result;
  1079. SendPacket(socket, &sendBuffer);
  1080. }
  1081. void ConnectorStateResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1082. {
  1083. struct PACKET_STRUCTURE sendBuffer;
  1084. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1085. sendBuffer.Header.se = packet->Header.se;
  1086. sendBuffer.Header.id = packet->Header.id;
  1087. sendBuffer.Header.op = _Header_Response;
  1088. sendBuffer.Header.len = 2;
  1089. sendBuffer.Payload.reg = _Reg_Connector_State;
  1090. sendBuffer.Payload.data[0] = result;
  1091. SendPacket(socket, &sendBuffer);
  1092. }
  1093. void UserIDResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1094. {
  1095. struct PACKET_STRUCTURE sendBuffer;
  1096. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1097. sendBuffer.Header.se = packet->Header.se;
  1098. sendBuffer.Header.id = packet->Header.id;
  1099. sendBuffer.Header.op = _Header_Response;
  1100. sendBuffer.Header.len = 3;
  1101. sendBuffer.Payload.reg = _Reg_User_ID;
  1102. sendBuffer.Payload.data[0] = result == _DAS_Wait ? _R_NG : _R_OK;
  1103. sendBuffer.Payload.data[1] = result == _DAS_Allowed ? _PS_Permitted : _PS_NotPermitted;
  1104. SendPacket(socket, &sendBuffer);
  1105. }
  1106. void ChargingPermissionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1107. {
  1108. struct PACKET_STRUCTURE sendBuffer;
  1109. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1110. sendBuffer.Header.se = packet->Header.se;
  1111. sendBuffer.Header.id = packet->Header.id;
  1112. sendBuffer.Header.op = _Header_Response;
  1113. sendBuffer.Header.len = 3;
  1114. sendBuffer.Payload.reg = _Reg_Charging_Permission;
  1115. sendBuffer.Payload.data[0] = result == _DAS_Wait ? _R_NG : _R_OK;
  1116. sendBuffer.Payload.data[1] = result == _DAS_Allowed ? _PS_Permitted : _PS_NotPermitted;
  1117. SendPacket(socket, &sendBuffer);
  1118. }
  1119. bool Is_Dispenser_MiscCommand(int dispenser, int misc_cmd)
  1120. {
  1121. return (ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue & misc_cmd) > 0 ? true : false;
  1122. }
  1123. void Set_Dispenser_MiscCommand(int dispenser, int misc_cmd)
  1124. {
  1125. ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue |= misc_cmd;
  1126. }
  1127. void Clean_Dispenser_MiscCommand(int dispenser, int misc_cmd)
  1128. {
  1129. ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue &= ~misc_cmd;
  1130. }
  1131. bool Is_Connector_MiscCommand(int connector, int misc_cmd)
  1132. {
  1133. return (ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue & misc_cmd) > 0 ? true : false;
  1134. }
  1135. void Set_Connector_MiscCommand(int connector, int misc_cmd)
  1136. {
  1137. ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue |= misc_cmd;
  1138. }
  1139. void Clean_Connector_MiscCommand(int connector, int misc_cmd)
  1140. {
  1141. ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue &= ~misc_cmd;
  1142. }
  1143. void AddMiscCommand(struct PACKET_STRUCTURE *packet, struct MISC_COMMAND *misc)
  1144. {
  1145. packet->Payload.data[packet->Header.len - 1 + 0] = ((misc->Command >> 8) & 0xFF);
  1146. packet->Payload.data[packet->Header.len - 1 + 1] = ((misc->Command >> 0) & 0xFF);
  1147. packet->Payload.data[packet->Header.len - 1 + 2] = ((misc->Value >> 24) & 0xFF);
  1148. packet->Payload.data[packet->Header.len - 1 + 3] = ((misc->Value >> 16) & 0xFF);
  1149. packet->Payload.data[packet->Header.len - 1 + 4] = ((misc->Value >> 8) & 0xFF);
  1150. packet->Payload.data[packet->Header.len - 1 + 5] = ((misc->Value >> 0) & 0xFF);
  1151. packet->Header.len += 6;
  1152. }
  1153. bool Is_LcmPageChange_Req(int gun_index, int lcm_req)
  1154. {
  1155. if((ShmChargerInfo->ConnectorPageReq[gun_index].CtrlValue & lcm_req) > 0)
  1156. {
  1157. return true;
  1158. }
  1159. return false;
  1160. }
  1161. void Clean_LcmPage_Req(int gun_index, int lcm_req)
  1162. {
  1163. ShmChargerInfo->ConnectorPageReq[gun_index].CtrlValue &= ~lcm_req;
  1164. }
  1165. bool Is_DispenserForceChargingTriggerWebApi(int gun_index)
  1166. {
  1167. int dispenserIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex;
  1168. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
  1169. {
  1170. int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
  1171. if(ShmChargerInfo->Control.FCharging[gun].FCtrl.bits.EnableForceCharging && ShmChargerInfo->Control.FCharging[gun].FCtrl.bits.WebApiTrigger)
  1172. {
  1173. return true;
  1174. }
  1175. }
  1176. return false;
  1177. }
  1178. // LOG_INFO("Cabinet >> Connector %d Availability [SelfTestFail]", packet->Header.id);
  1179. // LOG_INFO("Cabinet >> Connector %d Availability [Disable]", packet->Header.id);
  1180. // LOG_INFO("Cabinet >> Connector %d Availability [Inoperative]", packet->Header.id);
  1181. // LOG_INFO("Cabinet >> Connector %d Availability [Enable]", packet->Header.id);
  1182. // LOG_INFO("Cabinet >> Connector %d RemoteStart [%d]", packet->Header.id, misc.Value);
  1183. // LOG_INFO("Cabinet >> Connector %d Balance [%d]", packet->Header.id, (misc.Value));
  1184. // LOG_INFO("Cabinet >> Connector %d Reservation [Trigger]", packet->Header.id);
  1185. // LOG_INFO("Cabinet >> Connector %d QR Code [Trigger]", packet->Header.id);
  1186. // LOG_INFO("Cabinet >> Connector %d Final Cost [Trigger]", packet->Header.id);
  1187. // LOG_INFO("Cabinet >> Connector %d Line Status [%d]", packet->Header.id, misc.Value);
  1188. // LOG_INFO("Cabinet >> Connector %d User Price [Trigger]", packet->Header.id);
  1189. // LOG_INFO("Cabinet >> Connector %d Receipt URL [Trigger]", packet->Header.id);
  1190. // LOG_INFO("Cabinet >> Connector %d ChargingBill [Trigger]", packet->Header.id);
  1191. // LOG_INFO("Cabinet >> Dispenser %d PlugTimeout [%d]", dispenserIndex + 1, misc.Value);
  1192. // LOG_INFO("Cabinet >> Dispenser %d DefaultPrice [%d]", dispenserIndex + 1, misc.Value);
  1193. // LOG_INFO("Cabinet >> Dispenser %d Currency [%d]", dispenserIndex + 1, misc.Value);
  1194. // LOG_INFO("Cabinet >> Dispenser %d BackendConn [%s]", dispenserIndex + 1, strConnection[misc.Value]);
  1195. // LOG_INFO("Cabinet >> Dispenser %d BackendConn [%d]", dispenserIndex + 1, (misc.Value));
  1196. // LOG_INFO("Cabinet >> Dispenser %d EthernetConn [%s]", dispenserIndex + 1, strConnection[misc.Value]);
  1197. // LOG_INFO("Cabinet >> Dispenser %d EthernetConn [%d]", dispenserIndex + 1, (misc.Value));
  1198. // LOG_INFO("Cabinet >> Dispenser %d WiFiConn [%s]", dispenserIndex + 1, strConnection[misc.Value]);
  1199. // LOG_INFO("Cabinet >> Dispenser %d WiFiConn [%d]", dispenserIndex + 1, (misc.Value));
  1200. // LOG_INFO("Cabinet >> Dispenser %d TelModemConn [%s]", dispenserIndex + 1, strConnection[misc.Value]);
  1201. // LOG_INFO("Cabinet >> Dispenser %d TelModemConn [%d]", dispenserIndex + 1, (misc.Value));
  1202. // LOG_INFO("Cabinet >> Dispenser %d BillingInfo [%s]", dispenserIndex + 1, misc.Value ? "Enable" : "Disable");
  1203. // LOG_INFO("Cabinet >> Dispenser %d StopButton [%s]", dispenserIndex + 1, misc.Value ? "Enable" : "Disable");
  1204. // LOG_INFO("Cabinet >> Dispenser %d HardReboot [%d]", dispenserIndex + 1, misc.Value);
  1205. // LOG_INFO("Cabinet >> Dispenser %d SoftReset [%d]", dispenserIndex + 1, misc.Value);
  1206. // LOG_INFO("Cabinet >> Dispenser %d AuthMode [%s]", dispenserIndex + 1, misc.Value ? "Disable" : "Enable");
  1207. // LOG_INFO("Cabinet >> Dispenser %d EVCCID [%s]", dispenserIndex + 1, misc.Value ? "Enable" : "Disable");
  1208. // LOG_INFO("Cabinet >> Dispenser %d LEDIntensity [%s]", dispenserIndex + 1, strIntensity[misc.Value]);
  1209. // LOG_INFO("Cabinet >> Dispenser %d LEDIntensity [%d]", dispenserIndex + 1, misc.Value);
  1210. // LOG_INFO("Cabinet >> Dispenser %d Station Info [Trigger]", dispenserIndex + 1);
  1211. // LOG_INFO("Cabinet >> Dispenser %d Time Offset [%s%02d:%02d]", dispenserIndex + 1, misc.Value >= 0 ? "+" : "-", (abs(misc.Value) / 60), (abs(misc.Value) % 60));
  1212. // LOG_INFO("Cabinet >> Dispenser %d Time Offset [+%d]", dispenserIndex + 1, misc.Value);
  1213. // LOG_INFO("Cabinet >> Dispenser %d Time Offset [%d]", dispenserIndex + 1, misc.Value);
  1214. // LOG_INFO("Cabinet >> Dispenser %d DefaultPrice [Trigger]", dispenserIndex + 1);
  1215. void MiscCmdRes(int socket, struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex, unsigned char result)
  1216. {
  1217. char *strConnection[] = {STR_CONN_DISABLE, STR_CONN_CONNECTED, STR_CONN_DISCONNECTED};
  1218. char *strIntensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  1219. char *strLcmPage[] = {STR_PAGE_NONE, STR_REMOTE_NO_ID};
  1220. struct PACKET_STRUCTURE sendBuffer;
  1221. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1222. sendBuffer.Header.se = packet->Header.se;
  1223. sendBuffer.Header.id = packet->Header.id;
  1224. sendBuffer.Header.op = _Header_Response;
  1225. sendBuffer.Header.len = 2;
  1226. sendBuffer.Payload.reg = _Reg_Misc_Control;
  1227. sendBuffer.Payload.data[0] = result;
  1228. if(result == _R_OK)
  1229. {
  1230. struct MISC_COMMAND misc;
  1231. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_AVAILABILITY))
  1232. {
  1233. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_AVAILABILITY);
  1234. misc.Command = _MiscCmd_ChangeOperative;
  1235. unsigned char IsAvailable = true;
  1236. if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
  1237. {
  1238. IsAvailable = false;
  1239. LOG_INFO("Cabinet >> Connector %d Availability [SelfTestFail]", packet->Header.id);
  1240. }
  1241. else if(Is_DispenserForceChargingTriggerWebApi(packet->Header.id - 1))
  1242. {
  1243. IsAvailable = false;
  1244. LOG_INFO("Cabinet >> Connector %d Availability [Disable][ForceCharging]", packet->Header.id);
  1245. }
  1246. else if(!ShmChargerInfo->Control.GunAvailable[packet->Header.id - 1])
  1247. {
  1248. IsAvailable = false;
  1249. LOG_INFO("Cabinet >> Connector %d Availability [Disable]", packet->Header.id);
  1250. }
  1251. else if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.IsAvailable)
  1252. {
  1253. IsAvailable = false;
  1254. LOG_INFO("Cabinet >> Connector %d Availability [Inoperative]", packet->Header.id);
  1255. }
  1256. else
  1257. {
  1258. LOG_INFO("Cabinet >> Connector %d Availability [Enable]", packet->Header.id);
  1259. }
  1260. misc.Value = IsAvailable;
  1261. AddMiscCommand(&sendBuffer, &misc);
  1262. }
  1263. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_REMOTE_START))
  1264. {
  1265. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_REMOTE_START);
  1266. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.RemoteStartConfirm = true;
  1267. misc.Command = _MiscCmd_RemoteStart;
  1268. misc.Value = true;
  1269. LOG_INFO("Cabinet >> Connector %d RemoteStart [%d]", packet->Header.id, misc.Value);
  1270. AddMiscCommand(&sendBuffer, &misc);
  1271. }
  1272. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_REMOTE_STOP))
  1273. {
  1274. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_REMOTE_STOP);
  1275. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.RemoteStopConfirm = true;
  1276. misc.Command = _MiscCmd_RemoteStop;
  1277. misc.Value = true;
  1278. LOG_INFO("Cabinet >> Connector %d Remote Stop: %d", packet->Header.id, misc.Value);
  1279. AddMiscCommand(&sendBuffer, &misc);
  1280. }
  1281. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_UNLOCK))
  1282. {
  1283. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_UNLOCK);
  1284. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.UnlockStopConfirm = true;
  1285. misc.Command = _MiscCmd_UnlockStop;
  1286. misc.Value = true;
  1287. LOG_INFO("Cabinet >> Connector %d Unlock Stop: %d", packet->Header.id, misc.Value);
  1288. AddMiscCommand(&sendBuffer, &misc);
  1289. }
  1290. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_ACCOUNT_BALANCE))
  1291. {
  1292. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_ACCOUNT_BALANCE);
  1293. misc.Command = _MiscCmd_AccountBalance;
  1294. misc.Value = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].AccountBalance * 100);
  1295. LOG_INFO("Cabinet >> Connector %d Balance [%d]", packet->Header.id, (misc.Value));
  1296. AddMiscCommand(&sendBuffer, &misc);
  1297. }
  1298. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_RESERVATION))
  1299. {
  1300. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_RESERVATION);
  1301. misc.Command = _MiscCmd_Reservation;
  1302. misc.Value = true;
  1303. LOG_INFO("Cabinet >> Connector %d Reservation [Trigger]", packet->Header.id);
  1304. AddMiscCommand(&sendBuffer, &misc);
  1305. }
  1306. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_QRCODE_INFO))
  1307. {
  1308. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_QRCODE_INFO);
  1309. misc.Command = _MiscCmd_QRCodeRequest;
  1310. misc.Value = true;
  1311. LOG_INFO("Cabinet >> Connector %d QR Code [Trigger]", packet->Header.id);
  1312. AddMiscCommand(&sendBuffer, &misc);
  1313. }
  1314. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_FINAL_COST))
  1315. {
  1316. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_FINAL_COST);
  1317. misc.Command = _MiscCmd_FinalCost;
  1318. misc.Value = true;
  1319. LOG_INFO("Cabinet >> Connector %d Final Cost [Trigger]", packet->Header.id);
  1320. AddMiscCommand(&sendBuffer, &misc);
  1321. }
  1322. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_LINE_STATUS))
  1323. {
  1324. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_LINE_STATUS);
  1325. misc.Command = _MiscCmd_LineStatus;
  1326. misc.Value = ShmChargerInfo->LineApi.StatusCode[packet->Header.id - 1];
  1327. LOG_INFO("Cabinet >> Connector %d Line Status [%d]", packet->Header.id, misc.Value);
  1328. AddMiscCommand(&sendBuffer, &misc);
  1329. }
  1330. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_USER_PRICE_STRING))
  1331. {
  1332. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_USER_PRICE_STRING);
  1333. misc.Command = _MiscCmd_UserPriceString;
  1334. misc.Value = true;
  1335. LOG_INFO("Cabinet >> Connector %d User Price [Trigger]", packet->Header.id);
  1336. AddMiscCommand(&sendBuffer, &misc);
  1337. }
  1338. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_RECEIPT))
  1339. {
  1340. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_RECEIPT);
  1341. misc.Command = _MiscCmd_Receipt;
  1342. misc.Value = true;
  1343. LOG_INFO("Cabinet >> Connector %d Receipt URL [Trigger]", packet->Header.id);
  1344. AddMiscCommand(&sendBuffer, &misc);
  1345. }
  1346. if(Is_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_CHARGING_BILL))
  1347. {
  1348. Clean_Connector_MiscCommand(packet->Header.id - 1, MISC_CONN_CHARGING_BILL);
  1349. misc.Command = _MiscCmd_ChargingBill;
  1350. misc.Value = true;
  1351. if(ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].BillStatus == _BillStatus_WaitMiscClean)
  1352. {
  1353. ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].BillStatus = _BillStatus_MiscClean;
  1354. }
  1355. LOG_INFO("Cabinet >> Connector %d ChargingBill [Trigger]", packet->Header.id);
  1356. AddMiscCommand(&sendBuffer, &misc);
  1357. }
  1358. // announce misc command to first connector of the dispenser
  1359. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0] == packet->Header.id)
  1360. {
  1361. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_CONNECTION_TIMEOUT))
  1362. {
  1363. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_CONNECTION_TIMEOUT);
  1364. misc.Command = _MiscCmd_ConnectorTimeout;
  1365. misc.Value = ShmChargerInfo->CabinetMiscValue.ConnectionTimeout;
  1366. LOG_INFO("Cabinet >> Dispenser %d PlugTimeout [%d]", dispenserIndex + 1, misc.Value);
  1367. AddMiscCommand(&sendBuffer, &misc);
  1368. }
  1369. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_DEFAULT_PRICE))
  1370. {
  1371. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_DEFAULT_PRICE);
  1372. misc.Command = _MiscCmd_DefaultPrice;
  1373. misc.Value = (unsigned int)(ShmChargerInfo->CabinetMiscValue.DefaultPrice * 100);
  1374. LOG_INFO("Cabinet >> Dispenser %d DefaultPrice [%d.%02d]", dispenserIndex + 1, (misc.Value / 100), (misc.Value % 100));
  1375. AddMiscCommand(&sendBuffer, &misc);
  1376. }
  1377. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_CURRENCY))
  1378. {
  1379. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_CURRENCY);
  1380. misc.Command = _MiscCmd_Currency;
  1381. misc.Value = ShmChargerInfo->CabinetMiscValue.Currency;
  1382. LOG_INFO("Cabinet >> Dispenser %d Currency [%d]", dispenserIndex + 1, misc.Value);
  1383. AddMiscCommand(&sendBuffer, &misc);
  1384. }
  1385. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_BACKEND_STATUS))
  1386. {
  1387. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_BACKEND_STATUS);
  1388. misc.Command = _MiscCmd_BackendStatus;
  1389. misc.Value = ShmChargerInfo->CabinetMiscValue.BackendStatus;
  1390. if(misc.Value <= _Connnection_Disconnected)
  1391. {
  1392. LOG_INFO("Cabinet >> Dispenser %d BackendConn [%s]", dispenserIndex + 1, strConnection[misc.Value]);
  1393. }
  1394. else
  1395. {
  1396. LOG_INFO("Cabinet >> Dispenser %d BackendConn [%d]", dispenserIndex + 1, (misc.Value));
  1397. }
  1398. AddMiscCommand(&sendBuffer, &misc);
  1399. }
  1400. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_ETHERNET_STATUS))
  1401. {
  1402. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_ETHERNET_STATUS);
  1403. misc.Command = _MiscCmd_EthernetStatus;
  1404. misc.Value = ShmChargerInfo->CabinetMiscValue.EthernetStatus;
  1405. if(misc.Value <= _Connnection_Disconnected)
  1406. {
  1407. LOG_INFO("Cabinet >> Dispenser %d EthernetConn [%s]", dispenserIndex + 1, strConnection[misc.Value]);
  1408. }
  1409. else
  1410. {
  1411. LOG_INFO("Cabinet >> Dispenser %d EthernetConn [%d]", dispenserIndex + 1, (misc.Value));
  1412. }
  1413. AddMiscCommand(&sendBuffer, &misc);
  1414. }
  1415. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_WIFI_STATUS))
  1416. {
  1417. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_WIFI_STATUS);
  1418. misc.Command = _MiscCmd_WiFiStatus;
  1419. misc.Value = ShmChargerInfo->CabinetMiscValue.WiFiStatus;
  1420. if(misc.Value <= _Connnection_Disconnected)
  1421. {
  1422. LOG_INFO("Cabinet >> Dispenser %d WiFiConn [%s]", dispenserIndex + 1, strConnection[misc.Value]);
  1423. }
  1424. else
  1425. {
  1426. LOG_INFO("Cabinet >> Dispenser %d WiFiConn [%d]", dispenserIndex + 1, (misc.Value));
  1427. }
  1428. AddMiscCommand(&sendBuffer, &misc);
  1429. }
  1430. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_TELCOM_MODEM_STATUS))
  1431. {
  1432. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_TELCOM_MODEM_STATUS);
  1433. misc.Command = _MiscCmd_4GStatus;
  1434. misc.Value = ShmChargerInfo->CabinetMiscValue.TelcomModemStatus;
  1435. if(misc.Value <= _Connnection_Disconnected)
  1436. {
  1437. LOG_INFO("Cabinet >> Dispenser %d TelModemConn [%s]", dispenserIndex + 1, strConnection[misc.Value]);
  1438. }
  1439. else
  1440. {
  1441. LOG_INFO("Cabinet >> Dispenser %d TelModemConn [%d]", dispenserIndex + 1, (misc.Value));
  1442. }
  1443. AddMiscCommand(&sendBuffer, &misc);
  1444. }
  1445. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_BILLING_STATUS))
  1446. {
  1447. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_BILLING_STATUS);
  1448. misc.Command = _MiscCmd_Billing;
  1449. misc.Value = ShmChargerInfo->CabinetMiscValue.BillingStatus;
  1450. LOG_INFO("Cabinet >> Dispenser %d BillingInfo [%s]", dispenserIndex + 1, misc.Value ? "Enable" : "Disable");
  1451. AddMiscCommand(&sendBuffer, &misc);
  1452. }
  1453. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_STOP_BUTTON_STATUS))
  1454. {
  1455. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_STOP_BUTTON_STATUS);
  1456. misc.Command = _MiscCmd_StopButton;
  1457. misc.Value = ShmChargerInfo->CabinetMiscValue.StopChargingButton;
  1458. LOG_INFO("Cabinet >> Dispenser %d StopButton [%s]", dispenserIndex + 1, misc.Value ? "Enable" : "Disable");
  1459. AddMiscCommand(&sendBuffer, &misc);
  1460. }
  1461. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_HARDWARE_REBOOT))
  1462. {
  1463. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_HARDWARE_REBOOT);
  1464. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.HardwareRebootConfirm = true;
  1465. misc.Command = _MiscCmd_HardwareReboot;
  1466. misc.Value = true;
  1467. LOG_INFO("Cabinet >> Dispenser %d HardReboot [%d]", dispenserIndex + 1, misc.Value);
  1468. AddMiscCommand(&sendBuffer, &misc);
  1469. }
  1470. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_SOFTWARE_RESET))
  1471. {
  1472. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_SOFTWARE_RESET);
  1473. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.SoftwareResetConfirm = true;
  1474. misc.Command = _MiscCmd_SoftwareRestart;
  1475. misc.Value = true;
  1476. LOG_INFO("Cabinet >> Dispenser %d SoftReset [%d]", dispenserIndex + 1, misc.Value);
  1477. AddMiscCommand(&sendBuffer, &misc);
  1478. }
  1479. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_AUTH_MODE_CONFIG))
  1480. {
  1481. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_AUTH_MODE_CONFIG);
  1482. misc.Command = _MiscCmd_AuthDisable;
  1483. misc.Value = ShmChargerInfo->CabinetMiscValue.AuthModeConfig;
  1484. LOG_INFO("Cabinet >> Dispenser %d AuthMode [%s]", dispenserIndex + 1, misc.Value ? "Disable" : "Enable");
  1485. AddMiscCommand(&sendBuffer, &misc);
  1486. }
  1487. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_EVCCID_CONFIG))
  1488. {
  1489. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_EVCCID_CONFIG);
  1490. misc.Command = _MiscCmd_EVCCIDEnable;
  1491. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ModelName[0] == 'D' &&
  1492. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ModelName[1] == 'X')
  1493. {
  1494. misc.Value = ShmChargerInfo->CabinetMiscValue.AuthModeConfig > 0 ? 0 : 1;
  1495. }
  1496. else
  1497. {
  1498. misc.Value = ShmChargerInfo->CabinetMiscValue.EVCCIDConfig;
  1499. }
  1500. LOG_INFO("Cabinet >> Dispenser %d EVCCID [%s]", dispenserIndex + 1, misc.Value ? "Enable" : "Disable");
  1501. AddMiscCommand(&sendBuffer, &misc);
  1502. }
  1503. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_LED_INTENSITY))
  1504. {
  1505. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_LED_INTENSITY);
  1506. misc.Command = _MiscCmd_LEDIntensity;
  1507. misc.Value = ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity;
  1508. if(misc.Value <= _LED_INTENSITY_BRIGHTEST)
  1509. {
  1510. LOG_INFO("Cabinet >> Dispenser %d LEDIntensity [%s]", dispenserIndex + 1, strIntensity[misc.Value]);
  1511. }
  1512. else
  1513. {
  1514. LOG_INFO("Cabinet >> Dispenser %d LEDIntensity [%d]", dispenserIndex + 1, misc.Value);
  1515. }
  1516. AddMiscCommand(&sendBuffer, &misc);
  1517. }
  1518. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_STATION_INFO))
  1519. {
  1520. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_STATION_INFO);
  1521. misc.Command = _MiscCmd_StationInfo;
  1522. misc.Value = true;
  1523. LOG_INFO("Cabinet >> Dispenser %d Station Info [Trigger]", dispenserIndex + 1);
  1524. AddMiscCommand(&sendBuffer, &misc);
  1525. }
  1526. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_TIME_OFFSET))
  1527. {
  1528. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_TIME_OFFSET);
  1529. misc.Command = _MiscCmd_TimeOffset;
  1530. misc.Value = ShmChargerInfo->CabinetMiscValue.TimeOffset;
  1531. LOG_INFO("Cabinet >> Dispenser %d Time Offset [%s%02d:%02d]",
  1532. dispenserIndex + 1, misc.Value >= 0 ? "+" : "-", (abs(misc.Value) / 60), (abs(misc.Value) % 60));
  1533. AddMiscCommand(&sendBuffer, &misc);
  1534. }
  1535. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_DEFAULT_PRICE_STRING))
  1536. {
  1537. Clean_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_DEFAULT_PRICE_STRING);
  1538. misc.Command = _MiscCmd_DefaultPriceString;
  1539. misc.Value = true;
  1540. LOG_INFO("Cabinet >> Dispenser %d DefaultPrice [Trigger]", dispenserIndex + 1);
  1541. AddMiscCommand(&sendBuffer, &misc);
  1542. }
  1543. }
  1544. if(Is_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_CHANGE_LCM_INFO))
  1545. {
  1546. int gun = packet->Header.id - 1;
  1547. for(int i = 0; i < _LCM_Page_RemoteStartNoID; i++)
  1548. {
  1549. unsigned int pageReq = 1 << i;
  1550. if(Is_LcmPageChange_Req(gun, pageReq))
  1551. {
  1552. Clean_LcmPage_Req(gun, pageReq);
  1553. misc.Command = _MiscCmd_ChangeLcmPage;
  1554. misc.Value = i + 1;
  1555. LOG_INFO("Cabinet >> Connector %d LCM_Page [%s]", packet->Header.id, strLcmPage[misc.Value]);
  1556. AddMiscCommand(&sendBuffer, &misc);
  1557. }
  1558. }
  1559. }
  1560. }
  1561. SendPacket(socket, &sendBuffer);
  1562. }
  1563. void WriteCsuVersionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1564. {
  1565. struct PACKET_STRUCTURE sendBuffer;
  1566. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1567. sendBuffer.Header.se = packet->Header.se;
  1568. sendBuffer.Header.id = packet->Header.id;
  1569. sendBuffer.Header.op = _Header_Response;
  1570. sendBuffer.Header.len = 2;
  1571. sendBuffer.Payload.reg = _Reg_Report_Csu_Version;
  1572. sendBuffer.Payload.data[0] = result;
  1573. SendPacket(socket, &sendBuffer);
  1574. }
  1575. void WriteOtherVersionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1576. {
  1577. struct PACKET_STRUCTURE sendBuffer;
  1578. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1579. sendBuffer.Header.se = packet->Header.se;
  1580. sendBuffer.Header.id = packet->Header.id;
  1581. sendBuffer.Header.op = _Header_Response;
  1582. sendBuffer.Header.len = 2;
  1583. sendBuffer.Payload.reg = _Reg_Report_Other_Version;
  1584. sendBuffer.Payload.data[0] = result;
  1585. SendPacket(socket, &sendBuffer);
  1586. }
  1587. void WriteChargingInfoResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1588. {
  1589. struct PACKET_STRUCTURE sendBuffer;
  1590. unsigned short voltage = 0, current = 0;
  1591. unsigned char gun = packet->Header.id - 1;
  1592. #if 0
  1593. // for safety test
  1594. voltage = (unsigned short)(chargingInfo[gun]->PresentChargingVoltage * 10);
  1595. current = (unsigned short)(chargingInfo[gun]->PresentChargingCurrent * 10);
  1596. voltage -= ((current * 8 * 10) / 10000);
  1597. #endif
  1598. if(chargingInfo[gun]->PantographFlag == YES)
  1599. {
  1600. //voltage = (unsigned short)(chargingInfo[gun]->PresentChargingVoltage * 10);
  1601. voltage = (unsigned short)(chargingInfo[gun]->FireChargingVoltage);
  1602. current = (unsigned short)(chargingInfo[gun]->PresentChargingCurrent * 10);
  1603. }
  1604. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1605. sendBuffer.Header.se = packet->Header.se;
  1606. sendBuffer.Header.id = packet->Header.id;
  1607. sendBuffer.Header.op = _Header_Response;
  1608. sendBuffer.Header.len = 6;
  1609. sendBuffer.Payload.reg = _Reg_Charging_Info;
  1610. sendBuffer.Payload.data[0] = result;
  1611. sendBuffer.Payload.data[1] = (voltage >> 8) & 0xFF;
  1612. sendBuffer.Payload.data[2] = (voltage >> 0) & 0xFF;
  1613. sendBuffer.Payload.data[3] = (current >> 8) & 0xFF;
  1614. sendBuffer.Payload.data[4] = (current >> 0) & 0xFF;
  1615. SendPacket(socket, &sendBuffer);
  1616. }
  1617. int GetChargerSystemId(char *id)
  1618. {
  1619. int len = 0;
  1620. strcpy((char *)id, "");
  1621. if(ShmChargerInfo->Control.CustomerCode != _CUSTOMER_CODE_Audi &&
  1622. ShmChargerInfo->Control.CustomerCode != _CUSTOMER_CODE_TCC)
  1623. {
  1624. ShmChargerInfo->AuthInfo.QRCodeMode = ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode;
  1625. }
  1626. switch(ShmChargerInfo->AuthInfo.QRCodeMode)
  1627. {
  1628. case _QR_MODE_Customized:
  1629. strcpy((char *)id, (char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  1630. break;
  1631. case _QR_MODE_ChargeBoxId:
  1632. strcpy((char *)id, (char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  1633. break;
  1634. case _QR_MODE_Default:
  1635. default:
  1636. strcat((char *)id, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1637. strcat((char *)id, (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1638. break;
  1639. }
  1640. len = strlen((char *)id);
  1641. return len;
  1642. }
  1643. void ChargerQrCodeDateResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex, unsigned char result)
  1644. {
  1645. struct PACKET_STRUCTURE sendBuffer;
  1646. char system_id[128];
  1647. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1648. sendBuffer.Header.se = packet->Header.se;
  1649. sendBuffer.Header.id = packet->Header.id;
  1650. sendBuffer.Header.op = _Header_Response;
  1651. sendBuffer.Header.len = 2;
  1652. sendBuffer.Payload.reg = _Reg_QR_Code_Date;
  1653. sendBuffer.Payload.data[0] = result;
  1654. if(result == _R_OK)
  1655. {
  1656. int strLen = 0;
  1657. strLen = GetChargerSystemId(system_id);
  1658. memcpy(&sendBuffer.Payload.data[sendBuffer.Header.len - 1], (char *)system_id, strLen);
  1659. sendBuffer.Header.len += strLen + 1;
  1660. char TimeSync[32];
  1661. struct timeb SeqEndTime;
  1662. struct tm *tm;
  1663. ftime(&SeqEndTime);
  1664. SeqEndTime.time = time(NULL);
  1665. tm=localtime(&SeqEndTime.time);
  1666. memset(TimeSync, 0x00, 32);
  1667. sprintf(TimeSync, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  1668. strLen = strlen(TimeSync);
  1669. memcpy(&sendBuffer.Payload.data[sendBuffer.Header.len - 1], TimeSync, strLen);
  1670. sendBuffer.Header.len += strLen + 1;
  1671. //LOG_INFO("Dispenser %d Read System Id: %s", dispenserIndex + 1, ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  1672. }
  1673. SendPacket(socket, &sendBuffer);
  1674. }
  1675. void WriteWaitPlugInResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1676. {
  1677. struct PACKET_STRUCTURE sendBuffer;
  1678. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1679. sendBuffer.Header.se = packet->Header.se;
  1680. sendBuffer.Header.id = packet->Header.id;
  1681. sendBuffer.Header.op = _Header_Response;
  1682. sendBuffer.Header.len = 2;
  1683. sendBuffer.Payload.reg = _Reg_WaitPlugIn;
  1684. sendBuffer.Payload.data[0] = result;
  1685. SendPacket(socket, &sendBuffer);
  1686. }
  1687. void GroundFaultDetectionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1688. {
  1689. struct PACKET_STRUCTURE sendBuffer;
  1690. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1691. sendBuffer.Header.se = packet->Header.se;
  1692. sendBuffer.Header.id = packet->Header.id;
  1693. sendBuffer.Header.op = _Header_Response;
  1694. sendBuffer.Header.len = 3;
  1695. sendBuffer.Payload.reg = _Reg_GroundFaultDetection;
  1696. sendBuffer.Payload.data[0] = result;
  1697. sendBuffer.Payload.data[1] = result == _R_OK ? chargingInfo[packet->Header.id - 1]->GroundFaultStatus : GFD_WAIT;
  1698. SendPacket(socket, &sendBuffer);
  1699. }
  1700. void CabinetCSUVersionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1701. {
  1702. struct PACKET_STRUCTURE sendBuffer;
  1703. char version[64];
  1704. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1705. sendBuffer.Header.se = packet->Header.se;
  1706. sendBuffer.Header.id = packet->Header.id;
  1707. sendBuffer.Header.op = _Header_Response;
  1708. sendBuffer.Header.len = 194;
  1709. sendBuffer.Payload.reg = _Reg_Get_Cabinet_CSU_Version;
  1710. sendBuffer.Payload.data[0] = result;
  1711. memset(version, 0x00, sizeof(version));
  1712. strcpy(version, (char *)&ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  1713. memcpy(&sendBuffer.Payload.data[1], version, 32);
  1714. memset(version, 0x00, sizeof(version));
  1715. strcpy(version, (char *)&ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev[0]);
  1716. memcpy(&sendBuffer.Payload.data[33], version, 32);
  1717. memset(version, 0x00, sizeof(version));
  1718. strcpy(version, (char *)&ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[0]);
  1719. memcpy(&sendBuffer.Payload.data[65], version, 32);
  1720. memset(version, 0x00, sizeof(version));
  1721. strcpy(version, (char *)&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[0]);
  1722. memcpy(&sendBuffer.Payload.data[97], version, 32);
  1723. memset(version, 0x00, sizeof(version));
  1724. strcpy(version, (char *)&ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[0]);
  1725. memcpy(&sendBuffer.Payload.data[129], version, 32);
  1726. memset(version, 0x00, sizeof(version));
  1727. strcpy(version, (char *)&ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress[0]);
  1728. memcpy(&sendBuffer.Payload.data[161], version, 32);
  1729. SendPacket(socket, &sendBuffer);
  1730. }
  1731. void CabinetOtherVersionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1732. {
  1733. struct PACKET_STRUCTURE sendBuffer;
  1734. char version[64];
  1735. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1736. sendBuffer.Header.se = packet->Header.se;
  1737. sendBuffer.Header.id = packet->Header.id;
  1738. sendBuffer.Header.op = _Header_Response;
  1739. sendBuffer.Header.len = 98;
  1740. sendBuffer.Payload.reg = _Reg_Get_Cabinet_Other_Version;
  1741. sendBuffer.Payload.data[0] = result;
  1742. memset(version, 0x00, sizeof(version));
  1743. strcpy(version, (char *)&ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0]);
  1744. memcpy(&sendBuffer.Payload.data[1], version, 32);
  1745. memset(version, 0x00, sizeof(version));
  1746. strcpy(version, (char *)&ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev[0]);
  1747. memcpy(&sendBuffer.Payload.data[33], version, 32);
  1748. memset(version, 0x00, sizeof(version));
  1749. strcpy(version, (char *)&ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0]);
  1750. memcpy(&sendBuffer.Payload.data[65], version, 32);
  1751. SendPacket(socket, &sendBuffer);
  1752. }
  1753. void PsuQuantityResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1754. {
  1755. struct PACKET_STRUCTURE sendBuffer;
  1756. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1757. sendBuffer.Header.se = packet->Header.se;
  1758. sendBuffer.Header.id = packet->Header.id;
  1759. sendBuffer.Header.op = _Header_Response;
  1760. sendBuffer.Header.len = 3;
  1761. sendBuffer.Payload.reg = _Reg_Get_Psu_Quantity;
  1762. sendBuffer.Payload.data[0] = result;
  1763. sendBuffer.Payload.data[1] = ShmPsuData->SystemInitialPsuQuantity;
  1764. SendPacket(socket, &sendBuffer);
  1765. }
  1766. void PsuVersionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result, int psuIndex)
  1767. {
  1768. struct PACKET_STRUCTURE sendBuffer;
  1769. char version[64];
  1770. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1771. sendBuffer.Header.se = packet->Header.se;
  1772. sendBuffer.Header.id = packet->Header.id;
  1773. sendBuffer.Header.op = _Header_Response;
  1774. sendBuffer.Header.len = 3 + 64;
  1775. sendBuffer.Payload.reg = _Reg_Get_Psu_Version;
  1776. sendBuffer.Payload.data[0] = result;
  1777. sendBuffer.Payload.data[1] = psuIndex;
  1778. memset(version, 0x00, sizeof(version));
  1779. strcpy(version, (char *)&ShmPsuData->PsuVersion[psuIndex].FwPrimaryVersion[0]);
  1780. memcpy(&sendBuffer.Payload.data[2], version, 32);
  1781. memset(version, 0x00, sizeof(version));
  1782. strcpy(version, (char *)&ShmPsuData->PsuVersion[psuIndex].FwSecondVersion[0]);
  1783. memcpy(&sendBuffer.Payload.data[34], version, 32);
  1784. SendPacket(socket, &sendBuffer);
  1785. }
  1786. void ReservationResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result, unsigned char _reservation)
  1787. {
  1788. struct PACKET_STRUCTURE sendBuffer;
  1789. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1790. sendBuffer.Header.se = packet->Header.se;
  1791. sendBuffer.Header.id = packet->Header.id;
  1792. sendBuffer.Header.op = _Header_Response;
  1793. sendBuffer.Header.len = 3;
  1794. sendBuffer.Payload.reg = _Reg_Get_Reservation;
  1795. sendBuffer.Payload.data[0] = result;
  1796. sendBuffer.Payload.data[1] = _reservation;
  1797. if(_reservation)
  1798. {
  1799. strcpy((char *)&sendBuffer.Payload.data[2], &ShmChargerInfo->Control.ResevedIdTag[packet->Header.id - 1][0]);
  1800. sendBuffer.Header.len += strlen(&ShmChargerInfo->Control.ResevedIdTag[packet->Header.id - 1][0]);
  1801. }
  1802. // '\0'
  1803. sendBuffer.Header.len += 1;
  1804. SendPacket(socket, &sendBuffer);
  1805. }
  1806. void DispenserReqHandlerResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1807. {
  1808. struct PACKET_STRUCTURE sendBuffer;
  1809. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1810. sendBuffer.Header.se = packet->Header.se;
  1811. sendBuffer.Header.id = packet->Header.id;
  1812. sendBuffer.Header.op = _Header_Response;
  1813. sendBuffer.Header.len = 2;
  1814. sendBuffer.Payload.reg = _Reg_Dispenser_Request;
  1815. sendBuffer.Payload.data[0] = result;
  1816. SendPacket(socket, &sendBuffer);
  1817. }
  1818. void RemoteStarNoIDResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result, unsigned char state)
  1819. {
  1820. struct PACKET_STRUCTURE sendBuffer;
  1821. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1822. sendBuffer.Header.se = packet->Header.se;
  1823. sendBuffer.Header.id = packet->Header.id;
  1824. sendBuffer.Header.op = _Header_Response;
  1825. sendBuffer.Header.len = 3;
  1826. sendBuffer.Payload.reg = _Reg_RemoteStartNoIDState;
  1827. sendBuffer.Payload.data[0] = result;
  1828. sendBuffer.Payload.data[1] = state;
  1829. SendPacket(socket, &sendBuffer);
  1830. }
  1831. void RefundAmountResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1832. {
  1833. struct PACKET_STRUCTURE sendBuffer;
  1834. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1835. sendBuffer.Header.se = packet->Header.se;
  1836. sendBuffer.Header.id = packet->Header.id;
  1837. sendBuffer.Header.op = _Header_Response;
  1838. sendBuffer.Header.len = 2 + 128;
  1839. sendBuffer.Payload.reg = _Reg_RefundAmount;
  1840. sendBuffer.Payload.data[0] = result;
  1841. memcpy(&sendBuffer.Payload.data[1], &ConnectorRefund[packet->Header.id - 1].ChargingDate, 32);
  1842. memcpy(&sendBuffer.Payload.data[33], &ConnectorRefund[packet->Header.id - 1].ChargingDate, 32);
  1843. memcpy(&sendBuffer.Payload.data[65], &ConnectorRefund[packet->Header.id - 1].ChargingDate, 32);
  1844. memcpy(&sendBuffer.Payload.data[97], &ConnectorRefund[packet->Header.id - 1].ChargingDate, 32);
  1845. SendPacket(socket, &sendBuffer);
  1846. }
  1847. void PrepaymentResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1848. {
  1849. struct PACKET_STRUCTURE sendBuffer;
  1850. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1851. sendBuffer.Header.se = packet->Header.se;
  1852. sendBuffer.Header.id = packet->Header.id;
  1853. sendBuffer.Header.op = _Header_Response;
  1854. sendBuffer.Header.len = 3 + 128;
  1855. sendBuffer.Payload.reg = _Reg_PrepaymentInfo;
  1856. sendBuffer.Payload.data[0] = result;
  1857. sendBuffer.Payload.data[1] = ConnectorPrepayment[packet->Header.id - 1].PaymentType;
  1858. memcpy(&sendBuffer.Payload.data[2], &ConnectorPrepayment[packet->Header.id - 1].TopUp, 32);
  1859. memcpy(&sendBuffer.Payload.data[34], &ConnectorPrepayment[packet->Header.id - 1].AccountAmount, 32);
  1860. memcpy(&sendBuffer.Payload.data[66], &ConnectorPrepayment[packet->Header.id - 1].Prepayment, 32);
  1861. memcpy(&sendBuffer.Payload.data[98], &ConnectorPrepayment[packet->Header.id - 1].Balance, 32);
  1862. SendPacket(socket, &sendBuffer);
  1863. }
  1864. void PaymentFailReasonResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1865. {
  1866. struct PACKET_STRUCTURE sendBuffer;
  1867. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1868. sendBuffer.Header.se = packet->Header.se;
  1869. sendBuffer.Header.id = packet->Header.id;
  1870. sendBuffer.Header.op = _Header_Response;
  1871. sendBuffer.Header.len = 3;
  1872. sendBuffer.Payload.reg = _Reg_PaymentFailReason;
  1873. sendBuffer.Payload.data[0] = result;
  1874. sendBuffer.Payload.data[1] = ConnectorPaymentFailReason[packet->Header.id - 1].ReasonIndex;
  1875. if(ConnectorPaymentFailReason[packet->Header.id - 1].ReasonIndex == 0)
  1876. {
  1877. int len = strlen(ConnectorPaymentFailReason[packet->Header.id - 1].Reason) + 1;
  1878. memcpy(&sendBuffer.Payload.data[2], &ConnectorPaymentFailReason[packet->Header.id - 1].Reason, len);
  1879. sendBuffer.Header.len += len;
  1880. }
  1881. SendPacket(socket, &sendBuffer);
  1882. }
  1883. void QRCodeResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1884. {
  1885. struct PACKET_STRUCTURE sendBuffer;
  1886. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1887. sendBuffer.Header.se = packet->Header.se;
  1888. sendBuffer.Header.id = packet->Header.id;
  1889. sendBuffer.Header.op = _Header_Response;
  1890. sendBuffer.Header.len = 2;
  1891. sendBuffer.Payload.reg = _Reg_ConnectorQRCode;
  1892. sendBuffer.Payload.data[0] = result;
  1893. if(result == _R_OK)
  1894. {
  1895. char qrCode[128];
  1896. int qrCodeLen = 0;
  1897. memset(qrCode, 0x00, sizeof(qrCode));
  1898. qrCodeLen = strlen(ShmChargerInfo->StationInfo.QRCode[sendBuffer.Header.id - 1]);
  1899. if(qrCodeLen > 0)
  1900. {
  1901. memcpy(qrCode, ShmChargerInfo->StationInfo.QRCode[sendBuffer.Header.id - 1], qrCodeLen);
  1902. }
  1903. else
  1904. {
  1905. qrCodeLen = GetChargerSystemId(qrCode);
  1906. sprintf(&qrCode[qrCodeLen], "_%d", packet->Header.id - 1);
  1907. qrCodeLen = strlen(qrCode);
  1908. }
  1909. if(strcmp((char *)&_ConnectorQRCode[packet->Header.id - 1][0], qrCode) != 0)
  1910. {
  1911. strcpy((char *)&_ConnectorQRCode[packet->Header.id - 1][0], qrCode);
  1912. LOG_INFO("Gun %d QR Code: [%s]", packet->Header.id, &_ConnectorQRCode[packet->Header.id - 1][0]);
  1913. }
  1914. memcpy(&sendBuffer.Payload.data[1], (char *)qrCode, qrCodeLen);
  1915. sendBuffer.Header.len += qrCodeLen;
  1916. }
  1917. // '\0'
  1918. sendBuffer.Header.len += 1;
  1919. SendPacket(socket, &sendBuffer);
  1920. }
  1921. void StationInfoResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex, unsigned char result)
  1922. {
  1923. char strWeather[16];
  1924. char *str_weather_type[] = {STR_WEATHER_NONE, STR_WEATHER_SUNNY, STR_WEATHER_CLOUDY, STR_WEATHER_RAIN, STR_WEATHER_THUNDERSTORM, STR_WEATHER_SNOW, STR_WEATHER_MIST};
  1925. struct PACKET_STRUCTURE sendBuffer;
  1926. memset(strWeather, 0x00, sizeof(strWeather));
  1927. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1928. sendBuffer.Header.se = packet->Header.se;
  1929. sendBuffer.Header.id = packet->Header.id;
  1930. sendBuffer.Header.op = _Header_Response;
  1931. sendBuffer.Header.len = 78;
  1932. sendBuffer.Payload.reg = _Reg_StationInfo;
  1933. sendBuffer.Payload.data[0] = result;
  1934. sendBuffer.Payload.data[1] = ((ShmChargerInfo->StationInfo.StationID >> 24) & 0xFF);
  1935. sendBuffer.Payload.data[2] = ((ShmChargerInfo->StationInfo.StationID >> 16) & 0xFF);
  1936. sendBuffer.Payload.data[3] = ((ShmChargerInfo->StationInfo.StationID >> 8) & 0xFF);
  1937. sendBuffer.Payload.data[4] = (ShmChargerInfo->StationInfo.StationID & 0xFF);
  1938. memcpy(&sendBuffer.Payload.data[5], ShmChargerInfo->StationInfo.StationName, 64);
  1939. sendBuffer.Payload.data[69] = (ShmChargerInfo->StationInfo.WeatherID >> 24) & 0xFF;
  1940. sendBuffer.Payload.data[70] = (ShmChargerInfo->StationInfo.WeatherID >> 16) & 0xFF;
  1941. sendBuffer.Payload.data[71] = (ShmChargerInfo->StationInfo.WeatherID >> 8) & 0xFF;
  1942. sendBuffer.Payload.data[72] = ShmChargerInfo->StationInfo.WeatherID & 0xFF;
  1943. char *ptr = (char *)&ShmChargerInfo->StationInfo.Temperature;
  1944. sendBuffer.Payload.data[73] = *(ptr + 3);
  1945. sendBuffer.Payload.data[74] = *(ptr + 2);
  1946. sendBuffer.Payload.data[75] = *(ptr + 1);
  1947. sendBuffer.Payload.data[76] = *ptr;
  1948. if(strcmp(_stationInfo[dispenserIndex].StationName, ShmChargerInfo->StationInfo.StationName) != 0 ||
  1949. _stationInfo[dispenserIndex].StationID != ShmChargerInfo->StationInfo.StationID ||
  1950. _stationInfo[dispenserIndex].WeatherID != ShmChargerInfo->StationInfo.WeatherID ||
  1951. _stationInfo[dispenserIndex].Temperature != ShmChargerInfo->StationInfo.Temperature)
  1952. {
  1953. memcpy((char *)&_stationInfo[dispenserIndex], (char *)&ShmChargerInfo->StationInfo, sizeof(StationInfoData));
  1954. if(ShmChargerInfo->StationInfo.WeatherID <= _WEATHER_Mist)
  1955. {
  1956. strcpy(strWeather, str_weather_type[ShmChargerInfo->StationInfo.WeatherID]);
  1957. }
  1958. else
  1959. {
  1960. sprintf(strWeather, "%d", ShmChargerInfo->StationInfo.WeatherID);
  1961. }
  1962. LOG_INFO("Dispenser %d StationID: %d, Name: %s, WeatherID: %s, Temperature: %4.1f",
  1963. dispenserIndex + 1,
  1964. ShmChargerInfo->StationInfo.StationID,
  1965. ShmChargerInfo->StationInfo.StationName,
  1966. strWeather,
  1967. ShmChargerInfo->StationInfo.Temperature);
  1968. }
  1969. SendPacket(socket, &sendBuffer);
  1970. }
  1971. void DeductResultResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1972. {
  1973. struct PACKET_STRUCTURE sendBuffer;
  1974. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1975. sendBuffer.Header.se = packet->Header.se;
  1976. sendBuffer.Header.id = packet->Header.id;
  1977. sendBuffer.Header.op = _Header_Response;
  1978. sendBuffer.Header.len = 2;
  1979. sendBuffer.Payload.reg = _Reg_DeductResult;
  1980. sendBuffer.Payload.data[0] = result;
  1981. SendPacket(socket, &sendBuffer);
  1982. }
  1983. void CabinetSystemIDResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  1984. {
  1985. struct PACKET_STRUCTURE sendBuffer;
  1986. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  1987. sendBuffer.Header.se = packet->Header.se;
  1988. sendBuffer.Header.id = packet->Header.id;
  1989. sendBuffer.Header.op = _Header_Response;
  1990. sendBuffer.Header.len = 2;
  1991. sendBuffer.Payload.reg = _Reg_CabinetSystemID;
  1992. sendBuffer.Payload.data[0] = result;
  1993. if(result == _R_OK)
  1994. {
  1995. strcpy((char *)&sendBuffer.Payload.data[1], (char *)ShmSysConfigAndInfo->SysConfig.SystemId);
  1996. sendBuffer.Header.len += strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
  1997. }
  1998. SendPacket(socket, &sendBuffer);
  1999. }
  2000. void DefaultPriceStringResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  2001. {
  2002. struct PACKET_STRUCTURE sendBuffer;
  2003. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  2004. sendBuffer.Header.se = packet->Header.se;
  2005. sendBuffer.Header.id = packet->Header.id;
  2006. sendBuffer.Header.op = _Header_Response;
  2007. sendBuffer.Header.len = 2;
  2008. sendBuffer.Payload.reg = _Reg_DefaultPriceString;
  2009. sendBuffer.Payload.data[0] = result;
  2010. if(result == _R_OK)
  2011. {
  2012. strcpy((char *)&sendBuffer.Payload.data[1], &ShmChargerInfo->PriceAndReceiptInfo.DefaultPriceString[0]);
  2013. sendBuffer.Header.len += strlen(&ShmChargerInfo->PriceAndReceiptInfo.DefaultPriceString[0]);
  2014. }
  2015. SendPacket(socket, &sendBuffer);
  2016. }
  2017. void UserPriceStringResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  2018. {
  2019. struct PACKET_STRUCTURE sendBuffer;
  2020. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  2021. sendBuffer.Header.se = packet->Header.se;
  2022. sendBuffer.Header.id = packet->Header.id;
  2023. sendBuffer.Header.op = _Header_Response;
  2024. sendBuffer.Header.len = 2;
  2025. sendBuffer.Payload.reg = _Reg_UserPriceString;
  2026. sendBuffer.Payload.data[0] = result;
  2027. if(result == _R_OK)
  2028. {
  2029. strcpy((char *)&sendBuffer.Payload.data[1], &ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[packet->Header.id - 1][0]);
  2030. sendBuffer.Header.len += strlen(&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[packet->Header.id - 1][0]);
  2031. }
  2032. SendPacket(socket, &sendBuffer);
  2033. }
  2034. void ReceiptResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  2035. {
  2036. struct PACKET_STRUCTURE sendBuffer;
  2037. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  2038. sendBuffer.Header.se = packet->Header.se;
  2039. sendBuffer.Header.id = packet->Header.id;
  2040. sendBuffer.Header.op = _Header_Response;
  2041. sendBuffer.Header.len = 2;
  2042. sendBuffer.Payload.reg = _Reg_Receipt;
  2043. sendBuffer.Payload.data[0] = result;
  2044. if(result == _R_OK)
  2045. {
  2046. strcpy((char *)&sendBuffer.Payload.data[1], &ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[packet->Header.id - 1][0]);
  2047. sendBuffer.Header.len += strlen(&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[packet->Header.id - 1][0]);
  2048. }
  2049. SendPacket(socket, &sendBuffer);
  2050. }
  2051. void PowerConsumptionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  2052. {
  2053. struct PACKET_STRUCTURE sendBuffer;
  2054. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  2055. sendBuffer.Header.se = packet->Header.se;
  2056. sendBuffer.Header.id = packet->Header.id;
  2057. sendBuffer.Header.op = _Header_Response;
  2058. sendBuffer.Header.len = 2;
  2059. sendBuffer.Payload.reg = _Reg_PowerConsumption;
  2060. sendBuffer.Payload.data[0] = result;
  2061. if(result == _R_OK)
  2062. {
  2063. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2064. {
  2065. char *ptr = (char *)&chargingInfo[i]->PowerConsumption;
  2066. sendBuffer.Payload.data[1 + (i * 4) + 0] = *(ptr + 3);
  2067. sendBuffer.Payload.data[1 + (i * 4) + 1] = *(ptr + 2);
  2068. sendBuffer.Payload.data[1 + (i * 4) + 2] = *(ptr + 1);
  2069. sendBuffer.Payload.data[1 + (i * 4) + 3] = *ptr;
  2070. sendBuffer.Header.len += 4;
  2071. }
  2072. }
  2073. SendPacket(socket, &sendBuffer);
  2074. }
  2075. void ChargingTimestampResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  2076. {
  2077. int len = 0;
  2078. struct PACKET_STRUCTURE sendBuffer;
  2079. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  2080. sendBuffer.Header.se = packet->Header.se;
  2081. sendBuffer.Header.id = packet->Header.id;
  2082. sendBuffer.Header.op = _Header_Response;
  2083. sendBuffer.Header.len = 2;
  2084. sendBuffer.Payload.reg = _Reg_ChargingTimestamp;
  2085. sendBuffer.Payload.data[0] = result;
  2086. if(result == _R_OK)
  2087. {
  2088. // StartCharging Timestamp
  2089. strcpy((char *)&sendBuffer.Payload.data[sendBuffer.Header.len - 1], ShmChargerInfo->Timestamp[packet->Header.id - 1].StartCharging);
  2090. len = strlen(ShmChargerInfo->Timestamp[packet->Header.id - 1].StartCharging);
  2091. sendBuffer.Payload.data[sendBuffer.Header.len - 1 + len] = '\0';
  2092. sendBuffer.Header.len += (len + 1);
  2093. // StopCharging Timestamp
  2094. strcpy((char *)&sendBuffer.Payload.data[sendBuffer.Header.len - 1], ShmChargerInfo->Timestamp[packet->Header.id - 1].StopCharging);
  2095. len = strlen(ShmChargerInfo->Timestamp[packet->Header.id - 1].StopCharging);
  2096. sendBuffer.Payload.data[sendBuffer.Header.len - 1 + len] = '\0';
  2097. sendBuffer.Header.len += (len + 1);
  2098. }
  2099. SendPacket(socket, &sendBuffer);
  2100. }
  2101. void ChargingBillResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
  2102. {
  2103. struct PACKET_STRUCTURE sendBuffer;
  2104. memset(&sendBuffer, 0x00, sizeof(sendBuffer));
  2105. sendBuffer.Header.se = packet->Header.se;
  2106. sendBuffer.Header.id = packet->Header.id;
  2107. sendBuffer.Header.op = _Header_Response;
  2108. sendBuffer.Header.len = 30;
  2109. sendBuffer.Payload.reg = _Reg_ChargingBill;
  2110. sendBuffer.Payload.data[0] = result;
  2111. int txId = 0;
  2112. unsigned int lCost = 0, lBalance = 0, lDiscount = 0;
  2113. int energyCost = 0, parkingFee = 0;
  2114. if(result == _R_OK)
  2115. {
  2116. txId = ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].TxId;
  2117. lCost = (unsigned int)(ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.TotalCost * 100);
  2118. lBalance = (unsigned int)(ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.AccountBalance * 100);
  2119. lDiscount = (unsigned int)(ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.CostDiscount * 100);
  2120. energyCost = ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.EnergyCost >= 0 ?
  2121. (int)(ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.EnergyCost * 100) : -1;
  2122. parkingFee = ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.ParkingFee >= 0 ?
  2123. (int)(ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.ParkingFee * 100) : -1;
  2124. // Total cost
  2125. sendBuffer.Payload.data[1] = ((lCost >> 24) & 0xFF);
  2126. sendBuffer.Payload.data[2] = ((lCost >> 16) & 0xFF);
  2127. sendBuffer.Payload.data[3] = ((lCost >> 8) & 0xFF);
  2128. sendBuffer.Payload.data[4] = (lCost & 0xFF);
  2129. // Account balance
  2130. sendBuffer.Payload.data[5] = ((lBalance >> 24) & 0xFF);
  2131. sendBuffer.Payload.data[6] = ((lBalance >> 16) & 0xFF);
  2132. sendBuffer.Payload.data[7] = ((lBalance >> 8) & 0xFF);
  2133. sendBuffer.Payload.data[8] = (lBalance & 0xFF);
  2134. // Cost discount
  2135. sendBuffer.Payload.data[9] = ((lDiscount >> 24) & 0xFF);
  2136. sendBuffer.Payload.data[10] = ((lDiscount >> 16) & 0xFF);
  2137. sendBuffer.Payload.data[11] = ((lDiscount >> 8) & 0xFF);
  2138. sendBuffer.Payload.data[12] = (lDiscount & 0xFF);
  2139. // Transaction Id
  2140. sendBuffer.Payload.data[13] = ((txId >> 24) & 0xFF);
  2141. sendBuffer.Payload.data[14] = ((txId >> 16) & 0xFF);
  2142. sendBuffer.Payload.data[15] = ((txId >> 8) & 0xFF);
  2143. sendBuffer.Payload.data[16] = (txId & 0xFF);
  2144. // Energy cost
  2145. sendBuffer.Payload.data[17] = ((energyCost >> 24) & 0xFF);
  2146. sendBuffer.Payload.data[18] = ((energyCost >> 16) & 0xFF);
  2147. sendBuffer.Payload.data[19] = ((energyCost >> 8) & 0xFF);
  2148. sendBuffer.Payload.data[20] = (energyCost & 0xFF);
  2149. // Parking fee
  2150. sendBuffer.Payload.data[21] = ((parkingFee >> 24) & 0xFF);
  2151. sendBuffer.Payload.data[22] = ((parkingFee >> 16) & 0xFF);
  2152. sendBuffer.Payload.data[23] = ((parkingFee >> 8) & 0xFF);
  2153. sendBuffer.Payload.data[24] = (parkingFee & 0xFF);
  2154. // Remain Amount
  2155. char temp[4];
  2156. memcpy(temp, (char *)&ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.RemainAmount, sizeof(float));
  2157. sendBuffer.Payload.data[25] = temp[3];
  2158. sendBuffer.Payload.data[26] = temp[2];
  2159. sendBuffer.Payload.data[27] = temp[1];
  2160. sendBuffer.Payload.data[28] = temp[0];
  2161. if(ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].BillStatus == _BillStatus_MiscClean)
  2162. {
  2163. ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].BillStatus = _BillStatus_UpdateDone;
  2164. }
  2165. Database_INFO("Gun %d TxId[%d]\r\n Total: %8.2f\r\n Account: %8.2f\r\nDiscount: %8.2f\r\n Energgy: %8.2f\r\n Parking: %8.2f\r\n Remain: %8.2f",
  2166. packet->Header.id,
  2167. txId,
  2168. ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.TotalCost,
  2169. ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.AccountBalance,
  2170. ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.CostDiscount,
  2171. ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.EnergyCost,
  2172. ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.ParkingFee,
  2173. ShmChargerInfo->AllBill.GunBill[packet->Header.id - 1].FeeInfo.RemainAmount);
  2174. }
  2175. SendPacket(socket, &sendBuffer);
  2176. }
  2177. BOOL FindConnectorID(unsigned char dispenserIndex, unsigned char id)
  2178. {
  2179. BOOL find = false;
  2180. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
  2181. {
  2182. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] == id)
  2183. {
  2184. find = true;
  2185. break;
  2186. }
  2187. }
  2188. return find;
  2189. }
  2190. void ConnectorPhysicalLimitBindingHandler(unsigned char connectorIndex, unsigned char physical, unsigned char safety)
  2191. {
  2192. // 20210817 remove type "R"
  2193. //char modelList[11] = {'J', 'U', 'V', 'E', 'F', 'G', 'T', 'D', 'K', 'P'};
  2194. //unsigned char typeList[11] = { 0, 1, 1, 1, 1, 2, 1, 1, 0, 1}; // 0 : Chademo, 1: CCS, 2: GB
  2195. memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp, 0x00, sizeof(struct DERATING_BY_OTP));
  2196. switch(physical)
  2197. {
  2198. case 'J':
  2199. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CHA_MAX_PHYSICAL_VOLTAGE;
  2200. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CHA_NATURAL_J_MAX_CURRENT;
  2201. if(safety == 'J')
  2202. {
  2203. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CHA_NATURAL_J_JARI_MAX_CURRENT;
  2204. }
  2205. break;
  2206. case 'S':
  2207. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CHA_MAX_PHYSICAL_VOLTAGE;
  2208. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CHA_NATURAL_S_MAX_CURRENT;
  2209. // Boost Mode
  2210. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CHA_MAX_PHYSICAL_VOLTAGE;
  2211. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CHA_NATURAL_S_BOOST_CURRENT;
  2212. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.isNeedDerating = YES;
  2213. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingIndex = 0;
  2214. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetCurrent[0] = CHA_NATURAL_S_BOOST_CURRENT;
  2215. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetCurrent[1] = CHA_NATURAL_S_MAX_CURRENT;
  2216. break;
  2217. case 'K':
  2218. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CHA_MAX_PHYSICAL_VOLTAGE;
  2219. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CHA_NATURAL_K_MAX_CURRENT;
  2220. // Derating Mode
  2221. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.isNeedDerating = YES;
  2222. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingIndex = 0;
  2223. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetRate[0] = 1;
  2224. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetRate[1] = 0.8;
  2225. break;
  2226. case 'Y':
  2227. case 'Z':
  2228. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CCS_MAX_PHYSICAL_VOLTAGE;
  2229. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CCS_NATURAL_Y_Z_MAX_CURRENT;
  2230. break;
  2231. case 'U':
  2232. case 'E':
  2233. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CCS_MAX_PHYSICAL_VOLTAGE;
  2234. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CCS_NATURAL_U_E_MAX_CURRENT;
  2235. break;
  2236. case 'G':
  2237. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = GBT_MAX_PHYSICAL_VOLTAGE;
  2238. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = GBT_NATURAL_MAX_CURRENT;
  2239. break;
  2240. case 'V':
  2241. case 'F':
  2242. //case 'R': // 20210817 remove type "R"
  2243. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CCS_MAX_PHYSICAL_VOLTAGE;
  2244. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CCS_LIQUID_V_F_MAX_CURRENT;
  2245. // Derating Mode
  2246. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.isNeedDerating = YES;
  2247. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingIndex = 0;
  2248. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetCurrent[0] = CCS_LIQUID_V_F_MAX_CURRENT;
  2249. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetCurrent[1] = CCS_LIQUID_80_DERATING_1_CUR;
  2250. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetCurrent[2] = CCS_LIQUID_85_DERATING_2_CUR;
  2251. break;
  2252. case 'P':
  2253. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CCS_MAX_PHYSICAL_VOLTAGE;
  2254. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CCS_PANTOGRAPH_MAX_CURRENT;
  2255. break;
  2256. case 'T':
  2257. case 'D':
  2258. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CCS_MAX_PHYSICAL_VOLTAGE;
  2259. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CCS_NATURAL_T_D_MAX_CURRENT;
  2260. // Boost Mode
  2261. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CCS_MAX_PHYSICAL_VOLTAGE;
  2262. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CCS_NATURAL_T_D_BOOST_CURRENT;
  2263. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.isNeedDerating = YES;
  2264. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingIndex = 0;
  2265. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetCurrent[0] = CCS_NATURAL_T_D_BOOST_CURRENT;
  2266. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetCurrent[1] = CCS_NATURAL_T_D_MAX_CURRENT;
  2267. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].GeneralChargingData.deratingByConnOtp.deratingTargetCurrent[2] = CCS_NATURAL_T_D_85_DERATING_CUR;
  2268. break;
  2269. default:
  2270. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = 0;
  2271. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = 0;
  2272. break;
  2273. }
  2274. }
  2275. void ConnectorPantographBindingHandler(unsigned char connectorIndex, unsigned char physical)
  2276. {
  2277. switch(physical)
  2278. {
  2279. case 'P':
  2280. chargingInfo[connectorIndex]->PantographFlag = YES;
  2281. break;
  2282. default:
  2283. chargingInfo[connectorIndex]->PantographFlag = NO;
  2284. break;
  2285. }
  2286. }
  2287. void ConnectorTypeBindingHandler(unsigned char dispenserIndex, unsigned char *type, unsigned char *physicalType, unsigned char safety)
  2288. {
  2289. char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
  2290. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
  2291. {
  2292. unsigned char gunIndex = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
  2293. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParentDispensetIndex = dispenserIndex;
  2294. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.Index = gunIndex;
  2295. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.Type = type[i];
  2296. ConnectorPhysicalLimitBindingHandler(gunIndex, physicalType[i], safety);
  2297. ConnectorPantographBindingHandler(gunIndex, physicalType[i]);
  2298. LOG_INFO("Dispenser %d Connector %d type: %s, MaxVol: %4d, MaxCur: %4d, %s",
  2299. dispenserIndex + 1, gunIndex + 1, str_gun_type[type[i]],
  2300. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalVoltage,
  2301. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalCurrent,
  2302. chargingInfo[gunIndex]->PantographFlag == YES ? "Pantograph" : "Normal");
  2303. }
  2304. }
  2305. BOOL IsAvailableDispenserIndexSequence(unsigned char index)
  2306. {
  2307. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2308. {
  2309. if(i == index)
  2310. {
  2311. return true;
  2312. }
  2313. if((ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status & (1 << i)) == 0)
  2314. {
  2315. // i is not check in yet before index
  2316. return false;
  2317. }
  2318. }
  2319. return false;
  2320. }
  2321. void DispenserCheckInInfoUpdate(void)
  2322. {
  2323. unsigned char dispenser = 0, connector = 0;
  2324. BOOL change = false;
  2325. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2326. {
  2327. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  2328. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  2329. {
  2330. dispenser++;
  2331. connector += ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity;
  2332. }
  2333. }
  2334. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity != dispenser ||
  2335. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity != connector)
  2336. {
  2337. change = true;
  2338. }
  2339. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity = dispenser;
  2340. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity = connector;
  2341. if(change)
  2342. {
  2343. LOG_INFO("Total Dispenser: %d, Total Connector: %d\n",
  2344. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  2345. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity);
  2346. }
  2347. }
  2348. void SetConnectorID(unsigned char dispenserIndex, unsigned char quantity)
  2349. {
  2350. unsigned char currentQuantity = 0;
  2351. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0] = 0x00;
  2352. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[1] = 0x00;
  2353. for(int i = 0; i < dispenserIndex; i++)
  2354. {
  2355. currentQuantity += ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[i];
  2356. }
  2357. for(int i = 0; i < quantity; i++)
  2358. {
  2359. currentQuantity++;
  2360. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] = currentQuantity;
  2361. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[currentQuantity - 1].Enable = true;
  2362. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[currentQuantity - 1].GeneralChargingData.Index = currentQuantity - 1;
  2363. }
  2364. }
  2365. BOOL CheckNewDispenserSequence(unsigned char index, unsigned char quantity)
  2366. {
  2367. if(index == ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence)
  2368. {
  2369. LOG_INFO("Get New Dispenser %d, Connector Quantity: %d\n", index + 1, quantity);
  2370. ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status |= (1 << index);
  2371. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[index] = quantity;
  2372. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = index + 1;
  2373. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += quantity;
  2374. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[index] = quantity;
  2375. ShmChargerInfo->Control.SysCtrl.bits.FlashConfigChanged = true;
  2376. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  2377. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  2378. return true;
  2379. }
  2380. return false;
  2381. }
  2382. BOOL DispenserIdentificationHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex, unsigned char *modelName)
  2383. {
  2384. unsigned char quantity = 0;
  2385. unsigned char connectorType[2] = {0, 0};
  2386. unsigned char physicalType[2] = {0, 0};
  2387. unsigned char safety;
  2388. quantity = ConnectorQuantityTypeParsing(modelName, connectorType, physicalType, &safety);
  2389. if(quantity > 0)
  2390. {
  2391. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[dispenserIndex] != 0 &&
  2392. quantity != ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[dispenserIndex])
  2393. {
  2394. LOG_INFO("The same dispenser id (%d) but connector quantity not match", dispenserIndex + 1);
  2395. return false;
  2396. }
  2397. if(dispenserIndex == ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence &&
  2398. (quantity + ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity) > ShmChargerInfo->Control.MaxConnector)
  2399. {
  2400. LOG_INFO("Dispenser %d connector quantity %d over range, total quantity: %d",
  2401. dispenserIndex + 1, quantity, ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  2402. return false;
  2403. }
  2404. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus == _DS_None ||
  2405. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus == _DS_Timeout)
  2406. {
  2407. CheckNewDispenserSequence(dispenserIndex, quantity);
  2408. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus = _DS_Identification;
  2409. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity = quantity;
  2410. SetConnectorID(dispenserIndex, quantity);
  2411. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ModelName, packet->Payload.data, (packet->Header.len - 2));
  2412. ConnectorTypeBindingHandler(dispenserIndex, connectorType, physicalType, safety);
  2413. LOG_INFO("Dispenser id %d identified, Connector quantity: %d\n", dispenserIndex + 1, quantity);
  2414. DispenserCheckInInfoUpdate();
  2415. return true;
  2416. }
  2417. else
  2418. {
  2419. LOG_INFO("Conflict dispenser ID: %d", dispenserIndex + 1);
  2420. }
  2421. }
  2422. else
  2423. {
  2424. LOG_INFO("Connector quantity fail, model name: %s", modelName);
  2425. }
  2426. return false;
  2427. }
  2428. BOOL DispenserStatusCodeHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2429. {
  2430. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  2431. if(find)
  2432. {
  2433. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount = (packet->Header.len - 1) / 6;
  2434. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount > 10)
  2435. {
  2436. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount = 10;
  2437. }
  2438. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount; i++)
  2439. {
  2440. memcpy(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCode[i][0],
  2441. &packet->Payload.data[i * 6], 6);
  2442. }
  2443. /*
  2444. BOOL needUpdate = FALSE;
  2445. // check is there new status code
  2446. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount; i++)
  2447. {
  2448. if(strcmp(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCode[i][0],
  2449. &LastWarningInfo[packet->Header.id - 1].WarningCode[i][0]) == 0)
  2450. {
  2451. needUpdate = TRUE;
  2452. break;
  2453. }
  2454. }
  2455. if(needUpdate)
  2456. {
  2457. memcpy(&LastWarningInfo[packet->Header.id - 1], &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo, sizeof(struct WARNING_CODE_INFO));
  2458. }
  2459. */
  2460. char strDispenserStatus[128];
  2461. sprintf(strDispenserStatus, "Dispenser id %d, Status Code Len: %d", packet->Header.id, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount);
  2462. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount > 0)
  2463. {
  2464. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount; i++)
  2465. {
  2466. char strTemp[16];
  2467. sprintf(strTemp, ", %s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCode[i]);
  2468. strcat(strDispenserStatus, strTemp);
  2469. }
  2470. }
  2471. LOG_INFO("%s", strDispenserStatus);
  2472. }
  2473. else
  2474. {
  2475. }
  2476. return find;
  2477. }
  2478. BOOL ConnectorChargingCapabilityHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2479. {
  2480. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  2481. BOOL done = false;
  2482. if(find)
  2483. {
  2484. done = true;
  2485. }
  2486. return done;
  2487. }
  2488. BOOL ConnectorChargingTargetHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2489. {
  2490. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  2491. BOOL done = false;
  2492. unsigned short voltage = 0, current = 0, power = 0;
  2493. if(find)
  2494. {
  2495. voltage = ((packet->Payload.data[0] << 8) + packet->Payload.data[1]);
  2496. current = ((packet->Payload.data[2] << 8) + packet->Payload.data[3]);
  2497. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage != voltage ||
  2498. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent != current)
  2499. {
  2500. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage = voltage;
  2501. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent = current;
  2502. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.OutputLimitEnable)
  2503. {
  2504. LOG_INFO("Connector %d Remote Voltage: %d, Remote Current: %d", packet->Header.id, voltage, current);
  2505. }
  2506. }
  2507. RestrictAbsoluteLimit(packet->Header.id - 1, &power, &voltage, &current);
  2508. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage != voltage ||
  2509. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent != current)
  2510. {
  2511. if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.OutputLimitEnable)
  2512. {
  2513. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.OutputLimitEnable = true;
  2514. LOG_INFO("Connector %d Remote Voltage: %d, Remote Current: %d", packet->Header.id,
  2515. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage,
  2516. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent);
  2517. LOG_INFO("Connector %d Limit Voltage: %d, Limit Current: %d", packet->Header.id, voltage, current);
  2518. }
  2519. }
  2520. else
  2521. {
  2522. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.OutputLimitEnable = false;
  2523. }
  2524. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteLimitVoltage = voltage;
  2525. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteLimitCurrent = current;
  2526. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus == S_PREPARING_FOR_EVSE ||
  2527. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus == S_CHARGING)
  2528. {
  2529. float targetVol = (float)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteLimitVoltage / 10);
  2530. float targetCur = (float)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteLimitCurrent / 10);
  2531. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage != targetVol ||
  2532. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent != targetCur)
  2533. {
  2534. LOG_INFO("Connector %d Target Voltage: %d V, Current: %d A",
  2535. packet->Header.id, (int)(targetVol), (int)(targetCur));
  2536. }
  2537. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage = targetVol;
  2538. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent = targetCur;
  2539. done = true;
  2540. }
  2541. else
  2542. {
  2543. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage != 0 ||
  2544. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent != 0)
  2545. {
  2546. LOG_INFO("Connector %d Not Charging Status, Set Voltage & Current Fail", packet->Header.id);
  2547. }
  2548. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage = 0;
  2549. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent = 0;
  2550. }
  2551. }
  2552. else
  2553. {
  2554. }
  2555. return done;
  2556. }
  2557. unsigned char FirmwareUpgradeHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2558. {
  2559. unsigned char UpgradeResponse = _R_NoUpgrade;
  2560. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0] == packet->Header.id)
  2561. {
  2562. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateRequest)
  2563. {
  2564. if(packet->Payload.data[0] == 0)
  2565. {
  2566. UpgradeResponse = _R_NeedUpgrade;
  2567. }
  2568. else
  2569. {
  2570. if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateConfirm)
  2571. {
  2572. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateConfirm = true;
  2573. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateRequest = false;
  2574. LOG_INFO("Dispenser %d Updating...", dispenserIndex + 1);
  2575. }
  2576. }
  2577. }
  2578. else
  2579. {
  2580. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateConfirm)
  2581. {
  2582. if(packet->Payload.data[0] == 0)
  2583. {
  2584. if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateCompleted)
  2585. {
  2586. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateCompleted = true;
  2587. LOG_INFO("Dispenser %d Upgrade Completed", dispenserIndex + 1);
  2588. }
  2589. }
  2590. }
  2591. }
  2592. }
  2593. return UpgradeResponse;
  2594. }
  2595. BOOL ConnectorPlugInHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2596. {
  2597. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  2598. if(find)
  2599. {
  2600. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.ConnectorPlugIn != packet->Payload.data[0])
  2601. {
  2602. LOG_INFO("Connector %d %s", packet->Header.id, packet->Payload.data[0] == _PIS_PluggedIn ? "Pluged In" : "Un Plugged");
  2603. }
  2604. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.ConnectorPlugIn = packet->Payload.data[0];
  2605. }
  2606. else
  2607. {
  2608. }
  2609. return find;
  2610. }
  2611. BOOL ConnectorStateHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2612. {
  2613. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  2614. unsigned char ConnectionState;
  2615. unsigned char *AlarmCode;
  2616. unsigned char GunTemp = 0;
  2617. unsigned char ChillerTemp = 0;
  2618. unsigned char plugin = 0;
  2619. unsigned char noAlarm[6];
  2620. char *str_status[] = {
  2621. STR_MODE_BOOT,
  2622. STR_MODE_IDLE,
  2623. STR_MODE_AUTHORIZING,
  2624. STR_MODE_REASSIGN_CHECK,
  2625. STR_MODE_REASSIGN,
  2626. STR_MODE_PREPARNING,
  2627. STR_MODE_PREPARING_EV,
  2628. STR_MODE_PREPARING_EVSE,
  2629. STR_MODE_CHARGING,
  2630. STR_MODE_TERMINATING,
  2631. STR_MODE_COMPLETE,
  2632. STR_MODE_ALARM,
  2633. STR_MODE_FAULT,
  2634. STR_MODE_RESERVATION,
  2635. STR_MODE_BOOKING,
  2636. STR_MODE_MAINTAIN,
  2637. STR_MODE_DEBUG,
  2638. STR_MODE_CCS_ST0,
  2639. STR_MODE_CCS_ST1,
  2640. STR_MODE_UPDATE,
  2641. STR_MODE_NONE};
  2642. memset(noAlarm, 0x00, 6);
  2643. if(find)
  2644. {
  2645. ConnectionState = packet->Payload.data[0];
  2646. AlarmCode = packet->Header.len >= 8 ? &packet->Payload.data[1] : &noAlarm[0];
  2647. GunTemp = packet->Header.len >= 10 ? packet->Payload.data[7] : GunTemp;
  2648. ChillerTemp = packet->Header.len >= 10 ? packet->Payload.data[8] : ChillerTemp;
  2649. chargingInfo[packet->Header.id - 1]->ConnectorTemp = GunTemp;
  2650. chargingInfo[packet->Header.id - 1]->ChillerTemp = ChillerTemp;
  2651. plugin = packet->Header.len >= 11 ? packet->Payload.data[9] : plugin;
  2652. if(packet->Header.len >= 11)
  2653. {
  2654. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.ConnectorPlugIn != plugin)
  2655. {
  2656. LOG_INFO("Gun %d %s", packet->Header.id, plugin == _PIS_PluggedIn ? "Pluged In" : "Un Plugged");
  2657. }
  2658. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.ConnectorPlugIn = plugin;
  2659. }
  2660. if(packet->Header.len >= 15)
  2661. {
  2662. float meterValue = 0;
  2663. char *ptr = (char *)&meterValue;
  2664. *(ptr + 0) = packet->Payload.data[13];
  2665. *(ptr + 1) = packet->Payload.data[12];
  2666. *(ptr + 2) = packet->Payload.data[11];
  2667. *(ptr + 3) = packet->Payload.data[10];
  2668. ShmChargerInfo->MeterValue[packet->Header.id - 1].GunConsumption = meterValue;
  2669. }
  2670. if(packet->Header.len >= 16)
  2671. {
  2672. if(packet->Payload.data[14] >= S_NONE)
  2673. {
  2674. packet->Payload.data[14] = S_NONE;
  2675. }
  2676. if(ShmChargerInfo->Connector[packet->Header.id - 1].Status != packet->Payload.data[14])
  2677. {
  2678. LOG_INFO("Gun %d SystemStatus [%s]", packet->Header.id, str_status[packet->Payload.data[14]]);
  2679. }
  2680. ShmChargerInfo->Connector[packet->Header.id - 1].Status = packet->Payload.data[14];
  2681. }
  2682. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus != ConnectionState)
  2683. {
  2684. LOG_INFO("Connector %d Remote Status: %d", packet->Header.id, ConnectionState);
  2685. switch(ConnectionState)
  2686. {
  2687. case _CRS_Idle:
  2688. case _CRS_Terminating:
  2689. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Preparing ||
  2690. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Charging)
  2691. {
  2692. if(chargingInfo[packet->Header.id - 1]->SystemStatus != S_IDLE)
  2693. {
  2694. LOG_INFO("*********** Connector %d Set Normal Stop Flag ***********\n", packet->Header.id);
  2695. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.NormalStopRequest = true;
  2696. }
  2697. }
  2698. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Idle)
  2699. {
  2700. if(ConnectionState == _CRS_Terminating)
  2701. {
  2702. if(chargingInfo[packet->Header.id - 1]->SystemStatus == S_RESERVATION)
  2703. {
  2704. chargingInfo[packet->Header.id - 1]->ReservationId = -1;
  2705. LOG_INFO("*********** Connector %d Clean ReservationId ***********\n", packet->Header.id);
  2706. }
  2707. }
  2708. else if(chargingInfo[packet->Header.id - 1]->SystemStatus == S_AUTHORIZING)
  2709. {
  2710. if(_GunSystemStatus[packet->Header.id - 1] != ShmChargerInfo->Connector[packet->Header.id - 1].Status &&
  2711. ShmChargerInfo->Connector[packet->Header.id - 1].Status == S_IDLE)
  2712. {
  2713. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.NeedCleanAuthorizeInfo = true;
  2714. LOG_INFO("Connector %d Return Idle, Need Clean Authorize Info", packet->Header.id);
  2715. }
  2716. }
  2717. }
  2718. break;
  2719. case _CRS_Alarm:
  2720. memcpy(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemotenAlarmCode, AlarmCode, 6);
  2721. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Idle)
  2722. {
  2723. LOG_INFO("*********** Connector id %d Set Fault Status [%s] ***********", packet->Header.id,
  2724. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemotenAlarmCode);
  2725. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.FaultStatusRequest = true;
  2726. }
  2727. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Preparing ||
  2728. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Charging)
  2729. {
  2730. LOG_INFO("*********** Connector id %d Set Alarm Stop Flag [%s] ***********", packet->Header.id,
  2731. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemotenAlarmCode);
  2732. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.AlarmStopRequest = true;
  2733. }
  2734. break;
  2735. default:
  2736. break;
  2737. }
  2738. }
  2739. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus = ConnectionState;
  2740. _GunSystemStatus[packet->Header.id - 1] = ShmChargerInfo->Connector[packet->Header.id - 1].Status;
  2741. }
  2742. else
  2743. {
  2744. }
  2745. return true;
  2746. }
  2747. bool IsEnableForceCharging(byte dispenserIndex, byte connectorId)
  2748. {
  2749. if(connectorId != AUTO_GUN_SELECTION_ID)
  2750. {
  2751. return ShmChargerInfo->Control.FCharging[connectorId - 1].FCtrl.bits.EnableForceCharging ? true : false;
  2752. }
  2753. else
  2754. {
  2755. int gun = 0;
  2756. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
  2757. {
  2758. gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
  2759. if(ShmChargerInfo->Control.FCharging[gun].FCtrl.bits.EnableForceCharging)
  2760. {
  2761. return true;
  2762. }
  2763. }
  2764. }
  2765. return false;
  2766. }
  2767. AuthorizingInfoData preGunAuthInfo[GENERAL_GUN_QUANTITY];
  2768. AuthorizingInfoData preDispenserAuthInfo[GENERAL_GUN_QUANTITY];
  2769. unsigned char UserIDHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2770. {
  2771. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  2772. DispenserAck_Status authorize = _DAS_Wait;
  2773. unsigned char CardNumber[32];
  2774. //unsigned char *result;
  2775. AuthorizingInfoData *AuthInfo;
  2776. AuthorizingInfoData *preAuthInfo;
  2777. int length = 0;
  2778. int cardNumberLength = 0;
  2779. unsigned char idType = _Type_ISO14443;
  2780. char *str_IdType[] = {
  2781. STR_ID_TYPE_CENTRAL,
  2782. STR_ID_TYPE_EMAID,
  2783. STR_ID_TYPE_ISO14443,
  2784. STR_ID_TYPE_ISO15693,
  2785. STR_ID_TYPE_KEYCODE,
  2786. STR_ID_TYPE_LOCAL,
  2787. STR_ID_TYPE_MAC_ADDRESS,
  2788. STR_ID_TYPE_NO_AUTHORIZATION};
  2789. if(find || packet->Header.id == AUTO_GUN_SELECTION_ID)
  2790. {
  2791. if(IsEnableForceCharging(dispenserIndex, packet->Header.id))
  2792. {
  2793. return _DAS_NotAllowed;
  2794. }
  2795. length = packet->Header.len - 1;
  2796. memset(CardNumber, 0x00, sizeof(CardNumber));
  2797. memcpy(CardNumber, packet->Payload.data, length);
  2798. cardNumberLength = strlen((char *)&CardNumber);
  2799. if(length - cardNumberLength >= 2)
  2800. {
  2801. idType = packet->Payload.data[cardNumberLength + 1];
  2802. if(idType > _Type_NoAuthorization)
  2803. {
  2804. idType = _Type_ISO14443;
  2805. }
  2806. }
  2807. if(packet->Header.id != AUTO_GUN_SELECTION_ID)
  2808. {
  2809. //result = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].AuthorizingResult;
  2810. AuthInfo = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].AuthInfo;
  2811. preAuthInfo = &preGunAuthInfo[packet->Header.id - 1];
  2812. }
  2813. else
  2814. {
  2815. //result = &ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].AuthResult;
  2816. AuthInfo = &ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].AuthInfo;
  2817. preAuthInfo = &preDispenserAuthInfo[dispenserIndex];
  2818. }
  2819. //if(*result == _AuthResult_Valid)
  2820. if(AuthInfo->AuthResult == _AuthResult_Valid)
  2821. {
  2822. if(preAuthInfo->AuthResult != AuthInfo->AuthResult)
  2823. {
  2824. LOG_INFO("Dispenser %d Target %d user id %s authorizing ok", dispenserIndex + 1, packet->Header.id, CardNumber);
  2825. }
  2826. authorize = _DAS_Allowed;
  2827. }
  2828. //else if(*result == _AuthResult_Invalid)
  2829. else if(AuthInfo->AuthResult == _AuthResult_Invalid)
  2830. {
  2831. if(preAuthInfo->AuthResult != AuthInfo->AuthResult)
  2832. {
  2833. LOG_INFO("Dispenser %d Target %d user id %s authorizing fail", dispenserIndex + 1, packet->Header.id, CardNumber);
  2834. }
  2835. authorize = _DAS_NotAllowed;
  2836. }
  2837. else
  2838. {
  2839. if(AuthInfo->AuthStatus == _AuthorizeStatus_Idle && AuthInfo->AuthRequest == NO)
  2840. {
  2841. strcpy((char *)&AuthInfo->AuthId, (char *)&CardNumber);
  2842. AuthInfo->AuthTarget = packet->Header.id;
  2843. AuthInfo->AuthRequest = YES;
  2844. AuthInfo->AuthIdType = idType;
  2845. if(AuthInfo->AuthTarget != AUTO_GUN_SELECTION_ID)
  2846. {
  2847. LOG_INFO("Gun %d user id [%s] type [%s] need authorize",
  2848. packet->Header.id, CardNumber, str_IdType[idType]);
  2849. }
  2850. else
  2851. {
  2852. LOG_INFO("Dispenser %d user id [%s] type [%s] need authorize",
  2853. dispenserIndex + 1, CardNumber, str_IdType[idType]);
  2854. }
  2855. authorize = _DAS_Wait;
  2856. }
  2857. else
  2858. {
  2859. authorize = _DAS_Wait;
  2860. }
  2861. }
  2862. preAuthInfo->AuthResult = AuthInfo->AuthResult;
  2863. }
  2864. else
  2865. {
  2866. authorize = _DAS_NotAllowed;
  2867. }
  2868. return authorize;
  2869. }
  2870. unsigned char ChargingPermissionHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2871. {
  2872. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  2873. DispenserAck_Status permission = _DAS_Wait;
  2874. if(find)
  2875. {
  2876. switch(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus)
  2877. {
  2878. case S_IDLE:
  2879. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Idle ||
  2880. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Preparing)
  2881. {
  2882. permission = _DAS_Wait;
  2883. }
  2884. else
  2885. {
  2886. permission = _DAS_NotAllowed;
  2887. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
  2888. {
  2889. LOG_INFO("Cabinet status idle, not allow Dispenser %d Connector %d Charging",
  2890. dispenserIndex + 1, packet->Header.id);
  2891. }
  2892. }
  2893. break;
  2894. case S_AUTHORIZING:
  2895. case S_REASSIGN_CHECK:
  2896. case S_REASSIGN:
  2897. case S_PREPARNING:
  2898. permission = _DAS_Wait;
  2899. break;
  2900. case S_PREPARING_FOR_EV:
  2901. if(chargingInfo[packet->Header.id - 1]->ChargingStopFlag.bits.RemoteStop ||
  2902. chargingInfo[packet->Header.id - 1]->ChargingStopFlag.bits.UnlockStop)
  2903. {
  2904. permission = _DAS_NotAllowed;
  2905. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
  2906. {
  2907. LOG_INFO("RemoteStop or UnlockStop, not allow dispenser index %d connector id %d preparing to charge", dispenserIndex, packet->Header.id);
  2908. }
  2909. }
  2910. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus >= _CRS_Preparing &&
  2911. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus <= _CRS_Charging)
  2912. {
  2913. if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.PermissionRequest)
  2914. {
  2915. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.PermissionRequest = true;
  2916. LOG_INFO("Allow Dispenser %d Connector %d start preparing to charge", dispenserIndex + 1, packet->Header.id);
  2917. }
  2918. permission = _DAS_Allowed;
  2919. }
  2920. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Terminating)
  2921. {
  2922. permission = _DAS_NotAllowed;
  2923. LOG_INFO("Dispenser Terminating, Not allow dispenser index %d connector id %d preparing to charge", dispenserIndex, packet->Header.id);
  2924. }
  2925. else
  2926. {
  2927. // keep wait
  2928. }
  2929. break;
  2930. case S_PREPARING_FOR_EVSE:
  2931. permission = _DAS_Allowed;
  2932. break;
  2933. case S_CHARGING:
  2934. if(chargingInfo[packet->Header.id - 1]->ChargingStopFlag.bits.RemoteStop ||
  2935. chargingInfo[packet->Header.id - 1]->ChargingStopFlag.bits.UnlockStop)
  2936. {
  2937. permission = _DAS_NotAllowed;
  2938. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
  2939. {
  2940. LOG_INFO("RemoteStop or UnlockStop, not allow dispenser index %d connector id %d charging", dispenserIndex, packet->Header.id);
  2941. }
  2942. }
  2943. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Preparing ||
  2944. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Charging)
  2945. {
  2946. permission = _DAS_Allowed;
  2947. }
  2948. else
  2949. {
  2950. permission = _DAS_NotAllowed;
  2951. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
  2952. {
  2953. LOG_INFO("Dispenser index %d connector id %d remote status not in charging mode", dispenserIndex, packet->Header.id);
  2954. }
  2955. }
  2956. break;
  2957. case S_TERMINATING:
  2958. case S_COMPLETE:
  2959. case S_ALARM:
  2960. case S_FAULT:
  2961. case S_RESERVATION:
  2962. case S_MAINTAIN:
  2963. permission = _DAS_NotAllowed;
  2964. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
  2965. {
  2966. LOG_INFO("Cabinet status(%d) not match, not allow dispenser index %d connector id %d charging",
  2967. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus,
  2968. dispenserIndex, packet->Header.id);
  2969. }
  2970. break;
  2971. default:
  2972. break;
  2973. }
  2974. if(IsEnableForceCharging(dispenserIndex, packet->Header.id))
  2975. {
  2976. // not allow to charging when EnableForceCharging is true
  2977. permission = _DAS_NotAllowed;
  2978. }
  2979. }
  2980. else
  2981. {
  2982. LOG_INFO("Dispenser index %d Connector id %d not found", dispenserIndex, packet->Header.id);
  2983. permission = _DAS_NotAllowed;
  2984. }
  2985. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission = permission;
  2986. // LOG_INFO("Dispenser %d Permission %s, Gun Status: %d, Connector Status: %d, Wait Plug: %d, PlugIn: %d, Available: %d, Order: %d", dispenserIndex, permission == true ? "OK" : "NG",
  2987. // ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus,
  2988. // ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus,
  2989. // ShmSysConfigAndInfo->SysInfo.WaitForPlugit,
  2990. // ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.ConnectorPlugIn,
  2991. // ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.IsAvailable,
  2992. // ShmSysConfigAndInfo->SysInfo.OrderCharging);
  2993. return permission;
  2994. }
  2995. BOOL MiscControlHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  2996. {
  2997. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  2998. BOOL done = false;
  2999. if(find)
  3000. {
  3001. done = true;
  3002. }
  3003. return done;
  3004. }
  3005. unsigned char DispenserWriteCsuVersionInfoHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3006. {
  3007. char version[32];
  3008. BOOL writeVersion = FALSE, showVersion = FALSE;;
  3009. memcpy(version, &packet->Payload.data[0], 32);
  3010. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuBootLoadFwRev, version) != 0)
  3011. {
  3012. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuBootLoadFwRev, version, 32);
  3013. showVersion = true;
  3014. }
  3015. memcpy(version, &packet->Payload.data[32], 32);
  3016. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuKernelFwRev, version) != 0)
  3017. {
  3018. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuKernelFwRev, version, 32);
  3019. showVersion = true;
  3020. }
  3021. memcpy(version, &packet->Payload.data[64], 32);
  3022. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuRootFsFwRev, version) != 0)
  3023. {
  3024. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuRootFsFwRev, version, 32);
  3025. showVersion = true;
  3026. }
  3027. memcpy(version, &packet->Payload.data[96], 32);
  3028. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuPrimFwRev, version) != 0)
  3029. {
  3030. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuPrimFwRev, version, 32);
  3031. showVersion = true;
  3032. }
  3033. if(showVersion)
  3034. {
  3035. LOG_INFO("********** Dispenser id %d: Csu Version information **********", dispenserIndex + 1);
  3036. LOG_INFO("********** CsuBootLoadRev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuBootLoadFwRev);
  3037. LOG_INFO("********** CsuKernelFwRev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuKernelFwRev);
  3038. LOG_INFO("********** CsuRootFsFwRev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuRootFsFwRev);
  3039. LOG_INFO("********** CsuPrimFwRev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].CsuPrimFwRev);
  3040. }
  3041. writeVersion = TRUE;
  3042. return writeVersion;
  3043. }
  3044. unsigned char DispenserWriteOtherVersionInfoHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3045. {
  3046. char version[32];
  3047. BOOL writeVersion = FALSE, showVersion = FALSE;;
  3048. memcpy(version, &packet->Payload.data[0], 32);
  3049. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].FanModuleFwRev, version) != 0)
  3050. {
  3051. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].FanModuleFwRev, version, 32);
  3052. showVersion = true;
  3053. }
  3054. memcpy(version, &packet->Payload.data[32], 32);
  3055. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].RelayModuleFwRev, version) != 0)
  3056. {
  3057. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].RelayModuleFwRev, version, 32);
  3058. showVersion = true;
  3059. }
  3060. memcpy(version, &packet->Payload.data[64], 32);
  3061. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Connector1FwRev, version) != 0)
  3062. {
  3063. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Connector1FwRev, version, 32);
  3064. showVersion = true;
  3065. }
  3066. memcpy(version, &packet->Payload.data[96], 32);
  3067. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Connector2FwRev, version) != 0)
  3068. {
  3069. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Connector2FwRev, version, 32);
  3070. showVersion = true;
  3071. }
  3072. memcpy(version, &packet->Payload.data[128], 32);
  3073. if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LedModuleFwRev, version) != 0)
  3074. {
  3075. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LedModuleFwRev, version, 32);
  3076. showVersion = true;
  3077. }
  3078. if(showVersion)
  3079. {
  3080. LOG_INFO("********** Dispenser id %d: Other Version information **********", dispenserIndex + 1);
  3081. LOG_INFO("********** FanModuleFwRev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].FanModuleFwRev);
  3082. LOG_INFO("********** RelayModuleRev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].RelayModuleFwRev);
  3083. LOG_INFO("********** Connector1Rev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Connector1FwRev);
  3084. LOG_INFO("********** Connector2Rev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Connector2FwRev);
  3085. LOG_INFO("********** LedModuleFwRev: %32s ***", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LedModuleFwRev);
  3086. }
  3087. writeVersion = TRUE;
  3088. return writeVersion;
  3089. }
  3090. unsigned char DispenserWriteChargingInfoHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3091. {
  3092. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3093. unsigned char gun = 0;
  3094. if(find)
  3095. {
  3096. gun = packet->Header.id - 1;
  3097. unsigned short diffVoltage = 0, diffCurrent = 0;
  3098. unsigned short voltage = (packet->Payload.data[0] << 8) + (packet->Payload.data[1]);
  3099. unsigned short current = (packet->Payload.data[2] << 8) + (packet->Payload.data[3]);
  3100. //unsigned int time = (packet->Payload.data[4] << 24) + (packet->Payload.data[5] << 16) + (packet->Payload.data[6] << 8) + (packet->Payload.data[7]);
  3101. unsigned char soc = (packet->Payload.data[8]);
  3102. diffVoltage = voltage >= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingVoltage ?
  3103. voltage - ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingVoltage :
  3104. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingVoltage - voltage;
  3105. diffCurrent = current >= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingCurrent ?
  3106. current - ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingCurrent :
  3107. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingCurrent - current;
  3108. if(diffVoltage > 10 || diffCurrent > 10 || ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteSoc != soc)
  3109. {
  3110. LOG_INFO("Connector %d Charging Info: Voltage: %4d.%d V, Current: %3d.%d A, Soc: %3d, Temp: %3d, Chiller: %3d",
  3111. packet->Header.id, (voltage / 10), (voltage % 10), (current / 10), (current % 10), soc,
  3112. chargingInfo[gun]->ConnectorTemp - 60, chargingInfo[gun]->ChillerTemp - 60);
  3113. }
  3114. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingVoltage = voltage;
  3115. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingCurrent = current;
  3116. //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteRemainChargingDuration = time;
  3117. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteSoc = soc;
  3118. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].GeneralChargingData.EvBatterySoc = soc;
  3119. }
  3120. else
  3121. {
  3122. }
  3123. return find;
  3124. }
  3125. unsigned char ReadQrCodeAndDateHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3126. {
  3127. BOOL find = TRUE;
  3128. return find;
  3129. }
  3130. unsigned char WriteWaitPlugInHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3131. {
  3132. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3133. if(find)
  3134. {
  3135. unsigned char StartWait = packet->Payload.data[0];
  3136. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus == S_AUTHORIZING)
  3137. {
  3138. if(StartWait)
  3139. {
  3140. if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.StartWaitPlug)
  3141. {
  3142. LOG_INFO("Connector %d Start Wait Plug In", packet->Header.id);
  3143. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.SwipeRfidConfirm = true;
  3144. }
  3145. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.StartWaitPlug = true;
  3146. }
  3147. else
  3148. {
  3149. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.StartWaitPlug)
  3150. {
  3151. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus != S_IDLE)
  3152. {
  3153. LOG_INFO("Connector %d Stop Wait Plug In", packet->Header.id);
  3154. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.NeedCleanAuthorizeInfo = true;
  3155. }
  3156. }
  3157. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.StartWaitPlug = false;
  3158. }
  3159. }
  3160. else
  3161. {
  3162. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.StartWaitPlug = false;
  3163. }
  3164. }
  3165. else
  3166. {
  3167. }
  3168. return find;
  3169. }
  3170. unsigned char GroundFaultDetectionHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3171. {
  3172. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3173. unsigned char gun = 0;
  3174. if(find)
  3175. {
  3176. gun = packet->Header.id - 1;
  3177. unsigned char enable = packet->Payload.data[0];
  3178. if(chargingInfo[gun]->PantographFlag == YES)
  3179. {
  3180. if(enable == _GFD_Enable &&
  3181. (chargingInfo[gun]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gun]->SystemStatus <= S_CHARGING))
  3182. {
  3183. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Parameter.bits.GfdDetection != _GFD_Enable)
  3184. {
  3185. LOG_INFO("Connector %d Gfd Detection Start", gun + 1);
  3186. }
  3187. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Parameter.bits.GfdDetection = _GFD_Enable;
  3188. }
  3189. else
  3190. {
  3191. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Parameter.bits.GfdDetection != _GFD_Disable)
  3192. {
  3193. LOG_INFO("Connector %d Gfd Detection Stop", gun + 1);
  3194. }
  3195. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Parameter.bits.GfdDetection = _GFD_Disable;
  3196. }
  3197. }
  3198. }
  3199. else
  3200. {
  3201. }
  3202. return find;
  3203. }
  3204. unsigned char GetCabinetCSUVersionHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3205. {
  3206. return true;
  3207. }
  3208. unsigned char GetCabinetOtherVersionHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3209. {
  3210. return true;
  3211. }
  3212. unsigned char GetPsuQuantityHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
  3213. {
  3214. return true;
  3215. }
  3216. unsigned char GetPsuVersionHandler(struct PACKET_STRUCTURE *packet, int *psuIndex)
  3217. {
  3218. *psuIndex = 0;
  3219. if(packet->Payload.data[0] <= ShmPsuData->SystemInitialPsuQuantity && packet->Payload.data[0] > 0)
  3220. {
  3221. *psuIndex = packet->Payload.data[0] - 1;
  3222. }
  3223. return true;
  3224. }
  3225. unsigned char GetReservationHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex, unsigned char *reservation)
  3226. {
  3227. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3228. unsigned char gun = 0;
  3229. if(find)
  3230. {
  3231. gun = packet->Header.id - 1;
  3232. *reservation = chargingInfo[gun]->SystemStatus == S_RESERVATION ? YES : NO;
  3233. }
  3234. else
  3235. {
  3236. }
  3237. return find;
  3238. }
  3239. unsigned char DispenserReqHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3240. {
  3241. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3242. unsigned char gun = 0;
  3243. if(find)
  3244. {
  3245. gun = packet->Header.id - 1;
  3246. int count = 0;
  3247. struct MISC_COMMAND connector_req;
  3248. while((packet->Header.len - 1) > (count * 6))
  3249. {
  3250. if(((packet->Header.len - 1) - (count * 6)) % 6 == 0)
  3251. {
  3252. memset(&connector_req, 0x00, sizeof(struct MISC_COMMAND));
  3253. connector_req.Command = (packet->Payload.data[0 + (count * 6)] << 8) | packet->Payload.data[1 + (count * 6)];
  3254. connector_req.Value = (packet->Payload.data[2 + (count * 6)] << 24) |
  3255. (packet->Payload.data[3 + (count * 6)] << 16) |
  3256. (packet->Payload.data[4 + (count * 6)] << 8) |
  3257. (packet->Payload.data[5 + (count * 6)]);
  3258. count++;
  3259. switch(connector_req.Command)
  3260. {
  3261. case _DisReq_ChargingCancel:
  3262. if(connector_req.Value == YES)
  3263. {
  3264. if(!ShmChargerInfo->ConnectorActReq[gun].Flag.bits.ChargingCancel)
  3265. {
  3266. LOG_INFO("Gun %d ChargingCancel Request", gun + 1);
  3267. }
  3268. ShmChargerInfo->ConnectorActReq[gun].Flag.bits.ChargingCancel = true;
  3269. }
  3270. break;
  3271. default:
  3272. break;
  3273. }
  3274. }
  3275. else
  3276. {
  3277. break;
  3278. }
  3279. }
  3280. }
  3281. else
  3282. {
  3283. }
  3284. return find;
  3285. }
  3286. unsigned char GetRemoteStartNoIDHandler(struct PACKET_STRUCTURE *packet, unsigned char *state)
  3287. {
  3288. *state = ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId ? YES : NO;
  3289. return true;
  3290. }
  3291. unsigned char GetRefundAmountHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3292. {
  3293. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3294. if(find)
  3295. {
  3296. }
  3297. else
  3298. {
  3299. }
  3300. return find;
  3301. }
  3302. unsigned char GetPrepaymentHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3303. {
  3304. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3305. if(find)
  3306. {
  3307. }
  3308. else
  3309. {
  3310. }
  3311. return find;
  3312. }
  3313. unsigned char GetPaymentFailReasonHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3314. {
  3315. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3316. if(find)
  3317. {
  3318. }
  3319. else
  3320. {
  3321. }
  3322. return find;
  3323. }
  3324. unsigned char GetQRCodeRequestHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3325. {
  3326. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3327. if(find)
  3328. {
  3329. }
  3330. else
  3331. {
  3332. }
  3333. return find;
  3334. }
  3335. unsigned char GetStationInfoHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3336. {
  3337. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3338. if(find)
  3339. {
  3340. }
  3341. else
  3342. {
  3343. if(packet->Header.id == AUTO_GUN_SELECTION_ID)
  3344. {
  3345. find = true;
  3346. }
  3347. }
  3348. return find;
  3349. }
  3350. unsigned char WriteDeductResultHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3351. {
  3352. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3353. unsigned char gun = 0;
  3354. DeductResultInfoData deduct;
  3355. bool done = false;
  3356. char appNo[10];
  3357. char vemData[65];
  3358. char cardNo[21];
  3359. char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
  3360. memset(appNo, 0x00, sizeof(appNo));
  3361. memset(vemData, 0x00, sizeof(vemData));
  3362. memset(cardNo, 0x00, sizeof(cardNo));
  3363. if(find || packet->Header.id == AUTO_GUN_SELECTION_ID)
  3364. {
  3365. memset(&deduct, 0x00, sizeof(DeductResultInfoData));
  3366. deduct.ConnectorId = packet->Header.id != AUTO_GUN_SELECTION_ID ?
  3367. packet->Header.id : ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0];
  3368. gun = packet->Header.id - 1;
  3369. deduct.DeductResult = packet->Payload.data[0];
  3370. deduct.IsDonateInvoice = packet->Payload.data[1] == YES ? YES : NO;
  3371. deduct.TransactionId = (packet->Payload.data[2] << 24) +
  3372. (packet->Payload.data[3] << 16) +
  3373. (packet->Payload.data[4] << 8) +
  3374. packet->Payload.data[5];
  3375. deduct.DeductAmount = (packet->Payload.data[6] << 24) +
  3376. (packet->Payload.data[7] << 16) +
  3377. (packet->Payload.data[8] << 8) +
  3378. packet->Payload.data[9];
  3379. memcpy(deduct.ApprovalNumber, (char *)&packet->Payload.data[10], sizeof(deduct.ApprovalNumber));
  3380. memcpy(appNo, deduct.ApprovalNumber, sizeof(deduct.ApprovalNumber));
  3381. if(packet->Header.len >= 84)
  3382. {
  3383. memcpy(deduct.VemData, (char *)&packet->Payload.data[19], sizeof(deduct.VemData));
  3384. memcpy(vemData, deduct.VemData, sizeof(deduct.VemData));
  3385. }
  3386. if(packet->Header.len >= 104)
  3387. {
  3388. memcpy(deduct.creditNo, (char *)&packet->Payload.data[83], sizeof(deduct.creditNo));
  3389. memcpy(cardNo, deduct.creditNo, sizeof(deduct.creditNo));
  3390. }
  3391. if(deduct.DeductResult == _Deduct_Fail || deduct.DeductResult == _Deduct_Pass)
  3392. {
  3393. if(packet->Header.id != AUTO_GUN_SELECTION_ID)
  3394. {
  3395. if(deduct.TransactionId == ShmChargerInfo->DeductResultReq[gun].TransactionId)
  3396. {
  3397. if(!ShmChargerInfo->DeductResultReq[gun].DeductReq)
  3398. {
  3399. memcpy(&ShmChargerInfo->DeductResultReq[gun], &deduct, sizeof(DeductResultInfoData));
  3400. ShmChargerInfo->DeductResultReq[gun].DeductReq = YES;
  3401. done = true;
  3402. }
  3403. LOG_INFO("Gun %d [%s] %s", gun + 1, str_ReaderStatus[deduct.DeductResult], done ? "Done" : "Wait");
  3404. LOG_INFO("Gun %d TxId: [%d], Card: [%s], [%s], Amount: [%d.%02d], Donate: [%s], ApprovalNo: [%s], VemData: [%s]",
  3405. gun + 1,
  3406. deduct.TransactionId,
  3407. cardNo,
  3408. str_ReaderStatus[deduct.DeductResult],
  3409. (deduct.DeductAmount / 100), (deduct.DeductAmount % 100),
  3410. deduct.IsDonateInvoice ? "Yes" : "No",
  3411. appNo,
  3412. vemData);
  3413. return done;
  3414. }
  3415. }
  3416. if(!done)
  3417. {
  3418. if(!ShmChargerInfo->ReDeductReq.DeductReq)
  3419. {
  3420. memcpy(&ShmChargerInfo->ReDeductReq, &deduct, sizeof(DeductResultInfoData));
  3421. ShmChargerInfo->ReDeductReq.DeductReq = YES;
  3422. done = true;
  3423. }
  3424. LOG_INFO("Gun %d%s ReDeduct %s",
  3425. gun + 1, packet->Header.id != AUTO_GUN_SELECTION_ID ? "" : "(Default)", done ? "Done" : "Wait");
  3426. LOG_INFO("Gun %d ReDeduct TxId: [%d], Card: [%s], [%s], Amount: [%d.%02d], Donate: [%s], ApprovalNo: [%s], VemData: [%s]",
  3427. gun + 1,
  3428. deduct.TransactionId,
  3429. cardNo,
  3430. str_ReaderStatus[deduct.DeductResult],
  3431. (deduct.DeductAmount / 100), (deduct.DeductAmount % 100),
  3432. deduct.IsDonateInvoice ? "Yes" : "No",
  3433. appNo,
  3434. vemData);
  3435. return done;
  3436. }
  3437. }
  3438. else if(deduct.DeductResult == _Deduct_Cancel || deduct.DeductResult == _Deduct_PreAuth)
  3439. {
  3440. if(packet->Header.id != AUTO_GUN_SELECTION_ID)
  3441. {
  3442. if(!ShmChargerInfo->ReaderStatus[gun].ReaderStatusReq)
  3443. {
  3444. memcpy(&ShmChargerInfo->ReaderStatus[gun], &deduct, sizeof(DeductResultInfoData));
  3445. ShmChargerInfo->ReaderStatus[gun].ReaderStatusReq = YES;
  3446. done = true;
  3447. }
  3448. LOG_INFO("Gun %d [%s] %s", gun + 1, str_ReaderStatus[deduct.DeductResult], done ? "Done" : "Wait");
  3449. LOG_INFO("Gun %d %s, Card: [%s], ApprovalNo: [%s], VemData: [%s]",
  3450. gun + 1,
  3451. str_ReaderStatus[deduct.DeductResult],
  3452. cardNo,
  3453. appNo,
  3454. vemData);
  3455. return done;
  3456. }
  3457. else
  3458. {
  3459. find = true;
  3460. }
  3461. }
  3462. else
  3463. {
  3464. find = true;
  3465. }
  3466. }
  3467. return find;
  3468. }
  3469. unsigned char ReadCabinetSystemIDHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3470. {
  3471. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3472. if(packet->Header.id == AUTO_GUN_SELECTION_ID)
  3473. {
  3474. find = true;
  3475. }
  3476. return find;
  3477. }
  3478. unsigned char ReadDefaultPriceStringHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3479. {
  3480. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3481. if(packet->Header.id == AUTO_GUN_SELECTION_ID)
  3482. {
  3483. find = true;
  3484. }
  3485. return find;
  3486. }
  3487. unsigned char ReadUserPriceStringHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3488. {
  3489. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3490. if(find)
  3491. {
  3492. }
  3493. return find;
  3494. }
  3495. unsigned char ReadReceiptHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3496. {
  3497. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3498. if(find)
  3499. {
  3500. }
  3501. return find;
  3502. }
  3503. unsigned char ReadPowerConsumptionHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3504. {
  3505. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3506. if(packet->Header.id == AUTO_GUN_SELECTION_ID)
  3507. {
  3508. find = true;
  3509. }
  3510. return find;
  3511. }
  3512. unsigned char ReadChargingTimestampHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3513. {
  3514. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3515. return find;
  3516. }
  3517. unsigned char ReadChargingBillHandler(struct PACKET_STRUCTURE *packet, int dispenserIndex)
  3518. {
  3519. BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
  3520. return find;
  3521. }
  3522. void DisableConnector(unsigned char dispenserIndex)
  3523. {
  3524. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
  3525. {
  3526. unsigned char connector = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
  3527. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].Enable = false;
  3528. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].Parameter.bits.TimeoutStopRequest = true;
  3529. }
  3530. }
  3531. void DispenserSocketProcess(int socketFd, struct sockaddr_in clientInfo, unsigned char index)
  3532. {
  3533. int rxLen = 0, timeout = 0;
  3534. unsigned char dispenserID = 0, dispenserIndex = 0;
  3535. struct PACKET_STRUCTURE receiveBuffer;
  3536. unsigned char modelName[64];
  3537. unsigned char ackResult = _R_NG;
  3538. DispenserAck_Status ack = _DAS_Wait;
  3539. LOG_INFO("IP %s connection(%d) is established, start dispenser process, PID = %d", (inet_ntoa(clientInfo.sin_addr)), index, getpid());
  3540. while(1)
  3541. {
  3542. if((rxLen = recv(socketFd, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
  3543. {
  3544. if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
  3545. {
  3546. ackResult = _R_NG;
  3547. //ShowSocketData(&receiveBuffer);
  3548. CheckEvRxCommMsg(&receiveBuffer);
  3549. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].Status == _CNS_WaitModelName)
  3550. {
  3551. // Reg: 0x01, Dispenser model name
  3552. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Dispenser_Model_Name)
  3553. {
  3554. memset(modelName, 0x00, 64);
  3555. dispenserID = receiveBuffer.Payload.data[receiveBuffer.Header.len - 2];
  3556. if(dispenserID > 0 && dispenserID <= GENERAL_GUN_QUANTITY &&
  3557. dispenserID <= ShmChargerInfo->Control.MaxDispenser)
  3558. {
  3559. dispenserIndex = dispenserID - 1;
  3560. memcpy(modelName, receiveBuffer.Payload.data, receiveBuffer.Header.len - 2);
  3561. if(IsAvailableDispenserIndexSequence(dispenserIndex))
  3562. {
  3563. if(DispenserIdentificationHandler(&receiveBuffer, dispenserIndex, modelName) == true)
  3564. {
  3565. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].DispenserIndex = dispenserIndex;
  3566. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].Status = _CNS_DispenserMatched;
  3567. LOG_INFO("********** Dispenser id %d check in, model name: %s **********\n", dispenserID, modelName);
  3568. memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ModelName, modelName, 64);
  3569. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectionChannel = index;
  3570. ackResult = _R_OK;
  3571. }
  3572. else
  3573. {
  3574. // response NG: gun quantity fail
  3575. LOG_INFO("Dispenser ID %d Identification Fail", dispenserID);
  3576. }
  3577. }
  3578. else
  3579. {
  3580. // response NG: dispenser Index fail
  3581. LOG_INFO("Dispenser ID %d Fail, Need Wait Another Dispenser", dispenserID);
  3582. }
  3583. }
  3584. else
  3585. {
  3586. LOG_INFO("Dispenser ID: %d Over Range", dispenserID);
  3587. }
  3588. ModelNameResponse(socketFd, &receiveBuffer, ackResult);
  3589. }
  3590. else
  3591. {
  3592. // do nothing
  3593. }
  3594. }
  3595. else if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].Status == _CNS_DispenserMatched)
  3596. {
  3597. // Reg: 0x01, Dispenser model name
  3598. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Dispenser_Model_Name)
  3599. {
  3600. ackResult = _R_OK;
  3601. ModelNameResponse(socketFd, &receiveBuffer, ackResult);
  3602. }
  3603. // Reg: 0x02, Connector ID
  3604. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Connector_ID)
  3605. {
  3606. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity > 0)
  3607. {
  3608. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus = _DS_Idle;
  3609. ackResult = _R_OK;
  3610. }
  3611. LOG_INFO("Dispenser ID %d Get Connector ID %s", dispenserID, ackResult == _R_OK ? "OK" : "NG");
  3612. ConnectorIDResponse(socketFd, &receiveBuffer, ackResult, dispenserIndex);
  3613. if(ackResult == _R_OK)
  3614. {
  3615. if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.DispenserConfigSync)
  3616. {
  3617. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.DispenserConfigSync = true;
  3618. LOG_INFO("Dispenser ID %d Configuration Need To Synchronize", dispenserID);
  3619. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_CONNECTION_TIMEOUT);
  3620. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_DEFAULT_PRICE);
  3621. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_CURRENCY);
  3622. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_BACKEND_STATUS);
  3623. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_ETHERNET_STATUS);
  3624. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_WIFI_STATUS);
  3625. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_TELCOM_MODEM_STATUS);
  3626. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_BILLING_STATUS);
  3627. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_STOP_BUTTON_STATUS);
  3628. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_AUTH_MODE_CONFIG);
  3629. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_EVCCID_CONFIG);
  3630. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_TIME_OFFSET);
  3631. if(strlen(ShmChargerInfo->StationInfo.StationName) > 0 ||
  3632. ShmChargerInfo->StationInfo.StationID != 0 ||
  3633. ShmChargerInfo->StationInfo.WeatherID != 0 ||
  3634. ShmChargerInfo->StationInfo.Temperature != 0)
  3635. {
  3636. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_STATION_INFO);
  3637. }
  3638. if(strlen(ShmChargerInfo->PriceAndReceiptInfo.DefaultPriceString) > 0)
  3639. {
  3640. Set_Dispenser_MiscCommand(dispenserIndex, MISC_DISP_DEFAULT_PRICE_STRING);
  3641. }
  3642. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
  3643. {
  3644. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
  3645. Set_Connector_MiscCommand(gun, MISC_CONN_AVAILABILITY);
  3646. Set_Connector_MiscCommand(gun, MISC_CONN_QRCODE_INFO);
  3647. }
  3648. }
  3649. }
  3650. }
  3651. // Reg: 0x03, Power cabinet status
  3652. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Power_Cabinet_Status)
  3653. {
  3654. PowerCabinetStatusResponse(socketFd, &receiveBuffer, dispenserIndex);
  3655. }
  3656. // Reg: 0x04, Dispenser status
  3657. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Dispenser_Status)
  3658. {
  3659. if(DispenserStatusCodeHandler(&receiveBuffer, dispenserIndex))
  3660. {
  3661. ackResult = _R_OK;
  3662. }
  3663. DispenserStatusResponse(socketFd, &receiveBuffer, ackResult);
  3664. }
  3665. // Reg: 0x05, Charging capability
  3666. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Charging_Capability)
  3667. {
  3668. if(ConnectorChargingCapabilityHandler(&receiveBuffer, dispenserIndex))
  3669. {
  3670. ChargingCapabilityResponse(socketFd, &receiveBuffer);
  3671. }
  3672. }
  3673. // Reg: 0x06, Charging target
  3674. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Charging_Target)
  3675. {
  3676. if(receiveBuffer.Header.len == 5)
  3677. {
  3678. if(ConnectorChargingTargetHandler(&receiveBuffer, dispenserIndex))
  3679. {
  3680. ackResult = _R_OK;
  3681. }
  3682. }
  3683. ChargingTargetResponse(socketFd, &receiveBuffer, ackResult);
  3684. }
  3685. // Reg: 0x07, Software update
  3686. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Software_Update)
  3687. {
  3688. unsigned char NeedUpgrade = FirmwareUpgradeHandler(&receiveBuffer, dispenserIndex);
  3689. FirmwareUpgradeResponse(socketFd, &receiveBuffer, dispenserIndex, NeedUpgrade);
  3690. }
  3691. // Reg: 0x08, Plug-in status
  3692. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Plug_In_Status)
  3693. {
  3694. if(receiveBuffer.Header.len == 2)
  3695. {
  3696. if(ConnectorPlugInHandler(&receiveBuffer, dispenserIndex))
  3697. {
  3698. ackResult = _R_OK;
  3699. }
  3700. }
  3701. PlugInStatusResponse(socketFd, &receiveBuffer, ackResult);
  3702. }
  3703. // Reg: 0x09, Connector state
  3704. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Connector_State)
  3705. {
  3706. if(ConnectorStateHandler(&receiveBuffer, dispenserIndex))
  3707. {
  3708. ackResult = _R_OK;
  3709. }
  3710. ConnectorStateResponse(socketFd, &receiveBuffer, ackResult);
  3711. }
  3712. // Reg: 0x0A, User ID
  3713. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_User_ID)
  3714. {
  3715. ack = UserIDHandler(&receiveBuffer, dispenserIndex);
  3716. UserIDResponse(socketFd, &receiveBuffer, ack);
  3717. }
  3718. // Reg: 0x0B, Charging permission
  3719. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Charging_Permission)
  3720. {
  3721. ack = ChargingPermissionHandler(&receiveBuffer, dispenserIndex);
  3722. ChargingPermissionResponse(socketFd, &receiveBuffer, ack);
  3723. }
  3724. // Reg: 0x0C, Misc Control
  3725. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Misc_Control)
  3726. {
  3727. if(MiscControlHandler(&receiveBuffer, dispenserIndex))
  3728. {
  3729. ackResult = _R_OK;
  3730. }
  3731. MiscCmdRes(socketFd, &receiveBuffer, dispenserIndex, ackResult);
  3732. }
  3733. // Reg: 0x0D, Report csu version
  3734. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Report_Csu_Version)
  3735. {
  3736. if(DispenserWriteCsuVersionInfoHandler(&receiveBuffer, dispenserIndex))
  3737. {
  3738. ackResult = _R_OK;
  3739. }
  3740. WriteCsuVersionResponse(socketFd, &receiveBuffer, ackResult);
  3741. }
  3742. // Reg: 0x0E, Report other version
  3743. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Report_Other_Version)
  3744. {
  3745. if(DispenserWriteOtherVersionInfoHandler(&receiveBuffer, dispenserIndex))
  3746. {
  3747. ackResult = _R_OK;
  3748. }
  3749. WriteOtherVersionResponse(socketFd, &receiveBuffer, ackResult);
  3750. }
  3751. // Reg: 0x0F, Charging info
  3752. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Charging_Info)
  3753. {
  3754. if(DispenserWriteChargingInfoHandler(&receiveBuffer, dispenserIndex))
  3755. {
  3756. ackResult = _R_OK;
  3757. }
  3758. WriteChargingInfoResponse(socketFd, &receiveBuffer, ackResult);
  3759. }
  3760. // Reg: 0x10, QR Code And Date
  3761. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_QR_Code_Date)
  3762. {
  3763. if(ReadQrCodeAndDateHandler(&receiveBuffer, dispenserIndex))
  3764. {
  3765. ackResult = _R_OK;
  3766. }
  3767. ChargerQrCodeDateResponse(socketFd, &receiveBuffer, dispenserIndex, ackResult);
  3768. }
  3769. // Reg: 0x11, Wait plug in
  3770. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_WaitPlugIn)
  3771. {
  3772. if(WriteWaitPlugInHandler(&receiveBuffer, dispenserIndex))
  3773. {
  3774. ackResult = _R_OK;
  3775. }
  3776. WriteWaitPlugInResponse(socketFd, &receiveBuffer, ackResult);
  3777. }
  3778. // Reg: 0x12, Ground Fault Detection
  3779. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_GroundFaultDetection)
  3780. {
  3781. if(GroundFaultDetectionHandler(&receiveBuffer, dispenserIndex))
  3782. {
  3783. ackResult = _R_OK;
  3784. }
  3785. GroundFaultDetectionResponse(socketFd, &receiveBuffer, ackResult);
  3786. }
  3787. // Reg: 0x13, Get Cabinet CSU Version
  3788. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Get_Cabinet_CSU_Version)
  3789. {
  3790. if(GetCabinetCSUVersionHandler(&receiveBuffer, dispenserIndex))
  3791. {
  3792. ackResult = _R_OK;
  3793. }
  3794. CabinetCSUVersionResponse(socketFd, &receiveBuffer, ackResult);
  3795. }
  3796. // Reg: 0x14, Get Cabinet Other Version
  3797. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Get_Cabinet_Other_Version)
  3798. {
  3799. if(GetCabinetOtherVersionHandler(&receiveBuffer, dispenserIndex))
  3800. {
  3801. ackResult = _R_OK;
  3802. }
  3803. CabinetOtherVersionResponse(socketFd, &receiveBuffer, ackResult);
  3804. }
  3805. // Reg: 0x15, Get Psu Quantity
  3806. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Get_Psu_Quantity)
  3807. {
  3808. if(GetPsuQuantityHandler(&receiveBuffer, dispenserIndex))
  3809. {
  3810. ackResult = _R_OK;
  3811. }
  3812. PsuQuantityResponse(socketFd, &receiveBuffer, ackResult);
  3813. }
  3814. // Reg: 0x16, Get Psu Version
  3815. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Get_Psu_Version)
  3816. {
  3817. int _PsuIndex = 0;
  3818. if(GetPsuVersionHandler(&receiveBuffer, &_PsuIndex))
  3819. {
  3820. ackResult = _R_OK;
  3821. }
  3822. PsuVersionResponse(socketFd, &receiveBuffer, ackResult, _PsuIndex);
  3823. }
  3824. // Reg: 0x17, Get Reservation
  3825. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Get_Reservation)
  3826. {
  3827. unsigned char _reservation = NO;
  3828. if(GetReservationHandler(&receiveBuffer, dispenserIndex, &_reservation))
  3829. {
  3830. ackResult = _R_OK;
  3831. }
  3832. ReservationResponse(socketFd, &receiveBuffer, ackResult, _reservation);
  3833. }
  3834. // Reg: 0x18, Dispenser Request
  3835. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Dispenser_Request)
  3836. {
  3837. if(DispenserReqHandler(&receiveBuffer, dispenserIndex))
  3838. {
  3839. ackResult = _R_OK;
  3840. }
  3841. DispenserReqHandlerResponse(socketFd, &receiveBuffer, ackResult);
  3842. }
  3843. // Reg: 0x19, State Of Remote Start Without Connector ID
  3844. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_RemoteStartNoIDState)
  3845. {
  3846. unsigned char _NoConnectorIDRemoteStart = 0;
  3847. if(GetRemoteStartNoIDHandler(&receiveBuffer, &_NoConnectorIDRemoteStart))
  3848. {
  3849. ackResult = _R_OK;
  3850. }
  3851. RemoteStarNoIDResponse(socketFd, &receiveBuffer, ackResult, _NoConnectorIDRemoteStart);
  3852. }
  3853. // Reg: 0x1A, Refund Amount
  3854. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_RefundAmount)
  3855. {
  3856. if(GetRefundAmountHandler(&receiveBuffer, dispenserIndex))
  3857. {
  3858. ackResult = _R_OK;
  3859. }
  3860. RefundAmountResponse(socketFd, &receiveBuffer, ackResult);
  3861. }
  3862. // Reg: 0x1B, Prepayment Info
  3863. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_PrepaymentInfo)
  3864. {
  3865. if(GetPrepaymentHandler(&receiveBuffer, dispenserIndex))
  3866. {
  3867. ackResult = _R_OK;
  3868. }
  3869. PrepaymentResponse(socketFd, &receiveBuffer, ackResult);
  3870. }
  3871. // Reg: 0x1C, Payment Fail Reason
  3872. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_PaymentFailReason)
  3873. {
  3874. if(GetPaymentFailReasonHandler(&receiveBuffer, dispenserIndex))
  3875. {
  3876. ackResult = _R_OK;
  3877. }
  3878. PaymentFailReasonResponse(socketFd, &receiveBuffer, ackResult);
  3879. }
  3880. // Reg: 0x1D, QR Code Request
  3881. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_ConnectorQRCode)
  3882. {
  3883. if(GetQRCodeRequestHandler(&receiveBuffer, dispenserIndex))
  3884. {
  3885. ackResult = _R_OK;
  3886. }
  3887. QRCodeResponse(socketFd, &receiveBuffer, ackResult);
  3888. }
  3889. // Reg: 0x1E, Station Info
  3890. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_StationInfo)
  3891. {
  3892. if(GetStationInfoHandler(&receiveBuffer, dispenserIndex))
  3893. {
  3894. ackResult = _R_OK;
  3895. }
  3896. StationInfoResponse(socketFd, &receiveBuffer, dispenserIndex, ackResult);
  3897. }
  3898. // Reg: 0x1F, Deduct Result
  3899. if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_DeductResult)
  3900. {
  3901. if(WriteDeductResultHandler(&receiveBuffer, dispenserIndex))
  3902. {
  3903. ackResult = _R_OK;
  3904. }
  3905. DeductResultResponse(socketFd, &receiveBuffer, ackResult);
  3906. }
  3907. // Reg: 0x20, Read Cabinet System ID
  3908. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_CabinetSystemID)
  3909. {
  3910. if(ReadCabinetSystemIDHandler(&receiveBuffer, dispenserIndex))
  3911. {
  3912. ackResult = _R_OK;
  3913. }
  3914. CabinetSystemIDResponse(socketFd, &receiveBuffer, ackResult);
  3915. }
  3916. // Reg: 0x21, Read Default Price String
  3917. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_DefaultPriceString)
  3918. {
  3919. if(ReadDefaultPriceStringHandler(&receiveBuffer, dispenserIndex))
  3920. {
  3921. ackResult = _R_OK;
  3922. }
  3923. DefaultPriceStringResponse(socketFd, &receiveBuffer, ackResult);
  3924. }
  3925. // Reg: 0x22, Read User Price String
  3926. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_UserPriceString)
  3927. {
  3928. if(ReadUserPriceStringHandler(&receiveBuffer, dispenserIndex))
  3929. {
  3930. ackResult = _R_OK;
  3931. }
  3932. UserPriceStringResponse(socketFd, &receiveBuffer, ackResult);
  3933. }
  3934. // Reg: 0x23, Read Receipt
  3935. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Receipt)
  3936. {
  3937. if(ReadReceiptHandler(&receiveBuffer, dispenserIndex))
  3938. {
  3939. ackResult = _R_OK;
  3940. }
  3941. ReceiptResponse(socketFd, &receiveBuffer, ackResult);
  3942. }
  3943. // Reg: 0x24, Read Power Consumption
  3944. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_PowerConsumption)
  3945. {
  3946. if(ReadPowerConsumptionHandler(&receiveBuffer, dispenserIndex))
  3947. {
  3948. ackResult = _R_OK;
  3949. }
  3950. PowerConsumptionResponse(socketFd, &receiveBuffer, ackResult);
  3951. }
  3952. // Reg: 0x25, Read Charging Timestamp
  3953. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_ChargingTimestamp)
  3954. {
  3955. if(ReadChargingTimestampHandler(&receiveBuffer, dispenserIndex))
  3956. {
  3957. ackResult = _R_OK;
  3958. }
  3959. ChargingTimestampResponse(socketFd, &receiveBuffer, ackResult);
  3960. }
  3961. // Reg: 0x26, Read ChargingBill
  3962. if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_ChargingBill)
  3963. {
  3964. if(ReadChargingBillHandler(&receiveBuffer, dispenserIndex))
  3965. {
  3966. ackResult = _R_OK;
  3967. }
  3968. ChargingBillResponse(socketFd, &receiveBuffer, ackResult);
  3969. }
  3970. }
  3971. // clean timeout
  3972. timeout = 0;
  3973. }
  3974. }
  3975. else
  3976. {
  3977. timeout += SOCKET_RECEIVE_INTERVAL;
  3978. usleep((SOCKET_RECEIVE_INTERVAL * 1000));
  3979. }
  3980. if(timeout >= DISPENSER_SOCKET_TIMEOUT || ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.DuplicateIp)
  3981. {
  3982. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.DuplicateIp)
  3983. {
  3984. LOG_INFO("Dispenser %d has been kick", dispenserIndex + 1);
  3985. }
  3986. else
  3987. {
  3988. //timeout
  3989. LOG_INFO("IP: %s, Socket %d connection timeout", (inet_ntoa(clientInfo.sin_addr)), index);
  3990. }
  3991. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].Status == _CNS_DispenserMatched)
  3992. {
  3993. DisableConnector(dispenserIndex);
  3994. memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex], 0x00, sizeof(struct DispenserModule));
  3995. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus = _DS_Timeout;
  3996. DispenserCheckInInfoUpdate();
  3997. }
  3998. break;
  3999. }
  4000. }
  4001. }
  4002. int GetMacAddress(int sockFd, unsigned char *mac)
  4003. {
  4004. struct arpreq arpReq;
  4005. struct sockaddr_in clientInfo;
  4006. socklen_t len = sizeof(struct sockaddr_in);
  4007. memset(mac, 0x00, 6);
  4008. if(getpeername(sockFd, (struct sockaddr*)&clientInfo, &len) < 0)
  4009. {
  4010. return 0;
  4011. }
  4012. else
  4013. {
  4014. memcpy(&arpReq.arp_pa, &clientInfo, sizeof(struct sockaddr_in));
  4015. strcpy(arpReq.arp_dev, "eth1");
  4016. arpReq.arp_pa.sa_family = AF_INET;
  4017. arpReq.arp_ha.sa_family = AF_UNSPEC;
  4018. if(ioctl(sockFd, SIOCGARP, &arpReq) < 0)
  4019. {
  4020. return 0;
  4021. }
  4022. else
  4023. {
  4024. memcpy(mac, arpReq.arp_ha.sa_data, 6);
  4025. }
  4026. }
  4027. return 1;
  4028. }
  4029. int FindFreeChannel(void)
  4030. {
  4031. for(int i = 0; i < MAXIMUM_CONNECT_QUANTITY; i++)
  4032. {
  4033. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_FREE)
  4034. {
  4035. return i;
  4036. }
  4037. }
  4038. return FAIL;
  4039. }
  4040. BOOL IsConflictIp(uint32_t ipAddress)
  4041. {
  4042. for(int i = 0; i < MAXIMUM_CONNECT_QUANTITY; i++)
  4043. {
  4044. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress == ipAddress)
  4045. {
  4046. int dispenser = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex;
  4047. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Setting.bits.DuplicateIp == false)
  4048. {
  4049. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Setting.bits.DuplicateIp = true;
  4050. }
  4051. return true;
  4052. }
  4053. }
  4054. return false;
  4055. }
  4056. void InitDispenserInfo(void)
  4057. {
  4058. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  4059. {
  4060. bool disconnect = false;
  4061. //memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i], 0x00, sizeof(struct ConnectorInfoData));
  4062. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteStatus = 0;
  4063. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable = 0;
  4064. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].ReadyToCharge = 0;
  4065. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].ParentDispensetIndex = 0;
  4066. disconnect = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.Disconnection;
  4067. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.Value = 0;
  4068. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.Disconnection = disconnect;
  4069. memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].WarningInfo, 0x00, sizeof(struct WARNING_CODE_INFO));
  4070. //memset(&LastWarningInfo[i], 0x00, sizeof(struct WARNING_CODE_INFO));
  4071. }
  4072. //memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo, 0x00, sizeof(struct DispenserInfoData));
  4073. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  4074. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  4075. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity = 0;
  4076. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity = 0;
  4077. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  4078. {
  4079. unsigned char localStatus = 0;
  4080. localStatus = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus;
  4081. memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i], 0x00, sizeof(struct DispenserModule));
  4082. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus = localStatus;
  4083. }
  4084. // initial CheckInLog from WiringInfo.DispenserSequence
  4085. ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status = 0;
  4086. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  4087. {
  4088. ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status |= (1 << i);
  4089. }
  4090. // initial ConnectorLog from WiringInfo.WiringSetting
  4091. memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog, 0x00, sizeof(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog));
  4092. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  4093. {
  4094. if(i < GENERAL_GUN_QUANTITY)
  4095. {
  4096. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[i] = ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  4097. }
  4098. }
  4099. memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo, 0x00, sizeof(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo));
  4100. ShmChargerInfo->CabinetMiscValue.Currency = ShmSysConfigAndInfo->SysConfig.BillingData.Currency;
  4101. }
  4102. struct timespec _IpConflicted_time[CONNECTOR_QUANTITY];
  4103. void DispenserIpConflictedCheck(void)
  4104. {
  4105. while(1)
  4106. {
  4107. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  4108. {
  4109. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.DuplicateIp)
  4110. {
  4111. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.DuplicateIpConfirm == NO)
  4112. {
  4113. GetClockTime(&_IpConflicted_time[i]);
  4114. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.DuplicateIpConfirm = true;
  4115. LOG_INFO("Dispenser %d IP Conflicted Confirm", i + 1);
  4116. }
  4117. else
  4118. {
  4119. if((GetTimeoutValue(_IpConflicted_time[i]) / mSEC_VAL) >= IP_CONFLICTED_TIME)
  4120. {
  4121. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  4122. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  4123. {
  4124. unsigned char channel = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectionChannel;
  4125. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[channel].Status != _CNS_FREE)
  4126. {
  4127. LOG_INFO("Dispenser %d IP Conflicted Stop", i + 1);
  4128. DisableConnector(i);
  4129. memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i], 0x00, sizeof(struct DispenserModule));
  4130. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus = _DS_Timeout;
  4131. DispenserCheckInInfoUpdate();
  4132. memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[channel], 0x00, sizeof(struct ConnectionInfoData));
  4133. }
  4134. }
  4135. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.DuplicateIp = false;
  4136. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.DuplicateIpConfirm = false;
  4137. LOG_INFO("Dispenser %d IP Conflicted Clean", i + 1);
  4138. }
  4139. }
  4140. }
  4141. }
  4142. usleep(500000);
  4143. }
  4144. }
  4145. void ForkIpConflictedCheck(void)
  4146. {
  4147. pid_t forkId;
  4148. forkId = fork();
  4149. if(forkId == 0)
  4150. {
  4151. DispenserIpConflictedCheck();
  4152. return;
  4153. }
  4154. else if(forkId == -1)
  4155. {
  4156. LOG_INFO("fork fail");
  4157. }
  4158. }
  4159. int tcpSocketServerStart(void)
  4160. {
  4161. int sockFd = 0;
  4162. int clientSockFd = 0;
  4163. int connectIndex = 0;
  4164. int bindStatus = 0;
  4165. int reuseaddr = 1;
  4166. pid_t forkId;
  4167. struct sockaddr_in serverInfo, clientInfo;
  4168. socklen_t addrlen = sizeof(clientInfo);
  4169. //struct timeval timeout = {3, 0};
  4170. sockFd = socket(AF_INET, SOCK_STREAM, 0);
  4171. if(sockFd == -1)
  4172. {
  4173. LOG_INFO("InitSocketServer NG\n");
  4174. sleep(5);
  4175. return FAIL;
  4176. }
  4177. setsockopt(sockFd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr));
  4178. InitDispenserInfo();
  4179. bzero(&serverInfo,sizeof(serverInfo));
  4180. serverInfo.sin_family = PF_INET;
  4181. serverInfo.sin_addr.s_addr = htonl(INADDR_ANY);
  4182. serverInfo.sin_port = htons(TCP_LISTEN_PORT);
  4183. bindStatus = bind(sockFd, (struct sockaddr *)&serverInfo, sizeof(serverInfo));
  4184. if(bindStatus < 0)
  4185. {
  4186. LOG_INFO("socket bind fail");
  4187. return FAIL;
  4188. }
  4189. listen(sockFd, CONNECTION_LIMIT);
  4190. LOG_INFO("Dispenser TCP Server Start");
  4191. signal(SIGCHLD, SIG_IGN);
  4192. ForkIpConflictedCheck();
  4193. // Main loop
  4194. while(1)
  4195. {
  4196. clientSockFd = accept(sockFd, (struct sockaddr*) &clientInfo, &addrlen);
  4197. /*
  4198. if((errno == EWOULDBLOCK) || (errno == EAGAIN) || (errno == ENONET) ||
  4199. (errno == EPROTO) || (errno == ENOPROTOOPT) || (errno == EOPNOTSUPP) ||
  4200. (errno == ENETDOWN) || (errno == ENETUNREACH) || (errno == EHOSTDOWN) ||
  4201. (errno == EHOSTUNREACH) || (errno == ECONNABORTED))
  4202. {
  4203. printf("accept error: %s\n", strerror(errno));
  4204. //exit(EXIT_FAILURE);
  4205. //break;
  4206. }
  4207. else if ( errno == EINTR)
  4208. {
  4209. printf("accept EINTRn");
  4210. continue;
  4211. }
  4212. else
  4213. {
  4214. printf("AccepCb: accept error: %s\n", strerror(errno));
  4215. //break;
  4216. //exit(EXIT_FAILURE);
  4217. }*/
  4218. LOG_INFO("Client ip: %s is accepted at port: %d", inet_ntoa(clientInfo.sin_addr), clientInfo.sin_port);
  4219. connectIndex = FindFreeChannel();
  4220. if(connectIndex >= 0)
  4221. {
  4222. if(IsConflictIp(clientInfo.sin_addr.s_addr) == false)
  4223. {
  4224. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[connectIndex].Status = _CNS_WaitModelName;
  4225. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[connectIndex].IpAddress = clientInfo.sin_addr.s_addr;
  4226. forkId = fork();
  4227. if(forkId == 0)
  4228. {
  4229. // child process
  4230. DispenserSocketProcess(clientSockFd, clientInfo, connectIndex);
  4231. close(clientSockFd);
  4232. memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[connectIndex], 0x00, sizeof(struct ConnectionInfoData));
  4233. return 0;
  4234. }
  4235. else if(forkId == -1)
  4236. {
  4237. LOG_INFO("fork fail");
  4238. }
  4239. }
  4240. else
  4241. {
  4242. // conflict ip address
  4243. LOG_INFO("Conflict IP address, close socket");
  4244. close(clientSockFd);
  4245. memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[connectIndex], 0x00, sizeof(struct ConnectionInfoData));
  4246. }
  4247. }
  4248. else
  4249. {
  4250. // no free channel
  4251. LOG_INFO("No free channel, close socket");
  4252. close(clientSockFd);
  4253. }
  4254. usleep(10000);
  4255. }
  4256. return 0;
  4257. }
  4258. void InitialConnector(void)
  4259. {
  4260. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  4261. {
  4262. chargingInfo[i] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData;
  4263. }
  4264. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  4265. {
  4266. memset(&ConnectorCapability[i], 0x00, sizeof(ChargingCapabilityResponseInfo));
  4267. memcpy(ConnectorCapability[i].CurrencyString, Currency[0], 3);
  4268. memset(&ConnectorRefund[i], 0x00, sizeof(RefundResponse));
  4269. memset(&ConnectorPrepayment[i], 0x00, sizeof(PrepaymentResponseInfo));
  4270. memset(&ConnectorPaymentFailReason[i], 0x00, sizeof(PaymentFailResponse));
  4271. memset(&_ConnectorQRCode[i][0], 0x00, 128);
  4272. memset(&_stationInfo[i], 0x00, sizeof(StationInfoData));
  4273. memset(&_deductResult[i], 0x00, sizeof(DeductResultInfoData));
  4274. _GunSystemStatus[i] = 0;
  4275. }
  4276. }
  4277. int main(void)
  4278. {
  4279. if(InitShareMemory() == FAIL)
  4280. {
  4281. #ifdef SystemLogMessage
  4282. LOG_ERROR("InitShareMemory NG");
  4283. #endif
  4284. sleep(5);
  4285. return 0;
  4286. }
  4287. InitialConnector();
  4288. // wait for self test completed
  4289. while(ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING ||
  4290. ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
  4291. {
  4292. sleep(1);
  4293. }
  4294. tcpSocketServerStart();
  4295. //tcpSocketClientStart();
  4296. return 0;
  4297. }