/* * Module_Wifi.c * * Created on: 2020-01-14 * Update on: 2023-02-01 * Author: Jerry Wang, Eason Yang, Folus Wen * Version: V0.26 * * Issue tracking: * 1. Set AP mode should be waiting for 30 seconds. * 2. If use web site change Station mode to Access point mode,there are probability TCP 54089 will disppear. * * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "define.h" #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define is_error(ptr) ((unsigned long)ptr > (unsigned long)-4000L) #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0])) #define PASS 1 #define FAIL -1 #define ON 1 #define OFF 0 #define YES 1 #define NO 0 #define true 1 #define false 0 #define IP_TYPE_DHCP 0 #define IP_TYPE_STATIC 1 #define AUTH_TYPE_NONE 0 #define AUTH_TYPE_WEP 1 #define AUTH_TYPE_WPAPSK 2 #define AUTH_TYPE_WPA2PSK 3 #define WIFI_MODE_DISABLE 0 #define WIFI_MODE_STA 1 #define WIFI_MODE_AP 2 #define WIFI_MODE_ADHOC 3 #define STA_STATE_INIT 0 #define STA_STATE_DEVICE_DETECT 1 #define STA_STATE_AP_CONNECTED 2 #define STA_STATE_INTERNET_CHECKING 3 #define AP_STATE_INIT 0 #define AP_STATE_DEVICE_DETECT 1 #define AP_STATE_AP_START 2 #define AP_STATE_SERVER_LISTEN 3 #define LISTEN_PORT_UDP 54088 #define LISTEN_PORT_TCP 54089 #define CONNECTION_LIMIT 3 #define MtdBlockSize 0x300000 #define REGISTER 0x01 #define CLEAR_REGISTER 0x02 #define UBLOX //#define MT7601U #define DEBUG #define DB_FILE_PUK "/Storage/ChargeLog/puk_pin_list.db" #define DB_FILE_CHARGING "/Storage/ChargeLog/localCgargingRecord.db" enum WIFI_COMMAND { WIFI_CMD_LOGIN_SIGNIN = 0x01, WIFI_CMD_LOGIN_AUTH_PUK = 0x02, WIFI_CMD_LOGIN_GET_USER_ID = 0x03, WIFI_CMD_PROTOCOL_VERSION = 0x04, WIFI_CMD_GET_MODEL_NAME = 0x0d, WIFI_CMD_GET_SERIAL_NUMBER = 0x0e, WIFI_CMD_GET_SYSTEM_TIME = 0x0f, WIFI_CMD_GET_WHITE_CARD = 0x12, WIFI_CMD_GET_SYS_ALARM_CODE = 0x15, WIFI_CMD_GET_SYS_ID = 0x16, WIFI_CMD_GET_RATING_CURRENT = 0x17, WIFI_CMD_GET_VER_RFS = 0x1e, WIFI_CMD_GET_VER_PRIMARY_CSU = 0x1f, WIFI_CMD_GET_VER_LCM = 0x20, WIFI_CMD_GET_PSU_COUNT = 0x21, WIFI_CMD_GET_VER_PSU = 0x22, WIFI_CMD_GET_VER_AUX_POWER = 0x23, WIFI_CMD_GET_VER_FAN = 0x24, WIFI_CMD_GET_VER_RELAY = 0x25, WIFI_CMD_GET_VER_TELECOMM = 0x26, WIFI_CMD_GET_EVSE_CONFIG = 0x30, WIFI_CMD_GET_GUN_STS = 0x32, WIFI_CMD_GET_GUN_USER = 0x33, WIFI_CMD_GET_SCHEDULE = 0x36, WIFI_CMD_GET_NETWORK_STS = 0x41, WIFI_CMD_GET_ETH_DHCP = 0x42, WIFI_CMD_GET_ETH_MAC = 0x44, WIFI_CMD_GET_ETH_IP = 0x45, WIFI_CMD_GET_ETH_SUBMASK = 0x47, WIFI_CMD_GET_ETH_GATEWAY = 0x49, WIFI_CMD_GET_WIFI_MODE = 0x54, WIFI_CMD_GET_WIFI_SSID = 0x56, WIFI_CMD_GET_WIFI_PASSWD = 0x58, WIFI_CMD_GET_WIFI_RSSI = 0x5a, WIFI_CMD_GET_WIFI_DHCP = 0x5b, WIFI_CMD_GET_WIFI_MAC = 0x5d, WIFI_CMD_GET_WIFI_IP = 0x5e, WIFI_CMD_GET_WIFI_NETMASK = 0x60, WIFI_CMD_GET_WIFI_GATEWAY = 0x62, WIFI_CMD_GET_TELE_APN = 0x6b, WIFI_CMD_GET_TELE_RSSI = 0x6d, WIFI_CMD_GET_TELE_CHAP_ID = 0x6e, WIFI_CMD_GET_TELE_CHAP_PASSWD = 0x70, WIFI_CMD_GET_TELE_IMEI = 0x72, WIFI_CMD_GET_TELE_IMSI = 0x73, WIFI_CMD_GET_TELE_SIM_STS = 0x74, WIFI_CMD_GET_TELE_MODE = 0x75, WIFI_CMD_GET_TELE_IP = 0x76, WIFI_CMD_SET_SYSTEM_TIME = 0x10, WIFI_CMD_SET_WHITE_CARD = 0x13, WIFI_CMD_SET_FACTORY_RESET = 0x14, WIFI_CMD_SET_EVSE_CONFIG = 0x31, WIFI_CMD_SET_CHARGING_START = 0x34, WIFI_CMD_SET_CHARGING_STOP = 0x35, WIFI_CMD_SET_SCHEDULE = 0x37, WIFI_CMD_SET_ETH_CONFIG = 0x43, WIFI_CMD_SET_ETH_IP = 0x46, WIFI_CMD_SET_ETH_SUBMASK = 0x48, WIFI_CMD_SET_ETH_GATEWAY = 0x4a, WIFI_CMD_SET_WIFI_MODE = 0x55, WIFI_CMD_SET_WIFI_SSID = 0x57, WIFI_CMD_SET_WIFI_PASSWD = 0x59, WIFI_CMD_SET_WIFI_DHCP = 0x5c, WIFI_CMD_SET_WIFI_IP = 0x5f, WIFI_CMD_SET_WIFI_NETMASK = 0x61, WIFI_CMD_SET_WIFI_GATEWAY = 0x63, WIFI_CMD_SET_TELE_APN = 0x6c, WIFI_CMD_SET_TELE_CHAP_ID = 0x6f, WIFI_CMD_SET_TELE_CHAP_PASSWD = 0x71, WIFI_CMD_SET_TELE_IP = 0x77, WIFI_CMD_SET_CONFIRM = 0x81, WIFI_CMD_SET_DISCARD = 0x82, WIFI_CMD_UNKNOW = 0xfe }; enum LOGIN_ROLE { ROLE_UNKNOWN = 0x00, ROLE_MANAGER = 0x01, ROLE_USER = 0x02 }; struct SYS_FLAG { uint8_t isPkill; }Sys_Flag; struct interface_info { int ipType; int authType; int rssi; int cnt_InternetFail; char currentInterface[16]; char currentSSID[256]; char currentPasswd[256]; char currentMAC[24]; char currentIPAddr[24]; char currentNetmask[24]; char currentGateway[24]; char staticIPAddr[24]; }Wifi; struct Display_Request { unsigned char isShowed_IF_info:1; unsigned char isShowed_IP_info:1; }dispReq; struct auth_info { int auth_type; unsigned char ssid[256]; unsigned char passwd[256]; }Wifi_A; struct WIFI_LOGIN_INFO { uint8_t puk[8]; uint8_t loginRole; uint8_t loginId[32]; }wifi_login_info; struct SysConfigAndInfo *ShmSysConfigAndInfo; struct StatusCodeData *ShmStatusCodeData; struct OCPP16Data *ShmOCPP16Data; struct PsuData *ShmPsuData; struct SysConfigData SysConfigTemporarily; int isFindInterface(); int getInterfaceInfo(); int isReachableInternet(); int getLinkQuality(); int setWPAconf(); int restartWPA(); void refreshUSB(); void getParameters(); int Wifi_module_sts = STA_STATE_INIT; int isSetWPA_OK = false; int cnt_pingDNS_Fail; int cnt_getAP_Fail; int cnt_getIP_Fail; sqlite3 *localDb; void trim(char *s); int mystrcmp(char *p1,char *p2); void substr(char *dest, const char* src, unsigned int start, unsigned int cnt); void split(char **arr, char *str, const char *del); int isValidCheckSum(uint8_t *message); char *Support_InterfaceSTA[2] = {"mlan0", "wlan0"}; char *Support_InterfaceAP[1] = {"uap0"}; char *valid_Internet[3] = {"8.8.8.8", "180.76.76.76", "192.168.10.10"}; char *Version_And_Date[2] = {"V0.26","2023-02-01"}; int protocol_Version [] = {0,7,0}; int StoreLogMsg(const char *fmt, ...) { char Buf[4096+256]; char buffer[4096]; time_t CurrentTime; struct tm *tm; 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); sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]Wifi_SystemLog", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer, tm->tm_year+1900,tm->tm_mon+1); #ifdef SystemLogMessage system(Buf); #endif #ifdef ConsloePrintLog printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer); #endif return rc; } int DiffTimeb(struct timeb ST, struct timeb ET) { //return milli-second unsigned int StartTime,StopTime; StartTime=(unsigned int)ST.time; StopTime=(unsigned int)ET.time; return (StopTime-StartTime)*1000+ET.millitm-ST.millitm; } void displayMessage(uint8_t *data, uint16_t len, uint8_t isRX) { #ifdef DEBUG uint8_t output[8192]; if(isRX) { DEBUG_INFO("- RX --------------------------------------------\n"); } else { DEBUG_INFO("- TX --------------------------------------------\n"); } memset(output, 0x00, ARRAY_SIZE(output)); for(uint16_t idx=0;idx<16;idx++) sprintf((char*)output, "%s %02X", output, idx); DEBUG_INFO("%s\n", output); DEBUG_INFO("-------------------------------------------------\n"); for(uint16_t idx = 0;idx0) { sprintf((char*)output, "%s %02X", output, data[idx]); } else { if(idx != 0) DEBUG_INFO("%s\n", output); memset(output, 0x00, ARRAY_SIZE(output)); sprintf((char*)output, "%s %02X", output, data[idx]); } } DEBUG_INFO("%s\n", output); DEBUG_INFO("-------------------------------------------------\n"); #endif } int runShellCmd(const char*cmd) { int result = FAIL; char buf[256]; FILE *fp; fp = popen(cmd, "r"); if(fp != NULL) { while(fgets(buf, sizeof(buf), fp) != NULL) { DEBUG_INFO("%s\n", buf); } result = PASS; } pclose(fp); return result; } //========================================== // Init all share memory //========================================== int InitShareMemory() { int result = PASS; int MeterSMId; //creat ShmSysConfigAndInfo if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n"); #endif result = FAIL; } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n"); #endif result = FAIL; } else {} //creat ShmStatusCodeData if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmStatusCodeData NG\n"); #endif result = FAIL; } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage DEBUG_ERROR("shmat ShmStatusCodeData NG\n"); #endif result = FAIL; } else {} //creat ShmOCPP16Data if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmOCPP16Data NG"); #endif result = FAIL; } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage DEBUG_ERROR("shmat ShmOCPP16Data NG"); #endif result = FAIL; } else {} //creat ShmPsuData if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0) { #ifdef SystemLogMessage DEBUG_ERROR("shmget ShmPsuData NG \n"); #endif result = FAIL; } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage DEBUG_ERROR("shmat ShmPsuData NG \n"); #endif result = FAIL; } return result; } //========================================== // Valid MAC address //========================================== int isMacValid(char *MacAddress) { int result = FALSE; int r,cflags=0; regmatch_t pm[10]; const size_t nmatch = 10; regex_t reg; r=regcomp(®, "^[0-9A-F]\\([0-9A-F]\\:[0-9A-F]\\)\\{5\\}[0-9A-F]$", cflags); if(r==0) { r=regexec(®, MacAddress, nmatch, pm, cflags); } regfree(®); if(r==0)result = TRUE; DEBUG_INFO("MAC(%s) format valid result: %d\n", MacAddress, result); return result; } //========================================== // Get parameters from shared memory //========================================== void getParameters(void) { DEBUG_INFO("============= Configuration ===============\n"); strcpy((char*)Wifi_A.ssid, (const char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid); DEBUG_INFO("Wifi SSID: %s\n", Wifi_A.ssid); strcpy((char*)Wifi_A.passwd, (const char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword); DEBUG_INFO("Wifi Password: %s\n", Wifi_A.passwd); if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress != NULL) strcpy((char*)Wifi.staticIPAddr, (const char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress); DEBUG_INFO("Wifi Static IP: %s\n", Wifi.staticIPAddr); Wifi.ipType = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient; DEBUG_INFO("DHCP client flag: %d\n", Wifi.ipType); DEBUG_INFO("===========================================\n"); } //========================================== // Refresh USB interface //========================================== void refreshUSB(void) { FILE *fp; char cmd[256]; // Get IP address & net mask strcpy(cmd, "echo '1-1'> /sys/bus/usb/drivers/usb/unbind"); fp = popen(cmd, "r"); sleep(2); pclose(fp); strcpy(cmd, "echo '1-1'> /sys/bus/usb/drivers/usb/bind"); fp = popen(cmd, "r"); sleep(5); pclose(fp); } //========================================== // Check wifi interface status //========================================== int isFindInterface() { int result = FAIL; struct ifaddrs *ifaddr, *ifa; if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == WIFI_MODE_AP) { if (getifaddrs(&ifaddr) != FAIL) { for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_PACKET) continue; for(int idx=0;idxifa_name, Support_InterfaceAP[idx]) == PASS) { sprintf(Wifi.currentInterface, "%s", ifa->ifa_name); result = PASS; } } } freeifaddrs(ifaddr); freeifaddrs(ifa); } } else { if (getifaddrs(&ifaddr) != FAIL) { for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_PACKET) continue; for(int idx=0;idxifa_name, Support_InterfaceSTA[idx]) == PASS) { sprintf(Wifi.currentInterface, "%s", ifa->ifa_name); result = PASS; } } } freeifaddrs(ifaddr); freeifaddrs(ifa); } } return result; } //========================================== // Get wifi interface info //========================================== int getInterfaceInfo() { int result = PASS; FILE *fp; char cmd[256]; char buf[512]; char tmp[512]; // Get IP address & net mask strcpy(cmd, "ifconfig "); strcat(cmd, Wifi.currentInterface); fp = popen(cmd, "r"); if(fp == NULL) result = FAIL; else { while(fgets(buf, sizeof(buf), fp) != NULL) { if(strstr(buf, "HWaddr") > 0) { sscanf(buf, "%*s%*s%*s%*s%s", tmp); strcpy(Wifi.currentMAC, tmp); } if(strstr(buf, "inet addr:") > 0) { sscanf(buf, "%*s%s", tmp); substr(Wifi.currentIPAddr, tmp, strspn(tmp, "addr:"), strlen(tmp)-strspn(tmp, "addr:")); sscanf(buf, "%*s%*s%*s%s", tmp); substr(Wifi.currentNetmask, tmp, strspn(tmp, "Mask:"), strlen(tmp)-strspn(tmp, "Mask:")); } } } pclose(fp); // Get gateway fp = popen("ip route", "r"); if(fp == NULL) result = FAIL; else { while(fgets(buf, sizeof(buf), fp) != NULL) { #ifdef UBLOX if((strstr(buf, "default") != NULL) && (strstr(buf, "mlan0") != NULL)) #endif #ifdef MT7601U if((strstr(buf, "default") != NULL) && (strstr(buf, "wlan0") != NULL)) #endif break; } if(strstr(buf, "default") != NULL) { sscanf(buf, "%*s%*s%s", tmp); substr(Wifi.currentGateway, tmp, 0, strlen(tmp)); } } pclose(fp); if(!dispReq.isShowed_IF_info) { DEBUG_INFO("MAC: %s\n", Wifi.currentMAC); dispReq.isShowed_IF_info = true; } if(!dispReq.isShowed_IP_info) { DEBUG_INFO("IP address: %s\n", Wifi.currentIPAddr); DEBUG_INFO("Net mask: %s\n", Wifi.currentNetmask); DEBUG_INFO("Default gateway: %s\n", Wifi.currentGateway); dispReq.isShowed_IP_info = true; } strcpy((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress, (const char*)Wifi.currentIPAddr); strcpy((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress, (const char*)Wifi.currentNetmask); strcpy((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress, (const char*)Wifi.currentGateway); strcpy((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress, (const char*)Wifi.currentMAC); return result; } //========================================== // Check if module connect to wifi AP //========================================== int isConnectAP() { int result = PASS; FILE *fp; char cmd[256]; char buf[512]; // Get IP address & net mask strcpy(cmd, "iwconfig "); strcat(cmd, Wifi.currentInterface); fp = popen(cmd, "r"); if(fp == NULL) result = FAIL; else { if(fgets(buf, sizeof(buf), fp) == NULL) { result = FAIL; } else { while(fgets(buf, sizeof(buf), fp) != NULL) { if(strstr(buf, "Access Point") > 0) { DEBUG_INFO("Link AP info: %s", &buf[strcspn(buf, "Mode")]); } if(strstr(buf, "Not-Associated") > 0) { result = FAIL; } } } } pclose(fp); return result; } //========================================== // Check internet access status //========================================== int isReachableInternet() { int result = FAIL; FILE *fp; char cmd[256]; char buf[512]; //char tmp[512]; for(int idx=0;idx 0) { //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp); if(strstr(buf,"100%") != NULL) { } else { result = PASS; } //DEBUG_INFO("%s",buf); //DEBUG_INFO("%s\n",tmp); } } } pclose(fp); } return result; } //========================================== // Check module soft AP is start up //========================================== int isStartUpAP() { int result = FAIL; FILE *fp; char cmd[256]; char buf[512]; // Get IP address & net mask strcpy(cmd, "/root/uaputl sys_cfg_bss_status"); fp = popen(cmd, "r"); if(fp != NULL) { while(fgets(buf, sizeof(buf), fp) != NULL) { if(strstr(buf, "BSS status = started") > 0) { result = PASS; DEBUG_INFO("AP already start up.\n"); } } } pclose(fp); return result; } //========================================== // Get wifi connection quality //========================================== int getLinkQuality() { int result = FAIL; FILE *fp; char cmd[256]; char buf[512]; char tmp[512]; strcpy(cmd, "iwconfig "); strcat(cmd, Wifi.currentInterface); fp = popen(cmd, "r"); if(fp == NULL) result = FAIL; else { while(fgets(buf, sizeof(buf), fp) != NULL) { if(strstr(buf, "Signal level") > 0) { sscanf(buf, "%*s%*s%*s%s", tmp); substr(tmp, tmp, strspn(tmp, "level="), strlen(tmp)-strspn(tmp, "level=")); Wifi.rssi = atoi(tmp); result = PASS; } } } pclose(fp); return result; } //========================================== // WPA parameter set //========================================== int setWPAconf() { int result = FAIL; char cmdBuf[512]; FILE *pFile; char buffer[500]="ctrl_interface=/var/run/wpa_supplicant\nupdate_config=1\n"; // Stop dhcp client or server sprintf(cmdBuf, "pgrep -f \"udhcpc -i %s\" | xargs kill", Wifi.currentInterface); system(cmdBuf); sprintf(cmdBuf, "pgrep -f \"udhcpd /etc/udhcpd.conf\" | xargs kill"); system(cmdBuf); // Clear wifi configuration file system("cat /dev/null > /etc/wpa.conf"); system("cat /dev/null > /etc/hostapd.conf"); switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode) { case WIFI_MODE_STA: // Fill out configuration value depend on share memory setting if(strlen((const char*)Wifi_A.passwd)>0) { if(strlen((const char*)Wifi_A.passwd)>=8) { strcat(buffer, "network={\n ssid=\""); strcat(buffer, (char*)Wifi_A.ssid); strcat(buffer, "\"\n key_mgmt=WPA-EAP WPA-PSK \n"); strcat(buffer, " bgscan=\"simple:10:-65:3600\" \n"); strcat(buffer, " scan_ssid=1\n"); if((strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0) && isMacValid((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac)) { strcat(buffer, "\n bssid="); strcat(buffer, (char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac); strcat(buffer, "\n psk=\""); } else strcat(buffer, " psk=\""); strcat(buffer, (char*)Wifi_A.passwd); strcat(buffer, "\"\n}\n\n"); } if(strlen((const char*)Wifi_A.passwd)==5 || strlen((const char*)Wifi_A.passwd)==13) { strcat(buffer, "network={\n ssid=\""); strcat(buffer, (char*)Wifi_A.ssid); strcat(buffer, "\"\n key_mgmt=NONE\n"); strcat(buffer, " wep_key0=\""); strcat(buffer, (char*)Wifi_A.passwd); strcat(buffer, "\"\n auth_alg=OPEN SHARED\n"); strcat(buffer, " bgscan=\"simple:10:-65:3600\"\n"); strcat(buffer, " scan_ssid=1\n"); if((strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0) && isMacValid((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac)) { strcat(buffer, "\n bssid="); strcat(buffer, (char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac); } strcat(buffer, "\n}\n\n"); } strcat(buffer, "network={\n ssid=\""); strcat(buffer, (char*)Wifi_A.ssid); strcat(buffer, "\"\n key_mgmt=NONE"); strcat(buffer, "\n bgscan=\"simple:10:-65:3600\""); strcat(buffer, "\n scan_ssid=1"); if((strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0) && isMacValid((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac)) { strcat(buffer, "\n bssid="); strcat(buffer, (char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac); } strcat(buffer, "\n}"); } else { strcat(buffer, "network={\n ssid=\""); strcat(buffer, (char*)Wifi_A.ssid); strcat(buffer, "\"\n key_mgmt=NONE"); strcat(buffer, "\n bgscan=\"simple:10:-65:3600\""); strcat(buffer, "\n scan_ssid=1"); if((strlen((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0) && isMacValid((char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac)) { strcat(buffer, "\n bssid="); strcat(buffer, (char*)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac); } strcat(buffer, "\n}"); } // Configuration value write to /etc/wpa.conf pFile = fopen("/etc/wpa.conf","w"); fwrite(buffer,strlen(buffer), 1, pFile); fclose(pFile); // Restart wpa_supplicant sprintf(cmdBuf, "pgrep -f \"wpa_supplicant\" | xargs kill"); system(cmdBuf); #ifdef UBLOX sprintf(cmdBuf, "mlanutl mlan0 hostcmd /root/u-blox_tools/ed_mac_ctrl_V1_8801.conf ed_mac_ctrl"); system(cmdBuf); sprintf(cmdBuf, "mlanutl mlan0 regrdwr 2 0x70"); system(cmdBuf); sprintf(cmdBuf, "mlanutl mlan0 deepsleep 0"); system(cmdBuf); sprintf(cmdBuf, "mlanutl mlan0 psmode 0"); system(cmdBuf); #endif sprintf(cmdBuf, "/root/wpa_supplicant -i %s -c /etc/wpa.conf -B", Wifi.currentInterface); system(cmdBuf); // Stop wifi AP sprintf(cmdBuf, "pgrep -f \"hostapd\" | xargs kill"); system(cmdBuf); sleep(5); // Wifi IP set by DHCP client or static if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient==0) { sprintf(cmdBuf, "/sbin/udhcpc -i %s -x hostname:CSU3_%s -s /root/dhcp_script/wifi.script > /dev/null &", Wifi.currentInterface, ShmSysConfigAndInfo->SysConfig.SystemId); system(cmdBuf); } else { memset(cmdBuf, 0, ARRAY_SIZE(cmdBuf)); sprintf(cmdBuf,"/sbin/ifconfig %s %s netmask %s", Wifi.currentInterface, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress); system(cmdBuf); memset(cmdBuf, 0, ARRAY_SIZE(cmdBuf)); sprintf(cmdBuf,"route add default gw %s %s ", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress, Wifi.currentInterface); system(cmdBuf); DEBUG_INFO("Setting %s static IP to %s submask to %s gateway to %s...\n", Wifi.currentInterface, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress); } break; case WIFI_MODE_AP: // Stop dhcp client or server sprintf(cmdBuf, "pgrep -f \"udhcpc -i %s\" | xargs kill", Wifi.currentInterface); system(cmdBuf); sprintf(cmdBuf, "pgrep -f \"udhcpd /etc/udhcpd.conf\" | xargs kill"); system(cmdBuf); // Restart wpa_supplicant sprintf(cmdBuf, "pgrep -f \"wpa_supplicant\" | xargs kill"); system(cmdBuf); sprintf(cmdBuf, "pgrep -f \"hostapd\" | xargs kill"); system(cmdBuf); sprintf(cmdBuf, "echo interface=uap0 >> /etc/hostapd.conf"); system(cmdBuf); sprintf(cmdBuf, "echo driver=nl80211 >> /etc/hostapd.conf"); system(cmdBuf); sprintf(cmdBuf, "echo ssid=%s%s >> /etc/hostapd.conf", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber); system(cmdBuf); sprintf(cmdBuf, "echo channel=6 >> /etc/hostapd.conf"); system(cmdBuf); sprintf(cmdBuf, "echo wpa=2 >> /etc/hostapd.conf"); system(cmdBuf); sprintf(cmdBuf, "echo wpa_passphrase=%s%s >> /etc/hostapd.conf", ShmSysConfigAndInfo->SysConfig.SerialNumber, ShmSysConfigAndInfo->SysConfig.ModelName); system(cmdBuf); sprintf(cmdBuf, "echo wpa_key_mgmt=WPA-PSK >> /etc/hostapd.conf"); system(cmdBuf); sprintf(cmdBuf, "echo wpa_pairwise=CCMP >> /etc/hostapd.conf"); system(cmdBuf); sprintf(cmdBuf, "echo ignore_broadcast_ssid=%d >> /etc/hostapd.conf", ((ShmSysConfigAndInfo->SysConfig.AthInterface.WifiBroadcastSsid^1)==0?0:1)); system(cmdBuf); sprintf(cmdBuf, "hostapd /etc/hostapd.conf -B"); system(cmdBuf); sleep(5); // Set wifi AP ip address sprintf(cmdBuf, "ifconfig %s 192.168.10.10", Wifi.currentInterface); system(cmdBuf); DEBUG_INFO("Setting %s static IP to 192.168.10.10...\n", Wifi.currentInterface); // Start DHCP server if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpServer==0) { sprintf(cmdBuf, "/usr/sbin/udhcpd /etc/udhcpd.conf > /dev/null &"); system(cmdBuf); } break; case WIFI_MODE_ADHOC: break; case WIFI_MODE_DISABLE: default: break; } result = PASS; return result; } //========================================== // UDP socket server routine //========================================== int split2int(char *dest, char *src, const char *flag, int base) { uint8_t result = 0; char *s = strtok(src, flag); while(s != NULL) { *dest++ = (base==10?atoi(s):strtol(s, NULL, 16)); s = strtok(NULL, flag); result++; } return result; } uint8_t parseIP(uint8_t *ip) { uint8_t result = false; const char *flag_dot = "."; int8_t buf[16]; memcpy(buf, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress, ARRAY_SIZE(buf)); if(split2int((char*)ip , (char*)buf, flag_dot, 10)==4) result = PASS; return result; } uint8_t parseMAC(uint8_t *mac) { uint8_t result = false; const char *flag_colon = ":"; int8_t buf[18]; memcpy(buf, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress, ARRAY_SIZE(buf)); if(split2int((char*)mac , (char*)buf, flag_colon, 16)==6) result = PASS; return result; } int udpSocketServerStart(void) { int sockFd; struct sockaddr_in servaddr; struct sockaddr_in peeraddr; socklen_t peerlen = sizeof(peeraddr); uint8_t inputBuffer[2048] = {}; uint8_t outBuffer[2048] = {}; int16_t read_size; int16_t tx_size; uint8_t broadcastCmd[6] = {0xff, 0xff, 0x00, 0x02, 0x00, 0x02}; uint8_t validResult; uint8_t chksum; uint8_t ip[4]; uint8_t mac[6]; memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(LISTEN_PORT_UDP); servaddr.sin_addr.s_addr = htonl(INADDR_ANY); if ((sockFd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { DEBUG_ERROR("UDP server socket create fail.\n"); return FAIL; } if (bind(sockFd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { DEBUG_ERROR("UDP server socket bind fail.\n"); return FAIL; } else DEBUG_INFO("UDP server initial.\n"); for(;;) { if((read_size = recvfrom(sockFd, inputBuffer, sizeof(inputBuffer), 0, (struct sockaddr *)&peeraddr, &peerlen)) > 0) { DEBUG_INFO("Revieve from: %s:%d\n", inet_ntoa(peeraddr.sin_addr), htons(peeraddr.sin_port)); DEBUG_INFO("read_size: %d\n",read_size); displayMessage(inputBuffer, read_size, YES); if(read_size>=6) { validResult = PASS; for(uint8_t idx=0;idx<6;idx++) { if(inputBuffer[idx] != broadcastCmd[idx]) { validResult = FAIL; break; } } if(validResult) { DEBUG_INFO("Receive UDP broadcast command.\n"); DEBUG_INFO("GET IP WifiIpAddress : %s.\n",ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress); memset(outBuffer, 0x00, ARRAY_SIZE(outBuffer)); tx_size = 41; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = (0x25 << 0x08) & 0xff; outBuffer[3] = 0x25 & 0xff; outBuffer[4] = 0x00; if(parseIP(ip)==PASS) { outBuffer[5] = ip[0]; outBuffer[6] = ip[1]; outBuffer[7] = ip[2]; outBuffer[8] = ip[3]; } else { outBuffer[5] = 0x00; outBuffer[6] = 0x00; outBuffer[7] = 0x00; outBuffer[8] = 0x00; } if(parseMAC(mac)==PASS) { outBuffer[9] = mac[0]; outBuffer[10] = mac[1]; outBuffer[11] = mac[2]; outBuffer[12] = mac[3]; outBuffer[13] = mac[4]; outBuffer[14] = mac[5]; } else { outBuffer[9] = 0x00; outBuffer[10] = 0x00; outBuffer[11] = 0x00; outBuffer[12] = 0x00; outBuffer[13] = 0x00; outBuffer[14] = 0x00; } memcpy(&outBuffer[15], ShmSysConfigAndInfo->SysConfig.ModelName, 0x0e); memcpy(&outBuffer[29], ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x0b); chksum = 0x00; for(uint8_t idx=0;idx<36;idx++) { chksum ^= outBuffer[idx]; } outBuffer[40] = chksum; displayMessage(outBuffer, tx_size, NO); sendto(sockFd, outBuffer, tx_size, 0, (struct sockaddr *)&peeraddr, peerlen); } } } } return FAIL; } //=============================================== // SQLite3 related routine //=============================================== int DB_Open(sqlite3 *db) { int result = PASS; char* errMsg = NULL; char* createSql="CREATE TABLE IF NOT EXISTS list(" "idx integer primary key AUTOINCREMENT, " "list_type text, " "code text, " "user_id text, " "isReg text" ");"; //sqlite3_config(SQLITE_CONFIG_URI, 1); if(sqlite3_open(DB_FILE_PUK, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { DEBUG_INFO( "Local puk/pin list database open successfully.\n"); if (sqlite3_exec(db, createSql, 0, 0, &errMsg) != SQLITE_OK) { result = FAIL; DEBUG_INFO( "Create puk/pin list table error message: %s\n", errMsg); } else { DEBUG_INFO( "Opened puk/pin list table successfully\n"); } sqlite3_close(db); } return result; } uint8_t isPukReg(sqlite3 *db) { uint8_t result = false; char* errMsg = NULL; char sqlStr[1024]; char **rs; int rows, cols; sprintf(sqlStr, "select * from list where list_type='puk';"); DEBUG_INFO("sqlStr= %s\n", sqlStr); if(sqlite3_open(DB_FILE_PUK, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { DEBUG_INFO( "Local puk/pin list database open successfully.\n"); sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg); if(rows>0) result = true; sqlite3_free_table(rs); sqlite3_close(db); } return result; } uint8_t PukReg(sqlite3 *db) { uint8_t result = false; char* errMsg = NULL; char sqlStr[1024]; sprintf(sqlStr, "insert into list(list_type, code, user_id, isReg) " "values('puk', '%s', '%s', '1');", wifi_login_info.puk, wifi_login_info.loginId); DEBUG_INFO("sqlStr= %s\n", sqlStr); if(sqlite3_open(DB_FILE_PUK, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { DEBUG_INFO( "Local puk/pin list database open successfully.\n"); if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) { result = FAIL; DEBUG_INFO( "Insert puk/pin list error message: %s\n", errMsg); } else { DEBUG_INFO( "Insert puk/pin list successfully\n"); } sqlite3_close(db); } return result; } uint8_t isPinGen(sqlite3 *db) { uint8_t result = false; char* errMsg = NULL; char sqlStr[1024]; char **rs; int rows, cols; sprintf(sqlStr, "select * from list where list_type='pin';"); DEBUG_INFO("sqlStr= %s\n", sqlStr); if(sqlite3_open(DB_FILE_PUK, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { DEBUG_INFO( "Local puk/pin list database open successfully.\n"); sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg); if(rows>0) result = true; sqlite3_free_table(rs); sqlite3_close(db); } return result; } uint8_t PinGen(sqlite3 *db) { uint8_t result = false; char* errMsg = NULL; char sqlStr[1024]; srand(time(NULL)); if(sqlite3_open(DB_FILE_PUK, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { DEBUG_INFO( "Local puk/pin list database open successfully.\n"); sprintf(sqlStr, "delete from list where list_type='pin';"); DEBUG_INFO("sqlStr= %s\n", sqlStr); if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) { result = FAIL; DEBUG_INFO( "Delete puk/pin list error message: %s\n", errMsg); } else { for(int idxList=0;idxList<20;idxList++) { sprintf(sqlStr, "insert into list(list_type, code, user_id, isReg) " "values('pin', '%06X', '', '0');", (rand() % 0xffffff)); DEBUG_INFO("sqlStr= %s\n", sqlStr); if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) { result = FAIL; DEBUG_INFO( "Insert puk/pin list error message: %s\n", errMsg); } else { DEBUG_INFO( "Insert puk/pin list successfully\n"); } } } sqlite3_close(db); } return result; } uint8_t isValidPin(sqlite3 *db, uint8_t *pinCode) { uint8_t result = false; char* errMsg = NULL; char sqlStr[1024]; char **rs; int rows, cols; sprintf(sqlStr, "select * from list where list_type='pin' and code='%s';", pinCode); DEBUG_INFO("sqlStr= %s\n", sqlStr); if(sqlite3_open(DB_FILE_PUK, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { DEBUG_INFO( "Local puk/pin list database open successfully.\n"); sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg); if(rows>0) result = true; sqlite3_free_table(rs); sqlite3_close(db); } return result; } uint8_t loginValid(sqlite3 *db) { uint8_t result = ROLE_UNKNOWN; char* errMsg = NULL; char sqlStr[1024]; char **rs; int rows, cols; sprintf(sqlStr, "select * from list where user_id='%s';", wifi_login_info.loginId); DEBUG_INFO("sqlStr= %s\n", sqlStr); DEBUG_INFO("Login id: %s\n", wifi_login_info.loginId); if(sqlite3_open(DB_FILE_PUK, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { DEBUG_INFO( "Local puk/pin list database open successfully.\n"); sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg); for(int idxRow=0;idxRowisEnable)); json_object_object_add(scheduleObj, "scheduleType", json_object_new_int(schedule->scheduleType)); json_object_object_add(scheduleObj, "scheduleMethod", json_object_new_int(schedule->scheduleMethod)); json_object_object_add(scheduleObj, "startTimeHour", json_object_new_int(schedule->startTimeHour)); json_object_object_add(scheduleObj, "startTimeMinute", json_object_new_int(schedule->startTimeMinute)); json_object_object_add(scheduleObj, "stopTimeHour", json_object_new_int(schedule->stopTimeHour)); json_object_object_add(scheduleObj, "stopTimeMinute", json_object_new_int(schedule->stopTimeMinute)); sprintf((char*)sqlStr, "insert or replace into config (item, connector, val) VALUES('schedule', %d, '%s'); SELECT * from config;", gun_index, json_object_to_json_string(scheduleObj)); //* Execute SQL statement */ if(sqlite3_open(DB_FILE_CHARGING, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { if(sqlite3_exec(db, (char*)sqlStr, cbScheduleSave, 0, &errMsg) != SQLITE_OK) { DEBUG_INFO("SQL error: %s\n", errMsg); result = FAIL; } sqlite3_close(db); } return result; } int cbScheduleLoad(void *para, int columnCount, char **columnValue, char **columnName) { uint8_t gun_index; uint8_t idxAC = 0; uint8_t idxCCS = 0; uint8_t idxCHAdeMO = 0; uint8_t idxGBT = 0; uint8_t AC_GUN_IDX = 0; json_object *scheduleObj = json_tokener_parse(columnValue[3]); DEBUG_INFO("Query schedule callback.\n"); for(int i=0; i0) && !is_error(scheduleObj)) { gun_index = atoi(columnValue[2]); if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') { if(gun_index == 2) { AC_GUN_IDX = 0; } else if(gun_index == 1) { AC_GUN_IDX = 1; } else if(gun_index == 0) { AC_GUN_IDX = 2; } for(uint8_t idx=0;idxSysConfig.ModelName[9-idx]) { case '1' ... '6': idxAC++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX]) { case '1' ... '6': ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable = json_object_get_int(json_object_object_get(scheduleObj, "isEnable")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType = json_object_get_int(json_object_object_get(scheduleObj, "scheduleType")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod = json_object_get_int(json_object_object_get(scheduleObj, "scheduleMethod")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "startTimeHour")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "startTimeMinute")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeHour")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeMinute")); break; } } else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') { for(uint8_t idx=0;idxSysConfig.ModelName[7+idx]) { case '1' ... '6': idxAC++; break; case 'J': idxCHAdeMO++; break; case 'U': case 'E': idxCCS++; break; case 'G': idxGBT++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index]) { case '1' ... '6': ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable = json_object_get_int(json_object_object_get(scheduleObj, "isEnable")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType = json_object_get_int(json_object_object_get(scheduleObj, "scheduleType")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod = json_object_get_int(json_object_object_get(scheduleObj, "scheduleMethod")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "startTimeHour")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "startTimeMinute")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeHour")); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeMinute")); break; case 'J': ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isEnable = json_object_get_int(json_object_object_get(scheduleObj, "isEnable")); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleType = json_object_get_int(json_object_object_get(scheduleObj, "scheduleType")); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleMethod = json_object_get_int(json_object_object_get(scheduleObj, "scheduleMethod")); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "startTimeHour")); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "startTimeMinute")); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeHour")); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeMinute")); break; case 'U': case 'E': ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isEnable = json_object_get_int(json_object_object_get(scheduleObj, "isEnable")); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleType = json_object_get_int(json_object_object_get(scheduleObj, "scheduleType")); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleMethod = json_object_get_int(json_object_object_get(scheduleObj, "scheduleMethod")); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "startTimeHour")); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "startTimeMinute")); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeHour")); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeMinute")); break; case 'G': ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isEnable = json_object_get_int(json_object_object_get(scheduleObj, "isEnable")); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleType = json_object_get_int(json_object_object_get(scheduleObj, "scheduleType")); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleMethod = json_object_get_int(json_object_object_get(scheduleObj, "scheduleMethod")); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "startTimeHour")); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "startTimeMinute")); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeHour = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeHour")); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeMinute = json_object_get_int(json_object_object_get(scheduleObj, "stopTimeMinute")); break; } } } json_object_put(scheduleObj); return 0; } int scheduleLoadFromDb(sqlite3 *db, uint8_t gun_index) { int result = PASS; char* errMsg = NULL; char sqlStr[512]; sprintf(sqlStr, "select * from config where item='schedule' and connector=%d", gun_index); //* Execute SQL statement */ if(sqlite3_open(DB_FILE_CHARGING, &db)) { result = FAIL; DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { if(sqlite3_exec(db, sqlStr, cbScheduleLoad, 0, &errMsg) != SQLITE_OK) { DEBUG_INFO("SQL error: %s\n", errMsg); result = FAIL; } sqlite3_close(db); } return result; } //========================================== // TCP socket server routine //========================================== uint32_t stm32crc(uint32_t *ptr, uint32_t len) { uint32_t xbit, data; uint32_t crc32 = 0xFFFFFFFF; const uint32_t polynomial = 0x04c11db7; for(uint8_t i = 0; i < len; i ++) { xbit = 1 << 31; data = ptr[i]; for (uint32_t bits = 0; bits < 32; bits++) { if (crc32 & 0x80000000) { crc32 <<= 1; crc32 ^= polynomial; } else crc32 <<= 1; if (data & xbit) crc32 ^= polynomial; xbit >>= 1; } } return crc32; } int isValidCheckSum(uint8_t *message) { uint8_t chksum=0; for(int idx=0;idx<(((message[2]<<8) | message[3])>1024?1024:(((message[2]<<8) | message[3])-1));idx++) { chksum ^= message[4+idx]; } return ((chksum == message[3+(((message[2]<<8) | message[3])>1024?1024:((message[2]<<8) | message[3]))]) ? PASS : FAIL); } int chksumCal(uint8_t *message) { uint8_t chksum=0; for(int idx = 0;idx<(((message[2]<<8) | message[3])>1024?1024:(((message[2]<<8) | message[3])-1));idx++) { chksum ^= message[4+idx]; } return chksum & 0xff; } int StoreUsrConfigData(struct SysConfigData *UsrData) { int result = PASS; int fd,wrd; unsigned int i,Chk; unsigned char *ptr, *BufTmp; Chk=0; ptr=(unsigned char *)UsrData; if((BufTmp=malloc(MtdBlockSize))!=NULL) { memset(BufTmp,0,MtdBlockSize); memcpy(BufTmp,ptr,sizeof(struct SysConfigData)); for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);iSysConfig.ModelName[0] == 'A') { if(gun_index == 2) { AC_GUN_IDX = 0; } else if(gun_index == 1) { AC_GUN_IDX = 1; } else if(gun_index == 0) { AC_GUN_IDX = 2; } for(uint8_t idx=0;idxSysConfig.ModelName[9-idx]) { case '1' ... '6': idxAC++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX]) { case '1' ... '6': // AC outBuffer[6] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].SystemStatus; outBuffer[7] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingVoltage*10)>>8)&0xff; outBuffer[8] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingVoltage*10)>>0)&0xff; outBuffer[9] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingCurrent*10)>>8)&0xff; outBuffer[10] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingCurrent*10)>>0)&0xff; outBuffer[11] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingPower*10)>>8)&0xff; outBuffer[12] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingPower*10)>>0)&0xff; outBuffer[13] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargedEnergy*10)>>8)&0xff; outBuffer[14] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargedEnergy*10)>>0)&0xff; outBuffer[15] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargedDuration)>>8)&0xff; outBuffer[16] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargedDuration)>>0)&0xff; outBuffer[17] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].RemainChargingDuration)>>8)&0xff; outBuffer[18] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].RemainChargingDuration)>>0)&0xff; outBuffer[19] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].EvBatterySoc)>>0)&0xff; break; default: break; } } else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') { for(uint8_t idx=0;idxSysConfig.ModelName[7+idx]) { case '1' ... '6': idxAC++; break; case 'J': idxCHAdeMO++; break; case 'U': case 'E': idxCCS++; break; case 'G': idxGBT++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index]) { case '1' ... '6': // AC outBuffer[6] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].SystemStatus; outBuffer[7] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingVoltage*10)>>8)&0xff; outBuffer[8] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingVoltage*10)>>0)&0xff; outBuffer[9] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingCurrent*10)>>8)&0xff; outBuffer[10] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingCurrent*10)>>0)&0xff; outBuffer[11] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingPower*10)>>8)&0xff; outBuffer[12] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargingPower*10)>>0)&0xff; outBuffer[13] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargedEnergy*10)>>8)&0xff; outBuffer[14] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargedEnergy*10)>>0)&0xff; outBuffer[15] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargedDuration)>>8)&0xff; outBuffer[16] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].PresentChargedDuration)>>0)&0xff; outBuffer[17] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].RemainChargingDuration)>>8)&0xff; outBuffer[18] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].RemainChargingDuration)>>0)&0xff; outBuffer[19] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].EvBatterySoc)>>0)&0xff; break; case 'J': // CHAdeMO outBuffer[6] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].SystemStatus; outBuffer[7] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargingVoltage*10)>>8)&0xff; outBuffer[8] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargingVoltage*10)>>0)&0xff; outBuffer[9] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargingCurrent*10)>>8)&0xff; outBuffer[10] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargingCurrent*10)>>0)&0xff; outBuffer[11] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargingPower*10)>>8)&0xff; outBuffer[12] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargingPower*10)>>0)&0xff; outBuffer[13] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargedEnergy*10)>>8)&0xff; outBuffer[14] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargedEnergy*10)>>0)&0xff; outBuffer[15] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargedDuration)>>8)&0xff; outBuffer[16] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].PresentChargedDuration)>>0)&0xff; outBuffer[17] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].RemainChargingDuration)>>8)&0xff; outBuffer[18] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].RemainChargingDuration)>>0)&0xff; outBuffer[19] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].EvBatterySoc)>>0)&0xff; break; case 'U': case 'E': // CCS outBuffer[6] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].SystemStatus; outBuffer[7] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargingVoltage*10)>>8)&0xff; outBuffer[8] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargingVoltage*10)>>0)&0xff; outBuffer[9] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargingCurrent*10)>>8)&0xff; outBuffer[10] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargingCurrent*10)>>0)&0xff; outBuffer[11] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargingPower*10)>>8)&0xff; outBuffer[12] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargingPower*10)>>0)&0xff; outBuffer[13] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargedEnergy*10)>>8)&0xff; outBuffer[14] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargedEnergy*10)>>0)&0xff; outBuffer[15] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargedDuration)>>8)&0xff; outBuffer[16] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].PresentChargedDuration)>>0)&0xff; outBuffer[17] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].RemainChargingDuration)>>8)&0xff; outBuffer[18] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].RemainChargingDuration)>>0)&0xff; outBuffer[19] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].EvBatterySoc)>>0)&0xff; break; case 'G': // GBT outBuffer[6] = ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].SystemStatus; outBuffer[7] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargingVoltage*10)>>8)&0xff; outBuffer[8] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargingVoltage*10)>>0)&0xff; outBuffer[9] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargingCurrent*10)>>8)&0xff; outBuffer[10] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargingCurrent*10)>>0)&0xff; outBuffer[11] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargingPower*10)>>8)&0xff; outBuffer[12] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargingPower*10)>>0)&0xff; outBuffer[13] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargedEnergy*10)>>8)&0xff; outBuffer[14] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargedEnergy*10)>>0)&0xff; outBuffer[15] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargedDuration)>>8)&0xff; outBuffer[16] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].PresentChargedDuration)>>0)&0xff; outBuffer[17] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].RemainChargingDuration)>>8)&0xff; outBuffer[18] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].RemainChargingDuration)>>0)&0xff; outBuffer[19] = ((uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].EvBatterySoc)>>0)&0xff; break; default: break; } } } void getConnectorSchedule(uint8_t gun_index, uint8_t *outBuffer) { uint8_t idxAC = 0; uint8_t idxCCS = 0; uint8_t idxCHAdeMO = 0; uint8_t idxGBT = 0; uint8_t AC_GUN_IDX = 0; scheduleLoadFromDb(localDb, gun_index); if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') { if(gun_index == 2) { AC_GUN_IDX = 0; } else if(gun_index == 1) { AC_GUN_IDX = 1; } else if(gun_index == 0) { AC_GUN_IDX = 2; } for(uint8_t idx=0;idxSysConfig.ModelName[9-idx]) { case '1' ... '6': idxAC++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX]) { case '1' ... '6': outBuffer[6] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable; outBuffer[7] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType; outBuffer[8] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod; outBuffer[9] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour; outBuffer[10] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute; outBuffer[11] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour; outBuffer[12] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute; break; } } else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') { for(uint8_t idx=0;idxSysConfig.ModelName[7+idx]) { case '1' ... '6': idxAC++; break; case 'J': idxCHAdeMO++; break; case 'U': case 'E': idxCCS++; break; case 'G': idxGBT++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index]) { case '1' ... '6': outBuffer[6] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable; outBuffer[7] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType; outBuffer[8] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod; outBuffer[9] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour; outBuffer[10] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute; outBuffer[11] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour; outBuffer[12] = ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute; break; case 'J': outBuffer[6] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isEnable; outBuffer[7] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleType; outBuffer[8] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleMethod; outBuffer[9] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeHour; outBuffer[10] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeMinute; outBuffer[11] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeHour; outBuffer[12] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeMinute; break; case 'U': case 'E': outBuffer[6] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isEnable; outBuffer[7] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleType; outBuffer[8] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleMethod; outBuffer[9] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeHour; outBuffer[10] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeMinute; outBuffer[11] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeHour; outBuffer[12] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeMinute; break; case 'G': outBuffer[6] = ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isEnable; outBuffer[7] = ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleType; outBuffer[8] = ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleMethod; outBuffer[9] = ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeHour; outBuffer[10] = ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeMinute; outBuffer[11] = ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeHour; outBuffer[12] = ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeMinute; break; } } } uint8_t startConnectorCharging(uint8_t gun_index) { uint8_t idxAC = 0; uint8_t idxCCS = 0; uint8_t idxCHAdeMO = 0; uint8_t idxGBT = 0; uint8_t result = OFF; uint8_t AC_GUN_IDX = 0; if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') { if(gun_index == 2) { AC_GUN_IDX = 0; } else if(gun_index == 1) { AC_GUN_IDX = 1; } else if(gun_index == 0) { AC_GUN_IDX = 2; } for(uint8_t idx=0;idxSysConfig.ModelName[9-idx]) { case '1' ... '6': idxAC++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX]) { case '1' ... '6': // AC if(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].SystemStatus == SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[idxAC].RemoteStartTransactionReq = ON; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStart = ON; DEBUG_INFO("AC isTriggerStar : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStart); DEBUG_INFO("AC gun_index : [%d].\n", gun_index); DEBUG_INFO("AC idxAC : [%d].\n", idxAC); result = ON; } break; default: break; } return result; } else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') { for(uint8_t idx=0;idxSysConfig.ModelName[7+idx]) { case '1' ... '6': idxAC++; break; case 'J': idxCHAdeMO++; break; case 'U': case 'E': idxCCS++; break; case 'G': idxGBT++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index]) { case '1' ... '6': // AC if(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].SystemStatus == SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = ON; //DEBUG_INFO("AC : %d...\n", ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStart = ON; DEBUG_INFO("AC isTriggerStar : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStart); DEBUG_INFO("AC gun_index : [%d].\n", gun_index); DEBUG_INFO("AC idxAC : [%d].\n", idxAC); result = ON; } break; case 'J': // CHAdeMO if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].SystemStatus == SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = ON; //DEBUG_INFO("CHAdeMO : %d...\n", ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isTriggerStart = ON; DEBUG_INFO("CHAdeMO isTriggerStar : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isTriggerStart); DEBUG_INFO("CHAdeMO gun_index : [%d].\n", gun_index); DEBUG_INFO("CHAdeMO idxCHAdeMO : [%d].\n", idxCHAdeMO); result = ON; } break; case 'U': case 'E': // CCS if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].SystemStatus == SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = ON; //DEBUG_INFO("CCS : %d...\n", ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isTriggerStart = ON; DEBUG_INFO("CCS isTriggerStar : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isTriggerStart); DEBUG_INFO("CCS gun_index : [%d].\n", gun_index); DEBUG_INFO("CCS idxCCS : [%d].\n", idxCCS); result = ON; } break; case 'G': // GBT if(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].SystemStatus == SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = ON; //DEBUG_INFO("GBT : %d...\n", ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isTriggerStart = ON; DEBUG_INFO("GBT isTriggerStar : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isTriggerStart); DEBUG_INFO("GBT gun_index : [%d].\n", gun_index); DEBUG_INFO("GBT idxGBT : [%d].\n", idxGBT); result = ON; } break; default: break; } } return result; } uint8_t stopConnectorCharging(uint8_t gun_index) { uint8_t idxAC = 0; uint8_t idxCCS = 0; uint8_t idxCHAdeMO = 0; uint8_t idxGBT = 0; uint8_t result = OFF; uint8_t AC_GUN_IDX = 0; if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') { if(gun_index == 2) { AC_GUN_IDX = 0; } else if(gun_index == 1) { AC_GUN_IDX = 1; } else if(gun_index == 0) { AC_GUN_IDX = 2; } for(uint8_t idx=0;idxSysConfig.ModelName[9-idx]) { case '1' ... '6': idxAC++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX]) { case '1' ... '6': // AC if(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].SystemStatus != SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[idxAC].RemoteStopTransactionReq = ON; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStop = ON; DEBUG_INFO("AC isTriggerStop : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStop); DEBUG_INFO("AC gun_index : [%d].\n", gun_index); DEBUG_INFO("AC idxAC : [%d].\n", idxAC); result = ON; } break; default: break; } return result; } else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') { for(uint8_t idx=0;idxSysConfig.ModelName[7+idx]) { case '1' ... '6': idxAC++; break; case 'J': idxCHAdeMO++; break; case 'U': case 'E': idxCCS++; break; case 'G': idxGBT++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index]) { case '1' ... '6': // AC if(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].SystemStatus != SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = ON; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStop = ON; DEBUG_INFO("AC isTriggerStop : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStop); DEBUG_INFO("AC gun_index : [%d].\n", gun_index); DEBUG_INFO("AC idxAC : [%d].\n", idxAC); result = ON; } break; case 'J': // CHAdeMO if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].SystemStatus != SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = ON; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isTriggerStop = ON; DEBUG_INFO("CHAdeMO isTriggerStop : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isTriggerStop); DEBUG_INFO("CHAdeMO gun_index : [%d].\n", gun_index); DEBUG_INFO("CHAdeMO idxCHAdeMO : [%d].\n", idxCHAdeMO); result = ON; } break; case 'U': case 'E': // CCS if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].SystemStatus != SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = ON; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isTriggerStop = ON; DEBUG_INFO("CCS isTriggerStop : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isTriggerStop); DEBUG_INFO("CCS gun_index : [%d].\n", gun_index); DEBUG_INFO("CCS idxCCS : [%d].\n", idxCCS); result = ON; } break; case 'G': // GBT if(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].SystemStatus != SYS_MODE_IDLE) { //ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = ON; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isTriggerStop = ON; DEBUG_INFO("GBT isTriggerStop : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isTriggerStop); DEBUG_INFO("GBT gun_index : [%d].\n", gun_index); DEBUG_INFO("GBT idxCCS : [%d].\n", idxGBT); result = ON; } break; default: break; } } return result; } uint8_t setConnectorSchedule(uint8_t gun_index, uint8_t *inputBuffer) { uint8_t idxAC = 0; uint8_t idxCCS = 0; uint8_t idxCHAdeMO = 0; uint8_t idxGBT = 0; uint8_t result = OFF; uint8_t AC_GUN_IDX = 0; if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') { if(gun_index == 2) { AC_GUN_IDX = 0; } else if(gun_index == 1) { AC_GUN_IDX = 1; } else if(gun_index == 0) { AC_GUN_IDX = 2; } for(uint8_t idx=0;idxSysConfig.ModelName[9-idx]) { case '1' ... '6': idxAC++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX]) { case '1' ... '6': ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable = inputBuffer[10]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType = inputBuffer[11]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod = inputBuffer[12]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour = inputBuffer[13]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute = inputBuffer[14]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour = inputBuffer[15]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute = inputBuffer[16]; if(scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule) == PASS) result = ON; else result = OFF; break; } return result; } else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') { for(uint8_t idx=0;idxSysConfig.ModelName[7+idx]) { case '1' ... '6': idxAC++; break; case 'J': idxCHAdeMO++; break; case 'U': case 'E': idxCCS++; break; case 'G': idxGBT++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index]) { case '1' ... '6': ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable = inputBuffer[10]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType = inputBuffer[11]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod = inputBuffer[12]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour = inputBuffer[13]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute = inputBuffer[14]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour = inputBuffer[15]; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute = inputBuffer[16]; if(scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule) == PASS) result = ON; else result = OFF; break; case 'J': ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isEnable = inputBuffer[10]; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleType = inputBuffer[11]; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleMethod = inputBuffer[12]; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeHour = inputBuffer[13]; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeMinute = inputBuffer[14]; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeHour = inputBuffer[15]; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeMinute = inputBuffer[16]; if(scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule) == PASS) result = ON; else result = OFF; break; case 'U': case 'E': ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isEnable = inputBuffer[10]; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleType = inputBuffer[11]; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleMethod = inputBuffer[12]; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeHour = inputBuffer[13]; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeMinute = inputBuffer[14]; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeHour = inputBuffer[15]; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeMinute = inputBuffer[16]; if(scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule) == PASS) result = ON; else result = OFF; break; case 'G': ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isEnable = inputBuffer[10]; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleType = inputBuffer[11]; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleMethod = inputBuffer[12]; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeHour = inputBuffer[13]; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeMinute = inputBuffer[14]; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeHour = inputBuffer[15]; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeMinute = inputBuffer[16]; if(scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule) == PASS) result = ON; else result = OFF; break; } } return result; } void getConnectorUser(uint8_t gun_index, uint8_t *outBuffer) { uint8_t idxAC = 0; uint8_t idxCCS = 0; uint8_t idxCHAdeMO = 0; uint8_t idxGBT = 0; uint8_t AC_GUN_IDX = 0; if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') { if(gun_index == 2) { AC_GUN_IDX = 0; } else if(gun_index == 1) { AC_GUN_IDX = 1; } else if(gun_index == 0) { AC_GUN_IDX = 2; } for(uint8_t idx=0;idxSysConfig.ModelName[9-idx]) { case '1' ... '6': idxAC++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX]) { case '1' ... '6': // AC outBuffer[6] = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].SystemStatus == SYS_MODE_IDLE)?0x01:0x00); memcpy(&outBuffer[7], ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].StartUserId)); break; default: break; } } else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') { for(uint8_t idx=0;idxSysConfig.ModelName[7+idx]) { case '1' ... '6': idxAC++; break; case 'J': idxCHAdeMO++; break; case 'U': case 'E': idxCCS++; break; case 'G': idxGBT++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index]) { case '1' ... '6': // AC outBuffer[6] = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].SystemStatus == SYS_MODE_IDLE)?0x01:0x00); memcpy(&outBuffer[7], ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].StartUserId)); break; case 'J': // CHAdeMO outBuffer[6] = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].SystemStatus == SYS_MODE_IDLE)?0x01:0x00); memcpy(&outBuffer[7], ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].StartUserId)); break; case 'U': case 'E': // CCS outBuffer[6] = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].SystemStatus == SYS_MODE_IDLE)?0x01:0x00); memcpy(&outBuffer[7], ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].StartUserId)); break; case 'G': // GBT outBuffer[6] = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].SystemStatus == SYS_MODE_IDLE)?0x01:0x00); memcpy(&outBuffer[7], ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].StartUserId)); break; default: break; } } } void checkSchedule() { uint8_t idxAC = 0; uint8_t idxCCS = 0; uint8_t idxCHAdeMO = 0; uint8_t idxGBT = 0; uint8_t AC_GUN_IDX = 0; time_t CurrentTime; struct tm *tm; CurrentTime = time(NULL); tm=localtime(&CurrentTime); if((time((time_t*)NULL)%60) == 0) { for(int gun_index=0;gun_index<(AC_QUANTITY+CHAdeMO_QUANTITY+CCS_QUANTITY+GB_QUANTITY);gun_index++) { idxAC = 0; idxCCS = 0; idxCHAdeMO = 0; idxGBT = 0; AC_GUN_IDX = 0; if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') { //DEBUG_INFO("Schedule gun_index : [%d].\n", gun_index); if(gun_index == 2) { AC_GUN_IDX = 0; } else if(gun_index == 1) { AC_GUN_IDX = 1; } else if(gun_index == 0) { AC_GUN_IDX = 2; } //DEBUG_INFO("Schedule AC_GUN_IDX : [%d].\n", AC_GUN_IDX); for(uint8_t idx=0;idxSysConfig.ModelName[9-idx]) { case '1' ... '6': idxAC++; //DEBUG_INFO("Schedule idxAC : [%d].\n", idxAC); break; } } /* DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); DEBUG_INFO("idxAC : [%d].\n", idxAC); DEBUG_INFO("AC Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable); DEBUG_INFO("AC Schedule scheduleMethod : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod); DEBUG_INFO("AC Schedule startTimeHour : [%d] >> tm->tm_hour : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour, tm->tm_hour); DEBUG_INFO("AC Schedule startTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute, tm->tm_min); DEBUG_INFO("AC Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour, tm->tm_hour); DEBUG_INFO("AC Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute, tm->tm_min); DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); */ switch(ShmSysConfigAndInfo->SysConfig.ModelName[9-AC_GUN_IDX]) { case '1' ... '6': // Check schedule start if((ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger start...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour, ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStart = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule); } } // Check schedule stop if((ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger stop...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour, ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStop = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule); } } break; } } else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') { for(uint8_t idx=0;idxSysConfig.ModelName[7+idx]) { case '1' ... '6': idxAC++; break; case 'J': idxCHAdeMO++; break; case 'U': case 'E': idxCCS++; break; case 'G': idxGBT++; break; } } switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+gun_index]) { case '1' ... '6': /* DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); DEBUG_INFO("idxAC : [%d].\n", idxAC); DEBUG_INFO("AC Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable); DEBUG_INFO("AC Schedule scheduleMethod : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod); DEBUG_INFO("AC Schedule startTimeHour : [%d] >> tm->tm_hour : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour, tm->tm_hour); DEBUG_INFO("AC Schedule startTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute, tm->tm_min); DEBUG_INFO("AC Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour, tm->tm_hour); DEBUG_INFO("AC Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute, tm->tm_min); DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); */ // AC // Check schedule start if((ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger start...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour, ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStart = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.startTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule); } } // Check schedule stop if((ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleMethod) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger stop...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour, ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute); ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.isTriggerStop = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule.stopTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.AcChargingData[idxAC].schedule); } } break; case 'J': /* DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); DEBUG_INFO("idxCHAdeMO : [%d].\n", idxCHAdeMO); DEBUG_INFO("CHAdeMO Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isEnable); DEBUG_INFO("CHAdeMO Schedule scheduleMethod : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleMethod); DEBUG_INFO("CHAdeMO Schedule startTimeHour : [%d] >> tm->tm_hour : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeHour, tm->tm_hour); DEBUG_INFO("CHAdeMO Schedule startTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeMinute, tm->tm_min); DEBUG_INFO("CHAdeMO Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeHour, tm->tm_hour); DEBUG_INFO("CHAdeMO Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeMinute, tm->tm_min); DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); */ // CHAdeMO // Check schedule start if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger start...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeHour, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeMinute); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isTriggerStart = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.startTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule); } } // Check schedule stop if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleMethod) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger stop...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeHour, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeMinute); ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.isTriggerStop = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule.stopTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[idxCHAdeMO].schedule); } } break; case 'U': case 'E': /* DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); DEBUG_INFO("idxCCS : [%d].\n", idxCCS); DEBUG_INFO("CCS Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isEnable); DEBUG_INFO("CCS Schedule scheduleMethod : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleMethod); DEBUG_INFO("CCS Schedule startTimeHour : [%d] >> tm->tm_hour : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeHour, tm->tm_hour); DEBUG_INFO("CCS Schedule startTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeMinute, tm->tm_min); DEBUG_INFO("CCS Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeHour, tm->tm_hour); DEBUG_INFO("CCS Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeMinute, tm->tm_min); DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); */ // CCS // Check schedule start if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger start...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeHour, ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeMinute); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isTriggerStart = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.startTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule); } } // Check schedule stop if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleMethod) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger stop...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeHour, ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeMinute); ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.isTriggerStop = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule.stopTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.CcsChargingData[idxCCS].schedule); } } break; case 'G': /* DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); DEBUG_INFO("idxGBT : [%d].\n", idxGBT); DEBUG_INFO("GBT Schedule isEnable : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isEnable); DEBUG_INFO("GBT Schedule scheduleMethod : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleMethod); DEBUG_INFO("GBT Schedule startTimeHour : [%d] >> tm->tm_hour : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeHour, tm->tm_hour); DEBUG_INFO("GBT Schedule startTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeMinute, tm->tm_min); DEBUG_INFO("GBT Schedule stopTimeHour : [%d] >> tm->tm_hourr : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeHour, tm->tm_hour); DEBUG_INFO("GBT Schedule stopTimeMinute : [%d] >> tm->tm_min : [%d].\n", ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeMinute, tm->tm_min); DEBUG_INFO("++++++++++++++++++++++++++++++++++++++++++++++++++\n"); */ // GBT // Check schedule start if((ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger start...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeHour, ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeMinute); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isTriggerStart = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.startTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.GbChargingData[idxCHAdeMO].schedule); } } // Check schedule stop if((ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isEnable) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleMethod) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeHour == tm->tm_hour) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeMinute == tm->tm_min)) { DEBUG_INFO("Gun-%02d Schedule trigger stop...%02d:%02d\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeHour, ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeMinute); ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.isTriggerStop = ON; // Disable schedule time if type is once(0) if(ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.scheduleType == 0) { ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeHour = 0xff; ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule.stopTimeMinute = 0xff; scheduleSaveToDb(localDb, gun_index, &ShmSysConfigAndInfo->SysInfo.GbChargingData[idxGBT].schedule); } } break; default: break; } } } } } int tcpSocketServerStart(void) { int sockFd = 0; int clientSockFd = 0; uint8_t inputBuffer[2048] = {}; uint8_t outBuffer[2048] = {}; int16_t read_size; int16_t tx_size; uint32_t randomChk; struct sockaddr_in serverInfo, clientInfo; socklen_t addrlen = sizeof(clientInfo); uint8_t cmdBuf[512]; time_t rawtime; struct tm ts; sockFd = socket(AF_INET , SOCK_STREAM , 0); if(sockFd == -1) { DEBUG_ERROR("TCP service socket create fail.\n"); sleep(5); return FAIL; } bzero(&serverInfo,sizeof(serverInfo)); serverInfo.sin_family = PF_INET; serverInfo.sin_addr.s_addr = htonl(INADDR_ANY); serverInfo.sin_port = htons(LISTEN_PORT_TCP); if(bind(sockFd, (struct sockaddr *)&serverInfo, sizeof(serverInfo)) < 0) DEBUG_ERROR("TCP server socket bind fail.\n"); if(listen(sockFd, CONNECTION_LIMIT) < 0) DEBUG_ERROR("TCP server socket listen fail.\n"); else DEBUG_INFO("TCP server initial.\n"); // Main loop for(;;) { clientSockFd = accept(sockFd, (struct sockaddr*) &clientInfo, &addrlen); DEBUG_INFO("Client connect in.\n"); DEBUG_INFO("clientSockFd : %d...\n", clientSockFd); // Fork a child process to handle the new connection if(fork()==0) { // Copy ShmSysConfigAndInfo to SysConfigTemporarily memcpy(&SysConfigTemporarily, &ShmSysConfigAndInfo->SysConfig, sizeof(struct SysConfigData)); while((read_size = recv(clientSockFd, inputBuffer, sizeof(inputBuffer), 0)) > 0) { displayMessage(inputBuffer, read_size, YES); if(isValidCheckSum(inputBuffer) && (randomChk != ((inputBuffer[4]<<24) | (inputBuffer[5]<<16) | (inputBuffer[6]<<8) | (inputBuffer[7]<<0)))) { randomChk = ((inputBuffer[4]<<24) | (inputBuffer[5]<<16) | (inputBuffer[6]<<8) | (inputBuffer[7]<<0)); memset(outBuffer, 0x00, sizeof(outBuffer)); switch(inputBuffer[8]) { case WIFI_CMD_LOGIN_SIGNIN: memset(&wifi_login_info.loginId[0], 0x00, ARRAY_SIZE(wifi_login_info.loginId)); memcpy((char*)&wifi_login_info.loginId[0], (char*)&inputBuffer[9], (((inputBuffer[2] << 8)| inputBuffer[3])-6)); wifi_login_info.loginRole = loginValid(localDb); DEBUG_INFO("Receive login command.\n"); DEBUG_INFO("Login user id: %s\n", wifi_login_info.loginId); DEBUG_INFO("User id: %d\n", wifi_login_info.loginRole); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_LOGIN_SIGNIN; switch(wifi_login_info.loginRole) { case ROLE_MANAGER: case ROLE_USER: // Login success outBuffer[5] = 0x02; break; case ROLE_UNKNOWN: default: if(!isPukReg(localDb)) { // Login fail, PUK never be registered outBuffer[5] = 0x01; } else { // Login fail outBuffer[5] = 0x00; } break; } outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_LOGIN_AUTH_PUK: DEBUG_INFO("Receive authorize PUK command.\n"); if(!isPukReg(localDb)) { // PUK never be registered if((wifi_login_info.puk[0] == inputBuffer[9]) && (wifi_login_info.puk[1] == inputBuffer[10]) && (wifi_login_info.puk[2] == inputBuffer[11]) && (wifi_login_info.puk[3] == inputBuffer[12]) && (wifi_login_info.puk[4] == inputBuffer[13]) && (wifi_login_info.puk[5] == inputBuffer[14]) && (wifi_login_info.puk[6] == inputBuffer[15]) && (wifi_login_info.puk[7] == inputBuffer[16])) { // PUK valid success if(PukReg(localDb)) { // PUK registered success tx_size = 7 + strlen((char*)wifi_login_info.loginId); outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = ((0x03 + strlen((char*)wifi_login_info.loginId))>>8)&0xff; outBuffer[3] = (0x03 + strlen((char*)wifi_login_info.loginId)) & 0xff; outBuffer[4] = WIFI_CMD_LOGIN_AUTH_PUK; outBuffer[5] = 0x01; memcpy(&outBuffer[6], wifi_login_info.loginId, strlen((char*)wifi_login_info.loginId)); outBuffer[6+strlen((char*)wifi_login_info.loginId)] = chksumCal(outBuffer); } else { // PUK registered fail tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_LOGIN_AUTH_PUK; outBuffer[5] = 0x00; outBuffer[6] = chksumCal(outBuffer); } } else { // PUK valid fail tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_LOGIN_AUTH_PUK; outBuffer[5] = 0x00; outBuffer[6] = chksumCal(outBuffer); } } else { // PUK already be registered tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_LOGIN_AUTH_PUK; outBuffer[5] = 0x02; outBuffer[6] = chksumCal(outBuffer); } break; case WIFI_CMD_LOGIN_GET_USER_ID: DEBUG_INFO("Receive login get user ID command.\n"); if(wifi_login_info.loginRole != ROLE_UNKNOWN) { // Login role is Manager or User tx_size = 7 + strlen((char*)wifi_login_info.loginId); outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = ((0x03 + strlen((char*)wifi_login_info.loginId))>>8)&0xff; outBuffer[3] = (0x03 + strlen((char*)wifi_login_info.loginId)) & 0xff; outBuffer[4] = WIFI_CMD_LOGIN_GET_USER_ID; outBuffer[5] = 0x01; memcpy(&outBuffer[6], wifi_login_info.loginId, strlen((char*)wifi_login_info.loginId)); outBuffer[6+strlen((char*)wifi_login_info.loginId)] = chksumCal(outBuffer); } else { // Login role is Unknown tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_LOGIN_GET_USER_ID; outBuffer[5] = 0x00; outBuffer[6] = chksumCal(outBuffer); } break; case WIFI_CMD_PROTOCOL_VERSION: DEBUG_INFO("Receive get protocol version command.\n"); DEBUG_INFO("Protocol version: %d.%d.%d.\n", protocol_Version[0], protocol_Version[1], protocol_Version[2]); tx_size = 12; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x08; outBuffer[4] = WIFI_CMD_PROTOCOL_VERSION; outBuffer[5] = (protocol_Version[0] >> 0x08) & 0xff; outBuffer[6] = (protocol_Version[0] >> 0x00) & 0xff; outBuffer[7] = (protocol_Version[1] >> 0x08) & 0xff; outBuffer[8] = (protocol_Version[1] >> 0x00) & 0xff; outBuffer[9] = (protocol_Version[2] >> 0x08) & 0xff; outBuffer[10] = (protocol_Version[2] >> 0x00) & 0xff; outBuffer[11] = chksumCal(outBuffer); break; case WIFI_CMD_GET_MODEL_NAME: DEBUG_INFO("Receive get model name command.\n"); DEBUG_INFO("Model name: %s\n", ShmSysConfigAndInfo->SysConfig.ModelName); tx_size = 70; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x42; outBuffer[4] = WIFI_CMD_GET_MODEL_NAME; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)); outBuffer[69] = chksumCal(outBuffer); break; case WIFI_CMD_GET_SERIAL_NUMBER: DEBUG_INFO("Receive get serial number command.\n"); DEBUG_INFO("Serial number: %s\n", ShmSysConfigAndInfo->SysConfig.SerialNumber); tx_size = 70; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x42; outBuffer[4] = WIFI_CMD_GET_SERIAL_NUMBER; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)); outBuffer[69] = chksumCal(outBuffer); break; case WIFI_CMD_GET_SYSTEM_TIME: DEBUG_INFO("Receive get system time command.\n"); tx_size = 10; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x06; outBuffer[4] = WIFI_CMD_GET_SYSTEM_TIME; outBuffer[5] = (time(NULL)>>24)&0xff; outBuffer[6] = (time(NULL)>>16)&0xff; outBuffer[7] = (time(NULL)>>8)&0xff; outBuffer[8] = (time(NULL)>>0)&0xff; outBuffer[9] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WHITE_CARD: DEBUG_INFO("Receive get white list-%02d command.\n", inputBuffer[9]); DEBUG_INFO("White list: %s.\n", ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[inputBuffer[9]]); tx_size = 40; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x24; outBuffer[4] = WIFI_CMD_GET_WHITE_CARD; outBuffer[5] = inputBuffer[9]; outBuffer[6] = ((strlen((char*)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[inputBuffer[9]])>0)?0x00:0x01); memcpy(&outBuffer[7], ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[inputBuffer[9]], ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[inputBuffer[9]])); outBuffer[39] = chksumCal(outBuffer); break; case WIFI_CMD_GET_SYS_ALARM_CODE: DEBUG_INFO("Receive get alarm code command.\n"); tx_size = 70; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x42; outBuffer[4] = WIFI_CMD_GET_SYS_ALARM_CODE; memcpy(&outBuffer[5], ShmStatusCodeData->FaultCode.FaultEvents.FaultVal, ARRAY_SIZE(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal)); memcpy(&outBuffer[13], ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal, ARRAY_SIZE(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal)); memcpy(&outBuffer[29], ShmStatusCodeData->InfoCode.InfoEvents.InfoVal, ARRAY_SIZE(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal)); outBuffer[69] = chksumCal(outBuffer); break; case WIFI_CMD_GET_SYS_ID: DEBUG_INFO("Receive get system ID command.\n"); DEBUG_INFO("System ID: %s.\n", ShmSysConfigAndInfo->SysConfig.SystemId); tx_size = 70; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x42; outBuffer[4] = WIFI_CMD_GET_SYS_ID; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.SystemId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)); outBuffer[69] = chksumCal(outBuffer); break; case WIFI_CMD_GET_RATING_CURRENT: DEBUG_INFO("Receive get rating current command.\n"); DEBUG_INFO("Rating current: %d.\n", ShmSysConfigAndInfo->SysConfig.RatingCurrent); DEBUG_INFO("AcRating current: %d.\n", ShmSysConfigAndInfo->SysConfig.AcRatingCurrent); tx_size = 10; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x06; outBuffer[4] = WIFI_CMD_GET_RATING_CURRENT; outBuffer[5] = (ShmSysConfigAndInfo->SysConfig.RatingCurrent>>0x08) & 0xff; outBuffer[6] = (ShmSysConfigAndInfo->SysConfig.RatingCurrent>>0x00) & 0xff; outBuffer[7] = (ShmSysConfigAndInfo->SysConfig.AcRatingCurrent>>0x08) & 0xff; outBuffer[8] = (ShmSysConfigAndInfo->SysConfig.AcRatingCurrent>>0x00) & 0xff; outBuffer[9] = chksumCal(outBuffer); break; case WIFI_CMD_GET_VER_RFS: DEBUG_INFO("Receive get RFS version command.\n"); DEBUG_INFO("Version: %s.\n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev); tx_size = 38; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x22; outBuffer[4] = WIFI_CMD_GET_VER_RFS; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev)); outBuffer[37] = chksumCal(outBuffer); break; case WIFI_CMD_GET_VER_PRIMARY_CSU: DEBUG_INFO("Receive get primary MCU version command.\n"); DEBUG_INFO("Version: %s.\n", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev); tx_size = 38; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x22; outBuffer[4] = WIFI_CMD_GET_VER_PRIMARY_CSU; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev)); outBuffer[37] = chksumCal(outBuffer); break; case WIFI_CMD_GET_VER_LCM: DEBUG_INFO("Receive get LCM version command.\n"); DEBUG_INFO("Version: %s.\n", ShmSysConfigAndInfo->SysInfo.LcmHwRev); tx_size = 38; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x22; outBuffer[4] = WIFI_CMD_GET_VER_LCM; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysInfo.LcmHwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.LcmHwRev)); outBuffer[37] = chksumCal(outBuffer); break; case WIFI_CMD_GET_PSU_COUNT: DEBUG_INFO("Receive get PSU quantity command.\n"); DEBUG_INFO("Quantity: %d.\n", ShmPsuData->SystemPresentPsuQuantity); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_PSU_COUNT; outBuffer[5] = ShmPsuData->SystemPresentPsuQuantity; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_VER_PSU: DEBUG_INFO("Receive get PSU-%d version command.\n", inputBuffer[9]); DEBUG_INFO("Primary version: %s.\n", ShmPsuData->PsuVersion[inputBuffer[9]].FwPrimaryVersion); DEBUG_INFO("Second version: %s.\n", ShmPsuData->PsuVersion[inputBuffer[9]].FwSecondVersion); tx_size = 39; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x23; outBuffer[4] = WIFI_CMD_GET_VER_PSU; outBuffer[5] = inputBuffer[9]; memcpy(&outBuffer[6], ShmPsuData->PsuVersion[inputBuffer[9]].FwPrimaryVersion, ARRAY_SIZE(ShmPsuData->PsuVersion[inputBuffer[9]].FwPrimaryVersion)); memcpy(&outBuffer[22], ShmPsuData->PsuVersion[inputBuffer[9]].FwSecondVersion, ARRAY_SIZE(ShmPsuData->PsuVersion[inputBuffer[9]].FwSecondVersion)); outBuffer[38] = chksumCal(outBuffer); break; case WIFI_CMD_GET_VER_AUX_POWER: DEBUG_INFO("Receive get AUX power version command.\n"); DEBUG_INFO("Version: %s.\n", ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev); tx_size = 38; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x22; outBuffer[4] = WIFI_CMD_GET_VER_AUX_POWER; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev)); outBuffer[37] = chksumCal(outBuffer); break; case WIFI_CMD_GET_VER_FAN: DEBUG_INFO("Receive get fan board version command.\n"); DEBUG_INFO("Version: %s.\n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev); tx_size = 38; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x22; outBuffer[4] = WIFI_CMD_GET_VER_FAN; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev)); outBuffer[37] = chksumCal(outBuffer); break; case WIFI_CMD_GET_VER_RELAY: DEBUG_INFO("Receive get relay board version command.\n"); DEBUG_INFO("Version: %s.\n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev); tx_size = 38; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x22; outBuffer[4] = WIFI_CMD_GET_VER_RELAY; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev)); outBuffer[37] = chksumCal(outBuffer); break; case WIFI_CMD_GET_VER_TELECOMM: DEBUG_INFO("Receive get telecomm version command.\n"); DEBUG_INFO("Vesion: %s.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer); tx_size = 38; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x22; outBuffer[4] = WIFI_CMD_GET_VER_TELECOMM; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer)); outBuffer[37] = chksumCal(outBuffer); break; case WIFI_CMD_GET_EVSE_CONFIG: DEBUG_INFO("Receive get EVSE config command.\n"); DEBUG_INFO("MaxChargingEnergy: %d.\n", SysConfigTemporarily.MaxChargingEnergy); DEBUG_INFO("MaxChargingPower: %d.\n", SysConfigTemporarily.MaxChargingPower); DEBUG_INFO("MaxChargingCurrent: %d.\n", SysConfigTemporarily.MaxChargingCurrent); DEBUG_INFO("MaxChargingDuration: %d.\n", SysConfigTemporarily.MaxChargingDuration); DEBUG_INFO("AcMaxChargingCurrent: %d.\n", SysConfigTemporarily.AcMaxChargingCurrent); tx_size = 16; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x0C; outBuffer[4] = WIFI_CMD_GET_EVSE_CONFIG; outBuffer[5] = (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy>>0x08) & 0xff; outBuffer[6] = (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy>>0x00) & 0xff; outBuffer[7] = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower>>0x08) & 0xff; outBuffer[8] = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower>>0x00) & 0xff; outBuffer[9] = (ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>>0x08) & 0xff; outBuffer[10] = (ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>>0x00) & 0xff; outBuffer[11] = (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration>>0x08) & 0xff; outBuffer[12] = (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration>>0x00) & 0xff; outBuffer[13] = (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent>>0x08) & 0xff; outBuffer[14] = (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent>>0x00) & 0xff; outBuffer[15] = chksumCal(outBuffer); break; case WIFI_CMD_GET_GUN_STS: DEBUG_INFO("Receive get connector-%02d status command.\n", inputBuffer[9]); tx_size = 21; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x11; outBuffer[4] = WIFI_CMD_GET_GUN_STS; outBuffer[5] = inputBuffer[9]; getConnectorInfo(inputBuffer[9], outBuffer); outBuffer[20] = chksumCal(outBuffer); DEBUG_INFO("Status: %d.\n", outBuffer[6]); break; case WIFI_CMD_GET_GUN_USER: DEBUG_INFO("Receive get connector user command.\n"); tx_size = 40; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x24; outBuffer[4] = WIFI_CMD_GET_GUN_USER; outBuffer[5] = inputBuffer[9]; getConnectorUser(inputBuffer[9], outBuffer); outBuffer[39] = chksumCal(outBuffer); DEBUG_INFO("User ID: %s.\n", &outBuffer[7]); break; case WIFI_CMD_GET_SCHEDULE: DEBUG_INFO("Receive get connector-%02d schedule command.\n", inputBuffer[9]); tx_size = 14; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x0a; outBuffer[4] = WIFI_CMD_GET_SCHEDULE; outBuffer[5] = inputBuffer[9]; getConnectorSchedule(inputBuffer[9], outBuffer); outBuffer[13] = chksumCal(outBuffer); break; case WIFI_CMD_GET_NETWORK_STS: DEBUG_INFO("Receive get network status command.\n"); if(ShmSysConfigAndInfo->SysInfo.InternetConn) DEBUG_INFO("Internet enable.\n"); else DEBUG_INFO("Internet disable.\n"); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_NETWORK_STS; outBuffer[5] = ShmSysConfigAndInfo->SysInfo.InternetConn; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_ETH_DHCP: DEBUG_INFO("Receive get eth dhcp command.\n"); if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1) DEBUG_INFO("DHCP enable.\n"); else DEBUG_INFO("DHCP disable.\n"); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_ETH_DHCP; outBuffer[5] = ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient^1; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_ETH_MAC: DEBUG_INFO("Receive get eth MAC address command.\n"); DEBUG_INFO("MAC address: %s\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress); tx_size = 24; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x14; outBuffer[4] = WIFI_CMD_GET_ETH_MAC; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress)); outBuffer[23] = chksumCal(outBuffer); break; case WIFI_CMD_GET_ETH_IP: DEBUG_INFO("Receive get eth ip address command.\n"); DEBUG_INFO("IP address: %s\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_ETH_IP; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_GET_ETH_SUBMASK: DEBUG_INFO("Receive get eth submask command.\n"); DEBUG_INFO("Submask address: %s\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_ETH_SUBMASK; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_GET_ETH_GATEWAY: DEBUG_INFO("Receive get eth gateway command.\n"); DEBUG_INFO("Gateway address: %s\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_ETH_GATEWAY; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_MODE: DEBUG_INFO("Receive get wifi mode command.\n"); switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode) { case 0: DEBUG_INFO("Disable.\n"); break; case 1: DEBUG_INFO("Station mode.\n"); break; case 2: DEBUG_INFO("Ap mode.\n"); break; } tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_WIFI_MODE; outBuffer[5] = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_SSID: DEBUG_INFO("Receive get wifi ssid command.\n"); DEBUG_INFO("SSID: %s.\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid); tx_size = 261; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x01; outBuffer[3] = 0x01; outBuffer[4] = WIFI_CMD_GET_WIFI_SSID; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid)); outBuffer[260] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_PASSWD: DEBUG_INFO("Receive get wifi password command.\n"); DEBUG_INFO("Password: %s.\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword); tx_size = 261; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x01; outBuffer[3] = 0x01; outBuffer[4] = WIFI_CMD_GET_WIFI_PASSWD; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword)); outBuffer[260] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_RSSI: DEBUG_INFO("Receive get wifi rssi command.\n"); DEBUG_INFO("RSSI: %d.\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_WIFI_RSSI; outBuffer[5] = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi+100; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_DHCP: DEBUG_INFO("Receive get wifi dhcp command.\n"); if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1) DEBUG_INFO("DHCP enable.\n"); else DEBUG_INFO("DHCP disable.\n"); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_WIFI_DHCP; outBuffer[5] = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient^1; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_MAC: DEBUG_INFO("Receive get wifi MAC command.\n"); DEBUG_INFO("MAC address: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress); tx_size = 24; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x14; outBuffer[4] = WIFI_CMD_GET_WIFI_MAC; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress)); outBuffer[23] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_IP: DEBUG_INFO("Receive get wifi ip address command.\n"); DEBUG_INFO("IP address: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_WIFI_IP; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_NETMASK: DEBUG_INFO("Receive get wifi submask command.\n"); DEBUG_INFO("Submask address: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_WIFI_NETMASK; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_GET_WIFI_GATEWAY: DEBUG_INFO("Receive get wifi gateway command.\n"); DEBUG_INFO("Gateway address: %s\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_WIFI_GATEWAY; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_APN: DEBUG_INFO("Receive get telecomm APN command.\n"); DEBUG_INFO("APN: %s.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn); tx_size = 262; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x01; outBuffer[3] = 0x02; outBuffer[4] = WIFI_CMD_GET_TELE_APN; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn)); outBuffer[261] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_RSSI: DEBUG_INFO("Receive get telecomm rssi command.\n"); DEBUG_INFO("RSSI: %d.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_TELE_RSSI; outBuffer[5] = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi+100; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_CHAP_ID: DEBUG_INFO("Receive get telecomm CHAP ID command.\n"); DEBUG_INFO("ID: %s.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId); tx_size = 262; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x01; outBuffer[3] = 0x02; outBuffer[4] = WIFI_CMD_GET_TELE_CHAP_ID; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId)); outBuffer[261] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_CHAP_PASSWD: DEBUG_INFO("Receive get telecomm CHAP password command.\n"); DEBUG_INFO("Password: %s.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd); tx_size = 262; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x01; outBuffer[3] = 0x02; outBuffer[4] = WIFI_CMD_GET_TELE_CHAP_PASSWD; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd)); outBuffer[261] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_IMEI: DEBUG_INFO("Receive get telecomm IMEI command.\n"); DEBUG_INFO("Telecomm IMEI: %s.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_TELE_IMEI; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_IMSI: DEBUG_INFO("Receive get telecomm IMSI command.\n"); DEBUG_INFO("Telecomm IMSI: %s.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_TELE_IMSI; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_SIM_STS: DEBUG_INFO("Receive get telecomm SIM status command.\n"); DEBUG_INFO("Telecomm SIM status: %d.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_TELE_SIM_STS; outBuffer[5] = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_MODE: DEBUG_INFO("Receive get telecommand mode command.\n"); DEBUG_INFO("Telecomm mode: %d.\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_GET_TELE_MODE; outBuffer[5] = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_GET_TELE_IP: DEBUG_INFO("Receive get telecomm ip address command.\n"); DEBUG_INFO("IP adress: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress); tx_size = 22; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x12; outBuffer[4] = WIFI_CMD_GET_TELE_IP; memcpy(&outBuffer[5], ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress)); outBuffer[21] = chksumCal(outBuffer); break; case WIFI_CMD_SET_SYSTEM_TIME: DEBUG_INFO("Receive set system time command.\n"); rawtime = (inputBuffer[9]<<0) | (inputBuffer[10]<<8) | (inputBuffer[11]<<16) |(inputBuffer[12]<<24); ts = *localtime(&rawtime); sprintf((char*)cmdBuf, "date -u -s \"%04d-%02d-%02d %02d:%02d:%02d\"", (ts.tm_year+1900), (ts.tm_mon+1), ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec); system((char*)cmdBuf); system("hwclock -w -u"); system("hwclock -s"); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_SYSTEM_TIME; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_WHITE_CARD: DEBUG_INFO("Receive set white list command.\n"); if((0<=inputBuffer[9]) && (inputBuffer[9]<10)) { if(inputBuffer[10] == REGISTER) { // Register white card memcpy(SysConfigTemporarily.LocalWhiteCard[inputBuffer[9]], &inputBuffer[11],(((inputBuffer[2] << 8) | inputBuffer[3])-8)); DEBUG_INFO("Register list-%02d: %s.\n", inputBuffer[9], SysConfigTemporarily.LocalWhiteCard[inputBuffer[9]]); } else if (inputBuffer[10] == CLEAR_REGISTER) { // Clear register white card memset(SysConfigTemporarily.LocalWhiteCard[inputBuffer[9]], 0x00, ARRAY_SIZE(SysConfigTemporarily.LocalWhiteCard[inputBuffer[9]])); DEBUG_INFO("Unregister list-%02d: %s.\n", inputBuffer[9], SysConfigTemporarily.LocalWhiteCard[inputBuffer[9]]); } outBuffer[6] = 0x01; } else { outBuffer[6] = 0x00; } tx_size = 8; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x04; outBuffer[4] = WIFI_CMD_SET_WHITE_CARD; outBuffer[5] = inputBuffer[9]; outBuffer[7] = chksumCal(outBuffer); break; case WIFI_CMD_SET_FACTORY_RESET: DEBUG_INFO("Receive set factory default command.\n"); ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = ON; tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_FACTORY_RESET; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_EVSE_CONFIG: DEBUG_INFO("Receive set EVSE config command.\n"); if((inputBuffer[9]>>4)&0x01) { SysConfigTemporarily.AcMaxChargingCurrent = (inputBuffer[18]) | (inputBuffer[19]<<8); DEBUG_INFO("AcMaxChargingCurrent: %d.\n", SysConfigTemporarily.AcMaxChargingCurrent); } if((inputBuffer[9]>>3)&0x01) { SysConfigTemporarily.MaxChargingEnergy = (inputBuffer[10]) | (inputBuffer[11]<<8); DEBUG_INFO("MaxChargingEnergy: %d.\n", SysConfigTemporarily.MaxChargingEnergy); } if((inputBuffer[9]>>2)&0x01) { SysConfigTemporarily.MaxChargingPower = (inputBuffer[12]) | (inputBuffer[13]<<8); DEBUG_INFO("MaxChargingPower: %d.\n", SysConfigTemporarily.MaxChargingPower); } if((inputBuffer[9]>>1)&0x01) { SysConfigTemporarily.MaxChargingCurrent = (inputBuffer[14]) | (inputBuffer[15]<<8); DEBUG_INFO("MaxChargingCurrent: %d.\n", SysConfigTemporarily.MaxChargingCurrent); } if(inputBuffer[9]&0x01) { SysConfigTemporarily.MaxChargingDuration = (inputBuffer[16]) | (inputBuffer[17]<<8); DEBUG_INFO("MaxChargingDuration: %d.\n", SysConfigTemporarily.MaxChargingDuration); } tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_EVSE_CONFIG; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_CHARGING_START: DEBUG_INFO("Receive set connector start charging command.\n"); DEBUG_INFO("Gun_index: %d.\n", inputBuffer[9]); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_CHARGING_START; outBuffer[5] = (startConnectorCharging(inputBuffer[9])?0x01:0x00); outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_CHARGING_STOP: DEBUG_INFO("Receive set connector stop charging command.\n"); DEBUG_INFO("Gun_index: %d.\n", inputBuffer[9]); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_CHARGING_STOP; outBuffer[5] = (stopConnectorCharging(inputBuffer[9])?0x01:0x00); outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_SCHEDULE: DEBUG_INFO("Receive set connector schedule command.\n"); DEBUG_INFO("Gun_index: %d.\n", inputBuffer[9]); if(inputBuffer[10]) DEBUG_INFO("Schedule enable.\n"); else DEBUG_INFO("Schedule disable.\n"); if(inputBuffer[11]) DEBUG_INFO("Schedule type: Daily.\n"); else DEBUG_INFO("Schedule type: Once.\n"); if(inputBuffer[12]) DEBUG_INFO("Schedule end method: Specific stop time.\n"); else DEBUG_INFO("Schedule end method: Continuous.\n"); DEBUG_INFO("Schedule start hour: %d.\n", inputBuffer[13]); DEBUG_INFO("Schedule start minute: %d.\n", inputBuffer[14]); DEBUG_INFO("Schedule stop hour: %d.\n", inputBuffer[15]); DEBUG_INFO("Schedule stop minute: %d.\n", inputBuffer[16]); //setConnectorSchedule(inputBuffer[9], inputBuffer); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_SCHEDULE; outBuffer[5] = (setConnectorSchedule(inputBuffer[9], inputBuffer)?0x01:0x00); outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_ETH_CONFIG: DEBUG_INFO("Receive set eth dhcp command.\n"); if(inputBuffer[9]) DEBUG_INFO("DHCP enable.\n"); else DEBUG_INFO("DHCP disable.\n"); SysConfigTemporarily.Eth0Interface.EthDhcpClient = inputBuffer[9]^1; tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_ETH_CONFIG; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_ETH_IP: DEBUG_INFO("Receive set eth ip address command.\n"); memset(SysConfigTemporarily.Eth0Interface.EthIpAddress, 0x00, ARRAY_SIZE(SysConfigTemporarily.Eth0Interface.EthIpAddress)); memcpy(SysConfigTemporarily.Eth0Interface.EthIpAddress, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("IP adress: %s\n", SysConfigTemporarily.Eth0Interface.EthIpAddress); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_ETH_IP; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_ETH_SUBMASK: DEBUG_INFO("Receive set eth submask command.\n"); memset(SysConfigTemporarily.Eth0Interface.EthSubmaskAddress, 0x00, ARRAY_SIZE(SysConfigTemporarily.Eth0Interface.EthSubmaskAddress)); memcpy(SysConfigTemporarily.Eth0Interface.EthSubmaskAddress, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("Submask adress: %s\n", SysConfigTemporarily.Eth0Interface.EthSubmaskAddress); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_ETH_SUBMASK; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_ETH_GATEWAY: DEBUG_INFO("Receive set eth gateway command.\n"); memset(SysConfigTemporarily.Eth0Interface.EthGatewayAddress, 0x00, ARRAY_SIZE(SysConfigTemporarily.Eth0Interface.EthGatewayAddress)); memcpy(SysConfigTemporarily.Eth0Interface.EthGatewayAddress, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("Gateway adress: %s\n", SysConfigTemporarily.Eth0Interface.EthGatewayAddress); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_ETH_GATEWAY; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_WIFI_MODE: DEBUG_INFO("Receive set wifi mode command.\n"); switch(inputBuffer[9]) { case 0: DEBUG_INFO("WIFI disable.\n"); break; case 1: DEBUG_INFO("WIFI station mode.\n"); break; case 2: DEBUG_INFO("WIFI ap mode.\n"); break; } SysConfigTemporarily.AthInterface.WifiMode = inputBuffer[9]; tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_WIFI_MODE; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_WIFI_SSID: DEBUG_INFO("Receive set wifi SSID command.\n"); memset(SysConfigTemporarily.AthInterface.WifiSsid, 0x00, ARRAY_SIZE(SysConfigTemporarily.AthInterface.WifiSsid)); memcpy(SysConfigTemporarily.AthInterface.WifiSsid, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("SSID: %s\n", SysConfigTemporarily.AthInterface.WifiSsid); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_WIFI_SSID; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_WIFI_PASSWD: DEBUG_INFO("Receive set wifi password command.\n"); memset(SysConfigTemporarily.AthInterface.WifiPassword, 0x00, ARRAY_SIZE(SysConfigTemporarily.AthInterface.WifiPassword)); memcpy(SysConfigTemporarily.AthInterface.WifiPassword, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("Password: %s\n", SysConfigTemporarily.AthInterface.WifiPassword); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_WIFI_PASSWD; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_WIFI_DHCP: DEBUG_INFO("Receive set wifi dhcp command.\n"); if(inputBuffer[9]) DEBUG_INFO("DHCP enable.\n"); else DEBUG_INFO("DHCP disable.\n"); SysConfigTemporarily.AthInterface.WifiDhcpClient = inputBuffer[9]^1; tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_WIFI_DHCP; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_WIFI_IP: DEBUG_INFO("Receive set wifi ip address command.\n"); memset(SysConfigTemporarily.AthInterface.WifiIpAddress, 0x00, ARRAY_SIZE(SysConfigTemporarily.AthInterface.WifiIpAddress)); memcpy(SysConfigTemporarily.AthInterface.WifiIpAddress, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("IP adress: %s\n", SysConfigTemporarily.AthInterface.WifiIpAddress); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_WIFI_IP; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_WIFI_NETMASK: DEBUG_INFO("Receive set wifi submake command.\n"); DEBUG_INFO("Submask adress: %d.%d.%d.%d\n", inputBuffer[9], inputBuffer[10], inputBuffer[11], inputBuffer[12]); memset(SysConfigTemporarily.AthInterface.WifiSubmaskAddress, 0x00, ARRAY_SIZE(SysConfigTemporarily.AthInterface.WifiSubmaskAddress)); memcpy(SysConfigTemporarily.AthInterface.WifiSubmaskAddress, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("Submask adress: %s\n", SysConfigTemporarily.AthInterface.WifiSubmaskAddress); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_WIFI_NETMASK; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_WIFI_GATEWAY: DEBUG_INFO("Receive set wifi gateway command.\n"); memset(SysConfigTemporarily.AthInterface.WifiGatewayAddress, 0x00, ARRAY_SIZE(SysConfigTemporarily.AthInterface.WifiGatewayAddress)); memcpy(SysConfigTemporarily.AthInterface.WifiGatewayAddress, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("Gateway adress: %s\n", SysConfigTemporarily.AthInterface.WifiGatewayAddress); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_WIFI_GATEWAY; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_TELE_APN: DEBUG_INFO("Receive set telecomm APN command.\n"); memset(SysConfigTemporarily.TelecomInterface.TelcomApn, 0x00, ARRAY_SIZE(SysConfigTemporarily.TelecomInterface.TelcomApn)); memcpy(SysConfigTemporarily.TelecomInterface.TelcomApn, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("APN: %s\n", SysConfigTemporarily.TelecomInterface.TelcomApn); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_TELE_APN; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_TELE_CHAP_ID: DEBUG_INFO("Receive set telecomm CHAP ID command.\n"); memset(SysConfigTemporarily.TelecomInterface.TelcomChapPapId, 0x00, ARRAY_SIZE(SysConfigTemporarily.TelecomInterface.TelcomChapPapId)); memcpy(SysConfigTemporarily.TelecomInterface.TelcomChapPapId, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("ID: %s\n", SysConfigTemporarily.TelecomInterface.TelcomChapPapId); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_TELE_CHAP_ID; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_TELE_CHAP_PASSWD: DEBUG_INFO("Receive set telecomm CHAP password command.\n"); memset(SysConfigTemporarily.TelecomInterface.TelcomChapPapPwd, 0x00, ARRAY_SIZE(SysConfigTemporarily.TelecomInterface.TelcomChapPapPwd)); memcpy(SysConfigTemporarily.TelecomInterface.TelcomChapPapPwd, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("Password: %s\n", SysConfigTemporarily.TelecomInterface.TelcomChapPapPwd); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_TELE_CHAP_PASSWD; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_TELE_IP: DEBUG_INFO("Receive set telecomm ip address command.\n"); memset(SysConfigTemporarily.TelecomInterface.TelcomIpAddress, 0x00, ARRAY_SIZE(SysConfigTemporarily.TelecomInterface.TelcomIpAddress)); memcpy(SysConfigTemporarily.TelecomInterface.TelcomIpAddress, &inputBuffer[9], (((inputBuffer[2] << 8) | inputBuffer[3])-6)); DEBUG_INFO("IP adress: %s\n", SysConfigTemporarily.TelecomInterface.TelcomIpAddress); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_TELE_IP; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; case WIFI_CMD_SET_CONFIRM: DEBUG_INFO("Receive set confirm configuration command.\n"); // Copy SysConfigTemporarily to ShmSysConfigAndInfo->SysConfig memcpy(&ShmSysConfigAndInfo->SysConfig,&SysConfigTemporarily, sizeof(struct SysConfigData)); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_CONFIRM; outBuffer[5] = (StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig)!=0x01?0x00:0x01); outBuffer[6] = chksumCal(outBuffer); Sys_Flag.isPkill = ON; break; case WIFI_CMD_SET_DISCARD: DEBUG_INFO("Receive set discard command.\n"); // Copy ShmSysConfigAndInfo to SysConfigTemporarily memcpy(&SysConfigTemporarily, &ShmSysConfigAndInfo->SysConfig, sizeof(struct SysConfigData)); tx_size = 7; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x03; outBuffer[4] = WIFI_CMD_SET_DISCARD; outBuffer[5] = 0x01; outBuffer[6] = chksumCal(outBuffer); break; default: DEBUG_WARN("Receive unknown command.\n"); tx_size = 6; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x02; outBuffer[4] = WIFI_CMD_UNKNOW; outBuffer[5] = chksumCal(outBuffer); break; } } else { DEBUG_WARN("Receive command check sum error.\n"); tx_size = 6; outBuffer[0] = 0xff; outBuffer[1] = 0xff; outBuffer[2] = 0x00; outBuffer[3] = 0x02; outBuffer[4] = inputBuffer[8]; outBuffer[5] = chksumCal(outBuffer); } displayMessage(outBuffer, tx_size, NO); send(clientSockFd, outBuffer, tx_size, 0); } if(read_size == 0) { DEBUG_INFO("Client disconnected.\n"); wifi_login_info.loginRole = ROLE_UNKNOWN; memset(&wifi_login_info.loginId[0], 0x00, ARRAY_SIZE(wifi_login_info.loginId)); close(clientSockFd); if(Sys_Flag.isPkill == ON) { Sys_Flag.isPkill = OFF; shutdown(sockFd, SHUT_RDWR); close(sockFd); DEBUG_INFO("pKill Module_Wifi after set confirm...\n"); system("pkill Module_Wifi"); } // Copy ShmSysConfigAndInfo to SysConfigTemporarily memcpy(&SysConfigTemporarily, &ShmSysConfigAndInfo->SysConfig, sizeof(struct SysConfigData)); fflush(stdout); } else if(read_size == -1) { DEBUG_ERROR("Socket recv failed.\n"); } exit(0); } else { // if parent, close the socket and go back to listening new requests close(clientSockFd); } sleep(1); } return FAIL; } //========================================== // Common routine //========================================== void trim(char *s) { int i=0, j, k, l=0; while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n')) i++; j = strlen(s)-1; while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n')) j--; if(i==0 && j==strlen(s)-1) { } else if(i==0) s[j+1] = '\0'; else { for(k=i; k<=j; k++) s[l++] = s[k]; s[l] = '\0'; } } int mystrcmp(char *p1,char *p2) { while(*p1==*p2) { if(*p1=='\0' || *p2=='\0') break; p1++; p2++; } if(*p1=='\0' && *p2=='\0') return(PASS); else return(FAIL); } void substr(char *dest, const char* src, unsigned int start, unsigned int cnt) { strncpy(dest, src + start, cnt); dest[cnt] = 0; } void split(char **arr, char *str, const char *del) { char *s = strtok(str, del); while(s != NULL) { *arr++ = s; s = strtok(NULL, del); } } int checkIP(void) { // DHCP or static setting int isGetIP = FAIL; FILE *fp; char buf[512]; char tmp[512]; char cmd[512]; if(Wifi.ipType == IP_TYPE_DHCP) { // Get IP address & net mask strcpy(cmd, "ifconfig "); strcat(cmd, Wifi.currentInterface); fp = popen(cmd, "r"); if(fp == NULL) isGetIP = FAIL; else { while(fgets(buf, sizeof(buf), fp) != NULL) { if(strstr(buf, "addr:") > 0) { if(strstr(buf, "192.168.1.10") > 0) { DEBUG_INFO("IP cannot be same as default value of Ethernet...\n"); } else { isGetIP = PASS; cnt_getIP_Fail = 0; } sscanf(buf, "%*s%s", tmp); substr(Wifi.currentIPAddr, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:")); sscanf(buf, "%*s%*s%*s%s", tmp); substr(Wifi.currentNetmask, tmp, strspn(tmp, "Mask:"), strlen(buf)-strspn(tmp, "Mask:")); }else { } } } if(isGetIP == FAIL && cnt_getIP_Fail<3) { sprintf(cmd, "pgrep -f \"udhcpc -i %s\" | xargs kill", Wifi.currentInterface); system(cmd); if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient==0) { sprintf(cmd, "/sbin/udhcpc -i %s -s /root/dhcp_script/wifi.script > /dev/null &", Wifi.currentInterface); system(cmd); } DEBUG_INFO("Sending DHCP request...\n"); cnt_getIP_Fail++; sleep(5); } pclose(fp); }else { strcpy(cmd, "ifconfig "); strcat(cmd, Wifi.currentInterface); strcat(cmd, " "); strcat(cmd, Wifi.staticIPAddr); fp = popen(cmd, "r"); DEBUG_INFO("Setting static IP to %s ...\n", Wifi.staticIPAddr); pclose(fp); isGetIP = PASS; } cnt_getIP_Fail = 0; return isGetIP; } int restartWPA(void) { int result = FAIL; FILE *fp; char buf[512]; char cmd[50]; // Get IP address & net mask strcpy(cmd, "wpa_cli -i "); strcat(cmd, Wifi.currentInterface); strcat(cmd, " reconfigure"); fp = popen(cmd, "r"); DEBUG_INFO("WPA reconfigure %s ...\n", Wifi.currentInterface); if(fp == NULL) result = FAIL; else { while(fgets(buf, sizeof(buf), fp) != NULL) { if(strstr(buf, "OK") > 0) { DEBUG_INFO("reconfigure OK.\n"); result = PASS; }else { DEBUG_INFO("reconfigure failed.\n"); result = FAIL; } } } pclose(fp); if(result == PASS) { strcpy(cmd, "wpa_cli -i "); strcat(cmd, Wifi.currentInterface); strcat(cmd, " reconfigure"); fp = popen(cmd, "r"); DEBUG_INFO("WPA reconnect %s ...\n", Wifi.currentInterface); if(fp == NULL) result = FAIL; else{ while(fgets(buf, sizeof(buf), fp) != NULL) { if(strstr(buf, "OK") > 0){ DEBUG_INFO("reconnect OK.\n"); result = PASS; }else { DEBUG_INFO("reconnect failed.\n"); result = FAIL; } } } pclose(fp); } return result; } int resetModule(void) { //refreshUSB(); #ifdef UBLOX system("ifconfig mlan0 down"); sleep(1); system("ifconfig mlan0 up"); #endif #ifdef MT7601U system("ifconfig wlan0 down"); sleep(1); system("ifconfig wlan0 up"); #endif DEBUG_WARN("Wifi interface restart.\n"); return PASS; } void proc_sta() { switch(Wifi_module_sts) { case STA_STATE_INIT: dispReq.isShowed_IF_info = false; // get info from shared memory getParameters(); ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1; ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=1; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0; isSetWPA_OK = false; // check interface if((strlen((const char*)Wifi_A.ssid)>0) && (isFindInterface() == PASS)) { DEBUG_INFO("Wifi interface: %s\n", Wifi.currentInterface); Wifi_module_sts = STA_STATE_DEVICE_DETECT; ShmStatusCodeData->FaultCode.FaultEvents.bits.WiFiModuleBroken=0; DEBUG_INFO("=================[State 1]===================\n"); } else { ShmStatusCodeData->FaultCode.FaultEvents.bits.WiFiModuleBroken=1; DEBUG_ERROR("Wifi support interface valid result: Fail\n"); sleep(30); } break; case STA_STATE_DEVICE_DETECT: dispReq.isShowed_IP_info = false; if(!isSetWPA_OK && (setWPAconf() == PASS)) { isSetWPA_OK = true; sleep(5); } else if((isSetWPA_OK == true) && (isConnectAP() == PASS)) { Wifi_module_sts = STA_STATE_AP_CONNECTED; ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=0; ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=0; DEBUG_INFO("=================[State 2]===================\n"); } else { cnt_getAP_Fail++; DEBUG_INFO("Fail to connect to the AP %d times...\n",cnt_getAP_Fail); if(cnt_getAP_Fail>=3) { resetModule(); Wifi_module_sts = STA_STATE_INIT; cnt_getAP_Fail = 0; ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=1; DEBUG_INFO("=================[State 0]===================\n"); } else { sleep(10); } } break; case STA_STATE_AP_CONNECTED: getInterfaceInfo(); getLinkQuality(); DEBUG_INFO("Wifi quality: %d dBm\n", Wifi.rssi); ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi = Wifi.rssi; if(isReachableInternet() == PASS) { DEBUG_INFO("Wifi internet valid result: Pass\n"); ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=0; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=1; cnt_pingDNS_Fail = 0; sleep(30); } else { cnt_pingDNS_Fail++; DEBUG_INFO("Wifi internet valid result: Fail %d time\n", cnt_pingDNS_Fail); sleep(5); } if(cnt_pingDNS_Fail >= 3) { ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1; if(((!ShmSysConfigAndInfo->SysInfo.OcppConnStatus && (strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0)) || (strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") == 0))) { ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0; cnt_pingDNS_Fail = 0; DEBUG_INFO("Ping DNS failed...\n"); memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress); memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress); memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress); resetModule(); if(isFindInterface() == PASS) { DEBUG_INFO("Wifi interface: %s\n", Wifi.currentInterface); getParameters(); isSetWPA_OK = false; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi = 0; Wifi_module_sts = STA_STATE_DEVICE_DETECT; DEBUG_INFO("=================[State 1]===================\n"); } else { DEBUG_INFO("Wifi support interface valid result: Fail\n"); ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi = 0; Wifi_module_sts = STA_STATE_INIT; DEBUG_INFO("=================[State 0]===================\n"); } } } break; default: Wifi_module_sts = STA_STATE_INIT; break; } } void proc_ap() { switch(Wifi_module_sts) { case AP_STATE_INIT: // get info from shared memory getParameters(); isSetWPA_OK = false; ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1; ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=1; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0; // check interface if(isFindInterface() == PASS) { DEBUG_INFO("Wifi interface: %s\n", Wifi.currentInterface); Wifi_module_sts = AP_STATE_DEVICE_DETECT; ShmStatusCodeData->FaultCode.FaultEvents.bits.WiFiModuleBroken=0; DEBUG_INFO("=================[State 1]===================\n"); } else { ShmStatusCodeData->FaultCode.FaultEvents.bits.WiFiModuleBroken=1; DEBUG_ERROR("Wifi support interface valid result: Fail\n"); sleep(30); } break; case AP_STATE_DEVICE_DETECT: dispReq.isShowed_IP_info = false; if(!isSetWPA_OK && (setWPAconf() == PASS)) { isSetWPA_OK = true; sleep(5); } else if(isSetWPA_OK && (isStartUpAP() == PASS)) { Wifi_module_sts = AP_STATE_AP_START; ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1; ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=0; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0; ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=0; DEBUG_INFO("=================[State 2]===================\n"); } else { cnt_getAP_Fail++; DEBUG_INFO("Fail to start up AP %d times...\n",cnt_getAP_Fail); if(cnt_getAP_Fail>=3) { Wifi_module_sts = AP_STATE_INIT; cnt_getAP_Fail = 0; ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=1; DEBUG_INFO("=================[State 0]===================\n"); } else { sleep(10); } } break; case AP_STATE_AP_START: getInterfaceInfo(); if(isStartUpAP() == PASS) { DEBUG_INFO("Wifi AP start up valid result: Pass\n"); ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1; ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=0; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0; cnt_pingDNS_Fail = 0; sleep(30); } else { cnt_pingDNS_Fail++; DEBUG_INFO("Wifi AP start up valid result: Fail %d time\n", cnt_pingDNS_Fail); sleep(5); } if(cnt_pingDNS_Fail >= 3) { ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1; ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=1; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0; cnt_pingDNS_Fail = 0; DEBUG_INFO("Wifi AP start up status failed...\n"); memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress); memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress); memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress); if(isFindInterface() == PASS) { DEBUG_INFO("Wifi interface: %s\n", Wifi.currentInterface); isSetWPA_OK = false; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi = 0; Wifi_module_sts = STA_STATE_DEVICE_DETECT; DEBUG_INFO("=================[State 1]===================\n"); } else { DEBUG_INFO("Wifi support interface valid result: Fail\n"); ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi = 0; Wifi_module_sts = STA_STATE_INIT; DEBUG_INFO("=================[State 0]===================\n"); } } break; default: Wifi_module_sts = AP_STATE_INIT; break; } } void proc_killConnection() { char cmdBuf[512]; // Initialization flags when network is disable mode ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=ON; ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=OFF; ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=OFF; ShmStatusCodeData->FaultCode.FaultEvents.bits.WiFiModuleBroken=OFF; ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=OFF; // Stop dhcp client or server sprintf(cmdBuf, "pgrep -f \"udhcpc -i %s\" | xargs kill", Wifi.currentInterface); system(cmdBuf); sprintf(cmdBuf, "pgrep -f \"udhcpd /etc/udhcpd.conf\" | xargs kill"); system(cmdBuf); // Restart wpa_supplicant sprintf(cmdBuf, "pgrep -f \"wpa_supplicant\" | xargs kill"); system(cmdBuf); // Stop wifi AP sprintf(cmdBuf, "pgrep -f \"hostapd\" | xargs kill"); system(cmdBuf); #ifdef UBLOX system("ifconfig mlan0 down"); system("ifconfig uap0 down"); #endif #ifdef MT7601U system("ifconfig wlan0 down"); #endif // Clean share memory when network is disable mode memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress); memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress); memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress); } unsigned int isKernelSupportNAT() { unsigned int result = NO; unsigned int version = 0; FILE *fp; char cmd[256]; char buf[512]; // Get IP address & net mask strcpy(cmd, "uname -v"); fp = popen(cmd, "r"); if(fp != NULL) { if(fgets(buf, sizeof(buf), fp) != NULL) { sscanf(buf, "#%d", &version); DEBUG_INFO("Kernel version: %d\n", version); if(version >= 30) result = YES; } } pclose(fp); return result; } //========================================== // Main loop //========================================== int main(void) { pid_t pid; signal(SIGCHLD,SIG_IGN); if(InitShareMemory() == FAIL) { DEBUG_ERROR("InitShareMemory NG\n"); if(ShmStatusCodeData!=NULL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=ON; } sleep(5); return 0; } // Local database initial if(DB_Open(localDb) != PASS) { DEBUG_ERROR("Puk pin list local db initial fail.\n"); } // Load schedule from local database for(int gun_index=0;gun_index<(AC_QUANTITY+CHAdeMO_QUANTITY+CCS_QUANTITY+GB_QUANTITY);gun_index++) scheduleLoadFromDb(localDb, gun_index); // Wifi login info initial & PUK generate wifi_login_info.loginRole = ROLE_UNKNOWN; memset(&wifi_login_info.loginId[0], 0x00, ARRAY_SIZE(wifi_login_info.loginId)); memset(&wifi_login_info.puk[0], 0x00, ARRAY_SIZE(wifi_login_info.puk)); sprintf((char*)wifi_login_info.puk, "%08X", ~stm32crc((uint32_t*)&ShmSysConfigAndInfo->SysConfig.SystemId[0], (ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)>>2))); DEBUG_INFO("System ID: %s\n", ShmSysConfigAndInfo->SysConfig.SystemId); DEBUG_INFO("EVSE PUK: %s\n", wifi_login_info.puk); // UDP socket server start pid = fork(); if(pid == 0) { if(udpSocketServerStart() == FAIL) { DEBUG_ERROR("UDP socket server down.\n"); return 0; } } // TCP socket server start pid = fork(); if(pid == 0) { if(tcpSocketServerStart() == FAIL) { DEBUG_ERROR("TCP socket server down.\n"); return 0; } } // Schedule check thread start pid = fork(); if(pid == 0) { for(;;) { // Check schedule start/stop event checkSchedule(); sleep(1); } return 0; } //============================================= // Install WIFI module driver //============================================= #ifdef UBLOX if(isKernelSupportNAT() == YES) { system("insmod /lib/modules/mlan_nat.ko"); system("insmod /lib/modules/usb8801_nat.ko"); } else { system("insmod /lib/modules/mlan.ko"); system("insmod /lib/modules/usb8801.ko"); } system("echo 1 > /proc/sys/net/ipv4/ip_forward"); sleep(5); system("ifconfig mlan0 up"); system("ifconfig uap0 up"); #endif #ifdef MT7601U system("insmod /lib/modules/mt7601u.ko"); sleep(5); system("ifconfig wlan0 up"); #endif DEBUG_INFO("========================================\n"); DEBUG_INFO("Latest Firmware Version : [ %s ].\n", Version_And_Date[0]); DEBUG_INFO("Latest Upgrade Date : [ %s ].\n", Version_And_Date[1]); DEBUG_INFO("========================================\n"); DEBUG_INFO("=================[State 0]===================\n"); for(;;) { switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode) { case WIFI_MODE_STA: proc_sta(); break; case WIFI_MODE_AP: proc_ap(); break; case WIFI_MODE_ADHOC: break; case WIFI_MODE_DISABLE: default: proc_killConnection(); sleep(30); break; } } return 0; }