// Copyright 2022 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
#define PW_LOG_MODULE_NAME "ClientReader"

#include "rpc_demo/client/client_reader.h"

#include <pw_hdlc/decoder.h>
#include <pw_hdlc/rpc_packets.h>
#include <pw_log/log.h>
#include <pw_status/status.h>

namespace rpc_demo {

ClientReader::ClientReader(pw::stream::Reader &rx, pw::rpc::Client *rpc_client)
    : rx_(rx), rpc_client_(rpc_client), decode_buffer_(),
      decoder_(decode_buffer_) {}

bool ClientReader::ParsePacket() {
  PW_LOG_INFO("Reading bytes...");
  while (true) {
    std::byte data;
    if (auto result = rx_.Read(&data, 1); !result.ok()) {
      PW_LOG_ERROR("Failed to read data");
      continue;
    }
    PW_LOG_DEBUG("0x%02x", static_cast<uint8_t>(data));

    pw::Result<pw::hdlc::Frame> result = decoder_.Process(data);
    if (!result.ok()) {
      continue;
    }

    pw::hdlc::Frame &frame = result.value();
    if (frame.address() != pw::hdlc::kDefaultRpcAddress) {
      return false;
    }

    PW_LOG_INFO("Client got packet!");
    auto client_result = rpc_client_->ProcessPacket(frame.data());
    PW_LOG_DEBUG("Client ProcessPacket status (%s)",
                 pw_StatusString(client_result));
    decoder_.Clear();
    return true;
  }
}

} // namespace rpc_demo
