xio_instructionset/
lib.rs1#![deny(missing_docs)]
2
3#[macro_use]
6extern crate serde_derive;
7
8extern crate indexmap;
9extern crate ommui_file_loading;
10extern crate ommui_string_patterns;
11extern crate serde;
12extern crate xio_base_datatypes;
13
14use indexmap::IndexMap;
15use ommui_string_patterns::{
16 freetextstring, idstring, idstring_maybe_empty,
17};
18use xio_base_datatypes as base;
19
20mod hexnumber;
21
22pub mod filesystem;
24
25pub type InstructionMap = IndexMap<String, Instruction>;
27
28#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
30#[serde(rename_all = "camelCase", deny_unknown_fields)]
31pub struct Instruction {
32 #[serde(with = "hexnumber")]
34 pub code: u16,
35
36 #[serde(with = "freetextstring")]
38 pub description: String,
39
40 #[serde(
45 with = "freetextstring",
46 default,
47 skip_serializing_if = "String::is_empty"
48 )]
49 pub formatstring: String,
50
51 #[serde(default, skip_serializing_if = "Vec::is_empty")]
53 pub parameters: Vec<InstructionParameter>,
54}
55
56pub enum InstructionCategory {
58 CommandWithoutTimeExtent,
60
61 CommandWithTimeExtent,
63
64 Condition,
66
67 Invalid,
69}
70
71impl Instruction {
72 pub fn category(&self) -> InstructionCategory {
74 use std::ops::Shr;
75 use InstructionCategory::*;
76 match self.code.shr(8) & 0b1111u16 {
77 0b0000u16 => CommandWithoutTimeExtent,
78 0b0100u16 => CommandWithTimeExtent,
79 0b1000u16 => Condition,
80 _ => Invalid,
81 }
82 }
83}
84
85#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
87#[serde(rename_all = "camelCase", deny_unknown_fields)]
88pub struct InstructionParameter {
89 #[serde(with = "idstring")]
91 pub id: String,
92
93 #[serde(
98 with = "idstring_maybe_empty",
99 default,
100 skip_serializing_if = "String::is_empty"
101 )]
102 pub group: String,
103
104 #[serde(rename = "type")]
108 pub parameter_type: Vec<base::DataType>,
109
110 pub storage: base::StorageTypeWithMixed,
112
113 #[serde(with = "freetextstring")]
115 pub description: String,
116}