Shepherd-Sheep - Advanced#

This API is more low level than the approach described here.

Harvester-API#

class shepherd_sheep.ShepherdHarvester(*_args: tuple, **_kwargs: Unpack)#

API for recording a harvest with shepherd.

Provides an easy-to-use, high-level interface for recording data with shepherd. Configures all hardware and initializes the communication with kernel module and PRUs.

Parameters:
  • cfg – harvester task setting

  • mode (str) – Should be ‘harvester’ to record harvesting data

static get_aux_voltage(cal_emu: CalibrationEmulator | None = None) float#

Reads the auxiliary voltage (dac channel B) from the PRU core.

Parameters:

cal_emu – dict with offset/gain

Returns:

aux voltage

get_buffer(timeout_n: int = 10, verbose: bool = False) tuple[int, DataBuffer]#

Reads a data buffer from shared memory.

Polls the msg-channel for a message from PRU0 and, if the message points to a filled buffer in memory, returns the data in the corresponding memory location as DataBuffer.

:param : param timeout_n: (int) Time in buffer_periods that should be waited for :param : param verbose: (bool) more debug output

Returns:

Index and content of corresponding data buffer

Raises:

TimeoutException – If no message is received within specified timeout

return_buffer(index: int, verbose: bool = False) None#

Returns a buffer to the PRU

After reading the content of a buffer and potentially filling it with emulation data, we have to release the buffer to the PRU to avoid it running out of buffers.

Parameters:
  • index – (int) Index of the buffer. 0 <= index < n_buffers

  • verbose – chatter-prevention, performance-critical computation saver

select_port_for_io_interface(target: TargetPort | bool | None) None#

choose which targets (A or B) gets the io-connection (serial, swd, gpio) from beaglebone,

shepherd hw-rev2 has two ports for targets and can switch independently between power supplies

Parameters:

target – A or B for that specific Target-Port

select_port_for_power_tracking(target: TargetPort | bool | None) None#

choose which targets (A or B) gets the supply with current-monitor,

shepherd hw-rev2 has two ports for targets and two separate power supplies, but only one is able to measure current, the other is considered “auxiliary”

Parameters:

target – A or B for that specific Target-Port

send_calibration_settings(cal_: CalibrationEmulator | CalibrationHarvester | None) None#

Sends calibration settings to PRU core

For the virtual source it is required to have the calibration settings. Note: to apply these settings the pru has to do a re-init (reset)

Parameters:
  • cal (CalibrationEmulation or CalibrationHarvester) – Contains the device’s

  • settings. (calibration) –

static send_virtual_converter_settings(settings: ConverterPRUConfig) None#

Sends virtsource settings to PRU core looks like a simple one-liner but is needed by the child-classes Note: to apply these settings the pru has to do a re-init (reset)

Parameters:

settings – Contains the settings for the virtual source.

static send_virtual_harvester_settings(settings: HarvesterPRUConfig) None#

Sends virtsource settings to PRU core looks like a simple one-liner but is needed by the child-classes Note: to apply these settings the pru has to do a re-init (reset)

Parameters:

settings – Contains the settings for the virtual source.

static set_aux_target_voltage(voltage: float, cal_emu: CalibrationEmulator | None = None) None#

Enables or disables the voltage for the second target

The shepherd cape has two DAC-Channels that each serve as power supply for a target

Parameters:
  • cal_emu – CalibrationEmulator,

  • voltage (float) – Desired output voltage in volt. Providing 0 or False disables supply, setting it to True will link it to the other channel

set_io_level_converter(state: bool) None#

Enables or disables the GPIO level converter to targets.

The shepherd cape has bidirectional logic level translators (LSF0108) for translating UART, GPIO and SWD signals between BeagleBone and target voltage levels. This function enables or disables the converter and additional switches (NLAS4684) to keep leakage low.

Parameters:

state (bool) – True for enabling converter, False for disabling

set_power_state_emulator(state: bool) None#

triggered pin is currently connected to ADCs reset-line NOTE: this might be extended to DAC as well

Parameters:

state – bool, enable to get ADC out of reset

Returns:

set_power_state_recorder(state: bool) None#

triggered pin is currently connected to ADCs reset-line NOTE: this might be extended to DAC as well

Parameters:

state – bool, enable to get ADC out of reset

Returns:

set_shepherd_pcb_power(state: bool) None#

Controls state of power supplies on shepherd cape.

Parameters:

state (bool) – True for on, False for off

start(start_time: float | None = None, wait_blocking: bool = True) bool#

