check command send for valid data

This commit is contained in:
MichaelDvP
2022-09-13 07:54:36 +02:00
parent df8a36c695
commit e70b6b210e
6 changed files with 12 additions and 15 deletions

View File

@@ -1275,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() {

View File

@@ -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);

View File

@@ -108,8 +108,7 @@ bool System::command_pin(const char * value, const int8_t id) {
// 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

View File

@@ -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

View File

@@ -304,7 +304,7 @@ 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;

View File

@@ -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