Compare commits
14 Commits
main
...
5853187cd6
| Author | SHA1 | Date | |
|---|---|---|---|
| 5853187cd6 | |||
| d3b882f56d | |||
| 4aa86da14a | |||
| 42a09e8b0f | |||
| b8475a12ad | |||
| 778c1a0dfd | |||
| 0e28b0416a | |||
| 6fdbb868b7 | |||
| a3aeff1d6f | |||
| 6a5e3e2b24 | |||
| 9228bca4eb | |||
| 6980b7f6aa | |||
| 29f7f6d83b | |||
| 8d737e8f33 |
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1953,7 +1953,6 @@ dependencies = [
|
|||||||
"fern",
|
"fern",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"num-traits",
|
|
||||||
"papaya",
|
"papaya",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|||||||
@@ -2,17 +2,10 @@
|
|||||||
members = ["api", "api-core", "api-proc-macro", "server", "examples/simple_producer", "examples/simple_command"]
|
members = ["api", "api-core", "api-proc-macro", "server", "examples/simple_producer", "examples/simple_command"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Sergey <me@sergeysav.com>"]
|
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
actix-web = "4.12.1"
|
actix-web = "4.12.1"
|
||||||
actix-ws = "0.3.0"
|
actix-ws = "0.3.0"
|
||||||
anyhow = "1.0.100"
|
anyhow = "1.0.100"
|
||||||
api = { path = "./api" }
|
|
||||||
api-core = { path = "./api-core" }
|
|
||||||
api-proc-macro = { path = "./api-proc-macro" }
|
|
||||||
chrono = { version = "0.4.42" }
|
chrono = { version = "0.4.42" }
|
||||||
derive_more = { version = "2.1.1" }
|
derive_more = { version = "2.1.1" }
|
||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
@@ -29,8 +22,8 @@ sqlx = "0.8.6"
|
|||||||
syn = "2.0.112"
|
syn = "2.0.112"
|
||||||
thiserror = "2.0.17"
|
thiserror = "2.0.17"
|
||||||
tokio = { version = "1.48.0" }
|
tokio = { version = "1.48.0" }
|
||||||
tokio-stream = "0.1.17"
|
|
||||||
tokio-test = "0.4.4"
|
tokio-test = "0.4.4"
|
||||||
|
tokio-stream = "0.1.17"
|
||||||
tokio-tungstenite = { version = "0.28.0" }
|
tokio-tungstenite = { version = "0.28.0" }
|
||||||
tokio-util = "0.7.17"
|
tokio-util = "0.7.17"
|
||||||
trybuild = "1.0.114"
|
trybuild = "1.0.114"
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "api-core"
|
name = "api-core"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
version.workspace = true
|
version = "0.1.0"
|
||||||
authors.workspace = true
|
authors = ["Sergey <me@sergeysav.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { workspace = true, features = ["serde"] }
|
chrono = { workspace = true, features = ["serde"] }
|
||||||
|
|||||||
@@ -45,16 +45,3 @@ pub trait IntoCommandDefinition: Sized {
|
|||||||
|
|
||||||
fn parse(command: Command) -> Result<Self, IntoCommandDefinitionError>;
|
fn parse(command: Command) -> Result<Self, IntoCommandDefinitionError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoCommandDefinition for () {
|
|
||||||
fn create(name: String) -> CommandDefinition {
|
|
||||||
CommandDefinition {
|
|
||||||
name,
|
|
||||||
parameters: vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse(_: Command) -> Result<Self, IntoCommandDefinitionError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,32 +7,6 @@ pub enum DataType {
|
|||||||
Float32,
|
Float32,
|
||||||
Float64,
|
Float64,
|
||||||
Boolean,
|
Boolean,
|
||||||
Int8,
|
|
||||||
Int16,
|
|
||||||
Int32,
|
|
||||||
Int64,
|
|
||||||
Unsigned8,
|
|
||||||
Unsigned16,
|
|
||||||
Unsigned32,
|
|
||||||
Unsigned64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DataType {
|
|
||||||
pub fn get_data_length(self) -> u64 {
|
|
||||||
match self {
|
|
||||||
DataType::Float32 => 4,
|
|
||||||
DataType::Float64 => 8,
|
|
||||||
DataType::Boolean => 1,
|
|
||||||
DataType::Int8 => 1,
|
|
||||||
DataType::Int16 => 2,
|
|
||||||
DataType::Int32 => 4,
|
|
||||||
DataType::Int64 => 8,
|
|
||||||
DataType::Unsigned8 => 1,
|
|
||||||
DataType::Unsigned16 => 2,
|
|
||||||
DataType::Unsigned32 => 4,
|
|
||||||
DataType::Unsigned64 => 8,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToDataType: Into<DataValue> {
|
pub trait ToDataType: Into<DataValue> {
|
||||||
@@ -50,11 +24,3 @@ macro_rules! impl_to_data_type {
|
|||||||
impl_to_data_type!(f32, DataType::Float32);
|
impl_to_data_type!(f32, DataType::Float32);
|
||||||
impl_to_data_type!(f64, DataType::Float64);
|
impl_to_data_type!(f64, DataType::Float64);
|
||||||
impl_to_data_type!(bool, DataType::Boolean);
|
impl_to_data_type!(bool, DataType::Boolean);
|
||||||
impl_to_data_type!(i8, DataType::Int8);
|
|
||||||
impl_to_data_type!(i16, DataType::Int16);
|
|
||||||
impl_to_data_type!(i32, DataType::Int32);
|
|
||||||
impl_to_data_type!(i64, DataType::Int64);
|
|
||||||
impl_to_data_type!(u8, DataType::Unsigned8);
|
|
||||||
impl_to_data_type!(u16, DataType::Unsigned16);
|
|
||||||
impl_to_data_type!(u32, DataType::Unsigned32);
|
|
||||||
impl_to_data_type!(u64, DataType::Unsigned64);
|
|
||||||
|
|||||||
@@ -7,14 +7,6 @@ pub enum DataValue {
|
|||||||
Float32(f32),
|
Float32(f32),
|
||||||
Float64(f64),
|
Float64(f64),
|
||||||
Boolean(bool),
|
Boolean(bool),
|
||||||
Int8(i8),
|
|
||||||
Int16(i16),
|
|
||||||
Int32(i32),
|
|
||||||
Int64(i64),
|
|
||||||
Unsigned8(u8),
|
|
||||||
Unsigned16(u16),
|
|
||||||
Unsigned32(u32),
|
|
||||||
Unsigned64(u64),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DataValue {
|
impl DataValue {
|
||||||
@@ -23,14 +15,6 @@ impl DataValue {
|
|||||||
DataValue::Float32(_) => DataType::Float32,
|
DataValue::Float32(_) => DataType::Float32,
|
||||||
DataValue::Float64(_) => DataType::Float64,
|
DataValue::Float64(_) => DataType::Float64,
|
||||||
DataValue::Boolean(_) => DataType::Boolean,
|
DataValue::Boolean(_) => DataType::Boolean,
|
||||||
DataValue::Int8(_) => DataType::Int8,
|
|
||||||
DataValue::Int16(_) => DataType::Int16,
|
|
||||||
DataValue::Int32(_) => DataType::Int32,
|
|
||||||
DataValue::Int64(_) => DataType::Int64,
|
|
||||||
DataValue::Unsigned8(_) => DataType::Unsigned8,
|
|
||||||
DataValue::Unsigned16(_) => DataType::Unsigned16,
|
|
||||||
DataValue::Unsigned32(_) => DataType::Unsigned32,
|
|
||||||
DataValue::Unsigned64(_) => DataType::Unsigned64,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,18 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "api-proc-macro"
|
name = "api-proc-macro"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
version.workspace = true
|
version = "0.1.0"
|
||||||
authors.workspace = true
|
authors = ["Sergey <me@sergeysav.com>"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
api-core = { workspace = true }
|
api-core = { path = "../api-core" }
|
||||||
proc-macro-error = { workspace = true }
|
proc-macro-error = { workspace = true }
|
||||||
quote = { workspace = true }
|
quote = { workspace = true }
|
||||||
syn = { workspace = true }
|
syn = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
api = { workspace = true }
|
api = { path = "../api" }
|
||||||
trybuild = { workspace = true }
|
trybuild = { workspace = true }
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "api"
|
name = "api"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
version.workspace = true
|
version = "0.1.0"
|
||||||
authors.workspace = true
|
authors = ["Sergey <me@sergeysav.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
api-core = { workspace = true }
|
api-core = { path = "../api-core" }
|
||||||
api-proc-macro = { workspace = true }
|
api-proc-macro = { path = "../api-proc-macro" }
|
||||||
chrono = { workspace = true, features = ["serde"] }
|
chrono = { workspace = true, features = ["serde"] }
|
||||||
derive_more = { workspace = true, features = ["from", "try_into"] }
|
derive_more = { workspace = true, features = ["from", "try_into"] }
|
||||||
futures-util = { workspace = true }
|
futures-util = { workspace = true }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::client::Client;
|
use crate::client::Client;
|
||||||
use crate::messages::command::CommandResponse;
|
use crate::messages::command::CommandResponse;
|
||||||
use api_core::command::{Command, CommandDefinition, CommandHeader, IntoCommandDefinition};
|
use api_core::command::{CommandHeader, IntoCommandDefinition};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
@@ -15,13 +15,13 @@ impl CommandRegistry {
|
|||||||
Self { client }
|
Self { client }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_raw_handler<F, E: Display>(
|
pub fn register_handler<C: IntoCommandDefinition, F, E: Display>(
|
||||||
&self,
|
&self,
|
||||||
command_definition: CommandDefinition,
|
command_name: impl Into<String>,
|
||||||
mut callback: F,
|
mut callback: F,
|
||||||
) -> CommandHandle
|
) -> CommandHandle
|
||||||
where
|
where
|
||||||
F: FnMut(Command) -> Result<String, E> + Send + 'static,
|
F: FnMut(CommandHeader, C) -> Result<String, E> + Send + 'static,
|
||||||
{
|
{
|
||||||
let cancellation_token = CancellationToken::new();
|
let cancellation_token = CancellationToken::new();
|
||||||
let result = CommandHandle {
|
let result = CommandHandle {
|
||||||
@@ -29,6 +29,8 @@ impl CommandRegistry {
|
|||||||
};
|
};
|
||||||
let client = self.client.clone();
|
let client = self.client.clone();
|
||||||
|
|
||||||
|
let command_definition = C::create(command_name.into());
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while !cancellation_token.is_cancelled() {
|
while !cancellation_token.is_cancelled() {
|
||||||
// This would only fail if the sender closed while trying to insert data
|
// This would only fail if the sender closed while trying to insert data
|
||||||
@@ -45,10 +47,17 @@ impl CommandRegistry {
|
|||||||
select!(
|
select!(
|
||||||
rx_value = rx.recv() => {
|
rx_value = rx.recv() => {
|
||||||
if let Some((cmd, responder)) = rx_value {
|
if let Some((cmd, responder)) = rx_value {
|
||||||
let response = match callback(cmd) {
|
let header = cmd.header.clone();
|
||||||
Ok(response) => CommandResponse {
|
let response = match C::parse(cmd) {
|
||||||
success: true,
|
Ok(cmd) => match callback(header, cmd) {
|
||||||
response,
|
Ok(response) => CommandResponse {
|
||||||
|
success: true,
|
||||||
|
response,
|
||||||
|
},
|
||||||
|
Err(err) => CommandResponse {
|
||||||
|
success: false,
|
||||||
|
response: err.to_string(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Err(err) => CommandResponse {
|
Err(err) => CommandResponse {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -69,23 +78,6 @@ impl CommandRegistry {
|
|||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_handler<C: IntoCommandDefinition, F, E>(
|
|
||||||
&self,
|
|
||||||
command_name: impl Into<String>,
|
|
||||||
mut callback: F,
|
|
||||||
) -> CommandHandle
|
|
||||||
where
|
|
||||||
F: FnMut(CommandHeader, C) -> Result<String, E> + Send + 'static,
|
|
||||||
E: Display,
|
|
||||||
{
|
|
||||||
self.register_raw_handler(C::create(command_name.into()), move |command: Command| {
|
|
||||||
let header = command.header.clone();
|
|
||||||
C::parse(command)
|
|
||||||
.map_err(|e| e.to_string())
|
|
||||||
.and_then(|cmd| callback(header, cmd).map_err(|err| err.to_string()))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CommandHandle {
|
pub struct CommandHandle {
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ impl Client {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println!("Exited Loop");
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(outer_rx)
|
Ok(outer_rx)
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ mod tests {
|
|||||||
let (mut rx, _c, client) = create_test_client();
|
let (mut rx, _c, client) = create_test_client();
|
||||||
|
|
||||||
let tlm = TelemetryRegistry::new(Arc::new(client));
|
let tlm = TelemetryRegistry::new(Arc::new(client));
|
||||||
let tlm_handle = tlm.register::<bool>("typed");
|
let tlm_handle = tlm.register::<f32>("typed");
|
||||||
|
|
||||||
let tlm_uuid = Uuid::new_v4();
|
let tlm_uuid = Uuid::new_v4();
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ mod tests {
|
|||||||
panic!("Expected Telemetry Definition Request")
|
panic!("Expected Telemetry Definition Request")
|
||||||
};
|
};
|
||||||
assert_eq!(name, "typed".to_string());
|
assert_eq!(name, "typed".to_string());
|
||||||
assert_eq!(data_type, DataType::Boolean);
|
assert_eq!(data_type, DataType::Float32);
|
||||||
responder
|
responder
|
||||||
.send(ResponseMessage {
|
.send(ResponseMessage {
|
||||||
uuid: Uuid::new_v4(),
|
uuid: Uuid::new_v4(),
|
||||||
@@ -357,12 +357,15 @@ mod tests {
|
|||||||
|
|
||||||
// This should NOT block if there is space in the queue
|
// This should NOT block if there is space in the queue
|
||||||
tlm_handle
|
tlm_handle
|
||||||
.publish_now(true)
|
.publish_now(1.0f32.into())
|
||||||
.now_or_never()
|
.now_or_never()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// This should block as there should not be space in the queue
|
// This should block as there should not be space in the queue
|
||||||
assert!(tlm_handle.publish_now(false).now_or_never().is_none());
|
assert!(tlm_handle
|
||||||
|
.publish_now(2.0f32.into())
|
||||||
|
.now_or_never()
|
||||||
|
.is_none());
|
||||||
|
|
||||||
let tlm_msg = timeout(Duration::from_secs(1), rx.recv())
|
let tlm_msg = timeout(Duration::from_secs(1), rx.recv())
|
||||||
.await
|
.await
|
||||||
@@ -372,7 +375,7 @@ mod tests {
|
|||||||
match tlm_msg.msg.payload {
|
match tlm_msg.msg.payload {
|
||||||
RequestMessagePayload::TelemetryEntry(TelemetryEntry { uuid, value, .. }) => {
|
RequestMessagePayload::TelemetryEntry(TelemetryEntry { uuid, value, .. }) => {
|
||||||
assert_eq!(uuid, tlm_uuid);
|
assert_eq!(uuid, tlm_uuid);
|
||||||
assert_eq!(value, DataValue::Boolean(true));
|
assert_eq!(value, DataValue::Float32(1.0f32));
|
||||||
}
|
}
|
||||||
_ => panic!("Expected Telemetry Entry"),
|
_ => panic!("Expected Telemetry Entry"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
api = { workspace = true }
|
api = { path = "../../api" }
|
||||||
env_logger = { workspace = true }
|
env_logger = { workspace = true }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
tokio = { workspace = true, features = ["rt-multi-thread", "signal"] }
|
tokio = { workspace = true, features = ["rt-multi-thread", "signal"] }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
api = { workspace = true }
|
api = { path = "../../api" }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
env_logger = { workspace = true }
|
env_logger = { workspace = true }
|
||||||
futures-util = { workspace = true }
|
futures-util = { workspace = true }
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ import { computed, onMounted } from 'vue';
|
|||||||
import {
|
import {
|
||||||
type AnyTypeId,
|
type AnyTypeId,
|
||||||
type DynamicDataType,
|
type DynamicDataType,
|
||||||
getLimits,
|
|
||||||
isBooleanType,
|
isBooleanType,
|
||||||
isNumericType,
|
isNumericType,
|
||||||
type NumericLimits,
|
|
||||||
} from '@/composables/dynamic.ts';
|
} from '@/composables/dynamic.ts';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -19,100 +17,23 @@ const is_numeric = computed(() => {
|
|||||||
return isNumericType(props.type);
|
return isNumericType(props.type);
|
||||||
});
|
});
|
||||||
|
|
||||||
const numeric_limit = computed(() => {
|
|
||||||
if (isNumericType(props.type)) {
|
|
||||||
return getLimits(props.type);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
min: 0,
|
|
||||||
max: 0,
|
|
||||||
integer: false,
|
|
||||||
is_big: false,
|
|
||||||
} as NumericLimits;
|
|
||||||
});
|
|
||||||
|
|
||||||
const is_boolean = computed(() => {
|
const is_boolean = computed(() => {
|
||||||
return isBooleanType(props.type);
|
return isBooleanType(props.type);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize the parameter to some value:
|
// Initialize the parameter to some value:
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (model.value === undefined) {
|
if (is_numeric.value) {
|
||||||
if (is_numeric.value) {
|
model.value = 0.0;
|
||||||
if (numeric_limit.value.integer) {
|
} else if (is_boolean.value) {
|
||||||
if (numeric_limit.value.is_big) {
|
model.value = false;
|
||||||
model.value = 0n;
|
|
||||||
} else {
|
|
||||||
model.value = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
model.value = 0.0;
|
|
||||||
}
|
|
||||||
} else if (is_boolean.value) {
|
|
||||||
model.value = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const value = computed({
|
|
||||||
get: () => {
|
|
||||||
if (is_numeric.value) {
|
|
||||||
if (numeric_limit.value.is_big) {
|
|
||||||
return ((model.value || 0n) as bigint).toString();
|
|
||||||
} else {
|
|
||||||
return model.value as number;
|
|
||||||
}
|
|
||||||
} else if (is_boolean.value) {
|
|
||||||
// Force it into a boolean
|
|
||||||
return !!model.value;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
set: (value) => {
|
|
||||||
if (is_numeric.value) {
|
|
||||||
if (numeric_limit.value.is_big) {
|
|
||||||
let result = BigInt(value as string);
|
|
||||||
if (result > (numeric_limit.value.max as bigint)) {
|
|
||||||
result = numeric_limit.value.max as bigint;
|
|
||||||
} else if (result < (numeric_limit.value.min as bigint)) {
|
|
||||||
result = numeric_limit.value.min as bigint;
|
|
||||||
}
|
|
||||||
model.value = result;
|
|
||||||
} else {
|
|
||||||
let result_value = value as number;
|
|
||||||
if (numeric_limit.value.integer) {
|
|
||||||
result_value = Math.round(value as number);
|
|
||||||
}
|
|
||||||
if (result_value > (numeric_limit.value.max as number)) {
|
|
||||||
result_value = numeric_limit.value.max as number;
|
|
||||||
} else if (result_value < (numeric_limit.value.min as number)) {
|
|
||||||
result_value = numeric_limit.value.min as number;
|
|
||||||
}
|
|
||||||
model.value = result_value;
|
|
||||||
}
|
|
||||||
} else if (is_boolean.value) {
|
|
||||||
model.value = value as boolean;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<input
|
<input v-if="is_numeric" type="number" v-model="model" />
|
||||||
v-if="is_numeric && !numeric_limit.is_big"
|
<input v-else-if="is_boolean" type="checkbox" v-model="model" />
|
||||||
type="number"
|
|
||||||
v-model="value"
|
|
||||||
:max="numeric_limit.max as number"
|
|
||||||
:min="numeric_limit.min as number"
|
|
||||||
:step="numeric_limit.integer ? 1 : undefined"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
v-else-if="is_numeric && numeric_limit.is_big"
|
|
||||||
type="text"
|
|
||||||
v-model="value"
|
|
||||||
pattern="-?\d+"
|
|
||||||
/>
|
|
||||||
<input v-else-if="is_boolean" type="checkbox" v-model="value" />
|
|
||||||
<span v-else>UNKNOWN INPUT</span>
|
<span v-else>UNKNOWN INPUT</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import {
|
import {
|
||||||
type CommandParameterData,
|
type CommandParameterData,
|
||||||
type DynamicDataType,
|
type DynamicDataType,
|
||||||
getLimits,
|
|
||||||
isBooleanType,
|
isBooleanType,
|
||||||
isNumericType,
|
isNumericType,
|
||||||
} from '@/composables/dynamic.ts';
|
} from '@/composables/dynamic.ts';
|
||||||
@@ -19,9 +18,7 @@ const model = defineModel<{ [key: string]: CommandParameterData }>({
|
|||||||
required: true,
|
required: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: command_info, error: command_error } = useCommand(
|
const { data: command_info } = useCommand(props.command_name);
|
||||||
props.command_name,
|
|
||||||
);
|
|
||||||
|
|
||||||
watch([command_info], ([cmd_info]) => {
|
watch([command_info], ([cmd_info]) => {
|
||||||
if (cmd_info == null) {
|
if (cmd_info == null) {
|
||||||
@@ -43,8 +40,7 @@ watch([command_info], ([cmd_info]) => {
|
|||||||
switch (model_param_value.type) {
|
switch (model_param_value.type) {
|
||||||
case 'constant':
|
case 'constant':
|
||||||
if (
|
if (
|
||||||
(typeof model_param_value.value == 'number' ||
|
typeof model_param_value.value == 'number' &&
|
||||||
typeof model_param_value.value == 'bigint') &&
|
|
||||||
!isNumericType(param.data_type)
|
!isNumericType(param.data_type)
|
||||||
) {
|
) {
|
||||||
model_param_value = undefined;
|
model_param_value = undefined;
|
||||||
@@ -60,14 +56,10 @@ watch([command_info], ([cmd_info]) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (model_param_value === undefined) {
|
if (!model_param_value) {
|
||||||
let default_value: DynamicDataType = 0;
|
let default_value: DynamicDataType = 0;
|
||||||
if (isNumericType(param.data_type)) {
|
if (isNumericType(param.data_type)) {
|
||||||
if (getLimits(param.data_type).is_big) {
|
default_value = 0;
|
||||||
default_value = 0n;
|
|
||||||
} else {
|
|
||||||
default_value = 0;
|
|
||||||
}
|
|
||||||
} else if (isBooleanType(param.data_type)) {
|
} else if (isBooleanType(param.data_type)) {
|
||||||
default_value = false;
|
default_value = false;
|
||||||
}
|
}
|
||||||
@@ -76,21 +68,6 @@ watch([command_info], ([cmd_info]) => {
|
|||||||
value: default_value,
|
value: default_value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Perform some cleanup to remove data that shouldn't be there
|
|
||||||
switch (model_param_value.type) {
|
|
||||||
case 'constant':
|
|
||||||
model_param_value = {
|
|
||||||
type: model_param_value.type,
|
|
||||||
value: model_param_value.value,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case 'input':
|
|
||||||
model_param_value = {
|
|
||||||
type: model_param_value.type,
|
|
||||||
id: model_param_value.id,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
model_value[param.name] = model_param_value;
|
model_value[param.name] = model_param_value;
|
||||||
}
|
}
|
||||||
model.value = model_value;
|
model.value = model_value;
|
||||||
@@ -114,9 +91,6 @@ watch([command_info], ([cmd_info]) => {
|
|||||||
></CommandParameterDataConfigurator>
|
></CommandParameterDataConfigurator>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="command_error">
|
|
||||||
<span>Error: {{ command_error }}</span>
|
|
||||||
</template>
|
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<span> Loading... </span>
|
<span> Loading... </span>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { ref } from 'vue';
|
|||||||
import CommandParameter from '@/components/CommandParameter.vue';
|
import CommandParameter from '@/components/CommandParameter.vue';
|
||||||
import FlexDivider from '@/components/FlexDivider.vue';
|
import FlexDivider from '@/components/FlexDivider.vue';
|
||||||
import type { DynamicDataType } from '@/composables/dynamic.ts';
|
import type { DynamicDataType } from '@/composables/dynamic.ts';
|
||||||
import { parseJsonString, toJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
command: CommandDefinition | null;
|
command: CommandDefinition | null;
|
||||||
@@ -28,13 +27,12 @@ async function sendCommand() {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: toJsonString(params),
|
body: JSON.stringify(params),
|
||||||
});
|
});
|
||||||
const text_response = await response.text();
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
result.value = parseJsonString(text_response);
|
result.value = await response.json();
|
||||||
} else {
|
} else {
|
||||||
result.value = text_response;
|
result.value = await response.text();
|
||||||
}
|
}
|
||||||
busy.value = false;
|
busy.value = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
} from '@/composables/dynamic.ts';
|
} from '@/composables/dynamic.ts';
|
||||||
import { computed, defineAsyncComponent, inject, type Ref, ref } from 'vue';
|
import { computed, defineAsyncComponent, inject, type Ref, ref } from 'vue';
|
||||||
import CommandParameterListConfigurator from '@/components/CommandParameterListConfigurator.vue';
|
import CommandParameterListConfigurator from '@/components/CommandParameterListConfigurator.vue';
|
||||||
import { toJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
const TelemetryValue = defineAsyncComponent(
|
const TelemetryValue = defineAsyncComponent(
|
||||||
() => import('@/components/TelemetryValue.vue'),
|
() => import('@/components/TelemetryValue.vue'),
|
||||||
@@ -167,7 +166,7 @@ async function sendCommand(command: {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: toJsonString(params),
|
body: JSON.stringify(params),
|
||||||
});
|
});
|
||||||
busy.value = false;
|
busy.value = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { computed, watch } from 'vue';
|
|||||||
import CopyableDynamicSpan from '@/components/CopyableDynamicSpan.vue';
|
import CopyableDynamicSpan from '@/components/CopyableDynamicSpan.vue';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
value: number | bigint;
|
value: number;
|
||||||
max_width: number;
|
max_width: number;
|
||||||
copyable?: boolean;
|
copyable?: boolean;
|
||||||
include_span?: boolean;
|
include_span?: boolean;
|
||||||
@@ -23,9 +23,6 @@ const display_value = computed(() => {
|
|||||||
if (props.value == 0) {
|
if (props.value == 0) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
if (typeof props.value === 'bigint') {
|
|
||||||
return props.value.toString();
|
|
||||||
}
|
|
||||||
let precision = props.value.toPrecision(props.max_width - 3);
|
let precision = props.value.toPrecision(props.max_width - 3);
|
||||||
// Chop off the last character as long as it is a 0
|
// Chop off the last character as long as it is a 0
|
||||||
while (
|
while (
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import {
|
|||||||
isBooleanType,
|
isBooleanType,
|
||||||
isNumericType,
|
isNumericType,
|
||||||
} from '@/composables/dynamic.ts';
|
} from '@/composables/dynamic.ts';
|
||||||
import { parseJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
data: string;
|
data: string;
|
||||||
@@ -139,14 +138,7 @@ watch(
|
|||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`/api/tlm/history/${uuid}?from=${min_x.toISOString()}&to=${max_x.toISOString()}&resolution=${data_min_sep.value}`,
|
`/api/tlm/history/${uuid}?from=${min_x.toISOString()}&to=${max_x.toISOString()}&resolution=${data_min_sep.value}`,
|
||||||
);
|
);
|
||||||
const text_response = await res.text();
|
const response = (await res.json()) as TelemetryDataItem[];
|
||||||
if (!res.ok) {
|
|
||||||
console.error(text_response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const response = parseJsonString(
|
|
||||||
text_response,
|
|
||||||
) as TelemetryDataItem[];
|
|
||||||
for (const data_item of response) {
|
for (const data_item of response) {
|
||||||
const val_t = Date.parse(data_item.timestamp);
|
const val_t = Date.parse(data_item.timestamp);
|
||||||
const raw_item_val = data_item.value[
|
const raw_item_val = data_item.value[
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import {
|
|||||||
type WebsocketHandle,
|
type WebsocketHandle,
|
||||||
} from '@/composables/websocket.ts';
|
} from '@/composables/websocket.ts';
|
||||||
import NumericText from '@/components/NumericText.vue';
|
import NumericText from '@/components/NumericText.vue';
|
||||||
import BooleanText from '@/components/BooleanText.vue';
|
|
||||||
import { isBooleanType, isNumericType } from '@/composables/dynamic.ts';
|
|
||||||
|
|
||||||
const max_update_rate = 50; // ms
|
const max_update_rate = 50; // ms
|
||||||
const default_update_rate = 200; // ms
|
const default_update_rate = 200; // ms
|
||||||
@@ -35,23 +33,30 @@ const value = websocket.value.listen_to_telemetry(
|
|||||||
const is_data_present = computed(() => {
|
const is_data_present = computed(() => {
|
||||||
return value.value != null;
|
return value.value != null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const numeric_data = computed(() => {
|
||||||
|
const val = value.value;
|
||||||
|
if (val) {
|
||||||
|
const type = telemetry_data.value!.data_type;
|
||||||
|
const item_val = val.value[type];
|
||||||
|
if (typeof item_val == 'number') {
|
||||||
|
return item_val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<span v-if="!is_data_present" v-bind="$attrs"> No Data </span>
|
<span v-if="!is_data_present" v-bind="$attrs"> No Data </span>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<NumericText
|
<NumericText
|
||||||
v-if="isNumericType(telemetry_data!.data_type)"
|
v-if="numeric_data"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
:value="value!.value[telemetry_data!.data_type]"
|
:value="numeric_data"
|
||||||
:max_width="10"
|
:max_width="10"
|
||||||
include_span
|
include_span
|
||||||
></NumericText>
|
></NumericText>
|
||||||
<BooleanText
|
|
||||||
v-else-if="isBooleanType(telemetry_data!.data_type)"
|
|
||||||
v-bind="$attrs"
|
|
||||||
:value="value!.value[telemetry_data!.data_type]"
|
|
||||||
></BooleanText>
|
|
||||||
<span v-else v-bind="$attrs">
|
<span v-else v-bind="$attrs">
|
||||||
Cannot Display Data of Type {{ telemetry_data!.data_type }}
|
Cannot Display Data of Type {{ telemetry_data!.data_type }}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { ref, toValue, watchEffect } from 'vue';
|
import { ref, toValue, watchEffect } from 'vue';
|
||||||
import { type MaybeRefOrGetter } from 'vue';
|
import { type MaybeRefOrGetter } from 'vue';
|
||||||
import type { AnyTypeId } from '@/composables/dynamic.ts';
|
import type { AnyTypeId } from '@/composables/dynamic.ts';
|
||||||
import { parseJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
export interface CommandParameterDefinition {
|
export interface CommandParameterDefinition {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -21,14 +20,8 @@ export function useAllCommands() {
|
|||||||
watchEffect(async () => {
|
watchEffect(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/cmd`);
|
const res = await fetch(`/api/cmd`);
|
||||||
const text_response = await res.text();
|
data.value = await res.json();
|
||||||
if (res.ok) {
|
error.value = null;
|
||||||
data.value = parseJsonString(text_response);
|
|
||||||
error.value = null;
|
|
||||||
} else {
|
|
||||||
data.value = null;
|
|
||||||
error.value = text_response;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data.value = null;
|
data.value = null;
|
||||||
error.value = e;
|
error.value = e;
|
||||||
@@ -48,14 +41,8 @@ export function useCommand(name: MaybeRefOrGetter<string>) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/cmd/${name_value}`);
|
const res = await fetch(`/api/cmd/${name_value}`);
|
||||||
const text_response = await res.text();
|
data.value = await res.json();
|
||||||
if (res.ok) {
|
error.value = null;
|
||||||
data.value = parseJsonString(text_response);
|
|
||||||
error.value = null;
|
|
||||||
} else {
|
|
||||||
data.value = null;
|
|
||||||
error.value = text_response;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data.value = null;
|
data.value = null;
|
||||||
error.value = e;
|
error.value = e;
|
||||||
|
|||||||
@@ -1,74 +1,5 @@
|
|||||||
export const NumericTypes = [
|
export const NumericTypes = ['Float32', 'Float64'] as const;
|
||||||
'Float32',
|
|
||||||
'Float64',
|
|
||||||
'Int8',
|
|
||||||
'Int16',
|
|
||||||
'Int32',
|
|
||||||
'Int64',
|
|
||||||
'Unsigned8',
|
|
||||||
'Unsigned16',
|
|
||||||
'Unsigned32',
|
|
||||||
'Unsigned64',
|
|
||||||
] as const;
|
|
||||||
export type NumericTypeId = (typeof NumericTypes)[number];
|
export type NumericTypeId = (typeof NumericTypes)[number];
|
||||||
|
|
||||||
export type NumericLimits = {
|
|
||||||
min: number | bigint;
|
|
||||||
max: number | bigint;
|
|
||||||
integer: boolean;
|
|
||||||
is_big: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function getLimits(numeric_type: NumericTypeId): NumericLimits {
|
|
||||||
switch (numeric_type) {
|
|
||||||
case 'Float32':
|
|
||||||
return {
|
|
||||||
integer: false,
|
|
||||||
is_big: false,
|
|
||||||
min: -3.40282347e38,
|
|
||||||
max: 3.40282347e38,
|
|
||||||
};
|
|
||||||
case 'Float64':
|
|
||||||
return {
|
|
||||||
integer: false,
|
|
||||||
is_big: false,
|
|
||||||
min: -1.7976931348623157e308,
|
|
||||||
max: 1.7976931348623157e308,
|
|
||||||
};
|
|
||||||
case 'Int8':
|
|
||||||
return { integer: true, is_big: false, min: -128, max: 127 };
|
|
||||||
case 'Int16':
|
|
||||||
return { integer: true, is_big: false, min: -32768, max: 32767 };
|
|
||||||
case 'Int32':
|
|
||||||
return {
|
|
||||||
integer: true,
|
|
||||||
is_big: false,
|
|
||||||
min: -2147483648,
|
|
||||||
max: 2147483647,
|
|
||||||
};
|
|
||||||
case 'Int64':
|
|
||||||
return {
|
|
||||||
integer: true,
|
|
||||||
is_big: true,
|
|
||||||
min: -9223372036854775808n,
|
|
||||||
max: 9223372036854775807n,
|
|
||||||
};
|
|
||||||
case 'Unsigned8':
|
|
||||||
return { integer: true, is_big: false, min: 0, max: 255 };
|
|
||||||
case 'Unsigned16':
|
|
||||||
return { integer: true, is_big: false, min: 0, max: 65535 };
|
|
||||||
case 'Unsigned32':
|
|
||||||
return { integer: true, is_big: false, min: 0, max: 4294967295 };
|
|
||||||
case 'Unsigned64':
|
|
||||||
return {
|
|
||||||
integer: true,
|
|
||||||
is_big: true,
|
|
||||||
min: 0,
|
|
||||||
max: 18446744073709551615n,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const BooleanTypes = ['Boolean'] as const;
|
export const BooleanTypes = ['Boolean'] as const;
|
||||||
export type BooleanTypeId = (typeof BooleanTypes)[number];
|
export type BooleanTypeId = (typeof BooleanTypes)[number];
|
||||||
export const AnyTypes = [...NumericTypes, ...BooleanTypes] as const;
|
export const AnyTypes = [...NumericTypes, ...BooleanTypes] as const;
|
||||||
@@ -81,7 +12,7 @@ export function isBooleanType(type: AnyTypeId): type is BooleanTypeId {
|
|||||||
return BooleanTypes.some((it) => it == type);
|
return BooleanTypes.some((it) => it == type);
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DynamicDataType = bigint | number | boolean;
|
export type DynamicDataType = number | boolean;
|
||||||
|
|
||||||
export type CommandParameterData =
|
export type CommandParameterData =
|
||||||
| {
|
| {
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
export function toJsonString(data: any, pretty: boolean = false): string {
|
|
||||||
return JSON.stringify(
|
|
||||||
data,
|
|
||||||
(_key, value) => {
|
|
||||||
if (typeof value == 'bigint') {
|
|
||||||
// @ts-expect-error TS2339
|
|
||||||
return JSON.rawJSON(value.toString());
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
pretty ? 4 : undefined,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
export function parseJsonString(data: string): any {
|
|
||||||
// @ts-expect-error TS2345, TS7006
|
|
||||||
return JSON.parse(data, (key, value, context) => {
|
|
||||||
if (key === 'Int64' || key == 'Unsigned64') {
|
|
||||||
// Or use the constructor of your custom high-precision number library
|
|
||||||
return BigInt(context.source);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { ref, toValue, watchEffect } from 'vue';
|
import { ref, toValue, watchEffect } from 'vue';
|
||||||
import { type MaybeRefOrGetter } from 'vue';
|
import { type MaybeRefOrGetter } from 'vue';
|
||||||
import type { AnyTypeId } from '@/composables/dynamic.ts';
|
import type { AnyTypeId } from '@/composables/dynamic.ts';
|
||||||
import { parseJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
export interface TelemetryDefinition {
|
export interface TelemetryDefinition {
|
||||||
uuid: string;
|
uuid: string;
|
||||||
@@ -17,14 +16,8 @@ export function useAllTelemetry() {
|
|||||||
watchEffect(async () => {
|
watchEffect(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/tlm/info`);
|
const res = await fetch(`/api/tlm/info`);
|
||||||
const text_response = await res.text();
|
data.value = await res.json();
|
||||||
if (res.ok) {
|
error.value = null;
|
||||||
data.value = parseJsonString(text_response);
|
|
||||||
error.value = null;
|
|
||||||
} else {
|
|
||||||
data.value = null;
|
|
||||||
error.value = text_response;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data.value = null;
|
data.value = null;
|
||||||
error.value = e;
|
error.value = e;
|
||||||
@@ -44,14 +37,8 @@ export function useTelemetry(name: MaybeRefOrGetter<string>) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/tlm/info/${name_value}`);
|
const res = await fetch(`/api/tlm/info/${name_value}`);
|
||||||
const text_response = await res.text();
|
data.value = await res.json();
|
||||||
if (res.ok) {
|
error.value = null;
|
||||||
data.value = parseJsonString(text_response);
|
|
||||||
error.value = null;
|
|
||||||
} else {
|
|
||||||
data.value = null;
|
|
||||||
error.value = text_response;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data.value = null;
|
data.value = null;
|
||||||
error.value = e;
|
error.value = e;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
} from 'vue';
|
} from 'vue';
|
||||||
import type { TelemetryDefinition } from '@/composables/telemetry';
|
import type { TelemetryDefinition } from '@/composables/telemetry';
|
||||||
import { onDocumentVisibilityChange } from '@/composables/document.ts';
|
import { onDocumentVisibilityChange } from '@/composables/document.ts';
|
||||||
import { parseJsonString, toJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
export interface TelemetryDataItem {
|
export interface TelemetryDataItem {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@@ -72,7 +71,7 @@ export class WebsocketHandle {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.websocket.addEventListener('message', (event) => {
|
this.websocket.addEventListener('message', (event) => {
|
||||||
const message = parseJsonString(event.data);
|
const message = JSON.parse(event.data);
|
||||||
if (message['TlmValue']) {
|
if (message['TlmValue']) {
|
||||||
const tlm_value = message['TlmValue'] as TlmValue;
|
const tlm_value = message['TlmValue'] as TlmValue;
|
||||||
const listeners = this.on_telem_value.get(tlm_value.uuid);
|
const listeners = this.on_telem_value.get(tlm_value.uuid);
|
||||||
@@ -127,7 +126,7 @@ export class WebsocketHandle {
|
|||||||
([uuid_value, connected, enabled, min_sep, live_value]) => {
|
([uuid_value, connected, enabled, min_sep, live_value]) => {
|
||||||
if (connected && enabled && uuid_value && live_value) {
|
if (connected && enabled && uuid_value && live_value) {
|
||||||
this.websocket?.send(
|
this.websocket?.send(
|
||||||
toJsonString({
|
JSON.stringify({
|
||||||
RegisterTlmListener: {
|
RegisterTlmListener: {
|
||||||
uuid: uuid_value,
|
uuid: uuid_value,
|
||||||
minimum_separation_ms: min_sep,
|
minimum_separation_ms: min_sep,
|
||||||
@@ -143,7 +142,7 @@ export class WebsocketHandle {
|
|||||||
this.on_telem_value.get(uuid_value)?.push(callback_fn);
|
this.on_telem_value.get(uuid_value)?.push(callback_fn);
|
||||||
onWatcherCleanup(() => {
|
onWatcherCleanup(() => {
|
||||||
this.websocket?.send(
|
this.websocket?.send(
|
||||||
toJsonString({
|
JSON.stringify({
|
||||||
UnregisterTlmListener: {
|
UnregisterTlmListener: {
|
||||||
uuid: uuid_value,
|
uuid: uuid_value,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { RouteLocationRaw } from 'vue-router';
|
import type { RouteLocationRaw } from 'vue-router';
|
||||||
import { ref, type Ref, watchEffect } from 'vue';
|
import { ref, type Ref, watchEffect } from 'vue';
|
||||||
import { parseJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
export enum PanelHeirarchyType {
|
export enum PanelHeirarchyType {
|
||||||
LEAF = 'leaf',
|
LEAF = 'leaf',
|
||||||
@@ -62,11 +61,7 @@ export function usePanelHeirarchy(): Ref<PanelHeirarchyChildren> {
|
|||||||
watchEffect(async () => {
|
watchEffect(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/panel`);
|
const res = await fetch(`/api/panel`);
|
||||||
if (!res.ok) {
|
const data = await res.json();
|
||||||
console.error('Failed to fetch panels');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const data = parseJsonString(await res.text());
|
|
||||||
|
|
||||||
const server_panels: PanelHeirarchyFolder = {
|
const server_panels: PanelHeirarchyFolder = {
|
||||||
name: 'Server Panels',
|
name: 'Server Panels',
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import DynamicComponent from '@/components/DynamicComponent.vue';
|
import DynamicComponent from '@/components/DynamicComponent.vue';
|
||||||
import type { OptionalDynamicComponentData } from '@/composables/dynamic.ts';
|
import type { OptionalDynamicComponentData } from '@/composables/dynamic.ts';
|
||||||
import { ref, useTemplateRef, watchEffect } from 'vue';
|
import { ref, watchEffect } from 'vue';
|
||||||
import { parseJsonString, toJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
const data = ref<OptionalDynamicComponentData>({ type: 'none' });
|
const data = ref<OptionalDynamicComponentData>({ type: 'none' });
|
||||||
|
|
||||||
@@ -20,11 +19,7 @@ const unselect = () => {
|
|||||||
|
|
||||||
async function reload_panel_list() {
|
async function reload_panel_list() {
|
||||||
const res = await fetch(`/api/panel`);
|
const res = await fetch(`/api/panel`);
|
||||||
if (!res.ok) {
|
panel_list.value = await res.json();
|
||||||
console.error('Failed to reload panel list');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
panel_list.value = parseJsonString(await res.text());
|
|
||||||
}
|
}
|
||||||
watchEffect(reload_panel_list);
|
watchEffect(reload_panel_list);
|
||||||
|
|
||||||
@@ -33,9 +28,10 @@ async function load(id: string) {
|
|||||||
load_screen.value = false;
|
load_screen.value = false;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const panel_data = await fetch(`/api/panel/${id}`);
|
const panel_data = await fetch(`/api/panel/${id}`);
|
||||||
const panel_text_value = await panel_data.text();
|
const panel_json_value = await panel_data.json();
|
||||||
const panel_json_value = parseJsonString(panel_text_value);
|
data.value = JSON.parse(
|
||||||
data.value = panel_json_value['data'] as OptionalDynamicComponentData;
|
panel_json_value['data'],
|
||||||
|
) as OptionalDynamicComponentData;
|
||||||
panel_name.value = panel_json_value['name'];
|
panel_name.value = panel_json_value['name'];
|
||||||
panel_id.value = id;
|
panel_id.value = id;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@@ -54,33 +50,28 @@ async function save() {
|
|||||||
if (panel_id_value) {
|
if (panel_id_value) {
|
||||||
const res = await fetch(`/api/panel/${panel_id_value}`, {
|
const res = await fetch(`/api/panel/${panel_id_value}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: toJsonString({
|
body: JSON.stringify({
|
||||||
name: panel_name.value,
|
name: panel_name.value,
|
||||||
data: data.value,
|
data: JSON.stringify(data.value),
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await res.text();
|
await res.json();
|
||||||
// TODO: Handle failures
|
|
||||||
} else {
|
} else {
|
||||||
const res = await fetch('/api/panel', {
|
const res = await fetch('/api/panel', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: toJsonString({
|
body: JSON.stringify({
|
||||||
name: panel_name.value,
|
name: panel_name.value,
|
||||||
data: data.value,
|
data: JSON.stringify(data.value),
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const text_response = await res.text();
|
const uuid = await res.json();
|
||||||
if (res.ok) {
|
panel_id.value = uuid as string;
|
||||||
const uuid = parseJsonString(text_response);
|
|
||||||
panel_id.value = uuid as string;
|
|
||||||
}
|
|
||||||
// TODO: Handle failures
|
|
||||||
}
|
}
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
@@ -89,35 +80,6 @@ async function showLoadScreen() {
|
|||||||
load_screen.value = true;
|
load_screen.value = true;
|
||||||
await reload_panel_list();
|
await reload_panel_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
function download() {
|
|
||||||
const file = new Blob([toJsonString(data.value, true)], {
|
|
||||||
type: 'application/json',
|
|
||||||
});
|
|
||||||
const a = document.createElement('a');
|
|
||||||
const url = URL.createObjectURL(file);
|
|
||||||
a.href = url;
|
|
||||||
a.download = panel_name.value.toLowerCase().replace(' ', '_') + '.json';
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
setTimeout(function () {
|
|
||||||
document.body.removeChild(a);
|
|
||||||
window.URL.revokeObjectURL(url);
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const upload_input = useTemplateRef<HTMLInputElement>('upload-input');
|
|
||||||
|
|
||||||
function upload() {
|
|
||||||
upload_input.value!.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onUpload() {
|
|
||||||
const input = upload_input.value!;
|
|
||||||
const file = input.files![0];
|
|
||||||
const file_data = await file.text();
|
|
||||||
data.value = parseJsonString(file_data);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -150,15 +112,6 @@ async function onUpload() {
|
|||||||
{{ panel_id ? 'Save' : 'New' }}
|
{{ panel_id ? 'Save' : 'New' }}
|
||||||
</button>
|
</button>
|
||||||
<button @click.prevent.stop="showLoadScreen">Load</button>
|
<button @click.prevent.stop="showLoadScreen">Load</button>
|
||||||
<button @click.prevent.stop="download">Download</button>
|
|
||||||
<input
|
|
||||||
ref="upload-input"
|
|
||||||
class="file"
|
|
||||||
type="file"
|
|
||||||
accept="application/json"
|
|
||||||
@change="onUpload"
|
|
||||||
/>
|
|
||||||
<button @click.prevent.stop="upload">Upload</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="inspector" class="column"></div>
|
<div id="inspector" class="column"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -173,8 +126,4 @@ async function onUpload() {
|
|||||||
height: 100vh;
|
height: 100vh;
|
||||||
background: variables.$dark-background-color;
|
background: variables.$dark-background-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.file {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import type {
|
|||||||
} from '@/composables/dynamic.ts';
|
} from '@/composables/dynamic.ts';
|
||||||
import { computed, provide, ref, watchEffect } from 'vue';
|
import { computed, provide, ref, watchEffect } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { parseJsonString } from '@/composables/json.ts';
|
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
@@ -22,10 +21,10 @@ provide('inputs', inputs);
|
|||||||
|
|
||||||
watchEffect(async () => {
|
watchEffect(async () => {
|
||||||
const panel_data = await fetch(`/api/panel/${id.value}`);
|
const panel_data = await fetch(`/api/panel/${id.value}`);
|
||||||
const panel_text_value = await panel_data.text();
|
const panel_json_value = await panel_data.json();
|
||||||
panel.value = parseJsonString(panel_text_value)[
|
panel.value = JSON.parse(
|
||||||
'data'
|
panel_json_value['data'],
|
||||||
] as OptionalDynamicComponentData;
|
) as OptionalDynamicComponentData;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -2,20 +2,19 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "server"
|
name = "server"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
version.workspace = true
|
version = "0.1.0"
|
||||||
authors.workspace = true
|
authors = ["Sergey <me@sergeysav.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { workspace = true, features = [ ] }
|
actix-web = { workspace = true, features = [ ] }
|
||||||
actix-ws = { workspace = true }
|
actix-ws = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
api = { workspace = true }
|
api = { path = "../api" }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
derive_more = { workspace = true, features = ["from"] }
|
derive_more = { workspace = true, features = ["from"] }
|
||||||
fern = { workspace = true, features = ["colored"] }
|
fern = { workspace = true, features = ["colored"] }
|
||||||
futures-util = { workspace = true }
|
futures-util = { workspace = true }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
num-traits = { workspace = true }
|
|
||||||
papaya = { workspace = true }
|
papaya = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use api::messages::command::{Command, CommandDefinition, CommandHeader, CommandR
|
|||||||
use api::messages::ResponseMessage;
|
use api::messages::ResponseMessage;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use log::error;
|
use log::error;
|
||||||
use num_traits::FromPrimitive;
|
|
||||||
use papaya::HashMap;
|
use papaya::HashMap;
|
||||||
use std::collections::HashMap as StdHashMap;
|
use std::collections::HashMap as StdHashMap;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
@@ -103,34 +102,10 @@ impl CommandManagementService {
|
|||||||
let Some(param_value) = parameters.get(¶meter.name) else {
|
let Some(param_value) = parameters.get(¶meter.name) else {
|
||||||
return Err(MisingParameter(parameter.name.clone()));
|
return Err(MisingParameter(parameter.name.clone()));
|
||||||
};
|
};
|
||||||
let Some(Some(param_value)) = (match parameter.data_type {
|
let Some(param_value) = (match parameter.data_type {
|
||||||
DataType::Float32 => param_value
|
DataType::Float32 => param_value.as_f64().map(|v| DataValue::Float32(v as f32)),
|
||||||
.as_f64()
|
DataType::Float64 => param_value.as_f64().map(DataValue::Float64),
|
||||||
.map(|v| Some(DataValue::Float32(v as f32))),
|
DataType::Boolean => param_value.as_bool().map(DataValue::Boolean),
|
||||||
DataType::Float64 => param_value.as_f64().map(DataValue::Float64).map(Some),
|
|
||||||
DataType::Boolean => param_value.as_bool().map(DataValue::Boolean).map(Some),
|
|
||||||
DataType::Int8 => param_value
|
|
||||||
.as_i64()
|
|
||||||
.map(|v| Some(DataValue::Int8(i8::from_i64(v)?))),
|
|
||||||
DataType::Int16 => param_value
|
|
||||||
.as_i64()
|
|
||||||
.map(|v| Some(DataValue::Int16(i16::from_i64(v)?))),
|
|
||||||
DataType::Int32 => param_value
|
|
||||||
.as_i64()
|
|
||||||
.map(|v| Some(DataValue::Int32(i32::from_i64(v)?))),
|
|
||||||
DataType::Int64 => param_value.as_i64().map(|v| Some(DataValue::Int64(v))),
|
|
||||||
DataType::Unsigned8 => param_value
|
|
||||||
.as_u64()
|
|
||||||
.map(|v| Some(DataValue::Unsigned8(u8::from_u64(v)?))),
|
|
||||||
DataType::Unsigned16 => param_value
|
|
||||||
.as_u64()
|
|
||||||
.map(|v| Some(DataValue::Unsigned16(u16::from_u64(v)?))),
|
|
||||||
DataType::Unsigned32 => param_value
|
|
||||||
.as_u64()
|
|
||||||
.map(|v| Some(DataValue::Unsigned32(u32::from_u64(v)?))),
|
|
||||||
DataType::Unsigned64 => {
|
|
||||||
param_value.as_u64().map(|v| Some(DataValue::Unsigned64(v)))
|
|
||||||
}
|
|
||||||
}) else {
|
}) else {
|
||||||
return Err(WrongParameterType {
|
return Err(WrongParameterType {
|
||||||
name: parameter.name.clone(),
|
name: parameter.name.clone(),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::http::error::HttpServerResultError;
|
|||||||
use actix_web::{get, post, web, Responder};
|
use actix_web::{get, post, web, Responder};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[post("/cmd/{name:[\\.\\w\\d/_-]+}")]
|
#[post("/cmd/{name:[\\w\\d/_-]+}")]
|
||||||
pub(super) async fn send_command(
|
pub(super) async fn send_command(
|
||||||
command_service: web::Data<Arc<CommandManagementService>>,
|
command_service: web::Data<Arc<CommandManagementService>>,
|
||||||
name: web::Path<String>,
|
name: web::Path<String>,
|
||||||
@@ -23,16 +23,12 @@ pub(super) async fn get_all(
|
|||||||
Ok(web::Json(command_service.get_commands()?))
|
Ok(web::Json(command_service.get_commands()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/cmd/{name:[\\.\\w\\d/_-]+}")]
|
#[get("/cmd/{name:[\\w\\d/_-]+}")]
|
||||||
pub(super) async fn get_one(
|
pub(super) async fn get_one(
|
||||||
command_service: web::Data<Arc<CommandManagementService>>,
|
command_service: web::Data<Arc<CommandManagementService>>,
|
||||||
name: web::Path<String>,
|
name: web::Path<String>,
|
||||||
) -> Result<impl Responder, HttpServerResultError> {
|
) -> Result<impl Responder, HttpServerResultError> {
|
||||||
Ok(web::Json(
|
Ok(web::Json(
|
||||||
command_service
|
command_service.get_command_definition(&name.to_string()),
|
||||||
.get_command_definition(&name.to_string())
|
|
||||||
.ok_or_else(|| HttpServerResultError::CmdNotFound {
|
|
||||||
cmd: name.to_string(),
|
|
||||||
})?,
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use uuid::Uuid;
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct CreateParam {
|
struct CreateParam {
|
||||||
name: String,
|
name: String,
|
||||||
data: serde_json::Value,
|
data: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use std::time::Duration;
|
|||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[get("/tlm/info/{name:[\\.\\w\\d/_-]+}")]
|
#[get("/tlm/info/{name:[\\w\\d/_-]+}")]
|
||||||
pub(super) async fn get_tlm_definition(
|
pub(super) async fn get_tlm_definition(
|
||||||
data: web::Data<Arc<TelemetryManagementService>>,
|
data: web::Data<Arc<TelemetryManagementService>>,
|
||||||
name: web::Path<String>,
|
name: web::Path<String>,
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ pub enum HttpServerResultError {
|
|||||||
PanelUuidNotFound { uuid: Uuid },
|
PanelUuidNotFound { uuid: Uuid },
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Command(#[from] crate::command::error::Error),
|
Command(#[from] crate::command::error::Error),
|
||||||
#[error("Command Not Found: {cmd}")]
|
|
||||||
CmdNotFound { cmd: String },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResponseError for HttpServerResultError {
|
impl ResponseError for HttpServerResultError {
|
||||||
@@ -38,7 +36,6 @@ impl ResponseError for HttpServerResultError {
|
|||||||
HttpServerResultError::InternalError { .. } => StatusCode::INTERNAL_SERVER_ERROR,
|
HttpServerResultError::InternalError { .. } => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
HttpServerResultError::PanelUuidNotFound { .. } => StatusCode::NOT_FOUND,
|
HttpServerResultError::PanelUuidNotFound { .. } => StatusCode::NOT_FOUND,
|
||||||
HttpServerResultError::Command(inner) => inner.status_code(),
|
HttpServerResultError::Command(inner) => inner.status_code(),
|
||||||
HttpServerResultError::CmdNotFound { .. } => StatusCode::NOT_FOUND,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use crate::http::backend::setup_backend;
|
|||||||
use crate::http::websocket::setup_websocket;
|
use crate::http::websocket::setup_websocket;
|
||||||
use crate::panels::PanelService;
|
use crate::panels::PanelService;
|
||||||
use crate::telemetry::management_service::TelemetryManagementService;
|
use crate::telemetry::management_service::TelemetryManagementService;
|
||||||
use actix_web::middleware::{Compress, Logger};
|
use actix_web::middleware::Logger;
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
use log::info;
|
use log::info;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -36,7 +36,6 @@ pub async fn setup(
|
|||||||
.service(web::scope("/backend").configure(setup_backend))
|
.service(web::scope("/backend").configure(setup_backend))
|
||||||
.service(web::scope("/ws").configure(setup_websocket))
|
.service(web::scope("/ws").configure(setup_websocket))
|
||||||
.service(web::scope("/api").configure(setup_api))
|
.service(web::scope("/api").configure(setup_api))
|
||||||
.wrap(Compress::default())
|
|
||||||
.wrap(Logger::default())
|
.wrap(Logger::default())
|
||||||
})
|
})
|
||||||
.bind("localhost:8080")?
|
.bind("localhost:8080")?
|
||||||
|
|||||||
@@ -14,12 +14,10 @@ impl PanelService {
|
|||||||
Self { pool }
|
Self { pool }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(&self, name: &str, data: &serde_json::Value) -> anyhow::Result<Uuid> {
|
pub async fn create(&self, name: &str, data: &str) -> anyhow::Result<Uuid> {
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
let id_string = id.to_string();
|
let id_string = id.to_string();
|
||||||
|
|
||||||
let data = serde_json::to_string(data)?;
|
|
||||||
|
|
||||||
let mut transaction = self.pool.begin().await?;
|
let mut transaction = self.pool.begin().await?;
|
||||||
|
|
||||||
let _ = sqlx::query!(
|
let _ = sqlx::query!(
|
||||||
|
|||||||
@@ -12,12 +12,11 @@ pub struct Panel {
|
|||||||
#[sqlx(flatten)]
|
#[sqlx(flatten)]
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub header: PanelRequired,
|
pub header: PanelRequired,
|
||||||
#[sqlx(json)]
|
pub data: String,
|
||||||
pub data: serde_json::Value,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||||
pub struct PanelUpdate {
|
pub struct PanelUpdate {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub data: Option<serde_json::Value>,
|
pub data: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,17 +196,9 @@ impl HistorySegmentFile {
|
|||||||
// Write all the values
|
// Write all the values
|
||||||
for value in &data.values {
|
for value in &data.values {
|
||||||
match value {
|
match value {
|
||||||
DataValue::Float32(value) => file.write_data(*value)?,
|
DataValue::Float32(value) => file.write_data::<f32>(*value)?,
|
||||||
DataValue::Float64(value) => file.write_data(*value)?,
|
DataValue::Float64(value) => file.write_data::<f64>(*value)?,
|
||||||
DataValue::Boolean(value) => file.write_data(*value)?,
|
DataValue::Boolean(value) => file.write_data::<bool>(*value)?,
|
||||||
DataValue::Int8(value) => file.write_data(*value)?,
|
|
||||||
DataValue::Int16(value) => file.write_data(*value)?,
|
|
||||||
DataValue::Int32(value) => file.write_data(*value)?,
|
|
||||||
DataValue::Int64(value) => file.write_data(*value)?,
|
|
||||||
DataValue::Unsigned8(value) => file.write_data(*value)?,
|
|
||||||
DataValue::Unsigned16(value) => file.write_data(*value)?,
|
|
||||||
DataValue::Unsigned32(value) => file.write_data(*value)?,
|
|
||||||
DataValue::Unsigned64(value) => file.write_data(*value)?,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,20 +332,20 @@ impl HistorySegmentFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_telemetry_item(&mut self, telemetry_data_type: DataType) -> anyhow::Result<DataValue> {
|
fn read_telemetry_item(&mut self, telemetry_data_type: DataType) -> anyhow::Result<DataValue> {
|
||||||
self.file_position += telemetry_data_type.get_data_length() as i64;
|
match telemetry_data_type {
|
||||||
Ok(match telemetry_data_type {
|
DataType::Float32 => {
|
||||||
DataType::Float32 => self.file.read_data::<f32>()?.into(),
|
self.file_position += 4;
|
||||||
DataType::Float64 => self.file.read_data::<f64>()?.into(),
|
Ok(DataValue::Float32(self.file.read_data::<f32>()?))
|
||||||
DataType::Boolean => self.file.read_data::<bool>()?.into(),
|
}
|
||||||
DataType::Int8 => self.file.read_data::<i8>()?.into(),
|
DataType::Float64 => {
|
||||||
DataType::Int16 => self.file.read_data::<i16>()?.into(),
|
self.file_position += 8;
|
||||||
DataType::Int32 => self.file.read_data::<i32>()?.into(),
|
Ok(DataValue::Float64(self.file.read_data::<f64>()?))
|
||||||
DataType::Int64 => self.file.read_data::<i64>()?.into(),
|
}
|
||||||
DataType::Unsigned8 => self.file.read_data::<u8>()?.into(),
|
DataType::Boolean => {
|
||||||
DataType::Unsigned16 => self.file.read_data::<u16>()?.into(),
|
self.file_position += 1;
|
||||||
DataType::Unsigned32 => self.file.read_data::<u32>()?.into(),
|
Ok(DataValue::Boolean(self.file.read_data::<bool>()?))
|
||||||
DataType::Unsigned64 => self.file.read_data::<u64>()?.into(),
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_telemetry_item(
|
fn get_telemetry_item(
|
||||||
@@ -361,7 +353,11 @@ impl HistorySegmentFile {
|
|||||||
index: u64,
|
index: u64,
|
||||||
telemetry_data_type: DataType,
|
telemetry_data_type: DataType,
|
||||||
) -> anyhow::Result<DataValue> {
|
) -> anyhow::Result<DataValue> {
|
||||||
let item_length = telemetry_data_type.get_data_length();
|
let item_length = match telemetry_data_type {
|
||||||
|
DataType::Float32 => 4,
|
||||||
|
DataType::Float64 => 8,
|
||||||
|
DataType::Boolean => 1,
|
||||||
|
};
|
||||||
let desired_position =
|
let desired_position =
|
||||||
Self::HEADER_LENGTH + self.length * Self::TIMESTAMP_LENGTH + index * item_length;
|
Self::HEADER_LENGTH + self.length * Self::TIMESTAMP_LENGTH + index * item_length;
|
||||||
let seek_amount = desired_position as i64 - self.file_position;
|
let seek_amount = desired_position as i64 - self.file_position;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ use crate::telemetry::data_item::TelemetryDataItem;
|
|||||||
use crate::telemetry::definition::TelemetryDefinition;
|
use crate::telemetry::definition::TelemetryDefinition;
|
||||||
use crate::telemetry::history::{TelemetryHistory, TelemetryHistoryService};
|
use crate::telemetry::history::{TelemetryHistory, TelemetryHistoryService};
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
|
use api::data_type::DataType;
|
||||||
|
use api::data_value::DataValue;
|
||||||
use api::messages::telemetry_definition::{
|
use api::messages::telemetry_definition::{
|
||||||
TelemetryDefinitionRequest, TelemetryDefinitionResponse,
|
TelemetryDefinitionRequest, TelemetryDefinitionResponse,
|
||||||
};
|
};
|
||||||
@@ -142,7 +144,11 @@ impl TelemetryManagementService {
|
|||||||
bail!("Telemetry Item Not Found");
|
bail!("Telemetry Item Not Found");
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected_type = tlm_item.value.to_data_type();
|
let expected_type = match &tlm_item.value {
|
||||||
|
DataValue::Float32(_) => DataType::Float32,
|
||||||
|
DataValue::Float64(_) => DataType::Float64,
|
||||||
|
DataValue::Boolean(_) => DataType::Boolean,
|
||||||
|
};
|
||||||
if expected_type != tlm_data.data.definition.data_type {
|
if expected_type != tlm_data.data.definition.data_type {
|
||||||
bail!("Data Type Mismatch");
|
bail!("Data Type Mismatch");
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user