Commit a7246ca9 authored by Pavel Vainerman's avatar Pavel Vainerman

(ModbusMaster): вынес ещё одну общую функцию в базовый класс

parent bbdd555e
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Name: libuniset Name: libuniset
Version: 1.0 Version: 1.0
Release: alt49 Release: alt50
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: GPL License: GPL
Group: Development/C++ Group: Development/C++
...@@ -212,6 +212,9 @@ rm -f %buildroot%_libdir/*.la ...@@ -212,6 +212,9 @@ rm -f %buildroot%_libdir/*.la
%changelog %changelog
* Mon Oct 31 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt50
- ModbusMaster extensions code refactoring
* Tue Oct 25 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt49 * Tue Oct 25 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt49
- added support 'const' and [private|protecte|public] - added support 'const' and [private|protecte|public]
for <variables> in uniset-codegen for <variables> in uniset-codegen
......
...@@ -58,6 +58,9 @@ pollActivated(false) ...@@ -58,6 +58,9 @@ pollActivated(false)
recv_timeout = conf->getArgPInt("--" + prefix + "-recv-timeout",it.getProp("recv_timeout"), 500); recv_timeout = conf->getArgPInt("--" + prefix + "-recv-timeout",it.getProp("recv_timeout"), 500);
int tout = conf->getArgPInt("--" + prefix + "-timeout",it.getProp("timeout"), 5000); int tout = conf->getArgPInt("--" + prefix + "-timeout",it.getProp("timeout"), 5000);
// для совместимости со старым RTUExchange
// надо обратывать и all-timeout
tout = conf->getArgPInt("--" + prefix + "-all-timeout",it.getProp("all_timeout"), tout);
ptTimeout.setTiming(tout); ptTimeout.setTiming(tout);
noQueryOptimization = conf->getArgInt("--" + prefix + "-no-query-optimization",it.getProp("no_query_optimization")); noQueryOptimization = conf->getArgInt("--" + prefix + "-no-query-optimization",it.getProp("no_query_optimization"));
...@@ -189,6 +192,8 @@ void MBExchange::step() ...@@ -189,6 +192,8 @@ void MBExchange::step()
if( !checkProcActive() ) if( !checkProcActive() )
return; return;
updateRespondSensors();
if( sidHeartBeat!=DefaultObjectId && ptHeartBeat.checkTime() ) if( sidHeartBeat!=DefaultObjectId && ptHeartBeat.checkTime() )
{ {
try try
...@@ -219,7 +224,7 @@ void MBExchange::setProcActive( bool st ) ...@@ -219,7 +224,7 @@ void MBExchange::setProcActive( bool st )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBExchange::sigterm( int signo ) void MBExchange::sigterm( int signo )
{ {
dlog[Debug::WARN] << myname << ": ********* SIGTERM(" << signo <<") ********" << endl; dlog[Debug::WARN] << myname << ": ********* SIGTERM(" << signo << ") ********" << endl;
setProcActive(false); setProcActive(false);
UniSetObject_LT::sigterm(signo); UniSetObject_LT::sigterm(signo);
} }
...@@ -2659,3 +2664,73 @@ bool MBExchange::RTUDevice::checkRespond() ...@@ -2659,3 +2664,73 @@ bool MBExchange::RTUDevice::checkRespond()
return ( prev != resp_state ); return ( prev != resp_state );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBExchange::updateRespondSensors()
{
bool chanTimeout = false;
{
uniset_mutex_lock l(pollMutex);
chanTimeout = pollActivated && ptTimeout.checkTime();
}
for( MBExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 )
{
RTUDevice* d(it1->second);
if( chanTimeout )
it1->second->resp_real = false;
if( dlog.debugging(Debug::LEVEL4) )
{
dlog[Debug::LEVEL4] << myname << ": check respond addr=" << ModbusRTU::addr2str(d->mbaddr)
<< " respond_id=" << d->resp_id
<< " real=" << d->resp_real
<< " state=" << d->resp_state
<< endl;
}
if( d->checkRespond() && d->resp_id != DefaultObjectId )
{
try
{
bool set = d->resp_invert ? !d->resp_state : d->resp_state;
shm->localSaveState(d->resp_dit,d->resp_id,set,getId());
}
catch( Exception& ex )
{
dlog[Debug::CRIT] << myname << "(step): (respond) " << ex << std::endl;
}
}
}
}
// -----------------------------------------------------------------------------
void MBExchange::execute()
{
no_extimer = true;
try
{
askTimer(tmExchange,0);
}
catch(...){}
initMB(false);
while(1)
{
try
{
step();
}
catch( Exception& ex )
{
dlog[Debug::CRIT] << myname << "(execute): " << ex << std::endl;
}
catch(...)
{
dlog[Debug::CRIT] << myname << "(execute): catch ..." << endl;
}
msleep(polltime);
}
}
// -----------------------------------------------------------------------------
...@@ -117,54 +117,6 @@ void MBTCPMaster::sysCommand( UniSetTypes::SystemMessage *sm ) ...@@ -117,54 +117,6 @@ void MBTCPMaster::sysCommand( UniSetTypes::SystemMessage *sm )
pollThread->start(); pollThread->start();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBTCPMaster::step()
{
updateRespondSensors();
MBExchange::step();
}
// -----------------------------------------------------------------------------
void MBTCPMaster::updateRespondSensors()
{
bool tcpIsTimeout = false;
{
uniset_mutex_lock l(tcpMutex);
tcpIsTimeout = pollActivated && ptTimeout.checkTime();
}
if( dlog.debugging(Debug::LEVEL4) )
dlog[Debug::LEVEL4] << myname << ": tcpTimeout=" << tcpIsTimeout << endl;
for( MBTCPMaster::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 )
{
RTUDevice* d(it1->second);
if( tcpIsTimeout )
d->resp_real = false;
if( dlog.debugging(Debug::LEVEL4) )
{
dlog[Debug::LEVEL4] << myname << ": check respond addr=" << ModbusRTU::addr2str(d->mbaddr)
<< " respond_id=" << d->resp_id
<< " real=" << d->resp_real
<< " state=" << d->resp_state
<< endl;
}
if( d->checkRespond() && d->resp_id != DefaultObjectId )
{
try
{
bool set = d->resp_invert ? !d->resp_state : d->resp_state;
shm->localSaveState(d->resp_dit,d->resp_id,set,getId());
}
catch( Exception& ex )
{
dlog[Debug::CRIT] << myname << "(step): (respond) " << ex << std::endl;
}
}
}
}
// -----------------------------------------------------------------------------
void MBTCPMaster::poll_thread() void MBTCPMaster::poll_thread()
{ {
{ {
...@@ -193,39 +145,6 @@ void MBTCPMaster::poll_thread() ...@@ -193,39 +145,6 @@ void MBTCPMaster::poll_thread()
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBTCPMaster::sigterm( int signo )
{
dlog[Debug::WARN] << myname << ": ********* SIGTERM(" << signo <<") ********" << endl;
setProcActive(false);
/*! \todo Доделать выставление безопасного состояния на выходы.
И нужно ли это. Ведь может не хватить времени на "обмен"
*/
// выставление безопасного состояния на выходы....
/*
RSMap::iterator it=rsmap.begin();
for( ; it!=rsmap.end(); ++it )
{
// if( it->stype!=UniversalIO::DigitalOutput && it->stype!=UniversalIO::AnalogOutput )
// continue;
if( it->safety == NoSafetyState )
continue;
try
{
}
catch( UniSetTypes::Exception& ex )
{
dlog[Debug::WARN] << myname << "(sigterm): " << ex << std::endl;
}
catch(...){}
}
*/
UniSetObject_LT::sigterm(signo);
}
// ------------------------------------------------------------------------------------------
void MBTCPMaster::help_print( int argc, const char* const* argv ) void MBTCPMaster::help_print( int argc, const char* const* argv )
{ {
cout << "Default: prefix='mbtcp'" << endl; cout << "Default: prefix='mbtcp'" << endl;
...@@ -264,34 +183,3 @@ MBTCPMaster* MBTCPMaster::init_mbmaster( int argc, const char* const* argv, ...@@ -264,34 +183,3 @@ MBTCPMaster* MBTCPMaster::init_mbmaster( int argc, const char* const* argv,
return new MBTCPMaster(ID,icID,ic,prefix); return new MBTCPMaster(ID,icID,ic,prefix);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBTCPMaster::execute()
{
no_extimer = true;
try
{
askTimer(tmExchange,0);
}
catch(...){}
initMB(false);
while(1)
{
try
{
step();
}
catch( Exception& ex )
{
dlog[Debug::CRIT] << myname << "(execute): " << ex << std::endl;
}
catch(...)
{
dlog[Debug::CRIT] << myname << "(execute): catch ..." << endl;
}
msleep(polltime);
}
}
// -----------------------------------------------------------------------------
...@@ -10,5 +10,6 @@ uniset-start.sh -f ./uniset-rtuexchange --confile test.xml \ ...@@ -10,5 +10,6 @@ uniset-start.sh -f ./uniset-rtuexchange --confile test.xml \
--dlog-add-levels info,crit,warn,level4,level3 \ --dlog-add-levels info,crit,warn,level4,level3 \
--rs-force 0 \ --rs-force 0 \
--rs-force-out 0 \ --rs-force-out 0 \
--rs-polltime 3000
#,level3 #,level3
# --rs-force 1 \ # --rs-force 1 \
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