percival.carrier
package¶
percival.carrier.devices
module¶
Created on 8 May 2015
@author: Ulrik Pedersen
-
class
percival.carrier.devices.
Command
[source]¶ Represent the Command register bank:
- Word 0: Device command interface word
- Word 1: Sensor command interface word
- Word 2: System command interface word
-
class
percival.carrier.devices.
ControlChannel
[source]¶ Represent the map of Control Channels register bank
-
class
percival.carrier.devices.
DeviceSettings
[source]¶ Mixin to be used by classes that implement the IDeviceSettings interface
percival.carrier.registers
module¶
Created on 5 Dec 2014
@author: Ulrik Pedersen
-
percival.carrier.registers.
CarrierUARTRegisters
= {0: (u'Header settings left', 302, 1, 1, <class 'percival.carrier.devices.HeaderInfo'>), 1: (u'Control settings left', 303, 1, 1, <class 'percival.carrier.devices.ControlChannel'>), 130: (u'Control settings bottom', 306, 1, 1, <class 'percival.carrier.devices.ControlChannel'>), 65: (u'Monitoring settings left', 304, 1, 1, <class 'percival.carrier.devices.MonitoringChannel'>), 236: (u'Command', 324, 1, 1, <class 'percival.carrier.devices.Command'>), 138: (u'Monitoring settings bottom', 307, 1, 1, <class 'percival.carrier.devices.MonitoringChannel'>), 146: (u'Header settings carrier', 308, 1, 1, <class 'percival.carrier.devices.HeaderInfo'>), 147: (u'Control settings carrier', 309, 1, 1, <class 'percival.carrier.devices.ControlChannel'>), 155: (u'Monitoring settings carrier', 310, 1, 1, <class 'percival.carrier.devices.MonitoringChannel'>), 163: (u'Header settings plugin', 311, 1, 1, <class 'percival.carrier.devices.HeaderInfo'>), 164: (u'Control settings plugin', 312, 1, 1, <class 'percival.carrier.devices.ControlChannel'>), 129: (u'Header settings bottom', 305, 1, 1, <class 'percival.carrier.devices.HeaderInfo'>), 172: (u'Monitoring settings plugin', 313, 1, 1, <class 'percival.carrier.devices.MonitoringChannel'>)}¶ Look-up table of UART addresses and the corresponding details
The key is the UART write address and each item is a tuple of:
- description
- UART read_addr
- Number of entries
- Words per entry
- Corresponding implementation of the
percival.carrier.devices.IDeviceSettings
interface
-
class
percival.carrier.registers.
UARTRegister
(start_addr)[source]¶ Represent a specific UART register on the Percival Carrier Board
-
__init__
(start_addr)[source]¶ Constructor
Parameters: start_addr (int) – UART start address which also functions as a look-up key to the functionality of that register
-
get_read_cmdmsg
()[source]¶ Generate a message to do a readback (shortcut) command of the current register map
Returns: A read UART command message Return type: list of percival.carrier.txrx.TxMessage
objects
-
get_write_cmdmsg
()[source]¶ Flatten the 2D matrix of datawords into one continuous list
Returns: A write UART command message Return type: list of percival.carrier.txrx.TxMessage
objects
-
percival.carrier.txrx
module¶
Created on 4 Dec 2014
@author: Ulrik Pedersen
-
class
percival.carrier.txrx.
TxMessage
(message, num_response_msg=1, expect_eom=False)[source]¶ Encapsulate a Percival carrier board message and the number of messages to expect in response
-
__init__
(message, num_response_msg=1, expect_eom=False)[source]¶ TxMessage constructor
Parameters: - message (Byte array) – A Percival Carrier Board message contain address (2 bytes) and data (4 bytes)
- num_response_msg – Number of messages to expect in response
- expected_eom (boolean) – set true if end-of-message is expected in response
-
-
class
percival.carrier.txrx.
TxRx
(fpga_addr, port=10001, timeout=2.0)[source]¶ Transmit and receive data and commands to/from the Carrier Board through the XPort Ethernet
-
clean
()[source]¶ Shutdown and close the socket safely
Sockets are normally closed down cleanly on exit from the interpreter, however this method may be used in case the socket need to be closed down temporarily.
-
rx_msg
(expected_bytes=None)[source]¶ Receive messages of up to expected_bytes length
Parameters: expected_bytes – Number of bytes expected to be received. If expected_bytes is None, read at least one single message Raises RuntimeError: if a message of 0 bytes is received;indicating a broken socket connection Returns: The recieved message Return type: byte array
-
send_recv
(msg, expected_bytes=None)[source]¶ Send msg and wait for receipt of expected_bytes in response or timeout
Parameters: msg (Bytearray) – UART message to send Returns: Response from UART Return type: Bytearray
-
send_recv_message
(message)[source]¶ Send a message and wait for response
Parameters: message – a TxMessage object Retuns: Response from UART Return type: Bytearray
-
tx_msg
(msg)[source]¶ Transmit a single message to the Carrier Board
Parameters: msg (Bytearray of percival.carrier.encoding.NUM_BYTES_PER_MSG
bytes) – Message to transmit
-
-
percival.carrier.txrx.
TxRxContext
(*args, **kwds)[source]¶ Provide a context which keeps a TxRx module alive with an open socket only for the duration of the context
Minimal example:
>>> msg = encode_message(0x0144, 0x00000000) # Header Info Readback >>> >>> # Start the context - create the TxRx object and open the socket >>> with TxRxContext("192.168.1.3") as trx: >>> response = trx.send_recv(msg) >>> # End of context - socket is closed down cleanly >>> >>> response = decode_message(response) >>> print response
percival.carrier.encoding
module¶
Created on 4 Dec 2014
@author: Ulrik Pedersen
-
percival.carrier.encoding.
END_OF_MESSAGE
= b'\xff\xff\xab\xba\xba\xc1'¶ End of message is used in some cases. The EOM word is 0xFFFFABBABAC1
-
percival.carrier.encoding.
NUM_BYTES_PER_MSG
= 6¶ Number of bytes per message. Each message consist of a 2 byte address field and a 4 byte data field
-
percival.carrier.encoding.
decode_message
(msg)[source]¶ Decode a byte array into a list of (address, dataword) tuples.
The address field is a 16bit integer and the dataword is a 32bit integer.
Parameters: msg (Bytearray) – The input message Returns: A list of (address, data) tuples
-
percival.carrier.encoding.
encode_message
(addr, word)[source]¶ Encode a single address and dataword into a bytearray.
Parameters: - addr – UART address (16bit integer)
- word – data word (32bit integer)
Returns: bytearray of 6 bytes with address and dataword encoded
-
percival.carrier.encoding.
encode_multi_message
(start_addr, words)[source]¶ Encode multiple 32bit words as a multi-message.
Parameters: - start_addr – The UART starting address (a 16bit integer word)
- words – A list of 32bit integer words to be encoded
Returns: A list of encoded words, each of which consists of 6 bytes: 2 words of address and 4 words of data