JSON Control

JavaScript Object Notation (JSON) is a widely used data interchange format. The M.1k2 allows you to query and set audio crosspoints via HTTP requests that contain JSON data. Also the current device status can be queried.

Almost all modern scripting languages support JSON, so integrating the M.1k2 in your corporate setup can be accomplished easily.

JSON Reference

Currently there are three methods implemented:

PathMethodFunction
/json/status_get GET Get the device and signal status.
/json/xps_get GET Get the online matrix.
/json/xps_set POST Set a variable number of audio crosspoints in the online matrix.
/json/locks_get GET Get the channel locks.
/json/locks_set POST Set a variable number of locks.
/json/snapshots_get GET Get the list of system snapshots.
/json/snapshot_set GET Recall a system snapshot.
/json/destination_status GET Get the full status of destination channels.
/json/source_status GET Get the full status of source channels.

/json/status_get

Returns the current device and signal status.


{
  "serial": "12345678",
  "fpga_firmware": "2.2.87",
  "temperature": 49.3,
  "psu_1": "active",
  "psu_2": "off",
  "input_status": [
    {
      "status": "no signal",
      "frequency": 0,
      "ch": 56,
      "frame": 48,
      "last_change": 0,
      "label": "Input Port 1",
      "fg": "000000",
      "bg": "FFFFFF"
    },
    {
      "status": "sync",
      "frequency": 48000,
      "ch": 64,
      "frame": 48,
      "last_change": 1363553568,
      "label": "Input Port 2",
      "fg": "000000",
      "bg": "FFFFFF"
    },
    [..]
  ],
  "output_config": [
    {
      "clock": "wck_input",
      "fs": "1FS",
      "ch": 56,
      "frame": 48,
      "label": "Output Port 1",
      "fg": "000000",
      "bg": "FFFFFF"
    },
    [..]
  ],
  "wck_status": "sync",
  "wck_freq": 48000,
  "wck_last_change": 1363553562,
  "video_status": "no signal",
  "video_mode": "PAL",
  "video_freq_44": 44100,
  "video_freq_48": 48000
  "video_last_change": 0
}
FieldTypeContents
serial String The device's serial number
fpga_firmware String Currently running FPGA firmware
temperature Number Float containing the current temperature
psu_1, psu_2 Number Status of power supply 1/2. The possible values are off, active and failed.
input_status Array Array of 16 objects with the signal status for the 16 MADI inputs.
    status String One of no signal, lock or sync
    frequency Number Integer containing the measured frequency of the signal on that port.
    ch Number Integer reflecting the channel mode of this port. Can be 56 or 64.
    frame Number Integer reflecting the frame mode of this port. Can be 48 (for 48kHz frame format) or 96 (for 96kHz frame format).
    last_change Number Integer, containts the time of the last sync state change in seconds since 1970-01-01 (UNIX epoch).
    label String Port label, up to 16 chars.
    fg String Hex string with RGB values containing the foreground (text) color of the label.
    bg String Hex string with RGB values containung the background color of the label.
output_config Array Array of 16 objects with the confioguration for the 16 MADI outputs.
    clock String Active clock reference for this port. One of port1, ..., port16, wck_input, video_441, video_48, internal_441, internal_48.
    fs String Active WCK multiplier for this port. One of 1FS, 2FS, 4FS.
    ch Number Integer reflecting the channel mode of this port. Can be 56 or 64..
    frame Number Integer reflecting the frame mode of this port. Can be 48 (for 48kHz frame format) or 96 (for 96kHz frame format)..
    label String Port label, up to 16 chars.
    fg String Hex string with RGB values containing the foreground (text) color of the label..
    bg String Hex string with RGB values containung the background color of the label.
wck_status String One of no signal, lock or sync
wck_freq Number Integer containing the measured frequency of the incoming word clock signal.
wck_last_change Number Integer, containts the time of the last sync state change in seconds since 1970-01-01 (UNIX epoch).
video_status String One of no signal, lock or sync
video_mode Number Either PAL or NTSC
video_freq_44 Number The 44.1kHz frequency that is derived from the incoming video signal.
video_freq_48 Number The 48kHz frequency that is derived from the incoming video signal.
video_last_change Number Integer, containts the time of the last sync state change in seconds since 1970-01-01 (UNIX epoch).

/json/xps_get

The result is a fairly condensed JSON array containing all crosspoints indexed by destination channel. If a destination is connected, the corresponding source channel is given as a number (0..1023). If a destination is not connected, the value null is set.


[0,1,2,3,4,5,6,7,
 null,null,null,null,null,null,null,null, 
 [..] 
 1016,1017,1018,1019,1020,1021,1022,1023]

In the example above, we see unity connections except for destination channels 8..16, which are disconnected.

/json/xps_set

You can set any number of destination sources by passing a variable length object in the body of the POST request to this URL. The keys have to be the destination channels as decimal number in a string, the value has to be a decimal number of the source channel (0..1023) or the keyword null.

Note: All crosspoints in the same object will be set simultaneously.

If the JSON data could be parsed successfully and all commands are processed, you will receive a HTTP 200 status code reply. In case of an error, you will receive a HTTP 500 status code together with a (hopefully) meaningful error message.

Examples

  1. This will create a unity matrix (all sources routes 1:1 on the destinations):

    
    { "0": 0,
      "1": 1,
      [..]
      "1022": 1022,
      "1023": 1023
    }
    
  2. Set output channels 1/2 of MADI ports 1 and 2 to input channels 17/18 and disconnect output channels 5..8 on MADI port 1:

    
    { "0": 16, "1": 17,
      "64": 16, "65": 17,
      "4": null, "5": null,
      "6": null, "7": null
    }
    