Starts sampling either now or at later point in time.

Parameters:
  • start_time (int) – Desired start time in unix time

  • wait_blocking (bool) – If true, block until start has completed

static wait_for_start(timeout: float) None#

Waits until shepherd has started sampling.

Parameters:

timeout (float) – Time to wait in seconds

Emulator-API#

class shepherd_sheep.ShepherdEmulator(*_args: tuple, **_kwargs: Unpack)#

API for emulating data with shepherd.

Provides a high-level interface for emulating data with shepherd. Configures all hardware and initializes the communication with kernel module and PRUs.

static get_aux_voltage(cal_emu: CalibrationEmulator | None = None) float#

Reads the auxiliary voltage (dac channel B) from the PRU core.

Parameters:

cal_emu – dict with offset/gain

Returns:

aux voltage

get_buffer(timeout_n: int = 10, verbose: bool = False) tuple[int, DataBuffer]#

Reads a data buffer from shared memory.

Polls the msg-channel for a message from PRU0 and, if the message points to a filled buffer in memory, returns the data in the corresponding memory location as DataBuffer.

:param : param timeout_n: (int) Time in buffer_periods that should be waited for :param : param verbose: (bool) more debug output

Returns:

Index and content of corresponding data buffer

Raises:

TimeoutException – If no message is received within specified timeout

select_port_for_io_interface(target: TargetPort | bool | None) None#

choose which targets (A or B) gets the io-connection (serial, swd, gpio) from beaglebone,

shepherd hw-rev2 has two ports for targets and can switch independently between power supplies

Parameters:

target – A or B for that specific Target-Port

select_port_for_power_tracking(target: TargetPort | bool | None) None#

choose which targets (A or B) gets the supply with current-monitor,

shepherd hw-rev2 has two ports for targets and two separate power supplies, but only one is able to measure current, the other is considered “auxiliary”

Parameters:

target – A or B for that specific Target-Port

send_calibration_settings(cal_: CalibrationEmulator | CalibrationHarvester | None) None#

Sends calibration settings to PRU core

For the virtual source it is required to have the calibration settings. Note: to apply these settings the pru has to do a re-init (reset)

Parameters:
  • cal (CalibrationEmulation or CalibrationHarvester) – Contains the device’s

  • settings. (calibration) –

static send_virtual_converter_settings(settings: ConverterPRUConfig) None#

Sends virtsource settings to PRU core looks like a simple one-liner but is needed by the child-classes Note: to apply these settings the pru has to do a re-init (reset)

Parameters:

settings – Contains the settings for the virtual source.

static send_virtual_harvester_settings(settings: HarvesterPRUConfig) None#

Sends virtsource settings to PRU core looks like a simple one-liner but is needed by the child-classes Note: to apply these settings the pru has to do a re-init (reset)

Parameters:

settings – Contains the settings for the virtual source.

static set_aux_target_voltage(voltage: float, cal_emu: CalibrationEmulator | None = None) None#

Enables or disables the voltage for the second target

The shepherd cape has two DAC-Channels that each serve as power supply for a target

Parameters:
  • cal_emu – CalibrationEmulator,

  • voltage (float) – Desired output voltage in volt. Providing 0 or False disables supply, setting it to True will link it to the other channel

set_io_level_converter(state: bool) None#

Enables or disables the GPIO level converter to targets.

The shepherd cape has bidirectional logic level translators (LSF0108) for translating UART, GPIO and SWD signals between BeagleBone and target voltage levels. This function enables or disables the converter and additional switches (NLAS4684) to keep leakage low.

Parameters:

state (bool) – True for enabling converter, False for disabling

set_power_state_emulator(state: bool) None#

triggered pin is currently connected to ADCs reset-line NOTE: this might be extended to DAC as well

Parameters:

state – bool, enable to get ADC out of reset

Returns:

set_power_state_recorder(state: bool) None#

triggered pin is currently connected to ADCs reset-line NOTE: this might be extended to DAC as well

Parameters:

state – bool, enable to get ADC out of reset

Returns:

set_shepherd_pcb_power(state: bool) None#

Controls state of power supplies on shepherd cape.

Parameters:

state (bool) – True for on, False for off

start(start_time: float | None = None, wait_blocking: bool = True) bool#

Starts sampling either now or at later point in time.

Parameters:
  • start_time (int) – Desired start time in unix time

  • wait_blocking (bool) – If true, block until start has completed

static wait_for_start(timeout: float) None#

Waits until shepherd has started sampling.

Parameters:

timeout (float) – Time to wait in seconds