-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(test): clean up cbs and fix IO Node tests
- Loading branch information
Showing
22 changed files
with
557 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
@author <a href="mailto:[email protected]">Klaus Landsdorf</a> (Bianco Royal) | ||
*/ | ||
|
||
module.exports = function (RED) { | ||
'use strict' | ||
// SOURCE-MAP-REQUIRED | ||
|
@@ -25,29 +26,45 @@ module.exports = function (RED) { | |
const node = this | ||
node.setMaxListeners(UNLIMITED_LISTENERS) | ||
node.lastUpdatedAt = null | ||
const lineReader = new coreIO.LineByLineReader(node.path) | ||
|
||
if (!fs.existsSync(node.path)) { | ||
coreIO.internalDebug('IO File Not Found ' + node.path) | ||
node.warn('Modbus IO File Not Found ' + node.path) | ||
return | ||
} | ||
|
||
node.lineReader = new coreIO.LineByLineReader(node.path) | ||
coreIO.internalDebug('Read IO File ' + node.path) | ||
node.configData = [] | ||
|
||
lineReader.on('error', function (err) { | ||
coreIO.internalDebug(err.message) | ||
}) | ||
|
||
lineReader.on('line', function (line) { | ||
if (line) { | ||
node.configData.push(line) | ||
// node.configData.push(JSON.parse(line)) | ||
} | ||
}) | ||
function setLineReaderEvents () { | ||
node.lineReader.removeAllListeners() | ||
|
||
node.lineReader.on('error', function (err) { | ||
coreIO.internalDebug(err.message) | ||
}) | ||
|
||
node.lineReader.on('line', function (line) { | ||
if (line) { | ||
node.configData.push(line) | ||
} | ||
}) | ||
|
||
node.lineReader.on('end', function () { | ||
node.lastUpdatedAt = Date.now() | ||
coreIO.internalDebug('Read IO Done From File ' + node.path) | ||
node.warn({ | ||
payload: coreIO.allValueNamesFromIOFile(node), | ||
name: 'Modbus Value Names From IO File', | ||
path: node.path | ||
}) | ||
node.emit('updatedConfig', node.configData) | ||
}) | ||
|
||
lineReader.on('end', function () { | ||
node.lastUpdatedAt = Date.now() | ||
coreIO.internalDebug('Read IO Done From File ' + node.path) | ||
node.warn({ payload: coreIO.allValueNamesFromIOFile(node), name: 'Modbus Value Names From IO File', path: node.path }) | ||
node.emit('updatedConfig', node.configData) | ||
}) | ||
coreIO.internalDebug('Loading IO File Started For ' + node.path) | ||
} | ||
|
||
coreIO.internalDebug('Loading IO File Started For ' + node.path) | ||
setLineReaderEvents() | ||
|
||
node.watcher = fs.watchFile(node.path, (curr, prev) => { | ||
coreIO.internalDebug(`the current mtime is: ${curr.mtime}`) | ||
|
@@ -57,32 +74,18 @@ module.exports = function (RED) { | |
coreIO.internalDebug('Reload IO File ' + node.path) | ||
node.configData = [] | ||
delete node.lastUpdatedAt | ||
|
||
const lineReader = new coreIO.LineByLineReader(node.path) | ||
lineReader.on('error', function (err) { | ||
coreIO.internalDebug(err.message) | ||
}) | ||
|
||
lineReader.on('line', function (line) { | ||
if (line) { | ||
node.configData.push(JSON.parse(line)) | ||
} | ||
}) | ||
|
||
lineReader.on('end', function () { | ||
node.lastUpdatedAt = Date.now() | ||
coreIO.internalDebug('Reload IO Done From File ' + node.path) | ||
node.warn({ payload: coreIO.allValueNamesFromIOFile(node), name: 'Modbus Value Names From IO File', path: node.path }) | ||
node.emit('updatedConfig', node.configData) | ||
}) | ||
|
||
node.lineReader.removeAllListeners() | ||
node.lineReader = new coreIO.LineByLineReader(node.path) | ||
setLineReaderEvents() | ||
coreIO.internalDebug('Reloading IO File Started For ' + node.path) | ||
} | ||
}) | ||
|
||
node.on('close', function (done) { | ||
fs.unwatchFile(node.path) | ||
node.watcher.stop() | ||
node.lineReader.removeAllListeners() | ||
node.removeAllListeners() | ||
done() | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.