Control socket protocol

Basics

The communication protocol consists in exchanging of messages. Each message consists of binary-based length field followed by text-based json package. The message can be described by this packed C structure:

struct __attribute__((packed)) message {
	uint32_t length;
	uint8_t  json[];
};
length-length of json package (binary - LE)
data-flexible array containing json package (text - UTF8)

At the root level each json package must contain element named as id. Its string-typed value determines both the meaning of json package and also the presence of another elements. So the minimal json package looks like this:

{
	"id": <value>
}

Configuration properties

Configuration properties have these features:

Currently the validation of configuration properties is very limited, so it is mainly on user's own responsibility to set the correct values.

Set configuration properties

You can set the configuration properties with:

{
	"id": "set_configuration_properties",
	"properties": {
		<property_name>: <property_value>,
		<property_name>: <property_value>,
		...
	}
}

Any unknown property is ignored silently.

Response:

{
	"id": "set_configuration_properties_response",
	"result": <value>
	"properties": {
		<property_name>: <property_value>,
		<property_name>: <property_value>,
		...
	}
}

Result is contained in boolean-typed result element. Possible values:

true- all properties were set to the requested values. In this case properties element is empty.
false- at least one property couldn't be set to the requested value. In this case properties element contains these not-changed properties with their actual values.

Get configuration properties

You can get the configuration properties with:

{
	"id": "get_configuration_properties",
	"properties": [<property_name>, <property_name>, ...]
}

Empty properties element is considered as to get all available configuration properties. Any unknown property is ignored silently.

Response:

{
	"id": "get_configuration_properties_response",
	"properties": {
		<property_name>: <property_value>,
		<property_name>: <property_value>,
		...
	}
}

Configuration properties change

Whenever the configuration properties are changed, then all the control socket clients (not causing this change) are informed with:

{
	"id": "configuration_properties",
	"properties": {
		<property_name>: <property_value>,
		<property_name>: <property_value>,
		...
	}
}

Configuration properties list

NameTypeValuesDescription
video_enabledbooleanVideo streaming enabled
video_previewbooleanVideo preview (on HDMI) enabled
video_trig_mark_visiblebooleanTrigger mark visible
video_pretrig_buff_lengthnumber[0,60]Pre-trigger buffer length [seconds]
video_protocolstring{H264-RTP-UDP,
H264-MPEGTS-TCP,
JPEG-RTP-UDP,
JPEG-MUX-TCP,
RAW-RTP-UDP,
RAW-TCP}
Video protocol
video_ipstringIP address (UDP: remote address, TCP: unused)
video_portnumberTCP port (UDP: remote port, TCP: local port)
video_frameratenumberFramerate [fps] (currently this property has no effect)
video_aoi_enabledbooleanAOI (Area of Interest) enabled
video_aoi_xnumberX coordinate of the top-left AOI corner [pixels]
video_aoi_ynumberY coordinate of the top-left AOI corner [pixels]
video_aoi_widthnumberAOI width [pixels]
video_aoi_heightnumberAOI height [pixels]
video_ts_enabledbooleanTimestamp (in-picture) enabled
video_ts_tstypestring{MONOTONIC_RELATIVE,
MONOTONIC_ABSOLUTE,
REALTIME}
Timestamp type
video_ts_xposnumberTimestamp horizontal position [pixels]
video_ts_yposnumberTimestamp vertical position [pixels]
video_ts_bitwidthnumberTimestamp bit width [pixels]
video_ts_bitheightnumberTimestamp bit height [pixels]
photo_server_portnumberScreenshot server port
photo_periodic_enabledbooleanPeriodical screenshots enabled
photo_periodnumberPeriodical screenshots period [milliseconds]
photo_store_enabledbooleanStore periodical screenshots to file system enabled
photo_formatstringFormat of stored screenshots
photo_stored_framesnumberMaximum number of last stored periodical screenshots
lan_mgb_addressstringMGB IP address (reboot needed)
lan_mgb_netmaskstringMGB network mask (reboot needed)
lan_mgb_gatewaystringMGB gateway (reboot needed)
lan_mgb_namesrvstringMGB nameserver (reboot needed)
iface_modulestring{LVDS-FPD-LINK-2
LVDS-FPD-LINK-3}
Interface module
iface_lvds_inputstring{AUTO, SINGLE, DUAL}LVDS input
iface_openldistring{SINGLE, DUAL}OpenLDI
iface_color_depthstring{24BIT, 18BIT}Color depth
iface_color_mappingstring{MAPSEL-L, MAPSEL-H}Color mapping
iface_olfe_resetstring{NONE, DES, DES-SER}On lock falling edge reset
iface_olre_resetstring{NONE, DES, DES-SER}On lock rising edge reset
iface_syncgenbooleanInternal Hsync/Vsync generator enabled
iface_syncgen_devsyncnumberDE/Vsync length [pixels]
iface_custom_configbooleanCustom configuration enabled
iface_lvds3desctrl0stringLVDS3DESCTRL0 [hex]
iface_lvds3desctrl1stringLVDS3DESCTRL1 [hex]
iface_lvds3desctrl2stringLVDS3DESCTRL2 [hex]
iface_lvds3serctrl0stringLVDS3SERCTRL0 [hex]
iface_lvds3serctrl1stringLVDS3SERCTRL1 [hex]
iface_bchannelstring{NONE,
UART,
FORWARD-SPI,
REVERSE-SPI}
Back channel
iface_bchannel_snifferbooleanBack channel sniffer enabled
iface_bchannel_portnumberBack channel server port
iface_bchannel_uart_brnumberBack channel UART baudrate [bps]
trig_pwrbtn_releasestring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-TOGGLE}
Trigger button release
trig_tr1_risingstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
External trigger TR1 rising
trig_tr1_fallingstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
External trigger TR1 falling
trig_tr2_risingstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
External trigger TR2 rising
trig_tr2_fallingstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
External trigger TR2 falling
trig_can_match1string{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
CAN match 1
trig_can_match1_idstringCAN match 1 Identifier [hex] (append x to consider identifier as extended)
trig_can_match1_datastringCAN match 1 Data [hex] (concatenate all bytes into one number)
trig_can_match1_data_maskstringCAN match 1 Data mask [hex] (concatenate all bytes into one number)
trig_can_match2string{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
CAN match 2
trig_can_match2_idstringCAN match 2 Identifier [hex] (append x to consider identifier as extended)
trig_can_match2_datastringCAN match 2 Data [hex] (concatenate all bytes into one number)
trig_can_match2_data_maskstringCAN match 2 Data mask [hex] (concatenate all bytes into one number)
trig_can_timeoutstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
MGB-OFF}
CAN timeout
trig_can_timeout_valnumberCAN timeout value [seconds]
trig_can_wakeupstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
MGB-ON}
CAN wakeup
trig_mgb_startupstring{NONE,
SCREENSHOT-TO-SDC,
VIDEOREC-START}
MGB startup
ntp_server1stringNTP server 1 (leave empty if not used, reboot needed)
ntp_server2stringNTP server 2 (leave empty if not used, reboot needed)
ntp_server3stringNTP server 3 (leave empty if not used, reboot needed)
ntp_server4stringNTP server 4 (leave empty if not used, reboot needed)
ntp_tos_orphanstringNTP Orphan stratum (reboot needed)
ntp_tos_orphanwaitstringNTP Orphan wait [seconds] (reboot needed)
system_control_portnumberControl server port
system_timezonestringOlson timezone

Status properties

Status properties have these features:

Get status properties

You can get the status properties with:

{
	"id": "get_status_properties",
	"properties": [<property_name>, <property_name>, ...]
}

Empty properties element is considered as to get all available status properties. Any unknown property is ignored silently.

Response:

{
	"id": "get_status_properties_response",
	"properties": {
		<property_name>: <property_value>,
		<property_name>: <property_value>,
		...
	}
}

Status properties change

Whenever the status properties are changed, then all the control socket clients are informed with:

{
	"id": "status_properties",
	"properties": {
		<property_name>: <property_value>,
		<property_name>: <property_value>,
		...
	}
}

Status properties list

NameTypeValuesDescription
mgb_versionstringMGB version
app_versionstringApp version
lpc_sw_versionstringLPC version
fpga_sw_versionstringFPGA version
xpdriver_versionstringPCIe driver version
mgb_board_versionstringBoard version
snstringSerial number
video_streamedbooleantrue if video is streamed, otherwise false
video_lockedbooleantrue if video input is locked, otherwise false
video_detected_resolutionarrayLast detected valid resolution in form of [width, height].
[0, 0] means, that no valid video has has been detected yet.
video_streamed_resolutionarrayLast streamed resolution in form of [width, height].
[0, 0] means, that no video has been streamed yet.

Date and Time

All datetime elements are string-typed and hold the local date and time in this format (see POSIX function strptime):

%Y-%m-%d %H:%M:%S

Set local date and time

You can set the local date and time with:

{
	"id": "set_local_datetime",
	"datetime": <value>
}

Response:

{
	"id": "set_local_datetime_response",
	"result": <value>
}

Result is contained in boolean-typed result element. Possible values:

true-Local date and time were set successfully
false-Local date and time setting failed

Get local date and time

You can get the local date and time with:

{
	"id": "get_local_datetime"
}

Response:

{
	"id": "get_local_datetime_response",
	"datetime": <value>
}

Reboot

{
	"id": "reboot"
}

There is no response. However if the command is executed successfully, then the control socket closes at the MGB side.

Poweroff

{
	"id": "poweroff"
}

There is no response. However if the command is executed successfully, then the control socket closes at the MGB side.

Errors

In case of any problem with parsing of received json package (missing, unknown or wrong-typed elements), the response will be:

{
	"id": "error"
}