Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding existing connector to the repository #77

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "../../../../schema/connector.json",
"name": "Oyster GPS",
"images": {
"logo": "./assets/logo.png"
},
"versions": {
"v1.0.0": {
"src": "./v1.0.0/payload.js",
"manifest": "./v1.0.0/payload-config.jsonc"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Compact Long-Life Battery powered GPS asset tracking over Sigfox
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../../../../schema/connector_details.json",
"description": "../description.md",
"install_text": "##\nThe Oyster is a compact, rugged GPS tracking device that has been designed for locating and tracking non-powered assets such as containers, trailers, skip bins, and other assets where super-long battery life is required without sacrificing the frequency of updates and performance.\n * IP67 Rugged weather-proof housing.\n * Powered by 3 x AA Batteries with up to 5 years battery life.\n * High-precision GPS/GLONASS tracking device tracks assets when they're on the move and enters sleep mode when stationary to save power.\n * Small, Compact and easy to install and conceal.\n * Configure by USB cable \n",
"install_end_text": "",
"device_annotation": "Install the dashboard template: http://admin.tago.io/template/5d2cd07d8a146c002105bdf6",
"device_parameters": [],
"networks": [
"../../../../network/sigfox/v1.0.0/payload.js"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
//e.g. parseSigFox('10b67dcc0006efda3d9816c2')

//In an attempt to make the code clearer, I will not be using ArrayBuffer
function hex2Bytes(val) {
if (!val) {
return [];
}

val = val.trim();
if (val.startsWith("0x")) {
val = val.substring(2); //get rid of starting '0x'
}

var numBytes = val.length / 2;
var bytes = [];

for (var i = 0; i < numBytes; i++) {
bytes.push(parseInt(val.substring(i * 2, i * 2 + 2), 16));
}

return bytes;
}

function parseLittleEndianInt32(buffer, offset) {
return (
(buffer[offset + 3] << 24) +
(buffer[offset + 2] << 16) +
(buffer[offset + 1] << 8) +
buffer[offset]
);
}

function parseLittleEndianInt16(buffer, offset) {
return (buffer[offset + 1] << 8) + buffer[offset];
}

function parseLittleEndianInt16Bits(buffer, offset, bitOffset, bitLength) {
var temp = parseLittleEndianInt16(buffer, offset);
temp = temp >> bitOffset;
var mask = 0xffff >> (16 - bitLength);
return temp & mask;
}

//e.g. 10b67dcc0006efda3d9816c2
function parseSigFox(data) {
var buffer = hex2Bytes(data);

if (!buffer) {
return null;
}

var recordType = buffer[0] & 0x0f;

switch (recordType) {
case 0: //positional data
return parsePositionalData(buffer);

case 1: //downlink ACK
return parseDownlinkAck(buffer);

case 2: //device data
return parseDeviceStats(buffer);

case 3: //extended positional data
return parseExtendedData(buffer);

default:
return null;
}
}

function parsePositionalData(buffer) {
var flags = buffer[0] & 0xf0;
var inTrip = (flags & 0x10) > 0;
var lastFixFailed = (flags & 0x20) > 0;

var latitudeRaw = parseLittleEndianInt32(buffer, 1);
var longitudeRaw = parseLittleEndianInt32(buffer, 5);
var headingRaw = buffer[9];
var speedRaw = buffer[10];
var batteryRaw = buffer[11];

return {
MessageType: 0,
InTrip: inTrip,
LastFixFailed: lastFixFailed,
Latitude: latitudeRaw * 1e-7,
Longitude: longitudeRaw * 1e-7,
Heading: headingRaw * 2,
SpeedKmH: speedRaw,
BatteryVoltage: (batteryRaw * 25) / 1000.0,
};
}

function parseDownlinkAck(buffer) {
var flags = buffer[0] & 0xf0;
var downlinkAccepted = (flags & 0x10) > 0;

var firmwareMajor = buffer[2];
var firmwareMinor = buffer[3];

var data = [];
for (var i = 0; i < 8; i++) {
data.push(i + 4);
}

return {
MessageType: 1,
DownlinkAccepted: downlinkAccepted,
FirmwareVersion: firmwareMajor + "." + firmwareMinor,
DownlinkData: data,
};
}

function parseDeviceStats(buffer) {
var uptimeWeeks = parseLittleEndianInt16Bits(buffer, 0, 4, 9 /*bits*/);
var txCountRaw = parseLittleEndianInt16Bits(buffer, 1, 5, 11 /*bits*/);
var rxCountRaw = buffer[3];
var tripCountRaw = parseLittleEndianInt16Bits(buffer, 4, 0, 13 /*bits*/);
var gpsSuccessRaw = parseLittleEndianInt16Bits(buffer, 5, 5, 10 /*bits*/);
var gpsFailuresRaw = parseLittleEndianInt16Bits(buffer, 6, 7, 8 /*bits*/);
var averageFixTime = parseLittleEndianInt16Bits(buffer, 7, 7, 9 /*bits*/);
var averageFailTime = parseLittleEndianInt16Bits(buffer, 9, 0, 9 /*bits*/);
var averageFreshenTime = parseLittleEndianInt16Bits(
buffer,
10,
1,
8 /*bits*/
);
var wakeupsPerTrip = buffer[11] >> 1;

return {
MessageType: 2,
UptimeWeeks: uptimeWeeks,
TxCount: txCountRaw * 32,
RxCount: rxCountRaw * 32,
TripCount: tripCountRaw,
GpsSuccessCount: gpsSuccessRaw * 32,
GpsFailureCount: gpsFailuresRaw * 32,
AverageFixTimeSeconds: averageFixTime,
AverageFailTimeSeconds: averageFailTime,
AverageFreshenTimeSeconds: averageFreshenTime,
WakeUpsPerTrip: wakeupsPerTrip,
};
}

function parseExtendedData(buffer) {
var headingRaw = buffer[0] >> 4;
var latitudeRaw = buffer[1] + buffer[2] * 256 + buffer[3] * 65536;
if (latitudeRaw >= 0x800000)
// 2^23
latitudeRaw -= 0x1000000; // 2^24
var longitudeRaw = buffer[4] + buffer[5] * 256 + buffer[6] * 65536;
if (longitudeRaw >= 0x800000)
// 2^23
longitudeRaw -= 0x1000000; // 2^24
var posAccRaw = buffer[7];
var batteryRaw = buffer[8];
var speedRaw = buffer[9] & 0x3f;
var inTrip = (buffer[9] & 0x40) > 0;
var lastFixFailed = (buffer[9] & 0x80) > 0;

return {
MessageType: 3,
Heading: headingRaw * 22.5,
Latitude: (latitudeRaw * 256) / 1e7,
Longitude: (longitudeRaw * 256) / 1e7,
PosAccM: posAccRaw * 1,
BatteryVoltage: (batteryRaw * 25) / 1000.0,
SpeedKmH: speedRaw * 2.5,
InTrip: inTrip,
LastFixFailed: lastFixFailed,
};
}

function toTagoFormat(object_item, serie, prefix = "") {
const result = [];
for (const key in object_item) {
// if (ignore_vars.includes(key)) continue; // ignore chosen vars

result.push({
variable: `${prefix}${key}`,
value: object_item[key],
serie,
});
}

return result;
}

// Find the variable data from the payload, ignore the parse if the variable was not sent.
let data = payload.find((x) => x.variable === "data");
if (data) {
// get the data serie or generate a new one.
const serie = data.serie || new Date().getTime();
data = data.value;
const vars_to_tago = parseSigFox(data);

let location;
if (vars_to_tago.Longitude && vars_to_tago.Latitude) {
location = {
variable: "location",
value: `${vars_to_tago.Latitude}, ${vars_to_tago.Longitude}`,
location: { lat: vars_to_tago.Latitude, lng: vars_to_tago.Longitude },
serie,
};
delete vars_to_tago.Latitude;
delete vars_to_tago.Longitude;
}

payload = payload.concat(toTagoFormat(vars_to_tago, serie));
if (location) payload.push(location);
// payload.push({ variable: 'payload_raw', value: data, serie }); // uncomment this line to maintain the raw payload.

// Here's an example of how to add unit to a temperature variable. You can replicate the following code to do other changes
// Ex:
// const temp_var = payload.find(x => x.variable == 'temperature');
// if (temp_var) { temp_var.unit = "C"; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable unicorn/numeric-separators-style */
import { describe, expect, test } from "vitest";

import { decoderRun } from "../../../../../src/functions/decoder-run";

const file_path =
"decoders/connector/digital-matter/matter-oyster-sigfox/v1.0.0/payload.js";

function preparePayload(payloadHex, port) {
let payload = [
{ variable: "payload", value: payloadHex },
{ variable: "fport", value: port },
];
payload = decoderRun(file_path, { payload });
const parse_error = payload.find((item) => item.variable === "parse_error");
return {
payload,
parse_error,
};
}

describe("Shall not be parsed", () => {
let payload = [
{ variable: "shallnotpass", value: "04096113950292" },
{ variable: "fport", value: 9 },
];
payload = decoderRun(file_path, { payload });
test("Output Result", () => {
expect(Array.isArray(payload)).toBe(true);
});

test("Not parsed Result", () => {
expect(payload).toEqual([
{ variable: "shallnotpass", value: "04096113950292" },
{ variable: "fport", value: 9 },
]);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions decoders/connector/digital-matter/matter-oyster/connector.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "../../../../schema/connector.json",
"name": "Oyster Lora GPS",
"images": {
"logo": "./assets/logo.png"
},
"versions": {
"v1.0.0": {
"src": "./v1.0.0/payload.js",
"manifest": "./v1.0.0/payload-config.jsonc"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Compact Long-Life Battery powered GPS asset tracking over LoRaWAN
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "../../../../../schema/connector_details.json",
"description": "../description.md",
"install_text": "##\nThe Oyster is a compact, rugged GPS tracking device that has been designed for locating and tracking non-powered assets such as containers, trailers, skip bins, and other assets where super-long battery life is required without sacrificing the frequency of updates and performance.\n * IP67 Rugged weather-proof housing.\n * Powered by 3 x AA Batteries with up to 5 years battery life.\n * High-precision GPS/GLONASS tracking device tracks assets when they're on the move and enters sleep mode when stationary to save power.\n * Small, Compact and easy to install and conceal.\n * Configure by USB cable \n",
"install_end_text": "",
"device_annotation": "Install the dashboard template: http://admin.tago.io/template/5d2cd07d8a146c002105bdf6",
"device_parameters": [],
"networks": [
"../../../../network/lorawan-actility/v1.0.0/payload.js",
"../../../../network/lorawan-chirpstack/v1.0.0/payload.js",
"../../../../network/lorawan-citykinect/v1.0.0/payload.js",
"../../../../network/lorawan-everynet/v1.0.0/payload.js",
"../../../../network/lorawan-helium/v1.0.0/payload.js",
"../../../../network/lorawan-kerlink/v1.0.0/payload.js",
"../../../../network/lorawan-loriot/v1.0.0/payload.js",
"../../../../network/lorawan-machineq/v1.0.0/payload.js",
"../../../../network/lorawan-orbiwise/v1.0.0/payload.js",
"../../../../network/lorawan-senet/v1.0.0/payload.js",
"../../../../network/lorawan-swisscom/v1.0.0/payload.js",
"../../../../network/lorawan-tektelic/v1.0.0/payload.js",
"../../../../network/lorawan-ttittn-v3/v1.0.0/payload.js",
"../../../../network/lorawan-brdot/v1.0.0/payload.js"
]
}
Loading
Loading