upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
t3311.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 
28 #include <modbus/modbus.h>
29 
30 namespace upm {
31 
63  class T3311 {
64  public:
65 
66  // MODBUS input registers
67  typedef enum {
68  REG_TEMPERATURE = 0x0030,
69  REG_HUMIDITY = 0x0031,
70 
71  // This value is configured in the device itself. By default,
72  // it represents the Dew Point Temperature. Use the
73  // configuration utility from Comet to adjust the configuration.
74  REG_COMPUTED = 0x0032,
75 
76  // available in devices with FW > 2.44
77  REG_DEW_POINT = 0x0034,
78  REG_ABS_HUMIDITY = 0x0035,
79  REG_SPECIFIC_HUMIDITY = 0x0036,
80  REG_MIXING_RATIO = 0x0037,
81  REG_SPECIFIC_ENTHALPY = 0x0038,
82 
83  // 32 bit serial number. These appear to be reversed when
84  // comparing against the TSensor config utility, so the
85  // datasheet is probably wrong.
86  REG_SERIAL_HI = 0x1034,
87  REG_SERIAL_LO = 0x1035,
88 
89  // this is 'somewhat' documented (middle of page 15 in the
90  // Advantech-ADAM standard section) in the "Description of
91  // communications protocols of TXXXX series" document. We use
92  // it to simply detect whether the device is configured for
93  // Celcius or Fahrenheit data and compensate internally.
94 
95  REG_UNIT_SETTINGS = 0x203F,
96 
97  // firmware revision, BCD byte encoded. We only care about the
98  // LO word - the HI word just contains the manufacturing date.
99  REG_FW_HI = 0x3000,
100  REG_FW_LO = 0x3001
101  } REGS_T;
102 
103 
115  T3311(std::string device, int address, int baud=9600, int bits=8,
116  char parity='N', int stopBits=2);
117 
121  ~T3311();
122 
131  {
132  return m_isExtendedDataAvailable;
133  };
134 
140  void update();
141 
151  float getTemperature(bool fahrenheit=false);
152 
159  float getHumidity();
160 
177  float getComputedValue();
178 
191  float getDewPointTemperature(bool fahrenheit=false);
192 
202  float getAbsoluteHumidity();
203 
213  float getSpecificHumidity();
214 
224  float getMixingRatio();
225 
236  float getSpecificEnthalpy();
237 
243  std::string getSerialNumber()
244  {
245  return m_serialNumber;
246  };
247 
254  {
255  return m_fwRevHi;
256  };
257 
264  {
265  return m_fwRevLo;
266  };
267 
274  void setDebug(bool enable);
275 
276  protected:
277  uint16_t readInputReg(int reg);
278  int readInputRegs(int reg, int len, uint16_t *buf);
279 
280  // MODBUS context
281  modbus_t *m_mbContext;
282 
283  // is the device reporting in C or F?
284  bool m_isCelcius;
285 
286  // Is the device FW > than 2.44?
287  bool m_isExtendedDataAvailable;
288 
289  int m_fwRevHi;
290  int m_fwRevLo;
291 
292  std::string m_serialNumber;
293 
294  private:
295  bool m_debugging;
296 
297  // data
298  float m_temperature;
299  float m_humidity; // relative
300  float m_computedValue;
301 
302  // with FW versions > 2.44, these other computed values are
303  // available.
304  float m_dewPointTemperature;
305  float m_absoluteHumidity;
306  float m_specificHumidity;
307  float m_mixingRatio;
308  float m_specificEnthalpy;
309  };
310 }
float getSpecificEnthalpy()
Definition: t3311.cxx:296
void update()
Definition: t3311.cxx:214
float getMixingRatio()
Definition: t3311.cxx:291
std::string getSerialNumber()
Definition: t3311.h:243
bool extendedDataAvailable()
Definition: t3311.h:130
float getDewPointTemperature(bool fahrenheit=false)
Definition: t3311.cxx:273
float getAbsoluteHumidity()
Definition: t3311.cxx:281
~T3311()
Definition: t3311.cxx:179
void setDebug(bool enable)
Definition: t3311.cxx:301
float getComputedValue()
Definition: t3311.cxx:268
int getFirmwareMajor()
Definition: t3311.h:253
UPM API for the T3311 MODBUS Temperature and Humidity Sensor.
Definition: t3311.h:63
float getHumidity()
Definition: t3311.cxx:263
float getSpecificHumidity()
Definition: t3311.cxx:286
int getFirmwareMinor()
Definition: t3311.h:263
T3311(std::string device, int address, int baud=9600, int bits=8, char parity='N', int stopBits=2)
Definition: t3311.cxx:55
float getTemperature(bool fahrenheit=false)
Definition: t3311.cxx:255