Skip to content

Commit

Permalink
Fixing proxy message sending 2
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldn committed Feb 4, 2024
1 parent a27d1c3 commit 2c6d583
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions include/transport/protocol_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TransportLevelHandler
explicit TransportLevelHandler(ProtocolStream& stream, size_t buffer_size = MAX_FRAME_SIZE + 0x10) noexcept;
virtual ~TransportLevelHandler();
uint8_t send_data(uint8_t frameType, const uint8_t* data, size_t data_size, bool use_crc=true);
uint8_t send_data(const HaierFrame& frame);
size_t read_data();
void process_data();
size_t available() const noexcept { return this->incoming_queue_.size(); };
Expand Down
26 changes: 13 additions & 13 deletions src/protocol/haier_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void ProtocolHandler::loop()
if (this->proxy_transport_)
{
// If proxy defined redirect frame to proxy transport
this->proxy_transport_->send_data(frame.frame.get_frame_type(), frame.frame.get_data(), frame.frame.get_data_size(), frame.frame.get_use_crc());
this->proxy_transport_->send_data(frame.frame);
}
}
if (this->proxy_transport_)
Expand Down Expand Up @@ -164,20 +164,20 @@ void ProtocolHandler::loop()
TimestampedFrame frame;
if (this->transport_.pop(frame))
{
this->proxy_transport_->send_data(frame.frame.get_frame_type(), frame.frame.get_data(), frame.frame.get_data_size(), frame.frame.get_use_crc());
this->proxy_transport_->send_data(frame.frame);
FrameType msg_type = (FrameType) frame.frame.get_frame_type();
HandlerError hres;
std::map<FrameType, AnswerHandler>::const_iterator handler = this->answer_handlers_map_.find(last_message_type_);
if (handler != this->answer_handlers_map_.end())
hres = handler->second(this->last_message_type_, msg_type, frame.frame.get_data(), frame.frame.get_data_size(), AnswerDestination::PROXY_ANSWER);
else
hres = this->default_answer_handler_(this->last_message_type_, msg_type, frame.frame.get_data(), frame.frame.get_data_size(), AnswerDestination::PROXY_ANSWER);
if (hres != HandlerError::HANDLER_OK)
{
HAIER_LOGW("Proxy answer handler error, msg=%02X, answ=%02X, err=%d", this->last_message_type_, msg_type, hres);
}
this->state_ = ProtocolState::IDLE;
}
FrameType msg_type = (FrameType) frame.frame.get_frame_type();
HandlerError hres;
std::map<FrameType, AnswerHandler>::const_iterator handler = this->answer_handlers_map_.find(last_message_type_);
if (handler != this->answer_handlers_map_.end())
hres = handler->second(this->last_message_type_, msg_type, frame.frame.get_data(), frame.frame.get_data_size(), AnswerDestination::PROXY_ANSWER);
else
hres = this->default_answer_handler_(this->last_message_type_, msg_type, frame.frame.get_data(), frame.frame.get_data_size(), AnswerDestination::PROXY_ANSWER);
if (hres != HandlerError::HANDLER_OK)
{
HAIER_LOGW("Proxy answer handler error, msg=%02X, answ=%02X, err=%d", this->last_message_type_, msg_type, hres);
}
}
else
this->state_ = ProtocolState::IDLE;
Expand Down
11 changes: 8 additions & 3 deletions src/transport/protocol_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ uint8_t TransportLevelHandler::send_data(uint8_t frame_type, const uint8_t *data
{
if (data_size > MAX_FRAME_SIZE - PURE_HEADER_SIZE)
return 0;
HaierFrame frame = HaierFrame(frame_type, data, (uint8_t)data_size, use_crc);
return send_data(frame);
}

uint8_t TransportLevelHandler::send_data(const haier_protocol::HaierFrame& frame)
{
#if (HAIER_LOG_LEVEL > 3)
static char _header[]{"Sending frame: type 00, data:"};
const char *_p = hex_map + (frame_type * 2);
const char *_p = hex_map + (frame.get_frame_type() * 2);
_header[20] = _p[0];
_header[21] = _p[1];
HAIER_BUFD(_header, data, data_size);
HAIER_BUFD(_header, frame.get_data(), frame.get_data_size());
#endif
HaierFrame frame = HaierFrame(frame_type, data, (uint8_t)data_size, use_crc);
size_t size = frame.get_buffer_size();
std::unique_ptr<uint8_t[]> tmp_buf(new uint8_t[size]);
frame.fill_buffer(tmp_buf.get(), size);
Expand Down

0 comments on commit 2c6d583

Please sign in to comment.