17 #ifndef _MBExchange_H_
18 #define _MBExchange_H_
23 #include <unordered_map>
25 #include "IONotifyController.h"
26 #include "UniSetObject.h"
27 #include "PassiveTimer.h"
28 #include "DelayTimer.h"
31 #include "Calibration.h"
32 #include "SMInterface.h"
33 #include "SharedMemory.h"
34 #include "ThreadCreator.h"
38 #include "RTUStorage.h"
39 #include "modbus/ModbusClient.h"
40 #include "LogAgregator.h"
41 #include "LogServer.h"
42 #include "LogAgregator.h"
46 #define vmonit( var ) vmon.add( #var, var )
60 const std::string& prefix =
"mb" );
64 static void help_print(
int argc,
const char*
const* argv );
66 static const int NoSafetyState = -1;
78 friend std::ostream& operator<<( std::ostream& os,
const ExchangeMode& em );
88 static DeviceType getDeviceType(
const std::string& dtype );
89 friend std::ostream& operator<<( std::ostream& os,
const DeviceType& dt );
104 nbit(-1), vType(VTypes::vtUnknown),
105 rnum(VTypes::wsize(VTypes::vtUnknown)),
116 std::shared_ptr<RegInfo> reg;
119 friend std::ostream& operator<<( std::ostream& os,
const RSProperty& p );
121 typedef std::list<RSProperty> PList;
122 static std::ostream& print_plist( std::ostream& os,
const PList& p );
124 typedef std::map<ModbusRTU::RegID, std::shared_ptr<RegInfo>> RegMap;
137 rtuJack(RTUStorage::nUnknown), rtuChan(0),
142 ModbusRTU::ModbusData mbval;
148 std::shared_ptr<RTUDevice> dev;
151 RTUStorage::RTUJack rtuJack;
161 RegMap::iterator rit;
175 friend std::ostream& operator<<( std::ostream& os,
RegInfo& r );
176 friend std::ostream& operator<<( std::ostream& os,
RegInfo* r );
191 speed(ComPort::ComSpeed38400),
197 std::unordered_map<unsigned int, std::shared_ptr<RegMap>> pollmap;
203 IOController::IOStateList::iterator resp_it;
208 bool resp_force = {
false };
210 std::atomic<size_t> numreply;
211 std::atomic<size_t> prev_numreply;
218 IOController::IOStateList::iterator mode_it;
222 bool checkRespond( std::shared_ptr<DebugStream>& log );
225 ComPort::Speed speed;
226 std::shared_ptr<RTUStorage> rtu188;
228 std::string getShortInfo()
const;
231 friend std::ostream& operator<<( std::ostream& os,
RTUDevice& d );
233 typedef std::unordered_map<ModbusRTU::ModbusAddr, std::shared_ptr<RTUDevice>> RTUDeviceMap;
235 friend std::ostream& operator<<( std::ostream& os, RTUDeviceMap& d );
236 void printMap(RTUDeviceMap& d);
246 inline std::shared_ptr<LogAgregator> getLogAggregator()
250 inline std::shared_ptr<DebugStream> log()
262 virtual void askSensors( UniversalIO::UIOCommand cmd );
263 virtual void initOutput();
264 virtual void sigterm(
int signo )
override;
266 virtual void initIterators();
267 virtual void initValues();
273 mbfunc(ModbusRTU::fnUnknown),
277 std::shared_ptr<RTUDevice> dev;
278 ModbusRTU::ModbusData mbreg;
279 ModbusRTU::SlaveFunctionCode mbfunc;
281 std::shared_ptr<RegInfo> ri;
283 typedef std::list<InitRegInfo> InitList;
285 void firstInitRegisters();
286 bool preInitRead( InitList::iterator& p );
287 bool initSMValue( ModbusRTU::ModbusData* data,
int count,
RSProperty* p );
290 RTUDeviceMap devices;
294 virtual std::shared_ptr<ModbusClient> initMB(
bool reopen =
false ) = 0;
297 bool pollRTU( std::shared_ptr<RTUDevice>& dev, RegMap::iterator& it );
300 void updateRTU(RegMap::iterator& it);
301 void updateMTR(RegMap::iterator& it);
302 void updateRTU188(RegMap::iterator& it);
303 void updateRSProperty(
RSProperty* p,
bool write_only =
false );
304 virtual void updateRespondSensors();
306 bool checkUpdateSM(
bool wrFunc,
long devMode );
307 bool checkPoll(
bool wrFunc )
const;
309 bool checkProcActive()
const;
310 void setProcActive(
bool st );
313 void readConfiguration();
314 bool readItem(
const std::shared_ptr<UniXML>& xml,
UniXML::iterator& it, xmlNode* sec );
316 void initDeviceList();
317 void initOffsetList();
319 std::shared_ptr<RTUDevice> addDev( RTUDeviceMap& dmap, ModbusRTU::ModbusAddr a,
UniXML::iterator& it );
320 std::shared_ptr<RegInfo> addReg(std::shared_ptr<RegMap>& devices, ModbusRTU::RegID
id, ModbusRTU::ModbusData r,
UniXML::iterator& it, std::shared_ptr<RTUDevice> dev );
326 bool initRegInfo(std::shared_ptr<RegInfo>& r,
UniXML::iterator& it, std::shared_ptr<RTUDevice>& dev );
328 virtual bool initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a,
UniXML::iterator& it );
330 std::string initPropPrefix(
const std::string& def_prop_prefix =
"" );
332 void rtuQueryOptimization( RTUDeviceMap& m );
334 xmlNode* cnode = { 0 };
336 std::string s_fvalue;
338 std::shared_ptr<SMInterface> shm;
340 timeout_t initPause = { 3000 };
345 bool mbregFromID = {
false };
347 timeout_t sleepPause_msec;
352 long maxHeartBeat = { 10 };
353 IOController::IOStateList::iterator itHeartBeat;
357 IOController::IOStateList::iterator itExchangeMode;
360 std::atomic_bool activated = {
false };
361 timeout_t activateTimeout = { 20000 };
362 bool noQueryOptimization = {
false };
363 bool no_extimer = {
false };
368 size_t poll_count = { 0 };
370 std::string statInfo = {
"" };
374 std::shared_ptr<ModbusClient> mb;
377 timeout_t recv_timeout = { 500 };
378 timeout_t default_timeout = { 5000 };
380 timeout_t aftersend_pause = { 0 };
389 typedef std::list<IOBase> ThresholdList;
390 ThresholdList thrlist;
392 std::string defaultMBtype;
393 std::string defaultMBaddr;
394 bool defaultMBinitOK = {
false };
396 std::shared_ptr<LogAgregator> loga;
397 std::shared_ptr<DebugStream> mblog;
398 std::shared_ptr<LogServer> logserv;
399 std::string logserv_host = {
""};
400 int logserv_port = {0};
401 const std::shared_ptr<SharedMemory> ic;
414 #endif // _MBExchange_H_
Пассивный таймер
Definition: PassiveTimer.h:90
short nbit
Definition: MBExchange.h:98
Definition: MBExchange.h:82
MTR::MTRType mtrType
Definition: MBExchange.h:155
size_t maxQueryCount
Definition: MBExchange.h:348
size_t ncycle
Definition: MBExchange.h:405
Definition: MBExchange.h:55
PassiveTimer ptReopen
Definition: MBExchange.h:382
Definition: CallbackTimer.h:29
Definition: MBExchange.h:125
Definition: MBExchange.h:74
VTypes::VType vType
Definition: MBExchange.h:99
bool initItem(UniXML::iterator &it)
Definition: MBExchange.cc:2317
Definition: MBExchange.h:73
uniset::ObjectId sidExchangeMode
Definition: MBExchange.h:356
long exchangeMode
Definition: MBExchange.h:358
ModbusRTU::ModbusAddr mbaddr
Definition: MBExchange.h:196
unsigned short rnum
Definition: MBExchange.h:100
bool ask_every_reg
Definition: MBExchange.h:214
Definition: MessageType.h:166
Definition: UniSetObject.h:73
Definition: MBExchange.h:75
Definition: MBExchange.h:269
ExchangeMode
Definition: MBExchange.h:69
ModbusRTU::ModbusData mbreg
Definition: MBExchange.h:143
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:56
virtual void sigterm(int signo) override
Definition: MBExchange.cc:358
DeviceType dtype
Definition: MBExchange.h:199
size_t q_num
Definition: MBExchange.h:158
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации) ...
Definition: MBExchange.cc:2785
DeviceType
Definition: MBExchange.h:80
PassiveTimer ptInitChannel
Definition: MBExchange.h:385
bool mb_initOK
Definition: MBExchange.h:168
Definition: MBExchange.h:85
Definition: MBExchange.h:178
bool force
Definition: MBExchange.h:343
Definition: DelayTimer.h:29
Definition: MessageType.h:122
Definition: MBExchange.h:83
bool force_out
Definition: MBExchange.h:344
std::string prop_prefix
Definition: MBExchange.h:372
timeout_t stat_time
Definition: MBExchange.h:367
Definition: MessageType.h:209
InitList initRegList
Definition: MBExchange.h:291
timeout_t polltime
Definition: MBExchange.h:346
static void help_print(int argc, const char *const *argv)
Definition: MBExchange.cc:256
bool sm_initOK
Definition: MBExchange.h:172
unsigned short nbyte
Definition: MBExchange.h:101
Definition: UniSetTypes_i.idl:64
Definition: MBExchange.h:71
ModbusRTU::SlaveFunctionCode mbfunc
Definition: MBExchange.h:144
Definition: MBExchange.h:84
Definition: MBExchange.h:94
PassiveTimer ptStatistic
Definition: MBExchange.h:369
long ObjectId
Definition: UniSetTypes_i.idl:30
size_t q_count
Definition: MBExchange.h:159
Definition: MBExchange.h:72