hil2.action

  1from typing import Optional, Union
  2
  3import cantools.database.can.database as cantools_db
  4
  5
  6# Union type representing all possible actions ----------------------------------------#
  7ActionType = Union[
  8    "SetDo",
  9    "HiZDo",
 10    "GetDi",
 11    "SetAo",
 12    "HiZAo",
 13    "GetAi",
 14    "SetPot",
 15    "SendCan",
 16    "GetLastCan",
 17    "GetAllCan",
 18    "ClearCan",
 19]
 20
 21
 22# DO actions --------------------------------------------------------------------------#
 23class SetDo:
 24    """Action to set a digital output"""
 25
 26    __match_args__ = ("value",)
 27
 28    def __init__(self, value: bool):
 29        """
 30        :param value: The value to set the digital output to (low = false, high = true)
 31        """
 32        self.value: bool = value
 33
 34
 35class HiZDo:
 36    """Action to set a digital output to high impedance (HiZ)"""
 37
 38    def __init__(self):
 39        pass
 40
 41
 42# DI actions --------------------------------------------------------------------------#
 43class GetDi:
 44    """Action to get a digital input"""
 45
 46    def __init__(self):
 47        pass
 48
 49
 50# AO actions --------------------------------------------------------------------------#
 51class SetAo:
 52    """Action to set an analog output"""
 53
 54    __match_args__ = ("value",)
 55
 56    def __init__(self, value: float):
 57        """
 58        :param value: The value (in volts) to set the analog output to
 59        """
 60        self.value: float = value
 61
 62
 63class HiZAo:
 64    """Action to set an analog output to high impedance (HiZ)"""
 65
 66    def __init__(self):
 67        pass
 68
 69
 70class GetAi:
 71    """Action to get an analog input"""
 72
 73    def __init__(self):
 74        pass
 75
 76
 77# POT actions -------------------------------------------------------------------------#
 78class SetPot:
 79    """Action to set a potentiometer"""
 80
 81    __match_args__ = ("value",)
 82
 83    def __init__(self, value: float):
 84        """
 85        :param value: The value (in ohms) to set the potentiometer to
 86        """
 87        self.value: float = value
 88
 89
 90# CAN actions -------------------------------------------------------------------------#
 91class SendCan:
 92    """Action to send a CAN message"""
 93
 94    __match_args__ = ("signal", "data", "can_dbcs")
 95
 96    def __init__(self, signal: str | int, data: dict, can_dbcs: dict[str, cantools_db.Database]):
 97        """
 98        :param signal: The signal name or message ID to send
 99        :param data: The data to include in the CAN message. Will be encoded to bytes
100        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
101        """
102        self.signal: str | int = signal
103        self.data: dict = data
104        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs
105
106
107class GetLastCan:
108    """Action to get the last received CAN message"""
109
110    __match_args__ = ("signal", "can_dbcs")
111
112    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
113        """
114        :param signal: The signal name or message ID to get. If not specified, the last
115                       message will be returned (if any) regardless of the signal/id
116        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
117        """
118        self.signal: Optional[str | int] = signal
119        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs
120
121
122class GetAllCan:
123    """Action to get all received CAN messages"""
124
125    __match_args__ = ("signal", "can_dbcs")
126
127    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
128        """
129        :param signal: The signal name or message ID to get. If not specified, all
130                       messages will be returned (if any) regardless of the signal/id
131        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
132        """
133        self.signal: Optional[str | int] = signal
134        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs
135
136
137class ClearCan:
138    """Action to clear a CAN message"""
139
140    __match_args__ = ("signal", "can_dbcs")
141
142    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
143        """
144        :param signal: The signal name or message ID to clear. If not specified, all
145                       messages will be cleared (if any) regardless of the signal/id
146        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
147        """
148        self.signal: Optional[str | int] = signal
149        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs
ActionType = typing.Union[ForwardRef('SetDo'), ForwardRef('HiZDo'), ForwardRef('GetDi'), ForwardRef('SetAo'), ForwardRef('HiZAo'), ForwardRef('GetAi'), ForwardRef('SetPot'), ForwardRef('SendCan'), ForwardRef('GetLastCan'), ForwardRef('GetAllCan'), ForwardRef('ClearCan')]
class SetDo:
24class SetDo:
25    """Action to set a digital output"""
26
27    __match_args__ = ("value",)
28
29    def __init__(self, value: bool):
30        """
31        :param value: The value to set the digital output to (low = false, high = true)
32        """
33        self.value: bool = value

Action to set a digital output

SetDo(value: bool)
29    def __init__(self, value: bool):
30        """
31        :param value: The value to set the digital output to (low = false, high = true)
32        """
33        self.value: bool = value
Parameters
  • value: The value to set the digital output to (low = false, high = true)
value: bool
class HiZDo:
36class HiZDo:
37    """Action to set a digital output to high impedance (HiZ)"""
38
39    def __init__(self):
40        pass

Action to set a digital output to high impedance (HiZ)

class GetDi:
44class GetDi:
45    """Action to get a digital input"""
46
47    def __init__(self):
48        pass

Action to get a digital input

class SetAo:
52class SetAo:
53    """Action to set an analog output"""
54
55    __match_args__ = ("value",)
56
57    def __init__(self, value: float):
58        """
59        :param value: The value (in volts) to set the analog output to
60        """
61        self.value: float = value

Action to set an analog output

SetAo(value: float)
57    def __init__(self, value: float):
58        """
59        :param value: The value (in volts) to set the analog output to
60        """
61        self.value: float = value
Parameters
  • value: The value (in volts) to set the analog output to
