From 33e2c03b480a8d7c17036b92450f2a509dce0e43 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 10 Jun 2016 13:05:46 -0600 Subject: [PATCH] tb7300: Initial implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This module implements support for the Honeywell TB7300 Communicating Fan Coil Thermostat. It may also support the TB7200, though only the TB7300 was available for development of this driver. The TB7200 Series PI thermostats are designed for zoning applications, and the TB7300 Series PI thermostats are designed for fan coil control. Both Series are communicating thermostats with models available in BACnet® MS/TP protocol and can be easily integrated into a WEBs-AX building automation system based on the NiagaraAX® platform. TB7200 and TB7300 Series thermostats are compatible with the Honeywell Occupancy Sensor Cover. Thermostats equipped with an occupancy sensor cover provide advanced active occupancy logic, which will automatically switch occupancy levels from Occupied to Stand-By and Unoccupied as required by local activity being present or not. This advanced occupancy functionality provides advantageous energy savings during occupied hours without sacrificing occupant comfort. All thermostats can be ordered with or without a factory installed PIR cover. Signed-off-by: Jon Trulson --- examples/c++/CMakeLists.txt | 1 + examples/c++/tb7300.cxx | 124 ++++++++++++++ examples/java/CMakeLists.txt | 1 + examples/java/TB7300_Example.java | 99 ++++++++++++ examples/javascript/tb7300.js | 102 ++++++++++++ examples/python/tb7300.py | 96 +++++++++++ src/tb7300/CMakeLists.txt | 28 ++++ src/tb7300/javaupm_tb7300.i | 32 ++++ src/tb7300/jsupm_tb7300.i | 10 ++ src/tb7300/pyupm_tb7300.i | 14 ++ src/tb7300/tb7300.cxx | 108 +++++++++++++ src/tb7300/tb7300.hpp | 258 ++++++++++++++++++++++++++++++ 12 files changed, 873 insertions(+) create mode 100644 examples/c++/tb7300.cxx create mode 100644 examples/java/TB7300_Example.java create mode 100644 examples/javascript/tb7300.js create mode 100644 examples/python/tb7300.py create mode 100644 src/tb7300/CMakeLists.txt create mode 100644 src/tb7300/javaupm_tb7300.i create mode 100644 src/tb7300/jsupm_tb7300.i create mode 100644 src/tb7300/pyupm_tb7300.i create mode 100644 src/tb7300/tb7300.cxx create mode 100644 src/tb7300/tb7300.hpp diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 7d380310..ed367b3a 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -263,6 +263,7 @@ if (BACNET_FOUND) include_directories(${PROJECT_SOURCE_DIR}/src/bacnetmstp) add_example (e50hx) add_example (t8100) + add_example (tb7300) endif() add_example (vcap) add_example (ds2413) diff --git a/examples/c++/tb7300.cxx b/examples/c++/tb7300.cxx new file mode 100644 index 00000000..0aab8ac9 --- /dev/null +++ b/examples/c++/tb7300.cxx @@ -0,0 +1,124 @@ +/* + * Author: Jon Trulson + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include + +#include "tb7300.hpp" + +using namespace std; +using namespace upm; + +bool shouldRun = true; + +void sig_handler(int signo) +{ + if (signo == SIGINT) + shouldRun = false; +} + +int main(int argc, char **argv) +{ + signal(SIGINT, sig_handler); + +//! [Interesting] + // You will need to edit this example to conform to your site and your + // devices, specifically the Device Object Instance ID passed to the + // constructor, and the arguments to initMaster() that are + // appropriate for your BACnet network. + + string defaultDev = "/dev/ttyUSB0"; + + // if an argument was specified, use it as the device instead + if (argc > 1) + defaultDev = string(argv[1]); + + cout << "Using device " << defaultDev << endl; + cout << "Initializing..." << endl; + + // Instantiate an TB7300 object for an TB7300 device that has 73001 + // as it's unique Device Object Instance ID. NOTE: You will + // certainly want to change this to the correct value for your + // device(s). + TB7300 *sensor = new TB7300(73001); + + // Initialize our BACnet master, if it has not already been + // initialized, with the device and baudrate, choosing 1000001 as + // our unique Device Object Instance ID, 2 as our MAC address and + // using default values for maxMaster and maxInfoFrames + sensor->initMaster(defaultDev, 38400, 1000001, 2); + + // Uncomment to enable debugging output + // sensor->setDebug(true); + + cout << endl; + cout << "Device Name: " << sensor->getDeviceName() << endl; + cout << "Device Description: " << sensor->getDeviceDescription() << endl; + cout << "Device Location: " << sensor->getDeviceLocation() << endl; + cout << endl; + + cout << "Fan Mode: " + << sensor->getMultiStateValueText(TB7300::MV_Fan_Mode) + << endl; + + cout << "Fan Status: " + << sensor->getMultiStateValueText(TB7300::MV_Fan_Status) + << endl; + + cout << "System Mode: " + << sensor->getMultiStateValueText(TB7300::MV_System_Mode) + << endl; + + cout << "Service Alarm: " + << sensor->getBinaryInputText(TB7300::BI_Service_Alarm) + << endl; + + cout << endl; + + // update and print the room temperature every 5 seconds + while (shouldRun) + { + // update our values + sensor->update(); + + // we show both C and F for temperature + cout << "Temperature: " << sensor->getTemperature() + << " C / " + << sensor->getTemperature(true) + << " F" + << endl; + + cout << endl; + sleep(5); + } + + cout << "Exiting..." << endl; + + delete sensor; + +//! [Interesting] + + return 0; +} diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index b1ee421e..130cc4f2 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -125,6 +125,7 @@ endif() if (BACNET_FOUND) add_example(E50HX_Example e50hx) add_example(T8100_Example t8100) + add_example(TB7300_Example tb7300) endif() add_example(VCAP_Example vcap) add_example(BMP280_Example bmp280) diff --git a/examples/java/TB7300_Example.java b/examples/java/TB7300_Example.java new file mode 100644 index 00000000..250dcdf2 --- /dev/null +++ b/examples/java/TB7300_Example.java @@ -0,0 +1,99 @@ +/* + * Author: Jon Trulson + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import upm_tb7300.TB7300; + +public class TB7300_Example +{ + private static String defaultDev = "/dev/ttyUSB0"; + + public static void main(String[] args) throws InterruptedException + { +// ! [Interesting] + + // You will need to edit this example to conform to your site + // and your devices, specifically the Device Object Instance + // ID passed to the constructor, and the arguments to + // initMaster() that are appropriate for your BACnet network. + + if (args.length > 0) + defaultDev = args[0]; + System.out.println("Using device " + defaultDev); + System.out.println("Initializing..."); + + // Instantiate an TB7300 object for an TB7300 device that has + // 73001 as it's unique Device Object Instance ID. NOTE: You + // will certainly want to change this to the correct value for + // your device(s). + TB7300 sensor = new TB7300(73001); + + // Initialize our BACnet master, if it has not already been + // initialized, with the device and baudrate, choosing 1000001 + // as our unique Device Object Instance ID, 2 as our MAC + // address and using default values for maxMaster and + // maxInfoFrames + sensor.initMaster(defaultDev, 38400, 1000001, 2); + + // Uncomment to enable debugging output + // sensor.setDebug(true); + + System.out.println(); + System.out.println("Device Name: " + + sensor.getDeviceName()); + System.out.println("Device Description: " + + sensor.getDeviceDescription()); + System.out.println("Device Location: " + sensor.getDeviceLocation()); + System.out.println(); + + System.out.println("Fan Mode: " + + sensor.getMultiStateValueText(TB7300.MULTISTATE_VALUES_T.MV_Fan_Mode)); + System.out.println("Fan Status: " + + sensor.getMultiStateValueText(TB7300.MULTISTATE_VALUES_T.MV_Fan_Status)); + System.out.println("System Mode: " + + sensor.getMultiStateValueText(TB7300.MULTISTATE_VALUES_T.MV_System_Mode)); + System.out.println("Service Alarm:" + + sensor.getBinaryInputText(TB7300.BINARY_INPUTS_T.BI_Service_Alarm)); + + System.out.println(); + + // update and print the room temperature every 5 seconds + while (true) + { + // update our values + sensor.update(); + + // we show both C and F for temperature + System.out.println("Temperature: " + + sensor.getTemperature() + + " C / " + + sensor.getTemperature(true) + + " F"); + + System.out.println(); + Thread.sleep(5000); + } + +// ! [Interesting] + } +} diff --git a/examples/javascript/tb7300.js b/examples/javascript/tb7300.js new file mode 100644 index 00000000..8188a862 --- /dev/null +++ b/examples/javascript/tb7300.js @@ -0,0 +1,102 @@ +/*jslint node:true, vars:true, bitwise:true, unparam:true */ +/*jshint unused:true */ + +/* + * Author: Jon Trulson + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +var sensorObj = require('jsupm_tb7300'); + + +/************** Main code **************/ + +// You will need to edit this example to conform to your site and your +// devices, specifically the Device Object Instance ID passed to the +// constructor, and the arguments to initMaster() that are +// appropriate for your BACnet network. + +var defaultDev = "/dev/ttyUSB0"; + +// if an argument was specified, use it as the device instead +if (process.argv.length > 2) +{ + defaultDev = process.argv[2]; +} + +console.log("Using device " + defaultDev); +console.log("Initializing..."); + +// Instantiate an TB7300 object for an TB7300 device that has 73001 +// as it's unique Device Object Instance ID. NOTE: You will +// certainly want to change this to the correct value for your +// device(s). +var sensor = new sensorObj.TB7300(73001); + +// Initialize our BACnet master, if it has not already been +// initialized, with the device and baudrate, choosing 1000001 as +// our unique Device Object Instance ID, 2 as our MAC address and +// using default values for maxMaster and maxInfoFrames +sensor.initMaster(defaultDev, 38400, 1000001, 2); + +// Uncomment to enable debugging output +// sensor.setDebug(true); + +console.log(""); +console.log("Device Name:", sensor.getDeviceName()); +console.log("Device Description:", sensor.getDeviceDescription()); +console.log("Device Location:", sensor.getDeviceLocation()); +console.log(""); + +console.log("Fan Mode:", + sensor.getMultiStateValueText(sensorObj.TB7300.MV_Fan_Mode)); +console.log("Fan Status:", + sensor.getMultiStateValueText(sensorObj.TB7300.MV_Fan_Status)); +console.log("System Mode:", + sensor.getMultiStateValueText(sensorObj.TB7300.MV_System_Mode)); +console.log("Service Alarm:", + sensor.getBinaryInputText(sensorObj.TB7300.BI_Service_Alarm)); +console.log(""); + +// update and print the room temperature every 5 seconds +setInterval(function() +{ + // update our values + sensor.update(); + + // we show both C and F for temperature + console.log("Temperature:", sensor.getTemperature(), + "C /", sensor.getTemperature(true), "F"); + console.log(""); + +}, 5000); + + +process.on('SIGINT', function() +{ + sensor = null; + sensorObj.cleanUp(); + sensorObj = null; + console.log("Exiting..."); + process.exit(0); +}); diff --git a/examples/python/tb7300.py b/examples/python/tb7300.py new file mode 100644 index 00000000..93e879d3 --- /dev/null +++ b/examples/python/tb7300.py @@ -0,0 +1,96 @@ +#!/usr/bin/python +# Author: Jon Trulson +# Copyright (c) 2016 Intel Corporation. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import time, sys, signal, atexit +import pyupm_tb7300 as sensorObj + +## Exit handlers ## +# This function stops python from printing a stacktrace when you hit control-C +def SIGINTHandler(signum, frame): + raise SystemExit + +# This function lets you run code on exit +def exitHandler(): + print "Exiting..." + sys.exit(0) + +# Register exit handlers +atexit.register(exitHandler) +signal.signal(signal.SIGINT, SIGINTHandler) + +# You will need to edit this example to conform to your site and your +# devices, specifically the Device Object Instance ID passed to the +# constructor, and the arguments to initMaster() that are +# appropriate for your BACnet network. + +defaultDev = "/dev/ttyUSB0" + +# if an argument was specified, use it as the device instead +if (len(sys.argv) > 1): + defaultDev = sys.argv[1] + +print "Using device", defaultDev +print "Initializing..." + +# Instantiate an TB7300 object for an TB7300 device that has 73001 +# as it's unique Device Object Instance ID. NOTE: You will +# certainly want to change this to the correct value for your +# device(s). +sensor = sensorObj.TB7300(73001) + +# Initialize our BACnet master, if it has not already been +# initialized, with the device and baudrate, choosing 1000001 as +# our unique Device Object Instance ID, 2 as our MAC address and +# using default values for maxMaster and maxInfoFrames +sensor.initMaster(defaultDev, 38400, 1000001, 2) + +# Uncomment to enable debugging output +# sensor.setDebug(True); + +# output the serial number and firmware revision +print +print "Device Name:", sensor.getDeviceName() +print "Device Description:", sensor.getDeviceDescription() +print "Device Location:", sensor.getDeviceLocation() +print + +print "Fan Mode:", sensor.getMultiStateValueText(sensorObj.TB7300.MV_Fan_Mode) +print "Fan Status:", +print sensor.getMultiStateValueText(sensorObj.TB7300.MV_Fan_Status) +print "System Mode:", +print sensor.getMultiStateValueText(sensorObj.TB7300.MV_System_Mode) +print "Service Alarm:", +print sensor.getBinaryInputText(sensorObj.TB7300.BI_Service_Alarm) +print + +# update and print the room temperature every 5 seconds +while (1): + # update our values + sensor.update(); + + # we show both C and F for temperature + print "Temperature:", sensor.getTemperature(), + print "C /", sensor.getTemperature(True), "F" + + print + time.sleep(5) diff --git a/src/tb7300/CMakeLists.txt b/src/tb7300/CMakeLists.txt new file mode 100644 index 00000000..8564c805 --- /dev/null +++ b/src/tb7300/CMakeLists.txt @@ -0,0 +1,28 @@ +set (libname "tb7300") +set (libdescription "upm module for the TB7300 Fan Coil Thermostat") +set (module_src ${libname}.cxx) +set (module_hpp ${libname}.hpp) + +pkg_check_modules(BACNET libbacnet) +if (BACNET_FOUND) + # upm-libbacnetmstp will bring in libbacnet, I hope + set (reqlibname "upm-bacnetmstp") + include_directories(${BACNET_INCLUDE_DIRS}) + include_directories("../bacnetmstp") + upm_module_init() + target_link_libraries(${libname} bacnetmstp) + if (BUILDSWIG) + if (BUILDSWIGNODE) + set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE) + swig_link_libraries (jsupm_${libname} bacnetmstp) + endif() + if (BUILDSWIGPYTHON) + set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE) + swig_link_libraries (pyupm_${libname} bacnetmstp) + endif() + if (BUILDSWIGJAVA) + set_target_properties(${SWIG_MODULE_javaupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE) + swig_link_libraries (javaupm_${libname} bacnetmstp) + endif() + endif() +endif () diff --git a/src/tb7300/javaupm_tb7300.i b/src/tb7300/javaupm_tb7300.i new file mode 100644 index 00000000..7374878c --- /dev/null +++ b/src/tb7300/javaupm_tb7300.i @@ -0,0 +1,32 @@ +%module javaupm_tb7300 +%include "../upm.i" +%include "typemaps.i" + +// We need to use this method for enum wrapping since the enum typedefs used +// by the derived classes (like ANALOG_VALUES_T) are passed to methods +// in the base class which expect a uint32_t. This is fine, and +// works everywhere except Java. It's type safety is a little too +// stringent in these cases. %javaconst(1) is generally recommended +// as it avoids JNI calls to determine the enumerant values at +// runtime. +%include "enumtypeunsafe.swg" +%javaconst(1); + +%include "bacnetmstp.hpp" +%include "bacnetutil.hpp" +%include "tb7300.hpp" +%{ + #include "tb7300.hpp" +%} + + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_tb7300"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} diff --git a/src/tb7300/jsupm_tb7300.i b/src/tb7300/jsupm_tb7300.i new file mode 100644 index 00000000..e18f5924 --- /dev/null +++ b/src/tb7300/jsupm_tb7300.i @@ -0,0 +1,10 @@ +%module jsupm_tb7300 +%include "../upm.i" +%include "stdint.i" + +%include "bacnetmstp.hpp" +%include "bacnetutil.hpp" +%include "tb7300.hpp" +%{ + #include "tb7300.hpp" +%} diff --git a/src/tb7300/pyupm_tb7300.i b/src/tb7300/pyupm_tb7300.i new file mode 100644 index 00000000..a1e7bfe1 --- /dev/null +++ b/src/tb7300/pyupm_tb7300.i @@ -0,0 +1,14 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_tb7300 +%include "../upm.i" +%include "stdint.i" + +%feature("autodoc", "3"); + +%include "bacnetmstp.hpp" +%include "bacnetutil.hpp" +%include "tb7300.hpp" +%{ + #include "tb7300.hpp" +%} diff --git a/src/tb7300/tb7300.cxx b/src/tb7300/tb7300.cxx new file mode 100644 index 00000000..d4f14ccc --- /dev/null +++ b/src/tb7300/tb7300.cxx @@ -0,0 +1,108 @@ +/* + * Author: Jon Trulson + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "tb7300.hpp" + +using namespace upm; +using namespace std; + +// conversion from fahrenheit to celcius and back + +static float f2c(float f) +{ + return ((f - 32.0) / (9.0 / 5.0)); +} + +static float c2f(float c) +{ + return (c * (9.0 / 5.0) + 32.0); +} + + +TB7300::TB7300(uint32_t targetDeviceObjectID) : + BACNETUTIL(targetDeviceObjectID) +{ + setDebug(false); + + // we disable this by default for performance reasons + checkReliability(false); + + m_isTempInitialized = false; + m_isCelcius = false; + + // room temperature only + m_temperature = 0.0; +} + +TB7300::~TB7300() +{ +} + +void TB7300::update() +{ + if (!m_isTempInitialized) + { + // this will update internals so conversions work properly + getTemperatureScale(); + } + + float tmpF = getAnalogValue(AV_Room_Temperature); + + if (m_isCelcius) + m_temperature = tmpF; + else + m_temperature = f2c(tmpF); +} + +float TB7300::getTemperature(bool fahrenheit) +{ + if (fahrenheit) + return c2f(m_temperature); + else + return m_temperature; +} + +void TB7300::setTemperatureScale(bool fahrenheit) +{ + setBinaryValue(BV_Temperature_Scale, fahrenheit); + + m_isTempInitialized = true; + m_isCelcius = (fahrenheit) ? false : true; +} + +bool TB7300::getTemperatureScale() +{ + bool scale = getBinaryValue(BV_Temperature_Scale); + + m_isTempInitialized = true; + m_isCelcius = !scale; + + return scale; +} diff --git a/src/tb7300/tb7300.hpp b/src/tb7300/tb7300.hpp new file mode 100644 index 00000000..2b6a0cce --- /dev/null +++ b/src/tb7300/tb7300.hpp @@ -0,0 +1,258 @@ +/* + * Author: Jon Trulson + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once + +#include +#include + +#include "bacnetmstp.hpp" +#include "bacnetutil.hpp" + +namespace upm { + + /** + * @brief Honeywell TB7300 Communicating Fan Coil Thermostat + * @defgroup tb7300 libupm-tb7300 + * @ingroup uart temp + */ + + /** + * @library tb7300 + * @sensor tb7300 + * @comname UPM API for the Honeywell TB7300 Communicating Fan Coil + * Thermostat + * @type temp + * @man honeywell + * @con uart + * @web https://parts-hvac.com/tb7300c5014b.html + * + * @brief Honeywell TB7300 Communicating Fan Coil Thermostat + * + * This module implements support for the Honeywell TB7300 + * Communicating Fan Coil Thermostat. It may also support the + * TB7200, though only the TB7300 was available for development of + * this driver. + * + * The TB7200 Series PI thermostats are designed for zoning + * applications, and the TB7300 Series PI thermostats are designed + * for fan coil control. Both Series are communicating thermostats + * with models available in BACnet® MS/TP protocol and can be easily + * integrated into a WEBs-AX building automation system based on the + * NiagaraAX® platform. + * + * TB7200 and TB7300 Series thermostats are compatible with the + * Honeywell Occupancy Sensor Cover. Thermostats equipped with an + * occupancy sensor cover provide advanced active occupancy logic, + * which will automatically switch occupancy levels from Occupied to + * Stand-By and Unoccupied as required by local activity being + * present or not. This advanced occupancy functionality provides + * advantageous energy savings during occupied hours without + * sacrificing occupant comfort. All thermostats can be ordered with + * or without a factory installed PIR cover. + * + * If you intend to work with this device and driver, it is + * strongly suggested you get the BACnet Intergration Guide document + * for this device: 63-4524.pdf as recommended in the device + * documentation. + * + * This module was developed using the upm::BACNETMSTP library, + * based on libbacnet-stack 0.8.3. Both libbacnet 0.8.3 and the + * upm::BACNETMSTP libraries must be present in order to build this + * module. + * + * It was connected using an RS232->RS485 interface. You cannot use + * the built in MCU TTL UART pins for accessing this device -- you + * must use a full Serial RS232->RS485 or USB-RS485 interface + * connected via USB. + * + * @snippet tb7300.cxx Interesting + */ + + class TB7300 : public BACNETUTIL { + public: + + // Supported Analog Value Objects. These are readable and writable. + typedef enum : uint32_t { + AV_Room_Temperature = 7, + + // GRP 20 Control Output + AV_PI_Heating_Demand = 21, + AV_PI_Cooling_Demand = 22, + + // GRP 38 Temperature Setpoints + AV_Occupied_Heat_Setpoint = 39, + AV_Occupied_Cool_Setpoint = 40, + AV_Standby_Heat_Setpoint = 41, + AV_Standby_Cool_Setpoint = 42, + AV_Unoccupied_Heat_Setpoint = 43, + AV_Unoccupied_Cool_Setpoint = 44, + + // GRP 55 General Options 2 + AV_Password_Value = 56, + AV_Heating_Setpoint_Limit = 58, + AV_Cooling_Setpoint_Limit = 59, + AV_Deadband = 63, + AV_Standby_Time = 67, + AV_Unoccupied_Time = 68 + } ANALOG_VALUES_T; + + // Supported Analog Input Objects. These are read only. + typedef enum : uint32_t { + AI_Supply_Temperature = 12 + } ANALOG_INPUTS_T; + + // Supported Binary Value Objects. These are readable and writable. + typedef enum : uint32_t { + BV_Temp_Override = 8, + BV_Aux_Command = 14, + + // GRP 45 General Options 1 + BV_Menu_Scroll = 49, + BV_Auto_Mode_Enable = 50, + BV_Temperature_Scale = 51, + + // GRP 55 General Option 2 + BV_Setpoint_Type = 60, + BV_Setpoint_Function = 61, + BV_Reheat_Timebase = 64, + BV_Auto_Fan = 66, + + // GRP 74 Output Configuration Options + BV_Control_type = 75, + BV_Direct_Reverse_Acting = 78 + } BINARY_VALUES_T; + + // Supported Binary Input Objects. These are read only. + typedef enum : uint32_t { + // GRP 24 Controller Status + BI_AUX_Status = 25, + BI_BI1_Status = 29, + BI_BI2_Status = 30, + BI_UI3_Status = 31, + BI_Local_Motion = 32, + + // GRP 34 Controller Alarms + BI_Window_Alarm = 35, + BI_Filter_Alarm = 36, + BI_Service_Alarm = 37 + } BINARY_INPUTS_T; + + // Supported Multi-State Value Objects. These are readable and + // writable. + typedef enum : uint32_t { + MV_Sequence_of_Operation = 15, + MV_System_Mode = 16, + MV_Fan_Mode = 17, + MV_Occupancy_Command = 18, + MV_Keypad_Lockout = 19, + + // GRP 24 Controller Status + MV_Heating_Valve_Status = 26, + MV_Cooling_Valve_Status = 27, + MV_Fan_Status = 28, + MV_Effective_Occupancy = 33, + + // GRP 45 General Options 1 + MV_BI1_Configuration = 46, + MV_BI2_Configuration = 47, + MV_UI1_Configuration = 48, + MV_Pipe_Number = 52, + MV_Out1_Config = 53, + MV_AUX_Configuration = 54, + + // GRP 55 General Option 2 + MV_Fan_Mode_Sequence = 58, + MV_Temporary_Occupancy_Time = 62, + MV_Proportional_Band = 65, + + // GRP 74 Output Configuration Options + MV_Floating_Motor_Timing = 76, + MV_On_Off_Control_CPH = 77 + } MULTISTATE_VALUES_T; + + /** + * TB7300 constructor + * + * @param targetDeviceObjectID the unique Instance ID of the + * Device Object. This number is used to uniquely identify + * devices on the BACnet network, and ranges from 1 to 4194302. + * This is not the device's MAC address, though on some devices, + * the MAC address may be used as part of this number. On the + * TB7300, this number depends on the model and the MAC address. + */ + TB7300(uint32_t targetDeviceObjectID); + + /** + * TB7300 Destructor + */ + ~TB7300(); + + /** + * Read current temperature from the sensor and update internal + * stored value. This method must be called prior to querying the + * temperature. All other values in the device must be queried + * directly via the appropriate BACNETUTIL::get*() methods + * depending on the object of interest. + */ + void update(); + + /** + * Get the current temperature. update() must have been called + * prior to calling this method. + * + * @param fahrenheit true to return the temperature in degrees + * fahrenheit, false to return the temperature in degrees celcius. + * The default is false (degrees Celcius). + * @return The last temperature reading in Celcius or Fahrenheit. + */ + float getTemperature(bool fahrenheit=false); + + /** + * Set the device temperature scale to Celcius of Fahrenheit. For + * devices with an LCD display, this will affect which scale is + * displayed. When changing the scale, it may take several + * seconds for the setting to take effect. + * + * @param fahrenheit true to set the scale to fahrenheit, false + * for celcius. + */ + void setTemperatureScale(bool fahrenheit); + + /** + * Get the device temperature scale. + * + * @return true if scale is fahrenheit, false for celcius. + */ + bool getTemperatureScale(); + + protected: + // always stored in C + float m_temperature; + + bool m_isTempInitialized; + bool m_isCelcius; + + private: + }; +}