Commit 07b13146 authored by Pavel Vainerman's avatar Pavel Vainerman

(ModbusMultiMaster): работа над тестом, внесение правок по результатам тестирования

parent 3db7758a
......@@ -1808,7 +1808,7 @@ MBExchange::RTUDevice* MBExchange::addDev( RTUDeviceMap& mp, ModbusRTU::ModbusAd
return 0;
}
dcrit << myname << "(addDev): device for addr=" << ModbusRTU::addr2str(a)
dinfo << myname << "(addDev): device for addr=" << ModbusRTU::addr2str(a)
<< " already added. Ignore device params for " << xmlit.getProp("name") << " ..." << endl;
return it->second;
}
......@@ -2723,7 +2723,7 @@ void MBExchange::timerInfo( const TimerMessage *tm )
}
}
// -----------------------------------------------------------------------------
void MBExchange::poll()
bool MBExchange::poll()
{
if( !mb )
{
......@@ -2739,11 +2739,11 @@ void MBExchange::poll()
}
if( !checkProcActive() )
return;
return false;
updateSM();
allInitOK = false;
return;
return false;
}
{
......@@ -2756,7 +2756,7 @@ void MBExchange::poll()
firstInitRegisters();
if( !checkProcActive() )
return;
return false;
bool allNotRespond = true;
......@@ -2774,7 +2774,7 @@ void MBExchange::poll()
for( auto it=d->regmap.begin(); it!=d->regmap.end(); ++it )
{
if( !checkProcActive() )
return;
return false;
if( exchangeMode == emSkipExchange )
{
......@@ -2814,7 +2814,7 @@ void MBExchange::poll()
break;
if( !checkProcActive() )
return;
return false;
}
if( stat_time > 0 )
......@@ -2834,7 +2834,7 @@ void MBExchange::poll()
}
if( !checkProcActive() )
return;
return false;
// update SharedMemory...
updateSM();
......@@ -2843,7 +2843,7 @@ void MBExchange::poll()
for( auto t=thrlist.begin(); t!=thrlist.end(); ++t )
{
if( !checkProcActive() )
return;
return false;
IOBase::processingThreshold(&(*t),shm,force);
}
......@@ -2860,6 +2860,8 @@ void MBExchange::poll()
}
// printMap(rmap);
return !allNotRespond;
}
// -----------------------------------------------------------------------------
bool MBExchange::RTUDevice::checkRespond()
......
......@@ -251,7 +251,7 @@ class MBExchange:
virtual std::shared_ptr<ModbusClient> initMB( bool reopen=false )= 0;
virtual void poll();
virtual bool poll();
bool pollRTU( RTUDevice* dev, RegMap::iterator& it );
void updateSM();
......
......@@ -49,6 +49,8 @@ checkThread(0)
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());
UniXML::iterator it1(it);
if( !it1.find("GateList") )
{
......@@ -102,6 +104,7 @@ checkThread(0)
sinf.priority = it1.getIntProp("priority");
sinf.mbtcp = std::make_shared<ModbusTCPMaster>();
sinf.ptIgnoreTimeout.setTiming( it1.getPIntProp("ignore_timeout",ignore_timeout) );
sinf.recv_timeout = it1.getPIntProp("recv_timeout",recv_timeout);
sinf.aftersend_pause = it1.getPIntProp("aftersend_pause",aftersend_pause);
sinf.sleepPause_usec = it1.getPIntProp("sleepPause_usec",sleepPause_usec);
......@@ -175,7 +178,7 @@ MBTCPMultiMaster::~MBTCPMultiMaster()
for( auto &it: mblist )
{
it.mbtcp = nullptr;
it.mbtcp.reset(); // = nullptr;
mbi = mblist.rend();
}
}
......@@ -197,13 +200,33 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
{
uniset_rwmutex_wrlock l(tcpMutex);
// если reopen=true - значит почему текущему каналу нет (хотя соединение есть)
// тогда выставляем ему признак игнорирования
if( mbi!=mblist.rend() && reopen )
{
mbi->ignore = true;
mbi->ptIgnoreTimeout.reset();
dwarn << myname << "(initMB): set ignore=true for " << mbi->ip << ":" << mbi->port << endl;
}
// Если по текущему каналу связь есть, то возвращаем его
if( mbi!=mblist.rend() && mbi->respond )
if( mbi!=mblist.rend() && !mbi->ignore && mbi->respond )
{
if( mbi->mbtcp->isConnection() || ( !mbi->mbtcp->isConnection() && mbi->init()) )
{
mb = mbi->mbtcp;
return mbi->mbtcp;
if( !mbi->ignore )
{
mb = mbi->mbtcp;
return mbi->mbtcp;
}
if( mbi->ptIgnoreTimeout.checkTime() )
{
mbi->ignore = false;
mb = mbi->mbtcp;
return mbi->mbtcp;
}
}
}
......@@ -217,6 +240,14 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
uniset_rwmutex_wrlock l(tcpMutex);
if( it->respond && it->init() )
{
if( it->ignore )
{
if( !it->ptIgnoreTimeout.checkTime() )
continue;
it->ignore = false;
}
mbi = it;
mb = mbi->mbtcp;
return it->mbtcp;
......@@ -378,11 +409,13 @@ void MBTCPMultiMaster::help_print( int argc, const char* const* argv )
MBExchange::help_print(argc,argv);
cout << endl;
cout << " Настройки протокола TCP(MultiMaster): " << endl;
cout << "--prefix-persistent-connection 0,1 - Не закрывать соединение на каждом цикле опроса" << endl;
cout << "--prefix-checktime - период проверки связи по каналам (<GateList>)" << endl;
cout << "--prefix-persistent-connection 0,1 - Не закрывать соединение на каждом цикле опроса" << endl;
cout << "--prefix-checktime - период проверки связи по каналам (<GateList>)" << endl;
cout << "--prefix-ignore-timeout - Timeout на повторную попытку использования канала после 'reopen-timeout'. По умолчанию: reopen-timeout * 3" << endl;
cout << endl;
cout << " ВНИМАНИЕ! '--prefix-reopen-timeout' для MBTCPMultiMaster НЕ ДЕЙСТВУЕТ! " << endl;
cout << " Переключение на следующий канал зависит от '--prefix-timeout'" << endl;
cout << " Смена канала происходит по --prefix-timeout. " << endl;
cout << " При этом следует учитывать блокировку отключаемого канала на время: --prefix-ignore-timeout" << endl;
}
// -----------------------------------------------------------------------------
std::shared_ptr<MBTCPMultiMaster> MBTCPMultiMaster::init_mbmaster( int argc, const char* const* argv,
......
......@@ -247,7 +247,7 @@ class MBTCPMultiMaster:
respond(false),respond_id(UniSetTypes::DefaultObjectId),respond_invert(false),
recv_timeout(200),aftersend_pause(0),sleepPause_usec(100),
force_disconnect(true),
myname(""),initOK(false){}
myname(""),initOK(false),ignore(false){}
std::string ip;
int port;
......@@ -275,6 +275,8 @@ class MBTCPMultiMaster:
std::string myname;
bool initOK;
bool ignore; // игнорировать данное соединение (обычно флаг выставляется на время ignoreTimeout, если узел не отвечает, хотя связь есть.
PassiveTimer ptIgnoreTimeout;
};
typedef std::list<MBSlaveInfo> MBGateList;
......
......@@ -169,7 +169,7 @@ void RTUExchange::step()
MBExchange::step();
}
// -----------------------------------------------------------------------------
void RTUExchange::poll()
bool RTUExchange::poll()
{
if( !mb )
{
......@@ -185,11 +185,11 @@ void RTUExchange::poll()
}
if( !checkProcActive() )
return;
return false;
updateSM();
allInitOK = false;
return;
return false;
}
{
......@@ -202,7 +202,7 @@ void RTUExchange::poll()
firstInitRegisters();
if( !checkProcActive() )
return;
return false;
bool allNotRespond = true;
ComPort::Speed s = mbrtu->getSpeed();
......@@ -282,7 +282,7 @@ void RTUExchange::poll()
break;
if( !checkProcActive() )
return;
return false;
}
}
......@@ -297,7 +297,7 @@ void RTUExchange::poll()
for( auto &t: thrlist )
{
if( !checkProcActive() )
return;
return false;
IOBase::processingThreshold(&t,shm,force);
}
......@@ -314,6 +314,7 @@ void RTUExchange::poll()
}
// printMap(rmap);
return !allNotRespond;
}
// -----------------------------------------------------------------------------
std::shared_ptr<RTUExchange> RTUExchange::init_rtuexchange( int argc, const char* const* argv, UniSetTypes::ObjectId icID,
......
......@@ -34,7 +34,7 @@ class RTUExchange:
bool transmitCtl;
virtual void step() override;
virtual void poll() override;
virtual bool poll() override;
virtual std::shared_ptr<ModbusClient> initMB( bool reopen=false ) override;
virtual bool initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniXML::iterator& it ) override;
......
......@@ -12,6 +12,11 @@ using namespace std;
using namespace UniSetTypes;
using namespace ModbusRTU;
// -------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, const MBTCPTestServer* m )
{
return os << m->myname;
}
// -------------------------------------------------------------------------
MBTCPTestServer::MBTCPTestServer( ModbusAddr myaddr, const string& inetaddr, int port, bool verb ):
sslot(NULL),
addr(myaddr),
......@@ -22,7 +27,8 @@ MBTCPTestServer::MBTCPTestServer( ModbusAddr myaddr, const string& inetaddr, int
lastForceCoilsQ(0,0),
lastWriteOutputQ(0,0),
thr(0),
isrunning(false)
isrunning(false),
disabled(false)
{
ost::InetAddress ia(inetaddr.c_str());
......@@ -30,6 +36,12 @@ MBTCPTestServer::MBTCPTestServer( ModbusAddr myaddr, const string& inetaddr, int
cout << "(init): "
<< " addr: " << ia << ":" << port << endl;
{
ostringstream s;
s << ia << ":" << port;
myname = s.str();
}
sslot = new ModbusTCPServerSlot(ia,port);
// sslot->initLog(conf,name,logfile);
......@@ -83,7 +95,7 @@ void MBTCPTestServer::runThread()
void MBTCPTestServer::execute()
{
isrunning = true;
cerr << "******************** MBTCPTestServer running... " << endl;
cerr << "******************** MBTCPTestServer(" << myname << ") running... " << endl;
// Работа...
while(1)
{
......@@ -115,6 +127,9 @@ void MBTCPTestServer::sigterm( int signo )
ModbusRTU::mbErrCode MBTCPTestServer::readCoilStatus( ReadCoilMessage& query,
ReadCoilRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(readCoilStatus): " << query << endl;
......@@ -158,6 +173,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::readCoilStatus( ReadCoilMessage& query,
ModbusRTU::mbErrCode MBTCPTestServer::readInputStatus( ReadInputStatusMessage& query,
ReadInputStatusRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(readInputStatus): " << query << endl;
......@@ -194,6 +212,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::readInputStatus( ReadInputStatusMessage& q
mbErrCode MBTCPTestServer::readInputRegisters( ReadInputMessage& query,
ReadInputRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(readInputRegisters): " << query << endl;
......@@ -235,6 +256,9 @@ mbErrCode MBTCPTestServer::readInputRegisters( ReadInputMessage& query,
ModbusRTU::mbErrCode MBTCPTestServer::readOutputRegisters(
ModbusRTU::ReadOutputMessage& query, ModbusRTU::ReadOutputRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(readOutputRegisters): " << query << endl;
......@@ -272,6 +296,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::readOutputRegisters(
ModbusRTU::mbErrCode MBTCPTestServer::forceMultipleCoils( ModbusRTU::ForceCoilsMessage& query,
ModbusRTU::ForceCoilsRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(forceMultipleCoils): " << query << endl;
......@@ -284,6 +311,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::forceMultipleCoils( ModbusRTU::ForceCoilsM
ModbusRTU::mbErrCode MBTCPTestServer::writeOutputRegisters( ModbusRTU::WriteOutputMessage& query,
ModbusRTU::WriteOutputRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(writeOutputRegisters): " << query << endl;
......@@ -297,6 +327,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::writeOutputRegisters( ModbusRTU::WriteOutp
ModbusRTU::mbErrCode MBTCPTestServer::writeOutputSingleRegister( ModbusRTU::WriteSingleOutputMessage& query,
ModbusRTU::WriteSingleOutputRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(writeOutputSingleRegisters): " << query << endl;
......@@ -309,6 +342,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::writeOutputSingleRegister( ModbusRTU::Writ
ModbusRTU::mbErrCode MBTCPTestServer::forceSingleCoil( ModbusRTU::ForceSingleCoilMessage& query,
ModbusRTU::ForceSingleCoilRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(forceSingleCoil): " << query << endl;
......@@ -322,6 +358,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::forceSingleCoil( ModbusRTU::ForceSingleCoi
ModbusRTU::mbErrCode MBTCPTestServer::journalCommand( ModbusRTU::JournalCommandMessage& query,
ModbusRTU::JournalCommandRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(journalCommand): " << query << endl;
......@@ -358,6 +397,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::journalCommand( ModbusRTU::JournalCommandM
ModbusRTU::mbErrCode MBTCPTestServer::setDateTime( ModbusRTU::SetDateTimeMessage& query,
ModbusRTU::SetDateTimeRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(setDateTime): " << query << endl;
......@@ -445,6 +487,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::fileTransfer( ModbusRTU::FileTransferMessa
ModbusRTU::mbErrCode MBTCPTestServer::diagnostics( ModbusRTU::DiagnosticMessage& query,
ModbusRTU::DiagnosticRetMessage& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( query.subf == ModbusRTU::subEcho )
{
reply = query;
......@@ -484,6 +529,9 @@ ModbusRTU::mbErrCode MBTCPTestServer::diagnostics( ModbusRTU::DiagnosticMessage&
ModbusRTU::mbErrCode MBTCPTestServer::read4314( ModbusRTU::MEIMessageRDI& query,
ModbusRTU::MEIMessageRetRDI& reply )
{
if( disabled )
return ModbusRTU::erTimeOut;
if( verbose )
cout << "(read4314): " << query << endl;
......
......@@ -3,6 +3,7 @@
// -------------------------------------------------------------------------
#include <string>
#include <atomic>
#include <ostream>
#include "ThreadCreator.h"
#include "modbus/ModbusTCPServerSlot.h"
// -------------------------------------------------------------------------
......@@ -36,11 +37,15 @@ class MBTCPTestServer
inline bool isRunning(){ return isrunning; }
inline void disableExchange( bool set = true ){ disabled = set; }
inline bool getForceSingleCoilCmd(){ return forceSingleCoilCmd; }
inline int getLastWriteOutputSingleRegister(){ return lastWriteOutputSingleRegister; }
inline ModbusRTU::ForceCoilsMessage getLastForceCoilsQ(){ return lastForceCoilsQ; }
inline ModbusRTU::WriteOutputMessage getLastWriteOutput(){ return lastWriteOutputQ; }
friend std::ostream& operator<<(std::ostream& os, const MBTCPTestServer* m );
protected:
// действия при завершении работы
void sigterm( int signo );
......@@ -128,7 +133,8 @@ class MBTCPTestServer
private:
ThreadCreator<MBTCPTestServer>* thr;
std::atomic_bool isrunning;
bool disabled;
std::string myname;
};
// -------------------------------------------------------------------------
#endif // MBTCPTestServer_H_
......
if HAVE_TESTS
noinst_PROGRAMS = tests-with-sm
noinst_PROGRAMS = run_test_mbtcpmaster run_test_mbtcpmultimaster
tests_with_sm_SOURCES = tests_with_sm.cc test_mbtcpmaster.cc test_mbtcpmultimaster.cc MBTCPTestServer.cc
tests_with_sm_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \
run_test_mbtcpmaster_SOURCES = run_test_mbtcpmaster.cc test_mbtcpmaster.cc MBTCPTestServer.cc
run_test_mbtcpmaster_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/ModbusMaster/libUniSet2MBTCPMaster.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \
$(SIGC_LIBS) $(COMCPP_LIBS)
tests_with_sm_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include \
run_test_mbtcpmaster_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include \
-I$(top_builddir)/extensions/ModbusMaster \
-I$(top_builddir)/extensions/SharedMemory $(SIGC_CFLAGS) $(COMCPP_CFLAGS)
run_test_mbtcpmultimaster_SOURCES = run_test_mbtcpmultimaster.cc test_mbtcpmultimaster.cc MBTCPTestServer.cc
run_test_mbtcpmultimaster_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/ModbusMaster/libUniSet2MBTCPMaster.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \
$(SIGC_LIBS) $(COMCPP_LIBS)
run_test_mbtcpmultimaster_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include \
-I$(top_builddir)/extensions/ModbusMaster \
-I$(top_builddir)/extensions/SharedMemory $(SIGC_CFLAGS) $(COMCPP_CFLAGS)
......
......@@ -32,6 +32,15 @@
<item addr="0x01" invert="1" respondSensor="Slave_Not_Respond_S" timeout="1000"/>
</DeviceList>
</MBTCPMaster1>
<MBTCPMultiMaster1 name="MBTCPMultiMaster1" poll_time="200" reply_timeout="60">
<DeviceList>
<item addr="0x01" invert="1" respondSensor="Slave_Not_Respond_S" timeout="1000"/>
</DeviceList>
<GateList>
<item ip="127.0.0.1" port="20050" recv_timeout="200" invert="1" respondSensor="Slave1_Not_Respond_S"/>
<item ip="127.0.0.1" port="20052" recv_timeout="200" invert="1" respondSensor="Slave2_Not_Respond_S"/>
</GateList>
</MBTCPMultiMaster1>
</settings>
<ObjectsMap idfromfile="1">
<!--
......@@ -50,6 +59,8 @@
<item id="10" iotype="DI" name="Slave_Not_Respond_S" textname="Наличие связи со Slave"/>
<item id="11" iotype="AI" name="MBTCPMaster_Mode_AS" textname="Режим работы MBTCPMaster"/>
<item id="12" iotype="DI" name="Slave1_Not_Respond_S" textname="Наличие связи со Slave1"/>
<item id="13" iotype="DI" name="Slave2_Not_Respond_S" textname="Наличие связи со Slave1"/>
<item id="1000" mb="1" mbtype="rtu" mbaddr="0x01" mbreg="1" mbfunc="0x01" iotype="DI" name="TestReadCoil1_S" textname="Тестовый регистр для ReadCoil"/>
<item id="1001" mb="1" mbtype="rtu" mbaddr="0x01" mbreg="2" mbfunc="0x01" iotype="DI" name="TestReadCoil2_S" textname="Тестовый регистр для ReadCoil"/>
......@@ -111,6 +122,7 @@
<objects name="UniObjects">
<item id="6000" name="TestProc"/>
<item id="6004" name="MBTCPMaster1"/>
<item id="6005" name="MBTCPMultiMaster1"/>
</objects>
</ObjectsMap>
<messages idfromfile="1" name="messages"/>
......
AT_SETUP([ModbusTCPMaster tests (with SM)])
AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/ModbusMaster/tests tests_with_sm.sh],[0],[ignore],[ignore])
AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/ModbusMaster/tests run_test_mbtcpmaster.sh],[0],[ignore],[ignore])
AT_CLEANUP
#AT_SETUP([ModbusTCPMaster tests (Apart)])
#AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/ModbusMaster/tests tests_with_sm_apart.sh],[0],[ignore],[ignore])
#AT_CLEANUP
AT_SETUP([ModbusTCPMultiMaster tests (with SM)])
AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/ModbusMaster/tests run_test_mbtcpmultimaster.sh],[0],[ignore],[ignore])
AT_CLEANUP
......@@ -21,7 +21,7 @@ int main(int argc, char* argv[] )
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
session.showHelp("tests_mbtcpmaster");
return 0;
}
......@@ -33,7 +33,7 @@ int main(int argc, char* argv[] )
{
auto conf = uniset_init(argc,argv);
conf->initDebug(dlog,"dlog");
dlog.logFile("./smtest.log");
dlog.logFile("./smtest.log");
bool apart = findArgParam("--apart",argc,argv) != -1;
......@@ -61,7 +61,7 @@ int main(int argc, char* argv[] )
if( !act->exist() )
{
cerr << "(tests_with_sm): SharedMemory not exist! (timeout=" << tout << ")" << endl;
cerr << "(tests_mbtcpmaster): SharedMemory not exist! (timeout=" << tout << ")" << endl;
return 1;
}
......@@ -69,19 +69,19 @@ int main(int argc, char* argv[] )
}
catch( SystemError& err )
{
cerr << "(tests_with_sm): " << err << endl;
cerr << "(tests_mbtcpmaster): " << err << endl;
}
catch( Exception& ex )
{
cerr << "(tests_with_sm): " << ex << endl;
cerr << "(tests_mbtcpmaster): " << ex << endl;
}
catch( std::exception& e )
{
cerr << "(tests_with_sm): " << e.what() << endl;
cerr << "(tests_mbtcpmaster): " << e.what() << endl;
}
catch(...)
{
cerr << "(tests_with_sm): catch(...)" << endl;
cerr << "(tests_mbtcpmaster): catch(...)" << endl;
}
return 1;
......
......@@ -8,14 +8,14 @@ cd ../../../Utilities/Admin/
./uniset2-start.sh -f ./exist | grep -q UNISET_PLC/Controllers || exit 1
cd -
./uniset2-start.sh -f ./tests-with-sm $* -- --confile mbmaster-test-configure.xml --e-startup-pause 10 \
./uniset2-start.sh -f ./run_test_mbtcpmaster $* -- --confile mbmaster-test-configure.xml --e-startup-pause 10 \
--mbtcp-name MBTCPMaster1 \
--smemory-id SharedMemory \
--mbtcp-filter-field mb \
--mbtcp-filter-value 1 \
--mbtcp-gateway-iaddr localhost \
--mbtcp-gateway-port 20048 \
--mbtcp-polltime 50 --mbtcp-recv-timeout 1000
--mbtcp-polltime 50 --mbtcp-recv-timeout 500
#--dlog-add-levels any
#--mbtcp-force-out 1
......
......@@ -8,7 +8,7 @@ cd ../../../Utilities/Admin/
./uniset2-start.sh -f ./exist | grep -q UNISET_PLC/Controllers || exit 1
cd -
./uniset2-start.sh -g ./tests-with-sm $* -- --confile mbmaster-test-configure.xml --e-startup-pause 10 \
./uniset2-start.sh -g ./run_test_mbtcpmaster $* -- --confile mbmaster-test-configure.xml --e-startup-pause 10 \
--mbtcp-name MBTCPMaster1 \
--smemory-id SharedMemory \
--mbtcp-filter-field mb \
......
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <string>
#include "Debug.h"
#include "UniSetActivator.h"
#include "PassiveTimer.h"
#include "SharedMemory.h"
#include "Extensions.h"
#include "MBTCPMultiMaster.h"
// --------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
using namespace UniSetExtensions;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc>1 && ( strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_mbtcpmultimaster");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
auto conf = uniset_init(argc,argv);
conf->initDebug(dlog,"dlog");
dlog.logFile("./smtest.log");
bool apart = findArgParam("--apart",argc,argv) != -1;
auto shm = SharedMemory::init_smemory(argc, argv);
if( !shm )
return 1;
auto mb = MBTCPMultiMaster::init_mbmaster(argc,argv,shm->getId(), (apart ? nullptr : shm ));
if( !mb )
return 1;
auto act = UniSetActivator::Instance();
act->addObject(shm);
act->addObject(mb);
SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() );
act->run(true);
int tout = 6000;
PassiveTimer pt(tout);
while( !pt.checkTime() && !act->exist() )
msleep(100);
if( !act->exist() )
{
cerr << "(tests_mbtcpmultimaster): SharedMemory not exist! (timeout=" << tout << ")" << endl;
return 1;
}
return session.run();
}
catch( SystemError& err )
{
cerr << "(tests_mbtcpmultimaster): " << err << endl;
}
catch( Exception& ex )
{
cerr << "(tests_mbtcpmultimaster): " << ex << endl;
}
catch( std::exception& e )
{
cerr << "(tests_mbtcpmultimaster): " << e.what() << endl;
}
catch(...)
{
cerr << "(tests_mbtcpmultimaster): catch(...)" << endl;
}
return 1;
}
#!/bin/sh
# '--' - нужен для отделения аргументов catch, от наших..
cd ../../../Utilities/Admin/
./uniset2-start.sh -f ./create_links.sh
./uniset2-start.sh -f ./create
./uniset2-start.sh -f ./exist | grep -q UNISET_PLC/Controllers || exit 1
cd -
./uniset2-start.sh -f ./run_test_mbtcpmultimaster $* -- --confile mbmaster-test-configure.xml --e-startup-pause 10 \
--mbtcp-name MBTCPMultiMaster1 \
--smemory-id SharedMemory \
--mbtcp-filter-field mb \
--mbtcp-filter-value 1 \
--mbtcp-polltime 50 --mbtcp-recv-timeout 500 --mbtcp-timeout 3000 --mbtcp-ignore-timeout 3000 --dlog-add-levels warn,crit
# --dlog-add-levels any
#--mbtcp-force-out 1
#--dlog-add-levels any
......@@ -8,30 +8,92 @@
using namespace std;
using namespace UniSetTypes;
// -----------------------------------------------------------------------------
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <time.h>
#include <memory>
#include <limits>
#include "UniSetTypes.h"
#include "MBTCPTestServer.h"
#include "MBTCPMultiMaster.h"
// -----------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
// -----------------------------------------------------------------------------
static ModbusRTU::ModbusAddr slaveaddr = 0x01; // conf->getArgInt("--mbs-my-addr");
static int port = 20048; // conf->getArgInt("--mbs-inet-port");
static int port = 20050; // conf->getArgInt("--mbs-inet-port");
static string addr("127.0.0.1"); // conf->getArgParam("--mbs-inet-addr");
static ObjectId slaveID = 6004; // conf->getObjectID( conf->getArgParam("--mbs-name"));
static ModbusTCPMaster* mb = nullptr;
static UInterface* ui = nullptr;
static int port2 = 20052;
static string addr2("127.0.0.1");
static ModbusRTU::ModbusAddr slaveADDR = 0x01;
static shared_ptr<MBTCPTestServer> mbs1;
static shared_ptr<MBTCPTestServer> mbs2;
static shared_ptr<UInterface> ui;
static ObjectId mbID = 6005; // MBTCPMultiMaster1
static int polltime=50; // conf->getArgInt("--mbtcp-polltime");
static ObjectId slaveNotRespond = 10; // Slave_Not_Respond_S
static ObjectId slave1NotRespond = 12; // Slave1_Not_Respond_S
static ObjectId slave2NotRespond = 13; // Slave2_Not_Respond_S
static const ObjectId exchangeMode = 11; // MBTCPMaster_Mode_AS
// -----------------------------------------------------------------------------
static void InitTest()
{
auto conf = uniset_conf();
CHECK( conf!=nullptr );
if( ui == nullptr )
if( !ui )
{
ui = new UInterface();
ui = make_shared<UInterface>();
// UI понадобиться для проверки записанных в SM значений.
CHECK( ui->getObjectIndex() != nullptr );
CHECK( ui->getConf() == conf );
CHECK( ui->waitReady(slaveID,5000) );
CHECK( ui->waitReady(slaveNotRespond,8000) );
}
if( !mbs1 )
{
mbs1 = make_shared<MBTCPTestServer>(slaveADDR,addr,port,false);
CHECK( mbs1!= nullptr );
mbs1->setReply(0);
mbs1->runThread();
for( int i=0; !mbs1->isRunning() && i<10; i++ )
msleep(200);
CHECK( mbs1->isRunning() );
msleep(7000);
CHECK( ui->getValue(slaveNotRespond) == 0 );
}
if( !mbs2 )
{
mbs2 = make_shared<MBTCPTestServer>(slaveADDR,addr2,port2,false);
CHECK( mbs2!= nullptr );
mbs2->setReply(0);
mbs2->runThread();
for( int i=0; !mbs2->isRunning() && i<10; i++ )
msleep(200);
CHECK( mbs2->isRunning() );
}
}
// -----------------------------------------------------------------------------
TEST_CASE("MBTCPMultiMaster","[modbus][mbmaster][mbtcpmultimaster]")
TEST_CASE("MBTCPMultiMaster: rotate channel","[modbus][mbmaster][mbtcpmultimaster]")
{
WARN("Tests for MBTCPMaster not yet");
InitTest();
CHECK( ui->isExist(mbID) );
REQUIRE( ui->getValue(1003) == 0 );
mbs1->setReply(100);
mbs2->setReply(10);
msleep(polltime+1000);
REQUIRE( ui->getValue(1003) == 100 );
mbs1->disableExchange(true);
msleep(3200); // --mbtcp-timeout 3000 (см. run_test_mbtcmultipmaster.sh)
REQUIRE( ui->getValue(1003) == 10 );
mbs1->disableExchange(false);
mbs2->disableExchange(true);
msleep(3200); // --mbtcp-timeout 3000 (см. run_test_mbtcmultipmaster.sh)
REQUIRE( ui->getValue(1003) == 100 );
mbs2->disableExchange(false);
REQUIRE( ui->getValue(1003) == 100 );
}
// -----------------------------------------------------------------------------
......@@ -30,7 +30,7 @@ ModbusTCPMaster::~ModbusTCPMaster()
if( isConnection() )
disconnect();
tcp.reset();
tcp.reset();
}
// -------------------------------------------------------------------------
int ModbusTCPMaster::getNextData( unsigned char* buf, int len )
......@@ -297,7 +297,7 @@ bool ModbusTCPMaster::checkConnection( const std::string& ip, int port, int time
void ModbusTCPMaster::reconnect()
{
if( dlog.is_info() )
dlog.info() << "(ModbusTCPMaster): reconnect " << iaddr << endl;
dlog.info() << "(ModbusTCPMaster): reconnect " << iaddr << ":" << port << endl;
if( tcp )
{
......@@ -387,11 +387,11 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
void ModbusTCPMaster::disconnect()
{
if( dlog.is_info() )
dlog.info() << iaddr << "(ModbusTCPMaster): disconnect." << endl;
dlog.info() << iaddr << "(ModbusTCPMaster): disconnect (" << iaddr << ":" << port <<")." << endl;
if( !tcp )
return;
tcp->disconnect();
tcp.reset();
}
......
......@@ -185,7 +185,7 @@ bool UniSetManager::addObject( const std::shared_ptr<UniSetObject>& obj )
uinfo << myname << "(activator): добавляем объект "<< obj->getName()<< endl;
olist.push_back(obj);
}
} // unlock
} // unlock
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