UniSet @VERSION@
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 // -----------------------------------------------------------------------------
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#ifndef DISABLE_REST_API
272 virtual Poco::JSON::Object::Ptr httpGetMyInfo( Poco::JSON::Object::Ptr root ) override;
273#endif
274 virtual bool deactivateObject() override;
275 virtual bool reconfigure( const std::shared_ptr<uniset::UniXML>& xml, const std::shared_ptr<uniset::MBConfig>& mbconf ) override;
276
277 std::string iaddr;
278 int port;
279
280 void poll_thread();
281 void final_thread();
282 bool force_disconnect;
283
284 private:
285 MBTCPMaster();
286
287 std::shared_ptr<ModbusTCPMaster> mbtcp;
288
289 // т.к. TCP может "зависнуть" на подключении к недоступному узлу
290 // делаем опрос в отдельном потоке
291 std::unique_ptr<ThreadCreator<MBTCPMaster>> pollThread;
292 };
293 // --------------------------------------------------------------------------
294} // end of namespace uniset
295// -----------------------------------------------------------------------------
296#endif // _MBTCPMaster_H_
297// -----------------------------------------------------------------------------
Definition MBExchange.h:60
Definition MBTCPMaster.h:252
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")
Definition MBTCPMaster.cc:212
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
Definition MBTCPMaster.cc:186
Definition MessageType.h:171
Definition AccessConfig.h:30
long ObjectId
Definition UniSetTypes_i.idl:30
Definition UniSetTypes_i.idl:65