add boolean type

This commit is contained in:
2025-12-25 12:44:26 -05:00
parent ebbf864af9
commit 8cfaf468e9
12 changed files with 113 additions and 14 deletions

View File

@@ -5,12 +5,14 @@ package core;
enum TelemetryDataType {
Float32 = 0;
Float64 = 1;
Boolean = 2;
}
message TelemetryValue {
oneof value {
float float_32 = 1;
double float_64 = 2;
bool boolean = 3;
}
}

View File

@@ -111,6 +111,7 @@ impl CoreTelemetryService {
let expected_type = match value {
Value::Float32(_) => TelemetryDataType::Float32,
Value::Float64(_) => TelemetryDataType::Float64,
Value::Boolean(_) => TelemetryDataType::Boolean,
};
if expected_type != tlm_data.data.definition.data_type {
return Err(Status::failed_precondition("Data Type Mismatch"));
@@ -124,6 +125,7 @@ impl CoreTelemetryService {
let value = match value {
Value::Float32(x) => TelemetryDataValue::Float32(x),
Value::Float64(x) => TelemetryDataValue::Float64(x),
Value::Boolean(x) => TelemetryDataValue::Boolean(x),
};
let _ = tlm_data.data.data.send_replace(Some(TelemetryDataItem {
value: value.clone(),

View File

@@ -30,3 +30,16 @@ primitive_write_read!(i8, 1);
primitive_write_read!(f64, 8);
primitive_write_read!(f32, 4);
impl FileWriteableType for bool {
fn write_to_file(self, file: &mut impl Write) -> std::io::Result<()> {
file.write_all(&[if self { 0x01 } else { 0x00 }])
}
}
impl FileReadableType for bool {
fn read_from_file(file: &mut impl Read) -> std::io::Result<Self> {
let mut buffer = [0u8; 1];
file.read_exact(&mut buffer)?;
Ok(buffer[0] != 0x00)
}
}

View File

@@ -4,4 +4,5 @@ use serde::{Deserialize, Serialize};
pub enum TelemetryDataValue {
Float32(f32),
Float64(f64),
Boolean(bool),
}

View File

@@ -198,6 +198,7 @@ impl HistorySegmentFile {
match value {
TelemetryDataValue::Float32(value) => file.write_data::<f32>(*value)?,
TelemetryDataValue::Float64(value) => file.write_data::<f64>(*value)?,
TelemetryDataValue::Boolean(value) => file.write_data::<bool>(*value)?,
}
}
@@ -346,6 +347,10 @@ impl HistorySegmentFile {
self.file_position += 8;
Ok(TelemetryDataValue::Float64(self.file.read_data::<f64>()?))
}
TelemetryDataType::Boolean => {
self.file_position += 1;
Ok(TelemetryDataValue::Boolean(self.file.read_data::<bool>()?))
}
}
}
@@ -357,6 +362,7 @@ impl HistorySegmentFile {
let item_length = match telemetry_data_type {
TelemetryDataType::Float32 => 4,
TelemetryDataType::Float64 => 8,
TelemetryDataType::Boolean => 1,
};
let desired_position =
Self::HEADER_LENGTH + self.length * Self::TIMESTAMP_LENGTH + index * item_length;