From fd6f66f5cb64e1698f8c4670a28631eb27906951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E8=BF=9B?= Date: Wed, 16 Jan 2019 05:40:36 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20main.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 119 +++++--------------------------------------------------- 1 file changed, 9 insertions(+), 110 deletions(-) diff --git a/main.js b/main.js index 0863a9d..c033d9c 100644 --- a/main.js +++ b/main.js @@ -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;