19from .header
import ConfigMainHeader, PinHeader, ConfigSubHeader
20from .packet
import ConfigPacket, PinPacket
25 """ This exposes all the pin functionality for use,
27 for reading state
and data please use the functions provided
as they trigger an update of the internal state before returning values
29 at the moment it
is limited to digital read
and write
30 but
is supposed to be extended to analog read
and write
and PWM functionality on first need / request
34 """ 0 means not activated
35 1 means activation pending
43 -
"PWM" not implemented yet
44 -
"ANALOG_INPUT" not implemented yet
45 -
"ANALOG_OUTPUT" not implemented yet
58 self.
__api = api_object
59 self.
__header = [ConfigMainHeader.IN_CONF_PIN, PinHeader.IN_PIN, PinHeader.IN_PIN_READ, PinHeader.OUT_PIN_LOW, PinHeader.OUT_PIN_HIGH]
62 """header returns the packet headers associated whith this interface
64 :return: packet headers of this interface
65 :rtype: Header (IntEnum)
70 """status returns the state of this interface,
73 - active - everything is working fine
74 - activation pending - the uC has
not acknolaged the activation yet after the request to activate the interface
75 -
not active - the interface has
not been configured
and activate
76 - error - there was an error during activation
or during use, please consult the errors using the errors function
78 :
return: the state of the interface
and the timestamp
in us
82 state_str = ("active" if self.
__status == 2
else (
"activation pending" if self.
__status == 1
else (
"not active" if self.
__status == 0
else "error" )))
86 """interface_type returns the currently configured mode of the pin
88 :return: mode of the pin like
"INPUT" or "OUTPUT"
95 """interval not yet suported for PWM/analog read
97 :return: _description_
104 """data_from_chip will retun the data recoded by the uC send from the device under test (DUT)
106 will retun 2 lists: one with the word recoded
and one
with the time when it was recorded, linked by index
108 :
return: the words
from the DUT
and the times of those words
109 :rtype: ([int],[int])
115 """data_to_chip will retun the data send by the uC to the device under test (DUT)
117 will retun 2 lists: one with the word send
and one
with the exact time when it was send, linked by index
119 the time might differ slightly
from the time you sheduled the send word,
120 as it
is the time when it was send out
and the uC can only send one word at a time
122 :
return: the words send to the DUT
and the times of those words
123 :rtype: ([int],[int])
145 """errors all errors corresponding to this interface
147 :return: list of all errors
155 state_str = (
"active" if self.
__status == 2
else (
"activation pending" if self.
__status == 1
else (
"not active" if self.
__status == 0
else "error" )))
156 return "PIN_" + str(self.
__pin_id) + \
157 "\nHeader: " + str(self.
__header) + \
163 "\nERRORS: "+str(self.
__errors) +
"\n"
166 """ process packets arriving for this interface, updates the internal state and stores the data
167 @param packet: the packet to process
169 if packet.header()
in self.
__header:
171 if packet.header() == self.
__header[0]:
173 if packet.config_header() == ConfigSubHeader.CONF_INPUT:
180 elif packet.config_header() == ConfigSubHeader.CONF_OUTPUT:
187 elif packet.header() == self.
__header[1]
and packet.pin_id() == self.
__pin_id:
191 elif packet.header() == self.
__header[2]
and packet.pin_id() == self.
__pin_id:
193 elif packet.header() == self.
__header[3]
and packet.pin_id() == self.
__pin_id:
197 elif packet.header() == self.
__header[4]
and packet.pin_id() == self.
__pin_id:
205 def activate(self, pin_mode="OUTPUT", interval=0, time=0):
206 """ activate the pin with the given mode and interval
207 @param pin_mode: the mode of the pin, can be
"INPUT",
"OUTPUT" and future
"PWM",
"ANALOG_INPUT",
"ANALOG_OUTPUT"
208 @param interval: the interval
for the pin,
not yet implemented
209 @param time: the time when the activation should be done, 0 means
as soon
as possible
212 logging.warning(
"Pin "+str(self.
__pin_id)+
" is already activated or waiting activation, doing nothing")
214 if pin_mode ==
"OUTPUT":
220 elif pin_mode ==
"INPUT":
227 elif pin_mode ==
"PWM":
228 logging.warning(
"pin mode not implmented yet")
229 elif pin_mode ==
"ANALOG_INPUT":
230 logging.warning(
"pin mode not implmented yet")
231 elif pin_mode ==
"ANALOG_OUPUT":
232 logging.warning(
"pin mode not implmented yet")
234 logging.error(
"pin.activate got wrong type "+str(pin_mode)+
" only INPUT, OUTPUT, PWM, ANALOG_INPUT, ANALOG_OUTPUT are allowed")
238 def send(self, value, time = 0):
239 """ set the corresponding pin to the given value at the given time
240 @param value: the value to set the pin to, 0
or 1
241 @param time: the time when the value should be set, 0 means
as soon
as possible
250 """ update the internal state representation of the pin object
252 self.__api.update_state()
This exposes all the pin functionality for use,.
def status(self)
status returns the state of this interface,
def process_packet(self, packet)
process packets arriving for this interface, updates the internal state and stores the data
def data_to_chip_and_clear(self)
def data_from_chip_and_clear(self)
def activate(self, pin_mode="OUTPUT", interval=0, time=0)
activate the pin with the given mode and interval
def update(self)
update the internal state representation of the pin object
def __init__(self, api_object, interface_id)
def interface_type(self)
interface_type returns the currently configured mode of the pin
def interval(self)
interval not yet suported for PWM/analog read
def send(self, value, time=0)
set the corresponding pin to the given value at the given time
def errors(self)
errors all errors corresponding to this interface
def data_from_chip(self)
data_from_chip will retun the data recoded by the uC send from the device under test (DUT)
def data_to_chip(self)
data_to_chip will retun the data send by the uC to the device under test (DUT)
The ConfigPacket is used to cumunicate configuration instructions with the uC all availible instructi...
The PinPacket is used to comunicate pin instructions with the uC all availible instructions are defin...