This commit is contained in:
MichaelDvP
2020-06-15 18:57:09 +02:00
18 changed files with 176 additions and 115 deletions

View File

@@ -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. - 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: ### Setting up for the first time:
- connect the ESP8266/ESP32 via USB and enter via the serial/com port with baud 115200 - 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. - reboot and next time use the Telnet via WiFi to connect as the serial mode will be disabled.
### Debugging ### 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 - Error messages are shown in the color red
- type `show` from the main root to see if any data has come in - 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 - 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 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. - 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.
# List of console commands
# Full Console Commands
``` ```
common commands available in all contexts: common commands available in all contexts:

View File

@@ -56,7 +56,7 @@ void EMSuart::send_poll(uint8_t data) {
* buf contains the CRC and len is #bytes including the CRC * buf contains the CRC and len is #bytes including the CRC
* returns code, 0=success, 1=brk error, 2=watchdog timeout * 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) { if (len == 0) {
return EMS_TX_STATUS_OK; // nothing to send return EMS_TX_STATUS_OK; // nothing to send
} }

View File

@@ -23,11 +23,8 @@
namespace emsesp { namespace emsesp {
typedef enum { #define EMS_TX_STATUS_ERR 0
EMS_TX_STATUS_OK = 1, #define EMS_TX_STATUS_OK 1
EMS_TX_WTD_TIMEOUT, // watchdog timeout during send
EMS_TX_BRK_DETECT, // incoming BRK during Tx
} EMSUART_STATUS;
class EMSuart { class EMSuart {
public: public:
@@ -38,7 +35,7 @@ class EMSuart {
static void stop(); static void stop();
static void restart(); static void restart();
static void send_poll(uint8_t data); static void send_poll(uint8_t data);
static EMSUART_STATUS transmit(uint8_t * buf, uint8_t len); static uint16_t transmit(uint8_t * buf, uint8_t len);
private: private:
static char * hextoa(char * result, const uint8_t value); static char * hextoa(char * result, const uint8_t value);

View File

@@ -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(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 MAKE_PSTR_WORD(string_name) MAKE_PSTR(string_name, #string_name)
#define F_(string_name) FPSTR(__pstr__##string_name) #define F_(string_name) FPSTR(__pstr__##string_name)
#define NO_ARGUMENTS std::vector<std::string>{}
// clang-format on // clang-format on

View File

@@ -162,6 +162,9 @@ void Mixing::process_MMStatusMessage(std::shared_ptr<const Telegram> telegram) {
telegram->read_value(flowSetTemp_, 0); telegram->read_value(flowSetTemp_, 0);
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
// Mixing on a MM10 - 0xAA // Mixing on a MM10 - 0xAA
// e.g. Thermostat -> Mixing Module, type 0xAA, telegram: 10 21 AA 00 FF 0C 0A 11 0A 32 xx // 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) { 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 % // pos 1: position in %
} }
#pragma GCC diagnostic pop
} // namespace emsesp } // namespace emsesp

View File

@@ -816,8 +816,8 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
if (flags == EMS_DEVICE_FLAG_RC35) { 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("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("Temp sensor 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 2"), F_(degrees), Helpers::render_value(buffer, tempsensor2, 10));
} }
if (flags == EMS_DEVICE_FLAG_RC30_1) { if (flags == EMS_DEVICE_FLAG_RC30_1) {
// settings parameters // settings parameters

View File

@@ -120,19 +120,20 @@ void EMSESP::show_emsbus(uuid::console::Shell & shell) {
} }
shell.printfln(F("EMS Bus info:")); 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(" Bus protocol: %s"), EMSbus::is_ht3() ? F("HT3") : F("Buderus"));
shell.printfln(F(" #telegrams received: %d"), rxservice_.telegram_count()); shell.printfln(F(" #telegrams received: %d"), rxservice_.telegram_count());
shell.printfln(F(" #read requests sent: %d"), txservice_.telegram_read_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(" #write requests sent: %d"), txservice_.telegram_write_count());
shell.printfln(F(" #incomplete telegrams: %d (%d%%)"), rxservice_.telegram_error_count(), success_rate); shell.printfln(F(" #corrupted 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(" #tx fails (after %d retries): %d"), TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_fail_count());
} else { } else {
shell.printfln(F("EMS Bus is disconnected")); shell.printfln(F("EMS Bus is disconnected."));
} }
shell.println(); shell.println();
// Rx // Rx queue
auto rx_telegrams = rxservice_.queue(); auto rx_telegrams = rxservice_.queue();
if (rx_telegrams.empty()) { if (rx_telegrams.empty()) {
shell.printfln(F("Rx Queue is empty")); shell.printfln(F("Rx Queue is empty"));
@@ -145,7 +146,7 @@ void EMSESP::show_emsbus(uuid::console::Shell & shell) {
shell.println(); shell.println();
// Tx // Tx queue
auto tx_telegrams = txservice_.queue(); auto tx_telegrams = txservice_.queue();
if (tx_telegrams.empty()) { if (tx_telegrams.empty()) {
shell.printfln(F("Tx Queue is 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) // We also check for common telgram types, like the Version(0x02)
// returns false if there are none found // returns false if there are none found
bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) { bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
// if watching...
if (watch() == 1) { if (watch() == 1) {
if ((watch_id_ == WATCH_NONE) || (telegram->src == watch_id_) || (telegram->dest == watch_id_) || (telegram->type_id == watch_id_)) { 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,8 +725,7 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) {
}; };
}); });
EMSESPShell::commands->add_command( EMSESPShell::commands->add_command(ShellContext::EMS,
ShellContext::EMS,
CommandFlags::ADMIN, CommandFlags::ADMIN,
flash_string_vector{F_(set), F_(tx_mode)}, flash_string_vector{F_(set), F_(tx_mode)},
flash_string_vector{F_(n_mandatory)}, flash_string_vector{F_(n_mandatory)},
@@ -740,9 +742,6 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) {
} else { } else {
shell.println(F("Must be 1 for EMS generic, 2 for EMS+, 3 for HT3, 4 for experimental")); 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( EMSESPShell::commands->add_command(
@@ -858,7 +857,15 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) {
uint8_t watch = emsesp::EMSESP::watch(); uint8_t watch = emsesp::EMSESP::watch();
if (watch == 0) { if (watch == 0) {
shell.printfln(F("Watch is off")); 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")); shell.printfln(F("Watching incoming telegrams, displayed in decoded format"));
} else { } else {
shell.printfln(F("Watching incoming telegrams, displayed as raw bytes")); shell.printfln(F("Watching incoming telegrams, displayed as raw bytes"));

View File

@@ -29,7 +29,7 @@ class Helpers {
static char * hextoa(char * result, const uint8_t value); static char * hextoa(char * result, const uint8_t value);
static std::string data_to_hex(const uint8_t * data, const uint8_t length); 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 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 int8_t value, const uint8_t format);
static char * render_value(char * result, const uint16_t value, const uint8_t format); static char * render_value(char * result, const uint16_t value, const uint8_t format);

View File

@@ -70,7 +70,7 @@ void Roomctrl::check(const uint8_t addr, const uint8_t * data) {
return; return;
} }
// reply to writes with write nack byte // reply to writes with write nack byte
if(addr & 0x80) { // it's a write to us if (addr & 0x80) { // it's a write to us
nack_write(); // we don't accept writes. nack_write(); // we don't accept writes.
return; return;
} }

View File

@@ -37,7 +37,6 @@ class Roomctrl {
static void unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset); 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 temperature(uint8_t addr, uint8_t dst);
static void nack_write(); static void nack_write();
}; };
} // namespace emsesp } // namespace emsesp

View File

@@ -72,8 +72,7 @@ void System::mqtt_commands(const char * message) {
if (doc["send"] != nullptr) { if (doc["send"] != nullptr) {
const char * data = doc["send"]; const char * data = doc["send"];
EMSESP::send_raw_telegram(data); EMSESP::send_raw_telegram(data);
LOG_INFO(F("Sending raw: %s"),data); LOG_INFO(F("Sending raw: %s"), data);
} }
#if defined(ESP8266) #if defined(ESP8266)
@@ -87,39 +86,60 @@ void System::mqtt_commands(const char * message) {
const uint8_t d2_ = 21; const uint8_t d2_ = 21;
const uint8_t d3_ = 17; const uint8_t d3_ = 17;
#endif #endif
if(doc["D0"] != nullptr) {
#ifndef EMSESP_STANDALONE
if (doc["D0"] != nullptr) {
const int8_t set = doc["D0"]; const int8_t set = doc["D0"];
pinMode(d0_, OUTPUT); pinMode(d0_, OUTPUT);
if (set == 1) digitalWrite(d0_, HIGH); if (set == 1) {
else if (set == 0) digitalWrite(d0_, LOW); digitalWrite(d0_, HIGH);
LOG_INFO(F("Port D0 set to %d"),set); } else if (set == 0) {
digitalWrite(d0_, LOW);
} }
if(doc["D1"] != nullptr) { LOG_INFO(F("Port D0 set to %d"), set);
}
if (doc["D1"] != nullptr) {
const int8_t set = doc["D1"]; const int8_t set = doc["D1"];
pinMode(d1_, OUTPUT); pinMode(d1_, OUTPUT);
if (set == 1) digitalWrite(d1_, HIGH); if (set == 1) {
else if (set == 0) digitalWrite(d1_, LOW); digitalWrite(d1_, HIGH);
LOG_INFO(F("Port D1 set to %d"),set); } else if (set == 0) {
digitalWrite(d1_, LOW);
} }
if(doc["D2"] != nullptr) { LOG_INFO(F("Port D1 set to %d"), set);
}
if (doc["D2"] != nullptr) {
const int8_t set = doc["D2"]; const int8_t set = doc["D2"];
pinMode(d2_, OUTPUT); pinMode(d2_, OUTPUT);
if (set == 1) digitalWrite(d2_, HIGH); if (set == 1) {
else if (set == 0) digitalWrite(d2_, LOW); digitalWrite(d2_, HIGH);
LOG_INFO(F("Port D2 set to %d"),set); } else if (set == 0) {
digitalWrite(d2_, LOW);
} }
if(doc["D3"] != nullptr) { LOG_INFO(F("Port D2 set to %d"), set);
}
if (doc["D3"] != nullptr) {
const int8_t set = doc["D3"]; const int8_t set = doc["D3"];
pinMode(d3_, OUTPUT); pinMode(d3_, OUTPUT);
if (set == 1) digitalWrite(d3_, HIGH); if (set == 1) {
else if (set == 0) digitalWrite(d3_, LOW); digitalWrite(d3_, HIGH);
LOG_INFO(F("Port D3 set to %d"),set); } else if (set == 0) {
digitalWrite(d3_, LOW);
} }
LOG_INFO(F("Port D3 set to %d"), set);
}
#endif
const char * command = doc["cmd"]; const char * command = doc["cmd"];
if (command == nullptr) { if (command == nullptr) {
return; return;
} }
// send raw command // send raw command
if (strcmp(command, "send") == 0) { if (strcmp(command, "send") == 0) {
const char * data = doc["data"]; const char * data = doc["data"];
@@ -127,7 +147,7 @@ void System::mqtt_commands(const char * message) {
return; return;
} }
EMSESP::send_raw_telegram(data); EMSESP::send_raw_telegram(data);
LOG_INFO(F("Sending raw: %s"),data); LOG_INFO(F("Sending raw: %s"), data);
return; return;
} }
} }

View File

@@ -304,11 +304,11 @@ void RxService::add(uint8_t * data, uint8_t length) {
return; 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) { if (EMSESP::watch() == 2) {
uint16_t trace_watch_id = EMSESP::watch_id(); 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)) { 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 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 // send the telegram to the UART Tx
uint16_t status = EMSuart::transmit(telegram_raw, length); 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 increment_telegram_fail_count(); // another Tx fail
tx_waiting(false); // nothing send, tx not in wait state tx_waiting(false); // nothing send, tx not in wait state
return; 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 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 // send the telegram to the UART Tx
uint16_t status = EMSuart::transmit(telegram_raw, length); uint16_t status = EMSuart::transmit(telegram_raw, length);
if (status == EMS_TX_STATUS_ERR) { if (status == EMS_TX_STATUS_ERR) {
LOG_ERROR(F("Failed to transmit Tx via UART.")); LOG_ERROR(F("Failed to transmit Tx via UART."));
increment_telegram_fail_count(); // another Tx fail 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) { if (ems_mask() != EMS_MASK_UNSET) {
telegram_last_[0] ^= ems_mask(); telegram_last_[0] ^= ems_mask();
} }
} }
// add last Tx to tx queue and increment count // add last Tx to tx queue and increment count

View File

@@ -173,7 +173,8 @@ void EMSuart::restart() {
* Sends a 1-byte poll, ending with a <BRK> * Sends a 1-byte poll, ending with a <BRK>
*/ */
void EMSuart::send_poll(uint8_t data) { 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; EMS_UART.fifo.rw_byte = data;
emsTxBufIdx = 0; emsTxBufIdx = 0;
emsTxBufLen = 1; emsTxBufLen = 1;
@@ -186,13 +187,19 @@ void EMSuart::send_poll(uint8_t data) {
EMS_UART.fifo.rw_byte = data; EMS_UART.fifo.rw_byte = data;
delayMicroseconds(EMSUART_TX_WAIT_HT3); delayMicroseconds(EMSUART_TX_WAIT_HT3);
EMS_UART.conf0.txd_brk = 1; // <brk> 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) { } else if (tx_mode_ == EMS_TXMODE_EMSPLUS) {
EMS_UART.fifo.rw_byte = data; EMS_UART.fifo.rw_byte = data;
delayMicroseconds(EMSUART_TX_WAIT_PLUS); delayMicroseconds(EMSUART_TX_WAIT_PLUS);
EMS_UART.conf0.txd_brk = 1; // <brk> EMS_UART.conf0.txd_brk = 1; // <brk>
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
// EMS_UART.conf0.txd_brk = 0;
} else { } else {
volatile uint8_t _usrxc = EMS_UART.status.rxfifo_cnt;
EMS_UART.fifo.rw_byte = data; EMS_UART.fifo.rw_byte = data;
delayMicroseconds(EMSUART_TX_WAIT_BRK); while (EMS_UART.status.rxfifo_cnt == _usrxc) {
}
EMS_UART.conf0.txd_brk = 1; // <brk> 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) { if (len == 0 || len >= EMS_MAXBUFFERSIZE) {
return EMS_TX_STATUS_ERR; 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++) { for (uint8_t i = 0; i < len; i++) {
emsTxBuf[i] = buf[i]; emsTxBuf[i] = buf[i];
} }
@@ -230,6 +238,8 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
delayMicroseconds(EMSUART_TX_WAIT_PLUS); delayMicroseconds(EMSUART_TX_WAIT_PLUS);
} }
EMS_UART.conf0.txd_brk = 1; // <brk> after send, cleard by hardware after send 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; return EMS_TX_STATUS_OK;
} }
if (tx_mode_ == EMS_TXMODE_HT3) { // HT3 with 7 bittimes delay 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); delayMicroseconds(EMSUART_TX_WAIT_HT3);
} }
EMS_UART.conf0.txd_brk = 1; // <brk> after send, cleard by hardware after send 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; return EMS_TX_STATUS_OK;
} }
// mode 1 // 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 EMS_UART.fifo.rw_byte = buf[i]; // send each Tx byte
// wait for echo // wait for echo
while (EMS_UART.status.rxfifo_cnt == _usrxc) { 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 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; return EMS_TX_STATUS_OK;
} }

View File

@@ -88,7 +88,6 @@ class EMSuart {
static void emsuart_recvTask(void * para); static void emsuart_recvTask(void * para);
static void IRAM_ATTR emsuart_rx_intr_handler(void * para); static void IRAM_ATTR emsuart_rx_intr_handler(void * para);
static void IRAM_ATTR emsuart_tx_timer_intr_handler(); static void IRAM_ATTR emsuart_tx_timer_intr_handler();
}; };
} // namespace emsesp } // namespace emsesp

View File

@@ -272,9 +272,16 @@ void EMSuart::send_poll(uint8_t data) {
delayMicroseconds(EMSUART_TX_WAIT_PLUS); delayMicroseconds(EMSUART_TX_WAIT_PLUS);
tx_brk(); // send <BRK> tx_brk(); // send <BRK>
} else { // EMS1.0 } else { // EMS1.0
ETS_UART_INTR_DISABLE();
volatile uint8_t _usrxc = (USS(EMSUART_UART) >> USRXC) & 0xFF;
USF(EMSUART_UART) = data; USF(EMSUART_UART) = data;
delayMicroseconds(EMSUART_TX_WAIT_BRK); while (((USS(EMSUART_UART) >> USRXC) & 0xFF) == _usrxc) {
tx_brk(); // send <BRK> }
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
while (!(USIR(EMSUART_UART) & (1 << UIBD))) {
}
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear <BRK>
ETS_UART_INTR_ENABLE();
} }
} }

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "2.0.0a18" #define EMSESP_APP_VERSION "2.0.0a19"