fix build bug.

This commit is contained in:
pandx 2024-10-23 22:25:03 +08:00
parent 4ddc9e8285
commit 28d588728c
18 changed files with 220 additions and 195 deletions

View File

@ -1,6 +1,8 @@
#ifndef COMMON_FUNC_HPP_
#define COMMON_FUNC_HPP_
#include <string>
#include <vector>
// #include <stdio.h>
// #include <unistd.h>
// #include <sys/socket.h>
@ -282,12 +284,6 @@ typedef struct {
std::string softVersion;
} SystemInfo;
typedef struct {
int number;
std::string SensorEngineeringUnit;
float waveData[GENERAL_BUF_SIZE];
} WAVE_GENERAL;
typedef struct {
int zigAckrep;
int zigAckreset;

View File

@ -156,7 +156,8 @@ struct Param_41 {
int ZigbeePower;
int ZigbeeRetry;
std::string nodeWaveSend;
Param_41() : mdataNodeName(""), mdataNodeNo(""), mfeatureInterVal(0), mwaveInterVal(0), msamplingRate(0), mrange(0), mAccSampleTime(0), mstartBrands(""), mstopBrands(""), menvelopeBandPass(""), mviff(0), mfaultFrequency(""), mMeasurementID{""}, nodeWaveSend{""} {};
Param_41() : mdataNodeName(""), mdataNodeNo(""), mMeasurementID{""}, mfeatureInterVal(0), mwaveInterVal(0), msamplingRate(0), mrange(0),
mAccSampleTime(0), mstartBrands(""), mstopBrands(""), menvelopeBandPass(""), mviff(0), mfaultFrequency(""), nodeWaveSend{""} {};
};
struct Param_42 {

View File

@ -6,25 +6,26 @@
#include <json/json.h>
#include "common/parameter_defination.hpp"
// 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";
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

View File

@ -3,7 +3,7 @@
#include <iostream>
#include <string>
typedef enum MQTTCommand {
enum MQTTCommand {
kHWStatus = 7,
kRebootSystem = 10,
kTiming = 12,
@ -19,7 +19,7 @@ typedef enum MQTTCommand {
kModifyTransducerLoose = 53
};
typedef enum WebCommand {
enum WebCommand {
kLoginUpdateAccount = 1, // 登录与更新密码
kWebTiming = 2, // 校时
kWebHWStatus = 7, // 获取硬件状态

View File

@ -9,8 +9,10 @@
#include <dirent.h>
#include <map>
#include <zlog.h>
#include "mqttclient/mqtt_client.h"
#include "uart/uart.hpp"
#include "common/common_func.hpp"
#include "jsonparse/communication_cmd.hpp"
#include "wifi_5g/wpa_client.h"
extern zlog_category_t *zct;
@ -47,7 +49,6 @@ void CheckThread() {
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
zlog_error(zct, "[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !");
// 重新写入 0x8888
unsigned short shortAddr = 0x8888;
uart_inst::instance().modify_LocalAddr(0x8888);
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
// 延时1秒
@ -298,8 +299,8 @@ void CheckThread() {
logClean = 0;
DIR *dp; //创建一个指向root路径下每个文件的指针
struct dirent *dirp;
string root = "/opt/log/";
if ((dp = opendir(root.c_str())) == NULL) cout << "can't open" << root << endl;
std::string root = "/opt/log/";
if ((dp = opendir(root.c_str())) == NULL) zlog_error(zct, "can't open:[%s]", root.c_str());
while ((dirp = readdir(dp)) != NULL) {
if ((!strcmp(dirp->d_name, ".") || (!strcmp(dirp->d_name, "..")))) continue;
struct timeval curTime;
@ -316,7 +317,7 @@ void CheckThread() {
memcpy(todayDay, buffer + 8, 2);
memcpy(fileMonth, dirp->d_name + 5, 2);
memcpy(todayMonth, buffer + 5, 2);
string filename = root + string(dirp->d_name);
std::string filename = root + std::string(dirp->d_name);
if (atoi(fileMonth) == atoi(todayMonth) ? abs(atoi(todayDay) - atoi(fileDay)) > 15 : abs(abs(30 - (atoi(fileDay)) + atoi(todayDay))) > 15) {
zlog_info(zct, "filename = %s", filename.c_str());
remove(filename.c_str());

View File

@ -9,12 +9,19 @@
#include <dirent.h>
#include <boost/typeof/typeof.hpp>
#include <zlog.h>
#include <json/json.h>
#include "mqttclient/mqtt_client.h"
#include "uart/uart.hpp"
#include "common/common_func.hpp"
#include "wifi_5g/dial.h"
#include "wifi_5g/wpa_client.h"
#include "utility/tcp_cgi.hpp"
#include "utility/udp_scan.hpp"
#include "utility/search_dev.hpp"
#include "localserver/local_server.hpp"
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
static std::string serverPort;
static std::string uptime;
static long long connect_lost_time = 0; // ms
@ -24,9 +31,9 @@ Dial dial;
void StartCgiServer() {
zlog_info(zbt,"start deal cgi");
TcpCgi *tcpCgi = TcpCgi::instance();
while (1) {
tcpCgi->startCgiServer();
TcpCgi::startCgiServer();
sleep(10);
}
}
@ -41,7 +48,6 @@ void RunLED() {
}
void HeartRep() {
int count = 0;
while (1) {
Json::Value jsHeart;
Json::FastWriter fw;
@ -65,7 +71,6 @@ void HeartRep() {
GlobalConfig::serverStatus = 1;
} else {
GlobalConfig::serverStatus = 0;
count = 0;
gpio_set(GlobalConfig::GPIO_G.errorLed, 0);
}
sleep(10);
@ -330,8 +335,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result) {
}
void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result) {
int ret = 0;
ret = disconnect();
disconnect();
zlog_info(zct,"The MQTT connection lost\n");
char gwTime[32] = {0};
GetTimeNet(gwTime, 0);
@ -392,7 +396,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
if (message->payloadlen) {
std::string strtopic(message->topic);
zlog_info(zct,"strtopic : %s \n", strtopic.c_str());
cidwServer->HandleFromServer((const char *)message->payload, message->payloadlen, message->topic);
LocalServer::HandleFromServer((const char *)message->payload, message->payloadlen, message->topic);
if (ud->eol) {
}
} else {
@ -453,7 +457,7 @@ void SearchThread() {
while (GlobalConfig::QuitFlag_G) {
if (GlobalConfig::IpAddr_G.length() > 0 && 0 != GlobalConfig::IpAddr_G.compare("0.0.0.0")) {
zlog_info("%s\n", runinfo.c_str());
zlog_info(zct, "%s\n", runinfo.c_str());
boost::asio::io_service io_service;
SearchDev *searchDevObj = new SearchDev(io_service);
searchDevObj->MultiCastRecv();
@ -461,7 +465,7 @@ void SearchThread() {
delete searchDevObj;
}
sleep(5);
zlog_info(zct,"SearchThred restart.\n");
zlog_info(zct, "SearchThread restart.");
}
}
@ -478,26 +482,26 @@ void RecvUpdateFile() {
FILE *fp;
char buffer[1024];
size_t len = 0;
int write_len;
size_t write_len;
bzero(buffer, 1024);
fp = fopen("/tmp/upgrade.tar.gz", "w");
if (NULL == fp) {
zlog_info(zct,"File:\t Can Not Open To Write\n");
zlog_info(zct,"File:\t Can Not Open To Write");
exit(1);
}
while (len = socket.read_some(boost::asio::buffer(buffer), ec)) {
if (len < 0) {
zlog_info(zct,"Receive Data From Server Failed! \n");
zlog_info(zct,"Receive Data From Server Failed!");
break;
}
write_len = fwrite(buffer, sizeof(char), len, fp);
if (write_len < len) {
zlog_info("File:test Write Failed!\n");
zlog_info(zct, "File:test Write Failed!");
break;
}
bzero(buffer, 1024);
}
zlog_info(zct,"Receive File From Server Finished! \n");
zlog_info(zct, "Receive File From Server Finished!");
fclose(fp);
Json::Value jsData;
Json::FastWriter fw;

View File

@ -1,36 +1,36 @@
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <boost/thread/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/lexical_cast.hpp>
#include "common/global.hpp"
#include "common/common_func.hpp"
#include "mqttclient/mqtt_client.h"
#include "localserver/local_server.hpp"
#include "utility/search_dev.hpp"
#include "utility/tcp_cgi.hpp"
#include "utility/udp_qt.hpp"
// #include <signal.h>
// #include <sys/ioctl.h>
// #include <sys/socket.h>
// #include <unistd.h>
// #include <fstream>
// #include <iostream>
// #include <boost/thread/thread.hpp>
// #include <boost/date_time/posix_time/posix_time.hpp>
// #include <boost/lexical_cast.hpp>
// #include "common/global.hpp"
// #include "common/common_func.hpp"
// #include "mqttclient/mqtt_client.h"
// #include "localserver/local_server.hpp"
// #include "utility/search_dev.hpp"
// #include "utility/tcp_cgi.hpp"
// #include "utility/udp_scan.hpp"
/***********************************
*************线***********
************************************/
extern void CheckThread(); //循环检测线程
extern void StartMqttClient(); //启动mqtt服务
extern void SearchThread(); //组播功能, 提供发现设备功能
extern void RecvUpdateFile(); //更新升级包
extern void StartCgiServer(); //启动cgi处理服务端
extern void HeartRep();
extern void UartStart(); //
extern void TestUart();
extern void WatchDog();
extern void UartStartWave();
extern void StartUdpSys(); //组播通信
extern void GetCSQ();
extern void Dial5G();
extern void InitModule();
extern void RunLED();
void CheckThread(); //循环检测线程
void StartMqttClient(); //启动mqtt服务
void SearchThread(); //组播功能, 提供发现设备功能
void RecvUpdateFile(); //更新升级包
void StartCgiServer(); //启动cgi处理服务端
void HeartRep();
void UartStart(); //
void TestUart();
void WatchDog();
void UartStartWave();
void StartUdpSys(); //组播通信
void GetCSQ();
void Dial5G();
void InitModule();
void RunLED();

View File

@ -13,14 +13,21 @@
#include <boost/timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <zlog.h>
#include <json/json.h>
#include "mqttclient/mqtt_client.h"
#include "utility/serial.h"
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
extern std::map<std::string, compressWaveChannel> g_mapCompress;
int offSize = 0;
pTestRecvCallBack pTestRecv;
extern std::vector<RecvData> g_VecWaveDataX;
extern std::vector<RecvData> g_VecWaveDataY;
extern std::vector<RecvData> g_VecWaveDataZ;
int Uart::UartRecv(int fd, char srcshow, char *buffer) {
char buff[BUF_LENGTH];
int ret = 0;
@ -54,7 +61,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
zlog_info(zct,("wave end");
zlog_info(zct, "wave end");
}
mssleep(10000);
} else if (bUpdatePre || (bUpdateconfig && GlobalConfig::EnterZigBeeWaveTransmittingCnt_G > 15)) {
@ -124,7 +131,9 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
printf("\n");
FindRecvPackage(ret, buff, head);
}
#else if G2UL_GATEWAY
#endif
#ifdef G2UL_GATEWAY
memset(buff, 0x00, sizeof(buff));
ret = read_data(fd, buff, BUF_LENGTH, 50);
if (ret <= 0) {
@ -262,7 +271,7 @@ void Uart::ReadTestUart() {
}
iRet = ZigbeeTest();
} else if (!strcmp(buff, "1")) {
string IP = GetGwIp_("eth0");
std::string IP = GetGwIp_("eth0");
write_data(TestFd, (char *)IP.c_str(), IP.size());
IP = GetGwIp_("eth1");
write_data(TestFd, (char *)"|", 1);
@ -278,7 +287,6 @@ void Uart::ReadTestUart() {
}
int Uart::ZigbeeTest() {
char buff[BUF_LENGTH] = {0x00};
modify_Localchannel(22);
mssleep(100000);
@ -300,7 +308,7 @@ void Uart::WriteToUart(const char *strSend, int pLen) {
zlog_info(zct, "\nWrite To Uart End.");
}
int len = write_data(fd, (char *)strSend, pLen);
write_data(fd, (char *)strSend, pLen);
}
int Uart::ReadFromUart() {
@ -391,7 +399,7 @@ void Uart::DealRecvData(const char *pData) {
sprintf(shortAdd, "%02x%02x", pData[3] & 0xFF, pData[4] & 0xFF);
unsigned short ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF);
int flag = atoi(buf);
zlog_info(zct, "the data package type(1,2,3,4,5,6) is %s,%x", buf);
zlog_info(zct, "the data package type(1,2,3,4,5,6) is %s", buf);
switch (flag) {
case 1: { // 0x01:设备信息
@ -425,7 +433,6 @@ void Uart::DealDataNodeName(const char *pData) {
memcpy(shortAdd, &pData[3], 2);
char whereCon[64] = {0};
char uplCon[200] = {0x00};
int iRet = -1;
char nodeWaveSend[10] = {0x00};
UpdateWirelessNodeTime((unsigned char *)shortAdd, 1);
@ -441,7 +448,7 @@ void Uart::DealDataNodeName(const char *pData) {
zlog_info(zct, "whereCon = %s", 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++) {
for (size_t i = 0; i < vecRes.size(); i++) {
if (vecRes[i][1] != "") {
char whereCon1[64] = {0};
sprintf(whereCon1, " dataNodeNo='%s' ", vecRes[i][0].c_str());
@ -451,10 +458,10 @@ void Uart::DealDataNodeName(const char *pData) {
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());
sqlite_db_ctrl::instance().CreateTable(szTableName, 0);
sqlite_db_ctrl::instance().CreateTable(szTableName);
memset(szTableName, 0x00, sizeof(szTableName));
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", vecRes[i][0].c_str());
sqlite_db_ctrl::instance().CreateTable(szTableName, 0);
sqlite_db_ctrl::instance().CreateTable(szTableName);
}
}
}
@ -471,9 +478,9 @@ void Uart::DealDataNodeName(const char *pData) {
zlog_info(zct, "NodeName = %s", NodeName);
zlog_info(zct, "whereCon = %s", whereCon);
sprintf(uplCon, "dataNodeName = '%s' , MeasurementID = '%s',NodeWaveSend = '%s'", gbkNodeName, MeasurementID, nodeWaveSend);
iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), uplCon, whereCon, 0);
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), uplCon, whereCon);
std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
iRet = data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
}
void Uart::DealDataNodeInfo(const char *pData) {
@ -634,9 +641,9 @@ void Uart::DealDataNodeInfo(const char *pData) {
sprintf(buf, "%02x%02x", pRecvData->Data[55 + i * 4], pRecvData->Data[55 + i * 4 + 1]);
iTemp = (int)strtol(buf, NULL, 16);
if (0 == i) {
dataNodeInfo.StartBrands = to_string(iTemp);
dataNodeInfo.StartBrands = std::to_string(iTemp);
} else {
dataNodeInfo.StartBrands += ("," + to_string(iTemp));
dataNodeInfo.StartBrands += ("," + std::to_string(iTemp));
}
}
//使用了57 58 61 62 65 66 69 70 73 74
@ -645,21 +652,21 @@ void Uart::DealDataNodeInfo(const char *pData) {
sprintf(buf, "%02x%02x", pRecvData->Data[57 + j * 4], pRecvData->Data[57 + j * 4 + 1]);
iTemp = (int)strtol(buf, NULL, 16);
if (0 == j) {
dataNodeInfo.StopBrands = to_string(iTemp);
dataNodeInfo.StopBrands = std::to_string(iTemp);
} else {
dataNodeInfo.StopBrands += ("," + to_string(iTemp));
dataNodeInfo.StopBrands += ("," + std::to_string(iTemp));
}
}
memset(buf, 0, 32);
sprintf(buf, "%02x%02x", pRecvData->Data[75], pRecvData->Data[76]);
iTemp = (int)strtol(buf, NULL, 16);
dataNodeInfo.EnvelopeBandPass = to_string(iTemp);
dataNodeInfo.EnvelopeBandPass = std::to_string(iTemp);
memset(buf, 0, 32);
sprintf(buf, "%02x%02x", pRecvData->Data[77], pRecvData->Data[78]);
iTemp = (int)strtol(buf, NULL, 16);
dataNodeInfo.EnvelopeBandPass += ("," + to_string(iTemp));
dataNodeInfo.EnvelopeBandPass += ("," + std::to_string(iTemp));
//使用了79 80 81 82 83 84 85 86
for (int j = 0; j < 4; j++) {
memset(buf, 0, 32);
@ -667,16 +674,16 @@ void Uart::DealDataNodeInfo(const char *pData) {
iTemp = (int)strtol(buf, NULL, 16);
if (0 == j) {
dataNodeInfo.FaultFrequency = to_string(iTemp);
dataNodeInfo.FaultFrequency = std::to_string(iTemp);
} else {
dataNodeInfo.FaultFrequency += ("," + to_string(iTemp));
dataNodeInfo.FaultFrequency += ("," + std::to_string(iTemp));
}
}
memset(buf, 0, 32);
sprintf(buf, "%02x%02x%02x%02x", pRecvData->Data[87], pRecvData->Data[88], pRecvData->Data[89], pRecvData->Data[90]);
long lTimeStamp = strtol(buf, NULL, 16);
dataNodeInfo.ConfigDate = to_string(lTimeStamp);
dataNodeInfo.ConfigDate = std::to_string(lTimeStamp);
chTemp = pRecvData->Data[91];
memset(buf, 0, 32);
@ -799,7 +806,7 @@ void Uart::ZigbeeParameterConfig() {
std::string strchan = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "channel");
unsigned short Chan = (unsigned short)strtol(strchan.c_str(), NULL, 10);
zlog_info(zct, "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%the chan = %u", Chan);
zlog_info(zct, "the chan = %d", Chan);
zlog_info(zct, "ZigbeeInfo_G.Channel=%d", GlobalConfig::ZigbeeInfo_G.Channel);
if (Chan > 10 && Chan < 27) {
WriteChanl2Zigbee(Chan);
@ -860,7 +867,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
zlog_error(zct, "mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str());
mPackgeIndex = -1;
print_error("mPackgeIndex error ShortAddr :%s \n", strShortAddr.c_str());
zlog_error(zct, "mPackgeIndex error ShortAddr :%s", strShortAddr.c_str());
char tmp[10] = {0x00};
char tmp2[10] = {0x00};
@ -909,7 +916,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
m_TimeStamp = 0;
mPackgeIndex = -1;
zlog_info(zct, "CheckCrc error ShortAddr :%s command = %d", strShortAddr.c_str(), command);
print_error("CheckCrc error ShortAddr :%s \n", strShortAddr.c_str());
zlog_error(zct, "CheckCrc error ShortAddr :%s", strShortAddr.c_str());
char tmp[10] = {0x00};
char tmp2[10] = {0x00};
for (int j = 0; j < 100; j++) {
@ -1020,7 +1027,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str());
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
vector<string> vParamRSSI;
std::vector<std::string> vParamRSSI;
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
if (vParamRSSI.size() > 0) {
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), UartRecvBuf[i + 14] & 0xFF);
@ -1050,7 +1057,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
} else if (command == 220) { // DC
bModifyAddr = false;
zlog_info(zct, "zigbeeShortAddr = %s , ret = %02d", m_strDestShortAddr.c_str(), UartRecvBuf[i + 6] & 0xFF);
if (UartRecvBuf[i + 6] & 0xFF != 00) {
if ((UartRecvBuf[i + 6] & 0xFF) != 0) {
modify_LocalAddr(0x8888);
}
}
@ -1066,7 +1073,6 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
sprintf(buf, "%02d", UartRecvBuf[i + 3] & 0xFF);
int command = atoi(buf);
zlog_info(zct, "command = %d", command);
char tmp[16] = {0x00};
if (command == 209) { // D1
pTestRecv(command);
} else if (command == 219) { // DB
@ -1091,13 +1097,13 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
Json::Value jsBody, jsonVal;
Json::FastWriter showValue;
char looseValue[10] = {0x00};
readStringValue("config", "loose", looseValue, (char *)GlobalConfig::Config_G.c_str());
readStringValue("config", (char*)"loose", looseValue, GlobalConfig::Config_G.c_str());
if (atof(looseValue) < atof(vecDataNodeNo[1].c_str())) {
jsBody["looseStatus"] = "1";
} else {
jsBody["looseStatus"] = "0";
}
vector<string> vParamRSSI;
std::vector<std::string> vParamRSSI;
boost::split(vParamRSSI, vecDataNodeNo[2], boost::is_any_of(","), boost::token_compress_on);
if (vParamRSSI.size() == 1) {
sprintf(updateSql, "RSSI = '%02d,%s' ", UartRecvBuf[i + 6] & 0xFF, vParamRSSI[0].c_str());
@ -1119,4 +1125,5 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
}
}
}
return 0;
}

View File

@ -39,13 +39,13 @@ public:
// feature parse
void DealDataNodeFeature(const char* pData, int flag);
void RecordBattery(string& strLongAddr, DataRecvStatic& dataStatic, string& nowTimetamp);
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
void DealDataNodeWave(const char* pData, int comand);
void DealWaveThread();
void DealWave();
std::vector<float> DealData(int ichannel, float coe, int sampleRate, int ACCSampleTime, string strProduct);
float Calcoe(int ran, int iChannel, string& product, int range);
void WriteDatFile(int sampleRate, string& strMeasurementID, int iChannel, std::vector<float>& vecData);
std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct);
float Calcoe(int ran, int iChannel, std::string& product, int range);
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData);
float ScaleConvert(int highbit);
// command category
@ -92,7 +92,7 @@ private:
int mRdLength;
int mlastSize;
int mPackgeIndex;
string strTimetamp;
std::string strTimetamp;
std::string m_strDestShortAddr;

View File

@ -74,9 +74,8 @@ void Uart::modify_LocalPanID(unsigned short padID) {
}
void Uart::modify_info(unsigned short id, char *zigbee) {
int i, j, ret, con;
int i, con;
char command[100];
char command1[20];
char tmp = 0;
command[0] = 0xab;
command[1] = 0xbc;
@ -100,7 +99,8 @@ void Uart::modify_info(unsigned short id, char *zigbee) {
}
void Uart::zigbee_reset(unsigned short pad, unsigned short type) {
char command[10], tmp = 0, i;
char command[10], tmp = 0;
int i = 0;
command[0] = 0xab;
command[1] = 0xbc;
command[2] = 0xcd;

View File

@ -5,7 +5,11 @@
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <boost/algorithm/string.hpp>
#include <zlog.h>
#include <json/json.h>
#include "mqttclient/mqtt_client.h"
#include "minilzo/minilzo.h"
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
@ -55,7 +59,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
if (!bSendTimeStamp) {
bSendTimeStamp = true;
modify_distaddr_info(0x9999, "", pRecvData->ShortAddr); //临时参数配置
modify_distaddr_info(0x9999, (char*)"", pRecvData->ShortAddr); //临时参数配置
mssleep(10000);
zlog_info(zct, "Zigbee Signal !\n");
@ -74,14 +78,14 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
GlobalConfig::ZigbeeInfo_G.MyAddr = "9999";
GlobalConfig::Zigbee_G.MyAddr = 0x9999;
string strTime = GetLocalTimeWithMs();
std::string strTime = GetLocalTimeWithMs();
m_strDestShortAddr = std::string(buf);
bool isUpdate = ReadUpdatePackge(pRecvData->ShortAddr);
bUpdatePre = isUpdate;
if (!isUpdate) {
int iRet = UpdateConfig(pRecvData->ShortAddr);
UpdateConfig(pRecvData->ShortAddr);
}
if (isUpdate || bUpdateconfig) {
} else {
@ -100,9 +104,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
tempchannel.CountY = BUILD_UINT16(pRecvData->Data[57], pRecvData->Data[56]);
tempchannel.CountZ = BUILD_UINT16(pRecvData->Data[59], pRecvData->Data[58]);
} else if (strProductNo == "02") {
int CountX = 0;
int CountY = 0;
int CountZ = 0;
unsigned char buffer[6] = {0x00};
memcpy(buffer, &pRecvData->Data[55], 1);
@ -212,14 +213,14 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
memcpy(szTableNameStatic, szTableName, sizeof(szTableNameStatic));
memset(whereCon, 0x00, sizeof(whereCon));
sprintf(whereCon, "StaticIndex = %d", staticIndex);
sprintf(whereCon, "StaticIndex = %ld", staticIndex);
int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据
sprintf(szTableNameData, "t_data_%s", strLongAddr.c_str());
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);
sprintf(logInfo, "ShortAddr = %s,staticIndex = %ld,staticData = %d, data = %d", strShortAddr.c_str(), staticIndex, count, count2);
zlog_info(zct, logInfo);
return;
}
@ -252,11 +253,11 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
if (atol(strStaticIndex.c_str()) - staticIndex > 100) {
sqlite_db_ctrl::instance().Deletetable(szTableNameStatic);
sqlite_db_ctrl::instance().Deletetable(szTableNameData);
zlog_info(zct, "staticIndexNOW = %d,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str());
zlog_info(zct, "staticIndexNOW = %ld,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str());
}
zlog_info(zct, "NowstaticIndex = %d,RecordStaticIndex = %d", staticIndex, atol(strStaticIndex.c_str()));
zlog_info(zct, "NowstaticIndex = %ld,RecordStaticIndex = %ld", 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()));
sprintf(whereCon, "StaticIndex = %ld order by StaticIndex desc LIMIT 0 , 1", atol(strStaticIndex.c_str()));
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(szTableNameStatic, "timeStamp,StaticIndex", whereCon);
if (vecResult.size() > 0) {
memset(whereCon, 0x00, sizeof(whereCon));
@ -281,28 +282,28 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
}
zlog_info(zct, "strLongAddr = %s,strTime = %s", strLongAddr.c_str(), strTime.c_str());
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
zlog_info(zct, "lTime = %d,OneWeek = %d", lTime, OneWeek);
zlog_info(zct, "lTime = %ld,OneWeek = %d", lTime, OneWeek);
zlog_info(zct, "dataStatic.TemTop : %f dataStatic.TemBot : %f dataStatic.Dip :%d dataStatic.Voltage : %d", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage);
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,
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld, 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 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
zlog_info(zct, "insert static data to sql");
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,
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%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);
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
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);
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend);
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);
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex);
sqlite_db_ctrl::instance().UpdateTableData(T_DATASTATIC_INFO(TNAME), updateSql, whereCon);
}
} else {
@ -313,7 +314,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
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);
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex);
sqlite_db_ctrl::instance().UpdateTableData(T_DATASTATIC_INFO(TNAME), updateSql, whereCon);
}
memset(szTableName, 0x00, sizeof(szTableName));
@ -412,13 +413,13 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-X").c_str());
memset(updateSql, 0, 1024);
sprintf(updateSql, "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',StaticIndex = %d,nodeResend = %d ",
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,nodeResend = %d ",
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(), staticIndex, nodeResend);
if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) { // 1 week
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 + "-X").c_str(), dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues,
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%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);
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
@ -546,13 +547,13 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Y").c_str());
memset(updateSql, 0, 1024);
sprintf(updateSql, "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',StaticIndex = %d,nodeResend = %d ",
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,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 == 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,
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%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);
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
@ -707,13 +708,13 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
memset(updateSql, 0, 1024);
sprintf(updateSql, "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',StaticIndex = %d,nodeResend = %d ",
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,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 == 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,
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%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);
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
@ -851,13 +852,14 @@ void Uart::DealWaveThread() {
sleep(1);
}
}
std::vector<float> Uart::DealData(int iChannel, float coe, int sampleRate, int ACCSampleTime, string strProduct) {
int waveCount = 0;
std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct) {
size_t waveCount = 0;
unsigned char data[1024 * 100] = {0x00};
unsigned char outdata[1024 * 100] = {0x00};
unsigned char dealdata[1024 * 100] = {0x00};
long unsigned int new_len = 0, deallen = 0;
int compress = 0, count = 0;
int compress = 0;
size_t count = 0;
long iTemp = 0;
char buf[8] = {0x00};
std::vector<float> vecData;
@ -930,7 +932,7 @@ std::vector<float> Uart::DealData(int iChannel, float coe, int sampleRate, int A
memcpy(dealdata, data, j * 92);
deallen = j * 92;
}
for (int i = 0; i < deallen; i++) {
for (size_t i = 0; i < deallen; i++) {
float fTemp = 0.0;
memset(buf, 0, 8);
sprintf(buf, "%02x%02x", dealdata[2 * i + 1], dealdata[i * 2]);
@ -977,12 +979,7 @@ void Uart::DealWave() {
std::string strMeasurementID = "";
std::string strFileName = "";
std::string strProduct = "";
int iChannel = 0;
int iChannelTemp = 0;
std::vector<float> vecData;
RecvData recvTemp;
if (wave_trans_) { //对每个传感器的每个通道进行遍历然后处理数据例如传感器1x轴的数据处理完后再去处理y轴的。传感器1的所有数据处理完后再处理传感器2的
char getLongAddr_sql[32] = {0};
sprintf(getLongAddr_sql, "zigbeeShortAddr='%s'", m_strDestShortAddr.c_str());
@ -1044,7 +1041,7 @@ void Uart::DealWave() {
}
}
float Uart::Calcoe(int ran, int iChannel, string &product, int range) {
float Uart::Calcoe(int ran, int iChannel, std::string &product, int range) {
float coe = 0.0;
if (product == "01") {
switch (ran) {
@ -1076,7 +1073,7 @@ float Uart::Calcoe(int ran, int iChannel, string &product, int range) {
return coe;
}
void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, std::vector<float> &vecData) {
void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData) {
if (vecData.size() <= 0) return;
std::string strFileName = "";
char localtimestamp[32] = {0};
@ -1110,7 +1107,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
float frTemp;
char buf[33] = {0x00};
std::string strWaveData = "";
for (int i = 0; i < vecData.size(); i++) {
for (size_t i = 0; i < vecData.size(); i++) {
frTemp = vecData[i] - mean;
fwrite(&frTemp, sizeof(float), 1, fp);
memset(buf, 0x00, sizeof(buf));
@ -1129,7 +1126,6 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
fclose(fp);
Json::Value valWaveData;
int length = vecData.size();
valWaveData["number"] = sampleRate;
valWaveData["channelId"] = strChannelID;
valWaveData["dataNodeNo"] = strMeasurementID;
@ -1186,12 +1182,12 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
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 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, tmpWhere);
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 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
std::string strFileName_failed = strFileName + "_" + nowTimetamp;
char tmpCmd[128] = {0x00};
@ -1201,14 +1197,13 @@ 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 = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
memset(tmpCmd, 0x00, sizeof(tmpCmd));
sprintf(tmpCmd, "rm %s ", vecRet[1].c_str());
system(tmpCmd);
zlog_info(zct, "rm dat file %s \n", tmpCmd);
}
} else {
zlog_info(zct, "send data , filename %s,size = %d\n", strFileName.c_str(), vecData.size());
}
@ -1223,7 +1218,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", strChannelID.c_str(), nowTimetamp.c_str());
sprintf(updateSql, "save = 1 ");
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
string strFileName_save = strFileName + "_" + nowTimetamp + "_save";
std::string strFileName_save = strFileName + "_" + nowTimetamp + "_save";
char tmpCmd[128] = {0x00};
sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_save.c_str());
system(tmpCmd);
@ -1235,21 +1230,21 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
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 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, tmpWhere);
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 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
string strFileName_save = strFileName + "_" + nowTimetamp + "_save";
std::string strFileName_save = strFileName + "_" + nowTimetamp + "_save";
char tmpCmd[128] = {0x00};
sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_save.c_str());
system(tmpCmd);
memset(tmpWhere, 0x00, sizeof(tmpWhere));
sprintf(tmpWhere, " channelID = '%s' and save = 1 ", strChannelID.c_str());
int count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
memset(tmpCmd, 0x00, sizeof(tmpCmd));
sprintf(tmpCmd, "rm %s ", (vecRet[1] + "_save").c_str());

View File

@ -5,7 +5,9 @@
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <boost/algorithm/string.hpp>
#include <zlog.h>
#include "common/common_func.hpp"
extern zlog_category_t* zct;
extern zlog_category_t* zbt;
@ -18,12 +20,12 @@ void Uart::openSwitch() {
len = write_data(fdSwitch, (char*)strSend, 8);
sleep(1);
len = read_data(fdSwitch, (char*)buffer, 100, 10);
for (int i = 0; i < len; i++) print_debug("%02X ", buffer[i] & 0xFF);
for (int i = 0; i < len; i++) zlog_info(zct, "%02X ", buffer[i] & 0xFF);
char strSend2[8] = {0x01, 0x06, 0x00, 0x00, 0x00, 0x01, 0x48, 0x0A};
len = write_data(fdSwitch, (char*)strSend2, 8);
sleep(1);
len = read_data(fdSwitch, (char*)buffer, 100, 10);
for (int i = 0; i < len; i++) print_debug("%02X ", buffer[i] & 0xFF);
for (int i = 0; i < len; i++) zlog_info(zct, "%02X ", buffer[i] & 0xFF);
close(fdSwitch);
}
@ -52,8 +54,8 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
zlog_info(zct, "hardversion %s,softversion %s", vecResult[0].c_str(), vecResult[1].c_str());
int thisindex = -1;
int flag = -1;
for (int j = 0; j < vecDataNodeUpdate.size(); j++) {
for (int i = 0; i < vecDataNodeUpdate[j].hwVersion.size(); i++) {
for (size_t j = 0; j < vecDataNodeUpdate.size(); j++) {
for (size_t i = 0; i < vecDataNodeUpdate[j].hwVersion.size(); i++) {
if (vecResult[0] == vecDataNodeUpdate[j].hwVersion[i]) {
if (vecResult[1] == vecDataNodeUpdate[j].strSoftVersion) {
flag = 0;
@ -113,7 +115,7 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
if (iRet == 0) {
zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
} else {
zzlog_error(zct, zct, "Packge ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
zlog_error(zct, "Packge ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
}
std::string strTime = GetLocalTimeWithMs();
zlog_info(zct, "ReadUpdatePackge strTime = %s", strTime.c_str());
@ -207,7 +209,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) {
}
UpdateData[99] = tmp;
WriteToUart((const char*)UpdateData, 100);
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
mssleep(10);
int time = 0;
do {
@ -239,12 +241,12 @@ endUpdate:
resendCount = 0;
free(buffer);
tcflush(fd, TCIFLUSH);
boost::this_thread::sleep(boost::posix_time::seconds(1));
sleep(1);
bUpdate = false;
bSendTimeStamp = false;
modify_LocalAddr(0x8888);
bModifyAddr = true;
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
mssleep(100);
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
DataNodeUpdateFile = "";
@ -272,7 +274,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
m_strDestShortAddr = std::string(tmpbuf);
GlobalConfig::Zigbee_G.MyAddr = 0x9999;
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
mssleep(500);
vec_t vecResult;
sprintf(selCon, "featureInterVal,waveInterVal,range,samplingRate,ACCSampleTime,startBrands,stopBrands,\
envelopeBandPass,faultFrequency,timeStamp,viff,ZigbeePower,ZigbeeRetry,MeasurementID,NodeWaveSend");
@ -328,7 +330,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
UpdateData[21] = BUILD_UINT2(x, y);
UpdateData[22] = atoi(vecResult[4].c_str()) & 0xFF;
zlog_info(zct, "vecResult size = %s==%s==%s==%s=%s\n", vecResult[5].c_str(), vecResult[6].c_str(), vecResult[7].c_str(), vecResult[8].c_str(), vecResult[14].c_str());
vector<string> vStart, vStop, vEnvelopeBandPass, vfaultFrequency, vNodeWaveSend;
std::vector<std::string> vStart, vStop, vEnvelopeBandPass, vfaultFrequency, vNodeWaveSend;
boost::split(vStart, vecResult[5], boost::is_any_of(","), boost::token_compress_on);
boost::split(vStop, vecResult[6], boost::is_any_of(","), boost::token_compress_on);
boost::split(vEnvelopeBandPass, vecResult[7], boost::is_any_of(","), boost::token_compress_on);
@ -480,7 +482,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
}
return 0;
} else {
zlog_error(zct, "invalid vecResultNode[41]:%c", vecResultNode[41]);
zlog_error(zct, "invalid vecResultNode[41]:%s", vecResultNode[41].c_str());
return -1;
}
}

View File

@ -12,16 +12,16 @@ static const char* MULTICAST_HOST_NAME1 = "224.0.0.1"; //组播接收平台搜
static const int MULTICAST_PORT_RECV1 = 7301; //组播接收端口
static const int MULTICAST_PORT_SEND = 7302; //根据接收组播udp发送端口
SearchDev::SearchDev(boost::asio::io_service& ioservice) : mSockRecv_1(ioservice), mListenEP1(ip::udp::v4(), MULTICAST_PORT_RECV1), mSendEndpoint1(ip::address::from_string(MULTICAST_HOST_NAME1), MULTICAST_PORT_SEND) { Init(); }
SearchDev::SearchDev(boost::asio::io_service& ioservice) : mSockRecv_1(ioservice), mListenEP1(boost::asio::ip::udp::v4(), MULTICAST_PORT_RECV1), mSendEndpoint1(boost::asio::ip::address::from_string(MULTICAST_HOST_NAME1), MULTICAST_PORT_SEND) { Init(); }
SearchDev::~SearchDev() { Stop(); }
void SearchDev::Init() {
try {
mSockRecv_1.open(mListenEP1.protocol());
mSockRecv_1.set_option(ip::udp::socket::reuse_address(true));
mSockRecv_1.set_option(boost::asio::ip::udp::socket::reuse_address(true));
mSockRecv_1.bind(mListenEP1);
mSockRecv_1.set_option(ip::multicast::join_group(ip::address_v4::from_string(MULTICAST_HOST_NAME1)));
mSockRecv_1.set_option(boost::asio::ip::multicast::join_group(boost::asio::ip::address_v4::from_string(MULTICAST_HOST_NAME1)));
mSockRecv_1.set_option(boost::asio::ip::multicast::enable_loopback(false));
} catch (boost::system::system_error& e) {
std::cout << e.what() << std::endl;
@ -66,7 +66,7 @@ void SearchDev::HandleRecv_1(const boost::system::error_code& pEc, size_t pBytes
jsData["DeviceType"] = "WirelessGateWay";
std::string strData = fw.write(jsData);
zlog_info(zct, "send info %s ip: %s\n", strData.c_str(), mRecvEP1.address().to_string().c_str());
ip::udp::endpoint remoteEP(ip::address::from_string(mRecvEP1.address().to_string()), MULTICAST_PORT_SEND);
boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(mRecvEP1.address().to_string()), MULTICAST_PORT_SEND);
mSockRecv_1.async_send_to(boost::asio::buffer(strData), remoteEP, boost::bind(&SearchDev::HandleSend_1, this, "SockRecv_1_1", boost::asio::placeholders::error));
}
} break;

View File

@ -237,7 +237,8 @@ void _FDES(u_char *key, u_char *mtext, u_char *text, u_char k[17][48]) {
namespace TEAcrypt {
const u_char TEA_key[16] = {0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x09, 0x09, 0x0A, 0x0A, 0x0B, 0x0B, 0x0C, 0x0C};
#define MX (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z)
//#define MX (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z)
#define MX (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((sum ^ y) + (k[(p & 3) ^ e] ^ z)))
#define DELTA 0x9e3779b9
#define S_LOOPTIME 1 // 5
#define BLOCK_SIZE 31 // PAGE_SIZE,根据你所要加密的数据包长度修改此参数(单位:字节)
@ -1047,7 +1048,6 @@ char *Secure::FnMD5CACL(u_char *buf, int len) {
char *Secure::Md5Sum(const char *filename) {
unsigned char data_buf[1024];
unsigned char md5[16];
MD5crypt::MD5_CTX ctx;
int data_fd;
int nread;

View File

@ -1,4 +1,5 @@
#include "tcp_cgi.hpp"
#include "localserver/local_server.hpp"
#include <zlog.h>
extern zlog_category_t *zct;
@ -47,7 +48,7 @@ void TcpCgi::startCgiServer() {
buff[n] = '\0';
std::string recvData = std::string(buff);
std::string reqData = cidwServer->HandleCgi_cmd(recvData);
std::string reqData = LocalServer::HandleCgi_cmd(recvData);
if (send(connfd, reqData.c_str(), reqData.length(), 0) < 0) {
zlog_error(zct, "send msg error: %s(errno: %d)", strerror(errno), errno);
}

View File

@ -62,7 +62,7 @@ void UdpSys::HandleRead(const boost::system::error_code& pEc, std::size_t pBytes
}
} else {
std::string read_cmd(m_buffer.data(), pBytesTransferred);
print_light_purple("%s", read_cmd.c_str());
zlog_info(zct, "%s", read_cmd.c_str());
if (read_cmd.length() > 0) {
AnalysisDataSys(read_cmd);
}
@ -93,7 +93,7 @@ void UdpSys::AnalysisDataSys(std::string cmd) {
GlobalConfig::ServerPort = localServerPort;
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", GlobalConfig::ServerIP);
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", to_string(GlobalConfig::ServerPort));
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", std::to_string(GlobalConfig::ServerPort));
std::string fileserver = ReadStrByOpt(SERVERCONFIG, "FileServer", "FileServerIpAddress");
if (0 == fileserver.compare("0.0.0.0") || 0 == fileserver.length()) {

View File

@ -4,6 +4,7 @@
#include <vector>
#include <string>
#include <boost/asio.hpp>
#include <boost/thread/mutex.hpp>
#include <json/json.h>
#include <boost/array.hpp>
#include <boost/container/detail/singleton.hpp>

View File

@ -66,7 +66,7 @@ int Dial::parseData(Event event, const char *pData) {
m_dial = 0;
m_curState = QNETDEVSTATUS;
}
if (m_curState == Event_QCFGNET) {
if (m_curState == QCFGNET) {
m_curState = QNETDEVCTL;
}
if (m_curState == QICSGPAPN && m_APN == 1) {
@ -96,6 +96,7 @@ int Dial::parseData(Event event, const char *pData) {
break;
default: break;
}
return 0;
}
int Dial::recvData() {
@ -187,9 +188,9 @@ int Dial::recvData() {
}
}
int Dial::queryPin() { int iRet = write_data(m_fd, "AT+CPIN?\r\n", 12); }
int Dial::queryPin() { return write_data(m_fd, (char *)std::string("AT+CPIN?\r\n").c_str(), 12); }
int Dial::configNet() { write_data(m_fd, "AT+QCFG=\"NAT\"\r\n", 19); }
int Dial::configNet() { return write_data(m_fd, (char *)std::string("AT+QCFG=\"NAT\"\r\n").c_str(), 19); }
int Dial::configApn() {
m_APN = 1;
@ -198,15 +199,17 @@ int Dial::configApn() {
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);
zlog_info(zct, "configApn = %d,data = %s\n", iRet, szCmd);
return 0;
}
int Dial::getCsq() { write_data(m_fd, "AT+QENG=\"servingcell\"\r\n", 27); }
int Dial::getCsq() { return write_data(m_fd, (char *)std::string("AT+QENG=\"servingcell\"\r\n").c_str(), 27); }
int Dial::getTemp() { write_data(m_fd, "AT+QTEMP\r\n", 12); }
int Dial::getTemp() { return write_data(m_fd, (char *)std::string("AT+QTEMP\r\n").c_str(), 12); }
int Dial::conncectUSB() {
int iRet = write_data(m_fd, "AT+QNETDEVCTL=1,1,1\r\n", 23);
int iRet = write_data(m_fd, (char *)std::string("AT+QNETDEVCTL=1,1,1\r\n").c_str(), 23);
zlog_info(zct, "conncectUSB = %d\n", iRet);
return iRet;
}
int Dial::dial5G() {
@ -223,7 +226,7 @@ int Dial::dial5G() {
conncectUSB();
m_dial = 1;
} else if (m_curState == QNETDEVSTATUS) {
write_data(m_fd, "AT+QNETDEVSTATUS=1\r\n", 22);
write_data(m_fd, (char *)std::string("AT+QNETDEVSTATUS=1\r\n").c_str(), 22);
} else if (m_curState == QDCHPC) {
configdhcp();
m_curState = QENG;
@ -234,12 +237,25 @@ int Dial::dial5G() {
getTemp();
sleep(15);
}
return 0;
}
int Dial::configims() { write_data(m_fd, "AT+QCFG=\"ims\",0\r\n", 21); }
int Dial::configims() {
write_data(m_fd, (char *)std::string("AT+QCFG=\"ims\",0\r\n").c_str(), 21);
return 0;
}
int Dial::configdhcp() { system("busybox udhcpc -f -n -q -t 5 -i usb0"); }
int Dial::configdhcp() {
system("busybox udhcpc -f -n -q -t 5 -i usb0");
return 0;
}
int Dial::setState() { m_curState = CPIN; }
int Dial::setState() {
m_curState = CPIN;
return 0;
}
int Dial::closePort() { close(m_fd); }
int Dial::closePort() {
close(m_fd);
return 0;
}