Commit a90a4af9 authored by Pavel Vainerman's avatar Pavel Vainerman

(ModbusMultiChannel): попытка исправить зависание на проверке соединения,

при переключении на другой канал.
parent b9126956
......@@ -453,6 +453,8 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%changelog
* Thu Feb 18 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt24
- modbustcpserver-echo: fixed bug for options
- ModbusTCPMultiMaster: add new logs,
add ignore option for GateList, modify change channel logic
* Wed Feb 17 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt23
- IONotifyController: fixed buf for init thresholdslist
......
......@@ -3187,7 +3187,7 @@ void MBExchange::updateRespondSensors()
{
bool set = d->resp_invert ? !d->resp_state : d->resp_state;
mblog4 << myname << ": SAVE NEW respond state=" << set
mblog4 << myname << ": SAVE NEW " << (d->resp_invert ? "NOT" : "") << " respond state=" << set
<< " for addr=" << ModbusRTU::addr2str(d->mbaddr)
<< " respond_id=" << d->resp_id
<< " state=" << d->resp_state
......
......@@ -31,7 +31,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
checktime = conf->getArgPInt("--" + prefix + "-checktime", it.getProp("checktime"), 5000);
force_disconnect = conf->getArgInt("--" + prefix + "-persistent-connection", it.getProp("persistent_connection")) ? false : true;
int ignore_timeout = conf->getArgPInt("--" + prefix + "-ignore-timeout", it.getProp("ignoreTimeout"), ptReopen.getInterval());
int ignore_timeout = conf->getArgPInt("--" + prefix + "-ignore-timeout", it.getProp("ignore_timeout"), ptReopen.getInterval());
UniXML::iterator it1(it);
......@@ -53,6 +53,12 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
for( ; it1.getCurrent(); it1++ )
{
if( it1.getIntProp("ignore") )
{
mbinfo << myname << "(init): IGNORE " << it1.getProp("ip") << ":" << it1.getProp("port") << endl;
continue;
}
MBSlaveInfo sinf;
sinf.ip = it1.getProp("ip");
......@@ -191,6 +197,14 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
{
uniset_rwmutex_wrlock l(tcpMutex);
// сперва надо обновить все ignore-ы
// т.к. фактически флаги выставляются и сбрасываются только здесь
for( auto it = mblist.rbegin(); it != mblist.rend(); ++it )
{
if( it->ignore && it->ptIgnoreTimeout.checkTime() )
it->ignore = false;
}
// если reopen=true - значит почему текущему каналу нет (хотя соединение есть)
// тогда выставляем ему признак игнорирования
if( mbi != mblist.rend() && reopen )
......@@ -208,6 +222,8 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
{
if( !mbi->ignore )
{
mblog4 << myname << "(initMB): SELECT CHANNEL " << mbi->ip << ":" << mbi->port << endl;
mb = mbi->mbtcp;
mbi->setUse(true);
return mbi->mbtcp;
......@@ -234,19 +250,12 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
{
uniset_rwmutex_wrlock l(tcpMutex);
if( it->respond && it->init(mblog) )
{
if( it->ignore )
if( it->respond && !it->ignore && it->init(mblog) )
{
if( !it->ptIgnoreTimeout.checkTime() )
continue;
it->ignore = false;
}
mbi = it;
mb = mbi->mbtcp;
mbi->setUse(true);
mblog4 << myname << "(initMB): SELECT CHANNEL " << mbi->ip << ":" << mbi->port << endl;
return it->mbtcp;
}
}
......@@ -372,6 +381,9 @@ void MBTCPMultiMaster::check_thread()
{
try
{
// сбрасываем флаг ignore..раз время вышло.
it->ignore = !it->ptIgnoreTimeout.checkTime();
// Если use=1" связь не проверяем и считаем что связь есть..
bool r = ( it->use ? true : it->check() );
......@@ -507,9 +519,13 @@ const std::string MBTCPMultiMaster::MBSlaveInfo::getShortInfo() const
{
ostringstream s;
s << myname << " respond=" << respond
<< " (respond_id=" << respond_id << " respond_invert=" << respond_invert
<< " recv_timeout=" << recv_timeout << " resp_force=" << respond_force
<< " use=" << use << " ignore=" << ignore << " priority=" << priority
<< " (respond_id=" << respond_id
<< " respond_invert=" << respond_invert
<< " recv_timeout=" << recv_timeout
<< " resp_force=" << respond_force
<< " use=" << use
<< " ignore=" << ( ptIgnoreTimeout.checkTime() ? "0":"1")
<< " priority=" << priority
<< " persistent-connection=" << !force_disconnect
<< ")";
......
......@@ -4,7 +4,7 @@
--confile test.xml \
--mbtcp-name MBMultiMaster1 \
--smemory-id SharedMemory \
--dlog-add-levels info,crit,warn,level4,level3,level9 \
--dlog-add-levels crit,warn,level4,level9 \
--mbtcp-set-prop-prefix \
--mbtcp-filter-field rs \
--mbtcp-filter-value 5 \
......@@ -12,11 +12,12 @@
--mbtcp-timeout 2000 \
--mbtcp-polltime 2000 \
--mbtcp-force-out 1 \
--mbtcp-log-add-levels any \
--mbtcp-log-add-levels level4,warn,crit \
--mbtcp-persistent-connection 1 \
--mbtcp-run-logserver \
$*
#--dlog-add-levels info,crit,warn,level4,level3,level9 \
#--mbtcp-exchange-mode-id MB1_Mode_AS \
#--mbtcp-filter-field mbtcp --mbtcp-filter-value 1
#--mbtcp-set-prop-prefix rs_ \
......
......@@ -128,16 +128,26 @@ TEST_CASE("MBTCPMultiMaster: rotate channel", "[modbus][mbmaster][mbtcpmultimast
mbs1->disableExchange(true);
msleep(4000); // --mbtcp-timeout 3000 (см. run_test_mbtcmultipmaster.sh)
REQUIRE( ui->getValue(1003) == 10 );
REQUIRE( ui->getValue(12) == true );
// Т.к. respond/notrespond проверяется по возможности создать соединение
// а мы имитируем отключение просто отключением обмена
// то датчик связи всё-равно будет показывать что канал1 доступен
// поэтому датчик 12 - не проверяем..
// а просто проверяем что теперь значение приходит по другому каналу
// (см. setReply)
// ----------------------------
// REQUIRE( ui->getValue(12) == true );
REQUIRE( ui->getValue(13) == false );
mbs1->disableExchange(false);
mbs2->disableExchange(true);
msleep(4000); // --mbtcp-timeout 3000 (см. run_test_mbtcmultipmaster.sh)
REQUIRE( ui->getValue(1003) == 100 );
REQUIRE( ui->getValue(12) == false );
// REQUIRE( ui->getValue(12) == false );
mbs2->disableExchange(false);
REQUIRE( ui->getValue(1003) == 100 );
REQUIRE( ui->getValue(13) == true );
// REQUIRE( ui->getValue(13) == 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