Module_LcmControl.c 96 KB

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