kafka_dae_control.comms

Utilities for communicating to a UDP device such as a streaming control board.

The functions in this module assume that they have exclusive use of the passed-in socket. This means that the socket object should be protected by a lock, external to this module.

Members

read

Read a register on the streaming control board and return its value.

set_board_response_ip

Set the board's communication register to the local IP address.

write

Write a value.

write_and_inv_then_verify

Write by reading the current value then ANDing it with the inverse of the new data.

write_verify

Write a value then verify it by reading it back with a retry/timeout loop.

kafka_dae_control.comms.read(sock: socket, host: IPv4Address, address: int, count: int, port: int) int[source]

Read a register on the streaming control board and return its value.

This is a ‘low-level’ function that should just attempt a single read.

Parameters:
  • sock – the UDP socket instance

  • host – the IP address of the streaming control board

  • address – the address to read

  • count – how many 32-bit words to request when reading.

  • port – port to use for reading

Returns: The received data

kafka_dae_control.comms.set_board_response_ip(config: ControlConfig, sock: socket, sock_lock: RLock) None[source]

Set the board’s communication register to the local IP address.

Parameters:
  • config – The program’s configuration

  • sock – the socket instance to use

  • sock_lock – the lock to use when using the socket instance.

kafka_dae_control.comms.write(sock: socket, host: IPv4Address, address: int, data: int, count: int, port: int) None[source]

Write a value.

This is a low-level function that should just attempt a single write without verifying it.

Parameters:
  • sock – the UDP socket instance

  • host – the streaming control board host IP

  • address – the address to write to

  • data – the data to write

  • count – the number of 32-bit words to write

  • port – port to use when writing

Returns: None

kafka_dae_control.comms.write_and_inv_then_verify(config: ControlConfig, sock: socket, address: int, data: int, count: int, verify: VerifyFunc, write_attempts: int = WRITE_ATTEMPTS) None[source]

Write by reading the current value then ANDing it with the inverse of the new data.

This is essentially used to “clear” a bit and call write_verify()

An example could be you want to clear bit 0x1`(binary: 01). `0x3 (binary: 11) is the current value, so you AND 0x3 (binary: 11) with 0x2 (binary: 10) (as this is the inverse of 0x1`(binary: 01)) then verify that you end up with `0x2 (binary: 10)

Parameters:
  • config – the program’s configuration containing board IP and ports

  • sock – the UDP socket instance

  • address – the address to write to

  • data – the data to write

  • count – the number of 32-bit words to write

  • verify – Optionally verify against a different provided value by ORing it

  • write_attempts – The number of times to retry writing and verifying.

Returns: None

kafka_dae_control.comms.write_verify(config: ControlConfig, sock: socket, address: int, new_value: int, count: int, verify: VerifyFunc, write_attempts: int = WRITE_ATTEMPTS) None[source]

Write a value then verify it by reading it back with a retry/timeout loop.

This function takes an “attempts” argument, which will re-write if the verification times out.

Parameters:
  • config – the program’s configuration containing board IP and ports

  • sock – the UDP socket instance

  • address – the address to write to

  • new_value – the data to write

  • count – the number of 32-bit words to write

  • verify – Optionally verify against a different provided value by ORing it

  • write_attempts – The number of times to retry writing and verifying.

Returns: None