325 static std::shared_ptr<MBSlave>
init_mbslave(
int argc,
const char*
const* argv,
327 const std::string& prefix =
"mbs" );
329 static void help_print(
int argc,
const char*
const* argv );
331 static const int NoSafetyState = -1;
340 std::string amode2str( AccessMode m );
353 ModbusRTU::RegID regID;
358 vtype(VTypes::vtUnknown),
364 friend std::ostream& operator<<( std::ostream& os,
IOProperty& p );
370 typedef std::vector<IOProperty> BitSensorMap;
380 friend std::ostream& operator<<( std::ostream& os,
BitRegProperty& p );
381 friend std::ostream& operator<<( std::ostream& os,
BitRegProperty* p );
384 inline long getConnCount()
389 inline std::shared_ptr<LogAgregator> getLogAggregator()
393 inline std::shared_ptr<DebugStream> log()
400#ifndef DISABLE_REST_API
402 virtual Poco::JSON::Object::Ptr httpHelp(
const Poco::URI::QueryParameters& p )
override;
403 virtual Poco::JSON::Object::Ptr httpRequest(
const UHttp::HttpRequestContext& ctx )
override;
404 virtual Poco::JSON::Object::Ptr httpGetMyInfo( Poco::JSON::Object::Ptr root )
override;
410 ModbusRTU::mbErrCode
readCoilStatus(
const ModbusRTU::ReadCoilMessage& query,
411 ModbusRTU::ReadCoilRetMessage& reply );
413 ModbusRTU::mbErrCode
readInputStatus(
const ModbusRTU::ReadInputStatusMessage& query,
414 ModbusRTU::ReadInputStatusRetMessage& reply );
418 ModbusRTU::ReadOutputRetMessage& reply );
422 ModbusRTU::ReadInputRetMessage& reply );
425 ModbusRTU::mbErrCode
forceSingleCoil(
const ModbusRTU::ForceSingleCoilMessage& query,
426 ModbusRTU::ForceSingleCoilRetMessage& reply );
430 ModbusRTU::ForceCoilsRetMessage& reply );
435 ModbusRTU::WriteOutputRetMessage& reply );
439 ModbusRTU::WriteSingleOutputRetMessage& reply );
446 ModbusRTU::mbErrCode
setDateTime(
const ModbusRTU::SetDateTimeMessage& query,
447 ModbusRTU::SetDateTimeRetMessage& reply );
450 ModbusRTU::mbErrCode
remoteService(
const ModbusRTU::RemoteServiceMessage& query,
451 ModbusRTU::RemoteServiceRetMessage& reply );
453 ModbusRTU::mbErrCode fileTransfer(
const ModbusRTU::FileTransferMessage& query,
454 ModbusRTU::FileTransferRetMessage& reply );
456 ModbusRTU::mbErrCode diagnostics(
const ModbusRTU::DiagnosticMessage& query,
457 ModbusRTU::DiagnosticRetMessage& reply );
459 ModbusRTU::mbErrCode read4314(
const ModbusRTU::MEIMessageRDI& query,
460 ModbusRTU::MEIMessageRetRDI& reply );
464 typedef std::map<ModbusRTU::RegID, IOProperty> RegMap;
466 typedef std::unordered_map<ModbusRTU::ModbusAddr, RegMap> IOMap;
472 typedef std::list<IOBase> ThresholdList;
473 ThresholdList thrlist;
475 std::shared_ptr<ModbusServerSlot> mbslot;
476 std::unordered_set<ModbusRTU::ModbusAddr>
vaddr;
477 std::string default_mbaddr = {
"" };
478 ModbusRTU::ModbusAddr myaddr = { ModbusRTU::BroadcastAddr };
480 xmlNode* cnode = { 0 };
481 std::string s_field = {
"" };
482 std::string s_fvalue = {
"" };
483 int default_mbfunc = {0};
485 std::shared_ptr<SMInterface> shm;
490 void askSensors( UniversalIO::UIOCommand cmd );
492 virtual void execute_rtu();
493 virtual void execute_tcp();
494 virtual void updateStatistics();
495 virtual void updateTCPStatistics();
496 virtual void updateThresholds();
497 virtual void postReceiveEvent( ModbusRTU::mbErrCode res );
504 virtual void finalThread();
511 uniset::timeout_t checkExchangeTime = { 10000 };
513 virtual void initIterators();
514 bool initItem( UniXML::iterator& it );
515 bool readItem(
const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
517 void readConfiguration();
518 bool check_item( UniXML::iterator& it );
520 ModbusRTU::mbErrCode real_write( RegMap& rmap,
const ModbusRTU::ModbusData reg, ModbusRTU::ModbusData val,
const int fn = 0 );
521 ModbusRTU::mbErrCode real_write( RegMap& rmap,
const ModbusRTU::ModbusData regK,
const ModbusRTU::ModbusData* dat,
size_t& i,
size_t count,
const int fn = 0 );
522 ModbusRTU::mbErrCode real_read( RegMap& rmap,
const ModbusRTU::ModbusData reg, ModbusRTU::ModbusData& val,
const int fn = 0 );
523 ModbusRTU::mbErrCode much_read( RegMap& rmap,
const ModbusRTU::ModbusData reg, ModbusRTU::ModbusData* dat,
size_t count,
const int fn = 0 );
524 ModbusRTU::mbErrCode much_write(RegMap& rmap,
const ModbusRTU::ModbusData reg,
const ModbusRTU::ModbusData* dat,
size_t count,
const int fn = 0 );
525 ModbusRTU::mbErrCode bits_read( RegMap& rmap,
const ModbusRTU::ModbusData reg, ModbusRTU::BitsBuffer* dat,
size_t count,
const int fn = 0 );
527 ModbusRTU::mbErrCode real_read_it( RegMap& rmap, RegMap::iterator& it, ModbusRTU::ModbusData& val );
528 ModbusRTU::mbErrCode real_bitreg_read_it( std::shared_ptr<BitRegProperty>& bp, ModbusRTU::ModbusData& val );
529 ModbusRTU::mbErrCode real_read_prop( IOProperty* p, ModbusRTU::ModbusData& val );
531 ModbusRTU::mbErrCode real_write_it(RegMap& rmap, RegMap::iterator& it,
const ModbusRTU::ModbusData* dat,
size_t& i,
size_t count );
532 ModbusRTU::mbErrCode real_bitreg_write_it( std::shared_ptr<BitRegProperty>& bp,
const ModbusRTU::ModbusData val );
533 ModbusRTU::mbErrCode real_write_prop(IOProperty* p,
const ModbusRTU::ModbusData* dat,
size_t& i,
size_t count );
535#ifndef DISABLE_REST_API
537 Poco::JSON::Object::Ptr httpGetParam(
const Poco::URI::QueryParameters& p );
538 Poco::JSON::Object::Ptr httpSetParam(
const Poco::URI::QueryParameters& p );
539 Poco::JSON::Object::Ptr httpStatus();
540 Poco::JSON::Object::Ptr httpGet(
const Poco::URI::QueryParameters& p );
541 Poco::JSON::Object::Ptr httpRegisters(
const Poco::URI::QueryParameters& p );
543 bool httpEnabledSetParams = {
false };
546 timeout_t initPause = { 3000 };
548 std::unique_ptr< ThreadCreator<MBSlave> > thr;
550 std::mutex mutexStartNotify;
551 std::condition_variable startNotifyEvent;
553 PassiveTimer ptHeartBeat;
555 long maxHeartBeat = { 10 };
556 IOController::IOStateList::iterator itHeartBeat;
559 IOController::IOStateList::iterator itAskCount;
562 IOController::IOStateList::iterator itRespond;
564 bool respond_invert = {
false };
566 PassiveTimer ptTimeout;
567 long connCount = { 0 };
568 long restartTCPServerCount = { 0 };
570 std::atomic_bool activated = {
false };
571 std::atomic_bool canceled = {
false };
572 timeout_t activateTimeout = { 20000 };
573 bool smPingOK = {
false };
574 timeout_t wait_msec = { 3000 };
577 bool mbregFromID = {0};
578 bool checkMBFunc = {0};
579 bool noMBFuncOptimize = {0};
581 int getOptimizeWriteFunction(
const int fn );
583 typedef std::unordered_map<int, std::string> FileList;
585 std::string prefix = {
"" };
586 std::string prop_prefix = {
"" };
588 ModbusRTU::ModbusData
buf[ModbusRTU::MAXLENPACKET / 2 + 1];
593 typedef std::unordered_map<int, std::string> MEIValMap;
594 typedef std::unordered_map<int, MEIValMap> MEIObjIDMap;
595 typedef std::unordered_map<int, MEIObjIDMap> MEIDevIDMap;
599 std::shared_ptr<LogAgregator> loga;
600 std::shared_ptr<DebugStream> mblog;
601 std::shared_ptr<LogServer> logserv;
602 std::string logserv_host = {
""};
603 int logserv_port = {0};
605 std::string mbtype = {
"" };
609 void initTCPClients( UniXML::iterator confnode );
613 timeout_t updateStatTime = { 4000 };
614 ModbusTCPServer::Sessions
sess;
615 std::mutex sessMutex;
616 size_t sessMaxNum = { 5 };
617 std::shared_ptr<ModbusTCPServerSlot> tcpserver;
624 ptTimeout.setTiming(0);
627 std::string iaddr = {
"" };
630 IOController::IOStateList::iterator respond_it;
631 bool invert = {
false };
633 timeout_t tout = { 2000 };
635 long askCount = { 0 };
637 IOController::IOStateList::iterator askcount_it;
639 inline void initIterators(
const std::shared_ptr<SMInterface>& shm )
641 shm->initIterator( respond_it );
642 shm->initIterator( askcount_it );
645 const std::string getShortInfo()
const;
648 typedef std::unordered_map<std::string, ClientInfo> ClientsMap;
652 IOController::IOStateList::iterator sesscount_it;
654 std::atomic_bool tcpCancelled = {
true };
656 bool tcpBreakIfFailRun = {
false };
657 timeout_t tcpRepeatCreateSocketPause = { 30000 };