-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmodel.py
More file actions
184 lines (145 loc) · 5.45 KB
/
model.py
File metadata and controls
184 lines (145 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# generated by datamodel-codegen:
# filename: device.json
# timestamp: 2023-10-30T11:46:57+00:00
from __future__ import annotations
from enum import Enum
from typing import Annotated, Dict, List, Optional, Union
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, RootModel, field_serializer
class PayloadType(str, Enum):
U8 = "uint8"
S8 = "int8"
U16 = "uint16"
S16 = "int16"
U32 = "uint32"
S32 = "int32"
U64 = "uint64"
S64 = "int64"
Float = "float32"
class Access(Enum):
Read = "Read"
Write = "Write"
Event = "Event"
class MaskValueItem(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
value: int = Field(..., description="Specifies the numerical mask value.")
description: Optional[str] = Field(
None, description="Specifies a summary description of the mask value function."
)
def __int__(self):
return self.value
class MaskValue(RootModel[Union[int, MaskValueItem]]):
root: Union[int, MaskValueItem]
class BitMask(BaseModel):
description: Optional[str] = Field(
None, description="Specifies a summary description of the bit mask function."
)
bits: Dict[str, MaskValue]
class GroupMask(BaseModel):
description: Optional[str] = Field(
None, description="Specifies a summary description of the group mask function."
)
values: Dict[str, MaskValue]
class MaskType(RootModel[str]):
root: str = Field(
...,
description="Specifies the name of the bit mask or group mask used to represent the payload value.",
)
class InterfaceType(RootModel[str]):
root: str = Field(
...,
description="Specifies the name of the type used to represent the payload value in the high-level interface.",
)
class Converter(Enum):
None_ = "None"
Payload = "Payload"
RawPayload = "RawPayload"
class MinValue(RootModel[float]):
root: float = Field(
...,
description="Specifies the minimum allowable value for the payload or payload member.",
)
class MaxValue(RootModel[float]):
root: float = Field(
...,
description="Specifies the maximum allowable value for the payload or payload member.",
)
class DefaultValue(RootModel[float]):
root: float = Field(
...,
description="Specifies the default value for the payload or payload member.",
)
class PayloadMember(BaseModel):
mask: Optional[int] = Field(
None,
description="Specifies the mask used to read and write this payload member.",
)
offset: Optional[int] = Field(
None,
description="Specifies the payload array offset where this payload member is stored.",
)
description: Optional[str] = Field(
None, description="Specifies a summary description of the payload member."
)
minValue: Optional[MinValue] = None
maxValue: Optional[MaxValue] = None
defaultValue: Optional[DefaultValue] = None
maskType: Optional[MaskType] = None
interfaceType: Optional[InterfaceType] = None
converter: Optional[Converter] = None
class Visibility(Enum):
public = "public"
private = "private"
class Register(BaseModel):
address: Annotated[
int,
Field(le=255, description="Specifies the unique 8-bit address of the register."),
]
type: Annotated[PayloadType, BeforeValidator(lambda v: PayloadType[v])]
length: Annotated[
Optional[int],
Field(ge=1, default=1, description="Specifies the length of the register payload."),
]
access: Union[Access, List[Access]] = Field(
..., description="Specifies the expected use of the register."
)
description: Optional[str] = Field(
None, description="Specifies a summary description of the register function."
)
minValue: Optional[MinValue] = None
maxValue: Optional[MaxValue] = None
defaultValue: Optional[DefaultValue] = None
maskType: Optional[MaskType] = None
visibility: Optional[Visibility] = Field(
None,
description="Specifies whether the register function is exposed in the high-level interface.",
)
volatile: Optional[bool] = Field(
None,
description="Specifies whether register values can be saved in non-volatile memory.",
)
payloadSpec: Optional[Dict[str, PayloadMember]] = None
interfaceType: Optional[InterfaceType] = None
converter: Optional[Converter] = None
@field_serializer("type")
def _serialize_type(self, type: PayloadType):
return type.name
class Registers(BaseModel):
registers: Dict[str, Register] = Field(
...,
description="Specifies the collection of registers implementing the device function.",
)
bitMasks: Optional[Dict[str, BitMask]] = Field(
None,
description="Specifies the collection of masks available to be used with the different registers.",
)
groupMasks: Optional[Dict[str, GroupMask]] = Field(
None,
description="Specifies the collection of group masks available to be used with the different registers.",
)
class Model(Registers):
device: str = Field(..., description="Specifies the name of the device.")
whoAmI: int = Field(..., description="Specifies the unique identifier for this device type.")
firmwareVersion: str = Field(..., description="Specifies the semantic version of the device firmware.")
hardwareTargets: str = Field(..., description="Specifies the semantic version of the device hardware.")