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