diff --git a/README.md b/README.md index ee317491..0e1ab4cc 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,6 @@ By writing JSON data to the `raw.send` state you are able to send CAN messages c ### 1.0.0-beta.4 (2020-12-01) * (crycode-de) Ignore read value if a parser returned `undefined` -* (crycode-de) Updated detection of compact mode * (crycode-de) Updated dependencies ### 1.0.0-beta.3 (2020-11-25) diff --git a/build/main.js b/build/main.js index d6a1189a..40077c13 100644 --- a/build/main.js +++ b/build/main.js @@ -685,7 +685,7 @@ __decorate([ core_decorators_1.autobind ], CanBusAdapter.prototype, "handleCanMsg", null); exports.CanBusAdapter = CanBusAdapter; -if (require.main !== module) { +if (module.parent) { // Export the constructor in compact mode module.exports = (options) => new CanBusAdapter(options); } diff --git a/build/main.js.map b/build/main.js.map index c644d825..9d0b7725 100644 --- a/build/main.js.map +++ b/build/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sourceRoot":"/","sources":["main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAgD;AAChD,qDAA2C;AAG3C,mDAA+C;AAC/C,uCAAqC;AAErC,uCAAwC;AAExC,qCAKkB;AAElB,MAAa,aAAc,SAAQ,KAAK,CAAC,OAAO;IAW9C,YAAY,UAAyC,EAAE;QACrD,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,IAAI,EAAE,QAAQ;SACf,CAAC,CAAC;QAbG,iBAAY,GAAwB,IAAI,CAAC;QAEjD;;;;WAIG;QACK,kBAAa,GAAkC,EAAE,CAAC;QAQxD,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3C,qCAAqC;QACrC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IAEK,KAAK,CAAC,OAA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,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;aAC1K;SACF;IACH,CAAC;CACF;AAnqBC;IADC,0BAAQ;4CAkBR;AAMD;IADC,0BAAQ;6CAYR;AASD;IADC,0BAAQ;kDAkIR;AA6OD;IADC,0BAAQ;iDA6DR;AAhfH,sCA8rBC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;IAC3B,yCAAyC;IACzC,MAAM,CAAC,OAAO,GAAG,CAAC,OAAkD,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;CACrG;KAAM;IACL,wCAAwC;IACxC,CAAC,GAAG,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,EAAE,CAAC;CAC/B","sourcesContent":["import * as utils from '@iobroker/adapter-core';\nimport { autobind } from 'core-decorators';\nimport { CanMessage } from 'socketcan';\n\nimport { CanInterface } from './can-interface';\nimport { getHexId } from './helpers';\n\nimport { knownParsers } from './parsers'\n\nimport {\n MESSAGE_ID_REGEXP,\n MESSAGE_ID_REGEXP_WITH_DLC,\n PARSER_ID_REGEXP,\n PARSER_ID_RESERVED\n} from './consts';\n\nexport class CanBusAdapter extends utils.Adapter {\n\n private canInterface: CanInterface | null = null;\n\n /**\n * Mapping of CAN hex message IDs to the message configs.\n * The IDs must be hex strings (3 or 8 chars) to differentiate between\n * stanard frame and extended frame messages.\n */\n private canId2Message: Record = {};\n\n constructor(options: Partial = {}) {\n super({\n ...options,\n name: 'canbus',\n });\n\n this.on('ready', this.onReady);\n this.on('stateChange', this.onStateChange);\n //this.on('message', this.onMessage);\n this.on('unload', this.onUnload);\n }\n\n /**\n * Is called when databases are connected and adapter received configuration.\n */\n @autobind\n private async onReady(): Promise {\n // Reset the connection indicator during startup\n this.setState('info.connection', false, true);\n\n await this.setupObjects();\n\n this.canInterface = new CanInterface(this);\n this.canInterface.on('stopped', () => {\n this.setState('info.connection', false, true);\n });\n this.canInterface.on('message', this.handleCanMsg);\n\n if (this.canInterface.start()) {\n this.setState('info.connection', true, true);\n }\n\n this.subscribeStatesAsync('*');\n }\n\n /**\n * Is called when adapter shuts down - callback has to be called under any circumstances!\n */\n @autobind\n private onUnload(callback: () => void): void {\n try {\n if (this.canInterface) {\n this.canInterface.stop();\n }\n\n this.log.debug('cleaned everything up...');\n callback();\n } catch (e) {\n callback();\n }\n }\n\n /**\n * Is called if a subscribed state changes.\n *\n * This will trigger the sending of messages and conversion from parser states\n * into message json states if configured.\n */\n @autobind\n private async onStateChange(id: string, state: ioBroker.State | null | undefined): Promise {\n if (state) {\n // The state was changed\n this.log.silly(`state ${id} changed: ${JSON.stringify(state)}`);\n\n // don't do anything if the state is acked\n if (state.ack) return;\n\n // raw.send state?\n if (this.config.useRawStates && id === `${this.namespace}.raw.send`) {\n // load and check message data\n let canMsg: CanMessage;\n try {\n canMsg = JSON.parse(state.val as string)\n } catch (e) {\n this.log.warn(`Invalid JSON in '${this.namespace}.raw.send' state cannot be send!`);\n return;\n }\n if (canMsg && Array.isArray(canMsg.data)) {\n canMsg.data = Buffer.from(canMsg.data);\n }\n if (!canMsg || typeof canMsg.id !== 'number' || !Buffer.isBuffer(canMsg.data)) {\n this.log.warn(`Invalid message data in '${this.namespace}.raw.send' state cannot be send!`);\n return;\n }\n\n // send the message\n this.log.debug(`sendig data from raw.send state`);\n if (this.sendCanMsg(canMsg.id, canMsg.ext || false, canMsg.data, canMsg.rtr || false)) {\n // set ack flag if the message was send and not already acked\n if (!state.ack) {\n await this.setStateAsync(id, {\n ...state,\n ack: true\n });\n }\n }\n return;\n }\n\n // get msg und state ID\n const [,, msgId, stateId] = id.split('.');\n\n // we only want states of a message objects\n if (!msgId || !stateId || !msgId.match(MESSAGE_ID_REGEXP_WITH_DLC)) return;\n\n const msgCfg = this.canId2Message[msgId];\n\n // we need a message and the message must be configured for sending\n if (!msgCfg || !msgCfg.send) return;\n\n switch (stateId) {\n case 'send':\n if (state.val !== true) return;\n\n // send the current json data\n if (await this.sendMessageJsonData(msgCfg)) {\n // set ack flag on the send state if the message was sent\n await this.setStateAsync(`${msgCfg.idWithDlc}.send`, {\n ...state,\n ack: true\n });\n }\n\n break;\n\n case 'json':\n // let the parsers read the data from json to keep the parsers data in sync with the json data\n this.processParsers(this.getBufferFromJsonState(state, msgCfg.idWithDlc), msgCfg);\n\n // send current json data\n if (msgCfg.autosend) {\n this.sendMessageJsonData(msgCfg, state);\n }\n break;\n\n case 'rtr':\n // nothing to do here\n break;\n\n default:\n // it may be a parser...\n if (!stateId.match(PARSER_ID_REGEXP)) return;\n\n // find and run the configured parser\n for (const parserUuid in msgCfg.parsers) {\n if (msgCfg.parsers[parserUuid].id !== stateId) continue;\n\n // check if the parser is initialized\n const parser = msgCfg.parsers[parserUuid];\n if (parser.instance) {\n // load the current json from state\n const jsonState = await this.getStateAsync(`${msgCfg.idWithDlc}.json`);\n let data: Buffer | Error | null = this.getBufferFromJsonState(jsonState, msgCfg.idWithDlc);\n if (data === null) {\n return;\n }\n\n // write to data using the parser\n data = await parser.instance.write(data, state.val);\n\n // check the write result\n if (data instanceof Error) {\n this.log.warn(`Parser writing data for message ID ${msgCfg.idWithDlc} parser ID ${parser.id} failed: ${data}`);\n continue;\n }\n if (!(data instanceof Buffer)) {\n this.log.warn(`Parser writing data for message ID ${msgCfg.idWithDlc} parser ID ${parser.id} failed: Did not return a buffer`);\n continue;\n }\n\n // set the new json state with ack=false\n await this.setStateAsync(`${msgCfg.idWithDlc}.json`, JSON.stringify([...data]), false);\n\n // set ack flag on the parser state\n await this.setStateAsync(`${msgCfg.idWithDlc}.${parser.id}`, {\n ...state,\n ack: true\n });\n }\n\n break;\n }\n }\n\n } else {\n // The state was deleted\n this.log.silly(`state ${id} deleted`);\n }\n }\n\n /**\n * Get a buffer from a `.json` state.\n * The JSON string of the state will be parsed and checked to be an array.\n * @param state The state to get the data from.\n * @param msgId The message ID for logging in case of errors.\n */\n private getBufferFromJsonState (state: ioBroker.State | null | undefined, msgId: string): Buffer | null {\n if (!state) {\n this.log.warn(`Failed parsing JSON from ${this.namespace}.${msgId}.json: No state found`);\n return null;\n }\n\n let parsedJson: unknown;\n try {\n parsedJson = JSON.parse(state.val as string);\n } catch (err) {\n this.log.warn(`Failed parsing JSON from ${this.namespace}.${msgId}.json: ${err}`);\n return null;\n }\n\n if (!Array.isArray(parsedJson)) {\n this.log.warn(`JSON data in ${this.namespace}.${msgId}.json is not an array!`);\n return null;\n }\n if (parsedJson.length > 8) {\n this.log.warn(`Array length of JSON data in ${this.namespace}.${msgId}.json is greater than 8. Only up to 8 data bytes are supportet!`);\n return null;\n }\n\n return Buffer.from(parsedJson);\n }\n\n /**\n * Send the data of a message present in it's json state.\n * For the json and rtr states of the message the ack flag will be set if the message is sent.\n * @param msgCfg The `MessageConfig` of the message for which we should send the data.\n * @param state Optional state to use for sending. If not set, the current state of the object will be read.\n * @return `true` if the message was sent.\n */\n private async sendMessageJsonData (msgCfg: MessageConfig, state?: ioBroker.State | null | undefined): Promise {\n // read the state if not given by argument\n if (!state) {\n state = await this.getStateAsync(`${msgCfg.idWithDlc}.json`);\n if (!state) {\n this.log.warn(`No state found to send for ${this.namespace}.${msgCfg.idWithDlc}.json`);\n return false;\n }\n }\n\n // parse and check the json data\n const data = this.getBufferFromJsonState(state, msgCfg.idWithDlc);\n if (data === null) {\n return false;\n }\n\n // get rtr flag from state\n const rtrState = this.config.useRtrFlag && await this.getStateAsync(`${msgCfg.idWithDlc}.rtr`);\n const rtr = rtrState && !!rtrState.val || false;\n\n // send the message\n if (this.sendCanMsg(msgCfg.idNum, msgCfg.ext, data, rtr)) {\n // set ack flag on json if the message was send and not already acked\n if (!state.ack) {\n await this.setStateAsync(`${msgCfg.idWithDlc}.json`, {\n ...state,\n ack: true\n });\n }\n\n // set ack on rtr if not already acked\n if (rtrState && !rtrState.ack) {\n await this.setStateAsync(`${msgCfg.idWithDlc}.rtr`, {\n ...rtrState,\n ack: true\n });\n }\n\n // set raw state if enabled\n if (this.config.useRawStates) {\n const canMsg: CanMessage = {\n id: msgCfg.idNum,\n ext: msgCfg.ext,\n data\n }\n if (this.config.useRtrFlag) {\n canMsg.rtr = rtr;\n }\n this.setStateAsync('raw.send', {\n val: JSON.stringify({\n ...canMsg,\n data: [...data]\n }),\n ack: true\n });\n }\n\n return true;\n } else {\n this.log.warn(`Sending data message for ${msgCfg.idWithDlc} failed!`);\n return false;\n }\n }\n\n /**\n * Setup the object tree for the messages and parsers.\n */\n private async setupObjects (): Promise {\n // loop over configured messages\n for (const msgUuid in this.config.messages) {\n const msg = this.config.messages[msgUuid];\n if (!msg.id.match(MESSAGE_ID_REGEXP)) {\n this.log.warn(`Message-ID ${msg.id} is invalid. This message will be ignored.`);\n continue;\n }\n\n const msgCfg: MessageConfig = {\n ...msg,\n idNum: parseInt(msg.id, 16),\n idWithDlc: (msg.dlc >= 0) ? `${msg.id}-${msg.dlc}` : msg.id,\n ext: msg.id.length > 3,\n uuid: msgUuid\n };\n\n this.setupMessage(msgUuid, msgCfg);\n }\n\n // delete unconfigured message objects\n if (this.config.deleteUnconfiguredMessages) {\n const objList = await this.getObjectListAsync({\n startkey: `${this.namespace}.`,\n endkey: `${this.namespace}.\\u9999`\n });\n\n // loop over all objects in the namespace of the adapter and check them\n for (const obj of objList.rows) {\n // check if obj is a channel (all message objects are created as channel)\n if (obj.value.type !== 'channel') continue;\n\n // obj id must have three parts\n const idParts = obj.id.split('.');\n if (idParts.length !== 3) continue;\n\n // obj id part 2 (msgId) must match the message id regexp\n if (!idParts[2].match(MESSAGE_ID_REGEXP_WITH_DLC)) continue;\n\n const [id, dlcStr] = idParts[2].split('-');\n const dlc = (dlcStr === undefined) ? -1 : parseInt(dlcStr, 10);\n\n // is a message with this native.uuid configured whith this id?\n if (this.config.messages && this.config.messages[obj.value.native.uuid] && this.config.messages[obj.value.native.uuid].id === id && this.config.messages[obj.value.native.uuid].dlc === dlc) continue;\n\n // not configured... delete it recusively\n this.log.debug(`delete unconfigured message ${obj.id}`);\n await this.delForeignObjectAsync(obj.id, { recursive: true });\n }\n }\n\n // create or remove raw states\n if (this.config.useRawStates) {\n // raw states are enabled\n await this.extendObjectAsync('raw', {\n type: 'channel',\n common: {\n name: 'Raw message data'\n },\n native: {}\n });\n await this.extendObjectAsync('raw.received', {\n type: 'state',\n common: {\n role: 'json',\n type: 'string',\n name: 'Last received message',\n read: true,\n write: false\n },\n native: {}\n });\n await this.extendObjectAsync('raw.send', {\n type: 'state',\n common: {\n role: 'json',\n type: 'string',\n name: 'Last send message or message to send',\n read: true,\n write: true\n },\n native: {}\n });\n } else {\n // raw states are disabled... delete them if exists\n const chan = await this.getObjectAsync('raw');\n if (chan) {\n this.log.debug(`delete raw objects/states`);\n await this.delObjectAsync('raw', { recursive: true });\n }\n }\n }\n\n /**\n * Translate a configured data type to the corresponding ioBroker common type.\n * @param dataType Data type from the config.\n * @return The ioBroker common type.\n */\n private getCommonTypeFromDataType(dataType: ioBroker.AdapterConfigDataType): ioBroker.CommonType {\n switch (dataType) {\n case 'int8':\n case 'uint8':\n case 'int16_be':\n case 'uint16_le':\n case 'int16_be':\n case 'uint16_le':\n case 'int32_be':\n case 'uint32_le':\n case 'int32_be':\n case 'uint32_le':\n case 'float32_be':\n case 'float32_le':\n case 'double64_be':\n case 'double64_le':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'string':\n return 'string';\n default: // e.g. for custom\n return 'mixed';\n }\n }\n\n /**\n * Handler for received CAN messages.\n * @param msg The received CAN message.\n */\n @autobind\n private async handleCanMsg (msg: CanMessage): Promise {\n // TODO: maybe need to check the nummeric ID against a Set of known IDs for\n // a better performance on systems with verry high message load?\n\n const msgIdHex = getHexId(msg.id, !!msg.ext);\n let handled = false;\n\n // save to raw state if enabled\n if (this.config.useRawStates) {\n this.setStateAsync('raw.received', {\n val: JSON.stringify({\n ...msg,\n data: [...msg.data]\n }),\n ack: true\n });\n }\n\n if (this.canId2Message[msgIdHex]) {\n // it's a known message without DLC\n await this.processReceivedCanMsg(msg, this.canId2Message[msgIdHex]);\n handled = true;\n }\n if (this.canId2Message[`${msgIdHex}-${msg.data.length}`]) {\n // it's a known message with defined DLC\n await this.processReceivedCanMsg(msg, this.canId2Message[`${msgIdHex}-${msg.data.length}`]);\n handled = true;\n }\n\n // just end here if the message was handled by at least one config\n if (handled) {\n return;\n }\n\n if (this.config.autoAddSeenMessages) {\n // it's not known but we should add it\n this.log.debug(`auto adding new message ${msg.id}`);\n const msgCfg: MessageConfig = {\n id: msgIdHex,\n idNum: msg.id,\n idWithDlc: msgIdHex,\n ext: msgIdHex.length > 3,\n uuid: null,\n name: `CAN-Message 0x${msgIdHex}`,\n dlc: -1,\n autosend: false,\n send: false,\n receive: true,\n parsers: {}\n };\n await this.setupMessage(null, msgCfg);\n\n this.setStateAsync(`${msgCfg.id}.json`, JSON.stringify([...msg.data]), true);\n if (this.config.useRtrFlag) {\n this.setStateAsync(`${msgCfg.id}.rtr`, !!msg.rtr, true);\n }\n } else {\n // known message... just ignore\n this.log.debug(`ignoring message ${msg.id}`);\n }\n }\n\n /**\n * Send a CAN message with the given properties.\n * @param id The nummeric ID of the CAN message.\n * @param ext `true` if the message should be send in extended frame format.\n * @param data The data of the message. 0 to 8 bytes buffer.\n * @param rtr Remote transmission request flag.\n */\n private sendCanMsg (id: number, ext: boolean, data: Buffer, rtr: boolean): boolean {\n if (!this.canInterface || !this.canInterface.isReady()) {\n this.log.warn(`Could not send data because CAN interface is not ready.`);\n return false;\n }\n\n return this.canInterface.send(id, ext, data, rtr);\n }\n\n /**\n * Process a received CAN message using the given message config.\n * @param msg The received CAN message.\n * @param msgCfg The config for the Message.\n */\n private async processReceivedCanMsg (msg: CanMessage, msgCfg: MessageConfig): Promise {\n // do nothing if the message isn't configured for receiving\n if (!msgCfg.receive) return;\n\n // set raw states\n this.setStateAsync(`${msgCfg.idWithDlc}.json`, JSON.stringify([...msg.data]), true);\n if (this.config.useRtrFlag) {\n this.setStateAsync(`${msgCfg.idWithDlc}.rtr`, !!msg.rtr, true);\n }\n\n // run the configured parsers\n this.processParsers(msg.data, msgCfg);\n }\n\n /**\n * Process all parsers configured for a message to read the values from a buffer.\n * @param buf The buffer containing the data to read from.\n * @param msgCfg The message config to use.\n */\n private async processParsers (buf: Buffer | null, msgCfg: MessageConfig): Promise {\n if (!buf) return;\n\n for (const parserUuid in msgCfg.parsers) {\n // check if the parser is initialized\n const parser = msgCfg.parsers[parserUuid];\n if (parser.instance) {\n const readResult = await parser.instance.read(buf);\n // check if the parser has read a value (null indecates an error)\n if (readResult instanceof Error) {\n this.log.warn(`Parser reading from received data for ${msgCfg.idWithDlc} failed: ${readResult}`);\n continue;\n }\n if (readResult === undefined) {\n this.log.debug(`read parser for ${msgCfg.idWithDlc} returned undefined`);\n continue;\n }\n this.setStateAsync(`${msgCfg.idWithDlc}.${parser.id}`, readResult as any, true);\n }\n }\n }\n\n /**\n * Setup a message for use in this adapter.\n * This will create/update all needed/configured objects for a message.\n * This will also initialize the parsers if configured.\n * @param msgUuid UUID of the message or `null` if it is an unconfigured message.\n * @param msgCfg The message config containing the information about the message.\n */\n private async setupMessage(msgUuid: string | null, msgCfg: MessageConfig): Promise {\n this.log.debug(`create/update message id: ${msgCfg.idWithDlc}, uuid: ${msgUuid}`);\n\n // create/update channel object for the message\n await this.extendObjectAsync(msgCfg.idWithDlc, {\n type: 'channel',\n common: {\n name: msgCfg.name || `CAN-Message 0x${msgCfg.id}${msgCfg.dlc >= 0 ? ` DLC ${msgCfg.dlc}` : ''}`\n },\n native: {\n uuid: msgUuid\n }\n });\n\n // create/update \"raw\" data state\n await this.extendObjectAsync(`${msgCfg.idWithDlc}.json`, {\n type: 'state',\n common: {\n name: `JSON data`,\n role: 'json',\n type: 'string',\n read: true,\n write: msgCfg.send // allow write only if the message is configured for sending\n },\n native: {}\n });\n\n // create/update or delete \"rtr\" state\n if (this.config.useRtrFlag) {\n await this.extendObjectAsync(`${msgCfg.idWithDlc}.rtr`, {\n type: 'state',\n common: {\n name: `Remote Transmission Request`,\n role: 'indecator',\n type: 'boolean',\n read: true,\n write: msgCfg.send // allow write only if the message is configured for sending\n },\n native: {}\n });\n } else {\n const obj = await this.getObjectAsync(`${msgCfg.idWithDlc}.rtr`);\n if (obj) {\n await this.delObjectAsync(`${msgCfg.idWithDlc}.rtr`);\n }\n }\n\n // create/update or delete \"send\" state depending on \"send\" option\n if (msgCfg.send) {\n await this.extendObjectAsync(`${msgCfg.idWithDlc}.send`, {\n type: 'state',\n common: {\n name: msgCfg.autosend ? 'Manually send current data' : 'Send current data',\n role: 'button',\n type: 'boolean',\n read: false,\n write: true\n },\n native: {}\n });\n } else {\n const obj = await this.getObjectAsync(`${msgCfg.idWithDlc}.send`);\n if (obj) {\n await this.delObjectAsync(`${msgCfg.idWithDlc}.send`);\n }\n }\n\n // setup parser objects\n for (const parserUuid in msgCfg.parsers) {\n const parser = msgCfg.parsers[parserUuid];\n if (PARSER_ID_RESERVED.includes(parser.id)) {\n this.log.warn(`Parser ID ${parser.id} of message ID ${msgCfg.idWithDlc} is reserved and not allowed. This parser will be ignored.`);\n continue;\n }\n if (!parser.id.match(PARSER_ID_REGEXP)) {\n this.log.warn(`Parser ID ${parser.id} of message ID ${msgCfg.idWithDlc} is invalid. This parser will be ignored.`);\n continue;\n }\n this.log.debug(`create/update parser ${msgCfg.idWithDlc}.${parser.id}`);\n await this.extendObjectAsync(`${msgCfg.idWithDlc}.${parser.id}`, {\n type: 'state',\n common: {\n name: parser.name || `Parser ${parser.id}`,\n //role: 'state', // don't set the role here to let the user change it in admin\n type: this.getCommonTypeFromDataType(parser.dataType),\n unit: parser.dataUnit,\n read: true,\n write: msgCfg.send // allow write only if the message is configured for sending\n },\n native: {\n uuid: parserUuid\n }\n });\n }\n\n // remove unconfigured parsers\n const objList = await this.getObjectListAsync({\n startkey: `${this.namespace}.${msgCfg.idWithDlc}.`,\n endkey: `${this.namespace}.${msgCfg.idWithDlc}.\\u9999`\n });\n for (const obj of objList.rows) {\n // check if obj is a state (all parser objects are created as state)\n if (obj.value.type !== 'state') continue;\n\n // obj id must have vour parts\n const idParts = obj.id.split('.');\n if (idParts.length !== 4) continue;\n\n // obj id part 3 (parserId) must not be in the reserved ids\n if (PARSER_ID_RESERVED.includes(idParts[3])) continue;\n\n // is a parser with this native.uuid configured whith this id?\n if (msgCfg.parsers[obj.value.native.uuid] && msgCfg.parsers[obj.value.native.uuid].id === idParts[3]) continue;\n\n // not configured... delete it with all it's child objects\n this.log.debug(`delete unconfigured parser ${obj.id}`);\n await this.delForeignObjectAsync(obj.id);\n }\n\n // save to our canId->msg mapping\n this.canId2Message[msgCfg.idWithDlc] = msgCfg;\n\n // setup the parser instances\n for (const parserUuid in msgCfg.parsers) {\n for (const Parser of knownParsers) {\n if (Parser.canHandle(msgCfg.parsers[parserUuid].dataType)) {\n msgCfg.parsers[parserUuid].instance = new Parser(this, msgCfg.parsers[parserUuid]);\n break;\n }\n }\n if (!msgCfg.parsers[parserUuid].instance) {\n this.log.warn(`No matching parser found for message ID ${msgCfg.idWithDlc} parser ID ${msgCfg.parsers[parserUuid].id} data type ${msgCfg.parsers[parserUuid].dataType}`);\n }\n }\n }\n}\n\nif (require.main !== module) {\n // Export the constructor in compact mode\n module.exports = (options: Partial | undefined) => new CanBusAdapter(options);\n} else {\n // otherwise start the instance directly\n (() => new CanBusAdapter())();\n}\n"]} \ No newline at end of file +{"version":3,"file":"main.js","sourceRoot":"/","sources":["main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAgD;AAChD,qDAA2C;AAG3C,mDAA+C;AAC/C,uCAAqC;AAErC,uCAAwC;AAExC,qCAKkB;AAElB,MAAa,aAAc,SAAQ,KAAK,CAAC,OAAO;IAW9C,YAAY,UAAyC,EAAE;QACrD,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,IAAI,EAAE,QAAQ;SACf,CAAC,CAAC;QAbG,iBAAY,GAAwB,IAAI,CAAC;QAEjD;;;;WAIG;QACK,kBAAa,GAAkC,EAAE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AAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;oBACnF,MAAM;iBACP;aACF;YACD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE;gBACxC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,2CAA2C,MAAM,CAAC,SAAS,cAAc,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,cAAc,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;aAC1K;SACF;IACH,CAAC;CACF;AAnqBC;IADC,0BAAQ;4CAkBR;AAMD;IADC,0BAAQ;6CAYR;AASD;IADC,0BAAQ;kDAkIR;AA6OD;IADC,0BAAQ;iDA6DR;AAhfH,sCA8rBC;AAED,IAAI,MAAM,CAAC,MAAM,EAAE;IACjB,yCAAyC;IACzC,MAAM,CAAC,OAAO,GAAG,CAAC,OAAkD,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;CACrG;KAAM;IACL,wCAAwC;IACxC,CAAC,GAAG,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,EAAE,CAAC;CAC/B","sourcesContent":["import * as utils from '@iobroker/adapter-core';\nimport { autobind } from 'core-decorators';\nimport { CanMessage } from 'socketcan';\n\nimport { CanInterface } from './can-interface';\nimport { getHexId } from './helpers';\n\nimport { knownParsers } from './parsers'\n\nimport {\n MESSAGE_ID_REGEXP,\n MESSAGE_ID_REGEXP_WITH_DLC,\n PARSER_ID_REGEXP,\n PARSER_ID_RESERVED\n} from './consts';\n\nexport class CanBusAdapter extends utils.Adapter {\n\n private canInterface: CanInterface | null = null;\n\n /**\n * Mapping of CAN hex message IDs to the message configs.\n * The IDs must be hex strings (3 or 8 chars) to differentiate between\n * stanard frame and extended frame messages.\n */\n private canId2Message: Record = {};\n\n constructor(options: Partial = {}) {\n super({\n ...options,\n name: 'canbus',\n });\n\n this.on('ready', this.onReady);\n this.on('stateChange', this.onStateChange);\n //this.on('message', this.onMessage);\n this.on('unload', this.onUnload);\n }\n\n /**\n * Is called when databases are connected and adapter received configuration.\n */\n @autobind\n private async onReady(): Promise {\n // Reset the connection indicator during startup\n this.setState('info.connection', false, true);\n\n await this.setupObjects();\n\n this.canInterface = new CanInterface(this);\n this.canInterface.on('stopped', () => {\n this.setState('info.connection', false, true);\n });\n this.canInterface.on('message', this.handleCanMsg);\n\n if (this.canInterface.start()) {\n this.setState('info.connection', true, true);\n }\n\n this.subscribeStatesAsync('*');\n }\n\n /**\n * Is called when adapter shuts down - callback has to be called under any circumstances!\n */\n @autobind\n private onUnload(callback: () => void): void {\n try {\n if (this.canInterface) {\n this.canInterface.stop();\n }\n\n this.log.debug('cleaned everything up...');\n callback();\n } catch (e) {\n callback();\n }\n }\n\n /**\n * Is called if a subscribed state changes.\n *\n * This will trigger the sending of messages and conversion from parser states\n * into message json states if configured.\n */\n @autobind\n private async onStateChange(id: string, state: ioBroker.State | null | undefined): Promise {\n if (state) {\n // The state was changed\n this.log.silly(`state ${id} changed: ${JSON.stringify(state)}`);\n\n // don't do anything if the state is acked\n if (state.ack) return;\n\n // raw.send state?\n if (this.config.useRawStates && id === `${this.namespace}.raw.send`) {\n // load and check message data\n let canMsg: CanMessage;\n try {\n canMsg = JSON.parse(state.val as string)\n } catch (e) {\n this.log.warn(`Invalid JSON in '${this.namespace}.raw.send' state cannot be send!`);\n return;\n }\n if (canMsg && Array.isArray(canMsg.data)) {\n canMsg.data = Buffer.from(canMsg.data);\n }\n if (!canMsg || typeof canMsg.id !== 'number' || !Buffer.isBuffer(canMsg.data)) {\n this.log.warn(`Invalid message data in '${this.namespace}.raw.send' state cannot be send!`);\n return;\n }\n\n // send the message\n this.log.debug(`sendig data from raw.send state`);\n if (this.sendCanMsg(canMsg.id, canMsg.ext || false, canMsg.data, canMsg.rtr || false)) {\n // set ack flag if the message was send and not already acked\n if (!state.ack) {\n await this.setStateAsync(id, {\n ...state,\n ack: true\n });\n }\n }\n return;\n }\n\n // get msg und state ID\n const [,, msgId, stateId] = id.split('.');\n\n // we only want states of a message objects\n if (!msgId || !stateId || !msgId.match(MESSAGE_ID_REGEXP_WITH_DLC)) return;\n\n const msgCfg = this.canId2Message[msgId];\n\n // we need a message and the message must be configured for sending\n if (!msgCfg || !msgCfg.send) return;\n\n switch (stateId) {\n case 'send':\n if (state.val !== true) return;\n\n // send the current json data\n if (await this.sendMessageJsonData(msgCfg)) {\n // set ack flag on the send state if the message was sent\n await this.setStateAsync(`${msgCfg.idWithDlc}.send`, {\n ...state,\n ack: true\n });\n }\n\n break;\n\n case 'json':\n // let the parsers read the data from json to keep the parsers data in sync with the json data\n this.processParsers(this.getBufferFromJsonState(state, msgCfg.idWithDlc), msgCfg);\n\n // send current json data\n if (msgCfg.autosend) {\n this.sendMessageJsonData(msgCfg, state);\n }\n break;\n\n case 'rtr':\n // nothing to do here\n break;\n\n default:\n // it may be a parser...\n if (!stateId.match(PARSER_ID_REGEXP)) return;\n\n // find and run the configured parser\n for (const parserUuid in msgCfg.parsers) {\n if (msgCfg.parsers[parserUuid].id !== stateId) continue;\n\n // check if the parser is initialized\n const parser = msgCfg.parsers[parserUuid];\n if (parser.instance) {\n // load the current json from state\n const jsonState = await this.getStateAsync(`${msgCfg.idWithDlc}.json`);\n let data: Buffer | Error | null = this.getBufferFromJsonState(jsonState, msgCfg.idWithDlc);\n if (data === null) {\n return;\n }\n\n // write to data using the parser\n data = await parser.instance.write(data, state.val);\n\n // check the write result\n if (data instanceof Error) {\n this.log.warn(`Parser writing data for message ID ${msgCfg.idWithDlc} parser ID ${parser.id} failed: ${data}`);\n continue;\n }\n if (!(data instanceof Buffer)) {\n this.log.warn(`Parser writing data for message ID ${msgCfg.idWithDlc} parser ID ${parser.id} failed: Did not return a buffer`);\n continue;\n }\n\n // set the new json state with ack=false\n await this.setStateAsync(`${msgCfg.idWithDlc}.json`, JSON.stringify([...data]), false);\n\n // set ack flag on the parser state\n await this.setStateAsync(`${msgCfg.idWithDlc}.${parser.id}`, {\n ...state,\n ack: true\n });\n }\n\n break;\n }\n }\n\n } else {\n // The state was deleted\n this.log.silly(`state ${id} deleted`);\n }\n }\n\n /**\n * Get a buffer from a `.json` state.\n * The JSON string of the state will be parsed and checked to be an array.\n * @param state The state to get the data from.\n * @param msgId The message ID for logging in case of errors.\n */\n private getBufferFromJsonState (state: ioBroker.State | null | undefined, msgId: string): Buffer | null {\n if (!state) {\n this.log.warn(`Failed parsing JSON from ${this.namespace}.${msgId}.json: No state found`);\n return null;\n }\n\n let parsedJson: unknown;\n try {\n parsedJson = JSON.parse(state.val as string);\n } catch (err) {\n this.log.warn(`Failed parsing JSON from ${this.namespace}.${msgId}.json: ${err}`);\n return null;\n }\n\n if (!Array.isArray(parsedJson)) {\n this.log.warn(`JSON data in ${this.namespace}.${msgId}.json is not an array!`);\n return null;\n }\n if (parsedJson.length > 8) {\n this.log.warn(`Array length of JSON data in ${this.namespace}.${msgId}.json is greater than 8. Only up to 8 data bytes are supportet!`);\n return null;\n }\n\n return Buffer.from(parsedJson);\n }\n\n /**\n * Send the data of a message present in it's json state.\n * For the json and rtr states of the message the ack flag will be set if the message is sent.\n * @param msgCfg The `MessageConfig` of the message for which we should send the data.\n * @param state Optional state to use for sending. If not set, the current state of the object will be read.\n * @return `true` if the message was sent.\n */\n private async sendMessageJsonData (msgCfg: MessageConfig, state?: ioBroker.State | null | undefined): Promise {\n // read the state if not given by argument\n if (!state) {\n state = await this.getStateAsync(`${msgCfg.idWithDlc}.json`);\n if (!state) {\n this.log.warn(`No state found to send for ${this.namespace}.${msgCfg.idWithDlc}.json`);\n return false;\n }\n }\n\n // parse and check the json data\n const data = this.getBufferFromJsonState(state, msgCfg.idWithDlc);\n if (data === null) {\n return false;\n }\n\n // get rtr flag from state\n const rtrState = this.config.useRtrFlag && await this.getStateAsync(`${msgCfg.idWithDlc}.rtr`);\n const rtr = rtrState && !!rtrState.val || false;\n\n // send the message\n if (this.sendCanMsg(msgCfg.idNum, msgCfg.ext, data, rtr)) {\n // set ack flag on json if the message was send and not already acked\n if (!state.ack) {\n await this.setStateAsync(`${msgCfg.idWithDlc}.json`, {\n ...state,\n ack: true\n });\n }\n\n // set ack on rtr if not already acked\n if (rtrState && !rtrState.ack) {\n await this.setStateAsync(`${msgCfg.idWithDlc}.rtr`, {\n ...rtrState,\n ack: true\n });\n }\n\n // set raw state if enabled\n if (this.config.useRawStates) {\n const canMsg: CanMessage = {\n id: msgCfg.idNum,\n ext: msgCfg.ext,\n data\n }\n if (this.config.useRtrFlag) {\n canMsg.rtr = rtr;\n }\n this.setStateAsync('raw.send', {\n val: JSON.stringify({\n ...canMsg,\n data: [...data]\n }),\n ack: true\n });\n }\n\n return true;\n } else {\n this.log.warn(`Sending data message for ${msgCfg.idWithDlc} failed!`);\n return false;\n }\n }\n\n /**\n * Setup the object tree for the messages and parsers.\n */\n private async setupObjects (): Promise {\n // loop over configured messages\n for (const msgUuid in this.config.messages) {\n const msg = this.config.messages[msgUuid];\n if (!msg.id.match(MESSAGE_ID_REGEXP)) {\n this.log.warn(`Message-ID ${msg.id} is invalid. This message will be ignored.`);\n continue;\n }\n\n const msgCfg: MessageConfig = {\n ...msg,\n idNum: parseInt(msg.id, 16),\n idWithDlc: (msg.dlc >= 0) ? `${msg.id}-${msg.dlc}` : msg.id,\n ext: msg.id.length > 3,\n uuid: msgUuid\n };\n\n this.setupMessage(msgUuid, msgCfg);\n }\n\n // delete unconfigured message objects\n if (this.config.deleteUnconfiguredMessages) {\n const objList = await this.getObjectListAsync({\n startkey: `${this.namespace}.`,\n endkey: `${this.namespace}.\\u9999`\n });\n\n // loop over all objects in the namespace of the adapter and check them\n for (const obj of objList.rows) {\n // check if obj is a channel (all message objects are created as channel)\n if (obj.value.type !== 'channel') continue;\n\n // obj id must have three parts\n const idParts = obj.id.split('.');\n if (idParts.length !== 3) continue;\n\n // obj id part 2 (msgId) must match the message id regexp\n if (!idParts[2].match(MESSAGE_ID_REGEXP_WITH_DLC)) continue;\n\n const [id, dlcStr] = idParts[2].split('-');\n const dlc = (dlcStr === undefined) ? -1 : parseInt(dlcStr, 10);\n\n // is a message with this native.uuid configured whith this id?\n if (this.config.messages && this.config.messages[obj.value.native.uuid] && this.config.messages[obj.value.native.uuid].id === id && this.config.messages[obj.value.native.uuid].dlc === dlc) continue;\n\n // not configured... delete it recusively\n this.log.debug(`delete unconfigured message ${obj.id}`);\n await this.delForeignObjectAsync(obj.id, { recursive: true });\n }\n }\n\n // create or remove raw states\n if (this.config.useRawStates) {\n // raw states are enabled\n await this.extendObjectAsync('raw', {\n type: 'channel',\n common: {\n name: 'Raw message data'\n },\n native: {}\n });\n await this.extendObjectAsync('raw.received', {\n type: 'state',\n common: {\n role: 'json',\n type: 'string',\n name: 'Last received message',\n read: true,\n write: false\n },\n native: {}\n });\n await this.extendObjectAsync('raw.send', {\n type: 'state',\n common: {\n role: 'json',\n type: 'string',\n name: 'Last send message or message to send',\n read: true,\n write: true\n },\n native: {}\n });\n } else {\n // raw states are disabled... delete them if exists\n const chan = await this.getObjectAsync('raw');\n if (chan) {\n this.log.debug(`delete raw objects/states`);\n await this.delObjectAsync('raw', { recursive: true });\n }\n }\n }\n\n /**\n * Translate a configured data type to the corresponding ioBroker common type.\n * @param dataType Data type from the config.\n * @return The ioBroker common type.\n */\n private getCommonTypeFromDataType(dataType: ioBroker.AdapterConfigDataType): ioBroker.CommonType {\n switch (dataType) {\n case 'int8':\n case 'uint8':\n case 'int16_be':\n case 'uint16_le':\n case 'int16_be':\n case 'uint16_le':\n case 'int32_be':\n case 'uint32_le':\n case 'int32_be':\n case 'uint32_le':\n case 'float32_be':\n case 'float32_le':\n case 'double64_be':\n case 'double64_le':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'string':\n return 'string';\n default: // e.g. for custom\n return 'mixed';\n }\n }\n\n /**\n * Handler for received CAN messages.\n * @param msg The received CAN message.\n */\n @autobind\n private async handleCanMsg (msg: CanMessage): Promise {\n // TODO: maybe need to check the nummeric ID against a Set of known IDs for\n // a better performance on systems with verry high message load?\n\n const msgIdHex = getHexId(msg.id, !!msg.ext);\n let handled = false;\n\n // save to raw state if enabled\n if (this.config.useRawStates) {\n this.setStateAsync('raw.received', {\n val: JSON.stringify({\n ...msg,\n data: [...msg.data]\n }),\n ack: true\n });\n }\n\n if (this.canId2Message[msgIdHex]) {\n // it's a known message without DLC\n await this.processReceivedCanMsg(msg, this.canId2Message[msgIdHex]);\n handled = true;\n }\n if (this.canId2Message[`${msgIdHex}-${msg.data.length}`]) {\n // it's a known message with defined DLC\n await this.processReceivedCanMsg(msg, this.canId2Message[`${msgIdHex}-${msg.data.length}`]);\n handled = true;\n }\n\n // just end here if the message was handled by at least one config\n if (handled) {\n return;\n }\n\n if (this.config.autoAddSeenMessages) {\n // it's not known but we should add it\n this.log.debug(`auto adding new message ${msg.id}`);\n const msgCfg: MessageConfig = {\n id: msgIdHex,\n idNum: msg.id,\n idWithDlc: msgIdHex,\n ext: msgIdHex.length > 3,\n uuid: null,\n name: `CAN-Message 0x${msgIdHex}`,\n dlc: -1,\n autosend: false,\n send: false,\n receive: true,\n parsers: {}\n };\n await this.setupMessage(null, msgCfg);\n\n this.setStateAsync(`${msgCfg.id}.json`, JSON.stringify([...msg.data]), true);\n if (this.config.useRtrFlag) {\n this.setStateAsync(`${msgCfg.id}.rtr`, !!msg.rtr, true);\n }\n } else {\n // known message... just ignore\n this.log.debug(`ignoring message ${msg.id}`);\n }\n }\n\n /**\n * Send a CAN message with the given properties.\n * @param id The nummeric ID of the CAN message.\n * @param ext `true` if the message should be send in extended frame format.\n * @param data The data of the message. 0 to 8 bytes buffer.\n * @param rtr Remote transmission request flag.\n */\n private sendCanMsg (id: number, ext: boolean, data: Buffer, rtr: boolean): boolean {\n if (!this.canInterface || !this.canInterface.isReady()) {\n this.log.warn(`Could not send data because CAN interface is not ready.`);\n return false;\n }\n\n return this.canInterface.send(id, ext, data, rtr);\n }\n\n /**\n * Process a received CAN message using the given message config.\n * @param msg The received CAN message.\n * @param msgCfg The config for the Message.\n */\n private async processReceivedCanMsg (msg: CanMessage, msgCfg: MessageConfig): Promise {\n // do nothing if the message isn't configured for receiving\n if (!msgCfg.receive) return;\n\n // set raw states\n this.setStateAsync(`${msgCfg.idWithDlc}.json`, JSON.stringify([...msg.data]), true);\n if (this.config.useRtrFlag) {\n this.setStateAsync(`${msgCfg.idWithDlc}.rtr`, !!msg.rtr, true);\n }\n\n // run the configured parsers\n this.processParsers(msg.data, msgCfg);\n }\n\n /**\n * Process all parsers configured for a message to read the values from a buffer.\n * @param buf The buffer containing the data to read from.\n * @param msgCfg The message config to use.\n */\n private async processParsers (buf: Buffer | null, msgCfg: MessageConfig): Promise {\n if (!buf) return;\n\n for (const parserUuid in msgCfg.parsers) {\n // check if the parser is initialized\n const parser = msgCfg.parsers[parserUuid];\n if (parser.instance) {\n const readResult = await parser.instance.read(buf);\n // check if the parser has read a value (null indecates an error)\n if (readResult instanceof Error) {\n this.log.warn(`Parser reading from received data for ${msgCfg.idWithDlc} failed: ${readResult}`);\n continue;\n }\n if (readResult === undefined) {\n this.log.debug(`read parser for ${msgCfg.idWithDlc} returned undefined`);\n continue;\n }\n this.setStateAsync(`${msgCfg.idWithDlc}.${parser.id}`, readResult as any, true);\n }\n }\n }\n\n /**\n * Setup a message for use in this adapter.\n * This will create/update all needed/configured objects for a message.\n * This will also initialize the parsers if configured.\n * @param msgUuid UUID of the message or `null` if it is an unconfigured message.\n * @param msgCfg The message config containing the information about the message.\n */\n private async setupMessage(msgUuid: string | null, msgCfg: MessageConfig): Promise {\n this.log.debug(`create/update message id: ${msgCfg.idWithDlc}, uuid: ${msgUuid}`);\n\n // create/update channel object for the message\n await this.extendObjectAsync(msgCfg.idWithDlc, {\n type: 'channel',\n common: {\n name: msgCfg.name || `CAN-Message 0x${msgCfg.id}${msgCfg.dlc >= 0 ? ` DLC ${msgCfg.dlc}` : ''}`\n },\n native: {\n uuid: msgUuid\n }\n });\n\n // create/update \"raw\" data state\n await this.extendObjectAsync(`${msgCfg.idWithDlc}.json`, {\n type: 'state',\n common: {\n name: `JSON data`,\n role: 'json',\n type: 'string',\n read: true,\n write: msgCfg.send // allow write only if the message is configured for sending\n },\n native: {}\n });\n\n // create/update or delete \"rtr\" state\n if (this.config.useRtrFlag) {\n await this.extendObjectAsync(`${msgCfg.idWithDlc}.rtr`, {\n type: 'state',\n common: {\n name: `Remote Transmission Request`,\n role: 'indecator',\n type: 'boolean',\n read: true,\n write: msgCfg.send // allow write only if the message is configured for sending\n },\n native: {}\n });\n } else {\n const obj = await this.getObjectAsync(`${msgCfg.idWithDlc}.rtr`);\n if (obj) {\n await this.delObjectAsync(`${msgCfg.idWithDlc}.rtr`);\n }\n }\n\n // create/update or delete \"send\" state depending on \"send\" option\n if (msgCfg.send) {\n await this.extendObjectAsync(`${msgCfg.idWithDlc}.send`, {\n type: 'state',\n common: {\n name: msgCfg.autosend ? 'Manually send current data' : 'Send current data',\n role: 'button',\n type: 'boolean',\n read: false,\n write: true\n },\n native: {}\n });\n } else {\n const obj = await this.getObjectAsync(`${msgCfg.idWithDlc}.send`);\n if (obj) {\n await this.delObjectAsync(`${msgCfg.idWithDlc}.send`);\n }\n }\n\n // setup parser objects\n for (const parserUuid in msgCfg.parsers) {\n const parser = msgCfg.parsers[parserUuid];\n if (PARSER_ID_RESERVED.includes(parser.id)) {\n this.log.warn(`Parser ID ${parser.id} of message ID ${msgCfg.idWithDlc} is reserved and not allowed. This parser will be ignored.`);\n continue;\n }\n if (!parser.id.match(PARSER_ID_REGEXP)) {\n this.log.warn(`Parser ID ${parser.id} of message ID ${msgCfg.idWithDlc} is invalid. This parser will be ignored.`);\n continue;\n }\n this.log.debug(`create/update parser ${msgCfg.idWithDlc}.${parser.id}`);\n await this.extendObjectAsync(`${msgCfg.idWithDlc}.${parser.id}`, {\n type: 'state',\n common: {\n name: parser.name || `Parser ${parser.id}`,\n //role: 'state', // don't set the role here to let the user change it in admin\n type: this.getCommonTypeFromDataType(parser.dataType),\n unit: parser.dataUnit,\n read: true,\n write: msgCfg.send // allow write only if the message is configured for sending\n },\n native: {\n uuid: parserUuid\n }\n });\n }\n\n // remove unconfigured parsers\n const objList = await this.getObjectListAsync({\n startkey: `${this.namespace}.${msgCfg.idWithDlc}.`,\n endkey: `${this.namespace}.${msgCfg.idWithDlc}.\\u9999`\n });\n for (const obj of objList.rows) {\n // check if obj is a state (all parser objects are created as state)\n if (obj.value.type !== 'state') continue;\n\n // obj id must have vour parts\n const idParts = obj.id.split('.');\n if (idParts.length !== 4) continue;\n\n // obj id part 3 (parserId) must not be in the reserved ids\n if (PARSER_ID_RESERVED.includes(idParts[3])) continue;\n\n // is a parser with this native.uuid configured whith this id?\n if (msgCfg.parsers[obj.value.native.uuid] && msgCfg.parsers[obj.value.native.uuid].id === idParts[3]) continue;\n\n // not configured... delete it with all it's child objects\n this.log.debug(`delete unconfigured parser ${obj.id}`);\n await this.delForeignObjectAsync(obj.id);\n }\n\n // save to our canId->msg mapping\n this.canId2Message[msgCfg.idWithDlc] = msgCfg;\n\n // setup the parser instances\n for (const parserUuid in msgCfg.parsers) {\n for (const Parser of knownParsers) {\n if (Parser.canHandle(msgCfg.parsers[parserUuid].dataType)) {\n msgCfg.parsers[parserUuid].instance = new Parser(this, msgCfg.parsers[parserUuid]);\n break;\n }\n }\n if (!msgCfg.parsers[parserUuid].instance) {\n this.log.warn(`No matching parser found for message ID ${msgCfg.idWithDlc} parser ID ${msgCfg.parsers[parserUuid].id} data type ${msgCfg.parsers[parserUuid].dataType}`);\n }\n }\n }\n}\n\nif (module.parent) {\n // Export the constructor in compact mode\n module.exports = (options: Partial | undefined) => new CanBusAdapter(options);\n} else {\n // otherwise start the instance directly\n (() => new CanBusAdapter())();\n}\n"]} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index feabc934..05a66b3d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -718,7 +718,7 @@ export class CanBusAdapter extends utils.Adapter { } } -if (require.main !== module) { +if (module.parent) { // Export the constructor in compact mode module.exports = (options: Partial | undefined) => new CanBusAdapter(options); } else {