Skip to content

Commit

Permalink
Added help for options in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Oct 27, 2023
1 parent 5c072dd commit 3260184
Show file tree
Hide file tree
Showing 28 changed files with 878 additions and 686 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2022 Bluefox <[email protected]>
Copyright (c) 2015-2023 Bluefox <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
92 changes: 53 additions & 39 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function extractValue(type, len, buffer, offset) {
}
return str;
default:
throw new Error('Invalid type: ' + type);
throw new Error(`Invalid type: ${type}`);
return 0;
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ function writeValue(type, value, len) {
}
break;
default:
throw new Error('Invalid type: ' + type);
throw new Error(`Invalid type: ${type}`);
buffer = Buffer.alloc(2);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/jsmodbus/transports/modbus-client-serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = stampit()
}
let text = '';
for (let i = 0; i < buf.length; i++) {
text += (text ? ',' : '') + (isHex ? '0x' + buf[i].toString(16) : buf[i]);
text += (text ? ',' : '') + (isHex ? `0x${buf[i].toString(16)}` : buf[i]);
}
return text;
}
Expand Down Expand Up @@ -123,14 +123,14 @@ module.exports = stampit()

if (crc.crc16modbus(pdu) === 0) { /* PDU is valid if CRC across whole PDU equals 0, else ignore and do nothing */
if (this.options.unitId !== undefined && pdu[0] !== this.options.unitId) {
// answer for wrong device
this.log.debug('received answer for wrong ID ' + buffer[0] + ', expected ' + this.options.unitId);
// answer for a wrong device
this.log.debug(`received answer for wrong ID ${buffer[0]}, expected ${this.options.unitId}`);
}
// emit data event and let the
// listener handle the pdu
this.emit('data', pdu.slice(1, pdu.length - 2), pdu[0]);
} else {
this.log.error('Wrong CRC for frame: ' + toStrArray(pdu));
this.log.error(`Wrong CRC for frame: ${toStrArray(pdu)}`);
// reset buffer and try again
buffer = Buffer.alloc(0);
break;
Expand Down
4 changes: 2 additions & 2 deletions lib/jsmodbus/transports/modbus-client-tcp-rtu.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ module.exports = stampit()

if (crc.crc16modbus(pdu) === 0) { /* PDU is valid if CRC across whole PDU equals 0, else ignore and do nothing */
if (this.options.unitId !== undefined && pdu[0] !== this.options.unitId) {
// answer for wrong device
// answer for a wrong device
this.log.debug(`received answer for wrong ID ${buffer[0]}, expected ${this.options.unitId}`);
}
// emit data event and let the
// listener handle the pdu
this.emit('data', pdu.slice(1, pdu.length - 2), pdu[0]);
} else {
this.log.error('Wrong CRC for frame: ' + toStrArray(pdu));
this.log.error(`Wrong CRC for frame: ${toStrArray(pdu)}`);
// reset buffer and try again
buffer = new Buffer(0);
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/jsmodbus/transports/modbus-server-tcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = stampit()
}
});

this.log.debug('server is listening on port', tcp.hostname + ':' + tcp.port);
this.log.debug('server is listening on port', `${tcp.hostname}:${tcp.port}`);
this.on('newState_ready', flush);
this.setState('ready');
};
Expand Down
22 changes: 11 additions & 11 deletions lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ function Master(options, adapter) {
modbusClient.close();
}
} catch (e) {
adapter.log.error('Cannot close master: ' + e);
adapter.log.error(`Cannot close master: ${e}`);
}

