Commit 3e5a3923 authored by Pavel Vainerman's avatar Pavel Vainerman

(DB): Сделал сохранение аналоговых датчиков в БД с учётом precision

parent dda3e2fc
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <cmath>
#include "ORepHelpers.h" #include "ORepHelpers.h"
#include "DBServer_MySQL.h" #include "DBServer_MySQL.h"
...@@ -281,7 +282,9 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si ) ...@@ -281,7 +282,9 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
struct timezone tz; struct timezone tz;
gettimeofday(&si->tm,&tz); gettimeofday(&si->tm,&tz);
} }
float val = (float)si->value / (float)pow10(si->ci.precision);
// см. DBTABLE AnalogSensors, DigitalSensors // см. DBTABLE AnalogSensors, DigitalSensors
ostringstream data; ostringstream data;
data << "INSERT INTO " << tblName(si->type) data << "INSERT INTO " << tblName(si->type)
...@@ -289,10 +292,10 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si ) ...@@ -289,10 +292,10 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
// Поля таблицы // Поля таблицы
<< ui.dateToString(si->sm_tv_sec,"-") << "','" // date << ui.dateToString(si->sm_tv_sec,"-") << "','" // date
<< ui.timeToString(si->sm_tv_sec,":") << "','" // time << ui.timeToString(si->sm_tv_sec,":") << "','" // time
<< si->sm_tv_usec << "'," // time_usec << si->sm_tv_usec << "','" // time_usec
<< si->id << "," // sensor_id << si->id << "','" // sensor_id
<< si->value << "," // value << val << "','" // value
<< si->node << ")"; // node << si->node << "')"; // node
if( unideb.debugging(DBLEVEL) ) if( unideb.debugging(DBLEVEL) )
unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl; unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <cmath>
#include "ORepHelpers.h" #include "ORepHelpers.h"
#include "DBServer_SQLite.h" #include "DBServer_SQLite.h"
...@@ -258,7 +259,9 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si ) ...@@ -258,7 +259,9 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si )
struct timezone tz; struct timezone tz;
gettimeofday(&si->tm,&tz); gettimeofday(&si->tm,&tz);
} }
float val = (float)si->value / (float)pow10(si->ci.precision);
// см. DBTABLE AnalogSensors, DigitalSensors // см. DBTABLE AnalogSensors, DigitalSensors
ostringstream data; ostringstream data;
data << "INSERT INTO " << tblName(si->type) data << "INSERT INTO " << tblName(si->type)
...@@ -266,10 +269,10 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si ) ...@@ -266,10 +269,10 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si )
// Поля таблицы // Поля таблицы
<< ui.dateToString(si->sm_tv_sec,"-") << "','" // date << ui.dateToString(si->sm_tv_sec,"-") << "','" // date
<< ui.timeToString(si->sm_tv_sec,":") << "','" // time << ui.timeToString(si->sm_tv_sec,":") << "','" // time
<< si->sm_tv_usec << "'," // time_usec << si->sm_tv_usec << "','" // time_usec
<< si->id << "," // sensor_id << si->id << "','" // sensor_id
<< si->value << "," // value << si->value << "','" // value
<< si->node << ")"; // node << si->node << "')"; // node
if( unideb.debugging(DBLEVEL) ) if( unideb.debugging(DBLEVEL) )
unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl; unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment