diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index c389688..bbfc422 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: - node-version: [12.x] + node-version: [16.x] steps: - uses: actions/checkout@v1 diff --git a/LICENSE b/LICENSE index 9ba8fb6..296af10 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018-2022 Apollon77 +Copyright (c) 2018-2023 Apollon77 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index cbd4912..b7e7e64 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,12 @@ When you try to read data while communication is in progress your callback is ca * Also build the libmbus binaries and tools? (if needed) ## Changelog + +### __WORK IN PROGRESS__ +* (JKRhb) add support for Node.js 20.x +* (hasanheroglu) add context aware support +* (sjlongland) make device ping configurable and add TCP timeout documentation + ### 2.0.0 (2022-06-29) * IMPORTANT: Minimum node.js version is not 12.x and all LTS supported up to 18.x * Add promisified methods with Async at the end of the name (e.g. `connectAsync`) diff --git a/index.js b/index.js index cc5b229..5123e2c 100644 --- a/index.js +++ b/index.js @@ -131,17 +131,13 @@ class MbusMaster { // pingFirst: Work-around buggy behaviour with some M-Bus devices, // notably Sontex Supercal531 // https://github.com/rscada/libmbus/pull/95 - let pingFirst = true; if (typeof(options) === "function") { callback = options; options = null; } - if (options) { - // de-structure - ({pingFirst} = options); - } + const pingFirst = (options && options.pingFirst !== undefined) ? options.pingFirst : true; if (!this.mbusMaster.connected && !this.options.autoConnect) { if (callback) callback(new Error('Not connected and autoConnect is false')); @@ -181,7 +177,7 @@ class MbusMaster { }); } - getDataAsync(address, options=null) { + getDataAsync(address, options = null) { return new Promise((resolve, reject) => { this.getData(address, options, (err, data) => { if (err) { diff --git a/src/mbus-master.cc b/src/mbus-master.cc index 346c698..a7f4e41 100644 --- a/src/mbus-master.cc +++ b/src/mbus-master.cc @@ -259,15 +259,12 @@ class RecieveWorker : public Nan::AsyncWorker { memset((void *)&reply, 0, sizeof(mbus_frame)); - if (ping_first) + if (ping_first && init_slaves(handle) == 0) { - if (init_slaves(handle) == 0) - { - sprintf(error, "Failed to init slaves."); - SetErrorMessage(error); - uv_rwlock_wrunlock(lock); - return; - } + sprintf(error, "Failed to init slaves."); + SetErrorMessage(error); + uv_rwlock_wrunlock(lock); + return; } if (mbus_is_secondary_address(addr_str))