Difference between revisions of "Formats and structures"

From sigrok
Jump to: navigation, search
(Created page with 'This document describes various formats used by sigrok. == Data feed == The data feed format is used to transfer data feeds internally within sigrok. It is created by a hardwa…')
 
m
Line 12: Line 12:
 
  void *payload;
 
  void *payload;
 
  };
 
  };
 
  
 
=== Packet types ===
 
=== Packet types ===
  
==== DF_HEADER ====
+
'''DF_HEADER:'''
  
 
This the first packet in any data stream. The payload consists of the following struct:
 
This the first packet in any data stream. The payload consists of the following struct:
Line 23: Line 22:
 
  int feed_version;
 
  int feed_version;
 
  struct timeval starttime;
 
  struct timeval starttime;
  float rate;
+
  uint64_t samplerate;
 
  int protocol_id;
 
  int protocol_id;
 
  int num_probes;
 
  int num_probes;
 
  };
 
  };
  
 +
'''DF_END:'''
 +
End of stream (no further data).
  
==== DF_END ====
+
'''DF_TRIGGER:'''
Eend of stream (no further data).
+
The trigger matched at this point in the data feed. There is no payload in this packet, but the next data to come in will be the samples that matched the trigger.
 
 
==== DF_TRIGGER ====
 
The trigger matched at this point in the data feed
 
There is no payload in this packet, but the next data to come in will be the
 
samples that matched the trigger.
 
 
 
==== DF_LOGIC8 ====
 
Raw logic analyzer data. Unitsize is 1 byte, describing up to 8 probes worth of data, one sample per bit. MSB = first probe. unused bits are set to zero.
 
  
==== DF_LOGIC16 ====
+
'''DF_LOGIC8:'''
Raw logic analyzer data. Unitsize is 2 bytes, describing up to 16 probes worth of data, one sample per bit. MSB = first probe. unused bits are set to zero.
+
Raw logic analyzer data. Unitsize is 1 byte, describing up to 8 probes worth of data, one sample per bit. MSB = first probe. Unused bits are set to zero.
  
==== DF_LOGIC24 ====
+
'''DF_LOGIC16:'''
Raw logic analyzer data. Unitsize is 3 bytes, describing up to 24 probes worth of data, one sample per bit. MSB = first probe. unused bits are set to zero.
+
Raw logic analyzer data. Unitsize is 2 bytes, describing up to 16 probes worth of data, one sample per bit. MSB = first probe. Unused bits are set to zero.
  
==== DF_LOGIC32 ====
+
'''DF_LOGIC24:'''
Raw logic analyzer data. Unitsize is 4 bytes, describing up to 32 probes worth of data, one sample per bit. MSB = first probe. unused bits are set to zero.
+
Raw logic analyzer data. Unitsize is 3 bytes, describing up to 24 probes worth of data, one sample per bit. MSB = first probe. Unused bits are set to zero.
  
 +
'''DF_LOGIC32:'''
 +
Raw logic analyzer data. Unitsize is 4 bytes, describing up to 32 probes worth of data, one sample per bit. MSB = first probe. Unused bits are set to zero.
  
 
== Data store ==
 
== Data store ==
Line 62: Line 57:
 
  GSList *chunklist;
 
  GSList *chunklist;
 
  };
 
  };
 
  
 
== Session file ==
 
== Session file ==
Line 68: Line 62:
 
A sigrok session file contains all the raw data captured in a session, and various metadata identifying the source, pin names, and so on. The file extension of a session file is 'sigrok'. The file format is a ZIP file, containing the following files:
 
A sigrok session file contains all the raw data captured in a session, and various metadata identifying the source, pin names, and so on. The file extension of a session file is 'sigrok'. The file format is a ZIP file, containing the following files:
  
==== version ====
+
'''version:'''
 
 
 
Contains the version of the session format used in this ZIP file, as an ASCII string. The starting version is 1.
 
Contains the version of the session format used in this ZIP file, as an ASCII string. The starting version is 1.
  
==== metadata ====
+
'''metadata:'''
 
 
 
This is a key-value file (.ini-like) containing the following keys in the [main] section:
 
This is a key-value file (.ini-like) containing the following keys in the [main] section:
  
* probes
+
* probes: Number of probes in this data feed.
<blockquote>
+
* probename[]: An indexed list of probe names. The probe index starts at 1.
Number of probes in this data feed.
+
* trigger[]: An indexed list of triggers configured on the probes. The probe index starts at 1.
</blockquote>
+
* analyzers: A list of protocol analyzers that was used on this data feed at the time it was saved, separated by a space, with the first entry representing the bottom of the analysis stack. Regardless of this list, the data feed saved is '''always''' the raw feed.
 
+
* starttime: High-resolution timestamp denoting the date + time the data was originally captured, in RFC 3339 format e.g. ''2009-04-13 11:35:08.538429857+02:00''.
* probename[]
+
* freqdiv: Sample frequency expressed as 1s / freqdiv.
<blockquote>
+
* unitsize: The size (in bytes) of a single data unit in the data feed.
An indexed list of probe names. The probe index starts at 1.
+
* device: The name of the device that was used to capture this data feed originally.
</blockquote>
+
* port: The port to which the capture device was connected.
 
 
* trigger[]
 
