fix web and rssi save and config bugs
This commit is contained in:
parent
b1a3332d6f
commit
658de5c5ef
@ -81,7 +81,7 @@ std::string GetLocalTimeWithMs(void) {
|
||||
snprintf(currentTime, sizeof(currentTime), "%s%03d", buffer, milli);
|
||||
return currentTime;
|
||||
} catch (...) {
|
||||
zlog_error(zct, "GetLocalTimeWithMs failed, use default time");
|
||||
zlog_warn(zct, "GetLocalTimeWithMs failed, use default time");
|
||||
return defaultTime;
|
||||
}
|
||||
}
|
||||
@ -92,13 +92,13 @@ int code_convert(const char *from_charset, const char *to_charset, char *inbuf,
|
||||
char **pout = &outbuf;
|
||||
cd = iconv_open(to_charset, from_charset);
|
||||
if (cd == 0) {
|
||||
zlog_error(zct, "iconv_open failed");
|
||||
zlog_warn(zct, "iconv_open failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(outbuf, 0, outlen);
|
||||
if ((int)iconv(cd, pin, &inlen, pout, &outlen) == -1) {
|
||||
zlog_error(zct, "iconv failed");
|
||||
zlog_warn(zct, "iconv failed");
|
||||
iconv_close(cd);
|
||||
return -2;
|
||||
}
|
||||
@ -113,13 +113,13 @@ int InitGpio(unsigned int gpioN, unsigned int inout) {
|
||||
//闂傚倷鑳堕幊鎾绘倶濮樿泛绠伴柛婵<E69F9B>?劜椤洟鏌熸潏鈺佲偓宄闂備浇宕<E6B587>?慨鎶芥倿閿曞倸纾块柟璺哄閸<EE979E>?剦鏁嗛柛鏇ㄥ亝椤ユ繈姊洪幖鐐插姷闂傚<E99782>?瀚伴、鏇㈡晸閿燂<E996BF>?
|
||||
fd = open("/sys/class/gpio/export", O_WRONLY);
|
||||
if (-1 == fd) {
|
||||
zlog_error(zbt, "open gpio export file error");
|
||||
zlog_warn(zbt, "open gpio export file error");
|
||||
return 1;
|
||||
}
|
||||
//闂傚倷鐒﹂惇褰掑垂瑜版帗鍋柛銉墻閺佸鏌i悙<EFBD89>?<3F>?紬io
|
||||
sprintf(tmp, "%d", gpioN);
|
||||
if (write(fd, tmp, strlen(tmp)) < 0) {
|
||||
zlog_error(zbt, "write file operation error:%s", tmp);
|
||||
zlog_warn(zbt, "write file operation error:%s", tmp);
|
||||
close(fd);
|
||||
return 2;
|
||||
}
|
||||
@ -169,7 +169,7 @@ int InitGpio(unsigned int gpioN, unsigned int inout) {
|
||||
zlog_info(zbt, "open GPIO = %s", tmp);
|
||||
fd = open(tmp, O_WRONLY);
|
||||
if (-1 == fd) {
|
||||
zlog_error(zbt, "open gpio direction file error");
|
||||
zlog_warn(zbt, "open gpio direction file error");
|
||||
close(fd);
|
||||
return 3;
|
||||
}
|
||||
@ -177,14 +177,14 @@ int InitGpio(unsigned int gpioN, unsigned int inout) {
|
||||
if (inout == 0) {
|
||||
zlog_info(zbt, "=====InitGpio=====in");
|
||||
if (-1 == write(fd, "in", sizeof("in"))) {
|
||||
zlog_error(zbt, "[%d]write operation direction error", gpioN);
|
||||
zlog_warn(zbt, "[%d]write operation direction error", gpioN);
|
||||
close(fd);
|
||||
return 4;
|
||||
}
|
||||
} else if (inout == 1) {
|
||||
zlog_info(zbt, "=====InitGpio=====out");
|
||||
if (-1 == write(fd, "out", sizeof("out"))) {
|
||||
zlog_error(zbt, "[%d]write operation direction error", gpioN);
|
||||
zlog_warn(zbt, "[%d]write operation direction error", gpioN);
|
||||
close(fd);
|
||||
return 5;
|
||||
}
|
||||
@ -237,20 +237,20 @@ int gpio_set(unsigned int gpioN, char x) {
|
||||
//闂傚倷鑳堕幊鎾绘倶濮樿泛绠伴柛婵<E69F9B>?劜椤洟鏌熸潏鈺佲偓宄 value闂傚倷绀侀幖<E4BE80>?<3F>﹀磹缁<E7A3B9>?5娲晲閸涱亝鐎婚梺璺ㄥ櫐閹凤拷
|
||||
fd = open(tmp, O_WRONLY);
|
||||
if (-1 == fd) {
|
||||
zlog_error(zbt, "[%s] open gpio export file error", tmp);
|
||||
zlog_warn(zbt, "[%s] open gpio export file error", tmp);
|
||||
close(fd);
|
||||
return (-1);
|
||||
}
|
||||
//闂備浇宕<E6B587>?慨宕囩矆娴h娅犲ù鐘<C3B9>?儐閸嬵亪鏌涢埄鍐<E98D90>?<3F>闁稿鍔戝濠<EE9D8F>?醇閻旂儤鍒涢梺褰掓交閹凤<E996B9>?
|
||||
if (x) {
|
||||
if (-1 == write(fd, "1", sizeof("1"))) {
|
||||
zlog_error(zbt, "%d write operation value error", gpioN);
|
||||
zlog_warn(zbt, "%d write operation value error", gpioN);
|
||||
close(fd);
|
||||
return (-2);
|
||||
}
|
||||
} else {
|
||||
if (-1 == write(fd, "0", sizeof("0"))) {
|
||||
zlog_error(zbt, "%d write operation value errorn", gpioN);
|
||||
zlog_warn(zbt, "%d write operation value errorn", gpioN);
|
||||
close(fd);
|
||||
return (-3);
|
||||
}
|
||||
@ -305,12 +305,12 @@ int gpio_read(unsigned int gpioN) {
|
||||
//闂傚倷鑳堕幊鎾绘倶濮樿泛绠伴柛婵<E69F9B>?劜椤洟鏌熸潏鈺佲偓宄 value闂傚倷绀侀幖<E4BE80>?<3F>﹀磹缁<E7A3B9>?5娲晲閸涱亝鐎婚梺璺ㄥ櫐閹凤拷
|
||||
fd = open(tmp, O_RDONLY);
|
||||
if (-1 == fd) {
|
||||
zlog_error(zbt, "%d open gpio export file error", gpioN);
|
||||
zlog_warn(zbt, "%d open gpio export file error", gpioN);
|
||||
return (-1);
|
||||
}
|
||||
//闂備浇宕<E6B587>?慨鏉懨洪埡鍜佹晪鐟滄垿濡甸幇鐗堟櫢闁跨噦鎷<E599A6> value闂傚倷绀侀幖<E4BE80>?<3F>﹀磹缁<E7A3B9>?5娲晲閸涱亝鐎婚梺璺ㄥ櫐閹凤拷
|
||||
if (-1 == read(fd, &value, sizeof(value))) {
|
||||
zlog_error(zbt, "%d read gpiovalue is fail", gpioN);
|
||||
zlog_warn(zbt, "%d read gpiovalue is fail", gpioN);
|
||||
close(fd);
|
||||
return (-2);
|
||||
}
|
||||
@ -321,7 +321,7 @@ int gpio_read(unsigned int gpioN) {
|
||||
int config_uart(const char *port, int speed) {
|
||||
int iFd = open(port, O_RDWR | O_NOCTTY);
|
||||
if (iFd < 0) {
|
||||
zlog_error(zbt, "open port:%s failed", port);
|
||||
zlog_warn(zbt, "open port:%s failed", port);
|
||||
return -1;
|
||||
}
|
||||
struct termios opt;
|
||||
|
||||
@ -310,7 +310,8 @@ struct Param_58 {
|
||||
int waveInterVal;
|
||||
int waveInterTime;
|
||||
int maxSensorNum;
|
||||
Param_58() : mMode(0),featureInterVal(0),featureInterTime(0),waveInterVal(0),waveInterTime(0),maxSensorNum(0){};
|
||||
int sensorCount;
|
||||
Param_58() : mMode(0),featureInterVal(0),featureInterTime(0),waveInterVal(0),waveInterTime(0),maxSensorNum(0),sensorCount(0){};
|
||||
};
|
||||
|
||||
struct Param_59 {
|
||||
|
||||
@ -265,13 +265,14 @@ void SqliteDB::Createtable(const char *ptableName) {
|
||||
void SqliteDB::SqliteInitDel(const char *pDbName) {
|
||||
Deletetable(T_DATA_INFO(TNAME));
|
||||
Deletetable(T_DATASTATIC_INFO(TNAME));
|
||||
vec_t vecResult = GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), T_SENSOR_INFO(ZIGBEELONGADDR), NULL);
|
||||
vec_t vecResult = GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), " MeasurementID ", NULL);
|
||||
for (size_t i = 0; i < vecResult.size() && vecResult.size() > 0; i++) {
|
||||
char sztableName[100] = {0x00};
|
||||
sprintf(sztableName, "t_data_%s", vecResult[i].c_str());
|
||||
Deletetable(sztableName);
|
||||
sprintf(sztableName, "t_dataStatic_%s", vecResult[i].c_str());
|
||||
Deletetable(sztableName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -535,7 +535,7 @@ void JsonData::DataNodeStatusCheck() {
|
||||
int lTimeTemp = lNowTime - llastTime;
|
||||
lTimeTemp = abs(lTimeTemp);
|
||||
if (lTimeTemp > onlineCheck) {
|
||||
zlog_info(zct, "offline DataNodeStatusCheck lNowTime = %d,llastTime = %d,interval = %s", lNowTime, llastTime, vetRes[i][21].c_str());
|
||||
zlog_warn(zct, "offline DataNodeStatusCheck DataNodeNo = %s lNowTime = %d,llastTime = %d,interval = %s", strDataNodeNo.c_str(),lNowTime, llastTime, vetRes[i][21].c_str());
|
||||
char whereCon[32] = {0};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), "status='0'", whereCon);
|
||||
|
||||
@ -77,7 +77,7 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 ¶m) {
|
||||
jsonVal["cmd"] = "02";
|
||||
if (0 == param.mMode) {
|
||||
jsonVal["type"] = "SET";
|
||||
if (param.mMode == 0) { //本地校时
|
||||
if (param.mSetType == 0) { //本地校时
|
||||
unsigned long set_timestamp = (unsigned long)param.mTimeStamp;
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
@ -92,13 +92,20 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 ¶m) {
|
||||
} else {
|
||||
zlog_warn(zct, "diff seconds:%ld lesser than 5, not to modify", diff_seconds);
|
||||
}
|
||||
} else if (param.mMode == 1) { //与服务器校时
|
||||
} else if (param.mSetType == 1) { //与服务器校时
|
||||
char buf[256] = {0};
|
||||
sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str());
|
||||
std::string str = std::string(buf);
|
||||
data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
}
|
||||
}else if (1 == param.mMode) {
|
||||
char localtimestamp[32] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
std::string nowTimetamp = std::string(localtimestamp);
|
||||
jsonVal["type"] = "GET";
|
||||
jsonVal["timeStamp"] = atoi(nowTimetamp.c_str());
|
||||
}
|
||||
jsonVal["timezone"] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "timezone");
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
|
||||
@ -236,7 +236,6 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATA_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATANODE_TIME(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_BATTERY_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
@ -248,8 +247,11 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", param.mDataNodeNo.c_str());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
|
||||
scheduler::instance().ClearScheduleCfg(atoi(param.mShortAddr.c_str()));
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(param.mShortAddr.c_str(), &end_ptr, 16);
|
||||
zlog_warn(zct,"delete short_addr = %02x%02x",UINT16_HIGH(short_addr),UINT16_LOW(short_addr));
|
||||
scheduler::instance().ClearScheduleCfg(short_addr);
|
||||
|
||||
} else if (param.mDataNodeNo.length() > 0 && param.mType == "CORRECT") {
|
||||
char updateSql[1024] = {0};
|
||||
@ -671,6 +673,23 @@ std::string JsonData::JsonCmd_Cgi_41(std::vector<Param_41> ¶m, int isServer)
|
||||
char updateSql[1024] = {0};
|
||||
|
||||
for (size_t i = 0; i < param.size(); i++) {
|
||||
|
||||
if (!isServer)
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param[i].mdataNodeNo.c_str());
|
||||
else
|
||||
sprintf(whereCon, "MeasurementID ='%s'", param[i].mdataNodeNo.c_str());
|
||||
|
||||
std::string zigbeeShortAddr = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", whereCon);
|
||||
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(zigbeeShortAddr.c_str(), &end_ptr, 16);
|
||||
int res = scheduler::instance().UpdateSensorConfig(short_addr);
|
||||
if (res != 0){
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "update error";
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
char dataNodeName[100] = {0x00};
|
||||
hexToAscii(param[i].mdataNodeName.c_str(), dataNodeName);
|
||||
zlog_info(zct, "str = %s", dataNodeName);
|
||||
@ -687,12 +706,6 @@ std::string JsonData::JsonCmd_Cgi_41(std::vector<Param_41> ¶m, int isServer)
|
||||
param[i].ZigbeePower, param[i].ZigbeeRetry, param[i].mfeatureInterVal, param[i].mwaveInterVal, param[i].mrange, param[i].msamplingRate, param[i].mAccSampleTime, param[i].mstartBrands.c_str(), param[i].mstopBrands.c_str(), param[i].menvelopeBandPass.c_str(),
|
||||
param[i].mviff, param[i].mfaultFrequency.c_str(), param[i].mMeasurementID.c_str(), param[i].nodeWaveSend.c_str());
|
||||
}
|
||||
scheduler::instance().UpdateSensorConfig(atoi(param[i].mShortAddr.c_str()));
|
||||
if (!isServer)
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param[i].mdataNodeNo.c_str());
|
||||
else
|
||||
sprintf(whereCon, "MeasurementID ='%s'", param[i].mdataNodeNo.c_str());
|
||||
|
||||
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
|
||||
@ -110,7 +110,7 @@ std::string JsonData::JsonCmd_Cgi_50() {
|
||||
if (reader.parse(is, root)) {
|
||||
jsBody["sensor"] = root;
|
||||
}
|
||||
jsBody["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
|
||||
jsBody["GateWayVersion"] = GlobalConfig::Version;
|
||||
jsBody["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
||||
jsBody["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
||||
jsonVal["content"] = jsBody;
|
||||
@ -154,7 +154,13 @@ std::string JsonData::JsonCmd_Cgi_52(Param_52 ¶m) {
|
||||
jsonVal["cmdSerial"] = param.mCmdSerial;
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
|
||||
#ifndef WIFI_MODULE
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = " ";
|
||||
jsonVal["enable"] = false;
|
||||
return show_value_.write(jsonVal);
|
||||
#endif
|
||||
jsonVal["enable"] = true;
|
||||
if (0 == param.mMode) { // 扫描
|
||||
wifi::WPAClient wpa;
|
||||
std::string netssid = wpa.GetNetSsid();
|
||||
@ -512,13 +518,14 @@ std::string JsonData::JsonCmd_Cgi_58(Param_58 ¶m) {
|
||||
jsonVal[JSON_FIELD_CMD] = "58";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
int ret = 0;
|
||||
int ret = 0,sensorCount = 0;
|
||||
std::string error_msg = "";
|
||||
if (param.mMode == 1)
|
||||
{
|
||||
ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum,error_msg);
|
||||
}else if (param.mMode == 0)
|
||||
{
|
||||
sensorCount = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL);
|
||||
ret = scheduler::instance().GetScheduleConfig(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum);
|
||||
}
|
||||
if (ret == 0)
|
||||
@ -528,6 +535,7 @@ std::string JsonData::JsonCmd_Cgi_58(Param_58 ¶m) {
|
||||
jsBody["waveInterVal"] = param.waveInterVal;
|
||||
jsBody["waveInterTime"] = param.waveInterTime;
|
||||
jsBody["maxSensorNum"] = param.maxSensorNum;
|
||||
jsBody["sensorCount"] = sensorCount;
|
||||
}else{
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = error_msg;
|
||||
@ -543,12 +551,17 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
char table_name[50] ={0};
|
||||
int interval = 0;
|
||||
char sql[1024]={0};
|
||||
int featureInterVal = 0;
|
||||
int featureInterTime = 0;
|
||||
int waveInterVal = 0;
|
||||
int waveInterTime = 0;
|
||||
int maxSensorNum = 0;
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
|
||||
|
||||
if (param.mMode == 1)
|
||||
{
|
||||
sprintf(table_name,"t_dataStatic_%s",param.DataNodeNo.c_str());
|
||||
interval = 10;
|
||||
snprintf(sql, sizeof(sql),
|
||||
"WITH CTE AS ("
|
||||
" SELECT timestamp, "
|
||||
@ -561,11 +574,10 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
||||
"FROM CTE "
|
||||
"WHERE prev_timestamp IS NOT NULL "
|
||||
" AND (timestamp - prev_timestamp) > %d;",
|
||||
table_name,interval);
|
||||
table_name,featureInterVal + 6);
|
||||
}else if (param.mMode == 2)
|
||||
{
|
||||
sprintf(table_name,"t_data_waveSend");
|
||||
interval = 20;
|
||||
snprintf(sql, sizeof(sql),
|
||||
"WITH CTE AS ("
|
||||
" SELECT timestamp, "
|
||||
@ -578,8 +590,7 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
||||
"FROM CTE "
|
||||
"WHERE prev_timestamp IS NOT NULL "
|
||||
" AND (timestamp - prev_timestamp) > %d;",
|
||||
table_name,param.DataNodeNo.c_str(),param.straxis.c_str(),interval);
|
||||
|
||||
table_name,param.DataNodeNo.c_str(),param.straxis.c_str(),waveInterVal + 40);
|
||||
jsonVal["Raxis"] = param.straxis;
|
||||
}
|
||||
|
||||
@ -722,7 +733,15 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16);
|
||||
scheduler::instance().UpgradeSensor(short_addr,std::string(sensor_type),atoi(vecResult[0].c_str()),vecResult[1],std::string(sf_version));
|
||||
int res = scheduler::instance().UpgradeSensor(short_addr,std::string(sensor_type),atoi(vecResult[0].c_str()),vecResult[1],std::string(sf_version));
|
||||
if (res != 0)
|
||||
{
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "UpgradeSensor error";
|
||||
free(buffer);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
}
|
||||
free(buffer);
|
||||
return show_value_.write(jsonVal);
|
||||
@ -793,19 +812,37 @@ std::string JsonData::JsonCmd_Cgi_61(Param_61 ¶m){
|
||||
if (vecRes[i][0] == param.MeasurementID + "-X") {
|
||||
iTem.append(vecRes[i][1]);
|
||||
iTem.append(vecRes[i][2]);
|
||||
if (vecRes[i][3] == "4"){
|
||||
iTem.append("MOSQ_ERR_NO_CONN");
|
||||
}else if (vecRes[i][3] == "14"){
|
||||
iTem.append("MOSQ_ERR_ERRNO");
|
||||
}else{
|
||||
iTem.append(vecRes[i][3]);
|
||||
}
|
||||
jsStaticData["X"].append(iTem);
|
||||
}
|
||||
if (vecRes[i][0] == param.MeasurementID + "-Y") {
|
||||
iTem.append(vecRes[i][1]);
|
||||
iTem.append(vecRes[i][2]);
|
||||
if (vecRes[i][3] == "4"){
|
||||
iTem.append("MOSQ_ERR_NO_CONN");
|
||||
}else if (vecRes[i][3] == "14"){
|
||||
iTem.append("MOSQ_ERR_ERRNO");
|
||||
}else{
|
||||
iTem.append(vecRes[i][3]);
|
||||
}
|
||||
jsStaticData["Y"].append(iTem);
|
||||
}
|
||||
if (vecRes[i][0] == param.MeasurementID + "-Z") {
|
||||
iTem.append(vecRes[i][1]);
|
||||
iTem.append(vecRes[i][2]);
|
||||
if (vecRes[i][3] == "4"){
|
||||
iTem.append("MOSQ_ERR_NO_CONN");
|
||||
}else if (vecRes[i][3] == "14"){
|
||||
iTem.append("MOSQ_ERR_ERRNO");
|
||||
}else{
|
||||
iTem.append(vecRes[i][3]);
|
||||
}
|
||||
jsStaticData["Z"].append(iTem);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,20 +48,20 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
std::string data = jd.JsonCmd_Cgi_01(param);
|
||||
return data;
|
||||
} break;
|
||||
// case kWebTiming: {
|
||||
// Param_02 param;
|
||||
// std::string type = recvBody["type"].asString();
|
||||
// if (0 == type.compare("SET")) {
|
||||
// param.mMode = 0;
|
||||
// param.mTimeStamp = recvBody["timeStamp"].asInt();
|
||||
// param.mSetType = recvBody["setType"].asInt();
|
||||
// } else if (0 == type.compare("GET")) {
|
||||
// param.mMode = 1;
|
||||
// }
|
||||
// JsonData jd;
|
||||
// std::string data = jd.JsonCmd_Cgi_02(param);
|
||||
// return data;
|
||||
// } break;
|
||||
case kWebTiming: {
|
||||
Param_02 param;
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("SET")) {
|
||||
param.mMode = 0;
|
||||
param.mTimeStamp = recvBody["timeStamp"].asInt();
|
||||
param.mSetType = recvBody["setType"].asInt();
|
||||
} else if (0 == type.compare("GET")) {
|
||||
param.mMode = 1;
|
||||
}
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_02(param);
|
||||
return data;
|
||||
} break;
|
||||
case kWebHWStatus: {
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_07();
|
||||
@ -175,6 +175,8 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
case kWebDeleteTransducerInfo: {
|
||||
Param_27 param;
|
||||
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||
param.mShortAddr = recvBody["shortAddr"].asString();
|
||||
param.mMeasurementID = recvBody["MeasurementID"].asString();
|
||||
param.mType = recvBody["type"].asString();
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_27(param);
|
||||
|
||||
6
main.cpp
6
main.cpp
@ -66,8 +66,10 @@ int main(int argc, char *argv[]) {
|
||||
boost::thread uartTestReadTh(TestUart);
|
||||
uartReadTh.detach();
|
||||
|
||||
boost::thread InitModuleReadTh(InitModule);
|
||||
InitModuleReadTh.detach();
|
||||
// boost::thread InitModuleReadTh(InitModule);
|
||||
// InitModuleReadTh.detach();
|
||||
|
||||
InitModule();
|
||||
|
||||
// 休眠2秒,等待串口线程初始化完毕
|
||||
sleep(2);
|
||||
|
||||
@ -221,12 +221,12 @@ int data_publish(const char *str, const char *topic) {
|
||||
ret = mosquitto_publish(mosq, &mid_sent, topic, strlen(base64_aes), base64_aes, ud.topic_qos, false);
|
||||
if (base64_aes != NULL) delete[] base64_aes;
|
||||
if (ret != MOSQ_ERR_SUCCESS) {
|
||||
zlog_error(zct, "fail to send mqtt msg, ret: [%s], topic: %s, str: %s", mosquitto_strerror(ret), topic, str);
|
||||
zlog_error(zct, "fail to send mqtt msg, ret: [%s], topic: %s", mosquitto_strerror(ret), topic);
|
||||
}
|
||||
} else {
|
||||
ret = mosquitto_publish(mosq, &mid_sent, topic, strlen(str), str, ud.topic_qos, false);
|
||||
if (ret != MOSQ_ERR_SUCCESS) {
|
||||
zlog_error(zct, "fail to send mqtt msg, ret: [%s], topic: %s, str: %s", mosquitto_strerror(ret), topic, str);
|
||||
zlog_error(zct, "fail to send mqtt msg, ret: [%s], topic: %s", mosquitto_strerror(ret), topic);
|
||||
}
|
||||
}
|
||||
if (ret != 0) {
|
||||
|
||||
@ -193,9 +193,6 @@ void CheckThread() {
|
||||
std::string strTime = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), "timeStamp", selectCon);
|
||||
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
|
||||
zlog_info(zct, "online check = %ld", lTime);
|
||||
if (lTime > 1800) {
|
||||
zlog_error(zct, "nowTimetamp = %s,lastTime = %s,lTime = %ld", nowTimetamp.c_str(), strTime.c_str(), lTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (7200 == Battery) {
|
||||
|
||||
@ -359,7 +359,14 @@ void Uart::GetLocalZigbeeRSSI(uint16_t ushortAdd){
|
||||
mssleep(10000);
|
||||
}
|
||||
int Uart::DealAskTask(uint16_t ushortAdd){
|
||||
char wherecon[50]={0};
|
||||
sprintf(wherecon, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd));
|
||||
int sensor_count = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), wherecon);
|
||||
|
||||
if (sensor_count < 1) {
|
||||
zlog_warn(zct, "device info not found %02x%02x ", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd));
|
||||
return 1;
|
||||
}
|
||||
ModifyDistAddr(ushortAdd);
|
||||
int next_duration = 0;
|
||||
int taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration);
|
||||
@ -436,7 +443,7 @@ int Uart::DealConfig(uint16_t ushortAdd){
|
||||
char whereCon[1024] = {0};
|
||||
char updateSql[1024] = { 0 };
|
||||
sprintf(updateSql, "UpdateFlag = 1");
|
||||
sprintf(whereCon, "zigbeeShortAddr='%hu'", ushortAdd);
|
||||
sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd));
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
scheduler::instance().UpdateConfigResult(ushortAdd,0);
|
||||
return 0;
|
||||
@ -490,7 +497,7 @@ int Uart::DealSensorRSSI(const char *pData,uint16_t ushortAdd){
|
||||
vec_t vecDataNodeNo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " MeasurementID,RSSI ", whereCon);
|
||||
sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str());
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo='%s'", vecDataNodeNo[0].c_str());
|
||||
sprintf(whereCon, "dataNodeNo='%s' order by timeStamp desc limit 1", vecDataNodeNo[0].c_str());
|
||||
std::string timestamp_last = sqlite_db_ctrl::instance().GetData(tableName, " timeStamp ", whereCon);
|
||||
sprintf(updateSql, "zigbeeSignalNode = '%02d' ",atoi(sensor_rssi));
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
@ -518,9 +525,14 @@ int Uart::DealUpgrade(uint16_t ushortAdd,int status){
|
||||
sprintf(wherecon," zigbeeShortAddr = '%02x%02x' ",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd));
|
||||
sprintf(updateSql, " upgradeStatus = %d", status);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon);
|
||||
|
||||
memset(wherecon,0,sizeof(wherecon));
|
||||
sprintf(wherecon," short_addr = '%02x%02x' ORDER BY start_timestamp DESC LIMIT 1 ",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd));
|
||||
std::string start_timestamp = sqlite_db_ctrl::instance().GetData("firmware_upgrade ", " start_timestamp ", wherecon);
|
||||
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
memset(wherecon,0,sizeof(wherecon));
|
||||
sprintf(wherecon," short_addr = '%02x%02x' AND start_timestamp = ( SELECT start_timestamp FROM firmware_upgrade WHERE short_addr = '%02x%02x' ORDER BY start_timestamp DESC LIMIT 1)",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd),UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd));
|
||||
sprintf(wherecon," short_addr = '%02x%02x' AND start_timestamp = '%s'",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd),start_timestamp.c_str());
|
||||
sprintf(updateSql, " status = %d",status);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(" firmware_upgrade ", updateSql,wherecon);
|
||||
|
||||
@ -553,9 +565,7 @@ void Uart::DealRecvData(const char *pData) {
|
||||
case UPGRADE:
|
||||
if (recvcode == 0){
|
||||
DealUpgrade(ushortAdd,2);
|
||||
zlog_info(zbt, "[UPGRADE SUCCESS]1");
|
||||
scheduler::instance().UpgradeResult(ushortAdd,0);
|
||||
zlog_info(zbt, "[UPGRADE SUCCESS]2");
|
||||
zlog_info(zbt, "[UPGRADE SUCCESS] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
|
||||
}else{
|
||||
DealUpgrade(ushortAdd,3);
|
||||
@ -568,6 +578,7 @@ void Uart::DealRecvData(const char *pData) {
|
||||
DealReviveDuration(ushortAdd);
|
||||
DealConfig(ushortAdd);
|
||||
}else{
|
||||
scheduler::instance().UpdateConfigResult(ushortAdd,recvcode);
|
||||
zlog_warn(zbt, "[CONFIG] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
|
||||
}
|
||||
break;
|
||||
@ -1053,10 +1064,12 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
|
||||
char insertSql[100] = {0x00};
|
||||
char whereCon[50] = {0x00};
|
||||
char error_msg[50] = {0x00};
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'",strShortAddr.c_str());
|
||||
std::string strDataNodeNo = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeNo ", whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strDataNodeNo.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,1,"Index error");
|
||||
sprintf(error_msg,"Index error,command = %d",command);
|
||||
sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strDataNodeNo.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg);
|
||||
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
|
||||
|
||||
break;
|
||||
@ -1082,10 +1095,12 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
g_VecWaveDataZ.clear();
|
||||
char insertSql[100] = {0x00};
|
||||
char whereCon[50] = {0x00};
|
||||
char error_msg[50] = {0x00};
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'",strShortAddr.c_str());
|
||||
std::string strDataNodeNo = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeNo ", whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strDataNodeNo.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,2,"Crc error");
|
||||
sprintf(error_msg,"Crc error,command = %d",command);
|
||||
sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strDataNodeNo.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg);
|
||||
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
|
||||
|
||||
break;
|
||||
@ -1140,7 +1155,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
|
||||
strcat(tmp2, tmp);
|
||||
}
|
||||
zlog_warn(zct, "str = %s", tmp2);
|
||||
zlog_info(zct, "str = %s", tmp2);
|
||||
DealRecvData(RecvBuf);
|
||||
} else if (command == 35) {
|
||||
char signalNode[10] = {0x00};
|
||||
@ -1222,7 +1237,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(tableName,"t_dataStatic_%s",(char*)vecDataNodeNo[0].c_str());
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo='%s'", vecDataNodeNo[0].c_str());
|
||||
sprintf(whereCon, "dataNodeNo='%s' order by timeStamp desc limit 1", vecDataNodeNo[0].c_str());
|
||||
std::string timestamp_last = sqlite_db_ctrl::instance().GetData(tableName, " timeStamp ", whereCon);
|
||||
sprintf(updateSql, "zigbeeSignal = '%02d' ",UartRecvBuf[i+6]&0xFF);
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str());
|
||||
|
||||
@ -816,7 +816,7 @@ void Uart::DealWave() {
|
||||
char whereCon[50] = {0x00};
|
||||
sprintf(whereCon, "MeasurementID='%s'",strMeasurementID.c_str());
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(insertSql, "'%s','%02x%02x','%s',0,'0','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,"");
|
||||
sprintf(insertSql, "'%s','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,"");
|
||||
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
|
||||
wave_trans_ = false;
|
||||
}
|
||||
@ -843,6 +843,7 @@ float Uart::Calcoe(int ran, int iChannel, std::string &product, int range) {
|
||||
coe = 64 * 1.0f / 32767;
|
||||
} break;
|
||||
}
|
||||
|
||||
} else if (product == "02") {
|
||||
if (iChannel == WAVE_X || iChannel == WAVE_Y) {
|
||||
coe = 0.00048828125f;
|
||||
@ -956,7 +957,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
int count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere);
|
||||
zlog_info(zct, "save channlID %s dat count = %d", strChannelID.c_str(), count);
|
||||
zlog_warn(zct, "send failed,filename %s,iRet = %d", strFileName.c_str(), iRet);
|
||||
if (count <= 12) {
|
||||
if (count <= 3) {
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", strChannelID.c_str(), nowTimetamp.c_str());
|
||||
sprintf(updateSql, "SendMsg = 0 , error_code = %d",iRet);
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user