This commit is contained in:
proddy
2019-04-20 08:14:24 +02:00
parent 8814c2a504
commit 2cf9e3786b
2 changed files with 38 additions and 44 deletions

View File

@@ -156,21 +156,19 @@ _EMS_Thermostat EMS_Thermostat; // for thermostat
_EMS_Other EMS_Other; // for other known EMS devices _EMS_Other EMS_Other; // for other known EMS devices
// CRC lookup table with poly 12 for faster checking // CRC lookup table with poly 12 for faster checking
const uint8_t ems_crc_table[] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, const uint8_t ems_crc_table[] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24, 0x26,
0x24, 0x26, 0x28, 0x2A, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, 0x40, 0x42, 0x44, 0x46, 0x28, 0x2A, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, 0x40, 0x42, 0x44, 0x46, 0x48, 0x4A, 0x4C, 0x4E,
0x48, 0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E, 0x60, 0x62, 0x64, 0x66, 0x68, 0x6A, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E, 0x60, 0x62, 0x64, 0x66, 0x68, 0x6A, 0x6C, 0x6E, 0x70, 0x72, 0x74, 0x76,
0x6C, 0x6E, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7A, 0x7C, 0x7E, 0x80, 0x82, 0x84, 0x86, 0x88, 0x8A, 0x8C, 0x8E, 0x78, 0x7A, 0x7C, 0x7E, 0x80, 0x82, 0x84, 0x86, 0x88, 0x8A, 0x8C, 0x8E, 0x90, 0x92, 0x94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0xED, 0xEF,
0xE1, 0xE3, 0xE5, 0xE7};
const uint8_t TX_WRITE_TIMEOUT_COUNT = 2; // 3 retries before timeout const uint8_t TX_WRITE_TIMEOUT_COUNT = 2; // 3 retries before timeout
const uint32_t EMS_BUS_TIMEOUT = 15000; // timeout in ms before recognizing the ems bus is offline (15 seconds) const uint32_t EMS_BUS_TIMEOUT = 15000; // timeout in ms before recognizing the ems bus is offline (15 seconds)
@@ -403,6 +401,14 @@ char * _hextoa(uint8_t value, char * buffer) {
return buffer; return buffer;
} }
// long to hex
char * _hextoa16(uint16_t value, char * buffer) {
// TODO: needs improving
char s[10];
strlcpy(buffer, itoa(value, s, 10), 10);
return buffer;
}
// for decimals 0 to 99, printed as a string // for decimals 0 to 99, printed as a string
char * _smallitoa(uint8_t value, char * buffer) { char * _smallitoa(uint8_t value, char * buffer) {
buffer[0] = ((value / 10) == 0) ? '0' : (value / 10) + '0'; buffer[0] = ((value / 10) == 0) ? '0' : (value / 10) + '0';
@@ -748,9 +754,9 @@ void _ems_readTelegram(uint8_t * telegram, uint8_t length) {
*/ */
void _printMessage(_EMS_RxTelegram * EMS_RxTelegram) { void _printMessage(_EMS_RxTelegram * EMS_RxTelegram) {
// header info // header info
uint8_t src = EMS_RxTelegram->src; uint8_t src = EMS_RxTelegram->src;
uint8_t dest = EMS_RxTelegram->dest; uint8_t dest = EMS_RxTelegram->dest;
uint8_t type = EMS_RxTelegram->type; uint16_t type = EMS_RxTelegram->type;
char output_str[200] = {0}; char output_str[200] = {0};
char buffer[16] = {0}; char buffer[16] = {0};
@@ -794,7 +800,7 @@ void _printMessage(_EMS_RxTelegram * EMS_RxTelegram) {
// type // type
strlcat(output_str, ", type 0x", sizeof(output_str)); strlcat(output_str, ", type 0x", sizeof(output_str));
strlcat(output_str, _hextoa(type, buffer), sizeof(output_str)); strlcat(output_str, _hextoa16(type, buffer), sizeof(output_str));
if (EMS_Sys_Status.emsLogging == EMS_SYS_LOGGING_THERMOSTAT) { if (EMS_Sys_Status.emsLogging == EMS_SYS_LOGGING_THERMOSTAT) {
// only print ones to/from thermostat if logging is set to thermostat only // only print ones to/from thermostat if logging is set to thermostat only
@@ -830,8 +836,7 @@ void _ems_processTelegram(_EMS_RxTelegram * EMS_RxTelegram) {
if (EMS_Types[i].type == type) { if (EMS_Types[i].type == type) {
// is it common type for everyone? // is it common type for everyone?
// is it for us? So the src must match with either the boiler, thermostat or other devices // is it for us? So the src must match with either the boiler, thermostat or other devices
if ((EMS_Types[i].model_id == EMS_MODEL_ALL) if ((EMS_Types[i].model_id == EMS_MODEL_ALL) || ((src == EMS_Boiler.device_id) || (src == EMS_Thermostat.device_id) || (src == EMS_ID_SM))) {
|| ((src == EMS_Boiler.device_id) || (src == EMS_Thermostat.device_id) || (src == EMS_ID_SM))) {
typeFound = true; typeFound = true;
break; break;
} }
@@ -965,9 +970,7 @@ void _processType(_EMS_RxTelegram * EMS_RxTelegram) {
} else { } else {
// write failed // write failed
if (EMS_Sys_Status.emsLogging >= EMS_SYS_LOGGING_BASIC) { if (EMS_Sys_Status.emsLogging >= EMS_SYS_LOGGING_BASIC) {
myDebug("Last write failed. Compared set value 0x%02X with received value 0x%02X", myDebug("Last write failed. Compared set value 0x%02X with received value 0x%02X", EMS_TxTelegram.comparisonValue, dataReceived);
EMS_TxTelegram.comparisonValue,
dataReceived);
} }
if (++EMS_Sys_Status.txRetryCount > TX_WRITE_TIMEOUT_COUNT) { if (++EMS_Sys_Status.txRetryCount > TX_WRITE_TIMEOUT_COUNT) {
if (EMS_Sys_Status.emsLogging >= EMS_SYS_LOGGING_BASIC) { if (EMS_Sys_Status.emsLogging >= EMS_SYS_LOGGING_BASIC) {
@@ -1268,7 +1271,6 @@ void _process_SM10Monitor(_EMS_RxTelegram * EMS_RxTelegram) {
* SM100Monitor - type 0x0262 EMS+ * SM100Monitor - type 0x0262 EMS+
*/ */
void _process_SM100Monitor(_EMS_RxTelegram * EMS_RxTelegram) { void _process_SM100Monitor(_EMS_RxTelegram * EMS_RxTelegram) {
// to be completed // to be completed
// need help to decyper telegram, e.g. 30 00 FF 00 02 62 00 A1 01 3F 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 // need help to decyper telegram, e.g. 30 00 FF 00 02 62 00 A1 01 3F 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
//EMS_Other.SMcollectorTemp = _toShort(2); // collector temp from SM10/SM100, is *10 //EMS_Other.SMcollectorTemp = _toShort(2); // collector temp from SM10/SM100, is *10
@@ -1369,19 +1371,14 @@ void _process_Version(_EMS_RxTelegram * EMS_RxTelegram) {
if (typeFound) { if (typeFound) {
// its a boiler // its a boiler
myDebug("Boiler found. Model %s (DeviceID:0x%02X ProductID:%d Version:%s)", myDebug("Boiler found. Model %s (DeviceID:0x%02X ProductID:%d Version:%s)", Boiler_Types[i].model_string, Boiler_Types[i].device_id, product_id, version);
Boiler_Types[i].model_string,
Boiler_Types[i].device_id,
product_id,
version);
// add to list // add to list
_addDevice(product_id, Boiler_Types[i].device_id, version, Boiler_Types[i].model_string); _addDevice(product_id, Boiler_Types[i].device_id, version, Boiler_Types[i].model_string);
// if its a boiler set it, unless it already has been set by checking for a productID // if its a boiler set it, unless it already has been set by checking for a productID
// it will take the first one found in the list // it will take the first one found in the list
if (((EMS_Boiler.device_id == EMS_ID_NONE) || (EMS_Boiler.device_id == Boiler_Types[i].device_id)) if (((EMS_Boiler.device_id == EMS_ID_NONE) || (EMS_Boiler.device_id == Boiler_Types[i].device_id)) && EMS_Boiler.product_id == EMS_ID_NONE) {
&& EMS_Boiler.product_id == EMS_ID_NONE) {
myDebug("* Setting Boiler to model %s (DeviceID:0x%02X ProductID:%d Version:%s)", myDebug("* Setting Boiler to model %s (DeviceID:0x%02X ProductID:%d Version:%s)",
Boiler_Types[i].model_string, Boiler_Types[i].model_string,
Boiler_Types[i].device_id, Boiler_Types[i].device_id,
@@ -1457,11 +1454,7 @@ void _process_Version(_EMS_RxTelegram * EMS_RxTelegram) {
} }
if (typeFound) { if (typeFound) {
myDebug("Device found. Model %s with DeviceID 0x%02X, ProductID %d, Version %s", myDebug("Device found. Model %s with DeviceID 0x%02X, ProductID %d, Version %s", Other_Types[i].model_string, Other_Types[i].device_id, product_id, version);
Other_Types[i].model_string,
Other_Types[i].device_id,
product_id,
version);
// add to list // add to list
_addDevice(product_id, Other_Types[i].device_id, version, Other_Types[i].model_string); _addDevice(product_id, Other_Types[i].device_id, version, Other_Types[i].model_string);
@@ -1596,9 +1589,9 @@ void ems_getThermostatValues() {
* Generic function to return various settings from the thermostat * Generic function to return various settings from the thermostat
*/ */
void ems_getBoilerValues() { void ems_getBoilerValues() {
ems_doReadCommand(EMS_TYPE_UBAMonitorFast, EMS_Boiler.device_id); // get boiler stats, instead of waiting 10secs for the broadcast ems_doReadCommand(EMS_TYPE_UBAMonitorFast, EMS_Boiler.device_id); // get boiler stats, instead of waiting 10secs for the broadcast
ems_doReadCommand(EMS_TYPE_UBAMonitorSlow, EMS_Boiler.device_id); // get more boiler stats, instead of waiting 60secs for the broadcast ems_doReadCommand(EMS_TYPE_UBAMonitorSlow, EMS_Boiler.device_id); // get more boiler stats, instead of waiting 60secs for the broadcast
ems_doReadCommand(EMS_TYPE_UBAParameterWW, EMS_Boiler.device_id); // get Warm Water values ems_doReadCommand(EMS_TYPE_UBAParameterWW, EMS_Boiler.device_id); // get Warm Water values
ems_doReadCommand(EMS_TYPE_UBAParametersMessage, EMS_Boiler.device_id); // get MC10 boiler values ems_doReadCommand(EMS_TYPE_UBAParametersMessage, EMS_Boiler.device_id); // get MC10 boiler values
ems_doReadCommand(EMS_TYPE_UBATotalUptimeMessage, EMS_Boiler.device_id); // get uptime from boiler ems_doReadCommand(EMS_TYPE_UBATotalUptimeMessage, EMS_Boiler.device_id); // get uptime from boiler
} }
@@ -2211,14 +2204,15 @@ void ems_testTelegram(uint8_t test_num) {
if (test_num == 0) if (test_num == 0)
return; return;
static const char tests[5][200] = { static const char tests[7][200] = {
"08 00 34 00 3E 02 1D 80 00 31 00 00 01 00 01 0B AE 02", // test 1 "08 00 34 00 3E 02 1D 80 00 31 00 00 01 00 01 0B AE 02", // test 1
"10 00 FF 00 01 A5 80 00 01 30 28 00 30 28 01 54 03 03 01 01 54 02 A8 00 00 11 01 03 FF FF 00", // test 2 - RC310 ems+ "10 00 FF 00 01 A5 80 00 01 30 28 00 30 28 01 54 03 03 01 01 54 02 A8 00 00 11 01 03 FF FF 00", // test 2 - RC310 ems+
"10 00 FF 19 01 A5 06 04 00 00 00 00 FF 64 37 00 3C 01 FF 01", // test 3 - RC310 ems+ "10 00 FF 19 01 A5 06 04 00 00 00 00 FF 64 37 00 3C 01 FF 01", // test 3 - RC310 ems+
"30 00 FF 00 02 62 00 A1 01 3F 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00", // test 4 - SM100 "30 00 FF 00 02 62 00 A1 01 3F 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00", // test 4 - SM100
"10 00 FF 00 01 A5 00 D7 21 00 00 00 00 30 01 84 01 01 03 01 84 01 F1 00 00 11 01 00 08 63 00" // test 5 - RC1010 "10 00 FF 00 01 A5 00 D7 21 00 00 00 00 30 01 84 01 01 03 01 84 01 F1 00 00 11 01 00 08 63 00", // test 5 - RC1010
"18 00 FF 00 01 A5 00 DD 21 23 00 00 23 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00" // test 6 - RC300 "18 00 FF 00 01 A5 00 DD 21 23 00 00 23 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00", // test 6 - RC300
"90 00 FF 00 00 6F 01 01 00 46 00 B9" // test 7 - FR10
}; };

View File

@@ -6,5 +6,5 @@
#pragma once #pragma once
#define APP_NAME "EMS-ESP" #define APP_NAME "EMS-ESP"
#define APP_VERSION "1.7.0b8" #define APP_VERSION "1.7.0b9"
#define APP_HOSTNAME "ems-esp" #define APP_HOSTNAME "ems-esp"