UniSet  2.6.0
RTUStorage.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 _RTUSTORAGE_H_
18 #define _RTUSTORAGE_H_
19 // -----------------------------------------------------------------------------
20 #include <ostream>
21 #include <string>
22 #include <memory>
23 #include "modbus/ModbusTypes.h"
24 #include "UniSetTypes.h"
25 // --------------------------------------------------------------------------
26 namespace uniset
27 {
28  // -----------------------------------------------------------------------------
29  class ModbusRTUMaster;
30  // -----------------------------------------------------------------------------
31  class RTUStorage
32  {
33  public:
34  explicit RTUStorage( ModbusRTU::ModbusAddr addr );
35  ~RTUStorage();
36 
37  void poll( const std::shared_ptr<ModbusRTUMaster>& mb )
39 
40  inline ModbusRTU::ModbusAddr getAddress()
41  {
42  return addr;
43  }
44  inline bool ping()
45  {
46  return pingOK;
47  }
48 
49  inline void setPollADC( bool set )
50  {
51  pollADC = set;
52  }
53  inline void setPollDI( bool set )
54  {
55  pollDI = set;
56  }
57  inline void setPollDIO( bool set )
58  {
59  pollDIO = set;
60  }
61  inline void setPollUNIO( bool set )
62  {
63  pollUNIO = set;
64  }
65 
66  enum RTUJack
67  {
68  nUnknown,
69  nJ1, // UNIO48 (FPGA0)
70  nJ2, // UNIO48 (FPGA1)
71  nJ5, // DIO 16
72  nX1, // АЦП (8)
73  nX2, // АЦП (8)
74  nX4, // DI (8)
75  nX5 // DI (8)
76  };
77 
78  static RTUJack s2j( const std::string& jack );
79  static std::string j2s( RTUJack j );
80 
81  long getInt( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
82  float getFloat( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
83  bool getState( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
84 
85  static ModbusRTU::ModbusData getRegister( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
86 
87  static ModbusRTU::SlaveFunctionCode getFunction( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
88 
89  // ДОДЕЛАТЬ: setState, setValue
90  void print();
91 
92  friend std::ostream& operator<<(std::ostream& os, RTUStorage& m );
93  friend std::ostream& operator<<(std::ostream& os, RTUStorage* m );
94 
95  protected:
96  ModbusRTU::ModbusAddr addr;
97  bool pingOK;
98 
99  bool pollADC;
100  bool pollDI;
101  bool pollDIO;
102  bool pollUNIO;
103 
104 
105  float adc[8]; // АЦП
106  bool di[16]; // Порт 16DI
107  bool dio_do[16]; // Порт 16DIO DO
108  bool dio_di[16]; // Порт 16DIO DI
109  float dio_ai[16]; // Порт 16DIO AI
110  float dio_ao[16]; // Порт 16DIO AO
111  bool unio_do[48]; // Порт UNIO48 DO
112  bool unio_di[48]; // Порт UNIO48 DI
113  float unio_ai[24]; // Порт UNIO48 AI
114  float unio_ao[24]; // Порт UNIO48 AO
115  };
116  // --------------------------------------------------------------------------
117 } // end of namespace uniset
118 // --------------------------------------------------------------------------
119 #endif // _RTUSTORAGE_H_
120 // -----------------------------------------------------------------------------