node-red-contrib-omron-fins
Advanced tools
Comparing version 0.5.0-beta.4 to 0.5.0
@@ -70,5 +70,4 @@ /* | ||
let fins_client = fins.FinsClient(port, host, options, false); | ||
options.autoConnect = options.autoConnect == null ? true : options.autoConnect; | ||
let connecting = false; | ||
let preventAutoReconnect = true; | ||
let inhibitAutoReconnect = true; | ||
@@ -143,3 +142,3 @@ const finsClientWrapper = { | ||
connect(host, port, opts) { | ||
preventAutoReconnect = false; | ||
inhibitAutoReconnect = false; //as `connect` is being called, assume the user wants the connection to auto recover. | ||
finsClientWrapper.reconnect(host, port, opts); | ||
@@ -169,6 +168,8 @@ }, | ||
disconnect() { | ||
preventAutoReconnect = true; | ||
inhibitAutoReconnect = true; //as `disconnect` is being called, assume the user wants to stay disconnected. | ||
if (fins_client) { | ||
fins_client.disconnect(); | ||
} | ||
clearTimeout(finsClientWrapper.reconnectTimeOver); | ||
finsClientWrapper.reconnectTimeOver = null; | ||
connecting = false; | ||
@@ -215,7 +216,7 @@ }, | ||
try { | ||
clearTimeout(finsClientWrapper.reconnectTimeOver); | ||
finsClientWrapper.reconnectTimeOver = null; | ||
clearTimeout(finsClientWrapper.reconnectTimer); | ||
connecting = false; | ||
if (finsClientWrapper.reconnectTimer) { | ||
clearTimeout(finsClientWrapper.reconnectTimer); | ||
finsClientWrapper.reconnectTimer = null; | ||
} | ||
finsClientWrapper.reconnectTimer = null; | ||
node.log(`connected ~ ${id}`); | ||
@@ -229,2 +230,4 @@ // eslint-disable-next-line no-empty | ||
try { | ||
clearTimeout(finsClientWrapper.reconnectTimeOver); | ||
finsClientWrapper.reconnectTimeOver = null; | ||
connecting = false; | ||
@@ -239,3 +242,3 @@ node.log(`connection closed ~ ${id}`); | ||
if (!finsClientWrapper.connected) { | ||
if (!preventAutoReconnect && !finsClientWrapper.reconnectTimer) { | ||
if (!inhibitAutoReconnect && !finsClientWrapper.reconnectTimer) { | ||
scheduleReconnect(); | ||
@@ -249,5 +252,5 @@ } | ||
if(!connecting) { | ||
if (!finsClientWrapper.reconnectTimer && options.autoConnect && !preventAutoReconnect) { | ||
if (!finsClientWrapper.reconnectTimer && !inhibitAutoReconnect) { | ||
finsClientWrapper.reconnectTimer = setTimeout(() => { | ||
if (finsClientWrapper.reconnectTimer && options.autoConnect && !preventAutoReconnect) { | ||
if (finsClientWrapper.reconnectTimer && !inhibitAutoReconnect) { | ||
finsClientWrapper.reconnectTimer = null; | ||
@@ -274,6 +277,4 @@ node.log(`Scheduled reconnect ~ ${id}`); | ||
if(cli) { | ||
if(cli.reconnectTimer) { | ||
clearTimeout(cli.reconnectTimer); | ||
cli.reconnectTimer = null; | ||
} | ||
clearTimeout(cli.reconnectTimer); | ||
cli.reconnectTimer = null; | ||
cli.removeAllListeners(); | ||
@@ -280,0 +281,0 @@ if(cli.connected) { |
@@ -25,68 +25,79 @@ /* | ||
var {FinsConstants: constants, FinsDataUtils: {isInt}} = require('omron-fins'); | ||
const {FinsConstants: constants, FinsDataUtils: {isInt}} = require('omron-fins'); | ||
const connection_pool = require('../connection_pool.js'); | ||
/*! | ||
* Get value of environment variable. | ||
* @param {RED} _RED - accessing RED object | ||
* @param {String} name - name of variable | ||
* @return {String} value of env var / setting | ||
*/ | ||
function getSetting(_RED, name) { | ||
var result = _RED.util.getObjectProperty(_RED.settings, name); | ||
return result || process.env[name]; | ||
} | ||
module.exports = function (RED) { | ||
/** | ||
* Checks if a String contains any Environment Variable specifiers and returns | ||
* it with their values substituted in place. | ||
* | ||
* For example, if the env var `WHO` is set to `Joe`, the string `Hello ${WHO}!` | ||
* will return `Hello Joe!`. | ||
* @param {String} value - the string to parse | ||
* @param {Node} node - the node evaluating the property | ||
* @return {String} The parsed string | ||
*/ | ||
function resolveSetting(value, RED) { | ||
try { | ||
if (!value) return value; | ||
if (typeof value != "string") return value; | ||
var result; | ||
if (/^\${[^}]+}$/.test(value)) { | ||
// ${ENV_VAR} | ||
var name = value.substring(2, value.length - 1); | ||
result = getSetting(RED, name); | ||
} else { | ||
// FOO${ENV_VAR}BAR | ||
result = value.replace(/\${([^}]+)}/g, function (match, name) { | ||
return getSetting(RED, name); | ||
}); | ||
/*! | ||
* Get value of environment variable. | ||
* @param {RED} _RED - accessing RED object | ||
* @param {String} name - name of variable | ||
* @return {String} value of env var / setting | ||
*/ | ||
function getSetting(name) { | ||
let result = RED.util.getObjectProperty(RED.settings, name); | ||
return result || process.env[name]; | ||
} | ||
/** | ||
* Checks if a String contains any Environment Variable specifiers and returns | ||
* it with their values substituted in place. | ||
* | ||
* For example, if the env var `WHO` is set to `Joe`, the string `Hello ${WHO}!` | ||
* will return `Hello Joe!`. | ||
* @param {String} value - the string to parse | ||
* @param {Node} node - the node evaluating the property | ||
* @return {String} The parsed string | ||
*/ | ||
function resolveSetting(value) { | ||
try { | ||
if (!value) return value; | ||
if (typeof value != "string") return value; | ||
let result; | ||
if (/^\${[^}]+}$/.test(value)) { | ||
// ${ENV_VAR} | ||
let name = value.substring(2, value.length - 1); | ||
result = getSetting(name); | ||
} else { | ||
// FOO${ENV_VAR}BAR | ||
result = value.replace(/\${([^}]+)}/g, function (match, name) { | ||
return getSetting(name); | ||
}); | ||
} | ||
return (result == null) ? value : result; | ||
} catch (error) { | ||
return value; | ||
} | ||
return (result == null) ? value : result; | ||
} catch (error) { | ||
return value; | ||
} | ||
} | ||
module.exports = function (RED) { | ||
const connection_pool = require('../connection_pool.js'); | ||
function omronConnection(config) { | ||
RED.nodes.createNode(this, config); | ||
this.name = config.name; | ||
this.host = resolveSetting(config.host, RED); | ||
this.port = resolveSetting(config.port, RED); | ||
this.host = resolveSetting(config.host); | ||
this.port = resolveSetting(config.port); | ||
this.options = {}; | ||
this.options.MODE = 'CJ'; | ||
this.options.protocol = 'udp'; | ||
if (config.protocolType == "env") { | ||
this.options.protocol = resolveSetting(config.protocol, RED); | ||
this.options.protocol = ''; | ||
if(config.protocol) this.options.protocol = getSetting(config.protocol); | ||
} else { | ||
this.options.protocol = config.protocolType || "udp"; | ||
} | ||
this.options.MODE = config.MODE ? config.MODE : "CSCJ"; | ||
this.options.ICF = isInt(resolveSetting(config.ICF, RED), constants.DefaultFinsHeader.ICF); | ||
this.options.DNA = isInt(resolveSetting(config.DNA, RED), constants.DefaultFinsHeader.DNA); | ||
this.options.DA1 = isInt(resolveSetting(config.DA1, RED), constants.DefaultFinsHeader.DA1); | ||
this.options.DA2 = isInt(resolveSetting(config.DA2, RED), constants.DefaultFinsHeader.DA2); | ||
this.options.SNA = isInt(resolveSetting(config.SNA, RED), constants.DefaultFinsHeader.SNA); | ||
this.options.SA1 = isInt(resolveSetting(config.SA1, RED), constants.DefaultFinsHeader.SA1); | ||
this.options.SA2 = isInt(resolveSetting(config.SA2, RED), constants.DefaultFinsHeader.SA2); | ||
if(!config.MODEType && (config.MODE == 'CSCJ' || config.MODE == 'NJNX' || config.MODE == 'CV')) { | ||
config.MODEType = config.MODE.substr(0,2); | ||
} | ||
if (config.MODEType == 'env') { | ||
if(config.MODE) this.options.MODE = getSetting(config.MODE); | ||
} else { | ||
this.options.MODE = config.MODEType || 'CJ'; | ||
} | ||
if(this.options.MODE) this.options.MODE = this.options.MODE.substr(0,2); | ||
this.options.ICF = isInt(resolveSetting(config.ICF), constants.DefaultFinsHeader.ICF); | ||
this.options.DNA = isInt(resolveSetting(config.DNA), constants.DefaultFinsHeader.DNA); | ||
this.options.DA1 = isInt(resolveSetting(config.DA1), constants.DefaultFinsHeader.DA1); | ||
this.options.DA2 = isInt(resolveSetting(config.DA2), constants.DefaultFinsHeader.DA2); | ||
this.options.SNA = isInt(resolveSetting(config.SNA), constants.DefaultFinsHeader.SNA); | ||
this.options.SA1 = isInt(resolveSetting(config.SA1), constants.DefaultFinsHeader.SA1); | ||
this.options.SA2 = isInt(resolveSetting(config.SA2), constants.DefaultFinsHeader.SA2); | ||
this.autoConnect = config.autoConnect == null ? true : config.autoConnect; | ||
@@ -93,0 +104,0 @@ |
{ | ||
"name": "node-red-contrib-omron-fins", | ||
"version": "0.5.0-beta.4", | ||
"version": "0.5.0", | ||
"author": { | ||
@@ -28,3 +28,3 @@ "name": "Steve-Mcl", | ||
"dependencies": { | ||
"omron-fins": "0.5.0-beta.4" | ||
"omron-fins": "0.5.0" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
335065
1806
+ Addedomron-fins@0.5.0(transitive)
- Removedomron-fins@0.5.0-beta.4(transitive)
Updatedomron-fins@0.5.0