Module_LcmControl.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523
  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/ioctl.h>
  10. #include <sys/timeb.h>
  11. #include "Module_LcmControl.h"
  12. #include "../Log/log.h"
  13. #include "../ShareMemory/shmMem.h"
  14. #include "../Define/define.h"
  15. #include "../Config.h"
  16. #include "../SelectGun/SelectGun.h"
  17. #include "../CSU/main.h"
  18. //------------------------------------------------------------------------------
  19. //struct SysConfigAndInfo *ShmSysConfigAndInfo;
  20. //struct StatusCodeData *ShmStatusCodeData;
  21. static struct SysConfigData *pSysConfig = NULL;
  22. static struct SysInfoData *pSysInfo = NULL;
  23. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  24. static struct FanModuleData *ShmFanModuleData;
  25. static struct PrimaryMcuData *ShmPrimaryMcuData;
  26. static SelectGunInfo *ShmSelectGunInfo = NULL;
  27. static struct ChargingInfoData *pDcChargingInfo = NULL;
  28. static struct ChargingInfoData *pAcChargingInfo = NULL;
  29. static DcCommonInfo *ShmDcCommonData = NULL;
  30. bool needReloadQr = true;
  31. bool _saftydetect = false;
  32. bool _isShow = false; //DS60-120 add
  33. uint8_t _showInformIndex = 0; //DS60-120 add
  34. int _port;
  35. //char* pPortName = "/dev/ttyO2";
  36. char *pPortName = "/dev/ttyS3";
  37. char *moduleName = "DMT80480T070_09WT";
  38. uint8_t _totalCount;
  39. uint8_t acgunCount;
  40. //struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  41. //struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  42. uint8_t ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
  43. uint8_t isDiffStatus = false;
  44. uint8_t isChangeBattMap = false;
  45. // 當前選擇的槍號
  46. #if defined DD360Audi
  47. short _currentPage = _LCM_SELECT_GUN;
  48. short _oldPage = _LCM_SELECT_GUN;
  49. #else
  50. short _currentPage = _LCM_NONE;
  51. short _oldPage = _LCM_NONE;
  52. #endif //defined DD360Audi
  53. uint8_t _gunIndex = 0;
  54. bool _wifi_conn_status = false;
  55. bool _battery_display_ani = false;
  56. uint8_t _curPage_index = 0;
  57. bool _page_reload = false;
  58. // LCM - HW
  59. uint8_t _everyPageRollChange = 0;
  60. short __logo = 0x0000;
  61. short __conn_status = 0x0030;
  62. short __ethernet_status = 0x0032;
  63. short __3G4G_status = 0x0036;
  64. short __3G4G_status1 = 0x0037;
  65. short __3G4G_move_status = 0x0038;
  66. short __wifi_status = 0x003C;
  67. short __sel_gun_btn = 0x0040;
  68. short __ret_home_btn = 0x0042;
  69. short __stop_method_btn = 0x0044;
  70. short __lcm_version = 0x004A;
  71. short __qr_code = 0x0250;
  72. short __main_rfid = 0x0052;
  73. short __main_qr = 0x0054;
  74. short __main_app = 0x0056;
  75. short __plug_in_arrow = 0x0060;
  76. short __conn_line = 0x0066;
  77. short __gun_type_index = 0x0070;
  78. short __cmp_gun_type_index = 0x0080; ////For Audi
  79. short __batt_map_empty = 0x0090; ////For Audi
  80. short __qr_code_pre = 0x0280;
  81. short __side_top = 0x0090;
  82. short __side_down = 0x0092;
  83. short __side_mid = 0x0094;
  84. short __conn_line_chag = 0x0096;
  85. short __batt_map = 0x0100;
  86. short __soc_value_charging = 0x0102;
  87. short __remain_time_map = 0x0106;
  88. short __power_map = 0x0108;
  89. short __energy_map = 0x010A;
  90. short __remain_time_tx = 0x0110;
  91. short __trp_remain_time_map = 0x0116;
  92. short __trp_power_map = 0x0118;
  93. short __trp_energy_map = 0x011A;
  94. short __output_eng_tx = 0x0120;
  95. short __total_out_eng_tx = 0x0130;
  96. short __conn_line_comp = 0x0140;
  97. short __charging_fee_map = 0x0146;
  98. short __charging_fee_tx = 0x0150;
  99. short __money_by_rate = 0x0200;
  100. short __money_rate = 0x0220;
  101. short __money_rate_map = 0x0230;
  102. //DS60-120 add
  103. short __csu_ver_string = 0x0300;
  104. short __csu_ver_value = 0x0310;
  105. short __fan_speed_string = 0x0390;
  106. short __fan_speed_value = 0x0400;
  107. short __dc1_ver_string = 0x0320;
  108. short __dc1_ver_value = 0x0330;
  109. short __dc2_ver_string = 0x0340;
  110. short __dc2_ver_value = 0x0350;
  111. short __eth0_ip_string = 0x0360;
  112. short __eth0_ip_value = 0x0370;
  113. short __sn_string = 0x0410;
  114. short __sn_value = 0x0420;
  115. //For Audi, for select gun
  116. short __left_gun_map = 0x0260;
  117. short __right_gun_map = 0x0262;
  118. short __add_chk_btn = 0x0264;
  119. //short __station_id = 0x0270;
  120. short __balance = 0x0270;
  121. short __remain_balance = 0x0280;
  122. short __custStationIdL1 = 0x0450;
  123. //short __custStationIdL2 = 0x0470;
  124. short _emergency_map = 0x011C;
  125. short __logo_cmp = 0x014A;
  126. // ICON ID
  127. uint8_t _disappear = 0;
  128. uint8_t _disconnect = 1;
  129. uint8_t _connect = 2;
  130. uint8_t _warning = 3;
  131. uint8_t _arrow_dark = 4;
  132. uint8_t _arrow_light = 5;
  133. uint8_t _3G4G_disconnect = 6;
  134. uint8_t __3G4G_connect = 7;
  135. uint8_t _wifi_disconnect = 8;
  136. uint8_t _wifi_connect = 9;
  137. uint8_t _logo = 10;
  138. uint8_t _conn_map1 = 11;
  139. uint8_t _conn_map2 = 12;
  140. uint8_t _sel_gun_btn = 13;
  141. uint8_t _back_home_btn = 14;
  142. uint8_t _stop_charging_btn = 15;
  143. uint8_t _stop_charging_btn_scan = 16;
  144. uint8_t _chademo_dark = 17;
  145. uint8_t _ccs_dark = 18;
  146. uint8_t _gbt_dark = 19;
  147. uint8_t _actype_dark = 20;
  148. uint8_t _chademo_light = 21;
  149. uint8_t _ccs_light = 22;
  150. uint8_t _gbt_light = 23;
  151. uint8_t _actype_light = 24;
  152. uint8_t _main_none_rfid = 25;
  153. uint8_t _main_rfid = 26;
  154. uint8_t _main_none_app = 27;
  155. uint8_t _main_app = 28;
  156. uint8_t _main_none_qr = 29;
  157. uint8_t _main_qr = 30;
  158. uint8_t _charging_map1 = 31;
  159. uint8_t _charging_map2 = 32;
  160. uint8_t _battery_empty = 33;
  161. uint8_t _battery_cap_20 = 34;
  162. uint8_t _battery_cap_40 = 35;
  163. uint8_t _battery_cap_60 = 36;
  164. uint8_t _battery_cap_80 = 37;
  165. uint8_t _battery_cap_100 = 38;
  166. uint8_t _battery_map = 39;
  167. uint8_t _power_map = 40;
  168. uint8_t _time_map = 41;
  169. uint8_t _complete_map = 42;
  170. uint8_t _battery_soc_20 = 43;
  171. uint8_t _battery_soc_40 = 44;
  172. uint8_t _battery_soc_60 = 45;
  173. uint8_t _battery_soc_80 = 46;
  174. uint8_t _battery_soc_100 = 47;
  175. uint8_t _battery_eng_map = 48;
  176. uint8_t _money_map = 49;
  177. uint8_t _elapse_time_map = 50;
  178. uint8_t _charging_money = 51;
  179. //uint8_t _side_none_rfid = 52;
  180. //uint8_t _side_rfid = 53;
  181. //uint8_t _side_none_app = 54;
  182. //uint8_t _side_app = 55;
  183. //uint8_t _side_none_qr = 56;
  184. //uint8_t _side_qr = 57;
  185. uint8_t _eth_disconnect = 52; //58;
  186. uint8_t _eth_connect = 53; //59;
  187. uint8_t _chademo_dark_cmp = 54;
  188. uint8_t _ccs_dark_cmp = 55;
  189. uint8_t _gbt_dark_cmp = 56;
  190. uint8_t _actype_dark_cmp = 57;
  191. uint8_t _chademo_light_cmp = 58;
  192. uint8_t _ccs_light_cmp = 59;
  193. uint8_t _gbt_light_cmp = 60;
  194. uint8_t _actype_light_cmp = 61;
  195. uint8_t _logo_cmp = 62;
  196. uint8_t _battery_eng_trp_map = 63;
  197. uint8_t _money_trp_map = 64;
  198. uint8_t _elapse_time_trp_map = 65;
  199. #if defined DD360Audi
  200. ////For Audi
  201. uint8_t _left_gun_disable_map = 66;
  202. uint8_t _left_gun_enable_map = 67;
  203. uint8_t _right_gun_disable_map = 68;
  204. uint8_t _right_gun_enable_map = 69;
  205. uint8_t _select_gun_btn = 70;
  206. uint8_t _emergency_disable_map = 72;
  207. // For replug
  208. struct timespec showReplugStrTimer;
  209. struct timespec showFullTargetTimer;
  210. short __show_StatusString_value_1 = 0x0460;
  211. short __show_StatusString_value_2 = 0x0462;
  212. uint8_t _showfulltarget_1 = 73;
  213. uint8_t _showfulltarget_2 = 74;
  214. uint8_t _showReplugStr_1 = 75;
  215. uint8_t _showReplugStr_2 = 76;
  216. // Select Gun for Audi
  217. short __show_selectgun_value = 0x0464;
  218. uint8_t _showselectgun_left = 77;
  219. uint8_t _showselectgun_right = 78;
  220. // Wait for gun plugin Audi
  221. short __show_waitgunplug_value = 0x0468;
  222. uint8_t _showwaitgunplug_left = 80;
  223. uint8_t _showwaitgunplug_right = 81;
  224. #else
  225. short __show_handshark_value = 0x0464;
  226. short __show_GFD_value = 0x0466;
  227. short __show_precharge_value = 0x0468;
  228. uint8_t _show_handshark_dark = 67;
  229. uint8_t _show_handshark_light = 68;
  230. uint8_t _show_GFD_dark = 69;
  231. uint8_t _show_GFD_light = 70;
  232. uint8_t _show_precharge_dark = 71;
  233. uint8_t _show_precharge_light = 72;
  234. #endif
  235. //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  236. //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  237. //#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  238. //=================================
  239. // Common routine
  240. //=================================
  241. /*int StoreLogMsg(const char *fmt, ...)
  242. {
  243. char Buf[4096 + 256];
  244. char buffer[4096];
  245. va_list args;
  246. struct timeb SeqEndTime;
  247. struct tm *tm;
  248. va_start(args, fmt);
  249. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  250. va_end(args);
  251. memset(Buf, 0, sizeof(Buf));
  252. ftime(&SeqEndTime);
  253. SeqEndTime.time = time(NULL);
  254. tm = localtime(&SeqEndTime.time);
  255. if (pSysConfig->SwitchDebugFlag == YES) {
  256. sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
  257. tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
  258. printf("%s ", Buf);
  259. } else {
  260. sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  261. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
  262. buffer,
  263. tm->tm_year + 1900, tm->tm_mon + 1);
  264. system(Buf);
  265. }
  266. return rc;
  267. }
  268. char *getTimeString(void)
  269. {
  270. char *result = malloc(21);
  271. time_t timep;
  272. struct tm *p;
  273. time(&timep);
  274. p = gmtime(&timep);
  275. 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);
  276. return result;
  277. }
  278. */
  279. #if 0
  280. //==========================================
  281. // Init all share memory
  282. //==========================================
  283. int InitShareMemory()
  284. {
  285. int result = PASS;
  286. int MeterSMId;
  287. //creat ShmSysConfigAndInfo
  288. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0) {
  289. #ifdef SystemLogMessage
  290. log_error("shmget ShmSysConfigAndInfo NG");
  291. #endif
  292. result = FAIL;
  293. } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  294. #ifdef SystemLogMessage
  295. log_error("shmat ShmSysConfigAndInfo NG");
  296. #endif
  297. result = FAIL;
  298. } else
  299. {}
  300. //creat ShmStatusCodeData
  301. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0) {
  302. #ifdef SystemLogMessage
  303. log_error("shmget ShmStatusCodeData NG");
  304. #endif
  305. result = FAIL;
  306. } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  307. #ifdef SystemLogMessage
  308. log_error("shmat ShmStatusCodeData NG");
  309. #endif
  310. result = FAIL;
  311. } else
  312. {}
  313. //creat Audi customization info
  314. if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
  315. log_error("[main]CreatShareMemory:shmget select gun info NG ");
  316. return 0;
  317. } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  318. log_error("[main]CreatShareMemory:shmat shmget select gun info ");
  319. return 0;
  320. }
  321. //creat ShmStatusCodeData
  322. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
  323. #ifdef SystemLogMessage
  324. log_error("shmget ShmPrimaryMcuData NG");
  325. #endif
  326. result = FAIL;
  327. } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  328. #ifdef ShmPrimaryMcuData
  329. log_error("shmat ShmPrimaryMcuData NG");
  330. #endif
  331. result = FAIL;
  332. }
  333. return result;
  334. }
  335. #endif //0
  336. //==========================================
  337. // Open and Close RS232 and R/W
  338. //==========================================
  339. int CreateCommunicationLcmPort()
  340. {
  341. int fd;
  342. struct termios tios;
  343. fd = open(pPortName, O_RDWR);
  344. if (fd <= 0) {
  345. #ifdef SystemLogMessage
  346. log_error("open /dev/ttyS3 NG ");
  347. #endif
  348. return -1;
  349. }
  350. ioctl(fd, TCGETS, &tios);
  351. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  352. tios.c_lflag = 0;
  353. tios.c_iflag = 0;
  354. tios.c_oflag = 0;
  355. tios.c_cc[VMIN] = 0;
  356. tios.c_cc[VTIME] = (uint8_t) 5;
  357. tios.c_lflag = 0;
  358. tcflush(fd, TCIFLUSH);
  359. ioctl(fd, TCSETS, &tios);
  360. return fd;
  361. }
  362. void CloseCommunicationLcmPort()
  363. {
  364. close(_port);
  365. }
  366. void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
  367. {
  368. int len = write(_port, cmd, cmdLen);
  369. if (len >= sizeof(cmd)) {
  370. //log_info("Write cmd to LCM successfully. ");
  371. }
  372. }
  373. void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
  374. {
  375. read(_port, msg, readLen);
  376. if (*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2) {
  377. if (*(msg + 3) == CMD_WRITE) {
  378. switch (*(msg + 4)) {
  379. case CMD_REGISTER: {
  380. // 頁面
  381. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  382. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  383. }
  384. break;
  385. }
  386. } else if (*(msg + 3) == CMD_MULTI_READ) {
  387. short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
  388. if (key == __lcm_version)
  389. {
  390. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  391. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  392. ShmDcCommonData->LcmFwVersion = atoi((char *)(msg + 7));
  393. //printf("msg = %d \n", ShmDcCommonData->LcmFwVersion);
  394. // printf("msg = %x \n", *(msg + 7));
  395. // printf("msg = %x \n", *(msg + 8));
  396. // printf("msg = %x \n", *(msg + 9));
  397. }
  398. }
  399. }
  400. }
  401. //================================================
  402. // Function
  403. //================================================
  404. void ChangeToOtherPage(short newPage)
  405. {
  406. uint8_t cmd[7];
  407. memset(cmd, 0x00, sizeof(cmd));
  408. cmd[0] = CMD_TITLE_1;
  409. cmd[1] = CMD_TITLE_2;
  410. cmd[2] = 0x02 + sizeof(newPage);
  411. cmd[3] = CMD_READ;
  412. cmd[4] = CMD_REGISTER;
  413. cmd[5] = newPage >> 8;
  414. cmd[6] = newPage & 0x00FF;
  415. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  416. usleep(100000);
  417. }
  418. void ChangeBackLight(bool islight)
  419. {
  420. uint8_t value = 0x01;
  421. if (islight) {
  422. value = 0x20;
  423. }
  424. uint8_t cmd[7];
  425. memset(cmd, 0x00, sizeof(cmd));
  426. cmd[0] = CMD_TITLE_1;
  427. cmd[1] = CMD_TITLE_2;
  428. cmd[2] = 0x03;
  429. cmd[3] = CMD_READ;
  430. cmd[4] = CMD_BACKLIGHT;
  431. cmd[5] = value;
  432. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  433. usleep(100000);
  434. }
  435. void GetCurrentPage()
  436. {
  437. uint8_t cmd[6];
  438. memset(cmd, 0x00, sizeof(cmd));
  439. uint8_t msg[8];
  440. memset(msg, 0x00, sizeof(msg));
  441. cmd[0] = CMD_TITLE_1;
  442. cmd[1] = CMD_TITLE_2;
  443. cmd[2] = 0x03; // 底下總長度
  444. cmd[3] = CMD_WRITE;
  445. cmd[4] = CMD_REGISTER;
  446. cmd[5] = 0x02;
  447. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  448. usleep(100000);
  449. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  450. }
  451. void DisplayValueToLcm(short address, uint8_t *data, uint8_t len)
  452. {
  453. uint8_t cmd[256];
  454. memset(cmd, 0x00, sizeof(cmd));
  455. cmd[0] = CMD_TITLE_1;
  456. cmd[1] = CMD_TITLE_2;
  457. cmd[2] = 0x03 + len;
  458. cmd[3] = CMD_MULTI_WRITE;
  459. cmd[4] = address >> 8;
  460. cmd[5] = address & 0x00FF;
  461. for (uint8_t count = 0; count < len; count++) {
  462. cmd[6 + count] = *(data + count);
  463. }
  464. WriteCmdToLcm(cmd, cmd[2] + 3);
  465. }
  466. void ChangeDisplay2Value(short address, short value)
  467. {
  468. uint8_t data[2];
  469. data[0] = value >> 8;
  470. data[1] = value & 0x00FF;
  471. DisplayValueToLcm(address, data, sizeof(data));
  472. }
  473. void GetBtnStatus(short address, uint8_t len)
  474. {
  475. uint8_t cmd[8];
  476. memset(cmd, 0x00, sizeof(cmd));
  477. uint8_t msg[8];
  478. memset(msg, 0x00, sizeof(msg));
  479. cmd[0] = CMD_TITLE_1;
  480. cmd[1] = CMD_TITLE_2;
  481. cmd[2] = 0x03 + len;
  482. cmd[3] = CMD_MULTI_READ;
  483. cmd[4] = address >> 8;
  484. cmd[5] = address & 0x00FF;
  485. cmd[6] = 0x00 + len;
  486. WriteCmdToLcm(cmd, cmd[2] + 3);
  487. usleep(100000);
  488. ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
  489. }
  490. //================================================
  491. // Warning process
  492. //================================================
  493. void string2ByteArray(uint8_t *input, uint8_t *output)
  494. {
  495. int loop;
  496. int i;
  497. loop = 0;
  498. i = 0;
  499. while (input[loop] != '\0') {
  500. output[i++] = input[loop++];
  501. }
  502. output[loop] = '\0';
  503. }
  504. void ChangeWarningFunc()
  505. {
  506. uint8_t cmd[7] = {0};
  507. uint8_t i = 0;
  508. //uint8_t j = 0;
  509. //log_info("ChangeWarningFunc ");
  510. // 最多一次五筆
  511. //log_info("LCM PageIndex = %d ", pSysWarning->PageIndex);
  512. //log_info("WarningCount = %d ", pSysWarning->WarningCount);
  513. //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  514. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  515. log_info("Warming Code[%d]:%s",i,&pSysWarning->WarningCode[i][0]);
  516. memset(cmd, 0x00, sizeof(cmd));
  517. if ((i) >= 5) {
  518. break;
  519. }
  520. //error code
  521. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  522. DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
  523. //警告標示
  524. memset(cmd, 0x00, sizeof(cmd));
  525. cmd[0] = 0x00;
  526. cmd[1] = 0x01;
  527. DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
  528. }
  529. memset(cmd, 0x00, sizeof(cmd));
  530. for (; i < 5; i++) {
  531. DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
  532. DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
  533. }
  534. /*#else
  535. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  536. memset(cmd, 0x00, sizeof(cmd));
  537. if ((i - j) >= 5) {
  538. break;
  539. }
  540. if (
  541. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "033900", 6) == 0) ||
  542. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "033901", 6) == 0) ||
  543. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "033902", 6) == 0) ||
  544. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043627", 6) == 0) ||
  545. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043628", 6) == 0) ||
  546. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043622", 6) == 0) ||
  547. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043623", 6) == 0) ||
  548. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043624", 6) == 0) ||
  549. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043625", 6) == 0) ||
  550. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "043626", 6) == 0) ||
  551. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "042241", 6) == 0) ||
  552. (memcmp(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], "042242", 6) == 0)
  553. ) {
  554. j++;
  555. continue;
  556. }
  557. //error code
  558. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  559. DisplayValueToLcm(0x0010 + ((i - j) * 6), cmd, sizeof(cmd));
  560. //警告標示
  561. memset(cmd, 0x00, sizeof(cmd));
  562. cmd[0] = 0x00;
  563. cmd[1] = 0x01;
  564. DisplayValueToLcm(0x0002 + ((i - j) * 2), cmd, 2);
  565. }
  566. memset(cmd, 0x00, sizeof(cmd));
  567. i = i - j;
  568. for (; (i) < 5; i++) {
  569. DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
  570. DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
  571. }
  572. #endif //!defined DD360 && !defined DD360Audi
  573. */
  574. }
  575. //================================================
  576. // QR Code process
  577. //================================================
  578. void ChangeQrCode_Idle(char *input)
  579. {
  580. #if defined DD360Audi
  581. int len = strlen(input) + 3;
  582. int loop = 0;
  583. int i = 0, j = 0, k = 0, l = 0;
  584. uint8_t qrUrl[128] = {0};
  585. uint16_t urlLen = 0;
  586. uint8_t cmd[len];
  587. uint8_t tmpBuf[15] = {0};
  588. //uint8_t tmpLen = sizeof(tmpBuf) - 1;
  589. strncpy((char *)cmd, " ", len);
  590. while (input[loop] != '\0') {
  591. cmd[i++] = input[loop++];
  592. l = loop - 1;
  593. if (len >= 25) {
  594. if (i >= 16 && i <= 19) {
  595. tmpBuf[k++] = input[l];
  596. //printf("tmpBuf = %s", tmpBuf);
  597. } else if (i >= 21 && i <= 23) {
  598. tmpBuf[k++] = input[l];
  599. }
  600. }
  601. }
  602. tmpBuf[k] = '\0';
  603. //printf("tmpBuf = %s", tmpBuf);
  604. j += sprintf((char *)&cmd[i], ":%d", pSysInfo->CurGunSelected); ////For Audi
  605. cmd[len - 1] = '\0';
  606. urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
  607. qrUrl[urlLen] = '\0';
  608. //printf("qr url = %s", qrUrl);
  609. DisplayValueToLcm(__qr_code, qrUrl, urlLen);
  610. j = 0;
  611. j += sprintf((char *)&tmpBuf[k], "0%d", pSysInfo->CurGunSelected); ////For Audi
  612. tmpBuf[k + j] = '\0';
  613. //if (len < 25) {
  614. // strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  615. //}
  616. //tmpBuf[tmpLen] = '\0';
  617. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  618. /*if (len > sizeof(tmpBuf)) {
  619. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  620. tmpBuf[tmpLen] = '\0';
  621. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  622. memset(tmpBuf, 0, sizeof(tmpBuf));
  623. strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
  624. tmpBuf[tmpLen] = '\0';
  625. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  626. } else {
  627. DisplayValueToLcm(__custStationIdL1, cmd, len);
  628. strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
  629. tmpBuf[tmpLen] = '\0';
  630. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  631. }*/
  632. #else
  633. int len = strlen(input);
  634. uint8_t cmd[len];
  635. int loop = 0;
  636. int i = 0;
  637. while (input[loop] != '\0') {
  638. cmd[i++] = input[loop++];
  639. }
  640. DisplayValueToLcm(__qr_code, cmd, len + 1);
  641. #endif //defined DD360Audi
  642. }
  643. void ChangeQrCode_Charge(char *input)
  644. {
  645. #if defined DD360Audi
  646. int len = strlen(input) + 3;
  647. int loop = 0;
  648. int i = 0, j = 0, k = 0, l = 0;
  649. uint8_t qrUrl[128] = {0};
  650. uint16_t urlLen = 0;
  651. uint8_t cmd[len];
  652. uint8_t tmpBuf[15] = {0};
  653. //uint8_t tmpLen = sizeof(tmpBuf) - 1;
  654. strncpy((char *)cmd, " ", len);
  655. while (input[loop] != '\0') {
  656. cmd[i++] = input[loop++];
  657. l = loop - 1;
  658. if (len >= 25) {
  659. if (i >= 16 && i <= 19) {
  660. tmpBuf[k++] = input[l];
  661. //printf("tmpBuf = %s", tmpBuf);
  662. } else if (i >= 21 && i <= 23) {
  663. tmpBuf[k++] = input[l];
  664. }
  665. }
  666. }
  667. tmpBuf[k] = '\0';
  668. //printf("tmpBuf = %s", tmpBuf);
  669. j += sprintf((char *)&cmd[i], ":%d", pSysInfo->CurGunSelected); ////For Audi
  670. cmd[len - 1] = '\0';
  671. urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
  672. qrUrl[urlLen] = '\0';
  673. DisplayValueToLcm(__qr_code, qrUrl, urlLen);
  674. j = 0;
  675. j += sprintf((char *)&tmpBuf[k], "0%d", pSysInfo->CurGunSelected); ////For Audi
  676. tmpBuf[k + j] = '\0';
  677. if (len < 25) {
  678. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  679. }
  680. //tmpBuf[tmpLen] = '\0';
  681. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  682. /*if (len > sizeof(tmpBuf)) {
  683. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  684. tmpBuf[tmpLen] = '\0';
  685. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  686. memset(tmpBuf, 0, sizeof(tmpBuf));
  687. strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
  688. tmpBuf[tmpLen] = '\0';
  689. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  690. } else {
  691. DisplayValueToLcm(__custStationIdL1, cmd, len);
  692. strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
  693. tmpBuf[tmpLen] = '\0';
  694. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  695. }*/
  696. #else
  697. int len = strlen(input);
  698. uint8_t cmd[len];
  699. int loop = 0;
  700. int i = 0;
  701. while (input[loop] != '\0') {
  702. cmd[i++] = input[loop++];
  703. }
  704. DisplayValueToLcm(__qr_code_pre, cmd, len + 1);
  705. #endif //defined DD360Audi
  706. }
  707. //================================================
  708. // Change current page
  709. //================================================
  710. void ChangeCurPage()
  711. {
  712. //log_info("cur = %d, new = %d ", _currentPage, pSysInfo->PageIndex);
  713. if (_currentPage != pSysInfo->PageIndex) {
  714. _currentPage = pSysInfo->PageIndex;
  715. ChangeToOtherPage(_currentPage);
  716. _everyPageRollChange = 0;
  717. }
  718. }
  719. void GetDeviceInfoStatus(short address, uint8_t len)
  720. {
  721. uint8_t cmd[8];
  722. memset(cmd, 0x00, sizeof(cmd));
  723. uint8_t msg[11];
  724. memset(msg, 0x00, sizeof(msg));
  725. cmd[0] = CMD_TITLE_1;
  726. cmd[1] = CMD_TITLE_2;
  727. cmd[2] = 0x04;
  728. cmd[3] = CMD_MULTI_READ;
  729. cmd[4] = (address >> 8) & 0xff;
  730. cmd[5] = (address >> 0) & 0xff;
  731. cmd[6] = len;
  732. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  733. usleep(5000);
  734. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  735. }
  736. //================================================
  737. // Main process
  738. //================================================
  739. uint8_t demoCount = 0;
  740. void DemoFunction()
  741. {
  742. if (demoCount == 0) {
  743. pSysWarning->WarningCount = 6;
  744. memcpy(&pSysWarning->WarningCode[0][0], "000001", 7);
  745. memcpy(&pSysWarning->WarningCode[1][0], "000002", 7);
  746. memcpy(&pSysWarning->WarningCode[2][0], "000003", 7);
  747. memcpy(&pSysWarning->WarningCode[3][0], "000004", 7);
  748. memcpy(&pSysWarning->WarningCode[4][0], "000005", 7);
  749. memcpy(&pSysWarning->WarningCode[5][0], "000006", 7);
  750. } else {
  751. if (demoCount == 20) {
  752. pSysInfo->PageIndex = _LCM_IDLE;
  753. } else if (demoCount == 80) {
  754. pSysInfo->PageIndex = _LCM_AUTHORIZING;
  755. } else if (demoCount == 100) {
  756. pSysInfo->PageIndex = _LCM_AUTHORIZ_COMP;
  757. } else if (demoCount == 120) {
  758. pSysInfo->PageIndex = _LCM_AUTHORIZ_FAIL;
  759. } else if (demoCount == 140) {
  760. pSysInfo->PageIndex = _LCM_PRE_CHARGE;
  761. } else if (demoCount == 180) {
  762. pSysInfo->PageIndex = _LCM_CHARGING;
  763. }
  764. }
  765. if (demoCount < 180) {
  766. demoCount++;
  767. }
  768. }
  769. //================================================
  770. // Main process
  771. //================================================
  772. bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **_chargingData)
  773. {
  774. for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
  775. if (pSysInfo->ChademoChargingData[index].Index == target) {
  776. _chargingData[target] = &pSysInfo->ChademoChargingData[index];
  777. return true;
  778. }
  779. }
  780. for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
  781. if (pSysInfo->CcsChargingData[index].Index == target) {
  782. _chargingData[target] = &pSysInfo->CcsChargingData[index];
  783. return true;
  784. }
  785. }
  786. for (uint8_t index = 0; index < GB_QUANTITY; index++) {
  787. if (pSysInfo->GbChargingData[index].Index == target) {
  788. _chargingData[target] = &pSysInfo->GbChargingData[index];
  789. return true;
  790. }
  791. }
  792. return false;
  793. }
  794. bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
  795. {
  796. if (target < AC_QUANTITY) {
  797. acChargingData[target] = &pSysInfo->AcChargingData[target];
  798. return true;
  799. }
  800. return false;
  801. }
  802. int GetTimeoutValue(struct timespec *startTime)
  803. {
  804. struct timespec endTime;
  805. clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
  806. return endTime.tv_sec - startTime->tv_sec;
  807. }
  808. void GetTimespecFunc(struct timespec *time)
  809. {
  810. clock_gettime(CLOCK_MONOTONIC_COARSE, time);
  811. }
  812. #if defined DD360Audi
  813. void RunReplugStringFunction(bool isRun)
  814. {
  815. if (isRun) {
  816. int time = GetTimeoutValue(&showReplugStrTimer);
  817. if (time >=1 && time <2) {
  818. ChangeDisplay2Value(__show_StatusString_value_1, _showReplugStr_1);
  819. ChangeDisplay2Value(__show_StatusString_value_2, _showReplugStr_2);
  820. } else if (time < 1) {
  821. ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
  822. ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
  823. } else
  824. GetTimespecFunc(&showReplugStrTimer);
  825. } else {
  826. ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
  827. ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
  828. }
  829. }
  830. void RunFullTargetFunction(bool isRun)
  831. {
  832. if (isRun) {
  833. int time = GetTimeoutValue(&showFullTargetTimer);
  834. if (time >=1 && time <2) {
  835. ChangeDisplay2Value(__show_StatusString_value_1, _showfulltarget_1 );
  836. ChangeDisplay2Value(__show_StatusString_value_2, _showfulltarget_2);
  837. } else if (time < 1) {
  838. ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
  839. ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
  840. } else
  841. GetTimespecFunc(&showFullTargetTimer);
  842. } else {
  843. ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
  844. ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
  845. }
  846. }
  847. #endif
  848. /**
  849. * [ChangeBalanceValue :print balance information]
  850. * @Author
  851. * @DateTime 2020-11-26
  852. */
  853. static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
  854. {
  855. uint8_t cmd[10] = {0};
  856. uint8_t value[10] = {0};
  857. uint8_t len = 0;
  858. float balance = ShmSelectGunInfo->PricesInfo[index].Balance;
  859. if ((balance) == (FAIL_BALANCE_PRICES)) {
  860. balance = 0.00;
  861. }
  862. len += sprintf((char *) value, "%.2f", balance);
  863. if (len < 6) {
  864. sprintf((char *)&value[len], "%s",
  865. (uint8_t *)GetCurrency(pSysConfig->BillingData.Currency));
  866. }
  867. value[sizeof(value) - 1] = '\0';
  868. string2ByteArray(value, cmd);
  869. DisplayValueToLcm(addr, cmd, sizeof(cmd));
  870. }
  871. void ChangeAcBattMapAndValue(short page)
  872. {
  873. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  874. if (page == _LCM_CHARGING) {
  875. if (isDiffStatus != _battery_display_ani) {
  876. isChangeBattMap = false;
  877. isDiffStatus = _battery_display_ani;
  878. }
  879. if (pAcChargingInfo->IsCharging && !isChangeBattMap) {
  880. isChangeBattMap = true;
  881. if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
  882. ChangeDisplay2Value(__batt_map, _battery_empty);
  883. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_EMP;
  884. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
  885. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  886. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV1;
  887. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
  888. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  889. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV2;
  890. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
  891. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  892. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV3;
  893. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
  894. ChangeDisplay2Value(__batt_map, _battery_cap_80);
  895. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV4;
  896. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
  897. ChangeDisplay2Value(__batt_map, _battery_cap_100);
  898. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
  899. }
  900. }
  901. } else if (page == _LCM_COMPLETE) {
  902. if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
  903. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  904. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
  905. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  906. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
  907. ChangeDisplay2Value(__batt_map, _battery_soc_40);
  908. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
  909. ChangeDisplay2Value(__batt_map, _battery_soc_60);
  910. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
  911. ChangeDisplay2Value(__batt_map, _battery_soc_80);
  912. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
  913. ChangeDisplay2Value(__batt_map, _battery_soc_100);
  914. }
  915. }
  916. ChangeDisplay2Value(__soc_value_charging, _disappear);
  917. }
  918. void ChangeBattMapAndValue(short page, int soc)
  919. {
  920. // srand(time(NULL));
  921. // int min = 10;
  922. // int max = 90;
  923. // soc = rand() % (max - min + 1) + min;
  924. if (page == _LCM_PRE_CHARGE) {
  925. ChangeDisplay2Value(__batt_map_empty, _battery_empty);
  926. } else if (page == _LCM_CHARGING) {
  927. if (soc < 20) {
  928. if (_battery_display_ani) {
  929. ChangeDisplay2Value(__batt_map, _battery_empty);
  930. } else {
  931. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  932. }
  933. } else if (soc >= 20 && soc < 40) {
  934. if (_battery_display_ani) {
  935. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  936. } else {
  937. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  938. }
  939. } else if (soc >= 40 && soc < 60) {
  940. if (_battery_display_ani) {
  941. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  942. } else {
  943. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  944. }
  945. } else if (soc >= 60 && soc < 80) {
  946. if (_battery_display_ani) {
  947. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  948. } else {
  949. ChangeDisplay2Value(__batt_map, _battery_cap_80);
  950. }
  951. } else if (soc >= 80 && soc <= 100) {
  952. if (_battery_display_ani) {
  953. ChangeDisplay2Value(__batt_map, _battery_cap_80); //DS60-120 add
  954. } else {
  955. ChangeDisplay2Value(__batt_map, _battery_cap_100);
  956. }
  957. }
  958. } else if (page == _LCM_COMPLETE) {
  959. if (soc < 20) {
  960. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  961. } else if (soc >= 20 && soc < 40) {
  962. ChangeDisplay2Value(__batt_map, _battery_soc_40);
  963. } else if (soc >= 40 && soc < 60) {
  964. ChangeDisplay2Value(__batt_map, _battery_soc_60);
  965. } else if (soc >= 60 && soc < 80) {
  966. ChangeDisplay2Value(__batt_map, _battery_soc_80);
  967. } else if (soc >= 80 && soc <= 100) {
  968. ChangeDisplay2Value(__batt_map, _battery_soc_100);
  969. }
  970. }
  971. uint8_t cmd[5];
  972. uint8_t value[5];
  973. memset(cmd, 0x00, sizeof(cmd));
  974. memset(value, 0x00, sizeof(value));
  975. sprintf((char *)value, "%d%%", soc);
  976. string2ByteArray(value, cmd);
  977. DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
  978. }
  979. void ChangeRemainTime(int sec)
  980. {
  981. int h, m, s;
  982. uint8_t cmd[10];
  983. uint8_t value[10];
  984. memset(cmd, 0x00, sizeof(cmd));
  985. // srand(time(NULL));
  986. // int min = 0;
  987. // int max = 65536;
  988. // sec = rand() % (max - min + 1) + min;
  989. h = (sec / 3600);
  990. m = (sec - (3600 * h)) / 60;
  991. s = (sec - (3600 * h) - (m * 60));
  992. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  993. string2ByteArray(value, cmd);
  994. DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
  995. }
  996. void ChangeChargingEnergyValue(float energy)
  997. {
  998. uint8_t cmd[10];
  999. uint8_t value[10];
  1000. memset(cmd, 0x00, sizeof(cmd));
  1001. if (energy >= 0.05) {
  1002. energy -= 0.05;
  1003. }
  1004. sprintf((char *) value, "%.1f kWh", energy);
  1005. string2ByteArray(value, cmd);
  1006. DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
  1007. }
  1008. void ChangeChargingPowerValue(float pow)
  1009. {
  1010. uint8_t cmd[10];
  1011. uint8_t value[10];
  1012. memset(cmd, 0x00, sizeof(cmd));
  1013. // float min = 0.0;
  1014. // float max = 50;
  1015. // pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
  1016. sprintf((char *) value, "%.1f kW", pow);
  1017. string2ByteArray(value, cmd);
  1018. DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
  1019. }
  1020. void ChangeChargingFeeValue(float fee)
  1021. {
  1022. uint8_t cmd[10];
  1023. uint8_t value[10];
  1024. memset(cmd, 0x00, sizeof(cmd));
  1025. sprintf((char *) value, "%.2f", fee);
  1026. string2ByteArray(value, cmd);
  1027. DisplayValueToLcm(__charging_fee_tx, cmd, sizeof(cmd));
  1028. }
  1029. void DisplayMoneyRate(float money)
  1030. {
  1031. uint8_t cmd[8];
  1032. uint8_t value[8];
  1033. memset(cmd, 0x00, sizeof(cmd));
  1034. sprintf((char *) value, "%.2f", money);
  1035. string2ByteArray(value, cmd);
  1036. DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
  1037. }
  1038. void DisplayMoneyCur(uint8_t *cur)
  1039. {
  1040. uint8_t cmd[10] = {0};
  1041. uint8_t buf[10] = {0};
  1042. uint8_t len = 0;
  1043. *(cur + 3) = '\0';
  1044. memset(cmd, 0x00, sizeof(cmd));
  1045. len = sprintf((char *) buf, "%s/kWh", cur);
  1046. buf[len] = '\0';
  1047. string2ByteArray(buf, cmd);
  1048. DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
  1049. }
  1050. void RefreshPageAnimation(uint8_t value)
  1051. {
  1052. switch (_currentPage) {
  1053. case _LCM_IDLE: {
  1054. }
  1055. break;
  1056. case _LCM_WAIT_FOR_PLUG: {
  1057. if (_everyPageRollChange == 0) {
  1058. ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
  1059. } else if (_everyPageRollChange == 15) {
  1060. ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
  1061. }
  1062. _everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  1063. }
  1064. break;
  1065. case _LCM_PRE_CHARGE:
  1066. case _LCM_CHARGING:
  1067. case _LCM_COMPLETE: {
  1068. if (_currentPage == _LCM_PRE_CHARGE) {
  1069. if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
  1070. ChangeDisplay2Value(__conn_line, _conn_map1);
  1071. } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
  1072. ChangeDisplay2Value(__conn_line, _conn_map2);
  1073. }
  1074. } else if (_currentPage == _LCM_CHARGING) {
  1075. if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
  1076. ChangeDisplay2Value(__conn_line_chag, _charging_map1);
  1077. } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
  1078. ChangeDisplay2Value(__conn_line_chag, _charging_map2);
  1079. }
  1080. } else if (_currentPage == _LCM_COMPLETE) {
  1081. if (_everyPageRollChange == 0) {
  1082. ChangeDisplay2Value(__conn_line_comp, _complete_map);
  1083. }
  1084. }
  1085. _everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  1086. }
  1087. break;
  1088. }
  1089. }
  1090. void RefreshConnStatus()
  1091. {
  1092. // Wifi priority is higher than Ethernet
  1093. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  1094. uint8_t i = 0;
  1095. uint8_t ethstatus = 0;
  1096. for (i = 0; i < pSysWarning->WarningCount; i++) {
  1097. if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
  1098. ethstatus = 1;
  1099. //if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
  1100. // ShmSelectGunInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
  1101. //}
  1102. break;
  1103. }
  1104. }
  1105. if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_DISABLE) {
  1106. ChangeDisplay2Value(__conn_status, _disappear);
  1107. } else if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_ENABLE_USE) {
  1108. ChangeDisplay2Value(__conn_status, _connect);
  1109. } else if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_ENABLE_NO_USE) {
  1110. ChangeDisplay2Value(__conn_status, _disconnect);
  1111. }
  1112. if (ethstatus == 1) {
  1113. if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
  1114. ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
  1115. }
  1116. } else {
  1117. if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
  1118. ChangeDisplay2Value(__ethernet_status, _eth_connect);
  1119. }
  1120. //if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_DISABLE) {
  1121. //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_USE) {
  1122. // ChangeDisplay2Value(__ethernet_status, _eth_connect);
  1123. //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_NO_USE) {
  1124. // ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
  1125. //}
  1126. }
  1127. if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_DISABLE) {
  1128. ChangeDisplay2Value(__wifi_status, _disappear);
  1129. ChangeDisplay2Value(__3G4G_status, _disappear);
  1130. if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
  1131. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1132. } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
  1133. ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
  1134. } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
  1135. ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
  1136. }
  1137. } else if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_USE) {
  1138. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1139. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  1140. } else if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_NO_USE) {
  1141. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1142. ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
  1143. }
  1144. if (ShmSelectGunInfo->EthDevStatus.Wifi != DEV_ST_DISABLE) {
  1145. if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
  1146. ChangeDisplay2Value(__3G4G_status, _disappear);
  1147. } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
  1148. ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
  1149. } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
  1150. ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
  1151. }
  1152. }
  1153. //uint8_t flag[4] = {0};
  1154. /*for (i = 0; i < pSysWarning->WarningCount; i++) {
  1155. //printf("status code = %s", &pSysWarning->WarningCode[i][0]);
  1156. if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
  1157. flag[0] = 1;
  1158. continue;
  1159. }
  1160. if (memcmp(&pSysWarning->WarningCode[i][0], "043625", 6) == 0) {
  1161. //disconnected from AP through WiFi
  1162. flag[1] = 1;
  1163. continue;
  1164. }
  1165. if (memcmp(&pSysWarning->WarningCode[i][0], "043627", 6) == 0) { //wifi disabled
  1166. flag[1] = 2;
  1167. continue;
  1168. }
  1169. if ((memcmp(&pSysWarning->WarningCode[i][0], "033900", 6) == 0) ||
  1170. (memcmp(&pSysWarning->WarningCode[i][0], "033901", 6) == 0) ||
  1171. (memcmp(&pSysWarning->WarningCode[i][0], "033902", 6) == 0)) {
  1172. flag[2] = 1;
  1173. continue;
  1174. }
  1175. if (memcmp(&pSysWarning->WarningCode[i][0], "043626", 6) == 0) {
  1176. //disconnected from APN through 3G/4G
  1177. flag[3] = 1;
  1178. continue;
  1179. }
  1180. if (memcmp(&pSysWarning->WarningCode[i][0], "043628", 6) == 0) { //4g disabled
  1181. flag[3] = 2;
  1182. continue;
  1183. }
  1184. }
  1185. if (flag[0] == 1) {
  1186. ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
  1187. } else {
  1188. ChangeDisplay2Value(__ethernet_status, _eth_connect);
  1189. }
  1190. //ChangeDisplay2Value(__wifi_status, _disappear);
  1191. //ChangeDisplay2Value(__conn_status, _disappear);
  1192. //ChangeDisplay2Value(__3G4G_status, _disappear);
  1193. if (flag[1] == 1) {
  1194. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1195. ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
  1196. } else if (flag[1] == 2) {
  1197. ChangeDisplay2Value(__wifi_status, _disappear);
  1198. } else {
  1199. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1200. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  1201. }
  1202. if (flag[2] == 1) {
  1203. ChangeDisplay2Value(__conn_status, _disconnect);
  1204. } else {
  1205. ChangeDisplay2Value(__conn_status, _connect);
  1206. }
  1207. if (flag[1] == 2) {
  1208. ChangeDisplay2Value(__3G4G_status, _disappear);
  1209. if (flag[3] == 1) {
  1210. ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
  1211. } else if (flag[3] == 2) {
  1212. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1213. } else {
  1214. ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
  1215. }
  1216. } else {
  1217. if (flag[3] == 1) {
  1218. ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
  1219. } else if (flag[3] == 2) {
  1220. ChangeDisplay2Value(__3G4G_status, _disappear);
  1221. } else {
  1222. ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
  1223. }
  1224. }
  1225. */
  1226. #else
  1227. // eth
  1228. if (pSysInfo->ethInternetConn == YES) {
  1229. ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
  1230. } else {
  1231. ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
  1232. }
  1233. // Wifi
  1234. if ((pSysConfig->ModelName[10] == 'W' ||
  1235. pSysConfig->ModelName[10] == 'D') &&
  1236. pSysConfig->AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE) {
  1237. if (pSysConfig->AthInterface.WifiNetworkConn == YES ||
  1238. pSysConfig->AthInterface.WifiMode == _SYS_WIFI_MODE_AP) {
  1239. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  1240. } else {
  1241. ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
  1242. }
  1243. } else {
  1244. ChangeDisplay2Value(__wifi_status, _disappear);
  1245. }
  1246. if ((pSysConfig->ModelName[10] == 'T' ||
  1247. pSysConfig->ModelName[10] == 'D') &&
  1248. pSysConfig->TelecomInterface.TelcomEnabled != NO) {
  1249. if (pSysConfig->AthInterface.WifiMode == _SYS_WIFI_MODE_DISABLE) {
  1250. ChangeDisplay2Value(__3G4G_status, _disappear);
  1251. // 3G/4G
  1252. if (pSysConfig->TelecomInterface.TelcomNetworkConn == YES)
  1253. { ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect); }
  1254. else
  1255. { ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect); }
  1256. } else {
  1257. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1258. // 3G/4G
  1259. if (pSysConfig->TelecomInterface.TelcomNetworkConn == YES)
  1260. { ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect); }
  1261. else
  1262. { ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect); }
  1263. }
  1264. } else {
  1265. ChangeDisplay2Value(__3G4G_status, _disappear);
  1266. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  1267. }
  1268. // 連線到後台
  1269. if (pSysInfo->OcppConnStatus == YES) {
  1270. ChangeDisplay2Value(__conn_status, _connect);
  1271. } else {
  1272. ChangeDisplay2Value(__conn_status, _disconnect);
  1273. }
  1274. /*if (pSysConfig->AthInterface.WifiNetworkConn == YES ||
  1275. pSysConfig->AthInterface.WifiMode == _SYS_WIFI_MODE_AP) {
  1276. _wifi_conn_status = true;
  1277. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  1278. ChangeDisplay2Value(__ethernet_status, _disappear);
  1279. } else {
  1280. _wifi_conn_status = false;
  1281. ChangeDisplay2Value(__wifi_status, _disappear);
  1282. }
  1283. if (!_wifi_conn_status) {
  1284. if (pSysConfig->TelecomInterface.TelcomNetworkConn == YES ||
  1285. pSysInfo->InternetConn == YES) {
  1286. ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
  1287. } else {
  1288. ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
  1289. }
  1290. }
  1291. // 連線到後台
  1292. if (pSysInfo->OcppConnStatus == YES) {
  1293. ChangeDisplay2Value(__conn_status, _connect);
  1294. } else {
  1295. ChangeDisplay2Value(__conn_status, _disconnect);
  1296. }
  1297. */
  1298. #endif //defined DD360 || defined DD360Audi
  1299. }
  1300. uint8_t FirstPageChanged()
  1301. {
  1302. uint8_t result = NO;
  1303. if (_currentPage != _oldPage) {
  1304. result = YES;
  1305. _oldPage = _currentPage;
  1306. }
  1307. return result;
  1308. }
  1309. bool IsPageReloadChk()
  1310. {
  1311. bool result = false;
  1312. if (pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
  1313. if (_curPage_index != pSysInfo->CurGunSelected) {
  1314. _curPage_index = pSysInfo->CurGunSelected;
  1315. result = true;
  1316. }
  1317. } else {
  1318. if (_curPage_index != pSysInfo->CurGunSelectedByAc) {
  1319. _curPage_index = pSysInfo->CurGunSelectedByAc;
  1320. result = true;
  1321. }
  1322. }
  1323. return result;
  1324. }
  1325. void ClearDisplayInfo()
  1326. {
  1327. ChangeDisplay2Value(__csu_ver_string, _disappear);
  1328. ChangeDisplay2Value(__csu_ver_value, _disappear);
  1329. ChangeDisplay2Value(__eth0_ip_string, _disappear);
  1330. ChangeDisplay2Value(__eth0_ip_value, _disappear);
  1331. ChangeDisplay2Value(__sn_string, _disappear);
  1332. ChangeDisplay2Value(__sn_value, _disappear);
  1333. ChangeDisplay2Value(__dc1_ver_string, _disappear);
  1334. ChangeDisplay2Value(__dc1_ver_value, _disappear);
  1335. ChangeDisplay2Value(__dc2_ver_string, _disappear);
  1336. ChangeDisplay2Value(__dc2_ver_value, _disappear);
  1337. ChangeDisplay2Value(__fan_speed_string, _disappear);
  1338. ChangeDisplay2Value(__fan_speed_value, _disappear);
  1339. }
  1340. void DisplayInfoCsuVer(bool isShow, uint8_t *modelName)
  1341. {
  1342. if (isShow) {
  1343. uint8_t value[10];
  1344. memset(value, 0x00, sizeof(value));
  1345. strcpy((char *)value, "CSU Ver >");
  1346. DisplayValueToLcm(__csu_ver_string, value, sizeof(value));
  1347. memset(value, 0x00, sizeof(value));
  1348. strncpy((char *)value, (char *)modelName, 5);
  1349. DisplayValueToLcm(__csu_ver_value, value, sizeof(value));
  1350. } else {
  1351. ChangeDisplay2Value(__csu_ver_string, _disappear);
  1352. ChangeDisplay2Value(__csu_ver_value, _disappear);
  1353. }
  1354. }
  1355. void ShowWifiMode(bool isShow, uint8_t mode)
  1356. {
  1357. if (isShow) {
  1358. uint8_t value[20];
  1359. memset(value, 0x00, sizeof(value));
  1360. strcpy((char *) value, "Wifi Mo. >");
  1361. DisplayValueToLcm(__csu_ver_string, value, sizeof(value));
  1362. memset(value, 0x00, sizeof(value));
  1363. if (mode == 0) {
  1364. sprintf((char *)value, "disable");
  1365. } else if (mode == 1) {
  1366. sprintf((char *)value, "station");
  1367. } else if (mode == 2) {
  1368. sprintf((char *)value, "AP");
  1369. }
  1370. DisplayValueToLcm(__csu_ver_value, value, sizeof(value));
  1371. } else {
  1372. ChangeDisplay2Value(__csu_ver_string, _disappear);
  1373. ChangeDisplay2Value(__csu_ver_value, _disappear);
  1374. }
  1375. }
  1376. void DisplayInfoEthIp(bool isShow, uint8_t *ip)
  1377. {
  1378. if (isShow) {
  1379. uint8_t value[20];
  1380. memset(value, 0x00, sizeof(value));
  1381. strcpy((char *) value, "Eth IP >");
  1382. DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
  1383. memset(value, 0x00, sizeof(value));
  1384. strcpy((char *) value, (char *) ip);
  1385. DisplayValueToLcm(__eth0_ip_value, value, sizeof(value));
  1386. } else {
  1387. ChangeDisplay2Value(__eth0_ip_string, _disappear);
  1388. ChangeDisplay2Value(__eth0_ip_value, _disappear);
  1389. }
  1390. }
  1391. void Show4GRssi(bool isShow, int dbValue)
  1392. {
  1393. if (isShow) {
  1394. uint8_t value[20];
  1395. memset(value, 0x00, sizeof(value));
  1396. strcpy((char *) value, "RSSI >");
  1397. DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
  1398. memset(value, 0x00, sizeof(value));
  1399. sprintf((char *)value, "%d dBm", dbValue);
  1400. DisplayValueToLcm(__eth0_ip_value, value, sizeof(value));
  1401. } else {
  1402. ChangeDisplay2Value(__eth0_ip_string, _disappear);
  1403. ChangeDisplay2Value(__eth0_ip_value, _disappear);
  1404. }
  1405. }
  1406. void DisplayInfoSN(bool isShow, uint8_t *sn)
  1407. {
  1408. if (isShow) {
  1409. uint8_t value[30];
  1410. memset(value, 0x00, sizeof(value));
  1411. strcpy((char *) value, "SN >");
  1412. DisplayValueToLcm(__sn_string, value, sizeof(value));
  1413. memset(value, 0x00, sizeof(value));
  1414. strcpy((char *) value, (char *) sn);
  1415. DisplayValueToLcm(__sn_value, value, sizeof(value));
  1416. } else {
  1417. ChangeDisplay2Value(__sn_string, _disappear);
  1418. ChangeDisplay2Value(__sn_value, _disappear);
  1419. }
  1420. }
  1421. void ShowWifiRssi(bool isShow, int dbValue)
  1422. {
  1423. if (isShow) {
  1424. uint8_t value[20];
  1425. memset(value, 0x00, sizeof(value));
  1426. strcpy((char *) value, "RSSI >");
  1427. DisplayValueToLcm(__sn_string, value, sizeof(value));
  1428. memset(value, 0x00, sizeof(value));
  1429. sprintf((char *)value, "%d dBm", dbValue);
  1430. DisplayValueToLcm(__sn_value, value, sizeof(value));
  1431. } else {
  1432. ChangeDisplay2Value(__sn_string, _disappear);
  1433. ChangeDisplay2Value(__sn_value, _disappear);
  1434. }
  1435. }
  1436. void DisplayInfoGun1Ver(bool isShow, uint8_t *version)
  1437. {
  1438. if (isShow) {
  1439. uint8_t value[10];
  1440. memset(value, 0x00, sizeof(value));
  1441. strcpy((char *) value, "Ct1 Ver >");
  1442. DisplayValueToLcm(__dc1_ver_string, value, sizeof(value));
  1443. memset(value, 0x00, sizeof(value));
  1444. strcpy((char *) value, (char *) version);
  1445. DisplayValueToLcm(__dc1_ver_value, value, sizeof(value));
  1446. } else {
  1447. ChangeDisplay2Value(__dc1_ver_string, _disappear);
  1448. ChangeDisplay2Value(__dc1_ver_value, _disappear);
  1449. }
  1450. }
  1451. void Show4GMode(bool isShow, uint8_t mode)
  1452. {
  1453. if (isShow) {
  1454. uint8_t value[20];
  1455. memset(value, 0x00, sizeof(value));
  1456. strcpy((char *) value, "3/4G Mo. >");
  1457. DisplayValueToLcm(__dc1_ver_string, value, sizeof(value));
  1458. memset(value, 0x00, sizeof(value));
  1459. if (mode == 0) {
  1460. sprintf((char *)value, "disable");
  1461. } else if (mode == 1) {
  1462. sprintf((char *)value, "enable");
  1463. }
  1464. DisplayValueToLcm(__dc1_ver_value, value, sizeof(value));
  1465. } else {
  1466. ChangeDisplay2Value(__dc1_ver_string, _disappear);
  1467. ChangeDisplay2Value(__dc1_ver_value, _disappear);
  1468. }
  1469. }
  1470. void DisplayInfoGun2Ver(bool isShow, uint8_t *version)
  1471. {
  1472. if (isShow) {
  1473. uint8_t value[10];
  1474. memset(value, 0x00, sizeof(value));
  1475. strcpy((char *) value, "Ct2 Ver >");
  1476. DisplayValueToLcm(__dc2_ver_string, value, sizeof(value));
  1477. memset(value, 0x00, sizeof(value));
  1478. strcpy((char *) value, (char *) version);
  1479. DisplayValueToLcm(__dc2_ver_value, value, sizeof(value));
  1480. } else {
  1481. ChangeDisplay2Value(__dc2_ver_string, _disappear);
  1482. ChangeDisplay2Value(__dc2_ver_value, _disappear);
  1483. }
  1484. }
  1485. void Show4GIP(bool isShow, uint8_t *ip)
  1486. {
  1487. if (isShow) {
  1488. uint8_t value[20];
  1489. memset(value, 0x00, sizeof(value));
  1490. strcpy((char *) value, "3/4G IP >");
  1491. DisplayValueToLcm(__dc2_ver_string, value, sizeof(value));
  1492. memset(value, 0x00, sizeof(value));
  1493. strcpy((char *) value, (char *) ip);
  1494. DisplayValueToLcm(__dc2_ver_value, value, sizeof(value));
  1495. } else {
  1496. ChangeDisplay2Value(__dc2_ver_string, _disappear);
  1497. ChangeDisplay2Value(__dc2_ver_value, _disappear);
  1498. }
  1499. }
  1500. void DisplayInfoSpeed(bool isShow, unsigned int fan)
  1501. {
  1502. if (isShow) {
  1503. uint8_t value[10];
  1504. memset(value, 0x00, sizeof(value));
  1505. strcpy((char *) value, "Fan Spd >");
  1506. DisplayValueToLcm(__fan_speed_string, value, sizeof(value));
  1507. memset(value, 0x00, sizeof(value));
  1508. sprintf((char *)value, "%d", fan);
  1509. DisplayValueToLcm(__fan_speed_value, value, sizeof(value));
  1510. } else {
  1511. ChangeDisplay2Value(__fan_speed_string, _disappear);
  1512. ChangeDisplay2Value(__fan_speed_value, _disappear);
  1513. }
  1514. }
  1515. void ShowWifiIP(bool isShow, uint8_t *ip)
  1516. {
  1517. if (isShow) {
  1518. uint8_t value[20];
  1519. memset(value, 0x00, sizeof(value));
  1520. strcpy((char *) value, "Wifi IP >");
  1521. DisplayValueToLcm(__fan_speed_string, value, sizeof(value));
  1522. memset(value, 0x00, sizeof(value));
  1523. strcpy((char *) value, (char *) ip);
  1524. DisplayValueToLcm(__fan_speed_value, value, sizeof(value));
  1525. } else {
  1526. ChangeDisplay2Value(__fan_speed_string, _disappear);
  1527. ChangeDisplay2Value(__fan_speed_value, _disappear);
  1528. }
  1529. }
  1530. void InformationShow()
  1531. {
  1532. if (pSysConfig->ShowInformation == YES) {
  1533. bool show = _isShow = true;
  1534. if (_showInformIndex == 0) {
  1535. DisplayInfoCsuVer(show, pSysInfo->CsuRootFsFwRev);
  1536. DisplayInfoSpeed(show, pSysInfo->SystemFanRotaSpeed);
  1537. DisplayInfoSN(show, pSysConfig->SerialNumber);
  1538. DisplayInfoEthIp(show, pSysConfig->Eth0Interface.EthIpAddress);
  1539. DisplayInfoGun1Ver(show, pSysInfo->Connector1FwRev);
  1540. if (_totalCount > 1) {
  1541. DisplayInfoGun2Ver(show, pSysInfo->Connector2FwRev);
  1542. } else {
  1543. DisplayInfoGun2Ver(false, pSysInfo->Connector2FwRev);
  1544. }
  1545. } else if (_showInformIndex == 1) {
  1546. ShowWifiMode(show, pSysConfig->AthInterface.WifiMode);
  1547. ShowWifiIP(show, pSysConfig->AthInterface.WifiIpAddress);
  1548. ShowWifiRssi(show, pSysConfig->AthInterface.WifiRssi);
  1549. Show4GMode(show, pSysConfig->TelecomInterface.TelcomEnabled);
  1550. Show4GIP(show, pSysConfig->TelecomInterface.TelcomIpAddress);
  1551. Show4GRssi(show, pSysConfig->TelecomInterface.TelcomRssi);
  1552. }
  1553. } else {
  1554. ClearDisplayInfo();
  1555. if (_isShow) {
  1556. _isShow = false;
  1557. _showInformIndex++;
  1558. if (_showInformIndex >= 2) {
  1559. _showInformIndex = 0;
  1560. }
  1561. }
  1562. }
  1563. }
  1564. void showPhihongLogo(bool _show)
  1565. {
  1566. /*
  1567. if( pSysConfig->ModelName[3] == 'U' ) {
  1568. if (pSysConfig->ModelName[12] == 'P' && pSysConfig->ModelName[13] == 'H') {
  1569. ChangeDisplay2Value(_logo, _disappear);
  1570. ChangeDisplay2Value(_logo_cmp, _disappear);
  1571. }
  1572. }
  1573. */
  1574. if (!_show) {
  1575. ChangeDisplay2Value(_logo, _disappear);
  1576. ChangeDisplay2Value(_logo_cmp, _disappear);
  1577. }
  1578. }
  1579. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  1580. {
  1581. struct timeval _end_time;
  1582. gettimeofday(&_end_time, NULL);
  1583. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  1584. }
  1585. void ChangeTimeValue(uint8_t time)
  1586. {
  1587. uint8_t cmd[2];
  1588. uint8_t value[2];
  1589. memset(cmd, 0x00, sizeof(cmd));
  1590. sprintf((char *) value, "%d", time);
  1591. string2ByteArray(value, cmd);
  1592. DisplayValueToLcm(0x1290, cmd, sizeof(cmd));
  1593. }
  1594. void ProcessPageInfo()
  1595. {
  1596. _page_reload = IsPageReloadChk();
  1597. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  1598. struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
  1599. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1600. uint8_t i;
  1601. // 隨插即充 - 可省略該按鈕 //DS60-120 add
  1602. if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
  1603. ChangeDisplay2Value(__ret_home_btn, _back_home_btn);
  1604. if (_totalCount >= 2 && pSysInfo->IsAlternatvieConf == NO) {
  1605. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  1606. } else {
  1607. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  1608. }
  1609. }
  1610. showPhihongLogo(false);
  1611. switch (_currentPage) {
  1612. #if defined DD360Audi
  1613. case _LCM_SELECT_GUN: ////For Audi
  1614. if (pSysInfo->CurGunSelected == 0) {
  1615. ChangeDisplay2Value(__left_gun_map, _left_gun_enable_map);
  1616. ChangeDisplay2Value(__right_gun_map, _right_gun_disable_map);
  1617. } else if (pSysInfo->CurGunSelected == 1) {
  1618. ChangeDisplay2Value(__left_gun_map, _left_gun_disable_map);
  1619. ChangeDisplay2Value(__right_gun_map, _right_gun_enable_map);
  1620. }
  1621. ChangeDisplay2Value(__add_chk_btn, _select_gun_btn);
  1622. break;
  1623. #endif //defined DD360Audi
  1624. case _LCM_IDLE: {
  1625. if (pSysConfig->isRFID) {
  1626. ChangeDisplay2Value(__main_rfid, _main_rfid);
  1627. } else {
  1628. ChangeDisplay2Value(__main_rfid, _main_none_rfid);
  1629. }
  1630. if (pSysConfig->isQRCode) {
  1631. ChangeDisplay2Value(__main_qr, _main_qr);
  1632. } else {
  1633. ChangeDisplay2Value(__qr_code, _disappear);
  1634. ChangeDisplay2Value(__main_qr, _main_none_qr);
  1635. needReloadQr = true;
  1636. }
  1637. if (pSysConfig->isAPP) {
  1638. ChangeDisplay2Value(__main_app, _main_app);
  1639. } else {
  1640. ChangeDisplay2Value(__main_app, _main_none_app);
  1641. }
  1642. #if defined DD360Audi
  1643. if(pSysInfo->CurGunSelected == LEFT_GUN_NUM )
  1644. ChangeDisplay2Value(__show_selectgun_value, _showselectgun_left);
  1645. else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM )
  1646. ChangeDisplay2Value(__show_selectgun_value, _showselectgun_right);
  1647. #endif
  1648. //if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
  1649. if (pSysConfig->isQRCode) {
  1650. needReloadQr = false;
  1651. if (pSysConfig->QRCodeMadeMode == NO) {
  1652. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  1653. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1654. } else {
  1655. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  1656. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  1657. }
  1658. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1659. }
  1660. //}
  1661. //DS60-120 add
  1662. bool isCharging = false;
  1663. for (uint8_t i = 0; i < _totalCount; i++) {
  1664. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1665. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  1666. continue;
  1667. }
  1668. isCharging = true;
  1669. break;
  1670. }
  1671. if (isCharging && pSysInfo->IsAlternatvieConf == NO) {
  1672. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  1673. } else {
  1674. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  1675. }
  1676. }
  1677. break;
  1678. case _LCM_AUTHORIZING:
  1679. case _LCM_AUTHORIZ_COMP:
  1680. case _LCM_AUTHORIZ_FAIL: {
  1681. //case _LCM_WAIT_FOR_PLUG: {
  1682. FirstPageChanged();
  1683. #if defined DD360Audi
  1684. if (_currentPage == _LCM_AUTHORIZ_COMP) { ////For Audi
  1685. ChangeBalanceValue(__balance, pSysInfo->CurGunSelected);
  1686. }
  1687. #endif //defined DD360Audi
  1688. }
  1689. break;
  1690. case _LCM_WAIT_FOR_PLUG: {
  1691. #if defined DD360Audi
  1692. if(pSysInfo->CurGunSelected == LEFT_GUN_NUM )
  1693. ChangeDisplay2Value(__show_waitgunplug_value, _showwaitgunplug_left);
  1694. else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM )
  1695. ChangeDisplay2Value(__show_waitgunplug_value, _showwaitgunplug_right);
  1696. #endif
  1697. FirstPageChanged();
  1698. if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
  1699. // 新增隨插即充功能預設在等待插槍頁面在開啟
  1700. ChangeDisplay2Value(__ret_home_btn, _disappear);
  1701. bool isCharging = false;
  1702. for (uint8_t i = 0; i < _totalCount; i++) {
  1703. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1704. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  1705. continue;
  1706. }
  1707. isCharging = true;
  1708. break;
  1709. }
  1710. if (isCharging && pSysInfo->IsAlternatvieConf == NO) {
  1711. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  1712. } else {
  1713. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  1714. }
  1715. } else {
  1716. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  1717. }
  1718. }
  1719. break;
  1720. case _LCM_PRE_CHARGE:
  1721. case _LCM_CHARGING:
  1722. case _LCM_COMPLETE: {
  1723. bool isShowAc = false;
  1724. uint8_t gunTargetIndex = 0;
  1725. if (acgunCount > 0) {
  1726. gunTargetIndex = 2;
  1727. if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  1728. isShowAc = true;
  1729. //ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_light); //DS60-120 remove
  1730. if (_currentPage == _LCM_COMPLETE) {
  1731. ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _actype_light_cmp);
  1732. } else {
  1733. ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _actype_light);
  1734. }
  1735. if (_currentPage == _LCM_CHARGING) {
  1736. ChangeAcBattMapAndValue(_LCM_CHARGING);
  1737. if (pAcChargingInfo->PresentChargedDuration >= 0 &&
  1738. pAcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  1739. ChangeRemainTime(pAcChargingInfo->PresentChargedDuration);
  1740. } else {
  1741. ChangeRemainTime(0);
  1742. }
  1743. if (pAcChargingInfo->PresentChargingPower >= 0.1 &&
  1744. pAcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1745. ChangeChargingPowerValue(pAcChargingInfo->PresentChargingPower);
  1746. } else {
  1747. ChangeChargingPowerValue(0);
  1748. }
  1749. if (pAcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1750. pAcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1751. ChangeChargingEnergyValue(pAcChargingInfo->PresentChargedEnergy);
  1752. } else {
  1753. ChangeChargingEnergyValue(0);
  1754. }
  1755. if (strcmp((char *)pAcChargingInfo->StartUserId, "") == 0 ||
  1756. pSysConfig->StopChargingByButton == YES) {
  1757. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
  1758. } else {
  1759. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
  1760. }
  1761. } else if (_currentPage == _LCM_COMPLETE) {
  1762. ChangeAcBattMapAndValue(_LCM_COMPLETE);
  1763. if (pAcChargingInfo->PresentChargedDuration >= 0 &&
  1764. pAcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  1765. ChangeRemainTime(pAcChargingInfo->PresentChargedDuration);
  1766. } else {
  1767. ChangeRemainTime(0);
  1768. }
  1769. if (pAcChargingInfo->PresentChargingPower >= 0.1 &&
  1770. pAcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1771. ChangeChargingPowerValue(pAcChargingInfo->PresentChargingPower);
  1772. } else {
  1773. ChangeChargingPowerValue(0);
  1774. }
  1775. if (pAcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1776. pAcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1777. ChangeChargingEnergyValue(pAcChargingInfo->PresentChargedEnergy);
  1778. if (pSysConfig->BillingData.isBilling &&
  1779. pAcChargingInfo->ChargingFee >= 0) {
  1780. ChangeChargingFeeValue(pAcChargingInfo->ChargingFee);
  1781. }
  1782. } else {
  1783. ChangeChargingEnergyValue(0);
  1784. if (pSysConfig->BillingData.isBilling) {
  1785. ChangeChargingFeeValue(0);
  1786. }
  1787. }
  1788. if (!pSysConfig->BillingData.isBilling) {
  1789. ChangeDisplay2Value(__charging_fee_map, _disappear);
  1790. ChangeDisplay2Value(__charging_fee_tx, _disappear);
  1791. } else {
  1792. ChangeDisplay2Value(__charging_fee_map, _money_map);
  1793. }
  1794. }
  1795. } else {
  1796. //ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_dark); //DS60-120 remove
  1797. if (_currentPage == _LCM_COMPLETE) {
  1798. ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _actype_dark_cmp);
  1799. } else {
  1800. ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _actype_dark);
  1801. }
  1802. }
  1803. } else {
  1804. //ChangeDisplay2Value(__gun_type_index + (2 * 2), _disappear); //DS60-120 remove
  1805. if (_totalCount > 1) {
  1806. gunTargetIndex = 2;
  1807. ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _disappear);
  1808. ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _disappear);
  1809. }
  1810. }
  1811. gunTargetIndex = 0; //DS60-120 add
  1812. for (uint8_t i = 0; i < _totalCount; i++) {
  1813. if (_totalCount == 1 && acgunCount <= 0) { //DS60-120 add
  1814. gunTargetIndex = 2;
  1815. } else {
  1816. gunTargetIndex = i;
  1817. }
  1818. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1819. switch (pDcChargingInfo->Type) {
  1820. case _Type_Chademo: {
  1821. if (pSysInfo->CurGunSelected == i && !isShowAc) {
  1822. if (_currentPage == _LCM_COMPLETE) {
  1823. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_light_cmp);
  1824. } else {
  1825. ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
  1826. }
  1827. } else {
  1828. if (_currentPage == _LCM_COMPLETE) {
  1829. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_dark_cmp);
  1830. } else {
  1831. ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
  1832. }
  1833. }
  1834. }
  1835. break;
  1836. case _Type_GB: {
  1837. if (pSysInfo->CurGunSelected == i && !isShowAc) {
  1838. if (_currentPage == _LCM_COMPLETE) {
  1839. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_light_cmp);
  1840. } else {
  1841. ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_light);
  1842. }
  1843. } else {
  1844. if (_currentPage == _LCM_COMPLETE) {
  1845. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_dark_cmp);
  1846. } else {
  1847. ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_dark);
  1848. }
  1849. }
  1850. }
  1851. break;
  1852. case _Type_CCS_2: {
  1853. if (pSysInfo->CurGunSelected == i && !isShowAc) {
  1854. if (_currentPage == _LCM_COMPLETE) {
  1855. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_light_cmp);
  1856. } else {
  1857. ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
  1858. }
  1859. } else {
  1860. if (_currentPage == _LCM_COMPLETE) {
  1861. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_dark_cmp);
  1862. } else {
  1863. ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
  1864. }
  1865. }
  1866. }
  1867. break;
  1868. }
  1869. if (_currentPage == _LCM_PRE_CHARGE && !isShowAc) {
  1870. if (pSysInfo->CurGunSelected == i) {
  1871. ChangeBattMapAndValue(_currentPage, pDcChargingInfo->EvBatterySoc);
  1872. uint8_t precharg_time = (GetPreChargeTimeoutValue(pDcChargingInfo->PreChargeTimer)/1) / uSEC_VAL;
  1873. if (precharg_time > PRECHARGING_TTIMEOUT)
  1874. precharg_time = PRECHARGING_TTIMEOUT;
  1875. ChangeTimeValue(PRECHARGING_TTIMEOUT- precharg_time);
  1876. if (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
  1877. pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EV) {
  1878. pDcChargingInfo->_SaftyDetect = false;
  1879. ChangeDisplay2Value(__show_handshark_value, _show_handshark_light);
  1880. ChangeDisplay2Value(__show_GFD_value, _show_GFD_dark);
  1881. ChangeDisplay2Value(__show_precharge_value, _show_precharge_dark);
  1882. } else if (pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) {
  1883. if (pDcChargingInfo->Type == _Type_Chademo || pDcChargingInfo->Type == _Type_GB) {
  1884. if (pDcChargingInfo->_SaftyDetect == false ) {
  1885. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  1886. ChangeDisplay2Value(__show_GFD_value, _show_GFD_light);
  1887. ChangeDisplay2Value(__show_precharge_value, _show_precharge_dark);
  1888. if (pDcChargingInfo->EvBatterytargetVoltage == 0)
  1889. pDcChargingInfo->_SaftyDetect = true;
  1890. } else {
  1891. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  1892. ChangeDisplay2Value(__show_GFD_value, _show_GFD_dark);
  1893. ChangeDisplay2Value(__show_precharge_value, _show_precharge_light);
  1894. }
  1895. } else {
  1896. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  1897. ChangeDisplay2Value(__show_GFD_value, _show_GFD_light);
  1898. ChangeDisplay2Value(__show_precharge_value, _show_precharge_dark);
  1899. }
  1900. } else if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
  1901. pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
  1902. if (pDcChargingInfo->_SaftyDetect == false ) {
  1903. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  1904. ChangeDisplay2Value(__show_GFD_value, _show_GFD_light);
  1905. ChangeDisplay2Value(__show_precharge_value, _show_precharge_dark);
  1906. if (pDcChargingInfo->EvBatterytargetVoltage == 0)
  1907. pDcChargingInfo->_SaftyDetect = true;
  1908. } else {
  1909. ChangeDisplay2Value(__show_handshark_value, _show_handshark_dark);
  1910. ChangeDisplay2Value(__show_GFD_value, _show_GFD_dark);
  1911. ChangeDisplay2Value(__show_precharge_value, _show_precharge_light);
  1912. }
  1913. } else {
  1914. ChangeDisplay2Value(__show_handshark_value, _disappear);
  1915. ChangeDisplay2Value(__show_GFD_value, _disappear);
  1916. ChangeDisplay2Value(__show_precharge_value, _disappear);
  1917. }
  1918. }
  1919. } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
  1920. if (pSysInfo->CurGunSelected == i) {
  1921. ChangeBattMapAndValue(_LCM_CHARGING, pDcChargingInfo->EvBatterySoc);
  1922. if (pDcChargingInfo->PresentChargedDuration >= 0 &&
  1923. pDcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  1924. ChangeRemainTime(pDcChargingInfo->PresentChargedDuration);
  1925. } else {
  1926. ChangeRemainTime(0);
  1927. }
  1928. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  1929. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1930. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  1931. } else {
  1932. ChangeChargingPowerValue(0);
  1933. }
  1934. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1935. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1936. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1937. } else {
  1938. ChangeChargingEnergyValue(0);
  1939. }
  1940. if (strcmp((char *)pDcChargingInfo->StartUserId, "") == 0 ||
  1941. pSysConfig->StopChargingByButton == YES) {
  1942. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
  1943. } else {
  1944. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
  1945. }
  1946. }
  1947. } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
  1948. if (pSysInfo->CurGunSelected == i) {
  1949. ChangeBattMapAndValue(_LCM_COMPLETE, pDcChargingInfo->EvBatterySoc);
  1950. if (pDcChargingInfo->PresentChargedDuration >= 0 &&
  1951. pDcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  1952. ChangeRemainTime(pDcChargingInfo->PresentChargedDuration);
  1953. } else {
  1954. ChangeRemainTime(0);
  1955. }
  1956. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  1957. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1958. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  1959. } else {
  1960. ChangeChargingPowerValue(0);
  1961. }
  1962. #if 1
  1963. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1964. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1965. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1966. if (pSysConfig->BillingData.isBilling &&
  1967. pDcChargingInfo->ChargingFee >= 0) {
  1968. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  1969. ChangeBalanceValue(__remain_balance, i);
  1970. }
  1971. } else {
  1972. ChangeChargingEnergyValue(0);
  1973. if (pSysConfig->BillingData.isBilling) {
  1974. ChangeChargingFeeValue(0);
  1975. ChangeBalanceValue(__remain_balance, i);
  1976. }
  1977. }
  1978. #else
  1979. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1980. if (pSysConfig->BillingData.isBilling &&
  1981. pDcChargingInfo->ChargingFee >= 0) {
  1982. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  1983. ChangeBalanceValue(__remain_balance, i);
  1984. }
  1985. #endif // 0
  1986. if (!pSysConfig->BillingData.isBilling) {
  1987. ChangeDisplay2Value(__charging_fee_map, _disappear);
  1988. ChangeDisplay2Value(__charging_fee_tx, _disappear);
  1989. } else {
  1990. ChangeDisplay2Value(__charging_fee_map, _money_map);
  1991. }
  1992. #ifdef DD360Audi
  1993. // Warming Occur in prepare or precharing state, turn into complete mode
  1994. if (pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason) {
  1995. RunFullTargetFunction(true);
  1996. } else {
  1997. RunFullTargetFunction(false);
  1998. if (pDcChargingInfo->Replug_flag) {
  1999. RunReplugStringFunction(true);
  2000. } else {
  2001. RunReplugStringFunction(false);
  2002. }
  2003. }
  2004. #endif
  2005. }
  2006. }
  2007. }
  2008. // gun btn and QR code
  2009. if (_totalCount + acgunCount >= 2 && _currentPage) {
  2010. uint8_t index = 0;
  2011. for (index = 0; index < _totalCount; index++) {
  2012. if (pSysInfo->CurGunSelected != index) {
  2013. break;
  2014. }
  2015. }
  2016. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  2017. if (pDcChargingInfo->SystemStatus == S_IDLE ||
  2018. pDcChargingInfo->SystemStatus == S_RESERVATION ||
  2019. pDcChargingInfo->SystemStatus == S_BOOTING) {
  2020. if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
  2021. if (pSysConfig->isQRCode) {
  2022. needReloadQr = false;
  2023. //ChangeQrCode_Charge((char *)pSysConfig->SystemId); //DS60-120 remove
  2024. if (pSysConfig->QRCodeMadeMode == NO) {
  2025. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  2026. ChangeQrCode_Charge((char *)pSysConfig->SystemId);
  2027. } else {
  2028. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  2029. ChangeQrCode_Charge((char *)pSysConfig->QRCodeContent);
  2030. }
  2031. }
  2032. }
  2033. }
  2034. }
  2035. }
  2036. break;
  2037. case _LCM_FIX:
  2038. #if defined DD360Audi
  2039. // For Emergency Button
  2040. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == 1) {
  2041. ChangeToOtherPage(_LCM_EMERGENCY);
  2042. break;
  2043. }
  2044. // For Network Disconnect
  2045. for (i = 0; i < pSysWarning->WarningCount; i++) {
  2046. if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0 ||
  2047. memcmp(&pSysWarning->WarningCode[i][0], "042304", 6) == 0) {
  2048. ChangeToOtherPage(_LCM_DISCONNECT);
  2049. break;
  2050. }
  2051. }
  2052. #endif
  2053. break;
  2054. }
  2055. }
  2056. void ChangeDisplayMoneyInfo()
  2057. {
  2058. uint8_t curGun = pSysInfo->CurGunSelected;
  2059. if (pSysConfig->BillingData.isBilling) {
  2060. struct timeb csuTime;
  2061. struct tm *tmCSU;
  2062. ftime(&csuTime);
  2063. tmCSU = localtime(&csuTime.time);
  2064. ChangeDisplay2Value(__money_rate_map, _charging_money);
  2065. #if defined DD360Audi
  2066. if (ShmSelectGunInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
  2067. DisplayMoneyRate(ShmSelectGunInfo->PricesInfo[curGun].UserPrices);
  2068. } else {
  2069. #endif //defined DD360Audi
  2070. if (tmCSU->tm_hour <= 23) {
  2071. pSysConfig->BillingData.Cur_fee = pSysConfig->BillingData.Fee[tmCSU->tm_hour];
  2072. DisplayMoneyRate(pSysConfig->BillingData.Cur_fee);
  2073. }
  2074. if (pSysConfig->BillingData.Currency <= 53) {
  2075. DisplayMoneyCur((uint8_t *)GetCurrency(pSysConfig->BillingData.Currency));
  2076. }
  2077. #if defined DD360Audi
  2078. }
  2079. #endif //defined DD360Audi
  2080. } else {
  2081. ChangeDisplay2Value(__money_rate_map, _disappear);
  2082. ChangeDisplay2Value(__money_by_rate, _disappear);
  2083. ChangeDisplay2Value(__money_rate, _disappear);
  2084. }
  2085. }
  2086. /*void Initialization()
  2087. {
  2088. bool isPass = false;
  2089. uint8_t count = 5;
  2090. while (!isPass && count > 0) {
  2091. isPass = true;
  2092. for (uint8_t _index = 0; _index < _totalCount; _index++) {
  2093. if (!FindChargingInfoData(_index, &_chargingInfoData[0])) {
  2094. log_error("LcmComm (main) : FindChargingInfoData false ");
  2095. isPass = false;
  2096. count--;
  2097. break;
  2098. }
  2099. }
  2100. sleep(1);
  2101. }
  2102. isPass = false;
  2103. if (acgunCount > 0) {
  2104. while (!isPass) {
  2105. isPass = true;
  2106. for (uint8_t _index = 0; _index < acgunCount; _index++) {
  2107. if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
  2108. log_error("LcmComm : FindAcChargingInfoData false ");
  2109. isPass = false;
  2110. break;
  2111. }
  2112. }
  2113. sleep(1);
  2114. }
  2115. }
  2116. if (count == 0) {
  2117. log_info("LCM Initialization Gun Fail.............");
  2118. }
  2119. }
  2120. */
  2121. //DS60-120 add
  2122. void DefaultIconStatus()
  2123. {
  2124. for (uint8_t i = 0; i < 3; i++) {
  2125. ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
  2126. }
  2127. if (pSysInfo->IsAlternatvieConf == YES || _totalCount == 1) {
  2128. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  2129. } else {
  2130. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  2131. }
  2132. if (ShmDcCommonData->LcmFwVersion >= 2)
  2133. {
  2134. ChangeDisplay2Value(__logo, _logo);
  2135. ChangeDisplay2Value(__logo_cmp, _logo_cmp);
  2136. } else {
  2137. ChangeDisplay2Value(__logo, _disappear);
  2138. ChangeDisplay2Value(__logo_cmp, _disappear);
  2139. }
  2140. }
  2141. int main(void)
  2142. {
  2143. //if (InitShareMemory() == FAIL) {
  2144. // log_error("InitShareMemory NG");
  2145. //
  2146. // if (ShmStatusCodeData != NULL) {
  2147. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  2148. // }
  2149. // sleep(5);
  2150. // return 0;
  2151. //}
  2152. if (CreateAllCsuShareMemory() == FAIL) {
  2153. log_error("create share memory error");
  2154. return FAIL;
  2155. }
  2156. MappingGunChargingInfo("LCM Control Task");
  2157. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  2158. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  2159. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  2160. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  2161. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  2162. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  2163. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  2164. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  2165. _port = CreateCommunicationLcmPort();
  2166. uint8_t changeWarningPriority = 0;
  2167. uint8_t curWarningCount = 255;
  2168. ChangeBackLight(true);
  2169. _totalCount = pSysConfig->TotalConnectorCount;
  2170. acgunCount = pSysConfig->AcConnectorCount;
  2171. //Initialization();
  2172. //printf("_LCM_COMPLETE ");
  2173. //ChangeToOtherPage(_LCM_COMPLETE);
  2174. //return 0;
  2175. for (uint8_t i = 0; i < 3; i++) {
  2176. ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
  2177. }
  2178. uint8_t _verShowCount = 3;
  2179. DefaultIconStatus(); //DS60-120 add
  2180. while (_port != -1) {
  2181. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  2182. GetDeviceInfoStatus(__lcm_version, 3);
  2183. GetCurrentPage();
  2184. sleep(1);
  2185. #ifndef DD360ComBox
  2186. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  2187. #endif
  2188. if (_verShowCount > 0) {
  2189. log_info("LCM Version = V.%03d \n", ShmDcCommonData->LcmFwVersion);
  2190. _verShowCount--;
  2191. }
  2192. } else {
  2193. //DemoFunction();
  2194. #ifndef DD360ComBox
  2195. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  2196. #endif
  2197. // Warning 處理
  2198. if (curWarningCount != pSysWarning->WarningCount) {
  2199. changeWarningPriority = 0;
  2200. pSysWarning->PageIndex = 0;
  2201. curWarningCount = pSysWarning->WarningCount;
  2202. ChangeWarningFunc();
  2203. } else if (pSysWarning->WarningCount > 5 && changeWarningPriority == 0) {
  2204. // 當有兩頁 Warning 則每隔三秒改變一次
  2205. if (pSysWarning->PageIndex == 0) {
  2206. pSysWarning->PageIndex = 1;
  2207. } else {
  2208. pSysWarning->PageIndex = 0;
  2209. }
  2210. ChangeWarningFunc();
  2211. }
  2212. // 頁面資訊處理
  2213. ProcessPageInfo();
  2214. // 網路 - wifi - 連線訊號處理
  2215. RefreshConnStatus();
  2216. // 換頁處理
  2217. GetCurrentPage(); //DS60-120 add
  2218. ChangeCurPage();
  2219. RefreshPageAnimation(_everyPageRollChange);
  2220. #if defined DD360Audi
  2221. ChangeDisplayMoneyInfo();
  2222. #else
  2223. if (changeWarningPriority == 0) { ////For Audi
  2224. ChangeDisplayMoneyInfo();
  2225. InformationShow();
  2226. }
  2227. #endif //defined DD360Audi
  2228. changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
  2229. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  2230. usleep(100000);
  2231. }
  2232. }
  2233. #ifndef DD360ComBox
  2234. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  2235. #endif
  2236. log_info("Close LCM Uart Port");
  2237. CloseCommunicationLcmPort();
  2238. return FAIL;
  2239. }