Skip to content

Commit

Permalink
fix(vt): set object ids that can be NULL to nullable type
Browse files Browse the repository at this point in the history
  • Loading branch information
GwnDaan committed Dec 13, 2023
1 parent da74b03 commit baf3720
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/network_management/network_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl NetworkManager {
self.get_control_function_address_by_name(destination.get_name()),
priority,
)
.unwrap_or(CanId::default());
.unwrap_or_default();

if message_id.raw() != CanId::default().raw() {
self.enqueue_can_message(
Expand Down
5 changes: 4 additions & 1 deletion src/object_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod colour;
pub mod reader;
pub mod writer;

mod object;
pub mod object;
mod object_attributes;
mod object_id;
mod object_pool;
Expand All @@ -19,4 +19,7 @@ pub use object_type::ObjectType;
pub enum ParseError {
DataEmpty,
UnknownObjectType,
UnexpectedNullObjectId,
BooleanOutOfRange,
UnsupportedVtVersion,
}
74 changes: 38 additions & 36 deletions src/object_pool/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::object_pool::object_attributes::{
use crate::object_pool::object_id::ObjectId;
use crate::object_pool::{Colour, ObjectType};

use super::object_id::NullableObjectId;

#[derive(Debug)]
pub enum Object {
WorkingSet(WorkingSet),
Expand Down Expand Up @@ -191,7 +193,7 @@ pub struct WorkingSet {
pub struct DataMask {
pub id: ObjectId,
pub background_colour: u8,
pub soft_key_mask: ObjectId,
pub soft_key_mask: NullableObjectId,
pub object_refs: Vec<ObjectRef>,
pub macro_refs: Vec<MacroRef>,
}
Expand All @@ -200,7 +202,7 @@ pub struct DataMask {
pub struct AlarmMask {
pub id: ObjectId,
pub background_colour: u8,
pub soft_key_mask: ObjectId,
pub soft_key_mask: NullableObjectId,
pub priority: u8,
pub acoustic_signal: u8,
pub object_refs: Vec<ObjectRef>,
Expand Down Expand Up @@ -253,7 +255,7 @@ pub struct InputBoolean {
pub background_colour: u8,
pub width: u16,
pub foreground_colour: ObjectId,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub value: bool,
pub enabled: bool,
pub macro_refs: Vec<MacroRef>,
Expand All @@ -266,9 +268,9 @@ pub struct InputString {
pub height: u16,
pub background_colour: u8,
pub font_attributes: ObjectId,
pub input_attributes: ObjectId,
pub input_attributes: NullableObjectId,
pub options: InputStringOptions,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub justification: Alignment,
pub value: String,
pub enabled: bool,
Expand All @@ -283,7 +285,7 @@ pub struct InputNumber {
pub background_colour: u8,
pub font_attributes: ObjectId,
pub options: NumberOptions,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub value: u32,
pub min_value: u32,
pub max_value: u32,
Expand All @@ -301,10 +303,10 @@ pub struct InputList {
pub id: ObjectId,
pub width: u16,
pub height: u16,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub value: u8,
pub options: InputListOptions,
pub list_items: Vec<ObjectId>,
pub list_items: Vec<NullableObjectId>,
pub macro_refs: Vec<MacroRef>,
}

Expand All @@ -316,7 +318,7 @@ pub struct OutputString {
pub background_colour: u8,
pub font_attributes: ObjectId,
pub options: OutputStringOptions,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub justification: Alignment,
pub value: String,
pub macro_refs: Vec<MacroRef>,
Expand All @@ -330,7 +332,7 @@ pub struct OutputNumber {
pub background_colour: u8,
pub font_attributes: ObjectId,
pub options: NumberOptions,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub value: u32,
pub offset: i32,
pub scale: f32,
Expand All @@ -345,9 +347,9 @@ pub struct OutputList {
pub id: ObjectId,
pub width: u16,
pub height: u16,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub value: u8,
pub list_items: Vec<ObjectId>,
pub list_items: Vec<NullableObjectId>,
pub macro_refs: Vec<MacroRef>,
}

Expand All @@ -368,7 +370,7 @@ pub struct OutputRectangle {
pub width: u16,
pub height: u16,
pub line_suppression: u8,
pub fill_attributes: ObjectId,
pub fill_attributes: NullableObjectId,
pub macro_refs: Vec<MacroRef>,
}

Expand All @@ -381,7 +383,7 @@ pub struct OutputEllipse {
pub ellipse_type: u8,
pub start_angle: u8,
pub end_angle: u8,
pub fill_attributes: ObjectId,
pub fill_attributes: NullableObjectId,
pub macro_refs: Vec<MacroRef>,
}

Expand All @@ -391,7 +393,7 @@ pub struct OutputPolygon {
pub width: u16,
pub height: u16,
pub line_attributes: ObjectId,
pub fill_attributes: ObjectId,
pub fill_attributes: NullableObjectId,
pub polygon_type: u8,
pub points: Vec<Point<u16>>,
pub macro_refs: Vec<MacroRef>,
Expand All @@ -410,7 +412,7 @@ pub struct OutputMeter {
pub end_angle: u8,
pub min_value: u16,
pub max_value: u16,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub value: u16,
pub macro_refs: Vec<MacroRef>,
}
Expand All @@ -426,9 +428,9 @@ pub struct OutputLinearBarGraph {
pub nr_of_ticks: u8,
pub min_value: u16,
pub max_value: u16,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub value: u16,
pub target_value_variable_reference: ObjectId,
pub target_value_variable_reference: NullableObjectId,
pub target_value: u16,
pub macro_refs: Vec<MacroRef>,
}
Expand All @@ -446,9 +448,9 @@ pub struct OutputArchedBarGraph {
pub bar_graph_width: u16,
pub min_value: u16,
pub max_value: u16,
pub variable_reference: ObjectId,
pub variable_reference: NullableObjectId,
pub value: u16,
pub target_value_variable_reference: ObjectId,
pub target_value_variable_reference: NullableObjectId,
pub target_value: u16,
pub macro_refs: Vec<MacroRef>,
}
Expand Down Expand Up @@ -502,7 +504,7 @@ pub struct FillAttributes {
pub id: ObjectId,
pub fill_type: u8,
pub fill_colour: u8,
pub fill_pattern: ObjectId,
pub fill_pattern: NullableObjectId,
pub macro_refs: Vec<MacroRef>,
}

Expand Down Expand Up @@ -561,7 +563,7 @@ pub struct ExtendedInputAttributes {
#[derive(Debug)]
pub struct ObjectPointer {
pub id: ObjectId,
pub value: ObjectId,
pub value: NullableObjectId,
}

#[derive(Debug)]
Expand Down Expand Up @@ -630,9 +632,9 @@ pub struct GraphicsContext {
pub graphics_cursor_y: i16,
pub foreground_colour: u8,
pub background_colour: u8,
pub font_attributes_object: ObjectId,
pub line_attributes_object: ObjectId,
pub fill_attributes_object: ObjectId,
pub font_attributes_object: NullableObjectId,
pub line_attributes_object: NullableObjectId,
pub fill_attributes_object: NullableObjectId,
pub format: ColorFormat,
pub options: GraphicsContextOptions,
pub transparency_colour: u8,
Expand All @@ -646,9 +648,9 @@ pub struct WindowMask {
pub background_colour: u8,
pub options: WindowMaskOptions,
pub name: ObjectId,
pub window_title: ObjectId,
pub window_icon: ObjectId,
pub objects: Vec<ObjectId>,
pub window_title: NullableObjectId,
pub window_icon: NullableObjectId,
pub objects: Vec<NullableObjectId>,
pub object_refs: Vec<ObjectRef>,
pub macro_refs: Vec<MacroRef>,
}
Expand All @@ -658,7 +660,7 @@ pub struct KeyGroup {
pub id: ObjectId,
pub options: KeyGroupOptions,
pub name: ObjectId,
pub key_group_icon: ObjectId,
pub key_group_icon: NullableObjectId,
pub objects: Vec<ObjectId>,
pub macro_refs: Vec<MacroRef>,
}
Expand All @@ -674,7 +676,7 @@ pub struct ExternalObjectDefinition {
pub id: ObjectId,
pub options: ExternalObjectDefinitionOptions,
pub name: NAME,
pub objects: Vec<ObjectId>,
pub objects: Vec<NullableObjectId>,
}

#[derive(Debug)]
Expand All @@ -687,9 +689,9 @@ pub struct ExternalReferenceName {
#[derive(Debug)]
pub struct ExternalObjectPointer {
pub id: ObjectId,
pub default_object_id: ObjectId,
pub external_reference_name_id: ObjectId,
pub external_object_id: ObjectId,
pub default_object_id: NullableObjectId,
pub external_reference_name_id: NullableObjectId,
pub external_object_id: NullableObjectId,
}

#[derive(Debug)]
Expand Down Expand Up @@ -729,14 +731,14 @@ pub struct ScaledGraphic {
pub height: u16,
pub scale_type: u8,
pub options: ScaledGraphicOptions,
pub value: u16,
pub value: NullableObjectId,
pub macro_refs: Vec<MacroRef>,
}

#[derive(Debug)]
pub struct WorkingSetSpecialControls {
pub id: ObjectId,
pub id_of_colour_map: ObjectId,
pub id_of_colour_palette: ObjectId,
pub id_of_colour_map: NullableObjectId,
pub id_of_colour_palette: NullableObjectId,
pub language_pairs: Vec<(String, String)>,
}
6 changes: 4 additions & 2 deletions src/object_pool/object_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use bitvec::vec::BitVec;
use bitvec::view::BitView;
use strum_macros::FromRepr;

use super::object_id::NullableObjectId;

#[derive(FromRepr, Debug, PartialEq, Clone, Copy)]
#[repr(u8)]
pub enum WindowType {
Expand Down Expand Up @@ -168,9 +170,9 @@ impl core::ops::Add<Point<i16>> for Point<u16> {
#[derive(Debug)]
pub struct ObjectLabel {
pub id: ObjectId,
pub string_variable_reference: ObjectId,
pub string_variable_reference: NullableObjectId,
pub font_type: u8,
pub graphic_representation: ObjectId,
pub graphic_representation: NullableObjectId,
}

#[derive(Debug, PartialEq, Clone, Copy)]
Expand Down
3 changes: 2 additions & 1 deletion src/object_pool/object_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ impl ObjectId {

pub fn new(id: u16) -> Result<Self, ParseError> {
if id == Self::NULL.id {
Err(ParseError::UnknownObjectType)
Err(ParseError::UnexpectedNullObjectId)

Check warning on line 13 in src/object_pool/object_id.rs

View check run for this annotation

Codecov / codecov/patch

src/object_pool/object_id.rs#L13

Added line #L13 was not covered by tests
} else {
Ok(ObjectId { id })
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NullableObjectId(Option<ObjectId>);

impl NullableObjectId {
Expand Down
Loading

0 comments on commit baf3720

Please sign in to comment.