value: float
class HiZAo:
64class HiZAo:
65    """Action to set an analog output to high impedance (HiZ)"""
66
67    def __init__(self):
68        pass

Action to set an analog output to high impedance (HiZ)

class GetAi:
71class GetAi:
72    """Action to get an analog input"""
73
74    def __init__(self):
75        pass

Action to get an analog input

class SetPot:
79class SetPot:
80    """Action to set a potentiometer"""
81
82    __match_args__ = ("value",)
83
84    def __init__(self, value: float):
85        """
86        :param value: The value (in ohms) to set the potentiometer to
87        """
88        self.value: float = value

Action to set a potentiometer

SetPot(value: float)
84    def __init__(self, value: float):
85        """
86        :param value: The value (in ohms) to set the potentiometer to
87        """
88        self.value: float = value
Parameters
  • value: The value (in ohms) to set the potentiometer to
value: float
class SendCan:
 92class SendCan:
 93    """Action to send a CAN message"""
 94
 95    __match_args__ = ("signal", "data", "can_dbcs")
 96
 97    def __init__(self, signal: str | int, data: dict, can_dbcs: dict[str, cantools_db.Database]):
 98        """
 99        :param signal: The signal name or message ID to send
100        :param data: The data to include in the CAN message. Will be encoded to bytes
101        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
102        """
103        self.signal: str | int = signal
104        self.data: dict = data
105        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs

Action to send a CAN message

SendCan( signal: str | int, data: dict, can_dbcs: dict[str, cantools.database.can.database.Database])
 97    def __init__(self, signal: str | int, data: dict, can_dbcs: dict[str, cantools_db.Database]):
 98        """
 99        :param signal: The signal name or message ID to send
100        :param data: The data to include in the CAN message. Will be encoded to bytes
101        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
102        """
103        self.signal: str | int = signal
104        self.data: dict = data
105        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs
Parameters
  • signal: The signal name or message ID to send
  • data: The data to include in the CAN message. Will be encoded to bytes
  • can_dbcs: A dictionary of CAN databases, keyed by DBC file name
signal: str | int
data: dict
can_dbcs: dict[str, cantools.database.can.database.Database]
class GetLastCan:
108class GetLastCan:
109    """Action to get the last received CAN message"""
110
111    __match_args__ = ("signal", "can_dbcs")
112
113    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
114        """
115        :param signal: The signal name or message ID to get. If not specified, the last
116                       message will be returned (if any) regardless of the signal/id
117        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
118        """
119        self.signal: Optional[str | int] = signal
120        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs

Action to get the last received CAN message

GetLastCan( signal: Union[str, int, NoneType], can_dbcs: dict[str, cantools.database.can.database.Database])
113    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
114        """
115        :param signal: The signal name or message ID to get. If not specified, the last
116                       message will be returned (if any) regardless of the signal/id
117        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
118        """
119        self.signal: Optional[str | int] = signal
120        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs
Parameters
  • signal: The signal name or message ID to get. If not specified, the last message will be returned (if any) regardless of the signal/id
  • can_dbcs: A dictionary of CAN databases, keyed by DBC file name
signal: Union[str, int, NoneType]
can_dbcs: dict[str, cantools.database.can.database.Database]
class GetAllCan:
123class GetAllCan:
124    """Action to get all received CAN messages"""
125
126    __match_args__ = ("signal", "can_dbcs")
127
128    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
129        """
130        :param signal: The signal name or message ID to get. If not specified, all
131                       messages will be returned (if any) regardless of the signal/id
132        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
133        """
134        self.signal: Optional[str | int] = signal
135        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs

Action to get all received CAN messages

GetAllCan( signal: Union[str, int, NoneType], can_dbcs: dict[str, cantools.database.can.database.Database])
128    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
129        """
130        :param signal: The signal name or message ID to get. If not specified, all
131                       messages will be returned (if any) regardless of the signal/id
132        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
133        """
134        self.signal: Optional[str | int] = signal
135        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs
Parameters
  • signal: The signal name or message ID to get. If not specified, all messages will be returned (if any) regardless of the signal/id
  • can_dbcs: A dictionary of CAN databases, keyed by DBC file name
signal: Union[str, int, NoneType]
can_dbcs: dict[str, cantools.database.can.database.Database]
class ClearCan:
138class ClearCan:
139    """Action to clear a CAN message"""
140
141    __match_args__ = ("signal", "can_dbcs")
142
143    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
144        """
145        :param signal: The signal name or message ID to clear. If not specified, all
146                       messages will be cleared (if any) regardless of the signal/id
147        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
148        """
149        self.signal: Optional[str | int] = signal
150        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs

Action to clear a CAN message

ClearCan( signal: Union[str, int, NoneType], can_dbcs: dict[str, cantools.database.can.database.Database])
143    def __init__(self, signal: Optional[str | int], can_dbcs: dict[str, cantools_db.Database]):
144        """
145        :param signal: The signal name or message ID to clear. If not specified, all
146                       messages will be cleared (if any) regardless of the signal/id
147        :param can_dbcs: A dictionary of CAN databases, keyed by DBC file name
148        """
149        self.signal: Optional[str | int] = signal
150        self.can_dbcs: dict[str, cantools_db.Database] = can_dbcs
Parameters
  • signal: The signal name or message ID to clear. If not specified, all messages will be cleared (if any) regardless of the signal/id
  • can_dbcs: A dictionary of CAN databases, keyed by DBC file name
signal: Union[str, int, NoneType]
can_dbcs: dict[str, cantools.database.can.database.Database]