12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125 |
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <termios.h>
- #include <errno.h>
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include <limits.h>
- #include "define.h"
- #include "main.h"
- #include "Module_InternalComm.h"
- //#define SIMULATION
- #define FAIL_SPEC_COMM 100
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define PASS 1
- #define FAIL 0
- #define ON 1
- #define OFF 0
- #define PRIORITY_HIGH 0
- #define PRIORITY_LOW 1
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct PrimaryMcuData *ShmPrimaryMcuData;
- struct OCPP16Data *ShmOCPP16Data;
- struct Charger *ShmCharger;
- uint16_t stepIndex=21, logIndex;
- long long tsLast, tsNow, tsPrintLog[2];
- uint64_t tmpPowerConsumption;
- uint64_t tmpL1PowerConsumption;
- uint64_t tmpL2PowerConsumption;
- uint64_t tmpL3PowerConsumption;
- void trim(char *s);
- int mystrcmp(char *p1,char *p2);
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
- void split(char **arr, char *str, const char *del);
- int StoreLogMsg(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- time_t CurrentTime;
- struct tm *tm;
- struct timeval tv;
- va_list args;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf,0,sizeof(Buf));
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- gettimeofday(&tv, NULL); // get microseconds, 10^-6
- sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_InterCommLog",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1);
- #ifdef SystemLogMessage
- system(Buf);
- #endif
- #ifdef ConsloePrintLog
- printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
- #endif
- return rc;
- }
- int DiffTimeb(struct timeb ST, struct timeb ET)
- {
- //return milli-second
- unsigned int StartTime,StopTime;
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
- return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
- }
- long long current_timestamp()
- {
- struct timeval te;
- gettimeofday(&te, NULL); // get current time
- long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
- return milliseconds;
- }
- //=================================
- // Common routine
- //=================================
- void trim(char *s)
- {
- int i=0, j, k, l=0;
- while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
- i++;
- j = strlen(s)-1;
- while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
- j--;
- if(i==0 && j==strlen(s)-1) { }
- else if(i==0) s[j+1] = '\0';
- else {
- for(k=i; k<=j; k++) s[l++] = s[k];
- s[l] = '\0';
- }
- }
- int mystrcmp(char *p1,char *p2)
- {
- while(*p1==*p2)
- {
- if(*p1=='\0' || *p2=='\0')
- break;
- p1++;
- p2++;
- }
- if(*p1=='\0' && *p2=='\0')
- return(PASS);
- else
- return(FAIL);
- }
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
- {
- strncpy(dest, src + start, cnt);
- dest[cnt] = 0;
- }
- void split(char **arr, char *str, const char *del)
- {
- char *s = strtok(str, del);
- while(s != NULL)
- {
- *arr++ = s;
- s = strtok(NULL, del);
- }
- }
- //==========================================
- // Init all share memory
- //==========================================
- int InitShareMemory()
- {
- int result = PASS;
- int MeterSMId;
- //Initial ShmSysConfigAndInfo
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
- #endif
- result = FAIL;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
- #endif
- result = FAIL;
- }
- //Initial ShmStatusCodeData
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
- #endif
- result = FAIL;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
- #endif
- result = FAIL;
- }
- //Initial ShmPrimaryMcuKey
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
- #endif
- result = FAIL;
- }
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
- #endif
- result = FAIL;
- }
- //creat ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmget ShmOCPP16Data NG");
- #endif
- result = FAIL;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmat ShmOCPP16Data NG");
- #endif
- result = FAIL;
- }
- else
- {}
- //Initial ShmCharger
- if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmget ShmChargerKey NG\n");
- #endif
- result = FAIL;
- }
- else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("shmat ShmChargerKey NG\n");
- #endif
- result = FAIL;
- }
- return result;
- }
- int InitComPort()
- {
- int fd;
- struct termios tios;
- fd = open("/dev/ttyS1", O_RDWR);
- if(fd<=0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("open /dev/ttyS1 NG\n");
- #endif
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN]=0;
- tios.c_cc[VTIME]=(unsigned char)5; // timeout 0.5 secod
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- void ack_delay(unsigned char cmd)
- {
- switch(cmd)
- {
- case CMD_UPDATE_START:
- case CMD_UPDATE_END:
- usleep(300000);
- break;
- default:
- usleep(100000);
- break;
- }
- }
- int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
- {
- int len;
- tcflush(fd,TCIOFLUSH);
- if(write(fd, cmd, cmd_len) >= cmd_len)
- {
- ack_delay(cmd[3]);
- len = read(fd, rx, 512);
- }
- else
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("Serial command %s response fail.\n", cmd);
- #endif
- }
- return len;
- }
- unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_FW_VER, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- strncpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_HW_VER, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- strncpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetAddr, PresentInputVoltage *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_PRESENT_INPUTVOLTAGE, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->inputType = rx[6];
- Ret_Buf->L1N_L12 =( rx[7] | (rx[8]<<8))/10.0;
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- Ret_Buf->L2N_L23 =( rx[9] | (rx[10]<<8))/10.0;
- Ret_Buf->L3N_L31 =( rx[11] | (rx[12]<<8))/10.0;
- }
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char targetAddr, PresentOutputVoltage *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_PRESENT_OUTPUTVOLTAGE, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->behindFuse_Voltage_C1 =(rx[6] | (rx[7]<<8))/10.0;
- Ret_Buf->behindRelay_Voltage_C1 =(rx[8] | (rx[9]<<8))/10.0;
- if((rx[4] | rx[5]<<8) > 4)
- {
- Ret_Buf->behindFuse_Voltage_C2 =(rx[10] | (rx[11]<<8))/10.0;
- Ret_Buf->behindRelay_Voltage_C2 =(rx[12] | (rx[13]<<8))/10.0;
- }
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_FAN_SPEED, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- for(int idx=0;idx<((rx[4] | rx[5]<<8)>>1);idx++)
- Ret_Buf->speed[idx] =(rx[6+(2*idx)] | (rx[6+(2*idx)+1]<<8));
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temperature *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_TEMPERATURE, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- Ret_Buf->point[idx] = rx[6+idx] - 60;
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr, AuxPower *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_AUX_POWERVOLTAGE, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- Ret_Buf->voltage[idx] = rx[6+idx];
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_RELAY_OUTPUT, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- for(int idx_connector=0;idx_connector<(rx[4] | rx[5]<<8);idx_connector++)
- {
- for(int idx=0;idx<8;idx++)
- Ret_Buf->relay_status[idx_connector][idx] = (rx[6+idx_connector]>>idx) & 0x01;
- }
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GFD_ADC, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- for(int idx_connector=0;idx_connector<((rx[4] | rx[5]<<8)>>2);idx_connector++)
- {
- Ret_Buf->adc_value_positive[idx_connector] = (rx[6+(4*idx_connector)] | rx[6+(4*idx_connector)+1]<<8);
- Ret_Buf->adc_value_negative[idx_connector] = (rx[6+(4*idx_connector)+2] | rx[6+(4*idx_connector)+3]<<8);;
- }
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GPIO_INPUT, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->AC_Connector = (rx[6] >> 0) & 0x01;
- Ret_Buf->AC_MainBreaker = (rx[6] >> 1) & 0x01;
- Ret_Buf->SPD = (rx[6] >> 2) & 0x01;
- Ret_Buf->Door_Open = (rx[6] >> 3) & 0x01;
- Ret_Buf->GFD[0] = (rx[6] >> 4) & 0x01;
- Ret_Buf->GFD[1] = (rx[6] >> 5) & 0x01;
- Ret_Buf->Button[0] = (rx[6] >> 6) & 0x01;
- Ret_Buf->Button[1] = (rx[6] >> 7) & 0x01;
- Ret_Buf->Button_Emergency = (rx[7] >> 0) & 0x01;
- Ret_Buf->Button_Mode_Switch = (rx[7] >> 7) & 0x01;
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Alarm_Log(unsigned char fd, unsigned char targetAddr, Alarm_Log *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[10] = {0xaa, 0x00, targetAddr, CMD_QUERY_ALARM_LOG, 0x03, 0x00, Ret_Buf->logArea, Ret_Buf->alarmIndex&0xff, ((Ret_Buf->alarmIndex>>8)&0xff), 0x00};
- unsigned char rx[512];
- unsigned char chksum = Ret_Buf->logArea ^ (Ret_Buf->alarmIndex&0xff) ^ ((Ret_Buf->alarmIndex>>8)&0xff);
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- memcpy(&Ret_Buf->log[0], &rx[8], 8);
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_RTC, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->year = ((rx[6]-'0')*1000) + ((rx[7]-'0')*100) + ((rx[8]-'0')*10) + ((rx[9]-'0')*1);
- Ret_Buf->month = ((rx[10]-'0')*10) + ((rx[11]-'0')*1);
- Ret_Buf->day = ((rx[12]-'0')*10) + ((rx[13]-'0')*1);
- Ret_Buf->hour = ((rx[14]-'0')*10) + ((rx[15]-'0')*1);
- Ret_Buf->min = ((rx[16]-'0')*10) + ((rx[17]-'0')*1);
- Ret_Buf->sec = ((rx[18]-'0')*10) + ((rx[19]-'0')*1);
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_AC_MCU_Status(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_AC_STATUS, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->cp_state = rx[6];
- Ret_Buf->current_limit = rx[7] | (rx[8]<<0x08);
- Ret_Buf->cp_voltage_positive = (rx[9] | (rx[10]<<0x08))/100.0;
- Ret_Buf->cp_voltage_negtive = (rx[11] | (rx[12]<<0x08))/100.0;
- Ret_Buf->locker_state = rx[13];
- Ret_Buf->relay_state = rx[14];
- Ret_Buf->shutter_state = rx[15];
- Ret_Buf->meter_state = rx[16];
- Ret_Buf->pp_state = rx[17];
- Ret_Buf->rating_current = rx[18];
- Ret_Buf->rotatory_switch = (rx[19] & 0x0F);
- Ret_Buf->socket_e.isSocketEMode = (rx[20] & 0x01);
- Ret_Buf->socket_e.isSocketEPinOn = ((rx[20]>>1) & 0x01);
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_AC_MCU_Alarm(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Alarm *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_AC_ALARM, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- //rx[6]
- Ret_Buf->bits.OVP_L1 = (((rx[6]>>0)&0x01)?1:0);
- Ret_Buf->bits.UVP_L1 = (((rx[6]>>1)&0x01)?1:0);
- Ret_Buf->bits.OCP_L1 = (((rx[6]>>2)&0x01)?1:0);
- Ret_Buf->bits.OTP = (((rx[6]>>3)&0x01)?1:0);
- Ret_Buf->bits.gmi_fault = (((rx[6]>>4)&0x01)?1:0);
- Ret_Buf->bits.cp_fault = (((rx[6]>>5)&0x01)?1:0);
- Ret_Buf->bits.ac_leak = (((rx[6]>>6)&0x01)?1:0);
- Ret_Buf->bits.dc_leak = (((rx[6]>>7)&0x01)?1:0);
- //rx[7]
- Ret_Buf->bits.mcu_selftest_fail = (((rx[7]>>0)&0x01)?1:0);
- Ret_Buf->bits.handshaking_timeout = (((rx[7]>>1)&0x01)?1:0);
- Ret_Buf->bits.emergency_stop = (((rx[7]>>2)&0x01)?1:0);
- Ret_Buf->bits.relay_welding = (((rx[7]>>3)&0x01)?1:0);
- Ret_Buf->bits.leak_module_fail = (((rx[7]>>4)&0x01)?1:0);
- Ret_Buf->bits.shutter_fault = (((rx[7]>>5)&0x01)?1:0);
- Ret_Buf->bits.locker_fault = (((rx[7]>>6)&0x01)?1:0);
- Ret_Buf->bits.power_drop = (((rx[7]>>7)&0x01)?1:0);
- //rx[8] bit 3 reserved
- Ret_Buf->bits.short_circuit_L1 = (((rx[8]>>0)&0x01)?1:0);
- Ret_Buf->bits.rotate_switch_fault = (((rx[8]>>1)&0x01)?1:0);
- Ret_Buf->bits.relay_drive_fault = (((rx[8]>>2)&0x01)?1:0);
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- Ret_Buf->bits.OVP_L2 = (((rx[8]>>4)&0x01)?1:0);
- Ret_Buf->bits.OVP_L3 = (((rx[8]>>5)&0x01)?1:0);
- Ret_Buf->bits.UVP_L2 = (((rx[8]>>6)&0x01)?1:0);
- Ret_Buf->bits.UVP_L3 = (((rx[8]>>7)&0x01)?1:0);
- }
- //rx[9] bits 6 & 7 Reserved
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- Ret_Buf->bits.OCP_L2 = (((rx[9]>>0)&0x01)?1:0);
- Ret_Buf->bits.OCP_L3 = (((rx[9]>>1)&0x01)?1:0);
- Ret_Buf->bits.short_circuit_L2 = (((rx[9]>>2)&0x01)?1:0);
- Ret_Buf->bits.short_circuit_L3 = (((rx[9]>>3)&0x01)?1:0);
- }
- Ret_Buf->bits.meter_comm_timeout = (((rx[9]>>4)&0x01)?1:0);
- Ret_Buf->bits.meter_ic_comm_timeout = (((rx[9]>>5)&0x01)?1:0);
- Ret_Buf->bits.pilot_negative_error = (((rx[9]>>6)&0x01)?1:0);
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Present_OutputCurrent(unsigned char fd, unsigned char targetAddr, Presentoutputcurrent *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_PRESENT_OUTPUTCURRENT, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 0)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->L1N_L12[0] = (rx[6] | (rx[7]<<8))/10.0;
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- Ret_Buf->L2N_L23[0] = (rx[8] | (rx[9]<<8))/10.0;
- Ret_Buf->L3N_L31[0] = (rx[10] | (rx[11]<<8))/10.0;
- }
- Ret_Buf->L1N_L12[1] = (rx[12] | (rx[13]<<8))/10.0;
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- Ret_Buf->L2N_L23[1] = (rx[14] | (rx[15]<<8))/10.0;
- Ret_Buf->L3N_L31[1] = (rx[16] | (rx[17]<<8))/10.0;
- }
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Ble_Config(unsigned char fd, unsigned char targetAddr, Ble_Config_Data *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_BLE_CONFIG_DATA, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 0)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf->isLogin = (rx[6]?0x01:0x00);
- Ret_Buf->isRequestStart = (rx[7]?0x01:0x00);
- Ret_Buf->isRequestStop = (rx[8]?0x01:0x00);
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Ble_Central_ID(unsigned char fd, unsigned char targetAddr, Ble_Login_Central_Id *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_BLE_CENTRAL_ID, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 0)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- memset(Ret_Buf->id, 0x00, ARRAY_SIZE(Ret_Buf->id));
- memcpy(&Ret_Buf->id[0], &rx[6], (rx[4] | (rx[5]<<8)));
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_Power_Consumption(unsigned char fd, unsigned char targetAddr, Power_Consumption *Ret_Buf_T, Power_Consumption *Ret_Buf_L1, Power_Consumption *Ret_Buf_L2, Power_Consumption *Ret_Buf_L3)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_POWER_CONSUMPTION, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 0)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- #ifndef SIMULATION
- Ret_Buf_T-> power_consumption = ((uint64_t)rx[6] | (((uint64_t)rx[7])<<8) | (((uint64_t)rx[8])<<16) | (((uint64_t)rx[9])<<24) | (((uint64_t)rx[10])<<32) | (((uint64_t)rx[11])<<40) | (((uint64_t)rx[12])<<48) | (((uint64_t)rx[13])<<56));
- Ret_Buf_L1-> power_consumption = ((uint64_t)rx[14] | (((uint64_t)rx[15])<<8) | (((uint64_t)rx[16])<<16) | (((uint64_t)rx[17])<<24) | (((uint64_t)rx[18])<<32) | (((uint64_t)rx[19])<<40) | (((uint64_t)rx[20])<<48) | (((uint64_t)rx[21])<<56));
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- Ret_Buf_L2-> power_consumption = ((uint64_t)rx[22] | (((uint64_t)rx[23])<<8) | (((uint64_t)rx[24])<<16) | (((uint64_t)rx[25])<<24) | (((uint64_t)rx[26])<<32) | (((uint64_t)rx[27])<<40) | (((uint64_t)rx[28])<<48) | (((uint64_t)rx[29])<<56));
- Ret_Buf_L3-> power_consumption = ((uint64_t)rx[30] | (((uint64_t)rx[31])<<8) | (((uint64_t)rx[32])<<16) | (((uint64_t)rx[33])<<24) | (((uint64_t)rx[34])<<32) | (((uint64_t)rx[35])<<40) | (((uint64_t)rx[36])<<48) | (((uint64_t)rx[37])<<56));
- }
- #else //SIMULATION
- tsNow = current_timestamp();
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- tmpPowerConsumption += ((uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltage*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent)*((tsNow-tsLast)/360000.0)) +
- (uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltageL2*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrentL2)*((tsNow-tsLast)/360000.0)) +
- (uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltageL3*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrentL3)*((tsNow-tsLast)/360000.0)));
- tmpL1PowerConsumption += (uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltage*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent)*((tsNow-tsLast)/360000.0));
- tmpL2PowerConsumption += (uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltageL2*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrentL2)*((tsNow-tsLast)/360000.0));
- tmpL3PowerConsumption += (uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltageL3*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrentL3)*((tsNow-tsLast)/360000.0));
- Ret_Buf_L1-> power_consumption = tmpL1PowerConsumption;
- Ret_Buf_L2-> power_consumption = tmpL2PowerConsumption;
- Ret_Buf_L3-> power_consumption = tmpL3PowerConsumption;
- }
- else
- {
- tmpPowerConsumption += (uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltage*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent)*((tsNow-tsLast)/360000.0));
- }
- Ret_Buf_T-> power_consumption = tmpPowerConsumption;
- tsLast = tsNow;
- #endif //SIMULATION
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_MeterIc_CorrectionPara(unsigned char fd, unsigned char targetAddr, MeterIcCorrection *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[8] = {0xaa, 0x00, targetAddr, CMD_QUERY_METER_IC_CORRECTION_PARA, 0x01, 0x00, 0xb0, 0xb0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[7] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 0)
- {
- if(len < (6+(rx[4] | rx[5]<<8)))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6]) == 0xb0)
- {
- uint32_t cali_flag = (rx[7] | (rx[8]<<8) | (rx[9]<<16) | (rx[10]<<24));
- if(!(cali_flag & 0x80000000))
- {
- Ret_Buf->bits.isCalibratedVaGain = cali_flag & (1 << 0) ? 1 : 0;
- Ret_Buf->bits.isCalibratedVbGain = cali_flag & (1 << 1) ? 1 : 0;
- Ret_Buf->bits.isCalibratedVcGain = cali_flag & (1 << 2) ? 1 : 0;
- Ret_Buf->bits.isCalibratedVaOffset = cali_flag & (1 << 3) ? 1 : 0;
- Ret_Buf->bits.isCalibratedVbOffset = cali_flag & (1 << 4) ? 1 : 0;
- Ret_Buf->bits.isCalibratedVcOffset = cali_flag & (1 << 5) ? 1 : 0;
- Ret_Buf->bits.isCalibratedCaGain = cali_flag & (1 << 6) ? 1 : 0;
- Ret_Buf->bits.isCalibratedCbGain = cali_flag & (1 << 7) ? 1 : 0;
- Ret_Buf->bits.isCalibratedCcGain = cali_flag & (1 << 8) ? 1 : 0;
- Ret_Buf->bits.isCalibratedCaOffset = cali_flag & (1 << 9) ? 1 : 0;
- Ret_Buf->bits.isCalibratedCbOffset = cali_flag & (1 << 10) ? 1 : 0;
- Ret_Buf->bits.isCalibratedCcOffset = cali_flag & (1 << 11) ? 1 : 0;
- Ret_Buf->bits.isCalibratedPa = cali_flag & (1 << 12) ? 1 : 0;
- Ret_Buf->bits.isCalibratedPb = cali_flag & (1 << 13) ? 1 : 0;
- Ret_Buf->bits.isCalibratedPc = cali_flag & (1 << 14) ? 1 : 0;
- }
- else
- {
- Ret_Buf->value = 0;
- }
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[15] = {0xaa, 0x00, targetAddr, CMD_CONFIG_FAN_SPEED, 0x08, 0x00, Set_Buf->speed[0]&0xff, (Set_Buf->speed[0]>>8)&0xff, Set_Buf->speed[1]&0xff, (Set_Buf->speed[1]>>8)&0xff, Set_Buf->speed[2]&0xff, (Set_Buf->speed[2]>>8)&0xff, Set_Buf->speed[3]&0xff, (Set_Buf->speed[3]>>8)&0xff, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[14] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Serial_Number(unsigned char fd, unsigned char targetAddr, Evse_Id *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[27] = {0xaa, 0x00, targetAddr, CMD_CONFIG_SERIAL_NUMBER, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- memcpy(&tx[14], &Set_Buf->serial_number[0], ARRAY_SIZE(Set_Buf->serial_number));
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[26] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, Evse_Id *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[21] = {0xaa, 0x00, targetAddr, CMD_CONFIG_MODEL_NAME, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- memcpy(&tx[6], &Set_Buf->model_name[0], ARRAY_SIZE(Set_Buf->model_name));
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[20] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[15] = {0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_RELAY_OUTPUT;
- tx[4] = 0x08;
- tx[5] = 0x00;
- tx[6] = 0x00;
- tx[7] = 0x00;
- tx[8] = 0x00;
- for(int idx_connector=0;idx_connector<2;idx_connector++)
- for(int idx = 0;idx<8;idx++)
- tx[9+idx_connector] |= ((Set_Buf->relay_status[idx_connector][idx]?0x01:0x00)<<idx);
- tx[11] = 0x00;
- tx[12] = 0x00;
- tx[13] = 0x00;
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[14] = chksum;
- //for(int count = 0; count < ARRAY_SIZE(tx); count++)
- //printf("TX[%d] : %x \n",count, tx[count]);
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[9] = {0xaa, 0x00, targetAddr, CMD_CONFIG_GPIO_OUTPUT, 0x01, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[6] |= (Set_Buf->AC_Connector?0x01:0x00);
- for(int idx=0;idx<2;idx++)
- tx[6] |= (Set_Buf->Button_LED[idx]?0x01:0x00)<<(1+idx);
- for(int idx=0;idx<4;idx++)
- tx[6] |= (Set_Buf->System_LED[idx]?0x01:0x00)<<(3+idx);
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[8] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == tx[6]))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[21] = {0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_RTC;
- tx[4] = 0x0e;
- tx[5] = 0x00;
- tx[6] = ((Set_Buf->year)/1000)+'0';
- tx[7] = ((Set_Buf->year)/100%10)+'0';
- tx[8] = ((Set_Buf->year)/10%10)+'0';
- tx[9] = ((Set_Buf->year)%10)+'0';
- tx[10] = ((Set_Buf->month)/10)+'0';
- tx[11] = ((Set_Buf->month)%10)+'0';
- tx[12] = ((Set_Buf->day)/10)+'0';
- tx[13] = ((Set_Buf->day)%10)+'0';
- tx[14] = ((Set_Buf->hour)/10)+'0';
- tx[15] = ((Set_Buf->hour)%10)+'0';
- tx[16] = ((Set_Buf->min)/10)+'0';
- tx[17] = ((Set_Buf->min)%10)+'0';
- tx[18] = ((Set_Buf->sec)/10)+'0';
- tx[19] = ((Set_Buf->sec)%10)+'0';
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[20] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_AC_MCU_LED(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Led *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[12] = {0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_AC_LED;
- tx[4] = 0x05;
- tx[5] = 0x00;
- tx[6] = Set_Buf->mode;
- tx[7] = ((Set_Buf->alarm_code>>0)&0xff);
- tx[8] = ((Set_Buf->alarm_code>>8)&0xff);
- tx[9] = ((Set_Buf->alarm_code>>16)&0xff);
- tx[10] = ((Set_Buf->alarm_code>>24)&0xff);
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[11] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_AC_MCU_LEGACY_REQUEST(unsigned char fd, unsigned char targetAddr, Legacy_Request *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[9] = {0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_LEGACY_REQUEST;
- tx[4] = 0x02;
- tx[5] = 0x00;
- tx[6] = Set_Buf->isLegacyRequest;
- tx[7] = 0x00;
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[8] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_AC_MCU_RESET_REQUEST(unsigned char fd, unsigned char targetAddr, Mcu_Reset_Request *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[9] = {0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_MCU_RESET_REQUEST;
- tx[4] = 0x02;
- tx[5] = 0x00;
- tx[6] = Set_Buf->isMcuResetRequest;
- tx[7] = 0x00;
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[8] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Query_AC_GUN_PLUGIN_TIMES(unsigned char fd, unsigned char targetAddr, Gun_Plugin_Times *Ret_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GUN_PLUGIN_TIMES, 0x00, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]))
- {
- Ret_Buf-> GunPluginTimes = ((uint32_t)rx[6] | (((uint32_t)rx[7])<<8) | (((uint32_t)rx[8])<<16) | (((uint32_t)rx[9])<<24));
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Cp_Pwm_Duty *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[8] = {0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_CURRENT_LINIT;
- tx[4] = 0x01;
- tx[5] = 0x00;
- tx[6] = Set_Buf->max_current;
- //DEBUG_WARN("Config_AC_MaxCurrent_And_CpPwmDuty...%d\n", Set_Buf->max_current);
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[7] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- ((rx[6] == 0x00) || (rx[6] == 0x01)))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_AC_Set_Breathe_Led_Timing(unsigned char fd, unsigned char targetAddr,Set_Breathe_Led_Timing *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[19] = {0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_MCU_SET_BREATHE_LED_TIMING;
- tx[4] = 0x0C;
- tx[5] = 0x00;
- // Increase LED_ACTION_CONNECTED
- tx[6] = (Set_Buf->set_Led_Action_Connected_Fade_In & 0xff);
- tx[7] = (Set_Buf->set_Led_Action_Connected_Fade_In >> 8);
- // Decrease LED_ACTION_CONNECTED
- tx[8] = (Set_Buf->set_Led_Action_Connected_Fade_Out & 0xff);
- tx[9] = (Set_Buf->set_Led_Action_Connected_Fade_Out >> 8);
- // Increase LED_ACTION_AUTHED
- tx[10] = (Set_Buf->set_Led_Action_Authed_Fade_In & 0xff);
- tx[11] = (Set_Buf->set_Led_Action_Authed_Fade_In >> 8);
- // Decrease LED_ACTION_AUTHED
- tx[12] = (Set_Buf->set_Led_Action_Authed_Fade_Out & 0xff);
- tx[13] = (Set_Buf->set_Led_Action_Authed_Fade_Out >> 8);
- // Increase_LED_ACTION_CHARGING
- tx[14] = (Set_Buf->Set_Led_Action_Chaging_Fade_In & 0xff);
- tx[15] = (Set_Buf->Set_Led_Action_Chaging_Fade_In >> 8);
- // Decrease_LED_ACTION_CHARGING
- tx[16] = (Set_Buf->set_Led_Action_Chaging_Fade_Out & 0xff);
- tx[17] = (Set_Buf->set_Led_Action_Chaging_Fade_Out >> 8);
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[18] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_AC_Set_Led_Brightness(unsigned char fd, unsigned char targetAddr,Set_Led_Brightness *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[19] = {0};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_MCU_SET_LED_BRIGHTNESS;
- tx[4] = 0x0C;
- tx[5] = 0x00;
- tx[6] = Set_Buf-> sector_1; // 0~1 AM and 1~2 AM
- tx[7] = Set_Buf-> sector_2; // 2~3 AM and 3~4 AM
- tx[8] = Set_Buf-> sector_3; // 4~5 AM and 5~6 AM
- tx[9] = Set_Buf-> sector_4; // 6~7 AM and 7~8 AM
- tx[10] = Set_Buf-> sector_5; // 8~9 AM and 9~10 AM
- tx[11] = Set_Buf-> sector_6; // 10~11 AM and 11~12 AM
- tx[12] = Set_Buf-> sector_7; // 12~13 PM and 13~14 PM
- tx[13] = Set_Buf-> sector_8; // 14~15 PM and 15~16 PM
- tx[14] = Set_Buf-> sector_9; // 16~17 PM and 17~18 PM
- tx[15] = Set_Buf-> sector_10; // 18~19 PM and 19~20 PM
- tx[16] = Set_Buf-> sector_11; // 20~21 PM and 21~22 PM
- tx[17] = Set_Buf-> sector_12; // 22~23 PM and 23~24 PM
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[18] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Config_Aux_Power_Switch(unsigned char fd, unsigned char targetAddr, Set_Aux_Power_Switch *Set_Buf)
- {
- unsigned char result = FAIL;
- unsigned char tx[9];
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_CONFIG_AUX_POWER_SWITCH;
- tx[4] = 0x02;
- tx[5] = 0x00;
- tx[6] = Set_Buf->power_type; // 0~1 AM and 1~2 AM
- tx[7] = Set_Buf->power_switch; // 2~3 AM and 3~4 AM
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[8] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
- {
- unsigned char result = FAIL;
- unsigned char tx[11] = {0xaa, 0x00, targetAddr, CMD_UPDATE_START, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&0xff, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[10] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- chksum = 0x00;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x00))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_UPDATE_ABOARD, 0x04, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x00))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
- {
- unsigned char result = FAIL;
- unsigned char tx[11 + length];
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- tx[0] = 0xaa;
- tx[1] = 0x00;
- tx[2] = targetAddr;
- tx[3] = CMD_UPDATE_TRANSFER;
- tx[4] = (4 + length) & 0xff;
- tx[5] = ((4 + length)>>8) & 0xff;
- tx[6] = (startAddr>>0) & 0xff;
- tx[7] = (startAddr>>8) & 0xff;
- tx[8] = (startAddr>>16) & 0xff;
- tx[9] = (startAddr>>24) & 0xff;
- memcpy(tx+10, data, length);
- for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
- chksum ^= tx[6+idx];
- tx[ARRAY_SIZE(tx)-1] = chksum;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x00))
- {
- result = PASS;
- }
- }
- return result;
- }
- unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
- {
- unsigned char result = FAIL;
- unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_UPDATE_END, 0x04, 0x00, 0x00};
- unsigned char rx[512];
- unsigned char chksum = 0x00;
- unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
- if(len > 6)
- {
- if(len < 6+(rx[4] | rx[5]<<8))
- return result;
- for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
- {
- chksum ^= rx[6+idx];
- }
- if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
- (rx[2] == tx[1]) &&
- (rx[1] == tx[2]) &&
- (rx[3] == tx[3]) &&
- (rx[6] == 0x01))
- {
- result = PASS;
- }
- }
- return result;
- }
- //================================================
- // Main process
- //================================================
- int main(void)
- {
- int Uart1Fd;
- unsigned short int failCount[2] = {0,0};
- struct Charger previousCharger;
- if(InitShareMemory() == FAIL)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("InitShareMemory NG\n");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
- }
- sleep(5);
- return 0;
- }
- else
- {
- DEBUG_INFO("InitShareMemory OK.\n");
- }
- Uart1Fd=InitComPort();
- if(Uart1Fd<0)
- {
- DEBUG_ERROR("InitComPort NG\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- return 0;
- }
- else
- {
- DEBUG_INFO("ttyS1 port open success.\n");
- }
- if(fork() == 0)
- {
- for(;;)
- {
- for(int gun_index=0;gun_index<AC_QUANTITY;gun_index++)
- {
- //==========================================================
- // High priority polling log print out
- //==========================================================
- //==================================================
- // Case 1: Config primary MCU LED
- //==================================================
- if((previousCharger.gun_info[gun_index].primaryMcuLed.mode != ShmCharger->gun_info[gun_index].primaryMcuLed.mode) ||
- (previousCharger.gun_info[gun_index].primaryMcuLed.alarm_code != ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code))
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 1 ******\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d set Led mode : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.mode);
- DEBUG_INFO("MCU-%d set Alarm code : %x\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code);
- previousCharger.gun_info[gun_index].primaryMcuLed.mode = ShmCharger->gun_info[gun_index].primaryMcuLed.mode;
- previousCharger.gun_info[gun_index].primaryMcuLed.alarm_code = ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code;
- }
- //==================================================
- // Case 2: Config primary Legacy request
- //==================================================
- if(previousCharger.gun_info[gun_index].legacyRequest.isLegacyRequest != ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest)
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 2 ******\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d set PWN request : %d\n", gun_index, ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
- previousCharger.gun_info[gun_index].legacyRequest.isLegacyRequest = ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest;
- }
- //==================================================
- // Case 2: Config primary Relay
- //==================================================
- if((previousCharger.gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0] != ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0]) ||
- (previousCharger.gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1] != ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1]) ||
- (previousCharger.gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2] != ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2]) ||
- (previousCharger.gun_info[gun_index].primaryMcuState.relayState.relay_status[0][3] != ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][3]))
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("**** High priority polling : Case 2-X *****\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d set relay status [0][0] : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0]);
- DEBUG_INFO("MCU-%d set relay status [0][1] : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1]);
- DEBUG_INFO("MCU-%d set relay status [0][2] : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2]);
- DEBUG_INFO("MCU-%d set relay status [0][3] : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][3]);
- previousCharger.gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0] = ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0];
- previousCharger.gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1] = ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1];
- previousCharger.gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2] = ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2];
- previousCharger.gun_info[gun_index].primaryMcuState.relayState.relay_status[0][3] = ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][3];
- }
- //==================================================
- // Case 3: Query primary MCU status
- //==================================================
- if((previousCharger.gun_info[gun_index].primaryMcuState.cp_state != ShmCharger->gun_info[gun_index].primaryMcuState.cp_state) ||
- (previousCharger.gun_info[gun_index].primaryMcuState.current_limit != ShmCharger->gun_info[gun_index].primaryMcuState.current_limit) ||
- (previousCharger.gun_info[gun_index].primaryMcuState.relay_state != ShmCharger->gun_info[gun_index].primaryMcuState.relay_state) ||
- (previousCharger.gun_info[gun_index].primaryMcuState.rotatory_switch != ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch) ||
- (previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode != ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode) ||
- (previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn != ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn))
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 3 ******\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d get Pilot State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
- DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
- DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
- DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
- if(ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON)
- {
- if(ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn == ON)
- DEBUG_INFO("Relay mode : CHARGING_MODE_SOCKETE. \n");
- else
- DEBUG_INFO("Relay mode : CHARGING_MODE_BS / CHARGING_MODE_HLC. \n");
- }
- DEBUG_INFO("MCU-%d get Relay State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
- DEBUG_INFO("MCU-%d get Rating Current : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
- DEBUG_INFO("MCU-%d get Rotary switch : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
- DEBUG_INFO("MCU-%d get is on Socket-E mode : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode);
- DEBUG_INFO("MCU-%d get Socket-E detect pin : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn);
- DEBUG_INFO("MCU-%d get Locker State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
- DEBUG_INFO("MCU-%d get Shutter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
- DEBUG_INFO("MCU-%d get Meter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
- DEBUG_INFO("MCU-%d get PP State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
- previousCharger.gun_info[gun_index].primaryMcuState.cp_state = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
- previousCharger.gun_info[gun_index].primaryMcuState.current_limit = ShmCharger->gun_info[gun_index].primaryMcuState.current_limit;
- previousCharger.gun_info[gun_index].primaryMcuState.rotatory_switch = ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch;
- previousCharger.gun_info[gun_index].primaryMcuState.relay_state = ShmCharger->gun_info[gun_index].primaryMcuState.relay_state;
- previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode = ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode;
- previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn = ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn;
- }
- //==================================================
- // Case 4: Query primary MCU Alarm code
- //==================================================
- if((previousCharger.gun_info[gun_index].primaryMcuAlarm.InputAlarmCode != ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode))
- {
- if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode>0))
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 4 ******\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d get OVP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L1);
- DEBUG_INFO("MCU-%d get UVP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L1);
- DEBUG_INFO("MCU-%d get OCP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1);
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- DEBUG_INFO("MCU-%d get OVP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L2);
- DEBUG_INFO("MCU-%d get UVP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L2);
- DEBUG_INFO("MCU-%d get OCP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2);
- DEBUG_INFO("MCU-%d get OVP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L3);
- DEBUG_INFO("MCU-%d get UVP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L3);
- DEBUG_INFO("MCU-%d get OCP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3);
- }
- DEBUG_INFO("MCU-%d get OTP : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
- DEBUG_INFO("MCU-%d get gmi_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
- DEBUG_INFO("MCU-%d get cp_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
- DEBUG_INFO("MCU-%d get ac_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
- DEBUG_INFO("MCU-%d get dc_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
- DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
- DEBUG_INFO("MCU-%d get handshaking_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
- DEBUG_INFO("MCU-%d get emergency_stop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
- DEBUG_INFO("MCU-%d get relay_welding : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
- DEBUG_INFO("MCU-%d get leak_module_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
- DEBUG_INFO("MCU-%d get shutter_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
- DEBUG_INFO("MCU-%d get locker_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
- DEBUG_INFO("MCU-%d get power_drop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
- DEBUG_INFO("MCU-%d get rotate_switch_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.rotate_switch_fault);
- DEBUG_INFO("MCU-%d get short_circuit_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L1);
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- DEBUG_INFO("MCU-%d get short_circuit_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L2);
- DEBUG_INFO("MCU-%d get short_circuit_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L3);
- }
- DEBUG_INFO("MCU-%d get relay_drive_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
- DEBUG_INFO("MCU-%d get meter_comm_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_comm_timeout);
- DEBUG_INFO("MCU-%d get meter_ic_comm_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_ic_comm_timeout);
- DEBUG_INFO("MCU-%d get pilot_negative_error : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.pilot_negative_error);
- DEBUG_INFO("MCU-%d get InputAlarmCode : %x\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
- }
- previousCharger.gun_info[gun_index].primaryMcuAlarm.InputAlarmCode = ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode;
- }
- //==================================================
- // Case 5: Query primary MCU BLE config
- //==================================================
- /*
- if((previousCharger.gun_info[gun_index].bleConfigData.isLogin != ShmCharger->gun_info[gun_index].bleConfigData.isLogin) ||
- (previousCharger.gun_info[gun_index].bleConfigData.isRequestStart != ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart) ||
- (previousCharger.gun_info[gun_index].bleConfigData.isRequestStop != ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop))
- {
- if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin == ON)
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 5 ******\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d get isUserLogin : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
- DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
- DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
- }
- previousCharger.gun_info[gun_index].bleConfigData.isLogin = ShmCharger->gun_info[gun_index].bleConfigData.isLogin;
- previousCharger.gun_info[gun_index].bleConfigData.isRequestStart = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart;
- previousCharger.gun_info[gun_index].bleConfigData.isRequestStop = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop;
- }
- */
- //==================================================
- // Case 6: Query primary MCU ble login id
- //==================================================
- /*
- if((strcmp((char *)&previousCharger.gun_info[gun_index].bleLoginCentralId.id,(char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id) != 0))
- {
- if(strcmp((char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id,"") != 0)
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 6 ******\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d get ble central id : %s\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
- }
- memcpy(&previousCharger.gun_info[gun_index].bleLoginCentralId.id, ShmCharger->gun_info[gun_index].bleLoginCentralId.id, ARRAY_SIZE(ShmCharger->gun_info[gun_index].bleLoginCentralId.id));
- }
- */
- //==================================================
- // Case 8: Config primary MCU duty
- //==================================================
- if(previousCharger.gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 8 ******\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d set cp pwn duty : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
- previousCharger.gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current;
- }
- //==================================================
- // Case 10: Query primary MCU power consumption
- //==================================================
- if((abs(ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption - previousCharger.gun_info[gun_index].powerConsumptionTotal.power_consumption) > 200) ||
- (abs(ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption - previousCharger.gun_info[gun_index].powerConsumption[0].power_consumption) > 200) ||
- (abs(ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption - previousCharger.gun_info[gun_index].powerConsumption[1].power_consumption) > 200) ||
- (abs(ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption - previousCharger.gun_info[gun_index].powerConsumption[2].power_consumption) > 200))
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 10 *****\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d get total power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0));
- DEBUG_INFO("MCU-%d get L1N_L12 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/10000.0));
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- DEBUG_INFO("MCU-%d get L2N_L23 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/10000.0));
- DEBUG_INFO("MCU-%d get L3N_L31 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/10000.0));
- }
- previousCharger.gun_info[gun_index].powerConsumptionTotal.power_consumption = ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption;
- previousCharger.gun_info[gun_index].powerConsumption[0].power_consumption = ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption;
- previousCharger.gun_info[gun_index].powerConsumption[1].power_consumption = ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption;
- previousCharger.gun_info[gun_index].powerConsumption[2].power_consumption = ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption;
- }
- //==================================================
- // Case 11: Query primary Out put current config
- //==================================================
- if((abs((int)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0] - (int)previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0]) >= 2) ||
- (abs((int)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0] - (int)previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0]) >= 2) ||
- (abs((int)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0] - (int)previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0]) >= 2))
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("***** High priority polling : Case 11 *****\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d get output current L1: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- DEBUG_INFO("MCU-%d get output current L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]);
- DEBUG_INFO("MCU-%d get output current L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]);
- }
- previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0] = ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] = ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
- previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] = ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
- }
- //==========================================================
- // Low priority polling log print out
- //==========================================================
- //==================================================
- // Case 1: Query primary In put voltage
- //==================================================
- if((abs((int)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12 - (int)previousCharger.gun_info[gun_index].inputVoltage.L1N_L12) >= 2) ||
- (abs((int)ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23 - (int)previousCharger.gun_info[gun_index].inputVoltage.L2N_L23) >= 2) ||
- (abs((int)ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31 - (int)previousCharger.gun_info[gun_index].inputVoltage.L3N_L31) >= 2))
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 1 =====\n");
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("MCU-%d get Input voltage L1: %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
- DEBUG_INFO("MCU-%d get PresentChargingVoltage L1: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage);
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- DEBUG_INFO("MCU-%d get Input voltage L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23);
- DEBUG_INFO("MCU-%d get PresentChargingVoltage L2: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL2);
- DEBUG_INFO("MCU-%d get Input voltage L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31);
- DEBUG_INFO("MCU-%d get PresentChargingVoltage L3: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL3);
- }
- previousCharger.gun_info[gun_index].inputVoltage.L1N_L12 = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
- previousCharger.gun_info[gun_index].inputVoltage.L2N_L23 = ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23;
- previousCharger.gun_info[gun_index].inputVoltage.L3N_L31 = ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31;
- }
- //==================================================
- // Case 5: Query primary plug in times
- //==================================================
- if(previousCharger.gun_info[gun_index].gunPluginTimes.GunPluginTimes != ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 5 =====\n");
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("MCU-%d get gun plugin times : %ld\n", gun_index, (long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
- previousCharger.gun_info[gun_index].gunPluginTimes.GunPluginTimes = ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes;
- }
- //==================================================
- // Case 7: Query primary temperature
- //==================================================
- if(previousCharger.gun_info[gun_index].temperature.point[0] != ShmCharger->gun_info[gun_index].temperature.point[0])
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 7 =====\n");
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("MCU-%d get temperature : %d\n", gun_index, ShmCharger->gun_info[gun_index].temperature.point[0]);
- previousCharger.gun_info[gun_index].temperature.point[0] = ShmCharger->gun_info[gun_index].temperature.point[0];
- }
- //==================================================
- // Case 11: Config primary RTC time
- //==================================================
- if(previousCharger.gun_info[gun_index].rtc.min != ShmCharger->gun_info[gun_index].rtc.min)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 11 ====\n");
- DEBUG_INFO("===========================================\n");
- if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin && !ShmOCPP16Data->OcppConnStatus)
- {
- DEBUG_INFO("Sync from MCU-%d rtc OK...%04d-%02d-%02d %02d:%02d:%02d\n", gun_index,
- ShmCharger->gun_info[gun_index].rtc.year,
- ShmCharger->gun_info[gun_index].rtc.month,
- ShmCharger->gun_info[gun_index].rtc.day,
- ShmCharger->gun_info[gun_index].rtc.hour,
- ShmCharger->gun_info[gun_index].rtc.min,
- ShmCharger->gun_info[gun_index].rtc.sec);
- }
- else
- {
- DEBUG_INFO("MCU-%d set rtc OK...%04d-%02d-%02d %02d:%02d:%02d\n", gun_index,
- ShmCharger->gun_info[gun_index].rtc.year,
- ShmCharger->gun_info[gun_index].rtc.month,
- ShmCharger->gun_info[gun_index].rtc.day,
- ShmCharger->gun_info[gun_index].rtc.hour,
- ShmCharger->gun_info[gun_index].rtc.min,
- ShmCharger->gun_info[gun_index].rtc.sec);
- }
-
- previousCharger.gun_info[gun_index].rtc.min = ShmCharger->gun_info[gun_index].rtc.min;
- }
- //==================================================
- // Case 15: Config led breathe timing
- //==================================================
- if((previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In) ||
- (previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out) ||
- (previousCharger.gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In != ShmCharger->gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In) ||
- (previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out) ||
- (previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In) ||
- (previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out))
- {
- if(ShmCharger->gun_info[gun_index].isSetBreatheLedTiming == ON)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 15 ====\n");
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("MCU-%d set breathe led timing : Authed Fade in [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In);
- DEBUG_INFO("MCU-%d set breathe led timing : Authed Fade out [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out);
- DEBUG_INFO("MCU-%d set breathe led timing : Charging Fade in [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In);
- DEBUG_INFO("MCU-%d set breathe led timing : Charging Fade out [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out);
- DEBUG_INFO("MCU-%d set breathe led timing : Connected Fade in [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In);
- DEBUG_INFO("MCU-%d set breathe led timing : Connected Fade out [%ld].\n", gun_index, (long)ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out);
- }
- previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In;
- previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out;
- previousCharger.gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In = ShmCharger->gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In;
- previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out;
- previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In;
- previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out;
- }
- //==================================================
- // Case 17: Config led brightness
- //==================================================
- if((previousCharger.gun_info[gun_index].setLedBrightness.sector_1 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_1) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_2 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_2) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_3 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_3) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_4 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_4) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_5 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_5) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_6 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_6) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_7 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_7) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_8 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_8) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_9 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_9) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_10 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_10) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_11 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_11) ||
- (previousCharger.gun_info[gun_index].setLedBrightness.sector_12 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_12))
- {
- if(ShmCharger->gun_info[gun_index].isSetLedBrightness == ON)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 17 ====\n");
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("MCU-%d set led brightness Sector 01 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_1);
- DEBUG_INFO("MCU-%d set led brightness Sector 02 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_2);
- DEBUG_INFO("MCU-%d set led brightness Sector 03 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_3);
- DEBUG_INFO("MCU-%d set led brightness Sector 04 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_4);
- DEBUG_INFO("MCU-%d set led brightness Sector 05 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_5);
- DEBUG_INFO("MCU-%d set led brightness Sector 06 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_6);
- DEBUG_INFO("MCU-%d set led brightness Sector 07 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_7);
- DEBUG_INFO("MCU-%d set led brightness Sector 08 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_8);
- DEBUG_INFO("MCU-%d set led brightness Sector 09 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_9);
- DEBUG_INFO("MCU-%d set led brightness Sector 10 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_10);
- DEBUG_INFO("MCU-%d set led brightness Sector 11 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_11);
- DEBUG_INFO("MCU-%d set led brightness Sector 12 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_12);
- }
- previousCharger.gun_info[gun_index].setLedBrightness.sector_1 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_1;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_2 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_2;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_3 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_3;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_4 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_4;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_5 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_5;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_6 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_6;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_7 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_7;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_8 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_8;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_9 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_9;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_10 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_10;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_11 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_11;
- previousCharger.gun_info[gun_index].setLedBrightness.sector_12 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_12;
- }
- }
- usleep(100000);
- }
- exit(0);
- }
- for(;;)
- {
- for(int gun_index=0;gun_index<AC_QUANTITY;gun_index++)
- {
- /*
- * Polling loop
- */
- if((stepIndex%2)==0)
- {
- /*
- * High priority communication
- */
- //===============================
- // Case 1 : Config primary MCU LED
- //===============================
- ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code = ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode;
- if(Config_AC_MCU_LED(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuLed))
- {
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d set led fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- //===============================
- // Case 2 : Config primary Legacy request
- //===============================
- if(Config_AC_MCU_LEGACY_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1),&ShmCharger->gun_info[gun_index].legacyRequest))
- {
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d set PWN request fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
-
- //===============================
- // Case 2-X : Config primary Relay
- //===============================
- if(Config_Relay_Output(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1),&ShmCharger->gun_info[gun_index].primaryMcuState.relayState))
- {
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d set relay fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- //===============================
- // Case 3 : Query primary MCU status
- //===============================
- if(Query_AC_MCU_Status(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuState))
- {
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotDuty = (ShmCharger->gun_info[gun_index].primaryMcuState.current_limit>51?(unsigned char)((ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/2.5)+64):(unsigned char)(ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/0.6));
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotVoltage = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive;
- ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive;
- ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive;
-
- //pass info 2 CCS task
- if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_UNKNOWN)
- {
- if(ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative >= -12)
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_G;
- }
- else
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_H;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_A;
- }
- else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)
- {
- if(ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative == 0.0)
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_B1;
- }
- else
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_B2;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C)
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_C;
- }
- else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_D)
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_D;
- }
- else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_E)
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_E;
- }
- else //CP_STATE_F
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_F;
- }
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPositiveVoltage = ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive;
- ShmCharger->gun_info[gun_index].acCcsInfo.CpNegativeVoltage = ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative;
- ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentPWMDuty = ShmCharger->gun_info[gun_index].primaryMcuState.current_limit;
-
- if(ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.OutputRelayStatus = ON;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].RelayK1K2Status = ON;
- }
- else
- {
- ShmCharger->gun_info[gun_index].acCcsInfo.OutputRelayStatus = OFF;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].RelayK1K2Status = OFF;
- }
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get status fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- //===============================
- // Case 4 : Query primary MCU Alarm code
- //===============================
- if(Query_AC_MCU_Alarm(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuAlarm))
- {
- //DEBUG_INFO("MCU-%d get alarm code success.\n",gun_index);
- failCount[gun_index] = 0;
- ShmCharger->gun_info[gun_index].acCcsInfo.CSUAlarmStatusCode = ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode;
- }
- else
- {
- DEBUG_WARN("MCU-%d get alarm fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- /*
- //===============================
- // Case 5 : Query primary MCU BLE config
- //===============================
- if(Query_Ble_Config(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].bleConfigData))
- {
- ShmSysConfigAndInfo->SysConfig.Bluetooth.isLogin = ShmCharger->gun_info[gun_index].bleConfigData.isLogin;
- ShmSysConfigAndInfo->SysConfig.Bluetooth.isRequestStart = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart;
- ShmSysConfigAndInfo->SysConfig.Bluetooth.isRequestStop = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop;
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get ble config fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- //===============================
- // Case 6 : Query primary MCU ble login id
- //===============================
- if(Query_Ble_Central_ID(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].bleLoginCentralId))
- {
- memcpy(ShmSysConfigAndInfo->SysConfig.Bluetooth.LoginCentralID, ShmCharger->gun_info[gun_index].bleLoginCentralId.id, sizeof ShmSysConfigAndInfo->SysConfig.Bluetooth.LoginCentralID);
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get ble login central id fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }*/
- //===============================
- // Case 7 : Config primary MCU reset request
- //===============================
- if((access("/sys/class/gpio/gpio116/value", F_OK)) != -1)
- {
- if(ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest == ON)
- {
- if(Config_AC_MCU_RESET_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].mcuResetRequest) == PASS)
- {
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("**** High priority polling : Case 7 *******\n");
- DEBUG_INFO("*******************************************\n");
- DEBUG_INFO("MCU-%d set MCU reset Request : %d\n", gun_index, ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest);
- ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest = OFF;
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get MCU reset fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- }
- //===============================
- // Case 8 : Config primary set CP PWN duty
- //===============================
- if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == ON)
- {
- //DEBUG_WARN("Case 8 : Config primary set CP PWN duty...%d\n", ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty);
- if(Config_AC_MaxCurrent_And_CpPwmDuty(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty))
- {
- failCount[gun_index] = 0;
- ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = OFF;
- }
- else
- {
- DEBUG_WARN("MCU-%d set cp pwn duty fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- //===============================
- // Case 9 : Query GPIO
- //===============================
- if(Query_Gpio_Input(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].GPIO_Input))
- {
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get GPIO input fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- //===============================
- // Case 10 : Query primary MCU power consumption
- //===============================
- if(Query_Power_Consumption(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].powerConsumptionTotal, &ShmCharger->gun_info[gun_index].powerConsumption[0], &ShmCharger->gun_info[gun_index].powerConsumption[1], &ShmCharger->gun_info[gun_index].powerConsumption[2]))
- {
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get power consumption fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
-
- //===============================
- // Case 11 : Query present output current
- //===============================
- if(Query_Present_OutputCurrent(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].outputCurrent) == PASS)
- {
- #ifndef SIMULATION
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
-
-
- ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[0] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[1] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[2] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- #else //SIMULATION
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
- }
- #endif //SIMULATION
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get output current fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- else
- {
- /*
- * Normal priority communication
- */
- switch(stepIndex)
- {
- case 1:
- //===============================
- // Query present input voltage
- //===============================
- if(Query_Present_InputVoltage(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].inputVoltage) == PASS)
- {
- ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
- ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23;
- ShmSysConfigAndInfo->SysInfo.InputVoltageT = ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31;
-
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL2 = ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL3 = ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31;
-
- ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[0] = ShmSysConfigAndInfo->SysInfo.InputVoltageR;
- ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[1] = ShmSysConfigAndInfo->SysInfo.InputVoltageS;
- ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[2] = ShmSysConfigAndInfo->SysInfo.InputVoltageT;
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get input voltage fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- break;
- case 3:
- /*
- //===============================
- // Query present output current
- //===============================
- if(Query_Present_OutputCurrent(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].outputCurrent) == PASS)
- {
- #ifndef SIMULATION
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
-
-
- ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[0] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[1] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[2] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
- #else //SIMULATION
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
- if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
- {
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
- }
- #endif //SIMULATION
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get output current fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- */
- break;
- case 5:
- //===============================
- // Query gun plug-in times
- //===============================
- if(Query_AC_GUN_PLUGIN_TIMES(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].gunPluginTimes) == PASS)
- {
- ShmSysConfigAndInfo->SysConfig.AcPlugInTimes = ((long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes & 0xFFFF);
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get gun plugin times fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- break;
- case 7:
- //===============================
- // Query temperature
- //===============================
- if(Query_Temperature(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].temperature) == PASS)
- {
- ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = ShmCharger->gun_info[gun_index].temperature.point[0];
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ConnectorTemp = ShmCharger->gun_info[gun_index].temperature.point[0];
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get temperature fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- break;
- case 9:
- //===============================
- // Query RTC
- //===============================
- if(Query_RTC(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].rtc))
- {
- struct timeb csuTime, mcuTime;
- struct tm *tmCSU;
- struct tm tmMcu;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- tmMcu.tm_year = ShmCharger->gun_info[gun_index].rtc.year-1900;
- tmMcu.tm_mon = ShmCharger->gun_info[gun_index].rtc.month-1;
- tmMcu.tm_mday = ShmCharger->gun_info[gun_index].rtc.day;
- tmMcu.tm_hour = ShmCharger->gun_info[gun_index].rtc.hour;
- tmMcu.tm_min = ShmCharger->gun_info[gun_index].rtc.min;
- tmMcu.tm_sec = ShmCharger->gun_info[gun_index].rtc.sec;
- mcuTime.time = mktime(&tmMcu);
- if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin && !ShmOCPP16Data->OcppConnStatus)
- {
- if(abs(DiffTimeb(csuTime, mcuTime)) > 10000)
- {
- char cmdBuf[128];
- sprintf(cmdBuf, "date -u -s \"%04d-%02d-%02d %02d:%02d:%02d\"", ShmCharger->gun_info[gun_index].rtc.year,
- ShmCharger->gun_info[gun_index].rtc.month,
- ShmCharger->gun_info[gun_index].rtc.day,
- ShmCharger->gun_info[gun_index].rtc.hour,
- ShmCharger->gun_info[gun_index].rtc.min,
- ShmCharger->gun_info[gun_index].rtc.sec);
- system(cmdBuf);
- system("hwclock -w -u");
- system("hwclock -s");
- }
- }
- else
- {
- if(abs(DiffTimeb(csuTime, mcuTime)) > 10000)
- {
- ShmCharger->gun_info[gun_index].rtc.year = tmCSU->tm_year+1900;
- ShmCharger->gun_info[gun_index].rtc.month = tmCSU->tm_mon+1;
- ShmCharger->gun_info[gun_index].rtc.day = tmCSU->tm_mday;
- ShmCharger->gun_info[gun_index].rtc.hour = tmCSU->tm_hour;
- ShmCharger->gun_info[gun_index].rtc.min = tmCSU->tm_min;
- ShmCharger->gun_info[gun_index].rtc.sec = tmCSU->tm_sec;
- Config_RTC(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].rtc);
- }
- }
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get rtc fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- break;
- case 11:
- break;
- case 13:
- //===============================
- // Upgrade MCU
- //===============================
- if(ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 13 ====\n");
- DEBUG_INFO("===========================================\n");
- unsigned char cmd[512];
- if(Upgrade_UART(Uart1Fd, AC_WALLMOUNT_CONTROLLER, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), ShmCharger->fwUpgradeInfo.location, ShmCharger->fwUpgradeInfo.modelName))
- {
- DEBUG_INFO("MCU-%d upgrade firmware OK...%s\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
- sleep(20);
- ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq = OFF;
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d upgrade firmware fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- sprintf((char*)cmd, "yes|rm %s", ShmCharger->fwUpgradeInfo.location);
- system((char*)cmd);
- }
- break;
- case 15:
- //===============================
- // Config set breathe led timing
- //===============================
- if(ShmCharger->gun_info[gun_index].isSetBreatheLedTiming == ON)
- {
- if(Config_AC_Set_Breathe_Led_Timing(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].setBreatheLedTiming))
- {
- failCount[gun_index] = 0;
- ShmCharger->gun_info[gun_index].isSetBreatheLedTiming = OFF;
- }
- else
- {
- DEBUG_WARN("MCU-%d set breathe led timing fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- break;
- case 17:
- //===============================
- // Config set led brightness
- //===============================
- if(ShmCharger->gun_info[gun_index].isSetLedBrightness == ON)
- {
- if(Config_AC_Set_Led_Brightness(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].setLedBrightness))
- {
- failCount[gun_index] = 0;
- ShmCharger->gun_info[gun_index].isSetLedBrightness = OFF;
- }
- else
- {
- DEBUG_WARN("MCU-%d set led brightness fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- break;
- case 19:
- //===============================
- // Query firmware version
- //===============================
- if(ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass != PASS)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 19-1===\n");
- DEBUG_INFO("===========================================\n");
- if(Query_FW_Ver(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].ver) == PASS)
- {
- DEBUG_INFO("MCU-%d get firmware version : %s\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
- memcpy(ShmPrimaryMcuData->version, ShmCharger->gun_info[gun_index].ver.Version_FW, sizeof(ShmPrimaryMcuData->version));
- ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass = PASS;
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get firmware version fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- //===============================
- // Query meter ic correction status
- //===============================
- if(ShmCharger->gun_info[gun_index].mcuFlag.isReadMeterIcCorrectionStatus != PASS)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 19-2===\n");
- DEBUG_INFO("===========================================\n");
- if(Query_MeterIc_CorrectionPara(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].meterIcCorrectionStatus) == PASS)
- {
- DEBUG_INFO("MCU-%d get meter ic correction status: 0x%08X\n", gun_index, ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.value);
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVaGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVaGain;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVbGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVbGain;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVcGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVcGain;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVaOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVaOffset;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVbOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVbOffset;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVcOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVcOffset;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCaGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCaGain;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCbGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCbGain;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCcGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCcGain;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCaOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCaOffset;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCbOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCbOffset;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCcOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCcOffset;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedPa = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedPa;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedPb = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedPb;
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedPc = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedPc;
- ShmCharger->gun_info[gun_index].mcuFlag.isReadMeterIcCorrectionStatus = PASS;
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d get meter ic correction status fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- //===============================
- // Config primary MCU serial number
- //===============================
- if(ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass != PASS)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 19-3===\n");
- DEBUG_INFO("===========================================\n");
- memcpy(ShmCharger->evseId.serial_number, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmCharger->evseId.serial_number));
- if(Config_Serial_Number(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
- {
- DEBUG_INFO("MCU-%d set serial number : %.12s\n",gun_index,ShmCharger->evseId.serial_number);
- ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass = PASS;
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d set serial number fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- //===============================
- // Config primary MCU model name
- //===============================
- if(ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass != PASS)
- {
- DEBUG_INFO("===========================================\n");
- DEBUG_INFO("==== Normal priority polling : Case 19-4===\n");
- DEBUG_INFO("===========================================\n");
- memcpy(ShmCharger->evseId.model_name, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmCharger->evseId.model_name));
- if(Config_Model_Name(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
- {
- DEBUG_INFO("MCU-%d set model name : %.14s\n",gun_index,ShmCharger->evseId.model_name);
- ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass = PASS;
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d set model name fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- }
- break;
- case 21:
- //===============================
- // Config aux power switch
- //===============================
- ShmCharger->gun_info[gun_index].setAuxPowerSwitch.power_switch = 0x01;
- ShmCharger->gun_info[gun_index].setAuxPowerSwitch.power_switch = ShmCharger->gun_info[gun_index].isMeterOn;
- if(Config_Aux_Power_Switch(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].setAuxPowerSwitch))
- {
- failCount[gun_index] = 0;
- }
- else
- {
- DEBUG_WARN("MCU-%d set aux power switch fail...%d\n", gun_index, failCount[gun_index]);
- if(failCount[gun_index]<USHRT_MAX)
- failCount[gun_index]++;
- else
- failCount[gun_index] = FAIL_SPEC_COMM;
- }
- break;
- default:
- stepIndex = 0;
- break;
- }
- }
- stepIndex++;
- //===============================
- // Communication fail check
- //===============================
- if(failCount[gun_index] >= 13)
- ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
- if(failCount[gun_index] >= FAIL_SPEC_COMM)
- {
- if((0 <= failCount[gun_index]%FAIL_SPEC_COMM) && (failCount[gun_index]%FAIL_SPEC_COMM < 10))
- sleep(10);
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == OFF)
- {
- DEBUG_ERROR("Primary MCU-%d communication fault. \n", gun_index);
- ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout = ON;
- }
- }
- else
- {
- if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == ON)
- {
- DEBUG_ERROR("Primary MCU-%d communication recover. \n", gun_index);
- ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout = OFF;
- }
- }
- usleep(100000);
- }
- }
- return FAIL;
- }
|