Skip to content

Commit 7714097

Browse files
authored
Update PF for port (#125)
* Update PF for port * Add braces * Add braces
1 parent 8e351ca commit 7714097

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

examples/QuickStart/Converter.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
function Converter(decoded) {
1+
function Converter(decoded, port) {
22
// Merge, split or otherwise
33
// mutate decoded fields.
44
var converted = decoded;
55

6-
if (converted.led === 0) {
7-
converted.led = false;
8-
}
9-
10-
if (converted.led === 1) {
11-
converted.led = true;
6+
if (port === 1 && (converted.led === 0 || converted.led === 1)) {
7+
converted.led = Boolean(converted.led);
128
}
139

1410
return converted;

examples/QuickStart/Decoder.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
function Decoder(bytes) {
1+
function Decoder(bytes, port) {
22
// Decode an uplink message from a buffer
33
// (array) of bytes to an object of fields.
44
var decoded = {};
55

6-
decoded.led = bytes[0];
6+
if (port === 1) {
7+
decoded.led = bytes[0];
8+
}
79

810
return decoded;
911
}

examples/QuickStart/Encoder.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
function Encoder(object) {
1+
function Encoder(object, port) {
22
// Encode downlink messages sent as
33
// object to an array or buffer of bytes.
44
var bytes = [];
55

6-
bytes[0] = object.led ? 1 : 0;
6+
if (port === 1) {
7+
bytes[0] = object.led ? 1 : 0;
8+
}
79

810
return bytes;
911
}

examples/QuickStart/Validator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
function Validator(converted) {
1+
function Validator(converted, port) {
22
// Return false if the decoded, converted
33
// message is invalid and should be dropped.
44

5-
if (converted.led !== true && converted.led !== false) {
5+
if (port === 1 && typeof converted.led !== 'boolean') {
66
return false;
77
}
88

0 commit comments

Comments
 (0)