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