Skip to content

Commit

Permalink
added support for Adeunis pulse historic data and analog
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoder committed Nov 7, 2023
1 parent 4b3f4cf commit 07a9347
Show file tree
Hide file tree
Showing 21 changed files with 8,099 additions and 2,755 deletions.
4 changes: 2 additions & 2 deletions nodejs/c8y-codec-interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"jest": "^26.6.3",
"nodemon": "^2.0.7",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
"reflect-metadata": "^0.1.13",
"typescript": "^4.2.4"
},
"dependencies": {
"@c8y/client": "^1016.0.259",
Expand All @@ -30,7 +31,6 @@
"express": "^4.17.1",
"inversify": "^5.0.5",
"node-cron": "^3.0.0",
"reflect-metadata": "^0.1.13",
"winston": "^3.7.2"
}
}
495 changes: 294 additions & 201 deletions nodejs/c8y-codec-interface/src/lora/codec/DeviceCodec.ts

Large diffs are not rendered by default.

154 changes: 93 additions & 61 deletions nodejs/c8y-codec-interface/src/lora/codec/uplink/C8YData.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,103 @@
import {IMeasurementCreate, IEvent, IAlarm, IManagedObject, Severity} from '@c8y/client';
import {
IMeasurementCreate,
IEvent,
IAlarm,
IManagedObject,
Severity,
} from "@c8y/client";

export class C8YData {
measurements: Partial<IMeasurementCreate>[] = [];
events: IEvent[] = [];
alarms: IAlarm[] = [];
alarmsToClear: string[] = [];
morToUpdate?: IManagedObject;

addMeasurement(mor: IManagedObject, fragment: string, series: string, unit: string, value: number, time: Date) {
let m: Partial<IMeasurementCreate> = {
sourceId: mor.id,
type: fragment,
time: time
};
measurements: Partial<IMeasurementCreate>[] = [];
events: IEvent[] = [];
alarms: IAlarm[] = [];
alarmsToClear: string[] = [];
morToUpdate?: Partial<IManagedObject>;

m[fragment] = {};
m[fragment][series] = {"value": value, "unit": unit};
addMeasurement(
mor: Partial<IManagedObject>,
fragment: string,
series: string,
unit: string,
value: number,
time: Date
) {
let m: Partial<IMeasurementCreate> = {
sourceId: mor.id,
type: fragment,
time: time,
};

this.measurements.push(m);
}

addMeasurements(mor: IManagedObject, fragment: string, serieses: string[], units: string[], values: number[], time: Date) {
let m: Partial<IMeasurementCreate> = {
sourceId: mor.id,
type: fragment,
time: time
};
m[fragment] = {};
m[fragment][series] = { value: value, unit: unit };

m[fragment] = {}
for(let i=0;i<serieses.length;i++) {
m[fragment][serieses[i]] = {"value": values[i], "unit": units[i]};
}
this.measurements.push(m);
}

this.measurements.push(m);
}
addMeasurements(
mor: Partial<IManagedObject>,
fragment: string,
serieses: string[],
units: string[],
values: number[],
time: Date
) {
let m: Partial<IMeasurementCreate> = {
sourceId: mor.id,
type: fragment,
time: time,
};

addEvent(mor:IManagedObject, eventType: string, eventText: string, properties: {}, dateTime: Date) {
let event: IEvent = {
source: {
id: mor.id
},
type: eventType,
text: eventText,
time: dateTime.toISOString()
};
if (properties) {
Object.assign(event, properties);
}

this.events.push(event);
m[fragment] = {};
for (let i = 0; i < serieses.length; i++) {
m[fragment][serieses[i]] = { value: values[i], unit: units[i] };
}

addAlarm(mor: IManagedObject, alarmType: string, alarmText: string, severity: Severity, dateTime: Date) {
let alarm: IAlarm = {
source: {
id: mor.id
},
time: dateTime.toISOString(),
text: alarmText,
type: alarmType,
severity: severity
};

this.alarms.push(alarm);
}
this.measurements.push(m);
}

clearAlarm(alarmType: string) {
this.alarmsToClear.push(alarmType);
}
}
addEvent(
mor: Partial<IManagedObject>,
eventType: string,
eventText: string,
properties: {},
dateTime: Date
) {
let event: IEvent = {
source: {
id: mor.id,
},
type: eventType,
text: eventText,
time: dateTime.toISOString(),
};
if (properties) {
Object.assign(event, properties);
}

this.events.push(event);
}

addAlarm(
mor: Partial<IManagedObject>,
alarmType: string,
alarmText: string,
severity: Severity,
dateTime: Date
) {
let alarm: IAlarm = {
source: {
id: mor.id,
},
time: dateTime.toISOString(),
text: alarmText,
type: alarmType,
severity: severity,
};

this.alarms.push(alarm);
}

clearAlarm(alarmType: string) {
this.alarmsToClear.push(alarmType);
}
}
7 changes: 7 additions & 0 deletions nodejs/lora-codec-adeunis/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rm image.tar
rm lora-codec-adeunis.zip
cd ..
docker build . -t lora-codec-adeunis -f lora-codec-adeunis/Dockerfile
cd lora-codec-adeunis
docker save lora-codec-adeunis -o image.tar
zip lora-codec-adeunis image.tar cumulocity.json
4 changes: 4 additions & 0 deletions nodejs/lora-codec-adeunis/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node"
}
Loading

0 comments on commit 07a9347

Please sign in to comment.