Skip to content

Commit 9016928

Browse files
committed
implement new notification types; change ValueID index type
1 parent 88c1e28 commit 9016928

File tree

7 files changed

+116
-33
lines changed

7 files changed

+116
-33
lines changed

binding.gyp

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"OPENZWAVE_DOC=<!@(node -p -e \"'<(OZW_DOC)'.length ? '<(OZW_DOC)' : '/usr/local/share/doc/openzwave'\")",
3030
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)",
3131
"OPENZWAVE_EXCEPTIONS=<!@(find <(OZW_INC) -name OZWException.h | wc -l)",
32-
"OPENZWAVE_BITSET=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)"
32+
"OPENZWAVE_16=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)",
33+
"OPENZWAVE_VALUETYPE_FROM_ENUM=<!@(ldconfig -p | grep 'libopenzwave.so ' | awk '{print $4}' | xargs nm -g --demangle |grep OpenZWave::Value::GetTypeNameFromEnum | wc -l)",
34+
"OPENZWAVE_VALUETYPE_FROM_VALUEID=<!@(ldconfig -p | grep 'libopenzwave.so ' | awk '{print $4}' | xargs nm -g --demangle |grep OpenZWave::ValueID::GetTypeAsString | wc -l)"
3335
],
3436
"cflags": [ "-Wno-ignored-qualifiers -Wno-write-strings -Wno-unknown-pragmas" ],
3537
"link_settings": {
@@ -56,7 +58,7 @@
5658
"OPENZWAVE_DOC=<!@(node -p -e \"'<(OZW_DOC)'.length ? '<(OZW_DOC)' : '/usr/local/share/doc/openzwave'\")",
5759
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)",
5860
"OPENZWAVE_EXCEPTIONS=<!@(find <(OZW_INC) -name OZWException.h | wc -l)",
59-
"OPENZWAVE_BITSET=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)",
61+
"OPENZWAVE_16=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)",
6062
"OPENZWAVE_VALUETYPE_FROM_ENUM=<!@(ldconfig -p | grep 'libopenzwave.so ' | awk '{print $4}' | xargs nm -g --demangle |grep OpenZWave::Value::GetTypeNameFromEnum | wc -l)",
6163
"OPENZWAVE_VALUETYPE_FROM_VALUEID=<!@(ldconfig -p | grep 'libopenzwave.so ' | awk '{print $4}' | xargs nm -g --demangle |grep OpenZWave::ValueID::GetTypeAsString | wc -l)",
6264
],
@@ -90,7 +92,7 @@
9092
"OPENZWAVE_DOC=<!@(<(NODE) -p -e \"'<(OZW_DOC)'.length ? '<(OZW_DOC)' : '/usr/local/share/doc/openzwave'\")",
9193
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)",
9294
"OPENZWAVE_EXCEPTIONS=<!@(find <(OZW_INC) -name OZWException.h | wc -l)",
93-
"OPENZWAVE_BITSET=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)",
95+
"OPENZWAVE_16=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)",
9496
"OPENZWAVE_VALUETYPE_FROM_ENUM=<!@(ldconfig -p | grep 'libopenzwave.so ' | awk '{print $4}' | xargs nm -g --demangle |grep OpenZWave::Value::GetTypeNameFromEnum | wc -l)",
9597
"OPENZWAVE_VALUETYPE_FROM_VALUEID=<!@(ldconfig -p | grep 'libopenzwave.so ' | awk '{print $4}' | xargs nm -g --demangle |grep OpenZWave::ValueID::GetTypeAsString | wc -l)",
9698
],
@@ -125,7 +127,7 @@
125127
"OPENZWAVE_ETC=<(OZW_HOME)/config",
126128
"OPENZWAVE_SECURITY=1",
127129
"OPENZWAVE_EXCEPTIONS=1",
128-
"OPENZWAVE_BITSET=1",
130+
"OPENZWAVE_16=1",
129131
"OPENZWAVE_VALUETYPE_FROM_VALUEID=1"
130132
],
131133
'msvs_settings': {

src/callbacks.cc

+63-21
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,18 @@ void ozw_watcher_callback(OpenZWave::Notification const *cb, void *ctx)
9090
case OpenZWave::Notification::Type_ControllerCommand:
9191
notif->event = cb->GetEvent();
9292
notif->notification = cb->GetNotification();
93+
#if OPENZWAVE_16
94+
notif->command = cb->GetCommand();
95+
#endif
96+
break;
97+
#endif
98+
#if OPENZWAVE_16
99+
case OpenZWave::Notification::Type_UserAlerts:
100+
notif->notification = cb->GetUserAlertType();
93101
break;
94102
#endif
95103
}
96-
104+
// push the notification to the queue
97105
{
98106
mutex::scoped_lock sl(zqueue_mutex);
99107
zqueue.push(notif);
@@ -146,6 +154,7 @@ void handleControllerCommand(NotifInfo *notif)
146154
// ##### END OF LEGACY MODE ###### //
147155
#endif
148156

157+
149158
/*
150159
* handle normal OpenZWave notifications
151160
*/
@@ -252,10 +261,7 @@ void handleNotification(NotifInfo *notif)
252261
// #################
253262
case OpenZWave::Notification::Type_NodeRemoved: {
254263
// #################
255-
{
256-
mutex::scoped_lock sl(znodes_mutex);
257-
znodes.erase(notif->nodeid);
258-
}
264+
delete_node(notif->nodeid);
259265
emitinfo[0] = Nan::New<String>("node removed").ToLocalChecked();
260266
emitinfo[1] = Nan::New<Integer>(notif->nodeid);
261267
emit_cb->Call(Nan::New(ctx_obj), 2, emitinfo, resource);
@@ -420,38 +426,74 @@ void handleNotification(NotifInfo *notif)
420426
emit_cb->Call(Nan::New(ctx_obj), 4, emitinfo, resource);
421427
break;
422428
}
423-
case OpenZWave::Notification::Type_DriverRemoved:
424-
case OpenZWave::Notification::Type_Group:
429+
// ##################
430+
case OpenZWave::Notification::Type_DriverRemoved: {
431+
// ##################
432+
emitinfo[0] = Nan::New<String>("driver removed").ToLocalChecked();
433+
emit_cb->Call(Nan::New(ctx_obj), 1, emitinfo, resource);
434+
break;
435+
}
436+
// ###########
437+
case OpenZWave::Notification::Type_Group: {
438+
// ###########
425439
/* The associations for the node have changed. The
426440
* application should rebuild any group information it
427441
* holds about the node.
428442
*/
429-
// todo
443+
emitinfo[0] = Nan::New<String>("group").ToLocalChecked();
444+
emit_cb->Call(Nan::New(ctx_obj), 1, emitinfo, resource);
430445
break;
431-
#if OPENZWAVE_SECURITY == 1
432-
case OpenZWave::Notification::Type_ControllerCommand:
446+
}
447+
#if OPENZWAVE_16
448+
// ##############
449+
case OpenZWave::Notification::Type_NodeReset: {
450+
// ##############
451+
delete_node(notif->nodeid);
452+
emitinfo[0] = Nan::New<String>("node reset").ToLocalChecked();
453+
emitinfo[1] = Nan::New<Integer>(notif->nodeid);
454+
emit_cb->Call(Nan::New(ctx_obj), 2, emitinfo, resource);
455+
break;
456+
}
457+
// ##############
458+
case OpenZWave::Notification::Type_UserAlerts: {
459+
// ##############
460+
emitinfo[0] = Nan::New<String>("user alert").ToLocalChecked();
461+
emitinfo[1] = Nan::New<Integer>(notif->notification);
462+
emitinfo[2] = Nan::New<String>(notif->help.c_str()).ToLocalChecked();
463+
emit_cb->Call(Nan::New(ctx_obj), 3, emitinfo, resource);
464+
break;
465+
}
466+
// ################################
467+
case OpenZWave::Notification::Type_ManufacturerSpecificDBReady: {
468+
// ################################
469+
emitinfo[0] = Nan::New<String>("manufacturer specific DB ready").ToLocalChecked();
470+
emit_cb->Call(Nan::New(ctx_obj), 1, emitinfo, resource);
471+
break;
472+
}
473+
#endif
474+
475+
#if OPENZWAVE_SECURITY
476+
case OpenZWave::Notification::Type_ControllerCommand: {
433477
emitinfo[0] = Nan::New<String>("controller command").ToLocalChecked();
434478
emitinfo[1] = Nan::New<Integer>(notif->nodeid);
435479
emitinfo[2] = Nan::New<Integer>(notif->event); // Driver::ControllerCommand
436480
emitinfo[3] =
437481
Nan::New<Integer>(notif->notification); // Driver::ControllerState
438482
emitinfo[4] = Nan::New<String>(notif->help.c_str()).ToLocalChecked();
483+
#if OPENZWAVE_16
484+
emitinfo[5] = Nan::New<Integer>(notif->command);
485+
emit_cb->Call(Nan::New(ctx_obj), 6, emitinfo, resource);
486+
#else
439487
emit_cb->Call(Nan::New(ctx_obj), 5, emitinfo, resource);
488+
#endif
440489
break;
441-
case OpenZWave::Notification::Type_NodeReset:
442-
emitinfo[0] = Nan::New<String>("node reset").ToLocalChecked();
443-
emitinfo[1] = Nan::New<Integer>(notif->nodeid);
444-
emitinfo[2] = Nan::New<Integer>(notif->event); // Driver::ControllerCommand
445-
emitinfo[3] =
446-
Nan::New<Integer>(notif->notification); // Driver::ControllerState
447-
emit_cb->Call(Nan::New(ctx_obj), 4, emitinfo, resource);
448-
break;
490+
}
449491
#endif
450492
default:
451493
fprintf(stderr, "Unhandled OpenZWave notification: %d\n", notif->type);
452-
break;
453-
} // end switch
454-
}
494+
break;
495+
} // end switch
496+
} // end handleNotification
455497

