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

Updated bob to v2 #312

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 10 additions & 5 deletions types/watecco/bob/learning.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"title": "Device",
"description": "Device type",
"type": "string",
"enum": ["MPU", "KX"],
"enum": [
"MPU",
"KX"
],
"hideFromKpis": true
},
"learningPercentage": {
Expand Down Expand Up @@ -39,7 +42,10 @@
"title": "Learning",
"description": "Learning from scratch or additional learning",
"type": "string",
"enum": ["ZERO", "ADDITIONAL_LEARNING"],
"enum": [
"ZERO",
"ADDITIONAL_LEARNING"
],
"hideFromKpis": true
},
"peakFrequencyIndex": {
Expand Down Expand Up @@ -288,6 +294,5 @@
"description": "FFT Signal 39",
"hideFromKpis": true
}
},
"required": ["learningPerc", "vibration", "temperature", "learningFrom"]
}
}
}
17 changes: 14 additions & 3 deletions types/watecco/bob/lifecycle.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@
"title": "Sensor state",
"type": "string",
"description": "Sensor messages which indicate the state.",
"enum": ["SENSOR_START", "SENSOR_STOP", "MACHINE_STOP", "MACHINE_START"],
"enum": [
"SENSOR_START",
"SENSOR_STOP",
"SENSOR_START_NO_VIBRATION",
"SENSOR_STOP_NO_VIBRATION",
"SENSOR_LEARN_KEEPALIVE",
"SENSOR_STOP_WITH_ERASE",
"MACHINE_STOP",
"MACHINE_START"
],
"hideFromKpis": true
},
"batteryLevel": {
"$ref": "https://raw.githubusercontent.com/akenza-io/device-type-library/main/data-models/device/schema.json#/$defs/batteryLevel/percent"
}
},
"required": ["batteryLevel"]
}
"required": [
"batteryLevel"
]
}
26 changes: 23 additions & 3 deletions types/watecco/bob/uplink.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ function consume(event) {
data.learningFrom = "ADDITIONAL_LEARNING";
}
data.peakFrequencyIndex = Bits.bitsToUnsigned(bits.substr(40, 8)) + 1;
data.peakFrequency = (data.peakFrequencyIndex * frequency) / 256;

if (data.peakFrequencyIndex < 128) {
data.peakFrequency = (data.peakFrequencyIndex * frequency) / 256;
} else if (data.peakFrequencyIndex >= 128) {
data.peakFrequency =
(((Bits.bitsToUnsigned(bits.substr(40, 8)) & 0x7) + 1) * frequency) /
256;
}
// FFT Signal
for (let i = 8; i <= 39; i++) {
data[`fft${i - 7}`] =
Expand Down Expand Up @@ -71,8 +78,13 @@ function consume(event) {
// Frequency_index

data.peakFrequencyIndex = Bits.bitsToUnsigned(bits.substr(88, 8)) + 1;

data.peakFrequency = (data.peakFrequencyIndex * frequency) / 256;
if (data.peakFrequencyIndex < 128) {
data.peakFrequency = (data.peakFrequencyIndex * frequency) / 256;
} else if (data.peakFrequencyIndex >= 128) {
data.peakFrequency =
(((Bits.bitsToUnsigned(bits.substr(88, 8)) & 0x7) + 1) * frequency) /
256;
}

// Anomaly level time 0 - 10%, ok frequencies
data.goodVibration = round(
Expand Down Expand Up @@ -174,6 +186,14 @@ function consume(event) {
sensorState = "SENSOR_START";
} else if (sensorState === 101) {
sensorState = "SENSOR_STOP";
} else if (sensorState === 104) {
sensorState = "SENSOR_START_NO_VIBRATION";
} else if (sensorState === 105) {
sensorState = "SENSOR_STOP_NO_VIBRATION";
} else if (sensorState === 106) {
sensorState = "SENSOR_LEARN_KEEPALIVE";
} else if (sensorState === 110) {
sensorState = "SENSOR_STOP_WITH_ERASE";
} else if (sensorState === 125) {
sensorState = "MACHINE_STOP";
} else if (sensorState === 126) {
Expand Down
75 changes: 75 additions & 0 deletions types/watecco/bob/uplink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,82 @@ describe("Watecco BoB Uplink", () => {
});
});

let learningSchema = null;
before((done) => {
utils
.loadSchema(`${__dirname}/learning.schema.json`)
.then((parsedSchema) => {
learningSchema = parsedSchema;
done();
});
});

describe("consume()", () => {
it("should decode the Watecco BoB learning uplink", () => {
const data = {
data: {
port: 1,
payloadHex:
"6c00001f3f013601407f5b4467393c303176301c332b61345b7e303e2318373f333f2231444a4245",
},
};

utils.expectEmits((type, value) => {
assert.equal(type, "sample");
assert.isNotNull(value);
assert.typeOf(value.data, "object");

assert.equal(value.topic, "learning");

assert.equal(value.data.fft1, 0.013124353692099727);
assert.equal(value.data.fft2, 0.026043639357760395);
assert.equal(value.data.fft3, 0.0186611904059543);
assert.equal(value.data.fft4, 0.013944625797855959);
assert.equal(value.data.fft5, 0.021122006723222998);
assert.equal(value.data.fft6, 0.011688877507026319);
assert.equal(value.data.fft7, 0.012304081586343494);
assert.equal(value.data.fft8, 0.009843265269074794);
assert.equal(value.data.fft9, 0.010048333295513854);
assert.equal(value.data.fft10, 0.02419802711980887);

assert.equal(value.data.fft11, 0.009843265269074794);
assert.equal(value.data.fft12, 0.005741904740293631);
assert.equal(value.data.fft13, 0.01045846934839197);
assert.equal(value.data.fft14, 0.008817925136879503);
assert.equal(value.data.fft15, 0.019891598564588647);
assert.equal(value.data.fft16, 0.010663537374831026);
assert.equal(value.data.fft17, 0.0186611904059543);
assert.equal(value.data.fft18, 0.025838571331321336);
assert.equal(value.data.fft19, 0.009843265269074794);
assert.equal(value.data.fft20, 0.01271421763922161);

assert.equal(value.data.fft21, 0.007177380925367038);
assert.equal(value.data.fft22, 0.004921632634537397);
assert.equal(value.data.fft23, 0.011278741454148202);
assert.equal(value.data.fft24, 0.012919285665660668);
assert.equal(value.data.fft25, 0.01045846934839197);
assert.equal(value.data.fft26, 0.012919285665660668);
assert.equal(value.data.fft27, 0.006972312898927979);
assert.equal(value.data.fft28, 0.010048333295513854);
assert.equal(value.data.fft29, 0.013944625797855959);
assert.equal(value.data.fft30, 0.015175033956490308);

assert.equal(value.data.fft31, 0.013534489744977844);
assert.equal(value.data.fft32, 0.014149693824295017);

assert.equal(value.data.learningFrom, "ZERO");
assert.equal(value.data.learningPercentage, 0);
assert.equal(value.data.peakFrequency, 6.25);
assert.equal(value.data.peakFrequencyIndex, 2);
assert.equal(value.data.temperature, 24);
assert.equal(value.data.vibrationLevel, 0.026043639357760395);

utils.validateSchema(value.data, learningSchema, { throwError: true });
});

consume(data);
});

it("should decode the Watecco BoB report uplink", () => {
const data = {
data: {
Expand Down
Loading