mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
added ems gateway & switch. moved all code to devices folder
This commit is contained in:
60
src/devices/connect.cpp
Normal file
60
src/devices/connect.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
||||||
|
* Copyright 2019 Paul Derbyshire
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "connect.h"
|
||||||
|
|
||||||
|
// MAKE_PSTR_WORD(connect)
|
||||||
|
|
||||||
|
namespace emsesp {
|
||||||
|
|
||||||
|
REGISTER_FACTORY(Connect, EMSdevice::DeviceType::CONNECT);
|
||||||
|
|
||||||
|
MAKE_PSTR(logger_name, "connect")
|
||||||
|
uuid::log::Logger Connect::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
||||||
|
|
||||||
|
Connect::Connect(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand)
|
||||||
|
: EMSdevice(device_type, device_id, product_id, version, name, flags, brand) {
|
||||||
|
// telegram handlers
|
||||||
|
// register_telegram_type(EMS_TYPE_XX, "XX", false, std::bind(&Controller::process_XX, this, _1));
|
||||||
|
|
||||||
|
// MQTT callbacks
|
||||||
|
// register_mqtt_topic("cmd", std::bind(&Controller::cmd, this, _1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Connect::add_context_menu() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// display all values into the shell console
|
||||||
|
void Connect::show_values(uuid::console::Shell & shell) {
|
||||||
|
EMSdevice::show_values(shell); // always call this to show header
|
||||||
|
}
|
||||||
|
|
||||||
|
// publish values via MQTT
|
||||||
|
void Connect::publish_values() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see if values have been updated
|
||||||
|
bool Connect::updated_values() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add console commands
|
||||||
|
void Connect::console_commands() {
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace emsesp
|
||||||
52
src/devices/connect.h
Normal file
52
src/devices/connect.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
||||||
|
* Copyright 2019 Paul Derbyshire
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EMSESP_CONNECT_H
|
||||||
|
#define EMSESP_CONNECT_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include <uuid/log.h>
|
||||||
|
|
||||||
|
#include "emsdevice.h"
|
||||||
|
#include "telegram.h"
|
||||||
|
#include "emsesp.h"
|
||||||
|
#include "helpers.h"
|
||||||
|
#include "mqtt.h"
|
||||||
|
|
||||||
|
namespace emsesp {
|
||||||
|
|
||||||
|
class Connect : public EMSdevice {
|
||||||
|
public:
|
||||||
|
Connect(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand);
|
||||||
|
|
||||||
|
virtual void show_values(uuid::console::Shell & shell);
|
||||||
|
virtual void publish_values();
|
||||||
|
virtual bool updated_values();
|
||||||
|
virtual void add_context_menu();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static uuid::log::Logger logger_;
|
||||||
|
|
||||||
|
void console_commands();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace emsesp
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
REGISTER_FACTORY(Controller, EMSdevice::DeviceType::CONTROLLER);
|
REGISTER_FACTORY(Controller, EMSdevice::DeviceType::CONTROLLER);
|
||||||
|
|
||||||
MAKE_PSTR(logger_name, "controller")
|
MAKE_PSTR(logger_name, "controller")
|
||||||
uuid::log::Logger Controller::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
uuid::log::Logger Controller::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
||||||
|
|
||||||
60
src/devices/gateway.cpp
Normal file
60
src/devices/gateway.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
||||||
|
* Copyright 2019 Paul Derbyshire
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gateway.h"
|
||||||
|
|
||||||
|
// MAKE_PSTR_WORD(gateway)
|
||||||
|
|
||||||
|
namespace emsesp {
|
||||||
|
|
||||||
|
REGISTER_FACTORY(Gateway, EMSdevice::DeviceType::GATEWAY);
|
||||||
|
|
||||||
|
MAKE_PSTR(logger_name, "gateway")
|
||||||
|
uuid::log::Logger Gateway::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
||||||
|
|
||||||
|
Gateway::Gateway(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand)
|
||||||
|
: EMSdevice(device_type, device_id, product_id, version, name, flags, brand) {
|
||||||
|
// telegram handlers
|
||||||
|
// register_telegram_type(EMS_TYPE_XX, "XX", false, std::bind(&Controller::process_XX, this, _1));
|
||||||
|
|
||||||
|
// MQTT callbacks
|
||||||
|
// register_mqtt_topic("cmd", std::bind(&Controller::cmd, this, _1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gateway::add_context_menu() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// display all values into the shell console
|
||||||
|
void Gateway::show_values(uuid::console::Shell & shell) {
|
||||||
|
EMSdevice::show_values(shell); // always call this to show header
|
||||||
|
}
|
||||||
|
|
||||||
|
// publish values via MQTT
|
||||||
|
void Gateway::publish_values() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see if values have been updated
|
||||||
|
bool Gateway::updated_values() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add console commands
|
||||||
|
void Gateway::console_commands() {
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace emsesp
|
||||||
52
src/devices/gateway.h
Normal file
52
src/devices/gateway.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
||||||
|
* Copyright 2019 Paul Derbyshire
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EMSESP_GATEWAY_H
|
||||||
|
#define EMSESP_GATEWAY_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include <uuid/log.h>
|
||||||
|
|
||||||
|
#include "emsdevice.h"
|
||||||
|
#include "telegram.h"
|
||||||
|
#include "emsesp.h"
|
||||||
|
#include "helpers.h"
|
||||||
|
#include "mqtt.h"
|
||||||
|
|
||||||
|
namespace emsesp {
|
||||||
|
|
||||||
|
class Gateway : public EMSdevice {
|
||||||
|
public:
|
||||||
|
Gateway(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand);
|
||||||
|
|
||||||
|
virtual void show_values(uuid::console::Shell & shell);
|
||||||
|
virtual void publish_values();
|
||||||
|
virtual bool updated_values();
|
||||||
|
virtual void add_context_menu();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static uuid::log::Logger logger_;
|
||||||
|
|
||||||
|
void console_commands();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace emsesp
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
REGISTER_FACTORY(Heatpump, EMSdevice::DeviceType::HEATPUMP);
|
REGISTER_FACTORY(Heatpump, EMSdevice::DeviceType::HEATPUMP);
|
||||||
|
|
||||||
MAKE_PSTR(logger_name, "heatpump")
|
MAKE_PSTR(logger_name, "heatpump")
|
||||||
uuid::log::Logger Heatpump::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
uuid::log::Logger Heatpump::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
REGISTER_FACTORY(Mixing, EMSdevice::DeviceType::MIXING);
|
REGISTER_FACTORY(Mixing, EMSdevice::DeviceType::MIXING);
|
||||||
|
|
||||||
MAKE_PSTR(logger_name, "mixing")
|
MAKE_PSTR(logger_name, "mixing")
|
||||||
uuid::log::Logger Mixing::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
uuid::log::Logger Mixing::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
||||||
|
|
||||||
307
src/helpers.cpp
307
src/helpers.cpp
@@ -1,307 +0,0 @@
|
|||||||
/*
|
|
||||||
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
|
||||||
* Copyright 2019 Paul Derbyshire
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "helpers.h"
|
|
||||||
#include "telegram.h" // for EMS_VALUE_* settings
|
|
||||||
|
|
||||||
namespace emsesp {
|
|
||||||
|
|
||||||
// like itoa but for hex, and quicker
|
|
||||||
char * Helpers::hextoa(char * result, const uint8_t value) {
|
|
||||||
char * p = result;
|
|
||||||
uint8_t nib1 = (value >> 4) & 0x0F;
|
|
||||||
uint8_t nib2 = (value >> 0) & 0x0F;
|
|
||||||
*p++ = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
|
|
||||||
*p++ = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
|
|
||||||
*p = '\0'; // null terminate just in case
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* itoa for 2 byte integers
|
|
||||||
* written by Lukás Chmela, Released under GPLv3. http://www.strudel.org.uk/itoa/ version 0.4
|
|
||||||
*/
|
|
||||||
char * Helpers::itoa(char * result, int16_t value, const uint8_t base) {
|
|
||||||
// check that the base if valid
|
|
||||||
if (base < 2 || base > 36) {
|
|
||||||
*result = '\0';
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
char * ptr = result, *ptr1 = result, tmp_char;
|
|
||||||
int16_t tmp_value;
|
|
||||||
|
|
||||||
do {
|
|
||||||
tmp_value = value;
|
|
||||||
value /= base;
|
|
||||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
|
|
||||||
} while (value);
|
|
||||||
|
|
||||||
// Apply negative sign
|
|
||||||
if (tmp_value < 0) {
|
|
||||||
*ptr++ = '-';
|
|
||||||
}
|
|
||||||
*ptr-- = '\0';
|
|
||||||
while (ptr1 < ptr) {
|
|
||||||
tmp_char = *ptr;
|
|
||||||
*ptr-- = *ptr1;
|
|
||||||
*ptr1++ = tmp_char;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for decimals 0 to 99, printed as a 2 char string
|
|
||||||
char * Helpers::smallitoa(char * result, const uint8_t value) {
|
|
||||||
result[0] = ((value / 10) == 0) ? '0' : (value / 10) + '0';
|
|
||||||
result[1] = (value % 10) + '0';
|
|
||||||
result[2] = '\0';
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for decimals 0 to 999, printed as a string
|
|
||||||
char * Helpers::smallitoa(char * result, const uint16_t value) {
|
|
||||||
result[0] = ((value / 100) == 0) ? '0' : (value / 100) + '0';
|
|
||||||
result[1] = (((value % 100) / 10) == 0) ? '0' : ((value % 100) / 10) + '0';
|
|
||||||
result[2] = (value % 10) + '0';
|
|
||||||
result[3] = '\0';
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert unsigned int (single byte) to text value and returns it
|
|
||||||
// format: 2=divide by 2, 10=divide by 10, 255=handle as a Boolean
|
|
||||||
char * Helpers::render_value(char * result, uint8_t value, uint8_t format) {
|
|
||||||
result[0] = '\0';
|
|
||||||
|
|
||||||
// check if its a boolean
|
|
||||||
if (format == EMS_VALUE_BOOL) {
|
|
||||||
if (value == EMS_VALUE_BOOL_OFF) {
|
|
||||||
strlcpy(result, "off", 5);
|
|
||||||
} else if (value == EMS_VALUE_BOOL_NOTSET) {
|
|
||||||
strlcpy(result, "?", 5);
|
|
||||||
} else {
|
|
||||||
strlcpy(result, "on", 5); // assume on. could have value 0x01 or 0xFF
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value == EMS_VALUE_UINT_NOTSET) {
|
|
||||||
strlcpy(result, "?", 5);
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char s2[5] = {0};
|
|
||||||
|
|
||||||
switch (format) {
|
|
||||||
case 2:
|
|
||||||
strlcpy(result, itoa(s2, value >> 1, 10), 5);
|
|
||||||
strlcat(result, ".", 5);
|
|
||||||
strlcat(result, ((value & 0x01) ? "5" : "0"), 5);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 10:
|
|
||||||
strlcpy(result, itoa(s2, value / 10, 10), 5);
|
|
||||||
strlcat(result, ".", 5);
|
|
||||||
strlcat(result, itoa(s2, value % 10, 10), 5);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
itoa(result, value, 10);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert float to char
|
|
||||||
// format is the precision
|
|
||||||
char * Helpers::render_value(char * result, const float value, const uint8_t format) {
|
|
||||||
long p[] = {0, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
|
|
||||||
|
|
||||||
char * ret = result;
|
|
||||||
long whole = (long)value;
|
|
||||||
Helpers::itoa(result, whole, 10);
|
|
||||||
while (*result != '\0') {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
*result++ = '.';
|
|
||||||
long decimal = abs((long)((value - whole) * p[format]));
|
|
||||||
itoa(result, decimal, 10);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert short (two bytes) to text string and returns string
|
|
||||||
// decimals: 0 = no division, 10=divide value by 10, 2=divide by 2, 100=divide value by 100
|
|
||||||
// negative values are assumed stored as 1-compliment (https://medium.com/@LeeJulija/how-integers-are-stored-in-memory-using-twos-complement-5ba04d61a56c)
|
|
||||||
char * Helpers::render_value(char * result, const int16_t value, const uint8_t format) {
|
|
||||||
result[0] = '\0';
|
|
||||||
|
|
||||||
// remove errors or invalid values, 0x7D00 and higher
|
|
||||||
if ((value == EMS_VALUE_SHORT_NOTSET) || (value == EMS_VALUE_SHORT_INVALID) || (value == EMS_VALUE_USHORT_NOTSET)) {
|
|
||||||
strlcpy(result, "?", 10);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// just print it if mo conversion required
|
|
||||||
if ((format == 0) || (format == 1)) {
|
|
||||||
itoa(result, value, 10);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t new_value = value;
|
|
||||||
|
|
||||||
// check for negative values
|
|
||||||
if (new_value < 0) {
|
|
||||||
strlcpy(result, "-", 10);
|
|
||||||
new_value *= -1; // convert to positive
|
|
||||||
} else {
|
|
||||||
strlcpy(result, "", 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// do floating point
|
|
||||||
char s2[10] = {0};
|
|
||||||
if (format == 2) {
|
|
||||||
// divide by 2
|
|
||||||
strlcat(result, itoa(s2, new_value / 2, 10), 10);
|
|
||||||
strlcat(result, ".", 10);
|
|
||||||
strlcat(result, ((new_value & 0x01) ? "5" : "0"), 10);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
strlcat(result, itoa(s2, new_value / format, 10), 10);
|
|
||||||
strlcat(result, ".", 10);
|
|
||||||
strlcat(result, itoa(s2, new_value % format, 10), 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert unsigned short (two bytes) to text string and prints it
|
|
||||||
// format: 0 = no division, 10=divide value by 10, 2=divide by 2, 100=divide value by 100
|
|
||||||
char * Helpers::render_value(char * result, const uint16_t value, const uint8_t format) {
|
|
||||||
result[0] = '\0';
|
|
||||||
|
|
||||||
if ((value == EMS_VALUE_USHORT_NOTSET) || (value == EMS_VALUE_USHORT_INVALID)) {
|
|
||||||
strlcpy(result, "?", 10);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (render_value(result, (int16_t)value, format)); // use same code, force it to a signed int
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert signed byte to text string and prints it
|
|
||||||
// format: 0 = no division, 10=divide value by 10, 2=divide by 2, 100=divide value by 100
|
|
||||||
char * Helpers::render_value(char * result, const int8_t value, const uint8_t format) {
|
|
||||||
result[0] = '\0';
|
|
||||||
|
|
||||||
if (value == EMS_VALUE_INT_NOTSET) {
|
|
||||||
strlcpy(result, "?", 10);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (render_value(result, (int16_t)value, format)); // use same code, force it to a signed int
|
|
||||||
}
|
|
||||||
|
|
||||||
// render long (4 byte) unsigned values
|
|
||||||
// format = 0 for normal, any other value for divide by format
|
|
||||||
char * Helpers::render_value(char * result, const uint32_t value, const uint8_t format) {
|
|
||||||
result[0] = '\0';
|
|
||||||
|
|
||||||
if ((value == EMS_VALUE_ULONG_NOTSET) || (value == EMS_VALUE_ULONG_INVALID)) {
|
|
||||||
strlcpy(result, "?", 10);
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char s[20] = {0};
|
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
|
||||||
if (format <= 1) {
|
|
||||||
strlcat(result, ltoa(value, s, 10), 20);
|
|
||||||
} else {
|
|
||||||
strlcat(result, ltoa(value / format, s, 10), 20);
|
|
||||||
strlcat(result, ".", 2);
|
|
||||||
strlcat(result, ltoa(value % format, s, 10), 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
strncat(result, itoa(s, value / format, 10), 20);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// creates string of hex values from an arrray of bytes
|
|
||||||
std::string Helpers::data_to_hex(const uint8_t * data, const uint8_t length) {
|
|
||||||
if (length == 0) {
|
|
||||||
return uuid::read_flash_string(F("<empty>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string str(160, '\0');
|
|
||||||
char buffer[4];
|
|
||||||
char * p = &str[0];
|
|
||||||
for (uint8_t i = 0; i < length; i++) {
|
|
||||||
Helpers::hextoa(buffer, data[i]);
|
|
||||||
*p++ = buffer[0];
|
|
||||||
*p++ = buffer[1];
|
|
||||||
*p++ = ' '; // space
|
|
||||||
}
|
|
||||||
*--p = '\0'; // null terminate just in case, loosing the trailing space
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// takes a hex string and convert it to an unsigned 32bit number (max 8 hex digits)
|
|
||||||
// works with only positive numbers
|
|
||||||
uint32_t Helpers::hextoint(const char * hex) {
|
|
||||||
uint32_t val = 0;
|
|
||||||
while (*hex) {
|
|
||||||
// get current character then increment
|
|
||||||
char byte = *hex++;
|
|
||||||
// transform hex character to the 4bit equivalent number, using the ascii table indexes
|
|
||||||
if (byte >= '0' && byte <= '9')
|
|
||||||
byte = byte - '0';
|
|
||||||
else if (byte >= 'a' && byte <= 'f')
|
|
||||||
byte = byte - 'a' + 10;
|
|
||||||
else if (byte >= 'A' && byte <= 'F')
|
|
||||||
byte = byte - 'A' + 10;
|
|
||||||
else
|
|
||||||
return 0; // error
|
|
||||||
// shift 4 to make space for new digit, and add the 4 bits of the new digit
|
|
||||||
val = (val << 4) | (byte & 0xF);
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
// quick char to long
|
|
||||||
uint16_t Helpers::atoint(const char * value) {
|
|
||||||
unsigned int x = 0;
|
|
||||||
while (*value != '\0') {
|
|
||||||
x = (x * 10) + (*value - '0');
|
|
||||||
++value;
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// rounds a number to 2 decimal places
|
|
||||||
// example: round2(3.14159) -> 3.14
|
|
||||||
double Helpers::round2(double value) {
|
|
||||||
return (int)(value * 100 + 0.5) / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace emsesp
|
|
||||||
@@ -24,6 +24,7 @@ MAKE_PSTR(wh, "Wh")
|
|||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
REGISTER_FACTORY(Solar, EMSdevice::DeviceType::SOLAR);
|
REGISTER_FACTORY(Solar, EMSdevice::DeviceType::SOLAR);
|
||||||
|
|
||||||
MAKE_PSTR(logger_name, "solar")
|
MAKE_PSTR(logger_name, "solar")
|
||||||
uuid::log::Logger Solar::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
uuid::log::Logger Solar::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
||||||
|
|
||||||
|
|||||||
60
src/switch.cpp
Normal file
60
src/switch.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
||||||
|
* Copyright 2019 Paul Derbyshire
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "switch.h"
|
||||||
|
|
||||||
|
// MAKE_PSTR_WORD(switch)
|
||||||
|
|
||||||
|
namespace emsesp {
|
||||||
|
|
||||||
|
REGISTER_FACTORY(Switch, EMSdevice::DeviceType::SWITCH);
|
||||||
|
|
||||||
|
MAKE_PSTR(logger_name, "switch")
|
||||||
|
uuid::log::Logger Switch::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
||||||
|
|
||||||
|
Switch::Switch(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand)
|
||||||
|
: EMSdevice(device_type, device_id, product_id, version, name, flags, brand) {
|
||||||
|
// telegram handlers
|
||||||
|
// register_telegram_type(EMS_TYPE_XX, "XX", false, std::bind(&Controller::process_XX, this, _1));
|
||||||
|
|
||||||
|
// MQTT callbacks
|
||||||
|
// register_mqtt_topic("cmd", std::bind(&Controller::cmd, this, _1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Switch::add_context_menu() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// display all values into the shell console
|
||||||
|
void Switch::show_values(uuid::console::Shell & shell) {
|
||||||
|
EMSdevice::show_values(shell); // always call this to show header
|
||||||
|
}
|
||||||
|
|
||||||
|
// publish values via MQTT
|
||||||
|
void Switch::publish_values() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see if values have been updated
|
||||||
|
bool Switch::updated_values() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add console commands
|
||||||
|
void Switch::console_commands() {
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace emsesp
|
||||||
52
src/switch.h
Normal file
52
src/switch.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
||||||
|
* Copyright 2019 Paul Derbyshire
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EMSESP_SWITCH_H
|
||||||
|
#define EMSESP_SWITCH_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include <uuid/log.h>
|
||||||
|
|
||||||
|
#include "emsdevice.h"
|
||||||
|
#include "telegram.h"
|
||||||
|
#include "emsesp.h"
|
||||||
|
#include "helpers.h"
|
||||||
|
#include "mqtt.h"
|
||||||
|
|
||||||
|
namespace emsesp {
|
||||||
|
|
||||||
|
class Switch : public EMSdevice {
|
||||||
|
public:
|
||||||
|
Switch(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand);
|
||||||
|
|
||||||
|
virtual void show_values(uuid::console::Shell & shell);
|
||||||
|
virtual void publish_values();
|
||||||
|
virtual bool updated_values();
|
||||||
|
virtual void add_context_menu();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static uuid::log::Logger logger_;
|
||||||
|
|
||||||
|
void console_commands();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace emsesp
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -31,6 +31,7 @@ MAKE_PSTR(master_thermostat_fmt, "Master Thermostat device ID = %s")
|
|||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
REGISTER_FACTORY(Thermostat, EMSdevice::DeviceType::THERMOSTAT);
|
REGISTER_FACTORY(Thermostat, EMSdevice::DeviceType::THERMOSTAT);
|
||||||
|
|
||||||
MAKE_PSTR(logger_name, "thermostat")
|
MAKE_PSTR(logger_name, "thermostat")
|
||||||
uuid::log::Logger Thermostat::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
uuid::log::Logger Thermostat::logger_{F_(logger_name), uuid::log::Facility::CONSOLE};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user