Module_InternalComm.c 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082
  1. #include <sys/time.h>
  2. #include <sys/timeb.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/shm.h>
  11. #include <sys/mman.h>
  12. #include <linux/wireless.h>
  13. #include <arpa/inet.h>
  14. #include <netinet/in.h>
  15. #include <unistd.h>
  16. #include <stdarg.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <fcntl.h>
  21. #include <termios.h>
  22. #include <errno.h>
  23. #include <errno.h>
  24. #include <string.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <ifaddrs.h>
  28. #include <math.h>
  29. #include <limits.h>
  30. #include "define.h"
  31. #include "main.h"
  32. #include "Module_InternalComm.h"
  33. //#define SIMULATION
  34. #define FAIL_SPEC_COMM 100
  35. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  36. #define PASS 1
  37. #define FAIL 0
  38. #define ON 1
  39. #define OFF 0
  40. #define PRIORITY_HIGH 0
  41. #define PRIORITY_LOW 1
  42. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  43. struct StatusCodeData *ShmStatusCodeData;
  44. struct PrimaryMcuData *ShmPrimaryMcuData;
  45. struct OCPP16Data *ShmOCPP16Data;
  46. struct Charger *ShmCharger;
  47. uint16_t stepIndex=21, logIndex;
  48. long long tsLast, tsNow, tsPrintLog[2];
  49. uint64_t tmpPowerConsumption;
  50. void trim(char *s);
  51. int mystrcmp(char *p1,char *p2);
  52. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
  53. void split(char **arr, char *str, const char *del);
  54. int StoreLogMsg(const char *fmt, ...)
  55. {
  56. char Buf[4096+256];
  57. char buffer[4096];
  58. time_t CurrentTime;
  59. struct tm *tm;
  60. struct timeval tv;
  61. va_list args;
  62. va_start(args, fmt);
  63. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  64. va_end(args);
  65. memset(Buf,0,sizeof(Buf));
  66. CurrentTime = time(NULL);
  67. tm=localtime(&CurrentTime);
  68. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  69. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_InterCommLog",
  70. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  71. buffer,
  72. tm->tm_year+1900,tm->tm_mon+1);
  73. #ifdef SystemLogMessage
  74. system(Buf);
  75. #endif
  76. #ifdef ConsloePrintLog
  77. 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);
  78. #endif
  79. return rc;
  80. }
  81. int DiffTimeb(struct timeb ST, struct timeb ET)
  82. {
  83. //return milli-second
  84. unsigned int StartTime,StopTime;
  85. StartTime=(unsigned int)ST.time;
  86. StopTime=(unsigned int)ET.time;
  87. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  88. }
  89. long long current_timestamp()
  90. {
  91. struct timeval te;
  92. gettimeofday(&te, NULL); // get current time
  93. long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
  94. return milliseconds;
  95. }
  96. //=================================
  97. // Common routine
  98. //=================================
  99. void trim(char *s)
  100. {
  101. int i=0, j, k, l=0;
  102. while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
  103. i++;
  104. j = strlen(s)-1;
  105. while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
  106. j--;
  107. if(i==0 && j==strlen(s)-1) { }
  108. else if(i==0) s[j+1] = '\0';
  109. else {
  110. for(k=i; k<=j; k++) s[l++] = s[k];
  111. s[l] = '\0';
  112. }
  113. }
  114. int mystrcmp(char *p1,char *p2)
  115. {
  116. while(*p1==*p2)
  117. {
  118. if(*p1=='\0' || *p2=='\0')
  119. break;
  120. p1++;
  121. p2++;
  122. }
  123. if(*p1=='\0' && *p2=='\0')
  124. return(PASS);
  125. else
  126. return(FAIL);
  127. }
  128. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
  129. {
  130. strncpy(dest, src + start, cnt);
  131. dest[cnt] = 0;
  132. }
  133. void split(char **arr, char *str, const char *del)
  134. {
  135. char *s = strtok(str, del);
  136. while(s != NULL)
  137. {
  138. *arr++ = s;
  139. s = strtok(NULL, del);
  140. }
  141. }
  142. //==========================================
  143. // Init all share memory
  144. //==========================================
  145. int InitShareMemory()
  146. {
  147. int result = PASS;
  148. int MeterSMId;
  149. //Initial ShmSysConfigAndInfo
  150. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  151. {
  152. #ifdef SystemLogMessage
  153. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  154. #endif
  155. result = FAIL;
  156. }
  157. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  158. {
  159. #ifdef SystemLogMessage
  160. DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
  161. #endif
  162. result = FAIL;
  163. }
  164. //Initial ShmStatusCodeData
  165. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  166. {
  167. #ifdef SystemLogMessage
  168. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  169. #endif
  170. result = FAIL;
  171. }
  172. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  173. {
  174. #ifdef SystemLogMessage
  175. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  176. #endif
  177. result = FAIL;
  178. }
  179. //Initial ShmPrimaryMcuKey
  180. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
  181. {
  182. #ifdef SystemLogMessage
  183. DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
  184. #endif
  185. result = FAIL;
  186. }
  187. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  188. {
  189. #ifdef SystemLogMessage
  190. DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
  191. #endif
  192. result = FAIL;
  193. }
  194. //creat ShmOCPP16Data
  195. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  196. {
  197. #ifdef SystemLogMessage
  198. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  199. #endif
  200. result = FAIL;
  201. }
  202. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  203. {
  204. #ifdef SystemLogMessage
  205. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  206. #endif
  207. result = FAIL;
  208. }
  209. else
  210. {}
  211. //Initial ShmCharger
  212. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  213. {
  214. #ifdef SystemLogMessage
  215. DEBUG_ERROR("shmget ShmChargerKey NG\n");
  216. #endif
  217. result = FAIL;
  218. }
  219. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  220. {
  221. #ifdef SystemLogMessage
  222. DEBUG_ERROR("shmat ShmChargerKey NG\n");
  223. #endif
  224. result = FAIL;
  225. }
  226. return result;
  227. }
  228. int InitComPort()
  229. {
  230. int fd;
  231. struct termios tios;
  232. fd = open("/dev/ttyS1", O_RDWR);
  233. if(fd<=0)
  234. {
  235. #ifdef SystemLogMessage
  236. DEBUG_ERROR("open /dev/ttyS1 NG\n");
  237. #endif
  238. return -1;
  239. }
  240. ioctl (fd, TCGETS, &tios);
  241. tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
  242. tios.c_lflag = 0;
  243. tios.c_iflag = 0;
  244. tios.c_oflag = 0;
  245. tios.c_cc[VMIN]=0;
  246. tios.c_cc[VTIME]=(unsigned char)5; // timeout 0.5 secod
  247. tios.c_lflag=0;
  248. tcflush(fd, TCIFLUSH);
  249. ioctl (fd, TCSETS, &tios);
  250. return fd;
  251. }
  252. void ack_delay(unsigned char cmd)
  253. {
  254. switch(cmd)
  255. {
  256. case CMD_UPDATE_START:
  257. case CMD_UPDATE_END:
  258. usleep(300000);
  259. break;
  260. default:
  261. usleep(100000);
  262. break;
  263. }
  264. }
  265. int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
  266. {
  267. int len;
  268. tcflush(fd,TCIOFLUSH);
  269. if(write(fd, cmd, cmd_len) >= cmd_len)
  270. {
  271. ack_delay(cmd[3]);
  272. len = read(fd, rx, 512);
  273. }
  274. else
  275. {
  276. #ifdef SystemLogMessage
  277. DEBUG_ERROR("Serial command %s response fail.\n", cmd);
  278. #endif
  279. }
  280. return len;
  281. }
  282. unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
  283. {
  284. unsigned char result = FAIL;
  285. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_FW_VER, 0x00, 0x00, 0x00};
  286. unsigned char rx[512];
  287. unsigned char chksum = 0x00;
  288. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  289. if(len > 6)
  290. {
  291. if(len < 6+(rx[4] | rx[5]<<8))
  292. return result;
  293. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  294. {
  295. chksum ^= rx[6+idx];
  296. }
  297. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  298. (rx[2] == tx[1]) &&
  299. (rx[1] == tx[2]) &&
  300. (rx[3] == tx[3]))
  301. {
  302. strncpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
  303. result = PASS;
  304. }
  305. }
  306. return result;
  307. }
  308. unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
  309. {
  310. unsigned char result = FAIL;
  311. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_HW_VER, 0x00, 0x00, 0x00};
  312. unsigned char rx[512];
  313. unsigned char chksum = 0x00;
  314. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  315. if(len > 6)
  316. {
  317. if(len < 6+(rx[4] | rx[5]<<8))
  318. return result;
  319. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  320. {
  321. chksum ^= rx[6+idx];
  322. }
  323. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  324. (rx[2] == tx[1]) &&
  325. (rx[1] == tx[2]) &&
  326. (rx[3] == tx[3]))
  327. {
  328. strncpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
  329. result = PASS;
  330. }
  331. }
  332. return result;
  333. }
  334. unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetAddr, PresentInputVoltage *Ret_Buf)
  335. {
  336. unsigned char result = FAIL;
  337. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_PRESENT_INPUTVOLTAGE, 0x00, 0x00, 0x00};
  338. unsigned char rx[512];
  339. unsigned char chksum = 0x00;
  340. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  341. if(len > 6)
  342. {
  343. if(len < 6+(rx[4] | rx[5]<<8))
  344. return result;
  345. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  346. {
  347. chksum ^= rx[6+idx];
  348. }
  349. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  350. (rx[2] == tx[1]) &&
  351. (rx[1] == tx[2]) &&
  352. (rx[3] == tx[3]))
  353. {
  354. Ret_Buf->inputType = rx[6];
  355. Ret_Buf->L1N_L12 =( rx[7] | (rx[8]<<8))/10.0;
  356. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  357. {
  358. Ret_Buf->L2N_L23 =( rx[9] | (rx[10]<<8))/10.0;
  359. Ret_Buf->L3N_L31 =( rx[11] | (rx[12]<<8))/10.0;
  360. }
  361. result = PASS;
  362. }
  363. }
  364. return result;
  365. }
  366. unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char targetAddr, PresentOutputVoltage *Ret_Buf)
  367. {
  368. unsigned char result = FAIL;
  369. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_PRESENT_OUTPUTVOLTAGE, 0x00, 0x00, 0x00};
  370. unsigned char rx[512];
  371. unsigned char chksum = 0x00;
  372. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  373. if(len > 6)
  374. {
  375. if(len < 6+(rx[4] | rx[5]<<8))
  376. return result;
  377. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  378. {
  379. chksum ^= rx[6+idx];
  380. }
  381. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  382. (rx[2] == tx[1]) &&
  383. (rx[1] == tx[2]) &&
  384. (rx[3] == tx[3]))
  385. {
  386. Ret_Buf->behindFuse_Voltage_C1 =(rx[6] | (rx[7]<<8))/10.0;
  387. Ret_Buf->behindRelay_Voltage_C1 =(rx[8] | (rx[9]<<8))/10.0;
  388. if((rx[4] | rx[5]<<8) > 4)
  389. {
  390. Ret_Buf->behindFuse_Voltage_C2 =(rx[10] | (rx[11]<<8))/10.0;
  391. Ret_Buf->behindRelay_Voltage_C2 =(rx[12] | (rx[13]<<8))/10.0;
  392. }
  393. result = PASS;
  394. }
  395. }
  396. return result;
  397. }
  398. unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Ret_Buf)
  399. {
  400. unsigned char result = FAIL;
  401. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_FAN_SPEED, 0x00, 0x00, 0x00};
  402. unsigned char rx[512];
  403. unsigned char chksum = 0x00;
  404. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  405. if(len > 6)
  406. {
  407. if(len < 6+(rx[4] | rx[5]<<8))
  408. return result;
  409. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  410. {
  411. chksum ^= rx[6+idx];
  412. }
  413. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  414. (rx[2] == tx[1]) &&
  415. (rx[1] == tx[2]) &&
  416. (rx[3] == tx[3]))
  417. {
  418. for(int idx=0;idx<((rx[4] | rx[5]<<8)>>1);idx++)
  419. Ret_Buf->speed[idx] =(rx[6+(2*idx)] | (rx[6+(2*idx)+1]<<8));
  420. result = PASS;
  421. }
  422. }
  423. return result;
  424. }
  425. unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temperature *Ret_Buf)
  426. {
  427. unsigned char result = FAIL;
  428. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_TEMPERATURE, 0x00, 0x00, 0x00};
  429. unsigned char rx[512];
  430. unsigned char chksum = 0x00;
  431. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  432. if(len > 6)
  433. {
  434. if(len < 6+(rx[4] | rx[5]<<8))
  435. return result;
  436. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  437. {
  438. chksum ^= rx[6+idx];
  439. }
  440. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  441. (rx[2] == tx[1]) &&
  442. (rx[1] == tx[2]) &&
  443. (rx[3] == tx[3]))
  444. {
  445. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  446. Ret_Buf->point[idx] = rx[6+idx] - 60;
  447. result = PASS;
  448. }
  449. }
  450. return result;
  451. }
  452. unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr, AuxPower *Ret_Buf)
  453. {
  454. unsigned char result = FAIL;
  455. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_AUX_POWERVOLTAGE, 0x00, 0x00, 0x00};
  456. unsigned char rx[512];
  457. unsigned char chksum = 0x00;
  458. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  459. if(len > 6)
  460. {
  461. if(len < 6+(rx[4] | rx[5]<<8))
  462. return result;
  463. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  464. {
  465. chksum ^= rx[6+idx];
  466. }
  467. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  468. (rx[2] == tx[1]) &&
  469. (rx[1] == tx[2]) &&
  470. (rx[3] == tx[3]))
  471. {
  472. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  473. Ret_Buf->voltage[idx] = rx[6+idx];
  474. result = PASS;
  475. }
  476. }
  477. return result;
  478. }
  479. unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf)
  480. {
  481. unsigned char result = FAIL;
  482. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_RELAY_OUTPUT, 0x00, 0x00, 0x00};
  483. unsigned char rx[512];
  484. unsigned char chksum = 0x00;
  485. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  486. if(len > 6)
  487. {
  488. if(len < 6+(rx[4] | rx[5]<<8))
  489. return result;
  490. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  491. {
  492. chksum ^= rx[6+idx];
  493. }
  494. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  495. (rx[2] == tx[1]) &&
  496. (rx[1] == tx[2]) &&
  497. (rx[3] == tx[3]))
  498. {
  499. for(int idx_connector=0;idx_connector<(rx[4] | rx[5]<<8);idx_connector++)
  500. {
  501. for(int idx=0;idx<8;idx++)
  502. Ret_Buf->relay_status[idx_connector][idx] = (rx[6+idx_connector]>>idx) & 0x01;
  503. }
  504. result = PASS;
  505. }
  506. }
  507. return result;
  508. }
  509. unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf)
  510. {
  511. unsigned char result = FAIL;
  512. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GFD_ADC, 0x00, 0x00, 0x00};
  513. unsigned char rx[512];
  514. unsigned char chksum = 0x00;
  515. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  516. if(len > 6)
  517. {
  518. if(len < 6+(rx[4] | rx[5]<<8))
  519. return result;
  520. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  521. {
  522. chksum ^= rx[6+idx];
  523. }
  524. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  525. (rx[2] == tx[1]) &&
  526. (rx[1] == tx[2]) &&
  527. (rx[3] == tx[3]))
  528. {
  529. for(int idx_connector=0;idx_connector<((rx[4] | rx[5]<<8)>>2);idx_connector++)
  530. {
  531. Ret_Buf->adc_value_positive[idx_connector] = (rx[6+(4*idx_connector)] | rx[6+(4*idx_connector)+1]<<8);
  532. Ret_Buf->adc_value_negative[idx_connector] = (rx[6+(4*idx_connector)+2] | rx[6+(4*idx_connector)+3]<<8);;
  533. }
  534. result = PASS;
  535. }
  536. }
  537. return result;
  538. }
  539. unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
  540. {
  541. unsigned char result = FAIL;
  542. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GPIO_INPUT, 0x00, 0x00, 0x00};
  543. unsigned char rx[512];
  544. unsigned char chksum = 0x00;
  545. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  546. if(len > 6)
  547. {
  548. if(len < 6+(rx[4] | rx[5]<<8))
  549. return result;
  550. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  551. {
  552. chksum ^= rx[6+idx];
  553. }
  554. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  555. (rx[2] == tx[1]) &&
  556. (rx[1] == tx[2]) &&
  557. (rx[3] == tx[3]))
  558. {
  559. Ret_Buf->AC_Connector = (rx[6] >> 0) & 0x01;
  560. Ret_Buf->AC_MainBreaker = (rx[6] >> 1) & 0x01;
  561. Ret_Buf->SPD = (rx[6] >> 2) & 0x01;
  562. Ret_Buf->Door_Open = (rx[6] >> 3) & 0x01;
  563. Ret_Buf->GFD[0] = (rx[6] >> 4) & 0x01;
  564. Ret_Buf->GFD[1] = (rx[6] >> 5) & 0x01;
  565. Ret_Buf->Button[0] = (rx[6] >> 6) & 0x01;
  566. Ret_Buf->Button[1] = (rx[6] >> 7) & 0x01;
  567. Ret_Buf->Button_Emergency = (rx[7] >> 0) & 0x01;
  568. Ret_Buf->Button_Mode_Switch = (rx[7] >> 7) & 0x01;
  569. result = PASS;
  570. }
  571. }
  572. return result;
  573. }
  574. unsigned char Query_Alarm_Log(unsigned char fd, unsigned char targetAddr, Alarm_Log *Ret_Buf)
  575. {
  576. unsigned char result = FAIL;
  577. 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};
  578. unsigned char rx[512];
  579. unsigned char chksum = Ret_Buf->logArea ^ (Ret_Buf->alarmIndex&0xff) ^ ((Ret_Buf->alarmIndex>>8)&0xff);
  580. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  581. if(len > 6)
  582. {
  583. if(len < 6+(rx[4] | rx[5]<<8))
  584. return result;
  585. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  586. {
  587. chksum ^= rx[6+idx];
  588. }
  589. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  590. (rx[2] == tx[1]) &&
  591. (rx[1] == tx[2]) &&
  592. (rx[3] == tx[3]))
  593. {
  594. memcpy(&Ret_Buf->log[0], &rx[8], 8);
  595. result = PASS;
  596. }
  597. }
  598. return result;
  599. }
  600. unsigned char Query_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Ret_Buf)
  601. {
  602. unsigned char result = FAIL;
  603. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_RTC, 0x00, 0x00, 0x00};
  604. unsigned char rx[512];
  605. unsigned char chksum = 0x00;
  606. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  607. if(len > 6)
  608. {
  609. if(len < 6+(rx[4] | rx[5]<<8))
  610. return result;
  611. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  612. {
  613. chksum ^= rx[6+idx];
  614. }
  615. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  616. (rx[2] == tx[1]) &&
  617. (rx[1] == tx[2]) &&
  618. (rx[3] == tx[3]))
  619. {
  620. Ret_Buf->year = ((rx[6]-'0')*1000) + ((rx[7]-'0')*100) + ((rx[8]-'0')*10) + ((rx[9]-'0')*1);
  621. Ret_Buf->month = ((rx[10]-'0')*10) + ((rx[11]-'0')*1);
  622. Ret_Buf->day = ((rx[12]-'0')*10) + ((rx[13]-'0')*1);
  623. Ret_Buf->hour = ((rx[14]-'0')*10) + ((rx[15]-'0')*1);
  624. Ret_Buf->min = ((rx[16]-'0')*10) + ((rx[17]-'0')*1);
  625. Ret_Buf->sec = ((rx[18]-'0')*10) + ((rx[19]-'0')*1);
  626. result = PASS;
  627. }
  628. }
  629. return result;
  630. }
  631. unsigned char Query_AC_MCU_Status(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu *Ret_Buf)
  632. {
  633. unsigned char result = FAIL;
  634. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_AC_STATUS, 0x00, 0x00, 0x00};
  635. unsigned char rx[512];
  636. unsigned char chksum = 0x00;
  637. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  638. if(len > 6)
  639. {
  640. if(len < 6+(rx[4] | rx[5]<<8))
  641. return result;
  642. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  643. {
  644. chksum ^= rx[6+idx];
  645. }
  646. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  647. (rx[2] == tx[1]) &&
  648. (rx[1] == tx[2]) &&
  649. (rx[3] == tx[3]))
  650. {
  651. Ret_Buf->cp_state = rx[6];
  652. Ret_Buf->current_limit = rx[7] | (rx[8]<<0x08);
  653. Ret_Buf->cp_voltage_positive = (rx[9] | (rx[10]<<0x08))/100.0;
  654. Ret_Buf->cp_voltage_negtive = (rx[11] | (rx[12]<<0x08))/100.0;
  655. Ret_Buf->locker_state = rx[13];
  656. Ret_Buf->relay_state = rx[14];
  657. Ret_Buf->shutter_state = rx[15];
  658. Ret_Buf->meter_state = rx[16];
  659. Ret_Buf->pp_state = rx[17];
  660. Ret_Buf->rating_current = rx[18];
  661. Ret_Buf->rotatory_switch = (rx[19] & 0x0F);
  662. Ret_Buf->socket_e.isSocketEMode = (rx[20] & 0x01);
  663. Ret_Buf->socket_e.isSocketEPinOn = ((rx[20]>>1) & 0x01);
  664. result = PASS;
  665. }
  666. }
  667. return result;
  668. }
  669. unsigned char Query_AC_MCU_Alarm(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Alarm *Ret_Buf)
  670. {
  671. unsigned char result = FAIL;
  672. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_AC_ALARM, 0x00, 0x00, 0x00};
  673. unsigned char rx[512];
  674. unsigned char chksum = 0x00;
  675. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  676. if(len > 6)
  677. {
  678. if(len < 6+(rx[4] | rx[5]<<8))
  679. return result;
  680. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  681. {
  682. chksum ^= rx[6+idx];
  683. }
  684. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  685. (rx[2] == tx[1]) &&
  686. (rx[1] == tx[2]) &&
  687. (rx[3] == tx[3]))
  688. {
  689. //rx[6]
  690. Ret_Buf->bits.OVP_L1 = (((rx[6]>>0)&0x01)?1:0);
  691. Ret_Buf->bits.UVP_L1 = (((rx[6]>>1)&0x01)?1:0);
  692. Ret_Buf->bits.OCP_L1 = (((rx[6]>>2)&0x01)?1:0);
  693. Ret_Buf->bits.OTP = (((rx[6]>>3)&0x01)?1:0);
  694. Ret_Buf->bits.gmi_fault = (((rx[6]>>4)&0x01)?1:0);
  695. Ret_Buf->bits.cp_fault = (((rx[6]>>5)&0x01)?1:0);
  696. Ret_Buf->bits.ac_leak = (((rx[6]>>6)&0x01)?1:0);
  697. Ret_Buf->bits.dc_leak = (((rx[6]>>7)&0x01)?1:0);
  698. //rx[7]
  699. Ret_Buf->bits.mcu_selftest_fail = (((rx[7]>>0)&0x01)?1:0);
  700. Ret_Buf->bits.handshaking_timeout = (((rx[7]>>1)&0x01)?1:0);
  701. Ret_Buf->bits.emergency_stop = (((rx[7]>>2)&0x01)?1:0);
  702. Ret_Buf->bits.relay_welding = (((rx[7]>>3)&0x01)?1:0);
  703. Ret_Buf->bits.leak_module_fail = (((rx[7]>>4)&0x01)?1:0);
  704. Ret_Buf->bits.shutter_fault = (((rx[7]>>5)&0x01)?1:0);
  705. Ret_Buf->bits.locker_fault = (((rx[7]>>6)&0x01)?1:0);
  706. Ret_Buf->bits.power_drop = (((rx[7]>>7)&0x01)?1:0);
  707. //rx[8] bit 3 reserved
  708. Ret_Buf->bits.short_circuit_L1 = (((rx[8]>>0)&0x01)?1:0);
  709. Ret_Buf->bits.rotate_switch_fault = (((rx[8]>>1)&0x01)?1:0);
  710. Ret_Buf->bits.relay_drive_fault = (((rx[8]>>2)&0x01)?1:0);
  711. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  712. {
  713. Ret_Buf->bits.OVP_L2 = (((rx[8]>>4)&0x01)?1:0);
  714. Ret_Buf->bits.OVP_L3 = (((rx[8]>>5)&0x01)?1:0);
  715. Ret_Buf->bits.UVP_L2 = (((rx[8]>>6)&0x01)?1:0);
  716. Ret_Buf->bits.UVP_L3 = (((rx[8]>>7)&0x01)?1:0);
  717. }
  718. //rx[9] bits 6 & 7 Reserved
  719. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  720. {
  721. Ret_Buf->bits.OCP_L2 = (((rx[9]>>0)&0x01)?1:0);
  722. Ret_Buf->bits.OCP_L3 = (((rx[9]>>1)&0x01)?1:0);
  723. Ret_Buf->bits.short_circuit_L2 = (((rx[9]>>2)&0x01)?1:0);
  724. Ret_Buf->bits.short_circuit_L3 = (((rx[9]>>3)&0x01)?1:0);
  725. }
  726. Ret_Buf->bits.meter_comm_timeout = (((rx[9]>>4)&0x01)?1:0);
  727. Ret_Buf->bits.meter_ic_comm_timeout = (((rx[9]>>5)&0x01)?1:0);
  728. Ret_Buf->bits.pilot_negative_error = (((rx[9]>>6)&0x01)?1:0);
  729. result = PASS;
  730. }
  731. }
  732. return result;
  733. }
  734. unsigned char Query_Present_OutputCurrent(unsigned char fd, unsigned char targetAddr, Presentoutputcurrent *Ret_Buf)
  735. {
  736. unsigned char result = FAIL;
  737. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_PRESENT_OUTPUTCURRENT, 0x00, 0x00, 0x00};
  738. unsigned char rx[512];
  739. unsigned char chksum = 0x00;
  740. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  741. if(len > 0)
  742. {
  743. if(len < 6+(rx[4] | rx[5]<<8))
  744. return result;
  745. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  746. {
  747. chksum ^= rx[6+idx];
  748. }
  749. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  750. (rx[2] == tx[1]) &&
  751. (rx[1] == tx[2]) &&
  752. (rx[3] == tx[3]))
  753. {
  754. Ret_Buf->L1N_L12[0] = (rx[6] | (rx[7]<<8))/10.0;
  755. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  756. {
  757. Ret_Buf->L2N_L23[0] = (rx[8] | (rx[9]<<8))/10.0;
  758. Ret_Buf->L3N_L31[0] = (rx[10] | (rx[11]<<8))/10.0;
  759. }
  760. Ret_Buf->L1N_L12[1] = (rx[12] | (rx[13]<<8))/10.0;
  761. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  762. {
  763. Ret_Buf->L2N_L23[1] = (rx[14] | (rx[15]<<8))/10.0;
  764. Ret_Buf->L3N_L31[1] = (rx[16] | (rx[17]<<8))/10.0;
  765. }
  766. result = PASS;
  767. }
  768. }
  769. return result;
  770. }
  771. unsigned char Query_Ble_Config(unsigned char fd, unsigned char targetAddr, Ble_Config_Data *Ret_Buf)
  772. {
  773. unsigned char result = FAIL;
  774. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_BLE_CONFIG_DATA, 0x00, 0x00, 0x00};
  775. unsigned char rx[512];
  776. unsigned char chksum = 0x00;
  777. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  778. if(len > 0)
  779. {
  780. if(len < 6+(rx[4] | rx[5]<<8))
  781. return result;
  782. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  783. {
  784. chksum ^= rx[6+idx];
  785. }
  786. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  787. (rx[2] == tx[1]) &&
  788. (rx[1] == tx[2]) &&
  789. (rx[3] == tx[3]))
  790. {
  791. Ret_Buf->isLogin = (rx[6]?0x01:0x00);
  792. Ret_Buf->isRequestStart = (rx[7]?0x01:0x00);
  793. Ret_Buf->isRequestStop = (rx[8]?0x01:0x00);
  794. result = PASS;
  795. }
  796. }
  797. return result;
  798. }
  799. unsigned char Query_Ble_Central_ID(unsigned char fd, unsigned char targetAddr, Ble_Login_Central_Id *Ret_Buf)
  800. {
  801. unsigned char result = FAIL;
  802. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_BLE_CENTRAL_ID, 0x00, 0x00, 0x00};
  803. unsigned char rx[512];
  804. unsigned char chksum = 0x00;
  805. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  806. if(len > 0)
  807. {
  808. if(len < 6+(rx[4] | rx[5]<<8))
  809. return result;
  810. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  811. {
  812. chksum ^= rx[6+idx];
  813. }
  814. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  815. (rx[2] == tx[1]) &&
  816. (rx[1] == tx[2]) &&
  817. (rx[3] == tx[3]))
  818. {
  819. memset(Ret_Buf->id, 0x00, ARRAY_SIZE(Ret_Buf->id));
  820. memcpy(&Ret_Buf->id[0], &rx[6], (rx[4] | (rx[5]<<8)));
  821. result = PASS;
  822. }
  823. }
  824. return result;
  825. }
  826. 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)
  827. {
  828. unsigned char result = FAIL;
  829. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_POWER_CONSUMPTION, 0x00, 0x00, 0x00};
  830. unsigned char rx[512];
  831. unsigned char chksum = 0x00;
  832. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  833. if(len > 0)
  834. {
  835. if(len < 6+(rx[4] | rx[5]<<8))
  836. return result;
  837. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  838. {
  839. chksum ^= rx[6+idx];
  840. }
  841. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  842. (rx[2] == tx[1]) &&
  843. (rx[1] == tx[2]) &&
  844. (rx[3] == tx[3]))
  845. {
  846. #ifndef SIMULATION
  847. 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));
  848. 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));
  849. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  850. {
  851. 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));
  852. 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));
  853. }
  854. #else //SIMULATION
  855. tsNow = current_timestamp();
  856. tmpPowerConsumption += (uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltage*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent)*((tsNow-tsLast)/360000.0));
  857. Ret_Buf_T-> power_consumption = tmpPowerConsumption;
  858. tsLast = tsNow;
  859. #endif //SIMULATION
  860. result = PASS;
  861. }
  862. }
  863. return result;
  864. }
  865. unsigned char Query_MeterIc_CorrectionPara(unsigned char fd, unsigned char targetAddr, MeterIcCorrection *Ret_Buf)
  866. {
  867. unsigned char result = FAIL;
  868. unsigned char tx[8] = {0xaa, 0x00, targetAddr, CMD_QUERY_METER_IC_CORRECTION_PARA, 0x01, 0x00, 0xb0, 0xb0};
  869. unsigned char rx[512];
  870. unsigned char chksum = 0x00;
  871. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  872. chksum ^= tx[6+idx];
  873. tx[7] = chksum;
  874. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  875. if(len > 0)
  876. {
  877. if(len < (6+(rx[4] | rx[5]<<8)))
  878. return result;
  879. chksum = 0x00;
  880. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  881. {
  882. chksum ^= rx[6+idx];
  883. }
  884. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  885. (rx[2] == tx[1]) &&
  886. (rx[1] == tx[2]) &&
  887. (rx[3] == tx[3]) &&
  888. (rx[6]) == 0xb0)
  889. {
  890. uint32_t cali_flag = (rx[7] | (rx[8]<<8) | (rx[9]<<16) | (rx[10]<<24));
  891. if(!(cali_flag & 0x80000000))
  892. {
  893. Ret_Buf->bits.isCalibratedVaGain = cali_flag & (1 << 0) ? 1 : 0;
  894. Ret_Buf->bits.isCalibratedVbGain = cali_flag & (1 << 1) ? 1 : 0;
  895. Ret_Buf->bits.isCalibratedVcGain = cali_flag & (1 << 2) ? 1 : 0;
  896. Ret_Buf->bits.isCalibratedVaOffset = cali_flag & (1 << 3) ? 1 : 0;
  897. Ret_Buf->bits.isCalibratedVbOffset = cali_flag & (1 << 4) ? 1 : 0;
  898. Ret_Buf->bits.isCalibratedVcOffset = cali_flag & (1 << 5) ? 1 : 0;
  899. Ret_Buf->bits.isCalibratedCaGain = cali_flag & (1 << 6) ? 1 : 0;
  900. Ret_Buf->bits.isCalibratedCbGain = cali_flag & (1 << 7) ? 1 : 0;
  901. Ret_Buf->bits.isCalibratedCcGain = cali_flag & (1 << 8) ? 1 : 0;
  902. Ret_Buf->bits.isCalibratedCaOffset = cali_flag & (1 << 9) ? 1 : 0;
  903. Ret_Buf->bits.isCalibratedCbOffset = cali_flag & (1 << 10) ? 1 : 0;
  904. Ret_Buf->bits.isCalibratedCcOffset = cali_flag & (1 << 11) ? 1 : 0;
  905. Ret_Buf->bits.isCalibratedPa = cali_flag & (1 << 12) ? 1 : 0;
  906. Ret_Buf->bits.isCalibratedPb = cali_flag & (1 << 13) ? 1 : 0;
  907. Ret_Buf->bits.isCalibratedPc = cali_flag & (1 << 14) ? 1 : 0;
  908. }
  909. else
  910. {
  911. Ret_Buf->value = 0;
  912. }
  913. result = PASS;
  914. }
  915. }
  916. return result;
  917. }
  918. unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf)
  919. {
  920. unsigned char result = FAIL;
  921. 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};
  922. unsigned char rx[512];
  923. unsigned char chksum = 0x00;
  924. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  925. chksum ^= tx[6+idx];
  926. tx[14] = chksum;
  927. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  928. if(len > 6)
  929. {
  930. if(len < 6+(rx[4] | rx[5]<<8))
  931. return result;
  932. chksum = 0x00;
  933. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  934. {
  935. chksum ^= rx[6+idx];
  936. }
  937. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  938. (rx[2] == tx[1]) &&
  939. (rx[1] == tx[2]) &&
  940. (rx[3] == tx[3]) &&
  941. (rx[6] == 0x01))
  942. {
  943. result = PASS;
  944. }
  945. }
  946. return result;
  947. }
  948. unsigned char Config_Serial_Number(unsigned char fd, unsigned char targetAddr, Evse_Id *Set_Buf)
  949. {
  950. unsigned char result = FAIL;
  951. 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};
  952. unsigned char rx[512];
  953. unsigned char chksum = 0x00;
  954. memcpy(&tx[14], &Set_Buf->serial_number[0], ARRAY_SIZE(Set_Buf->serial_number));
  955. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  956. chksum ^= tx[6+idx];
  957. tx[26] = chksum;
  958. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  959. if(len > 6)
  960. {
  961. if(len < 6+(rx[4] | rx[5]<<8))
  962. return result;
  963. chksum = 0x00;
  964. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  965. {
  966. chksum ^= rx[6+idx];
  967. }
  968. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  969. (rx[2] == tx[1]) &&
  970. (rx[1] == tx[2]) &&
  971. (rx[3] == tx[3]) &&
  972. (rx[6] == 0x01))
  973. {
  974. result = PASS;
  975. }
  976. }
  977. return result;
  978. }
  979. unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, Evse_Id *Set_Buf)
  980. {
  981. unsigned char result = FAIL;
  982. 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};
  983. unsigned char rx[512];
  984. unsigned char chksum = 0x00;
  985. memcpy(&tx[6], &Set_Buf->model_name[0], ARRAY_SIZE(Set_Buf->model_name));
  986. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  987. chksum ^= tx[6+idx];
  988. tx[20] = chksum;
  989. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  990. if(len > 6)
  991. {
  992. if(len < 6+(rx[4] | rx[5]<<8))
  993. return result;
  994. chksum = 0x00;
  995. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  996. {
  997. chksum ^= rx[6+idx];
  998. }
  999. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1000. (rx[2] == tx[1]) &&
  1001. (rx[1] == tx[2]) &&
  1002. (rx[3] == tx[3]) &&
  1003. (rx[6] == 0x01))
  1004. {
  1005. result = PASS;
  1006. }
  1007. }
  1008. return result;
  1009. }
  1010. unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf)
  1011. {
  1012. unsigned char result = FAIL;
  1013. unsigned char tx[15] = {0};
  1014. unsigned char rx[512];
  1015. unsigned char chksum = 0x00;
  1016. tx[0] = 0xaa;
  1017. tx[1] = 0x00;
  1018. tx[2] = targetAddr;
  1019. tx[3] = CMD_CONFIG_RELAY_OUTPUT;
  1020. tx[4] = 0x08;
  1021. tx[5] = 0x00;
  1022. tx[6] = 0x00;
  1023. tx[7] = 0x00;
  1024. tx[8] = 0x00;
  1025. for(int idx_connector=0;idx_connector<2;idx_connector++)
  1026. for(int idx = 0;idx<8;idx++)
  1027. tx[9+idx_connector] |= ((Set_Buf->relay_status[idx_connector][idx]?0x01:0x00)<<idx);
  1028. tx[11] = 0x00;
  1029. tx[12] = 0x00;
  1030. tx[13] = 0x00;
  1031. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1032. chksum ^= tx[6+idx];
  1033. tx[14] = chksum;
  1034. //for(int count = 0; count < ARRAY_SIZE(tx); count++)
  1035. //printf("TX[%d] : %x \n",count, tx[count]);
  1036. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1037. if(len > 6)
  1038. {
  1039. if(len < 6+(rx[4] | rx[5]<<8))
  1040. return result;
  1041. chksum = 0x00;
  1042. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1043. {
  1044. chksum ^= rx[6+idx];
  1045. }
  1046. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1047. (rx[2] == tx[1]) &&
  1048. (rx[1] == tx[2]) &&
  1049. (rx[3] == tx[3]) &&
  1050. (rx[6] == 0x01))
  1051. {
  1052. result = PASS;
  1053. }
  1054. }
  1055. return result;
  1056. }
  1057. unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
  1058. {
  1059. unsigned char result = FAIL;
  1060. unsigned char tx[9] = {0xaa, 0x00, targetAddr, CMD_CONFIG_GPIO_OUTPUT, 0x01, 0x00, 0x00, 0x00};
  1061. unsigned char rx[512];
  1062. unsigned char chksum = 0x00;
  1063. tx[6] |= (Set_Buf->AC_Connector?0x01:0x00);
  1064. for(int idx=0;idx<2;idx++)
  1065. tx[6] |= (Set_Buf->Button_LED[idx]?0x01:0x00)<<(1+idx);
  1066. for(int idx=0;idx<4;idx++)
  1067. tx[6] |= (Set_Buf->System_LED[idx]?0x01:0x00)<<(3+idx);
  1068. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1069. chksum ^= tx[6+idx];
  1070. tx[8] = chksum;
  1071. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1072. if(len > 6)
  1073. {
  1074. if(len < 6+(rx[4] | rx[5]<<8))
  1075. return result;
  1076. chksum = 0x00;
  1077. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1078. {
  1079. chksum ^= rx[6+idx];
  1080. }
  1081. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1082. (rx[2] == tx[1]) &&
  1083. (rx[1] == tx[2]) &&
  1084. (rx[3] == tx[3]) &&
  1085. (rx[6] == tx[6]))
  1086. {
  1087. result = PASS;
  1088. }
  1089. }
  1090. return result;
  1091. }
  1092. unsigned char Config_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
  1093. {
  1094. unsigned char result = FAIL;
  1095. unsigned char tx[21] = {0};
  1096. unsigned char rx[512];
  1097. unsigned char chksum = 0x00;
  1098. tx[0] = 0xaa;
  1099. tx[1] = 0x00;
  1100. tx[2] = targetAddr;
  1101. tx[3] = CMD_CONFIG_RTC;
  1102. tx[4] = 0x0e;
  1103. tx[5] = 0x00;
  1104. tx[6] = ((Set_Buf->year)/1000)+'0';
  1105. tx[7] = ((Set_Buf->year)/100%10)+'0';
  1106. tx[8] = ((Set_Buf->year)/10%10)+'0';
  1107. tx[9] = ((Set_Buf->year)%10)+'0';
  1108. tx[10] = ((Set_Buf->month)/10)+'0';
  1109. tx[11] = ((Set_Buf->month)%10)+'0';
  1110. tx[12] = ((Set_Buf->day)/10)+'0';
  1111. tx[13] = ((Set_Buf->day)%10)+'0';
  1112. tx[14] = ((Set_Buf->hour)/10)+'0';
  1113. tx[15] = ((Set_Buf->hour)%10)+'0';
  1114. tx[16] = ((Set_Buf->min)/10)+'0';
  1115. tx[17] = ((Set_Buf->min)%10)+'0';
  1116. tx[18] = ((Set_Buf->sec)/10)+'0';
  1117. tx[19] = ((Set_Buf->sec)%10)+'0';
  1118. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1119. chksum ^= tx[6+idx];
  1120. tx[20] = chksum;
  1121. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1122. if(len > 6)
  1123. {
  1124. if(len < 6+(rx[4] | rx[5]<<8))
  1125. return result;
  1126. chksum = 0x00;
  1127. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1128. {
  1129. chksum ^= rx[6+idx];
  1130. }
  1131. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1132. (rx[2] == tx[1]) &&
  1133. (rx[1] == tx[2]) &&
  1134. (rx[3] == tx[3]) &&
  1135. (rx[6] == 0x01))
  1136. {
  1137. result = PASS;
  1138. }
  1139. }
  1140. return result;
  1141. }
  1142. unsigned char Config_AC_MCU_LED(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Led *Set_Buf)
  1143. {
  1144. unsigned char result = FAIL;
  1145. unsigned char tx[12] = {0};
  1146. unsigned char rx[512];
  1147. unsigned char chksum = 0x00;
  1148. tx[0] = 0xaa;
  1149. tx[1] = 0x00;
  1150. tx[2] = targetAddr;
  1151. tx[3] = CMD_CONFIG_AC_LED;
  1152. tx[4] = 0x05;
  1153. tx[5] = 0x00;
  1154. tx[6] = Set_Buf->mode;
  1155. tx[7] = ((Set_Buf->alarm_code>>0)&0xff);
  1156. tx[8] = ((Set_Buf->alarm_code>>8)&0xff);
  1157. tx[9] = ((Set_Buf->alarm_code>>16)&0xff);
  1158. tx[10] = ((Set_Buf->alarm_code>>24)&0xff);
  1159. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1160. chksum ^= tx[6+idx];
  1161. tx[11] = chksum;
  1162. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1163. if(len > 6)
  1164. {
  1165. if(len < 6+(rx[4] | rx[5]<<8))
  1166. return result;
  1167. chksum = 0x00;
  1168. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1169. {
  1170. chksum ^= rx[6+idx];
  1171. }
  1172. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1173. (rx[2] == tx[1]) &&
  1174. (rx[1] == tx[2]) &&
  1175. (rx[3] == tx[3]) &&
  1176. (rx[6] == 0x01))
  1177. {
  1178. result = PASS;
  1179. }
  1180. }
  1181. return result;
  1182. }
  1183. unsigned char Config_AC_MCU_LEGACY_REQUEST(unsigned char fd, unsigned char targetAddr, Legacy_Request *Set_Buf)
  1184. {
  1185. unsigned char result = FAIL;
  1186. unsigned char tx[9] = {0};
  1187. unsigned char rx[512];
  1188. unsigned char chksum = 0x00;
  1189. tx[0] = 0xaa;
  1190. tx[1] = 0x00;
  1191. tx[2] = targetAddr;
  1192. tx[3] = CMD_CONFIG_LEGACY_REQUEST;
  1193. tx[4] = 0x02;
  1194. tx[5] = 0x00;
  1195. tx[6] = Set_Buf->isLegacyRequest;
  1196. tx[7] = 0x00;
  1197. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1198. chksum ^= tx[6+idx];
  1199. tx[8] = chksum;
  1200. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1201. if(len > 6)
  1202. {
  1203. if(len < 6+(rx[4] | rx[5]<<8))
  1204. return result;
  1205. chksum = 0x00;
  1206. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1207. {
  1208. chksum ^= rx[6+idx];
  1209. }
  1210. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1211. (rx[2] == tx[1]) &&
  1212. (rx[1] == tx[2]) &&
  1213. (rx[3] == tx[3]) &&
  1214. (rx[6] == 0x01))
  1215. {
  1216. result = PASS;
  1217. }
  1218. }
  1219. return result;
  1220. }
  1221. unsigned char Config_AC_MCU_RESET_REQUEST(unsigned char fd, unsigned char targetAddr, Mcu_Reset_Request *Set_Buf)
  1222. {
  1223. unsigned char result = FAIL;
  1224. unsigned char tx[9] = {0};
  1225. unsigned char rx[512];
  1226. unsigned char chksum = 0x00;
  1227. tx[0] = 0xaa;
  1228. tx[1] = 0x00;
  1229. tx[2] = targetAddr;
  1230. tx[3] = CMD_CONFIG_MCU_RESET_REQUEST;
  1231. tx[4] = 0x02;
  1232. tx[5] = 0x00;
  1233. tx[6] = Set_Buf->isMcuResetRequest;
  1234. tx[7] = 0x00;
  1235. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1236. chksum ^= tx[6+idx];
  1237. tx[8] = chksum;
  1238. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1239. if(len > 6)
  1240. {
  1241. if(len < 6+(rx[4] | rx[5]<<8))
  1242. return result;
  1243. chksum = 0x00;
  1244. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1245. {
  1246. chksum ^= rx[6+idx];
  1247. }
  1248. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1249. (rx[2] == tx[1]) &&
  1250. (rx[1] == tx[2]) &&
  1251. (rx[3] == tx[3]) &&
  1252. (rx[6] == 0x01))
  1253. {
  1254. result = PASS;
  1255. }
  1256. }
  1257. return result;
  1258. }
  1259. unsigned char Query_AC_GUN_PLUGIN_TIMES(unsigned char fd, unsigned char targetAddr, Gun_Plugin_Times *Ret_Buf)
  1260. {
  1261. unsigned char result = FAIL;
  1262. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GUN_PLUGIN_TIMES, 0x00, 0x00, 0x00};
  1263. unsigned char rx[512];
  1264. unsigned char chksum = 0x00;
  1265. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1266. if(len > 6)
  1267. {
  1268. if(len < 6+(rx[4] | rx[5]<<8))
  1269. return result;
  1270. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1271. {
  1272. chksum ^= rx[6+idx];
  1273. }
  1274. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1275. (rx[2] == tx[1]) &&
  1276. (rx[1] == tx[2]) &&
  1277. (rx[3] == tx[3]))
  1278. {
  1279. Ret_Buf-> GunPluginTimes = ((uint32_t)rx[6] | (((uint32_t)rx[7])<<8) | (((uint32_t)rx[8])<<16) | (((uint32_t)rx[9])<<24));
  1280. result = PASS;
  1281. }
  1282. }
  1283. return result;
  1284. }
  1285. unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Cp_Pwm_Duty *Set_Buf)
  1286. {
  1287. unsigned char result = FAIL;
  1288. unsigned char tx[8] = {0};
  1289. unsigned char rx[512];
  1290. unsigned char chksum = 0x00;
  1291. tx[0] = 0xaa;
  1292. tx[1] = 0x00;
  1293. tx[2] = targetAddr;
  1294. tx[3] = CMD_CONFIG_CURRENT_LINIT;
  1295. tx[4] = 0x01;
  1296. tx[5] = 0x00;
  1297. tx[6] = Set_Buf->max_current;
  1298. //DEBUG_WARN("Config_AC_MaxCurrent_And_CpPwmDuty...%d\n", Set_Buf->max_current);
  1299. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1300. chksum ^= tx[6+idx];
  1301. tx[7] = chksum;
  1302. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1303. if(len > 6)
  1304. {
  1305. if(len < 6+(rx[4] | rx[5]<<8))
  1306. return result;
  1307. chksum = 0x00;
  1308. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1309. {
  1310. chksum ^= rx[6+idx];
  1311. }
  1312. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1313. (rx[2] == tx[1]) &&
  1314. (rx[1] == tx[2]) &&
  1315. (rx[3] == tx[3]) &&
  1316. ((rx[6] == 0x00) || (rx[6] == 0x01)))
  1317. {
  1318. result = PASS;
  1319. }
  1320. }
  1321. return result;
  1322. }
  1323. unsigned char Config_AC_Set_Breathe_Led_Timing(unsigned char fd, unsigned char targetAddr,Set_Breathe_Led_Timing *Set_Buf)
  1324. {
  1325. unsigned char result = FAIL;
  1326. unsigned char tx[19] = {0};
  1327. unsigned char rx[512];
  1328. unsigned char chksum = 0x00;
  1329. tx[0] = 0xaa;
  1330. tx[1] = 0x00;
  1331. tx[2] = targetAddr;
  1332. tx[3] = CMD_CONFIG_MCU_SET_BREATHE_LED_TIMING;
  1333. tx[4] = 0x0C;
  1334. tx[5] = 0x00;
  1335. // Increase LED_ACTION_CONNECTED
  1336. tx[6] = (Set_Buf->set_Led_Action_Connected_Fade_In & 0xff);
  1337. tx[7] = (Set_Buf->set_Led_Action_Connected_Fade_In >> 8);
  1338. // Decrease LED_ACTION_CONNECTED
  1339. tx[8] = (Set_Buf->set_Led_Action_Connected_Fade_Out & 0xff);
  1340. tx[9] = (Set_Buf->set_Led_Action_Connected_Fade_Out >> 8);
  1341. // Increase LED_ACTION_AUTHED
  1342. tx[10] = (Set_Buf->set_Led_Action_Authed_Fade_In & 0xff);
  1343. tx[11] = (Set_Buf->set_Led_Action_Authed_Fade_In >> 8);
  1344. // Decrease LED_ACTION_AUTHED
  1345. tx[12] = (Set_Buf->set_Led_Action_Authed_Fade_Out & 0xff);
  1346. tx[13] = (Set_Buf->set_Led_Action_Authed_Fade_Out >> 8);
  1347. // Increase_LED_ACTION_CHARGING
  1348. tx[14] = (Set_Buf->Set_Led_Action_Chaging_Fade_In & 0xff);
  1349. tx[15] = (Set_Buf->Set_Led_Action_Chaging_Fade_In >> 8);
  1350. // Decrease_LED_ACTION_CHARGING
  1351. tx[16] = (Set_Buf->set_Led_Action_Chaging_Fade_Out & 0xff);
  1352. tx[17] = (Set_Buf->set_Led_Action_Chaging_Fade_Out >> 8);
  1353. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1354. chksum ^= tx[6+idx];
  1355. tx[18] = chksum;
  1356. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1357. if(len > 6)
  1358. {
  1359. if(len < 6+(rx[4] | rx[5]<<8))
  1360. return result;
  1361. chksum = 0x00;
  1362. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1363. {
  1364. chksum ^= rx[6+idx];
  1365. }
  1366. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1367. (rx[2] == tx[1]) &&
  1368. (rx[1] == tx[2]) &&
  1369. (rx[3] == tx[3]) &&
  1370. (rx[6] == 0x01))
  1371. {
  1372. result = PASS;
  1373. }
  1374. }
  1375. return result;
  1376. }
  1377. unsigned char Config_AC_Set_Led_Brightness(unsigned char fd, unsigned char targetAddr,Set_Led_Brightness *Set_Buf)
  1378. {
  1379. unsigned char result = FAIL;
  1380. unsigned char tx[19] = {0};
  1381. unsigned char rx[512];
  1382. unsigned char chksum = 0x00;
  1383. tx[0] = 0xaa;
  1384. tx[1] = 0x00;
  1385. tx[2] = targetAddr;
  1386. tx[3] = CMD_CONFIG_MCU_SET_LED_BRIGHTNESS;
  1387. tx[4] = 0x0C;
  1388. tx[5] = 0x00;
  1389. tx[6] = Set_Buf-> sector_1; // 0~1 AM and 1~2 AM
  1390. tx[7] = Set_Buf-> sector_2; // 2~3 AM and 3~4 AM
  1391. tx[8] = Set_Buf-> sector_3; // 4~5 AM and 5~6 AM
  1392. tx[9] = Set_Buf-> sector_4; // 6~7 AM and 7~8 AM
  1393. tx[10] = Set_Buf-> sector_5; // 8~9 AM and 9~10 AM
  1394. tx[11] = Set_Buf-> sector_6; // 10~11 AM and 11~12 AM
  1395. tx[12] = Set_Buf-> sector_7; // 12~13 PM and 13~14 PM
  1396. tx[13] = Set_Buf-> sector_8; // 14~15 PM and 15~16 PM
  1397. tx[14] = Set_Buf-> sector_9; // 16~17 PM and 17~18 PM
  1398. tx[15] = Set_Buf-> sector_10; // 18~19 PM and 19~20 PM
  1399. tx[16] = Set_Buf-> sector_11; // 20~21 PM and 21~22 PM
  1400. tx[17] = Set_Buf-> sector_12; // 22~23 PM and 23~24 PM
  1401. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1402. chksum ^= tx[6+idx];
  1403. tx[18] = chksum;
  1404. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1405. if(len > 6)
  1406. {
  1407. if(len < 6+(rx[4] | rx[5]<<8))
  1408. return result;
  1409. chksum = 0x00;
  1410. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1411. {
  1412. chksum ^= rx[6+idx];
  1413. }
  1414. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1415. (rx[2] == tx[1]) &&
  1416. (rx[1] == tx[2]) &&
  1417. (rx[3] == tx[3]) &&
  1418. (rx[6] == 0x01))
  1419. {
  1420. result = PASS;
  1421. }
  1422. }
  1423. return result;
  1424. }
  1425. unsigned char Config_Aux_Power_Switch(unsigned char fd, unsigned char targetAddr, Set_Aux_Power_Switch *Set_Buf)
  1426. {
  1427. unsigned char result = FAIL;
  1428. unsigned char tx[9];
  1429. unsigned char rx[512];
  1430. unsigned char chksum = 0x00;
  1431. tx[0] = 0xaa;
  1432. tx[1] = 0x00;
  1433. tx[2] = targetAddr;
  1434. tx[3] = CMD_CONFIG_AUX_POWER_SWITCH;
  1435. tx[4] = 0x02;
  1436. tx[5] = 0x00;
  1437. tx[6] = Set_Buf->power_type; // 0~1 AM and 1~2 AM
  1438. tx[7] = Set_Buf->power_switch; // 2~3 AM and 3~4 AM
  1439. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1440. chksum ^= tx[6+idx];
  1441. tx[8] = chksum;
  1442. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1443. if(len > 6)
  1444. {
  1445. if(len < 6+(rx[4] | rx[5]<<8))
  1446. return result;
  1447. chksum = 0x00;
  1448. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1449. {
  1450. chksum ^= rx[6+idx];
  1451. }
  1452. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1453. (rx[2] == tx[1]) &&
  1454. (rx[1] == tx[2]) &&
  1455. (rx[3] == tx[3]) &&
  1456. (rx[6] == 0x01))
  1457. {
  1458. result = PASS;
  1459. }
  1460. }
  1461. return result;
  1462. }
  1463. unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
  1464. {
  1465. unsigned char result = FAIL;
  1466. 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};
  1467. unsigned char rx[512];
  1468. unsigned char chksum = 0x00;
  1469. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1470. chksum ^= tx[6+idx];
  1471. tx[10] = chksum;
  1472. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1473. if(len > 6)
  1474. {
  1475. if(len < 6+(rx[4] | rx[5]<<8))
  1476. return result;
  1477. chksum = 0x00;
  1478. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  1479. {
  1480. chksum ^= rx[6+idx];
  1481. }
  1482. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1483. (rx[2] == tx[1]) &&
  1484. (rx[1] == tx[2]) &&
  1485. (rx[3] == tx[3]) &&
  1486. (rx[6] == 0x00))
  1487. {
  1488. result = PASS;
  1489. }
  1490. }
  1491. return result;
  1492. }
  1493. unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
  1494. {
  1495. unsigned char result = FAIL;
  1496. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_UPDATE_ABOARD, 0x04, 0x00, 0x00};
  1497. unsigned char rx[512];
  1498. unsigned char chksum = 0x00;
  1499. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1500. if(len > 6)
  1501. {
  1502. if(len < 6+(rx[4] | rx[5]<<8))
  1503. return result;
  1504. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  1505. {
  1506. chksum ^= rx[6+idx];
  1507. }
  1508. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1509. (rx[2] == tx[1]) &&
  1510. (rx[1] == tx[2]) &&
  1511. (rx[3] == tx[3]) &&
  1512. (rx[6] == 0x00))
  1513. {
  1514. result = PASS;
  1515. }
  1516. }
  1517. return result;
  1518. }
  1519. unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
  1520. {
  1521. unsigned char result = FAIL;
  1522. unsigned char tx[11 + length];
  1523. unsigned char rx[512];
  1524. unsigned char chksum = 0x00;
  1525. tx[0] = 0xaa;
  1526. tx[1] = 0x00;
  1527. tx[2] = targetAddr;
  1528. tx[3] = CMD_UPDATE_TRANSFER;
  1529. tx[4] = (4 + length) & 0xff;
  1530. tx[5] = ((4 + length)>>8) & 0xff;
  1531. tx[6] = (startAddr>>0) & 0xff;
  1532. tx[7] = (startAddr>>8) & 0xff;
  1533. tx[8] = (startAddr>>16) & 0xff;
  1534. tx[9] = (startAddr>>24) & 0xff;
  1535. memcpy(tx+10, data, length);
  1536. for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
  1537. chksum ^= tx[6+idx];
  1538. tx[ARRAY_SIZE(tx)-1] = chksum;
  1539. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1540. if(len > 6)
  1541. {
  1542. if(len < 6+(rx[4] | rx[5]<<8))
  1543. return result;
  1544. for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
  1545. {
  1546. chksum ^= rx[6+idx];
  1547. }
  1548. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1549. (rx[2] == tx[1]) &&
  1550. (rx[1] == tx[2]) &&
  1551. (rx[3] == tx[3]) &&
  1552. (rx[6] == 0x00))
  1553. {
  1554. result = PASS;
  1555. }
  1556. }
  1557. return result;
  1558. }
  1559. unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
  1560. {
  1561. unsigned char result = FAIL;
  1562. unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_UPDATE_END, 0x04, 0x00, 0x00};
  1563. unsigned char rx[512];
  1564. unsigned char chksum = 0x00;
  1565. unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
  1566. if(len > 6)
  1567. {
  1568. if(len < 6+(rx[4] | rx[5]<<8))
  1569. return result;
  1570. for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
  1571. {
  1572. chksum ^= rx[6+idx];
  1573. }
  1574. if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
  1575. (rx[2] == tx[1]) &&
  1576. (rx[1] == tx[2]) &&
  1577. (rx[3] == tx[3]) &&
  1578. (rx[6] == 0x01))
  1579. {
  1580. result = PASS;
  1581. }
  1582. }
  1583. return result;
  1584. }
  1585. //================================================
  1586. // Main process
  1587. //================================================
  1588. int main(void)
  1589. {
  1590. int Uart1Fd;
  1591. unsigned short int failCount[2] = {0,0};
  1592. struct Charger previousCharger;
  1593. if(InitShareMemory() == FAIL)
  1594. {
  1595. #ifdef SystemLogMessage
  1596. DEBUG_ERROR("InitShareMemory NG\n");
  1597. #endif
  1598. if(ShmStatusCodeData!=NULL)
  1599. {
  1600. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1601. }
  1602. sleep(5);
  1603. return 0;
  1604. }
  1605. else
  1606. {
  1607. DEBUG_INFO("InitShareMemory OK.\n");
  1608. }
  1609. Uart1Fd=InitComPort();
  1610. if(Uart1Fd<0)
  1611. {
  1612. DEBUG_ERROR("InitComPort NG\n");
  1613. if(ShmStatusCodeData!=NULL)
  1614. {
  1615. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
  1616. }
  1617. sleep(5);
  1618. return 0;
  1619. }
  1620. else
  1621. {
  1622. DEBUG_INFO("ttyS1 port open success.\n");
  1623. }
  1624. if(fork() == 0)
  1625. {
  1626. for(;;)
  1627. {
  1628. for(int gun_index=0;gun_index<AC_QUANTITY;gun_index++)
  1629. {
  1630. //==========================================================
  1631. // High priority polling log print out
  1632. //==========================================================
  1633. //==================================================
  1634. // Case 1: Config primary MCU LED
  1635. //==================================================
  1636. if((previousCharger.gun_info[gun_index].primaryMcuLed.mode != ShmCharger->gun_info[gun_index].primaryMcuLed.mode) ||
  1637. (previousCharger.gun_info[gun_index].primaryMcuLed.alarm_code != ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code))
  1638. {
  1639. DEBUG_INFO("*******************************************\n");
  1640. DEBUG_INFO("***** High priority polling : Case 1 ******\n");
  1641. DEBUG_INFO("*******************************************\n");
  1642. DEBUG_INFO("MCU-%d set Led mode : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.mode);
  1643. DEBUG_INFO("MCU-%d set Alarm code : %x\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code);
  1644. previousCharger.gun_info[gun_index].primaryMcuLed.mode = ShmCharger->gun_info[gun_index].primaryMcuLed.mode;
  1645. previousCharger.gun_info[gun_index].primaryMcuLed.alarm_code = ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code;
  1646. }
  1647. //==================================================
  1648. // Case 2: Config primary Legacy request
  1649. //==================================================
  1650. if(previousCharger.gun_info[gun_index].legacyRequest.isLegacyRequest != ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest)
  1651. {
  1652. DEBUG_INFO("*******************************************\n");
  1653. DEBUG_INFO("***** High priority polling : Case 2 ******\n");
  1654. DEBUG_INFO("*******************************************\n");
  1655. DEBUG_INFO("MCU-%d set relay request : %d\n", gun_index, ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
  1656. previousCharger.gun_info[gun_index].legacyRequest.isLegacyRequest = ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest;
  1657. }
  1658. //==================================================
  1659. // Case 3: Query primary MCU status
  1660. //==================================================
  1661. if((previousCharger.gun_info[gun_index].primaryMcuState.cp_state != ShmCharger->gun_info[gun_index].primaryMcuState.cp_state) ||
  1662. (previousCharger.gun_info[gun_index].primaryMcuState.current_limit != ShmCharger->gun_info[gun_index].primaryMcuState.current_limit) ||
  1663. (previousCharger.gun_info[gun_index].primaryMcuState.relay_state != ShmCharger->gun_info[gun_index].primaryMcuState.relay_state) ||
  1664. (previousCharger.gun_info[gun_index].primaryMcuState.rotatory_switch != ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch) ||
  1665. (previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode != ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode) ||
  1666. (previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn != ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn))
  1667. {
  1668. DEBUG_INFO("*******************************************\n");
  1669. DEBUG_INFO("***** High priority polling : Case 3 ******\n");
  1670. DEBUG_INFO("*******************************************\n");
  1671. DEBUG_INFO("MCU-%d get Pilot State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
  1672. DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
  1673. DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
  1674. DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
  1675. if(ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON)
  1676. {
  1677. if(ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn == ON)
  1678. DEBUG_INFO("Relay on mode : CHARGING_MODE_SOCKETE. \n");
  1679. else
  1680. DEBUG_INFO("Relay on mode : CHARGING_MODE_BS / CHARGING_MODE_HLC. \n");
  1681. }
  1682. DEBUG_INFO("MCU-%d get Relay State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
  1683. DEBUG_INFO("MCU-%d get Rating Current : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
  1684. DEBUG_INFO("MCU-%d get Rotary switch : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
  1685. DEBUG_INFO("MCU-%d get is on Socket-E mode : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode);
  1686. DEBUG_INFO("MCU-%d get Socket-E detect pin : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn);
  1687. DEBUG_INFO("MCU-%d get Locker State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
  1688. DEBUG_INFO("MCU-%d get Shutter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
  1689. DEBUG_INFO("MCU-%d get Meter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
  1690. DEBUG_INFO("MCU-%d get PP State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
  1691. previousCharger.gun_info[gun_index].primaryMcuState.cp_state = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
  1692. previousCharger.gun_info[gun_index].primaryMcuState.current_limit = ShmCharger->gun_info[gun_index].primaryMcuState.current_limit;
  1693. previousCharger.gun_info[gun_index].primaryMcuState.rotatory_switch = ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch;
  1694. previousCharger.gun_info[gun_index].primaryMcuState.relay_state = ShmCharger->gun_info[gun_index].primaryMcuState.relay_state;
  1695. previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode = ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode;
  1696. previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn = ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn;
  1697. }
  1698. //==================================================
  1699. // Case 4: Query primary MCU Alarm code
  1700. //==================================================
  1701. if((previousCharger.gun_info[gun_index].primaryMcuAlarm.InputAlarmCode != ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode))
  1702. {
  1703. if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode>0))
  1704. {
  1705. DEBUG_INFO("*******************************************\n");
  1706. DEBUG_INFO("***** High priority polling : Case 4 ******\n");
  1707. DEBUG_INFO("*******************************************\n");
  1708. DEBUG_INFO("MCU-%d get OVP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L1);
  1709. DEBUG_INFO("MCU-%d get UVP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L1);
  1710. DEBUG_INFO("MCU-%d get OCP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1);
  1711. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  1712. {
  1713. DEBUG_INFO("MCU-%d get OVP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L2);
  1714. DEBUG_INFO("MCU-%d get UVP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L2);
  1715. DEBUG_INFO("MCU-%d get OCP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2);
  1716. DEBUG_INFO("MCU-%d get OVP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L3);
  1717. DEBUG_INFO("MCU-%d get UVP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L3);
  1718. DEBUG_INFO("MCU-%d get OCP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3);
  1719. }
  1720. DEBUG_INFO("MCU-%d get OTP : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
  1721. DEBUG_INFO("MCU-%d get gmi_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
  1722. DEBUG_INFO("MCU-%d get cp_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
  1723. DEBUG_INFO("MCU-%d get ac_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
  1724. DEBUG_INFO("MCU-%d get dc_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
  1725. DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
  1726. DEBUG_INFO("MCU-%d get handshaking_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
  1727. DEBUG_INFO("MCU-%d get emergency_stop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
  1728. DEBUG_INFO("MCU-%d get relay_welding : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
  1729. DEBUG_INFO("MCU-%d get leak_module_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
  1730. DEBUG_INFO("MCU-%d get shutter_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
  1731. DEBUG_INFO("MCU-%d get locker_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
  1732. DEBUG_INFO("MCU-%d get power_drop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
  1733. DEBUG_INFO("MCU-%d get rotate_switch_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.rotate_switch_fault);
  1734. DEBUG_INFO("MCU-%d get short_circuit_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L1);
  1735. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  1736. {
  1737. DEBUG_INFO("MCU-%d get short_circuit_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L2);
  1738. DEBUG_INFO("MCU-%d get short_circuit_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L3);
  1739. }
  1740. DEBUG_INFO("MCU-%d get relay_drive_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
  1741. DEBUG_INFO("MCU-%d get meter_comm_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_comm_timeout);
  1742. DEBUG_INFO("MCU-%d get meter_ic_comm_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_ic_comm_timeout);
  1743. DEBUG_INFO("MCU-%d get pilot_negative_error : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.pilot_negative_error);
  1744. DEBUG_INFO("MCU-%d get InputAlarmCode : %x\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
  1745. }
  1746. previousCharger.gun_info[gun_index].primaryMcuAlarm.InputAlarmCode = ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode;
  1747. }
  1748. //==================================================
  1749. // Case 5: Query primary MCU BLE config
  1750. //==================================================
  1751. /*
  1752. if((previousCharger.gun_info[gun_index].bleConfigData.isLogin != ShmCharger->gun_info[gun_index].bleConfigData.isLogin) ||
  1753. (previousCharger.gun_info[gun_index].bleConfigData.isRequestStart != ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart) ||
  1754. (previousCharger.gun_info[gun_index].bleConfigData.isRequestStop != ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop))
  1755. {
  1756. if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin == ON)
  1757. {
  1758. DEBUG_INFO("*******************************************\n");
  1759. DEBUG_INFO("***** High priority polling : Case 5 ******\n");
  1760. DEBUG_INFO("*******************************************\n");
  1761. DEBUG_INFO("MCU-%d get isUserLogin : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
  1762. DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
  1763. DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
  1764. }
  1765. previousCharger.gun_info[gun_index].bleConfigData.isLogin = ShmCharger->gun_info[gun_index].bleConfigData.isLogin;
  1766. previousCharger.gun_info[gun_index].bleConfigData.isRequestStart = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart;
  1767. previousCharger.gun_info[gun_index].bleConfigData.isRequestStop = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop;
  1768. }
  1769. */
  1770. //==================================================
  1771. // Case 6: Query primary MCU ble login id
  1772. //==================================================
  1773. /*
  1774. if((strcmp((char *)&previousCharger.gun_info[gun_index].bleLoginCentralId.id,(char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id) != 0))
  1775. {
  1776. if(strcmp((char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id,"") != 0)
  1777. {
  1778. DEBUG_INFO("*******************************************\n");
  1779. DEBUG_INFO("***** High priority polling : Case 6 ******\n");
  1780. DEBUG_INFO("*******************************************\n");
  1781. DEBUG_INFO("MCU-%d get ble central id : %s\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
  1782. }
  1783. memcpy(&previousCharger.gun_info[gun_index].bleLoginCentralId.id, ShmCharger->gun_info[gun_index].bleLoginCentralId.id, ARRAY_SIZE(ShmCharger->gun_info[gun_index].bleLoginCentralId.id));
  1784. }
  1785. */
  1786. //==================================================
  1787. // Case 8: Config primary MCU duty
  1788. //==================================================
  1789. if(previousCharger.gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
  1790. {
  1791. DEBUG_INFO("*******************************************\n");
  1792. DEBUG_INFO("***** High priority polling : Case 8 ******\n");
  1793. DEBUG_INFO("*******************************************\n");
  1794. DEBUG_INFO("MCU-%d set cp pwn duty : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
  1795. previousCharger.gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current;
  1796. }
  1797. //==================================================
  1798. // Case 10: Query primary MCU power consumption
  1799. //==================================================
  1800. if((previousCharger.gun_info[gun_index].powerConsumptionTotal.power_consumption != ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption) ||
  1801. (previousCharger.gun_info[gun_index].powerConsumption[0].power_consumption != ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption) ||
  1802. (previousCharger.gun_info[gun_index].powerConsumption[1].power_consumption != ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption) ||
  1803. (previousCharger.gun_info[gun_index].powerConsumption[2].power_consumption != ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption))
  1804. {
  1805. DEBUG_INFO("*******************************************\n");
  1806. DEBUG_INFO("***** High priority polling : Case 10 *****\n");
  1807. DEBUG_INFO("*******************************************\n");
  1808. DEBUG_INFO("MCU-%d get total power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0));
  1809. 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));
  1810. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  1811. {
  1812. 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));
  1813. 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));
  1814. }
  1815. previousCharger.gun_info[gun_index].powerConsumptionTotal.power_consumption = ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption;
  1816. previousCharger.gun_info[gun_index].powerConsumption[0].power_consumption = ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption;
  1817. previousCharger.gun_info[gun_index].powerConsumption[1].power_consumption = ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption;
  1818. previousCharger.gun_info[gun_index].powerConsumption[2].power_consumption = ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption;
  1819. }
  1820. //==================================================
  1821. // Case 11: Query primary Out put current config
  1822. //==================================================
  1823. if(((int)previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0] != (int)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]) ||
  1824. ((int)previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] != (int)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]) ||
  1825. ((int)previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] != (int)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]))
  1826. {
  1827. DEBUG_INFO("*******************************************\n");
  1828. DEBUG_INFO("***** High priority polling : Case 11 *****\n");
  1829. DEBUG_INFO("*******************************************\n");
  1830. DEBUG_INFO("MCU-%d get output current L1: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
  1831. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  1832. {
  1833. DEBUG_INFO("MCU-%d get output current L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]);
  1834. DEBUG_INFO("MCU-%d get output current L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]);
  1835. }
  1836. previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0] = ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  1837. previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] = ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
  1838. previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] = ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
  1839. }
  1840. //==========================================================
  1841. // Low priority polling log print out
  1842. //==========================================================
  1843. //==================================================
  1844. // Case 1: Query primary In put voltage
  1845. //==================================================
  1846. if(((int)previousCharger.gun_info[gun_index].inputVoltage.L1N_L12 != (int)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12) ||
  1847. ((int)previousCharger.gun_info[gun_index].inputVoltage.L2N_L23 != (int)ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23) ||
  1848. ((int)previousCharger.gun_info[gun_index].inputVoltage.L3N_L31 != (int)ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31))
  1849. {
  1850. DEBUG_INFO("===========================================\n");
  1851. DEBUG_INFO("==== Normal priority polling : Case 1 =====\n");
  1852. DEBUG_INFO("===========================================\n");
  1853. DEBUG_INFO("MCU-%d get Input voltage L1: %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
  1854. DEBUG_INFO("MCU-%d get PresentChargingVoltage L1: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage);
  1855. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  1856. {
  1857. DEBUG_INFO("MCU-%d get Input voltage L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23);
  1858. DEBUG_INFO("MCU-%d get PresentChargingVoltage L2: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL2);
  1859. DEBUG_INFO("MCU-%d get Input voltage L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31);
  1860. DEBUG_INFO("MCU-%d get PresentChargingVoltage L3: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL3);
  1861. }
  1862. previousCharger.gun_info[gun_index].inputVoltage.L1N_L12 = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
  1863. previousCharger.gun_info[gun_index].inputVoltage.L2N_L23 = ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23;
  1864. previousCharger.gun_info[gun_index].inputVoltage.L3N_L31 = ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31;
  1865. }
  1866. //==================================================
  1867. // Case 5: Query primary plug in times
  1868. //==================================================
  1869. if(previousCharger.gun_info[gun_index].gunPluginTimes.GunPluginTimes != ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes)
  1870. {
  1871. DEBUG_INFO("===========================================\n");
  1872. DEBUG_INFO("==== Normal priority polling : Case 5 =====\n");
  1873. DEBUG_INFO("===========================================\n");
  1874. DEBUG_INFO("MCU-%d get gun plugin times : %ld\n", gun_index, (long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
  1875. previousCharger.gun_info[gun_index].gunPluginTimes.GunPluginTimes = ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes;
  1876. }
  1877. //==================================================
  1878. // Case 7: Query primary temperature
  1879. //==================================================
  1880. if(previousCharger.gun_info[gun_index].temperature.point[0] != ShmCharger->gun_info[gun_index].temperature.point[0])
  1881. {
  1882. DEBUG_INFO("===========================================\n");
  1883. DEBUG_INFO("==== Normal priority polling : Case 7 =====\n");
  1884. DEBUG_INFO("===========================================\n");
  1885. DEBUG_INFO("MCU-%d get temperature : %d\n", gun_index, ShmCharger->gun_info[gun_index].temperature.point[0]);
  1886. previousCharger.gun_info[gun_index].temperature.point[0] = ShmCharger->gun_info[gun_index].temperature.point[0];
  1887. }
  1888. //==================================================
  1889. // Case 11: Config primary RTC time
  1890. //==================================================
  1891. if(previousCharger.gun_info[gun_index].rtc.min != ShmCharger->gun_info[gun_index].rtc.min)
  1892. {
  1893. DEBUG_INFO("===========================================\n");
  1894. DEBUG_INFO("==== Normal priority polling : Case 11 ====\n");
  1895. DEBUG_INFO("===========================================\n");
  1896. if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin && !ShmOCPP16Data->OcppConnStatus)
  1897. {
  1898. DEBUG_INFO("Sync from MCU-%d rtc OK...%04d-%02d-%02d %02d:%02d:%02d\n", gun_index,
  1899. ShmCharger->gun_info[gun_index].rtc.year,
  1900. ShmCharger->gun_info[gun_index].rtc.month,
  1901. ShmCharger->gun_info[gun_index].rtc.day,
  1902. ShmCharger->gun_info[gun_index].rtc.hour,
  1903. ShmCharger->gun_info[gun_index].rtc.min,
  1904. ShmCharger->gun_info[gun_index].rtc.sec);
  1905. }
  1906. else
  1907. {
  1908. DEBUG_INFO("MCU-%d set rtc OK...%04d-%02d-%02d %02d:%02d:%02d\n", gun_index,
  1909. ShmCharger->gun_info[gun_index].rtc.year,
  1910. ShmCharger->gun_info[gun_index].rtc.month,
  1911. ShmCharger->gun_info[gun_index].rtc.day,
  1912. ShmCharger->gun_info[gun_index].rtc.hour,
  1913. ShmCharger->gun_info[gun_index].rtc.min,
  1914. ShmCharger->gun_info[gun_index].rtc.sec);
  1915. }
  1916. previousCharger.gun_info[gun_index].rtc.min = ShmCharger->gun_info[gun_index].rtc.min;
  1917. }
  1918. //==================================================
  1919. // Case 15: Config led breathe timing
  1920. //==================================================
  1921. 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) ||
  1922. (previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out) ||
  1923. (previousCharger.gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In != ShmCharger->gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In) ||
  1924. (previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out) ||
  1925. (previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In) ||
  1926. (previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out != ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out))
  1927. {
  1928. if(ShmCharger->gun_info[gun_index].isSetBreatheLedTiming == ON)
  1929. {
  1930. DEBUG_INFO("===========================================\n");
  1931. DEBUG_INFO("==== Normal priority polling : Case 15 ====\n");
  1932. DEBUG_INFO("===========================================\n");
  1933. 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);
  1934. 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);
  1935. 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);
  1936. 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);
  1937. 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);
  1938. 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);
  1939. }
  1940. previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_In;
  1941. previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Authed_Fade_Out;
  1942. previousCharger.gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In = ShmCharger->gun_info[gun_index].setBreatheLedTiming.Set_Led_Action_Chaging_Fade_In;
  1943. previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Chaging_Fade_Out;
  1944. previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_In;
  1945. previousCharger.gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out = ShmCharger->gun_info[gun_index].setBreatheLedTiming.set_Led_Action_Connected_Fade_Out;
  1946. }
  1947. //==================================================
  1948. // Case 17: Config led brightness
  1949. //==================================================
  1950. if((previousCharger.gun_info[gun_index].setLedBrightness.sector_1 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_1) ||
  1951. (previousCharger.gun_info[gun_index].setLedBrightness.sector_2 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_2) ||
  1952. (previousCharger.gun_info[gun_index].setLedBrightness.sector_3 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_3) ||
  1953. (previousCharger.gun_info[gun_index].setLedBrightness.sector_4 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_4) ||
  1954. (previousCharger.gun_info[gun_index].setLedBrightness.sector_5 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_5) ||
  1955. (previousCharger.gun_info[gun_index].setLedBrightness.sector_6 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_6) ||
  1956. (previousCharger.gun_info[gun_index].setLedBrightness.sector_7 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_7) ||
  1957. (previousCharger.gun_info[gun_index].setLedBrightness.sector_8 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_8) ||
  1958. (previousCharger.gun_info[gun_index].setLedBrightness.sector_9 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_9) ||
  1959. (previousCharger.gun_info[gun_index].setLedBrightness.sector_10 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_10) ||
  1960. (previousCharger.gun_info[gun_index].setLedBrightness.sector_11 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_11) ||
  1961. (previousCharger.gun_info[gun_index].setLedBrightness.sector_12 != ShmCharger->gun_info[gun_index].setLedBrightness.sector_12))
  1962. {
  1963. if(ShmCharger->gun_info[gun_index].isSetLedBrightness == ON)
  1964. {
  1965. DEBUG_INFO("===========================================\n");
  1966. DEBUG_INFO("==== Normal priority polling : Case 17 ====\n");
  1967. DEBUG_INFO("===========================================\n");
  1968. DEBUG_INFO("MCU-%d set led brightness Sector 01 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_1);
  1969. DEBUG_INFO("MCU-%d set led brightness Sector 02 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_2);
  1970. DEBUG_INFO("MCU-%d set led brightness Sector 03 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_3);
  1971. DEBUG_INFO("MCU-%d set led brightness Sector 04 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_4);
  1972. DEBUG_INFO("MCU-%d set led brightness Sector 05 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_5);
  1973. DEBUG_INFO("MCU-%d set led brightness Sector 06 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_6);
  1974. DEBUG_INFO("MCU-%d set led brightness Sector 07 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_7);
  1975. DEBUG_INFO("MCU-%d set led brightness Sector 08 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_8);
  1976. DEBUG_INFO("MCU-%d set led brightness Sector 09 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_9);
  1977. DEBUG_INFO("MCU-%d set led brightness Sector 10 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_10);
  1978. DEBUG_INFO("MCU-%d set led brightness Sector 11 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_11);
  1979. DEBUG_INFO("MCU-%d set led brightness Sector 12 : [%x].\n", gun_index, ShmCharger->gun_info[gun_index].setLedBrightness.sector_12);
  1980. }
  1981. previousCharger.gun_info[gun_index].setLedBrightness.sector_1 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_1;
  1982. previousCharger.gun_info[gun_index].setLedBrightness.sector_2 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_2;
  1983. previousCharger.gun_info[gun_index].setLedBrightness.sector_3 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_3;
  1984. previousCharger.gun_info[gun_index].setLedBrightness.sector_4 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_4;
  1985. previousCharger.gun_info[gun_index].setLedBrightness.sector_5 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_5;
  1986. previousCharger.gun_info[gun_index].setLedBrightness.sector_6 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_6;
  1987. previousCharger.gun_info[gun_index].setLedBrightness.sector_7 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_7;
  1988. previousCharger.gun_info[gun_index].setLedBrightness.sector_8 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_8;
  1989. previousCharger.gun_info[gun_index].setLedBrightness.sector_9 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_9;
  1990. previousCharger.gun_info[gun_index].setLedBrightness.sector_10 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_10;
  1991. previousCharger.gun_info[gun_index].setLedBrightness.sector_11 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_11;
  1992. previousCharger.gun_info[gun_index].setLedBrightness.sector_12 = ShmCharger->gun_info[gun_index].setLedBrightness.sector_12;
  1993. }
  1994. }
  1995. usleep(100000);
  1996. }
  1997. exit(0);
  1998. }
  1999. for(;;)
  2000. {
  2001. for(int gun_index=0;gun_index<AC_QUANTITY;gun_index++)
  2002. {
  2003. /*
  2004. * Polling loop
  2005. */
  2006. if((stepIndex%2)==0)
  2007. {
  2008. /*
  2009. * High priority communication
  2010. */
  2011. //===============================
  2012. // Case 1 : Config primary MCU LED
  2013. //===============================
  2014. ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code = ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode;
  2015. if(Config_AC_MCU_LED(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuLed))
  2016. {
  2017. failCount[gun_index] = 0;
  2018. }
  2019. else
  2020. {
  2021. DEBUG_WARN("MCU-%d set led fail...%d\n", gun_index, failCount[gun_index]);
  2022. if(failCount[gun_index]<USHRT_MAX)
  2023. failCount[gun_index]++;
  2024. else
  2025. failCount[gun_index] = FAIL_SPEC_COMM;
  2026. }
  2027. //===============================
  2028. // Case 2 : Config primary Legacy request
  2029. //===============================
  2030. if(Config_AC_MCU_LEGACY_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1),&ShmCharger->gun_info[gun_index].legacyRequest))
  2031. {
  2032. failCount[gun_index] = 0;
  2033. }
  2034. else
  2035. {
  2036. DEBUG_WARN("MCU-%d set request fail...%d\n", gun_index, failCount[gun_index]);
  2037. if(failCount[gun_index]<USHRT_MAX)
  2038. failCount[gun_index]++;
  2039. else
  2040. failCount[gun_index] = FAIL_SPEC_COMM;
  2041. }
  2042. //===============================
  2043. // Case 2-X : Config primary Relay
  2044. //===============================
  2045. if(Config_Relay_Output(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1),&ShmCharger->gun_info[gun_index].primaryMcuState.relayState))
  2046. {
  2047. failCount[gun_index] = 0;
  2048. }
  2049. else
  2050. {
  2051. DEBUG_WARN("MCU-%d set relay fail...%d\n", gun_index, failCount[gun_index]);
  2052. if(failCount[gun_index]<USHRT_MAX)
  2053. failCount[gun_index]++;
  2054. else
  2055. failCount[gun_index] = FAIL_SPEC_COMM;
  2056. }
  2057. //===============================
  2058. // Case 3 : Query primary MCU status
  2059. //===============================
  2060. if(Query_AC_MCU_Status(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuState))
  2061. {
  2062. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
  2063. 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));
  2064. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotVoltage = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive;
  2065. ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive;
  2066. ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive;
  2067. //pass info 2 CCS task
  2068. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_UNKNOWN)
  2069. {
  2070. if(ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative >= -12)
  2071. {
  2072. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_G;
  2073. }
  2074. else
  2075. {
  2076. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_H;
  2077. }
  2078. }
  2079. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
  2080. {
  2081. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_A;
  2082. }
  2083. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)
  2084. {
  2085. if(ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative == 0.0)
  2086. {
  2087. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_B1;
  2088. }
  2089. else
  2090. {
  2091. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_B2;
  2092. }
  2093. }
  2094. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C)
  2095. {
  2096. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_C;
  2097. }
  2098. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_D)
  2099. {
  2100. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_D;
  2101. }
  2102. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_E)
  2103. {
  2104. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_E;
  2105. }
  2106. else //CP_STATE_F
  2107. {
  2108. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState = CCS_CP_STATE_F;
  2109. }
  2110. ShmCharger->gun_info[gun_index].acCcsInfo.CpPositiveVoltage = ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive;
  2111. ShmCharger->gun_info[gun_index].acCcsInfo.CpNegativeVoltage = ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative;
  2112. ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentPWMDuty = ShmCharger->gun_info[gun_index].primaryMcuState.current_limit;
  2113. if(ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
  2114. {
  2115. ShmCharger->gun_info[gun_index].acCcsInfo.OutputRelayStatus = ON;
  2116. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].RelayK1K2Status = ON;
  2117. }
  2118. else
  2119. {
  2120. ShmCharger->gun_info[gun_index].acCcsInfo.OutputRelayStatus = OFF;
  2121. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].RelayK1K2Status = OFF;
  2122. }
  2123. failCount[gun_index] = 0;
  2124. }
  2125. else
  2126. {
  2127. DEBUG_WARN("MCU-%d get status fail...%d\n", gun_index, failCount[gun_index]);
  2128. if(failCount[gun_index]<USHRT_MAX)
  2129. failCount[gun_index]++;
  2130. else
  2131. failCount[gun_index] = FAIL_SPEC_COMM;
  2132. }
  2133. //===============================
  2134. // Case 4 : Query primary MCU Alarm code
  2135. //===============================
  2136. if(Query_AC_MCU_Alarm(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuAlarm))
  2137. {
  2138. //DEBUG_INFO("MCU-%d get alarm code success.\n",gun_index);
  2139. failCount[gun_index] = 0;
  2140. ShmCharger->gun_info[gun_index].acCcsInfo.CSUAlarmStatusCode = ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode;
  2141. }
  2142. else
  2143. {
  2144. DEBUG_WARN("MCU-%d get alarm fail...%d\n", gun_index, failCount[gun_index]);
  2145. if(failCount[gun_index]<USHRT_MAX)
  2146. failCount[gun_index]++;
  2147. else
  2148. failCount[gun_index] = FAIL_SPEC_COMM;
  2149. }
  2150. /*
  2151. //===============================
  2152. // Case 5 : Query primary MCU BLE config
  2153. //===============================
  2154. if(Query_Ble_Config(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].bleConfigData))
  2155. {
  2156. ShmSysConfigAndInfo->SysConfig.Bluetooth.isLogin = ShmCharger->gun_info[gun_index].bleConfigData.isLogin;
  2157. ShmSysConfigAndInfo->SysConfig.Bluetooth.isRequestStart = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart;
  2158. ShmSysConfigAndInfo->SysConfig.Bluetooth.isRequestStop = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop;
  2159. failCount[gun_index] = 0;
  2160. }
  2161. else
  2162. {
  2163. DEBUG_WARN("MCU-%d get ble config fail...%d\n", gun_index, failCount[gun_index]);
  2164. if(failCount[gun_index]<USHRT_MAX)
  2165. failCount[gun_index]++;
  2166. else
  2167. failCount[gun_index] = FAIL_SPEC_COMM;
  2168. }
  2169. //===============================
  2170. // Case 6 : Query primary MCU ble login id
  2171. //===============================
  2172. if(Query_Ble_Central_ID(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].bleLoginCentralId))
  2173. {
  2174. memcpy(ShmSysConfigAndInfo->SysConfig.Bluetooth.LoginCentralID, ShmCharger->gun_info[gun_index].bleLoginCentralId.id, sizeof ShmSysConfigAndInfo->SysConfig.Bluetooth.LoginCentralID);
  2175. failCount[gun_index] = 0;
  2176. }
  2177. else
  2178. {
  2179. DEBUG_WARN("MCU-%d get ble login central id fail...%d\n", gun_index, failCount[gun_index]);
  2180. if(failCount[gun_index]<USHRT_MAX)
  2181. failCount[gun_index]++;
  2182. else
  2183. failCount[gun_index] = FAIL_SPEC_COMM;
  2184. }*/
  2185. //===============================
  2186. // Case 7 : Config primary MCU reset request
  2187. //===============================
  2188. if((access("/sys/class/gpio/gpio116/value", F_OK)) != -1)
  2189. {
  2190. if(ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest == ON)
  2191. {
  2192. 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)
  2193. {
  2194. DEBUG_INFO("*******************************************\n");
  2195. DEBUG_INFO("**** High priority polling : Case 7 *******\n");
  2196. DEBUG_INFO("*******************************************\n");
  2197. DEBUG_INFO("MCU-%d set MCU reset Request : %d\n", gun_index, ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest);
  2198. ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest = OFF;
  2199. failCount[gun_index] = 0;
  2200. }
  2201. else
  2202. {
  2203. DEBUG_WARN("MCU-%d get MCU reset fail...%d\n", gun_index, failCount[gun_index]);
  2204. if(failCount[gun_index]<USHRT_MAX)
  2205. failCount[gun_index]++;
  2206. else
  2207. failCount[gun_index] = FAIL_SPEC_COMM;
  2208. }
  2209. }
  2210. }
  2211. //===============================
  2212. // Case 8 : Config primary set CP PWN duty
  2213. //===============================
  2214. if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == ON)
  2215. {
  2216. //DEBUG_WARN("Case 8 : Config primary set CP PWN duty...%d\n", ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty);
  2217. 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))
  2218. {
  2219. failCount[gun_index] = 0;
  2220. ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = OFF;
  2221. }
  2222. else
  2223. {
  2224. DEBUG_WARN("MCU-%d set cp pwn duty fail...%d\n", gun_index, failCount[gun_index]);
  2225. if(failCount[gun_index]<USHRT_MAX)
  2226. failCount[gun_index]++;
  2227. else
  2228. failCount[gun_index] = FAIL_SPEC_COMM;
  2229. }
  2230. }
  2231. //===============================
  2232. // Case 9 : Query GPIO
  2233. //===============================
  2234. if(Query_Gpio_Input(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].GPIO_Input))
  2235. {
  2236. failCount[gun_index] = 0;
  2237. }
  2238. else
  2239. {
  2240. DEBUG_WARN("MCU-%d get GPIO input fail...%d\n", gun_index, failCount[gun_index]);
  2241. if(failCount[gun_index]<USHRT_MAX)
  2242. failCount[gun_index]++;
  2243. else
  2244. failCount[gun_index] = FAIL_SPEC_COMM;
  2245. }
  2246. //===============================
  2247. // Case 10 : Query primary MCU power consumption
  2248. //===============================
  2249. 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]))
  2250. {
  2251. failCount[gun_index] = 0;
  2252. }
  2253. else
  2254. {
  2255. DEBUG_WARN("MCU-%d get power consumption fail...%d\n", gun_index, failCount[gun_index]);
  2256. if(failCount[gun_index]<USHRT_MAX)
  2257. failCount[gun_index]++;
  2258. else
  2259. failCount[gun_index] = FAIL_SPEC_COMM;
  2260. }
  2261. //===============================
  2262. // Case 11 : Query present output current
  2263. //===============================
  2264. if(Query_Present_OutputCurrent(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].outputCurrent) == PASS)
  2265. {
  2266. #ifndef SIMULATION
  2267. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  2268. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
  2269. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
  2270. ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[0] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  2271. ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[1] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  2272. ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[2] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  2273. #else //SIMULATION
  2274. 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);
  2275. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  2276. {
  2277. 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);
  2278. 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);
  2279. }
  2280. #endif //SIMULATION
  2281. failCount[gun_index] = 0;
  2282. }
  2283. else
  2284. {
  2285. DEBUG_WARN("MCU-%d get output current fail...%d\n", gun_index, failCount[gun_index]);
  2286. if(failCount[gun_index]<USHRT_MAX)
  2287. failCount[gun_index]++;
  2288. else
  2289. failCount[gun_index] = FAIL_SPEC_COMM;
  2290. }
  2291. }
  2292. else
  2293. {
  2294. /*
  2295. * Normal priority communication
  2296. */
  2297. switch(stepIndex)
  2298. {
  2299. case 1:
  2300. //===============================
  2301. // Query present input voltage
  2302. //===============================
  2303. if(Query_Present_InputVoltage(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].inputVoltage) == PASS)
  2304. {
  2305. ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
  2306. ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23;
  2307. ShmSysConfigAndInfo->SysInfo.InputVoltageT = ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31;
  2308. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
  2309. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL2 = ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23;
  2310. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL3 = ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31;
  2311. ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[0] = ShmSysConfigAndInfo->SysInfo.InputVoltageR;
  2312. ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[1] = ShmSysConfigAndInfo->SysInfo.InputVoltageS;
  2313. ShmCharger->gun_info[gun_index].acCcsInfo.GridVoltage[2] = ShmSysConfigAndInfo->SysInfo.InputVoltageT;
  2314. failCount[gun_index] = 0;
  2315. }
  2316. else
  2317. {
  2318. DEBUG_WARN("MCU-%d get input voltage fail...%d\n", gun_index, failCount[gun_index]);
  2319. if(failCount[gun_index]<USHRT_MAX)
  2320. failCount[gun_index]++;
  2321. else
  2322. failCount[gun_index] = FAIL_SPEC_COMM;
  2323. }
  2324. break;
  2325. case 3:
  2326. /*
  2327. //===============================
  2328. // Query present output current
  2329. //===============================
  2330. if(Query_Present_OutputCurrent(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].outputCurrent) == PASS)
  2331. {
  2332. #ifndef SIMULATION
  2333. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  2334. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
  2335. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
  2336. ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[0] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  2337. ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[1] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  2338. ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[2] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
  2339. #else //SIMULATION
  2340. 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);
  2341. if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
  2342. {
  2343. 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);
  2344. 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);
  2345. }
  2346. #endif //SIMULATION
  2347. failCount[gun_index] = 0;
  2348. }
  2349. else
  2350. {
  2351. DEBUG_WARN("MCU-%d get output current fail...%d\n", gun_index, failCount[gun_index]);
  2352. if(failCount[gun_index]<USHRT_MAX)
  2353. failCount[gun_index]++;
  2354. else
  2355. failCount[gun_index] = FAIL_SPEC_COMM;
  2356. }
  2357. */
  2358. break;
  2359. case 5:
  2360. //===============================
  2361. // Query gun plug-in times
  2362. //===============================
  2363. 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)
  2364. {
  2365. ShmSysConfigAndInfo->SysConfig.AcPlugInTimes = ((long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes & 0xFFFF);
  2366. failCount[gun_index] = 0;
  2367. }
  2368. else
  2369. {
  2370. DEBUG_WARN("MCU-%d get gun plugin times fail...%d\n", gun_index, failCount[gun_index]);
  2371. if(failCount[gun_index]<USHRT_MAX)
  2372. failCount[gun_index]++;
  2373. else
  2374. failCount[gun_index] = FAIL_SPEC_COMM;
  2375. }
  2376. break;
  2377. case 7:
  2378. //===============================
  2379. // Query temperature
  2380. //===============================
  2381. if(Query_Temperature(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].temperature) == PASS)
  2382. {
  2383. ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = ShmCharger->gun_info[gun_index].temperature.point[0];
  2384. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ConnectorTemp = ShmCharger->gun_info[gun_index].temperature.point[0];
  2385. failCount[gun_index] = 0;
  2386. }
  2387. else
  2388. {
  2389. DEBUG_WARN("MCU-%d get temperature fail...%d\n", gun_index, failCount[gun_index]);
  2390. if(failCount[gun_index]<USHRT_MAX)
  2391. failCount[gun_index]++;
  2392. else
  2393. failCount[gun_index] = FAIL_SPEC_COMM;
  2394. }
  2395. break;
  2396. case 9:
  2397. //===============================
  2398. // Query RTC
  2399. //===============================
  2400. if(Query_RTC(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].rtc))
  2401. {
  2402. struct timeb csuTime, mcuTime;
  2403. struct tm *tmCSU;
  2404. struct tm tmMcu;
  2405. ftime(&csuTime);
  2406. tmCSU = localtime(&csuTime.time);
  2407. tmMcu.tm_year = ShmCharger->gun_info[gun_index].rtc.year-1900;
  2408. tmMcu.tm_mon = ShmCharger->gun_info[gun_index].rtc.month-1;
  2409. tmMcu.tm_mday = ShmCharger->gun_info[gun_index].rtc.day;
  2410. tmMcu.tm_hour = ShmCharger->gun_info[gun_index].rtc.hour;
  2411. tmMcu.tm_min = ShmCharger->gun_info[gun_index].rtc.min;
  2412. tmMcu.tm_sec = ShmCharger->gun_info[gun_index].rtc.sec;
  2413. mcuTime.time = mktime(&tmMcu);
  2414. if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin && !ShmOCPP16Data->OcppConnStatus)
  2415. {
  2416. if(abs(DiffTimeb(csuTime, mcuTime)) > 10000)
  2417. {
  2418. char cmdBuf[128];
  2419. sprintf(cmdBuf, "date -u -s \"%04d-%02d-%02d %02d:%02d:%02d\"", ShmCharger->gun_info[gun_index].rtc.year,
  2420. ShmCharger->gun_info[gun_index].rtc.month,
  2421. ShmCharger->gun_info[gun_index].rtc.day,
  2422. ShmCharger->gun_info[gun_index].rtc.hour,
  2423. ShmCharger->gun_info[gun_index].rtc.min,
  2424. ShmCharger->gun_info[gun_index].rtc.sec);
  2425. system(cmdBuf);
  2426. system("hwclock -w -u");
  2427. system("hwclock -s");
  2428. }
  2429. }
  2430. else
  2431. {
  2432. if(abs(DiffTimeb(csuTime, mcuTime)) > 10000)
  2433. {
  2434. ShmCharger->gun_info[gun_index].rtc.year = tmCSU->tm_year+1900;
  2435. ShmCharger->gun_info[gun_index].rtc.month = tmCSU->tm_mon+1;
  2436. ShmCharger->gun_info[gun_index].rtc.day = tmCSU->tm_mday;
  2437. ShmCharger->gun_info[gun_index].rtc.hour = tmCSU->tm_hour;
  2438. ShmCharger->gun_info[gun_index].rtc.min = tmCSU->tm_min;
  2439. ShmCharger->gun_info[gun_index].rtc.sec = tmCSU->tm_sec;
  2440. Config_RTC(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].rtc);
  2441. }
  2442. }
  2443. failCount[gun_index] = 0;
  2444. }
  2445. else
  2446. {
  2447. DEBUG_WARN("MCU-%d get rtc fail...%d\n", gun_index, failCount[gun_index]);
  2448. if(failCount[gun_index]<USHRT_MAX)
  2449. failCount[gun_index]++;
  2450. else
  2451. failCount[gun_index] = FAIL_SPEC_COMM;
  2452. }
  2453. break;
  2454. case 11:
  2455. break;
  2456. case 13:
  2457. //===============================
  2458. // Upgrade MCU
  2459. //===============================
  2460. if(ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq)
  2461. {
  2462. DEBUG_INFO("===========================================\n");
  2463. DEBUG_INFO("==== Normal priority polling : Case 13 ====\n");
  2464. DEBUG_INFO("===========================================\n");
  2465. unsigned char cmd[512];
  2466. if(Upgrade_UART(Uart1Fd, AC_WALLMOUNT_CONTROLLER, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), ShmCharger->fwUpgradeInfo.location, ShmCharger->fwUpgradeInfo.modelName))
  2467. {
  2468. DEBUG_INFO("MCU-%d upgrade firmware OK...%s\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
  2469. sleep(20);
  2470. ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq = OFF;
  2471. failCount[gun_index] = 0;
  2472. }
  2473. else
  2474. {
  2475. DEBUG_WARN("MCU-%d upgrade firmware fail...%d\n", gun_index, failCount[gun_index]);
  2476. if(failCount[gun_index]<USHRT_MAX)
  2477. failCount[gun_index]++;
  2478. else
  2479. failCount[gun_index] = FAIL_SPEC_COMM;
  2480. }
  2481. sprintf((char*)cmd, "yes|rm %s", ShmCharger->fwUpgradeInfo.location);
  2482. system((char*)cmd);
  2483. }
  2484. break;
  2485. case 15:
  2486. //===============================
  2487. // Config set breathe led timing
  2488. //===============================
  2489. if(ShmCharger->gun_info[gun_index].isSetBreatheLedTiming == ON)
  2490. {
  2491. 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))
  2492. {
  2493. failCount[gun_index] = 0;
  2494. ShmCharger->gun_info[gun_index].isSetBreatheLedTiming = OFF;
  2495. }
  2496. else
  2497. {
  2498. DEBUG_WARN("MCU-%d set breathe led timing fail...%d\n", gun_index, failCount[gun_index]);
  2499. if(failCount[gun_index]<USHRT_MAX)
  2500. failCount[gun_index]++;
  2501. else
  2502. failCount[gun_index] = FAIL_SPEC_COMM;
  2503. }
  2504. }
  2505. break;
  2506. case 17:
  2507. //===============================
  2508. // Config set led brightness
  2509. //===============================
  2510. if(ShmCharger->gun_info[gun_index].isSetLedBrightness == ON)
  2511. {
  2512. if(Config_AC_Set_Led_Brightness(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].setLedBrightness))
  2513. {
  2514. failCount[gun_index] = 0;
  2515. ShmCharger->gun_info[gun_index].isSetLedBrightness = OFF;
  2516. }
  2517. else
  2518. {
  2519. DEBUG_WARN("MCU-%d set led brightness fail...%d\n", gun_index, failCount[gun_index]);
  2520. if(failCount[gun_index]<USHRT_MAX)
  2521. failCount[gun_index]++;
  2522. else
  2523. failCount[gun_index] = FAIL_SPEC_COMM;
  2524. }
  2525. }
  2526. break;
  2527. case 19:
  2528. //===============================
  2529. // Query firmware version
  2530. //===============================
  2531. if(ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass != PASS)
  2532. {
  2533. DEBUG_INFO("===========================================\n");
  2534. DEBUG_INFO("==== Normal priority polling : Case 19-1===\n");
  2535. DEBUG_INFO("===========================================\n");
  2536. if(Query_FW_Ver(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].ver) == PASS)
  2537. {
  2538. DEBUG_INFO("MCU-%d get firmware version : %s\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
  2539. memcpy(ShmPrimaryMcuData->version, ShmCharger->gun_info[gun_index].ver.Version_FW, sizeof(ShmPrimaryMcuData->version));
  2540. ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass = PASS;
  2541. failCount[gun_index] = 0;
  2542. }
  2543. else
  2544. {
  2545. DEBUG_WARN("MCU-%d get firmware version fail...%d\n", gun_index, failCount[gun_index]);
  2546. if(failCount[gun_index]<USHRT_MAX)
  2547. failCount[gun_index]++;
  2548. else
  2549. failCount[gun_index] = FAIL_SPEC_COMM;
  2550. }
  2551. }
  2552. //===============================
  2553. // Query meter ic correction status
  2554. //===============================
  2555. if(ShmCharger->gun_info[gun_index].mcuFlag.isReadMeterIcCorrectionStatus != PASS)
  2556. {
  2557. DEBUG_INFO("===========================================\n");
  2558. DEBUG_INFO("==== Normal priority polling : Case 19-2===\n");
  2559. DEBUG_INFO("===========================================\n");
  2560. if(Query_MeterIc_CorrectionPara(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].meterIcCorrectionStatus) == PASS)
  2561. {
  2562. DEBUG_INFO("MCU-%d get meter ic correction status: 0x%08X\n", gun_index, ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.value);
  2563. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVaGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVaGain;
  2564. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVbGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVbGain;
  2565. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVcGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVcGain;
  2566. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVaOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVaOffset;
  2567. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVbOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVbOffset;
  2568. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedVcOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedVcOffset;
  2569. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCaGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCaGain;
  2570. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCbGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCbGain;
  2571. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCcGain = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCcGain;
  2572. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCaOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCaOffset;
  2573. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCbOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCbOffset;
  2574. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedCcOffset = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedCcOffset;
  2575. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedPa = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedPa;
  2576. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedPb = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedPb;
  2577. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].meterIcCalInfo.isCalibratedPc = ShmCharger->gun_info[gun_index].meterIcCorrectionStatus.bits.isCalibratedPc;
  2578. ShmCharger->gun_info[gun_index].mcuFlag.isReadMeterIcCorrectionStatus = PASS;
  2579. failCount[gun_index] = 0;
  2580. }
  2581. else
  2582. {
  2583. DEBUG_WARN("MCU-%d get meter ic correction status fail...%d\n", gun_index, failCount[gun_index]);
  2584. if(failCount[gun_index]<USHRT_MAX)
  2585. failCount[gun_index]++;
  2586. else
  2587. failCount[gun_index] = FAIL_SPEC_COMM;
  2588. }
  2589. }
  2590. //===============================
  2591. // Config primary MCU serial number
  2592. //===============================
  2593. if(ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass != PASS)
  2594. {
  2595. DEBUG_INFO("===========================================\n");
  2596. DEBUG_INFO("==== Normal priority polling : Case 19-3===\n");
  2597. DEBUG_INFO("===========================================\n");
  2598. memcpy(ShmCharger->evseId.serial_number, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmCharger->evseId.serial_number));
  2599. if(Config_Serial_Number(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
  2600. {
  2601. DEBUG_INFO("MCU-%d set serial number : %.12s\n",gun_index,ShmCharger->evseId.serial_number);
  2602. ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass = PASS;
  2603. failCount[gun_index] = 0;
  2604. }
  2605. else
  2606. {
  2607. DEBUG_WARN("MCU-%d set serial number fail...%d\n", gun_index, failCount[gun_index]);
  2608. if(failCount[gun_index]<USHRT_MAX)
  2609. failCount[gun_index]++;
  2610. else
  2611. failCount[gun_index] = FAIL_SPEC_COMM;
  2612. }
  2613. }
  2614. //===============================
  2615. // Config primary MCU model name
  2616. //===============================
  2617. if(ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass != PASS)
  2618. {
  2619. DEBUG_INFO("===========================================\n");
  2620. DEBUG_INFO("==== Normal priority polling : Case 19-4===\n");
  2621. DEBUG_INFO("===========================================\n");
  2622. memcpy(ShmCharger->evseId.model_name, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmCharger->evseId.model_name));
  2623. if(Config_Model_Name(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
  2624. {
  2625. DEBUG_INFO("MCU-%d set model name : %.14s\n",gun_index,ShmCharger->evseId.model_name);
  2626. ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass = PASS;
  2627. failCount[gun_index] = 0;
  2628. }
  2629. else
  2630. {
  2631. DEBUG_WARN("MCU-%d set model name fail...%d\n", gun_index, failCount[gun_index]);
  2632. if(failCount[gun_index]<USHRT_MAX)
  2633. failCount[gun_index]++;
  2634. else
  2635. failCount[gun_index] = FAIL_SPEC_COMM;
  2636. }
  2637. }
  2638. break;
  2639. case 21:
  2640. //===============================
  2641. // Config aux power switch
  2642. //===============================
  2643. ShmCharger->gun_info[gun_index].setAuxPowerSwitch.power_switch = 0x01;
  2644. ShmCharger->gun_info[gun_index].setAuxPowerSwitch.power_switch = ShmCharger->gun_info[gun_index].isMeterOn;
  2645. if(Config_Aux_Power_Switch(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].setAuxPowerSwitch))
  2646. {
  2647. failCount[gun_index] = 0;
  2648. }
  2649. else
  2650. {
  2651. DEBUG_WARN("MCU-%d set aux power switch fail...%d\n", gun_index, failCount[gun_index]);
  2652. if(failCount[gun_index]<USHRT_MAX)
  2653. failCount[gun_index]++;
  2654. else
  2655. failCount[gun_index] = FAIL_SPEC_COMM;
  2656. }
  2657. break;
  2658. default:
  2659. stepIndex = 0;
  2660. break;
  2661. }
  2662. }
  2663. stepIndex++;
  2664. //===============================
  2665. // Communication fail check
  2666. //===============================
  2667. if(failCount[gun_index] >= 13)
  2668. ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
  2669. if(failCount[gun_index] >= FAIL_SPEC_COMM)
  2670. {
  2671. if((0 <= failCount[gun_index]%FAIL_SPEC_COMM) && (failCount[gun_index]%FAIL_SPEC_COMM < 10))
  2672. sleep(10);
  2673. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == OFF)
  2674. {
  2675. DEBUG_ERROR("Primary MCU-%d communication fault. \n", gun_index);
  2676. ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout = ON;
  2677. }
  2678. }
  2679. else
  2680. {
  2681. if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == ON)
  2682. {
  2683. DEBUG_ERROR("Primary MCU-%d communication recover. \n", gun_index);
  2684. ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout = OFF;
  2685. }
  2686. }
  2687. usleep(100000);
  2688. }
  2689. }
  2690. return FAIL;
  2691. }