746 lines
28 KiB
JavaScript
746 lines
28 KiB
JavaScript
const bit = require('./bit.js');
|
||
|
||
function numberToMonth(num)
|
||
{
|
||
let month = "january";
|
||
if (num == 2)
|
||
month = "february";
|
||
else if (num == 3)
|
||
month = "march";
|
||
else if (num == 4)
|
||
month = "april";
|
||
else if (num == 5)
|
||
month = "may";
|
||
else if (num == 6)
|
||
month = "june";
|
||
else if (num == 7)
|
||
month = "july";
|
||
else if (num == 8)
|
||
month = "august";
|
||
else if (num == 9)
|
||
month = "september";
|
||
else if (num == 10)
|
||
month = "october";
|
||
else if (num == 11)
|
||
month = "november";
|
||
else
|
||
month = "december";
|
||
}
|
||
|
||
function numberToDay(num)
|
||
{
|
||
let day = "monday";
|
||
if (num == 2)
|
||
day = "tuesday";
|
||
else if (num == 3)
|
||
day = "wednessday";
|
||
else if (num == 4)
|
||
day = "thursday";
|
||
else if (num == 5)
|
||
day = "friday";
|
||
else if (num == 6)
|
||
day = "saturday";
|
||
else
|
||
day = "sunday";
|
||
|
||
return day
|
||
}
|
||
|
||
function decodeValue(add, cmd, a, b, c, d){
|
||
|
||
var cmd_pure = bit.band(cmd, 0x7FFF)
|
||
var response = [];
|
||
|
||
console.log("inside decodeValue", add, cmd, cmd_pure, a, b, c, d);
|
||
|
||
if (cmd_pure == 0) { // Status
|
||
if (add == 0) { // Master
|
||
if (bit.band(d,1)>0) {
|
||
response.push( {type: "ERROR", message: "Comunication error"});
|
||
} if (bit.band(d,2)>0) {
|
||
response.push( {type: "ERROR", message: "Init mode active"});
|
||
} if (bit.band(d,4)>0) {
|
||
response.push( {type: "ERROR", message: "Hit detected by accelerometer"});
|
||
}
|
||
}else{ // Slave
|
||
if (bit.band(a,1)>0) {
|
||
response.push( {type: "ERROR", message: "Unread critical event"});
|
||
} if (bit.band(a,2)>0) {
|
||
response.push( {type: "ERROR", message: "Unread non-critical event"});
|
||
} if (bit.band(a,4)>0) {
|
||
response.push( {type: "ERROR", message: "Event memory full"});
|
||
}
|
||
if (bit.band(b,1)>0) {
|
||
response.push( {type: "ERROR", message: "Power meter error"});
|
||
} if (bit.band(b,2)>0) {
|
||
response.push( {type: "ERROR", message: "Load status error"});
|
||
} if (bit.band(b,4)>0) {
|
||
response.push( {type: "ERROR", message: "Inclination error"});
|
||
} if (bit.band(b,8)>0) {
|
||
response.push( {type: "ERROR", message: "Time error"});
|
||
} if (bit.band(b,16)>0) {
|
||
response.push( {type: "ERROR", message: "Hit detected"});
|
||
} if (bit.band(b,32)>0) {
|
||
response.push( {type: "ERROR", message: "Max power cycle exceeded (input)"});
|
||
} if (bit.band(b,64)>0) {
|
||
response.push( {type: "ERROR", message: "Max power cycle exceeded (relay)"});
|
||
} if (bit.band(b,128)>0) {
|
||
response.push( {type: "ERROR", message: "Temperature error"});
|
||
}
|
||
|
||
if (bit.band(c,1)>0) {
|
||
response.push( {type: "ERROR", message: "No driver connection"});
|
||
} if (bit.band(c,2)>0) {
|
||
response.push( {type: "ERROR", message: "Driver error"});
|
||
} if (bit.band(c,4)>0) {
|
||
response.push( {type: "ERROR", message: "No external device connected"});
|
||
} if (bit.band(c,8)>0) {
|
||
response.push( {type: "ERROR", message: "External device error"});
|
||
} if (bit.band(c,16)>0) {
|
||
response.push( {type: "ERROR", message: "No external sensor connected"});
|
||
} if (bit.band(c,32)>0) {
|
||
response.push( {type: "ERROR", message: "External sensor error"});
|
||
} if (bit.band(c,64)>0) {
|
||
response.push( {type: "ERROR", message: "Dev. count exceeded"});
|
||
} if (bit.band(c,128)>0) {
|
||
response.push( {type: "ERROR", message: "DALI short circuit"});
|
||
}
|
||
|
||
if (bit.band(d,1)>0) {
|
||
response.push( {type: "ERROR", message: "Node error"});
|
||
} if (bit.band(d,2)>0) {
|
||
response.push( {type: "ERROR", message: "Node not init."});
|
||
} if (bit.band(d,4)>0) {
|
||
response.push( {type: "ERROR", message: "Bootloader active"});
|
||
} if (bit.band(d,8)>0) {
|
||
response.push( {type: "ERROR", message: "Lifetime exceeded"});
|
||
} if (bit.band(d,16)>0) {
|
||
response.push( {type: "ERROR", message: "Hold reinit active"});
|
||
} if (bit.band(d,32)>0) {
|
||
response.push( {type: "ERROR", message: "Dimming changed"});
|
||
} if (bit.band(d,128)>0) {
|
||
response.push( {type: "ERROR", message: "LM marks node as innactive"});
|
||
}
|
||
|
||
if (response.length == 0) {
|
||
response.push( "No errors recognized");
|
||
}else{
|
||
//<font style='color: red !important;'>
|
||
//response.push( "<font style='color: red !important;'>" + response + "</font>");
|
||
//response.push({type: "ERROR", message: });
|
||
}
|
||
}
|
||
}else if (cmd_pure == 1) {
|
||
if (add == 0) { // Master
|
||
if (bit.band(d,1)>0) {
|
||
response.push( "Init mode enabled");
|
||
}else{
|
||
response.push( "Init mode disabled");
|
||
}
|
||
}else{ // Slave
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}
|
||
}else if (cmd_pure == 2) {
|
||
if (add == 0) { // Master
|
||
if (d == 0) {
|
||
response.push( "PLC Master node");
|
||
}else if (d == 1) {
|
||
response.push( "RF Master node");
|
||
}else if (d == 2) {
|
||
response.push( "Mixed Master node");
|
||
}else{
|
||
response.push( "Unknown Master node (" + String(d) + ")");
|
||
}
|
||
}else{ // Slave
|
||
var nodetype = "Luminaire 1 channel";
|
||
if (d == 1) {
|
||
nodetype = "Luminaire 2 channels";
|
||
}else if (d==2) {
|
||
nodetype = "Luminaire 3 channels";
|
||
}else if (d==3) {
|
||
nodetype = "Luminaire 4 channels";
|
||
}else if (d==4) {
|
||
nodetype = "Sensor node";
|
||
}else{
|
||
nodetype = "Unknown type";
|
||
}
|
||
response.push( "External sensor DT : ");
|
||
response.push( "External device DT : " + String(b) );
|
||
response.push( "Main driver DT : " + String(c) );
|
||
response.push( "Node : " + nodetype );
|
||
}
|
||
}else if (cmd_pure == 3) {
|
||
if (add == 0) { // Master
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) );
|
||
}else{ // Slave
|
||
response.push( "Group addresses : {" + String(a) + ", " + String(b) + ", " + String(c) + ", " + String(d) + "}");
|
||
}
|
||
}else if (cmd_pure == 4) {
|
||
if (add == 0) { // Master
|
||
if (d < 255) {
|
||
var yearcount = Math.floor(d / 12);
|
||
var monthcount = (d - yearcount) + 1;
|
||
var month = numberToMonth(monthcount);
|
||
response.push( "HW Version : " + String(a) );
|
||
response.push( "FW Version : " + String(b) + "." + String(c) );
|
||
response.push( "Last update : " + month + " " + String(2018+yearcount) );
|
||
}else{
|
||
response.push( "HW Version : " + String(a) );
|
||
response.push( "FW Version : " + String(b) + "." + String(c));
|
||
response.push( "Last update : NEVER" );
|
||
}
|
||
}else{ // Slave
|
||
response.push( "Group addresses : {" + String(a) + ", " + String(b) + ", " + String(c) + ", " + String(d) + "}");
|
||
}
|
||
}else if (cmd_pure == 5) {
|
||
if (add == 0) { // Master
|
||
response.push( "Batch no. : " + String(bit.bor(bit.lshift(a,8), b)) );
|
||
response.push( "Production date : " + numberToMonth(c) + " " + String(2000+d));
|
||
}else{ // Slave
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) );
|
||
}
|
||
}else if (cmd_pure == 6) {
|
||
if (add == 0) { // Master
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) );
|
||
}else{ // Slave
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}
|
||
}else if (cmd_pure == 7) {
|
||
if (add == 0) { // Master
|
||
response.push( "RS232 param : " + String(a) + ", " + String(b) );
|
||
response.push( "Baudrate : " + String(bit.bor(bit.lshift(c,8), d)*100));
|
||
}else{ // Slave
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}
|
||
}else if (cmd_pure == 8) {
|
||
if (add == 0) { // Master
|
||
var x = bit.band(b,0x7F)
|
||
var y = bit.band(c,0x7F)
|
||
var z = bit.band(d,0x7F)
|
||
|
||
if (bit.band(b,0x80) > 0) {
|
||
x = x * -1;
|
||
}
|
||
if (bit.band(c,0x80) > 0) {
|
||
y = y * -1;
|
||
}
|
||
if (bit.band(d,0x80) > 0) {
|
||
z = z * -1;
|
||
}
|
||
|
||
response.push( "Temperature : " + String(a) );
|
||
response.push( "X tilt : " + String(x) );
|
||
response.push( "Y tilt : " + String(y) );
|
||
response.push( "Z tilt : " + String(z) );
|
||
|
||
}else{ // Slave
|
||
if (bit.band(a,1)>0) {
|
||
response.push( "Standard register behaviour");
|
||
} if (bit.band(a,2)>0) {
|
||
response.push( "TS activated without changing other settings");
|
||
} if (bit.band(a,4)>0) {
|
||
response.push( "TS deactivated without changing other settings ");
|
||
}
|
||
|
||
if (bit.band(b,1)>0) {
|
||
response.push( "DUSK control active");
|
||
} if (bit.band(b,2)>0) {
|
||
response.push( "DAWN control active");
|
||
} if (bit.band(b,4)>0) {
|
||
response.push( "Lux level source: in lamp");
|
||
}else{
|
||
response.push( "Lux level source: cabinet");
|
||
}
|
||
|
||
if (bit.band(c,1)>0) {
|
||
response.push( "movement control active");
|
||
}
|
||
|
||
if (bit.band(d,2)>0) {
|
||
response.push( "Default table: TS2");
|
||
}else{
|
||
response.push( "Default table: TS1");
|
||
} if (bit.band(d,4)>0) {
|
||
response.push( "Active table: TS2");
|
||
}else{
|
||
response.push( "Active table: TS1");
|
||
}
|
||
|
||
if (bit.band(d,16)>0) {
|
||
response.push( "Twilight mode active");
|
||
}else{
|
||
response.push( "Twilight mode inactive");
|
||
} if (bit.band(d,32)>0) {
|
||
response.push( "TS1 was resseted");
|
||
} if (bit.band(d,64)>0) {
|
||
response.push( "TS2 was resseted");
|
||
}
|
||
|
||
if (bit.band(d,1)>0) {
|
||
response.push( "Timer ACTIVE");
|
||
}else{
|
||
response.push( "Timer INACTIVE");
|
||
}
|
||
}
|
||
}else if (cmd_pure == 9) {
|
||
if (add == 0) { // Master
|
||
response.push( "Version : " + String(d) + "." + String(c) + "." + String(b) + "." + String(a) );
|
||
}else{ // Slave
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}
|
||
|
||
}else if (cmd_pure == 10) {
|
||
if (add == 0) { // Master
|
||
response.push( "MAC_0: " + String(c) );
|
||
response.push( "MAC_1: " + String(d) );
|
||
}else{ // Slave
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}
|
||
|
||
}else if (cmd_pure == 11) {
|
||
if (add == 0) { // Master
|
||
response.push( "MAC_2: " + String(a) );
|
||
response.push( "MAC_3: " + String(b) );
|
||
response.push( "MAC_4: " + String(c) );
|
||
response.push( "MAC_5: " + String(d) );
|
||
|
||
}else{ // Slave
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}
|
||
}else if (cmd_pure == 12) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 13) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 14) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 15) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 16) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 17) {
|
||
}else if (cmd_pure == 18) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 19) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 20) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 21) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 22) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 23) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 24) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 25) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 26) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 27) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 28) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 29) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 30) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 31) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 32) {
|
||
if (add == 0) { // Master
|
||
response.push( "");
|
||
}else{ // Slave
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}
|
||
}else if (cmd_pure == 33) {
|
||
if (addd == 0) { // Master
|
||
response.push( "");
|
||
}else{ // Slave
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}
|
||
}else if (cmd_pure == 34) {
|
||
if (add == 0) { // Master
|
||
response.push( "");
|
||
}else{ // Slave
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}
|
||
}else if (cmd_pure == 35) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 36) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 37) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 38) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 39) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 40) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 41) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 42) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 43) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 44) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 45) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 46) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 47) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 48) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 49) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 50) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 51) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 52) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 53) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 54) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 55) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 56) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 57) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 58) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 59) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 60) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 61) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 62) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 63) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 64) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 65) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 66) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 67) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 68) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 69) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 70) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 71) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 72) {
|
||
if (bit.band(d,0x80) > 0) {
|
||
response.push( "Relay : ON");
|
||
}else{
|
||
response.push( "Relay : OFF");
|
||
}
|
||
response.push( "Dimming : " + String(bit.band(d,0x7F)) + " %");
|
||
}else if (cmd_pure == 73) {
|
||
response.push( "");
|
||
}else if (cmd_pure == 74) {
|
||
response.push( (String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) / 10) + " V");
|
||
}else if (cmd_pure == 75) {
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) + " mA");
|
||
}else if (cmd_pure == 76) {
|
||
response.push( (String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) / 10) + " W");
|
||
}else if (cmd_pure == 77) {
|
||
var v = bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)/10
|
||
response.push( String(Math.cos(math.rad(v))) );
|
||
}else if (cmd_pure == 78) {
|
||
response.push( (String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) / 10) + " Hz");
|
||
}else if (cmd_pure == 79) {
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) + " Wh");
|
||
}else if (cmd_pure == 80) {
|
||
var mins = bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)
|
||
var hours = Math.floor(mins/60)
|
||
var rest_min = mins - (hours*60)
|
||
response.push( String(hours) + ":" + String(rest_min) );
|
||
}else if (cmd_pure == 81) {
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) );
|
||
}else if (cmd_pure == 82) {
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) );
|
||
}else if (cmd_pure == 83) {
|
||
var mins = bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)
|
||
var hours = Math.floor(mins/60);
|
||
var rest_min = mins - (hours*60);
|
||
response.push( String(hours) + ":" + String(rest_min) );
|
||
}else if (cmd_pure == 84) {
|
||
var x = bit.band(b,0x7F);
|
||
var y = bit.band(c,0x7F);
|
||
var z = bit.band(d,0x7F);
|
||
|
||
if (bit.band(b,0x80) > 0) {
|
||
x = x * -1;
|
||
}
|
||
if (bit.band(c,0x80) > 0) {
|
||
y = y * -1;
|
||
}
|
||
if (bit.band(d,0x80) > 0) {
|
||
z = z * -1;
|
||
}
|
||
|
||
response.push( "Temperature : " + String(a) );
|
||
response.push( "X tilt : " + String(x) );
|
||
response.push( "Y tilt : " + String(y) );
|
||
response.push( "Z tilt : " + String(z) );
|
||
}else if (cmd_pure == 85) {
|
||
if (a > 0) {
|
||
response.push( "-");
|
||
}
|
||
response.push( response + String(b) + "° " + String(c) + "’ " + String(d) + "’’");
|
||
}else if (cmd_pure == 86) {
|
||
if (a > 0) {
|
||
response.push( "-");
|
||
}
|
||
response.push( response + String(b) + "° " + String(c) + "’ " + String(d) + "’’");
|
||
}else if (cmd_pure == 87) {
|
||
response.push( String(a) + ":" + String(b) + ":" + String(c) );
|
||
}else if (cmd_pure == 88) {
|
||
response.push( numberToDay(a) + " " + String(b) + "." + String(c) + ". " + String(2000+d) );
|
||
}else if (cmd_pure == 89) {
|
||
if (d < 255) {
|
||
var yearcount = Math.floor(d / 12);
|
||
var monthcount = (d - yearcount) + 1;
|
||
var month = numberToMonth(monthcount);
|
||
response.push( "HW Version : " + String(a) );
|
||
response.push( "FW Version : " + String(b) + "." + String(c) );
|
||
response.push( "Last update : " + month + " " + String(2018+yearcount) );
|
||
}else{
|
||
response.push( "HW Version : " + String(a) );
|
||
response.push( "FW Version : " + String(b) + "." + String(c) );
|
||
response.push( "Last update : NEVER" );
|
||
}
|
||
}else if (cmd_pure == 90) {
|
||
response.push( "Batch no. : " + String(bit.bor(bit.lshift(a,8), b)) );
|
||
response.push( "Production date : " + numberToMonth(c) + " " + String(2000+d) );
|
||
}else if (cmd_pure == 91) {
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) );
|
||
}else if (cmd_pure == 92) {
|
||
response.push( "");
|
||
}else if (cmd_pure == 93) {
|
||
response.push( "");
|
||
}else if (cmd_pure == 94) {
|
||
response.push( "");
|
||
}else if (cmd_pure == 95) {
|
||
response.push( String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) );
|
||
}else if (cmd_pure == 96) {
|
||
response.push( "Dusk : " + String(bit.bor(bit.lshift(a,8),b)) );
|
||
response.push( "Dawn : " + String(bit.bor(bit.lshift(c,8),d)) );
|
||
}else if (cmd_pure == 97) {
|
||
response.push( "Dusk : " + String(bit.bor(bit.lshift(a,8),b)) );
|
||
response.push( "Dawn : " + String(bit.bor(bit.lshift(c,8),d)) );
|
||
}else if (cmd_pure == 98) {
|
||
response.push( "Dusk : " + String(c) );
|
||
response.push( "Dawn : " + String(d) );
|
||
}else if (cmd_pure == 99) {
|
||
response.push( "CCT max: " + String(bit.bor(bit.lshift(a,8), b)) );
|
||
response.push( "CCT min: " + String(bit.bor(bit.lshift(c,8), d)) );
|
||
}else if (cmd_pure == 100) {
|
||
var resid = "unknown (" + String(a) + ")";
|
||
if (a == 0x80) {
|
||
resid = "OK";
|
||
}else if (a == 0x81) {
|
||
resid = "timeout";
|
||
}else if (a == 0x83) {
|
||
resid = "error";
|
||
}
|
||
response.push( "Resp ID: " + resid );
|
||
response.push( "Add: " + String(b) );
|
||
response.push( "CMD: " + String(c) );
|
||
response.push( "Resp: " + String(d) );
|
||
}else if (cmd_pure == 101) {
|
||
response.push( "Version : " + String(d) + "." + String(c) + "." + String(b) + "." + String(a) );
|
||
}else if (cmd_pure == 102) {
|
||
response.push( "MAC_0: " + String(c) );
|
||
response.push( "MAC_1: " + String(d) );
|
||
}else if (cmd_pure == 103) {
|
||
response.push( "MAC_2: " + String(a) );
|
||
response.push( "MAC_3: " + String(b) );
|
||
response.push( "MAC_4: " + String(c) );
|
||
response.push( "MAC_5: " + String(d) );
|
||
}else if (cmd_pure == 122) {
|
||
response.push( "");
|
||
}else if (cmd_pure == 123) {
|
||
response.push( "");
|
||
}else if (cmd_pure == 124) {
|
||
response.push( "");
|
||
}else if ((cmd_pure > 127) && (cmd_pure < 0x100)) {
|
||
if (add == 0) {
|
||
response.push( "Serial nb. : " + String(bit.bor(bit.lshift(a,24),bit.lshift(b,16),bit.lshift(c,8),d)) );
|
||
}
|
||
}
|
||
|
||
return response;
|
||
}
|
||
|
||
module.exports = decodeValue
|