Module_LcmControl.c 85 KB

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