-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzwave_processor.h
More file actions
94 lines (72 loc) · 2.44 KB
/
zwave_processor.h
File metadata and controls
94 lines (72 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef ZWAVE_PROCESSOR_H_
#define ZWAVE_PROCESSOR_H_
#include <condition_variable>
#include <cstdint>
#include <functional>
#include <list>
#include <mutex>
#include <queue>
#include <set>
#include <thread>
#include "Driver.h"
#include "Group.h"
#include "Manager.h"
#include "Node.h"
#include "Notification.h"
#include "Options.h"
#include "platform/Log.h"
namespace zwave_app {
class ZWaveProcessor {
public:
// Provide path to zwave dongle, i.e. "/dev/ttyACM0"
ZWaveProcessor(const std::string &zwave_dongle_dev_path);
// Main thread loop. From main, create a ZWaveProcessor and call this method
// in a new thread. It will run forever, or until the user quits.
static void MainThreadFunc(ZWaveProcessor *processor);
// Give the processor a single character command from the keyboard.
void Command(char command);
// This will reset the controller and forget all the nodes that have
// joined the network.
void ResetNetwork();
// Calling AddNewNode starts the inclusion process, i.e. adding a new node.
void StartInclusion();
// Turns on or off a power switch node.
void TurnOnSwitchNode(uint8_t node_id, bool value);
// Returns set of unique node ids for paired switches.
std::set<uint8_t> GetNodeSwitchIds() const;
// Register a callback for when a new node is added.
void SetOnAddNodeCallback(std::function<void()> on_add_node_callback) {
on_add_node_callback_ = on_add_node_callback;
}
private:
struct NodeInfo {
uint32_t home_id;
uint8_t node_id;
bool polled;
std::list<OpenZWave::ValueID> values;
};
// Callback from the zwave library.
static void NotificationFunc(OpenZWave::Notification const *notification,
void *context);
void OnNotification(OpenZWave::Notification const *notification);
// Proccess the next command.
void DoNextCommand();
// Exit condition checked by thread loop.
bool IsExit();
// Prints out list of home ids and nodes.
void QueryHomeIds();
NodeInfo *GetNodeInfo(OpenZWave::Notification const *notification) const;
NodeInfo *GetNodeInfo(int nodeId) const;
std::function<void()> on_add_node_callback_;
uint32_t home_id_;
bool init_failed_ = false;
std::list<NodeInfo *> nodes_;
std::string zwave_dongle_dev_path_;
int port_;
std::mutex command_mutex_;
std::condition_variable command_condition_;
std::queue<char> command_queue_;
bool is_exit_ = false;
};
} // namespace zwave_app
#endif // ZWAVE_PROCESSOR_H_