From 424cad8755e6e3a43ea220ce1cb9880e013faee5 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Thu, 14 Nov 2024 20:19:56 +0800 Subject: [PATCH 1/4] 3 change to DG102 --- common/common_func.cpp | 27 ++------------- common/global.hpp | 11 ++---- jsonparse/web_cmd_parse.cpp | 16 +-------- jsonparse/web_cmd_parse2.cpp | 3 +- mqttclient/mqtt_client.cpp | 12 ++----- platform/platform_init.cpp | 66 +++--------------------------------- threadfunc/check_thread.cpp | 61 ++------------------------------- uart/uart.cpp | 26 +------------- 8 files changed, 18 insertions(+), 204 deletions(-) diff --git a/common/common_func.cpp b/common/common_func.cpp index 94463e8..c3615dc 100644 --- a/common/common_func.cpp +++ b/common/common_func.cpp @@ -127,7 +127,6 @@ int InitGpio(unsigned int gpioN, unsigned int inout) { close(fd); sleep(1); //闂傚倸鍊烽悞锕€�?�?Ο鑲╃煋闁割偅娲橀崑�?�堟煕閻�?彃鍘o闂傚倷绀侀幖�?�﹀磹婵犳艾绠犻柟鎹愵嚙缁犳牠鏌ㄩ悤鍌涘�? -#ifdef G2UL_GATEWAY char tmp2[100] = {0}; if (gpioN == 507) memcpy(tmp2, "P18_3", 5); @@ -161,10 +160,6 @@ int InitGpio(unsigned int gpioN, unsigned int inout) { memcpy(tmp2, "P16_1", 5); sprintf(tmp, "/sys/class/gpio/%s/direction", tmp2); -#endif -#ifdef IMX6UL_GATEWAY - sprintf(tmp, "/sys/class/gpio/gpio%d/direction", gpioN); -#endif zlog_info(zbt, "open GPIO = %s", tmp); fd = open(tmp, O_WRONLY); @@ -196,7 +191,6 @@ int InitGpio(unsigned int gpioN, unsigned int inout) { int gpio_set(unsigned int gpioN, char x) { int fd = 0; char tmp[100] = {0}; -#ifdef G2UL_GATEWAY char tmp2[100] = {0}; if (gpioN == 507) memcpy(tmp2, "P18_3", 5); @@ -229,10 +223,7 @@ int gpio_set(unsigned int gpioN, char x) { else if (gpioN == 489) memcpy(tmp2, "P16_1", 5); sprintf(tmp, "/sys/class/gpio/%s/value", tmp2); -#endif -#ifdef IMX6UL_GATEWAY - sprintf(tmp, "/sys/class/gpio/gpio%d/value", gpioN); -#endif + //闂傚倷鑳堕幊鎾绘倶濮樿泛绠伴柛婵�?劜椤洟鏌熸潏鈺佲偓宄 value闂傚倷绀侀幖�?�﹀磹缁�?5娲晲閸涱亝鐎婚梺璺ㄥ櫐閹凤拷 fd = open(tmp, O_WRONLY); @@ -265,7 +256,6 @@ int gpio_read(unsigned int gpioN) { char tmp[100] = {0}; -#ifdef G2UL_GATEWAY char tmp2[100] = {0}; if (gpioN == 507) memcpy(tmp2, "P18_3", 5); @@ -298,10 +288,7 @@ int gpio_read(unsigned int gpioN) { else if (gpioN == 489) memcpy(tmp2, "P16_1", 5); sprintf(tmp, "/sys/class/gpio/%s/value", tmp2); -#endif -#ifdef IMX6UL_GATEWAY - sprintf(tmp, "/sys/class/gpio/gpio%d/value", gpioN); -#endif + //闂傚倷鑳堕幊鎾绘倶濮樿泛绠伴柛婵�?劜椤洟鏌熸潏鈺佲偓宄 value闂傚倷绀侀幖�?�﹀磹缁�?5娲晲閸涱亝鐎婚梺璺ㄥ櫐閹凤拷 fd = open(tmp, O_RDONLY); if (-1 == fd) { @@ -1099,16 +1086,8 @@ std::string GetSysStatus() { char rateHardUse[32]; char chRes[100]; memset(chRes, 0, 100); -#ifdef IMX6UL_GATEWAY - char hardName[32]; - char hardUse[32]; - const char *getEmmcInfo = "df -h | grep /opt"; - system_custom(getEmmcInfo, chRes); - sscanf(chRes, "%s%s%s%s%s", hardName, hardTotal, hardUse, hardFree, rateHardUse); -#endif -#ifdef G2UL_GATEWAY getDiskInfo(hardTotal, hardFree); -#endif + std::string strhardTotal(hardTotal); std::string strhardFree(hardFree); diff --git a/common/global.hpp b/common/global.hpp index a0dfe39..ac03d9a 100644 --- a/common/global.hpp +++ b/common/global.hpp @@ -21,8 +21,7 @@ enum enumZigBeeTransmitStatus { //#define Q4G_MODULE //#define WIFI_MODULE //#define NR5G_MEIGE -//#define G2UL_GATEWAY -#define IMX6UL_GATEWAY + class GlobalConfig { @@ -57,14 +56,10 @@ public : }; -#ifdef IMX6UL_GATEWAY -#define SAVE_COUNT 4320 -#define OneWeek 432000 //5天 -#endif -#ifdef G2UL_GATEWAY + #define SAVE_COUNT 4800*4 #define OneWeek 604800*7 -#endif + //按8 取整 #define Length_(len) do{ \ diff --git a/jsonparse/web_cmd_parse.cpp b/jsonparse/web_cmd_parse.cpp index 3dc6093..5c894d8 100644 --- a/jsonparse/web_cmd_parse.cpp +++ b/jsonparse/web_cmd_parse.cpp @@ -539,10 +539,6 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) { bFlag4 = true; } zlog_info(zct, "bFlag1 = %d,bFlag2 = %d,bFlag3 = %d,bFlag4 = %d", bFlag1, bFlag2, bFlag3, bFlag4); -#ifdef IMX6UL_GATEWAY - strNet = param.mNet; - param.mNet = "Net"; -#endif if (0 == param.mMode && (bFlag1 && bFlag2 && bFlag3 && bFlag4) && param.mNetworkPortStatus == "STATIC") { WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", param.mDnsName); WriteStr2Config(NETWORKCONFIG, param.mNet, "networkPortStatus", param.mNetworkPortStatus); @@ -551,12 +547,6 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) { WriteStr2Config(NETWORKCONFIG, param.mNet, "ipAddress", param.mIp); WriteStr2Config(NETWORKCONFIG, param.mNet, "hostName", param.mHostName); -#ifdef IMX6UL_GATEWAY - char GateWay[100] = {0x00}; - sprintf(GateWay, "sed -i '7c route add default gw %s' /etc/init.d/S90start_userapp.sh", param.mGateway.c_str()); - zlog_info(zct, "GateWay = %s", GateWay); - system(GateWay); -#endif PlatformInit::EquipIpInit(param.mNet); } else if (0 == param.mMode && param.mNetworkPortStatus == "DHCP") { @@ -567,9 +557,6 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) { WriteStr2Config(NETWORKCONFIG, param.mNet, "ipAddress", ""); WriteStr2Config(NETWORKCONFIG, param.mNet, "hostName", ""); -#ifdef IMX6UL_GATEWAY - system("sed -i '7c udhcpc -i eth0 > /dev/null &' /etc/init.d/S90start_userapp.sh"); -#endif PlatformInit::EquipIpInit(param.mNet); } else if (0 == param.mMode && (!bFlag1 || !bFlag2 || !bFlag3 || !bFlag4) && param.mNetworkPortStatus == "STATIC") { @@ -585,7 +572,6 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) { jsonVal["content"]["eth0"] = jsonValnet; jsonVal["content"]["gatewaytype"] = 0; -#ifdef G2UL_GATEWAY jsonValnet["dnsName"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "dnsName"); jsonValnet["networkPortStatus"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "networkPortStatus"); jsonValnet["gateway"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "gateway"); @@ -594,6 +580,6 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) { jsonValnet["hostName"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "hostName"); jsonVal["content"]["eth1"] = jsonValnet; jsonVal["content"]["gatewaytype"] = 1; -#endif + return show_value_.write(jsonVal); } diff --git a/jsonparse/web_cmd_parse2.cpp b/jsonparse/web_cmd_parse2.cpp index 9e98129..8d015c9 100644 --- a/jsonparse/web_cmd_parse2.cpp +++ b/jsonparse/web_cmd_parse2.cpp @@ -190,7 +190,6 @@ std::string JsonData::JsonCmd_Cgi_54(Param_54 ¶m) { jsBody["ServerConfig"] = jsSystemSetting; jsonVal["content"] = jsBody; -#ifdef G2UL_GATEWAY jsonValnet1["dnsName"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "dnsName"); jsonValnet1["networkPortStatus"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "networkPortStatus"); jsonValnet1["gateway"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "gateway"); @@ -199,7 +198,7 @@ std::string JsonData::JsonCmd_Cgi_54(Param_54 ¶m) { jsonValnet1["hostName"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "hostName"); jsonVal["content"]["eth1"] = jsonValnet1; jsonVal["content"]["gatewaytype"] = 1; -#endif + jsSystemInfo["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion"); jsSystemInfo["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion"); diff --git a/mqttclient/mqtt_client.cpp b/mqttclient/mqtt_client.cpp index d8362f4..e492c9f 100644 --- a/mqttclient/mqtt_client.cpp +++ b/mqttclient/mqtt_client.cpp @@ -115,22 +115,14 @@ void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result) { #ifdef WIFI_MODULE char buf[128] = {0}; std::string wpa_state = ""; -#ifdef G2UL_GATEWAY wpa_state = "/usr/sbin/wpa_cli status|grep wpa_state | cut -f 2 -d '='"; -#endif -#ifdef IMX6UL_GATEWAY - wpa_state = "/opt/Cidn/wpa_cli status|grep wpa_state | cut -f 2 -d '='"; -#endif system_custom(wpa_state.c_str(), buf); std::string state = std::string(buf); std::string RSSI_cmd = ""; -#ifdef G2UL_GATEWAY + RSSI_cmd = "/usr/sbin/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='"; -#endif -#ifdef IMX6UL_GATEWAY - RSSI_cmd = "/opt/Cidn/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='"; -#endif + system_custom(RSSI_cmd.c_str(), buf); std::string RSSI = std::string(buf); diff --git a/platform/platform_init.cpp b/platform/platform_init.cpp index 11eb16b..98dd062 100644 --- a/platform/platform_init.cpp +++ b/platform/platform_init.cpp @@ -79,7 +79,6 @@ void PlatformInit::Init() { strMac.insert(14, ":"); ModifyMac((char*)strMac.c_str()); } -#ifdef G2UL_GATEWAY std::string strMac2 = sqlite_db_ctrl::instance().GetData("t_gateway_info", "MAC2", NULL); if (strMac2 == "60294D208518") { char szUpdateSql[100] = {0x00}; @@ -94,7 +93,7 @@ void PlatformInit::Init() { strMac2.insert(14, ":"); ModifyMac((char*)strMac2.c_str()); } -#endif + } catch (...) { zlog_error(zbt, "PlatFormInit exception happend."); std::string errorinfo = "系统初始化异常"; @@ -176,7 +175,7 @@ void PlatformInit::Sqlite3Init() { } void PlatformInit::GPIOInit() { -#ifdef G2UL_GATEWAY + GlobalConfig::GPIO_G.zigAckrep = 507; GlobalConfig::GPIO_G.zigAckreset = 499; GlobalConfig::GPIO_G.zigReset = 496; @@ -190,16 +189,6 @@ void PlatformInit::GPIOInit() { GlobalConfig::GPIO_G.runLed = 409; GlobalConfig::GPIO_G.errorLed = 410; GlobalConfig::GPIO_G.netResetNet0 = 489; -#endif -#ifdef IMX6UL_GATEWAY - GlobalConfig::GPIO_G.zigAckrep = 119; - GlobalConfig::GPIO_G.zigAckreset = 120; - GlobalConfig::GPIO_G.zigReset = 116; - GlobalConfig::GPIO_G.wifiReset = 8; - GlobalConfig::GPIO_G.commRest = 8; - GlobalConfig::GPIO_G.power = 9; - GlobalConfig::GPIO_G.errorLed = 130; -#endif } void PlatformInit::SystemInfoInit() { @@ -264,14 +253,6 @@ void PlatformInit::EquipIpInit(std::string eth) { if (0 == networkPortStatus.compare("DHCP")) { zlog_info(zbt, "dhcp config\n"); std::string cmd = ""; -#ifdef IMX6UL_GATEWAY - system("sed -i '17c auto eth0' /etc/network/interfaces"); - system("sed -i '18c iface eth0 inet dhcp' /etc/network/interfaces"); - system("sed -i '20c ' /etc/network/interfaces"); - system("sed -i '21c ' /etc/network/interfaces"); - system("sed -i '22c ' /etc/network/interfaces"); -#endif -#ifdef G2UL_GATEWAY if (eth == "eth0") { system("sed -i '5c DHCP=ipv4' /etc/systemd/network/static/10-eth0-static.network"); system("sed -i '6c ' /etc/systemd/network/static/10-eth0-static.network"); @@ -281,38 +262,10 @@ void PlatformInit::EquipIpInit(std::string eth) { system("sed -i '6c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network"); system("sed -i '7c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network"); } -#endif -// flag = 0; } if (0 == networkPortStatus.compare("STATIC")) { std::string cmd = ""; -#ifdef IMX6UL_GATEWAY - system("sed -i '18c iface eth0 inet static' /etc/network/interfaces"); - if (dataWatchIpAddress.length() > 0) { - cmd = "sed -i '20c address " + dataWatchIpAddress + "' /etc/network/interfaces"; - } else { - cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces"; - } - system(cmd.c_str()); - cmd.clear(); - if (subnetMask.length() > 0) { - cmd = "sed -i '21c netmask " + subnetMask + "' /etc/network/interfaces"; - } else { - cmd = "sed -i '21c netmask 255.255.255.0' /etc/network/interfaces"; - } - system(cmd.c_str()); - cmd.clear(); - - if (gateway.length() > 0) { - cmd = "sed -i '22c gateway " + gateway + "' /etc/network/interfaces"; - } else { - cmd = "sed -i '22c gateway 0.0.0.0' /etc/network/interfaces"; - } - system(cmd.c_str()); - cmd.clear(); -#endif -#ifdef G2UL_GATEWAY if (eth == "eth0") { cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/static/10-eth0-static.network"; system(cmd.c_str()); @@ -328,19 +281,10 @@ void PlatformInit::EquipIpInit(std::string eth) { cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network"; system(cmd.c_str()); } -#endif -// flag = 1; - } -#ifdef IMX6UL_GATEWAY - zlog_info(zbt, "system reboot by reboot system call"); - system("sync"); - sleep(1); - system("reboot"); - -#endif -#ifdef G2UL_GATEWAY + } + zlog_info(zbt, "network restart by systemctl call"); system("systemctl restart systemd-networkd.service"); -#endif + } diff --git a/threadfunc/check_thread.cpp b/threadfunc/check_thread.cpp index ff739d3..af49491 100644 --- a/threadfunc/check_thread.cpp +++ b/threadfunc/check_thread.cpp @@ -39,14 +39,6 @@ void CheckThread() { if (10 == heart_count) { if (GlobalConfig::LinkCount > 30) { zlog_error(zct, "MQTT connect failed "); -#ifdef IMX6UL_GATEWAY - char connect[10] = {0x00}; - readStringValue("config", "connect", connect, (char *)GlobalConfig::Config_G.c_str()); - if (atoi(connect)) { - zlog_error(zct, "MQTT connect failed,reboot"); - exit(0); - } -#endif } std::string ipTemp = IpAddrInit(); GlobalConfig::IpAddr_G = ipTemp; @@ -67,27 +59,7 @@ void CheckThread() { iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str()); if (iRet != 0) { zlog_error(zct, "MQTT connect failed ,time check"); -#ifdef IMX6UL_GATEWAY - char connect[10] = {0x00}; - readStringValue("config", "connect", connect, (char *)GlobalConfig::Config_G.c_str()); - if (atoi(connect)) { - zlog_error(zct, "MQTT connect failed,time check ,reboot"); - exit(0); - } -#endif #ifdef NR5G_MODULE -#ifdef IMX6UL_GATEWAY - dial.closePort(); - gpio_set(GlobalConfig::GPIO_G.commRest, 0); - zlog_warn(zct, "GPIO 8 start"); - sleep(2); - gpio_set(GlobalConfig::GPIO_G.commRest, 1); - zlog_warn(zct, "GPIO 8 End"); - sleep(20); - dial.openPort("/dev/ttyUSB2"); - dial.setState(); -#endif -#ifdef G2UL_GATEWAY dial.closePort(); gpio_set(GlobalConfig::GPIO_G.commPower, 0); zlog_warn(zct, "commPower start"); @@ -100,30 +72,12 @@ void CheckThread() { zlog_error(zct, "5G reset error ,reboot!"); system("reboot"); } -#ifndef NR5G_MEIGE dial.openPort("/dev/ttyUSB2"); dial.setState(); -#else - char szquectel[100] = {0x00}; - std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN"); - sprintf(szquectel, "/opt/quectel-CM/Meig-CM -s %s &", strAPN.c_str()); - system(szquectel); -#endif -#endif + #endif #ifdef WIFI_MODULE zlog_warn(zct, "WiFi reset!"); -#ifdef IMX6UL_GATEWAY - gpio_set(GlobalConfig::GPIO_G.wifiReset, 0); - sleep(5); - gpio_set(GlobalConfig::GPIO_G.wifiReset, 1); - sleep(5); - wifi::WPAClient wpa; - wpa.ReconnectWiFi(); - system("/etc/init.d/wpa_restart"); - system("udhcpc -i wlan2 &"); -#endif -#ifdef G2UL_GATEWAY system("/etc/init.d/wpa_restart"); sleep(5); string strip = GetGwIp_("wlan0"); @@ -140,7 +94,7 @@ void CheckThread() { sleep(5); system("udhcpc -b -i wlan0 &"); } -#endif + #endif } } @@ -243,12 +197,7 @@ void CheckThread() { char localtimestamp[32] = {0}; GetTimeNet(localtimestamp, 1); char whereCon[1024] = {0}; -#ifdef G2UL_GATEWAY sprintf(whereCon, " timestamp < '%ld' ", atol(localtimestamp) - 2592000 * 2); //删除2个月前的数据 -#endif -#ifdef IMX6UL_GATEWAY - sprintf(whereCon, " timestamp < '%ld' ", atol(localtimestamp) - 2592000); //删除1个月前的数据 -#endif sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon); sqlite_db_ctrl::instance().DeleteTableData(" receive_wave_status ", whereCon); @@ -268,13 +217,7 @@ void CheckThread() { if (currentssid.length() > 0) { char buf[64] = {0}; std::string rssiSend = ""; -#ifdef G2UL_GATEWAY rssiSend = "/usr/sbin/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='"; -#endif - -#ifdef IMX6UL_GATEWAY - rssiSend = "/opt/Cidn/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='"; -#endif system_custom(rssiSend.c_str(), buf); std::string Rssi = std::string(buf); diff --git a/uart/uart.cpp b/uart/uart.cpp index 1036456..982842f 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -36,9 +36,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { int offSize = 0; int timeoutflag = 0; char head[] = {0xAA, 0x55, 0xAA}; -#ifdef G2UL_GATEWAY char szbuffer[BUF_LENGTH] = {0x00}; -#endif while (1) { if (now_task == WAVE_CMD) { memset(buff, 0, sizeof(buff)); @@ -79,23 +77,6 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { } } else { -#ifdef IMX6UL_GATEWAY - memset(buff, 0, sizeof(buff)); - ret = read_data(fd, buff, BUF_LENGTH, 50); - if (ret <= 0) { - continue; - } - if (srcshow) { - zlog_info(zct, "0x8888 ===str_recv===,ret = %d", ret); - for (int i = 0; i < ret; i++) { - printf("[%02x]", buff[i] & 0xff); - } - printf("\n"); - FindRecvPackage(ret, buff, head); - } -#endif - -#ifdef G2UL_GATEWAY memset(buff, 0x00, sizeof(buff)); ret = read_data(fd, buff, BUF_LENGTH, 50); if (ret <= 0) { @@ -120,7 +101,6 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { memcpy(szbuffer + offSize, buff, ret); offSize = offSize + ret; } -#endif } } } @@ -157,12 +137,8 @@ Uart::~Uart() { } void Uart::InitUart(speed_t speed) { -#ifdef G2UL_GATEWAY fd = config_uart("/dev/ttySC2", speed); -#endif -#ifdef IMX6UL_GATEWAY - fd = config_uart("/dev/ttymxc4", speed); -#endif + zlog_info(zct, "InitUart fd = %d", fd); if (fd < 0) { zlog_error(zct, "config_uart error"); From f3b55aab7a0136bc4dd88001957edcf9bac4a8fc Mon Sep 17 00:00:00 2001 From: pandx Date: Thu, 14 Nov 2024 21:00:07 +0800 Subject: [PATCH 2/4] modify log info. --- scheduler/schedule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index 81e4d71..aa115b4 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -472,7 +472,7 @@ int SensorScheduler::UpdateSensorConfig(int short_addr) { int id = 0; auto iter = short_addr_map_.find(short_addr); if (iter == short_addr_map_.end()) { - zlog_error(zct, "cannot find id for short_addr %d", short_addr); + zlog_info(zct, "cannot find id for short_addr %d", short_addr); return 1; } else { id = iter->second; From 5b3ada1974f6e599fb63bcdb1ac05d77d7c3f5d6 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Sat, 16 Nov 2024 18:05:12 +0800 Subject: [PATCH 3/4] fix sensor online bugs --- uart/uart.cpp | 8 ++++++-- uart/uart_parameter_config.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/uart/uart.cpp b/uart/uart.cpp index 982842f..8e698d7 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -601,7 +601,6 @@ void Uart::DealDataNodeName(const char *pData) { sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), vecRes[i][1].c_str()); sqlite_db_ctrl::instance().DeleteTableData(T_DATA_INFO(TNAME), whereCon); sqlite_db_ctrl::instance().DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon); - sqlite_db_ctrl::instance().DeleteTableData(T_DATANODE_TIME(TNAME), whereCon); sqlite_db_ctrl::instance().DeleteTableData(T_BATTERY_INFO(TNAME), whereCon); sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon); memset(whereCon,0,sizeof(whereCon)); @@ -613,7 +612,10 @@ void Uart::DealDataNodeName(const char *pData) { memset(szTableName, 0x00, sizeof(szTableName)); sprintf(szTableName, "DROP TABLE t_dataStatic_%s", vecRes[i][1].c_str()); sqlite_db_ctrl::instance().CreateTable(szTableName); - scheduler::instance().ClearScheduleCfg(atoi(szShortAdd)); + uint16_t short_addr; + char *end_ptr = NULL; + short_addr = strtol(szShortAdd, &end_ptr, 16); + scheduler::instance().ClearScheduleCfg(short_addr); } } @@ -623,6 +625,8 @@ void Uart::DealDataNodeName(const char *pData) { if ((hardVersion == "3.0" && compareVersions(softVersion, "3.6") == -1) || (hardVersion == "4.0" && compareVersions(softVersion, "4.6") == -1)|| (hardVersion == "1.0" && compareVersions(softVersion,"1.2") == -1)) { memcpy(MeasurementID, vecRes[0][0].c_str(), sizeof(MeasurementID)); } + memset(whereCon,0,sizeof(whereCon)); + sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd); std::string strNodeName(NodeName); zlog_info(zct, "strNodeName = %s", strNodeName.c_str()); solve(gbkNodeName, NodeName); diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 0d3606f..85083a7 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -50,7 +50,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { GetTimeNet(localtimestamp, 1); char insertSql[100] = {0}; char wherecon[50] = {0}; - sprintf(wherecon," short_Addr = '%02x%02x' order by start_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); + sprintf(wherecon," short_Addr = '%02x%02x' and status = 3 order by start_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); std::string spend_count = sqlite_db_ctrl::instance().GetData(" firmware_upgrade ","spend_count",wherecon); if (atoi(spend_count.c_str()) >= 10){ zlog_warn(zbt, "UpdateWirelessNode spend_count %d,shortAddr = %02x%02x", atoi(spend_count.c_str()), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); From 092236cfd02a266110a164c30cba7b61b4d77d66 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Tue, 19 Nov 2024 15:42:51 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=B3=A2=E5=BD=A2=E6=95=B0=E6=8D=AE=E5=88=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .vscode/settings.json | 84 -------------------- dbaccess/sql_db.cpp | 139 --------------------------------- dbaccess/sql_db.hpp | 2 - threadfunc/check_thread.cpp | 10 --- uart/uart_parameter_config.cpp | 1 + 6 files changed, 2 insertions(+), 235 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 1dc6372..ba4f805 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /Debug/ .settings/* .cproject +.vscode/ diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index a6c2fe0..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "search.exclude": { - "**/Debug": true, - "**/Release": true - }, - "files.exclude": { - "**/Debug": true, - "**/Release": true - }, - "files.associations": { - "*.tcc": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "list": "cpp", - "map": "cpp", - "set": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "semaphore": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp", - "csignal": "cpp", - "strstream": "cpp", - "bitset": "cpp", - "cfenv": "cpp", - "codecvt": "cpp", - "complex": "cpp", - "any": "cpp", - "future": "cpp", - "typeindex": "cpp" - }, - "C_Cpp.errorSquiggles": "disabled" -} \ No newline at end of file diff --git a/dbaccess/sql_db.cpp b/dbaccess/sql_db.cpp index 2ce05a9..68881e6 100644 --- a/dbaccess/sql_db.cpp +++ b/dbaccess/sql_db.cpp @@ -1343,145 +1343,6 @@ int SqliteDB::QueryofflineData() { return res; } -int SqliteDB::CalculateData() { - int res = 0; - array_t vecRet = GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo,MeasurementID,NodeWaveSend,featureInterVal,waveInterVal,ZigbeePower ", NULL); - if (vecRet.size() > 0) { - int planCount = 0, planCountStatistic = 0, StatisticCountTotal = 0, SixCountTotal = 0, TimingCountTotal = 0, CountWaveXTotal = 0, waveInterVal = 0, featureInterVal = 0; - int CountWaveYTotal = 0, CountWaveZTotal = 0; - for (size_t i = 0; i < vecRet.size(); i++) { - planCount = 1440 / atoi(vecRet[i][4].c_str()); - planCountStatistic = 1440 / atoi(vecRet[i][3].c_str()); - int rate = readIntValue("config", "waveRate", (char *)GlobalConfig::Config_G.c_str()); - char tableName[50] = {0x00}; - char whereCon[128] = {0x00}; - sprintf(tableName, "t_dataStatic_%s", vecRet[i][0].c_str()); - const char *sql = " timestamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') " - "AND timestamp < strftime('%s', 'now', '-1 day','start of day','utc','+24 hours') "; - int StatisticCount = GetTableRows(tableName, sql); - - sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') AND timeStamp < strftime('%s', 'now', '-1 day','start of day','utc','+24 hours') and statisticType = '1' "; - int SixCount = GetTableRows(tableName, sql); - - sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') AND timeStamp < strftime('%s', 'now', '-1 day','start of day','utc','+24 hours') and statisticType = '1' and timing = '0'"; - int TimingCount = GetTableRows(tableName, sql); - zlog_info(zct, "nodeWaveSend = %s,waveInterVal = %s", vecRet[i][2].c_str(), vecRet[i][4].c_str()); - if (vecRet[i][2] == "") continue; - std::vector nodeWaveSend; - boost::split(nodeWaveSend, vecRet[i][2], boost::is_any_of(","), boost::token_compress_on); - int CountWaveX = 0, CountWaveY = 0, CountWaveZ = 0; - int CountWaveX2 = 0, CountWaveY2 = 0, CountWaveZ2 = 0; - int CountWaveX3 = 0, CountWaveY3 = 0, CountWaveZ3 = 0; - int rateX = 0, rateY = 0, rateZ = 0; - if (nodeWaveSend.size() < 3) { - continue; - } - sprintf(tableName, "t_data_waveSend"); - const char *sql1 = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc')" - " AND timeStamp < strftime('%s', 'now','-1 day', 'start of day','utc','+24 hours')"; - - const char *sql2 = "timeStamp >= strftime('%s', 'now', '-2 day', 'start of day','utc')" - " AND timeStamp < strftime('%s', 'now','-2 day', 'start of day','utc','+24 hours')"; - - const char *sql3 = "timeStamp >= strftime('%s', 'now', '-3 day', 'start of day','utc')" - " AND timeStamp < strftime('%s', 'now','-3 day', 'start of day','utc','+24 hours')"; - if (nodeWaveSend[0] == "0") { - sprintf(whereCon, " and channelID = '%s-X'", vecRet[i][1].c_str()); - std::string strsql = std::string(sql1) + std::string(whereCon); - zlog_info(zct, "sql = %s", strsql.c_str()); - CountWaveX = GetTableRows(tableName, strsql.c_str()); - sprintf(whereCon, " and channelID = '%s-X'", vecRet[i][1].c_str()); - strsql = std::string(sql2) + std::string(whereCon); - CountWaveX2 = GetTableRows(tableName, strsql.c_str()); - sprintf(whereCon, " and channelID = '%s-X'", vecRet[i][1].c_str()); - strsql = std::string(sql3) + std::string(whereCon); - CountWaveX3 = GetTableRows(tableName, strsql.c_str()); - if ((CountWaveX > 0 && (CountWaveX / planCount > (rate / 100))) && (CountWaveX2 > 0 && (CountWaveX2 / planCount > (rate / 100))) && (CountWaveX3 > 0 && (CountWaveX3 / planCount > (rate / 100)))) { - rateX = 1; - } else { - rateX = -1; - } - } - if (nodeWaveSend[1] == "0") { - sprintf(whereCon, " and channelID = '%s-Y'", vecRet[i][1].c_str()); - std::string strsql = std::string(sql1) + std::string(whereCon); - CountWaveY = GetTableRows(tableName, strsql.c_str()); - sprintf(whereCon, " and channelID = '%s-Y'", vecRet[i][1].c_str()); - strsql = std::string(sql2) + std::string(whereCon); - CountWaveY2 = GetTableRows(tableName, strsql.c_str()); - sprintf(whereCon, " and channelID = '%s-Y'", vecRet[i][1].c_str()); - strsql = std::string(sql3) + std::string(whereCon); - CountWaveY3 = GetTableRows(tableName, strsql.c_str()); - - if ((CountWaveY > 0 && (CountWaveY / planCount > (rate / 100))) && (CountWaveY2 > 0 && (CountWaveY2 / planCount > (rate / 100))) && (CountWaveY3 > 0 && (CountWaveY3 / planCount > (rate / 100)))) { - rateY = 1; - } else { - rateY = -1; - } - } - if (nodeWaveSend[2] == "0") { - sprintf(whereCon, " and channelID = '%s-Z'", vecRet[i][1].c_str()); - std::string strsql = std::string(sql1) + std::string(whereCon); - CountWaveZ = GetTableRows(tableName, strsql.c_str()); - sprintf(whereCon, " and channelID = '%s-Z'", vecRet[i][1].c_str()); - strsql = std::string(sql2) + std::string(whereCon); - CountWaveZ2 = GetTableRows(tableName, strsql.c_str()); - sprintf(whereCon, " and channelID = '%s-Z'", vecRet[i][1].c_str()); - strsql = std::string(sql3) + std::string(whereCon); - CountWaveZ3 = GetTableRows(tableName, strsql.c_str()); - - if ((CountWaveZ > 0 && (CountWaveZ / planCount > (rate / 100))) && (CountWaveZ2 > 0 && (CountWaveZ2 / planCount > (rate / 100))) && (CountWaveZ3 > 0 && (CountWaveZ3 / planCount > (rate / 100)))) { - rateZ = 1; - } else { - rateZ = -1; - } - } - StatisticCountTotal += StatisticCount; - SixCountTotal += SixCount; - TimingCountTotal += TimingCount; - CountWaveXTotal += CountWaveX; - CountWaveYTotal += CountWaveY; - CountWaveZTotal += CountWaveZ; - zlog_info(zct, "dataNodeNo = %s , Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d , CountWaveY = %d , CountWaveZ = %d , featureInterVal = %s , waveInterVal = %s , NodeWaveSend = %s", vecRet[i][0].c_str(), StatisticCount, SixCount, - TimingCount, CountWaveX, CountWaveY, CountWaveZ, vecRet[i][3].c_str(), vecRet[i][4].c_str(), vecRet[i][2].c_str()); - - int zigbeepowerEnable = readIntValue("config", "zigbeepowerEnable", (char *)GlobalConfig::Config_G.c_str()); - if (zigbeepowerEnable) { - zlog_info(zct, "rateX = %d,rateY = %d,rateZ = %d,zigbeepower = %s", rateX, rateY, rateZ, vecRet[i][5].c_str()); - if (rateX != -1 && rateY != -1 && rateZ != -1 && vecRet[i][5] == "3") { - char updateSql[50] = {0x00}; - sprintf(updateSql, "ZigbeePower = '2',UpdateFlag = 0 "); - memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(whereCon, " dataNodeNo = '%s'", vecRet[i][0].c_str()); - res = UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); - if(res !=0 ){ - zlog_error(zct, "res = %d", res); - } - zlog_info(zct, "2 update ZigbeePower "); - } - - if ((rateX == -1 || rateY == -1 || rateZ == -1) && vecRet[i][5] == "2") { - char updateSql[50] = {0x00}; - sprintf(updateSql, "ZigbeePower = '3',UpdateFlag = 0 "); - memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(whereCon, " dataNodeNo = '%s'", vecRet[i][0].c_str()); - res = UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); - if(res !=0 ){ - zlog_error(zct, "res = %d", res); - } - zlog_info(zct, "3 update ZigbeePower "); - } - } - featureInterVal = atoi(vecRet[i][3].c_str()); - waveInterVal = atoi(vecRet[i][4].c_str()); - } - zlog_info(zct, "Node Count = %d , featureInterVal = %d , waveInterVal = %d", vecRet.size(), featureInterVal, waveInterVal); - zlog_info(zct, "plan Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d ", planCountStatistic * vecRet.size(), planCount * vecRet.size(), planCount * vecRet.size(), planCount * vecRet.size()); - zlog_info(zct, "reality Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d ,CountWaveY = %d ,CountWaveZ = %d ", StatisticCountTotal, SixCountTotal, TimingCountTotal, CountWaveXTotal, CountWaveYTotal, CountWaveZTotal); - } - return res; -} - int SqliteDB::TransBegin() { return sqlite3_exec(mDBAcess, "begin;", 0, 0, 0); } int SqliteDB::TransRollback() { return sqlite3_exec(mDBAcess, "rollback;", 0, 0, 0); } diff --git a/dbaccess/sql_db.hpp b/dbaccess/sql_db.hpp index 16d4ba7..e09ae24 100644 --- a/dbaccess/sql_db.hpp +++ b/dbaccess/sql_db.hpp @@ -67,8 +67,6 @@ public: int CalculateDip(); int InintGateway(); int QueryofflineData(); - int CalculateData(); - int CalculateWaveRate(); std::string GetNodeConfigureInfor(const char *whereCon); int CloseDB(); diff --git a/threadfunc/check_thread.cpp b/threadfunc/check_thread.cpp index af49491..4b5bab0 100644 --- a/threadfunc/check_thread.cpp +++ b/threadfunc/check_thread.cpp @@ -103,16 +103,6 @@ void CheckThread() { std::string data = jd.JsonCmd_07(); data_publish(data.c_str(), GlobalConfig::Topic_G.mPubStatus.c_str()); HardStatus = 0; - int hour = 0; - struct tm *tm_info = get_current_date(); - hour = tm_info->tm_hour; - int statistics = readIntValue("config", "statistics", (char *)GlobalConfig::Config_G.c_str()); - if (statistics == 0 && hour > 13) { - writeIntValue("config", "statistics", 1, (char *)GlobalConfig::Config_G.c_str()); - sqlite_db_ctrl::instance().CalculateData(); - } else if (statistics == 1 && hour < 13) { - writeIntValue("config", "statistics", 0, (char *)GlobalConfig::Config_G.c_str()); - } } if (mqttresend == 7200) { mqttresend = 0; diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 85083a7..fd33eab 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -620,6 +620,7 @@ int Uart::CheckZigbeeACK() { break; } mssleep(10000); + time += 1; } while (time < 150); return iRet; }