Skip to content

Commit

Permalink
removing vifextensiion from plain text vif
Browse files Browse the repository at this point in the history
  • Loading branch information
maebli committed Mar 28, 2024
1 parent 4ec45a2 commit f926bfe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
27 changes: 10 additions & 17 deletions src/user_data/value_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ use arrayvec::ArrayVec;

const MAX_PLAIN_TEXT_VIF_SIZE: usize = 10;
/* TODO add suppor for 2 - 10 VIFE */
const MAX_VIF_RECORDS: usize = 10;

const MAX_VIFE_RECORDS: usize = 10;
#[derive(Debug)]
struct ValueInformationBlock {
_value_information: ValueInformation,
_value_information_extension: Option<ArrayVec<u8, MAX_VIF_RECORDS>>,
_value_information_extension: Option<ArrayVec<u8, MAX_VIFE_RECORDS>>,
}

#[derive(Debug, PartialEq)]
pub enum ValueInformation {
Primary(u8),
PlainText(ArrayVec<u8, MAX_PLAIN_TEXT_VIF_SIZE>, Option<VIFExtension>),
PlainText(ArrayVec<u8, MAX_PLAIN_TEXT_VIF_SIZE>),
Extended(VIFExtension),
Any,
ManufacturerSpecific,
Expand All @@ -22,8 +23,7 @@ impl ValueInformation {
pub fn get_size(&self) -> usize {
match self {
ValueInformation::Primary(_) => 1,
ValueInformation::PlainText(x, None) => x.len() + 2,
ValueInformation::PlainText(x, Some(_)) => x.len() + 3,
ValueInformation::PlainText(x) => x.len() + 2,
ValueInformation::Extended(_) => 2,
ValueInformation::Any => 1,
ValueInformation::ManufacturerSpecific => 1,
Expand All @@ -49,7 +49,7 @@ impl TryFrom<&[u8]> for ValueInformation {
vif.push(data[i + 2]);
}
vif.reverse();
ValueInformation::PlainText(vif, None)
ValueInformation::PlainText(vif)
}
0xFD => ValueInformation::Extended(match data[1] {
0x00..=0x03 => VIFExtension::CreditOfCurrencyUnits(0b11 & data[1]),
Expand Down Expand Up @@ -279,8 +279,8 @@ impl TryFrom<&ValueInformation> for Unit {
0x78 => Ok(Unit::FabricationNumber),
_ => todo!("Implement the rest of the units: {:?}", x),
},
ValueInformation::PlainText(_, None) => Ok(Unit::PlainText),
ValueInformation::PlainText(_, Some(_)) => Ok(Unit::PlainText),
ValueInformation::PlainText(_) => Ok(Unit::PlainText),
ValueInformation::PlainText(_) => Ok(Unit::PlainText),
ValueInformation::Extended(x) => match x {
VIFExtension::EnergyMWh(_) => Ok(Unit::MegaWattHour),
VIFExtension::EnergyGJ(_) => Ok(Unit::GigaJoul),
Expand Down Expand Up @@ -361,16 +361,12 @@ mod tests {
a.try_extend_from_slice(&data[2..5]).unwrap();
a.reverse();
let result = ValueInformation::try_from(data.as_slice()).unwrap();
assert_eq!(
result,
ValueInformation::PlainText(a, Some(VIFExtension::Reserved))
);
assert_eq!(result, ValueInformation::PlainText(a));
assert_eq!(result.get_size(), 6);
}

#[test]
fn test_plain_text_vif_norm_conform() {
use crate::user_data::value_information::VIFExtension;
use crate::user_data::value_information::ValueInformation;
use arrayvec::ArrayVec;
// This is the ascii conform method of encoding the VIF
Expand All @@ -382,10 +378,7 @@ mod tests {
a.try_extend_from_slice(&data[2..5]).unwrap();
a.reverse();
let result = ValueInformation::try_from(data.as_slice()).unwrap();
assert_eq!(
result,
ValueInformation::PlainText(a, Some(VIFExtension::Reserved))
);
assert_eq!(result, ValueInformation::PlainText(a));
assert_eq!(result.get_size(), 6);
}
}
6 changes: 3 additions & 3 deletions src/user_data/variable_user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl From<&ValueInformation> for Quantity {
0x78 => Quantity::IdentificationNumber,
_ => todo!("Implement the rest of the units: {:?}", x),
},
ValueInformation::PlainText(_, _) => Quantity::PlainText,
ValueInformation::PlainText(_) => Quantity::PlainText,
ValueInformation::Extended(x) => match x {
value_information::VIFExtension::DigitalInput => Quantity::BinaryDigitalInput,
_ => todo!("Implement the rest of the units: {:?}", x),
Expand All @@ -69,7 +69,7 @@ impl From<&ValueInformation> for Exponent {
0x6E..=0x6F | 0x78 => Exponent { inner: None },
_ => todo!("Implement the rest of the units: {:?}", x),
},
ValueInformation::PlainText(_, _) => Exponent { inner: None },
ValueInformation::PlainText(_) => Exponent { inner: None },
ValueInformation::Extended(x) => match x {
value_information::VIFExtension::DigitalInput => Exponent { inner: None },
_ => todo!("Implement the rest of the units: {:?}", x),
Expand Down Expand Up @@ -129,7 +129,7 @@ impl TryFrom<&[u8]> for DataRecord {
let value_and_data_information_size =
data_information.get_size() + value_information.get_size();
match value_information {
ValueInformation::PlainText(_, _) => {
ValueInformation::PlainText(_) => {
let plaintext_size = data[value_and_data_information_size] as usize;
let total_size = value_and_data_information_size + plaintext_size + 1;
Ok(DataRecord {
Expand Down

0 comments on commit f926bfe

Please sign in to comment.