#include #include #include "kirdy.hpp" Kirdy::Kirdy(asio::string_view host, asio::string_view service) { asio::ip::tcp::resolver resolver(io_context); asio::ip::tcp::resolver::results_type endpoints = resolver.resolve(host, service); socket = new asio::ip::tcp::socket(io_context); asio::connect(*socket, endpoints); } Kirdy::~Kirdy() { delete socket; } nlohmann::json Kirdy::command(nlohmann::json &request) { std::string reply; asio::write(*socket, asio::buffer(request.dump() + "\n")); asio::read_until(*socket, asio::dynamic_buffer(reply, 1024), '\n'); return nlohmann::json::parse(reply); } float Kirdy::get_laser_temp() { nlohmann::json json; json["device_cmd"] = "GetStatusReport"; auto reply = command(json); return reply["thermostat"]["temperature"]; }