Update main.js

master
Administrator 6 years ago
parent 9c0933cb8a
commit 4bf7edbc9d

@ -343,133 +343,15 @@ function checkObjects(options, regType, regName, regFullName, tasks, newObjects)
}
}
function iterateAddresses(isBools, deviceId, result, regName, regType, localOptions) {
const config = result.config;
if (config && config.length) {
result.addressLow = 0xFFFFFFFF;
result.addressHigh = 0;
for (let i = config.length - 1; i >= 0; i--) {
if (config[i].deviceId !== deviceId) continue;
const address = config[i].address = parseInt(config[i].address, 10);
if (address < 0) {
adapter.log.error(`Invalid ${regName} address: ${address}`);
config.splice(i, 1);
continue;
}
if (!isBools) {
config[i].type = config[i].type || 'uint16be';
config[i].offset = parseFloat(config[i].offset) || 0;
config[i].factor = parseFloat(config[i].factor) || 1;
if (config[i].type === 'string') {
config[i].len = parseInt(config[i].len, 10) || 1;
} else {
config[i].len = type_items_len[config[i].type];
}
config[i].len = config[i].len || 1;
} else {
config[i].len = 1;
}
if (localOptions.multiDeviceId) {
config[i].id = regName + '.' + deviceId + '.';
} else {
config[i].id = regName + '.';
}
if (localOptions.showAliases) {
config[i].id += address2alias(regType, address, localOptions.directAddresses, result.offset);
} else {
config[i].id += address;
}
config[i].id += (config[i].name ? '_' + (config[i].name.replace('.', '_').replace(' ', '_')) : '');
// collect cyclic write registers
if (config[i].cw) {
result.cyclicWrite.push(adapter.namespace + '.' + config[i].id);
}
if (address < result.addressLow) result.addressLow = address;
if (address + config[i].len > result.addressHigh) {
result.addressHigh = address + (config[i].len || 1);
}
}
const maxBlock = isBools ? localOptions.maxBoolBlock : localOptions.maxBlock;
let lastAddress = null;
let startIndex = 0;
let blockStart = 0;
let i;
for (i = 0; i < config.length; i++) {
if (config[i].deviceId !== deviceId) continue;
if (lastAddress === null) {
startIndex = i;
blockStart = config[i].address;
lastAddress = blockStart + config[i].len;
}
// try to detect next block
if (result.blocks) {
if ((config[i].address - lastAddress > 10 && config[i].len < 10) || (lastAddress - blockStart >= maxBlock)) {
if (result.blocks.map(obj => obj.start).indexOf(blockStart) === -1) {
result.blocks.push({start: blockStart, count: lastAddress - blockStart, startIndex: startIndex, endIndex: i});
}
blockStart = config[i].address;
startIndex = i;
}
}
lastAddress = config[i].address + config[i].len;
}
if (lastAddress && lastAddress - blockStart && result.blocks && result.blocks.map(obj => obj.start).indexOf(blockStart) === -1) {
result.blocks.push({start: blockStart, count: lastAddress - blockStart, startIndex: startIndex, endIndex: i});
}
if (config.length) {
result.length = result.addressHigh - result.addressLow;
if (isBools && !localOptions.doNotRoundAddressToWord) {
result.addressLow = Math.floor(result.addressLow / 16) * 16;
if (result.length % 16) {
result.length = (Math.floor(result.length / 16) + 1) * 16;
}
if (result.blocks) {
for (let b = 0; b < result.blocks.length; b++) {
result.blocks[b].start = Math.floor(result.blocks[b].start / 16) * 16;
if (result.blocks[b].count % 16) {
result.blocks[b].count = (Math.floor(result.blocks[b].count / 16) + 1) * 16;
}
}
}
}
} else {
result.length = 0;
}
if (result.mapping) {
for (let i = 0; i < config.length; i++) {
result.mapping[config[i].address - result.addressLow] = adapter.namespace + '.' + config[i].id;
}
}
}
}
function parseConfig(callback) {
adapter.log.warn('adapter.config=' + adapter.config);
let options = prepareConfig(adapter.config);
const params = adapter.config.params;
adapter.log.warn('params=' + params);
//adapter.log.warn('params=' + params);
adapter.getForeignObjects(adapter.namespace + '.*', (err, list) => {
let oldObjects = list;
@ -479,24 +361,13 @@ function parseConfig(callback) {
let tasks = [];
checkObjects(adapter.config, 'yz', 'yz', 'menjin', tasks, newObjects);
checkObjects(adapter.config, 'dz', 'dz', 'chedao', tasks, newObjects);
// device.yz.config = adapter.config.yz.filter(e => e.deviceId === deviceId);
//device.disInputs.config = adapter.config.disInputs. filter(e => e.deviceId === deviceId);
// Discrete inputs
// iterateAddresses(true, deviceId, device.yz, 'discreteInputs', 'disInputs', localOptions);
//iterateAddresses(true, deviceId, device.disInputs, 'discreteInputs', 'disInputs', localOptions);
// ------------- create states and objects ----------------------------
checkObjects(adapter.config, 'yz', 'yz', 'yz', tasks, newObjects);
//checkObjects(adapter.config, 'disInputs', 'discreteInputs', 'Discrete inputs', tasks, newObjects);
checkObjects(adapter.config, 'video', 'video', 'video', tasks, newObjects);
checkObjects(adapter.config, 'power', 'power', 'room power', tasks, newObjects);
tasks.push({
id: 'info',
@ -552,7 +423,7 @@ function parseConfig(callback) {
oldObjects = [];
newObjects = [];
adapter.subscribeStates('*');
// callback(options);
callback(options);
});
});
}

Loading…
Cancel
Save