PACMAN interface message format¶
A python interface to the pacman ZMQ message format.
The pacman ZMQ messages are a raw bytestring with two components: a short header and N words. It’s a bit cumbersome to work with bytestrings in data (and keep track of endianness / etc), so this module allows you to translate between native python objects and the pacman message bytestring.
To import this module:
import larpix.format.pacman_msg_format as pacman_msg_fmt
Access to the message content is provided by the parse_msg(msg)
method which
takes a single pacman message bytestring as an argument, e.g.:
msg = b'!----- P---------------' # a simple ping response
data = pacman_msg_fmt.parse_msg(msg) # (('REP',123456,1), [('PONG')])
msg = b'D----- D------datadata' # a simple data message
data = pacman_msg_fmt.parse_msg(msg) # (('DATA',123456,1), [('DATA',1,1234,b'datadata')])
The creation of messages can be performed with the inverse method,
format_msg(msg_type, msg_words)
. Here, the msg_type
is one of 'DATA'
,
'REQ'
, or 'REP'
, and msg_words
is a list
of tuples indicating the word
type (index 0) and the word data (index 1, 2, …). Word types are specified
by strings that can be found in the word_type_table
. The necessary fields
(and primitive types) for the word data is described in the word_fmt_table
.
E.g.:
data = ('REP', [('PONG')]) # simple ping response
msg = pacman_msg_fmt.format_msg(*data) # b'!---- P '
data = ('DATA', [('DATA',1,1234,b'datadata')])
msg = pacman_msg_fmt.format_msg(*data) # b'D---- D datadata'
To facilitate translating to/from larpix-control
packet objects, you can use
the format(pkts, msg_type)
and parse(msg, io_group=None)
methods. E.g.:
packet = Packet_v2()
packet.io_channel = 1
msg = pacman_msg_fmt.format([packet]) # b'?---- D '
packets = pacman_msg_fmt.parse(msg, io_group=1) # [Packet_v2(b'