/**
 * @file conveyor_example.cpp
 * @brief 传送带示例
 *
 * @copyright Copyright (C) 2026 ROKAE (Beijing) Technology Co., LTD. All Rights Reserved.
 * Information in this file is the intellectual property of Rokae Technology Co., Ltd,
 * And may contains trade secrets that must be stored and viewed confidentially.
 */

#include <iostream>
#include "rokae/robot.h"
#include "rokae/conveyor.h"
#include "print_helper.hpp"

std::ostream &operator<<(std::ostream &os, const rokae::ConveyorState &state) {
  os << "ConveyorState: " << std::endl;
  os << "  name: " << state.name << std::endl;
  os << "  Encoder value: " << state.encoder_value << std::endl;
  os << "  Encoder correction value: " << state.encoder_correction_value << std::endl;
  os << "  Speed: " << state.speed << std::endl;
  os << "  Photoelectric state: " << state.photoelectric_state << " mm/s" << std::endl;
  os << "  Wobj position: " << state.wobj_position << " mm" << std::endl;
  return os;
}

int main() {
  using namespace rokae;
  xMateRobot robot;
  try {
    auto remote_ip = "192.168.0.160";
    robot.connectToRobot(remote_ip);
  } catch (const std::exception& e) {
    std::cout << "Failed to connect to robot: " << e.what() << std::endl;
    return -1;
  }

  BaseConveyor conveyor(robot.getXService());
  error_code ec;
  // 读取传送带状态
  for (const auto& state : conveyor.getConveyorState(ec)) {
    std::cout << state << std::endl;
  }
  print(std::cout, ec);

  return 0;
}