23 #include <unordered_map> 25 #include "IONotifyController.h" 26 #include "Calibration.h" 27 #include "DelayTimer.h" 28 #include "SMInterface.h" 29 #include "SharedMemory.h" 33 #include "RTUStorage.h" 34 #include "modbus/ModbusClient.h" 35 #include "Configuration.h" 44 MBConfig(
const std::shared_ptr<uniset::Configuration>& conf
46 , std::shared_ptr<SMInterface> _shm );
59 friend std::ostream& operator<<( std::ostream& os,
const ExchangeMode& em );
70 friend std::string to_string(
const SafeMode& m );
71 friend std::ostream& operator<<( std::ostream& os,
const SafeMode& m );
81 static DeviceType getDeviceType(
const std::string& dtype ) noexcept;
82 friend std::ostream& operator<<( std::ostream& os,
const DeviceType& dt );
98 rnum(VTypes::wsize(VTypes::vtUnknown)),
109 std::shared_ptr<RegInfo> reg;
112 friend std::ostream& operator<<( std::ostream& os,
const RSProperty& p );
114 typedef std::list<RSProperty> PList;
115 std::ostream& print_plist( std::ostream& os,
const PList& p );
117 typedef std::map<ModbusRTU::RegID, std::shared_ptr<RegInfo>> RegMap;
128 ModbusRTU::ModbusData mbval = { 0 };
129 ModbusRTU::ModbusData
mbreg = { 0 };
130 ModbusRTU::SlaveFunctionCode
mbfunc = { ModbusRTU::fnUnknown };
132 ModbusRTU::RegID regID = { 0 };
134 std::shared_ptr<RTUDevice> dev;
137 RTUStorage::RTUJack rtuJack = { RTUStorage::nUnknown };
147 RegMap::iterator rit;
161 friend std::ostream& operator<<( std::ostream& os,
const RegInfo& r );
162 friend std::ostream& operator<<( std::ostream& os,
const RegInfo* r );
167 std::unordered_map<size_t, std::shared_ptr<RegMap>> pollmap;
173 IOController::IOStateList::iterator resp_it;
176 bool resp_state = {
false };
177 bool resp_invert = {
false };
178 bool resp_force = {
false };
180 std::atomic<size_t> numreply = { 0 };
181 std::atomic<size_t> prev_numreply = { 0 };
188 IOController::IOStateList::iterator mode_it;
194 IOController::IOStateList::iterator safemode_it;
195 long safemode_value = { 1 };
198 bool checkRespond( std::shared_ptr<DebugStream>& log );
201 ComPort::Speed speed = { ComPort::ComSpeed38400 };
202 std::shared_ptr<RTUStorage> rtu188;
204 std::string getShortInfo()
const;
207 friend std::ostream& operator<<( std::ostream& os, RTUDevice& d );
209 typedef std::unordered_map<ModbusRTU::ModbusAddr, std::shared_ptr<RTUDevice>> RTUDeviceMap;
211 friend std::ostream& operator<<( std::ostream& os, RTUDeviceMap& d );
212 static void printMap(RTUDeviceMap& d);
214 typedef std::list<IOBase> ThresholdList;
220 mbfunc(ModbusRTU::fnUnknown),
224 std::shared_ptr<RTUDevice> dev;
225 ModbusRTU::ModbusData mbreg;
226 ModbusRTU::SlaveFunctionCode mbfunc;
228 std::shared_ptr<RegInfo> ri;
230 typedef std::list<InitRegInfo> InitList;
232 static void rtuQueryOptimization( RTUDeviceMap& m,
size_t maxQueryCount );
233 static void rtuQueryOptimizationForDevice(
const std::shared_ptr<RTUDevice>& d,
size_t maxQueryCount );
234 static void rtuQueryOptimizationForRegMap(
const std::shared_ptr<RegMap>& regmap,
size_t maxQueryCount );
238 ThresholdList thrlist;
239 RTUDeviceMap devices;
242 void loadConfig(
const std::shared_ptr<uniset::UniXML>& xml,
UniXML::iterator sensorsSection );
243 void initDeviceList(
const std::shared_ptr<UniXML>& xml );
247 std::string s_fvalue;
250 timeout_t recv_timeout = { 500 };
251 timeout_t default_timeout = { 5000 };
252 timeout_t aftersend_pause = { 0 };
254 timeout_t sleepPause_msec = { 10 };
257 xmlNode* cnode = { 0 };
258 std::shared_ptr<DebugStream> mblog;
262 std::string defaultMBtype;
263 std::string defaultMBaddr;
264 bool mbregFromID = {
false };
265 bool defaultMBinitOK = {
false };
266 bool noQueryOptimization = {
false };
267 std::shared_ptr<uniset::Configuration> conf;
268 std::shared_ptr<SMInterface> shm;
270 void cloneParams(
const std::shared_ptr<MBConfig>& conf );
271 std::string getShortInfo()
const;
275 bool initSMValue( ModbusRTU::ModbusData* data,
int count, RSProperty* p );
277 void readConfiguration(
const std::shared_ptr<uniset::UniXML>& xml, UniXML::iterator sensorsSection );
278 void initOffsetList();
280 std::shared_ptr<RTUDevice> addDev( RTUDeviceMap& dmap, ModbusRTU::ModbusAddr a, UniXML::iterator& it );
281 std::shared_ptr<RegInfo> addReg(std::shared_ptr<RegMap>& devices, ModbusRTU::RegID
id, ModbusRTU::ModbusData r, UniXML::iterator& it, std::shared_ptr<RTUDevice> dev );
282 RSProperty* addProp( PList& plist, RSProperty&& p );
284 bool initMTRitem(UniXML::iterator& it, std::shared_ptr<RegInfo>& p );
285 bool initRTU188item(UniXML::iterator& it, std::shared_ptr<RegInfo>& p );
286 bool initRSProperty( RSProperty& p, UniXML::iterator& it );
287 bool initRegInfo(std::shared_ptr<RegInfo>& r, UniXML::iterator& it, std::shared_ptr<RTUDevice>& dev );
288 bool initRTUDevice( std::shared_ptr<RTUDevice>& d, UniXML::iterator& it );
289 bool initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniXML::iterator& it );
294 #endif // _MBConfig_H_ Пассивный таймер
Definition: PassiveTimer.h:92
Definition: MBConfig.h:56
InitList initRegList
Definition: MBConfig.h:240
Definition: CommonEventLoop.h:14
Definition: MBConfig.h:78
long safeMode
Definition: MBConfig.h:192
ModbusRTU::ModbusData mbreg
Definition: MBConfig.h:129
VTypes::VType vType
Definition: MBConfig.h:92
Definition: MBConfig.h:216
Definition: MBConfig.h:53
bool initItem(UniXML::iterator &it)
Definition: MBConfig.cc:575
Definition: MBConfig.h:54
int8_t nbit
Definition: MBConfig.h:91
DeviceType
Definition: MBConfig.h:73
std::string prop_prefix
Definition: MBConfig.h:261
Definition: MBConfig.h:75
bool mb_initOK
Definition: MBConfig.h:154
ModbusRTU::ModbusAddr mbaddr
Definition: MBConfig.h:166
size_t q_num
Definition: MBConfig.h:144
Definition: MBConfig.h:55
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:69
Definition: MBConfig.h:164
bool ask_every_reg
Definition: MBConfig.h:184
Definition: MBConfig.h:118
timeout_t polltime
Definition: MBConfig.h:253
SafeMode
Definition: MBConfig.h:62
Definition: DelayTimer.h:29
bool sm_initOK
Definition: MBConfig.h:158
ExchangeMode
Definition: MBConfig.h:51
uniset::ObjectId safemode_id
Definition: MBConfig.h:193
size_t maxQueryCount
Definition: MBConfig.h:256
Definition: MBConfig.h:87
DeviceType dtype
Definition: MBConfig.h:169
ModbusRTU::SlaveFunctionCode mbfunc
Definition: MBConfig.h:130
Definition: MBConfig.h:57
uint16_t rnum
Definition: MBConfig.h:93
Definition: MBConfig.h:77
Definition: MBConfig.h:41
Definition: MBConfig.h:65
MTR::MTRType mtrType
Definition: MBConfig.h:141
Definition: MBConfig.h:76
size_t q_count
Definition: MBConfig.h:145
Definition: MBConfig.h:64
uint8_t nbyte
Definition: MBConfig.h:94
long ObjectId
Definition: UniSetTypes_i.idl:30
Definition: MBConfig.h:66