Commit cba91305 authored by Spencer Williams's avatar Spencer Williams
Browse files

comments

parent 78b48524
'use strict';
/**
* A Device object manages an edge device and its bluetooth communication
*/
class Device {
constructor(bleDevice) {
this.id = bleDevice.address.replace(/:/g, '');
......@@ -7,6 +10,10 @@ class Device {
this.fwVersion = null;
}
/**
* Returns a Promise that will resolve with the ble device's firmware revision,
* or reject with an error
*/
readFirmware() {
return new Promise((resolve, reject) => {
console.log(`${this.id}: readFirmwareRevision`);
......@@ -24,6 +31,10 @@ class Device {
});
}
/**
* Returns a Promise that will connect and set up the ble device with noble.
* Once set up, it will read the device's firmware and enable its luxometer.
*/
setUp() {
return new Promise((resolve, reject) => {
this.bleDevice.connectAndSetUp((setupError) => {
......@@ -44,6 +55,9 @@ class Device {
});
}
/**
* Returns a Promise that will enable the device's luxometer
*/
enableLuxometer() {
return new Promise((resolve) => {
console.log(`${this.id}: enableLuxometer`);
......@@ -51,6 +65,9 @@ class Device {
});
}
/**
* Returns a Promise that will notify the device's luxometer
*/
notifyLuxometer() {
return new Promise((resolve) => {
console.log(`${this.id}: notifyLuxometer`);
......@@ -58,10 +75,14 @@ class Device {
});
}
onLuxometerChange(sendTelemetry) {
/**
* This function will bind its given callback to run when the ble device
* triggers a 'luxometerChange' event.
*/
onLuxometerChange(callback) {
console.log(`${this.id}: set up onluxchange`);
this.bleDevice.on('luxometerChange', (lux) => {
sendTelemetry(this, lux);
callback(this, lux);
});
return this.notifyLuxometer();
......
......@@ -6,7 +6,13 @@ const dateFormat = require('dateformat');
const ProviderStrategy = require('./providerStrategy.js');
/**
* A concrete Cloud Provider strategy for interacting with AWS Kinesis Firehose.
*/
class AWSProvider extends ProviderStrategy {
/**
* Initializes AWS config and a Firehose delivery stream
*/
constructor(config) {
super(config);
this.name = 'AWS';
......@@ -26,6 +32,7 @@ class AWSProvider extends ProviderStrategy {
sendTelemetry(telemetry) {
const now = new Date();
// AWS needs a specific time format
telemetry.timestamp = dateFormat(now, "yyyy-mm-dd hh:mm:ss.l");
this.firehose.putRecord(telemetry)
.then(() => {
......
......@@ -2,7 +2,15 @@
const AWSProvider = require('./aws.js');
/**
* A Cloud Provider object for a calling script to refer to.
*/
class Provider {
/**
* Takes in a full config object (see config.json.sample).
* Constructs a Provider based on the "cloudProvider" key in config.
* Sets the Provider's concrete strategy if valid.
*/
constructor(config) {
if (typeof config.cloudProvider === 'undefined' ||
Object.keys(config.cloudProvider).length === 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment