UniSet  2.6.0
RTUExchange.h
00001 /*
00002  * Copyright (c) 2015 Pavel Vainerman.
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as
00006  * published by the Free Software Foundation, version 2.1.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00011  * Lesser General Lesser Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00015  */
00016 // -----------------------------------------------------------------------------
00017 #ifndef _RTUEXCHANGE_H_
00018 #define _RTUEXCHANGE_H_
00019 // -----------------------------------------------------------------------------
00020 #include <ostream>
00021 #include <string>
00022 #include <map>
00023 #include <vector>
00024 #include "MBExchange.h"
00025 #include "modbus/ModbusRTUMaster.h"
00026 #include "RTUStorage.h"
00027 // --------------------------------------------------------------------------
00028 namespace uniset
00029 {
00030 // -----------------------------------------------------------------------------
00031 class RTUExchange:
00032     public MBExchange
00033 {
00034     public:
00035         RTUExchange( uniset::ObjectId objId, uniset::ObjectId shmID,
00036                      const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "rs" );
00037         virtual ~RTUExchange();
00038 
00040         static std::shared_ptr<RTUExchange> init_rtuexchange( int argc, const char* const* argv,
00041                 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
00042                 const std::string& prefix = "rs" );
00043 
00045         static void help_print( int argc, const char* const* argv );
00046 
00047     protected:
00048         std::shared_ptr<ModbusRTUMaster> mbrtu;
00049         std::mutex mbMutex;
00050         std::string devname;
00051         ComPort::Speed defSpeed;
00052         bool use485F;
00053         bool transmitCtl;
00054 
00055         virtual void step() override;
00056         virtual bool poll() override;
00057 
00058         virtual std::shared_ptr<ModbusClient> initMB( bool reopen = false ) override;
00059         virtual bool initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniXML::iterator& it ) override;
00060 
00061     private:
00062         RTUExchange();
00063 
00064         bool rs_pre_clean;
00065 };
00066 // --------------------------------------------------------------------------
00067 } // end of namespace uniset
00068 // -----------------------------------------------------------------------------
00069 #endif // _RS_EXCHANGE_H_
00070 // -----------------------------------------------------------------------------