Commit 7345c868 authored by Pavel Vainerman's avatar Pavel Vainerman

(2.0): переписал интерфейс работы с парогами.

parent 6886264f
...@@ -185,18 +185,6 @@ interface IONotifyController_i : IOController_i ...@@ -185,18 +185,6 @@ interface IONotifyController_i : IOController_i
*/ */
void askSensor(in SensorInfo si, in UniSetTypes::ConsumerInfo ci, in UniversalIO::UIOCommand cmd ) raises(NameNotFound,IOBadParam); void askSensor(in SensorInfo si, in UniSetTypes::ConsumerInfo ci, in UniversalIO::UIOCommand cmd ) raises(NameNotFound,IOBadParam);
/*! Заказ порогового датчика
* \sa UniversalIO::UniversalIOController::askThreshold()
* \param tid - идентификатор порога
* \param lowLimit - нижний порог срабатыания
* \param hiLimit - верхний порог срабатывания
*
* Датчик срабатывает при условии, что значение <= lowLimit или >= hiLimit
*/
void askThreshold(in SensorInfo si, in UniSetTypes::ConsumerInfo ci, in UniSetTypes::ThresholdId tid,
in long lowLimit, in long hiLimit,
in UniversalIO::UIOCommand cmd ) raises(NameNotFound, IOBadParam, BadRange);
/*! /*!
Заказ сразу списка объектов. Заказ сразу списка объектов.
\return Возвращает список объектов заказ по котором не прошёл. \return Возвращает список объектов заказ по котором не прошёл.
...@@ -207,6 +195,7 @@ interface IONotifyController_i : IOController_i ...@@ -207,6 +195,7 @@ interface IONotifyController_i : IOController_i
in UniversalIO::UIOCommand cmd ); in UniversalIO::UIOCommand cmd );
/*! Состояние порогового датчика */ /*! Состояние порогового датчика */
enum ThresholdState enum ThresholdState
{ {
...@@ -223,11 +212,29 @@ interface IONotifyController_i : IOController_i ...@@ -223,11 +212,29 @@ interface IONotifyController_i : IOController_i
ThresholdState state; ThresholdState state;
long tv_sec; /*!< время последнего изменения датчика, секунды (gettimeofday) */ long tv_sec; /*!< время последнего изменения датчика, секунды (gettimeofday) */
long tv_usec; /*!< время последнего изменения датчика, мксек (gettimeofday) */ long tv_usec; /*!< время последнего изменения датчика, мксек (gettimeofday) */
boolean inverse; /*!< инверсная логика */ boolean invert; /*!< инвертированная логика */
}; };
typedef sequence<ThresholdInfo> ThresholdInfoSeq; typedef sequence<ThresholdInfo> ThresholdInfoSeq;
/*! Заказ порогового датчика
* \sa UniversalIO::UniversalIOController::askThreshold()
* \param tid - идентификатор порога
* \param lowLimit - нижний порог срабатыания
* \param hiLimit - верхний порог срабатывания
* \param invert - инвертировать логику срабатывания
* Если invert=false, порог срабатывает при условии >= hilimit и отпускается при <= lowlimit
* Если invert=true, порог срабатывает при условии <= lowlimit и отпускается при <= hilimit
*/
void askThreshold(in SensorInfo si, in UniSetTypes::ConsumerInfo ci, in UniSetTypes::ThresholdId tid,
in long lowLimit, in long hiLimit, in boolean invert,
in UniversalIO::UIOCommand cmd ) raises(NameNotFound, IOBadParam, BadRange);
/*! Получение информации о пороге
* Т.к. пороги могут иметь одинаковый tid для разных аналоговых датчиков, то передаётся и SensorInfo
*/
ThresholdInfo getThresholdInfo( in SensorInfo si, in UniSetTypes::ThresholdId tid ) raises(NameNotFound);
struct ThresholdList struct ThresholdList
{ {
...@@ -238,8 +245,12 @@ interface IONotifyController_i : IOController_i ...@@ -238,8 +245,12 @@ interface IONotifyController_i : IOController_i
}; };
typedef sequence<ThresholdList> ThresholdsListSeq; typedef sequence<ThresholdList> ThresholdsListSeq;
ThresholdsListSeq getThresholdsList();
/*! получить список порогов для датчка "si" */
ThresholdList getThresholds( in SensorInfo si ) raises(NameNotFound);
/*! получить список ВСЕХ датчиков по которым созданы пороги */
ThresholdsListSeq getThresholdsList();
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#endif #endif
...@@ -359,6 +359,7 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -359,6 +359,7 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
- ObjectsManager --> UniSetManager - ObjectsManager --> UniSetManager
- ObjectsActitvator --> UniSetActivator - ObjectsActitvator --> UniSetActivator
- remove deprecated property: "sensebility" - remove deprecated property: "sensebility"
- rename property "inverse" --> "threshold_invert"
* Tue Dec 10 2013 Pavel Vainerman <pv@altlinux.ru> 1.7-alt3 * Tue Dec 10 2013 Pavel Vainerman <pv@altlinux.ru> 1.7-alt3
- add RRDServer - add RRDServer
......
...@@ -1559,6 +1559,7 @@ void IOControl::waitSM() ...@@ -1559,6 +1559,7 @@ void IOControl::waitSM()
err << myname << "(execute): did not wait for the ready 'SharedMemory'. Timeout " err << myname << "(execute): did not wait for the ready 'SharedMemory'. Timeout "
<< smReadyTimeout << " msec"; << smReadyTimeout << " msec";
if( dlog.is_crit() )
dlog.crit() << err.str() << endl; dlog.crit() << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
......
...@@ -312,7 +312,6 @@ class IOControl: ...@@ -312,7 +312,6 @@ class IOControl:
CardList cards; /*!< список карт - массив созданных ComediInterface */ CardList cards; /*!< список карт - массив созданных ComediInterface */
bool noCards; bool noCards;
typedef std::vector<IOInfo> IOMap; typedef std::vector<IOInfo> IOMap;
IOMap iomap; /*!< список входов/выходов */ IOMap iomap; /*!< список входов/выходов */
......
...@@ -353,7 +353,7 @@ void IOBase::processingThreshold( IOBase* it, SMInterface* shm, bool force ) ...@@ -353,7 +353,7 @@ void IOBase::processingThreshold( IOBase* it, SMInterface* shm, bool force )
// cout << "val=" << val << " set=" << set << endl; // cout << "val=" << val << " set=" << set << endl;
// Проверка нижнего предела // Проверка нижнего предела
// значение должно быть меньше lowLimit-чуствительность // значение должно быть меньше lowLimit-чуствительность
if (it->ti.inverse) if (it->ti.invert)
{ {
if( val <= it->ti.lowlimit ) if( val <= it->ti.lowlimit )
set = true; set = true;
...@@ -540,14 +540,9 @@ bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm, ...@@ -540,14 +540,9 @@ bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
b->ti.lowlimit = it.getIntProp("lowlimit"); b->ti.lowlimit = it.getIntProp("lowlimit");
b->ti.hilimit = it.getIntProp("hilimit"); b->ti.hilimit = it.getIntProp("hilimit");
b->ti.inverse = it.getIntProp("inverse"); b->ti.invert = it.getIntProp("threshold_invert");
} }
} }
// else
// {
// dlog.crit() << myname << "(IOBase::readItem): неизвестный iotype=: " << stype << " для " << sname << endl;
// return false;
// }
return true; return true;
} }
......
...@@ -126,5 +126,24 @@ void TestProc::test_thresholds() ...@@ -126,5 +126,24 @@ void TestProc::test_thresholds()
setValue(t_set_c,378); setValue(t_set_c,378);
dlog.level1() << myname << ": check threshold ON value: " << ( getValue(t_check_s) == 1 ? "OK" : "FAIL" ) << endl; dlog.level1() << myname << ": check threshold ON value: " << ( getValue(t_check_s) == 1 ? "OK" : "FAIL" ) << endl;
dlog.level1() << myname << ": ask threshold and check.. " << endl;
try
{
setValue(t_set_c, 0);
UniSetTypes::ThresholdId tid = 100;
ui.askThreshold( t_set_c, tid, UniversalIO::UIONotify, 10, 20 );
IONotifyController_i::ThresholdInfo ti = ui.getThresholdInfo(t_set_c,tid);
dlog.level1() << myname << ": ask OFF threshold: " << ( ti.state == IONotifyController_i::NormalThreshold ? "OK" : "FAIL" ) << endl;
setValue(t_set_c, 25);
ti = ui.getThresholdInfo(t_set_c,tid);
dlog.level1() << myname << ": ask ON threshold: " << ( ti.state == IONotifyController_i::HiThreshold ? "OK" : "FAIL" ) << endl;
}
catch( Exception& ex )
{
dlog.level2() << myname << ": CHE 'ask and get threshold' FAILED: " << ex << endl;
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
<!-- проверка работы threshold-ов --> <!-- проверка работы threshold-ов -->
<item name="t_set_c" vartype="out" comment="аналоговый датчик (для выставления порога)"/> <item name="t_set_c" vartype="out" comment="аналоговый датчик (для выставления порога)"/>
<item name="t_check_s" vartype="in" comment="датчик для проверки срабатывания"/> <item name="t_check_s" vartype="in" comment="датчик для проверки срабатывания"/>
</smap> </smap>
<msgmap> <msgmap>
......
...@@ -142,17 +142,24 @@ class IONotifyController: ...@@ -142,17 +142,24 @@ class IONotifyController:
virtual void askThreshold(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci, virtual void askThreshold(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci,
UniSetTypes::ThresholdId tid, UniSetTypes::ThresholdId tid,
CORBA::Long lowLimit, CORBA::Long hiLimit, UniversalIO::UIOCommand cmd ); CORBA::Long lowLimit, CORBA::Long hiLimit, CORBA::Boolean invert,
UniversalIO::UIOCommand cmd );
virtual IONotifyController_i::ThresholdInfo getThresholdInfo( const IOController_i::SensorInfo& si, UniSetTypes::ThresholdId tid );
virtual IONotifyController_i::ThresholdList* getThresholds(const IOController_i::SensorInfo& si );
virtual IONotifyController_i::ThresholdsListSeq* getThresholdsList();
virtual UniSetTypes::IDSeq* askSensorsSeq(const UniSetTypes::IDSeq& lst, virtual UniSetTypes::IDSeq* askSensorsSeq(const UniSetTypes::IDSeq& lst,
const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd); const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd);
// --------------------------------------------
// функция для работы напрямую черех iterator (оптимизация)
virtual void localSetValue( IOController::IOStateList::iterator& it, virtual void localSetValue( IOController::IOStateList::iterator& it,
const IOController_i::SensorInfo& si, const IOController_i::SensorInfo& si,
CORBA::Long value, UniSetTypes::ObjectId sup_id ); CORBA::Long value, UniSetTypes::ObjectId sup_id );
// -------------------- !!!!!!!!! ---------------------------------
virtual IONotifyController_i::ThresholdsListSeq* getThresholdsList(); // --------------------------------------------
/*! Информация о заказчике */ /*! Информация о заказчике */
struct ConsumerInfoExt: struct ConsumerInfoExt:
...@@ -173,11 +180,10 @@ class IONotifyController: ...@@ -173,11 +180,10 @@ class IONotifyController:
struct ThresholdInfoExt: struct ThresholdInfoExt:
public IONotifyController_i::ThresholdInfo public IONotifyController_i::ThresholdInfo
{ {
ThresholdInfoExt( UniSetTypes::ThresholdId tid, CORBA::Long low, CORBA::Long hi, ThresholdInfoExt( UniSetTypes::ThresholdId tid, CORBA::Long low, CORBA::Long hi, bool inv,
UniSetTypes::ObjectId _sid=UniSetTypes::DefaultObjectId, UniSetTypes::ObjectId _sid=UniSetTypes::DefaultObjectId ):
bool inv = false ):
sid(_sid), sid(_sid),
inverse(inv) invert(inv)
{ {
id = tid; id = tid;
hilimit = hi; hilimit = hi;
...@@ -194,13 +200,27 @@ class IONotifyController: ...@@ -194,13 +200,27 @@ class IONotifyController:
IOController::IOStateList::iterator sit; IOController::IOStateList::iterator sit;
/*! инверсная логика */ /*! инверсная логика */
bool inverse; bool invert;
inline bool operator== ( const ThresholdInfo& r ) const inline bool operator== ( const ThresholdInfo& r ) const
{ {
return ((id == r.id) && return ((id == r.id) &&
(hilimit == r.hilimit) && (hilimit == r.hilimit) &&
(lowlimit == r.lowlimit) ); (lowlimit == r.lowlimit) &&
(invert == r.invert) );
}
operator IONotifyController_i::ThresholdInfo()
{
IONotifyController_i::ThresholdInfo r;
r.id = id;
r.hilimit = hilimit;
r.lowlimit = lowlimit;
r.invert = invert;
r.tv_sec = tv_sec;
r.tv_usec = tv_usec;
r.state = state;
return r;
} }
}; };
......
...@@ -115,7 +115,7 @@ namespace UniSetTypes ...@@ -115,7 +115,7 @@ namespace UniSetTypes
IOController_i::CalibrateInfo ci; IOController_i::CalibrateInfo ci;
// для пороговых датчиков // для пороговых датчиков
bool threshold; bool threshold; /*!< TRUE - сработал порог, FALSE - порог отключился */
UniSetTypes::ThresholdId tid; UniSetTypes::ThresholdId tid;
SensorMessage(); SensorMessage();
......
...@@ -120,18 +120,20 @@ class UInterface ...@@ -120,18 +120,20 @@ class UInterface
IOController_i::CalibrateInfo getCalibrateInfo( const IOController_i::SensorInfo& si ); IOController_i::CalibrateInfo getCalibrateInfo( const IOController_i::SensorInfo& si );
//! Заказ информации об изменении порога
//! Заказ информации об изменении дискретного датчика
void askThreshold( UniSetTypes::ObjectId sensorId, UniSetTypes::ThresholdId tid, void askThreshold( UniSetTypes::ObjectId sensorId, UniSetTypes::ThresholdId tid,
UniversalIO::UIOCommand cmd, UniversalIO::UIOCommand cmd,
CORBA::Long lowLimit=0, CORBA::Long hiLimit=0, long lowLimit, long hiLimit, bool invert = false,
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId ); UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId );
void askRemoteThreshold( UniSetTypes::ObjectId sensorId, UniSetTypes::ObjectId node, void askRemoteThreshold( UniSetTypes::ObjectId sensorId, UniSetTypes::ObjectId node,
UniSetTypes::ThresholdId thresholdId, UniversalIO::UIOCommand cmd, UniSetTypes::ThresholdId thresholdId, UniversalIO::UIOCommand cmd,
CORBA::Long lowLimit=0, CORBA::Long hiLimit=0, long lowLimit, long hiLimit, bool invert = false,
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId ); UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId );
IONotifyController_i::ThresholdInfo getThresholdInfo( const IOController_i::SensorInfo& si, UniSetTypes::ThresholdId tid );
IONotifyController_i::ThresholdInfo getThresholdInfo( UniSetTypes::ObjectId sid, UniSetTypes::ThresholdId tid );
// --------------------------------------------------------------- // ---------------------------------------------------------------
// Вспомогательные функции // Вспомогательные функции
......
...@@ -1219,15 +1219,15 @@ string UInterface::set_err(const string& pre, UniSetTypes::ObjectId id, UniSetTy ...@@ -1219,15 +1219,15 @@ string UInterface::set_err(const string& pre, UniSetTypes::ObjectId id, UniSetTy
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
void UInterface::askThreshold( UniSetTypes::ObjectId sid, UniSetTypes::ThresholdId tid, void UInterface::askThreshold( UniSetTypes::ObjectId sid, UniSetTypes::ThresholdId tid,
UniversalIO::UIOCommand cmd, UniversalIO::UIOCommand cmd,
CORBA::Long low, CORBA::Long hi, long low, long hi, bool invert,
UniSetTypes::ObjectId backid) UniSetTypes::ObjectId backid)
{ {
askRemoteThreshold(sid, uconf->getLocalNode(), tid, cmd, low,hi, backid); askRemoteThreshold(sid, uconf->getLocalNode(), tid, cmd, low, hi, invert, backid);
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
void UInterface::askRemoteThreshold( UniSetTypes::ObjectId sid, UniSetTypes::ObjectId node, void UInterface::askRemoteThreshold( UniSetTypes::ObjectId sid, UniSetTypes::ObjectId node,
UniSetTypes::ThresholdId tid, UniversalIO::UIOCommand cmd, UniSetTypes::ThresholdId tid, UniversalIO::UIOCommand cmd,
CORBA::Long lowLimit, CORBA::Long hiLimit, long lowLimit, long hiLimit, bool invert,
UniSetTypes::ObjectId backid ) UniSetTypes::ObjectId backid )
{ {
if( backid==UniSetTypes::DefaultObjectId ) if( backid==UniSetTypes::DefaultObjectId )
...@@ -1264,7 +1264,7 @@ void UInterface::askRemoteThreshold( UniSetTypes::ObjectId sid, UniSetTypes::Obj ...@@ -1264,7 +1264,7 @@ void UInterface::askRemoteThreshold( UniSetTypes::ObjectId sid, UniSetTypes::Obj
ci->id = backid; ci->id = backid;
ci->node = uconf->getLocalNode(); ci->node = uconf->getLocalNode();
inc->askThreshold(si,ci,tid,lowLimit,hiLimit,cmd); inc->askThreshold(si,ci,tid,lowLimit,hiLimit,invert,cmd);
return; return;
} }
catch(CORBA::TRANSIENT){} catch(CORBA::TRANSIENT){}
...@@ -1315,6 +1315,87 @@ void UInterface::askRemoteThreshold( UniSetTypes::ObjectId sid, UniSetTypes::Obj ...@@ -1315,6 +1315,87 @@ void UInterface::askRemoteThreshold( UniSetTypes::ObjectId sid, UniSetTypes::Obj
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
IONotifyController_i::ThresholdInfo
UInterface::getThresholdInfo( UniSetTypes::ObjectId sid, UniSetTypes::ThresholdId tid )
{
IOController_i::SensorInfo si;
si.id = sid;
si.node = conf->getLocalNode();
return getThresholdInfo(si,tid);
}
// --------------------------------------------------------------------------------------------------------------
IONotifyController_i::ThresholdInfo
UInterface::getThresholdInfo( const IOController_i::SensorInfo& si, UniSetTypes::ThresholdId tid )
{
if ( si.id == DefaultObjectId )
throw ORepFailed("UI(getThresholdInfo): попытка обратиться к объекту с id=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
try
{
oref = rcache.resolve(si.id, si.node);
}
catch( NameNotFound ){}
for( unsigned int i=0; i<uconf->getRepeatCount(); i++)
{
try
{
if( CORBA::is_nil(oref) )
oref = resolve( si.id, si.node );
IONotifyController_i_var iom = IONotifyController_i::_narrow(oref);
return iom->getThresholdInfo(si,tid);
}
catch(CORBA::TRANSIENT){}
catch(CORBA::OBJECT_NOT_EXIST){}
catch(CORBA::SystemException& ex){}
msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil();
}
}
catch(UniSetTypes::TimeOut){}
catch(IOController_i::NameNotFound &ex)
{
rcache.erase(si.id, si.node);
throw UniSetTypes::NameNotFound("UI(getThresholdInfo): "+string(ex.err));
}
catch(IOController_i::IOBadParam& ex)
{
rcache.erase(si.id, si.node);
throw UniSetTypes::IOBadParam("UI(getThresholdInfo): "+string(ex.err));
}
catch(ORepFailed)
{
rcache.erase(si.id, si.node);
// не смогли получить ссылку на объект
throw UniSetTypes::IOBadParam(set_err("UI(getThresholdInfo): resolve failed ",si.id,si.node));
}
catch(CORBA::NO_IMPLEMENT)
{
rcache.erase(si.id, si.node);
throw UniSetTypes::IOBadParam(set_err("UI(getThresholdInfo): method no implement",si.id,si.node));
}
catch(CORBA::OBJECT_NOT_EXIST)
{
rcache.erase(si.id, si.node);
throw UniSetTypes::IOBadParam(set_err("UI(getThresholdInfo): object not exist",si.id,si.node));
}
catch(CORBA::COMM_FAILURE& ex)
{
// ошибка системы коммуникации
}
catch(CORBA::SystemException& ex)
{
// ошибка системы коммуникации
// ulog.warn() << "UI(getValue): CORBA::SystemException" << endl;
}
rcache.erase(si.id, si.node);
throw UniSetTypes::TimeOut(set_err("UI(getThresholdInfo): Timeout",si.id,si.node));
}
// --------------------------------------------------------------------------------------------
long UInterface::getRawValue( const IOController_i::SensorInfo& si ) long UInterface::getRawValue( const IOController_i::SensorInfo& si )
{ {
if ( si.id == DefaultObjectId ) if ( si.id == DefaultObjectId )
......
...@@ -521,7 +521,8 @@ void IONotifyController::dumpThresholdList(const IOController_i::SensorInfo& si, ...@@ -521,7 +521,8 @@ void IONotifyController::dumpThresholdList(const IOController_i::SensorInfo& si,
void IONotifyController::askThreshold(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci, void IONotifyController::askThreshold(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci,
UniSetTypes::ThresholdId tid, UniSetTypes::ThresholdId tid,
CORBA::Long lowLimit, CORBA::Long hiLimit, UniversalIO::UIOCommand cmd ) CORBA::Long lowLimit, CORBA::Long hiLimit, CORBA::Boolean invert,
UniversalIO::UIOCommand cmd )
{ {
if( lowLimit > hiLimit ) if( lowLimit > hiLimit )
throw IONotifyController_i::BadRange(); throw IONotifyController_i::BadRange();
...@@ -536,7 +537,7 @@ void IONotifyController::askThreshold(const IOController_i::SensorInfo& si, cons ...@@ -536,7 +537,7 @@ void IONotifyController::askThreshold(const IOController_i::SensorInfo& si, cons
// поиск датчика в списке // поиск датчика в списке
UniSetTypes::KeyType skey( key(si.id,si.node) ); UniSetTypes::KeyType skey( key(si.id,si.node) );
AskThresholdMap::iterator it = askTMap.find(skey); AskThresholdMap::iterator it = askTMap.find(skey);
ThresholdInfoExt ti(tid,lowLimit,hiLimit); ThresholdInfoExt ti(tid,lowLimit,hiLimit,invert);
ti.sit = myioEnd(); ti.sit = myioEnd();
switch( cmd ) switch( cmd )
...@@ -708,7 +709,7 @@ bool IONotifyController::addThreshold(ThresholdExtList& lst, ThresholdInfoExt& t ...@@ -708,7 +709,7 @@ bool IONotifyController::addThreshold(ThresholdExtList& lst, ThresholdInfoExt& t
return true; return true;
} }
// -------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------
bool IONotifyController::removeThreshold(ThresholdExtList& lst, ThresholdInfoExt& ti, const UniSetTypes::ConsumerInfo& ci) bool IONotifyController::removeThreshold( ThresholdExtList& lst, ThresholdInfoExt& ti, const UniSetTypes::ConsumerInfo& ci )
{ {
for( ThresholdExtList::iterator it=lst.begin(); it!=lst.end(); ++it) for( ThresholdExtList::iterator it=lst.begin(); it!=lst.end(); ++it)
{ {
...@@ -772,88 +773,61 @@ void IONotifyController::checkThreshold( IOStateList::iterator& li, ...@@ -772,88 +773,61 @@ void IONotifyController::checkThreshold( IOStateList::iterator& li,
{ {
// Используем здесь sm.value чтобы не делать ещё раз lock на li->second.value // Используем здесь sm.value чтобы не делать ещё раз lock на li->second.value
// Проверка нижнего предела IONotifyController_i::ThresholdState state = it->state;
// значение должно быть меньше lowLimit-чуствительность
if( sm.value <= it->lowlimit )
{
if( it->state == IONotifyController_i::LowThreshold )
continue;
it->state = IONotifyController_i::LowThreshold;
sm.threshold = false;
sm.tid = it->id;
// запоминаем время изменения состояния
it->tv_sec = tm.tv_sec;
it->tv_usec = tm.tv_usec;
sm.sm_tv_sec = tm.tv_sec;
sm.sm_tv_usec = tm.tv_usec;
// порог связан с дискретным датчиком if( !it->invert )
if( it->sid != UniSetTypes::DefaultObjectId )
{
try
{ {
bool state(sm.threshold); // Если логика не инвертированная, то срабатывание это - выход за зону >= hilimit
// проверка на инвертированную логику if( sm.value <= it->lowlimit )
if( it->inverse ) state = IONotifyController_i::NormalThreshold;
state^=1; else if( sm.value >= it->hilimit )
state = IONotifyController_i::HiThreshold;
localSetValue(it->sit,SensorInfo(it->sid),(state ? 1:0),getId());
} }
catch( UniSetTypes::Exception& ex ) else
{ {
if( ulog.is_crit() ) // Если логика инвертированная, то срабатывание это - выход за зону <= lowlimit
ulog.crit() << myname << "(checkThreshold): " if( sm.value >= it->hilimit )
<< ex << endl; state = IONotifyController_i::NormalThreshold;
} else if( sm.value <= it->lowlimit )
state = IONotifyController_i::LowThreshold;
} }
if( send_msg ) // если ничего не менялось..
send(it->clst, sm); if( it->state == state )
}
// Проверка верхнего предела
// значение должно быть больше hiLimit+чуствительность
else if( sm.value >= it->hilimit )
{
if( it->state == IONotifyController_i::HiThreshold )
continue; continue;
it->state = IONotifyController_i::HiThreshold; it->state = state;
sm.threshold = true;
sm.tid = it->id; sm.tid = it->id;
// если состояние не normal, значит порог сработал,
// не важно какой.. нижний или верхний (зависит от inverse)
sm.threshold = ( state != IONotifyController_i::NormalThreshold ) ? true : false;
// запоминаем время изменения состояния // запоминаем время изменения состояния
it->tv_sec = tm.tv_sec; it->tv_sec = tm.tv_sec;
it->tv_usec = tm.tv_usec; it->tv_usec = tm.tv_usec;
sm.sm_tv_sec = tm.tv_sec; sm.sm_tv_sec = tm.tv_sec;
sm.sm_tv_usec = tm.tv_usec; sm.sm_tv_usec = tm.tv_usec;
// порог связан с дискретным датчиком // если порог связан с ддатчиком, то надо его выставить
if( it->sid != UniSetTypes::DefaultObjectId ) if( it->sid != UniSetTypes::DefaultObjectId )
{ {
try try
{ {
bool state(sm.threshold); localSetValue(it->sit,SensorInfo(it->sid),(sm.threshold ? 1:0),getId());
// проверка на инвертированную логику
if( it->inverse )
state^=1;
localSetValue(it->sit,SensorInfo(it->sid),(state?1:0),getId());
} }
catch( UniSetTypes::Exception& ex ) catch( UniSetTypes::Exception& ex )
{ {
if( ulog.is_crit() ) if( ulog.is_crit() )
ulog.crit() << myname << "(checkThreshold): " ulog.crit() << myname << "(checkThreshold): " << ex << endl;
<< ex << endl;
} }
} }
// отдельно посылаем сообщения заказчикам порогов, по данному "порогу"
if( send_msg ) if( send_msg )
send(it->clst, sm); send(it->clst, sm);
} }
else
it->state = IONotifyController_i::NormalThreshold;
}
} // unlock } // unlock
} }
// -------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------
...@@ -879,6 +853,90 @@ IONotifyController::ThresholdExtList::iterator IONotifyController::findThreshold ...@@ -879,6 +853,90 @@ IONotifyController::ThresholdExtList::iterator IONotifyController::findThreshold
return it; return it;
} }
// -------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------
IONotifyController_i::ThresholdInfo IONotifyController::getThresholdInfo( const IOController_i::SensorInfo& si,
UniSetTypes::ThresholdId tid )
{
uniset_rwmutex_rlock lock(trshMutex);
AskThresholdMap::iterator it = askTMap.find( key(si) );
if( it == askTMap.end() )
{
ostringstream err;
err << myname << "(getThresholds): Not found sensor (" << si.id << ":" << si.node << ") "
<< conf->oind->getNameById(si.id);
if( ulog.is_info() )
ulog.info() << err.str() << endl;
throw IOController_i::NameNotFound(err.str().c_str());
}
for( ThresholdExtList::const_iterator it2= it->second.list.begin(); it2!=it->second.list.end(); ++it2 )
{
if( it2->id == tid )
return IONotifyController_i::ThresholdInfo( *it2 );
}
ostringstream err;
err << myname << "(getThresholds): Not found for sensor (" << si.id << ":" << si.node << ") "
<< conf->oind->getNameById(si.id) << " ThresholdID='" << tid << "'";
if( ulog.is_info() )
ulog.info() << err.str() << endl;
throw IOController_i::NameNotFound(err.str().c_str());
}
// --------------------------------------------------------------------------------------------------------------
IONotifyController_i::ThresholdList* IONotifyController::getThresholds( const IOController_i::SensorInfo& si )
{
uniset_rwmutex_rlock lock(trshMutex);
AskThresholdMap::iterator it = askTMap.find( key(si) );
if( it == askTMap.end() )
{
ostringstream err;
err << myname << "(getThresholds): Not found sensor (" << si.id << ":" << si.node << ") "
<< conf->oind->getNameById(si.id);
if( ulog.is_info() )
ulog.info() << err.str() << endl;
throw IOController_i::NameNotFound(err.str().c_str());
}
IONotifyController_i::ThresholdList* res = new IONotifyController_i::ThresholdList();
try
{
res->si = it->second.si;
res->value = IOController::localGetValue(it->second.ait,it->second.si);
res->type = it->second.type;
}
catch( Exception& ex )
{
if( ulog.is_warn() )
ulog.warn() << myname << "(getThresholdsList): для датчика "
<< conf->oind->getNameById(it->second.si.id, it->second.si.node)
<< " " << ex << endl;
}
res->tlist.length( it->second.list.size() );
int k=0;
for( ThresholdExtList::const_iterator it2= it->second.list.begin(); it2!=it->second.list.end(); ++it2 )
{
res->tlist[k].id = it2->id;
res->tlist[k].hilimit = it2->hilimit;
res->tlist[k].lowlimit = it2->lowlimit;
res->tlist[k].state = it2->state;
res->tlist[k].tv_sec = it2->tv_sec;
res->tlist[k].tv_usec = it2->tv_usec;
k++;
}
return res;
}
// --------------------------------------------------------------------------------------------------------------
IONotifyController_i::ThresholdsListSeq* IONotifyController::getThresholdsList() IONotifyController_i::ThresholdsListSeq* IONotifyController::getThresholdsList()
{ {
// ulog.info() << myname << "(getThresholdsList): ...\n"; // ulog.info() << myname << "(getThresholdsList): ...\n";
......
...@@ -372,7 +372,7 @@ void NCRestorer_XML::read_thresholds(UniXML& xml, xmlNode* node, IONotifyControl ...@@ -372,7 +372,7 @@ void NCRestorer_XML::read_thresholds(UniXML& xml, xmlNode* node, IONotifyControl
ulog.info() << "(read_thresholds): \tthreshold low=" ulog.info() << "(read_thresholds): \tthreshold low="
<< ti.lowlimit << " \thi=" << ti.hilimit << ti.lowlimit << " \thi=" << ti.hilimit
<< " \t sid=" << ti.sid << " \t sid=" << ti.sid
<< " \t inverse=" << ti.inverse << " \t invert=" << ti.invert
<< endl << flush; << endl << flush;
} }
...@@ -473,7 +473,7 @@ bool NCRestorer_XML::getThresholdInfo( UniXML& xml,xmlNode* node, ...@@ -473,7 +473,7 @@ bool NCRestorer_XML::getThresholdInfo( UniXML& xml,xmlNode* node,
ti.id = uit.getIntProp("id"); ti.id = uit.getIntProp("id");
ti.lowlimit = uit.getIntProp("lowlimit"); ti.lowlimit = uit.getIntProp("lowlimit");
ti.hilimit = uit.getIntProp("hilimit"); ti.hilimit = uit.getIntProp("hilimit");
ti.inverse = uit.getIntProp("inverse"); ti.invert = uit.getIntProp("invert");
ti.state = IONotifyController_i::NormalThreshold; ti.state = IONotifyController_i::NormalThreshold;
return true; return true;
} }
......
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