添加web接口,优化与传感器调用逻辑
This commit is contained in:
parent
f5b14e511b
commit
cdbf8bee6e
@ -1578,7 +1578,10 @@ int readStringValue(const char *section, const char *key, char *val, const char
|
||||
zlog_error(zct, "input parameter, section:%s, key:%s, val:%s, file:%s exist NULL", section, key, val, file);
|
||||
return -1;
|
||||
}
|
||||
IniReadValue(section, key, val, file);
|
||||
char sect[SECTION_MAX_LEN];
|
||||
memset(sect, 0, SECTION_MAX_LEN);
|
||||
sprintf(sect, "[%s]", section);
|
||||
IniReadValue(sect, key, val, file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -21,8 +21,8 @@ enum enumZigBeeTransmitStatus {
|
||||
//#define Q4G_MODULE
|
||||
//#define WIFI_MODULE
|
||||
//#define NR5G_MEIGE
|
||||
#define G2UL_GATEWAY
|
||||
//#define IMX6UL_GATEWAY
|
||||
//#define G2UL_GATEWAY
|
||||
#define IMX6UL_GATEWAY
|
||||
|
||||
class GlobalConfig
|
||||
{
|
||||
|
||||
@ -300,4 +300,19 @@ struct Param_57 {
|
||||
Param_57() : mZigbeePowerEnable(0){};
|
||||
};
|
||||
|
||||
struct Param_58 {
|
||||
int featureInterVal;
|
||||
int featureInterTime;
|
||||
int waveInterVal;
|
||||
int waveInterTime;
|
||||
int maxSensorNum;
|
||||
Param_58() : featureInterVal(0),featureInterTime(0),waveInterVal(0),waveInterTime(0),maxSensorNum(0){};
|
||||
};
|
||||
|
||||
struct Param_59 {
|
||||
int mMode;
|
||||
std::string DataNodeNo;
|
||||
Param_59() : mMode(0),DataNodeNo(""){};
|
||||
};
|
||||
|
||||
#endif // PARAMETER_DEFINATION_HPP_
|
||||
|
||||
@ -411,7 +411,7 @@ std::string SqliteDB::GetData(const char *tablename, const char *column, const c
|
||||
}
|
||||
zlog_info(zct, "[GetData] sql:%s", strSql.c_str());
|
||||
sqlite3_stmt *stmt;
|
||||
std::unique_lock<std::mutex> lock(mtx_);
|
||||
|
||||
mtx_.lock();
|
||||
if (sqlite3_prepare_v2(mDBAcess, strSql.c_str(), -1, &stmt, 0) != SQLITE_OK) {
|
||||
zlog_error(zct, "sqlite3_prepare_v2:%s, sql:[%s]", sqlite3_errmsg(mDBAcess), strSql.c_str());
|
||||
@ -426,9 +426,36 @@ std::string SqliteDB::GetData(const char *tablename, const char *column, const c
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
mtx_.unlock();
|
||||
zlog_info(zct, "[GetData] sql123:%s", strSql.c_str());
|
||||
return strRes;
|
||||
}
|
||||
|
||||
array_t SqliteDB::GetDataMultiLine(const char *sql){
|
||||
array_t arrResult;
|
||||
zlog_info(zct, "[GetDataMultiLine] sql:%s", sql);
|
||||
sqlite3_stmt *stmt;
|
||||
mtx_.lock();
|
||||
if (sqlite3_prepare_v2(mDBAcess, sql, -1, &stmt, 0) != SQLITE_OK) {
|
||||
zlog_error(zct, "sqlite3_prepare_v2:%s, sql:[%s]", sqlite3_errmsg(mDBAcess), sql);
|
||||
sqlite3_finalize(stmt);
|
||||
mtx_.unlock();
|
||||
return arrResult;
|
||||
}
|
||||
int retStep = sqlite3_step(stmt);
|
||||
int column_count = sqlite3_column_count(stmt);
|
||||
while (retStep == SQLITE_ROW) {
|
||||
vec_t vecResult;
|
||||
for (int iCol = 0; iCol < column_count; iCol++) {
|
||||
char *columninfo = (char *)sqlite3_column_text(stmt, iCol);
|
||||
std::string str = columninfo != NULL ? columninfo : "";
|
||||
vecResult.push_back(str);
|
||||
}
|
||||
arrResult.push_back(vecResult);
|
||||
retStep = sqlite3_step(stmt);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
mtx_.unlock();
|
||||
return arrResult;
|
||||
}
|
||||
array_t SqliteDB::GetDataMultiLine(const char *tablename, const char *column, const char *whereCon) {
|
||||
array_t arrResult;
|
||||
std::string strSql = "select ";
|
||||
@ -440,7 +467,6 @@ array_t SqliteDB::GetDataMultiLine(const char *tablename, const char *column, co
|
||||
|
||||
zlog_info(zct, "[GetDataMultiLine] sql:%s", strSql.c_str());
|
||||
sqlite3_stmt *stmt;
|
||||
std::unique_lock<std::mutex> lock(mtx_);
|
||||
mtx_.lock();
|
||||
if (sqlite3_prepare_v2(mDBAcess, strSql.c_str(), -1, &stmt, 0) != SQLITE_OK) {
|
||||
zlog_error(zct, "sqlite3_prepare_v2:%s, sql:[%s]", sqlite3_errmsg(mDBAcess), strSql.c_str());
|
||||
@ -624,7 +650,6 @@ int SqliteDB::UpdateTableData(const char *tablename, const char *updateColumn, c
|
||||
}
|
||||
zlog_info(zct, "[UpdateTableData] sql:%s", strSql.c_str());
|
||||
char *msg;
|
||||
std::unique_lock<std::mutex> lock(mtx_);
|
||||
mtx_.lock();
|
||||
int iRet = sqlite3_exec(GetDbHandle(), strSql.c_str(), 0, 0, &msg);
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@ public:
|
||||
int AlterTable(const char *tablename, const char *column, bool isAdd = true);
|
||||
vec_t GetDataSingleLine(const char *tablename, const char *column, const char *whereCon);
|
||||
std::string GetData(const char *tablename, const char *column, const char *whereCon);
|
||||
array_t GetDataMultiLine(const char *sql);
|
||||
array_t GetDataMultiLine(const char *tablename, const char *column, const char *whereCon);
|
||||
array_t GetDataMultiLineTransaction(const char *tablename, const char *column, const char *whereCon);
|
||||
vec_t GetDataMultiLineOfOneColumn(const char *tablename, const char *column, const char *whereCon);
|
||||
|
||||
@ -63,6 +63,8 @@ public:
|
||||
std::string JsonCmd_Cgi_55(Param_55 ¶m);
|
||||
std::string JsonCmd_Cgi_56(Param_56 ¶m);
|
||||
std::string JsonCmd_Cgi_57(Param_57 ¶m);
|
||||
std::string JsonCmd_Cgi_58(Param_58 ¶m);
|
||||
std::string JsonCmd_Cgi_59(Param_59 ¶m);
|
||||
std::string JsonCmd_Cgi_default();
|
||||
|
||||
private:
|
||||
|
||||
@ -192,7 +192,6 @@ std::string JsonData::JsonCmd_25(Param_25 ¶m) {
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
char GateWay[100] = {0x00};
|
||||
sprintf(GateWay, "sed -i '7c route add default gw %s' /etc/init.d/S90start_userapp.sh", param.mGateway.c_str());
|
||||
print_info("GateWay = %s\n", GateWay);
|
||||
system(GateWay);
|
||||
#endif
|
||||
PlatformInit::EquipIpInit(param.mNet);
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include "utility/md5.h"
|
||||
#include "wifi_5g/wpa_client.h"
|
||||
#include "utility/calculation.hpp"
|
||||
#include "scheduler/schedule.hpp"
|
||||
|
||||
extern zlog_category_t *zct;
|
||||
extern const char *JSON_FIELD_CMD;
|
||||
@ -504,3 +505,74 @@ std::string JsonData::JsonCmd_Cgi_57(Param_57 ¶m) {
|
||||
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_58(Param_58 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
Json::Value jsBody;
|
||||
jsonVal[JSON_FIELD_CMD] = "58";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
int ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum);
|
||||
if (ret != 0)
|
||||
{
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "保存失败!";
|
||||
}
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
Json::Value jsBody;
|
||||
jsonVal[JSON_FIELD_CMD] = "59";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
char table_name[50] ={0};
|
||||
int interval = 0;
|
||||
if (param.mMode == 1)
|
||||
{
|
||||
sprintf(table_name,"t_dataStatic_%s",param.DataNodeNo.c_str());
|
||||
interval = 400;
|
||||
}else if (param.mMode == 2)
|
||||
{
|
||||
sprintf(table_name,"t_data_waveSend");
|
||||
interval = 7300;
|
||||
}
|
||||
char sql[1024]={0};
|
||||
snprintf(sql, sizeof(sql),
|
||||
"WITH CTE AS ("
|
||||
" SELECT timestamp, "
|
||||
" LAG(timestamp) OVER (ORDER BY timestamp) AS prev_timestamp "
|
||||
" FROM %s"
|
||||
") "
|
||||
"SELECT timestamp, "
|
||||
" prev_timestamp, "
|
||||
" timestamp - prev_timestamp AS interval_seconds "
|
||||
"FROM CTE "
|
||||
"WHERE prev_timestamp IS NOT NULL "
|
||||
" AND (timestamp - prev_timestamp) > %d;",
|
||||
table_name,interval);
|
||||
|
||||
array_t arrResult = sqlite_db_ctrl::instance().GetDataMultiLine(sql);
|
||||
Json::Value valData;
|
||||
if (arrResult.size() > 0)
|
||||
{
|
||||
|
||||
for (size_t i = 0; i < arrResult.size(); i++)
|
||||
{
|
||||
Json::Value iTem;
|
||||
iTem.append(arrResult[i][0]);
|
||||
iTem.append(arrResult[i][1]);
|
||||
valData.append(iTem);
|
||||
}
|
||||
jsonVal["content"] = valData;
|
||||
|
||||
}else{
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "获取数据失败!";
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,8 @@ enum WebCommand {
|
||||
kVelocityTimeDomain = 55,
|
||||
kVelocityFreqDomain = 56,
|
||||
kEnableZigbeePower = 57,
|
||||
kSchedulingConfiguration = 58,
|
||||
kLostRecords = 59
|
||||
};
|
||||
|
||||
class LocalServer {
|
||||
|
||||
@ -373,6 +373,25 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
std::string data = jd.JsonCmd_Cgi_57(param);
|
||||
return data;
|
||||
} break;
|
||||
case kSchedulingConfiguration:{
|
||||
JsonData jd;
|
||||
Param_58 param;
|
||||
param.featureInterVal = recvBody["featureInterVal"].asInt();
|
||||
param.featureInterTime = recvBody["featureInterTime"].asInt();
|
||||
param.waveInterVal = recvBody["waveInterVal"].asInt();
|
||||
param.waveInterTime = recvBody["waveInterTime"].asInt();
|
||||
param.maxSensorNum = recvBody["maxSensorNum"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_58(param);
|
||||
return data;
|
||||
}break;
|
||||
case kLostRecords:{
|
||||
JsonData jd;
|
||||
Param_59 param;
|
||||
param.mMode = recvBody["type"].asInt();
|
||||
param.DataNodeNo = recvBody["DataNodeNo"].asString();
|
||||
std::string data = jd.JsonCmd_Cgi_59(param);
|
||||
return data;
|
||||
}break;
|
||||
default:
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_default();
|
||||
|
||||
6
main.cpp
6
main.cpp
@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
|
||||
print_info("WiFi_MODULE \n");
|
||||
#endif
|
||||
|
||||
// 通过UDP接收数据
|
||||
//通过UDP接收数据
|
||||
boost::thread StartConnectSys(attrs, StartUdpSys);
|
||||
StartConnectSys.detach();
|
||||
|
||||
@ -133,7 +133,7 @@ int main(int argc, char *argv[]) {
|
||||
zlog_error(zbt, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)");
|
||||
}
|
||||
|
||||
int fd = OpenWatchDog();
|
||||
//int fd = OpenWatchDog();
|
||||
int count = 0;
|
||||
while (GlobalConfig::QuitFlag_G) {
|
||||
#ifdef G2UL_GATEWAY
|
||||
@ -141,7 +141,7 @@ int main(int argc, char *argv[]) {
|
||||
usleep(20000);
|
||||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 0);
|
||||
#endif
|
||||
WriteWatchDog(fd);
|
||||
//WriteWatchDog(fd);
|
||||
sleep(20);
|
||||
if (GlobalConfig::threadStatus == 0) {
|
||||
count++;
|
||||
|
||||
@ -33,7 +33,6 @@ void CheckThread() {
|
||||
int loose_check = 0;
|
||||
int mqttresend = 0;
|
||||
int ModifyAddr = 0;
|
||||
int checkNet0 = 0;
|
||||
|
||||
while (GlobalConfig::QuitFlag_G) {
|
||||
GlobalConfig::threadStatus = 1;
|
||||
@ -70,7 +69,7 @@ void CheckThread() {
|
||||
zlog_error(zct, "MQTT connect failed ");
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
char connect[10] = {0x00};
|
||||
readStringValue(zct, "config", "connect", connect, (char *)GlobalConfig::Config_G.c_str());
|
||||
readStringValue("config", "connect", connect, (char *)GlobalConfig::Config_G.c_str());
|
||||
if (atoi(connect)) {
|
||||
zlog_error(zct, "MQTT connect failed,reboot");
|
||||
exit(0);
|
||||
|
||||
@ -36,7 +36,9 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
||||
int offSize = 0;
|
||||
int timeoutflag = 0;
|
||||
char head[] = {0xAA, 0x55, 0xAA};
|
||||
#ifdef G2UL_GATEWAY
|
||||
char szbuffer[BUF_LENGTH] = {0x00};
|
||||
#endif
|
||||
while (1) {
|
||||
if (now_task == WAVE_CMD) {
|
||||
memset(buff, 0, sizeof(buff));
|
||||
@ -99,7 +101,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
||||
if (srcshow) {
|
||||
zlog_info(zct, "0x8888 ===str_recv===,ret = %d", ret);
|
||||
for (int i = 0; i < ret; i++) {
|
||||
zlog_info(zct, "[%02x]", buff[i] & 0xff);
|
||||
printf("[%02x]", buff[i] & 0xff);
|
||||
}
|
||||
printf("\n");
|
||||
FindRecvPackage(ret, buff, head);
|
||||
@ -123,7 +125,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
||||
maxSize += ret;
|
||||
zlog_info(zct, "0x8888==str_recv===,ret = %d offSize = %d\n", ret, maxSize);
|
||||
for (int i = 0; i < ret; i++) {
|
||||
zlog_info(zct, "%02x ", buff[i] & 0xff);
|
||||
printf( "%02x ", buff[i] & 0xff);
|
||||
}
|
||||
zlog_info(zct, "\n");
|
||||
timeoutflag = 0;
|
||||
@ -277,7 +279,7 @@ void Uart::WriteToUart(const char *strSend, int pLen) {
|
||||
if (!bUpdate) {
|
||||
zlog_info(zct, "Write To Uart Start:");
|
||||
for (int i = 0; i < pLen; i++) {
|
||||
zlog_info(zct, "%02X ", *(strSend + i) & 0xFF);
|
||||
printf("%02X ", *(strSend + i) & 0xFF);
|
||||
}
|
||||
zlog_info(zct, "\nWrite To Uart End.");
|
||||
}
|
||||
@ -288,7 +290,7 @@ void Uart::WriteToUart(const char *strSend, int pLen) {
|
||||
int Uart::ReadFromUart() {
|
||||
char buffer[100] = {0x00};
|
||||
int len = read_data(fd, (char *)buffer, 100, 10);
|
||||
for (int i = 0; i < len; i++) zlog_info(zct, "%02X ", buffer[i] & 0xFF);
|
||||
for (int i = 0; i < len; i++) printf( "%02X ", buffer[i] & 0xFF);
|
||||
zlog_info(zct, "==========ReadFromUart========len = %d", len);
|
||||
|
||||
if (len) {
|
||||
@ -406,6 +408,12 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
||||
scheduleTask.shortAddr = ushortAdd;
|
||||
scheduleTask.duration = next_duration;
|
||||
TaskResp(scheduleTask);
|
||||
}else if (taskID == kScheduleConfigSensor) //6.更新配置
|
||||
{
|
||||
DealConfig(ushortAdd);
|
||||
}else if (taskID == kScheduleUpgrade) //7.更新固件
|
||||
{
|
||||
ReadUpdatePackge(ushortAdd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -435,24 +443,41 @@ int Uart::DealConfig(uint16_t ushortAdd){
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
return 0;
|
||||
}
|
||||
int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
|
||||
char buf[20] = {0x00};
|
||||
sprintf(buf, "%02x%02x", (ushortAdd >> 8) & 0xFF, ushortAdd & 0xFF);
|
||||
std::string strShortAddr = std::string(buf);
|
||||
compressWaveChannel tempchannel;
|
||||
tempchannel.compressChannelX = pData[8];
|
||||
tempchannel.compressChannelY = pData[9];
|
||||
tempchannel.compressChannelZ = pData[10];
|
||||
|
||||
tempchannel.CountX = BUILD_UINT32(pData[14], pData[13],pData[12],pData[11]);
|
||||
tempchannel.CountY = BUILD_UINT32(pData[18], pData[17],pData[16],pData[15]);
|
||||
tempchannel.CountZ = BUILD_UINT32(pData[22], pData[21],pData[20],pData[19]);
|
||||
|
||||
g_mapCompress[strShortAddr] = tempchannel;
|
||||
|
||||
zlog_info(zct, "count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ);
|
||||
zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Uart::DealRecvData(const char *pData) {
|
||||
|
||||
uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF);
|
||||
uint8_t command = pData[5] & 0xFF;
|
||||
uint8_t recvcode = pData[7] & 0xFF;
|
||||
if (recvcode != 0)
|
||||
{
|
||||
zlog_error(zct, "shortAdd = %d,command = %d,recvcode = %d ",ushortAdd,command,recvcode);
|
||||
}
|
||||
zlog_info(zct, "shortAdd = %d,command = %d,recvcode = %d ",ushortAdd,command,recvcode);
|
||||
|
||||
zlog_info(zct, "shortAdd = %02x%02x,command = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command);
|
||||
switch (command) {
|
||||
case DEVICE_INF: {
|
||||
case DEVICE_INF:
|
||||
DealDataNodeInfo(pData);
|
||||
} break;
|
||||
case DEVICE_INF2: {
|
||||
break;
|
||||
case DEVICE_INF2:
|
||||
DealDataNodeName(pData);
|
||||
} break;
|
||||
break;
|
||||
case ASK_TASK:
|
||||
DealAskTask(ushortAdd);
|
||||
break;
|
||||
@ -464,11 +489,23 @@ void Uart::DealRecvData(const char *pData) {
|
||||
DealReviveDuration(ushortAdd);
|
||||
break;
|
||||
case CONFIG:
|
||||
DealConfig(ushortAdd);
|
||||
DealReviveDuration(ushortAdd);
|
||||
if (recvcode == 0)
|
||||
{
|
||||
DealReviveDuration(ushortAdd);
|
||||
}else{
|
||||
zlog_error(zct, "shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
|
||||
}
|
||||
break;
|
||||
case UPGRADE:
|
||||
UpdateWirelessNode(ushortAdd);
|
||||
if (recvcode == 0)
|
||||
{
|
||||
UpdateWirelessNode(ushortAdd);
|
||||
}else{
|
||||
zlog_error(zct, "shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
|
||||
}
|
||||
break;
|
||||
case WAVE_COMPRESS:
|
||||
DealWaveCompress(pData,ushortAdd);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
@ -991,7 +1028,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
}
|
||||
memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100);
|
||||
DealDataNodeWave(RecvBuf, command);
|
||||
} else if (now_task != WAVE_CMD && (command == ASK_TASK || command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH)) {
|
||||
} else if (now_task != WAVE_CMD && (command == ASK_TASK || command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == WAVE_COMPRESS)) {
|
||||
char RecvBuf[100] = {0x00};
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
||||
if (!CheckCrc(RecvBuf, 99)) {
|
||||
|
||||
@ -27,6 +27,7 @@ enum InteractiveCommand {
|
||||
DEVICE_INF2 = 11, // 测点名称,测点编号
|
||||
SIGNAL_STRENGTH = 12, // 信号强度
|
||||
DEVICE_EXCEPTION = 13, // 异常: 外设
|
||||
WAVE_COMPRESS = 14, // 波形数据压缩
|
||||
};
|
||||
// 无线传感器请求任务
|
||||
typedef struct {
|
||||
@ -159,6 +160,7 @@ public:
|
||||
int DealException(const char* pData);
|
||||
int DealReviveDuration(uint16_t ushortAdd);
|
||||
int DealConfig(uint16_t ushortAdd);
|
||||
int DealWaveCompress(const char *pData,uint16_t ushortAdd);
|
||||
|
||||
// feature parse
|
||||
void DealDataNodeFeature(const char* pData, int flag);
|
||||
@ -194,7 +196,7 @@ public:
|
||||
void UpdateWirelessNode(unsigned short shortAdd);
|
||||
int UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr);
|
||||
int UpdateConfig(unsigned char* pDestShortAddr);
|
||||
bool ReadUpdatePackge(unsigned char* shortAddr);
|
||||
bool ReadUpdatePackge(uint16_t ushortAdd);
|
||||
int TaskResp(ScheduleTask scheduleTask);
|
||||
int SendReviveDuration(ReviveDuration recvDuration);
|
||||
void openSwitch();
|
||||
|
||||
@ -59,7 +59,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
|
||||
if (!bSendTimeStamp) {
|
||||
bSendTimeStamp = true;
|
||||
modify_distaddr_info(0x9999, (char*)"", pRecvData->ShortAddr); //临时参数配置
|
||||
//modify_distaddr_info(0x9999, (char*)"", pRecvData->ShortAddr); //临时参数配置
|
||||
mssleep(10000);
|
||||
|
||||
zlog_info(zct, "Zigbee Signal !\n");
|
||||
@ -71,67 +71,18 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
mssleep(20000);
|
||||
}
|
||||
mssleep(10000);
|
||||
timing = UpdateWirelessNodeTime((unsigned char *)pRecvData->ShortAddr, 0);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
GlobalConfig::ZigbeeInfo_G.MyAddr = "9999";
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x9999;
|
||||
std::string strTime = GetLocalTimeWithMs();
|
||||
// GlobalConfig::ZigbeeInfo_G.MyAddr = "9999";
|
||||
// GlobalConfig::Zigbee_G.MyAddr = 0x9999;
|
||||
// std::string strTime = GetLocalTimeWithMs();
|
||||
|
||||
m_strDestShortAddr = std::string(buf);
|
||||
|
||||
bool isUpdate = ReadUpdatePackge(pRecvData->ShortAddr);
|
||||
bUpdatePre = isUpdate;
|
||||
if (!isUpdate) {
|
||||
UpdateConfig(pRecvData->ShortAddr);
|
||||
}
|
||||
if (isUpdate || bUpdateconfig) {
|
||||
} else {
|
||||
zlog_info(zct, "DealDataNodeFeature %02x%02x,localaddr %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], UINT16_HIGH(GlobalConfig::Zigbee_G.MyAddr), UINT16_LOW(GlobalConfig::Zigbee_G.MyAddr));
|
||||
// 进入传输原始数据状态,启动计数 60秒
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||
}
|
||||
unsigned char compressChannel = pRecvData->Data[34];
|
||||
compressWaveChannel tempchannel;
|
||||
tempchannel.compressChannelX = GET_BIT(compressChannel, 0);
|
||||
tempchannel.compressChannelY = GET_BIT(compressChannel, 2);
|
||||
tempchannel.compressChannelZ = GET_BIT(compressChannel, 4);
|
||||
if (strProductNo == "01") {
|
||||
tempchannel.CountX = BUILD_UINT16(pRecvData->Data[55], pRecvData->Data[54]);
|
||||
tempchannel.CountY = BUILD_UINT16(pRecvData->Data[57], pRecvData->Data[56]);
|
||||
tempchannel.CountZ = BUILD_UINT16(pRecvData->Data[59], pRecvData->Data[58]);
|
||||
} else if (strProductNo == "02") {
|
||||
unsigned char buffer[6] = {0x00};
|
||||
|
||||
memcpy(buffer, &pRecvData->Data[55], 1);
|
||||
memcpy(buffer + 1, &pRecvData->Data[54], 1);
|
||||
memcpy(buffer + 2, &pRecvData->Data[57], 1);
|
||||
memcpy(buffer + 3, &pRecvData->Data[56], 1);
|
||||
memcpy(buffer + 4, &pRecvData->Data[59], 1);
|
||||
memcpy(buffer + 5, &pRecvData->Data[58], 1);
|
||||
|
||||
uint64_t packed_data = 0;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
packed_data |= (uint64_t)buffer[i] << (8 * (5 - i)); // 从高位开始组合
|
||||
}
|
||||
// 输出结果
|
||||
zlog_info(zct, "Resulting 48-bit integer: 0x%012llX\n", packed_data);
|
||||
// 提取 15 位的第一个数据
|
||||
tempchannel.CountX = (packed_data >> 33) & 0x7FFF; // 提取最高的 15 位
|
||||
|
||||
// 提取 15 位的第二个数据
|
||||
tempchannel.CountY = (packed_data >> 18) & 0x7FFF; // 提取中间的 15 位
|
||||
// 提取 18 位的第三个数据
|
||||
tempchannel.CountZ = packed_data & 0x3FFFF; // 提取最低的 18 位
|
||||
}
|
||||
|
||||
g_mapCompress[strShortAddr] = tempchannel;
|
||||
|
||||
zlog_info(zct, "count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ);
|
||||
zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ);
|
||||
|
||||
|
||||
} else {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
|
||||
@ -29,7 +29,7 @@ void Uart::openSwitch() {
|
||||
close(fdSwitch);
|
||||
}
|
||||
|
||||
bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
|
||||
bool Uart::ReadUpdatePackge(unsigned short shortAdd) {
|
||||
// compare hardversion in update list
|
||||
std::vector<std::string> strHWversion;
|
||||
std::string strFileName = "", strSoftVersion = "";
|
||||
@ -37,7 +37,7 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
|
||||
vecDataNodeUpdate = ReadStrUpdate("/opt/DataNode/config.json");
|
||||
char gethardVersion_sql[32] = {0};
|
||||
char selectsql[1024] = {0};
|
||||
sprintf(gethardVersion_sql, "zigbeeShortAddr='%02x%02x'", pDestShortAddr[0], pDestShortAddr[1]);
|
||||
sprintf(gethardVersion_sql, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
sprintf(selectsql, "%s,%s", T_SENSOR_INFO(HARDVERSION), T_SENSOR_INFO(SOFTVERSION));
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), selectsql, gethardVersion_sql);
|
||||
if (vecResult.size() < 1) {
|
||||
@ -87,8 +87,8 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
|
||||
Data[0] = 0xAA;
|
||||
Data[1] = 0x55;
|
||||
Data[2] = 0xAA;
|
||||
Data[3] = pDestShortAddr[0];
|
||||
Data[4] = pDestShortAddr[1];
|
||||
Data[3] = UINT16_HIGH(shortAdd);
|
||||
Data[4] = UINT16_LOW(shortAdd);
|
||||
Data[5] = 0x20;
|
||||
Data[6] = 0x00;
|
||||
int2bytes(thisSize, size, 4);
|
||||
@ -105,9 +105,9 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
|
||||
WriteToUart((const char*)Data, 12);
|
||||
int iRet = CheckZigbeeACK();
|
||||
if (iRet == 0) {
|
||||
zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||
zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
} else {
|
||||
zlog_error(zct, "Packge ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||
zlog_error(zct, "Packge ACK send failed,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
}
|
||||
std::string strTime = GetLocalTimeWithMs();
|
||||
zlog_info(zct, "ReadUpdatePackge strTime = %s", strTime.c_str());
|
||||
@ -548,9 +548,9 @@ int Uart::TaskResp(ScheduleTask scheduleTask){
|
||||
WriteToUart((const char*)UpdateData, 100);
|
||||
int iRet = CheckZigbeeACK();
|
||||
if (iRet == 0) {
|
||||
zlog_info(zct, "TaskResp ACK send success,shortAddr = %d", scheduleTask.shortAddr);
|
||||
zlog_info(zct, "TaskResp ACK send success,shortAddr = %02x%02x", UINT16_HIGH(scheduleTask.shortAddr),UINT16_LOW(scheduleTask.shortAddr));
|
||||
} else {
|
||||
zlog_error(zct, "TaskResp ACK send failed,shortAddr = %d", scheduleTask.shortAddr);
|
||||
zlog_error(zct, "TaskResp ACK send failed,shortAddr = %02x%02x", UINT16_HIGH(scheduleTask.shortAddr),UINT16_LOW(scheduleTask.shortAddr));
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user