INITIAL
This commit is contained in:
86
barani-meteo-helix.js
Normal file
86
barani-meteo-helix.js
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
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 != 11) return {"status": "ERROR", "description": "11 bytes are required"}
|
||||||
|
|
||||||
|
Type = bitShift(2);
|
||||||
|
Battery = precisionRound(bitShift(5)*0.05+3, 2);
|
||||||
|
Temperature = precisionRound(bitShift(11)*0.1-100, 1);
|
||||||
|
T_min = precisionRound(Temperature - bitShift(6)*0.1, 1);
|
||||||
|
T_max = precisionRound(Temperature + bitShift(6)*0.1, 1);
|
||||||
|
Humidity = precisionRound(bitShift(9)*0.2, 1);
|
||||||
|
Pressure = bitShift(14)*5+50000;
|
||||||
|
Irradiation = bitShift(10)*2;
|
||||||
|
Irr_max = Irradiation + bitShift(9)*2;
|
||||||
|
Rain = precisionRound(bitShift(8), 1);
|
||||||
|
Rain_min_time = precisionRound(bitShift(8), 1);
|
||||||
|
|
||||||
|
decoded = {
|
||||||
|
"Type": Type,
|
||||||
|
"Battery": Battery,
|
||||||
|
"Temperature": Temperature,
|
||||||
|
"T_min": T_min ,
|
||||||
|
"T_max": T_max,
|
||||||
|
"Humidity": Humidity,
|
||||||
|
"Pressure": Pressure,
|
||||||
|
"Irradiation": Irradiation,
|
||||||
|
"Irr_max": Irr_max,
|
||||||
|
"Rain": Rain,
|
||||||
|
"Rain min time": Rain_min_time
|
||||||
|
};
|
||||||
|
|
||||||
|
return decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeUplink(input) {
|
||||||
|
return {
|
||||||
|
data: Decoder(input.fPort, input.bytes, input.variables)
|
||||||
|
};
|
||||||
|
}
|
||||||
89
barani-meteo-wind-2022.js
Normal file
89
barani-meteo-wind-2022.js
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
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 != 10) return {"status": "ERROR", "description": "10 bytes are required"};
|
||||||
|
|
||||||
|
Index = precisionRound(bitShift(8)*1, 1);
|
||||||
|
Battery = precisionRound(bitShift(3)*0.2+3, 1);
|
||||||
|
Wind_ave = precisionRound(bitShift(9)*0.1, 1);
|
||||||
|
Wind_3sgust = Wind_ave + precisionRound(bitShift(9)*0.1, 1);
|
||||||
|
Wind_3smin = Wind_ave - precisionRound(bitShift(9)*0.1, 1);
|
||||||
|
Wind_stdev = precisionRound(bitShift(8)*0.1, 1);
|
||||||
|
Dir_ave = precisionRound(bitShift(9)*1, 1);
|
||||||
|
Dir_3sgust = precisionRound(bitShift(9)*1, 1);
|
||||||
|
Dir_stdev = precisionRound(bitShift(7)*1, 1);
|
||||||
|
Gust_time = precisionRound(bitShift(7)*5, 1);
|
||||||
|
Vector_scalar = precisionRound(bitShift(1)*1, 1);
|
||||||
|
Alarm_sent = precisionRound(bitShift(1)*1, 1);
|
||||||
|
|
||||||
|
decoded = {
|
||||||
|
"Index": Index,
|
||||||
|
"Battery": Battery,
|
||||||
|
"Wind_ave": Wind_ave,
|
||||||
|
"Wind_3sgust": Wind_3sgust,
|
||||||
|
"Wind_3smin": Wind_3smin,
|
||||||
|
"Wind_stdev": Wind_stdev,
|
||||||
|
"Dir_ave": Dir_ave,
|
||||||
|
"Dir_3sgust": Dir_3sgust,
|
||||||
|
"Dir_stdev": Dir_stdev,
|
||||||
|
"Gust_time": Gust_time,
|
||||||
|
"Vector_scalar": Vector_scalar,
|
||||||
|
"Alarm_sent": Alarm_sent,
|
||||||
|
};
|
||||||
|
|
||||||
|
return decoded;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeUplink(input) {
|
||||||
|
return {
|
||||||
|
data: Decoder(input.fPort, input.bytes, input.variables)
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user