Skip to content

Commit

Permalink
Merge branch 'master' into 8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tagyoureit committed Nov 22, 2022
2 parents 1e6cddc + 05ffd2a commit 906e517
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 26 deletions.
34 changes: 18 additions & 16 deletions controller/boards/IntelliCenterBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class IntelliCenterBoard extends SystemBoard {
[2, { name: 'solar', desc: 'Solar' }],
[3, { name: 'cooling', desc: 'Cooling' }],
[4, { name: 'hpheat', desc: 'Heating' }],
[5, { name: 'hybheat', desc: 'Heating'}],
[5, { name: 'hybheat', desc: 'Heating' }],
[6, { name: 'mtheat', desc: 'Heater' }],
[8, { name: 'hpcool', desc: 'Cooling' }]
]);
Expand Down Expand Up @@ -673,22 +673,23 @@ class IntelliCenterConfigQueue extends ConfigQueue {
// as both boards are processing at the same time and sending an outbound ack.
let out = Outbound.create({
action: 222, payload: [this.curr.category, itm], retries: 5,
response: Response.create({ dest: -1, action: 30, payload: [this.curr.category, itm]
response: Response.create({
dest: -1, action: 30, payload: [this.curr.category, itm]
// , callback: () => { self.processNext(out); }
})
});
logger.verbose(`Requesting config for: ${ConfigCategories[this.curr.category]} - Item: ${itm}`);
setTimeout(() => { conn.queueSendMessage(out) }, 50);
out.sendAsync()
.then(() => {
//logger.debug(`msg ${out.toShortPacket()} sent successfully`);
})
.catch((err) => {
logger.error(`Error sending configuration request message on port ${out.portId}: ${err.message};`);
})
.finally(()=>{
setTimeout(()=>{self.processNext(out);}, 10);
})
.then(() => {
//logger.debug(`msg ${out.toShortPacket()} sent successfully`);
})
.catch((err) => {
logger.error(`Error sending configuration request message on port ${out.portId}: ${err.message};`);
})
.finally(() => {
setTimeout(() => { self.processNext(out); }, 10);
})
} else {
// Now that we are done check the configuration a final time. If we have anything outstanding
// it will get picked up.
Expand Down Expand Up @@ -3636,15 +3637,16 @@ export class IntelliCenterChemControllerCommands extends ChemControllerCommands
out.setPayloadByte(1, 0);
out.setPayloadByte(2, chem.id - 1);
out.setPayloadByte(3, body.val);
out.setPayloadByte(4, acidTankLevel + 1);
//out.setPayloadByte(4, acidTankLevel + 1);
out.setPayloadByte(4, 1);
out.setPayloadByte(5, address);
out.setPayloadByte(6, 1);
out.setPayloadInt(7, Math.round(pHSetpoint * 100), 700);
out.setPayloadInt(9, orpSetpoint, 400);
out.setPayloadByte(11, 1);
out.setPayloadByte(12, 1);
//out.setPayloadByte(11, acidTankLevel + 1, 1);
//out.setPayloadByte(12, orpTankLevel + 1, 1);
//out.setPayloadByte(11, 1);
//out.setPayloadByte(12, 1);
out.setPayloadByte(11, acidTankLevel + 1, 1);
out.setPayloadByte(12, orpTankLevel + 1, 1);

out.setPayloadInt(13, calciumHardness, 25);
out.setPayloadInt(15, cyanuricAcid, 0);
Expand Down
12 changes: 6 additions & 6 deletions controller/boards/SystemBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,12 +823,12 @@ export class byteValueMaps {
]);
public eqMessageSeverities: byteValueMap = new byteValueMap([
[-1, { name: 'unspecified', desc: 'Unspecified' }],
[0, { name: 'info', desc: 'Information' }],
[1, { name: 'reminder', desc: 'Reminder' }],
[2, { name: 'alert', desc: 'Alert' }],
[3, { name: 'warning', desc: 'Warning' }],
[4, { name: 'error', desc: 'Error' }],
[5, { name: 'fatal', desc: 'Fatal' }]
[0, { name: 'info', desc: 'Information', icon: 'fas fa-circle-info' }],
[1, { name: 'reminder', desc: 'Reminder', icon: 'fas fa-bell' }],
[2, { name: 'alert', desc: 'Alert', icon: 'fas fa-circle-exclamation' }],
[3, { name: 'warning', desc: 'Warning', icon: 'fas fa-circle-exclamation' }],
[4, { name: 'error', desc: 'Error', icon: 'fas fa-triangle-exclamation' }],
[5, { name: 'fatal', desc: 'Fatal', icon: 'fas fa-skull-crossbones' }]
]);
// need to validate these...
public delay: byteValueMap = new byteValueMap([
Expand Down
13 changes: 10 additions & 3 deletions controller/comms/Comms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class Connection {
portId: portId,
rs485Port: "/dev/ttyUSB0",
portSettings: { baudRate: 9600, dataBits: 8, parity: 'none', stopBits: 1, flowControl: false, autoOpen: false, lock: false },
netSettings: { allowHalfOpen: false, keepAlive: false, keepAliveInitialDelay: 1000 },
mockPort: false,
netConnect: false,
netHost: "raspberrypi",
Expand All @@ -105,6 +106,9 @@ export class Connection {
if (typeof data.portSettings !== 'undefined') {
pdata.portSettings = extend(true, { baudRate: 9600, dataBits: 8, parity: 'none', stopBits: 1, flowControl: false, autoOpen: false, lock: false }, pdata.portSettings, data.portSettings);
}
if (typeof data.netSettings !== 'undefined') {
pdata.netSettings = extend(true, { keepAlive: false, allowHalfOpen: false, keepAliveInitialDelay: 10000 }, pdata.netSettings, data.netSettings);
}
let existing = this.findPortById(portId);
if (typeof existing !== 'undefined') {
if (!await existing.closeAsync()) {
Expand All @@ -116,6 +120,7 @@ export class Connection {
let cfg = config.getSection(section, {
rs485Port: "/dev/ttyUSB0",
portSettings: { baudRate: 9600, dataBits: 8, parity: 'none', stopBits: 1, flowControl: false, autoOpen: false, lock: false },
netSettings: { allowHalfOpen: false, keepAlive: false, keepAliveInitialDelay: 5 },
mockPort: false,
netConnect: false,
netHost: "raspberrypi",
Expand Down Expand Up @@ -482,7 +487,6 @@ export class RS485Port {
return true;
}
if (this._cfg.netConnect && !this._cfg.mockPort) {
let sock: net.Socket = this._port as net.Socket;
if (typeof this._port !== 'undefined' && this.isOpen) {
// This used to try to reconnect and recreate events even though the socket was already connected. This resulted in
// instances where multiple event processors were present. Node doesn't give us any indication that the socket is
Expand All @@ -499,7 +503,10 @@ export class RS485Port {
});
port.destroy();
}
let nc: net.Socket = new net.Socket();
let opts = extend(true, { keepAliveInitialDelay: 0 }, this._cfg.netSettings);
// Convert the initial delay to milliseconds.
if (typeof this._cfg.netSettings !== 'undefined' && typeof this._cfg.netSettings.keepAliveInitialDelay === 'number') opts.keepAliveInitialDelay = this._cfg.netSettings.keepAliveInitialDelay * 1000;
let nc: net.Socket = new net.Socket(opts);
nc.once('connect', () => { logger.info(`Net connect (socat) ${this._cfg.portId} connected to: ${this._cfg.netHost}:${this._cfg.netPort}`); }); // Socket is opened but not yet ready.
nc.once('ready', () => {
this.isOpen = true;
Expand All @@ -513,6 +520,7 @@ export class RS485Port {
this.processPackets(); // if any new packets have been added to queue, process them.
state.equipment.messages.removeItemByCode(`rs485:${this.portId}:connection`);
});

nc.once('close', (p) => {
this.isOpen = false;
if (typeof this._port !== 'undefined' && !this._port.destroyed) this._port.destroy();
Expand Down Expand Up @@ -574,7 +582,6 @@ export class RS485Port {
}
else logger.error(`Net connect (socat) connection ${this.portId} error: ${err}. Never retrying -- No retry time set`);
state.equipment.messages.setMessageByCode(`rs485:${this.portId}:connection`, 'error', `${this.name} RS485 port disconnected`);

});
nc.connect(this._cfg.netPort, this._cfg.netHost, () => {
if (typeof this._port !== 'undefined') logger.warn(`Net connect (socat) ${this.portId} recovered from lost connection.`);
Expand Down
5 changes: 5 additions & 0 deletions defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"rtscts": false,
"autoOpen": false,
"lock": false
},
"netSettings": {
"allowHalfOpen": false,
"keepAlive": false,
"keepAliveInitialDelay": 5
}
},
"backups": {
Expand Down
4 changes: 3 additions & 1 deletion web/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,8 @@ export class SsdpServer extends ProtoServer {
}
public deviceXML(): string {
let ver = sys.appVersion.split('.');
let friendlyName = 'njsPC: unknown model';
if (typeof sys !== 'undefined' && typeof sys.equipment !== 'undefined' && typeof sys.equipment.model !== 'undefined') friendlyName = `njsPC: ${sys.equipment.model}`;
let XML = `<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
Expand All @@ -906,7 +908,7 @@ export class SsdpServer extends ProtoServer {
</specVersion>
<device>
<deviceType>${this.deviceType}</deviceType>
<friendlyName>NodeJS Pool Controller</friendlyName>
<friendlyName>${friendlyName}</friendlyName>
<manufacturer>tagyoureit</manufacturer>
<manufacturerURL>https://github.com/tagyoureit/nodejs-poolController</manufacturerURL>
<presentationURL>http://${webApp.ip()}:${webApp.httpPort()}/state/all</presentationURL>
Expand Down
44 changes: 44 additions & 0 deletions web/services/state/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,55 @@ import { sys } from "../../../controller/Equipment";
import { utils } from '../../../controller/Constants';
import { logger } from "../../../logger/Logger";
import { DataLogger } from "../../../logger/DataLogger";
import { conn } from "../../../controller/comms/Comms";
import { config } from "../../../config/Config";

import { ServiceParameterError } from "../../../controller/Errors";

export class StateRoute {
public static initRoutes(app: express.Application) {
app.get('/state/rs485Port/:id', async (req, res, next) => {
try {
let portId = parseInt(req.params.id, 10);
if (isNaN(portId)) throw new ServiceParameterError(`RS485 port id not supplied`, '/state/rs485Port/:id', 'portId', req.params.id);
let cfg = config.getSection(portId === 0 ? 'controller.comms' : `controller.comms${portId}`);
if (typeof cfg === 'undefined') throw new ServiceParameterError(`RS485 port id not found`, '/state/rs485Port/:id', 'portId', req.params.id);
let port = conn.findPortById(portId);
let sport: any = {
portId: portId,
enabled: cfg.enabled || false,
netConnect: cfg.netConnect,
reconnects: 0,
inactivityRetry: cfg.inactivityRetry,
isOpen: false,
mockPort: cfg.mockPort || false
}
if (cfg.netConnect) sport.network = { host: cfg.netHost, port: cfg.netPort };
else sport.settings = extend(true, { name: cfg.rs485Port }, cfg.portSettings);
if (typeof port !== 'undefined') {
let stats = port.stats;
sport.reconnects = port.reconnects;
sport.isOpen = port.isOpen;
sport.received = {
bytes: stats.bytesReceived,
success: stats.recSuccess,
failed: stats.recFailed,
collisions: stats.recCollisions,
rewinds: stats.recFRewinds,
failureRate: stats.recFailureRate
};
sport.sent = {
bytes: stats.bytesSent,
success: stats.sndSuccess,
aborted: stats.sndAborted,
retries: stats.sndRetries,
failureRate: stats.sndFailureRate
}
}
res.status(200).send(sport);
}
catch (err) { next(err); }
});
app.get('/state/chemController/:id', (req, res) => {
res.status(200).send(state.chemControllers.getItemById(parseInt(req.params.id, 10)).getExtended());
});
Expand Down

0 comments on commit 906e517

Please sign in to comment.