upm  0.7.0
Sensor/Actuator repository for libmraa (v1.0.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
e50hx.hpp
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 #include <map>
28 
29 #include "bacnetmstp.hpp"
30 
31 namespace upm {
32 
84  class E50HX {
85  public:
86 
87  // Supported Analog Value Objects. These are readable and writable.
88  typedef enum : uint32_t {
89  AV_Config = 1, // always returns 0 on read
90  AV_System_Type = 2,
91  AV_CT_Ratio_Primary = 3,
92  AV_CT_Ratio_Secondary = 4,
93  AV_PT_Ratio = 5,
94  AV_System_Voltage = 6,
95  AV_Display_Units = 7,
96  AV_Phase_Loss_Voltage_Threshold = 8,
97  AV_Phase_Loss_Imbalance_Threshold = 9,
98  AV_Subintervals = 10,
99  AV_Subinterval_Length = 11
100  } ANALOG_VALUES_T;
101 
102  // Supported Analog Input Objects. These are read only.
103  typedef enum : uint32_t {
104  AI_Energy = 1,
105  AI_kW_Total = 2,
106  AI_kVAR_Total = 3,
107  AI_kVA_Total = 4,
108  AI_PF_Total = 5,
109  AI_Volts_LL_Avg = 6,
110  AI_Volts_LN_Avg = 7,
111  AI_Current_Avg = 8,
112  AI_kW_A = 9,
113  AI_kW_B = 10,
114  AI_kW_C = 11,
115  AI_PF_A = 12,
116  AI_PF_B = 13,
117  AI_PF_C = 14,
118  AI_Volts_AB = 15,
119  AI_Volts_BC = 16,
120  AI_Volts_AC = 17,
121  AI_Volts_AN = 18,
122  AI_Volts_BN = 19,
123  AI_Volts_CN = 20,
124  AI_Current_A = 21,
125  AI_Current_B = 22,
126  AI_Current_C = 23,
127  // AI24 is reserved
128  AI_Frequency = 25,
129  AI_kVAh = 26, // units = kVAh, not kWH
130  AI_kVARh = 27, // units = kVAh, not kWH
131  AI_kVA_A = 28,
132  AI_kVA_B = 29,
133  AI_kVA_C = 30,
134  AI_kVAR_A = 31,
135  AI_kVAR_B = 32,
136  AI_kVAR_C = 33,
137  AI_KW_Present_Demand = 34,
138  AI_KVAR_Present_Demand = 35,
139  AI_KWA_Present_Demand = 36,
140  AI_KW_Max_Demand = 37,
141  AI_KVAR_Max_Demand = 38,
142  AI_KVA_Max_Demand = 39,
143  AI_Pulse_Count_1 = 40, // H2 & H5
144  // AI41 is reserved on H2 variant
145  AI_Pulse_Count_2 = 41, // only on H5 variant
146  AI_KWH_A = 42,
147  AI_KWH_B = 43,
148  AI_KWH_C = 44,
149  AI_Max_Power = 45, // theoretical max power
150  // AI46 reserved
151  AI_Energy_Resets = 47,
152  // AI48 and AI49 reserved
153  AI_Power_Up_Count = 50,
154  AI_Output_Config = 51, // H2 = 11, H5 = 10
155  AI_Alarm_Bitmap = 52
156  } ANALOG_INPUTS_T;
157 
158  // Alarm bits (AI52)
159  typedef enum : uint16_t {
160  ALARM_Volts_Error_A = 0x0001,
161  ALARM_Volts_Error_B = 0x0002,
162  ALARM_Volts_Error_C = 0x0004,
163 
164  ALARM_Current_Error_A = 0x0008,
165  ALARM_Current_Error_B = 0x0010,
166  ALARM_Current_Error_C = 0x0020,
167 
168  ALARM_Frequency_Error = 0x0040,
169 
170  ALARM_Reserved_0 = 0x0080, // reserved
171 
172  ALARM_Phase_Loss_A = 0x0100,
173  ALARM_Phase_Loss_B = 0x0200,
174  ALARM_Phase_Loss_C = 0x0400,
175 
176  ALARM_Power_Factor_A = 0x0800,
177  ALARM_Power_Factor_B = 0x1000,
178  ALARM_Power_Factor_C = 0x2000,
179 
180  ALARM_RTC_RESET = 0x4000 // H5 only
181  } ALARM_BITS_T;
182 
183  // valid config values to write to AV1
184  typedef enum {
185  CFG_CLR_ENERGY_ACCUM = 30078, // clear energy accumulators
186  CFG_NEW_DSI = 21211, // begin new demand subinterval
187  CFG_RESET_MAX_TO_PRESENT = 21212, // reset max vals to present vals
188  CFG_CLEAR_PULSE_COUNTERS = 16498 // clear the pulse counters
189  } CFG_VALUES_T;
190 
191  // system type configuration
192  typedef enum {
193  SYSTYPE_SINGLE_PHASE_AN = 10,
194  SYSTYPE_SINGLE_PHASE_AB = 11,
195  SYSTYPE_SPLIT_PHASE_ABN = 12,
196  SYSTYPE_3PHASE_ABC = 31,
197  SYSTYPE_3PHASE_ABCN = 40
198  } SYSTEM_TYPES_T;
199 
200  // CT input ratio
201  typedef enum {
202  CT_RATIO_SECONDARY_1 = 1, // CT's w/ 1v outputs
203  CT_RATIO_SECONDARY_3 = 3 // CT's w/ 0.3v outputs
204  } CT_SECONDARY_T;
205 
206  // LCD display units
207  typedef enum {
208  DISP_UNITS_IEC = 0, // IEC display units
209  DISP_UNITS_IEEE = 1 // IEEE display units
210  } DISP_UNITS_T;
211 
212  // Since none of the legal values returned by getAnalogValue() or
213  // getAnalogInput() will ever be negative, we use these two values
214  // to indicate either an error (BACnet or UPM), or to indicate
215  // that the value is unreliable if checkReliability() has been
216  // enabled.
217  const float RETURN_ERROR = -1.0;
218  const float RETURN_UNRELIABLE = -2.0;
219 
232  E50HX(uint32_t targetDeviceObjectID);
233 
237  ~E50HX();
238 
268  void initMaster(std::string port, int baudRate, int deviceInstanceNumber,
269  int macAddr, int maxMaster=DEFAULT_MAX_MASTER,
270  int maxInfoFrames=1);
271 
278  void setDebug(bool enable);
279 
292  float getAnalogValue(ANALOG_VALUES_T objInstance);
293 
306  float getAnalogInput(ANALOG_INPUTS_T objInstance);
307 
317  bool writeConfig(CFG_VALUES_T config);
318 
327  bool writeSystemType(SYSTEM_TYPES_T systype);
328 
336  bool writeCTRatioPrimary(float ctRatio);
337 
345  bool writeCTRatioSecondary(CT_SECONDARY_T ctRatio);
346 
354  bool writePTRatio(float ptRatio);
355 
363  bool writeSystemVoltage(float sysVolts);
364 
372  bool writeDisplayUnits(DISP_UNITS_T dispUnits);
373 
382  bool writePhaseLossVT(float phaseLoss);
383 
392  bool writePhaseLossIT(float phaseLoss);
393 
406  std::string getAnalogValueUnits(ANALOG_VALUES_T objInstance);
407 
420  std::string getAnalogInputUnits(ANALOG_INPUTS_T objInstance);
421 
431  uint16_t getAlarmBits();
432 
456  void checkReliability(bool enable)
457  {
458  m_checkReliability = enable;
459  };
460 
468  std::string getDescription();
469 
477  std::string getLocation();
478 
485  bool setLocation(std::string location);
486 
494  std::string getAllErrorString();
495 
504  BACNETMSTP::BACERR_TYPE_T getErrorType();
505 
511  uint8_t getRejectReason();
512 
518  std::string getRejectString();
519 
525  uint8_t getAbortReason();
526 
532  std::string getAbortString();
533 
539  BACNET_ERROR_CLASS getErrorClass();
540 
546  BACNET_ERROR_CODE getErrorCode();
547 
554  std::string getErrorString();
555 
562  std::string getUPMErrorString();
563 
564  protected:
565  // a copy of the BACNETMSTP singleton instance pointer
566  BACNETMSTP* m_instance;
567 
568  // unique device object ID of e50hx
569  uint32_t m_targetDeviceObjectID;
570 
571  // are we initialized?
572  bool m_initialized;
573 
574  private:
575  bool m_debugging;
576 
577  // whether or not to verify reliability before reading a value.
578  bool m_checkReliability;
579 
580  // Unit cache for AV
581  typedef std::map<ANALOG_VALUES_T, std::string> avCacheMap_t;
582  avCacheMap_t m_avUnitCache;
583 
584  // Unit cache for AI
585  typedef std::map<ANALOG_INPUTS_T, std::string> aiCacheMap_t;
586  aiCacheMap_t m_aiUnitCache;
587  };
588 }
UPM API for BACNETMSTP.
Definition: bacnetmstp.hpp:103
bool writeSystemVoltage(float sysVolts)
Definition: e50hx.cxx:466
UPM API for the Veris E50HX Energy Meter.
Definition: e50hx.hpp:84
std::string getAllErrorString()
Definition: e50hx.cxx:275
~E50HX()
Definition: e50hx.cxx:62
BACNET_ERROR_CLASS getErrorClass()
Definition: e50hx.cxx:254
void checkReliability(bool enable)
Definition: e50hx.hpp:456
void initMaster(std::string port, int baudRate, int deviceInstanceNumber, int macAddr, int maxMaster=DEFAULT_MAX_MASTER, int maxInfoFrames=1)
Definition: e50hx.cxx:66
bool writePhaseLossVT(float phaseLoss)
Definition: e50hx.cxx:514
bool writeDisplayUnits(DISP_UNITS_T dispUnits)
Definition: e50hx.cxx:493
float getAnalogInput(ANALOG_INPUTS_T objInstance)
Definition: e50hx.cxx:159
bool writePTRatio(float ptRatio)
Definition: e50hx.cxx:439
uint8_t getRejectReason()
Definition: e50hx.cxx:234
void setDebug(bool enable)
Definition: e50hx.cxx:85
std::string getAbortString()
Definition: e50hx.cxx:249
bool writeConfig(CFG_VALUES_T config)
Definition: e50hx.cxx:351
BACNETMSTP::BACERR_TYPE_T getErrorType()
Definition: e50hx.cxx:229
std::string getUPMErrorString()
Definition: e50hx.cxx:264
bool writeCTRatioPrimary(float ctRatio)
Definition: e50hx.cxx:391
BACNET_ERROR_CODE getErrorCode()
Definition: e50hx.cxx:259
bool writePhaseLossIT(float phaseLoss)
Definition: e50hx.cxx:541
std::string getErrorString()
Definition: e50hx.cxx:269
std::string getLocation()
Definition: e50hx.cxx:316
bool setLocation(std::string location)
Definition: e50hx.cxx:331
std::string getRejectString()
Definition: e50hx.cxx:239
bool writeSystemType(SYSTEM_TYPES_T systype)
Definition: e50hx.cxx:371
uint16_t getAlarmBits()
Definition: e50hx.cxx:224
std::string getAnalogInputUnits(ANALOG_INPUTS_T objInstance)
Definition: e50hx.cxx:199
bool writeCTRatioSecondary(CT_SECONDARY_T ctRatio)
Definition: e50hx.cxx:418
E50HX(uint32_t targetDeviceObjectID)
Definition: e50hx.cxx:38
std::string getAnalogValueUnits(ANALOG_VALUES_T objInstance)
Definition: e50hx.cxx:134
std::string getDescription()
Definition: e50hx.cxx:301
float getAnalogValue(ANALOG_VALUES_T objInstance)
Definition: e50hx.cxx:93
uint8_t getAbortReason()
Definition: e50hx.cxx:244