add triger wave code
This commit is contained in:
parent
fc73714812
commit
ea80e15cbc
@ -298,7 +298,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
|
||||
execute_sql_file("/opt/configenv/t_process_info.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/t_wave_upload_rule_info.sql");
|
||||
execute_sql_file("/opt/configenv/t_shutdown_info.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/t_wave_triger_info.sql");
|
||||
|
||||
@ -1570,6 +1570,64 @@ int SqliteDB::NewBatteryIdentify(){
|
||||
}
|
||||
}
|
||||
}
|
||||
int SqliteDB::ShutdownCheck(){
|
||||
int checkNumber = readIntValue("config", "shutdownNumber", (char *)GlobalConfig::Config_G.c_str());
|
||||
char whereCon[1024] = {0};
|
||||
char updateSql[1024] = {0};
|
||||
char tablename[100] = {0};
|
||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
if (arrRes.size() > 0) {
|
||||
for (size_t i = 0; i < arrRes.size(); i++){
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(tablename,0,sizeof(tablename));
|
||||
sprintf(tablename,"t_data_%s",arrRes[i][44].c_str());
|
||||
sprintf(whereCon, "MeasurementID = '%s' ", arrRes[i][44].c_str());
|
||||
vec_t shutdownCheck = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info", " * ", whereCon);
|
||||
array_t arrData;
|
||||
if(shutdownCheck[2] == "1"){
|
||||
if (shutdownCheck[3] == "0")//加速度有效值
|
||||
{
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,%d;",arrRes[i][44].c_str(),checkNumber);
|
||||
arrData = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " rmsValues ", whereCon);
|
||||
}else if(shutdownCheck[3] == "1"){ //速度有效值
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,%d;",arrRes[i][44].c_str(),checkNumber);
|
||||
arrData = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " integratRMS ", whereCon);
|
||||
}
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
int shutdownFlag = 0;
|
||||
if (arrData.size() == checkNumber)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (i = 0; i < arrData.size(); i++)
|
||||
{
|
||||
if (atof(arrData[i][0].c_str()) > atof(shutdownCheck[4].c_str()))
|
||||
{
|
||||
break;
|
||||
}else{
|
||||
shutdownFlag = 1;
|
||||
}
|
||||
}
|
||||
if(i < arrData.size() - 1){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
if(shutdownFlag == 1){
|
||||
sprintf(updateSql,"effect = '1'");
|
||||
}else{
|
||||
sprintf(updateSql,"effect = '0'");
|
||||
}
|
||||
sprintf(whereCon, "MeasurementID = '%s' ", arrRes[i][44].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_shutdown_info", updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
int SqliteDB::TransBegin() { return sqlite3_exec(mDBAcess, "begin;", 0, 0, 0); }
|
||||
|
||||
int SqliteDB::TransRollback() { return sqlite3_exec(mDBAcess, "rollback;", 0, 0, 0); }
|
||||
|
||||
@ -74,6 +74,7 @@ public:
|
||||
int ClearExpireData();
|
||||
int SaveSystemHardStatus();
|
||||
int NewBatteryIdentify();
|
||||
int ShutdownCheck();
|
||||
std::string GetNodeConfigureInfor(const char *whereCon);
|
||||
int CloseDB();
|
||||
|
||||
|
||||
@ -242,7 +242,7 @@ std::string JsonData::JsonCmd_Cgi_27(std::vector<Param_27> ¶m) {
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "MeasurementID = '%s'", param[i].mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_debug_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_wave_upload_rule_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_shutdown_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_wave_triger_info ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID like '%%%s%%'", param[i].mMeasurementID.c_str());
|
||||
|
||||
@ -277,55 +277,7 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
char localtimestamp[32] = {0};
|
||||
std::string strWaveData = "";
|
||||
if (compareVersions(softVersion, "2.6") == -1) {
|
||||
std::string filename = "/opt/data/" + param.mChannelId + "-VOL.dat";
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "error";
|
||||
} else {
|
||||
float fTemp = 0.0f;
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * 1024;
|
||||
int number = vecWave.size();
|
||||
int start = param.mPackageFlag * 1024;
|
||||
if (number < 1024) {
|
||||
flag = number;
|
||||
start = 0;
|
||||
}
|
||||
char buf[32];
|
||||
for (int i = start; i < flag; i++) {
|
||||
if (i == start) {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
int max = number / 1024;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}else{
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
@ -390,6 +342,55 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}else{
|
||||
std::string filename = "/opt/data/" + param.mChannelId + "-VOL.dat";
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "error";
|
||||
} else {
|
||||
float fTemp = 0.0f;
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * 1024;
|
||||
int number = vecWave.size();
|
||||
int start = param.mPackageFlag * 1024;
|
||||
if (number < 1024) {
|
||||
flag = number;
|
||||
start = 0;
|
||||
}
|
||||
char buf[32];
|
||||
for (int i = start; i < flag; i++) {
|
||||
if (i == start) {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
int max = number / 1024;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
@ -1437,7 +1438,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 ¶m){
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam68[i].measurementID.c_str());
|
||||
sprintf(updateSql, " status = '%d',statisticType = '%d', threshold = '%f'",param.vecParam68[i].status,param.vecParam68[i].statisticType,param.vecParam68[i].threshold);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(" t_wave_upload_rule_info ", updateSql, whereCon);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(" t_shutdown_info ", updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
} else if (param.mMode == 0) {
|
||||
@ -1446,7 +1447,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 ¶m){
|
||||
lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str());
|
||||
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
shutdownDetection = readIntValue("config", "shutdownDetection", (char *)GlobalConfig::Config_G.c_str());
|
||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(" t_wave_upload_rule_info LEFT JOIN t_sensor_info ", " t_wave_upload_rule_info.*,t_sensor_info.dataNodeName ", "t_wave_upload_rule_info.MeasurementID = t_sensor_info.MeasurementID");
|
||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(" t_shutdown_info LEFT JOIN t_sensor_info ", " t_shutdown_info.*,t_sensor_info.dataNodeName ", "t_shutdown_info.MeasurementID = t_sensor_info.MeasurementID");
|
||||
if (arrRes.size() > 0) {
|
||||
for (size_t i = 0; i < arrRes.size(); i++)
|
||||
{
|
||||
|
||||
@ -50,13 +50,13 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
||||
if (timeoutflag > 200) {
|
||||
DealReviveDuration(wave_shortAddr);
|
||||
zlog_warn(zct, "===============0x9999 timeout= %d offSize = %d===============shortAddr = %02x%02x", timeoutflag, offSize,UINT16_HIGH(wave_shortAddr),UINT16_LOW(wave_shortAddr));
|
||||
zlog_warn(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize);
|
||||
printf("=============offSize = %d\n",offSize);
|
||||
for (size_t i = 0; i < 300; i++)
|
||||
{
|
||||
printf("%02x ",mUartRecvTmpBuf[i]);
|
||||
}
|
||||
printf("=============\n");
|
||||
// zlog_warn(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize);
|
||||
// printf("=============offSize = %d\n",offSize);
|
||||
// for (size_t i = 0; i < 300; i++)
|
||||
// {
|
||||
// printf("%02x ",mUartRecvTmpBuf[i]);
|
||||
// }
|
||||
// printf("=============\n");
|
||||
FindRecvPackage(offSize, mUartRecvTmpBuf, head);
|
||||
now_task = -1;
|
||||
timeoutflag = 0;
|
||||
@ -394,6 +394,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
||||
scheduleTask.cmd = REVIVE_DURATION;
|
||||
scheduleTask.shortAddr = ushortAdd;
|
||||
scheduleTask.duration = next_duration;
|
||||
scheduleTask.z = z;
|
||||
scheduleTask.next_taskID = WAVE_CMD;
|
||||
TaskResp(scheduleTask);
|
||||
}else if (next_task_id == kScheduleEigenValue) {
|
||||
@ -471,27 +472,46 @@ int Uart::DealConfig(uint16_t ushortAdd){
|
||||
return 0;
|
||||
}
|
||||
// 判断综合信号强度,低电量,停机状态,任一条件满足都不调度波形
|
||||
int Uart::WaveSendCondition(){
|
||||
int Uart::WaveSendCondition(char* shortAddr){
|
||||
int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1;
|
||||
char whereCon[100] = {0};
|
||||
std::string effect = "",rssi = "",batteryPower = "";
|
||||
sprintf(whereCon,"zigbeeShortAddr = '%s' ",shortAddr);
|
||||
lowSignal = readIntValue("config", "lowSignal", (char *)GlobalConfig::Config_G.c_str());
|
||||
signalThreshold = readIntValue("config", "signalThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str());
|
||||
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
vec_t sensorInfo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME),"RSSI,batteryPower",whereCon);
|
||||
rssi = sensorInfo[0];
|
||||
batteryPower = sensorInfo[1];
|
||||
std::vector<std::string> vParamBatteryPower;
|
||||
float fBatteryPower = 100.0;
|
||||
boost::split(vParamBatteryPower, batteryPower, boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParamBatteryPower.size() > 0) {
|
||||
fBatteryPower = atof(vParamBatteryPower[1].c_str())/atof(vParamBatteryPower[0].c_str());
|
||||
}
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info","*",whereCon);
|
||||
effect = vecResult[5];
|
||||
if((lowSignal == 1 && atof(rssi.c_str()) < signalThreshold) || (lowBatteryLevel == 1 && fBatteryPower < batteryLevelThreshold) || effect == "1"){
|
||||
zlog_warn(zct, "WaveSendCondition not meet condition shortAddr = %s,rssi = %s,batteryPower = %s,effect = %s",shortAddr,rssi.c_str(),batteryPower.c_str(),effect.c_str());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
|
||||
zlog_info(zct, "DealWaveCompress ");
|
||||
int ret = WaveSendCondition();
|
||||
now_task = WAVE_CMD;
|
||||
WaveResp(ushortAdd);
|
||||
char buf[20] = {0x00},whereCon[100] = {0};
|
||||
wave_shortAddr = ushortAdd;
|
||||
char shortAdd[20] = {0x00},whereCon[100] = {0};
|
||||
char sensor_rssi[10] = {0x00};
|
||||
sprintf(buf, "%02x%02x", (ushortAdd >> 8) & 0xFF, ushortAdd & 0xFF);
|
||||
std::string strShortAddr = std::string(buf);
|
||||
sprintf(whereCon,"zigbeeShortAddr = '%s' ",buf);
|
||||
sprintf(shortAdd, "%02x%02x", (ushortAdd >> 8) & 0xFF, ushortAdd & 0xFF);
|
||||
now_task = WAVE_CMD;
|
||||
std::string strShortAddr = std::string(shortAdd);
|
||||
sprintf(whereCon,"zigbeeShortAddr = '%s' ",shortAdd);
|
||||
std::string softVersion = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "softVersion", whereCon);
|
||||
compressWaveChannel tempchannel;
|
||||
if (compareVersions(softVersion, "2.6") == -1){
|
||||
WaveResp(ushortAdd);
|
||||
tempchannel.compressChannelX = pData[7];
|
||||
tempchannel.compressChannelY = pData[8];
|
||||
tempchannel.compressChannelZ = pData[9];
|
||||
@ -501,6 +521,14 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
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);
|
||||
if(ret == 1){
|
||||
zlog_warn(zct, "WaveSendCondition not meet condition ,shortAddr = %s",shortAdd);
|
||||
scheduler::instance().WaveSuccess(ushortAdd,true);
|
||||
return 1;
|
||||
}else{
|
||||
WaveResp(ushortAdd);
|
||||
}
|
||||
sprintf(sensor_rssi, "%02d", pData[7] & 0xFF);
|
||||
tempchannel.compressChannelX = pData[8];
|
||||
tempchannel.compressChannelY = pData[9];
|
||||
@ -525,7 +553,7 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
}
|
||||
|
||||
g_mapCompress[strShortAddr] = tempchannel;
|
||||
wave_shortAddr = ushortAdd;
|
||||
|
||||
|
||||
if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) {
|
||||
char errorInfo[100] = {0x00};
|
||||
@ -777,7 +805,7 @@ void Uart::DealRecvData(const char *pData) {
|
||||
}
|
||||
last_short_addr = ushortAdd;
|
||||
}
|
||||
void Uart::DelRepeatData(char *pShortAdd,char* dataNodeNo,char* measurementID){
|
||||
void Uart::DelRepeatData(char *pShortAdd,const char* dataNodeNo,const char* measurementID){
|
||||
char whereCon[64] = {0};
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), dataNodeNo);
|
||||
@ -791,7 +819,7 @@ void Uart::DelRepeatData(char *pShortAdd,char* dataNodeNo,char* measurementID){
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "MeasurementID = '%s'", measurementID);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_debug_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_wave_upload_rule_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_shutdown_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_wave_triger_info ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID like'%s'", measurementID);
|
||||
@ -890,12 +918,12 @@ void Uart::DealDataNodeName(const char *pData) {
|
||||
MeasurementID, szShortAdd);
|
||||
sqlite_db_ctrl::instance().InsertData("t_debug_info", insertSql);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '%s','%s','0','0','0'",
|
||||
MeasurementID, szShortAdd);
|
||||
sqlite_db_ctrl::instance().InsertData("t_wave_upload_rule_info", insertSql);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '%s','%s','0','0','0','0'",
|
||||
MeasurementID, szShortAdd);
|
||||
sqlite_db_ctrl::instance().InsertData("t_shutdown_info", insertSql);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '%s','%s','0','0','0','0','0'",
|
||||
MeasurementID, szShortAdd);
|
||||
sqlite_db_ctrl::instance().InsertData("t_wave_triger_info", insertSql);
|
||||
}
|
||||
|
||||
|
||||
@ -126,6 +126,7 @@ typedef struct ScheduleTask_{
|
||||
uint16_t millisecond;
|
||||
uint8_t next_taskID;
|
||||
uint8_t acc_z;
|
||||
bool z; // true: z波形 false: xy波形
|
||||
ScheduleTask_(){
|
||||
cmd = 0;
|
||||
shortAddr = 0;
|
||||
@ -134,6 +135,7 @@ typedef struct ScheduleTask_{
|
||||
millisecond = 0;
|
||||
next_taskID = 0;
|
||||
acc_z = 0;
|
||||
z = false;
|
||||
}
|
||||
} ScheduleTask;
|
||||
|
||||
@ -171,7 +173,7 @@ public:
|
||||
void UpdateZigbeeInfo(const char* pData);
|
||||
int DealAskTaskOld(uint16_t ushortAdd);
|
||||
void DealRecvData(const char* pData);
|
||||
void DelRepeatData(char *pShortAdd,char* dataNodeNo,char* measurementID);
|
||||
void DelRepeatData(char *pShortAdd,const char* dataNodeNo,const char* measurementID);
|
||||
void DealDataNodeInfo(const char* pData);
|
||||
void DealDataNodeName(const char* pData);
|
||||
void ZigbeeParameterConfig();
|
||||
@ -188,10 +190,11 @@ public:
|
||||
int DealSensorRSSI(const char *pData,uint16_t ushortAdd);
|
||||
int DealUpgrade(uint16_t ushortAdd,int status);
|
||||
void GetLocalZigbeeRSSI(uint16_t ushortAdd);
|
||||
int WaveSendCondition();
|
||||
int WaveSendCondition(char* shortAddr);
|
||||
|
||||
// feature parse
|
||||
int DealDataNodeFeature(const char* pData, int flag);
|
||||
void DealTriger(std::string & measurementID);
|
||||
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
|
||||
void DealDataNodeWave(const char* pData, int comand);
|
||||
void DealWaveThread();
|
||||
|
||||
@ -79,6 +79,32 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s
|
||||
zlog_info(zct, "dataNodeNo='%s',zigbeeSignal=%d,zigbeeSignalNode=%d,actualRate=%f,comprehensiveRSSI=%f", strLongAddr.c_str(), zigbeeSignal, zigbeeSignalNode, actualRate, comprehensiveRSSI);
|
||||
}
|
||||
}
|
||||
void Uart::DealTriger(std::string & measurementID){
|
||||
vec_t vecTrigger;
|
||||
char whereCon[256] = {0},tablename[128] = {0};
|
||||
sprintf(whereCon, "MeasurementID='%s' and status ='1' ", measurementID.c_str());
|
||||
sprintf(tablename,"t_data_%s",measurementID.c_str());
|
||||
vecTrigger = sqlite_db_ctrl::instance().GetDataSingleLine(" t_wave_triger_info ", " * ", whereCon);
|
||||
if (vecTrigger.size() > 0){
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,1;",measurementID);
|
||||
if(vecTrigger[3] == "0"){
|
||||
std::string rmsValue = sqlite_db_ctrl::instance().GetData(tablename, " rmsValues ", whereCon);
|
||||
float rmsValue_f = atof(rmsValue.c_str());
|
||||
if (rmsValue_f >= atof(vecTrigger[4].c_str())) {
|
||||
zlog_warn(zct, "measurementID='%s' trigger activated, rmsValue=%f", measurementID.c_str(), rmsValue_f);
|
||||
}
|
||||
|
||||
}else if (vecTrigger[3] == "1"){
|
||||
std::string integratRMS = sqlite_db_ctrl::instance().GetData(tablename, " integratRMS ", whereCon);
|
||||
float integratRMS_f = atof(integratRMS.c_str());
|
||||
if (integratRMS_f >= atof(vecTrigger[4].c_str())) {
|
||||
zlog_warn(zct, "measurementID='%s' trigger activated, integratRMS=%f", measurementID.c_str(), integratRMS_f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void Uart::DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n) {
|
||||
char buf[20] = {0};
|
||||
sprintf(buf, "%02x%02x", p->Data[id+1], p->Data[id]);
|
||||
@ -666,7 +692,11 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
valdatastatic["ChannelType"] = "STATUS";
|
||||
valdatastatic["ChannelId"] = strMeasurementID + "-S";
|
||||
valdatastatic["TimeStamp"] = localtimestamp;
|
||||
valdatastatic["bateryProportion"] = atof(vBattery[1].c_str()) / atof(vBattery[0].c_str());
|
||||
if(vBattery[1] == "" || vBattery[0] == ""){
|
||||
valdatastatic["bateryProportion"] = 0.9;
|
||||
}else{
|
||||
valdatastatic["bateryProportion"] = atof(vBattery[1].c_str()) / atof(vBattery[0].c_str());
|
||||
}
|
||||
valdatastatic["batteryRemainDay"] = atof(vBattery[1].c_str());
|
||||
valdatastatic["dataNodeNo"] = strMeasurementID;
|
||||
valNodeData.append(valdatastatic);
|
||||
@ -701,6 +731,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
}
|
||||
JsonData jd;
|
||||
jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,"");
|
||||
DealTriger(strMeasurementID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -887,15 +918,15 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
memcpy(dealdata, data, j * 92);
|
||||
deallen = j * 92;
|
||||
}
|
||||
if(iChannel == WAVE_X){
|
||||
for (size_t i = 0; i < 200; i++) {
|
||||
float fTemp = 0.0f;
|
||||
memset(buf, 0, 8);
|
||||
sprintf(buf, "%02x%02x", dealdata[2 * i + 1], dealdata[i * 2]);
|
||||
printf("%s ", buf);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
// if(iChannel == WAVE_X){
|
||||
// for (size_t i = 0; i < 200; i++) {
|
||||
// float fTemp = 0.0f;
|
||||
// memset(buf, 0, 8);
|
||||
// sprintf(buf, "%02x%02x", dealdata[2 * i + 1], dealdata[i * 2]);
|
||||
// printf("%s ", buf);
|
||||
// }
|
||||
// printf("\n");
|
||||
// }
|
||||
for (size_t i = 0; i < deallen; i++) {
|
||||
float fTemp = 0.0f;
|
||||
memset(buf, 0, 8);
|
||||
@ -1161,10 +1192,11 @@ float Uart::Calcoe(int ran, int iChannel, std::string &product, int range) {
|
||||
if (product == "01") {
|
||||
coe = pow(2, ran) * 8.0f / 32767;
|
||||
} else if (product == "02") {
|
||||
if (iChannel == WAVE_X || iChannel == WAVE_Y || iChannel == WAVE_VOL_X || iChannel == WAVE_VOL_Y) {
|
||||
if (iChannel == WAVE_X || iChannel == WAVE_Y || iChannel == WAVE_VOL_X ||
|
||||
iChannel == WAVE_VOL_Y || iChannel == WAVE_VOL_Z) {
|
||||
coe = 0.00048828125f;
|
||||
}
|
||||
if (iChannel == WAVE_Z || iChannel == WAVE_VOL_Z) {
|
||||
if (iChannel == WAVE_Z ) {
|
||||
coe = 0.00172607421875f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -580,8 +580,13 @@ int Uart::TaskResp(ScheduleTask scheduleTask){
|
||||
|
||||
if (scheduleTask.next_taskID == WAVE_CMD)
|
||||
{
|
||||
uint8_t x,y,z;
|
||||
wave_feature_set_inst::instance().GetWaveCfg(scheduleTask.shortAddr,x,y,z);
|
||||
uint8_t x = 0,y = 0,z = 1;
|
||||
if (scheduleTask.z)
|
||||
{
|
||||
x = 1;
|
||||
y = 1;
|
||||
z = 0;
|
||||
}
|
||||
zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z);
|
||||
send_data[17] = (x^1) & 0xFF;
|
||||
send_data[18] = (y^1) & 0xFF;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user