initial commit

This commit is contained in:
Martin Brodbeck 2021-12-16 16:31:51 +01:00
commit a4c00c164d
7 changed files with 145 additions and 0 deletions

24
COPYING Normal file
View file

@ -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.

7
Cargo.lock generated Normal file
View file

@ -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"

4
Cargo.toml Normal file
View file

@ -0,0 +1,4 @@
[package]
name = "clrigctl"
version = "0.1.0"
edition = "2018"

24
build-aux/cargo.sh Normal file
View file

@ -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

16
meson.build Normal file
View file

@ -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')

44
src/main.rs Normal file
View file

@ -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);
}

26
src/meson.build Normal file
View file

@ -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(),
]
)