tx_mode = tx_delay

This commit is contained in:
proddy
2019-05-26 15:56:00 +02:00
parent 1d7310411f
commit 4651987da8
7 changed files with 41 additions and 37 deletions

View File

@@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- MM50 Mixer
- tx_delay takes a value from 0 to 3 for the different Tx logic
- tx_mode takes a value from 0 to 3 for the different Tx logic
0 = original classic ems logic

View File

@@ -1186,7 +1186,7 @@ void MyESP::_fs_eraseConfig() {
"automatically restart when finished."));
if (SPIFFS.format()) {
delay(1000); // wait 1 seconds
delay(1000); // wait 1 second
resetESP();
}
}

View File

@@ -106,7 +106,7 @@ command_t project_cmds[] = {
{true, "shower_alert <on | off>", "send a warning of cold water after shower time is exceeded"},
{true, "publish_wait <seconds>", "set frequency for publishing to MQTT"},
{true, "heating_circuit <1 | 2>", "set the thermostat HC to work with if using multiple heating circuits"},
{true, "tx_delay <n>", "0=classic ems logic, 1=@kwertie01 ems+ logic, 2=@susisstrolch logic, 3=@philrich logic for Junkers"},
{true, "tx_mode <n>", "0=classic ems logic, 1=@kwertie01 ems+ logic, 2=@susisstrolch logic, 3=@philrich logic for Junkers"},
{false, "info", "show data captured on the EMS bus"},
{false, "log <n | b | t | r | v>", "set logging mode to none, basic, thermostat only, raw or verbose"},
@@ -338,11 +338,13 @@ void showInfo() {
if (ems_getBusConnected()) {
myDebug_P(PSTR(" Bus is connected"));
myDebug_P(PSTR(" Rx: Poll=%d microseconds, # Rx telegrams read=%d, # CRC errors=%d"), ems_getPollFrequency(), EMS_Sys_Status.emsRxPgks, EMS_Sys_Status.emxCrcErr);
myDebug_P(PSTR(" Rx: # successful read requests=%d, # CRC errors=%d"), EMS_Sys_Status.emsRxPgks, EMS_Sys_Status.emxCrcErr);
if (ems_getTxCapable()) {
myDebug_P(PSTR(" Tx: available, Tx delay is %d, # successful write commands=%d"), ems_getTxDelay(), EMS_Sys_Status.emsTxPkgs);
char valuestr[8] = {0}; // for formatting floats
myDebug_P(PSTR(" Tx: Last poll=%s seconds ago, Tx mode=%d, # successful write requests=%d"),
_float_to_char(valuestr, (ems_getPollFrequency() / (float)1000000), 3),
EMS_Sys_Status.emsTxPkgs);
} else {
myDebug_P(PSTR(" Tx: no signal"));
}
@@ -1020,8 +1022,8 @@ bool FSCallback(MYESP_FSACTION action, const JsonObject json) {
// shower_alert
EMSESP_Status.shower_alert = json["shower_alert"];
// tx delay
ems_setTxDelay(json["tx_delay"]);
// tx mode
ems_setTxMode(json["tx_mode"]);
// publish_wait
if (!(EMSESP_Status.publish_wait = json["publish_wait"])) {
@@ -1049,7 +1051,7 @@ bool FSCallback(MYESP_FSACTION action, const JsonObject json) {
json["shower_alert"] = EMSESP_Status.shower_alert;
json["publish_wait"] = EMSESP_Status.publish_wait;
json["heating_circuit"] = EMSESP_Status.heating_circuit;
json["tx_delay"] = ems_getTxDelay();
json["tx_mode"] = ems_getTxMode();
return true;
}
@@ -1180,9 +1182,9 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c
}
}
// tx delay
if ((strcmp(setting, "tx_delay") == 0) && (wc == 2)) {
ems_setTxDelay(atoi(value));
// tx delay/ tx mode
if (((strcmp(setting, "tx_mode") == 0) || (strcmp(setting, "tx_delay") == 0)) && (wc == 2)) {
ems_setTxMode(atoi(value));
ok = true;
}
}
@@ -1211,7 +1213,7 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c
myDebug_P(PSTR(" shower_timer=%s"), EMSESP_Status.shower_timer ? "on" : "off");
myDebug_P(PSTR(" shower_alert=%s"), EMSESP_Status.shower_alert ? "on" : "off");
myDebug_P(PSTR(" publish_wait=%d"), EMSESP_Status.publish_wait);
myDebug_P(PSTR(" tx_delay=%d"), ems_getTxDelay());
myDebug_P(PSTR(" tx_mode=%d"), ems_getTxMode());
}
return ok;

View File

@@ -201,7 +201,7 @@ const uint8_t ems_crc_table[] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E,
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_POLL_TIMEOUT = 5000; // timeout in ms before recognizing the ems bus is offline (5 seconds)
const uint32_t EMS_POLL_TIMEOUT = 5000000; // timeout in microseconds before recognizing the ems bus is offline (5 seconds)
// init stats and counters and buffers
// uses -255 or 255 for values that haven't been set yet (EMS_VALUE_INT_NOTSET and EMS_VALUE_FLOAT_NOTSET)
@@ -220,7 +220,7 @@ void ems_init() {
EMS_Sys_Status.emsTxDisabled = false;
EMS_Sys_Status.emsPollFrequency = 0;
EMS_Sys_Status.txRetryCount = 0;
EMS_Sys_Status.emsTxDelay = 0;
EMS_Sys_Status.emsTxMode = 0;
EMS_Sys_Status.emsReverse = false;
// thermostat
@@ -330,19 +330,19 @@ bool ems_getPoll() {
return EMS_Sys_Status.emsPollEnabled;
}
void ems_setTxDelay(uint8_t delay) {
EMS_Sys_Status.emsTxDelay = delay;
void ems_setTxMode(uint8_t mode) {
EMS_Sys_Status.emsTxMode = mode;
// special case for Junkers. If tx_delay is 3 then set the reverse poll flag
// special case for Junkers. If tx_mode is 3 then set the reverse poll flag
// https://github.com/proddy/EMS-ESP/issues/103#issuecomment-495945850
if (delay == 3) {
if (mode == 3) {
EMS_Sys_Status.emsReverse = true;
myDebug_P(PSTR("Setting for Tx Junkers logic and enabled the poll reverse flag"));
}
}
uint8_t ems_getTxDelay() {
return EMS_Sys_Status.emsTxDelay;
uint8_t ems_getTxMode() {
return EMS_Sys_Status.emsTxMode;
}
bool ems_getEmsRefreshed() {
@@ -690,15 +690,17 @@ void _ems_readTelegram(uint8_t * telegram, uint8_t length) {
// it could well be a Poll request from the boiler for us, which will have a value of 0x8B (0x0B | 0x80)
// or either a return code like 0x01 or 0x04 from the last Write command
if (length == 1) {
uint32_t timenow_microsecs = micros();
EMS_Sys_Status.emsPollFrequency = (timenow_microsecs - _last_emsPollFrequency);
_last_emsPollFrequency = timenow_microsecs;
uint8_t value = telegram[0]; // 1st byte of data package
// check first for a Poll for us
// the poll has the MSB set - seems to work on both EMS and Junkers
if (value == (EMS_ID_ME | 0x80)) {
EMS_Sys_Status.emsTxCapable = true;
uint32_t timenow_microsecs = micros();
EMS_Sys_Status.emsPollFrequency = (timenow_microsecs - _last_emsPollFrequency);
_last_emsPollFrequency = timenow_microsecs;
// do we have something to send thats waiting in the Tx queue?
// if so send it if the Queue is not in a wait state
if ((!EMS_TxQueue.isEmpty()) && (EMS_Sys_Status.emsTxStatus == EMS_TX_STATUS_IDLE)) {

View File

@@ -94,7 +94,7 @@ typedef struct {
bool emsTxCapable; // able to send via Tx
bool emsTxDisabled; // true to prevent all Tx
uint8_t txRetryCount; // # times the last Tx was re-sent
uint8_t emsTxDelay; // handles Tx logic
uint8_t emsTxMode; // handles Tx logic
bool emsReverse; // if true, poll logic is reversed
} _EMS_Sys_Status;
@@ -302,7 +302,7 @@ void ems_setFlowTemp(uint8_t temperature);
void ems_setWarmWaterActivated(bool activated);
void ems_setWarmTapWaterActivated(bool activated);
void ems_setPoll(bool b);
void ems_setTxDelay(uint8_t delay);
void ems_setTxMode(uint8_t mode);
void ems_setLogging(_EMS_SYS_LOGGING loglevel);
void ems_setEmsRefreshed(bool b);
void ems_setWarmWaterModeComfort(uint8_t comfort);
@@ -317,7 +317,7 @@ bool ems_getPoll();
bool ems_getTxEnabled();
bool ems_getThermostatEnabled();
bool ems_getBoilerEnabled();
uint8_t ems_getTxDelay();
uint8_t ems_getTxMode();
bool ems_getBusConnected();
_EMS_SYS_LOGGING ems_getLogging();
bool ems_getEmsRefreshed();

View File

@@ -175,9 +175,9 @@ void ICACHE_FLASH_ATTR emsuart_tx_brk() {
// automatically be sent when the tx fifo is empty
tmp = (1 << UCBRK);
USC0(EMSUART_UART) |= (tmp); // set bit
if (EMS_Sys_Status.emsTxDelay <= 2) {
if (EMS_Sys_Status.emsTxMode <= 2) {
delayMicroseconds(EMSUART_TX_BRK_WAIT); // classic mode
} else if (EMS_Sys_Status.emsTxDelay == 3) {
} else if (EMS_Sys_Status.emsTxMode == 3) {
delayMicroseconds(EMSUART_TX_WAIT_BRK - EMSUART_TX_LAG); // 1144 (11 Bits)
}
USC0(EMSUART_UART) &= ~(tmp); // clear bit
@@ -197,18 +197,18 @@ static inline void ICACHE_FLASH_ATTR emsuart_loopback(bool enable) {
* Send to Tx, ending with a <BRK>
*/
void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
if (EMS_Sys_Status.emsTxDelay == 0) { // Classic logic
if (EMS_Sys_Status.emsTxMode == 0) { // Classic logic
for (uint8_t i = 0; i < len; i++) {
USF(EMSUART_UART) = buf[i];
}
emsuart_tx_brk(); // send <BRK>
} else if (EMS_Sys_Status.emsTxDelay == 1) { // With extra tx delay for EMS+
} else if (EMS_Sys_Status.emsTxMode == 1) { // With extra tx delay for EMS+
for (uint8_t i = 0; i < len; i++) {
USF(EMSUART_UART) = buf[i];
delayMicroseconds(EMSUART_TX_BRK_WAIT); // https://github.com/proddy/EMS-ESP/issues/23#
}
emsuart_tx_brk(); // send <BRK>
} else if (EMS_Sys_Status.emsTxDelay == 3) { // Junkers logic by @philrich
} else if (EMS_Sys_Status.emsTxMode == 3) { // Junkers logic by @philrich
for (uint8_t i = 0; i < len; i++) {
USF(EMSUART_UART) = buf[i];
@@ -220,7 +220,7 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
delayMicroseconds(EMSUART_TX_WAIT_BYTE - EMSUART_TX_LAG + EMSUART_TX_WAIT_GAP);
}
emsuart_tx_brk(); // send <BRK>
} else if (EMS_Sys_Status.emsTxDelay == 2) { // smart Tx - take two - https://github.com/proddy/EMS-ESP/issues/103 by @susisstrolch
} else if (EMS_Sys_Status.emsTxMode == 2) { // smart Tx - take two - https://github.com/proddy/EMS-ESP/issues/103 by @susisstrolch
/*
* we emit the whole telegram, with Rx interrupt disabled, collecting busmaster response in FIFO.

View File

@@ -6,5 +6,5 @@
#pragma once
#define APP_NAME "EMS-ESP"
#define APP_VERSION "1.8.0b4"
#define APP_VERSION "1.8.0b5"
#define APP_HOSTNAME "ems-esp"