Skip to content

Commit 0bcdccc

Browse files
committed
WIP tase2
1 parent 3bd1fc8 commit 0bcdccc

File tree

3 files changed

+662
-0
lines changed

3 files changed

+662
-0
lines changed

src_py/hat/drivers/tase2/__init__.py

Whitespace-only changes.

src_py/hat/drivers/tase2/common.py

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import enum
2+
import typing
3+
4+
from hat.drivers import mms
5+
6+
7+
class SupportedFeature(enum.Enum):
8+
BLOCK1 = 0
9+
BLOCK2 = 1
10+
BLOCK4 = 3
11+
BLOCK5 = 4
12+
BLOCK11 = 10
13+
BLOCK12 = 11
14+
15+
16+
class ValueType(enum.Enum):
17+
REAL = 'REAL'
18+
STATE = 'STATE'
19+
DISCRETE = 'DISCRETE'
20+
21+
22+
class QualityType(enum.Enum):
23+
NO_QUALITY = 'NO_QUALITY'
24+
QUALITY = 'QUALITY'
25+
26+
27+
class TimestampType(enum.Enum):
28+
NO_TIMESTAMP = 'NO_TIMESTAMP'
29+
TIMESTAMP = 'TIMESTAMP'
30+
TIMESTAMP_EXTENDED = 'TIMESTAMP_EXTENDED'
31+
32+
33+
class CovType(enum.Enum):
34+
NO_COV = 'NO_COV'
35+
COV = 'COV'
36+
37+
38+
class DataType(typing.NamedTuple):
39+
value: ValueType
40+
quality: QualityType
41+
timestamp: TimestampType
42+
cov: CovType
43+
44+
45+
class Validity(enum.Enum):
46+
VALID = 0
47+
HELD = 1
48+
SUSPECT = 2
49+
NOT_VALID = 3
50+
51+
52+
class Source(enum.Enum):
53+
TELEMETERED = 0
54+
CALCULATED = 1
55+
ENTERED = 2
56+
ESTIMATED = 3
57+
58+
59+
class ValueQuality(enum.Enum):
60+
NORMAL = 0
61+
ABNORMAL = 1
62+
63+
64+
class TimestampQuality(enum.Enum):
65+
VALID = 0
66+
INVALID = 1
67+
68+
69+
class Quality(enum.Enum):
70+
validity: Validity
71+
source: Source
72+
value: ValueQuality
73+
timestamp: TimestampQuality
74+
75+
76+
class Data(typing.NamedTuple):
77+
name: str
78+
value: float | int
79+
quality: Quality | None = None
80+
timestamp: float | None = None
81+
"""number of seconds since 1970-01-01"""
82+
cov: int | None = None
83+
"""change of value counter"""
84+
85+
86+
class VmdIdentifier(typing.NamedTuple):
87+
name: str
88+
89+
90+
class DomainIdentifier(typing.NamedTuple):
91+
name: str
92+
domain: str
93+
94+
95+
Identifier: typing.TypeAlias = VmdIdentifier | DomainIdentifier
96+
97+
98+
class Dataset(typing.NamedTuple):
99+
identifier: Identifier
100+
data: dict[Identifier, DataType] # order is significant
101+
102+
103+
class TransfersetCondition(enum.Enum):
104+
INTERVAL_TIMEOUT = 0
105+
INTEGRITY_TIMEOUT = 1
106+
OBJECT_CHANGE = 2
107+
OPERATOR_REQUEST = 3
108+
OTHER_EXTERNAL_EVENT = 4
109+
110+
111+
class Transferset(typing.NamedTuple):
112+
identifier: Identifier
113+
dataset_identifier: Identifier
114+
start_time: int
115+
interval: int
116+
tle: int
117+
buffer_time: int
118+
integrity_check: int
119+
conditions: set[TransfersetCondition]
120+
block_data: bool
121+
critical: bool
122+
rbe: bool
123+
all_changes_reported: bool
124+
status: bool
125+
event_code_requested: int
126+
127+
128+
def validate_data_type(data_type: DataType):
129+
if (data_type.value == ValueType.STATE and
130+
data_type.quality == QualityType.NO_QUALITY):
131+
raise ValueError('state value without quality not supported')
132+
133+
if (data_type.timestamp != TimestampType.NO_TIMESTAMP and
134+
data_type.quality == QualityType.NO_QUALITY):
135+
raise ValueError('timestamp without quality not supported')
136+
137+
if (data_type.cov == CovType.COV and
138+
data_type.timestamp != TimestampType.TIMESTAMP):
139+
raise ValueError('cov without non extended timestamp not supported')
140+
141+
142+
def get_system_identifiers(domain: str) -> set[Identifier]:
143+
return {VmdIdentifier('TASE2_Version'),
144+
VmdIdentifier('Supported_Features'),
145+
DomainIdentifier('Bilateral_Table_ID', domain),
146+
DomainIdentifier('DSConditions', domain),
147+
DomainIdentifier('DSConditions_Detected', domain),
148+
DomainIdentifier('Event_Code_Detected', domain),
149+
DomainIdentifier('Next_DSTransfer_Set', domain),
150+
DomainIdentifier('Transfer_Report_ACK', domain),
151+
DomainIdentifier('Transfer_Report_NACK', domain),
152+
DomainIdentifier('Transfer_Set_Name', domain),
153+
DomainIdentifier('Transfer_Set_Time_Stamp', domain)}
154+
155+
156+
def identifier_to_object_name(identifier: Identifier
157+
) -> mms.ObjectName:
158+
if isinstance(identifier, VmdIdentifier):
159+
return mms.VmdSpecificObjectName(identifier.name)
160+
161+
if isinstance(identifier, DomainIdentifier):
162+
return mms.DomainSpecificObjectName(domain_id=identifier.domain,
163+
item_id=identifier.name)
164+
165+
raise TypeError('unsupported identifier type')
166+
167+
168+
def identifier_from_object_name(object_name: mms.ObjectName
169+
) -> Identifier:
170+
if isinstance(object_name, mms.VmdSpecificObjectName):
171+
return VmdIdentifier(object_name.identifier)
172+
173+
if isinstance(object_name, mms.DomainSpecificObjectName):
174+
return DomainIdentifier(name=object_name.item_id,
175+
domain=object_name.domain_id)
176+
177+
raise TypeError('unsupported object name type')

0 commit comments

Comments
 (0)