Power factor new calculation; new bytesToInt function with uint and bigendian
This commit is contained in:
parent
5540cee8ec
commit
1012544193
2 changed files with 114 additions and 127 deletions
|
|
@ -2616,7 +2616,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
//účinník
|
//účinník
|
||||||
else if (register == 77) {
|
else if (register == 77) {
|
||||||
let power_factor = Math.cos(bytesToInt(bytes) * 0.1).toFixed(2);
|
let power_factor = Math.cos(bytesToInt(bytes) * 0.1 * (Math.PI / 180)).toFixed(2);
|
||||||
values["power_factor"] = Number(power_factor);
|
values["power_factor"] = Number(power_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2629,8 +2629,7 @@ exports.install = function(instance) {
|
||||||
//energia
|
//energia
|
||||||
else if (register == 79) {
|
else if (register == 79) {
|
||||||
let energy = bytesToInt(bytes);
|
let energy = bytesToInt(bytes);
|
||||||
//Energiu treba reportovať v kWh -> delit 1000
|
values["energy"] = energy / 1000; //energia v kWh -> delit 1000
|
||||||
values["energy"] = energy / 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//doba života
|
//doba života
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,19 @@
|
||||||
function bytesToInt(bytes, numberOfBytes)
|
function bytesToInt(bytes, numberOfBytes) {
|
||||||
{
|
|
||||||
let buffer = [];
|
let buffer = [];
|
||||||
if(Array.isArray(bytes))
|
if (Array.isArray(bytes)) {
|
||||||
{
|
|
||||||
buffer = bytes.slice(0);
|
buffer = bytes.slice(0);
|
||||||
if(numberOfBytes != undefined)
|
if (numberOfBytes != undefined) {
|
||||||
{
|
|
||||||
buffer = bytes.slice(bytes.length - numberOfBytes);
|
buffer = bytes.slice(bytes.length - numberOfBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else buffer.push(bytes);
|
else buffer.push(bytes);
|
||||||
|
|
||||||
//var decimal = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
|
let result = 0;
|
||||||
let l = (buffer.length - 1) * 8;
|
for (let i = 0; i < buffer.length; i++) {
|
||||||
|
result = (result << 8) | buffer[i];
|
||||||
let decimal = 0;
|
|
||||||
for(let i = 0; i < buffer.length; i++)
|
|
||||||
{
|
|
||||||
var s = buffer[i] << l;
|
|
||||||
if(l < 8) s = buffer[i]
|
|
||||||
decimal = decimal + s;
|
|
||||||
|
|
||||||
l = l - 8;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return decimal;
|
return result >>> 0; //ensure it's an unsigned 32-bit number
|
||||||
}
|
}
|
||||||
|
|
||||||
function resizeArray(arr, newSize, defaultValue) {
|
function resizeArray(arr, newSize, defaultValue) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue