Skip to content

X52 Daemon

nirenjan edited this page May 29, 2020 · 2 revisions

While libx52 in conjunction with x52cli is a complete control mechanism to configure the LEDs and MFD, it makes more sense to integrate some of the functionality into a daemon that handles the communication with the X52 joystick and perhaps automate some actions, such as the MFD clock. Integrating the functionality into a single daemon also allows using uinput-like mechanisms to map key presses into keyboard/mouse events. Finally, this should also allow an application to generate MFD pages and act on those page button events.

Interprocess Communication

The daemon should listen on a Unix socket, most likely at $(runstatedir)/x52d.socket. Clients can connect to this socket and request the daemon to perform some activity, or request some info.

Message Format

Message Header

 3 3 2                 2 1                 1
 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Version    |   Message ID  |             Length            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Messages begin with a single byte version, this allows for future extensions to the message format. Message ID is a single byte identifier of the message type. Length is a 2-byte field that indicates the length of the embedded message.

Message IDs

This is a non-exhaustive list of the individual message IDs and a brief description. However, setting the clock time and date is explicitly disallowed since this is intended to be within the purview of the server. The client can still set the clock timezone and formats.

Message ID Description
0x00 Reserved, will never be used
0x01 Response from server, OK
0x02 Response from server, Failure
0x10 Set MFD text
0x11 Set LED state
0x12 Set clock timezone and format
0x13 Set date format
0x14 Set brightness
0x15 Set blink/shift state
0x16 Update joystick
0xFE Bulk Message
0xFF Reserved for extended message ID

Bulk Messages

Bulk messages are used to reduce the overhead when a client needs to send multiple messages to the server. These messages use the same format as a standard message, but embed several standard messages within the message body. The server will execute each of the embedded messages, but if any of the messages has a failure, it will return immediately with that error and any subsequent messages will not be executed.

Message marshal/unmarshal library

The library abstracts away the details of the socket API so that clients only need to call the library functions to communicate with the server.

// Connect to a server, returns a pointer descriptor to send messages to
x52d_connection * x52d_connect();

// On the server, set up the listener for clients to connect to. Use accept
// on the returned descriptor to accept connections.
int x52d_listen();

// Create message buffer
x52d_msgbuffer * x52d_create_msgbuffer();

// Push set led message into message buffer
int x52d_set_led_state(x52d_msgbuffer *, libx52_led_id, libx52_led_state);

// Push clock format message into message buffer
int x52d_set_clock_format(x52d_msgbuffer *, libx52_clock_id, libx52_clock_format);

// Send message to server. Buffer is no longer valid for application use.
int x52d_send_msg(x52d_connection *, x52d_msgbuffer *);

Clone this wiki locally