Module_LcmControl.c 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <termios.h>
  7. #include <fcntl.h>
  8. #include <time.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/ioctl.h>
  12. #include <sys/timeb.h>
  13. #include <dirent.h>
  14. #include "cbmp.h"
  15. #include "Module_LcmControl.h"
  16. #include "../Log/log.h"
  17. #include "../ShareMemory/shmMem.h"
  18. #include "../Define/define.h"
  19. #include "../Config.h"
  20. #include "../SelectGun/SelectGun.h"
  21. #include "../CSU/main.h"
  22. DcCommonInfo *ShmDcCommonData = NULL;
  23. //------------------------------------------------------------------------------
  24. //struct SysConfigAndInfo *ShmSysConfigAndInfo;
  25. //struct StatusCodeData *ShmStatusCodeData;
  26. static struct SysConfigData *pSysConfig = NULL;
  27. static struct SysInfoData *pSysInfo = NULL;
  28. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  29. static struct FanModuleData *ShmFanModuleData;
  30. static struct PrimaryMcuData *ShmPrimaryMcuData;
  31. static SelectGunInfo *ShmSelectGunInfo = NULL;
  32. static struct ChargingInfoData *pDcChargingInfo = NULL;
  33. static struct ChargingInfoData *pAcChargingInfo = NULL;
  34. bool needReloadQr = true;
  35. bool _isShow = false; //DS60-120 add
  36. uint8_t _showInformIndex = 0; //DS60-120 add
  37. int _port;
  38. //char* pPortName = "/dev/ttyO2";
  39. char *pPortName = "/dev/ttyS3";
  40. char *moduleName = "DMT80480T070_09WT";
  41. uint8_t _totalCount;
  42. uint8_t acgunCount;
  43. //struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  44. //struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  45. uint8_t ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
  46. uint8_t isDiffStatus = false;
  47. uint8_t isChangeBattMap = false;
  48. // 當前選擇的槍號
  49. #if defined DD360Audi
  50. short _currentPage = _LCM_SELECT_GUN;
  51. short _oldPage = _LCM_SELECT_GUN;
  52. #else
  53. short _currentPage = _LCM_NONE;
  54. short _oldPage = _LCM_NONE;
  55. #endif //defined DD360Audi
  56. uint8_t _gunIndex = 0;
  57. bool _wifi_conn_status = false;
  58. bool _battery_display_ani = false;
  59. uint8_t _curPage_index = 0;
  60. bool _page_reload = false;
  61. // LCM - HW
  62. uint8_t _everyPageRollChange = 0;
  63. short __conn_status = 0x1030;
  64. short __ethernet_status = 0x1032;
  65. short __3G4G_status = 0x1036;
  66. short __3G4G_status1 = 0x1037;
  67. short __3G4G_move_status = 0x1038;
  68. short __wifi_status = 0x103C;
  69. short __sel_gun_btn = 0x1040;
  70. short __ret_home_btn = 0x1042;
  71. short __stop_method_btn = 0x1044;
  72. short __lcm_version = 0x104A;
  73. short __qr_code = 0x1250;
  74. short __main_rfid = 0x1052;
  75. short __main_qr = 0x1054;
  76. short __main_app = 0x1056;
  77. short __plug_in_arrow = 0x1060;
  78. short __conn_line = 0x1066;
  79. short __gun_type_index = 0x1070;
  80. short __cmp_gun_type_index = 0x1080; ////For Audi
  81. short __batt_map_empty = 0x1090; ////For Audi
  82. short __qr_code_pre = 0x1280;
  83. short __side_top = 0x1090;
  84. short __side_down = 0x1092;
  85. short __side_mid = 0x1094;
  86. short __conn_line_chag = 0x1096;
  87. short __batt_map = 0x1100;
  88. short __soc_value_charging = 0x1102;
  89. short __remain_time_map = 0x1106;
  90. short __power_map = 0x1108;
  91. short __energy_map = 0x110A;
  92. short __remain_time_tx = 0x1110;
  93. short __trp_remain_time_map = 0x1116;
  94. short __trp_power_map = 0x1118;
  95. short __trp_energy_map = 0x111A;
  96. short __output_eng_tx = 0x1120;
  97. short __total_out_eng_tx = 0x1130;
  98. short __conn_line_comp = 0x1140;
  99. short __charging_fee_map = 0x1146;
  100. short __charging_fee_tx = 0x1150;
  101. short __money_by_rate = 0x1200;
  102. short __money_rate = 0x1220;
  103. short __money_rate_map = 0x1230;
  104. //DS60-120 add
  105. short __csu_ver_string = 0x1300;
  106. short __csu_ver_value = 0x1310;
  107. short __fan_speed_string = 0x1390;
  108. short __fan_speed_value = 0x1400;
  109. short __dc1_ver_string = 0x1320;
  110. short __dc1_ver_value = 0x1330;
  111. short __dc2_ver_string = 0x1340;
  112. short __dc2_ver_value = 0x1350;
  113. short __eth0_ip_string = 0x1360;
  114. short __eth0_ip_value = 0x1370;
  115. short __sn_string = 0x1410;
  116. short __sn_value = 0x1420;
  117. //For Audi, for select gun
  118. short __left_gun_map = 0x1260;
  119. short __right_gun_map = 0x1262;
  120. short __add_chk_btn = 0x1264;
  121. //short __station_id = 0x1270;
  122. short __balance = 0x1270;
  123. short __remain_balance = 0x1280;
  124. short __custStationIdL1 = 0x1450;
  125. //short __custStationIdL2 = 0x1470;
  126. short _emergency_map = 0x111C;
  127. uint8_t _btn_pressed = 0xF0;
  128. // ICON ID
  129. uint8_t _disappear = 0;
  130. uint8_t _disconnect = 1;
  131. uint8_t _connect = 2;
  132. uint8_t _warning = 3;
  133. uint8_t _arrow_dark = 4;
  134. uint8_t _arrow_light = 5;
  135. uint8_t _3G4G_disconnect = 6;
  136. uint8_t __3G4G_connect = 7;
  137. uint8_t _wifi_disconnect = 8;
  138. uint8_t _wifi_connect = 9;
  139. uint8_t _logo = 10;
  140. uint8_t _conn_map1 = 11;
  141. uint8_t _conn_map2 = 12;
  142. uint8_t _sel_gun_btn = 13;
  143. uint8_t _back_home_btn = 14;
  144. uint8_t _stop_charging_btn = 15;
  145. uint8_t _stop_charging_btn_scan = 16;
  146. uint8_t _chademo_dark = 17;
  147. uint8_t _ccs_dark = 18;
  148. uint8_t _gbt_dark = 19;
  149. uint8_t _actype_dark = 20;
  150. uint8_t _chademo_light = 21;
  151. uint8_t _ccs_light = 22;
  152. uint8_t _gbt_light = 23;
  153. uint8_t _actype_light = 24;
  154. uint8_t _main_none_rfid = 25;
  155. uint8_t _main_rfid = 26;
  156. uint8_t _main_none_app = 27;
  157. uint8_t _main_app = 28;
  158. uint8_t _main_none_qr = 29;
  159. uint8_t _main_qr = 30;
  160. uint8_t _charging_map1 = 31;
  161. uint8_t _charging_map2 = 32;
  162. uint8_t _battery_empty = 33;
  163. uint8_t _battery_cap_20 = 34;
  164. uint8_t _battery_cap_40 = 35;
  165. uint8_t _battery_cap_60 = 36;
  166. uint8_t _battery_cap_80 = 37;
  167. uint8_t _battery_cap_100 = 38;
  168. uint8_t _battery_map = 39;
  169. uint8_t _power_map = 40;
  170. uint8_t _time_map = 41;
  171. uint8_t _complete_map = 42;
  172. uint8_t _battery_soc_20 = 43;
  173. uint8_t _battery_soc_40 = 44;
  174. uint8_t _battery_soc_60 = 45;
  175. uint8_t _battery_soc_80 = 46;
  176. uint8_t _battery_soc_100 = 47;
  177. uint8_t _battery_eng_map = 48;
  178. uint8_t _money_map = 49;
  179. uint8_t _elapse_time_map = 50;
  180. uint8_t _charging_money = 51;
  181. //uint8_t _side_none_rfid = 52;
  182. //uint8_t _side_rfid = 53;
  183. //uint8_t _side_none_app = 54;
  184. //uint8_t _side_app = 55;
  185. //uint8_t _side_none_qr = 56;
  186. //uint8_t _side_qr = 57;
  187. uint8_t _eth_disconnect = 52; //58;
  188. uint8_t _eth_connect = 53; //59;
  189. uint8_t _chademo_dark_cmp = 54;
  190. uint8_t _ccs_dark_cmp = 55;
  191. uint8_t _gbt_dark_cmp = 56;
  192. uint8_t _actype_dark_cmp = 57;
  193. uint8_t _chademo_light_cmp = 58;
  194. uint8_t _ccs_light_cmp = 59;
  195. uint8_t _gbt_light_cmp = 60;
  196. uint8_t _actype_light_cmp = 61;
  197. uint8_t _logo_cmp = 62;
  198. uint8_t _battery_eng_trp_map = 63;
  199. uint8_t _money_trp_map = 64;
  200. uint8_t _elapse_time_trp_map = 65;
  201. #if defined DD360Audi
  202. ////For Audi
  203. uint8_t _left_gun_disable_map = 66;
  204. uint8_t _left_gun_enable_map = 67;
  205. uint8_t _right_gun_disable_map = 68;
  206. uint8_t _right_gun_enable_map = 69;
  207. uint8_t _select_gun_btn = 70;
  208. uint8_t _emergency_disable_map = 72;
  209. // For replug
  210. struct timespec showReplugStrTimer;
  211. struct timespec showFullTargetTimer;
  212. short __show_StatusString_value_1 = 0x0460;
  213. short __show_StatusString_value_2 = 0x0462;
  214. uint8_t _showfulltarget_1 = 73;
  215. uint8_t _showfulltarget_2 = 74;
  216. uint8_t _showReplugStr_1 = 75;
  217. uint8_t _showReplugStr_2 = 76;
  218. // Select Gun for Audi
  219. short __show_selectgun_value = 0x0464;
  220. uint8_t _showselectgun_left = 77;
  221. uint8_t _showselectgun_right = 78;
  222. // Wait for gun plugin Audi
  223. short __show_waitgunplug_value = 0x0468;
  224. uint8_t _showwaitgunplug_left = 80;
  225. uint8_t _showwaitgunplug_right = 81;
  226. #elif defined DD360Tcci
  227. short __show_handshark_value = 0x1464;
  228. short __show_GFD_value = 0x1466;
  229. short __show_precharge_value = 0x1468;
  230. uint8_t _show_handshark_dark = 67;
  231. uint8_t _show_handshark_light = 68;
  232. uint8_t _show_GFD_dark = 69;
  233. uint8_t _show_GFD_light = 70;
  234. uint8_t _show_precharge_dark = 71;
  235. uint8_t _show_precharge_light = 72;
  236. #endif
  237. //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  238. //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  239. //#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  240. //=================================
  241. // Common routine
  242. //=================================
  243. /*int StoreLogMsg(const char *fmt, ...)
  244. {
  245. char Buf[4096 + 256];
  246. char buffer[4096];
  247. va_list args;
  248. struct timeb SeqEndTime;
  249. struct tm *tm;
  250. va_start(args, fmt);
  251. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  252. va_end(args);
  253. memset(Buf, 0, sizeof(Buf));
  254. ftime(&SeqEndTime);
  255. SeqEndTime.time = time(NULL);
  256. tm = localtime(&SeqEndTime.time);
  257. if (pSysConfig->SwitchDebugFlag == YES) {
  258. sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
  259. tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
  260. printf("%s ", Buf);
  261. } else {
  262. sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  263. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
  264. buffer,
  265. tm->tm_year + 1900, tm->tm_mon + 1);
  266. system(Buf);
  267. }
  268. return rc;
  269. }
  270. char *getTimeString(void)
  271. {
  272. char *result = malloc(21);
  273. time_t timep;
  274. struct tm *p;
  275. time(&timep);
  276. p = gmtime(&timep);
  277. sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
  278. return result;
  279. }
  280. */
  281. #if 0
  282. //==========================================
  283. // Init all share memory
  284. //==========================================
  285. int InitShareMemory()
  286. {
  287. int result = PASS;
  288. int MeterSMId;
  289. //creat ShmSysConfigAndInfo
  290. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0) {
  291. #ifdef SystemLogMessage
  292. log_error("shmget ShmSysConfigAndInfo NG");
  293. #endif
  294. result = FAIL;
  295. } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  296. #ifdef SystemLogMessage
  297. log_error("shmat ShmSysConfigAndInfo NG");
  298. #endif
  299. result = FAIL;
  300. } else
  301. {}
  302. //creat ShmStatusCodeData
  303. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0) {
  304. #ifdef SystemLogMessage
  305. log_error("shmget ShmStatusCodeData NG");
  306. #endif
  307. result = FAIL;
  308. } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  309. #ifdef SystemLogMessage
  310. log_error("shmat ShmStatusCodeData NG");
  311. #endif
  312. result = FAIL;
  313. } else
  314. {}
  315. //creat Audi customization info
  316. if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
  317. log_error("[main]CreatShareMemory:shmget select gun info NG ");
  318. return 0;
  319. } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  320. log_error("[main]CreatShareMemory:shmat shmget select gun info ");
  321. return 0;
  322. }
  323. //creat ShmStatusCodeData
  324. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
  325. #ifdef SystemLogMessage
  326. log_error("shmget ShmPrimaryMcuData NG");
  327. #endif
  328. result = FAIL;
  329. } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  330. #ifdef ShmPrimaryMcuData
  331. log_error("shmat ShmPrimaryMcuData NG");
  332. #endif
  333. result = FAIL;
  334. }
  335. return result;
  336. }
  337. #endif //0
  338. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  339. {
  340. struct timeval _end_time;
  341. gettimeofday(&_end_time, NULL);
  342. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  343. }
  344. void displayMessageDgus(uint8_t *data, uint16_t len, uint8_t isRX)
  345. {
  346. uint8_t output[8192];
  347. memset(output, 0x00, ARRAY_SIZE(output));
  348. sprintf((char*)output, "%s", (isRX?"RX: ":"TX: "));
  349. for(uint16_t idx = 0;idx<len;idx++)
  350. {
  351. sprintf((char*)output, "%s%02x ", output, data[idx]);
  352. }
  353. #ifdef isDebugPrint
  354. log_info("%s\n", output);
  355. #endif
  356. }
  357. void ChangeTimeValue(uint8_t time)
  358. {
  359. uint8_t cmd[2];
  360. uint8_t value[2];
  361. memset(cmd, 0x00, sizeof(cmd));
  362. sprintf((char *) value, "%d", time);
  363. string2ByteArray(value, cmd);
  364. DisplayValueToLcm(0x1290, cmd, sizeof(cmd));
  365. }
  366. int transceiverDgus(int32_t fd, uint8_t *tx, uint16_t tx_len, uint8_t *rx, uint16_t rx_len)
  367. {
  368. int result = FAIL;
  369. int len;
  370. tcflush(fd,TCIOFLUSH);
  371. #ifdef isDebugPrint
  372. displayMessageDgus(tx, tx_len, NO);
  373. #endif
  374. usleep(10000);
  375. if(write(fd, tx, tx_len) >= ARRAY_SIZE(tx))
  376. {
  377. if(tx[3] == CMD_REG_WRITE_DATA)
  378. {
  379. len = read(fd, rx, rx_len);
  380. if(len > 0)
  381. {
  382. if((rx[0] == CMD_HEADER_1) && (rx[1] == CMD_HEADER_2))
  383. {
  384. if((rx[3] == CMD_REG_WRITE_DATA) && (rx[4] == 0x4f) && (rx[5] == 0x4b))
  385. {
  386. displayMessageDgus(rx, len, YES);
  387. result = PASS;
  388. }
  389. }
  390. }
  391. }
  392. else if(tx[3] == CMD_REG_READ_DATA)
  393. {
  394. len = read(fd, rx, rx_len);
  395. if(len > 0)
  396. {
  397. if((rx[0] == CMD_HEADER_1) && (rx[1] == CMD_HEADER_2))
  398. {
  399. if(rx[3] == CMD_REG_READ_DATA)
  400. {
  401. displayMessageDgus(rx, len, YES);
  402. result = PASS;
  403. }
  404. else
  405. {}
  406. }
  407. else
  408. {}
  409. }
  410. else
  411. {}
  412. }
  413. else
  414. {}
  415. }
  416. else
  417. {}
  418. return result;
  419. }
  420. //==========================================
  421. // Open and Close RS232 and R/W
  422. //==========================================
  423. int CreateCommunicationLcmPort()
  424. {
  425. int fd;
  426. struct termios tios;
  427. fd = open(pPortName, O_RDWR);
  428. if (fd <= 0) {
  429. #ifdef SystemLogMessage
  430. log_error("open /dev/ttyS3 NG ");
  431. #endif
  432. return -1;
  433. }
  434. ioctl(fd, TCGETS, &tios);
  435. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  436. tios.c_lflag = 0;
  437. tios.c_iflag = 0;
  438. tios.c_oflag = 0;
  439. tios.c_cc[VMIN] = 0;
  440. tios.c_cc[VTIME] = (uint8_t) 5;
  441. tios.c_lflag = 0;
  442. tcflush(fd, TCIFLUSH);
  443. ioctl(fd, TCSETS, &tios);
  444. return fd;
  445. }
  446. void CloseCommunicationLcmPort()
  447. {
  448. close(_port);
  449. }
  450. void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
  451. {
  452. int len = write(_port, cmd, cmdLen);
  453. if (len >= sizeof(cmd)) {
  454. //log_info("Write cmd to LCM successfully. ");
  455. }
  456. /*
  457. for(uint8_t i = 0 ; i<cmdLen; i++) {
  458. log_info("Write data[%d]:0x%x",i,cmd[i]);
  459. }
  460. */
  461. }
  462. void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
  463. {
  464. /*
  465. read(_port, msg, readLen);
  466. if (*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2) {
  467. if (*(msg + 3) == CMD_WRITE) {
  468. switch (*(msg + 4)) {
  469. case CMD_REGISTER: {
  470. // 頁面
  471. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  472. }
  473. break;
  474. }
  475. } else if (*(msg + 3) == CMD_MULTI_READ) {
  476. // switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
  477. // {
  478. // case BUTTON_GUN_INDEX:
  479. // {
  480. // // 當前選的槍號
  481. // _curGunIndex = (*(msg + 8));
  482. // }
  483. // break;
  484. // }
  485. }
  486. }*/
  487. read(_port, msg, readLen);
  488. // 5a : CMD_TITLE_1
  489. // a5 : CMD_TITLE_2
  490. // 5
  491. // 81 : CMD_WRITE
  492. // 3 : CMD_REGISTER
  493. // 2 : Data length
  494. // 0 : High byte
  495. // 1 : Low byte
  496. // printf("-------------------------------------------- \n");
  497. // printf("msg = %x \n", *msg); // A5
  498. // printf("msg = %x \n", *(msg + 1)); // 5A
  499. // printf("msg = %x \n", *(msg + 2)); // Len : [3] ~ [6] + Data Len
  500. // printf("msg = %x \n", *(msg + 3)); // cmd : 0x83
  501. // printf("msg = %x \n", *(msg + 4)); // addr : H
  502. // printf("msg = %x \n", *(msg + 5)); // addr : L
  503. // printf("msg = %x \n", *(msg + 6)); // Data Len
  504. //
  505. // printf("msg = %x \n", *(msg + 7));
  506. // printf("msg = %x \n", *(msg + 8));
  507. // printf("msg = %x \n", *(msg + 9));
  508. // printf("msg = %x \n", *(msg + 10));
  509. // printf("msg = %x \n", *(msg + 11));
  510. // printf("msg = %x \n", *(msg + 12));
  511. // printf("msg = %x \n", *(msg + 13));
  512. // printf("msg = %x \n", *(msg + 14));
  513. /*
  514. for(uint8_t i = 0 ; i<readLen+3; i++) {
  515. log_info("Read data[%d]:0x%x",i,msg[i]);
  516. }*/
  517. if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
  518. {
  519. if(*(msg + 3) == CMD_WRITE)
  520. {
  521. switch (*(msg + 4))
  522. {
  523. case CMD_REGISTER:
  524. {
  525. // 頁面
  526. //if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  527. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  528. _currentPage = *(msg + 7);
  529. log_info("Current Page:%d",_currentPage);
  530. // if (_currentPage != 1 && _currentPage != 5 && _currentPage != 6 && _currentPage != 7 && _currentPage != 8)
  531. // printf("_currentPage = %d \n", _currentPage);
  532. }
  533. break;
  534. }
  535. }
  536. else if (*(msg + 3) == CMD_MULTI_READ)
  537. {
  538. short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
  539. if (key == __lcm_version)
  540. {
  541. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  542. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  543. //pSysInfo->LcmFwRev = atoi((char *)(msg + 7));
  544. printf("msg = %d \n", atoi((char *)(msg + 7)));
  545. // printf("msg = %x \n", *(msg + 7));
  546. // printf("msg = %x \n", *(msg + 8));
  547. // printf("msg = %x \n", *(msg + 9));
  548. }
  549. else if (key == 0x0014)
  550. {
  551. //printf("page = %d \n", *(msg + 8));
  552. _currentPage = *(msg + 8);
  553. }
  554. else if (key == 0x0600)
  555. {
  556. if (_btn_pressed != *(msg + 8))
  557. {
  558. if (_btn_pressed == 0x0A)
  559. printf("NotPressed \n");
  560. else
  561. printf("Pressed \n");
  562. _btn_pressed = *(msg + 8);
  563. }
  564. //printf("msg = %x \n", *(msg + 7));
  565. }
  566. // switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
  567. // {
  568. // case BUTTON_GUN_INDEX:
  569. // {
  570. // // 當前選的槍號
  571. // _curGunIndex = (*(msg + 8));
  572. // }
  573. // break;
  574. // }
  575. }
  576. }
  577. }
  578. //================================================
  579. // Function
  580. //================================================
  581. void ChangeToOtherPage(short newPage)
  582. {
  583. /*
  584. uint8_t cmd[7];
  585. memset(cmd, 0x00, sizeof(cmd));
  586. cmd[0] = CMD_TITLE_1;
  587. cmd[1] = CMD_TITLE_2;
  588. cmd[2] = 0x02 + sizeof(newPage);
  589. cmd[3] = CMD_READ;
  590. cmd[4] = CMD_REGISTER;
  591. cmd[5] = newPage >> 8;
  592. cmd[6] = newPage & 0x00FF;
  593. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  594. usleep(100000);
  595. */
  596. uint8_t cmd[10];
  597. memset(cmd, 0x00, sizeof(cmd));
  598. uint8_t msg[9];
  599. memset(msg, 0x00, sizeof(msg));
  600. cmd[0] = CMD_TITLE_1;
  601. cmd[1] = CMD_TITLE_2;
  602. cmd[2] = 0x07;
  603. cmd[3] = 0x82;
  604. cmd[4] = 0x00;
  605. cmd[5] = 0x84;
  606. cmd[6] = 0x5A;
  607. cmd[7] = 0x01;
  608. cmd[8] = newPage >> 8;
  609. cmd[9] = newPage & 0x00FF;
  610. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  611. usleep(10000);
  612. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  613. }
  614. void ChangeBackLight(bool islight)
  615. {
  616. /*
  617. uint8_t value = 0x01;
  618. if (islight) {
  619. value = 0x20;
  620. }
  621. uint8_t cmd[7];
  622. memset(cmd, 0x00, sizeof(cmd));
  623. cmd[0] = CMD_TITLE_1;
  624. cmd[1] = CMD_TITLE_2;
  625. cmd[2] = 0x03;
  626. cmd[3] = CMD_READ;
  627. cmd[4] = CMD_BACKLIGHT;
  628. cmd[5] = value;
  629. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  630. usleep(100000);
  631. */
  632. uint8_t value = 0x01;
  633. uint8_t msg[9];
  634. memset(msg, 0x00, sizeof(msg));
  635. // 0x00 ~ 0x40
  636. if (islight)
  637. {
  638. value = 0x20;
  639. }
  640. uint8_t cmd[7];
  641. memset(cmd, 0x00, sizeof(cmd));
  642. cmd[0] = CMD_TITLE_1;
  643. cmd[1] = CMD_TITLE_2;
  644. cmd[2] = 0x03;
  645. cmd[3] = CMD_READ;
  646. cmd[4] = CMD_BACKLIGHT;
  647. cmd[5] = value;
  648. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  649. usleep(10000);
  650. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  651. }
  652. void GetCurrentPage()
  653. {
  654. /*
  655. uint8_t cmd[6];
  656. memset(cmd, 0x00, sizeof(cmd));
  657. uint8_t msg[8];
  658. memset(msg, 0x00, sizeof(msg));
  659. cmd[0] = CMD_TITLE_1;
  660. cmd[1] = CMD_TITLE_2;
  661. cmd[2] = 0x03; // 底下總長度
  662. cmd[3] = CMD_WRITE;
  663. cmd[4] = CMD_REGISTER;
  664. cmd[5] = 0x02;
  665. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  666. usleep(100000);
  667. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  668. */
  669. uint8_t cmd[7];
  670. memset(cmd, 0x00, sizeof(cmd));
  671. uint8_t msg[9];
  672. memset(msg, 0x00, sizeof(msg));
  673. cmd[0] = CMD_TITLE_1;
  674. cmd[1] = CMD_TITLE_2;
  675. cmd[2] = 0x04; // 底下總長度
  676. cmd[3] = 0x83;
  677. cmd[4] = 0x00;
  678. cmd[5] = 0x14;
  679. cmd[6] = 0x01;
  680. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  681. usleep(10000);
  682. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  683. }
  684. void DisplayValueToLcm(short address, uint8_t *data, uint8_t len)
  685. {
  686. /*
  687. uint8_t cmd[256];
  688. memset(cmd, 0x00, sizeof(cmd));
  689. cmd[0] = CMD_TITLE_1;
  690. cmd[1] = CMD_TITLE_2;
  691. cmd[2] = 0x03 + len;
  692. cmd[3] = CMD_MULTI_WRITE;
  693. cmd[4] = address >> 8;
  694. cmd[5] = address & 0x00FF;
  695. for (uint8_t count = 0; count < len; count++) {
  696. cmd[6 + count] = *(data + count);
  697. }
  698. WriteCmdToLcm(cmd, cmd[2] + 3);
  699. */
  700. uint8_t cmd[256];
  701. memset(cmd, 0x00, sizeof(cmd));
  702. uint8_t msg[9];
  703. memset(msg, 0x00, sizeof(msg));
  704. cmd[0] = CMD_TITLE_1;
  705. cmd[1] = CMD_TITLE_2;
  706. cmd[2] = 0x03 + len;
  707. cmd[3] = CMD_MULTI_WRITE;
  708. cmd[4] = address >> 8;
  709. cmd[5] = address & 0x00FF;
  710. for(uint8_t count = 0; count < len; count++)
  711. {
  712. cmd[6 + count] = *(data + count);
  713. }
  714. WriteCmdToLcm(cmd, cmd[2] + 3);
  715. usleep(10000);
  716. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  717. }
  718. void ChangeDisplay2Value(short address, short value)
  719. {
  720. uint8_t data[2];
  721. data[0] = value >> 8;
  722. data[1] = value & 0x00FF;
  723. DisplayValueToLcm(address, data, sizeof(data));
  724. }
  725. void GetBtnStatus(short address, uint8_t len)
  726. {
  727. uint8_t cmd[8];
  728. memset(cmd, 0x00, sizeof(cmd));
  729. uint8_t msg[8];
  730. memset(msg, 0x00, sizeof(msg));
  731. cmd[0] = CMD_TITLE_1;
  732. cmd[1] = CMD_TITLE_2;
  733. cmd[2] = 0x03 + len;
  734. cmd[3] = CMD_MULTI_READ;
  735. cmd[4] = address >> 8;
  736. cmd[5] = address & 0x00FF;
  737. cmd[6] = 0x00 + len;
  738. WriteCmdToLcm(cmd, cmd[2] + 3);
  739. usleep(100000);
  740. ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
  741. }
  742. //================================================
  743. // Warning process
  744. //================================================
  745. void string2ByteArray(uint8_t *input, uint8_t *output)
  746. {
  747. int loop;
  748. int i;
  749. loop = 0;
  750. i = 0;
  751. while (input[loop] != '\0') {
  752. output[i++] = input[loop++];
  753. }
  754. output[loop] = '\0';
  755. }
  756. void ChangeWarningFunc()
  757. {
  758. uint8_t cmd[7] = {0};
  759. uint8_t i = 0;
  760. //uint8_t j = 0;
  761. //log_info("ChangeWarningFunc ");
  762. // 最多一次五筆
  763. //log_info("LCM PageIndex = %d ", pSysWarning->PageIndex);
  764. //log_info("WarningCount = %d ", pSysWarning->WarningCount);
  765. //#if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox
  766. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  767. memset(cmd, 0x00, sizeof(cmd));
  768. if ((i) >= 5) {
  769. break;
  770. }
  771. //error code
  772. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  773. DisplayValueToLcm(0x1010 + ((i) * 6), cmd, sizeof(cmd));
  774. //警告標示
  775. memset(cmd, 0x00, sizeof(cmd));
  776. cmd[0] = 0x00;
  777. cmd[1] = 0x01;
  778. DisplayValueToLcm(0x1002 + ((i) * 2), cmd, 2);
  779. }
  780. memset(cmd, 0x00, sizeof(cmd));
  781. for (; i < 5; i++) {
  782. DisplayValueToLcm(0x1010 + ((i) * 6), cmd, sizeof(cmd));
  783. DisplayValueToLcm(0x1002 + ((i) * 2), cmd, 2);
  784. }
  785. /*#else
  786. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  787. memset(cmd, 0x00, sizeof(cmd));
  788. if ((i - j) >= 5) {
  789. break;
  790. }
  791. if (
  792. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "033900", 6) == 0) ||
  793. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "033901", 6) == 0) ||
  794. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "033902", 6) == 0) ||
  795. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043627", 6) == 0) ||
  796. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043628", 6) == 0) ||
  797. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043622", 6) == 0) ||
  798. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043623", 6) == 0) ||
  799. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043624", 6) == 0) ||
  800. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043625", 6) == 0) ||
  801. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043626", 6) == 0) ||
  802. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "042241", 6) == 0) ||
  803. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "042242", 6) == 0)
  804. ) {
  805. j++;
  806. continue;
  807. }
  808. //error code
  809. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  810. DisplayValueToLcm(0x0010 + ((i - j) * 6), cmd, sizeof(cmd));
  811. //警告標示
  812. memset(cmd, 0x00, sizeof(cmd));
  813. cmd[0] = 0x00;
  814. cmd[1] = 0x01;
  815. DisplayValueToLcm(0x0002 + ((i - j) * 2), cmd, 2);
  816. }
  817. memset(cmd, 0x00, sizeof(cmd));
  818. i = i - j;
  819. for (; (i) < 5; i++) {
  820. DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
  821. DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
  822. }
  823. #endif //!defined DD360Tcci && !defined DD360Audi
  824. */
  825. }
  826. //================================================
  827. // QR Code process
  828. //================================================
  829. void ChangeQrCode_Idle(char *input)
  830. {
  831. #if defined DD360Audi
  832. int len = strlen(input) + 3;
  833. int loop = 0;
  834. int i = 0, j = 0, k = 0, l = 0;
  835. uint8_t qrUrl[128] = {0};
  836. uint16_t urlLen = 0;
  837. uint8_t cmd[len];
  838. uint8_t tmpBuf[15] = {0};
  839. //uint8_t tmpLen = sizeof(tmpBuf) - 1;
  840. strncpy((char *)cmd, " ", len);
  841. while (input[loop] != '\0') {
  842. cmd[i++] = input[loop++];
  843. l = loop - 1;
  844. if (len >= 25) {
  845. if (i >= 16 && i <= 19) {
  846. tmpBuf[k++] = input[l];
  847. //printf("tmpBuf = %s", tmpBuf);
  848. } else if (i >= 21 && i <= 23) {
  849. tmpBuf[k++] = input[l];
  850. }
  851. }
  852. }
  853. tmpBuf[k] = '\0';
  854. //printf("tmpBuf = %s", tmpBuf);
  855. j += sprintf((char *)&cmd[i], ":%d", pSysInfo->CurGunSelected); ////For Audi
  856. cmd[len - 1] = '\0';
  857. urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
  858. qrUrl[urlLen] = '\0';
  859. //printf("qr url = %s", qrUrl);
  860. DisplayValueToLcm(__qr_code, qrUrl, urlLen);
  861. j = 0;
  862. j += sprintf((char *)&tmpBuf[k], "0%d", pSysInfo->CurGunSelected); ////For Audi
  863. tmpBuf[k + j] = '\0';
  864. //if (len < 25) {
  865. // strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  866. //}
  867. //tmpBuf[tmpLen] = '\0';
  868. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  869. /*if (len > sizeof(tmpBuf)) {
  870. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  871. tmpBuf[tmpLen] = '\0';
  872. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  873. memset(tmpBuf, 0, sizeof(tmpBuf));
  874. strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
  875. tmpBuf[tmpLen] = '\0';
  876. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  877. } else {
  878. DisplayValueToLcm(__custStationIdL1, cmd, len);
  879. strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
  880. tmpBuf[tmpLen] = '\0';
  881. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  882. }*/
  883. #else
  884. int len = strlen(input);
  885. uint8_t cmd[len];
  886. int loop = 0;
  887. int i = 0;
  888. while (input[loop] != '\0') {
  889. cmd[i++] = input[loop++];
  890. }
  891. DisplayValueToLcm(__qr_code, cmd, len + 1);
  892. #endif //defined DD360Audi
  893. }
  894. void ChangeQrCode_Charge(char *input)
  895. {
  896. #if defined DD360Audi
  897. int len = strlen(input) + 3;
  898. int loop = 0;
  899. int i = 0, j = 0, k = 0, l = 0;
  900. uint8_t qrUrl[128] = {0};
  901. uint16_t urlLen = 0;
  902. uint8_t cmd[len];
  903. uint8_t tmpBuf[15] = {0};
  904. //uint8_t tmpLen = sizeof(tmpBuf) - 1;
  905. strncpy((char *)cmd, " ", len);
  906. while (input[loop] != '\0') {
  907. cmd[i++] = input[loop++];
  908. l = loop - 1;
  909. if (len >= 25) {
  910. if (i >= 16 && i <= 19) {
  911. tmpBuf[k++] = input[l];
  912. //printf("tmpBuf = %s", tmpBuf);
  913. } else if (i >= 21 && i <= 23) {
  914. tmpBuf[k++] = input[l];
  915. }
  916. }
  917. }
  918. tmpBuf[k] = '\0';
  919. //printf("tmpBuf = %s", tmpBuf);
  920. j += sprintf((char *)&cmd[i], ":%d", pSysInfo->CurGunSelected); ////For Audi
  921. cmd[len - 1] = '\0';
  922. urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
  923. qrUrl[urlLen] = '\0';
  924. DisplayValueToLcm(__qr_code, qrUrl, urlLen);
  925. j = 0;
  926. j += sprintf((char *)&tmpBuf[k], "0%d", pSysInfo->CurGunSelected); ////For Audi
  927. tmpBuf[k + j] = '\0';
  928. if (len < 25) {
  929. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  930. }
  931. //tmpBuf[tmpLen] = '\0';
  932. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  933. /*if (len > sizeof(tmpBuf)) {
  934. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  935. tmpBuf[tmpLen] = '\0';
  936. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  937. memset(tmpBuf, 0, sizeof(tmpBuf));
  938. strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
  939. tmpBuf[tmpLen] = '\0';
  940. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  941. } else {
  942. DisplayValueToLcm(__custStationIdL1, cmd, len);
  943. strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
  944. tmpBuf[tmpLen] = '\0';
  945. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  946. }*/
  947. #else
  948. int len = strlen(input);
  949. uint8_t cmd[len];
  950. int loop = 0;
  951. int i = 0;
  952. while (input[loop] != '\0') {
  953. cmd[i++] = input[loop++];
  954. }
  955. DisplayValueToLcm(__qr_code_pre, cmd, len + 1);
  956. #endif //defined DD360Audi
  957. }
  958. //================================================
  959. // Change current page
  960. //================================================
  961. void ChangeCurPage()
  962. {
  963. //log_info("cur = %d, new = %d ", _currentPage, pSysInfo->PageIndex);
  964. if (_currentPage != pSysInfo->PageIndex) {
  965. _currentPage = pSysInfo->PageIndex;
  966. ChangeToOtherPage(_currentPage);
  967. _everyPageRollChange = 0;
  968. }
  969. }
  970. //================================================
  971. // Main process
  972. //================================================
  973. uint8_t demoCount = 0;
  974. void DemoFunction()
  975. {
  976. if (demoCount == 0) {
  977. pSysWarning->WarningCount = 6;
  978. memcpy(&pSysWarning->WarningCode[0][0], "000001", 7);
  979. memcpy(&pSysWarning->WarningCode[1][0], "000002", 7);
  980. memcpy(&pSysWarning->WarningCode[2][0], "000003", 7);
  981. memcpy(&pSysWarning->WarningCode[3][0], "000004", 7);
  982. memcpy(&pSysWarning->WarningCode[4][0], "000005", 7);
  983. memcpy(&pSysWarning->WarningCode[5][0], "000006", 7);
  984. } else {
  985. if (demoCount == 20) {
  986. pSysInfo->PageIndex = _LCM_IDLE;
  987. } else if (demoCount == 80) {
  988. pSysInfo->PageIndex = _LCM_AUTHORIZING;
  989. } else if (demoCount == 100) {
  990. pSysInfo->PageIndex = _LCM_AUTHORIZ_COMP;
  991. } else if (demoCount == 120) {
  992. pSysInfo->PageIndex = _LCM_AUTHORIZ_FAIL;
  993. } else if (demoCount == 140) {
  994. pSysInfo->PageIndex = _LCM_PRE_CHARGE;
  995. } else if (demoCount == 180) {
  996. pSysInfo->PageIndex = _LCM_CHARGING;
  997. }
  998. }
  999. if (demoCount < 180) {
  1000. demoCount++;
  1001. }
  1002. }
  1003. //================================================
  1004. // Main process
  1005. //================================================
  1006. bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **_chargingData)
  1007. {
  1008. for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
  1009. if (pSysInfo->ChademoChargingData[index].Index == target) {
  1010. _chargingData[target] = &pSysInfo->ChademoChargingData[index];
  1011. return true;
  1012. }
  1013. }
  1014. for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
  1015. if (pSysInfo->CcsChargingData[index].Index == target) {
  1016. _chargingData[target] = &pSysInfo->CcsChargingData[index];
  1017. return true;
  1018. }
  1019. }
  1020. for (uint8_t index = 0; index < GB_QUANTITY; index++) {
  1021. if (pSysInfo->GbChargingData[index].Index == target) {
  1022. _chargingData[target] = &pSysInfo->GbChargingData[index];
  1023. return true;
  1024. }
  1025. }
  1026. return false;
  1027. }
  1028. bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
  1029. {
  1030. if (target < AC_QUANTITY) {
  1031. acChargingData[target] = &pSysInfo->AcChargingData[target];
  1032. return true;
  1033. }
  1034. return false;
  1035. }
  1036. int GetTimeoutValue(struct timespec *startTime)
  1037. {
  1038. struct timespec endTime;
  1039. clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
  1040. return endTime.tv_sec - startTime->tv_sec;
  1041. }
  1042. void GetTimespecFunc(struct timespec *time)
  1043. {
  1044. clock_gettime(CLOCK_MONOTONIC_COARSE, time);
  1045. }
  1046. #if defined DD360Audi
  1047. void RunReplugStringFunction(bool isRun)
  1048. {
  1049. if (isRun) {
  1050. int time = GetTimeoutValue(&showReplugStrTimer);
  1051. if (time >=1 && time <2) {
  1052. ChangeDisplay2Value(__show_StatusString_value_1, _showReplugStr_1);
  1053. ChangeDisplay2Value(__show_StatusString_value_2, _showReplugStr_2);
  1054. } else if (time < 1) {
  1055. ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
  1056. ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
  1057. } else
  1058. GetTimespecFunc(&showReplugStrTimer);
  1059. } else {
  1060. ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
  1061. ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
  1062. }
  1063. }
  1064. void RunFullTargetFunction(bool isRun)
  1065. {
  1066. if (isRun) {
  1067. int time = GetTimeoutValue(&showFullTargetTimer);
  1068. if (time >=1 && time <2) {
  1069. ChangeDisplay2Value(__show_StatusString_value_1, _showfulltarget_1 );
  1070. ChangeDisplay2Value(__show_StatusString_value_2, _showfulltarget_2);
  1071. } else if (time < 1) {
  1072. ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
  1073. ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
  1074. } else
  1075. GetTimespecFunc(&showFullTargetTimer);
  1076. } else {
  1077. ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
  1078. ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
  1079. }
  1080. }
  1081. #endif
  1082. /**
  1083. * [ChangeBalanceValue :print balance information]
  1084. * @Author
  1085. * @DateTime 2020-11-26
  1086. */
  1087. static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
  1088. {
  1089. uint8_t cmd[10] = {0};
  1090. uint8_t value[10] = {0};
  1091. uint8_t len = 0;
  1092. float balance = ShmSelectGunInfo->PricesInfo[index].Balance;
  1093. if ((balance) == (FAIL_BALANCE_PRICES)) {
  1094. balance = 0.00;
  1095. }
  1096. len += sprintf((char *) value, "%.2f", balance);
  1097. if (len < 6) {
  1098. sprintf((char *)&value[len], "%s",
  1099. (uint8_t *)GetCurrency(pSysConfig->BillingData.Currency));
  1100. }
  1101. value[sizeof(value) - 1] = '\0';
  1102. string2ByteArray(value, cmd);
  1103. DisplayValueToLcm(addr, cmd, sizeof(cmd));
  1104. }
  1105. void ChangeAcBattMapAndValue(short page)
  1106. {
  1107. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  1108. if (page == _LCM_CHARGING) {
  1109. if (isDiffStatus != _battery_display_ani) {
  1110. isChangeBattMap = false;
  1111. isDiffStatus = _battery_display_ani;
  1112. }
  1113. if (pAcChargingInfo->IsCharging && !isChangeBattMap) {
  1114. isChangeBattMap = true;
  1115. if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
  1116. ChangeDisplay2Value(__batt_map, _battery_empty);
  1117. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_EMP;
  1118. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
  1119. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  1120. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV1;
  1121. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
  1122. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  1123. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV2;
  1124. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
  1125. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  1126. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV3;
  1127. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
  1128. ChangeDisplay2Value(__batt_map, _battery_cap_80);
  1129. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV4;
  1130. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
  1131. ChangeDisplay2Value(__batt_map, _battery_cap_100);
  1132. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
  1133. }
  1134. }
  1135. } else if (page == _LCM_COMPLETE) {
  1136. if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
  1137. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  1138. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
  1139. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  1140. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
  1141. ChangeDisplay2Value(__batt_map, _battery_soc_40);
  1142. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
  1143. ChangeDisplay2Value(__batt_map, _battery_soc_60);
  1144. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
  1145. ChangeDisplay2Value(__batt_map, _battery_soc_80);
  1146. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
  1147. ChangeDisplay2Value(__batt_map, _battery_soc_100);
  1148. }
  1149. }
  1150. ChangeDisplay2Value(__soc_value_charging, _disappear);
  1151. }
  1152. void ChangeBattMapAndValue(short page, int soc)
  1153. {
  1154. // srand(time(NULL));
  1155. // int min = 10;
  1156. // int max = 90;
  1157. // soc = rand() % (max - min + 1) + min;
  1158. if (page == _LCM_PRE_CHARGE) {
  1159. ChangeDisplay2Value(__batt_map_empty, _battery_empty);
  1160. } else if (page == _LCM_CHARGING) {
  1161. if (soc < 20) {
  1162. if (_battery_display_ani) {
  1163. ChangeDisplay2Value(__batt_map, _battery_empty);
  1164. } else {
  1165. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  1166. }
  1167. } else if (soc >= 20 && soc < 40) {
  1168. if (_battery_display_ani) {
  1169. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  1170. } else {
  1171. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  1172. }
  1173. } else if (soc >= 40 && soc < 60) {
  1174. if (_battery_display_ani) {
  1175. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  1176. } else {
  1177. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  1178. }
  1179. } else if (soc >= 60 && soc < 80) {
  1180. if (_battery_display_ani) {
  1181. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  1182. } else {
  1183. ChangeDisplay2Value(__batt_map, _battery_cap_80);
  1184. }
  1185. } else if (soc >= 80 && soc <= 100) {
  1186. if (_battery_display_ani) {
  1187. ChangeDisplay2Value(__batt_map, _battery_cap_80); //DS60-120 add
  1188. } else {
  1189. ChangeDisplay2Value(__batt_map, _battery_cap_100);
  1190. }
  1191. }
  1192. } else if (page == _LCM_COMPLETE) {
  1193. if (soc < 20) {
  1194. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  1195. } else if (soc >= 20 && soc < 40) {
  1196. ChangeDisplay2Value(__batt_map, _battery_soc_40);
  1197. } else if (soc >= 40 && soc < 60) {
  1198. ChangeDisplay2Value(__batt_map, _battery_soc_60);
  1199. } else if (soc >= 60 && soc < 80) {
  1200. ChangeDisplay2Value(__batt_map, _battery_soc_80);
  1201. } else if (soc >= 80 && soc <= 100) {
  1202. ChangeDisplay2Value(__batt_map, _battery_soc_100);
  1203. }
  1204. }
  1205. uint8_t cmd[5];
  1206. uint8_t value[5];
  1207. memset(cmd, 0x00, sizeof(cmd));
  1208. memset(value, 0x00, sizeof(value));
  1209. sprintf((char *)value, "%d%%", soc);
  1210. string2ByteArray(value, cmd);
  1211. DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
  1212. }
  1213. void ChangeRemainTime(int sec)
  1214. {
  1215. int h, m, s;
  1216. uint8_t cmd[10];
  1217. uint8_t value[10];
  1218. memset(cmd, 0x00, sizeof(cmd));
  1219. // srand(time(NULL));
  1220. // int min = 0;
  1221. // int max = 65536;
  1222. // sec = rand() % (max - min + 1) + min;
  1223. h = (sec / 3600);
  1224. m = (sec - (3600 * h)) / 60;
  1225. s = (sec - (3600 * h) - (m * 60));
  1226. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  1227. string2ByteArray(value, cmd);
  1228. DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
  1229. }
  1230. void ChangeChargingEnergyValue(float energy)
  1231. {
  1232. uint8_t cmd[10];
  1233. uint8_t value[10];
  1234. memset(cmd, 0x00, sizeof(cmd));
  1235. if (energy >= 0.05) {
  1236. energy -= 0.05;
  1237. }
  1238. sprintf((char *) value, "%.1f kWh", energy);
  1239. string2ByteArray(value, cmd);
  1240. DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
  1241. }
  1242. void ChangeChargingPowerValue(float pow)
  1243. {
  1244. uint8_t cmd[10];
  1245. uint8_t value[10];
  1246. memset(cmd, 0x00, sizeof(cmd));
  1247. // float min = 0.0;
  1248. // float max = 50;
  1249. // pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
  1250. sprintf((char *) value, "%.1f kW", pow);
  1251. string2ByteArray(value, cmd);
  1252. DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
  1253. }
  1254. void ChangeChargingFeeValue(float fee)
  1255. {
  1256. uint8_t cmd[10];
  1257. uint8_t value[10];
  1258. memset(cmd, 0x00, sizeof(cmd));
  1259. sprintf((char *) value, "%.2f", fee);
  1260. string2ByteArray(value, cmd);
  1261. DisplayValueToLcm(__charging_fee_tx, cmd, sizeof(cmd));
  1262. }
  1263. void DisplayMoneyRate(float money)
  1264. {
  1265. uint8_t cmd[8];
  1266. uint8_t value[8];
  1267. memset(cmd, 0x00, sizeof(cmd));
  1268. sprintf((char *) value, "%.2f", money);
  1269. string2ByteArray(value, cmd);
  1270. DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
  1271. }
  1272. void DisplayMoneyCur(uint8_t *cur)
  1273. {
  1274. uint8_t cmd[10] = {0};
  1275. uint8_t buf[10] = {0};
  1276. uint8_t len = 0;
  1277. *(cur + 3) = '\0';
  1278. memset(cmd, 0x00, sizeof(cmd));
  1279. len = sprintf((char *) buf, "%s/kWh", cur);
  1280. buf[len] = '\0';
  1281. string2ByteArray(buf, cmd);
  1282. DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
  1283. }
  1284. void RefreshPageAnimation(uint8_t value)
  1285. {
  1286. switch (_currentPage) {
  1287. case _LCM_IDLE: {
  1288. }
  1289. break;
  1290. case _LCM_WAIT_FOR_PLUG: {
  1291. if (_everyPageRollChange == 0) {
  1292. ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
  1293. } else if (_everyPageRollChange == 15) {
  1294. ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
  1295. }
  1296. _everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  1297. }
  1298. break;
  1299. case _LCM_PRE_CHARGE:
  1300. case _LCM_CHARGING:
  1301. case _LCM_COMPLETE: {
  1302. if (_currentPage == _LCM_PRE_CHARGE) {
  1303. if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
  1304. ChangeDisplay2Value(__conn_line, _conn_map1);
  1305. } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
  1306. ChangeDisplay2Value(__conn_line, _conn_map2);
  1307. }
  1308. } else if (_currentPage == _LCM_CHARGING) {
  1309. if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
  1310. ChangeDisplay2Value(__conn_line_chag, _charging_map1);
  1311. } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
  1312. ChangeDisplay2Value(__conn_line_chag, _charging_map2);
  1313. }
  1314. } else if (_currentPage == _LCM_COMPLETE) {
  1315. if (_everyPageRollChange == 0) {
  1316. ChangeDisplay2Value(__conn_line_comp, _complete_map);
  1317. }
  1318. }
  1319. _everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  1320. }
  1321. break;
  1322. }
  1323. }
  1324. void RefreshConnStatus()
  1325. {
  1326. // Wifi priority is higher than Ethernet
  1327. #if defined DD360Tcci ||defined DD360Audi || defined DD360ComBox
  1328. uint8_t i = 0;
  1329. uint8_t ethstatus = 0;
  1330. for (i = 0; i < pSysWarning->WarningCount; i++) {
  1331. if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
  1332. ethstatus = 1;
  1333. //if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
  1334. // ShmSelectGunInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
  1335. //}
  1336. break;
  1337. }
  1338. }
  1339. if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_DISABLE) {
  1340. ChangeDisplay2Value(__conn_status, _disappear);
  1341. } else if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_ENABLE_USE) {
  1342. ChangeDisplay2Value(__conn_status, _connect);
  1343. } else if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_ENABLE_NO_USE) {
  1344. ChangeDisplay2Value(__conn_status, _disconnect);
  1345. }
  1346. if (ethstatus == 1) {
  1347. if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
  1348. ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
  1349. }
  1350. } else {
  1351. if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
  1352. ChangeDisplay2Value(__ethernet_status, _eth_connect);
  1353. }
  1354. //if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_DISABLE) {
  1355. //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_USE) {
  1356. // ChangeDisplay2Value(__ethernet_status, _eth_connect);
  1357. //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_NO_USE) {
  1358. // ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
  1359. //}
  1360. }
  1361. if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_DISABLE) {
  1362. ChangeDisplay2Value(__wifi_status, _disappear);
  1363. ChangeDisplay2Value(__3G4G_status, _disappear);
  1364. if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
  1365. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1366. } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
  1367. ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
  1368. } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
  1369. ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
  1370. }
  1371. } else if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_USE) {
  1372. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1373. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  1374. } else if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_NO_USE) {
  1375. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1376. ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
  1377. }
  1378. if (ShmSelectGunInfo->EthDevStatus.Wifi != DEV_ST_DISABLE) {
  1379. if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
  1380. ChangeDisplay2Value(__3G4G_status, _disappear);
  1381. } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
  1382. ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
  1383. } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
  1384. ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
  1385. }
  1386. }
  1387. //uint8_t flag[4] = {0};
  1388. /*for (i = 0; i < pSysWarning->WarningCount; i++) {
  1389. //printf("status code = %s", &pSysWarning->WarningCode[i][0]);
  1390. if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
  1391. flag[0] = 1;
  1392. continue;
  1393. }
  1394. if (memcmp(&pSysWarning->WarningCode[i][0], "043625", 6) == 0) {
  1395. //disconnected from AP through WiFi
  1396. flag[1] = 1;
  1397. continue;
  1398. }
  1399. if (memcmp(&pSysWarning->WarningCode[i][0], "043627", 6) == 0) { //wifi disabled
  1400. flag[1] = 2;
  1401. continue;
  1402. }
  1403. if ((memcmp(&pSysWarning->WarningCode[i][0], "033900", 6) == 0) ||
  1404. (memcmp(&pSysWarning->WarningCode[i][0], "033901", 6) == 0) ||
  1405. (memcmp(&pSysWarning->WarningCode[i][0], "033902", 6) == 0)) {
  1406. flag[2] = 1;
  1407. continue;
  1408. }
  1409. if (memcmp(&pSysWarning->WarningCode[i][0], "043626", 6) == 0) {
  1410. //disconnected from APN through 3G/4G
  1411. flag[3] = 1;
  1412. continue;
  1413. }
  1414. if (memcmp(&pSysWarning->WarningCode[i][0], "043628", 6) == 0) { //4g disabled
  1415. flag[3] = 2;
  1416. continue;
  1417. }
  1418. }
  1419. if (flag[0] == 1) {
  1420. ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
  1421. } else {
  1422. ChangeDisplay2Value(__ethernet_status, _eth_connect);
  1423. }
  1424. //ChangeDisplay2Value(__wifi_status, _disappear);
  1425. //ChangeDisplay2Value(__conn_status, _disappear);
  1426. //ChangeDisplay2Value(__3G4G_status, _disappear);
  1427. if (flag[1] == 1) {
  1428. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1429. ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
  1430. } else if (flag[1] == 2) {
  1431. ChangeDisplay2Value(__wifi_status, _disappear);
  1432. } else {
  1433. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1434. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  1435. }
  1436. if (flag[2] == 1) {
  1437. ChangeDisplay2Value(__conn_status, _disconnect);
  1438. } else {
  1439. ChangeDisplay2Value(__conn_status, _connect);
  1440. }
  1441. if (flag[1] == 2) {
  1442. ChangeDisplay2Value(__3G4G_status, _disappear);
  1443. if (flag[3] == 1) {
  1444. ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
  1445. } else if (flag[3] == 2) {
  1446. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1447. } else {
  1448. ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
  1449. }
  1450. } else {
  1451. if (flag[3] == 1) {
  1452. ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
  1453. } else if (flag[3] == 2) {
  1454. ChangeDisplay2Value(__3G4G_status, _disappear);
  1455. } else {
  1456. ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
  1457. }
  1458. }
  1459. */
  1460. #else
  1461. // eth
  1462. if (pSysInfo->ethInternetConn == YES) {
  1463. ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
  1464. } else {
  1465. ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
  1466. }
  1467. // Wifi
  1468. if ((pSysConfig->ModelName[10] == 'W' ||
  1469. pSysConfig->ModelName[10] == 'D') &&
  1470. pSysConfig->AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE) {
  1471. if (pSysConfig->AthInterface.WifiNetworkConn == YES ||
  1472. pSysConfig->AthInterface.WifiMode == _SYS_WIFI_MODE_AP) {
  1473. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  1474. } else {
  1475. ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
  1476. }
  1477. } else {
  1478. ChangeDisplay2Value(__wifi_status, _disappear);
  1479. }
  1480. if ((pSysConfig->ModelName[10] == 'T' ||
  1481. pSysConfig->ModelName[10] == 'D') &&
  1482. pSysConfig->TelecomInterface.TelcomEnabled != NO) {
  1483. if (pSysConfig->AthInterface.WifiMode == _SYS_WIFI_MODE_DISABLE) {
  1484. ChangeDisplay2Value(__3G4G_status, _disappear);
  1485. // 3G/4G
  1486. if (pSysConfig->TelecomInterface.TelcomNetworkConn == YES)
  1487. { ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect); }
  1488. else
  1489. { ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect); }
  1490. } else {
  1491. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1492. // 3G/4G
  1493. if (pSysConfig->TelecomInterface.TelcomNetworkConn == YES)
  1494. { ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect); }
  1495. else
  1496. { ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect); }
  1497. }
  1498. } else {
  1499. ChangeDisplay2Value(__3G4G_status, _disappear);
  1500. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1501. }
  1502. // 連線到後台
  1503. if (pSysInfo->OcppConnStatus == YES) {
  1504. ChangeDisplay2Value(__conn_status, _connect);
  1505. } else {
  1506. ChangeDisplay2Value(__conn_status, _disconnect);
  1507. }
  1508. /*if (pSysConfig->AthInterface.WifiNetworkConn == YES ||
  1509. pSysConfig->AthInterface.WifiMode == _SYS_WIFI_MODE_AP) {
  1510. _wifi_conn_status = true;
  1511. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  1512. ChangeDisplay2Value(__ethernet_status, _disappear);
  1513. } else {
  1514. _wifi_conn_status = false;
  1515. ChangeDisplay2Value(__wifi_status, _disappear);
  1516. }
  1517. if (!_wifi_conn_status) {
  1518. if (pSysConfig->TelecomInterface.TelcomNetworkConn == YES ||
  1519. pSysInfo->InternetConn == YES) {
  1520. ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
  1521. } else {
  1522. ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
  1523. }
  1524. }
  1525. // 連線到後台
  1526. if (pSysInfo->OcppConnStatus == YES) {
  1527. ChangeDisplay2Value(__conn_status, _connect);
  1528. } else {
  1529. ChangeDisplay2Value(__conn_status, _disconnect);
  1530. }
  1531. */
  1532. #endif //defined DD360Tcci || defined DD360Audi
  1533. }
  1534. uint8_t FirstPageChanged()
  1535. {
  1536. uint8_t result = NO;
  1537. if (_currentPage != _oldPage) {
  1538. result = YES;
  1539. _oldPage = _currentPage;
  1540. }
  1541. return result;
  1542. }
  1543. bool IsPageReloadChk()
  1544. {
  1545. bool result = false;
  1546. if (pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
  1547. if (_curPage_index != pSysInfo->CurGunSelected) {
  1548. _curPage_index = pSysInfo->CurGunSelected;
  1549. result = true;
  1550. }
  1551. } else {
  1552. if (_curPage_index != pSysInfo->CurGunSelectedByAc) {
  1553. _curPage_index = pSysInfo->CurGunSelectedByAc;
  1554. result = true;
  1555. }
  1556. }
  1557. return result;
  1558. }
  1559. void ClearDisplayInfo()
  1560. {
  1561. ChangeDisplay2Value(__csu_ver_string, _disappear);
  1562. ChangeDisplay2Value(__csu_ver_value, _disappear);
  1563. ChangeDisplay2Value(__eth0_ip_string, _disappear);
  1564. ChangeDisplay2Value(__eth0_ip_value, _disappear);
  1565. ChangeDisplay2Value(__sn_string, _disappear);
  1566. ChangeDisplay2Value(__sn_value, _disappear);
  1567. ChangeDisplay2Value(__dc1_ver_string, _disappear);
  1568. ChangeDisplay2Value(__dc1_ver_value, _disappear);
  1569. ChangeDisplay2Value(__dc2_ver_string, _disappear);
  1570. ChangeDisplay2Value(__dc2_ver_value, _disappear);
  1571. ChangeDisplay2Value(__fan_speed_string, _disappear);
  1572. ChangeDisplay2Value(__fan_speed_value, _disappear);
  1573. }
  1574. void DisplayInfoCsuVer(bool isShow, uint8_t *modelName)
  1575. {
  1576. if (isShow) {
  1577. uint8_t value[10];
  1578. memset(value, 0x00, sizeof(value));
  1579. strcpy((char *)value, "CSU Ver >");
  1580. DisplayValueToLcm(__csu_ver_string, value, sizeof(value));
  1581. memset(value, 0x00, sizeof(value));
  1582. strncpy((char *)value, (char *)modelName, 5);
  1583. DisplayValueToLcm(__csu_ver_value, value, sizeof(value));
  1584. } else {
  1585. ChangeDisplay2Value(__csu_ver_string, _disappear);
  1586. ChangeDisplay2Value(__csu_ver_value, _disappear);
  1587. }
  1588. }
  1589. void ShowWifiMode(bool isShow, uint8_t mode)
  1590. {
  1591. if (isShow) {
  1592. uint8_t value[20];
  1593. memset(value, 0x00, sizeof(value));
  1594. strcpy((char *) value, "Wifi Mo. >");
  1595. DisplayValueToLcm(__csu_ver_string, value, sizeof(value));
  1596. memset(value, 0x00, sizeof(value));
  1597. if (mode == 0) {
  1598. sprintf((char *)value, "disable");
  1599. } else if (mode == 1) {
  1600. sprintf((char *)value, "station");
  1601. } else if (mode == 2) {
  1602. sprintf((char *)value, "AP");
  1603. }
  1604. DisplayValueToLcm(__csu_ver_value, value, sizeof(value));
  1605. } else {
  1606. ChangeDisplay2Value(__csu_ver_string, _disappear);
  1607. ChangeDisplay2Value(__csu_ver_value, _disappear);
  1608. }
  1609. }
  1610. void DisplayInfoEthIp(bool isShow, uint8_t *ip)
  1611. {
  1612. if (isShow) {
  1613. uint8_t value[20];
  1614. memset(value, 0x00, sizeof(value));
  1615. strcpy((char *) value, "Eth IP >");
  1616. DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
  1617. memset(value, 0x00, sizeof(value));
  1618. strcpy((char *) value, (char *) ip);
  1619. DisplayValueToLcm(__eth0_ip_value, value, sizeof(value));
  1620. } else {
  1621. ChangeDisplay2Value(__eth0_ip_string, _disappear);
  1622. ChangeDisplay2Value(__eth0_ip_value, _disappear);
  1623. }
  1624. }
  1625. void Show4GRssi(bool isShow, int dbValue)
  1626. {
  1627. if (isShow) {
  1628. uint8_t value[20];
  1629. memset(value, 0x00, sizeof(value));
  1630. strcpy((char *) value, "RSSI >");
  1631. DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
  1632. memset(value, 0x00, sizeof(value));
  1633. sprintf((char *)value, "%d dBm", dbValue);
  1634. DisplayValueToLcm(__eth0_ip_value, value, sizeof(value));
  1635. } else {
  1636. ChangeDisplay2Value(__eth0_ip_string, _disappear);
  1637. ChangeDisplay2Value(__eth0_ip_value, _disappear);
  1638. }
  1639. }
  1640. void DisplayInfoSN(bool isShow, uint8_t *sn)
  1641. {
  1642. if (isShow) {
  1643. uint8_t value[30];
  1644. memset(value, 0x00, sizeof(value));
  1645. strcpy((char *) value, "SN >");
  1646. DisplayValueToLcm(__sn_string, value, sizeof(value));
  1647. memset(value, 0x00, sizeof(value));
  1648. strcpy((char *) value, (char *) sn);
  1649. DisplayValueToLcm(__sn_value, value, sizeof(value));
  1650. } else {
  1651. ChangeDisplay2Value(__sn_string, _disappear);
  1652. ChangeDisplay2Value(__sn_value, _disappear);
  1653. }
  1654. }
  1655. void ShowWifiRssi(bool isShow, int dbValue)
  1656. {
  1657. if (isShow) {
  1658. uint8_t value[20];
  1659. memset(value, 0x00, sizeof(value));
  1660. strcpy((char *) value, "RSSI >");
  1661. DisplayValueToLcm(__sn_string, value, sizeof(value));
  1662. memset(value, 0x00, sizeof(value));
  1663. sprintf((char *)value, "%d dBm", dbValue);
  1664. DisplayValueToLcm(__sn_value, value, sizeof(value));
  1665. } else {
  1666. ChangeDisplay2Value(__sn_string, _disappear);
  1667. ChangeDisplay2Value(__sn_value, _disappear);
  1668. }
  1669. }
  1670. void DisplayInfoGun1Ver(bool isShow, uint8_t *version)
  1671. {
  1672. if (isShow) {
  1673. uint8_t value[10];
  1674. memset(value, 0x00, sizeof(value));
  1675. strcpy((char *) value, "Ct1 Ver >");
  1676. DisplayValueToLcm(__dc1_ver_string, value, sizeof(value));
  1677. memset(value, 0x00, sizeof(value));
  1678. strcpy((char *) value, (char *) version);
  1679. DisplayValueToLcm(__dc1_ver_value, value, sizeof(value));
  1680. } else {
  1681. ChangeDisplay2Value(__dc1_ver_string, _disappear);
  1682. ChangeDisplay2Value(__dc1_ver_value, _disappear);
  1683. }
  1684. }
  1685. void Show4GMode(bool isShow, uint8_t mode)
  1686. {
  1687. if (isShow) {
  1688. uint8_t value[20];
  1689. memset(value, 0x00, sizeof(value));
  1690. strcpy((char *) value, "3/4G Mo. >");
  1691. DisplayValueToLcm(__dc1_ver_string, value, sizeof(value));
  1692. memset(value, 0x00, sizeof(value));
  1693. if (mode == 0) {
  1694. sprintf((char *)value, "disable");
  1695. } else if (mode == 1) {
  1696. sprintf((char *)value, "enable");
  1697. }
  1698. DisplayValueToLcm(__dc1_ver_value, value, sizeof(value));
  1699. } else {
  1700. ChangeDisplay2Value(__dc1_ver_string, _disappear);
  1701. ChangeDisplay2Value(__dc1_ver_value, _disappear);
  1702. }
  1703. }
  1704. void DisplayInfoGun2Ver(bool isShow, uint8_t *version)
  1705. {
  1706. if (isShow) {
  1707. uint8_t value[10];
  1708. memset(value, 0x00, sizeof(value));
  1709. strcpy((char *) value, "Ct2 Ver >");
  1710. DisplayValueToLcm(__dc2_ver_string, value, sizeof(value));
  1711. memset(value, 0x00, sizeof(value));
  1712. strcpy((char *) value, (char *) version);
  1713. DisplayValueToLcm(__dc2_ver_value, value, sizeof(value));
  1714. } else {
  1715. ChangeDisplay2Value(__dc2_ver_string, _disappear);
  1716. ChangeDisplay2Value(__dc2_ver_value, _disappear);
  1717. }
  1718. }
  1719. void Show4GIP(bool isShow, uint8_t *ip)
  1720. {
  1721. if (isShow) {
  1722. uint8_t value[20];
  1723. memset(value, 0x00, sizeof(value));
  1724. strcpy((char *) value, "3/4G IP >");
  1725. DisplayValueToLcm(__dc2_ver_string, value, sizeof(value));
  1726. memset(value, 0x00, sizeof(value));
  1727. strcpy((char *) value, (char *) ip);
  1728. DisplayValueToLcm(__dc2_ver_value, value, sizeof(value));
  1729. } else {
  1730. ChangeDisplay2Value(__dc2_ver_string, _disappear);
  1731. ChangeDisplay2Value(__dc2_ver_value, _disappear);
  1732. }
  1733. }
  1734. void DisplayInfoSpeed(bool isShow, unsigned int fan)
  1735. {
  1736. if (isShow) {
  1737. uint8_t value[10];
  1738. memset(value, 0x00, sizeof(value));
  1739. strcpy((char *) value, "Fan Spd >");
  1740. DisplayValueToLcm(__fan_speed_string, value, sizeof(value));
  1741. memset(value, 0x00, sizeof(value));
  1742. sprintf((char *)value, "%d", fan);
  1743. DisplayValueToLcm(__fan_speed_value, value, sizeof(value));
  1744. } else {
  1745. ChangeDisplay2Value(__fan_speed_string, _disappear);
  1746. ChangeDisplay2Value(__fan_speed_value, _disappear);
  1747. }
  1748. }
  1749. void ShowWifiIP(bool isShow, uint8_t *ip)
  1750. {
  1751. if (isShow) {
  1752. uint8_t value[20];
  1753. memset(value, 0x00, sizeof(value));
  1754. strcpy((char *) value, "Wifi IP >");
  1755. DisplayValueToLcm(__fan_speed_string, value, sizeof(value));
  1756. memset(value, 0x00, sizeof(value));
  1757. strcpy((char *) value, (char *) ip);
  1758. DisplayValueToLcm(__fan_speed_value, value, sizeof(value));
  1759. } else {
  1760. ChangeDisplay2Value(__fan_speed_string, _disappear);
  1761. ChangeDisplay2Value(__fan_speed_value, _disappear);
  1762. }
  1763. }
  1764. void InformationShow()
  1765. {
  1766. if (pSysConfig->ShowInformation == YES) {
  1767. bool show = _isShow = true;
  1768. if (_showInformIndex == 0) {
  1769. DisplayInfoCsuVer(show, pSysInfo->CsuRootFsFwRev);
  1770. DisplayInfoSpeed(show, pSysInfo->SystemFanRotaSpeed);
  1771. DisplayInfoSN(show, pSysConfig->SerialNumber);
  1772. DisplayInfoEthIp(show, pSysConfig->Eth0Interface.EthIpAddress);
  1773. DisplayInfoGun1Ver(show, pSysInfo->Connector1FwRev);
  1774. if (_totalCount > 1) {
  1775. DisplayInfoGun2Ver(show, pSysInfo->Connector2FwRev);
  1776. } else {
  1777. DisplayInfoGun2Ver(false, pSysInfo->Connector2FwRev);
  1778. }
  1779. } else if (_showInformIndex == 1) {
  1780. ShowWifiMode(show, pSysConfig->AthInterface.WifiMode);
  1781. ShowWifiIP(show, pSysConfig->AthInterface.WifiIpAddress);
  1782. ShowWifiRssi(show, pSysConfig->AthInterface.WifiRssi);
  1783. Show4GMode(show, pSysConfig->TelecomInterface.TelcomEnabled);
  1784. Show4GIP(show, pSysConfig->TelecomInterface.TelcomIpAddress);
  1785. Show4GRssi(show, pSysConfig->TelecomInterface.TelcomRssi);
  1786. }
  1787. } else {
  1788. ClearDisplayInfo();
  1789. if (_isShow) {
  1790. _isShow = false;
  1791. _showInformIndex++;
  1792. if (_showInformIndex >= 2) {
  1793. _showInformIndex = 0;
  1794. }
  1795. }
  1796. }
  1797. }
  1798. void ProcessPageInfo()
  1799. {
  1800. _page_reload = IsPageReloadChk();
  1801. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  1802. struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
  1803. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1804. uint8_t i;
  1805. // 隨插即充 - 可省略該按鈕 //DS60-120 add
  1806. if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
  1807. ChangeDisplay2Value(__ret_home_btn, _back_home_btn);
  1808. if (_totalCount >= 2 && pSysInfo->IsAlternatvieConf == NO) {
  1809. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  1810. } else {
  1811. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  1812. }
  1813. }
  1814. switch (_currentPage) {
  1815. #if defined DD360Audi
  1816. case _LCM_SELECT_GUN: ////For Audi
  1817. if (pSysInfo->CurGunSelected == 0) {
  1818. ChangeDisplay2Value(__left_gun_map, _left_gun_enable_map);
  1819. ChangeDisplay2Value(__right_gun_map, _right_gun_disable_map);
  1820. } else if (pSysInfo->CurGunSelected == 1) {
  1821. ChangeDisplay2Value(__left_gun_map, _left_gun_disable_map);
  1822. ChangeDisplay2Value(__right_gun_map, _right_gun_enable_map);
  1823. }
  1824. ChangeDisplay2Value(__add_chk_btn, _select_gun_btn);
  1825. break;
  1826. #endif //defined DD360Audi
  1827. case _LCM_IDLE: {
  1828. if (pSysConfig->isRFID) {
  1829. ChangeDisplay2Value(__main_rfid, _main_rfid);
  1830. } else {
  1831. ChangeDisplay2Value(__main_rfid, _main_none_rfid);
  1832. }
  1833. if (pSysConfig->isQRCode) {
  1834. ChangeDisplay2Value(__main_qr, _main_qr);
  1835. } else {
  1836. ChangeDisplay2Value(__qr_code, _disappear);
  1837. ChangeDisplay2Value(__main_qr, _main_none_qr);
  1838. needReloadQr = true;
  1839. }
  1840. if (pSysConfig->isAPP) {
  1841. ChangeDisplay2Value(__main_app, _main_app);
  1842. } else {
  1843. ChangeDisplay2Value(__main_app, _main_none_app);
  1844. }
  1845. #if defined DD360Audi
  1846. if(pSysInfo->CurGunSelected == LEFT_GUN_NUM )
  1847. ChangeDisplay2Value(__show_selectgun_value, _showselectgun_left);
  1848. else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM )
  1849. ChangeDisplay2Value(__show_selectgun_value, _showselectgun_right);
  1850. #endif
  1851. //if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
  1852. if (pSysConfig->isQRCode) {
  1853. needReloadQr = false;
  1854. if (pSysConfig->QRCodeMadeMode == NO) {
  1855. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  1856. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1857. } else {
  1858. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  1859. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  1860. }
  1861. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1862. }
  1863. //}
  1864. //DS60-120 add
  1865. bool isCharging = false;
  1866. for (uint8_t i = 0; i < _totalCount; i++) {
  1867. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1868. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  1869. continue;
  1870. }
  1871. isCharging = true;
  1872. break;
  1873. }
  1874. if (isCharging && pSysInfo->IsAlternatvieConf == NO) {
  1875. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  1876. } else {
  1877. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  1878. }
  1879. }
  1880. break;
  1881. case _LCM_AUTHORIZING:
  1882. case _LCM_AUTHORIZ_COMP:
  1883. case _LCM_AUTHORIZ_FAIL: {
  1884. //case _LCM_WAIT_FOR_PLUG: {
  1885. FirstPageChanged();
  1886. #if defined DD360Audi
  1887. if (_currentPage == _LCM_AUTHORIZ_COMP) { ////For Audi
  1888. ChangeBalanceValue(__balance, pSysInfo->CurGunSelected);
  1889. }
  1890. #endif //defined DD360Audi
  1891. }
  1892. break;
  1893. case _LCM_WAIT_FOR_PLUG: {
  1894. #if defined DD360Audi
  1895. if(pSysInfo->CurGunSelected == LEFT_GUN_NUM )
  1896. ChangeDisplay2Value(__show_waitgunplug_value, _showwaitgunplug_left);
  1897. else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM )
  1898. ChangeDisplay2Value(__show_waitgunplug_value, _showwaitgunplug_right);
  1899. #endif
  1900. FirstPageChanged();
  1901. if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  1902. // 新增隨插即充功能預設在等待插槍頁面在開啟
  1903. ChangeDisplay2Value(__ret_home_btn, _disappear);
  1904. bool isCharging = false;
  1905. for (uint8_t i = 0; i < _totalCount; i++) {
  1906. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1907. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  1908. continue;
  1909. }
  1910. isCharging = true;
  1911. break;
  1912. }
  1913. if (isCharging && pSysInfo->IsAlternatvieConf == NO) {
  1914. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  1915. } else {
  1916. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  1917. }
  1918. } else {
  1919. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  1920. }
  1921. }
  1922. break;
  1923. case _LCM_PRE_CHARGE:
  1924. case _LCM_CHARGING:
  1925. case _LCM_COMPLETE: {
  1926. bool isShowAc = false;
  1927. uint8_t gunTargetIndex = 0;
  1928. if (_totalCount >= 2 )
  1929. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  1930. if (acgunCount > 0) {
  1931. gunTargetIndex = 2;
  1932. if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  1933. isShowAc = true;
  1934. //ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_light); //DS60-120 remove
  1935. if (_currentPage == _LCM_COMPLETE) {
  1936. ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _actype_light_cmp);
  1937. } else {
  1938. ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _actype_light);
  1939. }
  1940. if (_currentPage == _LCM_CHARGING) {
  1941. ChangeAcBattMapAndValue(_LCM_CHARGING);
  1942. if (pAcChargingInfo->PresentChargedDuration >= 0 &&
  1943. pAcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  1944. ChangeRemainTime(pAcChargingInfo->PresentChargedDuration);
  1945. } else {
  1946. ChangeRemainTime(0);
  1947. }
  1948. if (pAcChargingInfo->PresentChargingPower >= 0.1 &&
  1949. pAcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1950. ChangeChargingPowerValue(pAcChargingInfo->PresentChargingPower);
  1951. } else {
  1952. ChangeChargingPowerValue(0);
  1953. }
  1954. if (pAcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1955. pAcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1956. ChangeChargingEnergyValue(pAcChargingInfo->PresentChargedEnergy);
  1957. } else {
  1958. ChangeChargingEnergyValue(0);
  1959. }
  1960. if (strcmp((char *)pAcChargingInfo->StartUserId, "") == 0 ||
  1961. pSysConfig->StopChargingByButton == YES) {
  1962. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
  1963. } else {
  1964. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
  1965. }
  1966. } else if (_currentPage == _LCM_COMPLETE) {
  1967. ChangeAcBattMapAndValue(_LCM_COMPLETE);
  1968. if (pAcChargingInfo->PresentChargedDuration >= 0 &&
  1969. pAcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  1970. ChangeRemainTime(pAcChargingInfo->PresentChargedDuration);
  1971. } else {
  1972. ChangeRemainTime(0);
  1973. }
  1974. if (pAcChargingInfo->PresentChargingPower >= 0.1 &&
  1975. pAcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1976. ChangeChargingPowerValue(pAcChargingInfo->PresentChargingPower);
  1977. } else {
  1978. ChangeChargingPowerValue(0);
  1979. }
  1980. if (pAcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1981. pAcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1982. ChangeChargingEnergyValue(pAcChargingInfo->PresentChargedEnergy);
  1983. if (pSysConfig->BillingData.isBilling &&
  1984. pAcChargingInfo->ChargingFee >= 0) {
  1985. ChangeChargingFeeValue(pAcChargingInfo->ChargingFee);
  1986. }
  1987. } else {
  1988. ChangeChargingEnergyValue(0);
  1989. if (pSysConfig->BillingData.isBilling) {
  1990. ChangeChargingFeeValue(0);
  1991. }
  1992. }
  1993. if (!pSysConfig->BillingData.isBilling) {
  1994. ChangeDisplay2Value(__charging_fee_map, _disappear);
  1995. ChangeDisplay2Value(__charging_fee_tx, _disappear);
  1996. } else {
  1997. ChangeDisplay2Value(__charging_fee_map, _money_map);
  1998. }
  1999. }
  2000. } else {
  2001. //ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_dark); //DS60-120 remove
  2002. if (_currentPage == _LCM_COMPLETE) {
  2003. ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _actype_dark_cmp);
  2004. } else {
  2005. ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _actype_dark);
  2006. }
  2007. }
  2008. } else {
  2009. //ChangeDisplay2Value(__gun_type_index + (2 * 2), _disappear); //DS60-120 remove
  2010. if (_totalCount > 1) {
  2011. gunTargetIndex = 2;
  2012. ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _disappear);
  2013. ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _disappear);
  2014. }
  2015. }
  2016. gunTargetIndex = 0; //DS60-120 add
  2017. for (uint8_t i = 0; i < _totalCount; i++) {
  2018. if (_totalCount == 1 && acgunCount <= 0) { //DS60-120 add
  2019. gunTargetIndex = 2;
  2020. } else {
  2021. gunTargetIndex = i;
  2022. }
  2023. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  2024. switch (pDcChargingInfo->Type) {
  2025. case _Type_Chademo: {
  2026. if (pSysInfo->CurGunSelected == i && !isShowAc) {
  2027. if (_currentPage == _LCM_COMPLETE) {
  2028. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_light_cmp);
  2029. } else {
  2030. ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
  2031. }
  2032. } else {
  2033. if (_currentPage == _LCM_COMPLETE) {
  2034. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_dark_cmp);
  2035. } else {
  2036. ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
  2037. }
  2038. }
  2039. }
  2040. break;
  2041. case _Type_GB: {
  2042. if (pSysInfo->CurGunSelected == i && !isShowAc) {
  2043. if (_currentPage == _LCM_COMPLETE) {
  2044. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_light_cmp);
  2045. } else {
  2046. ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_light);
  2047. }
  2048. } else {
  2049. if (_currentPage == _LCM_COMPLETE) {
  2050. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_dark_cmp);
  2051. } else {
  2052. ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_dark);
  2053. }
  2054. }
  2055. }
  2056. break;
  2057. case _Type_CCS_2: {
  2058. if (pSysInfo->CurGunSelected == i && !isShowAc) {
  2059. if (_currentPage == _LCM_COMPLETE) {
  2060. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_light_cmp);
  2061. } else {
  2062. ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
  2063. }
  2064. } else {
  2065. if (_currentPage == _LCM_COMPLETE) {
  2066. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_dark_cmp);
  2067. } else {
  2068. ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
  2069. }
  2070. }
  2071. }
  2072. break;
  2073. }
  2074. if (_currentPage == _LCM_PRE_CHARGE && !isShowAc) {
  2075. if (pSysInfo->CurGunSelected == i) {
  2076. ChangeBattMapAndValue(_currentPage, pDcChargingInfo->EvBatterySoc);
  2077. uint8_t precharg_time = (GetPreChargeTimeoutValue(pDcChargingInfo->PreChargeTimer)/1) / uSEC_VAL;
  2078. if (precharg_time > PRECHARGING_TTIMEOUT)
  2079. precharg_time = PRECHARGING_TTIMEOUT;
  2080. ChangeTimeValue(PRECHARGING_TTIMEOUT- precharg_time);
  2081. if (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  2082. pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EV) {
  2083. ChangeDisplay2Value(__show_handshark_value, _show_handshark_light);
  2084. ChangeDisplay2Value(__show_GFD_value, _show_GFD_dark);
  2085. ChangeDisplay2Value(__show_precharge_value, _show_precharge_dark);
  2086. } else if (pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) {
  2087. // Detect GFD finish and into precharge mode
  2088. if (pDcChargingInfo->Type == _Type_Chademo || pDcChargingInfo->Type == _Type_GB) {
  2089. if (pDcChargingInfo->_SaftyDetect == false ) {
  2090. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  2091. ChangeDisplay2Value(__show_GFD_value, _show_GFD_light);
  2092. ChangeDisplay2Value(__show_precharge_value, _show_precharge_dark);
  2093. if (pDcChargingInfo->EvBatterytargetVoltage == 0)
  2094. pDcChargingInfo->_SaftyDetect = true;
  2095. } else {
  2096. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  2097. ChangeDisplay2Value(__show_GFD_value, _show_GFD_dark);
  2098. ChangeDisplay2Value(__show_precharge_value, _show_precharge_light);
  2099. }
  2100. } else {
  2101. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  2102. ChangeDisplay2Value(__show_GFD_value, _show_GFD_light);
  2103. ChangeDisplay2Value(__show_precharge_value, _show_precharge_dark);
  2104. }
  2105. } else if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
  2106. pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
  2107. if (pDcChargingInfo->_SaftyDetect == false ) {
  2108. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  2109. ChangeDisplay2Value(__show_GFD_value, _show_GFD_light);
  2110. ChangeDisplay2Value(__show_precharge_value, _show_precharge_dark);
  2111. if (pDcChargingInfo->EvBatterytargetVoltage == 0)
  2112. pDcChargingInfo->_SaftyDetect = true;
  2113. } else {
  2114. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  2115. ChangeDisplay2Value(__show_GFD_value, _show_GFD_dark);
  2116. ChangeDisplay2Value(__show_precharge_value, _show_precharge_light);
  2117. }
  2118. } else {
  2119. ChangeDisplay2Value(__show_handshark_value, _disappear);
  2120. ChangeDisplay2Value(__show_GFD_value, _disappear);
  2121. ChangeDisplay2Value(__show_precharge_value, _disappear);
  2122. }
  2123. }
  2124. } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
  2125. if (pSysInfo->CurGunSelected == i) {
  2126. ChangeBattMapAndValue(_LCM_CHARGING, pDcChargingInfo->EvBatterySoc);
  2127. if (pDcChargingInfo->PresentChargedDuration >= 0 &&
  2128. pDcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  2129. ChangeRemainTime(pDcChargingInfo->PresentChargedDuration);
  2130. } else {
  2131. ChangeRemainTime(0);
  2132. }
  2133. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  2134. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  2135. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  2136. } else {
  2137. ChangeChargingPowerValue(0);
  2138. }
  2139. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  2140. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  2141. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  2142. } else {
  2143. ChangeChargingEnergyValue(0);
  2144. }
  2145. if (strcmp((char *)pDcChargingInfo->StartUserId, "") == 0 ||
  2146. pSysConfig->StopChargingByButton == YES) {
  2147. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
  2148. } else {
  2149. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
  2150. }
  2151. }
  2152. } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
  2153. if (pSysInfo->CurGunSelected == i) {
  2154. ChangeBattMapAndValue(_LCM_COMPLETE, pDcChargingInfo->EvBatterySoc);
  2155. if (pDcChargingInfo->PresentChargedDuration >= 0 &&
  2156. pDcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  2157. ChangeRemainTime(pDcChargingInfo->PresentChargedDuration);
  2158. } else {
  2159. ChangeRemainTime(0);
  2160. }
  2161. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  2162. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  2163. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  2164. } else {
  2165. ChangeChargingPowerValue(0);
  2166. }
  2167. #if 1
  2168. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  2169. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  2170. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  2171. if (pSysConfig->BillingData.isBilling &&
  2172. pDcChargingInfo->ChargingFee >= 0) {
  2173. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  2174. ChangeBalanceValue(__remain_balance, i);
  2175. }
  2176. } else {
  2177. ChangeChargingEnergyValue(0);
  2178. if (pSysConfig->BillingData.isBilling) {
  2179. ChangeChargingFeeValue(0);
  2180. ChangeBalanceValue(__remain_balance, i);
  2181. }
  2182. }
  2183. #else
  2184. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  2185. if (pSysConfig->BillingData.isBilling &&
  2186. pDcChargingInfo->ChargingFee >= 0) {
  2187. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  2188. ChangeBalanceValue(__remain_balance, i);
  2189. }
  2190. #endif // 0
  2191. if (!pSysConfig->BillingData.isBilling) {
  2192. ChangeDisplay2Value(__charging_fee_map, _disappear);
  2193. ChangeDisplay2Value(__charging_fee_tx, _disappear);
  2194. } else {
  2195. ChangeDisplay2Value(__charging_fee_map, _money_map);
  2196. }
  2197. #ifdef DD360Audi
  2198. // Warming Occur in prepare or precharing state, turn into complete mode
  2199. if (pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason) {
  2200. RunFullTargetFunction(true);
  2201. } else {
  2202. RunFullTargetFunction(false);
  2203. if (pDcChargingInfo->Replug_flag) {
  2204. RunReplugStringFunction(true);
  2205. } else {
  2206. RunReplugStringFunction(false);
  2207. }
  2208. }
  2209. #endif
  2210. }
  2211. }
  2212. }
  2213. // gun btn and QR code
  2214. if (_totalCount + acgunCount >= 2 && _currentPage) {
  2215. uint8_t index = 0;
  2216. for (index = 0; index < _totalCount; index++) {
  2217. if (pSysInfo->CurGunSelected != index) {
  2218. break;
  2219. }
  2220. }
  2221. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  2222. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2223. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  2224. pDcChargingInfo->SystemStatus == S_BOOTING) {
  2225. if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
  2226. if (pSysConfig->isQRCode) {
  2227. needReloadQr = false;
  2228. //ChangeQrCode_Charge((char *)pSysConfig->SystemId); //DS60-120 remove
  2229. if (pSysConfig->QRCodeMadeMode == NO) {
  2230. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  2231. ChangeQrCode_Charge((char *)pSysConfig->SystemId);
  2232. } else {
  2233. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  2234. ChangeQrCode_Charge((char *)pSysConfig->QRCodeContent);
  2235. }
  2236. }
  2237. }
  2238. }
  2239. }
  2240. }
  2241. break;
  2242. case _LCM_FIX:
  2243. #if defined DD360Audi
  2244. // For Emergency Button
  2245. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == 1) {
  2246. ChangeToOtherPage(_LCM_EMERGENCY);
  2247. break;
  2248. }
  2249. // For Network Disconnect
  2250. for (i = 0; i < pSysWarning->WarningCount; i++) {
  2251. if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0 ||
  2252. memcmp(&pSysWarning->WarningCode[i][0], "042304", 6) == 0) {
  2253. ChangeToOtherPage(_LCM_DISCONNECT);
  2254. break;
  2255. }
  2256. }
  2257. #endif
  2258. break;
  2259. }
  2260. }
  2261. void ChangeDisplayMoneyInfo()
  2262. {
  2263. uint8_t curGun = pSysInfo->CurGunSelected;
  2264. if (pSysConfig->BillingData.isBilling) {
  2265. struct timeb csuTime;
  2266. struct tm *tmCSU;
  2267. ftime(&csuTime);
  2268. tmCSU = localtime(&csuTime.time);
  2269. ChangeDisplay2Value(__money_rate_map, _charging_money);
  2270. #if defined DD360Audi
  2271. if (ShmSelectGunInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
  2272. DisplayMoneyRate(ShmSelectGunInfo->PricesInfo[curGun].UserPrices);
  2273. } else {
  2274. #endif //defined DD360Audi
  2275. if (tmCSU->tm_hour <= 23) {
  2276. pSysConfig->BillingData.Cur_fee = pSysConfig->BillingData.Fee[tmCSU->tm_hour];
  2277. DisplayMoneyRate(pSysConfig->BillingData.Cur_fee);
  2278. }
  2279. if (pSysConfig->BillingData.Currency <= 53) {
  2280. DisplayMoneyCur((uint8_t *)GetCurrency(pSysConfig->BillingData.Currency));
  2281. }
  2282. #if defined DD360Audi
  2283. }
  2284. #endif //defined DD360Audi
  2285. } else {
  2286. ChangeDisplay2Value(__money_rate_map, _disappear);
  2287. ChangeDisplay2Value(__money_by_rate, _disappear);
  2288. ChangeDisplay2Value(__money_rate, _disappear);
  2289. }
  2290. }
  2291. /*void Initialization()
  2292. {
  2293. bool isPass = false;
  2294. uint8_t count = 5;
  2295. while (!isPass && count > 0) {
  2296. isPass = true;
  2297. for (uint8_t _index = 0; _index < _totalCount; _index++) {
  2298. if (!FindChargingInfoData(_index, &_chargingInfoData[0])) {
  2299. log_error("LcmComm (main) : FindChargingInfoData false ");
  2300. isPass = false;
  2301. count--;
  2302. break;
  2303. }
  2304. }
  2305. sleep(1);
  2306. }
  2307. isPass = false;
  2308. if (acgunCount > 0) {
  2309. while (!isPass) {
  2310. isPass = true;
  2311. for (uint8_t _index = 0; _index < acgunCount; _index++) {
  2312. if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
  2313. log_error("LcmComm : FindAcChargingInfoData false ");
  2314. isPass = false;
  2315. break;
  2316. }
  2317. }
  2318. sleep(1);
  2319. }
  2320. }
  2321. if (count == 0) {
  2322. log_info("LCM Initialization Gun Fail.............");
  2323. }
  2324. }
  2325. */
  2326. //DS60-120 add
  2327. void DefaultIconStatus()
  2328. {
  2329. for (uint8_t i = 0; i < 3; i++) {
  2330. ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
  2331. }
  2332. if (pSysInfo->IsAlternatvieConf == YES || _totalCount == 1) {
  2333. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  2334. } else {
  2335. log_info("DefaultIconStatus");
  2336. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  2337. }
  2338. }
  2339. void GetDeviceInfoStatus(short address, uint8_t len)
  2340. {
  2341. uint8_t cmd[8];
  2342. memset(cmd, 0x00, sizeof(cmd));
  2343. uint8_t msg[11];
  2344. memset(msg, 0x00, sizeof(msg));
  2345. cmd[0] = CMD_TITLE_1;
  2346. cmd[1] = CMD_TITLE_2;
  2347. cmd[2] = 0x04;
  2348. cmd[3] = CMD_MULTI_READ;
  2349. cmd[4] = (address >> 8) & 0xff;
  2350. cmd[5] = (address >> 0) & 0xff;
  2351. cmd[6] = len;
  2352. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  2353. usleep(10000);
  2354. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  2355. }
  2356. int8_t lcdRegisterWrite(int32_t fd, uint8_t regType, uint16_t address, uint8_t *data, uint16_t dataLen)
  2357. {
  2358. int8_t result = FAIL;
  2359. uint8_t tx[(regType == REG_TYPE_CONTROL? 8 : 6) + dataLen];
  2360. uint8_t rx[6];
  2361. memset(tx, 0x00, sizeof(tx));
  2362. memset(rx, 0x00, sizeof(rx));
  2363. tx[0] = CMD_HEADER_1;
  2364. tx[1] = CMD_HEADER_2;
  2365. tx[2] = (regType == REG_TYPE_CONTROL? 7 : (3 + dataLen));
  2366. tx[3] = CMD_REG_WRITE_DATA;
  2367. tx[4] = (address >> 8) & 0xff;
  2368. tx[5] = (address >> 0) & 0xff;
  2369. if(regType == REG_TYPE_CONTROL)
  2370. {
  2371. if(address == REG_ADDRESS_SET_PAGE_ID)
  2372. {
  2373. tx[6] = 0x5A;
  2374. tx[7] = 0x01;
  2375. memcpy(&tx[8], data, dataLen);
  2376. }
  2377. }
  2378. else
  2379. {
  2380. memcpy(&tx[6], data, dataLen);
  2381. }
  2382. if(fd > 0)
  2383. {
  2384. if(transceiverDgus(fd, tx, ARRAY_SIZE(tx), rx, ARRAY_SIZE(rx)) == PASS)
  2385. {
  2386. result = PASS;
  2387. }
  2388. else
  2389. {}
  2390. }
  2391. else
  2392. {}
  2393. return result;
  2394. }
  2395. void ResetLCM()
  2396. {
  2397. uint8_t cmd_reset [] = { 0x55, 0xaa, 0x5a, 0xa5 };
  2398. while (lcdRegisterWrite ( _port, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE( cmd_reset ) ) != PASS)
  2399. {
  2400. log_error( "LCD reset fail.\n" );
  2401. }
  2402. sleep ( 1 );
  2403. }
  2404. //=======================================
  2405. // LCD upgrade
  2406. //=======================================
  2407. int downloadBMP(uint8_t picIdx, char *filename)
  2408. {
  2409. int result = PASS;
  2410. BMP *bmp;
  2411. struct stat fileSt;
  2412. uint32_t pageSize = 0xf0;
  2413. uint32_t pixelSize;
  2414. uint32_t transferedByte=0;
  2415. uint16_t bufferRamAddr = 0x8000;
  2416. uint32_t dataLen = 0;
  2417. uint32_t startAddr=0;
  2418. // Reset LCD
  2419. ResetLCM();
  2420. // Get image file size
  2421. stat(filename, &fileSt);
  2422. bmp = bopen(filename);
  2423. uint8_t buf[bmp->width*bmp->height*2];
  2424. log_info("Target address: %d\n", picIdx);
  2425. log_info("Image filename: %s\n", filename);
  2426. log_info("Image width: %d height: %d\n", bmp->width, bmp->height);
  2427. log_info("Image data size: %d\n", ARRAY_SIZE(buf));
  2428. // Get bmp pixel data and convert to 16 bit color
  2429. for(uint16_t idxY=0 ; idxY<bmp->height ; idxY++)
  2430. {
  2431. for(uint16_t idxX=0 ; idxX<bmp->width ; idxX++)
  2432. {
  2433. uint8_t r, g, b;
  2434. get_pixel_rgb(bmp, idxX, (bmp->height-idxY-1), &r, &g, &b);
  2435. buf[(2*((idxY*bmp->width) + idxX)) + 0] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 8) & 0xff;
  2436. buf[(2*((idxY*bmp->width) + idxX)) + 1] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 0) & 0xff;
  2437. }
  2438. }
  2439. bclose(bmp);
  2440. // Transfer pixel to screen page
  2441. pixelSize = ARRAY_SIZE(buf);
  2442. for(uint16_t idxSrcData=0;idxSrcData<(((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1);idxSrcData++)
  2443. {
  2444. //log_info("Buffer start data address: 0x%08X\n", (idxSrcData*pageSize));
  2445. //log_info(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
  2446. uint8_t display_cmd[] ={0x5a, (bufferRamAddr>>8)&0xff, (bufferRamAddr>>0)&0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
  2447. if((idxSrcData+1) != (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1))
  2448. {
  2449. // Data transfer
  2450. while(lcdRegisterWrite(_port, REG_TYPE_RAM, (bufferRamAddr+(dataLen>>1)), &buf[(idxSrcData*pageSize)], pageSize) != PASS)
  2451. {
  2452. log_info("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2453. }
  2454. transferedByte += pageSize;
  2455. dataLen += pageSize;
  2456. }
  2457. else
  2458. {
  2459. // Last data transfer
  2460. while(lcdRegisterWrite(_port, REG_TYPE_RAM, (bufferRamAddr+(dataLen>>1)), &buf[(idxSrcData*pageSize)], (pixelSize-(idxSrcData*pageSize))) != PASS)
  2461. {
  2462. log_info("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2463. }
  2464. transferedByte += (pixelSize-(idxSrcData*pageSize));
  2465. dataLen += (pixelSize-(idxSrcData*pageSize));
  2466. }
  2467. // Move data from ram to flash
  2468. if((dataLen >= (pageSize*10)) || (idxSrcData == (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1)-1))
  2469. {
  2470. display_cmd[3] = ((dataLen>>1) >> 8) & 0xff; // Data length high byte
  2471. display_cmd[4] = ((dataLen>>1) >> 0) & 0xff; // Data length low byte
  2472. display_cmd[5] = (((startAddr)>>1) >> 16) & 0xff; // Screen on ram address 1st byte
  2473. display_cmd[6] = (((startAddr)>>1) >> 8) & 0xff; // Screen on ram address 2nd byte
  2474. display_cmd[7] = (((startAddr)>>1) >> 0) & 0xff; // Screen on ram address 3th byte
  2475. while(lcdRegisterWrite(_port, REG_TYPE_RAM, 0xa2, display_cmd, ARRAY_SIZE(display_cmd)) != PASS)
  2476. {
  2477. log_info("Write data to display buffer 0x%04X fail.\n", transferedByte);
  2478. }
  2479. startAddr += dataLen;
  2480. dataLen = 0;
  2481. }
  2482. }
  2483. // Save image to target address
  2484. uint8_t save_cmd[] ={0x5a, 0x02, ((picIdx>>8)&0xff), (picIdx&0xff)};
  2485. while(lcdRegisterWrite(_port, REG_TYPE_RAM, 0x84, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
  2486. {
  2487. log_info("Save image fail.\n");
  2488. }
  2489. log_info("Save image success.\n");
  2490. sleep(1);
  2491. return result;
  2492. }
  2493. int downloadBIN(uint8_t targetAddr, char *filename)
  2494. {
  2495. int result = PASS;
  2496. int fd;
  2497. struct stat fileSt;
  2498. uint32_t pageSize = 128;
  2499. uint32_t blocklSize = 32768;
  2500. uint32_t transferedByte=0;
  2501. uint16_t bufferRamAddr = 0x8000;
  2502. // Reset LCD
  2503. ResetLCM();
  2504. // Get image file size
  2505. stat(filename, &fileSt);
  2506. if(S_ISDIR(fileSt.st_mode))
  2507. {
  2508. return FAIL;
  2509. }
  2510. uint8_t buf[(fileSt.st_size%32768==0?(fileSt.st_size/32768)*32768:(fileSt.st_size/32768)+1)*32768];
  2511. log_info("Target address: %d\n", targetAddr);
  2512. log_info("Bin filename: %s\n", filename);
  2513. log_info("Bin data size: %ld\n", fileSt.st_size);
  2514. fd = open(filename, O_RDWR);
  2515. if (fd < 0)
  2516. {
  2517. log_info("Bin can not be open.\n");
  2518. result = FAIL;
  2519. }
  2520. else
  2521. {
  2522. // Read data from bin file
  2523. memset(buf, 0x00, ARRAY_SIZE(buf));
  2524. read(fd, buf, ARRAY_SIZE(buf));
  2525. close(fd);
  2526. for(uint8_t idxBinSrc=0;idxBinSrc<(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1);idxBinSrc++)
  2527. {
  2528. // Transfer data to ram
  2529. for(uint16_t idxSrcData=0;idxSrcData<(((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1);idxSrcData++)
  2530. {
  2531. //log_info("Buffer start data address: 0x%08X\n", (idxBinSrc*blocklSize)+(idxSrcData*pageSize));
  2532. //log_info(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
  2533. if((idxSrcData+1) != (((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1))
  2534. {
  2535. // Data transfer
  2536. while(lcdRegisterWrite(_port, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], pageSize) != PASS)
  2537. {
  2538. log_info("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2539. }
  2540. transferedByte += pageSize;
  2541. }
  2542. else
  2543. {
  2544. // Last data transfer
  2545. while(lcdRegisterWrite(_port, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], (blocklSize-(idxSrcData*pageSize)))!= PASS)
  2546. {
  2547. log_info("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2548. }
  2549. transferedByte += (blocklSize-(idxSrcData*pageSize));
  2550. }
  2551. }
  2552. // Move data from ram to flash
  2553. uint8_t save_cmd[] ={0x5a, 0x02, ((((targetAddr*8)+idxBinSrc)>>8)&0xff), ((((targetAddr*8)+idxBinSrc)>>0)&0xff), ((bufferRamAddr>>8)&0xff), ((bufferRamAddr>>0)&0xff), 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
  2554. while(lcdRegisterWrite(_port, REG_TYPE_RAM, 0xaa, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
  2555. {
  2556. log_info("Save bin file to 0x%04X fail.\n", ((targetAddr*8)+idxBinSrc));
  2557. }
  2558. //log_info("Save bin file on 0x%04X success.\n", ((targetAddr*8)+idxBinSrc));
  2559. sleep(1);
  2560. }
  2561. }
  2562. return result;
  2563. }
  2564. uint8_t lcdUpgrade(char *forlder)
  2565. {
  2566. int result = _LCM_UPGRADE_RESULT_PASS;
  2567. DIR *dir;
  2568. struct dirent *file;
  2569. struct stat fileSt;
  2570. log_info("forlder = %s \n", forlder);
  2571. if ((dir = opendir (forlder)) != NULL)
  2572. {
  2573. /* print all the files and directories within directory */
  2574. while ((file = readdir (dir)) != NULL)
  2575. {
  2576. //log_error("file->d_name = %s \n", file->d_name);
  2577. if((strlen(file->d_name) > 2) && (file->d_type == DT_REG))
  2578. {
  2579. int targetAddr;
  2580. stat(file->d_name, &fileSt);
  2581. if(sscanf(file->d_name, "%d", &targetAddr) == 1)
  2582. {
  2583. char targetFile[384];
  2584. sprintf(targetFile, "/mnt/lcd/DWIN_SET/%s", file->d_name);
  2585. log_info("targetFile = %s \n", targetFile);
  2586. if(strstr(file->d_name, ".bmp") != NULL)
  2587. {
  2588. downloadBMP(targetAddr, targetFile);
  2589. }
  2590. else
  2591. {
  2592. downloadBIN(targetAddr, targetFile);
  2593. }
  2594. }
  2595. else
  2596. {
  2597. log_error("%s can not parse target address.\n", file->d_name);
  2598. }
  2599. }
  2600. else
  2601. {
  2602. if(strlen(file->d_name) >= 3)
  2603. {
  2604. log_error("File name error.\n");
  2605. result = _LCM_UPGRADE_RESULT_FAIL;
  2606. }
  2607. else
  2608. {
  2609. log_error("Searching file.\n");
  2610. }
  2611. }
  2612. sleep(1);
  2613. }
  2614. closedir (dir);
  2615. }
  2616. else
  2617. {
  2618. log_error("%s does not valid.\n", forlder);
  2619. result = _LCM_UPGRADE_RESULT_FAIL;
  2620. }
  2621. return result;
  2622. }
  2623. void UpdateLcmFunction()
  2624. {
  2625. if(ShmDcCommonData->_upgrade_lcm_flag)
  2626. {
  2627. // 固定路徑 /mnt/lcd/DWIN_SET
  2628. ShmDcCommonData->_upgrade_lcm_result = lcdUpgrade("/mnt/lcd/DWIN_SET");
  2629. ResetLCM();
  2630. ShmDcCommonData->_upgrade_lcm_flag = NO;
  2631. }
  2632. }
  2633. int main(void)
  2634. {
  2635. //if (InitShareMemory() == FAIL) {
  2636. // log_error("InitShareMemory NG");
  2637. //
  2638. // if (ShmStatusCodeData != NULL) {
  2639. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  2640. // }
  2641. // sleep(5);
  2642. // return 0;
  2643. //}
  2644. if (CreateAllCsuShareMemory() == FAIL) {
  2645. log_error("create share memory error");
  2646. return FAIL;
  2647. }
  2648. MappingGunChargingInfo("LCM Control Task");
  2649. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  2650. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  2651. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  2652. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  2653. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  2654. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  2655. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  2656. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  2657. _port = CreateCommunicationLcmPort();
  2658. uint8_t changeWarningPriority = 0;
  2659. uint8_t curWarningCount = 255;
  2660. ChangeBackLight(true);
  2661. _totalCount = pSysConfig->TotalConnectorCount;
  2662. acgunCount = pSysConfig->AcConnectorCount;
  2663. //Initialization();
  2664. //printf("_LCM_COMPLETE ");
  2665. //ChangeToOtherPage(_LCM_COMPLETE);
  2666. //return 0;
  2667. for (uint8_t i = 0; i < 3; i++) {
  2668. ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
  2669. }
  2670. DefaultIconStatus(); //DS60-120 add
  2671. uint8_t _verShowCount = 5;
  2672. while (_port != -1) {
  2673. UpdateLcmFunction();
  2674. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  2675. GetDeviceInfoStatus(__lcm_version, 3);
  2676. GetCurrentPage();
  2677. sleep(1);
  2678. if (_verShowCount > 0)
  2679. {
  2680. //PRINTF_FUNC("LCM Version = V.%03d \n", ShmDcCommonData->LcmFwVersion);
  2681. _verShowCount--;
  2682. }
  2683. #ifndef DD360ComBox
  2684. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  2685. #endif
  2686. } else {
  2687. //DemoFunction();
  2688. #ifndef DD360ComBox
  2689. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  2690. #endif
  2691. // Warning 處理
  2692. if (curWarningCount != pSysWarning->WarningCount) {
  2693. log_info("Print Warming Code %d",curWarningCount);
  2694. changeWarningPriority = 0;
  2695. pSysWarning->PageIndex = 0;
  2696. curWarningCount = pSysWarning->WarningCount;
  2697. ChangeWarningFunc();
  2698. } else if (pSysWarning->WarningCount > 5 && changeWarningPriority == 0) {
  2699. // 當有兩頁 Warning 則每隔三秒改變一次
  2700. if (pSysWarning->PageIndex == 0) {
  2701. pSysWarning->PageIndex = 1;
  2702. } else {
  2703. pSysWarning->PageIndex = 0;
  2704. }
  2705. ChangeWarningFunc();
  2706. }
  2707. // 頁面資訊處理
  2708. ProcessPageInfo();
  2709. // 網路 - wifi - 連線訊號處理
  2710. RefreshConnStatus();
  2711. // 換頁處理
  2712. GetCurrentPage(); //DS60-120 add
  2713. ChangeCurPage();
  2714. RefreshPageAnimation(_everyPageRollChange);
  2715. #if defined DD360Audi
  2716. ChangeDisplayMoneyInfo();
  2717. #else
  2718. if (changeWarningPriority == 0) { ////For Audi
  2719. ChangeDisplayMoneyInfo();
  2720. InformationShow();
  2721. }
  2722. #endif //defined DD360Audi
  2723. changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
  2724. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  2725. usleep(100000);
  2726. }
  2727. }
  2728. #ifndef DD360ComBox
  2729. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  2730. #endif
  2731. log_info("Close LCM Uart Port");
  2732. CloseCommunicationLcmPort();
  2733. return FAIL;
  2734. }