diff --git a/components/panasonic_heatpump/commands.cpp b/components/panasonic_heatpump/commands.cpp index 447be26..3956883 100644 --- a/components/panasonic_heatpump/commands.cpp +++ b/components/panasonic_heatpump/commands.cpp @@ -5,10 +5,10 @@ namespace esphome { namespace panasonic_heatpump { - const uint8_t PanasonicCommand::InitialMessage[REQUEST_INITIAL_SIZE] = { + const uint8_t PanasonicCommand::InitialMessage[REQUEST_INIT_MSG_SIZE] = { 0x31, 0x05, 0x10, 0x01, 0x00, 0x00, 0x00, 0xB9 }; - const uint8_t PanasonicCommand::PeriodicalMessage[REQUEST_DATA_SIZE] = { + const uint8_t PanasonicCommand::PeriodicalMessage[REQUEST_DATA_MSG_SIZE] = { 0x71, 0x6C, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -18,7 +18,7 @@ namespace esphome 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12 }; - const uint8_t PanasonicCommand::CommandMessage[REQUEST_DATA_SIZE] = { + const uint8_t PanasonicCommand::CommandMessage[REQUEST_DATA_MSG_SIZE] = { 0xF1, 0x6C, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/components/panasonic_heatpump/commands.h b/components/panasonic_heatpump/commands.h index fcc8ab4..8c74e70 100644 --- a/components/panasonic_heatpump/commands.h +++ b/components/panasonic_heatpump/commands.h @@ -2,9 +2,9 @@ #include #include -#define REQUEST_INITIAL_SIZE 8 -#define REQUEST_DATA_SIZE 111 -#define REQUEST_OPTIONAL_SIZE 20 +#define REQUEST_INIT_MSG_SIZE 8 +#define REQUEST_DATA_MSG_SIZE 111 +#define REQUEST_OPTIONAL_MSG_SIZE 20 namespace esphome @@ -31,9 +31,9 @@ namespace esphome static uint8_t setByte6(uint8_t byte6, int val, int base, int bit); static uint8_t setDemandControl(size_t input); - static const uint8_t InitialMessage[REQUEST_INITIAL_SIZE]; - static const uint8_t PeriodicalMessage[REQUEST_DATA_SIZE]; - static const uint8_t CommandMessage[REQUEST_DATA_SIZE]; + static const uint8_t InitialMessage[REQUEST_INIT_MSG_SIZE]; + static const uint8_t PeriodicalMessage[REQUEST_DATA_MSG_SIZE]; + static const uint8_t CommandMessage[REQUEST_DATA_MSG_SIZE]; }; } // namespace panasonic_heatpump } // namespace esphome diff --git a/components/panasonic_heatpump/decode.cpp b/components/panasonic_heatpump/decode.cpp index cf13eeb..d8208fa 100644 --- a/components/panasonic_heatpump/decode.cpp +++ b/components/panasonic_heatpump/decode.cpp @@ -26,7 +26,7 @@ namespace esphome constexpr const char* const PanasonicDecode::Bivalent[]; constexpr const char* const PanasonicDecode::ModelNames[]; - // stores the bytes #129 to #138 of known models in the same order as the ModelNames above + // stores the bytes #129 to #138 of known models in the same order as the ModelNames static const uint8_t KnownModels[NUMBER_OF_MODELS][10] = { 0xE2, 0xCF, 0x0B, 0x13, 0x33, 0x32, 0xD1, 0x0C, 0x16, 0x33, // 0 @@ -177,7 +177,8 @@ namespace esphome uint16_t value = static_cast((input2 << 8) | input1); return (value - 1); } - + + // TOP127, TOP128 // float PanasonicDecode::getValvePID(uint8_t input) { return (((float)input - 1) / 2); diff --git a/components/panasonic_heatpump/decode.h b/components/panasonic_heatpump/decode.h index 567f58a..76b152a 100644 --- a/components/panasonic_heatpump/decode.h +++ b/components/panasonic_heatpump/decode.h @@ -3,6 +3,7 @@ #include #include +#define RESPONSE_MSG_SIZE 203 #define NUMBER_OF_MODELS 53 diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index d398517..d3d6a54 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -1,8 +1,5 @@ #include "panasonic_heatpump.h" -#define response_message_SIZE 203 -#define request_message_SIZE 111 - namespace esphome { @@ -341,9 +338,9 @@ namespace esphome // payload_length: payload_length + 3 = packet_length // checksum: if (sum(all bytes) & 0xFF == 0) ==> valid packet - if (bytes.size() != response_message_SIZE) + if (bytes.size() != RESPONSE_MSG_SIZE) { - ESP_LOGW(TAG, "Invalid response message length: recieved %d - expected %d", bytes.size(), response_message_SIZE); + ESP_LOGW(TAG, "Invalid response message length: recieved %d - expected %d", bytes.size(), RESPONSE_MSG_SIZE); delay(10); return; } @@ -511,7 +508,7 @@ namespace esphome void PanasonicHeatpumpComponent::send_initial_message() { // send command - this->uart_hp_->write_array(PanasonicCommand::InitialMessage, REQUEST_INITIAL_SIZE); + this->uart_hp_->write_array(PanasonicCommand::InitialMessage, REQUEST_INIT_MSG_SIZE); this->log_uart_hex(">>>", this->command_message_, ','); delay(100); // NOLINT } @@ -519,7 +516,7 @@ namespace esphome void PanasonicHeatpumpComponent::send_periodical_message() { // send command - this->uart_hp_->write_array(PanasonicCommand::PeriodicalMessage, REQUEST_DATA_SIZE); + this->uart_hp_->write_array(PanasonicCommand::PeriodicalMessage, REQUEST_DATA_MSG_SIZE); this->log_uart_hex(">>>", this->command_message_, ','); delay(100); // NOLINT } @@ -529,13 +526,17 @@ namespace esphome // initialize the command command_message_.clear(); command_message_.insert(this->command_message_.end(), PanasonicCommand::CommandMessage, - PanasonicCommand::CommandMessage + REQUEST_DATA_SIZE); + PanasonicCommand::CommandMessage + REQUEST_DATA_MSG_SIZE); // set command byte command_message_[index] = value; // calculate and set set checksum (last element) command_message_.back() = PanasonicCommand::calcChecksum(command_message_, command_message_.size() - 1); + + // ToDo: Wait until no request is send or stop periodic message. + // while (request_receiving_ == 1) { delay(1); } + // send command - this->uart_hp_->write_array(this->command_message_); + // this->uart_hp_->write_array(this->command_message_); this->log_uart_hex(">>>", this->command_message_, ','); delay(100); // NOLINT }