Skip to content

Commit

Permalink
rpcの各所にdescriptionを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
shunsuke-shimomura committed Jun 10, 2024
1 parent ee2fec5 commit 93c51cb
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 63 deletions.
39 changes: 35 additions & 4 deletions gaia-ccsds-c2a/src/access/cmd/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{ensure, Result};
use funty::{Floating, Integral};
use structpack::{
FloatingField, GenericFloatingField, GenericIntegralField, IntegralField, NumericField,
SizedField,
NumericValue, SizedField,
};
use tlmcmddb::{cmd as cmddb, Component};

Expand All @@ -13,20 +13,47 @@ pub struct Metadata {
pub component_name: String,
pub command_name: String,
pub cmd_id: u16,
pub description: String,
}

#[derive(Debug, Clone)]
pub struct CommandSchema {
pub sized_parameters: Vec<NumericField>,
pub sized_parameters: Vec<ParamField>,
pub static_size: usize,
pub has_trailer_parameter: bool,
}

#[derive(Debug, Clone)]
pub struct ParamField {
pub value: NumericField,
pub description: String,
}

impl SizedField for ParamField {
type Value<'a> = NumericValue;

fn read<'a>(&self, bytes: &'a [u8]) -> Result<Self::Value<'a>> {
self.value.read(bytes)
}

fn write(&self, bytes: &mut [u8], value: Self::Value<'_>) -> Result<()> {
self.value.write(bytes, value)
}

fn last_bit_exclusive(&self) -> usize {
self.value.last_bit_exclusive()
}

fn bit_len(&self) -> usize {
self.value.bit_len()
}
}

