use open_protocol_codec_proc_macro::{OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage};
#[derive(Debug, Eq, PartialEq, Default, OpenProtocolEncode, OpenProtocolDecode)]
pub enum RotationDirection {
#[default]
#[open_protocol_value(number=1)]
ClockWise,
#[open_protocol_value(number=2)]
CounterClockWise,
}
#[derive(Debug, Eq, PartialEq, Default, OpenProtocolEncode, OpenProtocolDecode)]
pub enum RelayStatus {
#[default]
#[open_protocol_value(number=0)]
Inactive,
#[open_protocol_value(number=1)]
Active,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0010, revision = 1)]
pub struct MID0010rev1 {
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0011, revision = 1)]
pub struct MID0011rev1 {
#[open_protocol_field(length = 3)]
pub number_of_parameter_sets: u16,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 3)]
pub parameter_set_ids: Vec<u16>,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0011, revision = 2)]
pub struct MID0011rev2 {
#[open_protocol_field(length = 3)]
pub number_of_parameter_sets: u16,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 3)]
pub parameter_set_ids: Vec<u16>,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 2)]
pub cycles: Vec<u8>,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0011, revision = 3)]
pub struct MID0011rev3 {
#[open_protocol_field(length = 3)]
pub number_of_parameter_sets: u16,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 3)]
pub parameter_set_ids: Vec<u16>,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 2)]
pub cycles: Vec<u8>,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 4)]
pub types: Vec<String>,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0011, revision = 4)]
pub struct MID0011rev4 {
#[open_protocol_field(length = 3)]
pub number_of_parameter_sets: u16,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 3)]
pub parameter_set_ids: Vec<u16>,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 2)]
pub cycles: Vec<u8>,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 4)]
pub types: Vec<String>,
#[open_protocol_field(list, amount = "number_of_parameter_sets", length = 19)]
pub date_of_last_change: Vec<String>,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0012, revision = 1)]
pub struct MID0012rev1 {
#[open_protocol_field(length = 3)]
pub parameter_set_id: u16,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0013, revision = 1)]
pub struct MID0013rev1 {
#[open_protocol_field(number = 1, length = 3)]
pub parameter_set_id: u16,
#[open_protocol_field(number = 2, length = 25)]
pub parameter_set_name: String,
#[open_protocol_field(number = 3, length = 1)]
pub rotation_direction: RotationDirection,
#[open_protocol_field(number = 4, length = 2)]
pub batch_size: u8,
#[open_protocol_field(number = 5, length = 6)]
pub torque_min: u32,
#[open_protocol_field(number = 6, length = 6)]
pub torque_max: u32,
#[open_protocol_field(number = 7, length = 6)]
pub final_torque_target: u32,
#[open_protocol_field(number = 8, length = 5)]
pub angle_min: u16,
#[open_protocol_field(number = 9, length = 5)]
pub angle_max: u16,
#[open_protocol_field(number = 10, length = 5)]
pub final_angle_target: u16,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0013, revision = 2)]
pub struct MID0013rev2 {
#[open_protocol_field(number = 1, length = 3)]
pub parameter_set_id: u16,
#[open_protocol_field(number = 2, length = 25)]
pub parameter_set_name: String,
#[open_protocol_field(number = 3, length = 1)]
pub rotation_direction: RotationDirection,
#[open_protocol_field(number = 4, length = 2)]
pub batch_size: u8,
#[open_protocol_field(number = 5, length = 6)]
pub torque_min: u32,
#[open_protocol_field(number = 6, length = 6)]
pub torque_max: u32,
#[open_protocol_field(number = 7, length = 6)]
pub final_torque_target: u32,
#[open_protocol_field(number = 8, length = 5)]
pub angle_min: u16,
#[open_protocol_field(number = 9, length = 5)]
pub angle_max: u16,
#[open_protocol_field(number = 10, length = 5)]
pub final_angle_target: u16,
#[open_protocol_field(number = 11, length = 6)]
pub first_target: u32,
#[open_protocol_field(number = 12, length = 6)]
pub start_final_angle: u32,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0014, revision = 1)]
pub struct MID0014rev1 {
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0015, revision = 1)]
pub struct MID0015rev1 {
#[open_protocol_field(number = 1, length = 3)]
pub parameter_set_id: u16,
#[open_protocol_field(number = 2, length = 19)]
pub date_of_last_change: String,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0015, revision = 2)]
pub struct MID0015rev2 {
#[open_protocol_field(number = 1, length = 3)]
pub parameter_set_id: u16,
#[open_protocol_field(number = 2, length = 25)]
pub parameter_set_name: String,
#[open_protocol_field(number = 3, length = 19)]
pub date_of_last_change: String,
#[open_protocol_field(number = 4, length = 1)]
pub rotation_direction: u8,
#[open_protocol_field(number = 5, length = 2)]
pub batch_size: u8,
#[open_protocol_field(number = 6, length = 6)]
pub torque_min: u32,
#[open_protocol_field(number = 7, length = 6)]
pub torque_max: u32,
#[open_protocol_field(number = 8, length = 6)]
pub final_torque_target: u32,
#[open_protocol_field(number = 9, length = 5)]
pub angle_min: u16,
#[open_protocol_field(number = 10, length = 5)]
pub angle_max: u16,
#[open_protocol_field(number = 11, length = 5)]
pub final_angle_target: u16,
#[open_protocol_field(number = 12, length = 6)]
pub first_torque_target: u32,
#[open_protocol_field(number = 13, length = 6)]
pub start_final_angle: u32,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0016, revision = 1)]
pub struct MID0016rev1 {
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0017, revision = 1)]
pub struct MID0017rev1 {
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0018, revision = 1)]
pub struct MID0018rev1 {
#[open_protocol_field(number = 1, length = 3)]
pub parameter_set_id: u16,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0019, revision = 1)]
pub struct MID0019rev1 {
#[open_protocol_field(number = 1, length = 3)]
pub parameter_set_id: u16,
#[open_protocol_field(number = 2, length = 2)]
pub batch_size: u8,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0019, revision = 2)]
pub struct MID0019rev2 {
#[open_protocol_field(number = 1, length = 3)]
pub parameter_set_id: u16,
#[open_protocol_field(number = 2, length = 4)]
pub batch_size: u16,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0020, revision = 1)]
pub struct MID0020rev1 {
#[open_protocol_field(number = 1, length = 3)]
pub parameter_set_id: u16,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0021, revision = 1)]
pub struct MID0021rev1 {
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 0022, revision = 1)]
pub struct MID0022rev1 {
#[open_protocol_field(number = 1, length = 1)]
pub relay_status: RelayStatus,
}
#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
#[open_protocol_message(MID = 2506, revision = 1)]
pub struct MID2506rev1 {
#[open_protocol_field(number = 1, length = 4)]
pub program_id: u32,
#[open_protocol_field(number = 2, length = 3)]
pub node_type: u16,
}
#[cfg(test)]
mod tests {
use open_protocol_codec::{decode, encode};
use super::*;
#[test]
fn encode_0010() {
let message = MID0010rev1 {};
let result = encode::encode(&message);
assert_eq!(result, Ok("".to_string()));
}
#[test]
fn encode_0012() {
let message = MID0012rev1 { parameter_set_id: 12 };
let result = encode::encode(&message);
assert_eq!(result, Ok("012".to_string()));
}
#[test]
fn encode_0011rev1() {
let message = MID0011rev1 {
number_of_parameter_sets: 5,
parameter_set_ids: vec![1, 2, 3, 10, 20],
};
let result = encode::encode(&message);
assert_eq!(result, Ok("005001002003010020".to_string()));
}
#[test]
fn decode_0011rev1() {
let message = "005001002003010020";
let result = decode::decode(message.as_bytes());
assert_eq!(result, Ok(MID0011rev1 {
number_of_parameter_sets: 5,
parameter_set_ids: vec![1, 2, 3, 10, 20],
}));
}
}