/json/locks_get

Returns an array with 1024 entries of 0/1 values, with 1 indicating a locked channel.


[0,0,0,0,1,0,0,0,
 [..] 
 1,1,1,1,1,1,1,1]

/json/locks_set

You can set any number of channel locks by passing a variable length object in the body of the POST request to this URL. The keys have to be the destination channels as decimal number in a string, the value has to be a 0 or null to clear a lock, and 1 to lock the corresponding channel.

Note: All locks in the same object will be set simultaneously.

If the JSON data could be parsed successfully and all commands are processed, you will receive a HTTP 200 status code reply. In case of an error, you will receive a HTTP 500 status code together with a (hopefully) meaningful error message.

Example

This will lock all channels:


{ "0": 1,
  "1": 1,
  [..]
  "1022": 1,
  "1023": 1
}

/json/snapshots_get

Returns an array containing all system snapshots. Empty slots are not reported. The snapshots are not sorted by their ID.

		
[
  {
    "id": 2,
    "timestamp": 1384944120,
    "date_time": "2013/11/20 11:42",
    "project": "Soundfield Demo",
    "fg": "000000",
    "bg": "FF6300",
    "name": "Test 1',
    "comment": ""
  },
  [..]
]       
FieldTypeContents
id Number Slot ID of the system snapshot, a number from 0..127.
timestamp Number Storage date/time in seconds since 1970-01-01 (UNIX epoch).
date_time String Human readable storage date/time.
project String Project name.
fg String Hex string with RGB values containing the foreground (text) color of the label.
bg String Hex string with RGB values containung the background color of the label.
name String Snapshot title.
comment String Optional snapshot comment.

/json/snapshot_set

Recalls a system snapshot. This resource has two mandatory GET arguments:

/json/snapshot_set?<ID>,<Flags>

ArgumentContents
ID Slot-ID of the system snapshot, a number from 0..127.
Flags Bitmask configuring what parts to recall from the snapshot.
DecHEXMeaning
10x01Restore offline matrix
20x02Restore offline matrix data in online (not set) or offline matrix (set)
40x04Restore online matrix
80x08Restore online matrix data in online (not set) or offline matrix (set)
160x10Restore port gains
320x20Restore channel gains
640x40Restore locks
1280x80Restore MIDI matrix
2560x100Restore serial matrix
5120x200Restore labels
10240x400Restore port configuration
20480x800Restore clock configuration

So, to restore everything from a snapshot, the flags argument has to be 4087 (1+2+4+16+32+64+128+256+512+1024+2048, or (4096-1)-8).

Examples

  1. Restore everything from system snapshot 10:
    /json/snapshot_set?10,4087
  2. Just the online matrix from snapshot 2:
    /json/snapshot_set?2,4
  3. Offline matrix into online matrix:
    /json/snapshot_set?2,3

/json/destination_status

Returns connection details for a range of destinations.

/json/destination_status?<from>,<to>

The GET arguments from and to define the destination channel range to report, ranging from 1..1024. The result is an object with this structure:

		
/json/destination_status?1,2
{
  "1": {
    "label": "Output 1/1",
    "fg": "000000",
    "bg": "FFFFFF",
    "locked": 0,
    "source": {
      "channel": 1,
      "label": "Input 1/1",
      "fg": "000000",
      "bg": "FFFFFF",
    }
  },
  "2": {
    "label": "Output 1/2",
    "fg": "000000",
    "bg": "FFFFFF",
    "locked": 0,
    "source": null
  }
}
FieldTypeContents
label String Name of the destination channel.
fg String Hex string with RGB values containing the foreground (text) color of the label.
bg String Hex string with RGB values containung the background color of the label.
locked Number Indicates wether the destination channel is locked (1) or not (0).
source Object If the destination is connected, this contains an object with the source channel description. If not, the value null is provided instead.

/json/source_status

Similar to the destination_status resource, but returns the data from a source channel's perspective.

/json/source_status?<from>,<to>

The GET arguments from and to define the source channel range to report, ranging from 1..1024. The result is an object with this structure:

		
/json/source_status?1,2
{
  "1": {
    "label": "Input 1/1",
    "fg": "000000",
    "bg": "FFFFFF",
    "destinations": {
      "1": {
        "label": "Output 1/1",
        "fg": "000000",
        "bg": "FFFFFF",
        "locked": 0},
      "3": {
        "label": "Output 1/3",
        "fg": "000000",
        "bg": "FFFFFF",
        "locked": 0}
    }
  },
  "2": {
    "label": "Output 1/2",
    "fg": "000000",
    "bg": "FFFFFF",
    "destinations": null
  }
}
FieldTypeContents
label String Name of the destination channel.
fg String Hex string with RGB values containing the foreground (text) color of the label.
bg String Hex string with RGB values containung the background color of the label.
destinations Object If the source is connected, this contains an object with a variable number of destination details. If the source is not connected, null is returned.

JSON Security

All JSON commands are executed with the permissions for the plugin 'json'. If you want to restrict the execution of JSON commands to parts of the M.1k2, please choose a fitting permission class for the 'json' plugin - or create a new permission class to suit your needs.

Example Script

This PHP script queries and sets all JSON data and handles the HTTP requests all the way from scratch for demonstration purposes:

json_test.php (Version 1, 2013-03-18)

JSON Specification

For more information about JavaScript Object Notation (JSON), please consult the IETF's specification, RFC 4627.

Questions? Suggestions?

If you have questions, found a bug or need new features, please do not hesitate to contact us: support@directout.eu.

Text and images © 2014 DirectOut Technologies, 21.01.2014