-
Notifications
You must be signed in to change notification settings - Fork 373
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
477 additions
and
5 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,35 @@ | ||
# Uplink decoder decodes binary data uplink into a JSON object (optional) | ||
# For documentation on writing encoders and decoders, see: https://www.thethingsindustries.com/docs/integrations/payload-formatters/javascript/ | ||
uplinkDecoder: | ||
fileName: elv-lw-omo.js | ||
# Examples (optional) | ||
examples: | ||
- description: device status information | ||
input: | ||
fPort: 10 | ||
bytes: [0x96, 0x01, 0x01, 0x00, 0x00, 0x00, 0x10] | ||
output: | ||
data: | ||
Supply_Voltage: 1500 | ||
frame_type: 'Device_State' | ||
TX_Reason: 'Button Pressed' | ||
Accelerated: false | ||
Tilt_Area_0: false | ||
Tilt_Area_1: false | ||
Tilt_Area_2: false | ||
Angle: 0 | ||
Activation_count: 16 | ||
- description: device acceleration | ||
input: | ||
fPort: 10 | ||
bytes: [0x96, 0x02, 0x05, 0x01, 0x2D] | ||
output: | ||
data: | ||
Supply_Voltage: 1500 | ||
frame_type: 'Acceleration_Data' | ||
TX_Reason: 'Acceleration' | ||
Accelerated: true | ||
Tilt_Area_0: false | ||
Tilt_Area_1: false | ||
Tilt_Area_2: false | ||
Angle: 45 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,125 @@ | ||
/* | ||
* ELV-LW-OMO Payload Parser | ||
* | ||
* Version: V1.0.1 | ||
* | ||
* */ | ||
|
||
function decodeUplink(input) { | ||
var data = input.bytes; | ||
var valid = true; | ||
|
||
if (typeof Decoder === "function") { | ||
data = Decoder(data, input.fPort); | ||
} | ||
|
||
if (typeof Converter === "function") { | ||
data = Converter(data, input.fPort); | ||
} | ||
|
||
if (typeof Validator === "function") { | ||
valid = Validator(data, input.fPort); | ||
} | ||
|
||
if (valid) { | ||
return { | ||
data: data | ||
}; | ||
} else { | ||
return { | ||
data: {}, | ||
errors: ["Invalid data received"] | ||
}; | ||
} | ||
} | ||
|
||
var tx_reason = ["Undefined","Button Pressed", "Heartbeat", "Settings", "Joined", "Acceleration", "Tilt", "Ongoing Acceleration", "Inactivity", "Error"]; | ||
var frame_type = ["Device_Info", "Device_State", "Acceleration_Data", "Button_Pressed", "Config_Data"]; | ||
var device_modes = ["Acceleration", "Tilt"]; | ||
/* | ||
* @brief Receives the bytes transmitted from a device of the ELV-LW-OMO | ||
* @param bytes: Array with the data stream | ||
* @param port: Used TTN/TTS data port | ||
* @return Decoded data from a device of the ELV-LW-OMO | ||
* */ | ||
function Decoder(bytes, port) { | ||
var decoded = {}; // Container with the decoded output | ||
var Temp_Value = 0; // Variable for temporarily calculated values | ||
|
||
if (port === 10) { // The default port for app data | ||
// Minimum 5 Bytes for Header | ||
|
||
// Collecting header data | ||
|
||
decoded.Supply_Voltage = bytes[0] * 10; | ||
decoded.frame_type = frame_type[(bytes[1])]; //Frametype encodes what Kind of Payload is being sent | ||
decoded.TX_Reason = tx_reason[(bytes[2])]; | ||
//Write every reason for sending correspondig to bit n | ||
switch (decoded.frame_type) | ||
{ | ||
case "Device_Info": | ||
var bl_version_major = bytes[3]; | ||
var bl_version_minor = bytes[4]; | ||
var bl_version_patch = bytes[5]; | ||
|
||
decoded.Bootloader_Version = `${bl_version_major}.${bl_version_minor}.${bl_version_patch}`; //Build version-String from 3 previous values | ||
|
||
var fw_version_major = bytes[6]; | ||
var fw_version_minor = bytes[7]; | ||
var fw_version_patch = bytes[8]; | ||
|
||
decoded.Firmware_Version = `${fw_version_major}.${fw_version_minor}.${fw_version_patch}`;//Build version-String from 3 previous values | ||
|
||
decoded.hw_revision = bytes[9] << 8 | bytes[10]; // //HW version is encoded as 16-Bit int | ||
break; | ||
case "Device_State": | ||
decoded.Accelerated = !!(bytes[3] & 0x1); | ||
decoded.Tilt_Area_0 = !!(bytes[3] & 0x10); | ||
decoded.Tilt_Area_1 = !!(bytes[3] & 0x20); | ||
decoded.Tilt_Area_2 = !!(bytes[3] & 0x40); | ||
|
||
decoded.Angle = bytes[4]; | ||
|
||
decoded.Activation_count = (bytes[5] << 8 | bytes[6]); | ||
break; | ||
case "Acceleration_Data": | ||
decoded.Accelerated = !!(bytes[3] & 0x1); | ||
decoded.Tilt_Area_0 = !!(bytes[3] & 0x10); | ||
decoded.Tilt_Area_1 = !!(bytes[3] & 0x20); | ||
decoded.Tilt_Area_2 = !!(bytes[3] & 0x40); | ||
|
||
decoded.Angle = bytes[4]; | ||
break; | ||
case "Button_Pressed": | ||
decoded.Button_Count = bytes[3]; | ||
break; | ||
case "Config_Data": | ||
decoded.device_mode = ""; | ||
for(let i = 0; i < 8; i++) | ||
{ | ||
if((bytes[3] >> i) & 1) | ||
{ | ||
decoded.device_mode += device_modes[i]; | ||
} | ||
} | ||
|
||
decoded.sensor_threshold = bytes[4]; | ||
|
||
decoded.range = bytes[5]; | ||
decoded.alpha = bytes[6]; | ||
|
||
decoded.beta = bytes[7]; | ||
|
||
decoded.hysteresis = bytes[8]; | ||
|
||
decoded.senc_cycle_minutes = bytes[9] * 6; | ||
break; | ||
} | ||
|
||
} | ||
else { | ||
decoded.parser_error = "Wrong Port Number"; | ||
} | ||
|
||
return decoded; | ||
} |
Oops, something went wrong.