diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index 3bf572d..55c8f79 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -74,20 +74,13 @@ "default" : "e380", "newLine": true }, - "e380_tree": { + "e380_active": { "type": "checkbox", - "label": "tree states", - "tooltip": "Show data as tree of obejcts", + "label": "active", + "tooltip": "Activate communication", "default" : true, "newLine": false }, - "e380_json": { - "type": "checkbox", - "label": "json states", - "tooltip": "Show data as JSON obejcts", - "default" : false, - "newLine": false - }, "e380_delay": { "type": "number", "label": "Min. update time (s)", @@ -161,24 +154,14 @@ }, { "type": "checkbox", - "attr": "collect_tree_states", - "width": "10% ", - "title": "tree states", - "tooltip": "Show data as tree of obejcts", + "attr": "collect_active", + "width": "5% ", + "title": "active", + "tooltip": "Activate communication", "filter": false, "sort": false, "default": true }, - { - "type": "checkbox", - "attr": "collect_json_states", - "width": "10% ", - "title": "json states", - "tooltip": "Show data as JSON obejcts", - "filter": false, - "sort": false, - "default": false - }, { "type": "number", "attr": "collect_delay_time", @@ -259,24 +242,14 @@ }, { "type": "checkbox", - "attr": "uds_tree_states", - "width": "10% ", - "title": "tree states", - "tooltip": "Show data as tree of obejcts", + "attr": "uds_active", + "width": "5% ", + "title": "active", + "tooltip": "Activate communication", "filter": false, "sort": false, "default": true }, - { - "type": "checkbox", - "attr": "uds_json_states", - "width": "10% ", - "title": "json states", - "tooltip": "Show data as JSON obejcts", - "filter": false, - "sort": false, - "default": false - }, { "type": "text", "attr": "uds_dev_addr", @@ -372,24 +345,14 @@ }, { "type": "checkbox", - "attr": "collect_tree_states", - "width": "10% ", - "title": "tree states", - "tooltip": "Show data as tree of obejcts", + "attr": "collect_active", + "width": "5% ", + "title": "active", + "tooltip": "Activate communication", "filter": false, "sort": false, "default": true }, - { - "type": "checkbox", - "attr": "collect_json_states", - "width": "10% ", - "title": "json states", - "tooltip": "Show data as JSON obejcts", - "filter": false, - "sort": false, - "default": false - }, { "type": "number", "attr": "collect_delay_time", diff --git a/lib/canUds.js b/lib/canUds.js index 9130eb2..8f2bd60 100644 --- a/lib/canUds.js +++ b/lib/canUds.js @@ -86,7 +86,6 @@ class uds { } async addSchedule(ctx, schedule, dids) { - // x const obj = await ctx.getStateAsync(this.schedulesId); const schedules = JSON.parse(obj.val); if (!Object.keys(schedules).includes(schedule)) { @@ -132,7 +131,7 @@ class uds { } await ctx.setStateAsync(this.cmndQueueId, {val: JSON.stringify(cmnds), ack: true}); } - await this.sleep(100); + await this.sleep(50); } } @@ -156,7 +155,7 @@ class uds { await this.pushCmnd(ctx, 'read', dids); } } } - await this.sleep(100); + await this.sleep(50); } } diff --git a/lib/storage.js b/lib/storage.js index 7de06dc..64a1a3a 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -6,28 +6,46 @@ class storage { this.config = config; } async initStates(ctx) { - if (this.config.doJson) { - await ctx.setObjectNotExistsAsync(this.config.stateBase+'.json', { - type: 'channel', - common: { - name: this.config.stateBase+' JSON', - role: 'device' - }, - native: {}, - }); - } + await ctx.setObjectNotExistsAsync(this.config.stateBase+'.json', { + type: 'channel', + common: { + name: this.config.stateBase+' JSON', + role: 'device' + }, + native: {}, + }); - if (this.config.doTree) { - await ctx.setObjectNotExistsAsync(this.config.stateBase+'.tree', { - type: 'channel', - common: { - name: this.config.stateBase+' TREE', - role: 'device' - }, - native: {}, - }); - } + await ctx.setObjectNotExistsAsync(this.config.stateBase+'.tree', { + type: 'channel', + common: { + name: this.config.stateBase+' TREE', + role: 'device' + }, + native: {}, + }); + + await ctx.setObjectNotExistsAsync(this.config.stateBase+'.raw', { + type: 'channel', + common: { + name: this.config.stateBase+' RAW', + role: 'device' + }, + native: {}, + }); + } + + toHex(d) { + // Convert integer to hex string of length len + return ('00'+(Number(d).toString(16))).slice(-2); + } + + arr2Hex(arr) { + // Convert byte array to hex string + let hs = ''; + for (const v in arr) { hs += this.toHex(arr[v]); } + return hs; } + async decodeDataCAN(ctx, did, data) { async function storeObjectJson(ctx, stateId, obj) { await ctx.setObjectNotExistsAsync(stateId, { @@ -58,13 +76,16 @@ class storage { } } const idStr = didsDict[this.config.device][did].id; + const raw = this.arr2Hex(data); const val = didsDict[this.config.device][did].decode(data); if (val) { const didStr = '000'+String(did); const stateIdJson = this.config.stateBase+'.json.'+didStr.slice(-4)+'_'+idStr; const stateIdTree = this.config.stateBase+'.tree.'+didStr.slice(-4)+'_'+idStr; - if (this.config.doTree) { await storeObjectTree(ctx, stateIdTree, val); } - if (this.config.doJson) { await storeObjectJson(ctx, stateIdJson, val); } + const stateIdRaw = this.config.stateBase+'.raw.'+didStr.slice(-4)+'_'+idStr; + await storeObjectTree(ctx, stateIdTree, val); + await storeObjectJson(ctx, stateIdJson, val); + await storeObjectJson(ctx, stateIdRaw, raw); } } diff --git a/main.js b/main.js index a2df9e5..725fe79 100644 --- a/main.js +++ b/main.js @@ -93,26 +93,24 @@ class E3oncan extends utils.Adapter { // =========================================== // Setup E380 collect: - if ( (this.config.e380_tree) || (this.config.e380_json) ) { + if (this.config.e380_active) { this.e380Collect = new collect.collect( { 'canID': [0x250,0x252,0x254,0x256,0x258,0x25A,0x25C], 'stateBase': this.config.e380_name, 'device': this.config.e380_name, 'delay': this.config.e380_delay, - 'doTree': this.config.e380_tree, - 'doJSON': this.config.e380_json}); + 'active': this.config.e380_active}); await this.e380Collect.initStates(this); } // Setup all configured devices for collect: for (const dev of Object.values(this.config.table_collect_ext)) { - if ( (dev.collect_tree_states) || (dev.collect_json_states) ) { + if (dev.collect_active) { const Collect = new collect.collect( { 'canID': [Number(dev.collect_canid)], 'stateBase': dev.collect_dev_name, 'device': 'common', 'delay': dev.collect_delay_time, - 'doTree': dev.collect_tree_states, - 'doJSON': dev.collect_json_states, + 'active': dev.collect_active, 'channel': this.channelExt}); this.E3CollectExt.push(Collect); await Collect.initStates(this); } @@ -120,15 +118,14 @@ class E3oncan extends utils.Adapter { // Setup all configured devices for UDS: for (const dev of Object.values(this.config.table_uds)) { - if ( (dev.uds_tree_states) || (dev.uds_json_states) ) { + if (dev.uds_active) { if (!(Object.keys(this.udsDevices).includes(dev.uds_dev_addr))) { const Uds = new uds.uds( { 'canID': [Number(dev.uds_dev_addr)], 'stateBase': dev.uds_dev_name, 'device': 'common', 'delay': 0, - 'doTree': dev.uds_tree_states, - 'doJSON': dev.uds_json_states, + 'active': dev.uds_active, 'channel': this.channelExt, 'timeout': 2 // Commuication timeout (s) }); @@ -148,14 +145,13 @@ class E3oncan extends utils.Adapter { // Setup all configured devices for collect: for (const dev of Object.values(this.config.table_collect_int)) { - if ( (dev.collect_tree_states) || (dev.collect_json_states) ) { + if (dev.collect_active) { const Collect = new collect.collect( { 'canID': [Number(dev.collect_canid)], 'stateBase': dev.collect_dev_name, 'device': 'common', 'delay': dev.collect_delay_time, - 'doTree': dev.collect_tree_states, - 'doJSON': dev.collect_json_states, + 'active': dev.collect_active, 'channel': this.channelInt}); this.E3CollectInt.push(Collect); await Collect.initStates(this); }