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

NameTypeValuesReboot
needed
Description
video_enabledbooleannoVideo streaming enabled
video_previewbooleannoVideo preview (on HDMI) enabled
video_trig_mark_visiblebooleannoTrigger mark visible
video_pretrig_buff_lengthnumber[0,60]noPre-trigger buffer length [seconds]
video_protocolstring{H264-RTP-UDP,
H264-MPEGTS-TCP,
JPEG-RTP-UDP,
JPEG-MUX-TCP,
RAW-RTP-UDP,
RAW-TCP}
noVideo protocol
video_ipstringnoIP address (UDP: remote address, TCP: unused)
video_portnumbernoTCP port (UDP: remote port, TCP: local port)
video_frameratenumbernoFramerate [fps] (currently this property has no effect)
video_aoi_enabledbooleannoAOI (Area of Interest) enabled
video_aoi_xnumbernoX coordinate of the top-left AOI corner [pixels]
video_aoi_ynumbernoY coordinate of the top-left AOI corner [pixels]
video_aoi_widthnumbernoAOI width [pixels]
video_aoi_heightnumbernoAOI height [pixels]
video_ts_enabledbooleannoTimestamp (in-picture) enabled
video_ts_tstypestring{MONOTONIC_RELATIVE,
MONOTONIC_ABSOLUTE,
REALTIME}
noTimestamp type
video_ts_xposnumbernoTimestamp horizontal position [pixels]
video_ts_yposnumbernoTimestamp vertical position [pixels]
video_ts_bitwidthnumbernoTimestamp bit width [pixels]
video_ts_bitheightnumbernoTimestamp bit height [pixels]
video_nosig_colorstring{BLACK,
PINK}
noNo-signal color
photo_server_portnumbernoScreenshot server port
photo_periodic_enabledbooleannoPeriodical screenshots enabled
photo_periodnumbernoPeriodical screenshots period [milliseconds]
photo_store_enabledbooleannoStore periodical screenshots to file system enabled
photo_formatstringnoFormat of stored screenshots
photo_stored_framesnumbernoMaximum number of last stored periodical screenshots
lan_mgb_addressstringyesMGB IP address (reboot needed)
lan_mgb_netmaskstringyesMGB network mask (reboot needed)
lan_mgb_gatewaystringyesMGB gateway (reboot needed)
lan_mgb_namesrvstringyesMGB nameserver (reboot needed)
iface_modulestring{LVDS-FPD-LINK-2,
LVDS-FPD-LINK-3,
DIFF-FPK-MEDIUM-1,
DIFF-FPK-BASIC-1,
GMSL}
yesInterface module
iface_lvds_inputstring{AUTO, SINGLE, DUAL}noLVDS input
iface_openldistring{SINGLE, DUAL}noOpenLDI
iface_color_depthstring{24BIT, 18BIT}noColor depth
iface_color_mappingstring{MAPSEL-L, MAPSEL-H}noColor mapping
iface_olfe_resetstring{NONE, DES, DES-SER}noOn lock falling edge reset
iface_olre_resetstring{NONE, DES, DES-SER}noOn lock rising edge reset
iface_syncgenbooleannoInternal Hsync/Vsync generator enabled
iface_syncgen_devsyncnumbernoDE/Vsync length [pixels]
iface_custom_configbooleannoCustom configuration enabled
iface_lvds3desctrl0stringnoLVDS3DESCTRL0 [hex]
iface_lvds3desctrl1stringnoLVDS3DESCTRL1 [hex]
iface_lvds3desctrl2stringnoLVDS3DESCTRL2 [hex]
iface_lvds3serctrl0stringnoLVDS3SERCTRL0 [hex]
iface_lvds3serctrl1stringnoLVDS3SERCTRL1 [hex]
iface_bchannelstring{NONE,
UART,
FORWARD-SPI,
REVERSE-SPI}
noBack channel
iface_bchannel_snifferbooleannoBack channel sniffer enabled
iface_bchannel_portnumbernoBack channel server port
iface_bchannel_uart_brnumbernoBack channel UART baudrate [bps]
iface_lockdrop_counter_enabledbooleannoInterface lock-drop counter enabled
iface_lockdrop_counter_timeoutnumber[1,42949672]noInterface lock-drop counter timeout [microseconds]
iface_gmsl_protocolstring{GMSL2,
GMSL3}
noGMSL protocol
iface_gmsl_ratestring{3Gbps,
6Gbps,
12Gbps}
noGMSL rate
iface_gmsl_stream_idstring{0,
1,
2,
3}
noGMSL stream identifier
iface_gmsl_fec_enabledbooleannoGMSL FEC enabled
trig_pwrbtn_releasestring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-TOGGLE}
noTrigger button release
trig_tr1_risingstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
noExternal trigger TR1 rising
trig_tr1_fallingstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
noExternal trigger TR1 falling
trig_tr2_risingstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
noExternal trigger TR2 rising
trig_tr2_fallingstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
noExternal trigger TR2 falling
trig_can_match1string{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
VIDEOREC-TOGGLE,
MGB-ON,
MGB-OFF}
noCAN match 1
trig_can_match1_idstringnoCAN match 1 Identifier [hex] (append x to consider identifier as extended)
trig_can_match1_datastringnoCAN match 1 Data [hex] (concatenate all bytes into one number)
trig_can_match1_data_maskstringnoCAN 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}
noCAN match 2
trig_can_match2_idstringnoCAN match 2 Identifier [hex] (append x to consider identifier as extended)
trig_can_match2_datastringnoCAN match 2 Data [hex] (concatenate all bytes into one number)
trig_can_match2_data_maskstringnoCAN 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}
noCAN timeout
trig_can_timeout_valnumbernoCAN timeout value [seconds]
trig_can_wakeupstring{NONE,
SCREENSHOT-TO-TCP,
SCREENSHOT-TO-SDC,
VIDEOREC-START,
VIDEOREC-STOP,
MGB-ON}
noCAN wakeup
trig_mgb_startupstring{NONE,
SCREENSHOT-TO-SDC,
VIDEOREC-START}
noMGB startup
ntp_server1stringyesNTP server 1 (leave empty if not used, reboot needed)
ntp_server2stringyesNTP server 2 (leave empty if not used, reboot needed)
ntp_server3stringyesNTP server 3 (leave empty if not used, reboot needed)
ntp_server4stringyesNTP server 4 (leave empty if not used, reboot needed)
ntp_tos_orphanstringyesNTP Orphan stratum (reboot needed)
ntp_tos_orphanwaitstringyesNTP Orphan wait [seconds] (reboot needed)
system_control_portnumbernoControl server port
system_timezonestringnoOlson timezone
system_statprop_defsubscrbooleannoDefault subscription to status variables

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>,
		...
	}
}

Each control socket client gets only its own subscribed status properties.

Subscription to status properties

When control socket client wants to receive changed status properties, it must subscribe to them with:

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

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

Response:

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

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

true-Subscription succeeded
false-Subscription failed

When control socket client doesn't want to receive changed status properties, it must unsubscribe to them with:

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

Empty properties element is considered as to unsubscribe to all subscribed status properties. Any unknown property is ignored silently.

Response:

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

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

true-Unsubscription succeeded
false-Unsubscription failed

The subscription state of each just connected control socket client is controlled by system_statprop_defsubscr configuration property. When the property is set to true, then each just connected control socket client is subscribed to all available status properties automatically. When the property is set to false, then each just connected client is not subscribed to any status property.

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 been detected yet.
video_streamed_resolutionarrayLast streamed resolution in form of [width, height].
[0, 0] means, that no video has been streamed yet.
iface_lockdrop_counternumberInterface lock-drop counter (uint32_t)

Interface lock-status

Lock-drop counter reset

You can reset lock-drop counter with:

{
	"id": "reset_iface_lockdrop_counter"
}

Response:

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

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

true-Lock-drop counter reset succeeded
false-Lock-drop counter reset failed

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"
}