diff --git a/nodejs/c8y-codec-interface/package-lock.json b/nodejs/c8y-codec-interface/package-lock.json index 7b1b82c81..b44de31bc 100644 --- a/nodejs/c8y-codec-interface/package-lock.json +++ b/nodejs/c8y-codec-interface/package-lock.json @@ -14,7 +14,6 @@ "express": "^4.17.1", "inversify": "^5.0.5", "node-cron": "^3.0.0", - "reflect-metadata": "^0.1.13", "source-map-support": "^0.5.19", "winston": "^3.7.2" }, @@ -24,8 +23,9 @@ "concurrently": "^6.0.0", "jest": "^26.6.3", "nodemon": "^2.0.7", + "reflect-metadata": "^0.1.13", "ts-node": "^9.1.1", - "typescript": "^4.2.3" + "typescript": "^4.2.4" } }, "node_modules/@ampproject/remapping": { @@ -6013,7 +6013,8 @@ "node_modules/reflect-metadata": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", - "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", + "dev": true }, "node_modules/regex-not": { "version": "1.0.2", @@ -12749,7 +12750,8 @@ "reflect-metadata": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", - "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", + "dev": true }, "regex-not": { "version": "1.0.2", diff --git a/nodejs/lora-codec-adeunis/src/AdeunisCodec.spec.ts b/nodejs/lora-codec-adeunis/src/AdeunisCodec.spec.ts index ea04f1db9..3ff744f5f 100644 --- a/nodejs/lora-codec-adeunis/src/AdeunisCodec.spec.ts +++ b/nodejs/lora-codec-adeunis/src/AdeunisCodec.spec.ts @@ -4,7 +4,10 @@ import { IManagedObject } from "@c8y/client"; class TestCodec extends AdeunisCodec { testDecode(model: string, payload: string): C8YData { - let mo: Partial = { id: "test" }; + let mo: Partial = { + id: "test", + c8y_RequiredAvailability: { responseInterval: 10 }, + }; return this._decode(null, mo, model, 1, new Date(), payload); } } @@ -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); + }); }); diff --git a/nodejs/lora-codec-adeunis/src/AdeunisCodec.ts b/nodejs/lora-codec-adeunis/src/AdeunisCodec.ts index 3175cfb63..268b42f3a 100644 --- a/nodejs/lora-codec-adeunis/src/AdeunisCodec.ts +++ b/nodejs/lora-codec-adeunis/src/AdeunisCodec.ts @@ -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) }; @@ -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, @@ -149,7 +163,6 @@ export class AdeunisCodec extends DeviceCodec { channel.index + value, new Date(time.getTime() + result.baseTime * i * 60000) ); - i++; }); }); }