Added decoding of messages

Also moved things out to their own files and setup require()s to bring it all together.
This commit is contained in:
Parnic
2018-03-30 16:07:56 -05:00
parent af02f60791
commit b6ee816fb3
9 changed files with 259 additions and 86 deletions

70
messages/SLPoolStatusMessage.js Executable file
View File

@ -0,0 +1,70 @@
const SLMessage = require('./SLMessage.js').SLMessage;
exports.SLPoolStatusMessage = class SLPoolStatusMessage extends SLMessage {
constructor(buf) {
super(0, 12526);
if (!buf) {
this.writeInt32LE(0);
} else {
this._wroteSize = true;
this.writeBuffer(buf, 0);
this.decode();
}
}
decode() {
super.decode();
this.ok = this.readInt32LE();
this.freezeMode = this.readUInt8();
this.remotes = this.readUInt8();
this.poolDelay = this.readUInt8();
this.spaDelay = this.readUInt8();
this.cleanerDelay = this.readUInt8();
this.readOffset += 3;
this.airTemp = this.readInt32LE();
let bodiesCount = this.readInt32LE();
if (bodiesCount > 2) {
bodiesCount = 2;
}
this.currentTemp = new Array(bodiesCount);
this.heatStatus = new Array(bodiesCount);
this.setPoint = new Array(bodiesCount);
this.coolSetPoint = new Array(bodiesCount);
this.heatMode = new Array(bodiesCount);
for (let i = 0; i < bodiesCount; i++) {
let bodyType = this.readInt32LE();
if (bodyType < 0 || bodyType >= 2) {
bodyType = 0;
}
this.currentTemp[bodyType] = this.readInt32LE();
this.heatStatus[bodyType] = this.readInt32LE();
this.setPoint[bodyType] = this.readInt32LE();
this.coolSetPoint[bodyType] = this.readInt32LE();
this.heatMode[bodyType] = this.readInt32LE();
}
let circuitCount = this.readInt32LE();
this.circuitArray = new Array(circuitCount);
for (let i = 0; i < circuitCount; i++) {
this.circuitArray[i] = {
id: this.readInt32LE(),
state: this.readInt32LE(),
colorSet: this.readUInt8(),
colorPos: this.readUInt8(),
colorStagger: this.readUInt8(),
delay: this.readUInt8()
}
}
this.pH = this.readInt32LE();
this.orp = this.readInt32LE();
this.saturation = this.readInt32LE();
this.saltPPM = this.readInt32LE();
this.pHTank = this.readInt32LE();
this.orpTank = this.readInt32LE();
this.alarms = this.readInt32LE();
}
}