modify structure.
This commit is contained in:
parent
c19d0dd2a8
commit
96ec70c629
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -73,5 +73,6 @@
|
||||
"random": "cpp",
|
||||
"set": "cpp",
|
||||
"*.ipp": "cpp"
|
||||
}
|
||||
},
|
||||
"C_Cpp.errorSquiggles": "disabled"
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
CPP_SRCS += \
|
||||
../MD5/md5.cpp
|
||||
|
||||
CPP_DEPS += \
|
||||
./MD5/md5.d
|
||||
|
||||
OBJS += \
|
||||
./MD5/md5.o
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
MD5/%.o: ../MD5/%.cpp MD5/subdir.mk
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross G++ Compiler'
|
||||
arm-linux-gnueabihf-g++ -std=c++0x -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
||||
clean: clean-MD5
|
||||
|
||||
clean-MD5:
|
||||
-$(RM) ./MD5/md5.d ./MD5/md5.o
|
||||
|
||||
.PHONY: clean-MD5
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
C_SRCS += \
|
||||
../aes/aes.c
|
||||
|
||||
C_DEPS += \
|
||||
./aes/aes.d
|
||||
|
||||
OBJS += \
|
||||
./aes/aes.o
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
aes/%.o: ../aes/%.c aes/subdir.mk
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross GCC Compiler'
|
||||
arm-linux-gnueabihf-gcc -O0 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
||||
clean: clean-aes
|
||||
|
||||
clean-aes:
|
||||
-$(RM) ./aes/aes.d ./aes/aes.o
|
||||
|
||||
.PHONY: clean-aes
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
CPP_SRCS += \
|
||||
../calculation/Calculation.cpp
|
||||
|
||||
CPP_DEPS += \
|
||||
./calculation/Calculation.d
|
||||
|
||||
OBJS += \
|
||||
./calculation/Calculation.o
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
calculation/%.o: ../calculation/%.cpp calculation/subdir.mk
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross G++ Compiler'
|
||||
arm-linux-gnueabihf-g++ -std=c++0x -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
||||
clean: clean-calculation
|
||||
|
||||
clean-calculation:
|
||||
-$(RM) ./calculation/Calculation.d ./calculation/Calculation.o
|
||||
|
||||
.PHONY: clean-calculation
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
#include "common_func.hpp"
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "SH_global.h"
|
||||
#include "SH_CommonFunc.hpp"
|
||||
#include <boost/xpressive/xpressive_dynamic.hpp>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -17,7 +15,10 @@
|
||||
#include <linux/sockios.h>
|
||||
#include <linux/rtc.h>
|
||||
#include <linux/rtc.h>
|
||||
#include "../dbaccess/SH_SqlDB.hpp"
|
||||
#include <boost/xpressive/xpressive_dynamic.hpp>
|
||||
#include "global.hpp"
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
|
||||
|
||||
#define ETHTOOL_GLINK 0x0000000a /* Get link status (ethtool_value) */
|
||||
#define MAX_WAIT_TIME 1
|
||||
@ -675,7 +676,7 @@ void ReadStrConfig(std::string filename) {
|
||||
char insertSql[1024] = {0};
|
||||
char whereCon[100] = {0x00};
|
||||
sprintf(whereCon, "dataNodeNo = '%s'", dataNodeNo.c_str());
|
||||
int rows = sql_ctl->GetTableRows(T_SENSOR_INFO(TNAME), whereCon);
|
||||
int rows = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), whereCon);
|
||||
if (rows > 0) continue;
|
||||
sprintf(insertSql, "'%s','%s','%d','%d','%d','%d','%d','%d',\
|
||||
'%s','%s','%s','%s','%s','%d',\
|
||||
@ -686,7 +687,7 @@ void ReadStrConfig(std::string filename) {
|
||||
dataNodeNo.c_str(), dataNodeName.c_str(), initFlag, accFlag, zigbeeFlag, temTopFlag, temBotFlag, EquipSta, hardVersion.c_str(), softVersion.c_str(), bpNo.c_str(), serialNo.c_str(), firstPowerTime.c_str(), atoi(wakeupTime.c_str()), atoi(StaticTime.c_str()),
|
||||
waveTime, atoi(bateryV.c_str()), productNo.c_str(), configFlag, startBrands.c_str(), stopBrands.c_str(), featureInterVal, waveInterVal, samplingRate, "", rangeValue, envelopeBandPass.c_str(), faultFrequency.c_str(), zigbeePanId.c_str(),
|
||||
atoi(zigbeeChannel.c_str()), zigbeeAddr.c_str(), zigbeeLongAddr.c_str(), zigbeeDesAddr.c_str(), zigbeePower, zigbeeRetry, ZigbeeRetryGap, ACCSampleTime, status, timeStamp.c_str(), viff, RSSI, updateValue);
|
||||
sql_ctl->InsertData(T_SENSOR_INFO(TNAME), insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData(T_SENSOR_INFO(TNAME), insertSql);
|
||||
}
|
||||
} else {
|
||||
print_info("parse error\n");
|
||||
@ -729,7 +730,7 @@ void ImportConfig(std::string filename) {
|
||||
vecDataNode[21].c_str(), vecDataNode[22].c_str(), vecDataNode[23].c_str(), vecDataNode[24].c_str(), vecDataNode[25].c_str(), vecDataNode[26].c_str(), vecDataNode[27].c_str(), vecDataNode[28].c_str(), vecDataNode[29].c_str(), vecDataNode[30].c_str(),
|
||||
vecDataNode[31].c_str(), vecDataNode[32].c_str(), vecDataNode[33].c_str(), vecDataNode[34].c_str(), vecDataNode[35].c_str(), vecDataNode[36].c_str(), vecDataNode[37].c_str(), vecDataNode[38].c_str(), vecDataNode[39].c_str(), vecDataNode[40].c_str(),
|
||||
vecDataNode[41].c_str(), vecDataNode[42].c_str(), vecDataNode[43].c_str(), vecDataNode[44].c_str());
|
||||
sql_ctl->InsertData(T_SENSOR_INFO(TNAME), insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData(T_SENSOR_INFO(TNAME), insertSql);
|
||||
}
|
||||
|
||||
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", jsSystemSetting["ServerIpAddress"].asString());
|
||||
@ -823,7 +824,7 @@ int UpdataDataNodeConfig(std::string filename) {
|
||||
vecDataNode[i].SamplingRate, vecDataNode[i].ACCSampleTime, vecDataNode[i].VIntegralFilterFrequency, vecDataNode[i].ZigbeePower, vecDataNode[i].ZigbeeRetry);
|
||||
sprintf(whereCon, "dataNodeNo='%s'", vecDataNode[i].ZigbeeLongAddr.c_str());
|
||||
|
||||
int iRet = sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
}
|
||||
|
||||
@ -1,340 +1,320 @@
|
||||
#ifndef COMMON_FUNC_HPP_
|
||||
#define COMMON_FUNC_HPP_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sys/statfs.h>
|
||||
#include <json/json.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <memory.h>
|
||||
#include <sys/ipc.h>//ipc
|
||||
#include <sys/shm.h>
|
||||
#include "dirent.h"
|
||||
#include <iconv.h>
|
||||
#include <termios.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netdb.h>
|
||||
#include "Mutex.h"
|
||||
// #include <stdio.h>
|
||||
// #include <unistd.h>
|
||||
// #include <sys/socket.h>
|
||||
// #include <netinet/in.h>
|
||||
// #include <net/if.h>
|
||||
// #include <stdlib.h>
|
||||
// #include <memory.h>
|
||||
// #include <string>
|
||||
// #include <list>
|
||||
// #include <boost/algorithm/string/split.hpp>
|
||||
// #include <boost/thread/mutex.hpp>
|
||||
// #include <boost/algorithm/string/classification.hpp>
|
||||
// #include <iostream>
|
||||
// #include <fstream>
|
||||
// #include <arpa/inet.h>
|
||||
// #include <sys/ioctl.h>
|
||||
// #include <boost/lexical_cast.hpp>
|
||||
// #include <sys/statfs.h>
|
||||
// #include <json/json.h>
|
||||
// #include <sys/mman.h>
|
||||
// #include <fcntl.h>
|
||||
// #include <memory.h>
|
||||
// #include <sys/ipc.h> //ipc
|
||||
// #include <sys/shm.h>
|
||||
// #include "dirent.h"
|
||||
// #include <iconv.h>
|
||||
// #include <termios.h>
|
||||
// #include <netinet/in.h>
|
||||
// #include <netinet/ip.h>
|
||||
// #include <netinet/ip_icmp.h>
|
||||
// #include <netdb.h>
|
||||
|
||||
typedef struct statfs DISK,*pDISK;
|
||||
typedef struct statfs DISK, *pDISK;
|
||||
|
||||
#define SECTION_MAX_LEN 256
|
||||
#define STRVALUE_MAX_LEN 256
|
||||
#define LINE_CONTENT_MAX_LEN 256
|
||||
//配置文件位置
|
||||
#define NETWORK "/etc/network/interfaces"
|
||||
#define SYSTEMINFOFILE "/opt/configenv/SystemInfo.json" //系统信息
|
||||
#define SYSTEMINFOFILE "/opt/configenv/SystemInfo.json" //系统信息
|
||||
#define SERVERCONFIG "/opt/configenv/ServerConfig.json"
|
||||
#define NETWORKCONFIG "/opt/configenv/NetWorkConfig.json"
|
||||
#define SOFTWARE_RUN_LOG "/opt/log/"
|
||||
#define BOARDTYPE "/opt/configenv/boardtype" //设备类型
|
||||
#define SOFTWARE_RUN_LOG "/opt/log/"
|
||||
#define BOARDTYPE "/opt/configenv/boardtype" //设备类型
|
||||
#define ZIGBEECONFIG "/opt/configenv/ZigbeeConfig.json"
|
||||
|
||||
|
||||
#define SN "/opt/system/sn" //设备序列号
|
||||
#define SYSTEMSTART "/opt/system/start" //系统启动类型标志 0:正常启动 1:重启 2:
|
||||
#define BUILD_UINT16(x,y) (((x & 0x00FFu) << 8u) | (y & 0x00FFu))
|
||||
#define BUILD_UINT2(x,y) (((x) << 2u) | (y))
|
||||
#define SN "/opt/system/sn" //设备序列号
|
||||
#define SYSTEMSTART "/opt/system/start" //系统启动类型标志 0:正常启动 1:重启 2:
|
||||
#define BUILD_UINT16(x, y) (((x & 0x00FFu) << 8u) | (y & 0x00FFu))
|
||||
#define BUILD_UINT2(x, y) (((x) << 2u) | (y))
|
||||
// 生成UINT32 数据
|
||||
#define BUILD_UINT32(u,v,x,y) (((u & 0x00FFu) << 24u) | (v & 0x00FFu) << 16u) | (((x & 0x00FFu) << 8u) | (y & 0x00FFu))
|
||||
#define BUILD_UINT32(u, v, x, y) (((u & 0x00FFu) << 24u) | (v & 0x00FFu) << 16u) | (((x & 0x00FFu) << 8u) | (y & 0x00FFu))
|
||||
|
||||
// 生成UINT64 数据
|
||||
#define BUILD_UINT48(u,v,x,y,x1,y1) ( ((u & 0x00FFu) << 40u)| ((u & 0x00FFu) << 32u) |((x & 0x00FFu) << 24u) | (y & 0x00FFu) << 16u) | (((x1 & 0x00FFu) << 8u) | (y1 & 0x00FFu))
|
||||
#define BUILD_UINT48(u, v, x, y, x1, y1) (((u & 0x00FFu) << 40u) | ((u & 0x00FFu) << 32u) | ((x & 0x00FFu) << 24u) | (y & 0x00FFu) << 16u) | (((x1 & 0x00FFu) << 8u) | (y1 & 0x00FFu))
|
||||
|
||||
// 获取UINT32的高低字节
|
||||
#define UINT32_HIGH_1(x) ((x & 0xFF000000u) >> 24u)
|
||||
#define UINT32_HIGH_2(x) ((x & 0x00FF0000u) >> 16u)
|
||||
#define UINT32_LOW_1(x) ((x & 0x0000FF00u) >> 8u)
|
||||
#define UINT32_LOW_2(x) ((x & 0x000000FFu))
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit) /* 获取第bit位 */
|
||||
#define UINT32_HIGH_1(x) ((x & 0xFF000000u) >> 24u)
|
||||
#define UINT32_HIGH_2(x) ((x & 0x00FF0000u) >> 16u)
|
||||
#define UINT32_LOW_1(x) ((x & 0x0000FF00u) >> 8u)
|
||||
#define UINT32_LOW_2(x) ((x & 0x000000FFu))
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit) /* 获取第bit位 */
|
||||
// 获取UINT32的高低字节
|
||||
#define UINT16_HIGH(x) ((x & 0xFF00u) >> 8u)
|
||||
#define UINT16_LOW(x) ((x & 0x00FFu))
|
||||
#define UINT16_HIGH(x) ((x & 0xFF00u) >> 8u)
|
||||
#define UINT16_LOW(x) ((x & 0x00FFu))
|
||||
|
||||
#define GENERAL_BUF_SIZE 128 * 1024 * 10
|
||||
|
||||
#define GENERAL_BUF_SIZE 128*1024*10
|
||||
using namespace std;
|
||||
enum TIME_SIZE { TIME_MINUTE = 5, TIME_SECEOND = 8 };
|
||||
|
||||
|
||||
|
||||
|
||||
enum TIME_SIZE{
|
||||
TIME_MINUTE=5,
|
||||
TIME_SECEOND=8
|
||||
};
|
||||
|
||||
struct DevData{
|
||||
struct DevData {
|
||||
char mData[128];
|
||||
char mDataMing[128];
|
||||
int mLen;
|
||||
DevData():mLen(0){
|
||||
DevData() : mLen(0) {
|
||||
memset(mData, 0, 128);
|
||||
memset(mDataMing, 0, 128);
|
||||
}
|
||||
};
|
||||
|
||||
struct compressWaveChannel
|
||||
{
|
||||
int compressChannelX;
|
||||
struct compressWaveChannel {
|
||||
int compressChannelX;
|
||||
int compressChannelY;
|
||||
int compressChannelZ;
|
||||
int CountX;
|
||||
int CountY;
|
||||
int CountZ;
|
||||
compressWaveChannel(){
|
||||
compressChannelX = 0;
|
||||
compressChannelY = 0;
|
||||
compressChannelZ = 0;
|
||||
CountX = 0;
|
||||
CountY = 0;
|
||||
CountZ = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct DevDataOfGwid{
|
||||
std::string mDevdata;
|
||||
std::string mDevid;
|
||||
bool mIsSimulate;
|
||||
DevDataOfGwid():mDevdata(""),mDevid(""),mIsSimulate(false){
|
||||
int CountX;
|
||||
int CountY;
|
||||
int CountZ;
|
||||
compressWaveChannel() {
|
||||
compressChannelX = 0;
|
||||
compressChannelY = 0;
|
||||
compressChannelZ = 0;
|
||||
CountX = 0;
|
||||
CountY = 0;
|
||||
CountZ = 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef void (*onReceiveUart) (DevDataOfGwid &devData);
|
||||
struct DevDataOfGwid {
|
||||
std::string mDevdata;
|
||||
std::string mDevid;
|
||||
bool mIsSimulate;
|
||||
DevDataOfGwid() : mDevdata(""), mDevid(""), mIsSimulate(false) {}
|
||||
};
|
||||
|
||||
typedef void (*onReceiveUart)(DevDataOfGwid& devData);
|
||||
|
||||
struct sys_data {
|
||||
char data[10240];
|
||||
char data[10240];
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int total;
|
||||
int count;
|
||||
int type;
|
||||
int total;
|
||||
int count;
|
||||
int type;
|
||||
int number;
|
||||
int flag;
|
||||
int flag;
|
||||
char channelId[16];
|
||||
char SensorEngineeringUnit[32];
|
||||
float waveData[32000];
|
||||
char SensorEngineeringUnit[32];
|
||||
float waveData[32000];
|
||||
} WAVE_CONTAIN;
|
||||
|
||||
|
||||
|
||||
struct ZigbeeInfo {
|
||||
int DevMode;
|
||||
int Channel;
|
||||
std::string PanID;
|
||||
std::string MyAddr;
|
||||
std::string DstAddr;
|
||||
std::string RetryNum;
|
||||
std::string TranTimeout;
|
||||
int DevMode;
|
||||
int Channel;
|
||||
std::string PanID;
|
||||
std::string MyAddr;
|
||||
std::string DstAddr;
|
||||
std::string RetryNum;
|
||||
std::string TranTimeout;
|
||||
};
|
||||
|
||||
struct ZIGBEE {
|
||||
char reserve[4];
|
||||
char DevName[16];
|
||||
char DevPwd[16];
|
||||
unsigned char DevMode;
|
||||
unsigned char Chan;
|
||||
short PanID;
|
||||
short MyAddr;
|
||||
unsigned char MyIEEE[8];
|
||||
short DstAddr;
|
||||
unsigned char DstIEEE[8];
|
||||
unsigned char Reserve0;
|
||||
unsigned char PowerLevel;
|
||||
unsigned char RetryNum;
|
||||
unsigned char TranTimeout;
|
||||
unsigned char Serial_Rate;
|
||||
unsigned char Serial_DataB;
|
||||
unsigned char Serial_StopB;
|
||||
unsigned char Serial_ParityB;
|
||||
unsigned char Reserve[10];
|
||||
char reserve[4];
|
||||
char DevName[16];
|
||||
char DevPwd[16];
|
||||
unsigned char DevMode;
|
||||
unsigned char Chan;
|
||||
short PanID;
|
||||
short MyAddr;
|
||||
unsigned char MyIEEE[8];
|
||||
short DstAddr;
|
||||
unsigned char DstIEEE[8];
|
||||
unsigned char Reserve0;
|
||||
unsigned char PowerLevel;
|
||||
unsigned char RetryNum;
|
||||
unsigned char TranTimeout;
|
||||
unsigned char Serial_Rate;
|
||||
unsigned char Serial_DataB;
|
||||
unsigned char Serial_StopB;
|
||||
unsigned char Serial_ParityB;
|
||||
unsigned char Reserve[10];
|
||||
};
|
||||
|
||||
|
||||
struct RecvData {
|
||||
unsigned char Head[3];
|
||||
unsigned char ShortAddr[2];
|
||||
unsigned char Type;
|
||||
unsigned char Order;
|
||||
unsigned char Data[92];
|
||||
unsigned char Crc;
|
||||
unsigned char Head[3];
|
||||
unsigned char ShortAddr[2];
|
||||
unsigned char Type;
|
||||
unsigned char Order;
|
||||
unsigned char Data[92];
|
||||
unsigned char Crc;
|
||||
};
|
||||
|
||||
struct DataNodeInfo {
|
||||
int InitFlag;
|
||||
int AccFlag;
|
||||
int ZigbeeFlag;
|
||||
int TemTopFlag;
|
||||
int TemBotFlag;
|
||||
int EquipSta;//设备状态
|
||||
std::string ZigbeeLongAddr;
|
||||
std::string HardVersion;
|
||||
std::string SoftVersion;
|
||||
std::string BpNo;
|
||||
std::string SerialNo;
|
||||
std::string FirstPowerTime;
|
||||
int WakeupTime;
|
||||
int StaticTime;
|
||||
int WaveTime;
|
||||
int BateryV;
|
||||
std::string ProductNo;
|
||||
int RSSI; // 接收信号强度
|
||||
int ConfigFlag;
|
||||
unsigned int FeatureInterVal; //特征值发送时间间隔,单位分钟
|
||||
unsigned int WaveInterVal; //原始数据发送时间间隔,单位分钟
|
||||
std::string ZigbeePanId;
|
||||
int ZigbeeChannel;
|
||||
std::string ZigbeeShortAddr;
|
||||
std::string ZigbeeDesAddr;
|
||||
int ZigbeePower;
|
||||
int ZigbeeRetry;
|
||||
int ZigbeeRetryGap;
|
||||
int Range;//量程
|
||||
int SamplingRate;//采样率
|
||||
int ACCSampleTime;//采样时间
|
||||
int InitFlag;
|
||||
int AccFlag;
|
||||
int ZigbeeFlag;
|
||||
int TemTopFlag;
|
||||
int TemBotFlag;
|
||||
int EquipSta; //设备状态
|
||||
std::string ZigbeeLongAddr;
|
||||
std::string HardVersion;
|
||||
std::string SoftVersion;
|
||||
std::string BpNo;
|
||||
std::string SerialNo;
|
||||
std::string FirstPowerTime;
|
||||
int WakeupTime;
|
||||
int StaticTime;
|
||||
int WaveTime;
|
||||
int BateryV;
|
||||
std::string ProductNo;
|
||||
int RSSI; // 接收信号强度
|
||||
int ConfigFlag;
|
||||
unsigned int FeatureInterVal; //特征值发送时间间隔,单位分钟
|
||||
unsigned int WaveInterVal; //原始数据发送时间间隔,单位分钟
|
||||
std::string ZigbeePanId;
|
||||
int ZigbeeChannel;
|
||||
std::string ZigbeeShortAddr;
|
||||
std::string ZigbeeDesAddr;
|
||||
int ZigbeePower;
|
||||
int ZigbeeRetry;
|
||||
int ZigbeeRetryGap;
|
||||
int Range; //量程
|
||||
int SamplingRate; //采样率
|
||||
int ACCSampleTime; //采样时间
|
||||
|
||||
std::string StartBrands; //频带能量参数 1,2,3,4,5,START
|
||||
std::string StopBrands; //频带能量参数 1,2,3,4,5,END
|
||||
std::string StartBrands; //频带能量参数 1,2,3,4,5,START
|
||||
std::string StopBrands; //频带能量参数 1,2,3,4,5,END
|
||||
|
||||
std::string EnvelopeBandPass; //冲击带通频率
|
||||
std::string FaultFrequency; //故障频率1,2,3,4
|
||||
|
||||
std::string ConfigDate;//配置时间
|
||||
int VIntegralFilterFrequency;//速度积分滤波频率
|
||||
DataNodeInfo(){
|
||||
FeatureInterVal = 0;WaveInterVal = 0;
|
||||
}
|
||||
std::string EnvelopeBandPass; //冲击带通频率
|
||||
std::string FaultFrequency; //故障频率1,2,3,4
|
||||
|
||||
std::string ConfigDate; //配置时间
|
||||
int VIntegralFilterFrequency; //速度积分滤波频率
|
||||
DataNodeInfo() {
|
||||
FeatureInterVal = 0;
|
||||
WaveInterVal = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct DataRecvStatic {
|
||||
float TemTop;
|
||||
float TemBot;
|
||||
int Dip;
|
||||
int Voltage;
|
||||
float nodeWorkTime;
|
||||
float nodeSendTime;
|
||||
|
||||
float TemTop;
|
||||
float TemBot;
|
||||
int Dip;
|
||||
int Voltage;
|
||||
float nodeWorkTime;
|
||||
float nodeSendTime;
|
||||
};
|
||||
|
||||
struct DataRecvDym {
|
||||
float DiagnosisPk;
|
||||
float IntegratPk;
|
||||
float IntegratRMS;
|
||||
float RmsValues;
|
||||
float EnvelopEnergy;
|
||||
float Amp1;
|
||||
float Amp2;
|
||||
float Amp3;
|
||||
float Amp4;
|
||||
float Amp5;
|
||||
long Time;
|
||||
float Phase1;
|
||||
float Phase2;
|
||||
float Phase3;
|
||||
float Phase4;
|
||||
float DiagnosisPk;
|
||||
float IntegratPk;
|
||||
float IntegratRMS;
|
||||
float RmsValues;
|
||||
float EnvelopEnergy;
|
||||
float Amp1;
|
||||
float Amp2;
|
||||
float Amp3;
|
||||
float Amp4;
|
||||
float Amp5;
|
||||
long Time;
|
||||
float Phase1;
|
||||
float Phase2;
|
||||
float Phase3;
|
||||
float Phase4;
|
||||
};
|
||||
|
||||
struct TopicList{
|
||||
std::string mPubData; //每秒特征数据上传主题
|
||||
std::string mPubStatus; //状态上传主题
|
||||
std::string mPubHeart;
|
||||
std::string mPubConfig; //上传配置主题
|
||||
std::string mSubData; //订阅主题
|
||||
std::string mPubWaveData; //原始数据发布主题
|
||||
std::string mPubWaveSecondData; //原始数据发布主题
|
||||
std::string mPubCmd; //命令控制发布主题
|
||||
std::string mPubRep;
|
||||
std::string mPubTiming; //校时
|
||||
struct TopicList {
|
||||
std::string mPubData; //每秒特征数据上传主题
|
||||
std::string mPubStatus; //状态上传主题
|
||||
std::string mPubHeart;
|
||||
std::string mPubConfig; //上传配置主题
|
||||
std::string mSubData; //订阅主题
|
||||
std::string mPubWaveData; //原始数据发布主题
|
||||
std::string mPubWaveSecondData; //原始数据发布主题
|
||||
std::string mPubCmd; //命令控制发布主题
|
||||
std::string mPubRep;
|
||||
std::string mPubTiming; //校时
|
||||
|
||||
std::string mPubLocalWifi;
|
||||
std::string mPubLocalWaveServer;
|
||||
std::string mPubLocalWaveQt;
|
||||
std::string mPubLocalTrigger;
|
||||
std::string mPubLocalConfig;
|
||||
std::string mPubLocalCmd;
|
||||
std::string mPubLocalWifi;
|
||||
std::string mPubLocalWaveServer;
|
||||
std::string mPubLocalWaveQt;
|
||||
std::string mPubLocalTrigger;
|
||||
std::string mPubLocalConfig;
|
||||
std::string mPubLocalCmd;
|
||||
};
|
||||
|
||||
|
||||
//系统描述文件数据定义
|
||||
typedef struct
|
||||
{
|
||||
string siteID; //Unique ID for each site
|
||||
string siteName; //Controller site name
|
||||
string siteCountry; //Controller location country
|
||||
string siteProvince; //province
|
||||
string siteCity; //city
|
||||
double siteLongitude; //longitude
|
||||
double siteLatitude; //latitude
|
||||
string siteTimeZone;
|
||||
string plantName; //Unique plant number
|
||||
string plantNo;
|
||||
string equipmentName; //Equipment Description in the plant
|
||||
string equipmentNo;
|
||||
string dataWatchName; //DNS Name for the DataWatch
|
||||
long dataWachAddedDate; //Date of settings’ creation (Time Stamp)
|
||||
string dataWatchAssetID; //Unique equipment Asset ID
|
||||
string deviceType;
|
||||
string dataWachAddedBy; //User who edited settings
|
||||
string serialNumber;
|
||||
string softVersion;
|
||||
typedef struct {
|
||||
string siteID; // Unique ID for each site
|
||||
string siteName; // Controller site name
|
||||
string siteCountry; // Controller location country
|
||||
string siteProvince; // province
|
||||
string siteCity; // city
|
||||
double siteLongitude; // longitude
|
||||
double siteLatitude; // latitude
|
||||
string siteTimeZone;
|
||||
string plantName; // Unique plant number
|
||||
string plantNo;
|
||||
string equipmentName; // Equipment Description in the plant
|
||||
string equipmentNo;
|
||||
string dataWatchName; // DNS Name for the DataWatch
|
||||
long dataWachAddedDate; // Date of settings’ creation (Time Stamp)
|
||||
string dataWatchAssetID; // Unique equipment Asset ID
|
||||
string deviceType;
|
||||
string dataWachAddedBy; // User who edited settings
|
||||
string serialNumber;
|
||||
string softVersion;
|
||||
|
||||
}SystemInfo;
|
||||
} SystemInfo;
|
||||
|
||||
typedef struct {
|
||||
int number;
|
||||
std::string SensorEngineeringUnit;
|
||||
float waveData[GENERAL_BUF_SIZE];
|
||||
int number;
|
||||
std::string SensorEngineeringUnit;
|
||||
float waveData[GENERAL_BUF_SIZE];
|
||||
} WAVE_GENERAL;
|
||||
|
||||
|
||||
typedef struct{
|
||||
int zigAckrep;
|
||||
int zigAckreset;
|
||||
int zigReset;
|
||||
int zigDef;
|
||||
int alarmLight;
|
||||
int commPower;//4G,5G 电源开关
|
||||
int vol3_8;//5G 3.8v电源
|
||||
int commRest;//4G,5G复位
|
||||
int wifiPower;//WiFi 电源开关
|
||||
int wifiReset;//WiFi 复位
|
||||
int hardWatchDog;
|
||||
int power;
|
||||
int runLed;
|
||||
int errorLed;
|
||||
int netResetNet0;
|
||||
int netResetNet1;
|
||||
typedef struct {
|
||||
int zigAckrep;
|
||||
int zigAckreset;
|
||||
int zigReset;
|
||||
int zigDef;
|
||||
int alarmLight;
|
||||
int commPower; // 4G,5G 电源开关
|
||||
int vol3_8; // 5G 3.8v电源
|
||||
int commRest; // 4G,5G复位
|
||||
int wifiPower; // WiFi 电源开关
|
||||
int wifiReset; // WiFi 复位
|
||||
int hardWatchDog;
|
||||
int power;
|
||||
int runLed;
|
||||
int errorLed;
|
||||
int netResetNet0;
|
||||
int netResetNet1;
|
||||
} GPIOInfo;
|
||||
|
||||
|
||||
typedef struct DataNodeUpdate{
|
||||
std::string strUpdataFileName;
|
||||
std::string strSoftVersion;
|
||||
std::vector <std::string> hwVersion;
|
||||
typedef struct DataNodeUpdate {
|
||||
std::string strUpdataFileName;
|
||||
std::string strSoftVersion;
|
||||
std::vector<std::string> hwVersion;
|
||||
};
|
||||
|
||||
struct ethtool_value {
|
||||
unsigned int cmd;
|
||||
unsigned int data;
|
||||
unsigned int cmd;
|
||||
unsigned int data;
|
||||
};
|
||||
|
||||
extern std::string GBKToUTF8(const std::string& strGBK);
|
||||
@ -342,12 +322,12 @@ extern std::string UTFtoGBK(const char* utf8);
|
||||
extern void hexToAscii(const char* hexStr, char* asciiStr);
|
||||
extern void stringToHex(const char* str, char* hexStr);
|
||||
extern string GetLocalTimeWithMs(void);
|
||||
extern void InitGpio(unsigned int gpioN,unsigned int inout);
|
||||
extern int gpio_set(unsigned int gpioN,char x);
|
||||
extern void InitGpio(unsigned int gpioN, unsigned int inout);
|
||||
extern int gpio_set(unsigned int gpioN, char x);
|
||||
extern int gpio_read(unsigned int gpioN);
|
||||
extern int config_uart(const char* Port,speed_t speed);
|
||||
extern int write_data(int fd, char *buff, int len);
|
||||
extern int read_data(int fd, char *buff, int len, int timeout);
|
||||
extern int config_uart(const char* Port, speed_t speed);
|
||||
extern int write_data(int fd, char* buff, int len);
|
||||
extern int read_data(int fd, char* buff, int len, int timeout);
|
||||
extern int ModifyMac(char* buff);
|
||||
extern void mssleep(unsigned long microseconds);
|
||||
/**
|
||||
@ -363,17 +343,14 @@ extern int CheckFileVersion(int argc, char** argv);
|
||||
*/
|
||||
extern std::string GetCurrentTime();
|
||||
|
||||
extern tm *get_current_date() ;
|
||||
extern tm* get_current_date();
|
||||
/**
|
||||
* @brief 和系统交互函数
|
||||
* @param cmd 要发出的系统命令 例:ls
|
||||
* @param buf 系统返回的数据存在buf里
|
||||
* @return -1:失败 0:成功
|
||||
*/
|
||||
extern int system_custom(const char *cmd, char *buf);
|
||||
|
||||
|
||||
//extern int uartreadhandle();
|
||||
extern int system_custom(const char* cmd, char* buf);
|
||||
|
||||
/**
|
||||
* @brief 向日志写入内存信息
|
||||
@ -390,7 +367,7 @@ extern std::string GetDayDate();
|
||||
* @brief 获取当前时间 例 12:00
|
||||
* @return void
|
||||
*/
|
||||
extern void GetTime_(char * time_buff,TIME_SIZE len) ;
|
||||
extern void GetTime_(char* time_buff, TIME_SIZE len);
|
||||
|
||||
/**
|
||||
* @brief 获取当前时间戳
|
||||
@ -399,7 +376,9 @@ extern void GetTime_(char * time_buff,TIME_SIZE len) ;
|
||||
* @return void
|
||||
*/
|
||||
extern void GetTimeNet(char* timebuf, int type);
|
||||
|
||||
extern std::string GetRTC(char* timebuf, int& millisecond);
|
||||
|
||||
/**
|
||||
* @brief 从配置文件中读取数据
|
||||
* @param filename 配置文件名
|
||||
@ -447,7 +426,7 @@ extern std::string GetSysInfo();
|
||||
* @brief 去掉字符串所有空格
|
||||
* @return std::string
|
||||
*/
|
||||
extern std::string & ClearAllSpace(std::string &str);
|
||||
extern std::string& ClearAllSpace(std::string& str);
|
||||
|
||||
/**
|
||||
* @brief 调用接口写入data数据
|
||||
@ -465,7 +444,7 @@ extern void BackupDatFile();
|
||||
* @brief 降采样
|
||||
* @return double
|
||||
*/
|
||||
extern float * ReSample(int WaveDataLength, int N, int *NewWaveDataLength, std::vector<float> & WaveData);
|
||||
extern float* ReSample(int WaveDataLength, int N, int* NewWaveDataLength, std::vector<float>& WaveData);
|
||||
|
||||
/**
|
||||
* @brief 设置系统时间
|
||||
@ -500,17 +479,17 @@ extern void ZoneConfig(std::string zoneid);
|
||||
*/
|
||||
extern std::string GetSysStatus();
|
||||
double GetHardDiskFree();
|
||||
extern bool CheckIP(const char *ip);
|
||||
extern bool CheckIP(const char* ip);
|
||||
|
||||
bool IsValidMask(std::string mask);
|
||||
//read update config file
|
||||
extern std::vector <DataNodeUpdate> ReadStrUpdate(std::string filename);
|
||||
// read update config file
|
||||
extern std::vector<DataNodeUpdate> ReadStrUpdate(std::string filename);
|
||||
|
||||
extern void ReadStrConfig(std::string filename);
|
||||
extern void ImportConfig(std::string filename);
|
||||
extern int UpdataDataNodeConfig(std::string filename);
|
||||
extern char* solve(char *dest,const char *src);
|
||||
extern void swap(char *data);
|
||||
extern char* solve(char* dest, const char* src);
|
||||
extern void swap(char* data);
|
||||
extern int hexStringToBytes(const char* hexStr, unsigned char* bytes, size_t bytesSize);
|
||||
|
||||
extern int OpenWatchDog();
|
||||
@ -518,29 +497,29 @@ extern int WriteWatchDog(int fd);
|
||||
extern int CloseWatchDog(int fd);
|
||||
//获取4G信号强度
|
||||
extern int getcsq();
|
||||
extern std::string GetGwIp_(const char *eth_name);
|
||||
extern std::string GetGwIp_(const char* eth_name);
|
||||
extern string GetOneContent(const char* szData, int nRow, const char* szSeparate);
|
||||
extern int readStringValue(const char* section, char* key, char* val, const char* file);
|
||||
extern int writeStringVlaue(const char* section, char* key, char* val, const char* file);
|
||||
extern int readIntValue(const char* section, char* key, const char* file);
|
||||
extern int writeIntValue(const char* section, char* key, int val, const char* file);
|
||||
|
||||
int getDiskInfo(char* diskTotal,char* diskFree);
|
||||
int getDiskInfo(char* diskTotal, char* diskFree);
|
||||
|
||||
void timeout(int signo);
|
||||
unsigned short cal_chksum(unsigned short *addr,int len);
|
||||
int pack(int pkt_no,char *sendpacket);
|
||||
int send_packet(int pkt_no,char *sendpacket);
|
||||
int recv_packet(int pkt_no,char *recvpacket);
|
||||
int unpack(int cur_seq,char *buf,int len);
|
||||
void tv_sub(struct timeval *out,struct timeval *in);
|
||||
unsigned short cal_chksum(unsigned short* addr, int len);
|
||||
int pack(int pkt_no, char* sendpacket);
|
||||
int send_packet(int pkt_no, char* sendpacket);
|
||||
int recv_packet(int pkt_no, char* recvpacket);
|
||||
int unpack(int cur_seq, char* buf, int len);
|
||||
void tv_sub(struct timeval* out, struct timeval* in);
|
||||
void _CloseSocket();
|
||||
|
||||
int socketHeart(const char* pSendData);
|
||||
|
||||
extern bool NetIsOk();
|
||||
extern int Ping( const char *ips, int timeout);
|
||||
extern int get_netlink_status(const char *if_name);
|
||||
extern int Ping(const char* ips, int timeout);
|
||||
extern int get_netlink_status(const char* if_name);
|
||||
extern int compareVersions(const std::string& version1, const std::string& version2);
|
||||
extern void Binary_Bit(unsigned char* p_data, unsigned char position, int flag);
|
||||
|
||||
|
||||
@ -6,10 +6,7 @@
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <sys/syscall.h>
|
||||
#include <signal.h>
|
||||
#include "../API_log/SH_log.h"
|
||||
#include "SH_CommonFunc.hpp"
|
||||
#include "../mqttclient/SH_MqttClient.h"
|
||||
#include "../minilzo-2.10/minilzo.h"
|
||||
#include "common_func.hpp"
|
||||
|
||||
|
||||
#define SECTION_MAX_LEN 1024
|
||||
|
||||
@ -1,13 +1,7 @@
|
||||
#include "SH_Datatrans.hpp"
|
||||
#include "data_trans.hpp"
|
||||
#include "dirent.h"
|
||||
#include <stdio.h>
|
||||
|
||||
DataTrans *pDataTrans = DataTrans::instance();
|
||||
|
||||
struct DowloadFile {
|
||||
const char *filename;
|
||||
FILE *stream;
|
||||
};
|
||||
DataTrans::DataTrans() : m_bDebug(false) {}
|
||||
|
||||
DataTrans::~DataTrans() {}
|
||||
@ -39,7 +33,7 @@ static size_t OnWriteData(void *buffer, size_t size, size_t nmemb, void *lpVoid)
|
||||
|
||||
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
||||
printf("size = %d\n", size);
|
||||
struct DowloadFile *out = (struct DowloadFile *)stream;
|
||||
struct DownloadFile *out = (struct DownloadFile *)stream;
|
||||
if (out && !out->stream) {
|
||||
out->stream = fopen(out->filename, "wb"); //打开文件进行写入
|
||||
if (!out->stream) return -1;
|
||||
@ -47,11 +41,11 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
||||
return fwrite(buffer, size, nmemb, out->stream);
|
||||
}
|
||||
|
||||
int DataTrans::download(char *pFilename, string &strUrl, string &strResponse, bool bDownload) {
|
||||
int DataTrans::download(char *pFilename, std::string &strUrl, std::string &strResponse, bool bDownload) {
|
||||
CURL *curl = NULL;
|
||||
CURLcode res;
|
||||
struct DowloadFile dlfile = {pFilename, //定义下载到本地的文件位置和路径
|
||||
NULL};
|
||||
struct DownloadFile dlfile = {pFilename, //定义下载到本地的文件位置和路径
|
||||
NULL};
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init(); //初始化一个curl指针
|
||||
if (curl) { // curl对象存在的情况下执行的操作
|
||||
@ -77,60 +71,55 @@ int DataTrans::download(char *pFilename, string &strUrl, string &strResponse, bo
|
||||
//释放curl对象
|
||||
curl_easy_cleanup(curl);
|
||||
if (res != CURLE_OK) {
|
||||
cout << stderr << res << endl;
|
||||
std::cout << stderr << res << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
printf("strResponse = %s\n", strResponse.c_str());
|
||||
if (bDownload) {
|
||||
if (dlfile.stream) {
|
||||
//关闭文件流
|
||||
fclose(dlfile.stream);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
//释放全局curl对象
|
||||
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
//下载文件数据接收函数
|
||||
|
||||
size_t writedata2file(void *ptr, size_t size, size_t nmemb, FILE *stream) {
|
||||
size_t written = fwrite(ptr, size, nmemb, stream);
|
||||
return written;
|
||||
}
|
||||
// http POST请求文件下载
|
||||
int DataTrans::dl_curl_post_req(const string &url, const string &postParams, string &filename) {
|
||||
|
||||
int DataTrans::dl_curl_post_req(const std::string &url, const std::string &postParams, std::string &filename) {
|
||||
CURL *curl;
|
||||
FILE *fp;
|
||||
CURLcode res;
|
||||
/* 调用curl_global_init()初始化libcurl */
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if (CURLE_OK != res) {
|
||||
printf("init libcurl failed.");
|
||||
curl_global_cleanup();
|
||||
return -1;
|
||||
}
|
||||
/* 调用curl_easy_init()函数得到 easy interface型指针 */
|
||||
|
||||
curl = curl_easy_init();
|
||||
if (curl) {
|
||||
fp = fopen(filename.c_str(), "wb");
|
||||
|
||||
/* 调用curl_easy_setopt()设置传输选项 */
|
||||
res = curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
if (res != CURLE_OK) {
|
||||
fclose(fp);
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
/* 根据curl_easy_setopt()设置的传输选项,实现回调函数以完成用户特定任务 */
|
||||
|
||||
res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writedata2file);
|
||||
if (res != CURLE_OK) {
|
||||
fclose(fp);
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
/* 根据curl_easy_setopt()设置的传输选项,实现回调函数以完成用户特定任务 */
|
||||
|
||||
res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
if (res != CURLE_OK) {
|
||||
fclose(fp);
|
||||
@ -139,18 +128,16 @@ int DataTrans::dl_curl_post_req(const string &url, const string &postParams, str
|
||||
}
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
// 调用curl_easy_perform()函数完成传输任务
|
||||
|
||||
fclose(fp);
|
||||
/* Check for errors */
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
// 调用curl_easy_cleanup()释放内存
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
@ -358,7 +345,7 @@ int DataTrans::Send_file_socket(const std::string &filename) { return 0; }
|
||||
|
||||
int DataTrans::Send_Dir_socket(const char *dirname) {
|
||||
DIR *dirp;
|
||||
std::vector<string> v;
|
||||
std::vector<std::string> v;
|
||||
std::string temp;
|
||||
struct dirent *dp;
|
||||
dirp = opendir(dirname);
|
||||
@ -374,9 +361,6 @@ int DataTrans::Send_Dir_socket(const char *dirname) {
|
||||
char buffer[BUFFER_SIZE];
|
||||
FILE *fp;
|
||||
int file_block_length = 0;
|
||||
/*
|
||||
*创建socket
|
||||
*/
|
||||
if (socketfd < 0) {
|
||||
print_error("Socket create error! \n");
|
||||
return -1;
|
||||
@ -401,10 +385,9 @@ int DataTrans::Send_Dir_socket(const char *dirname) {
|
||||
std::vector<std::string>::iterator iter;
|
||||
for (iter = v.begin(); iter != v.end(); ++iter) {
|
||||
temp = *iter;
|
||||
cout << temp.c_str() << endl;
|
||||
std::cout << temp.c_str() << std::endl;
|
||||
int file_name_length = (int)strlen(temp.c_str());
|
||||
if (send(socketfd, (char *)&file_name_length, sizeof(int), 0) < 0) { //发送文件名长度
|
||||
|
||||
print_error("Send File_Name_Length Failed!\n");
|
||||
} else {
|
||||
print_info("Send File_Name_Length Success!\n");
|
||||
@ -442,4 +425,5 @@ int DataTrans::Send_Dir_socket(const char *dirname) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DataTrans::SetDebug(bool bDebug) { m_bDebug = bDebug; }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef DATATRANS_HPP_
|
||||
#define DATATRANS_HPP_
|
||||
#ifndef DATAT_RANS_HPP_
|
||||
#define DATAT_RANS_HPP_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
@ -7,14 +7,20 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdlib.h>
|
||||
#include "../common/SH_global.h"
|
||||
#include <boost/container/detail/singleton.hpp>
|
||||
#include "common/global.hpp"
|
||||
|
||||
#define BUFFER_SIZE 4096
|
||||
|
||||
#define IP "127.0.0.1"
|
||||
#define PORT 12345
|
||||
|
||||
class DataTrans : public MySingleton<DataTrans> {
|
||||
struct DownloadFile {
|
||||
const char *filename;
|
||||
FILE *stream;
|
||||
};
|
||||
|
||||
class DataTrans {
|
||||
public:
|
||||
DataTrans();
|
||||
~DataTrans();
|
||||
@ -92,8 +98,8 @@ public:
|
||||
*/
|
||||
int Send_Dir_socket(const char *dirname);
|
||||
|
||||
int download(char *pFilename, string &strUrl, string &strResponse, bool bDownload);
|
||||
int dl_curl_post_req(const string &url, const string &postParams, string &filename);
|
||||
int download(char *pFilename, std::string &strUrl, std::string &strResponse, bool bDownload);
|
||||
int dl_curl_post_req(const std::string &url, const std::string &postParams, std::string &filename);
|
||||
|
||||
public:
|
||||
void SetDebug(bool bDebug);
|
||||
@ -102,5 +108,5 @@ private:
|
||||
bool m_bDebug;
|
||||
};
|
||||
|
||||
extern DataTrans *pDataTrans;
|
||||
#endif
|
||||
typedef boost::container::dtl::singleton_default<DataTrans> data_trans;
|
||||
#endif // DATAT_RANS_HPP_
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
#include "SH_SqlDB.hpp"
|
||||
#include "../API_log/SH_log.h"
|
||||
#include "../common/SH_global.h"
|
||||
#include "sql_db.hpp"
|
||||
#include <unistd.h>
|
||||
#include "../calculation/Calculation.hpp"
|
||||
#include "common/global.hpp"
|
||||
#include "calculation/calculation.hpp"
|
||||
|
||||
bool SqlSwitch() {
|
||||
if (access("./sql", 0) >= 0) {
|
||||
@ -11,8 +10,6 @@ bool SqlSwitch() {
|
||||
return false;
|
||||
}
|
||||
|
||||
SqliteDB *sql_ctl = SqliteDB::instance();
|
||||
|
||||
SqliteDB::SqliteDB() {}
|
||||
|
||||
SqliteDB::~SqliteDB() {}
|
||||
@ -105,21 +102,8 @@ void SqliteDB::SqliteInit(const char *pDbName, bool isDB2) {
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s);", "t_battery_history", T_BATTERY_INFO(DATANODENO), T_BATTERY_INFO(DIP), T_BATTERY_INFO(TEMBOT), T_BATTERY_INFO(NODEWORKTIME), T_BATTERY_INFO(NODESENDTIME), T_BATTERY_INFO(BATTERYVOLTAGE),
|
||||
T_BATTERY_INFO(BATTERYUSAGE), T_BATTERY_INFO(BATTERYREMAIN), T_BATTERY_INFO(TIMESTAMP));
|
||||
CreateTable(sql_exec, isDB2);
|
||||
|
||||
/*memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s integer,%s integer ,%s integer ,%s integer,%s integer);",
|
||||
T_DATANODE_TIME(TNAME),
|
||||
T_DATANODE_TIME(DATANODENO),
|
||||
T_DATANODE_TIME(SHORTADDR),
|
||||
T_DATANODE_TIME(STATICCYCLE),
|
||||
T_DATANODE_TIME(WAVECYCLE),
|
||||
T_DATANODE_TIME(NODEGROUP),
|
||||
T_DATANODE_TIME(NODEINDEX),
|
||||
T_DATANODE_TIME(NODEWAVEINDEX),
|
||||
T_DATANODE_TIME(STATICTIME),
|
||||
T_DATANODE_TIME(STATICSTARTTIME));
|
||||
CreateTable(sql_exec, isDB2);*/
|
||||
}
|
||||
|
||||
void SqliteDB::Createtable(const char *ptableName) {
|
||||
char sql_exec[2048];
|
||||
//创建传感器数据存储表
|
||||
@ -405,6 +389,7 @@ array_t SqliteDB::GetDataMultiLine(const char *tablename, const char *column, co
|
||||
g_tDbMutex.UnLock();
|
||||
return arrResult;
|
||||
}
|
||||
|
||||
array_t SqliteDB::GetDataMultiLineTransaction(const char *tablename, const char *column, const char *whereCon) {
|
||||
array_t arrResult;
|
||||
std::string strSql = "select ";
|
||||
@ -440,6 +425,7 @@ array_t SqliteDB::GetDataMultiLineTransaction(const char *tablename, const char
|
||||
sqlite3_exec(mDBAcess, "COMMIT", 0, 0, NULL);
|
||||
return arrResult;
|
||||
}
|
||||
|
||||
vec_t SqliteDB::GetDataMultiLineOfOneColumn(const char *tablename, const char *column, const char *whereCon) {
|
||||
vec_t vecResult;
|
||||
std::string strSql = "select ";
|
||||
@ -466,6 +452,7 @@ vec_t SqliteDB::GetDataMultiLineOfOneColumn(const char *tablename, const char *c
|
||||
sqlite3_finalize(stmt);
|
||||
return vecResult;
|
||||
}
|
||||
|
||||
vec_Value SqliteDB::GetDataMultiLineOfOneColumnDouble(const char *tablename, const char *column, const char *whereCon) {
|
||||
vec_Value vecResult;
|
||||
std::string strSql = "select ";
|
||||
@ -530,6 +517,7 @@ int SqliteDB::DeleteTableDataOneConditon(const char *tablename, const char *cond
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
int SqliteDB::UpdateNodeNameData(const char *tablename, const char *updateColumn, const char *whereCond, bool isDB2) {
|
||||
std::string strSql = "update ";
|
||||
char szSql[1024] = {0x00};
|
||||
@ -556,6 +544,7 @@ int SqliteDB::UpdateNodeNameData(const char *tablename, const char *updateColumn
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
int SqliteDB::UpdateTableData(const char *tablename, const char *updateColumn, const char *whereCond, bool isDB2) {
|
||||
std::string strSql = "update ";
|
||||
if (whereCond != NULL) {
|
||||
@ -643,6 +632,7 @@ int SqliteDB::InsertData(const char *tablename, const char *insertValues, int re
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
int SqliteDB::InsertData(const char *insertSql) {
|
||||
char *msg;
|
||||
int iRet = sqlite3_exec(GetDbHandle(false), insertSql, 0, 0, &msg);
|
||||
@ -652,6 +642,7 @@ int SqliteDB::InsertData(const char *insertSql) {
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
int SqliteDB::CalculateBattery() {
|
||||
LOG_INFO("CalculateBattery start\n");
|
||||
char whereCon[1024] = {0};
|
||||
@ -668,13 +659,13 @@ int SqliteDB::CalculateBattery() {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(selectSql, 0x00, sizeof(selectSql));
|
||||
sprintf(whereCon, " dataNodeNo = '%s' and batteryRemain <> '' order by timeStamp desc limit 0,1 ", vecRes[i][0].c_str());
|
||||
vec_t vecResSig = sql_ctl->GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||
vector<string> vParam;
|
||||
vec_t vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||
std::vector<std::string> vParam;
|
||||
boost::split(vParam, vecRes[i][6], boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParam.size() <= 0 || vecResSig.size() <= 0) { //第一次计算
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str());
|
||||
string Dip = sql_ctl->GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
||||
std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
||||
if (Dip == "") {
|
||||
continue;
|
||||
}
|
||||
@ -686,12 +677,10 @@ int SqliteDB::CalculateBattery() {
|
||||
int iRet = UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][0].c_str());
|
||||
vecResSig = sql_ctl->GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||
vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||
if (vecResSig.size() <= 0) { //一条数据都没有
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
} else {
|
||||
capacity = atof(vecResSig[7].c_str());
|
||||
}
|
||||
@ -712,9 +701,9 @@ int SqliteDB::CalculateBattery() {
|
||||
float y2 = (float)y10_mins / (float)d200_mins;
|
||||
|
||||
float k = (y2 - y1) / (x2 - x1);
|
||||
vector<float> vecb;
|
||||
vector<long> vecworkTime;
|
||||
vector<long> vecsendTime;
|
||||
std::vector<float> vecb;
|
||||
std::vector<long> vecworkTime;
|
||||
std::vector<long> vecsendTime;
|
||||
float to_math = 0.0;
|
||||
print_info("vecResbattery = %d,temp = %s\n", vecResbattery.size(), vecResbattery[0][2].c_str());
|
||||
|
||||
@ -754,12 +743,12 @@ int SqliteDB::CalculateBattery() {
|
||||
LOG_INFO("dataNodeNo = %s,batteryUsage = %f,batteryRemain = %f\n", vecRes[i][0].c_str(), atof(vecResSig[6].c_str()), remainBattery);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp desc limit 0,1 ", vecRes[i][0].c_str());
|
||||
string strtimeStamp = sql_ctl->GetData(T_BATTERY_INFO(TNAME), " timeStamp ", whereCon);
|
||||
std::string strtimeStamp = sqlite_db_ctrl::instance().GetData(T_BATTERY_INFO(TNAME), " timeStamp ", whereCon);
|
||||
|
||||
sprintf(updateSql, "batteryUsage='%f',batteryRemain='%f'", usageBattery, remainBattery);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo ='%s' and timeStamp = '%s'", vecRes[i][0].c_str(), strtimeStamp.c_str());
|
||||
sql_ctl->UpdateTableData(T_BATTERY_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_BATTERY_INFO(TNAME), updateSql, whereCon);
|
||||
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
@ -779,7 +768,7 @@ int SqliteDB::CalculateBattery() {
|
||||
}
|
||||
|
||||
int iRet = UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
}
|
||||
}
|
||||
@ -787,6 +776,7 @@ int SqliteDB::CalculateBattery() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SqliteDB::CalculateDip() {
|
||||
char whereCon[1024] = {0};
|
||||
char selectSql[1024] = {0};
|
||||
@ -802,7 +792,7 @@ int SqliteDB::CalculateDip() {
|
||||
vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), " * ", NULL);
|
||||
print_info("vecRes111 = %d\n", vecRes.size());
|
||||
for (int i = 0; i < vecRes.size(); i++) {
|
||||
vector<string> vParam;
|
||||
std::vector<std::string> vParam;
|
||||
print_info("vecRes =%s\n", vecRes[i][42].c_str());
|
||||
boost::split(vParam, vecRes[i][42], boost::is_any_of(","), boost::token_compress_on);
|
||||
print_info("vParam size = %d\n", vParam.size());
|
||||
@ -817,8 +807,7 @@ int SqliteDB::CalculateDip() {
|
||||
sprintf(whereCon, " timeStamp > '%ld' ", atol(vParam[2].c_str()));
|
||||
} else if (vParam[1] == "0") { //正常状态
|
||||
sprintf(whereCon, " timeStamp > '%ld' ", atol(localtimestamp) - 86400); //一天数据
|
||||
} else if (vParam[1] == "1") //松动状态
|
||||
{
|
||||
} else if (vParam[1] == "1") { //松动状态
|
||||
continue;
|
||||
}
|
||||
print_info("vParam[0]= %s,vParam[1]=%s\n", vParam[0].c_str(), vParam[1].c_str());
|
||||
@ -843,7 +832,7 @@ int SqliteDB::CalculateDip() {
|
||||
sprintf(updateSql, "LooseValue = '%f,0' ", atof(vParam[0].c_str()));
|
||||
} else {
|
||||
sprintf(updateSql, "LooseValue = '%f,2,", atof(vParam[0].c_str()));
|
||||
string strUpdateSql = string(updateSql) + vParam[2] + "' ";
|
||||
std::string strUpdateSql = std::string(updateSql) + vParam[2] + "' ";
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
memcpy(updateSql, strUpdateSql.c_str(), sizeof(updateSql));
|
||||
}
|
||||
@ -860,24 +849,24 @@ int SqliteDB::CalculateDip() {
|
||||
|
||||
int SqliteDB::InintGateway() {
|
||||
//更新网关配置表
|
||||
string strIP = GetGwIp_("eth0");
|
||||
string strServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||
string strServerPort = ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort");
|
||||
string strwebVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
||||
string strsystemVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
||||
string strGatewayVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
|
||||
std::string strIP = GetGwIp_("eth0");
|
||||
std::string strServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||
std::string strServerPort = ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort");
|
||||
std::string strwebVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
||||
std::string strsystemVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
||||
std::string strGatewayVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
|
||||
std::string strchan = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "channel");
|
||||
std::string strPanID = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "PanID");
|
||||
if (strPanID == "") {
|
||||
strPanID = GlobalConfig::MacAddr_G.substr(8);
|
||||
}
|
||||
if (0 == sql_ctl->GetTableRows(T_GATEWAY_INFO(TNAME), NULL)) {
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_GATEWAY_INFO(TNAME), NULL)) {
|
||||
char strSql[1024] = {0};
|
||||
sprintf(strSql, "insert into t_gateway_info(gatewayMAC,zigbeePanID,zigbeeChannel,\
|
||||
localIP,systemVersion,programVersion,webVersion,serverIP,serverPort,MAC2)\
|
||||
values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');",
|
||||
GlobalConfig::MacAddr_G.c_str(), strPanID.c_str(), strchan.c_str(), strIP.c_str(), strsystemVersion.c_str(), strGatewayVersion.c_str(), strwebVersion.c_str(), strServerIP.c_str(), strServerPort.c_str(), GlobalConfig::MacAddr_G2.c_str());
|
||||
sql_ctl->InsertData(strSql);
|
||||
sqlite_db_ctrl::instance().InsertData(strSql);
|
||||
print_info("strSql = %s\n", strSql);
|
||||
} else {
|
||||
char whereCon[1024] = {0};
|
||||
@ -885,7 +874,7 @@ int SqliteDB::InintGateway() {
|
||||
sprintf(updateSql, "zigbeePanID = '%s',zigbeeChannel = '%s',localIP = '%s',systemVersion='%s',programVersion='%s',webVersion='%s',serverIP='%s',serverPort='%s'", strPanID.c_str(), strchan.c_str(), strIP.c_str(), strsystemVersion.c_str(), strGatewayVersion.c_str(),
|
||||
strwebVersion.c_str(), strServerIP.c_str(), strServerPort.c_str());
|
||||
sprintf(whereCon, "gatewayMAC='%s'", GlobalConfig::MacAddr_G.c_str());
|
||||
sql_ctl->UpdateTableData(T_GATEWAY_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_GATEWAY_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
|
||||
//上传网关配置到MQTT
|
||||
@ -933,7 +922,7 @@ std::string SqliteDB::GetNodeConfigureInfor(const char *whereCon) {
|
||||
jsonVal["message"] = "查询成功";
|
||||
Json::Value jsArray;
|
||||
array_t arrRes;
|
||||
arrRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", whereCon);
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", whereCon);
|
||||
int iResult = arrRes.size();
|
||||
if (iResult > 0) {
|
||||
for (int j = 0; j < iResult; j++) {
|
||||
@ -1068,8 +1057,8 @@ int SqliteDB::QueryofflineData() {
|
||||
memset(whereCon, 0, 64);
|
||||
sprintf(whereCon, "dataNodeNo = '%s' and TimeStamp = '%s'", arrRetData[j][0].c_str(), arrRetData[j][8].c_str());
|
||||
memcpy(updateSql, "sendMsg='1'", sizeof(updateSql));
|
||||
sql_ctl->UpdateTableData(StaticTableName, updateSql, whereCon);
|
||||
sql_ctl->UpdateTableData(dataTableName, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(StaticTableName, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(dataTableName, updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1119,7 +1108,7 @@ int SqliteDB::QueryofflineData() {
|
||||
char updateSql[1024] = {0x00};
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", arrRetData[i][0].c_str(), arrRetData[i][2].c_str());
|
||||
sprintf(updateSql, "SendMsg = 1");
|
||||
sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
|
||||
std::string strCmd = "rm " + arrRetData[i][1];
|
||||
system(strCmd.c_str());
|
||||
@ -1151,7 +1140,7 @@ int SqliteDB::CalculateData() {
|
||||
int TimingCount = GetTableRows(tableName, sql);
|
||||
print_info("nodeWaveSend = %s,waveInterVal = %s\n", vecRet[i][2].c_str(), vecRet[i][4].c_str());
|
||||
if (vecRet[i][2] == "") continue;
|
||||
vector<string> nodeWaveSend;
|
||||
std::vector<std::string> 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;
|
||||
@ -1171,14 +1160,14 @@ int SqliteDB::CalculateData() {
|
||||
" 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());
|
||||
string strsql = string(sql1) + string(whereCon);
|
||||
std::string strsql = std::string(sql1) + std::string(whereCon);
|
||||
printf("sql = %s\n", strsql.c_str());
|
||||
CountWaveX = GetTableRows(tableName, strsql.c_str());
|
||||
sprintf(whereCon, " and channelID = '%s-X'", vecRet[i][1].c_str());
|
||||
strsql = string(sql2) + string(whereCon);
|
||||
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 = string(sql3) + string(whereCon);
|
||||
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;
|
||||
@ -1188,13 +1177,13 @@ int SqliteDB::CalculateData() {
|
||||
}
|
||||
if (nodeWaveSend[1] == "0") {
|
||||
sprintf(whereCon, " and channelID = '%s-Y'", vecRet[i][1].c_str());
|
||||
string strsql = string(sql1) + string(whereCon);
|
||||
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 = string(sql2) + string(whereCon);
|
||||
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 = string(sql3) + string(whereCon);
|
||||
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)))) {
|
||||
@ -1205,13 +1194,13 @@ int SqliteDB::CalculateData() {
|
||||
}
|
||||
if (nodeWaveSend[2] == "0") {
|
||||
sprintf(whereCon, " and channelID = '%s-Z'", vecRet[i][1].c_str());
|
||||
string strsql = string(sql1) + string(whereCon);
|
||||
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 = string(sql2) + string(whereCon);
|
||||
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 = string(sql3) + string(whereCon);
|
||||
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)))) {
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
#ifndef _SQLDB_H_L
|
||||
#define _SQLDB_H_L
|
||||
#ifndef SQL_DB_HPP_
|
||||
#define SQL_DB_HPP_
|
||||
extern "C" {
|
||||
#include <sqlite3.h>
|
||||
}
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <boost/container/detail/singleton.hpp>
|
||||
|
||||
#define T_SENSOR_INFO(x) T_SENSOR_INFO[T_SENSOR_INFO_##x]
|
||||
#define T_DATA_INFO(x) T_DATA_INFO[T_DATA_INFO_##x]
|
||||
@ -70,7 +69,8 @@ private:
|
||||
sqlite3 *mDBAcess;
|
||||
sqlite3 *mDb2;
|
||||
};
|
||||
extern SqliteDB *sql_ctl;
|
||||
|
||||
typedef boost::container::dtl::singleton_default<SqliteDB> sqlite_db_ctrl;
|
||||
|
||||
typedef enum {
|
||||
T_SENSOR_INFO_TNAME = 0,
|
||||
@ -202,4 +202,4 @@ typedef enum {
|
||||
|
||||
} T_BATTERY_INFO_Index;
|
||||
const static char *T_BATTERY_INFO[] = {"t_battery_info", "dataNodeNo", "Dip", "temBot", "nodeWorkTime", "nodeSendTime", "batteryVoltage", "batteryUsage", "batteryRemain", "timeStamp"};
|
||||
#endif
|
||||
#endif // SQL_DB_HPP_
|
||||
|
||||
509
dial5G/dial.cpp
509
dial5G/dial.cpp
@ -1,296 +1,247 @@
|
||||
/*
|
||||
* Dial.cpp
|
||||
*
|
||||
* Created on: 2023年6月13日
|
||||
* Author: chaos
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
#include "Dial.h"
|
||||
|
||||
// #include <fcntl.h>
|
||||
// #include <unistd.h>
|
||||
// #include <termios.h>
|
||||
// #include <sys/types.h>
|
||||
// #include <sys/stat.h>
|
||||
#include <string>
|
||||
#include "common/common_func.hpp"
|
||||
#include "dial.h"
|
||||
|
||||
Dial::Dial() {
|
||||
// TODO Auto-generated constructor stub
|
||||
m_fd = 0;
|
||||
m_curState = CPIN;
|
||||
m_dial = 0;
|
||||
m_APN = 0;
|
||||
m_fd = 0;
|
||||
m_curState = CPIN;
|
||||
m_dial = 0;
|
||||
m_APN = 0;
|
||||
}
|
||||
|
||||
Dial::~Dial() {
|
||||
// TODO Auto-generated destructor stub
|
||||
Dial::~Dial() {}
|
||||
|
||||
int Dial::openPort(const char *pPort) {
|
||||
m_fd = config_uart(pPort, 115200);
|
||||
print_info("m_fd = %d\n", m_fd);
|
||||
return m_fd;
|
||||
}
|
||||
|
||||
int Dial::openPort(const char* pPort)
|
||||
{
|
||||
m_fd = config_uart(pPort,115200);
|
||||
print_info("m_fd = %d\n",m_fd);
|
||||
return m_fd;
|
||||
}
|
||||
int Dial::parseData(Event event,const char* pData)
|
||||
{
|
||||
print_info("m_curState = %d,event = %d\n",m_curState,event);
|
||||
string signal;
|
||||
string ret;
|
||||
std::string str;
|
||||
int pos = 0;
|
||||
switch(event){
|
||||
case Event_CPIN:
|
||||
if(!strncmp(pData,"READY",5)){
|
||||
m_curState = QCFGNET;
|
||||
}else if(!strncmp(pData,"NOT READY",9)){
|
||||
m_curState = CPIN;
|
||||
GlobalConfig::NetStatus = "\"LIMSRV\"";
|
||||
}
|
||||
break;
|
||||
case Event_QCFGNET:
|
||||
case Event_QCFGSMS:
|
||||
/*ret = GetOneContent(pData,1,",");
|
||||
if(ret == "0")
|
||||
{
|
||||
m_curState = QICSGPAPN;
|
||||
}*/
|
||||
break;
|
||||
case Event_QICSGPAPN:
|
||||
//if(!strcmp(pData,"OK"))
|
||||
{
|
||||
m_curState = QNETDEVCTL;
|
||||
}
|
||||
break;
|
||||
case Event_QENG:
|
||||
GlobalConfig::NetStatus = GetOneContent(pData,1,",");
|
||||
GlobalConfig::NetType = GetOneContent(pData,2,",");
|
||||
signal = GetOneContent(pData,12,",");
|
||||
GlobalConfig::NetSignal = atoi(signal.c_str());
|
||||
print_info("NetStatus = %s,NetSignal = %d\n",GlobalConfig::NetStatus.c_str(),GlobalConfig::NetSignal);
|
||||
break;
|
||||
case Event_QNETDEVCTL:
|
||||
print_info("m_curState Event_QNETDEVCTL = %d\n",m_curState);
|
||||
if(m_dial == 1){
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
break;
|
||||
case Event_QNETDEVSTATUS:
|
||||
ret = GetOneContent(pData,3,",");
|
||||
if(ret == "0" || ret == "")
|
||||
m_curState = QDCHPC;
|
||||
else
|
||||
m_curState = QNETDEVSTATUS;
|
||||
break;
|
||||
case Event_OK:
|
||||
if(m_curState == QNETDEVCTL && m_dial == 1)
|
||||
{
|
||||
m_dial = 0;
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
if(m_curState == Event_QCFGNET){
|
||||
m_curState = QNETDEVCTL;
|
||||
}
|
||||
if(m_curState == QICSGPAPN && m_APN == 1)
|
||||
{
|
||||
m_APN = 0;
|
||||
m_curState = QNETDEVCTL;
|
||||
}
|
||||
int Dial::parseData(Event event, const char *pData) {
|
||||
print_info("m_curState = %d,event = %d\n", m_curState, event);
|
||||
std::string signal;
|
||||
std::string ret;
|
||||
std::string str;
|
||||
int pos = 0;
|
||||
switch (event) {
|
||||
case Event_CPIN:
|
||||
if (!strncmp(pData, "READY", 5)) {
|
||||
m_curState = QCFGNET;
|
||||
} else if (!strncmp(pData, "NOT READY", 9)) {
|
||||
m_curState = CPIN;
|
||||
GlobalConfig::NetStatus = "\"LIMSRV\"";
|
||||
}
|
||||
break;
|
||||
case Event_QCFGNET:
|
||||
case Event_QCFGSMS: break;
|
||||
case Event_QICSGPAPN: {
|
||||
m_curState = QNETDEVCTL;
|
||||
} break;
|
||||
case Event_QENG:
|
||||
GlobalConfig::NetStatus = GetOneContent(pData, 1, ",");
|
||||
GlobalConfig::NetType = GetOneContent(pData, 2, ",");
|
||||
signal = GetOneContent(pData, 12, ",");
|
||||
GlobalConfig::NetSignal = atoi(signal.c_str());
|
||||
print_info("NetStatus = %s,NetSignal = %d\n", GlobalConfig::NetStatus.c_str(), GlobalConfig::NetSignal);
|
||||
break;
|
||||
case Event_QNETDEVCTL:
|
||||
print_info("m_curState Event_QNETDEVCTL = %d\n", m_curState);
|
||||
if (m_dial == 1) {
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
break;
|
||||
case Event_QNETDEVSTATUS:
|
||||
ret = GetOneContent(pData, 3, ",");
|
||||
if (ret == "0" || ret == "")
|
||||
m_curState = QDCHPC;
|
||||
else
|
||||
m_curState = QNETDEVSTATUS;
|
||||
break;
|
||||
case Event_OK:
|
||||
if (m_curState == QNETDEVCTL && m_dial == 1) {
|
||||
m_dial = 0;
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
if (m_curState == Event_QCFGNET) {
|
||||
m_curState = QNETDEVCTL;
|
||||
}
|
||||
if (m_curState == QICSGPAPN && m_APN == 1) {
|
||||
m_APN = 0;
|
||||
m_curState = QNETDEVCTL;
|
||||
}
|
||||
|
||||
break;
|
||||
case Event_ERROR:
|
||||
if(m_curState == CPIN && !strcmp(pData,"3")){
|
||||
m_curState = CPIN;
|
||||
GlobalConfig::NetStatus = "\"LIMSRV\"";
|
||||
}
|
||||
if(m_curState == QNETDEVCTL){
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
break;
|
||||
case Event_TEMP:
|
||||
str = string(pData);
|
||||
pos = str.find("soc-thermal");
|
||||
if(pos > 0){
|
||||
std::string socTmp = str.substr(pos+14,2);
|
||||
GlobalConfig::NR5GTemp = socTmp;
|
||||
print_info("NR5GTemp = %s\n",GlobalConfig::NR5GTemp.c_str());
|
||||
}
|
||||
break;
|
||||
case Event_ERROR:
|
||||
if (m_curState == CPIN && !strcmp(pData, "3")) {
|
||||
m_curState = CPIN;
|
||||
GlobalConfig::NetStatus = "\"LIMSRV\"";
|
||||
}
|
||||
if (m_curState == QNETDEVCTL) {
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
break;
|
||||
case Event_TEMP:
|
||||
str = std::string(pData);
|
||||
pos = str.find("soc-thermal");
|
||||
if (pos > 0) {
|
||||
std::string socTmp = str.substr(pos + 14, 2);
|
||||
GlobalConfig::NR5GTemp = socTmp;
|
||||
print_info("NR5GTemp = %s\n", GlobalConfig::NR5GTemp.c_str());
|
||||
}
|
||||
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
int Dial::recvData()
|
||||
{
|
||||
int Dial::recvData() {
|
||||
char szbuffer[200] = {0x00};
|
||||
int offSize = 0;
|
||||
int timeoutflag = 0;
|
||||
while (1) {
|
||||
char buff[1024] = {0x00};
|
||||
|
||||
char szbuffer[200]={0x00};
|
||||
int offSize = 0;
|
||||
int timeoutflag = 0;
|
||||
while(1)
|
||||
{
|
||||
char buff[1024]={0x00};
|
||||
int ret = read_data(m_fd, buff, 1024, 10);
|
||||
if (ret <= 0) {
|
||||
timeoutflag++;
|
||||
if (timeoutflag > 5) {
|
||||
timeoutflag = 0;
|
||||
const char *strQENG = "+QENG: ";
|
||||
const char *strQNETDEVCTL = "+QNETDEVCTL: ";
|
||||
const char *strQICSGP = "+QICSGP: ";
|
||||
const char *strQNETDEVSTATUS = "+QNETDEVSTATUS: ";
|
||||
const char *strQCFG = "+QCFG: ";
|
||||
const char *strCPIN = "+CPIN: ";
|
||||
const char *strERROR = "+CME ERROR: ";
|
||||
const char *strQTEMP = "+QTEMP: ";
|
||||
const char *strOK = "OK";
|
||||
char data[128] = {0};
|
||||
char *pdata = strstr((char *)szbuffer, strQENG);
|
||||
if (pdata) {
|
||||
strncpy(data, pdata + 7, sizeof(data));
|
||||
print_purple("strQENG = %s\n", data);
|
||||
parseData(Event_QENG, data);
|
||||
}
|
||||
pdata = strstr((char *)szbuffer, strQNETDEVCTL);
|
||||
if (pdata) {
|
||||
strncpy(data, pdata + 13, sizeof(data));
|
||||
print_purple("strQNETDEVCTL = %s\n", data);
|
||||
parseData(Event_QNETDEVCTL, data);
|
||||
}
|
||||
pdata = strstr((char *)szbuffer, strQICSGP);
|
||||
if (pdata) {
|
||||
strncpy(data, pdata + 9, sizeof(data));
|
||||
print_purple("strQICSGP = %s\n", data);
|
||||
parseData(Event_QICSGPAPN, data);
|
||||
}
|
||||
pdata = strstr((char *)szbuffer, strQNETDEVSTATUS);
|
||||
if (pdata) {
|
||||
strncpy(data, pdata + 16, sizeof(data));
|
||||
print_purple("strQNETDEVSTATUS = %s\n", data);
|
||||
parseData(Event_QNETDEVSTATUS, data);
|
||||
}
|
||||
pdata = strstr((char *)szbuffer, strQCFG);
|
||||
if (pdata) {
|
||||
strncpy(data, pdata + 7, sizeof(data));
|
||||
print_purple("strQCFG = %s\n", data);
|
||||
parseData(Event_QCFGNET, data);
|
||||
}
|
||||
pdata = strstr((char *)szbuffer, strCPIN);
|
||||
if (pdata) {
|
||||
strncpy(data, pdata + 7, sizeof(data));
|
||||
print_purple("strCPIN = %s\n", data);
|
||||
parseData(Event_CPIN, data);
|
||||
}
|
||||
pdata = strstr((char *)szbuffer, strQTEMP);
|
||||
if (pdata) {
|
||||
strncpy(data, pdata + 8, sizeof(data));
|
||||
print_purple("strQTEMP = %s\n", data);
|
||||
parseData(Event_TEMP, data);
|
||||
}
|
||||
pdata = strstr((char *)szbuffer, strERROR);
|
||||
if (pdata) {
|
||||
strncpy(data, pdata + 12, sizeof(data));
|
||||
print_purple("strERROR = %s\n", data);
|
||||
parseData(Event_ERROR, data);
|
||||
}
|
||||
pdata = strstr((char *)szbuffer, strOK);
|
||||
if (pdata) {
|
||||
parseData(Event_OK, data);
|
||||
}
|
||||
memset(szbuffer, 0x00, sizeof(szbuffer));
|
||||
offSize = 0;
|
||||
}
|
||||
mssleep(100);
|
||||
} else if (ret > 0) {
|
||||
print_info("ret = %d,buff = %s\n", ret, buff);
|
||||
memcpy(szbuffer + offSize, buff, ret);
|
||||
offSize = offSize + ret;
|
||||
print_info("szbuffer = %s\n", szbuffer);
|
||||
continue;
|
||||
}
|
||||
mssleep(500000);
|
||||
}
|
||||
}
|
||||
|
||||
int ret = read_data(m_fd, buff, 1024, 10);
|
||||
if(ret <= 0){
|
||||
timeoutflag ++;
|
||||
if(timeoutflag > 5)
|
||||
{
|
||||
timeoutflag = 0;
|
||||
const char *strQENG = "+QENG: ";
|
||||
const char *strQNETDEVCTL = "+QNETDEVCTL: ";
|
||||
const char *strQICSGP = "+QICSGP: ";
|
||||
const char *strQNETDEVSTATUS= "+QNETDEVSTATUS: ";
|
||||
const char *strQCFG= "+QCFG: ";
|
||||
const char *strCPIN= "+CPIN: ";
|
||||
const char *strERROR= "+CME ERROR: ";
|
||||
const char *strQTEMP= "+QTEMP: ";
|
||||
const char *strOK= "OK";
|
||||
char data[128] = {0};
|
||||
char *pdata = strstr((char*)szbuffer, strQENG);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+7, sizeof(data));
|
||||
print_purple("strQENG = %s\n",data);
|
||||
parseData(Event_QENG,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQNETDEVCTL);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+13, sizeof(data));
|
||||
print_purple("strQNETDEVCTL = %s\n",data);
|
||||
parseData(Event_QNETDEVCTL,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQICSGP);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+9, sizeof(data));
|
||||
print_purple("strQICSGP = %s\n",data);
|
||||
parseData(Event_QICSGPAPN,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQNETDEVSTATUS);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+16, sizeof(data));
|
||||
print_purple("strQNETDEVSTATUS = %s\n",data);
|
||||
parseData(Event_QNETDEVSTATUS,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQCFG);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+7, sizeof(data));
|
||||
print_purple("strQCFG = %s\n",data);
|
||||
parseData(Event_QCFGNET,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strCPIN);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+7, sizeof(data));
|
||||
print_purple("strCPIN = %s\n",data);
|
||||
parseData(Event_CPIN,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQTEMP);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+8, sizeof(data));
|
||||
print_purple("strQTEMP = %s\n",data);
|
||||
parseData(Event_TEMP,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strERROR);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+12, sizeof(data));
|
||||
print_purple("strERROR = %s\n",data);
|
||||
parseData(Event_ERROR,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strOK);
|
||||
if(pdata){
|
||||
parseData(Event_OK,data);
|
||||
}
|
||||
memset(szbuffer,0x00,sizeof(szbuffer));
|
||||
offSize = 0;
|
||||
}
|
||||
mssleep(100);
|
||||
}else if(ret > 0){
|
||||
print_info("ret = %d,buff = %s\n",ret,buff);
|
||||
memcpy(szbuffer + offSize,buff,ret);
|
||||
offSize = offSize + ret;
|
||||
print_info("szbuffer = %s\n",szbuffer);
|
||||
continue;
|
||||
}
|
||||
mssleep(500000);
|
||||
}
|
||||
}
|
||||
int Dial::queryPin()
|
||||
{
|
||||
int iRet = write_data(m_fd,"AT+CPIN?\r\n",12);
|
||||
}
|
||||
int Dial::configNet()
|
||||
{
|
||||
write_data(m_fd,"AT+QCFG=\"NAT\"\r\n",19);
|
||||
}
|
||||
int Dial::configApn()
|
||||
{
|
||||
m_APN = 1;
|
||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||
char szCmd[100]={0x00};
|
||||
sprintf(szCmd,"AT+QICSGP=1,1,\"%s\",\"\",\"\",1\r\n",strAPN.c_str());
|
||||
int iRet = write_data(m_fd,szCmd,strlen(strAPN.c_str()) + 34);
|
||||
print_info("configApn = %d,data = %s\n",iRet,szCmd);
|
||||
}
|
||||
int Dial::getCsq()
|
||||
{
|
||||
write_data(m_fd,"AT+QENG=\"servingcell\"\r\n",27);
|
||||
}
|
||||
int Dial::getTemp()
|
||||
{
|
||||
write_data(m_fd,"AT+QTEMP\r\n",12);
|
||||
}
|
||||
int Dial::conncectUSB()
|
||||
{
|
||||
int iRet = write_data(m_fd,"AT+QNETDEVCTL=1,1,1\r\n",23);
|
||||
print_info("conncectUSB = %d\n",iRet);
|
||||
}
|
||||
int Dial::dial5G()
|
||||
{
|
||||
while(1){
|
||||
int Dial::queryPin() { int iRet = write_data(m_fd, "AT+CPIN?\r\n", 12); }
|
||||
|
||||
if(m_curState == CPIN){
|
||||
queryPin();
|
||||
}
|
||||
if(m_curState == QCFGNET){
|
||||
configNet();
|
||||
//configims();
|
||||
}
|
||||
if(m_curState == QICSGPAPN){
|
||||
configApn();
|
||||
}
|
||||
if(m_curState == QENG){
|
||||
getCsq();
|
||||
int Dial::configNet() { write_data(m_fd, "AT+QCFG=\"NAT\"\r\n", 19); }
|
||||
|
||||
}
|
||||
if(m_curState == QNETDEVCTL){
|
||||
conncectUSB();
|
||||
m_dial = 1;
|
||||
}
|
||||
if(m_curState == QNETDEVSTATUS){
|
||||
write_data(m_fd,"AT+QNETDEVSTATUS=1\r\n",22);
|
||||
}
|
||||
if(m_curState == QDCHPC){
|
||||
configdhcp();
|
||||
m_curState = QENG;
|
||||
}
|
||||
sleep(5);
|
||||
getTemp();
|
||||
sleep(15);
|
||||
}
|
||||
int Dial::configApn() {
|
||||
m_APN = 1;
|
||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||
char szCmd[100] = {0x00};
|
||||
sprintf(szCmd, "AT+QICSGP=1,1,\"%s\",\"\",\"\",1\r\n", strAPN.c_str());
|
||||
int iRet = write_data(m_fd, szCmd, strlen(strAPN.c_str()) + 34);
|
||||
print_info("configApn = %d,data = %s\n", iRet, szCmd);
|
||||
}
|
||||
int Dial::configims()
|
||||
{
|
||||
write_data(m_fd,"AT+QCFG=\"ims\",0\r\n",21);
|
||||
|
||||
int Dial::getCsq() { write_data(m_fd, "AT+QENG=\"servingcell\"\r\n", 27); }
|
||||
|
||||
int Dial::getTemp() { write_data(m_fd, "AT+QTEMP\r\n", 12); }
|
||||
|
||||
int Dial::conncectUSB() {
|
||||
int iRet = write_data(m_fd, "AT+QNETDEVCTL=1,1,1\r\n", 23);
|
||||
print_info("conncectUSB = %d\n", iRet);
|
||||
}
|
||||
int Dial::configdhcp()
|
||||
{
|
||||
system("busybox udhcpc -f -n -q -t 5 -i usb0");
|
||||
}
|
||||
int Dial::setState()
|
||||
{
|
||||
m_curState = CPIN;
|
||||
}
|
||||
int Dial::closePort()
|
||||
{
|
||||
close(m_fd);
|
||||
|
||||
int Dial::dial5G() {
|
||||
while (1) {
|
||||
if (m_curState == CPIN) {
|
||||
queryPin();
|
||||
} else if (m_curState == QCFGNET) {
|
||||
configNet();
|
||||
} else if (m_curState == QICSGPAPN) {
|
||||
configApn();
|
||||
} else if (m_curState == QENG) {
|
||||
getCsq();
|
||||
} else if (m_curState == QNETDEVCTL) {
|
||||
conncectUSB();
|
||||
m_dial = 1;
|
||||
} else if (m_curState == QNETDEVSTATUS) {
|
||||
write_data(m_fd, "AT+QNETDEVSTATUS=1\r\n", 22);
|
||||
} else if (m_curState == QDCHPC) {
|
||||
configdhcp();
|
||||
m_curState = QENG;
|
||||
} else {
|
||||
// TODO: show valid log info
|
||||
}
|
||||
sleep(5);
|
||||
getTemp();
|
||||
sleep(15);
|
||||
}
|
||||
}
|
||||
|
||||
int Dial::configims() { write_data(m_fd, "AT+QCFG=\"ims\",0\r\n", 21); }
|
||||
|
||||
int Dial::configdhcp() { system("busybox udhcpc -f -n -q -t 5 -i usb0"); }
|
||||
|
||||
int Dial::setState() { m_curState = CPIN; }
|
||||
|
||||
int Dial::closePort() { close(m_fd); }
|
||||
|
||||
@ -1,19 +1,31 @@
|
||||
#ifndef COMMUNICATION_CMD_HPP_
|
||||
#define COMMUNICATION_CMD_HPP_
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
#include <json/json.h>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include "../common/SH_global.h"
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
|
||||
#include "../datatransfer/SH_Datatrans.hpp"
|
||||
#include "common/parameter_defination.hpp"
|
||||
|
||||
class JsonData {
|
||||
public:
|
||||
// cmd "20"
|
||||
static const char *JSON_FIELD_CMD = "cmd"; //协议: 命令字段
|
||||
static const char *JSON_FIELD_NAME = "dataNodeGatewayName"; //协议: 终端名称
|
||||
static const char *JSON_FIELD_dataNodeGatewayNo = "dataNodeGatewayNo";
|
||||
static const char *JSON_FIELD_ASSETID = "dataNodeGatewayAssetId"; //协议: 资产编号 字段
|
||||
static const char *JSON_FIELD_ADDEDBY = "dataNodeGatewayAddedBy"; //协议: 添加人 字段
|
||||
static const char *JSON_FIELD_DEVICETYPE = "deviceType";
|
||||
static const char *JSON_FIELD_ADDEDDATE = "dataNodeGatewayAddedDate";
|
||||
static const char *JSON_FIELD_IPADDRESS = "dataNodeGatewayIpAddress";
|
||||
static const char *JSON_FIELD_SN = "serialNumber";
|
||||
static const char *JSON_FIELD_VERSION = "softVersion";
|
||||
static const char *JSON_FIELD_TIMEZONE = "timezone";
|
||||
|
||||
// cmd "23"
|
||||
static const char *JSON_FIELD_SERVERIP = "localServerIpAddress";
|
||||
static const char *JSON_FIELD_SERVERPORT = "localServerPort";
|
||||
static const char *JSON_FIELD_CommMode = "CommMode";
|
||||
|
||||
void DataNodeStatusCheck();
|
||||
// mqtt command
|
||||
std::string JsonCmd_07(); //获取系统内存温度硬盘等信息
|
||||
@ -72,39 +84,7 @@ public:
|
||||
std::string JsonCmd_Cgi_default();
|
||||
|
||||
private:
|
||||
Json::FastWriter showValue;
|
||||
Json::FastWriter show_value_;
|
||||
};
|
||||
|
||||
// cmd "20"
|
||||
static const char *JSON_FIELD_CMD = "cmd"; //协议: 命令字段
|
||||
static const char *JSON_FIELD_NAME = "dataNodeGatewayName"; //协议: 终端名称
|
||||
static const char *JSON_FIELD_dataNodeGatewayNo = "dataNodeGatewayNo";
|
||||
static const char *JSON_FIELD_ASSETID = "dataNodeGatewayAssetId"; //协议: 资产编号 字段
|
||||
static const char *JSON_FIELD_ADDEDBY = "dataNodeGatewayAddedBy"; //协议: 添加人 字段
|
||||
static const char *JSON_FIELD_DEVICETYPE = "deviceType";
|
||||
static const char *JSON_FIELD_ADDEDDATE = "dataNodeGatewayAddedDate";
|
||||
static const char *JSON_FIELD_IPADDRESS = "dataNodeGatewayIpAddress";
|
||||
static const char *JSON_FIELD_SN = "serialNumber";
|
||||
static const char *JSON_FIELD_VERSION = "softVersion";
|
||||
static const char *JSON_FIELD_TIMEZONE = "timezone";
|
||||
|
||||
// cmd "23"
|
||||
static const char *JSON_FIELD_SERVERIP = "localServerIpAddress";
|
||||
static const char *JSON_FIELD_SERVERPORT = "localServerPort";
|
||||
static const char *JSON_FIELD_CommMode = "CommMode";
|
||||
static const char *JSON_FIELD_SERVERSECOND = "writingPeriodLocalServer";
|
||||
|
||||
// cmd "24"
|
||||
static const char *JSON_FIELD_FILESERVERIP = "fileServerIpAddress";
|
||||
static const char *JSON_FIELD_FILESERVERPORT = "fileServerPort";
|
||||
|
||||
// cmd "26"
|
||||
static const char *JSON_FIELD_EMAILSERVERIP = "ServerIpAddress";
|
||||
static const char *JSON_FIELD_PORT = "ServerPort";
|
||||
static const char *JSON_FIELD_FILESERVERSECOND = "secondaryDataPath";
|
||||
|
||||
#define CMD_TYPE_20 20
|
||||
#define CMD_TYPE_21 21
|
||||
#define CMD_TYPE_22 22
|
||||
|
||||
#endif // COMMUNICATION_CMD_HPP_
|
||||
|
||||
@ -1,11 +1,7 @@
|
||||
#include "communication_cmd.hpp"
|
||||
#include "../dbaccess/SH_SqlDB.hpp"
|
||||
#include "../platform/SH_PlatformInit.hpp"
|
||||
#include "../MD5/md5.h"
|
||||
|
||||
namespace {
|
||||
PlatformInit *platform = PlatformInit::instance();
|
||||
}
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
#include "platform/platform_init.hpp"
|
||||
#include "MD5/md5.h"
|
||||
|
||||
std::string JsonData::JsonCmd_20(Param_20 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
@ -58,9 +54,9 @@ std::string JsonData::JsonCmd_20(Param_20 ¶m) {
|
||||
jsSystemInfo[JSON_FIELD_CommMode] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "CommMode").c_str());
|
||||
jsBody["SystemInfo"] = jsSystemInfo;
|
||||
|
||||
std::string dataBody = showValue.write(jsBody);
|
||||
std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_22(Param_22 ¶m) {
|
||||
@ -80,10 +76,10 @@ std::string JsonData::JsonCmd_22(Param_22 ¶m) {
|
||||
Json::Value jsBody;
|
||||
jsBody[JSON_FIELD_TIMEZONE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "timezone");
|
||||
|
||||
std::string dataBody = showValue.write(jsBody);
|
||||
std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_23(Param_23 ¶m) {
|
||||
@ -136,10 +132,10 @@ std::string JsonData::JsonCmd_23(Param_23 ¶m) {
|
||||
jsBody[JSON_FIELD_CommMode] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "CommMode").c_str());
|
||||
jsBody["Password"] = (ReadStrByOpt(SERVERCONFIG, "Server", "Password"));
|
||||
jsBody["UserName"] = (ReadStrByOpt(SERVERCONFIG, "Server", "UserName"));
|
||||
std::string dataBody = showValue.write(jsBody);
|
||||
std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_25(Param_25 ¶m) {
|
||||
@ -200,7 +196,7 @@ std::string JsonData::JsonCmd_25(Param_25 ¶m) {
|
||||
jsonVal["content"]["subnetMask"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "subnetMask");
|
||||
jsonVal["content"]["dataWatchIpAddress"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "ipAddress");
|
||||
jsonVal["content"]["hostName"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "hostName");
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_26(Param_26 ¶m) {
|
||||
@ -213,7 +209,7 @@ std::string JsonData::JsonCmd_26(Param_26 ¶m) {
|
||||
jsonVal["message"] = "查询成功";
|
||||
Json::Value jsArray;
|
||||
array_t arrRes;
|
||||
arrRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
int iResult = arrRes.size();
|
||||
if (iResult > 0) {
|
||||
for (int j = 0; j < iResult; j++) {
|
||||
@ -275,9 +271,9 @@ std::string JsonData::JsonCmd_26(Param_26 ¶m) {
|
||||
Json::Value jsBody;
|
||||
jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsBody["dataNodeArray"] = jsArray;
|
||||
std::string dataBody = showValue.write(jsBody);
|
||||
std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_27(Json::Value &recvBody) {
|
||||
@ -294,16 +290,16 @@ std::string JsonData::JsonCmd_27(Json::Value &recvBody) {
|
||||
for (int i = 0; i < nSize; i++) {
|
||||
char whereCon[128] = {0};
|
||||
sprintf(whereCon, "%s= '%s'", "MeasurementID", recvBody["dataNodeArray"][i].asString().c_str());
|
||||
sql_ctl->DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||||
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME), whereCon);
|
||||
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon);
|
||||
sql_ctl->DeleteTableData(T_DATANODE_TIME(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有传感器号";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_50(Json::Value &recvBody) {
|
||||
@ -326,11 +322,11 @@ std::string JsonData::JsonCmd_50(Json::Value &recvBody) {
|
||||
system(cmd);
|
||||
}
|
||||
sleep(2);
|
||||
int iRet = pDataTrans->dl_curl_post_req(updateURL, "", updateName);
|
||||
int iRet = data_trans::instance().dl_curl_post_req(updateURL, "", updateName);
|
||||
if (iRet != 0) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "download failed";
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
string md5Val = md5file(updateName.c_str());
|
||||
printf("md5Val = %s\n", md5Val.c_str());
|
||||
@ -338,7 +334,7 @@ std::string JsonData::JsonCmd_50(Json::Value &recvBody) {
|
||||
if (md5 != md5Val) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "download file check failed";
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
if (updateDevice == "1") { // update sensor
|
||||
string strcmd = "tar xvf ";
|
||||
@ -349,7 +345,7 @@ std::string JsonData::JsonCmd_50(Json::Value &recvBody) {
|
||||
sleep(3);
|
||||
system("/opt/opt.sh");
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_51(Json::Value &recvBody) {
|
||||
@ -363,12 +359,12 @@ std::string JsonData::JsonCmd_51(Json::Value &recvBody) {
|
||||
std::string DataNodeName = recvBody["dataNodeName"].asString();
|
||||
char szSql[100] = {0x00};
|
||||
sprintf(szSql, "update %s set dataNodeName = '%s' where MeasurementID = '%s' ", T_SENSOR_INFO(TNAME), DataNodeName.c_str(), DataNodeNo.c_str());
|
||||
int iRet = sql_ctl->UpdateTableData(szSql);
|
||||
int iRet = sqlite_db_ctrl::instance().UpdateTableData(szSql);
|
||||
if (iRet != 0) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "updata dataNodeName failed";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_52() {
|
||||
@ -380,7 +376,7 @@ std::string JsonData::JsonCmd_52() {
|
||||
std::string strTimeStamp = "";
|
||||
char selectCon[128] = {0};
|
||||
memcpy(selectCon, "sendMsg = '0'", sizeof(selectCon));
|
||||
int count = sql_ctl->GetTableRows(T_DATASTATIC_INFO(TNAME), selectCon);
|
||||
int count = sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), selectCon);
|
||||
if (count < 1) {
|
||||
return "";
|
||||
}
|
||||
@ -392,7 +388,7 @@ std::string JsonData::JsonCmd_52() {
|
||||
memcpy(whereCon, "sendMsg = '0' ORDER BY timeStamp DESC LIMIT 0,3", sizeof(whereCon));
|
||||
// 自数据库获取传感器特征数据
|
||||
array_t arrRes;
|
||||
arrRes = sql_ctl->GetDataMultiLine(T_DATA_INFO(TNAME), "*", whereCon);
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_DATA_INFO(TNAME), "*", whereCon);
|
||||
int iResult = arrRes.size();
|
||||
if (iResult > 0) {
|
||||
for (int j = 0; j < iResult; j++) {
|
||||
@ -422,7 +418,7 @@ std::string JsonData::JsonCmd_52() {
|
||||
|
||||
memset(selectCon, 0x00, sizeof(selectCon));
|
||||
sprintf(selectCon, "dataNodeNo='%s' and sendMsg = '0' ORDER BY timeStamp DESC LIMIT 0,1", strDataNodeNo.c_str());
|
||||
vec_t vecRes = sql_ctl->GetDataSingleLine(T_DATASTATIC_INFO(TNAME), "*", selectCon);
|
||||
vec_t vecRes = sqlite_db_ctrl::instance().GetDataSingleLine(T_DATASTATIC_INFO(TNAME), "*", selectCon);
|
||||
Json::Value jsStaticData;
|
||||
if (vecRes.size() > 0) {
|
||||
jsStaticData["TemperatureTop"] = atof(vecRes[2].c_str());
|
||||
@ -438,13 +434,13 @@ std::string JsonData::JsonCmd_52() {
|
||||
jsSensor.append(jsStaticData);
|
||||
|
||||
jsonVal["content"].append(jsSensor);
|
||||
std::string data = showValue.write(jsonVal);
|
||||
std::string data = show_value_.write(jsonVal);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "sendMsg = '0' and timeStamp = '%s'", strTimeStamp.c_str());
|
||||
int iRet = data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
if (iRet == 0) {
|
||||
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME), whereCon, 0);
|
||||
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon, 0);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATA_INFO(TNAME), whereCon, 0);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon, 0);
|
||||
}
|
||||
mssleep(100);
|
||||
}
|
||||
@ -465,7 +461,7 @@ std::string JsonData::JsonCmd_53(Json::Value &recvBody) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "update failed";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_29(Param_29 ¶m) {
|
||||
@ -476,7 +472,7 @@ std::string JsonData::JsonCmd_29(Param_29 ¶m) {
|
||||
jsonVal["cmd"] = "29";
|
||||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
array_t arrRes;
|
||||
arrRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
int iResult = arrRes.size();
|
||||
if (iResult > 0) {
|
||||
for (int i = 0; i < iResult; i++) {
|
||||
@ -487,9 +483,9 @@ std::string JsonData::JsonCmd_29(Param_29 ¶m) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string strBody = showValue.write(jsBody);
|
||||
std::string strBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = strBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
void JsonData::JsonCmd_38(Json::Value &recvBody) {
|
||||
@ -518,7 +514,7 @@ void JsonData::JsonCmd_38(Json::Value &recvBody) {
|
||||
}
|
||||
|
||||
void JsonData::DataNodeStatusCheck() {
|
||||
array_t vetRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
int nSize = vetRes.size();
|
||||
|
||||
char localtimestamp[32] = {0};
|
||||
@ -537,7 +533,7 @@ void JsonData::DataNodeStatusCheck() {
|
||||
char whereCon[512] = {0x00}, tablename[128] = {0x00};
|
||||
sprintf(whereCon, "dataNodeNo='%s' and channelID='%s' ORDER BY timeStamp DESC LIMIT 0,1", strDataNodeNo.c_str(), strChannelId.c_str());
|
||||
sprintf(tablename, "t_data_%s", strDataNodeNo.c_str());
|
||||
std::string strTimeRes = sql_ctl->GetData(tablename, "timeStamp", whereCon);
|
||||
std::string strTimeRes = sqlite_db_ctrl::instance().GetData(tablename, "timeStamp", whereCon);
|
||||
if (strTimeRes.length() > 0) {
|
||||
int llastTime = atoi(strTimeRes.c_str());
|
||||
int lTimeTemp = lNowTime - llastTime;
|
||||
@ -546,11 +542,11 @@ void JsonData::DataNodeStatusCheck() {
|
||||
LOG_DEBUG("offline DataNodeStatusCheck lNowTime = %d,llastTime = %d,interval = %s\n", lNowTime, llastTime, vetRes[i][21].c_str());
|
||||
char whereCon[32] = {0};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), "status='0'", whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), "status='0'", whereCon);
|
||||
} else {
|
||||
char whereCon[32] = {0};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), "status='1'", whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), "status='1'", whereCon);
|
||||
}
|
||||
if (lTimeTemp > atoi(vetRes[i][21].c_str()) * 5 * 60) //判定传感器是否超过五次未传特征值
|
||||
{
|
||||
@ -584,5 +580,5 @@ std::string JsonData::JsonCmd_07() {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "状态获取失败";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
@ -1,13 +1,7 @@
|
||||
#include "communication_cmd.hpp"
|
||||
#include "../dbaccess/SH_SqlDB.hpp"
|
||||
#include "../platform/SH_PlatformInit.hpp"
|
||||
#include "../MD5/md5.h"
|
||||
|
||||
namespace {
|
||||
PlatformInit *platform = PlatformInit::instance();
|
||||
Calculation *pCalculation = Calculation::instance();
|
||||
Uart *pUart = Uart::instance();
|
||||
}
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
#include "platform/platform_init.hpp"
|
||||
#include "MD5/md5.h"
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_01(Param_01 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
@ -52,7 +46,7 @@ std::string JsonData::JsonCmd_Cgi_01(Param_01 ¶m) {
|
||||
jsonVal["success"] = success;
|
||||
jsonVal["message"] = message;
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_02(Param_02 ¶m) {
|
||||
@ -83,7 +77,7 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 ¶m) {
|
||||
jsonVal["type"] = "GET";
|
||||
jsonVal["timeStamp"] = atoi(nowTimetamp.c_str());
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_07() {
|
||||
@ -104,7 +98,7 @@ std::string JsonData::JsonCmd_Cgi_07() {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "状态获取失败";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_07() {
|
||||
Json::Value jsonVal;
|
||||
@ -124,7 +118,7 @@ std::string JsonData::JsonCmd_07() {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "状态获取失败";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_08() {
|
||||
Json::Value jsonVal;
|
||||
@ -138,7 +132,7 @@ std::string JsonData::JsonCmd_Cgi_08() {
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||
@ -156,7 +150,7 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||
char looseValue[10] = {0x00};
|
||||
readStringValue("config", "loose", looseValue, (char *)GlobalConfig::Config_G.c_str());
|
||||
|
||||
array_t arrResAll = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo,MeasurementID ", NULL);
|
||||
array_t arrResAll = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo,MeasurementID ", NULL);
|
||||
int nSize = arrResAll.size();
|
||||
if (nSize > 0) {
|
||||
int packgeNo = param.mPackageFlag;
|
||||
@ -193,7 +187,7 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||
sprintf(whereCon, "channelID like '%%%s%%' ORDER BY timeStamp DESC LIMIT 0,3", strMeasurementID.c_str());
|
||||
// 自数据库获取传感器特征数据
|
||||
array_t arrRes;
|
||||
arrRes = sql_ctl->GetDataMultiLineTransaction(T_DATA_INFO(TNAME), "*", whereCon);
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_DATA_INFO(TNAME), "*", whereCon);
|
||||
int iResult = arrRes.size();
|
||||
if (iResult > 0) {
|
||||
for (int j = 0; j < iResult; j++) {
|
||||
@ -228,7 +222,7 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||
ON %s.channelID like '%%%s%%' ",
|
||||
T_DATASTATIC_INFO(TNAME), T_DATASTATIC_INFO(TNAME), strMeasurementID.c_str());
|
||||
|
||||
vec_t vecRes = sql_ctl->GetDataSingleLine(tablename, column, selectCon);
|
||||
vec_t vecRes = sqlite_db_ctrl::instance().GetDataSingleLine(tablename, column, selectCon);
|
||||
Json::Value jsStaticData;
|
||||
if (vecRes.size() > 0) {
|
||||
jsStaticData["TemperatureTop"] = atof(vecRes[2].c_str());
|
||||
@ -267,7 +261,7 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
// LOG_INFO("09 end\n");
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
@ -276,7 +270,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
||||
jsonVal[JSON_FIELD_CMD] = "10";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
vec_t vetRes = sql_ctl->GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), T_SENSOR_INFO(DATANODENO), NULL);
|
||||
vec_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), T_SENSOR_INFO(DATANODENO), NULL);
|
||||
int nSize = vetRes.size();
|
||||
if (nSize > 0) {
|
||||
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
|
||||
@ -295,7 +289,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
||||
sprintf(whereCon, " channelID like '%%%s%%' and %s <> '' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.strStatic.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
}
|
||||
|
||||
int rows = sql_ctl->GetTableRows(szTableName, whereCon);
|
||||
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
int packgeNo = param.mPackageFlag;
|
||||
int packgeMax = 0;
|
||||
int packgeNum = 0;
|
||||
@ -331,7 +325,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
||||
}
|
||||
array_t vecRes;
|
||||
|
||||
vecRes = sql_ctl->GetDataMultiLine(szTableName, selectCon, whereCon);
|
||||
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
|
||||
print_info("vecRes = %d\n", vecRes.size());
|
||||
if (vecRes.size() > 0) {
|
||||
Json::Value jsStaticData;
|
||||
@ -374,7 +368,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_11(Param_11 ¶m) {
|
||||
@ -389,7 +383,7 @@ std::string JsonData::JsonCmd_Cgi_11(Param_11 ¶m) {
|
||||
sprintf(whereCon, "dataNodeNo='%s' ORDER BY timeStamp DESC LIMIT 0,3", param.DataNodeNo.c_str());
|
||||
// 自数据库获取传感器特征数据
|
||||
array_t arrRes;
|
||||
arrRes = sql_ctl->GetDataMultiLineTransaction(T_DATA_INFO(TNAME), "*", whereCon);
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_DATA_INFO(TNAME), "*", whereCon);
|
||||
int iResult = arrRes.size();
|
||||
print_info("iResult = %d\n", iResult);
|
||||
if (iResult > 0) {
|
||||
@ -419,7 +413,7 @@ std::string JsonData::JsonCmd_Cgi_11(Param_11 ¶m) {
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
jsonVal["content"] = jsSensor;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_20(Param_20 ¶m) {
|
||||
@ -497,9 +491,9 @@ std::string JsonData::JsonCmd_Cgi_20(Param_20 ¶m) {
|
||||
|
||||
jsBody["SystemInfo"] = jsSystemInfo;
|
||||
|
||||
// std::string dataBody = showValue.write(jsBody);
|
||||
// std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_22(Param_22 ¶m) {
|
||||
@ -523,7 +517,7 @@ std::string JsonData::JsonCmd_Cgi_22(Param_22 ¶m) {
|
||||
|
||||
jsonVal["content"] = jsBody;
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_23(Param_23 ¶m) {
|
||||
@ -564,7 +558,7 @@ std::string JsonData::JsonCmd_Cgi_23(Param_23 ¶m) {
|
||||
jsBody["SystemSettings"] = jsSystemSetting;
|
||||
jsonVal["content"] = jsBody;
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) {
|
||||
@ -641,5 +635,5 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) {
|
||||
jsonVal["content"]["eth1"] = jsonValnet;
|
||||
jsonVal["content"]["gatewaytype"] = 1;
|
||||
#endif
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
@ -1,13 +1,8 @@
|
||||
#include "communication_cmd.hpp"
|
||||
#include "../dbaccess/SH_SqlDB.hpp"
|
||||
#include "../platform/SH_PlatformInit.hpp"
|
||||
#include "../MD5/md5.h"
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
#include "platform/platform_init.hpp"
|
||||
#include "MD5/md5.h"
|
||||
|
||||
namespace {
|
||||
PlatformInit *platform = PlatformInit::instance();
|
||||
Calculation *pCalculation = Calculation::instance();
|
||||
Uart *pUart = Uart::instance();
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
||||
// LOG_INFO("26 start\n");
|
||||
@ -24,7 +19,7 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
||||
// print_debug("loose = %f \n",atof(looseValue));
|
||||
Json::Value jsArray;
|
||||
array_t arrRes;
|
||||
arrRes = sql_ctl->GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
int iResult = arrRes.size();
|
||||
if (iResult > 0) {
|
||||
int packgeNo = param.mPackageFlag;
|
||||
@ -125,7 +120,7 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
||||
jsonVal["gatewayMac"] = GlobalConfig::MacAddr_G;
|
||||
jsonVal["gatewayIP"] = GlobalConfig::IpAddr_G;
|
||||
jsonVal["content"]["dataNodeArray"] = jsArray;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_54(Param_54 ¶m) {
|
||||
@ -139,7 +134,7 @@ std::string JsonData::JsonCmd_Cgi_54(Param_54 ¶m) {
|
||||
|
||||
Json::Value jsArray, nodeArray, gatewayArray;
|
||||
array_t arrRes;
|
||||
arrRes = sql_ctl->GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
int iResult = arrRes.size();
|
||||
if (iResult > 0) {
|
||||
int packgeNo = param.mPackageFlag;
|
||||
@ -262,7 +257,7 @@ std::string JsonData::JsonCmd_Cgi_54(Param_54 ¶m) {
|
||||
jsonVal["gatewayIP"] = GlobalConfig::IpAddr_G;
|
||||
jsonVal["content"]["dataNodeArray"] = jsArray;
|
||||
jsonVal["content"]["gateWay"] = gatewayArray;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
@ -277,17 +272,17 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
char localtimestamp[32] = {0};
|
||||
if (param.mDataNodeNo.length() > 0 && param.mType == "DELETE") {
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str());
|
||||
sql_ctl->DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||||
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME), whereCon);
|
||||
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon);
|
||||
sql_ctl->DeleteTableData(T_DATANODE_TIME(TNAME), whereCon);
|
||||
sql_ctl->DeleteTableData(T_BATTERY_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||||
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);
|
||||
char szTableName[50] = {0x00};
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", param.mDataNodeNo.c_str());
|
||||
sql_ctl->CreateTable(szTableName, 0);
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName, 0);
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", param.mDataNodeNo.c_str());
|
||||
sql_ctl->CreateTable(szTableName, 0);
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName, 0);
|
||||
} else if (param.mDataNodeNo.length() > 0 && param.mType == "CORRECT") {
|
||||
char updateSql[1024] = {0};
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str());
|
||||
@ -295,12 +290,12 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
sprintf(updateSql, "LooseValue = '0,2,");
|
||||
string strUpdateSql = string(updateSql) + string(localtimestamp) + "' ";
|
||||
print_info("updateSql = %s\n", strUpdateSql.c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), strUpdateSql.c_str(), whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), strUpdateSql.c_str(), whereCon);
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有传感器号";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_28(Param_28 ¶m) {
|
||||
@ -317,12 +312,12 @@ std::string JsonData::JsonCmd_Cgi_28(Param_28 ¶m) {
|
||||
char whereCon[64] = {0};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||
sprintf(updateColumn, "dataNodeName='%s'", param.mDataNodeName.c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateColumn, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateColumn, whereCon);
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有传感器号";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
||||
@ -338,7 +333,7 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
||||
/* 新增代码 */
|
||||
char whereCon[64] = {};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
char localtimestamp[32] = {0};
|
||||
std::string strWaveData = "";
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
@ -416,7 +411,7 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
||||
jsBody["Data"] = strWaveData;
|
||||
jsBody["timestamp"] = string(localtimestamp);
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
||||
@ -441,7 +436,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
||||
/* 新增代码 */
|
||||
char whereCon[64] = {};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), ios::in | ios::binary);
|
||||
if (!inFile) {
|
||||
@ -572,7 +567,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
||||
jsBody["resolution"] = std::string(buf);
|
||||
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
@ -590,7 +585,7 @@ std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) {
|
||||
/* 新增代码 */
|
||||
char whereCon[64] = {};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
std::string strWaveData;
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
char localtimestamp[32] = {0};
|
||||
@ -737,7 +732,7 @@ std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) {
|
||||
jsBody["resolution"] = std::string(buf);
|
||||
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_41(std::vector<Param_41> ¶m, int isServer) {
|
||||
@ -774,12 +769,12 @@ std::string JsonData::JsonCmd_Cgi_41(std::vector<Param_41> ¶m, int isServer)
|
||||
else
|
||||
sprintf(whereCon, "MeasurementID ='%s'", param[i].mdataNodeNo.c_str());
|
||||
|
||||
int iRet = sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
if (iRet != 0) jsonVal["success"] = false;
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_42(Param_42 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
@ -829,7 +824,7 @@ std::string JsonData::JsonCmd_Cgi_42(Param_42 ¶m) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "文件名错误!";
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_31(Param_31 ¶m) {
|
||||
@ -850,7 +845,7 @@ std::string JsonData::JsonCmd_Cgi_31(Param_31 ¶m) {
|
||||
jsBody["status"] = "1";
|
||||
jsonVal["content"] = jsBody;
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_32(Param_32 ¶m) {
|
||||
@ -868,7 +863,7 @@ std::string JsonData::JsonCmd_Cgi_32(Param_32 ¶m) {
|
||||
jsBody["Data"] = strWaveData;
|
||||
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_43() {
|
||||
@ -876,5 +871,5 @@ std::string JsonData::JsonCmd_Cgi_43() {
|
||||
jsonVal.clear();
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
@ -1,13 +1,7 @@
|
||||
#include "communication_cmd.hpp"
|
||||
#include "../dbaccess/SH_SqlDB.hpp"
|
||||
#include "../platform/SH_PlatformInit.hpp"
|
||||
#include "../MD5/md5.h"
|
||||
|
||||
namespace {
|
||||
PlatformInit *platform = PlatformInit::instance();
|
||||
Calculation *pCalculation = Calculation::instance();
|
||||
Uart *pUart = Uart::instance();
|
||||
}
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
#include "platform/platform_init.hpp"
|
||||
#include "MD5/md5.h"
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_default() {
|
||||
Json::Value jsonVal;
|
||||
@ -15,7 +9,7 @@ std::string JsonData::JsonCmd_Cgi_default() {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "功能不支持";
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_45(Param_45 ¶m) {
|
||||
@ -40,7 +34,7 @@ std::string JsonData::JsonCmd_Cgi_45(Param_45 ¶m) {
|
||||
jsBody["cityListId"] = ReadStrByOpt(SYSTEMINFOFILE, "Area", "cityListId");
|
||||
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_46(Param_46 ¶m) {
|
||||
@ -59,10 +53,10 @@ std::string JsonData::JsonCmd_Cgi_46(Param_46 ¶m) {
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有升级包";
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_47(Param_47 ¶m) {
|
||||
@ -80,11 +74,12 @@ std::string JsonData::JsonCmd_Cgi_47(Param_47 ¶m) {
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有找到logo";
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_50() {
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
@ -109,7 +104,7 @@ std::string JsonData::JsonCmd_Cgi_50() {
|
||||
jsBody["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
||||
jsBody["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_51(Param_51 ¶m) {
|
||||
@ -127,17 +122,18 @@ std::string JsonData::JsonCmd_Cgi_51(Param_51 ¶m) {
|
||||
sprintf(updateSql, "gatewayLocation='%s'", param.strGateWayLocation.c_str());
|
||||
sprintf(whereCon, "gatewayMAC='%s'", param.strGateWayMAC.c_str());
|
||||
if (param.mMode == 0) {
|
||||
int iRet = sql_ctl->UpdateTableData(T_GATEWAY_INFO(TNAME), updateSql, whereCon);
|
||||
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_GATEWAY_INFO(TNAME), updateSql, whereCon);
|
||||
if (iRet != 0) jsonVal["success"] = false;
|
||||
} else {
|
||||
gatewayLocation = sql_ctl->GetData(T_GATEWAY_INFO(TNAME), "gatewayLocation", NULL);
|
||||
gatewayLocation = sqlite_db_ctrl::instance().GetData(T_GATEWAY_INFO(TNAME), "gatewayLocation", NULL);
|
||||
jsBody["gateWayLocation"] = gatewayLocation;
|
||||
}
|
||||
|
||||
jsonVal["content"] = jsBody;
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_52(Param_52 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
Json::Value jsBody;
|
||||
@ -202,7 +198,7 @@ std::string JsonData::JsonCmd_Cgi_52(Param_52 ¶m) {
|
||||
}
|
||||
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_53(std::vector<Param_53> ¶m) {
|
||||
@ -226,12 +222,12 @@ std::string JsonData::JsonCmd_Cgi_53(std::vector<Param_53> ¶m) {
|
||||
}
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param[i].mdataNodeNo.c_str());
|
||||
|
||||
int iRet = sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
if (iRet != 0) jsonVal["success"] = false;
|
||||
}
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
@ -248,7 +244,7 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
/* 新增代码 */
|
||||
char whereCon[64] = {};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
int SampleRate = 0;
|
||||
double resolution = 0.0;
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
@ -352,7 +348,7 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
jsBody["Data"] = strWaveData;
|
||||
jsBody["timestamp"] = string(localtimestamp);
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
||||
@ -378,7 +374,7 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
||||
/* 新增代码 */
|
||||
char whereCon[64] = {};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
int SampleRate = 0;
|
||||
double resolution = 0.0;
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
@ -513,7 +509,7 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
||||
jsBody["resolution"] = std::string(buf);
|
||||
|
||||
jsonVal["content"] = jsBody;
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_57(Param_57 ¶m) {
|
||||
@ -532,5 +528,5 @@ std::string JsonData::JsonCmd_Cgi_57(Param_57 ¶m) {
|
||||
jsBody["zigbeepowerEnable"] = zigbeepowerEnable;
|
||||
jsonVal["content"] = jsBody;
|
||||
|
||||
return showValue.write(jsonVal);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
@ -1,9 +1,7 @@
|
||||
#include "local_server.hpp"
|
||||
#include <json/json.h>
|
||||
|
||||
namespace {
|
||||
PlatformInit *platform = PlatformInit::instance();
|
||||
}
|
||||
#include "secure/secure.hpp"
|
||||
#include "jsonparse/communication_cmd.hpp"
|
||||
|
||||
LocalServer::LocalServer() {}
|
||||
|
||||
@ -18,7 +16,7 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
LOG_INFO("MQTT recv base64 %s\n", data_r.c_str());
|
||||
char *base64_data = new char[data_r.length()];
|
||||
memset(base64_data, 0, data_r.length());
|
||||
Secure::instance()->Base64Decode(data_r.c_str(), (unsigned char *)base64_data);
|
||||
secure::instance().Base64Decode(data_r.c_str(), (unsigned char *)base64_data);
|
||||
std::string pData = std::string(base64_data);
|
||||
delete[] base64_data;
|
||||
LOG_INFO("MQTT recv %s\n", pData.c_str());
|
||||
@ -184,7 +182,7 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
std::string data = jd.JsonCmd_Cgi_41(param41, 1);
|
||||
char whereCon[64] = {0};
|
||||
sprintf(whereCon, " UpdateFlag <> 1 ");
|
||||
std::string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
|
||||
} break;
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
#include "local_server.hpp"
|
||||
#include <json/json.h>
|
||||
|
||||
namespace {
|
||||
PlatformInit *platform = PlatformInit::instance();
|
||||
}
|
||||
|
||||
std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
try {
|
||||
@ -253,7 +250,7 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
std::string data = jd.JsonCmd_Cgi_41(param41);
|
||||
char whereCon[64] = {0};
|
||||
sprintf(whereCon, " UpdateFlag <> 1 ");
|
||||
std::string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
return data;
|
||||
} break;
|
||||
@ -322,7 +319,7 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
std::string data = jd.JsonCmd_Cgi_53(param53);
|
||||
char whereCon[64] = {0};
|
||||
sprintf(whereCon, "UpdateFlag <> 0 ");
|
||||
string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
return data;
|
||||
} break;
|
||||
|
||||
2
main.cpp
2
main.cpp
@ -47,7 +47,7 @@ int main(int argc, char *argv[])
|
||||
// 初始化平台配置文件
|
||||
platform->PlatFormInit();
|
||||
|
||||
sql_ctl->InintGateway();
|
||||
sqlite_db_ctrl::instance().InintGateway();
|
||||
|
||||
uart_inst::instance().InitZigbee();
|
||||
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||||
|
||||
@ -68,11 +68,11 @@ try{
|
||||
this->GPIOInit();
|
||||
|
||||
print_info("ServerIP : %s \n", GlobalConfig::ServerIP.c_str());
|
||||
std::string strMac = sql_ctl->GetData("t_gateway_info","gatewayMAC",NULL);
|
||||
std::string strMac = sqlite_db_ctrl::instance().GetData("t_gateway_info","gatewayMAC",NULL);
|
||||
if(strMac == "60294D208517"){
|
||||
char szUpdateSql[100]={0x00};
|
||||
sprintf(szUpdateSql,"gatewayMAC = '%s'",GlobalConfig::MacAddr_G.c_str());
|
||||
sql_ctl->UpdateTableData("t_gateway_info",szUpdateSql,NULL);
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info",szUpdateSql,NULL);
|
||||
}
|
||||
else if(strMac != GlobalConfig::MacAddr_G ){
|
||||
LOG_ERROR("MAC error strMac1 = %s,MacAddr_G1 = %s\n",strMac.c_str(),GlobalConfig::MacAddr_G.c_str());
|
||||
@ -85,11 +85,11 @@ try{
|
||||
//system("reboot");
|
||||
}
|
||||
#ifdef G2UL_GATEWAY
|
||||
std::string strMac2 = sql_ctl->GetData("t_gateway_info","MAC2",NULL);
|
||||
std::string strMac2 = sqlite_db_ctrl::instance().GetData("t_gateway_info","MAC2",NULL);
|
||||
if(strMac2 == "60294D208518"){
|
||||
char szUpdateSql[100]={0x00};
|
||||
sprintf(szUpdateSql,"MAC2 = '%s'",GlobalConfig::MacAddr_G2.c_str());
|
||||
sql_ctl->UpdateTableData("t_gateway_info",szUpdateSql,NULL);
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info",szUpdateSql,NULL);
|
||||
}
|
||||
else if(strMac2 != GlobalConfig::MacAddr_G2 ){
|
||||
LOG_ERROR("MAC error strMac2 = %s,MacAddr_G2 = %s\n",strMac2.c_str(),GlobalConfig::MacAddr_G2.c_str());
|
||||
@ -108,7 +108,7 @@ try{
|
||||
print_error("PlatFormInit exception happend.\n");
|
||||
std::string errorinfo = "系统初始化异常";
|
||||
}
|
||||
vec_t vecResult = sql_ctl->GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME)," zigbeeShortAddr ",NULL);
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME)," zigbeeShortAddr ",NULL);
|
||||
for (size_t i = 0; i < vecResult.size(); i++)
|
||||
{
|
||||
compressWaveChannel tempchannel;
|
||||
@ -196,15 +196,15 @@ int PlatformInit::ServerIpInit()
|
||||
|
||||
void PlatformInit::Sqlite3Init()
|
||||
{
|
||||
sql_ctl->OpenDB(GlobalConfig::DbName_G.c_str());
|
||||
sqlite_db_ctrl::instance().OpenDB(GlobalConfig::DbName_G.c_str());
|
||||
char szValue[10] = {0x00};
|
||||
int nType = readIntValue( "Update", "type",(char*)GlobalConfig::Config_G.c_str());
|
||||
if(nType== 1){
|
||||
sql_ctl->SqliteInitDel(GlobalConfig::DbName_G.c_str());
|
||||
sqlite_db_ctrl::instance().SqliteInitDel(GlobalConfig::DbName_G.c_str());
|
||||
writeIntValue("Update", "type",0,(char*)GlobalConfig::Config_G.c_str());
|
||||
}
|
||||
print_info("szValue = %d\n",nType);
|
||||
sql_ctl->SqliteInit(GlobalConfig::DbName_G.c_str());
|
||||
sqlite_db_ctrl::instance().SqliteInit(GlobalConfig::DbName_G.c_str());
|
||||
print_info("Sqlite3Init \n");
|
||||
}
|
||||
|
||||
|
||||
@ -1,15 +1,13 @@
|
||||
#ifndef _PLATFORMINIT_H_
|
||||
#define _PLATFORMINIT_H_
|
||||
#ifndef PLATFORM_INIT_HPP_
|
||||
#define PLATFORM_INIT_HPP_
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "../utility/SH_MySingleton.hpp"
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
|
||||
#include "common/common_func.hpp"
|
||||
|
||||
|
||||
|
||||
class PlatformInit : public MySingleton<PlatformInit>
|
||||
{
|
||||
class PlatformInit {
|
||||
public :
|
||||
PlatformInit();
|
||||
virtual ~PlatformInit();
|
||||
@ -18,43 +16,43 @@ public :
|
||||
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
||||
* @return void
|
||||
*/
|
||||
void PlatFormInit();
|
||||
static void PlatFormInit();
|
||||
|
||||
/**
|
||||
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
||||
* @return void
|
||||
*/
|
||||
void ConfigFileCheck();
|
||||
static void ConfigFileCheck();
|
||||
|
||||
/**
|
||||
* @brief 服务器IP初始化
|
||||
* @return void
|
||||
*/
|
||||
int ServerIpInit();
|
||||
static int ServerIpInit();
|
||||
|
||||
/**
|
||||
* @brief 设备信息重新校验
|
||||
* @return void
|
||||
*/
|
||||
void SystemInfoInit();
|
||||
static void SystemInfoInit();
|
||||
|
||||
/**
|
||||
* @brief cgi用户信息初始化
|
||||
* @return void
|
||||
*/
|
||||
void UserInit();
|
||||
static void UserInit();
|
||||
|
||||
/**
|
||||
* @brief 数据库初始化
|
||||
* @return void
|
||||
*/
|
||||
void Sqlite3Init();
|
||||
static void Sqlite3Init();
|
||||
/**
|
||||
*@eth0 初始化
|
||||
*/
|
||||
void EquipIpInit(std::string eth);
|
||||
static void EquipIpInit(std::string eth);
|
||||
|
||||
void GPIOInit();
|
||||
static void GPIOInit();
|
||||
private:
|
||||
|
||||
/**
|
||||
@ -65,4 +63,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // PLATFORM_INIT_HPP_
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
CPP_SRCS += \
|
||||
../searchdev/SH_SearchDev.cpp
|
||||
|
||||
CPP_DEPS += \
|
||||
./searchdev/SH_SearchDev.d
|
||||
|
||||
OBJS += \
|
||||
./searchdev/SH_SearchDev.o
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
searchdev/%.o: ../searchdev/%.cpp searchdev/subdir.mk
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross G++ Compiler'
|
||||
arm-linux-gnueabihf-g++ -std=c++0x -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
||||
clean: clean-searchdev
|
||||
|
||||
clean-searchdev:
|
||||
-$(RM) ./searchdev/SH_SearchDev.d ./searchdev/SH_SearchDev.o
|
||||
|
||||
.PHONY: clean-searchdev
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
CPP_SRCS += \
|
||||
../secure/SH_Secure.cpp
|
||||
|
||||
CPP_DEPS += \
|
||||
./secure/SH_Secure.d
|
||||
|
||||
OBJS += \
|
||||
./secure/SH_Secure.o
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
secure/%.o: ../secure/%.cpp secure/subdir.mk
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross G++ Compiler'
|
||||
arm-linux-gnueabihf-g++ -std=c++0x -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
||||
clean: clean-secure
|
||||
|
||||
clean-secure:
|
||||
-$(RM) ./secure/SH_Secure.d ./secure/SH_Secure.o
|
||||
|
||||
.PHONY: clean-secure
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
C_SRCS += \
|
||||
../serial/serial.c
|
||||
|
||||
C_DEPS += \
|
||||
./serial/serial.d
|
||||
|
||||
OBJS += \
|
||||
./serial/serial.o
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
serial/%.o: ../serial/%.c serial/subdir.mk
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross GCC Compiler'
|
||||
arm-linux-gnueabihf-gcc -O0 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
||||
clean: clean-serial
|
||||
|
||||
clean-serial:
|
||||
-$(RM) ./serial/serial.d ./serial/serial.o
|
||||
|
||||
.PHONY: clean-serial
|
||||
|
||||
@ -202,7 +202,7 @@ void CheckThread() {
|
||||
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());
|
||||
sql_ctl->CalculateData();
|
||||
sqlite_db_ctrl::instance().CalculateData();
|
||||
} else if (statistics == 1 && hour < 13) {
|
||||
writeIntValue("config", "statistics", 0, (char *)GlobalConfig::Config_G.c_str());
|
||||
}
|
||||
@ -218,13 +218,13 @@ void CheckThread() {
|
||||
std::string strJson = fw.write(jsHeart);
|
||||
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
||||
if (iRet == 0) {
|
||||
sql_ctl->QueryofflineData();
|
||||
sqlite_db_ctrl::instance().QueryofflineData();
|
||||
}
|
||||
}
|
||||
|
||||
if (600 == online_check) {
|
||||
online_check = 0;
|
||||
int Count = sql_ctl->GetTableRows(T_SENSOR_INFO(TNAME), NULL);
|
||||
int Count = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL);
|
||||
if (Count > 0) {
|
||||
JsonData jd;
|
||||
jd.DataNodeStatusCheck();
|
||||
@ -237,7 +237,7 @@ void CheckThread() {
|
||||
char selectCon[128] = {0};
|
||||
sprintf(selectCon, " sendMsg <> '' ORDER BY timeStamp DESC LIMIT 0,1");
|
||||
sleep(1);
|
||||
std::string strTime = sql_ctl->GetData(T_DATASTATIC_INFO(TNAME), "timeStamp", selectCon);
|
||||
std::string strTime = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), "timeStamp", selectCon);
|
||||
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
|
||||
LOG_INFO("online check = %d\n", lTime);
|
||||
if (lTime > 1800) {
|
||||
@ -248,13 +248,13 @@ void CheckThread() {
|
||||
if (7200 == Battery) {
|
||||
Battery = 0;
|
||||
LOG_INFO("Battery\n");
|
||||
sql_ctl->CalculateBattery();
|
||||
sqlite_db_ctrl::instance().CalculateBattery();
|
||||
}
|
||||
|
||||
if (3500 == loose_check) {
|
||||
LOG_INFO("loosecheck\n");
|
||||
loose_check = 0;
|
||||
sql_ctl->CalculateDip();
|
||||
sqlite_db_ctrl::instance().CalculateDip();
|
||||
}
|
||||
if (ModifyAddr == 3600) {
|
||||
LOG_INFO("ModifyAddr check\n");
|
||||
@ -333,7 +333,7 @@ void CheckThread() {
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
sprintf(whereCon, " timestamp < '%ld' ", atol(localtimestamp) - 2592000); //删除1个月前的数据
|
||||
#endif
|
||||
sql_ctl->DeleteTableData(" t_battery_history ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon);
|
||||
}
|
||||
#ifdef WIFI_MODULE
|
||||
if (wifi_reconnect_count == 600) { // 每 10分钟,重连WiFi网络
|
||||
|
||||
@ -436,22 +436,22 @@ void Uart::DealDataNodeName(const char *pData) {
|
||||
char gbkNodeName[128] = {0x00};
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd);
|
||||
print_info("whereCon = %s\n", whereCon);
|
||||
array_t vecRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon);
|
||||
array_t vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon);
|
||||
if (vecRes.size() > 1) {
|
||||
for (int i = 0; i < vecRes.size(); i++) {
|
||||
if (vecRes[i][1] != "") {
|
||||
char whereCon1[64] = {0};
|
||||
sprintf(whereCon1, " dataNodeNo='%s' ", vecRes[i][0].c_str());
|
||||
sql_ctl->DeleteTableData(T_SENSOR_INFO(TNAME), whereCon1);
|
||||
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME), whereCon1);
|
||||
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon1);
|
||||
sql_ctl->DeleteTableData(T_DATANODE_TIME(TNAME), whereCon1);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_INFO(TNAME), whereCon1);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATA_INFO(TNAME), whereCon1);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon1);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATANODE_TIME(TNAME), whereCon1);
|
||||
char szTableName[50] = {0x00};
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", vecRes[i][0].c_str());
|
||||
sql_ctl->CreateTable(szTableName, 0);
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName, 0);
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", vecRes[i][0].c_str());
|
||||
sql_ctl->CreateTable(szTableName, 0);
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -468,8 +468,8 @@ void Uart::DealDataNodeName(const char *pData) {
|
||||
print_info("NodeName = %s\n", NodeName);
|
||||
print_info("whereCon = %s\n", whereCon);
|
||||
sprintf(uplCon, "dataNodeName = '%s' , MeasurementID = '%s',NodeWaveSend = '%s'", gbkNodeName, MeasurementID, nodeWaveSend);
|
||||
iRet = sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), uplCon, whereCon, 0);
|
||||
string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), uplCon, whereCon, 0);
|
||||
string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
||||
iRet = data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
||||
|
||||
char whereCon[64] = {0};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", dataNodeInfo.ZigbeeLongAddr.c_str());
|
||||
if (sql_ctl->GetTableRows(T_SENSOR_INFO(TNAME), whereCon) > 0) {
|
||||
if (sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), whereCon) > 0) {
|
||||
char updateSql[1024] = {0};
|
||||
sprintf(updateSql, " initFlag = '%d',accFlag = '%d',zigbeeFlag = '%d',temTopFlag = '%d',temBotFlag = '%d',equipSta = '%d',\
|
||||
hardVersion = '%s',softVersion = '%s',bpNo = '%s',serialNo = '%s',firstPowerTime = '%s',WakeupTime = '%d',\
|
||||
@ -701,7 +701,7 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
||||
dataNodeInfo.ZigbeeChannel, dataNodeInfo.ZigbeeShortAddr.c_str(), dataNodeInfo.ZigbeeLongAddr.c_str(), dataNodeInfo.ZigbeeDesAddr.c_str(), dataNodeInfo.ZigbeePower, dataNodeInfo.ZigbeeRetry, dataNodeInfo.ZigbeeRetryGap, dataNodeInfo.ACCSampleTime, "1",
|
||||
dataNodeInfo.ConfigDate.c_str(), dataNodeInfo.VIntegralFilterFrequency, dataNodeInfo.RSSI);
|
||||
sprintf(whereCon, "dataNodeNo = '%s'", dataNodeInfo.ZigbeeLongAddr.c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
} else {
|
||||
char insertSql[1024] = {0};
|
||||
sprintf(insertSql, " '%s','%s','%d','%d','%d','%d','%d','%d',\
|
||||
@ -715,14 +715,14 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
||||
dataNodeInfo.StartBrands.c_str(), dataNodeInfo.StopBrands.c_str(), dataNodeInfo.FeatureInterVal, dataNodeInfo.WaveInterVal, dataNodeInfo.SamplingRate, "", dataNodeInfo.Range, dataNodeInfo.EnvelopeBandPass.c_str(), dataNodeInfo.FaultFrequency.c_str(),
|
||||
dataNodeInfo.ZigbeePanId.c_str(), dataNodeInfo.ZigbeeChannel, dataNodeInfo.ZigbeeShortAddr.c_str(), dataNodeInfo.ZigbeeLongAddr.c_str(), dataNodeInfo.ZigbeeDesAddr.c_str(), dataNodeInfo.ZigbeePower, dataNodeInfo.ZigbeeRetry, dataNodeInfo.ZigbeeRetryGap,
|
||||
dataNodeInfo.ACCSampleTime, "1", dataNodeInfo.ConfigDate.c_str(), dataNodeInfo.VIntegralFilterFrequency, dataNodeInfo.RSSI);
|
||||
sql_ctl->InsertData(T_SENSOR_INFO(TNAME), insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData(T_SENSOR_INFO(TNAME), insertSql);
|
||||
}
|
||||
char szTableName[50] = {0x00};
|
||||
sprintf(szTableName, "t_data_%s", dataNodeInfo.ZigbeeLongAddr.c_str());
|
||||
sql_ctl->Createtable(szTableName);
|
||||
sqlite_db_ctrl::instance().Createtable(szTableName);
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "t_dataStatic_%s", dataNodeInfo.ZigbeeLongAddr.c_str());
|
||||
sql_ctl->CreatedataStatictable(szTableName);
|
||||
sqlite_db_ctrl::instance().CreatedataStatictable(szTableName);
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
jsonVal["cmd"] = "26";
|
||||
@ -789,7 +789,7 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
||||
}
|
||||
|
||||
void Uart::ZigbeeParameterConfig() {
|
||||
std::string strPanId = sql_ctl->GetData("t_gateway_info", "zigbeePanID", NULL);
|
||||
std::string strPanId = sqlite_db_ctrl::instance().GetData("t_gateway_info", "zigbeePanID", NULL);
|
||||
{
|
||||
unsigned short shortAddr = 0x8888;
|
||||
WriteShortAddr2Zigbee(shortAddr);
|
||||
@ -988,7 +988,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
sprintf(buf, "%02x%02x", UartRecvBuf[i + 3] & 0xFF, UartRecvBuf[i + 4] & 0xFF); // Zigbee 本地地址 2 byte
|
||||
sprintf(updateSql, "UpdateFlag = UpdateFlag + 1");
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'", buf);
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
||||
bUpdateconfig = false;
|
||||
@ -1017,12 +1017,12 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
char updateSql[1024] = {0};
|
||||
char tableName[100] = {0x00};
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'", strShortAddr.c_str());
|
||||
vec_t vecDataNodeNo = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " dataNodeNo,RSSI ", whereCon);
|
||||
vec_t vecDataNodeNo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " dataNodeNo,RSSI ", whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(updateSql, "zigbeeSignalNode = '%02d' ", UartRecvBuf[i + 14] & 0xFF); // zigbeeRSSIType = 0 传感器获取网关信号强度
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char *)vecDataNodeNo[0].c_str(), strTimetamp.c_str());
|
||||
sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str());
|
||||
sql_ctl->UpdateTableData(tableName, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
|
||||
|
||||
vector<string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
|
||||
@ -1030,7 +1030,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), UartRecvBuf[i + 14] & 0xFF);
|
||||
// LOG_INFO(updateSql);
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1087,12 +1087,12 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
char tableName[100] = {0x00};
|
||||
bZigbeeSinal = false;
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'", m_strDestShortAddr.c_str());
|
||||
vec_t vecDataNodeNo = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " dataNodeNo,LooseValue,RSSI ", whereCon);
|
||||
vec_t vecDataNodeNo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " dataNodeNo,LooseValue,RSSI ", whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(updateSql, "zigbeeSignal = '%02d' ", UartRecvBuf[i + 6] & 0xFF); // zigbeeRSSIType = 1 网关获取传感器信号强度
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char *)vecDataNodeNo[0].c_str(), strTimetamp.c_str());
|
||||
sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str());
|
||||
sql_ctl->UpdateTableData(tableName, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
|
||||
Json::Value jsBody, jsonVal;
|
||||
Json::FastWriter showValue;
|
||||
char looseValue[10] = {0x00};
|
||||
@ -1111,7 +1111,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
sprintf(updateSql, "RSSI = '%02d,%s' ", UartRecvBuf[i + 6] & 0xFF, vParamRSSI[1].c_str());
|
||||
}
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
|
||||
jsonVal["cmd"] = "52";
|
||||
jsBody["timeStamp"] = strTimetamp;
|
||||
|
||||
@ -14,7 +14,7 @@ map<std::string, compressWaveChannel> g_mapCompress;
|
||||
void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, std::string &nowTimetamp) {
|
||||
char insertSql[1024] = {0};
|
||||
sprintf(insertSql, "'%s','%d','%f','%f','%f','%d','','','%s'", strLongAddr.c_str(), dataStatic.Dip, dataStatic.TemBot, dataStatic.nodeWorkTime, dataStatic.nodeSendTime, dataStatic.Voltage, nowTimetamp.c_str());
|
||||
sql_ctl->InsertData(T_BATTERY_INFO(TNAME), insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData(T_BATTERY_INFO(TNAME), insertSql);
|
||||
}
|
||||
|
||||
void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
@ -36,7 +36,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
char getLongAddr_sql[32] = {0};
|
||||
//根据数据包中的传感器的短地址获取数据库中长地址(MAC),在下面判断该传感器是否存在,如果不存在则把数据包丢弃
|
||||
sprintf(getLongAddr_sql, "zigbeeShortAddr='%s'", strShortAddr.c_str());
|
||||
vec_t vecResult = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " softVersion,dataNodeNo,MeasurementID,ProductNo ", getLongAddr_sql);
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " softVersion,dataNodeNo,MeasurementID,ProductNo ", getLongAddr_sql);
|
||||
|
||||
if (vecResult.size() < 1) {
|
||||
LOG_ERROR("device info not found %02x%02x\n", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
||||
@ -134,7 +134,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'", strShortAddr.c_str());
|
||||
sprintf(updateSql, " StaticTime = StaticTime + 1");
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
|
||||
if (vecResult[0] == "3.0" || vecResult[0] == "4.0") {
|
||||
@ -220,10 +220,10 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
|
||||
sprintf(whereCon, "StaticIndex = %d", staticIndex);
|
||||
int count = sql_ctl->GetTableRows(szTableNameStatic, whereCon); //避免重复数据
|
||||
int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据
|
||||
sprintf(szTableNameData, "t_data_%s", strLongAddr.c_str());
|
||||
|
||||
int count2 = sql_ctl->GetTableRows(szTableNameData, whereCon);
|
||||
int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon);
|
||||
if (count > 0 || count2 > 0) {
|
||||
char logInfo[20] = {0x00};
|
||||
sprintf(logInfo, "ShortAddr = %s,staticIndex = %d,staticData = %d, data = %d", strShortAddr.c_str(), staticIndex, count, count2);
|
||||
@ -236,39 +236,39 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
char sztmp[100] = {0x00};
|
||||
strTmp = "name = '" + std::string(szTableNameStatic) + "' and sql LIKE '%nodeResend%' ";
|
||||
|
||||
int row = sql_ctl->GetTableRows(" sqlite_master ", strTmp.c_str());
|
||||
int row = sqlite_db_ctrl::instance().GetTableRows(" sqlite_master ", strTmp.c_str());
|
||||
print_info("row1 = %d\n", row);
|
||||
if (row == 0) {
|
||||
memset(sztmp, 0x00, sizeof(sztmp));
|
||||
sprintf(sztmp, "ALTER TABLE %s ADD COLUMN 'nodeResend'", szTableNameStatic);
|
||||
sql_ctl->CreateTable(sztmp);
|
||||
sqlite_db_ctrl::instance().CreateTable(sztmp);
|
||||
}
|
||||
|
||||
strTmp = "name = '" + std::string(szTableNameData) + "' and sql LIKE '%nodeResend%' ";
|
||||
row = sql_ctl->GetTableRows(" sqlite_master ", strTmp.c_str());
|
||||
row = sqlite_db_ctrl::instance().GetTableRows(" sqlite_master ", strTmp.c_str());
|
||||
print_info("row2 = %d\n", row);
|
||||
if (row == 0) {
|
||||
memset(sztmp, 0x00, sizeof(sztmp));
|
||||
sprintf(sztmp, "ALTER TABLE %s ADD COLUMN 'nodeResend'", szTableNameData);
|
||||
sql_ctl->CreateTable(sztmp);
|
||||
sqlite_db_ctrl::instance().CreateTable(sztmp);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////更换电池判断
|
||||
sprintf(whereCon, " dataNodeNo = '%s' and StaticIndex > 0 order by StaticIndex desc LIMIT 0 , 1 ", strLongAddr.c_str());
|
||||
std::string strStaticIndex = sql_ctl->GetData(szTableNameStatic, "StaticIndex", whereCon);
|
||||
std::string strStaticIndex = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "StaticIndex", whereCon);
|
||||
if (atol(strStaticIndex.c_str()) - staticIndex > 100) {
|
||||
sql_ctl->Deletetable(szTableNameStatic);
|
||||
sql_ctl->Deletetable(szTableNameData);
|
||||
sqlite_db_ctrl::instance().Deletetable(szTableNameStatic);
|
||||
sqlite_db_ctrl::instance().Deletetable(szTableNameData);
|
||||
LOG_INFO("staticIndexNOW = %d,strStaticIndexLast = %s\n", staticIndex, strStaticIndex.c_str());
|
||||
}
|
||||
print_info("NowstaticIndex = %d,RecordStaticIndex = %d", staticIndex, atol(strStaticIndex.c_str()));
|
||||
if (staticIndex != atol(strStaticIndex.c_str() + 1) && strStaticIndex != "" && staticIndex < atol(strStaticIndex.c_str())) {
|
||||
sprintf(whereCon, "StaticIndex = %d order by StaticIndex desc LIMIT 0 , 1", atol(strStaticIndex.c_str()));
|
||||
vec_t vecResult = sql_ctl->GetDataSingleLine(szTableNameStatic, "timeStamp,StaticIndex", whereCon);
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(szTableNameStatic, "timeStamp,StaticIndex", whereCon);
|
||||
if (vecResult.size() > 0) {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str());
|
||||
string staticInterval = sql_ctl->GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon);
|
||||
string staticInterval = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon);
|
||||
long nNowTimetamp = atol(vecResult[0].c_str()) - (atol(staticInterval.c_str()) * (atol(vecResult[1].c_str()) - staticIndex)) * 60;
|
||||
char tmp[10] = {0x00};
|
||||
sprintf(tmp, "%ld", nNowTimetamp);
|
||||
@ -280,11 +280,11 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
// save dataStatic of 7 days
|
||||
char selectCon[128] = {0};
|
||||
sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", (strMeasurementID + "-S").c_str());
|
||||
std::string strTime = sql_ctl->GetData(szTableName, "timeStamp", selectCon);
|
||||
std::string strTime = sqlite_db_ctrl::instance().GetData(szTableName, "timeStamp", selectCon);
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str());
|
||||
int Count = sql_ctl->GetTableRows(szTableName, whereCon);
|
||||
int Count = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
if (Count == -1) {
|
||||
sql_ctl->CreatedataStatictable(szTableName);
|
||||
sqlite_db_ctrl::instance().CreatedataStatictable(szTableName);
|
||||
}
|
||||
print_info("strLongAddr = %s,strTime = %s\n", strLongAddr.c_str(), strTime.c_str());
|
||||
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
|
||||
@ -295,38 +295,38 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %d, nodeResend = %d,zigbeeSignal = '',zigbeeSignalNode = '',statisticType = '%d',timing = '%d' ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage,
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend, flag, timing);
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str());
|
||||
if (/*0 == sql_ctl->GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
|
||||
if (/*0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
|
||||
print_info("insert static data to sql\n");
|
||||
char insertSql[1024] = {0};
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%d,'%s','1',%d,'','%d','%d'", strLongAddr.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend, flag,
|
||||
timing);
|
||||
sql_ctl->InsertData(szTableName, insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||
|
||||
if (0 == sql_ctl->GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)) { // First Connect
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)) { // First Connect
|
||||
char insertSql[1024] = {0};
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%d,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||
sql_ctl->InsertData(T_DATASTATIC_INFO(TNAME), insertSql);
|
||||
sql_ctl->CalculateBattery();
|
||||
sqlite_db_ctrl::instance().InsertData(T_DATASTATIC_INFO(TNAME), insertSql);
|
||||
sqlite_db_ctrl::instance().CalculateBattery();
|
||||
} else {
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %d ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex);
|
||||
sql_ctl->UpdateTableData(T_DATASTATIC_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATASTATIC_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
} else {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-S").c_str(), strTime.c_str());
|
||||
print_info("update static data to sql\n");
|
||||
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str());
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %d ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex);
|
||||
sql_ctl->UpdateTableData(T_DATASTATIC_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATASTATIC_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "t_data_%s", strLongAddr.c_str());
|
||||
if (Count == -1) {
|
||||
sql_ctl->Createtable(szTableName);
|
||||
sqlite_db_ctrl::instance().Createtable(szTableName);
|
||||
}
|
||||
DataRecvDym dataDymX;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
@ -436,20 +436,20 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
memset(insertSql, 0x00, sizeof(insertSql));
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%d,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues,
|
||||
dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||
sql_ctl->InsertData(szTableName, insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||
|
||||
if (0 == sql_ctl->GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
sql_ctl->InsertData(T_DATA_INFO(TNAME), insertSql);
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
sqlite_db_ctrl::instance().InsertData(T_DATA_INFO(TNAME), insertSql);
|
||||
else
|
||||
sql_ctl->UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
} else {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-X").c_str(), strTime.c_str());
|
||||
|
||||
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-X").c_str());
|
||||
sql_ctl->UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
print_info("x:%s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s\n", strLongAddr.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk,
|
||||
dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, nowTimetamp.c_str());
|
||||
@ -574,24 +574,24 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %d,nodeResend = %d ",
|
||||
dataDymY.DiagnosisPk, dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues, dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4,
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend);
|
||||
if (/*0 == sql_ctl->GetTableRows(T_DATA_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
|
||||
if (/*0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
|
||||
char insertSql[1024] = {0};
|
||||
memset(insertSql, 0x00, sizeof(insertSql));
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%d,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-Y").c_str(), dataDymY.DiagnosisPk, dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues,
|
||||
dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||
sql_ctl->InsertData(szTableName, insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||
|
||||
if (0 == sql_ctl->GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
sql_ctl->InsertData(T_DATA_INFO(TNAME), insertSql);
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
sqlite_db_ctrl::instance().InsertData(T_DATA_INFO(TNAME), insertSql);
|
||||
else
|
||||
sql_ctl->UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
} else {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-Y").c_str(), strTime.c_str());
|
||||
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Y").c_str());
|
||||
sql_ctl->UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
print_info("y: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s\n", strLongAddr.c_str(), (strMeasurementID + "-Y").c_str(), dataDymY.DiagnosisPk,
|
||||
dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues, dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4, nowTimetamp.c_str());
|
||||
@ -735,31 +735,31 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %d,nodeResend = %d ",
|
||||
dataDymZ.DiagnosisPk, dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues, dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4,
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend);
|
||||
if (/*0 == sql_ctl->GetTableRows(T_DATA_INFO(TNAME), whereCon)*/ Count * 3 < SAVE_COUNT && (lTime < OneWeek || strTime.size() == 0)) {
|
||||
if (/*0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon)*/ Count * 3 < SAVE_COUNT && (lTime < OneWeek || strTime.size() == 0)) {
|
||||
char insertSql[1024] = {0};
|
||||
memset(insertSql, 0x00, sizeof(insertSql));
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%d,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-Z").c_str(), dataDymZ.DiagnosisPk, dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues,
|
||||
dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||
sql_ctl->InsertData(szTableName, insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||
|
||||
if (0 == sql_ctl->GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
sql_ctl->InsertData(T_DATA_INFO(TNAME), insertSql);
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
sqlite_db_ctrl::instance().InsertData(T_DATA_INFO(TNAME), insertSql);
|
||||
else
|
||||
sql_ctl->UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
} else {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-Z").c_str(), strTime.c_str());
|
||||
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Z").c_str());
|
||||
sql_ctl->UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
print_info("Z: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s\n", strLongAddr.c_str(), (strMeasurementID + "-Z").c_str(), dataDymZ.DiagnosisPk,
|
||||
dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues, dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4, nowTimetamp.c_str());
|
||||
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), "status='1'", whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), "status='1'", whereCon);
|
||||
|
||||
//无线传感器Z信息
|
||||
valNodeFeature["dataNodeNo"] = strMeasurementID;
|
||||
@ -784,7 +784,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
memset(whereCon, 0, 1024);
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str());
|
||||
|
||||
std::string strBattery = sql_ctl->GetData(T_SENSOR_INFO(TNAME), "batteryPower", whereCon);
|
||||
std::string strBattery = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "batteryPower", whereCon);
|
||||
vector<std::string> vBattery;
|
||||
vBattery.push_back("0");
|
||||
vBattery.push_back("0");
|
||||
@ -823,8 +823,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
memset(whereCon, 0, 64);
|
||||
sprintf(whereCon, "dataNodeNo = '%s' and TimeStamp = '%s'", strLongAddr.c_str(), nowTimetamp.c_str());
|
||||
memcpy(updateSql, "sendMsg='0'", sizeof(updateSql));
|
||||
sql_ctl->UpdateTableData(szTableNameStatic, updateSql, whereCon);
|
||||
sql_ctl->UpdateTableData(szTableNameData, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableNameStatic, updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableNameData, updateSql, whereCon);
|
||||
}
|
||||
//综上代码,把静态数据,x y z轴的特征值存放到sql数据库中(如果数据原来不存在,则插入新数据;如果存在,则更新数据)
|
||||
|
||||
@ -832,7 +832,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
|
||||
memset(selectCon, 0x00, sizeof(selectCon));
|
||||
sprintf(selectCon, "zigbeeSignal <> '' ORDER BY timeStamp desc LIMIT 0,1");
|
||||
strTime = sql_ctl->GetData(szTableNameStatic, "timeStamp", selectCon);
|
||||
strTime = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "timeStamp", selectCon);
|
||||
|
||||
if (flag == 1) {
|
||||
LOG_INFO("DealDataNodeFeature end %02x%02x\n", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
||||
@ -1017,7 +1017,7 @@ void Uart::DealWave() {
|
||||
if (wave_trans_) { //对每个传感器的每个通道进行遍历然后处理数据,例如:传感器1x轴的数据处理完后,再去处理y轴的。传感器1的所有数据处理完后,再处理传感器2的
|
||||
char getLongAddr_sql[32] = {0};
|
||||
sprintf(getLongAddr_sql, "zigbeeShortAddr='%s'", m_strDestShortAddr.c_str());
|
||||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", getLongAddr_sql);
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", getLongAddr_sql);
|
||||
strLongAddr = res[0];
|
||||
strMeasurementID = res[44];
|
||||
if (0 == strLongAddr.length()) {
|
||||
@ -1070,7 +1070,7 @@ void Uart::DealWave() {
|
||||
char updateSql[1024] = {0x00};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str());
|
||||
sprintf(updateSql, "WaveTime = WaveTime + 1");
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
wave_trans_ = false;
|
||||
}
|
||||
}
|
||||
@ -1175,21 +1175,21 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
||||
|
||||
char selectCon[128] = {0};
|
||||
sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", strChannelID.c_str());
|
||||
std::string strTime = sql_ctl->GetData("t_data_waveSend", "timeStamp", selectCon);
|
||||
std::string strTime = sqlite_db_ctrl::instance().GetData("t_data_waveSend", "timeStamp", selectCon);
|
||||
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
|
||||
int Count = sql_ctl->GetTableRows("t_data_waveSend", NULL);
|
||||
int Count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", NULL);
|
||||
std::string strFileName_Record = strFileName + "_" + nowTimetamp;
|
||||
if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
|
||||
char insertSql[128] = {0x00};
|
||||
sprintf(insertSql, "'%s','%s','%s',1,0", strChannelID.c_str(), strFileName_Record.c_str(), nowTimetamp.c_str());
|
||||
sql_ctl->InsertData("t_data_waveSend", insertSql);
|
||||
sqlite_db_ctrl::instance().InsertData("t_data_waveSend", insertSql);
|
||||
} else {
|
||||
char updateSql[128] = {0}, whereCon[128] = {0};
|
||||
sprintf(updateSql, "waveName='%s',timeStamp='%s'", strFileName_Record.c_str(), nowTimetamp.c_str());
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", strChannelID.c_str(), strTime.c_str());
|
||||
print_info("update static data to sql\n");
|
||||
sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
}
|
||||
//传感器发来的数据包中的表示设备信息的数据转化为json格式后,通过调用data_publish将数据传给mqttclient : Topic:wireless/cmd/60294D203717
|
||||
|
||||
@ -1199,12 +1199,12 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
||||
char updateSql[1024] = {0x00};
|
||||
char tmpWhere[128] = {0x00};
|
||||
sprintf(tmpWhere, "channelID = '%s' and sendMsg = 0 ", strChannelID.c_str());
|
||||
int count = sql_ctl->GetTableRows("t_data_waveSend", tmpWhere);
|
||||
int count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
|
||||
LOG_ERROR("save channlID %s dat count = %d\n", strChannelID.c_str(), count);
|
||||
if (count <= 12) {
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", strChannelID.c_str(), nowTimetamp.c_str());
|
||||
sprintf(updateSql, "SendMsg = 0 ");
|
||||
sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
LOG_ERROR("send failed,filename %s,iRet = %d\n", strFileName.c_str(), iRet);
|
||||
string strFileName_failed = strFileName + "_" + nowTimetamp;
|
||||
char tmpCmd[128] = {0x00};
|
||||
@ -1214,16 +1214,16 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
||||
memset(tmpWhere, 0x00, sizeof(tmpWhere));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(tmpWhere, " sendMsg = 0 and channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", strChannelID.c_str());
|
||||
vec_t vecRet = sql_ctl->GetDataSingleLine("t_data_waveSend", "*", tmpWhere);
|
||||
vec_t vecRet = sqlite_db_ctrl::instance().GetDataSingleLine("t_data_waveSend", "*", tmpWhere);
|
||||
memset(tmpWhere, 0x00, sizeof(tmpWhere));
|
||||
sprintf(tmpWhere, " sendMsg = 0 and timeStamp = '%s' and channelID = '%s' ", vecRet[2].c_str(), vecRet[0].c_str());
|
||||
sprintf(updateSql, "sendMsg = 3 ");
|
||||
int iRet = sql_ctl->UpdateTableData("t_data_waveSend", updateSql, tmpWhere);
|
||||
int iRet = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, tmpWhere);
|
||||
memset(tmpWhere, 0x00, sizeof(tmpWhere));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", strChannelID.c_str(), nowTimetamp.c_str());
|
||||
sprintf(updateSql, "sendMsg = 0");
|
||||
int iRet2 = sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
int iRet2 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
|
||||
string strFileName_failed = strFileName + "_" + nowTimetamp;
|
||||
char tmpCmd[128] = {0x00};
|
||||
@ -1233,7 +1233,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
||||
|
||||
memset(tmpWhere, 0x00, sizeof(tmpWhere));
|
||||
sprintf(tmpWhere, " channelID = '%s' and sendMsg = 0 ", strChannelID.c_str());
|
||||
int count = sql_ctl->GetTableRows("t_data_waveSend", tmpWhere);
|
||||
int count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
|
||||
|
||||
memset(tmpCmd, 0x00, sizeof(tmpCmd));
|
||||
sprintf(tmpCmd, "rm %s ", vecRet[1].c_str());
|
||||
@ -1249,12 +1249,12 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
||||
char updateSql[1024] = {0x00};
|
||||
char tmpWhere[128] = {0x00};
|
||||
sprintf(tmpWhere, "channelID = '%s' and save = 1 ", strChannelID.c_str());
|
||||
int count = sql_ctl->GetTableRows("t_data_waveSend", tmpWhere);
|
||||
int count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
|
||||
LOG_INFO("save channlID %s dat count = %d\n", strChannelID.c_str(), count);
|
||||
if (count <= 5) {
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", strChannelID.c_str(), nowTimetamp.c_str());
|
||||
sprintf(updateSql, "save = 1 ");
|
||||
sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
string strFileName_save = strFileName + "_" + nowTimetamp + "_save";
|
||||
char tmpCmd[128] = {0x00};
|
||||
sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_save.c_str());
|
||||
@ -1263,16 +1263,16 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
||||
memset(tmpWhere, 0x00, sizeof(tmpWhere));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(tmpWhere, " save = 1 and channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", strChannelID.c_str());
|
||||
vec_t vecRet = sql_ctl->GetDataSingleLine("t_data_waveSend", "*", tmpWhere);
|
||||
vec_t vecRet = sqlite_db_ctrl::instance().GetDataSingleLine("t_data_waveSend", "*", tmpWhere);
|
||||
memset(tmpWhere, 0x00, sizeof(tmpWhere));
|
||||
sprintf(tmpWhere, " save = 1 and timeStamp = '%s' and channelID = '%s' ", vecRet[2].c_str(), vecRet[0].c_str());
|
||||
sprintf(updateSql, "save = 0 ");
|
||||
int iRet = sql_ctl->UpdateTableData("t_data_waveSend", updateSql, tmpWhere);
|
||||
int iRet = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, tmpWhere);
|
||||
memset(tmpWhere, 0x00, sizeof(tmpWhere));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", strChannelID.c_str(), nowTimetamp.c_str());
|
||||
sprintf(updateSql, "save = 1");
|
||||
int iRet2 = sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
int iRet2 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
|
||||
string strFileName_save = strFileName + "_" + nowTimetamp + "_save";
|
||||
char tmpCmd[128] = {0x00};
|
||||
@ -1281,7 +1281,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
||||
|
||||
memset(tmpWhere, 0x00, sizeof(tmpWhere));
|
||||
sprintf(tmpWhere, " channelID = '%s' and save = 1 ", strChannelID.c_str());
|
||||
int count = sql_ctl->GetTableRows("t_data_waveSend", tmpWhere);
|
||||
int count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
|
||||
|
||||
memset(tmpCmd, 0x00, sizeof(tmpCmd));
|
||||
sprintf(tmpCmd, "rm %s ", (vecRet[1] + "_save").c_str());
|
||||
|
||||
@ -41,7 +41,7 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
|
||||
char selectsql[1024] = {0};
|
||||
sprintf(gethardVersion_sql, "zigbeeShortAddr='%02x%02x'", pDestShortAddr[0], pDestShortAddr[1]);
|
||||
sprintf(selectsql, "%s,%s", T_SENSOR_INFO(HARDVERSION), T_SENSOR_INFO(SOFTVERSION));
|
||||
vec_t vecResult = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), selectsql, gethardVersion_sql);
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), selectsql, gethardVersion_sql);
|
||||
if (vecResult.size() < 1) {
|
||||
return false;
|
||||
}
|
||||
@ -255,7 +255,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
|
||||
char selCon[100] = {0x00};
|
||||
sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", pDestShortAddr[0], pDestShortAddr[1]);
|
||||
|
||||
vec_t vecResultNode = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), "*", whereCon);
|
||||
vec_t vecResultNode = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), "*", whereCon);
|
||||
if (vecResultNode.size() <= 0) return -1;
|
||||
if (vecResultNode[41] == "0") {
|
||||
print_info("UpdateConfig\n");
|
||||
@ -274,7 +274,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
|
||||
vec_t vecResult;
|
||||
sprintf(selCon, "featureInterVal,waveInterVal,range,samplingRate,ACCSampleTime,startBrands,stopBrands,\
|
||||
envelopeBandPass,faultFrequency,timeStamp,viff,ZigbeePower,ZigbeeRetry,MeasurementID,NodeWaveSend");
|
||||
vecResult = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), selCon, whereCon);
|
||||
vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), selCon, whereCon);
|
||||
print_info("vecResult size = %d\n", vecResult.size());
|
||||
if (vecResult.size() < 1) {
|
||||
return -1;
|
||||
@ -439,7 +439,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
|
||||
unsigned short localAddr = 0x9999;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||
string strName = sql_ctl->GetData(T_SENSOR_INFO(TNAME), " dataNodeName ", whereCon);
|
||||
string strName = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeName ", whereCon);
|
||||
|
||||
unsigned char UpdateData[100] = {0x00};
|
||||
//帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte]
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
CPP_SRCS += \
|
||||
../udpqt/SH_UdpQt.cpp
|
||||
|
||||
CPP_DEPS += \
|
||||
./udpqt/SH_UdpQt.d
|
||||
|
||||
OBJS += \
|
||||
./udpqt/SH_UdpQt.o
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
udpqt/%.o: ../udpqt/%.cpp udpqt/subdir.mk
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: Cross G++ Compiler'
|
||||
arm-linux-gnueabihf-g++ -std=c++0x -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include -I/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
||||
clean: clean-udpqt
|
||||
|
||||
clean-udpqt:
|
||||
-$(RM) ./udpqt/SH_UdpQt.d ./udpqt/SH_UdpQt.o
|
||||
|
||||
.PHONY: clean-udpqt
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "Calculation.hpp"
|
||||
#include "calculation.hpp"
|
||||
|
||||
Calculation::Calculation() {}
|
||||
|
||||
@ -214,7 +214,7 @@ void Calculation::Hanning(std::vector<float> &vecData, std::vector<float> &vecHa
|
||||
if (N % 2 == 0) {
|
||||
half = N / 2;
|
||||
for (i = 0; i < half; i++) // CALC_HANNING Calculates Hanning window samples.
|
||||
w[i] = 0.5 * (1 - cos(2 * pi * (i + 1) / (N + 1)));
|
||||
w[i] = 0.5 * (1 - cos(2 * M_PI * (i + 1) / (N + 1)));
|
||||
|
||||
idx = half - 1;
|
||||
for (i = half; i < N; i++) {
|
||||
@ -224,7 +224,7 @@ void Calculation::Hanning(std::vector<float> &vecData, std::vector<float> &vecHa
|
||||
} else {
|
||||
half = (N + 1) / 2;
|
||||
for (i = 0; i < half; i++) // CALC_HANNING Calculates Hanning window samples.
|
||||
w[i] = 0.5 * (1 - cos(2 * pi * (i + 1) / (N + 1)));
|
||||
w[i] = 0.5 * (1 - cos(2 * M_PI * (i + 1) / (N + 1)));
|
||||
|
||||
idx = half - 2;
|
||||
for (i = half; i < N; i++) {
|
||||
@ -1,5 +1,4 @@
|
||||
#ifndef CALCULATION_HPP_
|
||||
|
||||
#define CALCULATION_HPP_
|
||||
|
||||
#include <vector>
|
||||
@ -10,8 +9,6 @@
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
#define pi 3.1415
|
||||
|
||||
typedef struct {
|
||||
float real, imag;
|
||||
} complex;
|
||||
@ -92,4 +89,4 @@ public:
|
||||
static void Integration(std::vector<float>& vecData, std::vector<float>& retData, double& resolution);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // CALCULATION_HPP_
|
||||
@ -1,16 +1,14 @@
|
||||
#ifndef _WL_SEARCHDEV_
|
||||
#define _WL_SEARCHDEV_
|
||||
#ifndef SEARCH_DEV_HPP_
|
||||
#define SEARCH_DEV_HPP_
|
||||
#include <boost/container/detail/singleton.hpp>
|
||||
#include <boost/asio/ip/udp.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <json/json.h>
|
||||
#include "../common/SH_global.h"
|
||||
#include "../utility/SH_MySingleton.hpp"
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
#include "common/global.hpp"
|
||||
#include "common/common_func.hpp"
|
||||
|
||||
using namespace boost::asio;
|
||||
// using boost::system::error_code;
|
||||
|
||||
class SearchDev : public MySingleton<SearchDev> {
|
||||
class SearchDev {
|
||||
public:
|
||||
SearchDev(boost::asio::io_service &ioservice);
|
||||
~SearchDev();
|
||||
@ -28,13 +26,14 @@ private:
|
||||
|
||||
private:
|
||||
enum { BUF_LENGTH = 128 };
|
||||
// io_service mIoSev;
|
||||
ip::udp::socket mSockRecv_1; //组播地址1
|
||||
ip::udp::endpoint mRecvEP1;
|
||||
ip::udp::endpoint mListenEP1;
|
||||
ip::udp::endpoint mSendEndpoint1; //组播发送端点
|
||||
boost::asio::ip::udp::socket mSockRecv_1; //组播地址1
|
||||
boost::asio::ip::udp::endpoint mRecvEP1;
|
||||
boost::asio::ip::udp::endpoint mListenEP1;
|
||||
boost::asio::ip::udp::endpoint mSendEndpoint1; //组播发送端点
|
||||
char mRecvBuf1[BUF_LENGTH];
|
||||
char mSendBuf1[BUF_LENGTH];
|
||||
};
|
||||
|
||||
#endif
|
||||
typedef boost::container::dtl::singleton_default<SearchDev> search_dev;
|
||||
|
||||
#endif // SEARCH_DEV_HPP_
|
||||
@ -1,7 +1,7 @@
|
||||
#ifndef _WL_SECUREAPI_H_
|
||||
#define _WL_SECUREAPI_H_
|
||||
#include <string>
|
||||
#include "../utility/SH_MySingleton.hpp"
|
||||
#include <boost/container/detail/singleton.hpp>
|
||||
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned long u_long;
|
||||
@ -10,7 +10,7 @@ typedef unsigned long u_long;
|
||||
* 所有的加密与解密都只针对一条指令
|
||||
*
|
||||
*************************/
|
||||
class Secure : public MySingleton<Secure> {
|
||||
class Secure {
|
||||
public:
|
||||
Secure();
|
||||
virtual ~Secure();
|
||||
@ -50,4 +50,6 @@ private:
|
||||
char result[33];
|
||||
};
|
||||
|
||||
typedef boost::container::dtl::singleton_default<Secure> secure;
|
||||
|
||||
#endif
|
||||
@ -46,8 +46,7 @@
|
||||
/*
|
||||
* convert baud_rate to speed_t
|
||||
*/
|
||||
static speed_t get_speed(unsigned int baud_rate)
|
||||
{
|
||||
static speed_t get_speed(unsigned int baud_rate) {
|
||||
switch (baud_rate) {
|
||||
case 0:
|
||||
return B0;
|
||||
@ -115,7 +114,6 @@ static speed_t get_speed(unsigned int baud_rate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set baud rate of serial port
|
||||
*
|
||||
@ -126,58 +124,30 @@ static speed_t get_speed(unsigned int baud_rate)
|
||||
* return negative error code if fail
|
||||
*/
|
||||
int serial_set_baud_rate(int file_descriptor, int baud_rate) {
|
||||
/* struct termios termio;
|
||||
speed_t speed;
|
||||
int fd = file_descriptor;
|
||||
|
||||
if ( fd < 0 ) {
|
||||
return SERIAL_INVALID_FILE;
|
||||
}
|
||||
|
||||
memset(&termio, 0, sizeof(termio));
|
||||
|
||||
//get old attribute
|
||||
if (tcgetattr(fd, &termio)) {
|
||||
return SERIAL_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
//calculate baud rate
|
||||
speed = get_speed(baud_rate);
|
||||
if (speed == 0) {
|
||||
return SERIAL_ERROR_BAUDRATE;
|
||||
}
|
||||
cfsetispeed(&termio, speed);
|
||||
cfsetospeed(&termio, speed);
|
||||
|
||||
// set baud rate
|
||||
if (tcsetattr(fd, TCSAFLUSH, &termio) < 0) {
|
||||
return SERIAL_ERROR_BAUDRATE;
|
||||
}*/
|
||||
int iFd = file_descriptor;
|
||||
int len,ret;
|
||||
struct termios opt;
|
||||
tcgetattr(iFd, &opt);
|
||||
cfsetispeed(&opt, B115200);
|
||||
cfsetospeed(&opt, B115200);
|
||||
if (tcgetattr(iFd, &opt)<0) {
|
||||
return -1;
|
||||
}
|
||||
opt.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
|
||||
opt.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
||||
opt.c_oflag &= ~(OPOST);
|
||||
opt.c_cflag &= ~(CSIZE | PARENB | CBAUD);
|
||||
opt.c_cflag |= (CS8 | B115200);
|
||||
opt.c_cc[VMIN] = 255;
|
||||
opt.c_cc[VTIME] = 5;
|
||||
if (tcsetattr(iFd, TCSANOW, &opt)<0) {
|
||||
return -1;
|
||||
}
|
||||
tcflush(iFd,TCIOFLUSH);
|
||||
int iFd = file_descriptor;
|
||||
int len,ret;
|
||||
struct termios opt;
|
||||
tcgetattr(iFd, &opt);
|
||||
cfsetispeed(&opt, B115200);
|
||||
cfsetospeed(&opt, B115200);
|
||||
if (tcgetattr(iFd, &opt)<0) {
|
||||
return -1;
|
||||
}
|
||||
opt.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
|
||||
opt.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
||||
opt.c_oflag &= ~(OPOST);
|
||||
opt.c_cflag &= ~(CSIZE | PARENB | CBAUD);
|
||||
opt.c_cflag |= (CS8 | B115200);
|
||||
opt.c_cc[VMIN] = 255;
|
||||
opt.c_cc[VTIME] = 5;
|
||||
if (tcsetattr(iFd, TCSANOW, &opt)<0) {
|
||||
return -1;
|
||||
}
|
||||
tcflush(iFd,TCIOFLUSH);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set serial attributes
|
||||
*
|
||||
@ -190,8 +160,7 @@ int serial_set_baud_rate(int file_descriptor, int baud_rate) {
|
||||
* @return 1 if success.
|
||||
* return negative error code if fail.
|
||||
*/
|
||||
int serial_set_attr(int file_descriptor, int data_bits, char parity, int stop_bits, int flow_ctrl)
|
||||
{
|
||||
int serial_set_attr(int file_descriptor, int data_bits, char parity, int stop_bits, int flow_ctrl) {
|
||||
struct termios termio;
|
||||
int fd = file_descriptor;
|
||||
|
||||
@ -278,7 +247,6 @@ int serial_set_attr(int file_descriptor, int data_bits, char parity, int stop_bi
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* open serial port
|
||||
*
|
||||
@ -329,8 +297,7 @@ int serial_open_file(char *device_filename, int baud_rate) {
|
||||
* @return 1 if success
|
||||
* return negative error code if fail
|
||||
*/
|
||||
int serial_set_timeout(int file_descriptor, int timeout)
|
||||
{
|
||||
int serial_set_timeout(int file_descriptor, int timeout) {
|
||||
int fd = file_descriptor;
|
||||
struct termios termio;
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
#include "TcpCgi.hpp"
|
||||
#include "tcp_cgi.hpp"
|
||||
|
||||
|
||||
namespace {
|
||||
LocalServer *cidwServer = LocalServer::instance();
|
||||
}
|
||||
|
||||
TcpCgi::TcpCgi() { print_light_green("TcpCgi Init\n"); }
|
||||
|
||||
@ -8,18 +8,16 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <json/json.h>
|
||||
#include <boost/array.hpp>
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
#include "../API_log/SH_log.h"
|
||||
#include "../utility/SH_MySingleton.hpp"
|
||||
#include "../common/SH_global.h"
|
||||
#include "../localserver/SH_LocalServer.hpp"
|
||||
#include "common/common_func.hpp"
|
||||
#include "common/global.hpp"
|
||||
#include "localserver/local_server.hpp"
|
||||
|
||||
class TcpCgi : public MySingleton<TcpCgi> {
|
||||
class TcpCgi {
|
||||
public:
|
||||
TcpCgi();
|
||||
~TcpCgi();
|
||||
|
||||
void startCgiServer();
|
||||
static void startCgiServer();
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -7,8 +7,7 @@
|
||||
#include <json/json.h>
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/container/detail/singleton.hpp>
|
||||
#include "../common/SH_global.h"
|
||||
|
||||
#include "common/global.hpp"
|
||||
|
||||
|
||||
#define MULTICAST_PORT_SEND 7302 //根据接收组播udp发送端口
|
||||
Loading…
x
Reference in New Issue
Block a user