|
|
|
|
@@ -1,6 +1,44 @@
|
|
|
|
|
const dbcontroller = require('../db');
|
|
|
|
|
const util = require('../util');
|
|
|
|
|
|
|
|
|
|
const deviceUsesPrograms = function(device) {
|
|
|
|
|
switch (device.msn.slice(0,2).toUpperCase() || 'xx') {
|
|
|
|
|
case '1F':
|
|
|
|
|
case '20':
|
|
|
|
|
case '51':
|
|
|
|
|
case '53':
|
|
|
|
|
case '55':
|
|
|
|
|
case '5A':
|
|
|
|
|
case '7A': return false;
|
|
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (device.programs != undefined && device.programs.programs != undefined && device.programs.programs.programs != undefined) { return true; }
|
|
|
|
|
if (device.programs == undefined && device.slots == undefined) { return true; }
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const deviceUsesSlots = function(device) {
|
|
|
|
|
switch (device.msn.slice(0,2).toUpperCase() || 'xx') {
|
|
|
|
|
case '1F':
|
|
|
|
|
case '20':
|
|
|
|
|
case '51':
|
|
|
|
|
case '53':
|
|
|
|
|
case '55':
|
|
|
|
|
case '5A':
|
|
|
|
|
case '7A': return true;
|
|
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (device.slots != undefined && device.slots.slots != undefined && device.slots.slots.slots != undefined) { return true; }
|
|
|
|
|
if (device.programs == undefined && device.slots == undefined) { return true; }
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const postRequestToDo = async function (msn, body) {
|
|
|
|
|
try {
|
|
|
|
|
await dbcontroller.addDevice(body, null)
|
|
|
|
|
@@ -30,24 +68,24 @@ const getRequestToDo = async function (msn) {
|
|
|
|
|
var todo = { serialNumber : msn }
|
|
|
|
|
|
|
|
|
|
///// Programs
|
|
|
|
|
if (device.programs != undefined) {
|
|
|
|
|
if (child.programmingTimestamp != undefined && deviceUsesPrograms(child)) {
|
|
|
|
|
timestamp = child.programmingTimestamp || -1
|
|
|
|
|
if (timestamp < device.programs.timestamp) { todo.programs = 1 }
|
|
|
|
|
else if (timestamp > device.programs.timestamp) { todo.programs = 2 }
|
|
|
|
|
if ((device.programs == undefined) || (timestamp > device.programs.timestamp)) { todo.programs = 2 }
|
|
|
|
|
else if (timestamp < device.programs.timestamp) { todo.programs = 1 }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///// Configuration
|
|
|
|
|
if (device.configuration != undefined) {
|
|
|
|
|
if (child.configurationTimestamp != undefined) {
|
|
|
|
|
timestamp = child.configurationTimestamp || child.relayConfigurationTimestamp || -1
|
|
|
|
|
if (timestamp < device.configuration.timestamp) { todo.configuration = 1 }
|
|
|
|
|
else if (timestamp > device.configuration.timestamp) { todo.configuration = 2 }
|
|
|
|
|
if ((device.configuration == undefined) || (timestamp > device.configuration.timestamp)) { todo.configuration = 2 }
|
|
|
|
|
else if (timestamp < device.configuration.timestamp) { todo.configuration = 1 }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///// Slots
|
|
|
|
|
if (device.slots != undefined) {
|
|
|
|
|
if (child.programmingTimestamp != undefined && deviceUsesSlots(child)) {
|
|
|
|
|
timestamp = child.programmingTimestamp || -1
|
|
|
|
|
if (timestamp < device.slots.timestamp) { todo.slots = 1 }
|
|
|
|
|
else if (timestamp > device.slots.timestamp) { todo.slots = 2 }
|
|
|
|
|
if ((device.slots == undefined) || (timestamp > device.slots.timestamp)) { todo.slots = 2 }
|
|
|
|
|
else if (timestamp < device.slots.timestamp) { todo.slots = 1 }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///// Status
|
|
|
|
|
|