From 1490334f875e1a5749e5619192ee5aa63929cd7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Sun, 19 Jan 2025 18:22:51 +0800 Subject: [PATCH] report laser temperatures --- Makefile | 2 +- kirdy.cpp | 33 +++++++++++++++++++++++++++++++++ kirdy.hpp | 15 +++++++++++++++ sndlock.cpp | 20 +++++++++++++++++++- 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 kirdy.cpp create mode 100644 kirdy.hpp diff --git a/Makefile b/Makefile index dbb69da..66c4372 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PROG= sndlock -SRCS= imgui_impl_glfw.cpp imgui_impl_opengl3.cpp imgui_draw.cpp imgui_widgets.cpp imgui_tables.cpp imgui.cpp sndlock.cpp +SRCS= imgui_impl_glfw.cpp imgui_impl_opengl3.cpp imgui_draw.cpp imgui_widgets.cpp imgui_tables.cpp imgui.cpp kirdy.cpp sndlock.cpp CXXOPTS= -Wall `pkg-config --cflags glfw3 gl` LDFLAGS= `pkg-config --libs glfw3 gl` LDADD= -lsndio -lm diff --git a/kirdy.cpp b/kirdy.cpp new file mode 100644 index 0000000..fa92140 --- /dev/null +++ b/kirdy.cpp @@ -0,0 +1,33 @@ +#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"]; +} diff --git a/kirdy.hpp b/kirdy.hpp new file mode 100644 index 0000000..48b1886 --- /dev/null +++ b/kirdy.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +class Kirdy { + private: + asio::io_context io_context; + asio::ip::tcp::socket *socket; + nlohmann::json command(nlohmann::json &request); + public: + Kirdy(asio::string_view host, asio::string_view service); + ~Kirdy(); + float get_laser_temp(); +}; diff --git a/sndlock.cpp b/sndlock.cpp index 65ad41b..f7f7c9b 100644 --- a/sndlock.cpp +++ b/sndlock.cpp @@ -16,6 +16,7 @@ #include "dsp_lib.hpp" #include "fifo.hpp" +#include "kirdy.hpp" #define SND_BITS 24 #define SND_PCHAN 2 @@ -245,12 +246,20 @@ static void dsp_thread() sio_close(hdl); } +static const char *kirdies[SND_PCHAN][2] = { + {"192.168.1.128", "1337"}, + {"192.168.1.126", "1337"}, +}; + +static std::atomic laser_temp[SND_PCHAN]; + static void servo_thread(int channel) { Clocker clocker = Clocker(std::chrono::milliseconds(100)); + Kirdy kirdy = Kirdy(kirdies[channel][0], kirdies[channel][1]); while(!shutdown_threads) { clocker.tick(); - std::cout << "servo thread tick " << channel << std::endl; + laser_temp[channel] = kirdy.get_laser_temp(); } } @@ -418,6 +427,15 @@ int main(int argc, char* argv[]) } } + if(ImGui::CollapsingHeader("Laser servo")) { + for(int i=0;i