Created
May 1, 2015 00:08
-
-
Save jarrodbell/6631f2ff6268ac36659a to your computer and use it in GitHub Desktop.
Heatmiser Data Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code to run on startup | |
CF.userMain = function() { | |
// watch the feedback coming from the system, adjust the values to match the system name and feedback name in your guiDesigner project | |
CF.watch(CF.FeedbackMatchedEvent, "HeatmiserWired", "Capture", function(fbName, data) { | |
dataBuffer += data; // Append the incoming data to the buffer, now process it | |
var MessageCount = 0; | |
while ((matches = dataRegex.exec(dataBuffer)) !== null) { | |
if (matches) { | |
var length = matches[1].charCodeAt(0); // Get the length decimal value | |
if (dataBuffer.length >= (length + lengthAdd)) { | |
// All the data is here, so now process it as you need, and remove it from the buffer | |
var wholeMsg = dataBuffer.substr(0, (length + lengthAdd)); // Get the whole message | |
var ProvidedChecksum = wholeMsg.substr((wholeMsg.length - 3), 2); // Get the provided checksum | |
var Message = wholeMsg.substr(0, (wholeMsg.length - 3)); // Get the message without checksum | |
MessageCount++; | |
dataBuffer = dataBuffer.replace(wholeMsg, ''); // Remove the message from the buffer | |
//CF.log(makeReadable(Message)); | |
//CF.log("ProvidedChecksum="+makeReadable(ProvidedChecksum)); | |
CalculatedChecksum = crc16(Message,"Little"); | |
//CF.log("CalculatedChecksum="+makeReadable(CalculatedChecksum)); | |
if (ProvidedChecksum !== CalculatedChecksum) { | |
CF.log("Checksum Failure Detected on HeatmiserWired. Message "+MessageCount+" Failed CRC"); | |
} else { | |
// Determine Stat ID | |
var ID = wholeMsg.charCodeAt(3); | |
// Push data into Joins | |
CF.setJoin("Heatmiser_"+ID+"_SetTemp", wholeMsg.charCodeAt(27)); | |
CF.setToken(CF.GlobalTokensJoin, "Heatmiser_"+ID+"_SetTemp", wholeMsg.charCodeAt(27)); | |
CF.setJoin("Heatmiser_"+ID+"_RemoteAirTemp", (wholeMsg.charCodeAt(38)/10)); | |
CF.setJoin("Heatmiser_"+ID+"_FloorTemp", (wholeMsg.charCodeAt(40)/10)); | |
CF.setJoin("Heatmiser_"+ID+"_InternalAirTemp", (wholeMsg.charCodeAt(42)/10)); | |
CF.setJoin("Heatmiser_"+ID+"_CallingHeat", wholeMsg.charCodeAt(44)); | |
CF.setJoin("Heatmiser_"+ID+"_CallingHW", wholeMsg.charCodeAt(45)); | |
} | |
} | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment