Skip to content

Commit

Permalink
Add allowed values to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
argerus committed Sep 24, 2024
1 parent 7951c62 commit 4f1a0b0
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 3 deletions.
3 changes: 3 additions & 0 deletions databroker-cli/src/sdv_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ mod test {
entry_type: proto::v1::EntryType::Sensor.into(),
change_type: proto::v1::ChangeType::OnChange.into(),
description: "".into(),
allowed: None,
},
proto::v1::Metadata {
id: 2,
Expand All @@ -1270,6 +1271,7 @@ mod test {
entry_type: proto::v1::EntryType::Sensor.into(),
change_type: proto::v1::ChangeType::OnChange.into(),
description: "".into(),
allowed: None,
},
proto::v1::Metadata {
id: 3,
Expand All @@ -1278,6 +1280,7 @@ mod test {
entry_type: proto::v1::EntryType::Sensor.into(),
change_type: proto::v1::ChangeType::OnChange.into(),
description: "".into(),
allowed: None,
},
]
.to_vec();
Expand Down
68 changes: 67 additions & 1 deletion databroker/src/grpc/kuksa_val_v1/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,73 @@ fn proto_entry_from_entry_and_fields(
}
if all || fields.contains(&proto::Field::MetadataValueRestriction) {
metadata_is_set = true;
// TODO: Add to Metadata
metadata.value_restriction = match entry.metadata().allowed.as_ref() {
Some(allowed) => match allowed {
broker::DataValue::StringArray(vec) => Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::String(
proto::ValueRestrictionString {
allowed_values: vec.clone(),
},
)),
}),
broker::DataValue::Int32Array(vec) => Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::Signed(
proto::ValueRestrictionInt {
allowed_values: vec.iter().cloned().map(i64::from).collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
}),
broker::DataValue::Int64Array(vec) => Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::Signed(
proto::ValueRestrictionInt {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
}),
broker::DataValue::Uint32Array(vec) => Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::Unsigned(
proto::ValueRestrictionUint {
allowed_values: vec.iter().cloned().map(u64::from).collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
}),
broker::DataValue::Uint64Array(vec) => Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::Unsigned(
proto::ValueRestrictionUint {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
}),
broker::DataValue::FloatArray(vec) => Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::FloatingPoint(
proto::ValueRestrictionFloat {
allowed_values: vec.iter().cloned().map(f64::from).collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
}),
broker::DataValue::DoubleArray(vec) => Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::FloatingPoint(
proto::ValueRestrictionFloat {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
}),
_ => None,
},
None => None,
}
}
if all || fields.contains(&proto::Field::MetadataActuator) {
metadata_is_set = true;
Expand Down
48 changes: 48 additions & 0 deletions databroker/src/grpc/sdv_databroker_v1/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,54 @@ impl From<&broker::Metadata> for proto::Metadata {
data_type: proto::DataType::from(&metadata.data_type) as i32,
change_type: proto::ChangeType::Continuous as i32, // TODO: Add to metadata
description: metadata.description.to_owned(),
allowed: match metadata.allowed.as_ref() {
Some(broker::DataValue::StringArray(vec)) => Some(proto::Allowed {
values: Some(proto::allowed::Values::StringValues(proto::StringArray {
values: vec.clone(),
})),
}),
Some(broker::DataValue::Int32Array(vec)) => Some(proto::Allowed {
values: Some(proto::allowed::Values::Int32Values(proto::Int32Array {
values: vec.clone(),
})),
}),
Some(broker::DataValue::Int64Array(vec)) => Some(proto::Allowed {
values: Some(proto::allowed::Values::Int64Values(proto::Int64Array {
values: vec.clone(),
})),
}),
Some(broker::DataValue::Uint32Array(vec)) => Some(proto::Allowed {
values: Some(proto::allowed::Values::Uint32Values(proto::Uint32Array {
values: vec.clone(),
})),
}),
Some(broker::DataValue::Uint64Array(vec)) => Some(proto::Allowed {
values: Some(proto::allowed::Values::Uint64Values(proto::Uint64Array {
values: vec.clone(),
})),
}),
Some(broker::DataValue::FloatArray(vec)) => Some(proto::Allowed {
values: Some(proto::allowed::Values::FloatValues(proto::FloatArray {
values: vec.clone(),
})),
}),
Some(broker::DataValue::DoubleArray(vec)) => Some(proto::Allowed {
values: Some(proto::allowed::Values::DoubleValues(proto::DoubleArray {
values: vec.clone(),
})),
}),
Some(broker::DataValue::BoolArray(_))
| Some(broker::DataValue::NotAvailable)
| Some(broker::DataValue::Bool(_))
| Some(broker::DataValue::String(_))
| Some(broker::DataValue::Int32(_))
| Some(broker::DataValue::Int64(_))
| Some(broker::DataValue::Uint32(_))
| Some(broker::DataValue::Uint64(_))
| Some(broker::DataValue::Float(_))
| Some(broker::DataValue::Double(_))
| None => None,
},
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions proto/sdv/databroker/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,27 @@ message Datapoint {
}
}

message Allowed {
oneof values {
StringArray string_values = 1;
Int32Array int32_values = 3;
Int64Array int64_values = 4;
Uint32Array uint32_values = 5;
Uint64Array uint64_values = 6;
FloatArray float_values = 7;
DoubleArray double_values = 8;
}
}

message Metadata {
// Id to be used in "get" and "subscribe" requests. Ids stay valid during
// one power cycle, only.
int32 id = 1;
EntryType entry_type = 2;
string name = 4;
DataType data_type = 5;
ChangeType change_type = 6; // CONTINUOUS or STATIC or ON_CHANGE
string description = 7;

Allowed allowed = 10;
// int32 min_update_hz = 10; // Only for CONTINUOUS
// int32 max_update_hz = 11; // Only for CONTINUOUS
};

0 comments on commit 4f1a0b0

Please sign in to comment.