mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
uart and some small fixes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -19,3 +19,4 @@ emsesp
|
||||
doc/github.txt
|
||||
doc/test_data.txt
|
||||
|
||||
/src/uart/uart_proddy.txt
|
||||
|
||||
@@ -49,7 +49,7 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const
|
||||
LOG_DEBUG(F("Registering new Boiler with device ID 0x%02X"), device_id);
|
||||
|
||||
// the telegram handlers...
|
||||
register_telegram_type(0x18, F("UBAMonitorFast"), true, std::bind(&Boiler::process_UBAMonitorFast, this, _1));
|
||||
register_telegram_type(0x18, F("UBAMonitorFast"), false, std::bind(&Boiler::process_UBAMonitorFast, this, _1));
|
||||
register_telegram_type(0x19, F("UBAMonitorSlow"), true, std::bind(&Boiler::process_UBAMonitorSlow, this, _1));
|
||||
register_telegram_type(0x34, F("UBAMonitorWW"), false, std::bind(&Boiler::process_UBAMonitorWW, this, _1));
|
||||
register_telegram_type(0x1C, F("UBAMaintenanceStatus"), false, std::bind(&Boiler::process_UBAMaintenanceStatus, this, _1));
|
||||
@@ -61,12 +61,12 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const
|
||||
register_telegram_type(0x16, F("UBAParameters"), true, std::bind(&Boiler::process_UBAParameters, this, _1));
|
||||
register_telegram_type(0x1A, F("UBASetPoints"), false, std::bind(&Boiler::process_UBASetPoints, this, _1));
|
||||
register_telegram_type(0xD1, F("UBAOutdoorTemp"), false, std::bind(&Boiler::process_UBAOutdoorTemp, this, _1));
|
||||
register_telegram_type(0xE4, F("UBAMonitorFastPlus"), true, std::bind(&Boiler::process_UBAMonitorFastPlus, this, _1));
|
||||
register_telegram_type(0xE5, F("UBAMonitorSlowPlus"), true, std::bind(&Boiler::process_UBAMonitorSlowPlus, this, _1));
|
||||
register_telegram_type(0xE4, F("UBAMonitorFastPlus"), false, std::bind(&Boiler::process_UBAMonitorFastPlus, this, _1));
|
||||
register_telegram_type(0xE5, F("UBAMonitorSlowPlus"), false, std::bind(&Boiler::process_UBAMonitorSlowPlus, this, _1));
|
||||
|
||||
register_telegram_type(0xE9, F("UBADHWStatus"), false, std::bind(&Boiler::process_UBADHWStatus, this, _1));
|
||||
register_telegram_type(0xE3, F("HeatPumpMonitor1"), true, std::bind(&Boiler::process_HPMonitor1, this, _1));
|
||||
register_telegram_type(0xE5, F("HeatPumpMonitor2"), true, std::bind(&Boiler::process_HPMonitor2, this, _1));
|
||||
register_telegram_type(0xE3, F("HeatPumpMonitor1"), false, std::bind(&Boiler::process_HPMonitor1, this, _1));
|
||||
register_telegram_type(0xE5, F("HeatPumpMonitor2"), false, std::bind(&Boiler::process_HPMonitor2, this, _1));
|
||||
|
||||
// MQTT callbacks
|
||||
register_mqtt_topic("boiler_cmd", std::bind(&Boiler::boiler_cmd, this, _1));
|
||||
@@ -190,14 +190,17 @@ void Boiler::publish_values() {
|
||||
doc["pumpMod"] = pumpMod_;
|
||||
}
|
||||
if (wWCircPump_ != EMS_VALUE_BOOL_NOTSET) {
|
||||
doc["wWCircPump"] = wWCircPump_;
|
||||
doc["wWCircPump"] = Helpers::render_value(s, wWCircPump_, EMS_VALUE_BOOL);
|
||||
}
|
||||
if (wWCircPumpType_ != EMS_VALUE_BOOL_NOTSET) {
|
||||
doc["wWCiPuType"] = wWCircPumpType_;
|
||||
doc["wWCiPuType"] = wWCircPumpType_ ? "valve" : "pump";
|
||||
}
|
||||
if (wWCircPumpMode_ != EMS_VALUE_UINT_NOTSET) {
|
||||
doc["wWCiPuMode"] = wWCircPumpMode_;
|
||||
}
|
||||
if (wWCirc_ != EMS_VALUE_BOOL_NOTSET) {
|
||||
doc["wWCirc"] = Helpers::render_value(s, wWCirc_, EMS_VALUE_BOOL);
|
||||
}
|
||||
if (extTemp_ != EMS_VALUE_SHORT_NOTSET) {
|
||||
doc["outdoorTemp"] = (float)extTemp_ / 10;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
|
||||
// Boilers - 0x08
|
||||
{ 72, DeviceType::BOILER, F("GB125/MC10"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
|
||||
{115, DeviceType::BOILER, F("Topline/GB162"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
|
||||
{123, DeviceType::BOILER, F("GBx72/Trendline/Cerapur/Greenstar Si/27i"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
|
||||
{133, DeviceType::BOILER, F("GB125/Logamatic MC110"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
|
||||
@@ -37,6 +36,7 @@
|
||||
{122, DeviceType::BOILER, F("Proline"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
|
||||
{170, DeviceType::BOILER, F("Logano GB212"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
|
||||
{172, DeviceType::BOILER, F("Enviline/Compress 6000AW"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
|
||||
{ 72, DeviceType::BOILER, F("GB125/MC10"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
|
||||
|
||||
// Solar Modules - 0x30
|
||||
{ 73, DeviceType::SOLAR, F("SM10"), DeviceFlags::EMS_DEVICE_FLAG_SM10},
|
||||
|
||||
@@ -367,13 +367,14 @@ void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
|
||||
uint8_t product_id = telegram->message_data[offset]; // product ID
|
||||
|
||||
// get version as XX.XX
|
||||
char buf[6] = {0};
|
||||
char buf[6] = {0},
|
||||
buf1[6] = {0};
|
||||
std::string version(5, '\0');
|
||||
snprintf_P(&version[0],
|
||||
version.capacity() + 1,
|
||||
PSTR("%s.%s"),
|
||||
Helpers::smallitoa(buf, telegram->message_data[offset + 1]),
|
||||
Helpers::smallitoa(buf, telegram->message_data[offset + 2]));
|
||||
Helpers::smallitoa(buf1, telegram->message_data[offset + 2]));
|
||||
|
||||
// some devices store the protocol type (HT3, Buderus) in the last byte
|
||||
uint8_t brand;
|
||||
@@ -570,6 +571,7 @@ void EMSESP::send_write_request(const uint16_t type_id,
|
||||
// we check if its a complete telegram or just a single byte (which could be a poll or a return status)
|
||||
void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
// check first for echo
|
||||
//LOG_TRACE(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str());
|
||||
uint8_t first_value = data[0];
|
||||
if (((first_value & 0x7F) == txservice_.ems_bus_id()) && (length > 1)) {
|
||||
return; // it's an echo
|
||||
@@ -752,7 +754,7 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) {
|
||||
shell.printfln(F("Performing a deep scan by pinging our device library..."));
|
||||
std::vector<uint8_t> Device_Ids;
|
||||
|
||||
Device_Ids.push_back(0x09); // Controllers - 0x09
|
||||
Device_Ids.push_back(0x08); // Boilers - 0x08
|
||||
Device_Ids.push_back(0x38); // HeatPump - 0x38
|
||||
Device_Ids.push_back(0x30); // Solar Module - 0x30
|
||||
Device_Ids.push_back(0x09); // Controllers - 0x09
|
||||
@@ -760,10 +762,16 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) {
|
||||
Device_Ids.push_back(0x48); // Gateway - 0x48
|
||||
Device_Ids.push_back(0x20); // Mixing Devices - 0x20
|
||||
Device_Ids.push_back(0x21); // Mixing Devices - 0x21
|
||||
Device_Ids.push_back(0x22); // Mixing Devices - 0x22
|
||||
Device_Ids.push_back(0x23); // Mixing Devices - 0x23
|
||||
Device_Ids.push_back(0x28); // Mixing Devices WW- 0x28
|
||||
Device_Ids.push_back(0x29); // Mixing Devices WW- 0x29
|
||||
Device_Ids.push_back(0x10); // Thermostats - 0x10
|
||||
Device_Ids.push_back(0x17); // Thermostats - 0x17
|
||||
Device_Ids.push_back(0x18); // Thermostats - 0x18
|
||||
Device_Ids.push_back(0x19); // Thermostats - 0x19
|
||||
Device_Ids.push_back(0x18); // Thermostat remote - 0x18
|
||||
Device_Ids.push_back(0x19); // Thermostat remote - 0x19
|
||||
Device_Ids.push_back(0x1A); // Thermostat remote - 0x1A
|
||||
Device_Ids.push_back(0x1B); // Thermostat remote - 0x1B
|
||||
Device_Ids.push_back(0x11); // Switches - 0x11
|
||||
|
||||
// send the read command with Version command
|
||||
|
||||
@@ -66,20 +66,20 @@ void Mixing::show_values(uuid::console::Shell & shell) {
|
||||
|
||||
if (type_ == Type::WWC) {
|
||||
shell.printfln(F(" Warm Water Circuit #: %d"), hc_);
|
||||
|
||||
} else {
|
||||
shell.printfln(F(" Heating Circuit #: %d"), hc_);
|
||||
}
|
||||
print_value(shell, 2, F("Current flow temperature"), F_(degrees), Helpers::render_value(buffer, flowTemp_, 10));
|
||||
print_value(shell, 2, F("Setpoint flow temperature"), F_(degrees), Helpers::render_value(buffer, flowSetTemp_, 1));
|
||||
print_value(shell, 2, F("Current pump modulation"), Helpers::render_value(buffer, pumpMod_, 1));
|
||||
print_value(shell, 2, F("Current valve status"), Helpers::render_value(buffer, status_, 1));
|
||||
print_value(shell, 4, F("Current flow temperature"), F_(degrees), Helpers::render_value(buffer, flowTemp_, 10));
|
||||
print_value(shell, 4, F("Setpoint flow temperature"), F_(degrees), Helpers::render_value(buffer, flowSetTemp_, 1));
|
||||
print_value(shell, 4, F("Current pump modulation"), Helpers::render_value(buffer, pumpMod_, 1));
|
||||
print_value(shell, 4, F("Current valve status"), Helpers::render_value(buffer, status_, 1));
|
||||
}
|
||||
|
||||
// publish values via MQTT
|
||||
// ideally we should group up all the mixing units together into a nested JSON but for now we'll send them individually
|
||||
void Mixing::publish_values() {
|
||||
DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_SMALL);
|
||||
static DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_MEDIUM);
|
||||
// StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc;
|
||||
JsonObject rootMixing = doc.to<JsonObject>();
|
||||
JsonObject dataMixing;
|
||||
|
||||
|
||||
@@ -232,18 +232,7 @@ std::string Sensors::Device::to_string() const {
|
||||
(unsigned int)(id_)&0xFF);
|
||||
return str;
|
||||
}
|
||||
std::string Sensors::Device::to_stringc() const {
|
||||
std::string str(20, '\0');
|
||||
snprintf_P(&str[0],
|
||||
str.capacity() + 1,
|
||||
PSTR("%02X%04X%04X%04X%02X"),
|
||||
(unsigned int)(id_ >> 56) & 0xFF,
|
||||
(unsigned int)(id_ >> 40) & 0xFFFF,
|
||||
(unsigned int)(id_ >> 24) & 0xFFFF,
|
||||
(unsigned int)(id_ >> 8) & 0xFFFF,
|
||||
(unsigned int)(id_)&0xFF);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
// send all dallas sensor values as a JSON package to MQTT
|
||||
// assumes there are devices
|
||||
@@ -287,7 +276,7 @@ void Sensors::publish_values() {
|
||||
for (const auto & device : devices_) {
|
||||
if (mqtt_format_ == Settings::MQTT_format::MY) {
|
||||
char s[5];
|
||||
doc[device.to_stringc()] = Helpers::render_value(s, device.temperature_c_, 2);
|
||||
doc[device.to_string()] = Helpers::render_value(s, device.temperature_c_, 2);
|
||||
} else {
|
||||
char sensorID[10]; // sensor{1-n}
|
||||
strlcpy(sensorID, "sensor", 10);
|
||||
|
||||
@@ -46,7 +46,6 @@ class Sensors {
|
||||
|
||||
uint64_t id() const;
|
||||
std::string to_string() const;
|
||||
std::string to_stringc() const;
|
||||
|
||||
float temperature_c_ = NAN;
|
||||
|
||||
|
||||
@@ -364,6 +364,7 @@ void TxService::loop() {
|
||||
|
||||
// sends a 1 byte poll which is our own device ID
|
||||
void TxService::send_poll() {
|
||||
//OG_TRACE(F("Ack %02X"),ems_bus_id() ^ ems_mask());
|
||||
EMSuart::send_poll(ems_bus_id() ^ ems_mask());
|
||||
}
|
||||
|
||||
@@ -472,7 +473,7 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) {
|
||||
|
||||
// send the telegram to the UART Tx
|
||||
EMSUART_STATUS status = EMSuart::transmit(telegram_raw, length);
|
||||
LOG_TRACE(F("Tx: %s"), Helpers::data_to_hex(telegram_raw, length).c_str());
|
||||
//LOG_TRACE(F("Tx: %s"), Helpers::data_to_hex(telegram_raw, length).c_str());
|
||||
if (status != EMS_TX_STATUS_OK) {
|
||||
LOG_ERROR(F("Failed to transmit Tx via UART. Error: %s"), status == EMS_TX_WTD_TIMEOUT ? F("Timeout") : F("BRK"));
|
||||
}
|
||||
@@ -495,7 +496,7 @@ void TxService::send_telegram(const uint8_t * data, const uint8_t length) {
|
||||
|
||||
// send the telegram to the UART Tx
|
||||
EMSUART_STATUS status = EMSuart::transmit(telegram_raw, length);
|
||||
LOG_TRACE(F("Tx: %s"), Helpers::data_to_hex(telegram_raw, length).c_str());
|
||||
//LOG_TRACE(F("Tx: %s"), Helpers::data_to_hex(telegram_raw, length).c_str());
|
||||
if (status != EMS_TX_STATUS_OK) {
|
||||
LOG_ERROR(F("Failed to transmit Tx via UART. Error: %s"), status == EMS_TX_WTD_TIMEOUT ? F("Timeout") : F("BRK"));
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ class RxService : public EMSbus {
|
||||
|
||||
class TxService : public EMSbus {
|
||||
public:
|
||||
static constexpr size_t MAX_TX_TELEGRAMS = 50;
|
||||
static constexpr size_t MAX_TX_TELEGRAMS = 30;
|
||||
|
||||
static constexpr uint8_t TX_WRITE_FAIL = 4;
|
||||
static constexpr uint8_t TX_WRITE_SUCCESS = 1;
|
||||
|
||||
@@ -327,7 +327,8 @@ bool Thermostat::updated_values() {
|
||||
static uint16_t current_value_ = 0;
|
||||
for (const auto & hc : heating_circuits_) {
|
||||
// don't publish if we haven't yet received some data
|
||||
if ((hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) || (hc->curr_roomTemp == EMS_VALUE_SHORT_NOTSET)) {
|
||||
// if ((hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) || (hc->curr_roomTemp == EMS_VALUE_SHORT_NOTSET)) {
|
||||
if (hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) {
|
||||
return false;
|
||||
}
|
||||
new_value += hc->setpoint_roomTemp + hc->curr_roomTemp + hc->mode;
|
||||
@@ -359,14 +360,17 @@ void Thermostat::publish_values() {
|
||||
|
||||
// optional, add external temp. I don't think anyone actually is interested in this
|
||||
if ((flags == EMS_DEVICE_FLAG_RC35) && ((mqtt_format_ == Settings::MQTT_format::SINGLE) || (mqtt_format_ == Settings::MQTT_format::MY))) {
|
||||
if (datetime_.size()) {
|
||||
rootThermostat["time"] = datetime_.c_str();
|
||||
}
|
||||
if (dampedoutdoortemp != EMS_VALUE_INT_NOTSET) {
|
||||
rootThermostat["dampedtemp"] = dampedoutdoortemp;
|
||||
}
|
||||
if (tempsensor1 != EMS_VALUE_USHORT_NOTSET) {
|
||||
rootThermostat["tempsens1"] = (float)tempsensor1 / 10;
|
||||
rootThermostat["tempsensor1"] = (float)tempsensor1 / 10;
|
||||
}
|
||||
if (tempsensor2 != EMS_VALUE_USHORT_NOTSET) {
|
||||
rootThermostat["tempsens2"] = (float)tempsensor2 / 10;
|
||||
rootThermostat["tempsensor2"] = (float)tempsensor2 / 10;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,69 +672,18 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
|
||||
if (datetime_.size()) {
|
||||
shell.printfln(F(" Clock: %s"), datetime_.c_str());
|
||||
if (ibaClockOffset != EMS_VALUE_UINT_NOTSET) {
|
||||
print_value(shell, 1, F("Offset clock"), Helpers::render_value(buffer, ibaClockOffset, 1)); // offset (in sec) to clock, 0xff = -1 s, 0x02 = 2 s
|
||||
print_value(shell, 2, F("Offset clock"), Helpers::render_value(buffer, ibaClockOffset, 1)); // offset (in sec) to clock, 0xff = -1 s, 0x02 = 2 s
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t flags = (this->flags() & 0x0F); // specific thermostat characteristics, strip the option bits
|
||||
|
||||
if (flags == EMS_DEVICE_FLAG_RC35) {
|
||||
print_value(shell, 1, F("Damped Outdoor temperature"), F_(degrees), Helpers::render_value(buffer, dampedoutdoortemp, 1));
|
||||
print_value(shell, 1, F("Tempsensor 1"), F_(degrees), Helpers::render_value(buffer, tempsensor1, 10));
|
||||
print_value(shell, 1, F("Tempsensor 2"), F_(degrees), Helpers::render_value(buffer, tempsensor2, 10));
|
||||
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));
|
||||
}
|
||||
|
||||
for (const auto & hc : heating_circuits_) {
|
||||
shell.printfln(F(" Heating Circuit %d:"), hc->hc_num());
|
||||
|
||||
// different thermostat types store their temperature values differently
|
||||
uint8_t format_setpoint, format_curr;
|
||||
switch (flags) {
|
||||
case EMS_DEVICE_FLAG_EASY:
|
||||
format_setpoint = 100; // *100
|
||||
format_curr = 100; // *100
|
||||
break;
|
||||
case EMS_DEVICE_FLAG_JUNKERS:
|
||||
format_setpoint = 10; // *10
|
||||
format_curr = 10; // *10
|
||||
break;
|
||||
default: // RC30, RC35 etc...
|
||||
format_setpoint = 2; // *2
|
||||
format_curr = 10; // *10
|
||||
break;
|
||||
}
|
||||
|
||||
print_value(shell, 2, F("Current room temperature"), F_(degrees), Helpers::render_value(buffer, hc->curr_roomTemp, format_curr));
|
||||
print_value(shell, 2, F("Setpoint room temperature"), F_(degrees), Helpers::render_value(buffer, hc->setpoint_roomTemp, format_setpoint));
|
||||
if (hc->mode != EMS_VALUE_UINT_NOTSET) {
|
||||
print_value(shell, 2, F("Mode"), mode_tostring(hc->get_mode(flags)).c_str());
|
||||
}
|
||||
if (hc->mode_type != EMS_VALUE_UINT_NOTSET) {
|
||||
print_value(shell, 2, F("Mode Type"), mode_tostring(hc->get_mode_type(flags)).c_str());
|
||||
}
|
||||
|
||||
if ((flags == EMS_DEVICE_FLAG_RC35) || (flags == EMS_DEVICE_FLAG_RC30_1)) {
|
||||
if (hc->summer_mode) {
|
||||
shell.printfln(F(" Program is set to Summer mode"));
|
||||
} else if (hc->holiday_mode) {
|
||||
shell.printfln(F(" Program is set to Holiday mode"));
|
||||
}
|
||||
|
||||
print_value(shell, 2, F("Day temperature"), F_(degrees), Helpers::render_value(buffer, hc->daytemp, 2));
|
||||
print_value(shell, 2, F("Night temperature"), F_(degrees), Helpers::render_value(buffer, hc->nighttemp, 2));
|
||||
print_value(shell, 2, F("Vacation temperature"), F_(degrees), Helpers::render_value(buffer, hc->holidaytemp, 2));
|
||||
|
||||
if (hc->offsettemp < 100) {
|
||||
print_value(shell, 2, F("Offset temperature"), F_(degrees), Helpers::render_value(buffer, hc->offsettemp, 2));
|
||||
}
|
||||
print_value(shell, 2, F("Design temperature"), F_(degrees), Helpers::render_value(buffer, hc->designtemp, 2));
|
||||
}
|
||||
|
||||
// show flow temp if we have it
|
||||
if (hc->circuitcalctemp != EMS_VALUE_UINT_NOTSET) {
|
||||
print_value(shell, 2, F("Calculated flow temperature"), F_(degrees), Helpers::render_value(buffer, hc->circuitcalctemp, 1));
|
||||
}
|
||||
|
||||
if (flags == EMS_DEVICE_FLAG_RC30_1) {
|
||||
// settings parameters
|
||||
if (ibaMainDisplay != EMS_VALUE_UINT_NOTSET) {
|
||||
if (ibaMainDisplay == 0) {
|
||||
@@ -765,13 +718,15 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
|
||||
shell.printfln(F(" Language: Italian"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags == EMS_DEVICE_FLAG_RC35 ||flags == EMS_DEVICE_FLAG_RC30_1) {
|
||||
|
||||
if (ibaCalIntTemperature != EMS_VALUE_INT_NOTSET) {
|
||||
print_value(shell, 2, F("Offset int. temperature"), F_(degrees), Helpers::render_value(buffer, ibaCalIntTemperature, 2));
|
||||
}
|
||||
|
||||
if (ibaMinExtTemperature != EMS_VALUE_INT_NOTSET) {
|
||||
print_value(shell, 2, F("Min ext. temperature"), F_(degrees), Helpers::render_value(buffer, ibaMinExtTemperature, 10)); // min ext temp for heating curve, in deg.
|
||||
print_value(shell, 2, F("Min ext. temperature"), F_(degrees), Helpers::render_value(buffer, ibaMinExtTemperature, 0)); // min ext temp for heating curve, in deg.
|
||||
}
|
||||
|
||||
if (ibaBuildingType != EMS_VALUE_UINT_NOTSET) {
|
||||
@@ -784,6 +739,58 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto & hc : heating_circuits_) {
|
||||
shell.printfln(F(" Heating Circuit %d:"), hc->hc_num());
|
||||
|
||||
// different thermostat types store their temperature values differently
|
||||
uint8_t format_setpoint, format_curr;
|
||||
switch (flags) {
|
||||
case EMS_DEVICE_FLAG_EASY:
|
||||
format_setpoint = 100; // *100
|
||||
format_curr = 100; // *100
|
||||
break;
|
||||
case EMS_DEVICE_FLAG_JUNKERS:
|
||||
format_setpoint = 10; // *10
|
||||
format_curr = 10; // *10
|
||||
break;
|
||||
default: // RC30, RC35 etc...
|
||||
format_setpoint = 2; // *2
|
||||
format_curr = 10; // *10
|
||||
break;
|
||||
}
|
||||
|
||||
print_value(shell, 4, F("Current room temperature"), F_(degrees), Helpers::render_value(buffer, hc->curr_roomTemp, format_curr));
|
||||
print_value(shell, 4, F("Setpoint room temperature"), F_(degrees), Helpers::render_value(buffer, hc->setpoint_roomTemp, format_setpoint));
|
||||
if (hc->mode != EMS_VALUE_UINT_NOTSET) {
|
||||
print_value(shell, 4, F("Mode"), mode_tostring(hc->get_mode(flags)).c_str());
|
||||
}
|
||||
if (hc->mode_type != EMS_VALUE_UINT_NOTSET) {
|
||||
print_value(shell, 4, F("Mode Type"), mode_tostring(hc->get_mode_type(flags)).c_str());
|
||||
}
|
||||
|
||||
if ((flags == EMS_DEVICE_FLAG_RC35) || (flags == EMS_DEVICE_FLAG_RC30_1)) {
|
||||
if (hc->summer_mode) {
|
||||
shell.printfln(F(" Program is set to Summer mode"));
|
||||
} else if (hc->holiday_mode) {
|
||||
shell.printfln(F(" Program is set to Holiday mode"));
|
||||
}
|
||||
|
||||
print_value(shell, 4, F("Day temperature"), F_(degrees), Helpers::render_value(buffer, hc->daytemp, 2));
|
||||
print_value(shell, 4, F("Night temperature"), F_(degrees), Helpers::render_value(buffer, hc->nighttemp, 2));
|
||||
print_value(shell, 4, F("Holiday temperature"), F_(degrees), Helpers::render_value(buffer, hc->holidaytemp, 2));
|
||||
|
||||
if (hc->offsettemp < 100) {
|
||||
print_value(shell, 4, F("Offset temperature"), F_(degrees), Helpers::render_value(buffer, hc->offsettemp, 2));
|
||||
}
|
||||
print_value(shell, 4, F("Design temperature"), F_(degrees), Helpers::render_value(buffer, hc->designtemp, 0));
|
||||
}
|
||||
|
||||
// show flow temp if we have it
|
||||
if (hc->circuitcalctemp != EMS_VALUE_UINT_NOTSET) {
|
||||
print_value(shell, 4, F("Calculated flow temperature"), F_(degrees), Helpers::render_value(buffer, hc->circuitcalctemp, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 0xA8 - for reading the mode from the RC20 thermostat (0x17)
|
||||
@@ -859,12 +866,12 @@ void Thermostat::process_EasyMonitor(std::shared_ptr<const Telegram> telegram) {
|
||||
// Settings Parameters - 0xA5 - RC30_1
|
||||
void Thermostat::process_IBASettings(std::shared_ptr<const Telegram> telegram) {
|
||||
uint8_t extTemp = 100; // Min. ext temperature is coded as int8, 0xF6=-10, 0x0 = 0, 0xFF=-1. 100 is out of permissible range
|
||||
|
||||
// 22 - display line on RC35
|
||||
telegram->read_value(ibaMainDisplay,
|
||||
0); // display on Thermostat: 0 int. temp, 1 int. setpoint, 2 ext. temp., 3 burner temp., 4 ww temp, 5 functioning mode, 6 time, 7 data, 9 smoke temp
|
||||
telegram->read_value(ibaLanguage, 6); // language on Thermostat: 0 german, 1 dutch, 2 french, 3 italian
|
||||
telegram->read_value(ibaBuildingType, 2); // building type: 0 = light, 1 = medium, 2 = heavy
|
||||
telegram->read_value(ibaLanguage, 1); // language on Thermostat: 0 german, 1 dutch, 2 french, 3 italian
|
||||
telegram->read_value(ibaCalIntTemperature, 2); // offset int. temperature sensor, by * 0.1 Kelvin
|
||||
telegram->read_value(ibaBuildingType, 6); // building type: 0 = light, 1 = medium, 2 = heavy
|
||||
telegram->read_value(extTemp, 5); // min ext temp for heating curve, in deg., 0xF6=-10, 0x0 = 0, 0xFF=-1
|
||||
if (extTemp != 100) {
|
||||
// code as signed short, to benefit from negative value rendering
|
||||
|
||||
@@ -52,10 +52,9 @@ void EMSuart::emsuart_recvTask(void * param) {
|
||||
/*
|
||||
* UART interrupt, on break read the fifo and put the whole telegram to ringbuffer
|
||||
*/
|
||||
static void IRAM_ATTR uart_intr_handle(void * arg) {
|
||||
void IRAM_ATTR EMSuart::uart_intr_handle(void * arg) {
|
||||
if (EMS_UART.int_st.brk_det) {
|
||||
uint8_t rx_fifo_len = EMS_UART.status.rxfifo_cnt;
|
||||
for (rxlen = 0; rxlen < rx_fifo_len; rxlen++) {
|
||||
for (uint8_t rxlen = 0; EMS_UART.status.rxfifo_cnt > 0; rxlen++) {
|
||||
rxbuf[rxlen] = EMS_UART.fifo.rw_byte; // read all bytes into buffer
|
||||
}
|
||||
if (!drop_first_rx && (rxlen == 2) || ((rxlen > 4) && (rxlen <= EMS_MAXBUFFERSIZE))) {
|
||||
@@ -81,8 +80,6 @@ void EMSuart::start(uint8_t tx_mode) {
|
||||
|
||||
ESP_ERROR_CHECK(uart_param_config(EMSUART_UART, &uart_config));
|
||||
ESP_ERROR_CHECK(uart_set_pin(EMSUART_UART, EMSUART_TXPIN, EMSUART_RXPIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||
//EMS_UART.conf1.rxfifo_full_thrhd = 127; // enough to hold the incoming telegram, should never reached
|
||||
//EMS_UART.idle_conf.tx_brk_num = 12; // breaklength 12 bit
|
||||
EMS_UART.int_ena.val = 0; // disable all intr.
|
||||
EMS_UART.int_clr.val = 0xFFFFFFFF; // clear all intr. flags
|
||||
buf_handle = xRingbufferCreate(128, RINGBUF_TYPE_NOSPLIT);
|
||||
@@ -116,7 +113,7 @@ void EMSuart::restart() {
|
||||
void EMSuart::send_poll(uint8_t data) {
|
||||
EMS_UART.conf0.txd_brk = 0; // just to make sure the bit is cleared
|
||||
EMS_UART.fifo.rw_byte = data;
|
||||
EMS_UART.idle_conf.tx_brk_num = 12; // breaklength 12 bit
|
||||
EMS_UART.idle_conf.tx_brk_num = 11; // breaklength 11 bit
|
||||
EMS_UART.conf0.txd_brk = 1; // sending ends in a break
|
||||
}
|
||||
|
||||
@@ -127,15 +124,12 @@ void EMSuart::send_poll(uint8_t data) {
|
||||
*/
|
||||
EMSUART_STATUS EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
if (len > 0) {
|
||||
if (EMS_UART.status.txfifo_cnt > 0) { // fifo not empty
|
||||
return EMS_TX_WTD_TIMEOUT;
|
||||
}
|
||||
EMS_UART.conf0.txd_brk = 0; // just to make sure the bit is cleared
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
EMS_UART.fifo.rw_byte = buf[i];
|
||||
}
|
||||
//uart_tx_chars(EMSUART_UART, (const char *)buf, len);
|
||||
EMS_UART.idle_conf.tx_brk_num = 12; // breaklength 12 bit
|
||||
EMS_UART.idle_conf.tx_brk_num = 11; // breaklength 11 bit
|
||||
EMS_UART.conf0.txd_brk = 1; // sending ends in a break
|
||||
}
|
||||
return EMS_TX_STATUS_OK;
|
||||
|
||||
@@ -58,6 +58,7 @@ class EMSuart {
|
||||
|
||||
private:
|
||||
static void emsuart_recvTask(void * param);
|
||||
static void IRAM_ATTR emsuart_rx_intr_handler(void * para);
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -25,35 +25,62 @@
|
||||
namespace emsesp {
|
||||
|
||||
os_event_t recvTaskQueue[EMSUART_recvTaskQueueLen]; // our Rx queue
|
||||
|
||||
EMSuart::EMSRxBuf_t * pEMSRxBuf;
|
||||
EMSuart::EMSRxBuf_t * paEMSRxBuf[EMS_MAXBUFFERS];
|
||||
uint8_t emsRxBufIdx = 0;
|
||||
bool drop_first_rx = true;
|
||||
uint8_t phantomBreak = 0;
|
||||
uint8_t tx_mode_ = EMS_TXMODE_NEW;
|
||||
uint8_t tx_mode_ = EMS_TXMODE_DEFAULT;
|
||||
bool drop_first_rx = true;
|
||||
|
||||
//
|
||||
// Main interrupt handler
|
||||
// Important: must not use ICACHE_FLASH_ATTR
|
||||
//
|
||||
void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
||||
static uint8_t length = 0;
|
||||
static uint8_t uart_buffer[128];
|
||||
// static bool rx_idle_ = true;
|
||||
static uint8_t uart_buffer[EMS_MAXBUFFERSIZE + 2];
|
||||
|
||||
/*
|
||||
// is a new buffer? if so init the thing for a new telegram
|
||||
if (rx_idle_) {
|
||||
rx_idle_ = false; // status set to busy
|
||||
length = 0;
|
||||
}
|
||||
// fill IRQ buffer, by emptying Rx FIFO
|
||||
if (USIS(EMSUART_UART) & ((1 << UIFF) | (1 << UITO) | (1 << UIBD))) {
|
||||
while ((USS(EMSUART_UART) >> USRXC) & 0xFF) {
|
||||
uint8_t rx = USF(EMSUART_UART);
|
||||
if (length < EMS_MAXBUFFERSIZE)
|
||||
uart_buffer[length++] = rx;
|
||||
}
|
||||
|
||||
// clear Rx FIFO full and Rx FIFO timeout interrupts
|
||||
USIC(EMSUART_UART) = (1 << UIFF) | (1 << UITO);
|
||||
}
|
||||
*/
|
||||
// BREAK detection = End of EMS data block
|
||||
if (USIS(EMSUART_UART) & ((1 << UIBD))) {
|
||||
uint8_t rxlen = (USS(EMSUART_UART) & 0xFF); // length of buffer
|
||||
for (length = 0; length < rxlen; length++) {
|
||||
uart_buffer[length] = USF(EMSUART_UART);
|
||||
length = 0;
|
||||
while ((USS(EMSUART_UART) >> USRXC) & 0xFF) {
|
||||
uint8_t rx = USF(EMSUART_UART);
|
||||
if (length < EMS_MAXBUFFERSIZE) {
|
||||
uart_buffer[length++] = rx;
|
||||
}
|
||||
USIE(EMSUART_UART) = 0; // disable all interrupts and clear them
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset <BRK> from sending
|
||||
if (!drop_first_rx && (length < EMS_MAXBUFFERSIZE)) { // only a valid telegram
|
||||
}
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear <BRK> bit
|
||||
ETS_UART_INTR_DISABLE(); // disable all interrupts and clear them
|
||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||
if (!drop_first_rx) {
|
||||
pEMSRxBuf->length = length;
|
||||
os_memcpy((void *)pEMSRxBuf->buffer, (void *)&uart_buffer, pEMSRxBuf->length); // copy data into transfer buffer, including the BRK 0x00 at the end
|
||||
system_os_post(EMSUART_recvTaskPrio, 0, 0); // call emsuart_recvTask() at next opportunity
|
||||
// rx_idle_ = true; // check set the status flag stating BRK has been received and we can start a new package
|
||||
}
|
||||
drop_first_rx = false;
|
||||
USIC(EMSUART_UART) |= (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||
USIE(EMSUART_UART) = (1 << UIBD); // enable only rx break
|
||||
ETS_UART_INTR_ENABLE(); // re-enable UART interrupts
|
||||
|
||||
system_os_post(EMSUART_recvTaskPrio, 0, 0); // call emsuart_recvTask() at next opportunity
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,18 +106,29 @@ void ICACHE_FLASH_ATTR EMSuart::emsuart_recvTask(os_event_t * events) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ignore double BRK at the end, possibly from the Tx loopback
|
||||
// also telegrams with no data value
|
||||
// then transmit EMS buffer, excluding the BRK, length is checked by irq
|
||||
if (length > 4) {
|
||||
// then transmit EMS buffer, excluding the BRK
|
||||
if ((length > 4) && (length <= EMS_MAXBUFFERSIZE + 1)) {
|
||||
EMSESP::incoming_telegram((uint8_t *)pCurrent->buffer, length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* flush everything left over in buffer, this clears both rx and tx FIFOs
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR EMSuart::emsuart_flush_fifos() {
|
||||
uint32_t tmp = ((1 << UCRXRST) | (1 << UCTXRST)); // bit mask
|
||||
USC0(EMSUART_UART) |= (tmp); // set bits
|
||||
USC0(EMSUART_UART) &= ~(tmp); // clear bits
|
||||
}
|
||||
|
||||
/*
|
||||
* init UART0 driver
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) {
|
||||
tx_mode_ = tx_mode;
|
||||
|
||||
// allocate and preset EMS Receive buffers
|
||||
for (int i = 0; i < EMS_MAXBUFFERS; i++) {
|
||||
EMSRxBuf_t * p = (EMSRxBuf_t *)malloc(sizeof(EMSRxBuf_t));
|
||||
@@ -98,6 +136,9 @@ void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) {
|
||||
}
|
||||
pEMSRxBuf = paEMSRxBuf[0]; // reset EMS Rx Buffer
|
||||
|
||||
ETS_UART_INTR_DISABLE();
|
||||
ETS_UART_INTR_ATTACH(nullptr, nullptr);
|
||||
|
||||
// pin settings
|
||||
PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
|
||||
@@ -106,22 +147,45 @@ void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) {
|
||||
|
||||
// set 9600, 8 bits, no parity check, 1 stop bit
|
||||
USD(EMSUART_UART) = (UART_CLK_FREQ / EMSUART_BAUD);
|
||||
USC0(EMSUART_UART) = EMSUART_CONFIG;
|
||||
// flash fifo buffers, not required since we drop the first telegram
|
||||
// USC0(EMSUART_UART) |= ((1 << UCRXRST) | (1 << UCTXRST)); // set bits
|
||||
// USC0(EMSUART_UART) &= ~((1 << UCRXRST) | (1 << UCTXRST)); // clear bits
|
||||
USC0(EMSUART_UART) = EMSUART_CONFIG; // 8N1
|
||||
|
||||
// we dont use fifo-full interrupt anymore, no need to set this
|
||||
//USC1(EMSUART_UART) = (0x7F << UCFFT); // rx buffer full
|
||||
emsuart_flush_fifos();
|
||||
|
||||
// conf1 params
|
||||
// UCTOE = RX TimeOut enable (default is 1)
|
||||
// UCTOT = RX TimeOut Threshold (7 bit) = want this when no more data after 1 characters (default is 2)
|
||||
// UCFFT = RX FIFO Full Threshold (7 bit) = want this to be 31 for 32 bytes of buffer (default was 127)
|
||||
// see https://www.espressif.com/sites/default/files/documentation/esp8266-technical_reference_en.pdf
|
||||
//
|
||||
// change: we set UCFFT to 1 to get an immediate indicator about incoming traffic.
|
||||
// Otherwise, we're only noticed by UCTOT or RxBRK!
|
||||
// change: don't care, we do not use these interrupts
|
||||
//USC1(EMSUART_UART) = 0; // reset config first
|
||||
//USC1(EMSUART_UART) = (0x01 << UCFFT) | (0x01 << UCTOT) | (0 << UCTOE); // enable interupts
|
||||
|
||||
// set interrupts for triggers
|
||||
USIC(EMSUART_UART) = 0xFFFF; // clear all interupts
|
||||
USIE(EMSUART_UART) = 0; // disable all interrupts
|
||||
USIC(EMSUART_UART) = 0xFFFF; // clear all interupt flags
|
||||
|
||||
system_set_os_print(0); // disable esp debug which will go to Tx and mess up the line - see https://github.com/espruino/Espruino/issues/655
|
||||
system_uart_swap(); // swap Rx and Tx pins to use GPIO13 (D7) and GPIO15 (D8) respectively
|
||||
system_os_task(emsuart_recvTask, EMSUART_recvTaskPrio, recvTaskQueue, EMSUART_recvTaskQueueLen); // set up interrupt callbacks for Rx
|
||||
// enable rx break, fifo full and timeout.
|
||||
// but not frame error UIFR (because they are too frequent) or overflow UIOF because our buffer is only max 32 bytes
|
||||
// change: we don't care about Rx Timeout - it may lead to wrong readouts
|
||||
// change:we don't care about Fifo full and read only on break-detect
|
||||
USIE(EMSUART_UART) = (1 << UIBD) | (0 << UIFF) | (0 << UITO);
|
||||
|
||||
// set up interrupt callbacks for Rx
|
||||
system_os_task(emsuart_recvTask, EMSUART_recvTaskPrio, recvTaskQueue, EMSUART_recvTaskQueueLen);
|
||||
|
||||
// disable esp debug which will go to Tx and mess up the line - see https://github.com/espruino/Espruino/issues/655
|
||||
system_set_os_print(0);
|
||||
|
||||
// swap Rx and Tx pins to use GPIO13 (D7) and GPIO15 (D8) respectively
|
||||
system_uart_swap();
|
||||
|
||||
ETS_UART_INTR_ATTACH(emsuart_rx_intr_handler, nullptr);
|
||||
drop_first_rx = true; // drop first telegram since it is incomplete
|
||||
USIE(EMSUART_UART) = (1 << UIBD); // enable only rx break interrupt
|
||||
ETS_UART_INTR_ENABLE();
|
||||
drop_first_rx = true;
|
||||
// LOG_INFO(F("UART service for Rx/Tx started"));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -129,23 +193,56 @@ void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) {
|
||||
* This is called prior to an OTA upload and also before a save to the filesystem to prevent conflicts
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR EMSuart::stop() {
|
||||
USIE(EMSUART_UART) = 0; // disable uart interrupt
|
||||
ETS_UART_INTR_DISABLE();
|
||||
}
|
||||
|
||||
/*
|
||||
* re-start UART0 driver
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR EMSuart::restart() {
|
||||
if (USIS(EMSUART_UART) & ((1 << UIBD))) { // if we had a break
|
||||
USIC(EMSUART_UART) |= (1 << UIBD); // clear the BREAK detect flag
|
||||
drop_first_rx = true; // and drop first frame
|
||||
} // otherwise there is the beginning of a valid telegram in the fifo
|
||||
USIE(EMSUART_UART) = (1 << UIBD); // enable rx break interrupt
|
||||
if (USIS(EMSUART_UART) & ((1 << UIBD))) {
|
||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||
drop_first_rx = true;
|
||||
}
|
||||
ETS_UART_INTR_ENABLE();
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a BRK signal
|
||||
* Which is a 11-bit set of zero's (11 cycles)
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR EMSuart::tx_brk() {
|
||||
uint32_t tmp;
|
||||
|
||||
// must make sure Tx FIFO is empty
|
||||
while (((USS(EMSUART_UART) >> USTXC) & 0xFF))
|
||||
;
|
||||
|
||||
tmp = ((1 << UCRXRST) | (1 << UCTXRST)); // bit mask
|
||||
USC0(EMSUART_UART) |= (tmp); // set bits
|
||||
USC0(EMSUART_UART) &= ~(tmp); // clear bits
|
||||
|
||||
// To create a 11-bit <BRK> we set TXD_BRK bit so the break signal will
|
||||
// automatically be sent when the tx fifo is empty
|
||||
tmp = (1 << UCBRK);
|
||||
USC0(EMSUART_UART) |= (tmp); // set bit
|
||||
|
||||
if (tx_mode_ == EMS_TXMODE_EMSPLUS) { // EMS+ mode
|
||||
delayMicroseconds(EMSUART_TX_BRK_WAIT);
|
||||
} else if (tx_mode_ == EMS_TXMODE_HT3) { // junkers mode
|
||||
delayMicroseconds(EMSUART_TX_WAIT_BRK - EMSUART_TX_LAG); // 1144 (11 Bits)
|
||||
}
|
||||
|
||||
USC0(EMSUART_UART) &= ~(tmp); // clear bit
|
||||
}
|
||||
|
||||
/*
|
||||
* Sends a 1-byte poll, ending with a <BRK>
|
||||
* It's a bit dirty. there is no special wait logic per tx_mode type, fifo flushes or error checking
|
||||
*/
|
||||
void EMSuart::send_poll(uint8_t data) {
|
||||
if (tx_mode_ == EMS_TXMODE_NEW) {
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // in doubt clear <BRK> bit
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // make sure <BRK> bit is cleared
|
||||
USF(EMSUART_UART) = data;
|
||||
USC0(EMSUART_UART) |= (1 << UCBRK); // send <BRK> at the end
|
||||
} else {
|
||||
@@ -158,6 +255,7 @@ void EMSuart::send_poll(uint8_t data) {
|
||||
/*
|
||||
* Send data to Tx line, ending with a <BRK>
|
||||
* buf contains the CRC and len is #bytes including the CRC
|
||||
* returns code, 0=success, 1=brk error, 2=watchdog timeout
|
||||
*/
|
||||
EMSUART_STATUS ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
if (len == 0) {
|
||||
@@ -166,12 +264,9 @@ EMSUART_STATUS ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
|
||||
// new code from Michael. See https://github.com/proddy/EMS-ESP/issues/380
|
||||
if (tx_mode_ == EMS_TXMODE_NEW) {
|
||||
if ((USS(EMSUART_UART) >> USTXC) & 0xFF) { // buffer not empty
|
||||
return EMS_TX_WTD_TIMEOUT;
|
||||
}
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear <BRK> bit
|
||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // make sure <BRK> bit is cleared
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
USF(EMSUART_UART) = buf[i]; // fill fifo buffer
|
||||
USF(EMSUART_UART) = buf[i];
|
||||
}
|
||||
USC0(EMSUART_UART) |= (1 << UCBRK); // send <BRK> at the end
|
||||
return EMS_TX_STATUS_OK;
|
||||
@@ -181,7 +276,7 @@ EMSUART_STATUS ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
if (tx_mode_ == EMS_TXMODE_EMSPLUS) { // With extra tx delay for EMS+
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
USF(EMSUART_UART) = buf[i];
|
||||
delayMicroseconds(EMSUART_TX_BRK_WAIT);
|
||||
delayMicroseconds(EMSUART_TX_BRK_WAIT); // 2070
|
||||
}
|
||||
tx_brk(); // send <BRK>
|
||||
return EMS_TX_STATUS_OK;
|
||||
@@ -282,44 +377,6 @@ EMSUART_STATUS ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
||||
return result; // send the Tx status back
|
||||
}
|
||||
|
||||
/*
|
||||
* flush everything left over in buffer, this clears both rx and tx FIFOs
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR EMSuart::emsuart_flush_fifos() {
|
||||
uint32_t tmp = ((1 << UCRXRST) | (1 << UCTXRST)); // bit mask
|
||||
USC0(EMSUART_UART) |= (tmp); // set bits
|
||||
USC0(EMSUART_UART) &= ~(tmp); // clear bits
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a BRK signal
|
||||
* Which is a 11-bit set of zero's (11 cycles)
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR EMSuart::tx_brk() {
|
||||
uint32_t tmp;
|
||||
|
||||
// must make sure Tx FIFO is empty
|
||||
while (((USS(EMSUART_UART) >> USTXC) & 0xFF))
|
||||
;
|
||||
|
||||
tmp = ((1 << UCRXRST) | (1 << UCTXRST)); // bit mask
|
||||
USC0(EMSUART_UART) |= (tmp); // set bits
|
||||
USC0(EMSUART_UART) &= ~(tmp); // clear bits
|
||||
|
||||
// To create a 11-bit <BRK> we set TXD_BRK bit so the break signal will
|
||||
// automatically be sent when the tx fifo is empty
|
||||
tmp = (1 << UCBRK);
|
||||
USC0(EMSUART_UART) |= (tmp); // set bit
|
||||
|
||||
if (tx_mode_ == EMS_TXMODE_EMSPLUS) { // EMS+ mode
|
||||
delayMicroseconds(EMSUART_TX_BRK_WAIT);
|
||||
} else if (tx_mode_ == EMS_TXMODE_HT3) { // junkers mode
|
||||
delayMicroseconds(EMSUART_TX_WAIT_BRK - EMSUART_TX_LAG); // 1144 (11 Bits)
|
||||
}
|
||||
|
||||
USC0(EMSUART_UART) &= ~(tmp); // clear bit
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
#define EMSUART_TX_LAG 8
|
||||
#define EMSUART_BUSY_WAIT (EMSUART_BIT_TIME / 8)
|
||||
#define EMS_TX_TO_CHARS (2 + 20)
|
||||
#define EMS_TX_TO_COUNT (EMS_TX_TO_CHARS * 8)
|
||||
#define EMS_TX_TO_COUNT ((EMS_TX_TO_CHARS) * 8)
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user