tmp
This commit is contained in:
parent
7e6c525181
commit
7d4375234f
@ -810,7 +810,8 @@ int SqliteDB::CalculateBattery() {
|
|||||||
memset(selectSql, 0x00, sizeof(selectSql));
|
memset(selectSql, 0x00, sizeof(selectSql));
|
||||||
char updateSql[1024] = {0};
|
char updateSql[1024] = {0};
|
||||||
int res = 0;
|
int res = 0;
|
||||||
sprintf(selectSql, " dataNodeNo,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate,batteryPower ");
|
//数据关联使用MeasurementID字段
|
||||||
|
sprintf(selectSql, " dataNodeNo,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate,batteryPower,MeasurementID ");
|
||||||
array_t vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
array_t vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
||||||
zlog_info(zct, "Size = %d", vecRes.size());
|
zlog_info(zct, "Size = %d", vecRes.size());
|
||||||
if (vecRes.size() > 0) {
|
if (vecRes.size() > 0) {
|
||||||
@ -818,13 +819,13 @@ int SqliteDB::CalculateBattery() {
|
|||||||
float capacity = 0.0, startCapacity = 0.0;
|
float capacity = 0.0, startCapacity = 0.0;
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
memset(selectSql, 0x00, sizeof(selectSql));
|
memset(selectSql, 0x00, sizeof(selectSql));
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' and batteryRemain <> '' order by timeStamp desc limit 0,1 ", vecRes[i][0].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' and batteryRemain <> '' order by timeStamp desc limit 0,1 ", vecRes[i][7].c_str());
|
||||||
vec_t vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
vec_t vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||||
std::vector<std::string> vParam;
|
std::vector<std::string> vParam;
|
||||||
boost::split(vParam, vecRes[i][6], boost::is_any_of(","), boost::token_compress_on);
|
boost::split(vParam, vecRes[i][6], boost::is_any_of(","), boost::token_compress_on);
|
||||||
if (vParam.size() <= 0 || vecResSig.size() <= 0) { //第一次计算
|
if (vParam.size() <= 0 || vecResSig.size() <= 0) { //第一次计算
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str());
|
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][7].c_str());
|
||||||
std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
||||||
if (Dip == "") {
|
if (Dip == "") {
|
||||||
continue;
|
continue;
|
||||||
@ -840,7 +841,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][0].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][7].c_str());
|
||||||
vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||||
if (vecResSig.size() <= 0) { //一条数据都没有
|
if (vecResSig.size() <= 0) { //一条数据都没有
|
||||||
continue;
|
continue;
|
||||||
@ -852,7 +853,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
zlog_info(zct, "dip = %d", atoi(vecResSig[1].c_str()));
|
zlog_info(zct, "dip = %d", atoi(vecResSig[1].c_str()));
|
||||||
|
|
||||||
zlog_info(zct, "capacity = %f", capacity);
|
zlog_info(zct, "capacity = %f", capacity);
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' and timeStamp > '%s'", vecRes[i][0].c_str(), vecResSig[8].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' and timeStamp > '%s'", vecRes[i][7].c_str(), vecResSig[8].c_str());
|
||||||
array_t vecResbattery = GetDataMultiLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
array_t vecResbattery = GetDataMultiLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||||
zlog_info(zct, "vecResbattery size = %d", vecResbattery.size());
|
zlog_info(zct, "vecResbattery size = %d", vecResbattery.size());
|
||||||
if (vecResbattery.size() <= 0) {
|
if (vecResbattery.size() <= 0) {
|
||||||
@ -904,14 +905,14 @@ int SqliteDB::CalculateBattery() {
|
|||||||
remainBattery = 10;
|
remainBattery = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
zlog_info(zct, "dataNodeNo = %s,batteryUsage = %f,batteryRemain = %f", vecRes[i][0].c_str(), atof(vecResSig[6].c_str()), remainBattery);
|
zlog_info(zct, "dataNodeNo = %s,batteryUsage = %f,batteryRemain = %f", vecRes[i][7].c_str(), atof(vecResSig[6].c_str()), remainBattery);
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp desc limit 0,1 ", vecRes[i][0].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp desc limit 0,1 ", vecRes[i][7].c_str());
|
||||||
std::string strtimeStamp = GetData(T_BATTERY_INFO(TNAME), " timeStamp ", whereCon);
|
std::string strtimeStamp = GetData(T_BATTERY_INFO(TNAME), " timeStamp ", whereCon);
|
||||||
|
|
||||||
sprintf(updateSql, "batteryUsage='%f',batteryRemain='%f'", usageBattery, remainBattery);
|
sprintf(updateSql, "batteryUsage='%f',batteryRemain='%f'", usageBattery, remainBattery);
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, "dataNodeNo ='%s' and timeStamp = '%s'", vecRes[i][0].c_str(), strtimeStamp.c_str());
|
sprintf(whereCon, "dataNodeNo ='%s' and timeStamp = '%s'", vecRes[i][7].c_str(), strtimeStamp.c_str());
|
||||||
res = UpdateTableData(T_BATTERY_INFO(TNAME), updateSql, whereCon);
|
res = UpdateTableData(T_BATTERY_INFO(TNAME), updateSql, whereCon);
|
||||||
if(res !=0 ){
|
if(res !=0 ){
|
||||||
zlog_error(zct, "res = %d", res);
|
zlog_error(zct, "res = %d", res);
|
||||||
@ -921,19 +922,19 @@ int SqliteDB::CalculateBattery() {
|
|||||||
memset(updateSql, 0x00, sizeof(updateSql));
|
memset(updateSql, 0x00, sizeof(updateSql));
|
||||||
|
|
||||||
char insertSql[1024] = {0x00}, deleteSql[1024] = {0x00};
|
char insertSql[1024] = {0x00}, deleteSql[1024] = {0x00};
|
||||||
sprintf(insertSql, "insert into t_battery_history select * from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][0].c_str());
|
sprintf(insertSql, "insert into t_battery_history select * from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][7].c_str());
|
||||||
res = ExeSql(insertSql);
|
res = ExeSql(insertSql);
|
||||||
if(res !=0 ){
|
if(res !=0 ){
|
||||||
zlog_error(zct, "res = %d", res);
|
zlog_error(zct, "res = %d", res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sprintf(deleteSql, "delete from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][0].c_str());
|
sprintf(deleteSql, "delete from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][7].c_str());
|
||||||
res = ExeSql(deleteSql);
|
res = ExeSql(deleteSql);
|
||||||
if(res !=0 ){
|
if(res !=0 ){
|
||||||
zlog_error(zct, "res = %d", res);
|
zlog_error(zct, "res = %d", res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str());
|
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][7].c_str());
|
||||||
if (startCapacity > 0) {
|
if (startCapacity > 0) {
|
||||||
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, remainBattery);
|
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, remainBattery);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -226,7 +226,7 @@ int Uart::ZigbeeTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uart::WriteToUart(const char *strSend, int pLen) {
|
void Uart::WriteToUart(const char *strSend, int pLen) {
|
||||||
if (!bUpdate)
|
if (bUpdate)
|
||||||
{
|
{
|
||||||
printf( "Write To Uart Start:\n");
|
printf( "Write To Uart Start:\n");
|
||||||
for (int i = 0; i < pLen; i++) {
|
for (int i = 0; i < pLen; i++) {
|
||||||
|
|||||||
@ -228,7 +228,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
|
|
||||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)) { // First Connect
|
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)) { // First Connect
|
||||||
char insertSql[1024] = {0};
|
char insertSql[1024] = {0};
|
||||||
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend);
|
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d", strMeasurementID.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||||
sqlite_db_ctrl::instance().InsertData(T_DATASTATIC_INFO(TNAME), insertSql);
|
sqlite_db_ctrl::instance().InsertData(T_DATASTATIC_INFO(TNAME), insertSql);
|
||||||
sqlite_db_ctrl::instance().CalculateBattery();
|
sqlite_db_ctrl::instance().CalculateBattery();
|
||||||
} else {
|
} else {
|
||||||
@ -303,7 +303,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) { // 1 week
|
if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) { // 1 week
|
||||||
char insertSql[1024] = {0};
|
char insertSql[1024] = {0};
|
||||||
memset(insertSql, 0x00, sizeof(insertSql));
|
memset(insertSql, 0x00, sizeof(insertSql));
|
||||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues,
|
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d", strMeasurementID.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues,
|
||||||
dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend);
|
dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||||
|
|
||||||
|
|||||||
@ -168,7 +168,9 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
|||||||
}
|
}
|
||||||
Data[99] = tmp;
|
Data[99] = tmp;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
zlog_info(zct, "thisSize1 = %d", (int)thisSize);
|
||||||
WriteToUart((const char*)Data, 100);
|
WriteToUart((const char*)Data, 100);
|
||||||
|
zlog_info(zct, "thisSize2 = %d", (int)thisSize);
|
||||||
int iRet = CheckZigbeeACK();
|
int iRet = CheckZigbeeACK();
|
||||||
if (iRet == 0) {
|
if (iRet == 0) {
|
||||||
zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||||
@ -474,7 +476,7 @@ int Uart::UpdateConfig(uint16_t ushortAdd) {
|
|||||||
UpdateData[4] = UINT16_LOW(ushortAdd);
|
UpdateData[4] = UINT16_LOW(ushortAdd);
|
||||||
UpdateData[5] = 0x0A;
|
UpdateData[5] = 0x0A;
|
||||||
UpdateData[6] = 0x01;
|
UpdateData[6] = 0x01;
|
||||||
UpdateData[7] = 0x02;
|
UpdateData[7] = 0x00;
|
||||||
char hex[200] = {0x00};
|
char hex[200] = {0x00};
|
||||||
stringToHex(strName.c_str(), hex);
|
stringToHex(strName.c_str(), hex);
|
||||||
bytesSize = strlen(hex) / 2;
|
bytesSize = strlen(hex) / 2;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user