-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../.eslintrc.js", | ||
"rules": { | ||
"no-unused-vars": 0 | ||
}, | ||
"globals": { | ||
"encode": false, | ||
"decode": false, | ||
"LoraMessage": false, | ||
"unixtime": false, | ||
"latLng": false, | ||
"uint16": false, | ||
"uint8": false, | ||
"temperature": false, | ||
"humidity": false, | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <LoraMessage.h> | ||
|
||
void setup() { | ||
LoraMessage message; | ||
message.addUnixtime(1468075322); | ||
message.addLatLng(-33.905024, 151.26648); | ||
|
||
do_send(message.getLength(), message.getBytes()); | ||
} | ||
|
||
void loop(void) { | ||
os_runloop_once(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function ttn_encoder() { | ||
// IMPORTANT: paste code from src/encoder.js here | ||
|
||
return encode( | ||
[ Date.now() / 1000, [-33.905052, 151.26641] ], | ||
[ unixtime, latLng ] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function ttn_encoder() { | ||
// IMPORTANT: paste code from src/encoder.js here | ||
// IMPORTANT: paste code from src/LoraMessage.js here | ||
|
||
return new LoraMessage() | ||
.addUnixtime(Date.now() / 1000) | ||
.addLatLng(-33.905052, 151.26641); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"tdd": "mocha --watch", | ||
"test": "mocha" | ||
}, | ||
"keywords": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(function(root) { | ||
function LoraMessage(encoder) { | ||
this.dataTuples = []; | ||
this.encoder = encoder || root; | ||
} | ||
|
||
LoraMessage.prototype.addTuple = function(data, fnName) { | ||
this.dataTuples.push({ | ||
data: data, | ||
fn: this.encoder[fnName] | ||
}); | ||
}; | ||
|
||
|
||
LoraMessage.prototype.addUnixtime = function(unixtime) { | ||
this.addTuple([unixtime], 'unixtime'); | ||
return this; | ||
}; | ||
|
||
LoraMessage.prototype.addLatLng = function(latitude, longitude) { | ||
this.addTuple([latitude, longitude], 'latLng'); | ||
return this; | ||
}; | ||
|
||
LoraMessage.prototype.addUint16 = function(uint16) { | ||
this.addTuple([uint16], 'uint16'); | ||
return this; | ||
}; | ||
|
||
LoraMessage.prototype.addTemperature = function(temperature) { | ||
this.addTuple([temperature], 'temperature'); | ||
return this; | ||
}; | ||
|
||
LoraMessage.prototype.addUint8 = function(uint8) { | ||
this.addTuple([uint8], 'uint8'); | ||
return this; | ||
}; | ||
|
||
LoraMessage.prototype.addHumidity = function(humidity) { | ||
this.addTuple([humidity], 'humidity'); | ||
return this; | ||
}; | ||
|
||
LoraMessage.prototype.getBytes = function() { | ||
var buffer = new Buffer(this.getLength()); | ||
var offset = 0; | ||
this.dataTuples.forEach(function(tuple) { | ||
var current = tuple.fn.apply(null, tuple.data); | ||
current.copy(buffer, offset); | ||
offset += tuple.fn.BYTES; | ||
}); | ||
return buffer; | ||
}; | ||
|
||
LoraMessage.prototype.getLength = function() { | ||
return this.dataTuples.reduce(function(previous, tuple) { | ||
return previous + tuple.fn.BYTES; | ||
}, 0); | ||
}; | ||
|
||
if (typeof module === 'object' && typeof module.exports !== 'undefined') { | ||
module.exports = LoraMessage; | ||
} | ||
})(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const path = require('path'); | ||
const chai = require('chai'); | ||
const encoder = require(path.join(__dirname, '..', 'src', 'encoder.js')); | ||
const base = require('./base.js'); | ||
const LoraMessage = require(path.join(__dirname, '..', 'src', 'LoraMessage.js')); | ||
|
||
chai.should(); | ||
|
||
describe('LoraMessage', () => { | ||
|
||
it('should be possible to construct a simple message', () => { | ||
const m = new LoraMessage(encoder); | ||
m.addUnixtime(base.unixtime); | ||
m.getLength().should.equal(4); | ||
m.getBytes().should.deep.equal(base.unixtimeBytes); | ||
}); | ||
|
||
it('should be possible to chain message parts', () => { | ||
new LoraMessage(encoder) | ||
.addLatLng(base.latLng[0], base.latLng[1]) | ||
.addUnixtime(base.unixtime) | ||
.addUint16(base.uint16) | ||
.addTemperature(base.temp) | ||
.addUint8(base.uint8) | ||
.addHumidity(base.humidity) | ||
.getBytes() | ||
.should.be.deep.equal( | ||
Buffer.concat([ | ||
base.latLngBytes, | ||
base.unixtimeBytes, | ||
base.uint16Bytes, | ||
base.tempBytes, | ||
base.uint8Bytes, | ||
base.humidityBytes | ||
]) | ||
); | ||
}); | ||
}); |