impl CommandSchema {
pub fn build_writer<'b>(
&'b self,
bytes: &'b mut [u8],
) -> Writer<'b, std::slice::Iter<'b, NumericField>> {
) -> Writer<'b, std::slice::Iter<'b, ParamField>> {
Writer::new(
self.sized_parameters.iter(),
self.static_size,
Expand Down Expand Up @@ -76,6 +103,7 @@ impl<'a> Iterator for Iter<'a> {
component_name: self.name.to_string(),
command_name: command.name.to_string(),
cmd_id: command.code,
description: command.description.to_string(),
};
return build_schema(command)
.map(|schema| Some((metadata, schema)))
Expand All @@ -92,7 +120,10 @@ fn build_schema(db: &cmddb::Command) -> Result<CommandSchema> {
for parameter in params_iter.by_ref() {
if let Some(field) = build_numeric_field(static_size_bits, parameter) {
static_size_bits += field.bit_len();
sized_parameters.push(field);
sized_parameters.push(ParamField {
value: field,
description: parameter.description.clone(),
});
} else {
// raw parameter is present
has_trailer_parameter = true;
Expand Down
82 changes: 48 additions & 34 deletions gaia-ccsds-c2a/src/access/tlm/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ impl FloatingFieldSchema {
}
}

pub enum FieldSchema {
pub struct FieldSchema {
pub metadata: FieldMetadata,
pub value: FieldValueSchema,
}

pub struct FieldMetadata {
pub description: String,
}

pub enum FieldValueSchema {
Integral(IntegralFieldSchema),
Floating(FloatingFieldSchema),
}
Expand Down Expand Up @@ -135,39 +144,44 @@ fn build_field_schema(
let converter = build_integral_converter(&field.conversion_info);
Ok((
&field.name,
match obs.variable_type {
tlmdb::VariableType::Int8 => FieldSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::I8(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Int16 => FieldSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::I16(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Int32 => FieldSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::I32(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Uint8 => FieldSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::U8(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Uint16 => FieldSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::U16(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Uint32 => FieldSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::U32(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Float => FieldSchema::Floating(FloatingFieldSchema {
converter: as_polynomial(converter)?,
field: GenericFloatingField::F32(build_telemetry_floating_field(bit_range)?),
}),
tlmdb::VariableType::Double => FieldSchema::Floating(FloatingFieldSchema {
converter: as_polynomial(converter)?,
field: GenericFloatingField::F64(build_telemetry_floating_field(bit_range)?),
}),
FieldSchema {
metadata: FieldMetadata {
description: field.description.clone(),
},
value: match obs.variable_type {
tlmdb::VariableType::Int8 => FieldValueSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::I8(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Int16 => FieldValueSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::I16(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Int32 => FieldValueSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::I32(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Uint8 => FieldValueSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::U8(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Uint16 => FieldValueSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::U16(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Uint32 => FieldValueSchema::Integral(IntegralFieldSchema {
converter,
field: GenericIntegralField::U32(build_telemetry_integral_field(bit_range)?),
}),
tlmdb::VariableType::Float => FieldValueSchema::Floating(FloatingFieldSchema {
converter: as_polynomial(converter)?,
field: GenericFloatingField::F32(build_telemetry_floating_field(bit_range)?),
}),
tlmdb::VariableType::Double => FieldValueSchema::Floating(FloatingFieldSchema {
converter: as_polynomial(converter)?,
field: GenericFloatingField::F64(build_telemetry_floating_field(bit_range)?),
}),
},
},
))
}
Expand Down
14 changes: 11 additions & 3 deletions tmtc-c2a/proto/tmtc_generic_c2a.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ message CommandSchema {

message CommandSchemaMetadata {
uint32 id = 1;
string description = 2;
}

message CommandParameterSchema {
Expand All @@ -53,7 +54,7 @@ message CommandParameterSchema {
}

message CommandParameterSchemaMetadata {
// TODO: string description = 1;
string description = 1;
}

enum CommandParameterDataType {
Expand All @@ -74,11 +75,18 @@ message TelemetrySchemaMetadata {
message TelemetryFieldSchema {
TelemetryFieldSchemaMetadata metadata = 1;
string name = 2;
// TODO: TelemetryFieldDataType data_type = 3;
}

enum TelemetryFieldDataType {
Integer = 0;
Double = 1;
Enum = 3;
Bytes = 4;
}

message TelemetryFieldSchemaMetadata {
// TODO: string description = 1;
string description = 1;
TelemetryFieldDataType data_type = 2;
}

message TelemetryChannelSchema {
Expand Down
38 changes: 23 additions & 15 deletions tmtc-c2a/src/registry/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use anyhow::{anyhow, Result};
use gaia_ccsds_c2a::access::cmd::schema::{from_tlmcmddb, CommandSchema};
use gaia_ccsds_c2a::access::cmd::schema::{from_tlmcmddb, CommandSchema, Metadata};
use itertools::Itertools;

use crate::proto::tmtc_generic_c2a as proto;
Expand Down Expand Up @@ -62,7 +62,7 @@ struct CommandSchemaWithId {
#[derive(Debug, Clone)]
pub struct Registry {
prefix_map: satconfig::CommandPrefixMap,
schema_map: HashMap<(String, String), CommandSchemaWithId>,
schema_map: HashMap<(String, String), (Metadata, CommandSchemaWithId)>,
}

impl Registry {
Expand Down Expand Up @@ -100,16 +100,18 @@ impl Registry {
self.schema_map
.iter()
.sorted_by_key(|&((component_name, _), _)| component_name)
.group_by(|&((component_name, _), schema_with_id)| {
.group_by(|&((component_name, _), (_, schema_with_id))| {
(component_name, schema_with_id.apid)
})
.into_iter()
.map(|((component_name, apid), group)| {
let command_schema_map = group
.map(|((_, command_name), schema_with_id)| {
.map(|((_, command_name), (metadata, schema_with_id))| {
let trailer_parameter = if schema_with_id.schema.has_trailer_parameter {
Some(proto::CommandParameterSchema {
metadata: Some(proto::CommandParameterSchemaMetadata {}),
metadata: Some(proto::CommandParameterSchemaMetadata {
description: metadata.description.clone(),
}),
data_type: proto::CommandParameterDataType::CmdParameterBytes
.into(),
})
Expand All @@ -121,7 +123,7 @@ impl Registry {
.sized_parameters
.iter()
.map(|param| {
let data_type = match param {
let data_type = match param.value {
structpack::NumericField::Integral(_) => {
proto::CommandParameterDataType::CmdParameterInteger
}
Expand All @@ -130,7 +132,9 @@ impl Registry {
}
};
proto::CommandParameterSchema {
metadata: Some(proto::CommandParameterSchemaMetadata {}),
metadata: Some(proto::CommandParameterSchemaMetadata {
description: param.description.clone(),
}),
data_type: data_type.into(),
}
})
Expand All @@ -140,6 +144,7 @@ impl Registry {
let command_schema = proto::CommandSchema {
metadata: Some(proto::CommandSchemaMetadata {
id: schema_with_id.command_id as u32,
description: metadata.description.clone(),
}),
parameters,
};
Expand All @@ -166,11 +171,14 @@ impl Registry {
destination_type,
execution_type,
} = self.prefix_map.get(&prefix)?.get(&component)?;
let CommandSchemaWithId {
apid,
command_id,
schema,
} = self.schema_map.get(&(component, command))?;
let (
_,
CommandSchemaWithId {
apid,
command_id,
schema,
},
) = self.schema_map.get(&(component, command))?;
Some(FatCommandSchema {
apid: *apid,
command_id: *command_id,
Expand All @@ -190,8 +198,8 @@ impl Registry {
.flatten()
.map(|schema| {
let (metadata, schema) = schema?;
let component = metadata.component_name;
let cmddb_name = metadata.command_name;
let component = metadata.component_name.clone();
let cmddb_name = metadata.command_name.clone();
let apid = *apid_map
.get(&component)
.ok_or_else(|| anyhow!("APID is not defined for {component}"))?;
Expand All @@ -200,7 +208,7 @@ impl Registry {
command_id: metadata.cmd_id,
schema,
};
Ok(((component, cmddb_name), schema_with_id))
Ok(((component, cmddb_name), (metadata, schema_with_id)))
})
.collect::<Result<_>>()?;
Ok(Self {
Expand Down
Loading

0 comments on commit 93c51cb

Please sign in to comment.