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 3 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.
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 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,25 @@
{
"$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": "",
"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-senra/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"
]
}
135 changes: 135 additions & 0 deletions decoders/connector/digital-matter/matter-oyster/v1.0.0/payload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// e.g. parseSigFox('10b67dcc0006efda3d9816c2')

// In an attempt to make the code clearer, I will not be using ArrayBuffer
const ignore_vars = [
"device_addr",
"port",
"duplicate",
"network",
"packet_hash",
"application",
"device",
"packet_id",
];

// Decode an uplink message from an array of bytes to an object of fields
function Decoder(bytes, port) {
bytes = Buffer.from(bytes, "hex");
var decoded = {};
if (port === 1) {
decoded.type = "position";
decoded.latitudeDeg =
bytes[0] + bytes[1] * 256 + bytes[2] * 65536 + bytes[3] * 16777216;
if (decoded.latitudeDeg >= 0x80000000)
// 2^31
decoded.latitudeDeg -= 0x100000000; // 2^32
decoded.latitudeDeg /= 1e7;

decoded.longitudeDeg =
bytes[4] + bytes[5] * 256 + bytes[6] * 65536 + bytes[7] * 16777216;
if (decoded.longitudeDeg >= 0x80000000)
// 2^31
decoded.longitudeDeg -= 0x100000000; // 2^32
decoded.longitudeDeg /= 1e7;
decoded.inTrip = (bytes[8] & 0x1) !== 0 ? true : false;
decoded.fixFailed = (bytes[8] & 0x2) !== 0 ? true : false;
decoded.headingDeg = (bytes[8] >> 2) * 5.625;

decoded.speedKmph = bytes[9];
decoded.batV = bytes[10] * 0.025;
decoded.manDown = null;
} else if (port === 4) {
decoded.type = "Extended GPS Data Record";
decoded.latitudeDeg = bytes[0] + bytes[1] * 256 + bytes[2] * 65536;
if (decoded.latitudeDeg >= 0x800000)
// 2^23
decoded.latitudeDeg -= 0x1000000; // 2^24
decoded.latitudeDeg *= 256e-7;

decoded.longitudeDeg = bytes[3] + bytes[4] * 256 + bytes[5] * 65536;
if (decoded.longitudeDeg >= 0x800000)
// 2^23
decoded.longitudeDeg -= 0x1000000; // 2^24
decoded.longitudeDeg *= 256e-7;
decoded.headingDeg = (bytes[6] & 0x7) * 45;
decoded.speedKmph = (bytes[6] >> 3) * 5;
decoded.batV = bytes[7] * 0.025;
decoded.inTrip = (bytes[8] & 0x1) !== 0 ? true : false;
decoded.fixFailed = (bytes[8] & 0x2) !== 0 ? true : false;
decoded.manDown = (bytes[8] & 0x4) !== 0 ? true : false;
} else if (port === 2) {
decoded.type = "downlink ack";
decoded.sequence = bytes[0] & 0x7f;
decoded.accepted = (bytes[0] & 0x80) !== 0 ? true : false;
decoded.fwMaj = bytes[1];
decoded.fwMin = bytes[2];
} else if (port === 3) {
decoded.type = "stats";
decoded.initialBatV = 4.0 + 0.1 * (bytes[0] & 0xf);
decoded.txCount = 32 * ((bytes[0] >> 4) + (bytes[1] & 0x7f) * 16);
decoded.tripCount =
32 * ((bytes[1] >> 7) + (bytes[2] & 0xff) * 2 + (bytes[3] & 0x0f) * 512);
decoded.gpsSuccesses = 32 * ((bytes[3] >> 4) + (bytes[4] & 0x3f) * 16);
decoded.gpsFails = 32 * ((bytes[4] >> 6) + (bytes[5] & 0x3f) * 4);
decoded.aveGpsFixS = 1 * ((bytes[5] >> 6) + (bytes[6] & 0x7f) * 4);
decoded.aveGpsFailS = 1 * ((bytes[6] >> 7) + (bytes[7] & 0xff) * 2);
decoded.aveGpsFreshenS = 1 * ((bytes[7] >> 8) + (bytes[8] & 0xff) * 1);
decoded.wakeupsPerTrip = 1 * ((bytes[8] >> 8) + (bytes[9] & 0x7f) * 1);
decoded.uptimeWeeks = 1 * ((bytes[9] >> 7) + (bytes[10] & 0xff) * 2);
}
return decoded;
}

function toTagoFormat(object_item, serie, prefix = "") {
const result = [];
for (const key in object_item) {
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 === "payload_raw" ||
x.variable === "payload_hex" ||
x.variable === "payload" ||
x.variable === "data"
);
const port = payload.find(
(x) =>
x.variable === "port" ||
x.variable === "fport" ||
x.variable === "FPort" ||
x.variable === "fPort"
);

if (data) {
const serie = data.serie || new Date().getTime();
data = data.value;
const vars_to_tago = Decoder(data, port.value);

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

payload = payload.concat(toTagoFormat(vars_to_tago, serie));
if (location) payload.push(location);
payload = payload.filter((x) => !ignore_vars.includes(x.variable));
}
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/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 },
]);
});
});