UniSet 2.41.2
MBTCPMaster.h
1/*
2 * Copyright (c) 2015 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16// -----------------------------------------------------------------------------
17#ifndef _MBTCPMaster_H_
18#define _MBTCPMaster_H_
19// -----------------------------------------------------------------------------
20#include <ostream>
21#include <string>
22#include <map>
23#include <vector>
24#include <memory>
25#include "MBExchange.h"
26#include "modbus/ModbusTCPMaster.h"
27// -------------------------------------------------------------------------
28namespace uniset
29{
30 // -----------------------------------------------------------------------------
240 // -----------------------------------------------------------------------------
250 class MBTCPMaster:
251 public MBExchange
252 {
253 public:
254 MBTCPMaster( uniset::ObjectId objId, xmlNode* confnode,
255 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
256 const std::string& prefix = "mbtcp" );
257 virtual ~MBTCPMaster();
258
260 static std::shared_ptr<MBTCPMaster> init_mbmaster( int argc, const char* const* argv,
261 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
262 const std::string& prefix = "mbtcp" );
263
264 static void help_print( int argc, const char* const* argv );
265
266 virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
267
268 protected:
269 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
270 virtual std::shared_ptr<ModbusClient> initMB( bool reopen = false ) override;
271 virtual bool deactivateObject() override;
272 virtual bool reconfigure( const std::shared_ptr<uniset::UniXML>& xml, const std::shared_ptr<uniset::MBConfig>& mbconf ) override;
273
274 std::string iaddr;
275 int port;
276
277 void poll_thread();
278 void final_thread();
279 bool force_disconnect;
280
281 private:
282 MBTCPMaster();
283
284 std::shared_ptr<ModbusTCPMaster> mbtcp;
285
286 // т.к. TCP может "зависнуть" на подключении к недоступному узлу
287 // делаем опрос в отдельном потоке
288 std::unique_ptr<ThreadCreator<MBTCPMaster>> pollThread;
289 };
290 // --------------------------------------------------------------------------
291} // end of namespace uniset
292// -----------------------------------------------------------------------------
293#endif // _MBTCPMaster_H_
294// -----------------------------------------------------------------------------
static std::shared_ptr< MBTCPMaster > init_mbmaster(int argc, const char *const *argv, uniset::ObjectId shmID, const std::shared_ptr< SharedMemory > &ic=nullptr, const std::string &prefix="mbtcp")
Определения MBTCPMaster.cc:211
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы).
Определения MBTCPMaster.cc:185
Определения MessageType.h:171
Определения Calibration.h:27
long ObjectId
Определения UniSetTypes_i.idl:30
Определения UniSetTypes_i.idl:65