Skip to content

Commit

Permalink
Enginko (#491)
Browse files Browse the repository at this point in the history
* added mcf88 devices

* added mcf88 devices

* Rename .yml to .yaml

* Format and fix strings

* mcf88 sensors updated

* mcf88 sensors updated

* mcf88 new sensors added

* mcf88 sensors added

* mcf88 sensors revised

* mcf88 sensors revised code

* mcf88 sensors revised type

* Small fixes

* Format files

* mcf88 sensors revised filename

* mcf88 sensors revised filename

* updated decode functions

* deleted mcf88, added enginko

* readdedd mcf88 folder

* Aggiunto LW22PLG

* Modificata temp

* Stile

* Added level sensors

* Changed sensors type

* Added level

* Minime sistemazioni di decodel-level.js

* Added MCF-LW06485

* Updated

* Updated

* Updated

* Updated

* Merge branch 'enginko-dev' into enginko pt.2

* Merge branch 'enginko-dev' into enginko pt.3

* Merge branch 'enginko-dev' into enginko, prettied

* Restored vendor mcf88

* Fixed an issue with mcf88 logo

* Fixed an issue with mcf88 logo

* validate fmt

Co-authored-by: Franco Zampicinini <[email protected]>
Co-authored-by: Johan Stokking <[email protected]>
Co-authored-by: francozampicinini <[email protected]>
Co-authored-by: Stefano Colognato <[email protected]>
Co-authored-by: Jaime Trinidad <[email protected]>
  • Loading branch information
6 people authored Aug 25, 2022
1 parent ad6d08c commit 8d56fc3
Show file tree
Hide file tree
Showing 40 changed files with 1,719 additions and 1,045 deletions.
Binary file added vendor/enginko/EGK-LW20L00.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendor/enginko/EGK-LW20W00.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
446 changes: 446 additions & 0 deletions vendor/enginko/decodel-level.js

Large diffs are not rendered by default.

252 changes: 100 additions & 152 deletions vendor/enginko/decoder-digital.js

Large diffs are not rendered by default.

578 changes: 229 additions & 349 deletions vendor/enginko/decoder-environmental.js

Large diffs are not rendered by default.

206 changes: 206 additions & 0 deletions vendor/enginko/decoder-level.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
'use strict';

function decodeUplink(payload) {
payload = TTNfrom(payload);
var uplinkId = payload.substring(0, 2);
var content;

switch (uplinkId.toUpperCase()) {
case '01':
content = parseTimeSync(payload.trim());
break;

case '04':
content = parseTER(payload.trim());
break;

case '09':
content = parseMetering(payload.trim());
break;

case '10':
content = parseDigitalData(payload.trim());
break;

case '12':
content = parseVOC(payload.trim(), true); //true is for new sensor

break;

case '13':
content = parseCo2(payload.trim(), true); //true is for new sensor

break;

case '0A':
content = parseIO(payload.trim());
break;

case '0B':
content = parseReportData(payload.trim());
break;

case '0C':
content = parseVOC(payload.trim(), false); //false is for new sensor

break;

case '0D':
content = parseAnalog(payload.trim());
break;

case '0E':
content = parseCo2(payload.trim(), false); //false is for new sensor

break;

case '14':
content = parseLevel(payload.trim(), false); //false is for new sensor

break;

default:
content = null;
break;
}

return TTNto(content);
}

function TTNfrom(TTNpayload) {
var obj;

if (typeof TTNpayload === 'string') {
obj = JSON.parse(TTNpayload);
} else {
obj = JSON.parse(JSON.stringify(TTNpayload));
}

var fPort = obj.fPort;
var payload = '';

for (var i = 0; i < obj.bytes.length; i++) {
payload += parseInt(obj.bytes[i], 10).toString(16).padStart(2, '0');
}

return payload;
}

function TTNto(content) {
var TTNcontent = {};

if (content !== null) {
for (var i = 0; i < content.length; i++) {
TTNcontent[content[i].variable] = content[i].value;
}

return {
data: TTNcontent,
};
} else {
return {
data: content,
warnings: [],
errors: ['Error on decoding payload'],
};
}
}

function parseDate(payload) {
var date = new Date();
var binary = Number(parseInt(reverseBytes(payload), 16))
.toString(2)
.padStart(32, '0');
var year = parseInt(binary.substring(0, 7), 2) + 2000;
var month = parseInt(binary.substring(7, 11), 2);
var day = parseInt(binary.substring(11, 16), 2);
var hour = parseInt(binary.substring(16, 21), 2);
var minute = parseInt(binary.substring(21, 27), 2);
var second = parseInt(binary.substring(27, 32), 2) * 2;
date = new Date(year, month - 1, day, hour, minute, second, 0).toLocaleString();
return date;
}

function parseSignedInt(bytes) {
bytes = reverseBytes(bytes);
var rno = hexStringToByteArray(bytes);
var n = 0;

if (rno.length === 4) {
n = ((rno[0] << 24) & 0xff000000) | ((rno[1] << 16) & 0x00ff0000) | ((rno[2] << 8) & 0x0000ff00) | ((rno[3] << 0) & 0x000000ff);
}

return n;
}

function parseUnsignedInt(bytes) {
bytes = reverseBytes(bytes);
var n = parseInt(bytes, 16);
return n;
}

function parseSignedShort(bytes) {
bytes = reverseBytes(bytes);
var rno = hexStringToByteArray(bytes);
var n = 0;

if (rno.length === 2) {
var n = (((rno[0] << 8) | rno[1]) << 16) >> 16;
}

return n;
}

function parseUnsignedShort(bytes) {
bytes = reverseBytes(bytes);
var rno = hexStringToByteArray(bytes);
var n = 0;

if (rno.length === 2) {
n = ((rno[0] << 8) & 0x0000ff00) | ((rno[1] << 0) & 0x000000ff);
}

return n;
}

function reverseBytes(bytes) {
var reversed = bytes;

if (bytes.length % 2 === 0) {
reversed = '';

for (var starting = 0; starting + 2 <= bytes.length; starting += 2) {
reversed = bytes.substring(starting, starting + 2) + reversed;
}
}

return reversed;
}

function hexStringToByteArray(s) {
for (var bytes = [], c = 0; c < s.length; c += 2) {
bytes.push(parseInt(s.substr(c, 2), 16));
}

return bytes;
}

function parseDateByte(payload) {
var date = new Date();
var binary = (payload[0] & 0xff) + ((payload[1] << 8) & 0xff00) + ((payload[2] << 16) & 0xff0000) + ((payload[3] << 24) & 0xff000000);
var second = binary & 0x1f;
second *= 2;
binary = binary >> 5;
var minute = binary & 0x3f;
binary = binary >> 6;
var hour = binary & 0x1f;
binary = binary >> 5;
var day = binary & 0x1f;
binary = binary >> 5;
var month = binary & 0x0f;
binary = binary >> 4;
var year = binary & 0x7f;
year += 2000;
date = new Date(year, month - 1, day, hour, minute, second, 0).toLocaleString();
return date;
}
Loading

0 comments on commit 8d56fc3

Please sign in to comment.