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 );
75 friend std::ostream& operator<<( std::ostream& os,
const ExchangeMode& em );
86 friend std::string to_string(
const SafeMode& m );
87 friend std::ostream& operator<<( std::ostream& os,
const SafeMode& m );
97 static DeviceType getDeviceType(
const std::string& dtype ) noexcept;
98 friend std::ostream& operator<<( std::ostream& os,
const DeviceType& dt );
113 nbit(-1), vType(VTypes::vtUnknown),
114 rnum(VTypes::wsize(VTypes::vtUnknown)),
125 std::shared_ptr<RegInfo> reg;
128 friend std::ostream& operator<<( std::ostream& os,
const RSProperty& p );
130 typedef std::list<RSProperty> PList;
131 static std::ostream& print_plist( std::ostream& os,
const PList& p );
133 typedef std::map<ModbusRTU::RegID, std::shared_ptr<RegInfo>> RegMap;
144 ModbusRTU::ModbusData mbval = { 0 };
145 ModbusRTU::ModbusData mbreg = { 0 };
146 ModbusRTU::SlaveFunctionCode mbfunc = { ModbusRTU::fnUnknown };
148 ModbusRTU::RegID regID = { 0 };
150 std::shared_ptr<RTUDevice> dev;
153 RTUStorage::RTUJack rtuJack = { RTUStorage::nUnknown };
157 MTR::MTRType mtrType = { MTR::mtUnknown };
160 size_t q_num = { 0 };
161 size_t q_count = { 1 };
163 RegMap::iterator rit;
170 bool mb_initOK = {
false };
174 bool sm_initOK = {
false };
177 friend std::ostream& operator<<( std::ostream& os,
const RegInfo& r );
178 friend std::ostream& operator<<( std::ostream& os,
const RegInfo* r );
182 ModbusRTU::ModbusAddr mbaddr = { 0 };
183 std::unordered_map<size_t, std::shared_ptr<RegMap>> pollmap;
189 IOController::IOStateList::iterator resp_it;
192 bool resp_state = {
false };
193 bool resp_invert = {
false };
194 bool resp_force = {
false };
196 std::atomic<size_t> numreply = { 0 };
197 std::atomic<size_t> prev_numreply = { 0 };
200 bool ask_every_reg = {
false };
204 IOController::IOStateList::iterator mode_it;
210 IOController::IOStateList::iterator safemode_it;
211 long safemode_value = { 1 };
214 bool checkRespond( std::shared_ptr<DebugStream>& log );
217 ComPort::Speed speed = { ComPort::ComSpeed38400 };
218 std::shared_ptr<RTUStorage> rtu188;
220 std::string getShortInfo()
const;
223 friend std::ostream& operator<<( std::ostream& os,
RTUDevice& d );
225 typedef std::unordered_map<ModbusRTU::ModbusAddr, std::shared_ptr<RTUDevice>> RTUDeviceMap;
227 friend std::ostream& operator<<( std::ostream& os, RTUDeviceMap& d );
228 void printMap(RTUDeviceMap& d);
238 inline std::shared_ptr<LogAgregator> getLogAggregator()
242 inline std::shared_ptr<DebugStream> log()
254 virtual void askSensors( UniversalIO::UIOCommand cmd );
255 virtual void initOutput();
258 virtual void initIterators();
259 virtual void initValues();
265 mbfunc(ModbusRTU::fnUnknown),
269 std::shared_ptr<RTUDevice> dev;
270 ModbusRTU::ModbusData mbreg;
271 ModbusRTU::SlaveFunctionCode mbfunc;
273 std::shared_ptr<RegInfo> ri;
275 typedef std::list<InitRegInfo> InitList;
277 void firstInitRegisters();
278 bool preInitRead( InitList::iterator& p );
279 bool initSMValue( ModbusRTU::ModbusData* data,
int count,
RSProperty* p );
282 RTUDeviceMap devices;
285 virtual std::shared_ptr<ModbusClient> initMB(
bool reopen =
false ) = 0;
288 bool pollRTU( std::shared_ptr<RTUDevice>& dev, RegMap::iterator& it );
294 void updateRTU(RegMap::iterator& it);
296 void updateRTU188(RegMap::iterator& it);
298 virtual void updateRespondSensors();
300 bool isUpdateSM(
bool wrFunc,
long devMode )
const noexcept;
301 bool isPollEnabled(
bool wrFunc )
const noexcept;
302 bool isSafeMode( std::shared_ptr<RTUDevice>& dev )
const noexcept;
304 bool isProcActive()
const;
305 void setProcActive(
bool st );
308 void readConfiguration();
309 bool readItem(
const std::shared_ptr<UniXML>& xml,
UniXML::iterator& it, xmlNode* sec );
311 void initDeviceList();
312 void initOffsetList();
314 std::shared_ptr<RTUDevice> addDev( RTUDeviceMap& dmap, ModbusRTU::ModbusAddr a,
UniXML::iterator& it );
315 std::shared_ptr<RegInfo> addReg(std::shared_ptr<RegMap>& devices, ModbusRTU::RegID
id, ModbusRTU::ModbusData r,
UniXML::iterator& it, std::shared_ptr<RTUDevice> dev );
321 bool initRegInfo(std::shared_ptr<RegInfo>& r,
UniXML::iterator& it, std::shared_ptr<RTUDevice>& dev );
323 virtual bool initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a,
UniXML::iterator& it );
325 std::string initPropPrefix(
const std::string& def_prop_prefix =
"" );
327 void rtuQueryOptimization( RTUDeviceMap& m );
328 void rtuQueryOptimizationForDevice(
const std::shared_ptr<RTUDevice>& d );
329 void rtuQueryOptimizationForRegMap(
const std::shared_ptr<RegMap>& regmap );
331 xmlNode* cnode = { 0 };
333 std::string s_fvalue;
335 std::shared_ptr<SMInterface> shm;
337 timeout_t initPause = { 3000 };
342 bool mbregFromID = {
false };
344 timeout_t sleepPause_msec = { 10 };
349 long maxHeartBeat = { 10 };
350 IOController::IOStateList::iterator itHeartBeat;
354 IOController::IOStateList::iterator itExchangeMode;
357 std::atomic_bool activated = {
false };
358 std::atomic_bool canceled = {
false };
359 timeout_t activateTimeout = { 20000 };
360 bool noQueryOptimization = {
false };
361 bool notUseExchangeTimer = {
false };
366 size_t poll_count = { 0 };
368 std::string statInfo = {
"" };
372 std::shared_ptr<ModbusClient> mb;
375 timeout_t recv_timeout = { 500 };
376 timeout_t default_timeout = { 5000 };
378 timeout_t aftersend_pause = { 0 };
387 typedef std::list<IOBase> ThresholdList;
388 ThresholdList thrlist;
390 std::string defaultMBtype;
391 std::string defaultMBaddr;
392 bool defaultMBinitOK = {
false };
394 std::shared_ptr<LogAgregator> loga;
395 std::shared_ptr<DebugStream> mblog;
396 std::shared_ptr<LogServer> logserv;
397 std::string logserv_host = {
""};
398 int logserv_port = {0};
399 const std::shared_ptr<SharedMemory> ic;
412 #endif // _MBExchange_H_ Пассивный таймер
Definition: PassiveTimer.h:92
Definition: MBExchange.h:91
size_t maxQueryCount
Definition: MBExchange.h:345
size_t ncycle
Definition: MBExchange.h:403
Definition: MBExchange.h:55
PassiveTimer ptReopen
Definition: MBExchange.h:380
Definition: CallbackTimer.h:29
Definition: MBExchange.h:134
Definition: MBExchange.h:72
VTypes::VType vType
Definition: MBExchange.h:108
Definition: MBExchange.h:71
uniset::ObjectId sidExchangeMode
Definition: MBExchange.h:353
void updateRSProperty(RSProperty *p, bool write_only=false)
Definition: MBExchange.cc:1348
long exchangeMode
Definition: MBExchange.h:355
Definition: MBExchange.h:82
Definition: MBExchange.h:81
Definition: MessageType.h:168
Definition: UniSetObject.h:73
Definition: VMonitor.h:116
Definition: MBExchange.h:73
Definition: MBExchange.h:261
ExchangeMode
Definition: MBExchange.h:67
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:69
SafeMode
Definition: MBExchange.h:78
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации) ...
Definition: MBExchange.cc:2990
DeviceType
Definition: MBExchange.h:89
PassiveTimer ptInitChannel
Definition: MBExchange.h:383
uint8_t nbyte
Definition: MBExchange.h:110
Definition: MBExchange.h:94
Definition: MBExchange.h:180
bool force
Definition: MBExchange.h:340
Definition: DelayTimer.h:29
Definition: MessageType.h:124
uint16_t rnum
Definition: MBExchange.h:109
Definition: MBExchange.h:92
bool force_out
Definition: MBExchange.h:341
int8_t nbit
Definition: MBExchange.h:107
Definition: MBExchange.h:80
std::string prop_prefix
Definition: MBExchange.h:370
timeout_t stat_time
Definition: MBExchange.h:365
Definition: MessageType.h:211
InitList initRegList
Definition: MBExchange.h:283
timeout_t polltime
Definition: MBExchange.h:343
static void help_print(int argc, const char *const *argv)
Definition: MBExchange.cc:256
Definition: UniSetTypes_i.idl:64
void updateMTR(RegMap::iterator &it)
Definition: MBExchange.cc:1800
Definition: MBExchange.h:69
Definition: MBExchange.h:93
Definition: MBExchange.h:103
virtual bool deactivateObject() override
Деактивиция объекта (переопределяется для необходимых действий при завершении работы) ...
Definition: MBExchange.cc:362
static bool initItem(IOBase *b, UniXML::iterator &it, const std::shared_ptr< SMInterface > &shm, const std::string &prefix, bool init_prefix_only, std::shared_ptr< DebugStream > dlog=nullptr, std::string myname="", int def_filtersize=0, float def_filterT=0.0, float def_lsparam=0.2, float def_iir_coeff_prev=0.5, float def_iir_coeff_new=0.5)
Definition: IOBase.cc:549
PassiveTimer ptStatistic
Definition: MBExchange.h:367
long ObjectId
Definition: UniSetTypes_i.idl:30
Definition: MBExchange.h:70