12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154 |
- /*
- * Module_LcmControl_Wistron.c
- *
- * Created on: 2021/11/6
- * Author: folus
- */
- #include "Module_LcmControl_Wistron.h"
- #include "define.h"
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct OCPP16Data *ShmOCPP16Data;
- struct OCPP20Data *ShmOCPP20Data;
- ParsingRatedCur modelnameInfo = {0};
- uint8_t gunType[4] = {0};
- struct timespec timer[TMR_IDX_CNT];
- /**
- *
- * @param fmt
- * @return
- */
- int StoreLogMsg(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- time_t CurrentTime;
- struct tm *tm;
- struct timeval tv;
- va_list args;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf,0,sizeof(Buf));
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- gettimeofday(&tv, NULL); // get microseconds, 10^-6
- sprintf(Buf,"echo -n \'[%04d.%02d.%02d %02d:%02d:%02d.%03ld]%s\' >> /Storage/SystemLog/[%04d.%02d]Module_LcmControl_Wistron_Log",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,(tv.tv_usec/1000),
- buffer,
- tm->tm_year+1900,tm->tm_mon+1);
- #ifdef SystemLogMessage
- system((const char*)Buf);
- #endif
- #ifdef ConsloePrintLog
- printf("[%04d.%02d.%02d %02d:%02d:%02d.%03ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,(tv.tv_usec/1000), buffer);
- #endif
- return rc;
- }
- /**
- *
- * @param data
- * @param length
- * @return
- */
- uint32_t crc32(uint8_t *data, uint32_t length)
- {
- uint32_t crc=0xFFFFFFFF;
- for(size_t i=0;i<length;i++)
- {
- char ch=data[i];
- for(size_t j=0;j<8;j++)
- {
- uint32_t b=(ch^crc)&1;
- crc>>=1;
- if(b) crc=crc^0xEDB88320;
- ch>>=1;
- }
- }
- return ~crc;
- }
- /**
- *
- * @param filename
- * @return
- */
- uint32_t getFileCrc32(char *filename)
- {
- uint32_t result = 0;
- int fd = open(filename, O_RDONLY);
- if(fd < 0)
- {
- DEBUG_ERROR("Can not open file %s\n", filename);
- }
- else
- {
- struct stat st;
- stat(filename, &st);
- uint8_t *data;
- data = malloc(st.st_size);
- if(read(fd,data,st.st_size) == st.st_size)
- {
- result = crc32(data, st.st_size);
- close(fd);
- }
- free(data);
- }
- return result;
- }
- /**
- *
- * @param timer
- */
- void refreshStartTimer(struct timespec *timer)
- {
- clock_gettime(CLOCK_MONOTONIC, timer);
- }
- /**
- *
- * @param timer
- * @return
- */
- int getDiffSecNow(struct timespec timer)
- {
- struct timespec timerNow;
- clock_gettime(CLOCK_MONOTONIC, &timerNow);
- return (int)((((unsigned long)(timerNow.tv_sec - timer.tv_sec) * 1000) + ((unsigned long)((timerNow.tv_nsec / 1000000) - (timer.tv_nsec / 1000000))))/1000);
- }
- /**
- *
- * @return
- */
- int InitShareMemory()
- {
- int result = PASS;
- int MeterSMId;
- //Initial ShmSysConfigAndInfo
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
- result = FAIL;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
- result = FAIL;
- }
- else
- {}
- // Initial ShmStatusCodeData
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
- result = FAIL;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
- result = FAIL;
- }
- else
- {}
- // Initial ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
- result = FAIL;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
- result = FAIL;
- }
- else
- {}
- // Initial ShmOCPP20Data
- if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
- result = FAIL;
- }
- else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
- result = FAIL;
- }
- else
- {}
- // Parsing model name to get related info about charger
- if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
- {
- DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
- if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
- ) // 'D' means DC
- {
- // DO series
- for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
- {
- gunType[gun_index] = GUN_TYPE_DO;
- switch(modelnameInfo.ParsingInfo[gun_index].GunType)
- {
- case Gun_Type_Chademo:
- DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
- break;
- case Gun_Type_CCS_2:
- DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
- break;
- case Gun_Type_GB:
- DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
- break;
- case Gun_Type_AC:
- DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
- break;
- default:
- DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
- break;
- }
- }
- }
- else
- {
- for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
- {
- switch(modelnameInfo.ParsingInfo[gun_index].GunType)
- {
- case Gun_Type_Chademo:
- gunType[gun_index] = GUN_TYPE_CHAdeMO;
- DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
- break;
- case Gun_Type_CCS_2:
- gunType[gun_index] = GUN_TYPE_CCS;
- DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
- break;
- case Gun_Type_GB:
- gunType[gun_index] = GUN_TYPE_GBT;
- DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
- break;
- case Gun_Type_AC:
- gunType[gun_index] = GUN_TYPE_AC;
- DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
- break;
- default:
- DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
- break;
- }
- }
- }
- }
- else
- {
- DEBUG_ERROR("Model name parsing fail.\n");
- result = FAIL;
- }
- // Initial all timer
- for(uint8_t idxTmr=0;idxTmr<TMR_IDX_CNT;idxTmr++)
- {
- refreshStartTimer(&timer[idxTmr]);
- }
- return result;
- }
- /**
- *
- * @param mosq
- * @param userdata
- * @param msg
- * @return
- */
- int on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *msg)
- {
- json_object *payload;
- payload = json_tokener_parse(msg->payload);
- if(!is_error(payload))
- {
- /*
- * TODO:
- * 1. Process message depend on receive topic
- * 2. Message maybe could define as JSON format
- */
- if(strstr(msg->topic, "client/connect"))
- {
- sprintf((char*)clientInfo.verHW, "%s", json_object_get_string(json_object_object_get(payload, "HW_version")));
- sprintf((char*)clientInfo.verFW_OS, "%s", json_object_get_string(json_object_object_get(payload, "FW_version_OS")));
- sprintf((char*)clientInfo.verFW_APK, "%s", json_object_get_string(json_object_object_get(payload, "FW_version_APK")));
- sprintf((char*)clientInfo.verFW_UI, "%s", json_object_get_string(json_object_object_get(payload, "FW_version_UI")));
- sprintf((char*)clientInfo.macAddr, "%s", json_object_get_string(json_object_object_get(payload, "MAC_addr")));
- sprintf((char*)clientInfo.orientation, "%s", json_object_get_string(json_object_object_get(payload, "Orientation")));
- DEBUG_INFO("HW_version: %s\n", clientInfo.verHW);
- DEBUG_INFO("FW_version_OS: %s\n", clientInfo.verFW_OS);
- DEBUG_INFO("FW_version_APK: %s\n", clientInfo.verFW_APK);
- DEBUG_INFO("FW_version_UI: %s\n", clientInfo.verFW_UI);
- DEBUG_INFO("MAC_addr: %s\n", clientInfo.macAddr);
- DEBUG_INFO("Orientation: %s\n", clientInfo.orientation);
- }
- else if(strstr(msg->topic, "client/touch"))
- {
- if(json_object_object_get(payload, "touchlist") != NULL)
- {
- for(int idx=0;idx<json_object_array_length(json_object_object_get(payload, "touchlist"));idx++)
- {
- DEBUG_INFO("Touch point-%d(%s-%s)=> x: %s, y: %s\n", idx,
- json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(payload, "touchlist"), idx), "obj_type")),
- json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(payload, "touchlist"), idx), "obj_onClick")),
- json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(payload, "touchlist"), idx), "touch_point_x")),
- json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(payload, "touchlist"), idx), "touch_point_y")));
- }
- }
- }
- else if(strstr(msg->topic, "client/info"))
- {
- if(json_object_object_get(payload, "status") != NULL)
- {
- switch(atoi(json_object_get_string(json_object_object_get(payload, "status"))))
- {
- case 1:
- DEBUG_INFO("Status normal.\n");
- break;
- case 2:
- DEBUG_INFO("Status downloading.\n");
- break;
- case 3:
- DEBUG_INFO("Status uploading.\n");
- break;
- case 4:
- DEBUG_INFO("Status reboot.\n");
- break;
- case 5:
- DEBUG_INFO("Status reset.\n");
- break;
- case 6:
- DEBUG_INFO("Status sleep.\n");
- break;
- case 255:
- DEBUG_INFO("Status fault.\n");
- break;
- default:
- DEBUG_INFO("Unknown status.\n");
- break;
- }
- }
- if(json_object_object_get(payload, "temperature") != NULL)
- {
- DEBUG_INFO("Temperature: %s.\n", json_object_get_string(json_object_object_get(payload, "temperature")));
- }
- if(json_object_object_get(payload, "cpu_temperatue") != NULL)
- {
- DEBUG_INFO("CPU temperature: %s.\n", json_object_get_string(json_object_object_get(payload, "cpu_temperatue")));
- }
- }
- else if(strstr(msg->topic, "client/profile") ||
- strstr(msg->topic, "client/command") ||
- strstr(msg->topic, "client/timesync") ||
- strstr(msg->topic, "client/layout/textview") ||
- strstr(msg->topic, "client/layout/imageview") ||
- strstr(msg->topic, "client/layout/videoview") ||
- strstr(msg->topic, "client/layout/remove"))
- {
- // Skip topic publish from CSU
- }
- else
- {
- DEBUG_INFO("Unknown topic: %s\n", msg->topic);
- DEBUG_INFO("Unknown payload: %s\n", msg->payload);
- }
- }
- else
- {
- DEBUG_WARN("Payload is not JSON format.\n");
- }
- json_object_put(payload);
- return 0;
- }
- /**
- *
- * @param mosq
- * @param obj
- * @param reason_code
- */
- void on_connect(struct mosquitto *mosq, void *obj, int reason_code)
- {
- DEBUG_INFO("on_connect: %s\n", mosquitto_connack_string(reason_code));
- if(reason_code != 0)mosquitto_disconnect(mosq);
- }
- /**
- *
- * @param mosq
- * @param obj
- * @param reason_code
- */
- void on_disconnect(struct mosquitto *mosq, void *obj, int reason_code)
- {
- DEBUG_INFO("on_disconnect: %s\n", mosquitto_connack_string(reason_code));
- if(reason_code != 0)mosquitto_disconnect(mosq);
- }
- /**
- *
- * @param mosq
- * @param obj
- * @param mid
- */
- void on_publish(struct mosquitto *mosq, void *obj, int mid)
- {}
- //==========================================================================
- // Page routine
- //==========================================================================
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Booting(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Idle(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Authorizing(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Preparing(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Charging(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Terminating(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Complete(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Reservation(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Maintain(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Update(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_AlarmFault(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- /**
- *
- * @param targetChargingInfoData
- */
- void page_Unknown(struct ChargingInfoData *targetChargingInfoData)
- {
- /*
- * TODO:
- * 1. Page content
- */
- }
- //==========================================================================
- // Command publish sample routine
- //==========================================================================
- /**
- *
- * @param mosq
- */
- int publish_profile_sample(struct mosquitto *mosq)
- {
- return publish_profile(mosq, PROFILE_CONNECT_TIMEOUT, "10000");
- }
- /**
- *
- * @param mosq
- */
- int publish_upgrade_sample(struct mosquitto *mosq)
- {
- char url[128];
- char chkCrc32[16];
- sprintf(url, "ftp://ftpuser:ftppasswd@%s/mnt/dummy_Image.zip", BROKER_ADDRESS);
- sprintf(chkCrc32, "0x%08X", getFileCrc32("/mnt/dummy_Image.zip"));
- DEBUG_INFO("image file crc32: %s\n", chkCrc32);
- return publish_upgrade(mosq, OTA_TYPE_SDCARD, url, chkCrc32, "V0.01");
- }
- /**
- *
- * @param mosq
- */
- int publish_restart_sample(struct mosquitto *mosq)
- {
- return publish_restart(mosq, FALSE);
- }
- /**
- *
- * @param mosq
- */
- int publish_power_saving_sample(struct mosquitto *mosq)
- {
- return publish_power_saving(mosq, TRUE);
- }
- /**
- *
- * @param mosq
- */
- int publish_back_dimming_sample(struct mosquitto *mosq)
- {
- return publish_back_dimming(mosq, BRIGHTNESS_LEVEL_AUTO);
- }
- /**
- *
- * @param mosq
- */
- int publish_timesync_sample(struct mosquitto *mosq)
- {
- return publish_timesync(mosq);
- }
- /**
- *
- * @param mosq
- */
- int publish_textview_add_sample(struct mosquitto *mosq)
- {
- Text_List textList[2] = {0};
- for(int idx=0;idx<ARRAY_SIZE(textList);idx++)
- {
- textList[idx].textviewIndex = idx;
- sprintf(textList[idx].textString, "%08d", (rand()%99999999+10000000));
- sprintf(textList[idx].textFont, FONT_ARIAL);
- sprintf(textList[idx].textStyle, FONT_STYLE_NORMAL);
- textList[idx].textSize = FONT_SIZE_20PX;
- textList[idx].layout_x = 10;//(rand()%800+100);
- textList[idx].layout_y = 10;//(rand()%800+100);
- }
- return publish_textview_add(mosq, textList, ARRAY_SIZE(textList));
- }
- /**
- *
- * @param mosq
- */
- int publish_imageview_add_sample(struct mosquitto *mosq)
- {
- Image_List imageList[2] = {0};
- for(int idx=0;idx<ARRAY_SIZE(imageList);idx++)
- {
- imageList[idx].imageviewIndex = idx;
- imageList[idx].imgsrc_addr = (rand()%10+0);
- imageList[idx].layout_x = 100;//(rand()%800+100);
- imageList[idx].layout_y = 100;//(rand()%800+100);
- imageList[idx].width = (rand()%800+100);
- imageList[idx].height = (rand()%800+100);
- }
- return publish_imageview_add(mosq, imageList, ARRAY_SIZE(imageList));
- }
- /**
- *
- * @param mosq
- */
- int publish_videoview_add_sample(struct mosquitto *mosq)
- {
- Video_List videoList[2] = {0};
- for(int idx=0;idx<ARRAY_SIZE(videoList);idx++)
- {
- videoList[idx].videoviewIndex = idx;
- videoList[idx].videosrc_addr = 11;//(rand()%10+0);
- videoList[idx].layout_x = 200;//(rand()%800+100);
- videoList[idx].layout_y = 200;//(rand()%800+100);
- videoList[idx].width = (rand()%800+100);
- videoList[idx].height = (rand()%800+100);
- }
- return publish_videoview_add(mosq, videoList, ARRAY_SIZE(videoList));
- }
- /**
- *
- * @param mosq
- */
- int publish_qr_code_image(struct mosquitto *mosq)
- {
- QrCode_List qrCodeList[2] = {0};
- for(int idx=0;idx<ARRAY_SIZE(qrCodeList);idx++)
- {
- qrCodeList[idx].qrCodeIndex = idx;
- sprintf((char*)qrCodeList[idx].qrCodeContent, "djsalkdjskjslkdjsalkdjslkdjsalkdjsal");
- sprintf((char*)qrCodeList[idx].errorCorrection, "M");
- qrCodeList[idx].layout_x = 100;//(rand()%800+100);
- qrCodeList[idx].layout_y = 100;//(rand()%800+100);
- qrCodeList[idx].width = (rand()%800+100);
- qrCodeList[idx].height = (rand()%800+100);
- }
- return publish_qrcodeimage_add(mosq, qrCodeList, ARRAY_SIZE(qrCodeList));
- }
- /**
- *
- * @param mosq
- */
- int publish_view_remove_sample(struct mosquitto *mosq)
- {
- Text_List textList[2] = {0};
- Image_List imageList[2] = {0};
- Video_List videoList[2] = {0};
- QrCode_List qrCodeList[2] = {0};
- // Remove text view
- for(int idx=0;idx<ARRAY_SIZE(textList);idx++)
- {
- textList[idx].textviewIndex = idx;
- }
- // Remove image view
- for(int idx=0;idx<ARRAY_SIZE(imageList);idx++)
- {
- imageList[idx].imageviewIndex = idx;
- }
- // Remove video view
- for(int idx=0;idx<ARRAY_SIZE(videoList);idx++)
- {
- videoList[idx].videoviewIndex = idx;
- }
- // Remove qrCode view
- for(int idx=0;idx<ARRAY_SIZE(qrCodeList);idx++)
- {
- qrCodeList[idx].qrCodeIndex = idx;
- }
- return publish_view_remove(mosq, textList, ARRAY_SIZE(textList), imageList, ARRAY_SIZE(imageList), videoList, ARRAY_SIZE(videoList), qrCodeList, ARRAY_SIZE(qrCodeList));
- }
- /**
- *
- * @param mosq
- */
- int publish_clear_screen_sample(struct mosquitto *mosq)
- {
- return publish_clear_screen(mosq);
- }
- /**
- *
- */
- int publish_audio_volume_sample(struct mosquitto *mosq)
- {
- return publish_audio_volume(mosq, 50);
- }
- /**
- *
- * @param mosq
- * @return
- */
- int publish_trigger_report_status_sample(struct mosquitto *mosq)
- {
- return publish_trigger_report_status(mosq);
- }
- /**
- *
- * @return
- */
- int main(void)
- {
- struct mosquitto *mosq;
- int result;
- //===========================================
- // Initial share memory
- //===========================================
- if(InitShareMemory() == FAIL)
- {
- DEBUG_ERROR("InitShareMemory NG\n");
- sleep(5);
- return FAIL;
- }
- else
- {
- DEBUG_INFO("Share memory initial OK.\n");
- }
- //===========================================
- // Start mosquitto broker
- //===========================================
- system("killall mosquitto");
- sleep(1);
- system("/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d");
- DEBUG_INFO("Broker target: %s:%d\n", BROKER_ADDRESS, BROKER_PORT);
- //===========================================
- // Initialize mosquitto library
- //===========================================
- mosquitto_lib_init();
- //===========================================
- // Initialize subscriber callback
- //===========================================
- if(fork())
- {
- DEBUG_INFO("Initialize subscribe callback function.\n");
- result = mosquitto_subscribe_callback(on_message,
- NULL,
- "client/#",
- QOS_ENSURE_BROKER,
- BROKER_ADDRESS,
- BROKER_PORT,
- NULL,
- TIMEOUT_KEEPALIVE,
- true,
- LOGIN_USER,
- LOGIN_PASSWD,
- NULL,
- NULL);
- if(result)DEBUG_ERROR("Subscribe initialization error: %s\n", mosquitto_strerror(result));
- return -1;
- }
- //===========================================
- // Initialize publisher client instance
- //===========================================
- DEBUG_INFO("Initialize publisher from host side.\n");
- mosq = mosquitto_new(NULL, true, NULL);
- if(mosq == NULL)
- {
- DEBUG_ERROR("Publisher initialization error: Out of memory.\n");
- return -1;
- }
- mosquitto_connect_callback_set(mosq, on_connect);
- mosquitto_disconnect_callback_set(mosq, on_disconnect);
- mosquitto_publish_callback_set(mosq, on_publish);
- //===========================================
- // Publisher connect to broker
- //===========================================
- DEBUG_INFO("Publisher connect to broker.\n");
- result = mosquitto_connect(mosq, BROKER_ADDRESS, BROKER_PORT, TIMEOUT_KEEPALIVE);
- if(result != MOSQ_ERR_SUCCESS)
- {
- mosquitto_destroy(mosq);
- DEBUG_ERROR("Connect broker error: %s\n", mosquitto_strerror(result));
- return -1;
- }
- //===========================================
- // Publisher start loop
- //===========================================
- DEBUG_INFO("Publisher loop start.\n");
- result = mosquitto_loop_start(mosq);
- if(result != MOSQ_ERR_SUCCESS)
- {
- mosquitto_destroy(mosq);
- DEBUG_ERROR("MQTT loop start initialization error: %s\n", mosquitto_strerror(result));
- return -1;
- }
- DEBUG_INFO("Module_LcmControl_Wistron initialized.\n");
- //===========================================
- // Main loop
- //===========================================
- for(;;)
- {
- #ifndef TEST_MODE
- struct ChargingInfoData *targetChargingInfoData;
- uint8_t tempIndex;
- static struct PREVIOUS_DATA
- {
- uint8_t gun_selected;
- uint8_t SystemStatus;
- }previousData;
- // Get selected gun info
- switch(gunType[ShmSysConfigAndInfo->SysInfo.CurGunSelected])
- {
- case GUN_TYPE_CHAdeMO:
- if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
- {
- tempIndex = ((ShmSysConfigAndInfo->SysInfo.CurGunSelected==2) ? 1: 0);
- }
- else
- {
- tempIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- }
- for (int index = 0; index < CHAdeMO_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
- {
- targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
- }
- }
- break;
- case GUN_TYPE_CCS:
- if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
- {
- tempIndex = ((ShmSysConfigAndInfo->SysInfo.CurGunSelected==2) ? 1: 0);
- }
- else
- {
- tempIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- }
- for (int index = 0; index < CCS_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
- {
- targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
- }
- }
- break;
- case GUN_TYPE_GBT:
- if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
- {
- tempIndex = ((ShmSysConfigAndInfo->SysInfo.CurGunSelected==2) ? 1: 0);
- }
- else
- {
- tempIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- }
- for (int index = 0; index < GB_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
- {
- targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
- }
- }
- break;
- case GUN_TYPE_DO:
- tempIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
- {
- targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData;
- }
- }
- break;
- case GUN_TYPE_AC:
- if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
- {
- tempIndex = 2;
- }
- else
- {
- tempIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- }
- for (int index = 0; index < AC_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
- {
- targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.AcChargingData[index];
- }
- }
- break;
- case GUN_TYPE_UNKNOWN:
- default:
- break;
- }
- // If selected gun or system status changed, clear page all content
- if((previousData.gun_selected != ShmSysConfigAndInfo->SysInfo.CurGunSelected) ||
- (previousData.SystemStatus != targetChargingInfoData->SystemStatus))
- {
- publish_clear_screen(mosq);
- previousData.gun_selected = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- previousData.SystemStatus = targetChargingInfoData->SystemStatus;
- }
- // Display page content depend on selected gun system status
- switch(targetChargingInfoData->SystemStatus)
- {
- case SYS_MODE_BOOTING:
- page_Booting(targetChargingInfoData);
- break;
- case SYS_MODE_IDLE:
- page_Idle(targetChargingInfoData);
- break;
- case SYS_MODE_AUTHORIZING:
- page_Authorizing(targetChargingInfoData);
- break;
- case SYS_MODE_PREPARING:
- page_Preparing(targetChargingInfoData);
- break;
- case SYS_MODE_CHARGING:
- page_Charging(targetChargingInfoData);
- break;
- case SYS_MODE_TERMINATING:
- page_Terminating(targetChargingInfoData);
- break;
- case SYS_MODE_COMPLETE:
- page_Complete(targetChargingInfoData);
- break;
- case SYS_MODE_RESERVATION:
- page_Reservation(targetChargingInfoData);
- break;
- case SYS_MODE_MAINTAIN:
- page_Maintain(targetChargingInfoData);
- break;
- case SYS_MODE_UPDATE:
- page_Update(targetChargingInfoData);
- break;
- case SYS_MODE_ALARM:
- case SYS_MODE_FAULT:
- page_AlarmFault(targetChargingInfoData);
- break;
- default:
- page_Unknown(targetChargingInfoData);
- break;
- }
- #else
- // For test command
- char cmd[128];
- system("clear");
- memset(cmd, 0x00, ARRAY_SIZE(cmd));
- printf("\n ===== main menu ==================================");
- printf("\n 1: publish_profile_sample.");
- printf("\n 2: publish_upgrade_sample.");
- printf("\n 3: publish_restart_sample.");
- printf("\n 4: publish_power_saving_sample.");
- printf("\n 5: publish_back_dimming_sample.");
- printf("\n 6: publish_timesync.");
- printf("\n 7: publish_textview_add_sample.");
- printf("\n 8: publish_imageview_add_sample.");
- printf("\n 9: publish_videoview_add_sample.");
- printf("\n 10: publish_view_remove_sample.");
- printf("\n 11: publish_clear_screen.");
- printf("\n 12: publish_audio_volume.");
- printf("\n 13: publish_trigger_report_status.");
- printf("\n 14: publish_qr_code_image.");
- printf("\n ==================================================");
- printf("\n Please input item to test: ");
- scanf("%s", &cmd[0]);
- switch(atoi(cmd))
- {
- case 1:
- publish_profile_sample(mosq);
- break;
- case 2:
- publish_upgrade_sample(mosq);
- break;
- case 3:
- publish_restart_sample(mosq);
- break;
- case 4:
- publish_power_saving_sample(mosq);
- break;
- case 5:
- publish_back_dimming_sample(mosq);
- break;
- case 6:
- publish_timesync_sample(mosq);
- break;
- case 7:
- publish_textview_add_sample(mosq);
- break;
- case 8:
- publish_imageview_add_sample(mosq);
- break;
- case 9:
- publish_videoview_add_sample(mosq);
- break;
- case 10:
- publish_view_remove_sample(mosq);
- break;
- case 11:
- publish_clear_screen_sample(mosq);
- break;
- case 12:
- publish_audio_volume_sample(mosq);
- break;
- case 13:
- publish_trigger_report_status_sample(mosq);
- case 14:
- publish_qr_code_image(mosq);
- break;
- }
- #endif
- usleep(500000);
- }
- mosquitto_lib_cleanup();
- return -1;
- }
|