if (connected) {
if (options.config.tcp) {
adapter.log.info('Disconnected from slave ' + options.config.tcp.bind);
adapter.log.info(`Disconnected from slave ${options.config.tcp.bind}`);
} else {
adapter.log.info('Disconnected from slave');
}
Expand Down Expand Up @@ -197,7 +197,7 @@ function Master(options, adapter) {
adapter.log.warn(`[${prefixAddr}] Calculation of a scaleFactor which is based on another scaleFactor seems strange. Please check the config for address ${regs.config[n].address} !`);
}
// calculate value from formula or report an error
const func = new Function('x', 'sf', 'return ' + regs.config[n].formula);
const func = new Function('x', 'sf', `return ${regs.config[n].formula}`);
val = func(val, scaleFactors[regs.deviceId]);
val = Math.round(val * options.config.round) / options.config.round;
} catch (e) {
Expand All @@ -211,7 +211,7 @@ function Master(options, adapter) {
scaleFactors[regs.deviceId][regs.config[n]._address] = val;
showDebug && adapter.log.debug(`[${prefixAddr}] Scale factor value stored from this address = ${val}`);
} catch (err) {
adapter.log.error('Can not set value: ' + err.message);
adapter.log.error(`Can not set value: ${err.message}`);
}
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ function Master(options, adapter) {
}

// calculate value from formula or report an error
const func = new Function('x', 'sf', 'return ' + regs.config[n].formula);
const func = new Function('x', 'sf', `return ${regs.config[n].formula}`);
val = func(val, scaleFactors[regs.deviceId]);
showDebug && adapter.log.debug(`[${prefixAddr}] Calculation result = ${val}, type = ${typeof val}`);
// only do rounding in case the calculation result is a number
Expand All @@ -283,7 +283,7 @@ function Master(options, adapter) {
err && adapter.log.error(`Can not set state ${id}: ${err}`));
}
} catch (err) {
adapter.log.error('Can not set value: ' + err.message);
adapter.log.error(`Can not set value: ${err.message}`);
}
}
} else {
Expand Down Expand Up @@ -366,7 +366,7 @@ function Master(options, adapter) {
modbusClient.writeMultipleRegisters(regs.deviceId, obj.native.address, buffer)
.then(() => callback())
.catch(err => {
adapter.log.error('Cannot write multiple registers_: ' + JSON.stringify(err));
adapter.log.error(`Cannot write multiple registers_: ${JSON.stringify(err)}`);
callback(err);
});
} else {
Expand Down Expand Up @@ -671,7 +671,7 @@ function Master(options, adapter) {
let _id = id.substring(adapter.namespace.length + 1);
adapter.setState(id, ackObjects[_id] ? ackObjects[_id].val : null, true, err =>
// analyse if the state could be set (because of permissions)
err && adapter.log.error('Can not set state ' + id + ': ' + err));
err && adapter.log.error(`Can not set state ${id}: ${err}`));
});
}
};
Expand Down Expand Up @@ -793,7 +793,7 @@ function Master(options, adapter) {
modbusClient.on('connect', () => {
if (!connected) {
if (options.config.type === 'tcp') {
adapter.log.info('Connected to slave ' + options.config.tcp.bind);
adapter.log.info(`Connected to slave ${options.config.tcp.bind}`);
} else {
adapter.log.info('Connected to slave');
}
Expand Down Expand Up @@ -827,7 +827,7 @@ function Master(options, adapter) {
if (isStop) {
return;
}
adapter.log.warn('On error: ' + JSON.stringify(err));
adapter.log.warn(`On error: ${JSON.stringify(err)}`);

reconnectTimeout = reconnectTimeout || setTimeout(reconnect, 1000);
});
Expand All @@ -836,7 +836,7 @@ function Master(options, adapter) {
if (isStop) {
return;
}
adapter.log.warn('Error: ' + JSON.stringify(err));
adapter.log.warn(`Error: ${JSON.stringify(err)}`);
if (!reconnectTimeout) {
reconnectTimeout = setTimeout(reconnect, 1000);
}
Expand Down
28 changes: 14 additions & 14 deletions lib/slave.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function Slave(options, adapter) {

this.write = (id, state) => {
if (!objects[id] || !objects[id].native) {
return adapter.log.error('Can not set state ' + id + ': unknown object');
return adapter.log.error(`Can not set state ${id}: unknown object`);
}

if (objects[id].native.float === undefined) {
Expand All @@ -59,7 +59,7 @@ function Slave(options, adapter) {
let t = typeof state.val;
let type = objects[id].native.regType;
if (!device || !device[type]) {
return adapter.log.error('Invalid type ' + type);
return adapter.log.error(`Invalid type ${type}`);
}
let regs = device[type];
regs.changed = true;
Expand Down Expand Up @@ -93,7 +93,7 @@ function Slave(options, adapter) {
adapter.log.warn(`Can not write value ${val}: ${err}`);
}
} else {
adapter.log.error('Unknown state "' + id + '" type: ' + objects[id].native.regType);
adapter.log.error(`Unknown state "${id}" type: ${objects[id].native.regType}`);
}
};

Expand Down Expand Up @@ -243,7 +243,7 @@ function Slave(options, adapter) {
if (a >= 0 && regs.mapping[a]) {
adapter.setState(regs.mapping[a], value, true, err =>
// analyse if the state could be set (because of permissions)
err && adapter.log.error('Can not set state: ' + err.message));
err && adapter.log.error(`Can not set state: ${err.message}`));
regs.values[a] = value;
}
});
Expand Down Expand Up @@ -275,7 +275,7 @@ function Slave(options, adapter) {
value = value & mPow2[(i + start) % 8];
adapter.setState(regs.mapping[a], !!value, true, err =>
// analyse if the state could be set (because of permissions)
err && adapter.log.error('Can not set state: ' + err.message));
err && adapter.log.error(`Can not set state: ${err.message}`));

regs.values[a] = !!value;
}
Expand All @@ -302,9 +302,9 @@ function Slave(options, adapter) {

adapter.setState(regs.mapping[a], val, true, err =>
// analyse if the state could be set (because of permissions)
err && adapter.log.error('Can not set state: ' + err.message));
err && adapter.log.error(`Can not set state: ${err.message}`));
} catch (err) {
adapter.log.error('Can not set value: ' + err.message);
adapter.log.error(`Can not set value: ${err.message}`);
}

regs.values[a] = buf[0];
Expand Down Expand Up @@ -336,9 +336,9 @@ function Slave(options, adapter) {
}
adapter.setState(regs.mapping[a], val, true, err =>
// analyse if the state could be set (because of permissions)
err && adapter.log.error('Can not set state: ' + err.message));
err && adapter.log.error(`Can not set state: ${err.message}`));
} catch (err) {
adapter.log.error('Can not set value: ' + err.message);
adapter.log.error(`Can not set value: ${err.message}`);
}

