From a4c00c164d23537b261fb5b356dfa6fc94d4ab9f Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 16 Dec 2021 16:31:51 +0100 Subject: [PATCH] initial commit --- COPYING | 24 ++++++++++++++++++++++++ Cargo.lock | 7 +++++++ Cargo.toml | 4 ++++ build-aux/cargo.sh | 24 ++++++++++++++++++++++++ meson.build | 16 ++++++++++++++++ src/main.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/meson.build | 26 ++++++++++++++++++++++++++ 7 files changed, 145 insertions(+) create mode 100644 COPYING create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 build-aux/cargo.sh create mode 100644 meson.build create mode 100644 src/main.rs create mode 100644 src/meson.build diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..88422d8 --- /dev/null +++ b/COPYING @@ -0,0 +1,24 @@ +Copyright (C) 2021 Martin Brodbeck +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name(s) of the above copyright +holders shall not be used in advertising or otherwise to promote the sale, +use or other dealings in this Software without prior written +authorization. diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..24572c0 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "clrigctl" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b6348f2 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "clrigctl" +version = "0.1.0" +edition = "2018" diff --git a/build-aux/cargo.sh b/build-aux/cargo.sh new file mode 100644 index 0000000..3c37396 --- /dev/null +++ b/build-aux/cargo.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +export MESON_BUILD_ROOT="$1" +export MESON_SOURCE_ROOT="$2" +export CARGO_TARGET_DIR="$MESON_BUILD_ROOT"/target +export CARGO_HOME="$MESON_BUILD_ROOT"/cargo-home +export OUTPUT="$3" +export BUILDTYPE="$4" +export APP_BIN="$5" + + +if [ $BUILDTYPE = "release" ] +then + echo "RELEASE MODE" + cargo build --manifest-path \ + "$MESON_SOURCE_ROOT"/Cargo.toml --release && \ + cp "$CARGO_TARGET_DIR"/release/"$APP_BIN" "$OUTPUT" +else + echo "DEBUG MODE" + cargo build --manifest-path \ + "$MESON_SOURCE_ROOT"/Cargo.toml && \ + cp "$CARGO_TARGET_DIR"/debug/"$APP_BIN" "$OUTPUT" +fi + diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..c8e1dac --- /dev/null +++ b/meson.build @@ -0,0 +1,16 @@ +project('clrigctl', 'rust', + version: '0.1.0', + meson_version: '>= 0.50.0', + default_options: [ 'warning_level=2', + ], +) + + + +cargo_sources = files( + 'Cargo.toml', + 'Cargo.lock', +) + +subdir('src') + diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4312e09 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,44 @@ +use std::io::prelude::*; +use std::net::TcpStream; +use std::str; + +pub struct RigCtl +{ + pub stream: TcpStream, +} + +impl RigCtl { + pub fn new() -> Self { + let stream = TcpStream::connect("127.0.0.1:4532").unwrap(); + RigCtl { + stream: stream, + } + } + + pub fn get_frequency(&mut self) -> String { + self.stream.write(b"f").unwrap(); + let mut buffer = [0; 64]; + self.stream.read(&mut buffer[..]).unwrap(); + let freq = str::from_utf8(&buffer).unwrap().lines().next().unwrap().to_string(); + freq + } + + pub fn get_mode(&mut self) -> (String, String) { + self.stream.write(b"m").unwrap(); + let mut buffer = [0; 64]; + self.stream.read(&mut buffer[..]).unwrap(); + let mut retvals = str::from_utf8(&buffer).unwrap().lines(); + let mode = retvals.next().unwrap().to_string(); + let passband = retvals.next().unwrap().to_string(); + (mode, passband) + } +} + +fn main() { + let mut rigctl = RigCtl::new(); + let freq = rigctl.get_frequency(); + println!("Frequenz: {} Hz", freq); + + let (mode, passband) = rigctl.get_mode(); + println!("Mode: {} – Passband: {}", mode, passband); +} diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..3b8a5f3 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,26 @@ +clrigctl_sources = [ + cargo_sources, + 'main.rs', +] + +clrigctl_deps = [ +] + +cargo_script = find_program(join_paths(meson.source_root(), 'build-aux/cargo.sh')) +cargo_release = custom_target( + 'cargo-build', + build_by_default: true, + input: clrigctl_sources, + output: meson.project_name(), + console: true, + install: true, + install_dir: get_option('bindir'), + command: [ + cargo_script, + meson.build_root(), + meson.source_root(), + '@OUTPUT@', + get_option('buildtype'), + meson.project_name(), + ] +)