upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
ozw.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 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 "Manager.h"
30 #include "Notification.h"
31 #include "Options.h"
32 #include "Driver.h"
33 #include "Node.h"
34 #include "Group.h"
35 #include "platform/Log.h"
36 
37 namespace upm {
38 
99  // forward declaration of private zwNode data
100  class zwNode;
101 
102  class OZW {
103  public:
104 
105  typedef std::map<uint8_t, zwNode *> zwNodeMap_t;
106 
110  OZW();
111 
115  ~OZW();
116 
131  void optionsCreate(std::string configPath="/etc/openzwave",
132  std::string userConfigDir="",
133  std::string cmdLine="");
134 
142  void optionAddInt(std::string name, int val);
143 
151  void optionAddBool(std::string name, bool val);
152 
161  void optionAddString(std::string name, std::string val, bool append);
162 
170  void optionsLock();
171 
193  bool init(std::string devicePath, bool isHID=false);
194 
207  void dumpNodes(bool all=false);
208 
218  std::string getValueUnits(int nodeId, int index);
219 
227  void setValueUnits(int nodeId, int index, std::string text);
228 
237  std::string getValueLabel(int nodeId, int index);
238 
246  void setValueLabel(int nodeId, int index, std::string text);
247 
256  std::string getValueHelp(int nodeId, int index);
257 
265  void setValueHelp(int nodeId, int index, std::string text);
266 
277  void setValueAsString(int nodeId, int index, std::string val);
278 
288  void setValueAsBool(int nodeId, int index, bool val);
289 
299  void setValueAsByte(int nodeId, int index, uint8_t val);
300 
310  void setValueAsFloat(int nodeId, int index, float val);
311 
322  void setValueAsInt32(int nodeId, int index, int32_t val);
323 
334  void setValueAsInt16(int nodeId, int index, int16_t val);
335 
347  void setValueAsBytes(int nodeId, int index, uint8_t *val, uint8_t len);
348 
356  int getValueMin(int nodeId, int index);
357 
365  int getValueMax(int nodeId, int index);
366 
374  bool isValueReadOnly(int nodeId, int index);
375 
383  bool isValueWriteOnly(int nodeId, int index);
384 
394  bool isValueSet(int nodeId, int index);
395 
408  bool isValuePolled(int nodeId, int index);
409 
418  std::string getValueAsString(int nodeId, int index);
419 
428  bool getValueAsBool(int nodeId, int index);
429 
438  uint8_t getValueAsByte(int nodeId, int index);
439 
449  float getValueAsFloat(int nodeId, int index);
450 
459  int getValueAsInt32(int nodeId, int index);
460 
469  int getValueAsInt16(int nodeId, int index);
470 
484  void refreshValue(int nodeId, int index);
485 
493  void setDebug(bool enable);
494 
502  bool isNodeListeningDevice(int nodeId);
503 
512  bool isNodeFrequentListeningDevice(int nodeId);
513 
520  bool isNodeAwake(int nodeId);
521 
522  protected:
532  bool getValueID(int nodeId, int index, OpenZWave::ValueID *vid);
533 
540  void lockNodes() { pthread_mutex_lock(&m_nodeLock); };
544  void unlockNodes() { pthread_mutex_unlock(&m_nodeLock); };
545 
546  private:
547  uint32_t m_homeId;
548  bool m_mgrCreated;
549  bool m_driverFailed;
550  bool m_debugging;
551 
552  bool m_driverIsHID;
553  std::string m_devicePath;
554 
555  // our notification handler, called by OpenZWave for events on the
556  // network.
557  static void notificationHandler(OpenZWave::Notification
558  const* notification,
559  void *ctx);
560 
561  // a map of added nodes
562  zwNodeMap_t m_zwNodeMap;
563 
564  // for coordinating access to the node list
565  pthread_mutex_t m_nodeLock;
566 
567  // We use these to determine init failure or success (if OpenZWave
568  // has successfully queried essential data about the network).
569  pthread_mutex_t m_initLock;
570  pthread_cond_t m_initCond;
571  };
572 }
573 
574 
void optionAddBool(std::string name, bool val)
Definition: ozw.cxx:123
uint8_t getValueAsByte(int nodeId, int index)
Definition: ozw.cxx:757
void setValueAsInt32(int nodeId, int index, int32_t val)
Definition: ozw.cxx:537
void optionsCreate(std::string configPath="/etc/openzwave", std::string userConfigDir="", std::string cmdLine="")
Definition: ozw.cxx:111
bool getValueID(int nodeId, int index, OpenZWave::ValueID *vid)
Definition: ozw.cxx:332
void setValueAsBytes(int nodeId, int index, uint8_t *val, uint8_t len)
Definition: ozw.cxx:585
int getValueMin(int nodeId, int index)
Definition: ozw.cxx:646
OZW()
Definition: ozw.cxx:42
bool getValueAsBool(int nodeId, int index)
Definition: ozw.cxx:730
void setDebug(bool enable)
Definition: ozw.cxx:901
bool isValueSet(int nodeId, int index)
Definition: ozw.cxx:702
void setValueAsBool(int nodeId, int index, bool val)
Definition: ozw.cxx:465
bool init(std::string devicePath, bool isHID=false)
Definition: ozw.cxx:140
bool isValuePolled(int nodeId, int index)
Definition: ozw.cxx:716
bool isNodeFrequentListeningDevice(int nodeId)
Definition: ozw.cxx:877
std::string getValueAsString(int nodeId, int index)
Definition: ozw.cxx:367
void setValueAsInt16(int nodeId, int index, int16_t val)
Definition: ozw.cxx:561
void unlockNodes()
Definition: ozw.h:544
~OZW()
Definition: ozw.cxx:76
float getValueAsFloat(int nodeId, int index)
Definition: ozw.cxx:784
Definition: a110x.h:33
bool isNodeAwake(int nodeId)
Definition: ozw.cxx:889
void setValueHelp(int nodeId, int index, std::string text)
Definition: ozw.cxx:453
void setValueAsFloat(int nodeId, int index, float val)
Definition: ozw.cxx:513
void setValueUnits(int nodeId, int index, std::string text)
Definition: ozw.cxx:399
bool isNodeListeningDevice(int nodeId)
Definition: ozw.cxx:865
void optionsLock()
Definition: ozw.cxx:133
int getValueAsInt16(int nodeId, int index)
Definition: ozw.cxx:838
std::string getValueHelp(int nodeId, int index)
Definition: ozw.cxx:438
void optionAddString(std::string name, std::string val, bool append)
Definition: ozw.cxx:128
Definition: ozw.h:102
int getValueAsInt32(int nodeId, int index)
Definition: ozw.cxx:811
bool isValueReadOnly(int nodeId, int index)
Definition: ozw.cxx:674
void setValueAsString(int nodeId, int index, std::string val)
Definition: ozw.cxx:609
void setValueLabel(int nodeId, int index, std::string text)
Definition: ozw.cxx:426
void refreshValue(int nodeId, int index)
Definition: ozw.cxx:634
std::string getValueLabel(int nodeId, int index)
Definition: ozw.cxx:411
void lockNodes()
Definition: ozw.h:540
int getValueMax(int nodeId, int index)
Definition: ozw.cxx:660
std::string getValueUnits(int nodeId, int index)
Definition: ozw.cxx:384
void optionAddInt(std::string name, int val)
Definition: ozw.cxx:118
void dumpNodes(bool all=false)
Definition: ozw.cxx:311
void setValueAsByte(int nodeId, int index, uint8_t val)
Definition: ozw.cxx:489
bool isValueWriteOnly(int nodeId, int index)
Definition: ozw.cxx:688