mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
uart changes and merge https://github.com/proddy/EMS-ESP
This commit is contained in:
17
README.md
17
README.md
@@ -33,6 +33,17 @@ Note: Version 2.0 is not backward compatible with v1.0. The File system structur
|
||||
|
||||
- LED behaves like in 1.9. A solid LED means good connection and EMS data is coming in. A slow pulse means either the WiFi or the EMS bus is not connected. A very fast pulse is when the system is booting up and configuring itself.
|
||||
|
||||
### Uploading the firmware
|
||||
|
||||
- If you don't have Python 3.8, install it (https://www.python.org/downloads/)
|
||||
#### Using direct to USB:
|
||||
- install `esptool` using the command `pip install esptool`
|
||||
- connect an ESP8266 to the USB. Figure out which COM port it's on (e.g. windows device manager)
|
||||
- `esptool.py -p COM6 -b 921600 write_flash 0x00000 <firmware.bin>`
|
||||
#### Using OTA (Over The Air):
|
||||
- download `espota` from https://github.com/esp8266/Arduino/blob/master/tools/espota.py
|
||||
- `espota.py --debug --progress --port 8266 --auth neo -i <ip address> -f <firmware.bin>`
|
||||
|
||||
### Setting up for the first time:
|
||||
|
||||
- connect the ESP8266/ESP32 via USB and enter via the serial/com port with baud 115200
|
||||
@@ -46,16 +57,14 @@ Note: Version 2.0 is not backward compatible with v1.0. The File system structur
|
||||
- reboot and next time use the Telnet via WiFi to connect as the serial mode will be disabled.
|
||||
|
||||
### Debugging
|
||||
- Turn on logging with either `log all` or `log trace` or `log debug`
|
||||
- Turn on logging with either `log all` or `log debug`
|
||||
- Error messages are shown in the color red
|
||||
- type `show` from the main root to see if any data has come in
|
||||
- if not, go to the `ems` context and type `show` which will display some EMS bus stats
|
||||
- use the `refresh` command to fetch new data from the EMS bus
|
||||
- use `scan devices` or `scan devices deep` to locate devices on the EMS bus. If any are unknown please report back to the project so we can update our EMS device library.
|
||||
|
||||
|
||||
|
||||
# Full Console Commands
|
||||
# List of console commands
|
||||
|
||||
```
|
||||
common commands available in all contexts:
|
||||
|
||||
@@ -56,7 +56,7 @@ void EMSuart::send_poll(uint8_t data) {
|
||||
* buf contains the CRC and len is #bytes including the CRC
|
||||
* returns code, 0=success, 1=brk error, 2=watchdog timeout
|
||||
*/
|
||||
EMSUART_STATUS EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
if (len == 0) {
|
||||
return EMS_TX_STATUS_OK; // nothing to send
|
||||
}
|
||||
|
||||
@@ -23,25 +23,22 @@
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
typedef enum {
|
||||
EMS_TX_STATUS_OK = 1,
|
||||
EMS_TX_WTD_TIMEOUT, // watchdog timeout during send
|
||||
EMS_TX_BRK_DETECT, // incoming BRK during Tx
|
||||
} EMSUART_STATUS;
|
||||
#define EMS_TX_STATUS_ERR 0
|
||||
#define EMS_TX_STATUS_OK 1
|
||||
|
||||
class EMSuart {
|
||||
public:
|
||||
EMSuart() = default;
|
||||
~EMSuart() = default;
|
||||
|
||||
static void start(uint8_t tx_mode);
|
||||
static void stop();
|
||||
static void restart();
|
||||
static void send_poll(uint8_t data);
|
||||
static EMSUART_STATUS transmit(uint8_t * buf, uint8_t len);
|
||||
static void start(uint8_t tx_mode);
|
||||
static void stop();
|
||||
static void restart();
|
||||
static void send_poll(uint8_t data);
|
||||
static uint16_t transmit(uint8_t * buf, uint8_t len);
|
||||
|
||||
private:
|
||||
static char * hextoa(char * result, const uint8_t value);
|
||||
static char * hextoa(char * result, const uint8_t value);
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -51,7 +51,6 @@ using uuid::log::Level;
|
||||
#define MAKE_PSTR(string_name, string_literal) static const char __pstr__##string_name[] __attribute__((__aligned__(sizeof(int)))) PROGMEM = string_literal;
|
||||
#define MAKE_PSTR_WORD(string_name) MAKE_PSTR(string_name, #string_name)
|
||||
#define F_(string_name) FPSTR(__pstr__##string_name)
|
||||
#define NO_ARGUMENTS std::vector<std::string>{}
|
||||
|
||||
// clang-format on
|
||||
|
||||
|
||||
@@ -679,7 +679,7 @@ void Boiler::process_UBAMaintenanceStatus(std::shared_ptr<const Telegram> telegr
|
||||
void Boiler::process_UBAMaintenanceSettings(std::shared_ptr<const Telegram> telegram) {
|
||||
}
|
||||
|
||||
// 0x10, 0x11, 0x12
|
||||
// 0x10, 0x11, 0x12
|
||||
// not yet implemented
|
||||
void Boiler::process_UBAErrorMessage(std::shared_ptr<const Telegram> telegram) {
|
||||
// data: displaycode(2), errornumner(2), year, month, hour, day, minute, duration(2), src-addr
|
||||
|
||||
@@ -162,6 +162,9 @@ void Mixing::process_MMStatusMessage(std::shared_ptr<const Telegram> telegram) {
|
||||
telegram->read_value(flowSetTemp_, 0);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
// Mixing on a MM10 - 0xAA
|
||||
// e.g. Thermostat -> Mixing Module, type 0xAA, telegram: 10 21 AA 00 FF 0C 0A 11 0A 32 xx
|
||||
void Mixing::process_MMConfigMessage(std::shared_ptr<const Telegram> telegram) {
|
||||
@@ -177,4 +180,6 @@ void Mixing::process_MMSetMessage(std::shared_ptr<const Telegram> telegram) {
|
||||
// pos 1: position in %
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
} // namespace emsesp
|
||||
@@ -816,8 +816,8 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
|
||||
|
||||
if (flags == EMS_DEVICE_FLAG_RC35) {
|
||||
print_value(shell, 2, F("Damped Outdoor temperature"), F_(degrees), Helpers::render_value(buffer, dampedoutdoortemp, 1));
|
||||
print_value(shell, 2, F("Tempsensor 1"), F_(degrees), Helpers::render_value(buffer, tempsensor1, 10));
|
||||
print_value(shell, 2, F("Tempsensor 2"), F_(degrees), Helpers::render_value(buffer, tempsensor2, 10));
|
||||
print_value(shell, 2, F("Temp sensor 1"), F_(degrees), Helpers::render_value(buffer, tempsensor1, 10));
|
||||
print_value(shell, 2, F("Temp sensor 2"), F_(degrees), Helpers::render_value(buffer, tempsensor2, 10));
|
||||
}
|
||||
if (flags == EMS_DEVICE_FLAG_RC30_1) {
|
||||
// settings parameters
|
||||
@@ -1042,7 +1042,7 @@ void Thermostat::process_RC300Set(std::shared_ptr<const Telegram> telegram) {
|
||||
// manual is position 10
|
||||
// comfort is position 2
|
||||
// I think auto is position 8?
|
||||
// actual setpoint taken from RC300Monitor (Michael 12.06.2020)
|
||||
// actual setpoint taken from RC300Monitor (Michael 12.06.2020)
|
||||
// telegram->read_value8(hc->setpoint_roomTemp, 8); // single byte conversion, value is * 2 - auto?
|
||||
// telegram->read_value8(hc->setpoint_roomTemp, 10); // single byte conversion, value is * 2 - manual
|
||||
|
||||
|
||||
@@ -46,21 +46,21 @@ class Thermostat : public EMSdevice {
|
||||
}
|
||||
~HeatingCircuit() = default;
|
||||
|
||||
int16_t setpoint_roomTemp = EMS_VALUE_SHORT_NOTSET;
|
||||
int16_t curr_roomTemp = EMS_VALUE_SHORT_NOTSET;
|
||||
uint8_t mode = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t mode_type = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t summer_mode = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t holiday_mode = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t daytemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t nighttemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t holidaytemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t heatingtype = EMS_VALUE_UINT_NOTSET; // type of heating: 1 radiator, 2 convectors, 3 floors, 4 room supply
|
||||
uint8_t circuitcalctemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t summertemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t nofrosttemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t designtemp = EMS_VALUE_UINT_NOTSET; // heatingcurve design temp at MinExtTemp
|
||||
int8_t offsettemp = EMS_VALUE_INT_NOTSET; // heatingcurve offest temp at roomtemp signed!
|
||||
int16_t setpoint_roomTemp = EMS_VALUE_SHORT_NOTSET;
|
||||
int16_t curr_roomTemp = EMS_VALUE_SHORT_NOTSET;
|
||||
uint8_t mode = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t mode_type = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t summer_mode = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t holiday_mode = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t daytemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t nighttemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t holidaytemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t heatingtype = EMS_VALUE_UINT_NOTSET; // type of heating: 1 radiator, 2 convectors, 3 floors, 4 room supply
|
||||
uint8_t circuitcalctemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t summertemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t nofrosttemp = EMS_VALUE_UINT_NOTSET;
|
||||
uint8_t designtemp = EMS_VALUE_UINT_NOTSET; // heatingcurve design temp at MinExtTemp
|
||||
int8_t offsettemp = EMS_VALUE_INT_NOTSET; // heatingcurve offest temp at roomtemp signed!
|
||||
|
||||
|
||||
uint8_t hc_num() const {
|
||||
|
||||
@@ -120,19 +120,20 @@ void EMSESP::show_emsbus(uuid::console::Shell & shell) {
|
||||
}
|
||||
|
||||
shell.printfln(F("EMS Bus info:"));
|
||||
shell.printfln(F(" Tx mode: %d"), Settings().ems_tx_mode());
|
||||
shell.printfln(F(" Bus protocol: %s"), EMSbus::is_ht3() ? F("HT3") : F("Buderus"));
|
||||
shell.printfln(F(" #telegrams received: %d"), rxservice_.telegram_count());
|
||||
shell.printfln(F(" #read requests sent: %d"), txservice_.telegram_read_count());
|
||||
shell.printfln(F(" #write requests sent: %d"), txservice_.telegram_write_count());
|
||||
shell.printfln(F(" #incomplete telegrams: %d (%d%%)"), rxservice_.telegram_error_count(), success_rate);
|
||||
shell.printfln(F(" #tx fails (after 3 retries): %d"), txservice_.telegram_fail_count());
|
||||
shell.printfln(F(" #corrupted telegrams: %d (%d%%)"), rxservice_.telegram_error_count(), success_rate);
|
||||
shell.printfln(F(" #tx fails (after %d retries): %d"), TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_fail_count());
|
||||
} else {
|
||||
shell.printfln(F("EMS Bus is disconnected"));
|
||||
shell.printfln(F("EMS Bus is disconnected."));
|
||||
}
|
||||
|
||||
shell.println();
|
||||
|
||||
// Rx
|
||||
// Rx queue
|
||||
auto rx_telegrams = rxservice_.queue();
|
||||
if (rx_telegrams.empty()) {
|
||||
shell.printfln(F("Rx Queue is empty"));
|
||||
@@ -145,7 +146,7 @@ void EMSESP::show_emsbus(uuid::console::Shell & shell) {
|
||||
|
||||
shell.println();
|
||||
|
||||
// Tx
|
||||
// Tx queue
|
||||
auto tx_telegrams = txservice_.queue();
|
||||
if (tx_telegrams.empty()) {
|
||||
shell.printfln(F("Tx Queue is empty"));
|
||||
@@ -393,9 +394,11 @@ void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
|
||||
// We also check for common telgram types, like the Version(0x02)
|
||||
// returns false if there are none found
|
||||
bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
|
||||
// if watching...
|
||||
if (watch() == 1) {
|
||||
if ((watch_id_ == WATCH_NONE) || (telegram->src == watch_id_) || (telegram->dest == watch_id_) || (telegram->type_id == watch_id_)) {
|
||||
LOG_INFO(pretty_telegram(telegram).c_str());
|
||||
LOG_NOTICE(pretty_telegram(telegram).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,28 +725,24 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) {
|
||||
};
|
||||
});
|
||||
|
||||
EMSESPShell::commands->add_command(
|
||||
ShellContext::EMS,
|
||||
CommandFlags::ADMIN,
|
||||
flash_string_vector{F_(set), F_(tx_mode)},
|
||||
flash_string_vector{F_(n_mandatory)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
uint8_t tx_mode = std::strtol(arguments[0].c_str(), nullptr, 10);
|
||||
if ((tx_mode > 0) && (tx_mode <= 30)) {
|
||||
Settings settings;
|
||||
settings.ems_tx_mode(tx_mode);
|
||||
settings.commit();
|
||||
shell.printfln(F_(tx_mode_fmt), settings.ems_tx_mode());
|
||||
// reset the UART
|
||||
EMSuart::stop();
|
||||
EMSuart::start(tx_mode);
|
||||
} else {
|
||||
shell.println(F("Must be 1 for EMS generic, 2 for EMS+, 3 for HT3, 4 for experimental"));
|
||||
}
|
||||
},
|
||||
[](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments __attribute__((unused))) -> const std::vector<std::string> {
|
||||
return std::vector<std::string>{read_flash_string(F("1")), read_flash_string(F("2")), read_flash_string(F("3")), read_flash_string(F("4"))};
|
||||
});
|
||||
EMSESPShell::commands->add_command(ShellContext::EMS,
|
||||
CommandFlags::ADMIN,
|
||||
flash_string_vector{F_(set), F_(tx_mode)},
|
||||
flash_string_vector{F_(n_mandatory)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
uint8_t tx_mode = std::strtol(arguments[0].c_str(), nullptr, 10);
|
||||
if ((tx_mode > 0) && (tx_mode <= 30)) {
|
||||
Settings settings;
|
||||
settings.ems_tx_mode(tx_mode);
|
||||
settings.commit();
|
||||
shell.printfln(F_(tx_mode_fmt), settings.ems_tx_mode());
|
||||
// reset the UART
|
||||
EMSuart::stop();
|
||||
EMSuart::start(tx_mode);
|
||||
} else {
|
||||
shell.println(F("Must be 1 for EMS generic, 2 for EMS+, 3 for HT3, 4 for experimental"));
|
||||
}
|
||||
});
|
||||
|
||||
EMSESPShell::commands->add_command(
|
||||
ShellContext::EMS,
|
||||
@@ -858,7 +857,15 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) {
|
||||
uint8_t watch = emsesp::EMSESP::watch();
|
||||
if (watch == 0) {
|
||||
shell.printfln(F("Watch is off"));
|
||||
} else if (watch == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if logging is off, the watch won't show anything, show force it back to INFO
|
||||
if (!logger_.enabled(Level::NOTICE)) {
|
||||
shell.log_level(Level::NOTICE);
|
||||
}
|
||||
|
||||
if (watch == 1) {
|
||||
shell.printfln(F("Watching incoming telegrams, displayed in decoded format"));
|
||||
} else {
|
||||
shell.printfln(F("Watching incoming telegrams, displayed as raw bytes"));
|
||||
|
||||
@@ -29,7 +29,7 @@ class Helpers {
|
||||
static char * hextoa(char * result, const uint8_t value);
|
||||
static std::string data_to_hex(const uint8_t * data, const uint8_t length);
|
||||
|
||||
static char * render_value(char * result, const float value, const uint8_t format); // format is precision
|
||||
static char * render_value(char * result, const float value, const uint8_t format); // format is the precision
|
||||
static char * render_value(char * result, const uint8_t value, const uint8_t format);
|
||||
static char * render_value(char * result, const int8_t value, const uint8_t format);
|
||||
static char * render_value(char * result, const uint16_t value, const uint8_t format);
|
||||
|
||||
@@ -69,9 +69,9 @@ void Roomctrl::check(const uint8_t addr, const uint8_t * data) {
|
||||
if (remotetemp[hc_] == EMS_VALUE_SHORT_NOTSET) {
|
||||
return;
|
||||
}
|
||||
// reply to writes with write nack byte
|
||||
if(addr & 0x80) { // it's a write to us
|
||||
nack_write(); // we don't accept writes.
|
||||
// reply to writes with write nack byte
|
||||
if (addr & 0x80) { // it's a write to us
|
||||
nack_write(); // we don't accept writes.
|
||||
return;
|
||||
}
|
||||
// for now we only reply to version and remote temperature
|
||||
|
||||
@@ -37,7 +37,6 @@ class Roomctrl {
|
||||
static void unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset);
|
||||
static void temperature(uint8_t addr, uint8_t dst);
|
||||
static void nack_write();
|
||||
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -72,8 +72,7 @@ void System::mqtt_commands(const char * message) {
|
||||
if (doc["send"] != nullptr) {
|
||||
const char * data = doc["send"];
|
||||
EMSESP::send_raw_telegram(data);
|
||||
LOG_INFO(F("Sending raw: %s"),data);
|
||||
|
||||
LOG_INFO(F("Sending raw: %s"), data);
|
||||
}
|
||||
|
||||
#if defined(ESP8266)
|
||||
@@ -87,39 +86,60 @@ void System::mqtt_commands(const char * message) {
|
||||
const uint8_t d2_ = 21;
|
||||
const uint8_t d3_ = 17;
|
||||
#endif
|
||||
if(doc["D0"] != nullptr) {
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
|
||||
if (doc["D0"] != nullptr) {
|
||||
const int8_t set = doc["D0"];
|
||||
pinMode(d0_, OUTPUT);
|
||||
if (set == 1) digitalWrite(d0_, HIGH);
|
||||
else if (set == 0) digitalWrite(d0_, LOW);
|
||||
LOG_INFO(F("Port D0 set to %d"),set);
|
||||
if (set == 1) {
|
||||
digitalWrite(d0_, HIGH);
|
||||
} else if (set == 0) {
|
||||
digitalWrite(d0_, LOW);
|
||||
}
|
||||
LOG_INFO(F("Port D0 set to %d"), set);
|
||||
}
|
||||
if(doc["D1"] != nullptr) {
|
||||
|
||||
if (doc["D1"] != nullptr) {
|
||||
const int8_t set = doc["D1"];
|
||||
pinMode(d1_, OUTPUT);
|
||||
if (set == 1) digitalWrite(d1_, HIGH);
|
||||
else if (set == 0) digitalWrite(d1_, LOW);
|
||||
LOG_INFO(F("Port D1 set to %d"),set);
|
||||
if (set == 1) {
|
||||
digitalWrite(d1_, HIGH);
|
||||
} else if (set == 0) {
|
||||
digitalWrite(d1_, LOW);
|
||||
}
|
||||
LOG_INFO(F("Port D1 set to %d"), set);
|
||||
}
|
||||
if(doc["D2"] != nullptr) {
|
||||
|
||||
if (doc["D2"] != nullptr) {
|
||||
const int8_t set = doc["D2"];
|
||||
pinMode(d2_, OUTPUT);
|
||||
if (set == 1) digitalWrite(d2_, HIGH);
|
||||
else if (set == 0) digitalWrite(d2_, LOW);
|
||||
LOG_INFO(F("Port D2 set to %d"),set);
|
||||
if (set == 1) {
|
||||
digitalWrite(d2_, HIGH);
|
||||
} else if (set == 0) {
|
||||
digitalWrite(d2_, LOW);
|
||||
}
|
||||
LOG_INFO(F("Port D2 set to %d"), set);
|
||||
}
|
||||
if(doc["D3"] != nullptr) {
|
||||
|
||||
if (doc["D3"] != nullptr) {
|
||||
const int8_t set = doc["D3"];
|
||||
pinMode(d3_, OUTPUT);
|
||||
if (set == 1) digitalWrite(d3_, HIGH);
|
||||
else if (set == 0) digitalWrite(d3_, LOW);
|
||||
LOG_INFO(F("Port D3 set to %d"),set);
|
||||
if (set == 1) {
|
||||
digitalWrite(d3_, HIGH);
|
||||
} else if (set == 0) {
|
||||
digitalWrite(d3_, LOW);
|
||||
}
|
||||
LOG_INFO(F("Port D3 set to %d"), set);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const char * command = doc["cmd"];
|
||||
if (command == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// send raw command
|
||||
if (strcmp(command, "send") == 0) {
|
||||
const char * data = doc["data"];
|
||||
@@ -127,7 +147,7 @@ void System::mqtt_commands(const char * message) {
|
||||
return;
|
||||
}
|
||||
EMSESP::send_raw_telegram(data);
|
||||
LOG_INFO(F("Sending raw: %s"),data);
|
||||
LOG_INFO(F("Sending raw: %s"), data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,11 +304,11 @@ void RxService::add(uint8_t * data, uint8_t length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if we're in "trace" and "raw" print out actual telegram as bytes to the console
|
||||
// if we're watching and "raw" print out actual telegram as bytes to the console
|
||||
if (EMSESP::watch() == 2) {
|
||||
uint16_t trace_watch_id = EMSESP::watch_id();
|
||||
if ((trace_watch_id == WATCH_NONE) || (src == trace_watch_id) || (dest == trace_watch_id) || (type_id == trace_watch_id)) {
|
||||
LOG_INFO(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str());
|
||||
LOG_NOTICE(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,6 +461,20 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) {
|
||||
|
||||
length++; // add one since we want to now include the CRC
|
||||
|
||||
#if defined(ESP32)
|
||||
// This logging causes errors with timer based tx-modes on esp8266!
|
||||
LOG_DEBUG(F("Sending %s Tx [#%d], telegram: %s"),
|
||||
(telegram->operation == Telegram::Operation::TX_WRITE) ? F("write") : F("read"),
|
||||
tx_telegram.id_,
|
||||
telegram->to_string(telegram_raw, length).c_str());
|
||||
|
||||
#ifdef EMSESP_DEBUG
|
||||
// if watching in 'raw' mode
|
||||
if (EMSESP::watch() == 2) {
|
||||
LOG_NOTICE(F("[DEBUG] Tx: %s"), Helpers::data_to_hex(telegram_raw, length).c_str());
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
// send the telegram to the UART Tx
|
||||
uint16_t status = EMSuart::transmit(telegram_raw, length);
|
||||
|
||||
@@ -469,11 +483,6 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) {
|
||||
increment_telegram_fail_count(); // another Tx fail
|
||||
tx_waiting(false); // nothing send, tx not in wait state
|
||||
return;
|
||||
// } else {
|
||||
// LOG_DEBUG(F("Send %s Tx [#%d], telegram: %s"),
|
||||
// (telegram->operation == Telegram::Operation::TX_WRITE) ? F("write") : F("read"),
|
||||
// tx_telegram.id_,
|
||||
// telegram->to_string(telegram_raw, length).c_str());
|
||||
}
|
||||
|
||||
tx_waiting(true); // tx now in a wait state
|
||||
@@ -495,12 +504,9 @@ void TxService::send_telegram(const uint8_t * data, const uint8_t length) {
|
||||
// send the telegram to the UART Tx
|
||||
uint16_t status = EMSuart::transmit(telegram_raw, length);
|
||||
|
||||
|
||||
if (status == EMS_TX_STATUS_ERR) {
|
||||
LOG_ERROR(F("Failed to transmit Tx via UART."));
|
||||
increment_telegram_fail_count(); // another Tx fail
|
||||
// } else {
|
||||
// LOG_DEBUG(F("Send Raw telegram: %s (length=%d)"), Helpers::data_to_hex(telegram_raw, length).c_str(), length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,7 +616,6 @@ void TxService::remember_tx(const uint8_t * data, const uint8_t length) {
|
||||
if (ems_mask() != EMS_MASK_UNSET) {
|
||||
telegram_last_[0] ^= ems_mask();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// add last Tx to tx queue and increment count
|
||||
|
||||
@@ -173,7 +173,8 @@ void EMSuart::restart() {
|
||||
* Sends a 1-byte poll, ending with a <BRK>
|
||||
*/
|
||||
void EMSuart::send_poll(uint8_t data) {
|
||||
if (tx_mode_ > 5 || tx_mode_ < 4) {
|
||||
if (tx_mode_ > 5 || tx_mode_ < 4) { // modes 1, 2, 3 also here
|
||||
// if (tx_mode_ > 5) {
|
||||
EMS_UART.fifo.rw_byte = data;
|
||||
emsTxBufIdx = 0;
|
||||
emsTxBufLen = 1;
|
||||
@@ -186,13 +187,19 @@ void EMSuart::send_poll(uint8_t data) {
|
||||
EMS_UART.fifo.rw_byte = data;
|
||||
delayMicroseconds(EMSUART_TX_WAIT_HT3);
|
||||
EMS_UART.conf0.txd_brk = 1; // <brk>
|
||||
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
|
||||
// EMS_UART.conf0.txd_brk = 0;
|
||||
} else if (tx_mode_ == EMS_TXMODE_EMSPLUS) {
|
||||
EMS_UART.fifo.rw_byte = data;
|
||||
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
|
||||
EMS_UART.conf0.txd_brk = 1; // <brk>
|
||||
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
|
||||
// EMS_UART.conf0.txd_brk = 0;
|
||||
} else {
|
||||
EMS_UART.fifo.rw_byte = data;
|
||||
delayMicroseconds(EMSUART_TX_WAIT_BRK);
|
||||
volatile uint8_t _usrxc = EMS_UART.status.rxfifo_cnt;
|
||||
EMS_UART.fifo.rw_byte = data;
|
||||
while (EMS_UART.status.rxfifo_cnt == _usrxc) {
|
||||
}
|
||||
EMS_UART.conf0.txd_brk = 1; // <brk>
|
||||
}
|
||||
}
|
||||
@@ -206,7 +213,8 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
if (len == 0 || len >= EMS_MAXBUFFERSIZE) {
|
||||
return EMS_TX_STATUS_ERR;
|
||||
}
|
||||
if (tx_mode_ > 5 || tx_mode_ < 4) { // timer controlled modes
|
||||
if (tx_mode_ > 5 || tx_mode_ < 4) { // timer controlled modes, also modes 1, 2, 3 because delays not working
|
||||
// if (tx_mode_ > 5) { // timer controlled modes
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
emsTxBuf[i] = buf[i];
|
||||
}
|
||||
@@ -230,6 +238,8 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
|
||||
}
|
||||
EMS_UART.conf0.txd_brk = 1; // <brk> after send, cleard by hardware after send
|
||||
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
|
||||
// EMS_UART.conf0.txd_brk = 0;
|
||||
return EMS_TX_STATUS_OK;
|
||||
}
|
||||
if (tx_mode_ == EMS_TXMODE_HT3) { // HT3 with 7 bittimes delay
|
||||
@@ -238,6 +248,8 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
delayMicroseconds(EMSUART_TX_WAIT_HT3);
|
||||
}
|
||||
EMS_UART.conf0.txd_brk = 1; // <brk> after send, cleard by hardware after send
|
||||
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
|
||||
// EMS_UART.conf0.txd_brk = 0;
|
||||
return EMS_TX_STATUS_OK;
|
||||
}
|
||||
// mode 1
|
||||
@@ -249,10 +261,12 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
EMS_UART.fifo.rw_byte = buf[i]; // send each Tx byte
|
||||
// wait for echo
|
||||
while (EMS_UART.status.rxfifo_cnt == _usrxc) {
|
||||
delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
|
||||
// delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
|
||||
}
|
||||
}
|
||||
EMS_UART.conf0.txd_brk = 1; // <brk> after send, cleard by hardware after send
|
||||
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
|
||||
// EMS_UART.conf0.txd_brk = 0;
|
||||
return EMS_TX_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,17 +78,16 @@ class EMSuart {
|
||||
EMSuart() = default;
|
||||
~EMSuart() = default;
|
||||
|
||||
static void start(uint8_t tx_mode);
|
||||
static void send_poll(uint8_t data);
|
||||
static void stop();
|
||||
static void restart();
|
||||
static uint16_t transmit(uint8_t * buf, uint8_t len);
|
||||
static void start(uint8_t tx_mode);
|
||||
static void send_poll(uint8_t data);
|
||||
static void stop();
|
||||
static void restart();
|
||||
static uint16_t transmit(uint8_t * buf, uint8_t len);
|
||||
|
||||
private:
|
||||
static void emsuart_recvTask(void * para);
|
||||
static void IRAM_ATTR emsuart_rx_intr_handler(void * para);
|
||||
static void IRAM_ATTR emsuart_tx_timer_intr_handler();
|
||||
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -272,9 +272,16 @@ void EMSuart::send_poll(uint8_t data) {
|
||||
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
|
||||
tx_brk(); // send <BRK>
|
||||
} else { // EMS1.0
|
||||
USF(EMSUART_UART) = data;
|
||||
delayMicroseconds(EMSUART_TX_WAIT_BRK);
|
||||
tx_brk(); // send <BRK>
|
||||
ETS_UART_INTR_DISABLE();
|
||||
volatile uint8_t _usrxc = (USS(EMSUART_UART) >> USRXC) & 0xFF;
|
||||
USF(EMSUART_UART) = data;
|
||||
while (((USS(EMSUART_UART) >> USRXC) & 0xFF) == _usrxc) {
|
||||
}
|
||||
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
|
||||
while (!(USIR(EMSUART_UART) & (1 << UIBD))) {
|
||||
}
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear <BRK>
|
||||
ETS_UART_INTR_ENABLE();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "2.0.0a18"
|
||||
#define EMSESP_APP_VERSION "2.0.0a19"
|
||||
|
||||
Reference in New Issue
Block a user