UniSet  2.7.0
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 // -------------------------------------------------------------------------
28 namespace uniset
29 {
30  // -----------------------------------------------------------------------------
238  // -----------------------------------------------------------------------------
248  class MBTCPMaster:
249  public MBExchange
250  {
251  public:
252  MBTCPMaster( uniset::ObjectId objId, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
253  const std::string& prefix = "mbtcp" );
254  virtual ~MBTCPMaster();
255 
257  static std::shared_ptr<MBTCPMaster> init_mbmaster( int argc, const char* const* argv,
258  uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
259  const std::string& prefix = "mbtcp" );
260 
261  static void help_print( int argc, const char* const* argv );
262 
263  virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
264 
265  protected:
266  virtual void sysCommand( const uniset::SystemMessage* sm ) override;
267  virtual std::shared_ptr<ModbusClient> initMB( bool reopen = false ) override;
268  virtual bool deactivateObject() override;
269 
270  std::string iaddr;
271  int port;
272 
273  void poll_thread();
274  void final_thread();
275  bool force_disconnect;
276 
277  private:
278  MBTCPMaster();
279 
280  std::shared_ptr<ModbusTCPMaster> mbtcp;
281 
282  // т.к. TCP может "зависнуть" на подключении к недоступному узлу
283  // делаем опрос в отдельном потоке
284  std::unique_ptr<ThreadCreator<MBTCPMaster>> pollThread;
285  };
286  // --------------------------------------------------------------------------
287 } // end of namespace uniset
288 // -----------------------------------------------------------------------------
289 #endif // _MBTCPMaster_H_
290 // -----------------------------------------------------------------------------
Definition: MBExchange.h:55
Definition: CallbackTimer.h:29
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:217
Definition: MessageType.h:168
virtual bool deactivateObject() override
Деактивиция объекта (переопределяется для необходимых действий при завершении работы) ...
Definition: MBTCPMaster.cc:191
Definition: MBTCPMaster.h:248
Definition: UniSetTypes_i.idl:64
long ObjectId
Definition: UniSetTypes_i.idl:30