323 static std::shared_ptr<MBSlave>
init_mbslave(
int argc,
const char*
const* argv,
325 const std::string& prefix =
"mbs" );
327 static void help_print(
int argc,
const char*
const* argv );
329 static const int NoSafetyState = -1;
338 std::string amode2str( AccessMode m );
351 ModbusRTU::RegID regID;
356 vtype(VTypes::vtUnknown),
362 friend std::ostream& operator<<( std::ostream& os,
IOProperty& p );
368 typedef std::vector<IOProperty> BitSensorMap;
378 friend std::ostream& operator<<( std::ostream& os,
BitRegProperty& p );
379 friend std::ostream& operator<<( std::ostream& os,
BitRegProperty* p );
382 inline long getConnCount()
387 inline std::shared_ptr<LogAgregator> getLogAggregator()
391 inline std::shared_ptr<DebugStream> log()
398#ifndef DISABLE_REST_API
400 virtual Poco::JSON::Object::Ptr httpHelp(
const Poco::URI::QueryParameters& p )
override;
401 virtual Poco::JSON::Object::Ptr httpRequest(
const std::string& req,
const Poco::URI::QueryParameters& p )
override;
407 ModbusRTU::mbErrCode
readCoilStatus(
const ModbusRTU::ReadCoilMessage& query,
408 ModbusRTU::ReadCoilRetMessage& reply );
410 ModbusRTU::mbErrCode
readInputStatus(
const ModbusRTU::ReadInputStatusMessage& query,
411 ModbusRTU::ReadInputStatusRetMessage& reply );
415 ModbusRTU::ReadOutputRetMessage& reply );
419 ModbusRTU::ReadInputRetMessage& reply );
422 ModbusRTU::mbErrCode
forceSingleCoil(
const ModbusRTU::ForceSingleCoilMessage& query,
423 ModbusRTU::ForceSingleCoilRetMessage& reply );
427 ModbusRTU::ForceCoilsRetMessage& reply );
432 ModbusRTU::WriteOutputRetMessage& reply );
436 ModbusRTU::WriteSingleOutputRetMessage& reply );
443 ModbusRTU::mbErrCode
setDateTime(
const ModbusRTU::SetDateTimeMessage& query,
444 ModbusRTU::SetDateTimeRetMessage& reply );
447 ModbusRTU::mbErrCode
remoteService(
const ModbusRTU::RemoteServiceMessage& query,
448 ModbusRTU::RemoteServiceRetMessage& reply );
450 ModbusRTU::mbErrCode fileTransfer(
const ModbusRTU::FileTransferMessage& query,
451 ModbusRTU::FileTransferRetMessage& reply );
453 ModbusRTU::mbErrCode diagnostics(
const ModbusRTU::DiagnosticMessage& query,
454 ModbusRTU::DiagnosticRetMessage& reply );
456 ModbusRTU::mbErrCode read4314(
const ModbusRTU::MEIMessageRDI& query,
457 ModbusRTU::MEIMessageRetRDI& reply );
461 typedef std::map<ModbusRTU::RegID, IOProperty> RegMap;
463 typedef std::unordered_map<ModbusRTU::ModbusAddr, RegMap> IOMap;
469 typedef std::list<IOBase> ThresholdList;
470 ThresholdList thrlist;
472 std::shared_ptr<ModbusServerSlot> mbslot;
473 std::unordered_set<ModbusRTU::ModbusAddr>
vaddr;
474 std::string default_mbaddr = {
"" };
476 xmlNode* cnode = { 0 };
477 std::string s_field = {
"" };
478 std::string s_fvalue = {
"" };
479 int default_mbfunc = {0};
481 std::shared_ptr<SMInterface> shm;
486 void askSensors( UniversalIO::UIOCommand cmd );
488 virtual void execute_rtu();
489 virtual void execute_tcp();
490 virtual void updateStatistics();
491 virtual void updateTCPStatistics();
492 virtual void updateThresholds();
493 virtual void postReceiveEvent( ModbusRTU::mbErrCode res );
500 virtual void finalThread();
507 uniset::timeout_t checkExchangeTime = { 10000 };
509 virtual void initIterators();
510 bool initItem( UniXML::iterator& it );
511 bool readItem(
const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
513 void readConfiguration();
514 bool check_item( UniXML::iterator& it );
516 ModbusRTU::mbErrCode real_write( RegMap& rmap,
const ModbusRTU::ModbusData reg, ModbusRTU::ModbusData val,
const int fn = 0 );
517 ModbusRTU::mbErrCode real_write( RegMap& rmap,
const ModbusRTU::ModbusData regK,
const ModbusRTU::ModbusData* dat,
size_t& i,
size_t count,
const int fn = 0 );
518 ModbusRTU::mbErrCode real_read( RegMap& rmap,
const ModbusRTU::ModbusData reg, ModbusRTU::ModbusData& val,
const int fn = 0 );
519 ModbusRTU::mbErrCode much_read( RegMap& rmap,
const ModbusRTU::ModbusData reg, ModbusRTU::ModbusData* dat,
size_t count,
const int fn = 0 );
520 ModbusRTU::mbErrCode much_write(RegMap& rmap,
const ModbusRTU::ModbusData reg,
const ModbusRTU::ModbusData* dat,
size_t count,
const int fn = 0 );
521 ModbusRTU::mbErrCode bits_read( RegMap& rmap,
const ModbusRTU::ModbusData reg, ModbusRTU::BitsBuffer* dat,
size_t count,
const int fn = 0 );
523 ModbusRTU::mbErrCode real_read_it( RegMap& rmap, RegMap::iterator& it, ModbusRTU::ModbusData& val );
524 ModbusRTU::mbErrCode real_bitreg_read_it( std::shared_ptr<BitRegProperty>& bp, ModbusRTU::ModbusData& val );
525 ModbusRTU::mbErrCode real_read_prop( IOProperty* p, ModbusRTU::ModbusData& val );
527 ModbusRTU::mbErrCode real_write_it(RegMap& rmap, RegMap::iterator& it,
const ModbusRTU::ModbusData* dat,
size_t& i,
size_t count );
528 ModbusRTU::mbErrCode real_bitreg_write_it( std::shared_ptr<BitRegProperty>& bp,
const ModbusRTU::ModbusData val );
529 ModbusRTU::mbErrCode real_write_prop(IOProperty* p,
const ModbusRTU::ModbusData* dat,
size_t& i,
size_t count );
531#ifndef DISABLE_REST_API
533 Poco::JSON::Object::Ptr request_regs(
const std::string& req,
const Poco::URI::QueryParameters& p );
534 Poco::JSON::Object::Ptr get_regs(ModbusRTU::ModbusAddr addr,
const RegMap& rmap,
const std::vector<std::string>& q_regs );
535 Poco::JSON::Object::Ptr get_reginfo(
const IOProperty& prop );
538 timeout_t initPause = { 3000 };
540 std::unique_ptr< ThreadCreator<MBSlave> > thr;
542 std::mutex mutexStartNotify;
543 std::condition_variable startNotifyEvent;
545 PassiveTimer ptHeartBeat;
547 long maxHeartBeat = { 10 };
548 IOController::IOStateList::iterator itHeartBeat;
551 IOController::IOStateList::iterator itAskCount;
554 IOController::IOStateList::iterator itRespond;
556 bool respond_invert = {
false };
558 PassiveTimer ptTimeout;
559 long connCount = { 0 };
560 long restartTCPServerCount = { 0 };
562 std::atomic_bool activated = {
false };
563 std::atomic_bool canceled = {
false };
564 timeout_t activateTimeout = { 20000 };
565 bool smPingOK = {
false };
566 timeout_t wait_msec = { 3000 };
569 bool mbregFromID = {0};
570 bool checkMBFunc = {0};
571 bool noMBFuncOptimize = {0};
573 int getOptimizeWriteFunction(
const int fn );
575 typedef std::unordered_map<int, std::string> FileList;
577 std::string prefix = {
"" };
578 std::string prop_prefix = {
"" };
580 ModbusRTU::ModbusData
buf[ModbusRTU::MAXLENPACKET / 2 + 1];
585 typedef std::unordered_map<int, std::string> MEIValMap;
586 typedef std::unordered_map<int, MEIValMap> MEIObjIDMap;
587 typedef std::unordered_map<int, MEIObjIDMap> MEIDevIDMap;
591 std::shared_ptr<LogAgregator> loga;
592 std::shared_ptr<DebugStream> mblog;
593 std::shared_ptr<LogServer> logserv;
594 std::string logserv_host = {
""};
595 int logserv_port = {0};
597 std::string mbtype = {
"" };
601 void initTCPClients( UniXML::iterator confnode );
605 timeout_t updateStatTime = { 4000 };
606 ModbusTCPServer::Sessions
sess;
607 std::mutex sessMutex;
608 size_t sessMaxNum = { 5 };
609 std::shared_ptr<ModbusTCPServerSlot> tcpserver;
616 ptTimeout.setTiming(0);
619 std::string iaddr = {
"" };
622 IOController::IOStateList::iterator respond_it;
623 bool invert = {
false };
625 timeout_t tout = { 2000 };
627 long askCount = { 0 };
629 IOController::IOStateList::iterator askcount_it;
631 inline void initIterators(
const std::shared_ptr<SMInterface>& shm )
633 shm->initIterator( respond_it );
634 shm->initIterator( askcount_it );
637 const std::string getShortInfo()
const;
640 typedef std::unordered_map<std::string, ClientInfo> ClientsMap;
644 IOController::IOStateList::iterator sesscount_it;
646 std::atomic_bool tcpCancelled = {
true };
648 bool tcpBreakIfFailRun = {
false };
649 timeout_t tcpRepeatCreateSocketPause = { 30000 };