mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
Merge pull request #622 from MichaelDvP/v3.5.0
add operation sign to log and some other small changes
This commit is contained in:
@@ -685,10 +685,13 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
std::string str;
|
||||
str.reserve(200);
|
||||
if (telegram->operation == Telegram::Operation::RX_READ) {
|
||||
str = src_name + "(" + Helpers::hextoa(src) + ") <- " + dest_name + "(" + Helpers::hextoa(dest) + "), " + type_name + "("
|
||||
str = src_name + "(" + Helpers::hextoa(src) + ") -R-> " + dest_name + "(" + Helpers::hextoa(dest) + "), " + type_name + "("
|
||||
+ Helpers::hextoa(telegram->type_id) + "), length: " + Helpers::hextoa(telegram->message_data[0]);
|
||||
} else if (telegram->dest == 0) {
|
||||
str = src_name + "(" + Helpers::hextoa(src) + ") -B-> " + dest_name + "(" + Helpers::hextoa(dest) + "), " + type_name + "("
|
||||
+ Helpers::hextoa(telegram->type_id) + "), data: " + telegram->to_string_message();
|
||||
} else {
|
||||
str = src_name + "(" + Helpers::hextoa(src) + ") -> " + dest_name + "(" + Helpers::hextoa(dest) + "), " + type_name + "("
|
||||
str = src_name + "(" + Helpers::hextoa(src) + ") -W-> " + dest_name + "(" + Helpers::hextoa(dest) + "), " + type_name + "("
|
||||
+ Helpers::hextoa(telegram->type_id) + "), data: " + telegram->to_string_message();
|
||||
}
|
||||
|
||||
@@ -1213,7 +1216,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
tx_successful = true;
|
||||
|
||||
// if telegram is longer read next part with offset +25 for ems+ or +27 for ems1.0
|
||||
if ((length == 32) && (txservice_.read_next_tx(data[3]) == read_id_)) {
|
||||
if ((length >= 31) && (txservice_.read_next_tx(data[3], length) == read_id_)) {
|
||||
read_next_ = true;
|
||||
}
|
||||
}
|
||||
@@ -1272,11 +1275,6 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
}
|
||||
}
|
||||
|
||||
// sends raw data of bytes along the Tx line
|
||||
void EMSESP::send_raw_telegram(const char * data) {
|
||||
txservice_.send_raw(data);
|
||||
}
|
||||
|
||||
// start all the core services
|
||||
// the services must be loaded in the correct order
|
||||
void EMSESP::start() {
|
||||
|
||||
@@ -128,7 +128,6 @@ class EMSESP {
|
||||
static void send_write_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t value);
|
||||
static void send_write_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t value, const uint16_t validate_typeid);
|
||||
|
||||
static void send_raw_telegram(const char * data);
|
||||
static bool device_exists(const uint8_t device_id);
|
||||
static bool cmd_is_readonly(const uint8_t device_type, const char * cmd, const int8_t id);
|
||||
|
||||
|
||||
@@ -67,49 +67,9 @@ uint8_t System::language_index() {
|
||||
return 0; // EN
|
||||
}
|
||||
|
||||
// send on/off to a gpio pin
|
||||
// value: true = HIGH, false = LOW
|
||||
bool System::command_pin(const char * value, const int8_t id) {
|
||||
#ifndef EMSESP_STANDALONE
|
||||
|
||||
if (!is_valid_gpio(id)) {
|
||||
LOG_INFO(F("Invalid GPIO number"));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool v = false;
|
||||
std::string v1 = {7, '\0'};
|
||||
int v2 = 0;
|
||||
|
||||
if (id == 25 && Helpers::value2number(value, v2)) {
|
||||
if (v2 >= 0 && v2 <= 255) {
|
||||
dacWrite(id, v2);
|
||||
return true;
|
||||
}
|
||||
} else if (Helpers::value2bool(value, v)) {
|
||||
pinMode(id, OUTPUT);
|
||||
digitalWrite(id, v);
|
||||
// LOG_INFO(F("GPIO %d set to %s"), id, v ? "HIGH" : "LOW");
|
||||
return true;
|
||||
} else if (Helpers::value2string(value, v1)) {
|
||||
if (v1 == "input" || v1 == "in" || v1 == "-1") {
|
||||
pinMode(id, INPUT);
|
||||
v = digitalRead(id);
|
||||
// LOG_INFO(F("GPIO %d set input, state %s"), id, v ? "HIGH" : "LOW");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// LOG_INFO(F("GPIO %d: invalid value"), id);
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// send raw to ems
|
||||
bool System::command_send(const char * value, const int8_t id) {
|
||||
EMSESP::send_raw_telegram(value); // ignore id
|
||||
return true;
|
||||
return EMSESP::txservice_.send_raw(value); // ignore id
|
||||
}
|
||||
|
||||
// fetch device values
|
||||
@@ -695,8 +655,6 @@ void System::system_check() {
|
||||
|
||||
// commands - takes static function pointers
|
||||
void System::commands_init() {
|
||||
// Command::add(EMSdevice::DeviceType::SYSTEM, F_(pin), System::command_pin, F("set a GPIO on/off"), CommandFlag::ADMIN_ONLY);
|
||||
|
||||
// TODO these should be translated too
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send, F("send a telegram"), CommandFlag::ADMIN_ONLY);
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(fetch), System::command_fetch, F("refresh all EMS values"), CommandFlag::ADMIN_ONLY);
|
||||
|
||||
@@ -49,7 +49,6 @@ class System {
|
||||
void loop();
|
||||
|
||||
// commands
|
||||
static bool command_pin(const char * value, const int8_t id);
|
||||
static bool command_send(const char * value, const int8_t id);
|
||||
static bool command_publish(const char * value, const int8_t id);
|
||||
static bool command_fetch(const char * value, const int8_t id);
|
||||
|
||||
@@ -540,9 +540,9 @@ void TxService::read_request(const uint16_t type_id, const uint8_t dest, const u
|
||||
}
|
||||
|
||||
// Send a raw telegram to the bus, telegram is a text string of hex values
|
||||
void TxService::send_raw(const char * telegram_data) {
|
||||
bool TxService::send_raw(const char * telegram_data) {
|
||||
if (telegram_data == nullptr) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// since the telegram data is a const, make a copy. add 1 to grab the \0 EOS
|
||||
@@ -562,6 +562,8 @@ void TxService::send_raw(const char * telegram_data) {
|
||||
if ((p = strtok(telegram, " ,"))) { // delimiter
|
||||
strlcpy(value, p, sizeof(value));
|
||||
data[0] = (uint8_t)strtol(value, 0, 16);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// and iterate until end
|
||||
@@ -573,11 +575,13 @@ void TxService::send_raw(const char * telegram_data) {
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
return; // nothing to send
|
||||
// check valid length and src
|
||||
if ((count < 4) || ((data[0] & 0x7F) != ems_bus_id())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
add(Telegram::Operation::TX_RAW, data, count + 1, 0, true); // add to top/front of Tx queue
|
||||
return true;
|
||||
}
|
||||
|
||||
// add last Tx to tx queue and increment count
|
||||
@@ -625,24 +629,18 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui
|
||||
}
|
||||
|
||||
// send a request to read the next block of data from longer telegrams
|
||||
uint16_t TxService::read_next_tx(uint8_t offset) {
|
||||
// add to the top/front of the queue
|
||||
uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes
|
||||
if (telegram_last_->offset != offset) {
|
||||
return 0;
|
||||
uint16_t TxService::read_next_tx(const uint8_t offset, const uint8_t length) {
|
||||
uint8_t old_length = telegram_last_->type_id > 0xFF ? length - 7 : length - 5;
|
||||
uint8_t next_length = telegram_last_->type_id > 0xFF ? EMS_MAX_TELEGRAM_MESSAGE_LENGTH - 2 : EMS_MAX_TELEGRAM_MESSAGE_LENGTH;
|
||||
uint8_t next_offset = telegram_last_->offset + old_length;
|
||||
uint8_t message_data = (UINT8_MAX - next_offset) >= next_length ? next_length : UINT8_MAX - next_offset;
|
||||
// check telegram, offset and overflow
|
||||
// some telegrams only reply with one byte less, but have higher offsets (0x10)
|
||||
if (old_length >= (next_length - 1) && telegram_last_->offset == offset) {
|
||||
add(Telegram::Operation::TX_READ, telegram_last_->dest, telegram_last_->type_id, next_offset, &message_data, 1, 0, true);
|
||||
return telegram_last_->type_id;
|
||||
}
|
||||
|
||||
uint8_t add_offset = 25; // for EMS+ telegram increase offset by 25
|
||||
if (telegram_last_->type_id < 0x100) { // but for EMS1.0 by 27
|
||||
add_offset = 27;
|
||||
}
|
||||
|
||||
if (UINT8_MAX - telegram_last_->offset < add_offset) { // stop if new offset would overflow
|
||||
return 0;
|
||||
}
|
||||
|
||||
add(Telegram::Operation::TX_READ, telegram_last_->dest, telegram_last_->type_id, telegram_last_->offset + add_offset, message_data, 1, 0, true);
|
||||
return telegram_last_->type_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// checks if a telegram is sent to us matches the last Tx request
|
||||
|
||||
@@ -304,12 +304,12 @@ class TxService : public EMSbus {
|
||||
const bool front = false);
|
||||
void add(const uint8_t operation, const uint8_t * data, const uint8_t length, const uint16_t validateid, const bool front = false);
|
||||
void read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset = 0, const uint8_t length = 0);
|
||||
void send_raw(const char * telegram_data);
|
||||
bool send_raw(const char * telegram_data);
|
||||
void send_poll() const;
|
||||
void retry_tx(const uint8_t operation, const uint8_t * data, const uint8_t length);
|
||||
bool is_last_tx(const uint8_t src, const uint8_t dest) const;
|
||||
uint16_t post_send_query();
|
||||
uint16_t read_next_tx(uint8_t offset);
|
||||
uint16_t read_next_tx(const uint8_t offset, const uint8_t length);
|
||||
|
||||
uint8_t retry_count() const {
|
||||
return retry_count_;
|
||||
|
||||
@@ -1046,7 +1046,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
EMSESP::show_device_values(shell);
|
||||
shell.invoke_command("call system publish");
|
||||
|
||||
// EMSESP::send_raw_telegram("B0 00 FF 18 02 62 80 00 B8");
|
||||
// EMSESP::txservice_.send_raw("B0 00 FF 18 02 62 80 00 B8");
|
||||
}
|
||||
|
||||
if (command == "heatpump") {
|
||||
@@ -1071,7 +1071,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
|
||||
rx_telegram({0xB0, 00, 0xFF, 0x18, 02, 0x62, 0x80, 00, 0xB8});
|
||||
|
||||
EMSESP::send_raw_telegram("B0 00 FF 18 02 62 80 00 B8");
|
||||
EMSESP::txservice_.send_raw("B0 00 FF 18 02 62 80 00 B8");
|
||||
|
||||
uart_telegram("30 00 FF 0A 02 6A 04"); // SM100 pump on 1
|
||||
uart_telegram("30 00 FF 00 02 64 00 00 00 04 00 00 FF 00 00 1E 0B 09 64 00 00 00 00"); // SM100 modulation
|
||||
|
||||
Reference in New Issue
Block a user