6#include <unordered_set>
7#include <unordered_map>
8#include <sigc++/sigc++.h>
12#include "Configuration.h"
13#include "PassiveTimer.h"
14#include "ModbusTypes.h"
19 struct hash<
uniset::ModbusRTU::mbErrCode>
21 size_t operator()(
const uniset::ModbusRTU::mbErrCode& e)
const
23 return std::hash<size_t>()(e);
38 void initLog(
uniset::Configuration* conf,
const std::string& name,
const std::string& logfile =
"" );
39 void setLog( std::shared_ptr<DebugStream> dlog );
40 inline std::shared_ptr<DebugStream> log()
45 static std::unordered_set<ModbusRTU::ModbusAddr> addr2vaddr( ModbusRTU::ModbusAddr& mbaddr );
52 ModbusRTU::mbErrCode
receive(
const std::unordered_set<ModbusRTU::ModbusAddr>& vaddr, timeout_t msecTimeout );
55 virtual ModbusRTU::mbErrCode receive_one(
const ModbusRTU::ModbusAddr addr, timeout_t msec );
63 typedef sigc::signal<ModbusRTU::mbErrCode, const std::unordered_set<ModbusRTU::ModbusAddr>, timeout_t> PreReceiveSignal;
64 PreReceiveSignal signal_pre_receive();
67 typedef sigc::signal<void, ModbusRTU::mbErrCode> PostReceiveSignal;
68 PostReceiveSignal signal_post_receive();
77 static bool checkAddr(
const std::unordered_set<ModbusRTU::ModbusAddr>& vaddr,
const ModbusRTU::ModbusAddr addr );
78 static std::string vaddr2str(
const std::unordered_set<ModbusRTU::ModbusAddr>& vaddr );
96 void setCRCNoCheckit(
bool set );
97 bool isCRCNoCheckit()
const;
99 void setBroadcastMode(
bool set );
100 bool getBroadcastMode()
const;
102 void setCleanBeforeSend(
bool set );
103 bool getCleanBeforeSend()
const;
110 std::shared_ptr<DebugStream> dlog =
nullptr );
121 std::shared_ptr<DebugStream> dlog =
nullptr );
123 virtual void cleanupChannel() {}
124 virtual void terminate() {}
126 virtual bool isActive()
const = 0;
129 typedef std::unordered_map<ModbusRTU::mbErrCode, size_t> ExchangeErrorMap;
131 ExchangeErrorMap getErrorMap();
132 size_t getErrCount( ModbusRTU::mbErrCode e )
const;
133 size_t resetErrCount( ModbusRTU::mbErrCode e,
size_t set = 0 );
135 size_t getAskCount()
const noexcept;
136 void resetAskCounter();
140 virtual void iowait( timeout_t usec );
143 virtual ModbusRTU::mbErrCode
realReceive(
const std::unordered_set<ModbusRTU::ModbusAddr>& vaddr, timeout_t msecTimeout ) = 0;
270 virtual ModbusRTU::mbErrCode sendData(
unsigned char* buf,
int len ) = 0;
281 return ModbusRTU::erNoError;
285 return ModbusRTU::erNoError;
289 virtual ModbusRTU::mbErrCode processing( ModbusRTU::ModbusMessage& buf );
292 ModbusRTU::mbErrCode
recv(
const std::unordered_set<ModbusRTU::ModbusAddr>& vaddr, ModbusRTU::ModbusMessage& buf, timeout_t timeout );
293 ModbusRTU::mbErrCode recv_pdu( ModbusRTU::ModbusMessage& rbuf, timeout_t timeout );
295 std::timed_mutex recvMutex;
301 bool crcNoCheckit = {
false };
302 bool cleanBeforeSend = {
false };
304 void printProcessingTime();
305 PassiveTimer tmProcessing;
307 std::shared_ptr<DebugStream> dlog;
310 size_t askCount = { 0 };
313 PreReceiveSignal m_pre_signal;
314 PostReceiveSignal m_post_signal;
Definition Configuration.h:46
Definition ModbusServer.h:33
void setRecvTimeout(timeout_t msec)
Definition ModbusServer.cc:60
timeout_t aftersend_msec
Definition ModbusServer.h:298
static bool checkAddr(const std::unordered_set< ModbusRTU::ModbusAddr > &vaddr, const ModbusRTU::ModbusAddr addr)
Definition ModbusServer.cc:122
virtual ModbusRTU::mbErrCode journalCommand(ModbusRTU::JournalCommandMessage &query, ModbusRTU::JournalCommandRetMessage &reply)=0
timeout_t recvTimeOut_ms
Definition ModbusServer.h:296
virtual ModbusRTU::mbErrCode diagnostics(ModbusRTU::DiagnosticMessage &query, ModbusRTU::DiagnosticRetMessage &reply)=0
timeout_t setReplyTimeout(timeout_t msec)
Definition ModbusServer.cc:101
virtual ModbusRTU::mbErrCode realReceive(const std::unordered_set< ModbusRTU::ModbusAddr > &vaddr, timeout_t msecTimeout)=0
virtual ModbusRTU::mbErrCode send(ModbusRTU::ModbusMessage &buf)
Definition ModbusServer.cc:1790
virtual ModbusRTU::mbErrCode writeOutputSingleRegister(ModbusRTU::WriteSingleOutputMessage &query, ModbusRTU::WriteSingleOutputRetMessage &reply)=0
virtual ModbusRTU::mbErrCode readCoilStatus(ModbusRTU::ReadCoilMessage &query, ModbusRTU::ReadCoilRetMessage &reply)=0
static ModbusRTU::mbErrCode replySetDateTime(ModbusRTU::SetDateTimeMessage &query, ModbusRTU::SetDateTimeRetMessage &reply, std::shared_ptr< DebugStream > dlog=nullptr)
Definition ModbusServer.cc:1750
virtual ModbusRTU::mbErrCode setDateTime(ModbusRTU::SetDateTimeMessage &query, ModbusRTU::SetDateTimeRetMessage &reply)=0
bool onBroadcast
Definition ModbusServer.h:300
virtual ModbusRTU::mbErrCode read4314(ModbusRTU::MEIMessageRDI &query, ModbusRTU::MEIMessageRetRDI &reply)=0
virtual ModbusRTU::mbErrCode forceSingleCoil(ModbusRTU::ForceSingleCoilMessage &query, ModbusRTU::ForceSingleCoilRetMessage &reply)=0
timeout_t setAfterSendPause(timeout_t msec)
Definition ModbusServer.cc:115
virtual ModbusRTU::mbErrCode forceMultipleCoils(ModbusRTU::ForceCoilsMessage &query, ModbusRTU::ForceCoilsRetMessage &reply)=0
virtual ModbusRTU::mbErrCode readInputStatus(ModbusRTU::ReadInputStatusMessage &query, ModbusRTU::ReadInputStatusRetMessage &reply)=0
virtual void setChannelTimeout(timeout_t msec)=0
timeout_t replyTimeout_ms
Definition ModbusServer.h:297
void setSleepPause(timeout_t msec)
Definition ModbusServer.cc:66
virtual ModbusRTU::mbErrCode fileTransfer(ModbusRTU::FileTransferMessage &query, ModbusRTU::FileTransferRetMessage &reply)=0
virtual ModbusRTU::mbErrCode writeOutputRegisters(ModbusRTU::WriteOutputMessage &query, ModbusRTU::WriteOutputRetMessage &reply)=0
static ModbusRTU::mbErrCode replyFileTransfer(const std::string &fname, ModbusRTU::FileTransferMessage &query, ModbusRTU::FileTransferRetMessage &reply, std::shared_ptr< DebugStream > dlog=nullptr)
Definition ModbusServer.cc:1632
virtual size_t getNextData(unsigned char *buf, int len)=0
virtual ModbusRTU::mbErrCode readOutputRegisters(ModbusRTU::ReadOutputMessage &query, ModbusRTU::ReadOutputRetMessage &reply)=0
virtual ModbusRTU::mbErrCode remoteService(ModbusRTU::RemoteServiceMessage &query, ModbusRTU::RemoteServiceRetMessage &reply)=0
virtual ModbusRTU::mbErrCode readInputRegisters(ModbusRTU::ReadInputMessage &query, ModbusRTU::ReadInputRetMessage &reply)=0
timeout_t sleepPause_msec
Definition ModbusServer.h:299
ExchangeErrorMap errmap
Definition ModbusServer.h:311
ModbusRTU::mbErrCode receive(const std::unordered_set< ModbusRTU::ModbusAddr > &vaddr, timeout_t msecTimeout)
Definition ModbusServer.cc:1566
ModbusRTU::mbErrCode recv(const std::unordered_set< ModbusRTU::ModbusAddr > &vaddr, ModbusRTU::ModbusMessage &buf, timeout_t timeout)
Definition ModbusServer.cc:631
Definition Calibration.h:27
Definition ModbusTypes.h:1118
Definition ModbusTypes.h:1176
Definition ModbusTypes.h:1575
Definition ModbusTypes.h:1603
Definition ModbusTypes.h:727
Definition ModbusTypes.h:804
Definition ModbusTypes.h:937
Definition ModbusTypes.h:988
Definition ModbusTypes.h:1310
Definition ModbusTypes.h:1333
Definition ModbusTypes.h:1188
Definition ModbusTypes.h:1243
Definition ModbusTypes.h:211
Definition ModbusTypes.h:347
Definition ModbusTypes.h:378
Definition ModbusTypes.h:548
Definition ModbusTypes.h:577
Definition ModbusTypes.h:1456
Definition ModbusTypes.h:1489
Definition ModbusTypes.h:1398
Definition ModbusTypes.h:1436
Definition ModbusTypes.h:844
Definition ModbusTypes.h:898
Definition ModbusTypes.h:1033
Definition ModbusTypes.h:1079