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 iterator

  • attribute_read_delay (float) – time in seconds to wait after writing an attribute before reading it again

  • port_status_read_delay (float) – time in seconds to wait after setting port status before reading it again

  • logger (Logger) – a logger.

desire_alarm_reset()

Register a request to reset the alarm.

Return type:

None

desire_attribute_write(attribute_name, values)

Register a request to write an attribute.

Parameters:
  • attribute_name (str) – the name of the attribute to set.

  • values (list[Any]) – the new value(s) to write.

Return type:

None

desire_initialize()

Register a request to initialize the device.

Return type:

None

desire_led_pattern(pattern)

Register a request to set the device’s LED pattern.

Parameters:

pattern (str) – name of the service LED pattern.

Return type:

None

desire_port_breaker_reset(port_number)

Register a request to reset a port breaker.

Parameters:

port_number (int) – the number of the port whose breaker is to be reset.

Return type:

None

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:

None

desire_read_startup_info()

Register a request to read the info usually just read on startup.

Return type:

None

desire_set_low_pass_filter(cutoff, extra_sensors)

Register a request to set the device’s low pass filter constants.

Parameters:
  • cutoff (float) – frequency of LPF to set.

  • extra_sensors (bool) – write the constant to the extra sensors’ registers after the LED status register.

Return type:

None

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:

None

desire_status_reset()

Register a request to reset the status register.

Return type:

None

desire_warning_reset()

Register a request to reset the warning state.

Return type:

None

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:

Optional[DelayedRequest]

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:

str

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.

Return type:

tuple[str, Any]

Returns:

A tuple, comprising the name of the write / command, along with any additional information such as the value to be written.

get_write_read_sequence(device_id)

Return a list of DelayedRequests to perform a write-read sequence.

By default there are none.

Parameters:

device_id (int) – The id of the device requiring the request.

Return type:

Optional[list[DelayedRequest]]

Returns:

a list of DelayedRequests to be serviced.

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 iterator

  • attribute_read_delay (float) – time in seconds to wait after writing an attribute before reading it again

  • port_status_read_delay (float) – time in seconds to wait after setting port status before reading it again

  • port_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:

Optional[list[DelayedRequest]]

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 device

  • logger (Logger) – a logger.

  • attribute_read_delay (float) – time in seconds to wait after writing an attribute before reading it again

  • port_status_read_delay (float) – time in seconds to wait after setting port status before reading it again

  • port_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 port

  • smartbox_startup_delay (float) – time in seconds to wait after a smartbox is powered on before starting to poll it.

abort()

Clear all delayed requests and any pending port power changes.

Return type:

None

desire_alarm_reset(device_id)

Register a request to reset an alarm.

Parameters:

device_id (int) – the device number.

Return type:

None

desire_attribute_write(device_id, name, values)

Register a request to write an attribute.

Parameters:
  • device_id (int) – the device number.

  • name (str) – the name of the attribute to write.

  • values (list[Any]) – the new value(s) to write.

Return type:

None

desire_initialize(device_id)

Register a request to initialize a device.

Parameters:

device_id (int) – the device number.

Return type:

None

desire_led_pattern(device_id, pattern)

Register a request to set a device’s LED pattern.

Parameters:
  • device_id (int) – the device number.

  • pattern (str) – name of the service LED pattern.

Return type:

None

desire_port_breaker_reset(device_id, port_number)

Register a request to reset a port breaker.

Parameters:
  • device_id (int) – the device number.

  • port_number (int) – the number of the port whose breaker is to be reset.

Return type:

None

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:

None

desire_read_startup_info(device_id)

Register a request to read the information usually just read at startup.

Parameters:

device_id (int) – the device number.

Return type:

None

desire_set_low_pass_filter(device_id, cutoff, extra_sensors)

Register a request to set a device’s low pass filter constants.

Parameters:
  • device_id (int) – the device number.

  • cutoff (float) – frequency of LPF to set.

  • extra_sensors (bool) – write the constant to the extra sensors’ registers after the LED status register.

Return type:

None

desire_status_read(device_id)

Register a request to read the status register.

Parameters:

device_id (int) – the device number.

Return type:

None

desire_status_reset(device_id)

Register a request to reset the status register.

Parameters:

device_id (int) – the device number.

Return type:

None

desire_warning_reset(device_id)

Register a request to reset a warning.

Parameters:

device_id (int) – the device number.

Return type:

None

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:

Optional[tuple[int, str, Any]]

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:

None

stop_polling_smartboxes(port_power_requests)

Stop polling a smartbox if it has been requested to switch off.

Parameters:

port_power_requests (list[Optional[tuple[bool, bool]]]) – list of port power requests

Return type:

None

update_port_power_states(port_power_states)

Use the new power states to update the smartbox polling list.

Parameters:

port_power_states (list[bool]) – list of FNDH port power states.

Return type:

None

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.

Yields:

the name of an attribute group to be read from the device.

Return type:

Iterator[str]

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.

Yields:

the name of an attribute group to be read from the device.

Return type:

Iterator[str]

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.

Yields:

the name of an attribute group to be read from the device.

Return type:

Iterator[str]