<blockquote>
 
An indexed list of triggers configured on the probes. The probe index starts at 1.
 
</blockquote>
 
 
 
* analyzers
 
<blockquote>
 
A list of protocol analyzers that was used on this data feed at the time it was saved, separated by a space, with the first entry representing the bottom of the analysis stack. Regardless of this list, the data feed saved is **always** the raw feed.
 
</blockquote>
 
 
 
* starttime
 
<blockquote>
 
High-resolution timestamp denoting the date + time the data was originally captured, in RFC 3339 format e.g. ``2009-04-13 11:35:08.538429857+02:00``
 
</blockquote>
 
 
 
* freqdiv
 
<blockquote>
 
Sample frequency expressed as 1s / freqdiv.
 
</blockquote>
 
 
 
* unitsize
 
<blockquote>
 
The size (in bytes) of a single data unit in the data feed.
 
</blockquote>
 
 
 
* device
 
<blockquote>
 
The name of the device that was used to capture this data feed originally.
 
</blockquote>
 
 
 
* port
 
<blockquote>
 
The port to which the capture device was connected
 
</blockquote>
 
  
 
Unused probes have no probename defined, and probes that have no trigger defined are not mentioned in this file. Only relevant data is stored.
 
Unused probes have no probename defined, and probes that have no trigger defined are not mentioned in this file. Only relevant data is stored.
  
==== raw ====
+
'''raw:'''
 
 
 
This file contains the raw signal data, in network-endian format. The size of a unit is set in the "metadata" file.
 
This file contains the raw signal data, in network-endian format. The size of a unit is set in the "metadata" file.

Revision as of 16:14, 19 March 2010

This document describes various formats used by sigrok.

Data feed

The data feed format is used to transfer data feeds internally within sigrok. It is created by a hardware plugin (or the session load code) by taking raw data and adding metadata to it. A feed packet consists of a packet type, followed by a structure particular to that data type.

Data feed packet

struct datafeed_packet {
	uint16_t type;
	uint16_t length;
	void *payload;
};

Packet types

DF_HEADER:

This the first packet in any data stream. The payload consists of the following struct:

struct datafeed_header {
	int feed_version;
	struct timeval starttime;
	uint64_t samplerate;
	int protocol_id;
	int num_probes;
};

DF_END: End of stream (no further data).

DF_TRIGGER: The trigger matched at this point in the data feed. There is no payload in this packet, but the next data to come in will be the samples that matched the trigger.

DF_LOGIC8: Raw logic analyzer data. Unitsize is 1 byte, describing up to 8 probes worth of data, one sample per bit. MSB = first probe. Unused bits are set to zero.

DF_LOGIC16: Raw logic analyzer data. Unitsize is 2 bytes, describing up to 16 probes worth of data, one sample per bit. MSB = first probe. Unused bits are set to zero.

DF_LOGIC24: Raw logic analyzer data. Unitsize is 3 bytes, describing up to 24 probes worth of data, one sample per bit. MSB = first probe. Unused bits are set to zero.

DF_LOGIC32: Raw logic analyzer data. Unitsize is 4 bytes, describing up to 32 probes worth of data, one sample per bit. MSB = first probe. Unused bits are set to zero.

Data store

The data store consists of a series of chunks of memory, storing raw samples. The chunks are used to reduce the need for the system to provide a single contiguous area of memory for a potentially large dataset, while allowing the dataset to grow easily as data streams in.

Data store size is kept as small as possible by only storing as much data as is actually used, regardless of the sample size provided by a data feed. For example, a raw logic analyzer feed that comes in as a 4-byte unit of which only 4 probes (and thus 4 bits) are used, will use only 1 byte per unit.

struct datastore {
	/* size in bytes of the number of units stored in this datastore */
	int unitsize;
	unsigned int num_units;
	GSList *chunklist;
};

Session file

A sigrok session file contains all the raw data captured in a session, and various metadata identifying the source, pin names, and so on. The file extension of a session file is 'sigrok'. The file format is a ZIP file, containing the following files:

version: Contains the version of the session format used in this ZIP file, as an ASCII string. The starting version is 1.

metadata: This is a key-value file (.ini-like) containing the following keys in the [main] section:

  • probes: Number of probes in this data feed.
  • probename[]: An indexed list of probe names. The probe index starts at 1.
  • trigger[]: An indexed list of triggers configured on the probes. The probe index starts at 1.
  • analyzers: A list of protocol analyzers that was used on this data feed at the time it was saved, separated by a space, with the first entry representing the bottom of the analysis stack. Regardless of this list, the data feed saved is always the raw feed.
  • starttime: High-resolution timestamp denoting the date + time the data was originally captured, in RFC 3339 format e.g. 2009-04-13 11:35:08.538429857+02:00.
  • freqdiv: Sample frequency expressed as 1s / freqdiv.
  • unitsize: The size (in bytes) of a single data unit in the data feed.
  • device: The name of the device that was used to capture this data feed originally.
  • port: The port to which the capture device was connected.

Unused probes have no probename defined, and probes that have no trigger defined are not mentioned in this file. Only relevant data is stored.

raw: This file contains the raw signal data, in network-endian format. The size of a unit is set in the "metadata" file.