Skip to content

Commit

Permalink
Adding initial REM linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
rstrouse authored and tagyoureit committed Feb 11, 2021
1 parent 4b85fb2 commit edcda15
Show file tree
Hide file tree
Showing 11 changed files with 503 additions and 60 deletions.
98 changes: 97 additions & 1 deletion controller/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import * as extend from 'extend';
import { EventEmitter } from 'events';
import { logger } from "../logger/Logger";
export class Heliotrope {
Expand Down Expand Up @@ -315,6 +314,103 @@ export class Utils {
}
return false;
}
public uuid(a?, b?) { for (b = a = ''; a++ < 36; b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-'); return b }
public convert = {
temperature: {
f: {
k: (val) => { return (val - 32) * (5 / 9) + 273.15; },
c: (val) => { return (val - 32) * (5 / 9); },
f: (val) => { return val; }
},
c: {
k: (val) => { return val + 273.15; },
c: (val) => { return val; },
f: (val) => { return (val * (9 / 5)) + 32; }
},
k: {
k: (val) => { return val; },
c: (val) => { return val - 273.15; },
f: (val) => { return ((val - 273.15) * (9 / 5)) + 32; }
},
convertUnits: (val: number, from: string, to: string) => {
if (typeof val !== 'number') return null;
let fn = this.convert.temperature[from.toLowerCase()];
if (typeof fn !== 'undefined' && typeof fn[to.toLowerCase()] === 'function') return fn[to.toLowerCase()](val);
}
},
volume: {
gal: {
l: (val) => { return val * 3.78541; },
ml: (val) => { return val * 3.78541 * 1000; },
cl: (val) => { return val * 3.78541 * 100; },
gal: (val) => { return val; },
oz: (val) => { return val * 128; },
pint: (val) => { return val / 8; },
qt: (val) => { return val / 4; },
},
l: {
l: (val) => { return val; },
ml: (val) => { return val * 1000; },
cl: (val) => { return val * 100; },
gal: (val) => { return val * 0.264172; },
oz: (val) => { return val * 33.814; },
pint: (val) => { return val * 2.11338; },
qt: (val) => { return val * 1.05669; },
},
ml: {
l: (val) => { return val * .001; },
ml: (val) => { return val; },
cl: (val) => { return val * .1; },
gal: (val) => { return val * 0.000264172; },
oz: (val) => { return val * 0.033814; },
pint: (val) => { return val * 0.00211338; },
qt: (val) => { return val * 0.00105669; },
},
cl: {
l: (val) => { return val * .01; },
ml: (val) => { return val * 10; },
cl: (val) => { return val; },
gal: (val) => { return val * 0.00264172; },
oz: (val) => { return val * 0.33814; },
pint: (val) => { return val * 0.0211338; },
qt: (val) => { return val * 0.0105669; },
},
oz: {
l: (val) => { return val * 0.0295735; },
ml: (val) => { return val * 29.5735; },
cl: (val) => { return val * 2.95735; },
gal: (val) => { return val * 0.0078125; },
oz: (val) => { return val; },
pint: (val) => { return val * 0.0625; },
qt: (val) => { return val * 0.03125; },
},
pint: {
l: (val) => { return val * 0.473176; },
ml: (val) => { return val * 473.176; },
cl: (val) => { return val * 47.3176; },
gal: (val) => { return val * 0.125; },
oz: (val) => { return val * 16; },
pint: (val) => { return val; },
qt: (val) => { return val * 0.5; },
},
qt: {
l: (val) => { return val * 0.946353; },
ml: (val) => { return val * 946.353; },
cl: (val) => { return val * 94.6353; },
gal: (val) => { return val * 0.25; },
oz: (val) => { return val * 32; },
pint: (val) => { return val * 2; },
qt: (val) => { return val; },

},
convertUnits: (val: number, from: string, to: string) => {
if (typeof val !== 'number') return null;
let fn = this.convert.volume[from.toLowerCase()];
if (typeof fn !== 'undefined' && typeof fn[to.toLowerCase()] === 'function') return fn[to.toLowerCase()](val);
}
}
}

}

export const utils = new Utils();
48 changes: 47 additions & 1 deletion controller/Equipment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class PoolSystem implements IPoolSystem {
versionCheck.compare(); // if we installed a new version, reset the flag so we don't show an outdated message for up to 2 days
this.board = BoardFactory.fromControllerType(this.controllerType, this);
// this.intellibrite = new LightGroup(this.data, 'intellibrite', { id: 0, isActive: false, type: 3 });
//console.log(utils.uuid());
}

// This performs a safe load of the config file. If the file gets corrupt or actually does not exist
// it will not break the overall system and allow hardened recovery.
public async updateControllerDateTimeAsync(obj: any) { return sys.board.system.setDateTimeAsync(obj); }
Expand Down Expand Up @@ -256,6 +256,43 @@ export class PoolSystem implements IPoolSystem {
.then(() => { fs.writeFileSync(sys.cfgPath, JSON.stringify(sys.data, undefined, 2)); })
.catch(function(err) { if (err) logger.error('Error writing pool config %s %s', err, sys.cfgPath); });
}
// We are doing this because TS is lame. Accessing the app servers from the routes causes a cyclic include.
public findServersByType(type: string) {
let srv = [];
let servers = webApp.findServersByType(type);
for (let i = 0; i < servers.length; i++) {
srv.push({
uuid: servers[i].uuid,
name: servers[i].name,
type: servers[i].type,
isRunning: servers[i].isRunning,
isConnected: servers[i].isConnected
});
}
return srv;
}
public async getREMServers() {
try {
let srv = [];
let servers = webApp.findServersByType('rem');
for (let i = 0; i < servers.length; i++) {
let server = servers[i];
// Sometimes I hate type safety.
let devices = typeof server['getDevices'] === 'function' ? await server['getDevices']() : [];
console.log(devices);
srv.push({
uuid: servers[i].uuid,
name: servers[i].name,
type: servers[i].type,
isRunning: servers[i].isRunning,
isConnected: servers[i].isConnected,
devices: devices
});
}
return srv;
} catch (err) { logger.error(err); }

}
protected onchange=(obj, fn) => {
const handler = {
get(target, property, receiver) {
Expand Down Expand Up @@ -1602,6 +1639,15 @@ export class ChemController extends EqItem {
public set isorpDoseByVolume(val: boolean) { this.setDataVal('isorpDoseByVolume', val); }
public get pHManualDosing(): boolean { return this.data.pHManualDosing; }
public set pHManualDosing(val: boolean) { this.setDataVal('pHManualDosing', val); }
public get acidTankCapacity() { return this.data.acidTankCapacity; }
public set acidTankCapacity(val) { this.setDataVal('acidTankCapacity', val); }
public get acidTankUnits() { return this.data.acidTankUnits; }
public set acidTankUnits(val) { this.setDataVal('acidTankUnits', val); }
public get orpTankCapacity() { return this.data.orpTankCapacity; }
public set orpTankCapacity(val) { this.setDataVal('orpTankCapacity', val); }
public get orpTankUnits() { return this.data.orpTankUnits; }
public set orpTankUnits(val) { this.setDataVal('orpTankUnits', val); }

public getExtended() {
let chem = this.get(true);
chem.type = sys.board.valueMaps.chemControllerTypes.transform(chem.type);
Expand Down
10 changes: 7 additions & 3 deletions controller/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1382,9 +1382,9 @@ export class ChemControllerState extends EqState {
this.hasChanged = true;
}
} */
public get acidTankLevel(): number { return this.data.acidTankLevel; }
public get acidTankLevel(): number { return this.data.acidTankLevel || 0; }
public set acidTankLevel(val: number) { this.setDataVal('acidTankLevel', val); }
public get orpTankLevel(): number { return this.data.orpTankLevel; }
public get orpTankLevel(): number { return this.data.orpTankLevel || 0; }
public set orpTankLevel(val: number) { this.setDataVal('orpTankLevel', val); }
/* public get status1(): number { return this.data.status1; }
public set status1(val: number) {
Expand Down Expand Up @@ -1439,7 +1439,7 @@ export class ChemControllerState extends EqState {
public get orpDosingVolume(): number { return this.data.orpDosingVolume; }
public set orpDosingVolume(val: number) { this.setDataVal('orpDosingVolume', val); }
public get saturationIndex(): number { return this.data.saturationIndex; }
public set saturationIndex(val: number) { this.setDataVal('saturationIndex', val); }
public set saturationIndex(val: number) { this.setDataVal('saturationIndex', val || 0); }
public get temp(): number { return this.data.temp; }
public set temp(val: number) { this.setDataVal('temp', val); }
public get firmware(): string { return this.data.firmware; }
Expand Down Expand Up @@ -1480,6 +1480,10 @@ export class ChemControllerState extends EqState {
obj.acidTankLevel = this.acidTankLevel || 0;
obj.pHLevel = this.pHLevel || 0;
obj.orpLevel = this.orpLevel || 0;
obj.acidTankCapacity = chem.acidTankCapacity;
obj.acidTankUnits = chem.acidTankUnits;
obj.orpTankCapacity = chem.orpTankCapacity;
obj.orpTankUnits = chem.orpTankUnits;
return obj;
}
}
Expand Down
4 changes: 3 additions & 1 deletion controller/boards/SystemBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ export class byteValueMaps {
[0, { name: 'none', desc: 'None' }],
[1, { name: 'unknown', desc: 'Unknown' }],
[2, { name: 'intellichem', desc: 'IntelliChem' }],
[3, { name: 'homegrown', desc: 'Homegrown' }]
[3, { name: 'homegrown', desc: 'Homegrown' }],
[4, { name: 'rem', desc: 'REM Chem'}]
]);
public chemControllerStatus: byteValueMap = new byteValueMap([
[0, { name: 'ok', desc: 'Ok' }],
Expand Down Expand Up @@ -2873,6 +2874,7 @@ export class ChemControllerCommands extends BoardCommands {
chem.calciumHardness = _ch;
chem.alkalinity = _alk;
schem.acidTankLevel = Math.max(typeof data.acidTankLevel !== 'undefined' ? parseInt(data.acidTankLevel, 10) : schem.acidTankLevel, 0);

schem.orpTankLevel = Math.max(typeof data.orpTankLevel !== 'undefined' ? parseInt(data.orpTankLevel, 10) : schem.orpTankLevel, 0);
chem.cyanuricAcid = typeof data.cyanuricAcid !== 'undefined' ? parseInt(data.cyanuricAcid, 10) : chem.cyanuricAcid;
chem.isActive = schem.isActive = true;
Expand Down
19 changes: 19 additions & 0 deletions defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@
"rootTopic": "@bind=(state.equipment.model).replace(' ','-').replace('/','').toLowerCase();",
"retain": true,
"qos": 0
},
"rem": {
"name": "Relay Equipment Manager",
"type": "rem",
"enabled": false,
"options": {
"protocol": "http://",
"host": "raspberrypi",
"port": 8080
},
"socket": {
"transports": [
"websocket"
],
"upgrade": false,
"reconnectionDelay": 2000,
"reconnection": true,
"reconnectionDelayMax": 20000
}
}
}
}
Expand Down
Loading

0 comments on commit edcda15

Please sign in to comment.