更新 main.js

This commit is contained in:
钟进 2019-01-16 05:40:36 +00:00
parent 6a0d6e3831
commit fd6f66f5cb

119
main.js
View File

@ -335,7 +335,15 @@ function checkObjects(options, regType, regName, regFullName, tasks, newObjects)
let regs = options[regType];
for (let i = 0; regs.length > i; i++) {
const id = adapter.namespace + '.' + regs[i].id;
// const id = adapter.namespace + '.' + regs[i].id;
const id = adapter.namespace + '.' + regType + '.' + regs[i]._address + '.' + regs[i].name;
regs[i].id = id;
adapter.log.warn('id=' + id);
regs[i].fullId = id;
objects[id] = {
_id: regs[i].id,
@ -395,115 +403,6 @@ 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 (!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) {
let options = prepareConfig(adapter.config);
const params = adapter.config.params;