for (let k = 0; k < native.len * 2; k++) {
Expand All @@ -356,26 +356,26 @@ function Slave(options, adapter) {
let list = '';
if (modbusServer) {
list = getListOfClients(modbusServer.getClients());
adapter.log.debug('+ Clients connected: ' + list);
adapter.log.debug(`+ Clients connected: ${list}`);
}
adapter.setState('info.connection', list, true);
})
.on('close', client => {
let list = '';
if (modbusServer) {
list = getListOfClients(modbusServer.getClients());
adapter.log.debug('- Client connected: ' + list);
adapter.log.debug(`- Client connected: ${list}`);
}
adapter.setState('info.connection', list, true);
})
.on('error', err => {
let list = '';
if (modbusServer) {
list = getListOfClients(modbusServer.getClients());
adapter.log.info('- Clients connected: ' + list);
adapter.log.info(`- Clients connected: ${list}`);
}
adapter.setState('info.connection', list, true);
adapter.log.warn('Error on connection: ' + JSON.stringify(err));
adapter.log.warn(`Error on connection: ${JSON.stringify(err)}`);
});
}
};
Expand Down Expand Up @@ -403,7 +403,7 @@ function Slave(options, adapter) {
} else {
adapter.setState(id, 0, true, err => {
// analyse if the state could be set (because of permissions)
if (err) adapter.log.error('Can not set state ' + id + ': ' + err.message);
if (err) adapter.log.error(`Can not set state ${id}: ${err.message}`);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async function translateGoogle(text, targetLang) {
const response = await axios({url, timeout: 15000});
if (isArray(response.data)) {
if (!Array.isArray(response.data[0]) || !Array.isArray(response.data[0][0])) {
console.log('ERR: ' + JSON.stringify(response.data));
return "";
console.log(`ERR: ${JSON.stringify(response.data)}`);
return '';
}
// we got a valid response
return response.data[0][0][0];
Expand Down
Loading

0 comments on commit 3260184

Please sign in to comment.