diff --git a/Makefile b/Makefile index 58dcf68..2116d58 100644 --- a/Makefile +++ b/Makefile @@ -38,12 +38,12 @@ CPP_SRCDIR = $(AllDirs) CPP_SOURCES = $(foreach d,$(CPP_SRCDIR),$(wildcard $(d)/*.cpp) ) CPP_OBJS = $(patsubst %.cpp, $(OBJ_PATH)/%.o, $(CPP_SOURCES)) -default:init compile strip +default: init $(TARGET) strip -$(C_OBJS):$(OBJ_PATH)/%.o:%.c +$(C_OBJS):$(OBJ_PATH)/%.o:%.c | init $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@ -$(CPP_OBJS):$(OBJ_PATH)/%.o:%.cpp +$(CPP_OBJS):$(OBJ_PATH)/%.o:%.cpp | init $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@ init: @@ -55,7 +55,9 @@ test: @echo "CPP_SOURCES: $(CPP_SOURCES)" @echo "CPP_OBJS: $(CPP_OBJS)" -compile:$(C_OBJS) $(CPP_OBJS) +compile: $(TARGET) + +$(TARGET): $(C_OBJS) $(CPP_OBJS) $(CC) -O2 -o $(TARGET) $^ $(LINKFLAGS) $(LIBS) clean: @@ -67,7 +69,7 @@ install: $(TARGET) uninstall: rm -f $(PREFIX_BIN)/$(TARGET) -strip: +strip: $(TARGET) $(STRIP) $(TARGET) cp $(TARGET) ~/tftpboot diff --git a/jsonparse/web_cmd_parse.cpp b/jsonparse/web_cmd_parse.cpp index 862d9e9..b2d7c48 100644 --- a/jsonparse/web_cmd_parse.cpp +++ b/jsonparse/web_cmd_parse.cpp @@ -246,11 +246,11 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) { jsStaticData["ChannelType"] = "STATUS"; jsStaticData["ChannelId"] = vecRes[1]; jsStaticData["TimeStamp"] = vecRes[8]; - jsStaticData["battery"] = vecRes[15]; + jsStaticData["battery"] = vecRes[14]; jsStaticData["MeasurementID"] = strMeasurementID; jsStaticData["dataNodeNo"] = arrResAll[i][0]; jsStaticData["ShortAddr"] = strShortAddr; - jsStaticData["status"] = vecRes[13]; + jsStaticData["status"] = vecRes[12]; jsStaticData["loose"] = "0"; } else { diff --git a/jsonparse/web_cmd_parse3.cpp b/jsonparse/web_cmd_parse3.cpp index 2423bde..96a083e 100644 --- a/jsonparse/web_cmd_parse3.cpp +++ b/jsonparse/web_cmd_parse3.cpp @@ -1481,7 +1481,7 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 ¶m){ char whereCon[512] = {0}; char updateSql[256] = {0}; sprintf(whereCon, " MeasurementID = '%s' ", param.measurementID[i].c_str()); - sprintf(updateSql, " status = '%d' ", 1);// 0 未调试,1 调试中,2 调试完成 + sprintf(updateSql, " status = '%d' ", 1);// 0 未调试,1 调试中,2 调试完成,3停止调试 sqlite_db_ctrl::instance().UpdateTableData("t_debug_info", updateSql, whereCon); uint16_t short_addr; char *end_ptr = NULL; @@ -1495,7 +1495,7 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 ¶m){ char whereCon[512] = {0}; char updateSql[256] = {0}; sprintf(whereCon, " status = '1' "); - sprintf(updateSql, " status = '%d' ", 0);// 0 未调试,1 调试中,2 调试完成 + sprintf(updateSql, " status = '%d' ", 3);// 0 未调试,1 调试中,2 调试完成,3停止调试 sqlite_db_ctrl::instance().UpdateTableData("t_debug_info", updateSql, whereCon); scheduler::instance().CloseDebugMode(); } @@ -1581,7 +1581,7 @@ std::string JsonData::JsonCmd_Cgi_69(Param_69 ¶m){ memset(updateSql,0,sizeof(updateSql)); sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam69[i].measurementID.c_str()); sprintf(updateSql, " status = '%d',trigerType = '%d',statisticType = '%d', threshold = '%f'",param.vecParam69[i].status,param.vecParam69[i].trigerType,param.vecParam69[i].statisticType,param.vecParam69[i].threshold); - sqlite_db_ctrl::instance().UpdateTableData(" t_waveTriger_info ", updateSql, whereCon); + sqlite_db_ctrl::instance().UpdateTableData(" t_wave_triger_info ", updateSql, whereCon); } } } else if (param.mMode == 0) { diff --git a/uart/uart.cpp b/uart/uart.cpp index 8762b5d..88f5d3c 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -374,23 +374,25 @@ int Uart::DealAskTask(uint16_t ushortAdd){ zlog_warn(zct, "device info not found %02x%02x ", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd)); return 1; } - int next_duration = 0,next_task_id = 0; + int next_duration_,next_task_id = 0; int taskID; ScheduleTask scheduleTask; bool z = false; - taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id); + //taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id); current_z = z; - zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d,current_z = %d", taskID, next_duration, next_task_id,current_z); - if (taskID == kScheduleConfigSensor) + if (scheduler::instance().StartSchedule(ushortAdd,next_duration_,z, next_task_id) == kScheduleConfigSensor) { scheduleTask.cmd = CONFIG; - scheduleTask.duration = next_duration; + scheduleTask.duration = next_duration_; scheduleTask.next_taskID = next_task_id; scheduleTask.shortAddr = ushortAdd; TaskResp(scheduleTask); mssleep(50000); UpdateConfig(ushortAdd); } + uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd,z,next_task_id); + zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d,current_z = %d", taskID, next_duration, next_task_id,current_z); + if(next_task_id == kScheduleWaveForm){ scheduleTask.cmd = REVIVE_DURATION; scheduleTask.shortAddr = ushortAdd; @@ -516,7 +518,7 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ std::string productNo = res[17]; compressWaveChannel tempchannel; if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01"){ // DN101所有版本和DN102 2.6以前版本 - ScheduleStatus schedule_status = scheduler::instance().GetScheduleStatus(); + schedule_status = scheduler::instance().GetScheduleStatus(); if(schedule_status == kScheduleStatusDebug || schedule_status == kScheduleStatusUpgrade){ zlog_warn(zct, "ScheduleStatus not meet condition ,shortAddr = %s,schedule_status = %d",shortAdd,schedule_status); scheduler::instance().WaveSuccess(ushortAdd,true); @@ -531,14 +533,15 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ tempchannel.CountY = BUILD_UINT32(pData[17], pData[16],pData[15],pData[14]); tempchannel.CountZ = BUILD_UINT32(pData[21], pData[20],pData[19],pData[18]); sprintf(sensor_rssi, "%02d", pData[22] & 0xFF); - }else{ - int ret = 0;//= WaveSendCondition(shortAdd); + }else + { + int ret = WaveSendCondition(shortAdd); if(ret == 1){ zlog_warn(zct, "WaveSendCondition not meet condition ,shortAddr = %s",shortAdd); scheduler::instance().WaveSuccess(ushortAdd,true); return 1; }else{ - ScheduleStatus schedule_status = scheduler::instance().GetScheduleStatus(); + schedule_status = scheduler::instance().GetScheduleStatus(); if(schedule_status == kScheduleStatusUpgrade){ zlog_warn(zct, "ScheduleStatus not meet condition ,shortAddr = %s,schedule_status = %d",shortAdd,schedule_status); scheduler::instance().WaveSuccess(ushortAdd,true); @@ -590,6 +593,15 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ memset(whereCon,0,sizeof(whereCon)); sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str()); sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon); + if(schedule_status == kScheduleStatusDebug){ + memset(whereCon,0,sizeof(whereCon)); + memset(updateSql,0,sizeof(updateSql)); + memset(tableName,0,sizeof(tableName)); + sprintf(tableName, "t_debug_info"); + sprintf(updateSql, " datanodeRSSI = '%s' ", sensor_rssi); + sprintf(whereCon, "shortAddr = '%02x%02x' ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd)); + sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon); + } } zlog_warn(zct, "count X = %d,Y = %d,Z = %d,vol X = %d,vol Y = %d,vol Z = %d short_add = %s", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ,tempchannel.CountVolX,tempchannel.CountVolY,tempchannel.CountVolZ,strShortAddr.c_str()); @@ -599,43 +611,7 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ zlog_info(zct, "samplerate vol X = %d,vol Y = %d,vol Z = %d ", tempchannel.samplerateVolX, tempchannel.samplerateVolY, tempchannel.samplerateVolZ); return 0; } -int Uart::DealSensorRSSI(const char *pData,uint16_t ushortAdd){ - //传感器获取网关信号强度 - zlog_info(zct, "DealSensorRSSI ushortAdd = %02x%02x",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd)); - mssleep(200000); - ScheduleTask scheduleTask; - now_task = WAVE_CMD; - scheduleTask.cmd = WAVE_CMD; - scheduleTask.shortAddr = ushortAdd; - - TaskResp(scheduleTask); - - char localtimestamp[32] = {0}; - GetTimeNet(localtimestamp, 1); - char sensor_rssi[10] = {0x00}; - sprintf(sensor_rssi, "%02d", pData[7] & 0xFF); - if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) { - char errorInfo[100] = {0x00}; - sprintf(errorInfo, "No RSSI %s", sensor_rssi); - zlog_error(zct, errorInfo); - } else { - char tableName[100] = {0x00}; - char whereCon[100] = {0}; - char updateSql[100] = {0}; - sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(ushortAdd),UINT16_LOW(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' 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)); - sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str()); - sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon); - } - return 0; -} int Uart::DealUpgrade(uint16_t ushortAdd,int status){ char updateSql[100] = {0}; @@ -671,14 +647,14 @@ int Uart::DealFeatureValue(const char *pData,uint16_t ushortAdd){ { return -1; } - // char logInfo[100] = {0x00}; - // std::vector& data_vec = map_send_data[ushortAdd]; - // const uint8_t* send_data = data_vec.data(); - // WriteToUart((const char*)send_data, 100); - // mssleep(50000); - // WriteToUart((const char*)send_data, 100); - // mssleep(50000); - // WriteToUart((const char*)send_data, 100); + char logInfo[100] = {0x00}; + std::vector& data_vec = map_send_data[ushortAdd]; + const uint8_t* send_data = data_vec.data(); + WriteToUart((const char*)send_data, 100); + mssleep(50000); + WriteToUart((const char*)send_data, 100); + mssleep(50000); + WriteToUart((const char*)send_data, 100); }else { DealAskTask(ushortAdd); DealDataNodeFeature(pData, 0); @@ -1584,6 +1560,15 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str()); sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon); + if(schedule_status == kScheduleStatusDebug){ + memset(whereCon,0,sizeof(whereCon)); + memset(updateSql,0,sizeof(updateSql)); + memset(tableName,0,sizeof(tableName)); + sprintf(tableName, "t_debug_info"); + sprintf(updateSql, " gatewayRSSI = '%02d' ", UartRecvBuf[i+6]&0xFF); + sprintf(whereCon, "MeasurementID = '%s' ",(char*)vecDataNodeNo[0].c_str()); + sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon); + } // zigbeeRSSIType = 1 网关获取传感器信号强度 diff --git a/uart/uart.hpp b/uart/uart.hpp index 4e198a3..cff68f7 100644 --- a/uart/uart.hpp +++ b/uart/uart.hpp @@ -8,6 +8,7 @@ #include "common/global.hpp" #include "dbaccess/sql_db.hpp" #include "utility/calculation.hpp" +#include "scheduler/status_mgr.hpp" typedef void (*pTestRecvCallBack)(int Status); @@ -187,7 +188,6 @@ public: int DealReviveDuration(uint16_t ushortAdd); int DealConfig(uint16_t ushortAdd); int DealWaveCompress(const char *pData,uint16_t ushortAdd); - int DealSensorRSSI(const char *pData,uint16_t ushortAdd); int DealUpgrade(uint16_t ushortAdd,int status); void GetLocalZigbeeRSSI(uint16_t ushortAdd); int WaveSendCondition(char* shortAddr); @@ -285,6 +285,8 @@ private: long last_time; bool current_z; std::map> map_send_data; + + ScheduleStatus schedule_status; }; typedef boost::container::dtl::singleton_default uart_inst; diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index 7541fc0..96bd7a3 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -63,7 +63,7 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s if (res_static.size() > 0){ int zigbeeSignal = atoi(res_static[6].c_str()); int zigbeeSignalNode = atoi(res_static[11].c_str()); - float standardRate = 5000.0f; //5kB/s + float standardRate = 5.0f; //5kB/s float actualRate = 0.0f; if (dataStatic.nodeSendTime > 0){ actualRate = (wave_dataLen / 1024.0f) / (dataStatic.nodeSendTime / 1000.0f); //单位:KB/s @@ -73,7 +73,8 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s comprehensiveRSSI = 1.0f; //综合信号强度最大为1 } - zlog_info(zct, "dataNodeNo='%s',wave_dataLen=%d,nodeSendTime=%f,actualRate=%f", strLongAddr.c_str(), wave_dataLen, dataStatic.nodeSendTime, actualRate); + zlog_info(zct, "dataNodeNo='%s',zigbeeSignal = '%d',zigbeeSignalNode = '%d',wave_dataLen=%d,nodeSendTime=%f,actualRate=%f", + strLongAddr.c_str(),zigbeeSignal, zigbeeSignalNode,wave_dataLen, dataStatic.nodeSendTime, actualRate); //更新综合信号强度到数据库 char updateSql[256] = {0}; memset(whereCon, 0x00, sizeof(whereCon)); @@ -86,6 +87,17 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s sprintf(updateSql,"RSSI = '%f'", comprehensiveRSSI); sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); zlog_info(zct, "dataNodeNo='%s',zigbeeSignal=%d,zigbeeSignalNode=%d,actualRate=%f,comprehensiveRSSI=%f", strLongAddr.c_str(), zigbeeSignal, zigbeeSignalNode, actualRate, comprehensiveRSSI); + if (schedule_status == kScheduleStatusDebug) + { + char localtimestamp[32] = { 0 }; + GetTimeNet(localtimestamp, 1); + memset(updateSql,0,sizeof(updateSql)); + memset(tableName,0,sizeof(tableName)); + sprintf(tableName, "t_debug_info"); + sprintf(updateSql, " comprehensiveRSSI = '%f',minnumVoltage = '%d',status = '2',timeStamp = '%s' ", comprehensiveRSSI,dataStatic.instantaneousBatteryVoltage,localtimestamp); + sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon); + } + } } void Uart::DealTriger(uint16_t ushortAdd,std::string & measurementID){ @@ -271,6 +283,9 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) { iTemp = (int)strtol(buf, NULL, 16); dataStatic.instantaneousBatteryVoltage = iTemp; + if(schedule_status == kScheduleStatusDebug){ + + } char szTableName[50] = {0x00}, szTableNameStatic[50] = {0x00}, szTableNameData[50] = {0x00}; sprintf(szTableName, "t_dataStatic_%s", strMeasurementID.c_str()); memcpy(szTableNameStatic, szTableName, sizeof(szTableNameStatic));