456498
/*
457499
* Async handler, triggered by the OpenZWave callback.

src/callbacks.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ namespace OZW {
3131
uint8 notification;
3232
::std::list<OpenZWave::ValueID> values;
3333
::std::string help;
34+
#if OPENZWAVE_16
35+
uint8 command;
36+
#endif
3437
} NotifInfo;
3538

3639
typedef struct {

src/openzwave-values.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ namespace OZW {
9090
OZWManager( SetValue, *vit, val, len);
9191
break;
9292
}
93-
#if OPENZWAVE_BITSET
93+
#if OPENZWAVE_16
9494
case OpenZWave::ValueID::ValueType_BitSet: {
95-
// TODO
95+
uint8 pos = Nan::To<Number>(info[validx]).ToLocalChecked()->Value();
96+
bool val = Nan::To<Boolean>(info[validx+1]).ToLocalChecked()->Value();
97+
OZWManager( SetValue, *vit, pos, val);
9698
}
9799
#endif
98100
}
@@ -276,7 +278,7 @@ namespace OZW {
276278
}
277279
}
278280

279-
#if OPENZWAVE_BITSET
281+
#if OPENZWAVE_16
280282
// =================================================================
281283
NAN_METHOD(OZW::GetValueAsBitSet)
282284
// =================================================================

src/openzwave.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ namespace OZW {
157157
static NAN_METHOD(ClearSwitchPoints);
158158
static NAN_METHOD(SetSwitchPoint);
159159
static NAN_METHOD(RemoveSwitchPoint);
160-
#if OPENZWAVE_BITSET
160+
#if OPENZWAVE_16
161161
static NAN_METHOD(GetValueAsBitSet);
162162
static NAN_METHOD(SetBitMask);
163163
static NAN_METHOD(GetBitMask);

src/utils.cc

+30-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ namespace OZW {
4343
return NULL;
4444
}
4545

46+
/*
47+
* Delete NodeInfo after a NodeReset or NodeRemoved notification
48+
*/
49+
void delete_node(uint8 nodeid) {
50+
mutex::scoped_lock sl(znodes_mutex);
51+
if (znodes.erase(nodeid)) {
52+
// TODO: extra cleanup??
53+
}
54+
}
55+
4656
SceneInfo *get_scene_info(uint8 sceneid) {
4757
::std::list<SceneInfo *>::iterator it;
4858

@@ -122,9 +132,18 @@ namespace OZW {
122132
AddStringProp(valobj, value, val.c_str())
123133
break;
124134
}
125-
#if OPENZWAVE_BITSET
135+
#if OPENZWAVE_16
136+
#define SET(val,offset) val |= (1 << offset)
137+
#define CLEAR(val,offset) val &= ~(1 << offset)
138+
// just return the whole bitset, mask your bit in JS land
126139
case OpenZWave::ValueID::ValueType_BitSet: {
127-
// TODO
140+
uint8 val = 0;
141+
bool bit;
142+
for (uint8 pos = 0; pos < 8; pos++) {
143+
OZWManager( GetValueAsBitSet, value, pos, &bit);
144+
bit ? SET(val, pos) : CLEAR(val, pos);
145+
}
146+
AddIntegerProp(valobj, value, val);
128147
}
129148
#endif
130149
/*
@@ -313,7 +332,8 @@ namespace OZW {
313332
index: the index of the command (usually 0)
314333
*/
315334
OpenZWave::ValueID* populateValueId(const Nan::FunctionCallbackInfo<v8::Value> &info, uint8 offset) {
316-
uint8 nodeid, comclass, instance, index;
335+
uint8 nodeid, comclass, instance;
336+
OZWValueIdIndex index;
317337
if ( (info.Length() >= offset) && info[offset]->IsObject() ) {
318338
Local<Object> o = Nan::To<Object>(info[offset]).ToLocalChecked();
319339
if (isOzwValue(o)) {
@@ -461,7 +481,13 @@ const ::std::string getNotifHelpMsg(Notification const *n) {
461481
str.append(getControllerStateAsStr((OpenZWave::Driver::ControllerState) n->GetByte()));
462482
break;
463483
case Notification::Type_DriverRemoved:
464-
str = "DriverRemoved"; break;
484+
str = "DriverRemoved"; break;
485+
case Notification::Type_NodeReset:
486+
str = "NodeReset"; break;
487+
case Notification::Type_UserAlerts:
488+
str = "UserAlerts"; break;
489+
case Notification::Type_ManufacturerSpecificDBRead:
490+
str = "ManuacturerSpecificDBRead"; break;
465491
}
466492
return str;
467493
#endif

src/utils.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
#define OZWManagerAssign(VALUE,METHOD,...) VALUE = OpenZWave::Manager::Get()->METHOD(__VA_ARGS__)
4747
#endif
4848

49+
typedef
50+
#if OPENZWAVE_16
51+
uint16_t
52+
#else
53+
uint8_t
54+
#endif
55+
OZWValueIdIndex;
4956

5057
#define AddIntegerProp(OBJ,PROPNAME,PROPVALUE) \
5158
Nan::Set(OBJ, \
@@ -124,6 +131,7 @@ namespace OZW {
124131

125132
v8::Local<v8::Object> zwaveValue2v8Value(OpenZWave::ValueID value);
126133
NodeInfo *get_node_info(uint8 nodeid);
134+
void delete_node(uint8 nodeid);
127135

128136
#ifdef OPENZWAVE_DEPRECATED16
129137
v8::Local<v8::Object> zwaveSceneValue2v8Value(uint8 sceneId, OpenZWave::ValueID value);

0 commit comments

Comments
 (0)