UniSet  2.6.0
RTUStorage.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 _RTUSTORAGE_H_
00018 #define _RTUSTORAGE_H_
00019 // -----------------------------------------------------------------------------
00020 #include <ostream>
00021 #include <string>
00022 #include <memory>
00023 #include "modbus/ModbusTypes.h"
00024 #include "UniSetTypes.h"
00025 // --------------------------------------------------------------------------
00026 namespace uniset
00027 {
00028 // -----------------------------------------------------------------------------
00029 class ModbusRTUMaster;
00030 // -----------------------------------------------------------------------------
00031 class RTUStorage
00032 {
00033     public:
00034         explicit RTUStorage( ModbusRTU::ModbusAddr addr );
00035         ~RTUStorage();
00036 
00037         void poll( const std::shared_ptr<ModbusRTUMaster>& mb )
00038         throw(ModbusRTU::mbException);
00039 
00040         inline ModbusRTU::ModbusAddr getAddress()
00041         {
00042             return addr;
00043         }
00044         inline bool ping()
00045         {
00046             return pingOK;
00047         }
00048 
00049         inline void setPollADC( bool set )
00050         {
00051             pollADC = set;
00052         }
00053         inline void setPollDI( bool set )
00054         {
00055             pollDI = set;
00056         }
00057         inline void setPollDIO( bool set )
00058         {
00059             pollDIO = set;
00060         }
00061         inline void setPollUNIO( bool set )
00062         {
00063             pollUNIO = set;
00064         }
00065 
00066         enum RTUJack
00067         {
00068             nUnknown,
00069             nJ1,    // UNIO48 (FPGA0)
00070             nJ2,    // UNIO48 (FPGA1)
00071             nJ5,    // DIO 16
00072             nX1,    // АЦП (8)
00073             nX2,    // АЦП (8)
00074             nX4,    // DI (8)
00075             nX5        // DI (8)
00076         };
00077 
00078         static RTUJack s2j( const std::string& jack );
00079         static std::string j2s( RTUJack j );
00080 
00081         long getInt( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
00082         float getFloat( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
00083         bool getState( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
00084 
00085         static ModbusRTU::ModbusData getRegister( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
00086 
00087         static ModbusRTU::SlaveFunctionCode getFunction( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
00088 
00089         // ДОДЕЛАТЬ: setState, setValue
00090         void print();
00091 
00092         friend std::ostream& operator<<(std::ostream& os, RTUStorage& m );
00093         friend std::ostream& operator<<(std::ostream& os, RTUStorage* m );
00094 
00095     protected:
00096         ModbusRTU::ModbusAddr addr;
00097         bool pingOK;
00098 
00099         bool pollADC;
00100         bool pollDI;
00101         bool pollDIO;
00102         bool pollUNIO;
00103 
00104 
00105         float adc[8];         // АЦП
00106         bool di[16];         // Порт 16DI
00107         bool dio_do[16];     // Порт 16DIO DO
00108         bool dio_di[16];     // Порт 16DIO DI
00109         float dio_ai[16];     // Порт 16DIO AI
00110         float dio_ao[16];     // Порт 16DIO AO
00111         bool unio_do[48];     // Порт UNIO48 DO
00112         bool unio_di[48];     // Порт UNIO48 DI
00113         float unio_ai[24];     // Порт UNIO48 AI
00114         float unio_ao[24];     // Порт UNIO48 AO
00115 };
00116 // --------------------------------------------------------------------------
00117 } // end of namespace uniset
00118 // --------------------------------------------------------------------------
00119 #endif // _RTUSTORAGE_H_
00120 // -----------------------------------------------------------------------------