PaSD bus poll management
This module implements polling management for a PaSD bus.
- class DelayedRequest(device_id, request_description, not_before)
Class to represent a delayed request.
Encapsulates data about a delayed request including a ‘not before’ timestamp before which the request should not be actioned.
- __init__(device_id, request_description, not_before)
- class DeviceRequestProvider(number_of_ports, read_request_iterator_factory, attribute_read_delay, port_status_read_delay, logger)
A class that determines the next communication with a specified device.
It keeps track of the current intent of PaSD monitoring and control, for example, whether a command has been requested to be executed on the device; and it decides what, if any, communication with it should occur in the next poll.
- __init__(number_of_ports, read_request_iterator_factory, attribute_read_delay, port_status_read_delay, logger)
Initialise a new instance.
- Parameters:
number_of_ports (
int) – the number of ports this device has.read_request_iterator_factory (
Callable[[],Iterator[str]]) – a callable that returns a read request iteratorattribute_read_delay (
float) – time in seconds to wait after writing an attribute before reading it againport_status_read_delay (
float) – time in seconds to wait after setting port status before reading it againlogger (
Logger) – a logger.
- desire_attribute_write(attribute_name, values)
Register a request to write an attribute.
- desire_led_pattern(pattern)
Register a request to set the device’s LED pattern.
- desire_port_breaker_reset(port_number)
Register a request to reset a port breaker.
- desire_port_powers(port_powers, stay_on_when_offline)
Register a request to modify the power of some device ports.
- Parameters:
port_powers (
Sequence[Optional[bool]]) – a desired port power state for each port. True means the port is desired on, False means it is desired off, None means no desire to change the port.stay_on_when_offline (
bool) – whether any ports being turned on should remain on if MCCS loses its connection with the PaSD.
- Return type:
- desire_read_startup_info()
Register a request to read the info usually just read on startup.
- Return type:
- desire_set_low_pass_filter(cutoff, extra_sensors)
Register a request to set the device’s low pass filter constants.
- desire_status_read()
Register a request to read the status register.
This is done whenever a comms failure has occurred to attempt to re-establish communications.
- Return type:
- get_expedited_read(device_id)
Return a DelayedRequest for future action to expedite a read.
This is required for attributes which have been written to by the user, so we don’t have to wait until their turn in the regular poll. The request is delayed to ensure the register has been updated before we read it again.
- Param:
device_id: The id of the device requiring the request.
- Return type:
- Returns:
A DelayedRequest, encapsulating information about the request to make and when it should be actioned.
- get_read()
Return a description of the next read to be performed on the device.
- Return type:
- Returns:
The name of the next read to be performed on the device.
- get_write()
Return a description of the next write / command to be performed on the device.
- class FndhRequestProvider(number_of_ports, read_request_iterator_factory, attribute_read_delay, port_status_read_delay, port_power_delay, logger)
A class to handle staggered powering of Fndh ports.
A request for powering N ports becomes N requests for powering 1 port.
- __init__(number_of_ports, read_request_iterator_factory, attribute_read_delay, port_status_read_delay, port_power_delay, logger)
Initialise a new instance.
- Parameters:
number_of_ports (
int) – the number of ports this device has.read_request_iterator_factory (
Callable[[],Iterator[str]]) – a callable that returns a read request iteratorattribute_read_delay (
float) – time in seconds to wait after writing an attribute before reading it againport_status_read_delay (
float) – time in seconds to wait after setting port status before reading it againport_power_delay (
float) – time in seconds to wait between setting each FNDH port power.logger (
Logger) – a logger.
- get_write_read_sequence(device_id)
Get a sequence of write-read requests.
A command to set port powers will be converted into N requests to write, interleaved with N requests to read.
- Parameters:
device_id (
int) – The id of the device requiring the request.- Return type:
- Returns:
a list of DelayedRequests.
- class PasdBusRequestProvider(min_ticks, logger, attribute_read_delay, port_status_read_delay, port_power_delay, smartbox_ids, smartbox_startup_delay=0.0)
A class that determines the next communication with the PaSD, across all devices.
It ensures that:
a certain number of ticks are guaranteed to have passed between communications with any single device.
commands get executed as promptly as possible
device attributes are polled as frequently as possible, given the above constraints
- __init__(min_ticks, logger, attribute_read_delay, port_status_read_delay, port_power_delay, smartbox_ids, smartbox_startup_delay=0.0)
Initialise a new instance.
- Parameters:
min_ticks (
int) – minimum number of ticks between communications with any given devicelogger (
Logger) – a logger.attribute_read_delay (
float) – time in seconds to wait after writing an attribute before reading it againport_status_read_delay (
float) – time in seconds to wait after setting port status before reading it againport_power_delay (
float) – time in seconds to wait between setting each FNDH port power.smartbox_ids (
list[int]) – list of smartbox IDs associated with each FNDH portsmartbox_startup_delay (
float) – time in seconds to wait after a smartbox is powered on before starting to poll it.
- desire_alarm_reset(device_id)
Register a request to reset an alarm.
- desire_attribute_write(device_id, name, values)
Register a request to write an attribute.
- desire_initialize(device_id)
Register a request to initialize a device.
- desire_led_pattern(device_id, pattern)
Register a request to set a device’s LED pattern.
- desire_port_breaker_reset(device_id, port_number)
Register a request to reset a port breaker.
- desire_port_powers(device_id, port_powers, stay_on_when_offline)
Register a request to turn some of device’s ports on.
- Parameters:
device_id (
int) – the device number.port_powers (
Sequence[Optional[bool]]) – a desired port power state for each port. True means the port is desired on, False means it is desired off, None means no desire to change the port.stay_on_when_offline (
bool) – whether any ports being turned on should remain on if MCCS loses its connection with the PaSD.
- Return type:
- desire_read_startup_info(device_id)
Register a request to read the information usually just read at startup.
- desire_set_low_pass_filter(device_id, cutoff, extra_sensors)
Register a request to set a device’s low pass filter constants.
- desire_status_read(device_id)
Register a request to read the status register.
- desire_status_reset(device_id)
Register a request to reset the status register.
- desire_warning_reset(device_id)
Register a request to reset a warning.
- get_request(tick_increment)
Get a description of the next communication with the PaSD bus.
- Parameters:
tick_increment (
int) – the number of ticks to increment by. This is usually 1, but can be higher if more than the usual polling period has elapsed since the last request.- Return type:
- Returns:
a tuple consisting of the name of the communication and any arguments or extra information.
- initialise()
Initialise the PasdBusRequestProvider.
This may be called when the device is taken offline to reset all the request providers.
- Return type:
- stop_polling_smartboxes(port_power_requests)
Stop polling a smartbox if it has been requested to switch off.
- fncc_read_request_iterator()
Return an iterator that says what attributes should be read next on the FNCC.
It starts by reading static information attributes and then loops forever to read the status.
- fndh_read_request_iterator()
Return an iterator that says what attributes should be read next on the FNDH.
It starts by reading static information attributes, then moves on to writable attributes that are otherwise static, and then loops forever, alternating between status attributes and port attributes.
- smartbox_read_request_iterator()
Return an iterator that says what attributes should be read next on a smartbox.
It starts by reading static information attributes, then moves on to writable attributes that are otherwise static, and then loops forever, alternating between status attributes and port attributes.