添加任务调用流程
This commit is contained in:
parent
39dacf1021
commit
3a5c763fc1
@ -109,6 +109,12 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
|||||||
memset(sql_exec, 0, 2048);
|
memset(sql_exec, 0, 2048);
|
||||||
sprintf(sql_exec,"update t_sensor_info set MeasurementID = dataNodeNo where MeasurementID = '' ;");
|
sprintf(sql_exec,"update t_sensor_info set MeasurementID = dataNodeNo where MeasurementID = '' ;");
|
||||||
UpdateTableData(sql_exec);
|
UpdateTableData(sql_exec);
|
||||||
|
memset(sql_exec, 0, 2048);
|
||||||
|
sprintf(sql_exec,"update t_sensor_info set NodeWaveSend = '0,0,0' where NodeWaveSend = '' ;");
|
||||||
|
UpdateTableData(sql_exec);
|
||||||
|
memset(sql_exec, 0, 2048);
|
||||||
|
sprintf(sql_exec,"update t_sensor_info set NodeWaveSend = '0,0,0' where NodeWaveSend IS NULL ;");
|
||||||
|
UpdateTableData(sql_exec);
|
||||||
|
|
||||||
//创建传感器数据存储表
|
//创建传感器数据存储表
|
||||||
memset(sql_exec, 0, 2048);
|
memset(sql_exec, 0, 2048);
|
||||||
|
|||||||
@ -48,20 +48,20 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
|||||||
std::string data = jd.JsonCmd_Cgi_01(param);
|
std::string data = jd.JsonCmd_Cgi_01(param);
|
||||||
return data;
|
return data;
|
||||||
} break;
|
} break;
|
||||||
case kWebTiming: {
|
// case kWebTiming: {
|
||||||
Param_02 param;
|
// Param_02 param;
|
||||||
std::string type = recvBody["type"].asString();
|
// std::string type = recvBody["type"].asString();
|
||||||
if (0 == type.compare("SET")) {
|
// if (0 == type.compare("SET")) {
|
||||||
param.mMode = 0;
|
// param.mMode = 0;
|
||||||
param.mTimeStamp = recvBody["timeStamp"].asInt();
|
// param.mTimeStamp = recvBody["timeStamp"].asInt();
|
||||||
param.mSetType = recvBody["setType"].asInt();
|
// param.mSetType = recvBody["setType"].asInt();
|
||||||
} else if (0 == type.compare("GET")) {
|
// } else if (0 == type.compare("GET")) {
|
||||||
param.mMode = 1;
|
// param.mMode = 1;
|
||||||
}
|
// }
|
||||||
JsonData jd;
|
// JsonData jd;
|
||||||
std::string data = jd.JsonCmd_Cgi_02(param);
|
// std::string data = jd.JsonCmd_Cgi_02(param);
|
||||||
return data;
|
// return data;
|
||||||
} break;
|
// } break;
|
||||||
case kWebHWStatus: {
|
case kWebHWStatus: {
|
||||||
JsonData jd;
|
JsonData jd;
|
||||||
std::string data = jd.JsonCmd_Cgi_07();
|
std::string data = jd.JsonCmd_Cgi_07();
|
||||||
|
|||||||
@ -91,97 +91,97 @@ void CheckThread() {
|
|||||||
GlobalConfig::net0Status = iStatus;
|
GlobalConfig::net0Status = iStatus;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (7200 == time_check) { // 2h
|
// if (7200 == time_check) { // 2h //校时暂时不测
|
||||||
char buf[256] = {0};
|
// char buf[256] = {0};
|
||||||
char buf2[256] = {0};
|
// char buf2[256] = {0};
|
||||||
sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str());
|
// sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str());
|
||||||
sprintf(buf2, "{\"dataWatchNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str());
|
// sprintf(buf2, "{\"dataWatchNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str());
|
||||||
std::string str = std::string(buf);
|
// std::string str = std::string(buf);
|
||||||
std::string str2 = std::string(buf2);
|
// std::string str2 = std::string(buf2);
|
||||||
time_check = 0;
|
// time_check = 0;
|
||||||
int iRet = data_publish(str.c_str(), GlobalConfig::Topic_G.mPubTiming.c_str());
|
// int iRet = data_publish(str.c_str(), GlobalConfig::Topic_G.mPubTiming.c_str());
|
||||||
iRet = data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
// iRet = data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubTiming.c_str());
|
// iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubTiming.c_str());
|
||||||
iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
// iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
if (iRet != 0) {
|
// if (iRet != 0) {
|
||||||
zlog_error(zct, "MQTT connect failed ,time check");
|
// zlog_error(zct, "MQTT connect failed ,time check");
|
||||||
#ifdef IMX6UL_GATEWAY
|
// #ifdef IMX6UL_GATEWAY
|
||||||
char connect[10] = {0x00};
|
// char connect[10] = {0x00};
|
||||||
readStringValue("config", "connect", connect, (char *)GlobalConfig::Config_G.c_str());
|
// readStringValue("config", "connect", connect, (char *)GlobalConfig::Config_G.c_str());
|
||||||
if (atoi(connect)) {
|
// if (atoi(connect)) {
|
||||||
zlog_error(zct, "MQTT connect failed,time check ,reboot");
|
// zlog_error(zct, "MQTT connect failed,time check ,reboot");
|
||||||
exit(0);
|
// exit(0);
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
#ifdef NR5G_MODULE
|
// #ifdef NR5G_MODULE
|
||||||
#ifdef IMX6UL_GATEWAY
|
// #ifdef IMX6UL_GATEWAY
|
||||||
dial.closePort();
|
// dial.closePort();
|
||||||
gpio_set(GlobalConfig::GPIO_G.commRest, 0);
|
// gpio_set(GlobalConfig::GPIO_G.commRest, 0);
|
||||||
zlog_warn(zct, "GPIO 8 start");
|
// zlog_warn(zct, "GPIO 8 start");
|
||||||
sleep(2);
|
// sleep(2);
|
||||||
gpio_set(GlobalConfig::GPIO_G.commRest, 1);
|
// gpio_set(GlobalConfig::GPIO_G.commRest, 1);
|
||||||
zlog_warn(zct, "GPIO 8 End");
|
// zlog_warn(zct, "GPIO 8 End");
|
||||||
sleep(20);
|
// sleep(20);
|
||||||
dial.openPort("/dev/ttyUSB2");
|
// dial.openPort("/dev/ttyUSB2");
|
||||||
dial.setState();
|
// dial.setState();
|
||||||
#endif
|
// #endif
|
||||||
#ifdef G2UL_GATEWAY
|
// #ifdef G2UL_GATEWAY
|
||||||
dial.closePort();
|
// dial.closePort();
|
||||||
gpio_set(GlobalConfig::GPIO_G.commPower, 0);
|
// gpio_set(GlobalConfig::GPIO_G.commPower, 0);
|
||||||
zlog_warn(zct, "commPower start");
|
// zlog_warn(zct, "commPower start");
|
||||||
sleep(2);
|
// sleep(2);
|
||||||
gpio_set(GlobalConfig::GPIO_G.commPower, 1);
|
// gpio_set(GlobalConfig::GPIO_G.commPower, 1);
|
||||||
zlog_warn(zct, "commPower End");
|
// zlog_warn(zct, "commPower End");
|
||||||
sleep(20);
|
// sleep(20);
|
||||||
connectCount++;
|
// connectCount++;
|
||||||
if (connectCount > 10) {
|
// if (connectCount > 10) {
|
||||||
zlog_error(zct, "5G reset error ,reboot!");
|
// zlog_error(zct, "5G reset error ,reboot!");
|
||||||
system("reboot");
|
// system("reboot");
|
||||||
}
|
// }
|
||||||
#ifndef NR5G_MEIGE
|
// #ifndef NR5G_MEIGE
|
||||||
dial.openPort("/dev/ttyUSB2");
|
// dial.openPort("/dev/ttyUSB2");
|
||||||
dial.setState();
|
// dial.setState();
|
||||||
#else
|
// #else
|
||||||
char szquectel[100] = {0x00};
|
// char szquectel[100] = {0x00};
|
||||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
// std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||||
sprintf(szquectel, "/opt/quectel-CM/Meig-CM -s %s &", strAPN.c_str());
|
// sprintf(szquectel, "/opt/quectel-CM/Meig-CM -s %s &", strAPN.c_str());
|
||||||
system(szquectel);
|
// system(szquectel);
|
||||||
#endif
|
// #endif
|
||||||
#endif
|
// #endif
|
||||||
#endif
|
// #endif
|
||||||
#ifdef WIFI_MODULE
|
// #ifdef WIFI_MODULE
|
||||||
zlog_warn(zct, "WiFi reset!");
|
// zlog_warn(zct, "WiFi reset!");
|
||||||
#ifdef IMX6UL_GATEWAY
|
// #ifdef IMX6UL_GATEWAY
|
||||||
gpio_set(GlobalConfig::GPIO_G.wifiReset, 0);
|
// gpio_set(GlobalConfig::GPIO_G.wifiReset, 0);
|
||||||
sleep(5);
|
// sleep(5);
|
||||||
gpio_set(GlobalConfig::GPIO_G.wifiReset, 1);
|
// gpio_set(GlobalConfig::GPIO_G.wifiReset, 1);
|
||||||
sleep(5);
|
// sleep(5);
|
||||||
wifi::WPAClient wpa;
|
// wifi::WPAClient wpa;
|
||||||
wpa.ReconnectWiFi();
|
// wpa.ReconnectWiFi();
|
||||||
system("/etc/init.d/wpa_restart");
|
// system("/etc/init.d/wpa_restart");
|
||||||
system("udhcpc -i wlan2 &");
|
// system("udhcpc -i wlan2 &");
|
||||||
#endif
|
// #endif
|
||||||
#ifdef G2UL_GATEWAY
|
// #ifdef G2UL_GATEWAY
|
||||||
system("/etc/init.d/wpa_restart");
|
// system("/etc/init.d/wpa_restart");
|
||||||
sleep(5);
|
// sleep(5);
|
||||||
string strip = GetGwIp_("wlan0");
|
// string strip = GetGwIp_("wlan0");
|
||||||
print_info("strip = %s\n", strip.c_str());
|
// print_info("strip = %s\n", strip.c_str());
|
||||||
if (strip.compare("0.0.0.0") != 0) {
|
// if (strip.compare("0.0.0.0") != 0) {
|
||||||
} else {
|
// } else {
|
||||||
gpio_set(GlobalConfig::GPIO_G.wifiReset, 1);
|
// gpio_set(GlobalConfig::GPIO_G.wifiReset, 1);
|
||||||
sleep(5);
|
// sleep(5);
|
||||||
gpio_set(GlobalConfig::GPIO_G.wifiReset, 0);
|
// gpio_set(GlobalConfig::GPIO_G.wifiReset, 0);
|
||||||
sleep(30);
|
// sleep(30);
|
||||||
wifi::WPAClient wpa;
|
// wifi::WPAClient wpa;
|
||||||
wpa.ReconnectWiFi();
|
// wpa.ReconnectWiFi();
|
||||||
system("/etc/init.d/wpa_restart");
|
// system("/etc/init.d/wpa_restart");
|
||||||
sleep(5);
|
// sleep(5);
|
||||||
system("udhcpc -b -i wlan0 &");
|
// system("udhcpc -b -i wlan0 &");
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
#endif
|
// #endif
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (HardStatus == 3600) { // one hour 3600
|
if (HardStatus == 3600) { // one hour 3600
|
||||||
JsonData jd;
|
JsonData jd;
|
||||||
std::string data = jd.JsonCmd_07();
|
std::string data = jd.JsonCmd_07();
|
||||||
|
|||||||
124
uart/uart.cpp
124
uart/uart.cpp
@ -16,6 +16,7 @@
|
|||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include "mqttclient/mqtt_client.h"
|
#include "mqttclient/mqtt_client.h"
|
||||||
#include "utility/serial.h"
|
#include "utility/serial.h"
|
||||||
|
#include "scheduler/schedule.hpp"
|
||||||
|
|
||||||
extern zlog_category_t *zct;
|
extern zlog_category_t *zct;
|
||||||
extern zlog_category_t *zbt;
|
extern zlog_category_t *zbt;
|
||||||
@ -37,54 +38,30 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
|||||||
char head[] = {0xAA, 0x55, 0xAA};
|
char head[] = {0xAA, 0x55, 0xAA};
|
||||||
char szbuffer[BUF_LENGTH] = {0x00};
|
char szbuffer[BUF_LENGTH] = {0x00};
|
||||||
while (1) {
|
while (1) {
|
||||||
if (now_task == kWaveForm) {
|
if (now_task == WAVE_CMD) {
|
||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
ret = read_data(fd, buff, BUF_LENGTH, 10);
|
ret = read_data(fd, buff, BUF_LENGTH, 10);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
if (!bUpdate && !bUpdateconfig) {
|
|
||||||
timeoutflag++;
|
timeoutflag++;
|
||||||
if (timeoutflag > 300) {
|
if (timeoutflag > 300) {
|
||||||
|
DealReviveDuration(wave_shortAddr);
|
||||||
zlog_info(zct, "===============0x9999 timeout= %d offSize = %d===============", timeoutflag, offSize);
|
zlog_info(zct, "===============0x9999 timeout= %d offSize = %d===============", timeoutflag, offSize);
|
||||||
zlog_info(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize);
|
zlog_info(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize);
|
||||||
FindRecvPackage(offSize, mUartRecvTmpBuf, head);
|
FindRecvPackage(offSize, mUartRecvTmpBuf, head);
|
||||||
|
|
||||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
||||||
now_task = -1;
|
now_task = -1;
|
||||||
|
wave_shortAddr = 0;
|
||||||
timeoutflag = 0;
|
timeoutflag = 0;
|
||||||
offSize = 0;
|
offSize = 0;
|
||||||
maxSize = 0;
|
maxSize = 0;
|
||||||
tcflush(fd, TCIFLUSH);
|
tcflush(fd, TCIFLUSH);
|
||||||
bModifyAddr = true;
|
|
||||||
modify_LocalAddr(0x8888);
|
|
||||||
bSendTimeStamp = false;
|
|
||||||
mssleep(10000);
|
mssleep(10000);
|
||||||
wave_trans_ = true;
|
wave_trans_ = true;
|
||||||
memset(mUartRecvTmpBuf, 0, BUF_LENGTH);
|
memset(mUartRecvTmpBuf, 0, BUF_LENGTH);
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
|
||||||
|
|
||||||
zlog_info(zct, "wave end");
|
zlog_info(zct, "wave end");
|
||||||
}
|
}
|
||||||
mssleep(10000);
|
mssleep(10000);
|
||||||
} else if (bUpdatePre || (bUpdateconfig && GlobalConfig::EnterZigBeeWaveTransmittingCnt_G > 15)) {
|
|
||||||
timeoutflag++;
|
|
||||||
if (timeoutflag > 300) {
|
|
||||||
zlog_info(zct, "bUpdateconfig %d===============", timeoutflag);
|
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
|
||||||
timeoutflag = 0;
|
|
||||||
offSize = 0;
|
|
||||||
maxSize = 0;
|
|
||||||
bUpdate = false;
|
|
||||||
bUpdatePre = false;
|
|
||||||
bUpdateconfig = false;
|
|
||||||
bModifyAddr = true;
|
|
||||||
bSendTimeStamp = false;
|
|
||||||
modify_LocalAddr(0x8888);
|
|
||||||
mssleep(10000);
|
|
||||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
|
||||||
}
|
|
||||||
mssleep(10000);
|
|
||||||
}
|
|
||||||
} else if (ret > 0) {
|
} else if (ret > 0) {
|
||||||
maxSize += ret;
|
maxSize += ret;
|
||||||
|
|
||||||
@ -108,16 +85,11 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
|||||||
offSize = 0;
|
offSize = 0;
|
||||||
maxSize = 0;
|
maxSize = 0;
|
||||||
tcflush(fd, TCIOFLUSH);
|
tcflush(fd, TCIOFLUSH);
|
||||||
bModifyAddr = true;
|
|
||||||
modify_LocalAddr(0x8888);
|
|
||||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ((unsigned short)GlobalConfig::Zigbee_G.MyAddr == 0x8888) {
|
} else {
|
||||||
#ifdef IMX6UL_GATEWAY
|
#ifdef IMX6UL_GATEWAY
|
||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
ret = read_data(fd, buff, BUF_LENGTH, 50);
|
ret = read_data(fd, buff, BUF_LENGTH, 50);
|
||||||
@ -177,6 +149,7 @@ Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) {
|
|||||||
memset(mUartRecvTmpBuf, 0, BUF_LENGTH);
|
memset(mUartRecvTmpBuf, 0, BUF_LENGTH);
|
||||||
bTest = false;
|
bTest = false;
|
||||||
TestFd = 0;
|
TestFd = 0;
|
||||||
|
wave_shortAddr = 0;
|
||||||
DataNodeUpdateFile = "";
|
DataNodeUpdateFile = "";
|
||||||
strTimetamp = "";
|
strTimetamp = "";
|
||||||
bZigbeeSinal = false;
|
bZigbeeSinal = false;
|
||||||
@ -393,13 +366,48 @@ void int2bytes(int i, unsigned char *bytes, int size) {
|
|||||||
bytes[3] = (unsigned char)((0xff000000 & i) >> 24);
|
bytes[3] = (unsigned char)((0xff000000 & i) >> 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Uart::DealAskTask(unsigned short ushortAdd){
|
int Uart::DealAskTask(uint16_t ushortAdd){
|
||||||
|
|
||||||
|
ModifyDistAddr(ushortAdd);
|
||||||
|
int next_duration = 0;
|
||||||
|
int taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration);
|
||||||
|
ScheduleTask scheduleTask;
|
||||||
|
if (taskID == kScheduleEigenValue) //1.特征值
|
||||||
|
{
|
||||||
|
char localtimestamp[32] = {0x00};
|
||||||
|
int millisecond = 0;
|
||||||
|
std::string rtcTime = GetRTC(localtimestamp, millisecond);
|
||||||
|
scheduleTask.cmd = MEAS_EVAL;
|
||||||
|
scheduleTask.shortAddr = ushortAdd;
|
||||||
|
scheduleTask.timeStamp = atoi(localtimestamp);
|
||||||
|
TaskResp(scheduleTask);
|
||||||
|
}
|
||||||
|
else if (taskID == kScheduleWaveForm) //2.波形
|
||||||
|
{
|
||||||
|
now_task = WAVE_CMD;
|
||||||
|
scheduleTask.cmd = WAVE_CMD;
|
||||||
|
scheduleTask.shortAddr = ushortAdd;
|
||||||
|
wave_shortAddr = ushortAdd;
|
||||||
|
TaskResp(scheduleTask);
|
||||||
|
}
|
||||||
|
else if (taskID == kScheduleUpgrade) //3.升级
|
||||||
|
{
|
||||||
|
scheduleTask.cmd = UPGRADE;
|
||||||
|
scheduleTask.shortAddr = ushortAdd;
|
||||||
|
TaskResp(scheduleTask);
|
||||||
|
}else if (taskID == kScheduleConfigSensor) //4.更新配置
|
||||||
|
{
|
||||||
|
scheduleTask.cmd = CONFIG;
|
||||||
|
scheduleTask.shortAddr = ushortAdd;
|
||||||
|
TaskResp(scheduleTask);
|
||||||
|
}else if (taskID == kScheduleWrongTime) //5.异常连接
|
||||||
|
{
|
||||||
|
scheduleTask.cmd = REVIVE_DURATION;
|
||||||
|
scheduleTask.shortAddr = ushortAdd;
|
||||||
|
scheduleTask.duration = next_duration;
|
||||||
|
TaskResp(scheduleTask);
|
||||||
|
}
|
||||||
|
|
||||||
//1.特征值
|
|
||||||
//2.波形
|
|
||||||
now_task = kWaveForm;
|
|
||||||
//3.升级
|
|
||||||
//4.更新配置
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,6 +416,13 @@ int Uart::DealException(const char* pData){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Uart::DealReviveDuration(uint16_t ushortAdd){
|
int Uart::DealReviveDuration(uint16_t ushortAdd){
|
||||||
|
|
||||||
|
ScheduleTask scheduleTask;
|
||||||
|
uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd);
|
||||||
|
scheduleTask.cmd = REVIVE_DURATION;
|
||||||
|
scheduleTask.shortAddr = ushortAdd;
|
||||||
|
scheduleTask.duration = next_duration;
|
||||||
|
TaskResp(scheduleTask);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,28 +447,27 @@ void Uart::DealRecvData(const char *pData) {
|
|||||||
}
|
}
|
||||||
zlog_info(zct, "shortAdd = %d,command = %d,recvcode = %d ",ushortAdd,command,recvcode);
|
zlog_info(zct, "shortAdd = %d,command = %d,recvcode = %d ",ushortAdd,command,recvcode);
|
||||||
switch (command) {
|
switch (command) {
|
||||||
// case 1: { // 0x01:设备信息
|
case DEVICE_INF: {
|
||||||
// DealDataNodeInfo(pData);
|
DealDataNodeInfo(pData);
|
||||||
// } break;
|
} break;
|
||||||
// case 7: {
|
case DEVICE_INF2: {
|
||||||
// DealDataNodeName(pData);
|
DealDataNodeName(pData);
|
||||||
// } break;
|
} break;
|
||||||
case kAskTask:
|
case ASK_TASK:
|
||||||
DealAskTask(ushortAdd);
|
DealAskTask(ushortAdd);
|
||||||
break;
|
break;
|
||||||
case kException:
|
case DEVICE_EXCEPTION:
|
||||||
DealException(pData);
|
DealException(pData);
|
||||||
break;
|
break;
|
||||||
case kEigenValue:
|
case MEAS_EVAL:
|
||||||
DealDataNodeFeature(pData, 0);
|
DealDataNodeFeature(pData, 0);
|
||||||
break;
|
|
||||||
case kReviveDuration:
|
|
||||||
DealReviveDuration(ushortAdd);
|
DealReviveDuration(ushortAdd);
|
||||||
break;
|
break;
|
||||||
case kConfig:
|
case CONFIG:
|
||||||
DealConfig(ushortAdd);
|
DealConfig(ushortAdd);
|
||||||
|
DealReviveDuration(ushortAdd);
|
||||||
break;
|
break;
|
||||||
case kUpgrade:
|
case UPGRADE:
|
||||||
UpdateWirelessNode(ushortAdd);
|
UpdateWirelessNode(ushortAdd);
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
@ -936,7 +950,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (now_task == kWaveForm && (command == 3 || command == 4 || command == 5)) {
|
if (now_task == WAVE_CMD && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z)) {
|
||||||
if (!CheckCrc(&UartRecvBuf[i], 99)) {
|
if (!CheckCrc(&UartRecvBuf[i], 99)) {
|
||||||
m_TimeStamp = 0;
|
m_TimeStamp = 0;
|
||||||
mPackgeIndex = -1;
|
mPackgeIndex = -1;
|
||||||
@ -977,7 +991,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
}
|
}
|
||||||
memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100);
|
memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100);
|
||||||
DealDataNodeWave(RecvBuf, command);
|
DealDataNodeWave(RecvBuf, command);
|
||||||
} else if (now_task != kWaveForm && (command == 1 || command == 4 || command == 11 || command == 21 || command == 22 || command == 24)) {
|
} 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)) {
|
||||||
char RecvBuf[100] = {0x00};
|
char RecvBuf[100] = {0x00};
|
||||||
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
||||||
if (!CheckCrc(RecvBuf, 99)) {
|
if (!CheckCrc(RecvBuf, 99)) {
|
||||||
|
|||||||
@ -13,23 +13,20 @@ typedef void (*pTestRecvCallBack)(int Status);
|
|||||||
|
|
||||||
// 无关网关与传感器交互命令 1 ~ 255
|
// 无关网关与传感器交互命令 1 ~ 255
|
||||||
enum InteractiveCommand {
|
enum InteractiveCommand {
|
||||||
// 传感器发给网关
|
|
||||||
kAskTask = 1, // 请求任务
|
|
||||||
kReviveConfig = 2, // 请求基本的复活配置, 使用新的传感器时
|
|
||||||
kVersionInfo = 3, // 版本信息
|
|
||||||
kException = 4, // 异常: 外设
|
|
||||||
|
|
||||||
// 交互命令
|
ASK_TASK = 1, // 请求任务 只从传感器发出
|
||||||
kEigenValue = 11, // 特征值
|
DEVICE_INF = 2, // 上线发送通道配置,版本信息, 会收到REVIVE_DURATION = 8,
|
||||||
kWaveForm = 12, // 波形
|
MEAS_EVAL = 3, // 特征值 校时信息带给传感器
|
||||||
// kBatteryLevel = 14, // 电池电量 特征值里面带
|
WAVE_CMD = 4, // 只从无线网关发出,x,y,z
|
||||||
|
WAVE_X = 5, // 只从传感器发出
|
||||||
// 网关发给传感器
|
WAVE_Y = 6, // 只从传感器发出
|
||||||
kReviveDuration = 21, // 复活时长
|
WAVE_Z = 7, // 只从传感器发出
|
||||||
kConfig = 22, // 配置
|
REVIVE_DURATION = 8, // 复活时长
|
||||||
// kExecuteTask = 23, // 需要无线传感器执行的任务
|
CONFIG = 9, // 配置 只从无线网关发出
|
||||||
kUpgrade = 24, // 升级
|
UPGRADE = 10, // 升级, 升级给这条信息
|
||||||
kSignalStrength = 25, // 信号强度
|
DEVICE_INF2 = 11, // 测点名称,测点编号
|
||||||
|
SIGNAL_STRENGTH = 12, // 信号强度
|
||||||
|
DEVICE_EXCEPTION = 13, // 异常: 外设
|
||||||
};
|
};
|
||||||
// 无线传感器请求任务
|
// 无线传感器请求任务
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -115,7 +112,8 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
uint16_t shortAddr;
|
uint16_t shortAddr;
|
||||||
uint8_t to_exec_cmd; // 需要传感器立即执行的任务
|
uint16_t duration;
|
||||||
|
uint32_t timeStamp;
|
||||||
} ScheduleTask;
|
} ScheduleTask;
|
||||||
|
|
||||||
// 升级任务
|
// 升级任务
|
||||||
@ -157,7 +155,7 @@ public:
|
|||||||
int UartRecv(int fd, char srcshow, char* buffer);
|
int UartRecv(int fd, char srcshow, char* buffer);
|
||||||
int FindRecvPackage(int bytesRead, char* mUartRecvBuf, char* head);
|
int FindRecvPackage(int bytesRead, char* mUartRecvBuf, char* head);
|
||||||
|
|
||||||
int DealAskTask(unsigned short ushortAdd);
|
int DealAskTask(uint16_t ushortAdd);
|
||||||
int DealException(const char* pData);
|
int DealException(const char* pData);
|
||||||
int DealReviveDuration(uint16_t ushortAdd);
|
int DealReviveDuration(uint16_t ushortAdd);
|
||||||
int DealConfig(uint16_t ushortAdd);
|
int DealConfig(uint16_t ushortAdd);
|
||||||
@ -178,6 +176,7 @@ public:
|
|||||||
void modify_distaddr_info(unsigned short id, char* zigbee, unsigned char* distAddr);
|
void modify_distaddr_info(unsigned short id, char* zigbee, unsigned char* distAddr);
|
||||||
void modify_LocalAddr(unsigned short id);
|
void modify_LocalAddr(unsigned short id);
|
||||||
void modify_DistAddr(unsigned char* distAddr);
|
void modify_DistAddr(unsigned char* distAddr);
|
||||||
|
void ModifyDistAddr(uint16_t distAddr);
|
||||||
void modify_Localchannel(unsigned char pad);
|
void modify_Localchannel(unsigned char pad);
|
||||||
void modify_LocalPanID(unsigned short padID);
|
void modify_LocalPanID(unsigned short padID);
|
||||||
void getZigbeeSignal(unsigned char* distAddr);
|
void getZigbeeSignal(unsigned char* distAddr);
|
||||||
@ -222,6 +221,7 @@ private:
|
|||||||
std::string strTimetamp;
|
std::string strTimetamp;
|
||||||
|
|
||||||
std::string m_strDestShortAddr;
|
std::string m_strDestShortAddr;
|
||||||
|
uint16_t wave_shortAddr;
|
||||||
int now_task;
|
int now_task;
|
||||||
|
|
||||||
int waittime;
|
int waittime;
|
||||||
|
|||||||
@ -41,6 +41,18 @@ void Uart::modify_DistAddr(unsigned char *distAddr) {
|
|||||||
command[5] = distAddr[1];
|
command[5] = distAddr[1];
|
||||||
WriteToUart(command, 6);
|
WriteToUart(command, 6);
|
||||||
}
|
}
|
||||||
|
void Uart::ModifyDistAddr(uint16_t distAddr){
|
||||||
|
char command[6] = {0x00};
|
||||||
|
memset(command, 0x00, sizeof(command));
|
||||||
|
command[0] = 0xDE;
|
||||||
|
command[1] = 0xDF;
|
||||||
|
command[2] = 0xEF;
|
||||||
|
command[3] = 0xD2;
|
||||||
|
command[4] = (distAddr >> 8) & 0xFF;
|
||||||
|
command[5] = distAddr & 0xFF;
|
||||||
|
WriteToUart(command, 6);
|
||||||
|
}
|
||||||
|
|
||||||
void Uart::modify_LocalAddr(unsigned short id) {
|
void Uart::modify_LocalAddr(unsigned short id) {
|
||||||
char command[6] = {0x00};
|
char command[6] = {0x00};
|
||||||
command[0] = 0xDE;
|
command[0] = 0xDE;
|
||||||
|
|||||||
@ -528,8 +528,18 @@ int Uart::TaskResp(ScheduleTask scheduleTask){
|
|||||||
UpdateData[4] = scheduleTask.shortAddr & 0xFF;
|
UpdateData[4] = scheduleTask.shortAddr & 0xFF;
|
||||||
UpdateData[5] = scheduleTask.cmd & 0xFF;
|
UpdateData[5] = scheduleTask.cmd & 0xFF;
|
||||||
UpdateData[6] = 0x00;
|
UpdateData[6] = 0x00;
|
||||||
UpdateData[7] = scheduleTask.to_exec_cmd & 0xFF;
|
if (scheduleTask.cmd == REVIVE_DURATION)
|
||||||
|
{
|
||||||
|
UpdateData[7] = (scheduleTask.duration >> 8) & 0xFF;
|
||||||
|
UpdateData[8] = scheduleTask.duration & 0xFF;
|
||||||
|
}
|
||||||
|
if (scheduleTask.cmd == MEAS_EVAL)
|
||||||
|
{
|
||||||
|
UpdateData[9] = UINT32_LOW_2(scheduleTask.timeStamp);
|
||||||
|
UpdateData[10] = UINT32_LOW_1(scheduleTask.timeStamp);
|
||||||
|
UpdateData[11] = UINT32_HIGH_2(scheduleTask.timeStamp);
|
||||||
|
UpdateData[12] = UINT32_HIGH_1(scheduleTask.timeStamp);
|
||||||
|
}
|
||||||
unsigned char tmp = 0x00;
|
unsigned char tmp = 0x00;
|
||||||
for (int k = 0; k < 99; k++) {
|
for (int k = 0; k < 99; k++) {
|
||||||
tmp += UpdateData[k];
|
tmp += UpdateData[k];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user