Commit 8d4fbf3b authored by Pavel Vainerman's avatar Pavel Vainerman

(Log): встроил LogServer в MBSlave и MBMaster

parent 32204606
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#include "MTR.h" #include "MTR.h"
#include "RTUStorage.h" #include "RTUStorage.h"
#include "modbus/ModbusClient.h" #include "modbus/ModbusClient.h"
#include "modbus/MBLogSugar.h"
#include "LogAgregator.h"
#include "LogServer.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! /*!
\par Базовый класс для реализация обмена по протоколу Modbus [RTU|TCP]. \par Базовый класс для реализация обмена по протоколу Modbus [RTU|TCP].
...@@ -192,7 +195,7 @@ class MBExchange: ...@@ -192,7 +195,7 @@ class MBExchange:
long mode; // режим работы с устройством (см. ExchangeMode) long mode; // режим работы с устройством (см. ExchangeMode)
// return TRUE if state changed // return TRUE if state changed
bool checkRespond(); bool checkRespond( std::shared_ptr<DebugStream>& log );
// специфические поля для RS // специфические поля для RS
ComPort::Speed speed; ComPort::Speed speed;
...@@ -349,6 +352,11 @@ class MBExchange: ...@@ -349,6 +352,11 @@ class MBExchange:
std::string defaultMBaddr; std::string defaultMBaddr;
bool defaultMBinitOK; // флаг определяющий нужно ли ждать "первого обмена" или при запуске сохранять в SM значение default. bool defaultMBinitOK; // флаг определяющий нужно ли ждать "первого обмена" или при запуске сохранять в SM значение default.
std::shared_ptr<DebugStream> mblog;
std::shared_ptr<LogServer> logserv;
std::string logserv_host = {""};
int logserv_port = {0};
private: private:
MBExchange(); MBExchange();
......
...@@ -22,7 +22,7 @@ MBTCPMaster::MBTCPMaster( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shm ...@@ -22,7 +22,7 @@ MBTCPMaster::MBTCPMaster( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shm
// префикс для "свойств" - по умолчанию "tcp_"; // префикс для "свойств" - по умолчанию "tcp_";
prop_prefix = initPropPrefix("tcp_"); prop_prefix = initPropPrefix("tcp_");
dinfo << myname << "(init): prop_prefix=" << prop_prefix << endl; mbinfo << myname << "(init): prop_prefix=" << prop_prefix << endl;
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
...@@ -39,10 +39,10 @@ MBTCPMaster::MBTCPMaster( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shm ...@@ -39,10 +39,10 @@ MBTCPMaster::MBTCPMaster( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shm
if( port <= 0 ) if( port <= 0 )
throw UniSetTypes::SystemError(myname + "(MBMaster): Unknown inet port...(Use: " + tmp + ")" ); throw UniSetTypes::SystemError(myname + "(MBMaster): Unknown inet port...(Use: " + tmp + ")" );
dinfo << myname << "(init): gateway " << iaddr << ":" << port << endl; mbinfo << myname << "(init): gateway " << iaddr << ":" << port << endl;
force_disconnect = conf->getArgInt("--" + prefix + "-persistent-connection", it.getProp("persistent_connection")) ? false : true; force_disconnect = conf->getArgInt("--" + prefix + "-persistent-connection", it.getProp("persistent_connection")) ? false : true;
dinfo << myname << "(init): persisten-connection=" << (!force_disconnect) << endl; mbinfo << myname << "(init): persisten-connection=" << (!force_disconnect) << endl;
if( shm->isLocalwork() ) if( shm->isLocalwork() )
{ {
...@@ -56,7 +56,7 @@ MBTCPMaster::MBTCPMaster( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shm ...@@ -56,7 +56,7 @@ MBTCPMaster::MBTCPMaster( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shm
pollThread = make_shared<ThreadCreator<MBTCPMaster>>(this, &MBTCPMaster::poll_thread); pollThread = make_shared<ThreadCreator<MBTCPMaster>>(this, &MBTCPMaster::poll_thread);
pollThread->setFinalAction(this, &MBTCPMaster::final_thread); pollThread->setFinalAction(this, &MBTCPMaster::final_thread);
if( dlog()->is_info() ) if( mblog->is_info() )
printMap(rmap); printMap(rmap);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -97,20 +97,20 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen ) ...@@ -97,20 +97,20 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen )
mbtcp->setSleepPause(sleepPause_usec); mbtcp->setSleepPause(sleepPause_usec);
mbtcp->setAfterSendPause(aftersend_pause); mbtcp->setAfterSendPause(aftersend_pause);
dinfo << myname << "(init): ipaddr=" << iaddr << " port=" << port << endl; mbinfo << myname << "(init): ipaddr=" << iaddr << " port=" << port << endl;
if( dlog()->is_level9() ) if( mblog->is_level9() )
mbtcp->setLog(dlog()); mbtcp->setLog(mblog);
} }
catch( ModbusRTU::mbException& ex ) catch( ModbusRTU::mbException& ex )
{ {
dwarn << "(init): " << ex << endl; mbwarn << "(init): " << ex << endl;
mb = nullptr; mb = nullptr;
mbtcp = nullptr; mbtcp = nullptr;
} }
catch( const ost::Exception& e ) catch( const ost::Exception& e )
{ {
dwarn << myname << "(init): Can`t create socket " << iaddr << ":" << port << " err: " << e.getString() << endl; mbwarn << myname << "(init): Can`t create socket " << iaddr << ":" << port << " err: " << e.getString() << endl;
mb = nullptr; mb = nullptr;
mbtcp = nullptr; mbtcp = nullptr;
} }
......
...@@ -23,7 +23,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob ...@@ -23,7 +23,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
auto conf = uniset_conf(); auto conf = uniset_conf();
prop_prefix = initPropPrefix("tcp_"); prop_prefix = initPropPrefix("tcp_");
dinfo << myname << "(init): prop_prefix=" << prop_prefix << endl; mbinfo << myname << "(init): prop_prefix=" << prop_prefix << endl;
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
...@@ -38,7 +38,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob ...@@ -38,7 +38,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
{ {
ostringstream err; ostringstream err;
err << myname << "(init): not found <GateList>"; err << myname << "(init): not found <GateList>";
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw UniSetTypes::SystemError(err.str()); throw UniSetTypes::SystemError(err.str());
} }
...@@ -46,7 +46,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob ...@@ -46,7 +46,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
{ {
ostringstream err; ostringstream err;
err << myname << "(init): empty <GateList> ?!"; err << myname << "(init): empty <GateList> ?!";
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw UniSetTypes::SystemError(err.str()); throw UniSetTypes::SystemError(err.str());
} }
...@@ -59,7 +59,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob ...@@ -59,7 +59,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
{ {
ostringstream err; ostringstream err;
err << myname << "(init): ip='' in <GateList>"; err << myname << "(init): ip='' in <GateList>";
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw UniSetTypes::SystemError(err.str()); throw UniSetTypes::SystemError(err.str());
} }
...@@ -69,7 +69,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob ...@@ -69,7 +69,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
{ {
ostringstream err; ostringstream err;
err << myname << "(init): ERROR: port=''" << sinf.port << " for ip='" << sinf.ip << "' in <GateList>"; err << myname << "(init): ERROR: port=''" << sinf.port << " for ip='" << sinf.ip << "' in <GateList>";
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw UniSetTypes::SystemError(err.str()); throw UniSetTypes::SystemError(err.str());
} }
...@@ -81,7 +81,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob ...@@ -81,7 +81,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
{ {
ostringstream err; ostringstream err;
err << myname << "(init): ERROR: Unknown SensorID for '" << it1.getProp("respond") << "' in <GateList>"; err << myname << "(init): ERROR: Unknown SensorID for '" << it1.getProp("respond") << "' in <GateList>";
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw UniSetTypes::SystemError(err.str()); throw UniSetTypes::SystemError(err.str());
} }
} }
...@@ -101,19 +101,19 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob ...@@ -101,19 +101,19 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
n << sinf.ip << ":" << sinf.port; n << sinf.ip << ":" << sinf.port;
sinf.myname = n.str(); sinf.myname = n.str();
if( dlog()->is_level9() ) if( mblog->is_level9() )
sinf.mbtcp->setLog(dlog()); sinf.mbtcp->setLog(mblog);
mblist.push_back(sinf); mblist.push_back(sinf);
dinfo << myname << "(init): add slave channel " << sinf.myname << endl; mbinfo << myname << "(init): add slave channel " << sinf.myname << endl;
} }
if( mblist.empty() ) if( mblist.empty() )
{ {
ostringstream err; ostringstream err;
err << myname << "(init): empty <GateList>!"; err << myname << "(init): empty <GateList>!";
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw UniSetTypes::SystemError(err.str()); throw UniSetTypes::SystemError(err.str());
} }
...@@ -139,7 +139,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob ...@@ -139,7 +139,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
// неудачной попытки запросов по одному из каналов, то ПЕРЕОПРЕДЕЛЯЕМ reopen, на timeout.. // неудачной попытки запросов по одному из каналов, то ПЕРЕОПРЕДЕЛЯЕМ reopen, на timeout..
ptReopen.setTiming(default_timeout); ptReopen.setTiming(default_timeout);
if( dlog()->is_info() ) if( mblog->is_info() )
printMap(rmap); printMap(rmap);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -175,7 +175,7 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen ) ...@@ -175,7 +175,7 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
if( mbi == mblist.rend() ) if( mbi == mblist.rend() )
mbi = mblist.rbegin(); mbi = mblist.rbegin();
mbi->init(); mbi->init(mblog);
mb = mbi->mbtcp; mb = mbi->mbtcp;
return mbi->mbtcp; return mbi->mbtcp;
} }
...@@ -189,13 +189,13 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen ) ...@@ -189,13 +189,13 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
{ {
mbi->ignore = true; mbi->ignore = true;
mbi->ptIgnoreTimeout.reset(); mbi->ptIgnoreTimeout.reset();
dwarn << myname << "(initMB): set ignore=true for " << mbi->ip << ":" << mbi->port << endl; mbwarn << myname << "(initMB): set ignore=true for " << mbi->ip << ":" << mbi->port << endl;
} }
// Если по текущему каналу связь есть, то возвращаем его // Если по текущему каналу связь есть, то возвращаем его
if( mbi != mblist.rend() && !mbi->ignore && mbi->respond ) if( mbi != mblist.rend() && !mbi->ignore && mbi->respond )
{ {
if( mbi->mbtcp->isConnection() || ( !mbi->mbtcp->isConnection() && mbi->init()) ) if( mbi->mbtcp->isConnection() || ( !mbi->mbtcp->isConnection() && mbi->init(mblog)) )
{ {
if( !mbi->ignore ) if( !mbi->ignore )
{ {
...@@ -221,7 +221,7 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen ) ...@@ -221,7 +221,7 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
{ {
uniset_rwmutex_wrlock l(tcpMutex); uniset_rwmutex_wrlock l(tcpMutex);
if( it->respond && it->init() ) if( it->respond && it->init(mblog) )
{ {
if( it->ignore ) if( it->ignore )
{ {
...@@ -257,13 +257,13 @@ bool MBTCPMultiMaster::MBSlaveInfo::check() ...@@ -257,13 +257,13 @@ bool MBTCPMultiMaster::MBSlaveInfo::check()
return mbtcp->checkConnection(ip, port); return mbtcp->checkConnection(ip, port);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool MBTCPMultiMaster::MBSlaveInfo::init() bool MBTCPMultiMaster::MBSlaveInfo::init( std::shared_ptr<DebugStream>& mblog )
{ {
try try
{ {
ost::Thread::setException(ost::Thread::throwException); ost::Thread::setException(ost::Thread::throwException);
dinfo << myname << "(init): connect..." << endl; mbinfo << myname << "(init): connect..." << endl;
mbtcp->connect(ip, port); mbtcp->connect(ip, port);
mbtcp->setForceDisconnect(force_disconnect); mbtcp->setForceDisconnect(force_disconnect);
...@@ -277,7 +277,7 @@ bool MBTCPMultiMaster::MBSlaveInfo::init() ...@@ -277,7 +277,7 @@ bool MBTCPMultiMaster::MBSlaveInfo::init()
mbtcp->setAfterSendPause(aftersend_pause); mbtcp->setAfterSendPause(aftersend_pause);
if( mbtcp->isConnection() ) if( mbtcp->isConnection() )
dinfo << "(init): " << myname << " connect OK" << endl; mbinfo << "(init): " << myname << " connect OK" << endl;
initOK = true; initOK = true;
} }
...@@ -285,15 +285,15 @@ bool MBTCPMultiMaster::MBSlaveInfo::init() ...@@ -285,15 +285,15 @@ bool MBTCPMultiMaster::MBSlaveInfo::init()
} }
catch( ModbusRTU::mbException& ex ) catch( ModbusRTU::mbException& ex )
{ {
dwarn << "(init): " << ex << endl; mbwarn << "(init): " << ex << endl;
} }
catch( const ost::Exception& e ) catch( const ost::Exception& e )
{ {
dwarn << myname << "(init): Can`t create socket " << ip << ":" << port << " err: " << e.getString() << endl; mbwarn << myname << "(init): Can`t create socket " << ip << ":" << port << " err: " << e.getString() << endl;
} }
catch(...) catch(...)
{ {
dwarn << "(init): " << myname << " catch ..." << endl; mbwarn << "(init): " << myname << " catch ..." << endl;
} }
initOK = false; initOK = false;
...@@ -353,7 +353,7 @@ void MBTCPMultiMaster::check_thread() ...@@ -353,7 +353,7 @@ void MBTCPMultiMaster::check_thread()
try try
{ {
bool r = it->check(); bool r = it->check();
dinfo << myname << "(check): " << it->myname << " " << ( r ? "OK" : "FAIL" ) << endl; mbinfo << myname << "(check): " << it->myname << " " << ( r ? "OK" : "FAIL" ) << endl;
try try
{ {
...@@ -365,11 +365,11 @@ void MBTCPMultiMaster::check_thread() ...@@ -365,11 +365,11 @@ void MBTCPMultiMaster::check_thread()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(check): (respond) " << ex << std::endl; mbcrit << myname << "(check): (respond) " << ex << std::endl;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
dcrit << myname << "(check): (respond) " << ex.what() << std::endl; mbcrit << myname << "(check): (respond) " << ex.what() << std::endl;
} }
...@@ -380,7 +380,7 @@ void MBTCPMultiMaster::check_thread() ...@@ -380,7 +380,7 @@ void MBTCPMultiMaster::check_thread()
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
dcrit << myname << "(check): (respond) " << ex.what() << std::endl; mbcrit << myname << "(check): (respond) " << ex.what() << std::endl;
} }
if( !checkProcActive() ) if( !checkProcActive() )
......
...@@ -267,7 +267,7 @@ class MBTCPMultiMaster: ...@@ -267,7 +267,7 @@ class MBTCPMultiMaster:
return priority < mbs.priority; return priority < mbs.priority;
} }
bool init(); bool init( std::shared_ptr<DebugStream>& mblog );
bool check(); bool check();
int recv_timeout; int recv_timeout;
......
...@@ -17,7 +17,7 @@ int main( int argc, const char** argv ) ...@@ -17,7 +17,7 @@ int main( int argc, const char** argv )
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--mbtcp-logfile filename - logfilename. Default: mbtcpmaster.log" << endl; cout << "--mbtcp-logfile filename - logfilename" << endl;
cout << endl; cout << endl;
MBTCPMaster::help_print(argc, argv); MBTCPMaster::help_print(argc, argv);
return 0; return 0;
...@@ -29,14 +29,14 @@ int main( int argc, const char** argv ) ...@@ -29,14 +29,14 @@ int main( int argc, const char** argv )
string logfilename(conf->getArgParam("--mbtcp-logfile")); string logfilename(conf->getArgParam("--mbtcp-logfile"));
if( logfilename.empty() ) if( !logfilename.empty() )
logfilename = "mbtcpmaster.log"; {
std::ostringstream logname;
std::ostringstream logname; string dir(conf->getLogDir());
string dir(conf->getLogDir()); logname << dir << logfilename;
logname << dir << logfilename; ulog()->logFile( logname.str() );
ulog()->logFile( logname.str() ); dlog()->logFile( logname.str() );
dlog()->logFile( logname.str() ); }
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
...@@ -15,7 +15,7 @@ int main( int argc, const char** argv ) ...@@ -15,7 +15,7 @@ int main( int argc, const char** argv )
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: get from configure..." << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: get from configure..." << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--mbtcp-logfile filename - logfilename. Default: mbtcpmultimaster.log" << endl; cout << "--mbtcp-logfile filename - logfilename" << endl;
cout << endl; cout << endl;
MBTCPMultiMaster::help_print(argc, argv); MBTCPMultiMaster::help_print(argc, argv);
return 0; return 0;
...@@ -27,14 +27,14 @@ int main( int argc, const char** argv ) ...@@ -27,14 +27,14 @@ int main( int argc, const char** argv )
string logfilename(conf->getArgParam("--mbtcp-logfile")); string logfilename(conf->getArgParam("--mbtcp-logfile"));
if( logfilename.empty() ) if( !logfilename.empty() )
logfilename = "mbtcpmultimaster.log"; {
std::ostringstream logname;
std::ostringstream logname; string dir(conf->getLogDir());
string dir(conf->getLogDir()); logname << dir << logfilename;
logname << dir << logfilename; ulog()->logFile( logname.str() );
ulog()->logFile( logname.str() ); dlog()->logFile( logname.str() );
dlog()->logFile( logname.str() ); }
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
--confile test.xml \ --confile test.xml \
--mbtcp-name MBMaster1 \ --mbtcp-name MBMaster1 \
--smemory-id SharedMemory \ --smemory-id SharedMemory \
--dlog-add-levels system,info,crit,warn,level4,level3 \ --mbtcp-log-add-levels system,info,crit,warn,level4,level3 \
--mbtcp-set-prop-prefix \ --mbtcp-set-prop-prefix \
--mbtcp-filter-field rs \ --mbtcp-filter-field rs \
--mbtcp-filter-value 5 \ --mbtcp-filter-value 5 \
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
--mbtcp-polltime 3000 \ --mbtcp-polltime 3000 \
--mbtcp-force-out 1 \ --mbtcp-force-out 1 \
--ulog-add-levels system \ --ulog-add-levels system \
--mbtcp-run-logserver \
$* $*
#--mbtcp-exchange-mode-id MB1_Mode_AS \ #--mbtcp-exchange-mode-id MB1_Mode_AS \
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#include "IOBase.h" #include "IOBase.h"
#include "VTypes.h" #include "VTypes.h"
#include "ThreadCreator.h" #include "ThreadCreator.h"
#include "LogAgregator.h"
#include "LogServer.h"
#include "modbus/MBLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! /*!
\page page_ModbusSlave Реализация Modbus slave \page page_ModbusSlave Реализация Modbus slave
...@@ -511,6 +514,11 @@ class MBSlave: ...@@ -511,6 +514,11 @@ class MBSlave:
typedef std::unordered_map<int, MEIObjIDMap> MEIDevIDMap; typedef std::unordered_map<int, MEIObjIDMap> MEIDevIDMap;
MEIDevIDMap meidev; MEIDevIDMap meidev;
std::shared_ptr<DebugStream> mblog;
std::shared_ptr<LogServer> logserv;
std::string logserv_host = {""};
int logserv_port = {0};
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#endif // _MBSlave_H_ #endif // _MBSlave_H_
......
...@@ -55,7 +55,7 @@ MBTCPMultiSlave::MBTCPMultiSlave( UniSetTypes::ObjectId objId, UniSetTypes::Obje ...@@ -55,7 +55,7 @@ MBTCPMultiSlave::MBTCPMultiSlave( UniSetTypes::ObjectId objId, UniSetTypes::Obje
{ {
ostringstream err; ostringstream err;
err << myname << "(init): Unknown ip=''"; err << myname << "(init): Unknown ip=''";
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
...@@ -71,7 +71,7 @@ MBTCPMultiSlave::MBTCPMultiSlave( UniSetTypes::ObjectId objId, UniSetTypes::Obje ...@@ -71,7 +71,7 @@ MBTCPMultiSlave::MBTCPMultiSlave( UniSetTypes::ObjectId objId, UniSetTypes::Obje
{ {
ostringstream err; ostringstream err;
err << myname << "(init): Not found sensor ID for " << cit.getProp("respond"); err << myname << "(init): Not found sensor ID for " << cit.getProp("respond");
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -84,7 +84,7 @@ MBTCPMultiSlave::MBTCPMultiSlave( UniSetTypes::ObjectId objId, UniSetTypes::Obje ...@@ -84,7 +84,7 @@ MBTCPMultiSlave::MBTCPMultiSlave( UniSetTypes::ObjectId objId, UniSetTypes::Obje
{ {
ostringstream err; ostringstream err;
err << myname << "(init): Not found sensor ID for " << cit.getProp("askcount"); err << myname << "(init): Not found sensor ID for " << cit.getProp("askcount");
dcrit << err.str() << endl; mbcrit << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -98,7 +98,7 @@ MBTCPMultiSlave::MBTCPMultiSlave( UniSetTypes::ObjectId objId, UniSetTypes::Obje ...@@ -98,7 +98,7 @@ MBTCPMultiSlave::MBTCPMultiSlave( UniSetTypes::ObjectId objId, UniSetTypes::Obje
} }
cmap[c.iaddr] = c; cmap[c.iaddr] = c;
dinfo << myname << "(init): add client: " << c.iaddr << " respond=" << c.respond_s << " askcount=" << c.askcount_s << endl; mbinfo << myname << "(init): add client: " << c.iaddr << " respond=" << c.respond_s << " askcount=" << c.askcount_s << endl;
} }
} }
} }
...@@ -150,20 +150,20 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -150,20 +150,20 @@ void MBTCPMultiSlave::execute_tcp()
if( !sslot ) if( !sslot )
{ {
dcrit << myname << "(execute_tcp): DYNAMIC CAST ERROR (mbslot --> ModbusTCPServerSlot)" << std::endl; mbcrit << myname << "(execute_tcp): DYNAMIC CAST ERROR (mbslot --> ModbusTCPServerSlot)" << std::endl;
raise(SIGTERM); raise(SIGTERM);
return; return;
} }
if( dlog()->is_level9() ) if( mblog->is_level9() )
sslot->setLog(dlog()); sslot->setLog(mblog);
for( auto&& i : cmap ) for( auto && i : cmap )
i.second.ptTimeout.reset(); i.second.ptTimeout.reset();
sslot->setMaxSessions( sessMaxNum ); sslot->setMaxSessions( sessMaxNum );
dinfo << myname << "(execute_tcp): thread running.." << endl; mbinfo << myname << "(execute_tcp): thread running.." << endl;
while( !cancelled ) while( !cancelled )
{ {
...@@ -175,7 +175,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -175,7 +175,7 @@ void MBTCPMultiSlave::execute_tcp()
sess.clear(); sess.clear();
sslot->getSessions(sess); sslot->getSessions(sess);
for( auto&& s : sess ) for( auto && s : sess )
{ {
auto i = cmap.find( s.iaddr ); auto i = cmap.find( s.iaddr );
...@@ -196,7 +196,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -196,7 +196,7 @@ void MBTCPMultiSlave::execute_tcp()
{ {
auto c = it.second; auto c = it.second;
dlog4 << myname << "(work): " << c.iaddr << " resp=" << (c.invert ? c.ptTimeout.checkTime() : !c.ptTimeout.checkTime()) mblog4 << myname << "(work): " << c.iaddr << " resp=" << (c.invert ? c.ptTimeout.checkTime() : !c.ptTimeout.checkTime())
<< " askcount=" << c.askCount << " askcount=" << c.askCount
<< endl; << endl;
...@@ -210,7 +210,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -210,7 +210,7 @@ void MBTCPMultiSlave::execute_tcp()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(execute_tcp): " << ex << std::endl; mbcrit << myname << "(execute_tcp): " << ex << std::endl;
} }
} }
...@@ -222,7 +222,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -222,7 +222,7 @@ void MBTCPMultiSlave::execute_tcp()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(execute_tcp): " << ex << std::endl; mbcrit << myname << "(execute_tcp): " << ex << std::endl;
} }
} }
} }
...@@ -245,7 +245,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -245,7 +245,7 @@ void MBTCPMultiSlave::execute_tcp()
prev = res; prev = res;
if( res != ModbusRTU::erNoError && res != ModbusRTU::erTimeOut ) if( res != ModbusRTU::erNoError && res != ModbusRTU::erTimeOut )
dlog[Debug::WARN] << myname << "(execute_tcp): " << ModbusRTU::mbErr2Str(res) << endl; mblog[Debug::WARN] << myname << "(execute_tcp): " << ModbusRTU::mbErr2Str(res) << endl;
#endif #endif
...@@ -261,7 +261,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -261,7 +261,7 @@ void MBTCPMultiSlave::execute_tcp()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(execute_tcp): (hb) " << ex << std::endl; mbcrit << myname << "(execute_tcp): (hb) " << ex << std::endl;
} }
} }
...@@ -278,7 +278,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -278,7 +278,7 @@ void MBTCPMultiSlave::execute_tcp()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(execute_rtu): (respond) " << ex << std::endl; mbcrit << myname << "(execute_rtu): (respond) " << ex << std::endl;
} }
} }
...@@ -290,7 +290,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -290,7 +290,7 @@ void MBTCPMultiSlave::execute_tcp()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(execute_rtu): (askCount) " << ex << std::endl; mbcrit << myname << "(execute_rtu): (askCount) " << ex << std::endl;
} }
} }
...@@ -302,14 +302,14 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -302,14 +302,14 @@ void MBTCPMultiSlave::execute_tcp()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(execute_rtu): (sessCount) " << ex << std::endl; mbcrit << myname << "(execute_rtu): (sessCount) " << ex << std::endl;
} }
} }
} }
catch(...) {} catch(...) {}
} }
dinfo << myname << "(execute_tcp): thread stopped.." << endl; mbinfo << myname << "(execute_tcp): thread stopped.." << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBTCPMultiSlave::initIterators() void MBTCPMultiSlave::initIterators()
...@@ -318,7 +318,7 @@ void MBTCPMultiSlave::initIterators() ...@@ -318,7 +318,7 @@ void MBTCPMultiSlave::initIterators()
shm->initIterator(sesscount_it); shm->initIterator(sesscount_it);
for( auto&& i : cmap ) for( auto && i : cmap )
i.second.initIterators(shm); i.second.initIterators(shm);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -21,7 +21,7 @@ int main(int argc, const char** argv) ...@@ -21,7 +21,7 @@ int main(int argc, const char** argv)
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--mbs-logfile filename - logfilename. Default: mbslave.log" << endl; cout << "--mbs-logfile filename - logfilename" << endl;
cout << endl; cout << endl;
MBSlave::help_print(argc, argv); MBSlave::help_print(argc, argv);
return 0; return 0;
...@@ -33,14 +33,14 @@ int main(int argc, const char** argv) ...@@ -33,14 +33,14 @@ int main(int argc, const char** argv)
string logfilename(conf->getArgParam("--mbs-logfile")); string logfilename(conf->getArgParam("--mbs-logfile"));
if( logfilename.empty() ) if( !logfilename.empty() )
logfilename = "mbslave.log"; {
std::ostringstream logname;
std::ostringstream logname; string dir(conf->getLogDir());
string dir(conf->getLogDir()); logname << dir << logfilename;
logname << dir << logfilename; ulog()->logFile( logname.str() );
ulog()->logFile( logname.str() ); dlog()->logFile( logname.str() );
dlog()->logFile( logname.str() ); }
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
...@@ -21,7 +21,7 @@ int main(int argc, const char** argv) ...@@ -21,7 +21,7 @@ int main(int argc, const char** argv)
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--mbs-logfile filename - logfilename. Default: mbslave.log" << endl; cout << "--mbs-logfile filename - logfilename" << endl;
cout << endl; cout << endl;
MBSlave::help_print(argc, argv); MBSlave::help_print(argc, argv);
return 0; return 0;
...@@ -33,14 +33,14 @@ int main(int argc, const char** argv) ...@@ -33,14 +33,14 @@ int main(int argc, const char** argv)
string logfilename(conf->getArgParam("--mbs-logfile")); string logfilename(conf->getArgParam("--mbs-logfile"));
if( logfilename.empty() ) if( !logfilename.empty() )
logfilename = "mbslave.log"; {
std::ostringstream logname;
std::ostringstream logname; string dir(conf->getLogDir());
string dir(conf->getLogDir()); logname << dir << logfilename;
logname << dir << logfilename; ulog()->logFile( logname.str() );
ulog()->logFile( logname.str() ); dlog()->logFile( logname.str() );
dlog()->logFile( logname.str() ); }
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
#!/bin/sh #!/bin/sh
uniset2-start.sh -f ./uniset2-mbslave --confile test.xml --dlog-add-levels any \ uniset2-start.sh -f ./uniset2-mbslave --confile test.xml \
--smemory-id SharedMemory \ --smemory-id SharedMemory \
--mbs-name MBSlave1 \ --mbs-name MBSlave1 \
--mbs-type TCP --mbs-inet-addr 127.0.0.1 --mbs-inet-port 2048 --mbs-reg-from-id 1 --mbs-my-addr 0x01 \ --mbs-type TCP --mbs-inet-addr 127.0.0.1 --mbs-inet-port 2048 --mbs-reg-from-id 1 --mbs-my-addr 0x01 \
--mbs-askcount-id SVU_AskCount_AS --mbs-respond-id RespondRTU_S --mbs-respond-invert 1 --ulog-add-levels system $* --mbs-askcount-id SVU_AskCount_AS --mbs-respond-id RespondRTU_S --mbs-respond-invert 1 --ulog-add-levels system \
--mbs-log-add-levels any $*
# --mbs-force 1 # --mbs-force 1
#--mbs-reg-from-id 1 \ #--mbs-reg-from-id 1 \
#--mbs-filter-field CAN2sender --mbs-filter-value SYSTSNode \ #--mbs-filter-field CAN2sender --mbs-filter-value SYSTSNode \
\ No newline at end of file
#ifndef MBLogSugar_H_
#define MBLogSugar_H_
// "синтаксический сахар"..для логов
#ifndef mbinfo
#define mbinfo if( mblog->debugging(Debug::INFO) ) mblog->info()
#endif
#ifndef mbwarn
#define mbwarn if( mblog->debugging(Debug::WARN) ) mblog->warn()
#endif
#ifndef mbcrit
#define mbcrit if( mblog->debugging(Debug::CRIT) ) mblog->crit()
#endif
#ifndef mblog1
#define mblog1 if( mblog->debugging(Debug::LEVEL1) ) mblog->level1()
#endif
#ifndef mblog2
#define mblog2 if( mblog->debugging(Debug::LEVEL2) ) mblog->level2()
#endif
#ifndef mblog3
#define mblog3 if( mblog->debugging(Debug::LEVEL3) ) mblog->level3()
#endif
#ifndef mblog4
#define mblog4 if( mblog->debugging(Debug::LEVEL4) ) mblog->level4()
#endif
#ifndef mblog5
#define mblog5 if( mblog->debugging(Debug::LEVEL5) ) mblog->level5()
#endif
#ifndef mblog6
#define mblog6 if( mblog->debugging(Debug::LEVEL6) ) mblog->level6()
#endif
#ifndef mblog7
#define mblog7 if( mblog->debugging(Debug::LEVEL7) ) mblog->level7()
#endif
#ifndef mblog8
#define mblog8 if( mblog->debugging(Debug::LEVEL8) ) mblog->level8()
#endif
#ifndef mblog9
#define mblog9 if( mblog->debugging(Debug::LEVEL9) ) mblog->level9()
#endif
#ifndef mblogany
#define mblogany mblog->any()
#endif
#endif
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