mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
allow read commands with length
This commit is contained in:
@@ -222,12 +222,16 @@ void EMSESPShell::add_console_commands() {
|
||||
[=](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments) {
|
||||
uint8_t device_id = Helpers::hextoint(arguments.front().c_str());
|
||||
uint16_t type_id = Helpers::hextoint(arguments[1].c_str());
|
||||
EMSESP::set_read_id(type_id);
|
||||
if (arguments.size() == 3) {
|
||||
if (arguments.size() == 4) {
|
||||
uint16_t offset = Helpers::hextoint(arguments[2].c_str());
|
||||
uint8_t length = Helpers::hextoint(arguments.back().c_str());
|
||||
EMSESP::send_read_request(type_id, device_id, offset, length);
|
||||
} else if (arguments.size() == 3) {
|
||||
uint16_t offset = Helpers::hextoint(arguments.back().c_str());
|
||||
EMSESP::send_read_request(type_id, device_id, offset);
|
||||
EMSESP::send_read_request(type_id, device_id, offset, EMS_MAX_TELEGRAM_LENGTH);
|
||||
} else {
|
||||
EMSESP::send_read_request(type_id, device_id);
|
||||
// send with length to send immediatly and trigger publish read_id
|
||||
EMSESP::send_read_request(type_id, device_id, 0, EMS_MAX_TELEGRAM_LENGTH);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -800,8 +800,8 @@ void EMSdevice::write_command(const uint16_t type_id, const uint8_t offset, cons
|
||||
}
|
||||
|
||||
// send Tx read command to the device
|
||||
void EMSdevice::read_command(const uint16_t type_id) {
|
||||
EMSESP::send_read_request(type_id, device_id());
|
||||
void EMSdevice::read_command(const uint16_t type_id, const uint8_t offset, const uint8_t length) {
|
||||
EMSESP::send_read_request(type_id, device_id(), offset, length);
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -279,7 +279,7 @@ class EMSdevice {
|
||||
void write_command(const uint16_t type_id, const uint8_t offset, uint8_t * message_data, const uint8_t message_length, const uint16_t validate_typeid);
|
||||
void write_command(const uint16_t type_id, const uint8_t offset, const uint8_t value, const uint16_t validate_typeid);
|
||||
void write_command(const uint16_t type_id, const uint8_t offset, const uint8_t value);
|
||||
void read_command(const uint16_t type_id);
|
||||
void read_command(const uint16_t type_id, uint8_t offset = 0, uint8_t length = 0);
|
||||
|
||||
void register_mqtt_topic(const std::string & topic, mqtt_subfunction_p f);
|
||||
void register_mqtt_cmd(const __FlashStringHelper * cmd, cmdfunction_p f, uint8_t flag = 0);
|
||||
|
||||
@@ -949,14 +949,9 @@ bool EMSESP::command_info(uint8_t device_type, JsonObject & json, const int8_t i
|
||||
return has_value;
|
||||
}
|
||||
|
||||
// send a read request, passing it into to the Tx Service, with offset
|
||||
void EMSESP::send_read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset) {
|
||||
txservice_.read_request(type_id, dest, offset);
|
||||
}
|
||||
|
||||
// send a read request, passing it into to the Tx Service, with no offset
|
||||
void EMSESP::send_read_request(const uint16_t type_id, const uint8_t dest) {
|
||||
txservice_.read_request(type_id, dest, 0); // 0 = no offset
|
||||
// send a read request, passing it into to the Tx Service, with optional offset and length
|
||||
void EMSESP::send_read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t length) {
|
||||
txservice_.read_request(type_id, dest, offset, length);
|
||||
}
|
||||
|
||||
// sends write request
|
||||
|
||||
@@ -92,8 +92,7 @@ class EMSESP {
|
||||
static bool process_telegram(std::shared_ptr<const Telegram> telegram);
|
||||
static std::string pretty_telegram(std::shared_ptr<const Telegram> telegram);
|
||||
|
||||
static void send_read_request(const uint16_t type_id, const uint8_t dest);
|
||||
static void send_read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset);
|
||||
static void send_read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset = 0, const uint8_t length = 0);
|
||||
static void send_write_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, uint8_t * message_data, const uint8_t message_length, const uint16_t validate_typeid);
|
||||
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);
|
||||
|
||||
@@ -419,7 +419,7 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt
|
||||
}
|
||||
|
||||
// build header. src, dest and offset have fixed positions
|
||||
uint8_t src = data[0];
|
||||
uint8_t src = ems_bus_id(); // data[0]; we can only send data with own bus_id.
|
||||
uint8_t dest = data[1];
|
||||
uint8_t offset = data[3];
|
||||
|
||||
@@ -485,11 +485,16 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt
|
||||
}
|
||||
|
||||
// send a Tx telegram to request data from an EMS device
|
||||
void TxService::read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset) {
|
||||
void TxService::read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t length) {
|
||||
LOG_DEBUG(F("Tx read request to device 0x%02X for type ID 0x%02X"), dest, type_id);
|
||||
|
||||
uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes
|
||||
add(Telegram::Operation::TX_READ, dest, type_id, offset, message_data, 1, 0);
|
||||
// if length set, publish result and set telegram to front
|
||||
if (length) {
|
||||
message_data[0] = length;
|
||||
EMSESP::set_read_id(type_id);
|
||||
}
|
||||
add(Telegram::Operation::TX_READ, dest, type_id, offset, message_data, 1, 0, length != 0);
|
||||
}
|
||||
|
||||
// Send a raw telegram to the bus, telegram is a text string of hex values
|
||||
|
||||
@@ -264,7 +264,7 @@ class TxService : public EMSbus {
|
||||
void send();
|
||||
void add(const uint8_t operation, const uint8_t dest, const uint16_t type_id, const uint8_t offset, uint8_t * message_data, const uint8_t message_length, const uint16_t validateid, 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);
|
||||
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);
|
||||
void send_poll();
|
||||
void retry_tx(const uint8_t operation, const uint8_t * data, const uint8_t length);
|
||||
|
||||
Reference in New Issue
Block a user