UniSet 2.32.1
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 // -----------------------------------------------------------------------------
254 // -----------------------------------------------------------------------------
265 public MBExchange
266 {
267 public:
268 MBTCPMaster( uniset::ObjectId objId, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
269 const std::string& prefix = "mbtcp" );
270 virtual ~MBTCPMaster();
271
273 static std::shared_ptr<MBTCPMaster> init_mbmaster( int argc, const char* const* argv,
274 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
275 const std::string& prefix = "mbtcp" );
276
277 static void help_print( int argc, const char* const* argv );
278
279 virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
280
281 protected:
282 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
283 virtual std::shared_ptr<ModbusClient> initMB( bool reopen = false ) override;
284 virtual bool deactivateObject() override;
285 virtual bool reconfigure( const std::shared_ptr<uniset::UniXML>& xml, const std::shared_ptr<uniset::MBConfig>& mbconf ) override;
286
287 std::string iaddr;
288 int port;
289
290 void poll_thread();
291 void final_thread();
292 bool force_disconnect;
293
294 private:
295 MBTCPMaster();
296
297 std::shared_ptr<ModbusTCPMaster> mbtcp;
298
299 // т.к. TCP может "зависнуть" на подключении к недоступному узлу
300 // делаем опрос в отдельном потоке
301 std::unique_ptr<ThreadCreator<MBTCPMaster>> pollThread;
302 };
303 // --------------------------------------------------------------------------
304} // end of namespace uniset
305// -----------------------------------------------------------------------------
306#endif // _MBTCPMaster_H_
307// -----------------------------------------------------------------------------
Definition MBExchange.h:58
Definition MBTCPMaster.h:266
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:210
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
Definition MBTCPMaster.cc:184
Definition MessageType.h:171
Definition Calibration.h:27
long ObjectId
Definition UniSetTypes_i.idl:30
Definition UniSetTypes_i.idl:65