control Rigol PSU
This commit is contained in:
parent
5b8f284a41
commit
1b363e7de9
2
Makefile
2
Makefile
@ -4,7 +4,7 @@ SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui
|
||||
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
|
||||
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
|
||||
|
||||
CXXFLAGS = -std=c++14 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I$(POCKETFFT_DIR)
|
||||
CXXFLAGS = -std=c++20 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I$(POCKETFFT_DIR)
|
||||
CXXFLAGS += -g -Wall -Wformat -O2
|
||||
|
||||
LIBS += -lGL `pkg-config --static --libs glfw3 libbladeRF`
|
||||
|
7
flake.lock
generated
7
flake.lock
generated
@ -2,16 +2,15 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1693953029,
|
||||
"narHash": "sha256-1+28KQl4YC4IBzKo/epvEyK5KH4MlgoYueJ8YwLGbOc=",
|
||||
"lastModified": 1694427587,
|
||||
"narHash": "sha256-1DIVQFhmCt6N4AzF1QwqEE758JmQRDs4vpSC2RpjjTg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "4077a0e4ac3356222bc1f0a070af7939c3098535",
|
||||
"rev": "6559511e312129514eecd392cc530fafa858f7b7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-23.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
11
flake.nix
11
flake.nix
@ -1,11 +1,14 @@
|
||||
{
|
||||
description = "Micro Optical Spectrum Analyzer";
|
||||
|
||||
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-23.05;
|
||||
inputs.nixpkgs.url = github:NixOS/nixpkgs;
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
pkgs = import nixpkgs {
|
||||
system = "x86_64-linux";
|
||||
#config = { replaceStdenv = ({ pkgs }: pkgs.gcc13Stdenv); };
|
||||
};
|
||||
imgui_dir = "${pkgs.imgui}/include/imgui";
|
||||
pocketfft = pkgs.fetchgit {
|
||||
url = "https://gitlab.mpcdf.mpg.de/mtr/pocketfft.git";
|
||||
@ -13,7 +16,7 @@
|
||||
hash = "sha256-xl7Tr1A1cqXhAL1Bljfk68R3AB1xOgkH15LHKxjYoSc=";
|
||||
};
|
||||
in rec {
|
||||
packages.x86_64-linux.fastsa = pkgs.stdenv.mkDerivation {
|
||||
packages.x86_64-linux.fastsa = pkgs.gcc13Stdenv.mkDerivation {
|
||||
name = "fastsa";
|
||||
src = self;
|
||||
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||
@ -27,7 +30,7 @@
|
||||
cp fastsa $out/bin
|
||||
'';
|
||||
};
|
||||
devShell.x86_64-linux = pkgs.mkShell {
|
||||
devShell.x86_64-linux = pkgs.mkShell.override { stdenv = pkgs.gcc13Stdenv; } {
|
||||
name = "fastsa-dev-shell";
|
||||
buildInputs = packages.x86_64-linux.fastsa.nativeBuildInputs ++ packages.x86_64-linux.fastsa.propagatedBuildInputs;
|
||||
shellHook = packages.x86_64-linux.fastsa.preBuild;
|
||||
|
25
main.cpp
25
main.cpp
@ -7,6 +7,8 @@
|
||||
#include <vector>
|
||||
#include <complex>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <experimental/net>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
@ -20,6 +22,7 @@
|
||||
#define POCKETFFT_NO_MULTITHREADING // MT doesn't seem to help at small sizes
|
||||
#include <pocketfft_hdronly.h>
|
||||
|
||||
namespace net = std::experimental::net;
|
||||
|
||||
static std::atomic<bool> terminate_dsp;
|
||||
|
||||
@ -35,9 +38,12 @@ static std::atomic<int> fps;
|
||||
static void dsp_thread() {
|
||||
using namespace std::literals::chrono_literals;
|
||||
|
||||
net::io_context io_context;
|
||||
net::ip::tcp::socket tec_socket(io_context);
|
||||
tec_socket.connect(net::ip::tcp::endpoint(net::ip::make_address("192.168.1.91"), 5555));
|
||||
|
||||
size_t len = 16384;
|
||||
std::vector<std::complex<int16_t>> frames(len);
|
||||
|
||||
std::vector<std::complex<float>> frames_f(len);
|
||||
pocketfft::shape_t shape{len};
|
||||
pocketfft::stride_t stride(1);
|
||||
@ -45,17 +51,30 @@ static void dsp_thread() {
|
||||
pocketfft::shape_t axes;
|
||||
axes.push_back(0);
|
||||
std::vector<std::complex<float>> frames_ft(len);
|
||||
|
||||
int iterations = 0;
|
||||
auto last_second = std::chrono::steady_clock::now();
|
||||
auto last_tec = std::chrono::steady_clock::now();
|
||||
while(!terminate_dsp) {
|
||||
int status;
|
||||
if((status = bladerf_sync_rx(bladerf_dev, frames.data(), len, NULL, 0)) != 0) {
|
||||
std::cerr << "failed to receive samples from bladeRF: " << bladerf_strerror(status) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
// FFT
|
||||
for(size_t i=0;i<len;i++)
|
||||
frames_f[i] = frames[i];
|
||||
pocketfft::c2c(shape, stride, stride, axes, pocketfft::FORWARD, frames_f.data(), frames_ft.data(), 1.0f);
|
||||
|
||||
// stabilize laser
|
||||
if((std::chrono::steady_clock::now() - last_tec) >= 100ms) {
|
||||
// FIXME: net::write seems unimplemented as of libstdc++ 13
|
||||
tec_socket.write_some(net::buffer(std::format(":SOUR2:VOLT {:.3f}\n", 0.1)));
|
||||
last_tec += 100ms;
|
||||
}
|
||||
|
||||
// update waterfall
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(waterfall_data_mutex);
|
||||
std::memmove(&waterfall_data[waterfall_width], &waterfall_data[0], sizeof(int)*waterfall_width*(waterfall_height - 1));
|
||||
@ -65,13 +84,15 @@ static void dsp_thread() {
|
||||
waterfall_data[i] = 0xff000000 | 0x010101*std::min(int(abs(frames_ft[j])/900.), 255);
|
||||
}
|
||||
}
|
||||
|
||||
// FPS counter
|
||||
iterations++;
|
||||
if((std::chrono::steady_clock::now() - last_second) >= 1s) {
|
||||
fps = iterations;
|
||||
iterations = 0;
|
||||
last_second += 1s;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
Loading…
Reference in New Issue
Block a user