Skip to content

Commit

Permalink
added support for Adeunis Pulse 4
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoder committed Nov 9, 2023
1 parent 07a9347 commit 3b28a50
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
10 changes: 6 additions & 4 deletions nodejs/c8y-codec-interface/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion nodejs/lora-codec-adeunis/src/AdeunisCodec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { IManagedObject } from "@c8y/client";

class TestCodec extends AdeunisCodec {
testDecode(model: string, payload: string): C8YData {
let mo: Partial<IManagedObject> = { id: "test" };
let mo: Partial<IManagedObject> = {
id: "test",
c8y_RequiredAvailability: { responseInterval: 10 },
};
return this._decode(null, mo, model, 1, new Date(), payload);
}
}
Expand Down Expand Up @@ -34,4 +37,13 @@ describe("Test Adeunis Codec", () => {
console.log(c8yData);
expect(c8yData.measurements.length).toBe(2);
});
test("Test Pulse 4 with historic data", () => {
let codec: TestCodec = new TestCodec(null);
let c8yData: C8YData = codec.testDecode(
"pulse4",
"5A8400000127000100020003000414ABA3E9"
);
console.log(c8yData);
expect(c8yData.measurements.length).toBe(5);
});
});
37 changes: 25 additions & 12 deletions nodejs/lora-codec-adeunis/src/AdeunisCodec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,30 @@ export class AdeunisCodec extends DeviceCodec {
time
);
}
if (result.counterValues) {
c8yData.addMeasurements(
mo,
"Pulse",
["Channel A", "Channel B"],
["", ""],
[result.counterValues[0], result.counterValues[1]],
time
);
if (
(result.type?.includes("0x5a") || result.type?.includes("0x5b")) &&
result.counterValues
) {
if (!mo.c8y_RequiredAvailability?.responseInterval) {
console.error("Device must first retrieve its configuration.");
}
let channel = "Channel A";
if (result.type?.includes("0x5b")) {
channel = "Channel B";
}
result.counterValues.forEach((c, i) => {
c8yData.addMeasurement(
mo,
"Pulse",
channel,
"",
c,
new Date(
time.getTime() -
mo["c8y_RequiredAvailability"]["responseInterval"] * i * 60000
)
);
});
}
if (result.type?.includes("configuration")) {
mo["c8y_Configuration"] = { config: JSON.stringify(result) };
Expand Down Expand Up @@ -139,8 +154,7 @@ export class AdeunisCodec extends DeviceCodec {
}
if (result.type?.includes("0x48") && result.channels) {
result.channels.forEach((channel) => {
let i = 1;
channel.deltaValues.forEach((value) => {
channel.deltaValues.forEach((value, i) => {
c8yData.addMeasurement(
mo,
channel.name,
Expand All @@ -149,7 +163,6 @@ export class AdeunisCodec extends DeviceCodec {
channel.index + value,
new Date(time.getTime() + result.baseTime * i * 60000)
);
i++;
});
});
}
Expand Down

0 comments on commit 3b28a50

Please sign in to comment.