MeteoWind 2021
This commit is contained in:
Generated
+2
@@ -0,0 +1,2 @@
|
||||
# Default ignored files
|
||||
.idea
|
||||
@@ -0,0 +1,83 @@
|
||||
var pos = 0;
|
||||
var bindata = "";
|
||||
|
||||
var ConvertBase = function (num) {
|
||||
return {
|
||||
from : function (baseFrom) {
|
||||
return {
|
||||
to : function (baseTo) {
|
||||
return parseInt(num, baseFrom).toString(baseTo);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function pad(num) {
|
||||
var s = "0000000" + num;
|
||||
return s.slice(-8);
|
||||
}
|
||||
|
||||
ConvertBase.dec2bin = function (num) {
|
||||
return pad(ConvertBase(num).from(10).to(2));
|
||||
};
|
||||
|
||||
ConvertBase.bin2dec = function (num) {
|
||||
return ConvertBase(num).from(2).to(10);
|
||||
};
|
||||
|
||||
function data2bits(data) {
|
||||
var binary = "";
|
||||
for(var i=0; i<data.length; i++) {
|
||||
binary += ConvertBase.dec2bin(data[i]);
|
||||
}
|
||||
return binary;
|
||||
}
|
||||
|
||||
function bitShift(bits) {
|
||||
var num = ConvertBase.bin2dec(bindata.substr(pos, bits));
|
||||
pos += bits;
|
||||
return Number(num);
|
||||
}
|
||||
|
||||
function precisionRound(number, precision) {
|
||||
var factor = Math.pow(10, precision);
|
||||
return Math.round(number * factor) / factor;
|
||||
}
|
||||
|
||||
function Decoder(fPort, bytes, variables) {
|
||||
bindata = data2bits(bytes);
|
||||
|
||||
if(bytes.length != 9) return {"status": "ERROR", "description": "9 bytes are required"};
|
||||
|
||||
Type = bitShift(2);
|
||||
Battery = precisionRound(bitShift(5)*0.05+3, 1);
|
||||
Wind_ave10 = precisionRound(bitShift(9)*0.1, 1);
|
||||
Wind_max10 = Wind_ave10 + precisionRound(bitShift(9)*0.1, 1);
|
||||
Wind_min10 = Wind_ave10 - precisionRound(bitShift(9)*0.1, 1);
|
||||
Dir_ave10 = precisionRound(bitShift(9)*1, 1);
|
||||
Dir_max10 = precisionRound(bitShift(9)*1, 1);
|
||||
Dir_hi10 = precisionRound(bitShift(8)*1, 1);
|
||||
Dir_lo10 = precisionRound(bitShift(8)*1, 1);
|
||||
|
||||
decoded = {
|
||||
"Type": Type,
|
||||
"Battery": Battery,
|
||||
"Wind_ave10": Wind_ave10,
|
||||
"Wind_max10": Wind_max10,
|
||||
"Wind_min10": Wind_min10,
|
||||
"Dir_ave10": Dir_ave10,
|
||||
"Dir_max10": Dir_max10,
|
||||
"Dir_hi10": Dir_hi10,
|
||||
"Dir_lo10": Dir_lo10,
|
||||
};
|
||||
|
||||
return decoded;
|
||||
|
||||
}
|
||||
|
||||
function decodeUplink(input) {
|
||||
return {
|
||||
data: Decoder(input.fPort, input.bytes, input.variables)
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user