Commit 6a27d830 authored by Pavel Vainerman's avatar Pavel Vainerman

Глобальный переход от microseconds --> nanoseconds

[timeval --> timespec, gettimeofday --> clock_gettime] ТРЕБУЕТСЯ КОНВЕРТИРОВАНИЕ БД! т.к. поле 'time_usec' меняется на 'time_nsec'
parent 0b8286f5
...@@ -103,8 +103,8 @@ interface IOController_i : UniSetManager_i ...@@ -103,8 +103,8 @@ interface IOController_i : UniSetManager_i
IOController_i::SensorInfo si; IOController_i::SensorInfo si;
long default_val; /*!< значение по умолчанию */ long default_val; /*!< значение по умолчанию */
CalibrateInfo ci; /*!< калибровочные параметры */ CalibrateInfo ci; /*!< калибровочные параметры */
long tv_sec; /*!< время последнего изменения датчика, секунды (gettimeofday) */ unsigned long tv_sec; /*!< время последнего изменения датчика, секунды (clock_gettime(CLOCK_REALTIME) */
long tv_usec; /*!< время последнего изменения датчика, мксек (gettimeofday) */ unsigned long tv_nsec; /*!< время последнего изменения датчика, nanosec (clock_gettime(CLOCK_REALTIME) */
UniSetTypes::ObjectId supplier; /*!< идентификатор объекта изменившего состояние датчика */ UniSetTypes::ObjectId supplier; /*!< идентификатор объекта изменившего состояние датчика */
boolean dbignore; /*!< не сохранять изменения в БД */ boolean dbignore; /*!< не сохранять изменения в БД */
}; };
...@@ -140,8 +140,10 @@ interface IOController_i : UniSetManager_i ...@@ -140,8 +140,10 @@ interface IOController_i : UniSetManager_i
struct ShortIOInfo struct ShortIOInfo
{ {
long value; long value;
long tv_sec; /*!< время последнего изменения датчика, секунды (gettimeofday) */
long tv_usec; /*!< время последнего изменения датчика, мксек (gettimeofday) */ // могут быть проблеммы в 64bit-ных
unsigned long tv_sec; /*!< время последнего изменения датчика, секунды (clock_gettime(CLOCK_REALTIME) */
unsigned long tv_nsec; /*!< время последнего изменения датчика, nanosec (clock_gettime(CLOCK_REALTIME) */
UniSetTypes::ObjectId supplier; /*!< идентификатор того, кто менял датчик (последний раз) */ UniSetTypes::ObjectId supplier; /*!< идентификатор того, кто менял датчик (последний раз) */
}; };
...@@ -207,8 +209,8 @@ interface IONotifyController_i : IOController_i ...@@ -207,8 +209,8 @@ interface IONotifyController_i : IOController_i
long hilimit; /*!< верхняя граница срабатывания */ long hilimit; /*!< верхняя граница срабатывания */
long lowlimit; /*!< нижняя гранийа срабатывания */ long lowlimit; /*!< нижняя гранийа срабатывания */
ThresholdState state; ThresholdState state;
long tv_sec; /*!< время последнего изменения датчика, секунды (gettimeofday) */ unsigned long tv_sec; /*!< время последнего изменения датчика, секунды (clock_gettime(CLOCK_REALTIME) */
long tv_usec; /*!< время последнего изменения датчика, мксек (gettimeofday) */ unsigned long tv_nsec; /*!< время последнего изменения датчика, nanosec (clock_gettime(CLOCK_REALTIME) */
boolean invert; /*!< инвертированная логика */ boolean invert; /*!< инвертированная логика */
}; };
......
...@@ -317,7 +317,7 @@ CXX_EXTRA_FLAGS="-Wnon-virtual-dtor -Woverloaded-virtual -Woverflow -D_GLIBCXX_U ...@@ -317,7 +317,7 @@ CXX_EXTRA_FLAGS="-Wnon-virtual-dtor -Woverloaded-virtual -Woverflow -D_GLIBCXX_U
# export # export
LDFLAGS="$LDFLAGS ${OMNI_LIBS} ${XML_LIBS} ${SIGC_LIBS} ${COV_LIBS} ${COMCPP_LIBS}" LDFLAGS="$LDFLAGS ${OMNI_LIBS} ${XML_LIBS} ${SIGC_LIBS} ${COV_LIBS} ${COMCPP_LIBS}"
# all developer liked options add to autogen.sh, please # all developer liked options add to autogen.sh, please
CXXFLAGS="$CXXFLAGS -funsigned-char -std=c++11 -g -D_GNU_SOURCE ${OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${COMCPP_CFLAGS} -I\$(top_builddir)/include $CXX_EXTRA_FLAGS" CXXFLAGS="-I\$(top_builddir)/include $CXXFLAGS -funsigned-char -std=c++11 -g -D_GNU_SOURCE ${OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${COMCPP_CFLAGS} $CXX_EXTRA_FLAGS"
AC_SUBST(LDFLAGS) AC_SUBST(LDFLAGS)
AC_SUBST(CXXFLAGS) AC_SUBST(CXXFLAGS)
......
...@@ -106,7 +106,7 @@ void DBServer_MySQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem ) ...@@ -106,7 +106,7 @@ void DBServer_MySQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
<< " WHERE sensor_id='" << cem->sensor_id << "'" << " WHERE sensor_id='" << cem->sensor_id << "'"
<< " AND date='" << dateToString(cem->time, "-") << " '" << " AND date='" << dateToString(cem->time, "-") << " '"
<< " AND time='" << timeToString(cem->time, ":") << " '" << " AND time='" << timeToString(cem->time, ":") << " '"
<< " AND time_usec='" << cem->time_usec << " '"; << " AND time_nsec='" << cem->time_nsec << " '";
dbinfo << myname << "(update_confirm): " << data.str() << endl; dbinfo << myname << "(update_confirm): " << data.str() << endl;
...@@ -201,7 +201,12 @@ void DBServer_MySQL::sensorInfo( const UniSetTypes::SensorMessage* si ) ...@@ -201,7 +201,12 @@ void DBServer_MySQL::sensorInfo( const UniSetTypes::SensorMessage* si )
// если время не было выставлено (указываем время сохранения в БД) // если время не было выставлено (указываем время сохранения в БД)
if( !si->tm.tv_sec ) if( !si->tm.tv_sec )
{ {
gettimeofday( const_cast<struct timeval*>(&si->tm), NULL); // Выдаём CRIT, но тем не менее сохраняем в БД
dbcrit << myname << "(insert_main_history): UNKNOWN TIMESTAMP! (tm.tv_sec=0)"
<< " for sid=" << si->id
<< " supplier=" << uniset_conf()->oind->getMapName(si->supplier)
<< endl;
} }
float val = (float)si->value / (float)pow10(si->ci.precision); float val = (float)si->value / (float)pow10(si->ci.precision);
...@@ -209,11 +214,11 @@ void DBServer_MySQL::sensorInfo( const UniSetTypes::SensorMessage* si ) ...@@ -209,11 +214,11 @@ void DBServer_MySQL::sensorInfo( const UniSetTypes::SensorMessage* si )
// см. DBTABLE AnalogSensors, DigitalSensors // см. DBTABLE AnalogSensors, DigitalSensors
ostringstream data; ostringstream data;
data << "INSERT INTO " << tblName(si->type) data << "INSERT INTO " << tblName(si->type)
<< "(date, time, time_usec, sensor_id, value, node) VALUES( '" << "(date, time, time_nsec, sensor_id, value, node) VALUES( '"
// Поля таблицы // Поля таблицы
<< dateToString(si->sm_tv_sec, "-") << "','" // date << dateToString(si->sm_tv.tv_sec, "-") << "','" // date
<< timeToString(si->sm_tv_sec, ":") << "','" // time << timeToString(si->sm_tv.tv_sec, ":") << "','" // time
<< si->sm_tv_usec << "','" // time_usec << si->sm_tv.tv_nsec << "','" // time_nsec
<< si->id << "','" // sensor_id << si->id << "','" // sensor_id
<< val << "','" // value << val << "','" // value
<< si->node << "')"; // node << si->node << "')"; // node
......
...@@ -87,7 +87,7 @@ CREATE TABLE `main_history` ( ...@@ -87,7 +87,7 @@ CREATE TABLE `main_history` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL, `date` date NOT NULL,
`time` time NOT NULL, `time` time NOT NULL,
`time_usec` int(10) unsigned NOT NULL, `time_nsec` int(10) unsigned NOT NULL,
`sensor_id` int(10) unsigned NOT NULL, `sensor_id` int(10) unsigned NOT NULL,
`value` double NOT NULL, `value` double NOT NULL,
`node` int(10) unsigned NOT NULL, `node` int(10) unsigned NOT NULL,
...@@ -102,7 +102,7 @@ CREATE TABLE `main_emergencylog` ( ...@@ -102,7 +102,7 @@ CREATE TABLE `main_emergencylog` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL, `date` date NOT NULL,
`time` time NOT NULL, `time` time NOT NULL,
`time_usec` int(10) unsigned NOT NULL, `time_nsec` int(10) unsigned NOT NULL,
`type_id` int(10) unsigned NOT NULL, `type_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `main_emergencylog_type_id` (`type_id`), KEY `main_emergencylog_type_id` (`type_id`),
...@@ -115,7 +115,7 @@ CREATE TABLE `main_emergencyrecords` ( ...@@ -115,7 +115,7 @@ CREATE TABLE `main_emergencyrecords` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL, `date` date NOT NULL,
`time` time NOT NULL, `time` time NOT NULL,
`time_usec` int(10) unsigned NOT NULL, `time_nsec` int(10) unsigned NOT NULL,
`log_id` int(11) NOT NULL, `log_id` int(11) NOT NULL,
`sensor_id` int(10) unsigned NOT NULL, `sensor_id` int(10) unsigned NOT NULL,
`value` double NOT NULL, `value` double NOT NULL,
......
...@@ -117,7 +117,7 @@ void DBServer_PostgreSQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem ) ...@@ -117,7 +117,7 @@ void DBServer_PostgreSQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
<< " WHERE sensor_id='" << cem->sensor_id << "'" << " WHERE sensor_id='" << cem->sensor_id << "'"
<< " AND date='" << dateToString(cem->time, "-") << " '" << " AND date='" << dateToString(cem->time, "-") << " '"
<< " AND time='" << timeToString(cem->time, ":") << " '" << " AND time='" << timeToString(cem->time, ":") << " '"
<< " AND time_usec='" << cem->time_usec << " '"; << " AND time_nsec='" << cem->time_nsec << " '";
dbinfo << myname << "(update_confirm): " << data.str() << endl; dbinfo << myname << "(update_confirm): " << data.str() << endl;
...@@ -249,23 +249,22 @@ void DBServer_PostgreSQL::sensorInfo( const UniSetTypes::SensorMessage* si ) ...@@ -249,23 +249,22 @@ void DBServer_PostgreSQL::sensorInfo( const UniSetTypes::SensorMessage* si )
{ {
try try
{ {
#if 0 if( !si->tm.tv_sec )
// если время не было выставлено (указываем время сохранения в БД)
struct timeval tm = si->tm;
if( !tm.tv_sec )
{ {
struct timezone tz; // Выдаём CRIT, но тем не менее сохраняем в БД
gettimeofday(&tm, &tz);
dbcrit << myname << "(insert_main_history): UNKNOWN TIMESTAMP! (tm.tv_sec=0)"
<< " for sid=" << si->id
<< " supplier=" << uniset_conf()->oind->getMapName(si->supplier)
<< endl;
} }
#endif // (date, time, time_nsec, sensor_id, value, node)
// (date, time, time_usec, sensor_id, value, node)
PostgreSQLInterface::Record rec = PostgreSQLInterface::Record rec =
{ {
dateToString(si->sm_tv_sec, "-"), // date dateToString(si->sm_tv.tv_sec, "-"), // date
timeToString(si->sm_tv_sec, ":"), // time timeToString(si->sm_tv.tv_sec, ":"), // time
std::to_string(si->sm_tv_usec), std::to_string(si->sm_tv.tv_nsec),
std::to_string(si->id), std::to_string(si->id),
std::to_string(si->value), std::to_string(si->value),
std::to_string(si->node), std::to_string(si->node),
......
...@@ -103,7 +103,7 @@ void DBServer_SQLite::confirmInfo( const UniSetTypes::ConfirmMessage* cem ) ...@@ -103,7 +103,7 @@ void DBServer_SQLite::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
<< " WHERE sensor_id='" << cem->sensor_id << "'" << " WHERE sensor_id='" << cem->sensor_id << "'"
<< " AND date='" << dateToString(cem->time, "-") << " '" << " AND date='" << dateToString(cem->time, "-") << " '"
<< " AND time='" << timeToString(cem->time, ":") << " '" << " AND time='" << timeToString(cem->time, ":") << " '"
<< " AND time_usec='" << cem->time_usec << " '"; << " AND time_nsec='" << cem->time_nsec << " '";
dbinfo << myname << "(update_confirm): " << data.str() << endl; dbinfo << myname << "(update_confirm): " << data.str() << endl;
...@@ -184,7 +184,12 @@ void DBServer_SQLite::sensorInfo( const UniSetTypes::SensorMessage* si ) ...@@ -184,7 +184,12 @@ void DBServer_SQLite::sensorInfo( const UniSetTypes::SensorMessage* si )
// если время не было выставлено (указываем время сохранения в БД) // если время не было выставлено (указываем время сохранения в БД)
if( !si->tm.tv_sec ) if( !si->tm.tv_sec )
{ {
gettimeofday(const_cast<struct timeval*>(&si->tm), NULL); // Выдаём CRIT, но тем не менее сохраняем в БД
dbcrit << myname << "(insert_main_history): UNKNOWN TIMESTAMP! (tm.tv_sec=0)"
<< " for sid=" << si->id
<< " supplier=" << uniset_conf()->oind->getMapName(si->supplier)
<< endl;
} }
float val = (float)si->value / (float)pow10(si->ci.precision); float val = (float)si->value / (float)pow10(si->ci.precision);
...@@ -192,11 +197,11 @@ void DBServer_SQLite::sensorInfo( const UniSetTypes::SensorMessage* si ) ...@@ -192,11 +197,11 @@ void DBServer_SQLite::sensorInfo( const UniSetTypes::SensorMessage* si )
// см. DBTABLE AnalogSensors, DigitalSensors // см. DBTABLE AnalogSensors, DigitalSensors
ostringstream data; ostringstream data;
data << "INSERT INTO " << tblName(si->type) data << "INSERT INTO " << tblName(si->type)
<< "(date, time, time_usec, sensor_id, value, node) VALUES( '" << "(date, time, time_nsec, sensor_id, value, node) VALUES( '"
// Поля таблицы // Поля таблицы
<< dateToString(si->sm_tv_sec, "-") << "','" // date << dateToString(si->sm_tv.tv_sec, "-") << "','" // date
<< timeToString(si->sm_tv_sec, ":") << "','" // time << timeToString(si->sm_tv.tv_sec, ":") << "','" // time
<< si->sm_tv_usec << "'," // time_usec << si->sm_tv.tv_nsec << "'," // time_nsec
<< si->id << "','" // sensor_id << si->id << "','" // sensor_id
<< val << "','" // value << val << "','" // value
<< si->node << "')"; // node << si->node << "')"; // node
......
...@@ -87,7 +87,7 @@ CREATE TABLE `main_history` ( ...@@ -87,7 +87,7 @@ CREATE TABLE `main_history` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL, `date` date NOT NULL,
`time` time NOT NULL, `time` time NOT NULL,
`time_usec` int(10) unsigned NOT NULL, `time_nsec` int(10) unsigned NOT NULL,
`sensor_id` int(10) unsigned NOT NULL, `sensor_id` int(10) unsigned NOT NULL,
`value` double NOT NULL, `value` double NOT NULL,
`node` int(10) unsigned NOT NULL, `node` int(10) unsigned NOT NULL,
...@@ -102,7 +102,7 @@ CREATE TABLE `main_emergencylog` ( ...@@ -102,7 +102,7 @@ CREATE TABLE `main_emergencylog` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL, `date` date NOT NULL,
`time` time NOT NULL, `time` time NOT NULL,
`time_usec` int(10) unsigned NOT NULL, `time_nsec` int(10) unsigned NOT NULL,
`type_id` int(10) unsigned NOT NULL, `type_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `main_emergencylog_type_id` (`type_id`), KEY `main_emergencylog_type_id` (`type_id`),
...@@ -115,7 +115,7 @@ CREATE TABLE `main_emergencyrecords` ( ...@@ -115,7 +115,7 @@ CREATE TABLE `main_emergencyrecords` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL, `date` date NOT NULL,
`time` time NOT NULL, `time` time NOT NULL,
`time_usec` int(10) unsigned NOT NULL, `time_nsec` int(10) unsigned NOT NULL,
`log_id` int(11) NOT NULL, `log_id` int(11) NOT NULL,
`sensor_id` int(10) unsigned NOT NULL, `sensor_id` int(10) unsigned NOT NULL,
`value` double NOT NULL, `value` double NOT NULL,
......
...@@ -761,13 +761,13 @@ void SharedMemory::checkFuse( std::shared_ptr<USensorInfo>& usi, IOController* ) ...@@ -761,13 +761,13 @@ void SharedMemory::checkFuse( std::shared_ptr<USensorInfo>& usi, IOController* )
// return; // return;
long value = 0; long value = 0;
long sm_tv_sec = 0; unsigned long sm_tv_sec = 0;
long sm_tv_usec = 0; unsigned long sm_tv_nsec = 0;
{ {
uniset_rwmutex_rlock lock(usi->val_lock); uniset_rwmutex_rlock lock(usi->val_lock);
value = usi->value; value = usi->value;
sm_tv_sec = usi->tv_sec; sm_tv_sec = usi->tv_sec;
sm_tv_usec = usi->tv_usec; sm_tv_nsec = usi->tv_nsec;
} }
sminfo << myname << "(updateHistory): " sminfo << myname << "(updateHistory): "
...@@ -792,7 +792,7 @@ void SharedMemory::checkFuse( std::shared_ptr<USensorInfo>& usi, IOController* ) ...@@ -792,7 +792,7 @@ void SharedMemory::checkFuse( std::shared_ptr<USensorInfo>& usi, IOController* )
sminfo << myname << "(updateHistory): HISTORY EVENT for " << (*it) << endl; sminfo << myname << "(updateHistory): HISTORY EVENT for " << (*it) << endl;
it->fuse_sec = sm_tv_sec; it->fuse_sec = sm_tv_sec;
it->fuse_usec = sm_tv_usec; it->fuse_usec = sm_tv_nsec;
m_historySignal.emit( (*it) ); m_historySignal.emit( (*it) );
} }
} }
...@@ -811,7 +811,7 @@ void SharedMemory::checkFuse( std::shared_ptr<USensorInfo>& usi, IOController* ) ...@@ -811,7 +811,7 @@ void SharedMemory::checkFuse( std::shared_ptr<USensorInfo>& usi, IOController* )
sminfo << myname << "(updateHistory): HISTORY EVENT for " << (*it) << endl; sminfo << myname << "(updateHistory): HISTORY EVENT for " << (*it) << endl;
it->fuse_sec = sm_tv_sec; it->fuse_sec = sm_tv_sec;
it->fuse_usec = sm_tv_usec; it->fuse_usec = sm_tv_nsec;
m_historySignal.emit( (*it) ); m_historySignal.emit( (*it) );
} }
} }
...@@ -822,7 +822,7 @@ void SharedMemory::checkFuse( std::shared_ptr<USensorInfo>& usi, IOController* ) ...@@ -822,7 +822,7 @@ void SharedMemory::checkFuse( std::shared_ptr<USensorInfo>& usi, IOController* )
sminfo << myname << "(updateHistory): HISTORY EVENT for " << (*it) << endl; sminfo << myname << "(updateHistory): HISTORY EVENT for " << (*it) << endl;
it->fuse_sec = sm_tv_sec; it->fuse_sec = sm_tv_sec;
it->fuse_usec = sm_tv_usec; it->fuse_usec = sm_tv_nsec;
m_historySignal.emit( (*it) ); m_historySignal.emit( (*it) );
} }
} }
......
...@@ -85,7 +85,7 @@ struct IOBase ...@@ -85,7 +85,7 @@ struct IOBase
ti.id = UniSetTypes::DefaultObjectId; ti.id = UniSetTypes::DefaultObjectId;
ti.state = IONotifyController_i::NormalThreshold; ti.state = IONotifyController_i::NormalThreshold;
ti.tv_sec = 0; ti.tv_sec = 0;
ti.tv_usec = 0; ti.tv_nsec = 0;
} }
bool check_channel_break( long val ); /*!< проверка обрыва провода */ bool check_channel_break( long val ); /*!< проверка обрыва провода */
......
...@@ -326,8 +326,8 @@ class IOController: ...@@ -326,8 +326,8 @@ class IOController:
{ {
UniSetTypes::uniset_rwmutex_rlock lock(val_lock); UniSetTypes::uniset_rwmutex_rlock lock(val_lock);
sm.value = value; sm.value = value;
sm.sm_tv_sec = tv_sec; sm.sm_tv.tv_sec = tv_sec;
sm.sm_tv_usec = tv_usec; sm.sm_tv.tv_nsec = tv_nsec;
sm.ci = ci; sm.ci = ci;
sm.supplier = supplier; sm.supplier = supplier;
sm.undefined = undefined; sm.undefined = undefined;
......
...@@ -237,7 +237,7 @@ class IONotifyController: ...@@ -237,7 +237,7 @@ class IONotifyController:
r.lowlimit = lowlimit; r.lowlimit = lowlimit;
r.invert = invert; r.invert = invert;
r.tv_sec = tv_sec; r.tv_sec = tv_sec;
r.tv_usec = tv_usec; r.tv_nsec = tv_nsec;
r.state = state; r.state = state;
return r; return r;
} }
......
...@@ -56,8 +56,7 @@ namespace UniSetTypes ...@@ -56,8 +56,7 @@ namespace UniSetTypes
ObjectId node = { UniSetTypes::DefaultObjectId }; // откуда ObjectId node = { UniSetTypes::DefaultObjectId }; // откуда
ObjectId supplier = { UniSetTypes::DefaultObjectId }; // от кого ObjectId supplier = { UniSetTypes::DefaultObjectId }; // от кого
ObjectId consumer = { UniSetTypes::DefaultObjectId }; // кому ObjectId consumer = { UniSetTypes::DefaultObjectId }; // кому
struct timeval tm = { 0, 0 }; struct timespec tm = { 0, 0 };
Message( Message&& ) = default; Message( Message&& ) = default;
Message& operator=(Message&& ) = default; Message& operator=(Message&& ) = default;
...@@ -106,7 +105,7 @@ namespace UniSetTypes ...@@ -106,7 +105,7 @@ namespace UniSetTypes
if( tm.tv_sec != msg.tm.tv_sec ) if( tm.tv_sec != msg.tm.tv_sec )
return tm.tv_sec >= msg.tm.tv_sec; return tm.tv_sec >= msg.tm.tv_sec;
return tm.tv_usec >= msg.tm.tv_usec; return tm.tv_nsec >= msg.tm.tv_nsec;
} }
inline TransportMessage transport_msg() const inline TransportMessage transport_msg() const
...@@ -127,8 +126,7 @@ namespace UniSetTypes ...@@ -127,8 +126,7 @@ namespace UniSetTypes
bool undefined; bool undefined;
// время изменения состояния датчика // время изменения состояния датчика
long sm_tv_sec; struct timespec sm_tv;
long sm_tv_usec;
UniversalIO::IOType sensor_type; UniversalIO::IOType sensor_type;
IOController_i::CalibrateInfo ci; IOController_i::CalibrateInfo ci;
...@@ -233,7 +231,7 @@ namespace UniSetTypes ...@@ -233,7 +231,7 @@ namespace UniSetTypes
ConfirmMessage(ObjectId in_sensor_id, ConfirmMessage(ObjectId in_sensor_id,
double in_value, double in_value,
time_t in_time, time_t in_time,
time_t in_time_usec, time_t in_time_nsec,
time_t in_confirm, time_t in_confirm,
Priority in_priority = Message::Medium); Priority in_priority = Message::Medium);
...@@ -245,7 +243,7 @@ namespace UniSetTypes ...@@ -245,7 +243,7 @@ namespace UniSetTypes
ObjectId sensor_id; /* ID датчика */ ObjectId sensor_id; /* ID датчика */
double value; /* значение датчика */ double value; /* значение датчика */
time_t time; /* время, когда датчик получил сигнал */ time_t time; /* время, когда датчик получил сигнал */
time_t time_usec; /* время в микросекундах */ time_t time_nsec; /* время в наносекундах */
time_t confirm; /* время, когда произошло квитирование */ time_t confirm; /* время, когда произошло квитирование */
bool broadcast; bool broadcast;
......
...@@ -539,7 +539,7 @@ std::ostream& UniSetTypes::operator<<( std::ostream& os, const IONotifyControlle ...@@ -539,7 +539,7 @@ std::ostream& UniSetTypes::operator<<( std::ostream& os, const IONotifyControlle
<< " lowlim=" << ti.lowlimit << " lowlim=" << ti.lowlimit
<< " state=" << ti.state << " state=" << ti.state
<< " tv_sec=" << ti.tv_sec << " tv_sec=" << ti.tv_sec
<< " tv_usec=" << ti.tv_usec << " tv_nsec=" << ti.tv_nsec
<< " invert=" << ti.invert << " invert=" << ti.invert
<< " ]"; << " ]";
...@@ -549,7 +549,7 @@ std::ostream& UniSetTypes::operator<<( std::ostream& os, const IONotifyControlle ...@@ -549,7 +549,7 @@ std::ostream& UniSetTypes::operator<<( std::ostream& os, const IONotifyControlle
std::ostream& UniSetTypes::operator<<( std::ostream& os, const IOController_i::ShortIOInfo& s ) std::ostream& UniSetTypes::operator<<( std::ostream& os, const IOController_i::ShortIOInfo& s )
{ {
os << setw(10) << dateToString(s.tv_sec) os << setw(10) << dateToString(s.tv_sec)
<< " " << setw(8) << timeToString(s.tv_sec) << "." << s.tv_usec << " " << setw(8) << timeToString(s.tv_sec) << "." << s.tv_nsec
<< " [ value=" << s.value << " supplier=" << s.supplier << " ]"; << " [ value=" << s.value << " supplier=" << s.supplier << " ]";
return os; return os;
......
...@@ -304,12 +304,10 @@ void IOController::localSetValue( std::shared_ptr<USensorInfo>& usi, ...@@ -304,12 +304,10 @@ void IOController::localSetValue( std::shared_ptr<USensorInfo>& usi,
usi->value = (blocked ? usi->d_off_value : value); usi->value = (blocked ? usi->d_off_value : value);
// запоминаем время изменения // запоминаем время изменения
struct timeval tm = { 0 }; struct timespec tm;
tm.tv_sec = 0; ::clock_gettime(CLOCK_REALTIME, &tm);
tm.tv_usec = 0;
gettimeofday(&tm, NULL);
usi->tv_sec = tm.tv_sec; usi->tv_sec = tm.tv_sec;
usi->tv_usec = tm.tv_usec; usi->tv_nsec = tm.tv_nsec;
} }
} // unlock } // unlock
...@@ -376,12 +374,10 @@ void IOController::ioRegistration( std::shared_ptr<USensorInfo>& usi, bool force ...@@ -376,12 +374,10 @@ void IOController::ioRegistration( std::shared_ptr<USensorInfo>& usi, bool force
IOStateList::mapped_type ai = usi; IOStateList::mapped_type ai = usi;
// запоминаем начальное время // запоминаем начальное время
struct timeval tm; struct timespec tm;
tm.tv_sec = 0; ::clock_gettime(CLOCK_REALTIME, &tm);
tm.tv_usec = 0;
gettimeofday(&tm, NULL);
ai->tv_sec = tm.tv_sec; ai->tv_sec = tm.tv_sec;
ai->tv_usec = tm.tv_usec; ai->tv_nsec = tm.tv_nsec;
ai->value = ai->default_val; ai->value = ai->default_val;
ai->supplier = getId(); ai->supplier = getId();
...@@ -426,8 +422,6 @@ void IOController::logging( UniSetTypes::SensorMessage& sm ) ...@@ -426,8 +422,6 @@ void IOController::logging( UniSetTypes::SensorMessage& sm )
try try
{ {
// struct timezone tz;
// gettimeofday(&sm.tm,&tz);
ObjectId dbID = uniset_conf()->getDBServer(); ObjectId dbID = uniset_conf()->getDBServer();
// значит на этом узле нет DBServer-а // значит на этом узле нет DBServer-а
...@@ -701,7 +695,7 @@ IOController_i::ShortIOInfo IOController::getChangedTime( UniSetTypes::ObjectId ...@@ -701,7 +695,7 @@ IOController_i::ShortIOInfo IOController::getChangedTime( UniSetTypes::ObjectId
uniset_rwmutex_rlock lock(s->val_lock); uniset_rwmutex_rlock lock(s->val_lock);
i.value = s->value; i.value = s->value;
i.tv_sec = s->tv_sec; i.tv_sec = s->tv_sec;
i.tv_usec = s->tv_usec; i.tv_nsec = s->tv_nsec;
i.supplier = s->supplier; i.supplier = s->supplier;
return i; return i;
} }
......
...@@ -316,8 +316,8 @@ void IONotifyController::localSetValue( std::shared_ptr<IOController::USensorInf ...@@ -316,8 +316,8 @@ void IONotifyController::localSetValue( std::shared_ptr<IOController::USensorInf
sm.priority = (Message::Priority)usi->priority; sm.priority = (Message::Priority)usi->priority;
sm.supplier = sup_id; // owner_id sm.supplier = sup_id; // owner_id
sm.sensor_type = usi->type; sm.sensor_type = usi->type;
sm.sm_tv_sec = usi->tv_sec; sm.sm_tv.tv_sec = usi->tv_sec;
sm.sm_tv_usec = usi->tv_usec; sm.sm_tv.tv_nsec = usi->tv_nsec;
sm.ci = usi->ci; sm.ci = usi->ci;
} // unlock } // unlock
...@@ -648,12 +648,10 @@ bool IONotifyController::addThreshold( ThresholdExtList& lst, ThresholdInfoExt&& ...@@ -648,12 +648,10 @@ bool IONotifyController::addThreshold( ThresholdExtList& lst, ThresholdInfoExt&&
addConsumer(ti.clst, ci); addConsumer(ti.clst, ci);
// запоминаем начальное время // запоминаем начальное время
struct timeval tm; struct timespec tm;
tm.tv_sec = 0; ::clock_gettime(CLOCK_REALTIME, &tm);
tm.tv_usec = 0;
gettimeofday(&tm, NULL);
ti.tv_sec = tm.tv_sec; ti.tv_sec = tm.tv_sec;
ti.tv_usec = tm.tv_usec; ti.tv_nsec = tm.tv_nsec;
lst.emplace_back( std::move(ti) ); lst.emplace_back( std::move(ti) );
return true; return true;
...@@ -716,10 +714,8 @@ void IONotifyController::checkThreshold( std::shared_ptr<IOController::USensorIn ...@@ -716,10 +714,8 @@ void IONotifyController::checkThreshold( std::shared_ptr<IOController::USensorIn
SensorMessage sm(std::move(usi->makeSensorMessage())); SensorMessage sm(std::move(usi->makeSensorMessage()));
// текущее время // текущее время
struct timeval tm; struct timespec tm;
tm.tv_sec = 0; ::clock_gettime(CLOCK_REALTIME, &tm);
tm.tv_usec = 0;
gettimeofday(&tm, NULL);
{ {
uniset_rwmutex_rlock l(ti->mut); uniset_rwmutex_rlock l(ti->mut);
...@@ -761,9 +757,8 @@ void IONotifyController::checkThreshold( std::shared_ptr<IOController::USensorIn ...@@ -761,9 +757,8 @@ void IONotifyController::checkThreshold( std::shared_ptr<IOController::USensorIn
// запоминаем время изменения состояния // запоминаем время изменения состояния
it->tv_sec = tm.tv_sec; it->tv_sec = tm.tv_sec;
it->tv_usec = tm.tv_usec; it->tv_nsec = tm.tv_nsec;
sm.sm_tv_sec = tm.tv_sec; sm.sm_tv = tm;
sm.sm_tv_usec = tm.tv_usec;
// если порог связан с датчиком, то надо его выставить // если порог связан с датчиком, то надо его выставить
if( it->sid != UniSetTypes::DefaultObjectId ) if( it->sid != UniSetTypes::DefaultObjectId )
...@@ -889,7 +884,7 @@ IONotifyController_i::ThresholdList* IONotifyController::getThresholds( UniSetTy ...@@ -889,7 +884,7 @@ IONotifyController_i::ThresholdList* IONotifyController::getThresholds( UniSetTy
res->tlist[k].lowlimit = it2.lowlimit; res->tlist[k].lowlimit = it2.lowlimit;
res->tlist[k].state = it2.state; res->tlist[k].state = it2.state;
res->tlist[k].tv_sec = it2.tv_sec; res->tlist[k].tv_sec = it2.tv_sec;
res->tlist[k].tv_usec = it2.tv_usec; res->tlist[k].tv_nsec = it2.tv_nsec;
k++; k++;
} }
...@@ -943,7 +938,7 @@ IONotifyController_i::ThresholdsListSeq* IONotifyController::getThresholdsList() ...@@ -943,7 +938,7 @@ IONotifyController_i::ThresholdsListSeq* IONotifyController::getThresholdsList()
(*res)[i].tlist[k].lowlimit = it2.lowlimit; (*res)[i].tlist[k].lowlimit = it2.lowlimit;
(*res)[i].tlist[k].state = it2.state; (*res)[i].tlist[k].state = it2.state;
(*res)[i].tlist[k].tv_sec = it2.tv_sec; (*res)[i].tlist[k].tv_sec = it2.tv_sec;
(*res)[i].tlist[k].tv_usec = it2.tv_usec; (*res)[i].tlist[k].tv_nsec = it2.tv_nsec;
k++; k++;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
############################################################################ ############################################################################
noinst_LTLIBRARIES = libProcesses.la noinst_LTLIBRARIES = libProcesses.la
libProcesses_la_CXXFLAGS = $(SIGC_CFLAGS) $(EV_CFLAGS) libProcesses_la_CXXFLAGS = -I$(top_builddir)/include $(SIGC_CFLAGS) $(EV_CFLAGS)
libProcesses_la_LIBADD = $(SIGC_LIBS) $(EV_LIBS) libProcesses_la_LIBADD = $(SIGC_LIBS) $(EV_LIBS)
libProcesses_la_SOURCES = IOController_iSK.cc IOController.cc IONotifyController.cc \ libProcesses_la_SOURCES = IOController_iSK.cc IOController.cc IONotifyController.cc \
NCRestorer.cc NCRestorer_XML.cc EventLoopServer.cc CommonEventLoop.cc NCRestorer.cc NCRestorer_XML.cc EventLoopServer.cc CommonEventLoop.cc
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <chrono>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
...@@ -56,21 +57,9 @@ namespace UniSetTypes ...@@ -56,21 +57,9 @@ namespace UniSetTypes
supplier(DefaultObjectId), supplier(DefaultObjectId),
consumer(DefaultObjectId) consumer(DefaultObjectId)
{ {
tm.tv_sec = 0; ::clock_gettime(CLOCK_REALTIME, &tm);
tm.tv_usec = 0;
gettimeofday(&tm, NULL);
} }
/*
template<class In>
TransportMessage Message::transport(const In &msg)
{
TransportMessage tmsg;
assert(sizeof(UniSetTypes::RawDataOfTransportMessage)>=sizeof(msg));
memcpy(&tmsg.data,&msg,sizeof(msg));
return tmsg;
}
*/
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
VoidMessage::VoidMessage( const TransportMessage& tm ): VoidMessage::VoidMessage( const TransportMessage& tm ):
...@@ -95,10 +84,8 @@ namespace UniSetTypes ...@@ -95,10 +84,8 @@ namespace UniSetTypes
threshold(false), threshold(false),
tid(UniSetTypes::DefaultThresholdId) tid(UniSetTypes::DefaultThresholdId)
{ {
type = Message::SensorInfo; type = Message::SensorInfo;
sm_tv_sec = tm.tv_sec; sm_tv = tm; // или инициализировать нулём ?
sm_tv_usec = tm.tv_usec;
ci.minRaw = 0; ci.minRaw = 0;
ci.maxRaw = 0; ci.maxRaw = 0;
ci.minCal = 0; ci.minCal = 0;
...@@ -120,8 +107,7 @@ namespace UniSetTypes ...@@ -120,8 +107,7 @@ namespace UniSetTypes
type = Message::SensorInfo; type = Message::SensorInfo;
this->priority = priority; this->priority = priority;
this->consumer = consumer; this->consumer = consumer;
sm_tv_sec = tm.tv_sec; sm_tv = tm;
sm_tv_usec = tm.tv_usec;
} }
SensorMessage::SensorMessage(const VoidMessage* msg): SensorMessage::SensorMessage(const VoidMessage* msg):
...@@ -212,13 +198,13 @@ namespace UniSetTypes ...@@ -212,13 +198,13 @@ namespace UniSetTypes
ConfirmMessage::ConfirmMessage( UniSetTypes::ObjectId in_sensor_id, ConfirmMessage::ConfirmMessage( UniSetTypes::ObjectId in_sensor_id,
double in_value, double in_value,
time_t in_time, time_t in_time,
time_t in_time_usec, time_t in_time_nsec,
time_t in_confirm, time_t in_confirm,
Priority in_priority ): Priority in_priority ):
sensor_id(in_sensor_id), sensor_id(in_sensor_id),
value(in_value), value(in_value),
time(in_time), time(in_time),
time_usec(in_time_usec), time_nsec(in_time_nsec),
confirm(in_confirm), confirm(in_confirm),
broadcast(false), broadcast(false),
route(false) route(false)
......
...@@ -111,8 +111,8 @@ void SMonitor::sensorInfo( const SensorMessage* si ) ...@@ -111,8 +111,8 @@ void SMonitor::sensorInfo( const SensorMessage* si )
cout << "(" << setw(6) << si->id << "):" cout << "(" << setw(6) << si->id << "):"
<< "[(" << std::right << setw(5) << si->supplier << ")" << "[(" << std::right << setw(5) << si->supplier << ")"
<< std::left << setw(20) << s_sup << "] " << std::left << setw(20) << s_sup << "] "
<< std::right << setw(8) << timeToString(si->sm_tv_sec, ":") << std::right << setw(8) << timeToString(si->sm_tv.tv_sec, ":")
<< "(" << setw(6) << si->sm_tv_usec << "): " << "(" << setw(6) << si->sm_tv.tv_nsec << "): "
<< std::right << setw(45) << conf->oind->getMapName(si->id) << std::right << setw(45) << conf->oind->getMapName(si->id)
<< " value:" << std::right << setw(9) << si->value << " value:" << std::right << setw(9) << si->value
<< " fvalue:" << std::right << setw(12) << ( (float)si->value / pow(10.0, si->ci.precision) ) << endl; << " fvalue:" << std::right << setw(12) << ( (float)si->value / pow(10.0, si->ci.precision) ) << endl;
...@@ -128,7 +128,7 @@ void SMonitor::sensorInfo( const SensorMessage* si ) ...@@ -128,7 +128,7 @@ void SMonitor::sensorInfo( const SensorMessage* si )
else else
cmd << conf->getBinDir() << script; cmd << conf->getBinDir() << script;
cmd << " " << si->id << " " << si->value << " " << si->sm_tv_sec << " " << si->sm_tv_usec; cmd << " " << si->id << " " << si->value << " " << si->sm_tv.tv_sec << " " << si->sm_tv.tv_nsec;
int ret = system(cmd.str().c_str()); int ret = system(cmd.str().c_str());
int res = WEXITSTATUS(ret); int res = WEXITSTATUS(ret);
......
...@@ -190,12 +190,12 @@ TEST_CASE("ConfirmMessage", "[basic][message types][ConfirmMessage]" ) ...@@ -190,12 +190,12 @@ TEST_CASE("ConfirmMessage", "[basic][message types][ConfirmMessage]" )
ObjectId sid = 1; ObjectId sid = 1;
double val = 100; double val = 100;
time_t t_sec = 10; time_t t_sec = 10;
time_t t_usec = 300; time_t t_nsec = 300;
time_t t_confirm = 10; time_t t_confirm = 10;
SECTION("Default consturctor") SECTION("Default consturctor")
{ {
ConfirmMessage cm(sid, val, t_sec, t_usec, t_confirm); ConfirmMessage cm(sid, val, t_sec, t_nsec, t_confirm);
CHECK( cm.type == Message::Confirm ); CHECK( cm.type == Message::Confirm );
CHECK( cm.priority == Message::Medium ); CHECK( cm.priority == Message::Medium );
CHECK( cm.node == conf->getLocalNode() ); CHECK( cm.node == conf->getLocalNode() );
...@@ -204,7 +204,7 @@ TEST_CASE("ConfirmMessage", "[basic][message types][ConfirmMessage]" ) ...@@ -204,7 +204,7 @@ TEST_CASE("ConfirmMessage", "[basic][message types][ConfirmMessage]" )
REQUIRE( cm.sensor_id == sid ); REQUIRE( cm.sensor_id == sid );
REQUIRE( cm.value == val ); REQUIRE( cm.value == val );
REQUIRE( cm.time == t_sec ); REQUIRE( cm.time == t_sec );
REQUIRE( cm.time_usec == t_usec ); REQUIRE( cm.time_nsec == t_nsec );
REQUIRE( cm.confirm == t_confirm ); REQUIRE( cm.confirm == t_confirm );
CHECK( cm.broadcast == false ); CHECK( cm.broadcast == false );
CHECK( cm.route == false ); CHECK( cm.route == false );
...@@ -212,11 +212,11 @@ TEST_CASE("ConfirmMessage", "[basic][message types][ConfirmMessage]" ) ...@@ -212,11 +212,11 @@ TEST_CASE("ConfirmMessage", "[basic][message types][ConfirmMessage]" )
SECTION("Transport ConfirmMessage") SECTION("Transport ConfirmMessage")
{ {
ConfirmMessage cm(sid, val, t_sec, t_usec, t_confirm); ConfirmMessage cm(sid, val, t_sec, t_nsec, t_confirm);
REQUIRE( cm.sensor_id == sid ); REQUIRE( cm.sensor_id == sid );
REQUIRE( cm.value == val ); REQUIRE( cm.value == val );
REQUIRE( cm.time == t_sec ); REQUIRE( cm.time == t_sec );
REQUIRE( cm.time_usec == t_usec ); REQUIRE( cm.time_nsec == t_nsec );
REQUIRE( cm.confirm == t_confirm ); REQUIRE( cm.confirm == t_confirm );
auto tm = cm.transport_msg(); auto tm = cm.transport_msg();
...@@ -228,7 +228,7 @@ TEST_CASE("ConfirmMessage", "[basic][message types][ConfirmMessage]" ) ...@@ -228,7 +228,7 @@ TEST_CASE("ConfirmMessage", "[basic][message types][ConfirmMessage]" )
REQUIRE( cm2.sensor_id == sid ); REQUIRE( cm2.sensor_id == sid );
REQUIRE( cm2.value == val ); REQUIRE( cm2.value == val );
REQUIRE( cm2.time == t_sec ); REQUIRE( cm2.time == t_sec );
REQUIRE( cm2.time_usec == t_usec ); REQUIRE( cm2.time_nsec == t_nsec );
REQUIRE( cm2.confirm == t_confirm ); REQUIRE( cm2.confirm == t_confirm );
} }
} }
......
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