Skip to content

Commit af0ee7f

Browse files
authored
Merge pull request #306 from OpenZWave/feature/294-sendRawData
Feature/294 send raw data
2 parents 0644c73 + 21a377b commit af0ee7f

File tree

8 files changed

+54
-29
lines changed

8 files changed

+54
-29
lines changed

README-api.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
> This library is as similar as possible to the [C++ OpenZwave::Manager API](http://www.openzwave.com/dev/classOpenZWave_1_1Manager.html) for Node.js. Please note that this is not always possible to have the _exact_ same behaviour as in the C++ library.
44
5-
Start by loading the addon with `require` and then create a new instance of the addon:
5+
Start by loading the addon with `require` and then create a new instance of the addon. You can also pass in an optional object specifying any desired option overrides:
66
```js
77
var OZW = require('openzwave-shared');
88
var zwave = new OZW();
9-
```
10-
11-
You can also pass in an optional object specifying any desired option overrides:
12-
```js
9+
// OR pass extra options
1310
var zwave = new OZW({
1411
Logging: false, // disable file logging (OZWLog.txt)
1512
ConsoleOutput: true // enable console logging
@@ -44,6 +41,7 @@ zwave.disconnect('dev/ttyUSB0');// disconnect from the current connection
4441
zwave.connect('\\\\.\\COM3'); // connect to a USB ZWave controller on COM3
4542
zwave.disconnect('\\\\.\\COM3');// disconnect from the current connection on COM3
4643
```
44+
4745
**Important notice**: the connect() call is asynchronous following the
4846
node/v8 javascript paradigm. This means that connect() will yield
4947
control to your script *immediately*, but the underlying OpenZWave C++
@@ -60,26 +58,19 @@ Javascipt object or as 4 discrete integer arguments:
6058
- 3: Instance and
6159
- 4: Index
6260

63-
For example if Zwave Node #3 is a binary switch, to turn it on and off, use
64-
command class 37:
61+
Some examples:
6562

6663
```js
64+
// if Zwave Node #3 is a binary switch, to turn it on and off, use command class 37
6765
zwave.setValue(3, 37, 1, 0, true); // node 3: turn on
6866
zwave.setValue(3, 37, 1, 0, false); // node 3: turn off
6967
zwave.setValue({ node_id:3, class_id: 37, instance:1, index:0}, false); // the same turn-off command using an object
70-
```
71-
72-
Another example: if Zwave Node #5 is a dimmer, use class 38:
73-
74-
```js
68+
// if Zwave Node #5 is a dimmer, use class 38:
7569
zwave.setValue(5, 38, 1, 0, 50); // 1) passing each individual ValueID constituent:
7670
zwave.setValue({ node_id:5, class_id: 38, instance:1, index:0}, 50); // 2) or a valueID object (emitted by ValueAdded event):
77-
```
78-
79-
The 'standard' way to control your devices is by `setValue` which is also the
80-
_only_ way to control multi-instance devices, such as the Fibaro FGS-221
81-
(double in-wall 2x1,5kw relay) for example:
82-
```js
71+
// The 'standard' way to control your devices is by `setValue` which is also the
72+
// _only_ way to control multi-instance devices, such as the Fibaro FGS-221
73+
// (double in-wall 2x1,5kw relay) for example:
8374
zwave.setValue(8, 37, 1, 0, true); // node 8: turn on 1st relay
8475
zwave.setValue(8, 37, 1, 0, false);// node 8: turn off 1st relay
8576
zwave.setValue(8, 37, 2, 0, true); // node 8: turn on 2nd relay
@@ -161,3 +152,5 @@ zwave.requestAllConfigParams(nodeId);
161152
zwave.requestConfigParam(nodeId, paramId);
162153
zwave.setConfigParam(nodeId, paramId, paramValue, <sizeof paramValue>);
163154
```
155+
156+
You can always refer to [the official OpenZWave::Manager API](http://www.openzwave.com/dev/classOpenZWave_1_1Manager.html) for more details on calling Manager methods. The aim of this wrapper is to provide a 1-to-1 mapping to all available methods, with the only change here being that the first letter of each method is downcased (eg. `RequestNodeInfo` in C++ is named `requestNodeInfo` in Javascript)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node-openzwave-shared
33
[Linux![Linux Build Status](https://travis-ci.org/OpenZWave/node-openzwave-shared.svg?branch=master)](https://travis-ci.org/OpenZWave/node-openzwave-shared)
44
[Windows![Windows Build status](https://ci.appveyor.com/api/projects/status/txg360huomtpgc8o?svg=true)](https://ci.appveyor.com/project/ekarak/node-openzwave-shared)
55
[![Join the chat at https://gitter.im/OpenZWave/node-openzwave-shared](https://badges.gitter.im/OpenZWave/node-openzwave-shared.svg)](https://gitter.im/OpenZWave/node-openzwave-shared?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6+
[![Google group](http://www.google.com/images/icons/product/groups-32.png)](https://groups.google.com/d/forum/node-openzwave-shared)
67

78
This is the homepage for *node-openzwave-shared*, the official binary add-on for
89
Node.js, which wraps [Open ZWave](http://openzwave.com/), a high quality C++
@@ -147,7 +148,8 @@ download the
147148
- [Management of nodes](../master/README-mgmt.md)
148149
- [Security API](../master/README-security.md)
149150
- [Usage example](../master/README-example.md)
150-
151+
- [Deprecated API calls in OpenZWave 1.6](../master/README-deprecated-16.md)
152+
151153
## Environment-specific documentation
152154
- [Installing on Rapsbian](../master/README-raspbian.md)
153155
- [Installing on Ubuntu 15.04](../master/README-ubuntu.md)

src/openzwave-driver.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ namespace OZW {
4646
version = OpenZWave::Manager::getVersionAsString();
4747
#if OPENZWAVE_EXCEPTIONS
4848
} catch ( OpenZWave::OZWException& e ) {
49-
char buffer [100];
50-
sprintf(buffer, "Exception connecting in %s(%d): %s",
49+
char buffer [200];
50+
snprintf(buffer, 200, "Exception connecting in %s(%d): %s",
5151
e.GetFile().c_str(), e.GetLine(), e.GetMsg().c_str());
5252
Nan::ThrowError( buffer );
5353
}
@@ -122,8 +122,8 @@ namespace OZW {
122122
OpenZWave::Options::Destroy();
123123
#if OPENZWAVE_EXCEPTIONS
124124
} catch ( OpenZWave::OZWException& e ) {
125-
char buffer [100];
126-
sprintf(buffer, "Exception disconnecting in %s(%d): %s",
125+
char buffer [200];
126+
snprintf(buffer, 200, "Exception disconnecting in %s(%d): %s",
127127
e.GetFile().c_str(), e.GetLine(), e.GetMsg().c_str());
128128
Nan::ThrowError( buffer );
129129
}

src/openzwave-nodes.cc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,30 @@ namespace OZW {
9393
OZWManager( SwitchAllOff, homeid);
9494
}
9595
#endif
96-
96+
#ifdef OPENZWAVE_16
97+
// ===================================================================
98+
NAN_METHOD(OZW::SendRawData)
99+
// ===================================================================
100+
{
101+
Nan::HandleScope scope;
102+
CheckMinArgs(5, "nodeid, logText<str>, msgType<uint8>, sendSecure<bool>, content<Buffer> (,length)");
103+
uint8 nodeid = Nan::To<Number>(info[0]).ToLocalChecked()->Value();
104+
::std::string logText(*Nan::Utf8String( info[1] ));
105+
uint8 msgType = Nan::To<Number>(info[2]).ToLocalChecked()->Value();
106+
bool sendSecure = Nan::To<Boolean>(info[3]).ToLocalChecked()->Value();
107+
checkType(Buffer::HasInstance(info[4]));
108+
uint8 *content = (uint8*)Buffer::Data(info[4]);
109+
double buflength = Buffer::Length(info[4]);
110+
uint8 length = 0;
111+
// can either deduce length from JS buffer, or use the length provided
112+
if (info.Length() > 5) {
113+
length = ::std::min<double>( Nan::To<Number>(info[5]).ToLocalChecked()->Value(), buflength );
114+
} else {
115+
length = buflength;
116+
}
117+
OZWManager( SendRawData, homeid, nodeid, logText, msgType, sendSecure, content, length );
118+
}
119+
#endif
97120
// ===================================================================
98121
NAN_METHOD(OZW::PressButton)
99122
// ===================================================================

src/openzwave.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ namespace OZW {
120120
Nan::SetPrototypeMethod(t, "setNodeLevel", OZW::SetNodeLevel);
121121
Nan::SetPrototypeMethod(t, "switchAllOn", OZW::SwitchAllOn);
122122
Nan::SetPrototypeMethod(t, "switchAllOff", OZW::SwitchAllOff);
123+
#endif
124+
#ifdef OPENZWAVE_16
125+
Nan::SetPrototypeMethod(t, "sendRawData", OZW::SendRawData);
123126
#endif
124127
Nan::SetPrototypeMethod(t, "pressButton", OZW::PressButton);
125128
Nan::SetPrototypeMethod(t, "releaseButton", OZW::ReleaseButton);

src/openzwave.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef __NODE_OPENZWAVE_HPP_INCLUDED__
1919
#define __NODE_OPENZWAVE_HPP_INCLUDED__
2020

21+
#include <algorithm>
2122
#include <iostream>
2223
#include <sstream>
2324
#include <list>
@@ -114,6 +115,9 @@ namespace OZW {
114115
static NAN_METHOD(SetNodeLevel);
115116
static NAN_METHOD(SwitchAllOn);
116117
static NAN_METHOD(SwitchAllOff);
118+
#endif
119+
#ifdef OPENZWAVE_16
120+
static NAN_METHOD(SendRawData);
117121
#endif
118122
static NAN_METHOD(PressButton);
119123
static NAN_METHOD(ReleaseButton);

src/utils.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ namespace OZW {
6969

7070
::std::string getValueIdDescriptor(OpenZWave::ValueID value) {
7171
char buffer[32];
72-
sprintf(buffer, "%d-%d-%d-%d", value.GetNodeId(), value.GetCommandClassId(), value.GetInstance(), value.GetIndex());
72+
snprintf(buffer, 32, "%d-%d-%d-%d", value.GetNodeId(), value.GetCommandClassId(), value.GetInstance(), value.GetIndex());
7373
return ::std::string(buffer);
7474
}
75-
::std::string getValueIdDescriptor(uint8 node_id, uint8 class_id, uint8 instance, uint8 index) {
75+
::std::string getValueIdDescriptor(uint8 node_id, uint8 class_id, OZWValueIdIndex instance, uint8 index) {
7676
char buffer[32];
77-
sprintf(buffer, "%d-%d-%d-%d", node_id, class_id, instance, index);
77+
snprintf(buffer, 32, "%d-%d-%d-%d", node_id, class_id, instance, index);
7878
return ::std::string(buffer);
7979
}
8080

src/utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ OZWValueIdIndex;
8080

8181
#define CheckMinArgs(NUM, DESC) \
8282
if(info.Length() < NUM) { \
83-
char buffer [100]; \
84-
sprintf(buffer, "This OpenZwave method requires at least %d argument(s): %s", NUM, DESC); \
83+
char buffer [200]; \
84+
snprintf(buffer, 200, "This OpenZwave method requires at least %d argument(s): %s", NUM, DESC); \
8585
Nan::ThrowError( buffer ); \
8686
}
8787

0 commit comments

Comments
 (0)