diff --git a/index.js b/index.js index 659e9c1..4fdc23c 100644 --- a/index.js +++ b/index.js @@ -232,6 +232,23 @@ class UnitConnection extends EventEmitter { this.client.write(new messages.SLSetSaltCellConfigMessage(controllerId, poolOutput, spaOutput).toBuffer()); } + getScheduleData(scheduleType) { + this.client.write(new messages.SLGetScheduleData(null, scheduleType).toBuffer()); + } + + addNewScheduleEvent(scheduleType) { + this.client.write(new messages.SLAddNewScheduleEvent(null, scheduleType).toBuffer()); + } + + deleteScheduleEventById(scheduleId) { + this.client.write(new messages.SLDeleteScheduleEventById(scheduleId).toBuffer()); + } + + setScheduleEventById(scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint) { + this.client.write(new messages.SLSetScheduleEventById(null, scheduleId, circuitId, startTime, stopTime, + dayMask, flags, heatCmd, heatSetPoint).toBuffer()); + } + onClientMessage(msg) { // console.log('received message of length ' + msg.length); if (msg.length < 4) { @@ -292,6 +309,18 @@ class UnitConnection extends EventEmitter { case messages.SLEquipmentConfigurationMessage.getResponseId(): this.emit('equipmentConfiguration', new messages.SLEquipmentConfigurationMessage(msg)); break; + case messages.SLGetScheduleData.getResponseId(): + this.emit('getScheduleData', new messages.SLGetScheduleData(msg)); + break; + case messages.SLAddNewScheduleEvent.getResponseId(): + this.emit('addNewScheduleEvent', new messages.SLAddNewScheduleEvent(msg)); + break; + case messages.SLDeleteScheduleEventById.getResponseId(): + this.emit('deleteScheduleEventById', new messages.SLDeleteScheduleEventById(msg)); + break; + case messages.SLSetScheduleEventById.getResponseId(): + this.emit('setScheduleEventById', new messages.SLSetScheduleEventById(msg)); + break; case 13: // console.log(" it's a login failure."); this.emit('loginFailed'); diff --git a/messages/SLAddNewScheduleEvent.js b/messages/SLAddNewScheduleEvent.js new file mode 100644 index 0000000..865f4aa --- /dev/null +++ b/messages/SLAddNewScheduleEvent.js @@ -0,0 +1,38 @@ +'use strict'; + +const SLMessage = require('./SLMessage.js').SLMessage; + +const MSG_ID = 12544; + + +exports.SLAddNewScheduleEvent = class SLAddNewScheduleEvent extends SLMessage { + constructor(buf, scheduleType) { + var size; + if (buf) { + size = buf.readInt32LE(4) + 8; + } + super(0, MSG_ID, size); + + + if (!buf) { + // console.log('Requested Schedule type = ', scheduleType); + this.writeInt32LE(0); + this.writeInt32LE(scheduleType); + } else { + this._wroteSize = true; + this.writeBuffer(buf, 0); + + this.decode(); + } + } + + decode() { + super.decode(); + + this.scheduleId = this.readUInt32LE(); + } + + static getResponseId() { + return MSG_ID + 1; + } +}; diff --git a/messages/SLDeleteScheduleEventById.js b/messages/SLDeleteScheduleEventById.js new file mode 100644 index 0000000..6e69ed6 --- /dev/null +++ b/messages/SLDeleteScheduleEventById.js @@ -0,0 +1,18 @@ +'use strict'; + +const SLMessage = require('./SLMessage.js').SLMessage; + +const MSG_ID = 12546; + +exports.SLDeleteScheduleEventById = class SLDeleteScheduleEventById extends SLMessage { + constructor(scheduleId) { + super(0, MSG_ID); + + this.writeInt32LE(0); + this.writeInt32LE(scheduleId); + } + + static getResponseId() { + return MSG_ID + 1; + } +}; diff --git a/messages/SLGetScheduleData.js b/messages/SLGetScheduleData.js new file mode 100644 index 0000000..70572f6 --- /dev/null +++ b/messages/SLGetScheduleData.js @@ -0,0 +1,63 @@ +'use strict'; + +const SLMessage = require('./SLMessage.js').SLMessage; + +const MSG_ID = 12542; + +exports.SLGetScheduleData = class SLGetScheduleData extends SLMessage { + constructor(buf, scheduleType) { + var size; + if (buf) { + size = buf.readInt32LE(4) + 8; + } + super(0, MSG_ID, size); + + + if (!buf) { + // console.log('Requested Schedule type = ', scheduleType); + this.writeInt32LE(0); + this.writeInt32LE(scheduleType); + } else { + this._wroteSize = true; + this.writeBuffer(buf, 0); + + this.decode(); + } + } + + decode() { + super.decode(); + + this.eventCount = this.readUInt32LE(); + + this.events = new Array(this.eventCount); + + for (var i = 0; i < this.events.length; i++) { + this.events[i] = {}; + + this.events[i].scheduleId = this.readUInt32LE(); + this.events[i].circuitId = this.readUInt32LE(); + this.events[i].startTime = this.readTime(this.readUInt32LE()); + this.events[i].stopTime = this.readTime(this.readUInt32LE()); + this.events[i].dayMask = this.readUInt32LE(); + this.events[i].flags = this.readUInt32LE(); + this.events[i].heatCmd = this.readUInt32LE(); + this.events[i].heatSetPoint = this.readUInt32LE(); + + } + } + + readTime(rawTime) { + var retVal; + + retVal = Math.floor(rawTime / 60) * 100 + rawTime % 60; + + retVal = String(retVal).padStart(4, '0'); + + return retVal; + } + + static getResponseId() { + return MSG_ID + 1; + } +}; diff --git a/messages/SLSetScheduleEventById.js b/messages/SLSetScheduleEventById.js new file mode 100644 index 0000000..ecd5d9f --- /dev/null +++ b/messages/SLSetScheduleEventById.js @@ -0,0 +1,38 @@ +'use strict'; + +const SLMessage = require('./SLMessage.js').SLMessage; + +const MSG_ID = 12548; + + +exports.SLSetScheduleEventById = class SLSetScheduleEventById extends SLMessage { + constructor(buf, scheduleId, circuitId, startTime, stopTime, dayMask, flags, heatCmd, heatSetPoint) { + var size; + if (buf) { + size = buf.readInt32LE(4) + 8; + } + super(0, MSG_ID, size); + + + if (!buf) { + this.writeInt32LE(0); + this.writeInt32LE(scheduleId); + this.writeInt32LE(circuitId); + this.writeInt32LE(startTime); + this.writeInt32LE(stopTime); + this.writeInt32LE(dayMask); + this.writeInt32LE(flags); + this.writeInt32LE(heatCmd); + this.writeInt32LE(heatSetPoint); + } else { + this._wroteSize = true; + this.writeBuffer(buf, 0); + + this.decode(); + } + } + + static getResponseId() { + return MSG_ID + 1; + } +}; diff --git a/messages/index.js b/messages/index.js index 2fbf36f..288c30a 100644 --- a/messages/index.js +++ b/messages/index.js @@ -15,3 +15,7 @@ exports.SLLightControlMessage = require('./SLLightControl.js').SLLightControl; exports.SLSetSaltCellConfigMessage = require('./SLSetSaltCellConfigMessage.js').SLSetSaltCellConfigMessage; exports.SLEquipmentConfigurationMessage = require('./SLEquipmentConfigurationMessage.js').SLEquipmentConfigurationMessage; +exports.SLGetScheduleData = require('./SLGetScheduleData.js').SLGetScheduleData; +exports.SLAddNewScheduleEvent = require('./SLAddNewScheduleEvent.js').SLAddNewScheduleEvent; +exports.SLDeleteScheduleEventById = require('./SLDeleteScheduleEventById.js').SLDeleteScheduleEventById; +exports.SLSetScheduleEventById = require('./SLSetScheduleEventById.js').SLSetScheduleEventById;