upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
ozw.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015-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 "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 
92  // forward declaration of private zwNode data
93  class zwNode;
94 
95  class OZW {
96  public:
97 
98  typedef std::map<uint8_t, zwNode *> zwNodeMap_t;
99 
107  static OZW* instance();
108 
123  void optionsCreate(std::string configPath="/etc/openzwave",
124  std::string userConfigDir="",
125  std::string cmdLine="");
126 
134  void optionAddInt(std::string name, int val);
135 
143  void optionAddBool(std::string name, bool val);
144 
153  void optionAddString(std::string name, std::string val, bool append);
154 
162  void optionsLock();
163 
185  bool init(std::string devicePath, bool isHID=false);
186 
199  void dumpNodes(bool all=false);
200 
210  std::string getValueUnits(int nodeId, int index);
211 
219  void setValueUnits(int nodeId, int index, std::string text);
220 
229  std::string getValueLabel(int nodeId, int index);
230 
238  void setValueLabel(int nodeId, int index, std::string text);
239 
248  std::string getValueHelp(int nodeId, int index);
249 
257  void setValueHelp(int nodeId, int index, std::string text);
258 
269  void setValueAsString(int nodeId, int index, std::string val);
270 
280  void setValueAsBool(int nodeId, int index, bool val);
281 
291  void setValueAsByte(int nodeId, int index, uint8_t val);
292 
302  void setValueAsFloat(int nodeId, int index, float val);
303 
314  void setValueAsInt32(int nodeId, int index, int32_t val);
315 
326  void setValueAsInt16(int nodeId, int index, int16_t val);
327 
339  void setValueAsBytes(int nodeId, int index, uint8_t *val, uint8_t len);
340 
348  int getValueMin(int nodeId, int index);
349 
357  int getValueMax(int nodeId, int index);
358 
366  bool isValueReadOnly(int nodeId, int index);
367 
375  bool isValueWriteOnly(int nodeId, int index);
376 
386  bool isValueSet(int nodeId, int index);
387 
400  bool isValuePolled(int nodeId, int index);
401 
410  std::string getValueAsString(int nodeId, int index);
411 
420  bool getValueAsBool(int nodeId, int index);
421 
430  uint8_t getValueAsByte(int nodeId, int index);
431 
441  float getValueAsFloat(int nodeId, int index);
442 
451  int getValueAsInt32(int nodeId, int index);
452 
461  int getValueAsInt16(int nodeId, int index);
462 
476  void refreshValue(int nodeId, int index);
477 
485  void setDebug(bool enable);
486 
494  bool isNodeListeningDevice(int nodeId);
495 
504  bool isNodeFrequentListeningDevice(int nodeId);
505 
512  bool isNodeAwake(int nodeId);
513 
521  bool isNodeInfoReceived(int nodeId);
522 
529  {
530  return m_initialized;
531  }
532 
533  protected:
537  OZW();
538 
542  ~OZW();
543 
553  bool getValueID(int nodeId, int index, OpenZWave::ValueID *vid);
554 
560  uint32_t getHomeID()
561  {
562  return m_homeId;
563  }
564 
570  void lockNodes() { pthread_mutex_lock(&m_nodeLock); };
571 
575  void unlockNodes() { pthread_mutex_unlock(&m_nodeLock); };
576 
577  private:
578  // prevent copying and assignment
579  OZW(OZW const &) = delete;
580  OZW& operator=(OZW const&) = delete;
581 
582  // our class instance
583  static OZW* m_instance;
584 
585  uint32_t m_homeId;
586  bool m_mgrCreated;
587  bool m_driverFailed;
588  bool m_debugging;
589  bool m_initialized;
590 
591  bool m_driverIsHID;
592  std::string m_devicePath;
593 
594  // our notification handler, called by OpenZWave for events on the
595  // network.
596  static void notificationHandler(OpenZWave::Notification
597  const* notification,
598  void *ctx);
599 
600  // a map of added nodes
601  zwNodeMap_t m_zwNodeMap;
602 
603  // for coordinating access to the node list
604  pthread_mutex_t m_nodeLock;
605 
606  // We use these to determine init failure or success (if OpenZWave
607  // has successfully queried essential data about the network).
608  pthread_mutex_t m_initLock;
609  pthread_cond_t m_initCond;
610  };
611 }
612 
613 
void optionAddBool(std::string name, bool val)
Definition: ozw.cxx:136
uint8_t getValueAsByte(int nodeId, int index)
Definition: ozw.cxx:832
void setValueAsInt32(int nodeId, int index, int32_t val)
Definition: ozw.cxx:612
void optionsCreate(std::string configPath="/etc/openzwave", std::string userConfigDir="", std::string cmdLine="")
Definition: ozw.cxx:123
bool getValueID(int nodeId, int index, OpenZWave::ValueID *vid)
Definition: ozw.cxx:407
void setValueAsBytes(int nodeId, int index, uint8_t *val, uint8_t len)
Definition: ozw.cxx:660
int getValueMin(int nodeId, int index)
Definition: ozw.cxx:721
OZW()
Definition: ozw.cxx:44
bool getValueAsBool(int nodeId, int index)
Definition: ozw.cxx:805
void setDebug(bool enable)
Definition: ozw.cxx:988
bool isValueSet(int nodeId, int index)
Definition: ozw.cxx:777
void setValueAsBool(int nodeId, int index, bool val)
Definition: ozw.cxx:540
bool init(std::string devicePath, bool isHID=false)
Definition: ozw.cxx:155
bool isValuePolled(int nodeId, int index)
Definition: ozw.cxx:791
bool isNodeFrequentListeningDevice(int nodeId)
Definition: ozw.cxx:952
std::string getValueAsString(int nodeId, int index)
Definition: ozw.cxx:442
void setValueAsInt16(int nodeId, int index, int16_t val)
Definition: ozw.cxx:636
void unlockNodes()
Definition: ozw.hpp:575
~OZW()
Definition: ozw.cxx:80
float getValueAsFloat(int nodeId, int index)
Definition: ozw.cxx:859
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
bool isNodeAwake(int nodeId)
Definition: ozw.cxx:964
void setValueHelp(int nodeId, int index, std::string text)
Definition: ozw.cxx:528
void setValueAsFloat(int nodeId, int index, float val)
Definition: ozw.cxx:588
void setValueUnits(int nodeId, int index, std::string text)
Definition: ozw.cxx:474
bool isNodeListeningDevice(int nodeId)
Definition: ozw.cxx:940
void optionsLock()
Definition: ozw.cxx:148
int getValueAsInt16(int nodeId, int index)
Definition: ozw.cxx:913
std::string getValueHelp(int nodeId, int index)
Definition: ozw.cxx:513
void optionAddString(std::string name, std::string val, bool append)
Definition: ozw.cxx:142
Definition: ozw.hpp:95
int getValueAsInt32(int nodeId, int index)
Definition: ozw.cxx:886
bool isValueReadOnly(int nodeId, int index)
Definition: ozw.cxx:749
void setValueAsString(int nodeId, int index, std::string val)
Definition: ozw.cxx:684
void setValueLabel(int nodeId, int index, std::string text)
Definition: ozw.cxx:501
void refreshValue(int nodeId, int index)
Definition: ozw.cxx:709
bool isInitialized()
Definition: ozw.hpp:528
std::string getValueLabel(int nodeId, int index)
Definition: ozw.cxx:486
void lockNodes()
Definition: ozw.hpp:570
static OZW * instance()
Definition: ozw.cxx:115
int getValueMax(int nodeId, int index)
Definition: ozw.cxx:735
std::string getValueUnits(int nodeId, int index)
Definition: ozw.cxx:459
void optionAddInt(std::string name, int val)
Definition: ozw.cxx:130
void dumpNodes(bool all=false)
Definition: ozw.cxx:349
uint32_t getHomeID()
Definition: ozw.hpp:560
void setValueAsByte(int nodeId, int index, uint8_t val)
Definition: ozw.cxx:564
bool isValueWriteOnly(int nodeId, int index)
Definition: ozw.cxx:763
bool isNodeInfoReceived(int nodeId)
Definition: ozw.cxx:976