Commit fb5945ec authored by Pavel Vainerman's avatar Pavel Vainerman

(Modbus): Добавил параметр --xxx-reopen-timeout определяющий, через сколько msec…

(Modbus): Добавил параметр --xxx-reopen-timeout определяющий, через сколько msec после пропажи соединения, будет происходить попытка, переоткрыть соединение (TCP) или файл устройства (RTU). // close eterbug #9296
parent bf3fb32a
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
Name: libuniset Name: libuniset
Version: 1.6 Version: 1.6
Release: alt8 Release: alt9
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
...@@ -319,6 +319,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -319,6 +319,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%exclude %_pkgconfigdir/libUniSet.pc %exclude %_pkgconfigdir/libUniSet.pc
%changelog %changelog
* Tue May 14 2013 Pavel Vainerman <pv@altlinux.ru> 1.6-alt9
- add for Modbus (RTU|TCP) exchange --xxx-reopen-timeout msec. (eterbug #9296)
* Wed May 08 2013 Pavel Vainerman <pv@altlinux.ru> 1.6-alt8 * Wed May 08 2013 Pavel Vainerman <pv@altlinux.ru> 1.6-alt8
- fixed minor bug in uniset-codegen (getValue) - fixed minor bug in uniset-codegen (getValue)
......
...@@ -65,6 +65,9 @@ pollActivated(false) ...@@ -65,6 +65,9 @@ pollActivated(false)
tout = conf->getArgPInt("--" + prefix + "-all-timeout",it.getProp("all_timeout"), tout); tout = conf->getArgPInt("--" + prefix + "-all-timeout",it.getProp("all_timeout"), tout);
ptTimeout.setTiming(tout); ptTimeout.setTiming(tout);
tout = conf->getArgPInt("--" + prefix + "-reopen-timeout",it.getProp("reopen_timeout"), 10000);
ptReopen.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"));
mbregFromID = conf->getArgInt("--" + prefix + "-reg-from-id",it.getProp("reg_from_id")); mbregFromID = conf->getArgInt("--" + prefix + "-reg-from-id",it.getProp("reg_from_id"));
...@@ -139,6 +142,7 @@ void MBExchange::help_print( int argc, const char* const* argv ) ...@@ -139,6 +142,7 @@ void MBExchange::help_print( int argc, const char* const* argv )
cout << "--prefix-polltime msec - Пауза между опросаом карт. По умолчанию 200 мсек." << endl; cout << "--prefix-polltime msec - Пауза между опросаом карт. По умолчанию 200 мсек." << endl;
cout << "--prefix-recv-timeout msec - Таймаут на приём одного сообщения" << endl; cout << "--prefix-recv-timeout msec - Таймаут на приём одного сообщения" << endl;
cout << "--prefix-timeout msec - Таймаут для определения отсутсвия соединения" << endl; cout << "--prefix-timeout msec - Таймаут для определения отсутсвия соединения" << endl;
cout << "--prefix-reopen-timeout msec - Таймаут для 'переоткрытия соединения' при отсутсвия соединения msec милисекунд. По умолчанию 10 сек." << endl;
cout << "--prefix-heartbeat-id name - Данный процесс связан с указанным аналоговым heartbeat-дачиком." << endl; cout << "--prefix-heartbeat-id name - Данный процесс связан с указанным аналоговым heartbeat-дачиком." << endl;
cout << "--prefix-heartbeat-max val - Максимальное значение heartbeat-счётчика для данного процесса. По умолчанию 10." << endl; cout << "--prefix-heartbeat-max val - Максимальное значение heartbeat-счётчика для данного процесса. По умолчанию 10." << endl;
cout << "--prefix-ready-timeout msec - Время ожидания готовности SM к работе, мсек. (-1 - ждать 'вечно')" << endl; cout << "--prefix-ready-timeout msec - Время ожидания готовности SM к работе, мсек. (-1 - ждать 'вечно')" << endl;
...@@ -2656,6 +2660,8 @@ void MBExchange::poll() ...@@ -2656,6 +2660,8 @@ void MBExchange::poll()
if( !checkProcActive() ) if( !checkProcActive() )
return; return;
bool allNotRespond = true;
for( MBExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 ) for( MBExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 )
{ {
RTUDevice* d(it1->second); RTUDevice* d(it1->second);
...@@ -2700,6 +2706,9 @@ void MBExchange::poll() ...@@ -2700,6 +2706,9 @@ void MBExchange::poll()
d->resp_real = true; d->resp_real = true;
} }
if( d->resp_real )
allNotRespond = false;
if( it==d->regmap.end() ) if( it==d->regmap.end() )
break; break;
...@@ -2743,6 +2752,19 @@ void MBExchange::poll() ...@@ -2743,6 +2752,19 @@ void MBExchange::poll()
IOBase::processingThreshold( &(*i),shm,force); IOBase::processingThreshold( &(*i),shm,force);
} }
} }
if( trReopen.hi(allNotRespond) )
ptReopen.reset();
if( allNotRespond && ptReopen.checkTime() )
{
uniset_mutex_lock l(pollMutex, 300);
if( dlog.debugging(Debug::WARN) )
dlog[Debug::WARN] << myname << ": REOPEN timeout..(" << ptReopen.getInterval() << ")" << endl;
mb = initMB(true);
ptReopen.reset();
}
// printMap(rmap); // printMap(rmap);
} }
......
...@@ -314,6 +314,9 @@ class MBExchange: ...@@ -314,6 +314,9 @@ class MBExchange:
bool pollActivated; bool pollActivated;
int recv_timeout; int recv_timeout;
PassiveTimer ptReopen; /*!< таймер для переоткрытия соединения */
Trigger trReopen;
private: private:
MBExchange(); MBExchange();
......
...@@ -67,7 +67,6 @@ rs_pre_clean(false) ...@@ -67,7 +67,6 @@ rs_pre_clean(false)
else else
ic->addReadItem( sigc::mem_fun(this,&RTUExchange::readItem) ); ic->addReadItem( sigc::mem_fun(this,&RTUExchange::readItem) );
initMB(false); initMB(false);
if( dlog.debugging(Debug::INFO) ) if( dlog.debugging(Debug::INFO) )
...@@ -205,6 +204,7 @@ void RTUExchange::poll() ...@@ -205,6 +204,7 @@ void RTUExchange::poll()
if( !checkProcActive() ) if( !checkProcActive() )
return; return;
bool allNotRespond = true;
ComPort::Speed s = mbrtu->getSpeed(); ComPort::Speed s = mbrtu->getSpeed();
for( MBExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 ) for( MBExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 )
...@@ -291,6 +291,9 @@ void RTUExchange::poll() ...@@ -291,6 +291,9 @@ void RTUExchange::poll()
return; return;
} }
} }
if( d->resp_real )
allNotRespond = false;
} }
// update SharedMemory... // update SharedMemory...
...@@ -307,6 +310,19 @@ void RTUExchange::poll() ...@@ -307,6 +310,19 @@ void RTUExchange::poll()
IOBase::processingThreshold( &(*i),shm,force); IOBase::processingThreshold( &(*i),shm,force);
} }
} }
if( trReopen.hi(allNotRespond) )
ptReopen.reset();
if( allNotRespond && ptReopen.checkTime() )
{
uniset_mutex_lock l(pollMutex, 300);
if( dlog.debugging(Debug::WARN) )
dlog[Debug::WARN] << myname << ": REOPEN timeout..(" << ptReopen.getInterval() << ")" << endl;
mb = initMB(true);
ptReopen.reset();
}
// printMap(rmap); // printMap(rmap);
} }
......
...@@ -44,9 +44,6 @@ class RTUExchange: ...@@ -44,9 +44,6 @@ class RTUExchange:
UniSetTypes::uniset_mutex pollMutex; UniSetTypes::uniset_mutex pollMutex;
bool rs_pre_clean; bool rs_pre_clean;
bool allNotRespond;
Trigger trAllNotRespond;
// PassiveTimer ptAllNotRespond;
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#endif // _RS_EXCHANGE_H_ #endif // _RS_EXCHANGE_H_
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
--mbtcp-gateway-port 2048 \ --mbtcp-gateway-port 2048 \
--mbtcp-recv-timeout 5000 \ --mbtcp-recv-timeout 5000 \
--mbtcp-force-disconnect 1 \ --mbtcp-force-disconnect 1 \
--mbtcp-polltime 5000 \ --mbtcp-polltime 3000 \
--mbtcp-exchange-mode-id MB1_Mode_AS \ --mbtcp-exchange-mode-id MB1_Mode_AS \
#--mbtcp-set-prop-prefix tcp_ #--mbtcp-set-prop-prefix tcp_
#--mbtcp-filter-field mbtcp --mbtcp-filter-value 1 #--mbtcp-filter-field mbtcp --mbtcp-filter-value 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