#include <Python.h>
#include <stdint.h>
#include <glib.h>
Go to the source code of this file.
Data Structures | |
struct | srd_decoder |
struct | srd_probe |
Structure which contains information about one protocol decoder probe. More... | |
struct | srd_decoder_inst |
struct | srd_pd_output |
struct | srd_proto_data |
struct | srd_pd_callback |
struct | srd_Decoder |
struct | srd_logic |
Macros | |
#define | SRD_PACKAGE_VERSION_MAJOR 0 |
The libsigrokdecode package 'major' version number. More... | |
#define | SRD_PACKAGE_VERSION_MINOR 1 |
The libsigrokdecode package 'minor' version number. More... | |
#define | SRD_PACKAGE_VERSION_MICRO 1 |
The libsigrokdecode package 'micro' version number. More... | |
#define | SRD_PACKAGE_VERSION_STRING "0.1.1" |
The libsigrokdecode package version ("major.minor.micro") as string. More... | |
#define | SRD_LIB_VERSION_CURRENT 0 |
The libsigrokdecode libtool 'current' version number. More... | |
#define | SRD_LIB_VERSION_REVISION 1 |
The libsigrokdecode libtool 'revision' version number. More... | |
#define | SRD_LIB_VERSION_AGE 0 |
The libsigrokdecode libtool 'age' version number. More... | |
#define | SRD_LIB_VERSION_STRING "0:1:0" |
The libsigrokdecode libtool version ("current:revision:age") as string. More... | |
#define | SRD_OK 0 |
No error. More... | |
#define | SRD_ERR -1 |
Generic/unspecified error. More... | |
#define | SRD_ERR_MALLOC -2 |
Malloc/calloc/realloc error. More... | |
#define | SRD_ERR_ARG -3 |
Function argument error. More... | |
#define | SRD_ERR_BUG -4 |
Errors hinting at internal bugs. More... | |
#define | SRD_ERR_PYTHON -5 |
Python C API error. More... | |
#define | SRD_ERR_DECODERS_DIR -6 |
Protocol decoder path invalid. More... | |
#define | SRD_LOG_NONE 0 |
Output no messages at all. More... | |
#define | SRD_LOG_ERR 1 |
Output error messages. More... | |
#define | SRD_LOG_WARN 2 |
Output warnings. More... | |
#define | SRD_LOG_INFO 3 |
Output informational messages. More... | |
#define | SRD_LOG_DBG 4 |
Output debug messages. More... | |
#define | SRD_LOG_SPEW 5 |
Output very noisy debug messages. More... | |
#define | SRD_API __attribute__((visibility("default"))) |
#define | SRD_PRIV __attribute__((visibility("hidden"))) |
#define | SRD_MAX_NUM_PROBES 64 |
Typedefs | |
typedef void(* | srd_pd_output_callback_t )(struct srd_proto_data *pdata, void *cb_data) |
typedef int(* | srd_log_callback_t )(void *cb_data, int loglevel, const char *format, va_list args) |
Enumerations | |
enum | { SRD_OUTPUT_ANN, SRD_OUTPUT_PROTO, SRD_OUTPUT_BINARY } |
Functions | |
SRD_API int | srd_init (const char *path) |
Initialize libsigrokdecode. More... | |
SRD_API int | srd_exit (void) |
Shutdown libsigrokdecode. More... | |
SRD_API int | srd_inst_option_set (struct srd_decoder_inst *di, GHashTable *options) |
Set one or more options in a decoder instance. More... | |
SRD_API int | srd_inst_probe_set_all (struct srd_decoder_inst *di, GHashTable *probes) |
Set all probes in a decoder instance. More... | |
SRD_API struct srd_decoder_inst * | srd_inst_new (const char *id, GHashTable *options) |
Create a new protocol decoder instance. More... | |
SRD_API int | srd_inst_stack (struct srd_decoder_inst *di_from, struct srd_decoder_inst *di_to) |
Stack a decoder instance on top of another. More... | |
SRD_API struct srd_decoder_inst * | srd_inst_find_by_id (const char *inst_id) |
Find a decoder instance by its instance ID. More... | |
SRD_API int | srd_session_start (int num_probes, int unitsize, uint64_t samplerate) |
Start a decoding session. More... | |
SRD_API int | srd_session_send (uint64_t start_samplenum, const uint8_t *inbuf, uint64_t inbuflen) |
Send a chunk of logic sample data to a running decoder session. More... | |
SRD_API int | srd_pd_output_callback_add (int output_type, srd_pd_output_callback_t cb, void *cb_data) |
Register/add a decoder output callback function. More... | |
SRD_API GSList * | srd_decoder_list (void) |
Returns the list of supported/loaded protocol decoders. More... | |
SRD_API struct srd_decoder * | srd_decoder_get_by_id (const char *id) |
Get the decoder with the specified ID. More... | |
SRD_API int | srd_decoder_load (const char *name) |
Load a protocol decoder module into the embedded Python interpreter. More... | |
SRD_API int | srd_decoder_unload (struct srd_decoder *dec) |
Unload decoder module. More... | |
SRD_API int | srd_decoder_load_all (void) |
Load all installed protocol decoders. More... | |
SRD_API int | srd_decoder_unload_all (void) |
Unload all loaded protocol decoders. More... | |
SRD_API char * | srd_decoder_doc_get (const struct srd_decoder *dec) |
Return a protocol decoder's docstring. More... | |
SRD_API int | srd_log_loglevel_set (int loglevel) |
Set the libsigrokdecode loglevel. More... | |
SRD_API int | srd_log_loglevel_get (void) |
Get the libsigrokdecode loglevel. More... | |
SRD_API int | srd_log_callback_set (srd_log_callback_t cb, void *cb_data) |
Set the libsigrokdecode log callback to the specified function. More... | |
SRD_API int | srd_log_callback_set_default (void) |
Set the libsigrokdecode log callback to the default built-in one. More... | |
SRD_API int | srd_log_logdomain_set (const char *logdomain) |
Set the libsigrokdecode logdomain string. More... | |
SRD_API char * | srd_log_logdomain_get (void) |
Get the currently configured libsigrokdecode logdomain. More... | |
SRD_API int | srd_package_version_major_get (void) |
SRD_API int | srd_package_version_minor_get (void) |
SRD_API int | srd_package_version_micro_get (void) |
SRD_API const char * | srd_package_version_string_get (void) |
SRD_API int | srd_lib_version_current_get (void) |
SRD_API int | srd_lib_version_revision_get (void) |
SRD_API int | srd_lib_version_age_get (void) |
SRD_API const char * | srd_lib_version_string_get (void) |
#define SRD_API __attribute__((visibility("default"))) |
Definition at line 116 of file sigrokdecode.h.
#define SRD_ERR -1 |
Generic/unspecified error.
Definition at line 83 of file sigrokdecode.h.
#define SRD_ERR_ARG -3 |
Function argument error.
Definition at line 85 of file sigrokdecode.h.
Referenced by srd_inst_decode(), srd_inst_option_set(), srd_inst_probe_set_all(), srd_inst_stack(), srd_log_callback_set(), srd_log_logdomain_set(), and srd_log_loglevel_set().
#define SRD_ERR_BUG -4 |
Errors hinting at internal bugs.
Definition at line 86 of file sigrokdecode.h.
#define SRD_ERR_DECODERS_DIR -6 |
Protocol decoder path invalid.
Definition at line 88 of file sigrokdecode.h.
Referenced by srd_decoder_load_all().
#define SRD_ERR_MALLOC -2 |
Malloc/calloc/realloc error.
Definition at line 84 of file sigrokdecode.h.
Referenced by py_str_as_str(), py_strlist_to_char(), srd_decoder_load(), srd_decoder_searchpath_add(), srd_inst_probe_set_all(), and srd_pd_output_callback_add().
#define SRD_ERR_PYTHON -5 |
Python C API error.
Definition at line 87 of file sigrokdecode.h.
Referenced by py_attr_as_str(), py_dictitem_as_str(), py_str_as_str(), py_strlist_to_char(), srd_decoder_load(), srd_inst_decode(), srd_inst_option_set(), srd_inst_start(), and srd_session_start().
#define SRD_LIB_VERSION_AGE 0 |
The libsigrokdecode libtool 'age' version number.
Definition at line 60 of file sigrokdecode.h.
Referenced by srd_lib_version_age_get().
#define SRD_LIB_VERSION_CURRENT 0 |
The libsigrokdecode libtool 'current' version number.
Definition at line 54 of file sigrokdecode.h.
Referenced by srd_lib_version_current_get().
#define SRD_LIB_VERSION_REVISION 1 |
The libsigrokdecode libtool 'revision' version number.
Definition at line 57 of file sigrokdecode.h.
Referenced by srd_lib_version_revision_get().
#define SRD_LIB_VERSION_STRING "0:1:0" |
The libsigrokdecode libtool version ("current:revision:age") as string.
Definition at line 63 of file sigrokdecode.h.
Referenced by srd_lib_version_string_get().
#define SRD_LOG_DBG 4 |
#define SRD_LOG_ERR 1 |
#define SRD_LOG_INFO 3 |
Output informational messages.
Definition at line 94 of file sigrokdecode.h.
Referenced by srd_info().
#define SRD_LOG_NONE 0 |
Output no messages at all.
Definition at line 91 of file sigrokdecode.h.
#define SRD_LOG_SPEW 5 |
Output very noisy debug messages.
Definition at line 96 of file sigrokdecode.h.
Referenced by srd_log_loglevel_set(), and srd_spew().
#define SRD_LOG_WARN 2 |
#define SRD_MAX_NUM_PROBES 64 |
Definition at line 140 of file sigrokdecode.h.
#define SRD_OK 0 |
No error.
Definition at line 82 of file sigrokdecode.h.
Referenced by py_str_as_str(), py_strlist_to_char(), srd_decoder_load(), srd_decoder_load_all(), srd_decoder_searchpath_add(), srd_decoder_unload(), srd_decoder_unload_all(), srd_exit(), srd_init(), srd_inst_decode(), srd_inst_new(), srd_inst_option_set(), srd_inst_probe_set_all(), srd_inst_stack(), srd_inst_start(), srd_log_callback_set(), srd_log_callback_set_default(), srd_log_logdomain_set(), srd_log_loglevel_set(), srd_pd_output_callback_add(), srd_session_send(), and srd_session_start().
#define SRD_PACKAGE_VERSION_MAJOR 0 |
The libsigrokdecode package 'major' version number.
Definition at line 38 of file sigrokdecode.h.
Referenced by srd_package_version_major_get().
#define SRD_PACKAGE_VERSION_MICRO 1 |
The libsigrokdecode package 'micro' version number.
Definition at line 44 of file sigrokdecode.h.
Referenced by srd_package_version_micro_get().
#define SRD_PACKAGE_VERSION_MINOR 1 |
The libsigrokdecode package 'minor' version number.
Definition at line 41 of file sigrokdecode.h.
Referenced by srd_package_version_minor_get().
#define SRD_PACKAGE_VERSION_STRING "0.1.1" |
The libsigrokdecode package version ("major.minor.micro") as string.
Definition at line 47 of file sigrokdecode.h.
Referenced by srd_package_version_string_get().
#define SRD_PRIV __attribute__((visibility("hidden"))) |
Definition at line 123 of file sigrokdecode.h.
typedef int(* srd_log_callback_t)(void *cb_data, int loglevel, const char *format, va_list args) |
Definition at line 281 of file sigrokdecode.h.
typedef void(* srd_pd_output_callback_t)(struct srd_proto_data *pdata, void *cb_data) |
Definition at line 224 of file sigrokdecode.h.
anonymous enum |
Enumerator | |
---|---|
SRD_OUTPUT_ANN | |
SRD_OUTPUT_PROTO | |
SRD_OUTPUT_BINARY |
Definition at line 134 of file sigrokdecode.h.
SRD_API char* srd_decoder_doc_get | ( | const struct srd_decoder * | dec | ) |
Return a protocol decoder's docstring.
dec | The loaded protocol decoder. |
Definition at line 292 of file decoder.c.
References srd_decoder::py_mod, py_str_as_str(), and srd_exception_catch().
|
read |
Get the decoder with the specified ID.
id | The ID string of the decoder to return. |
Definition at line 51 of file decoder.c.
References srd_decoder::id, and srd_decoder_list().
Referenced by srd_inst_new().
SRD_API GSList* srd_decoder_list | ( | void | ) |
Returns the list of supported/loaded protocol decoders.
This is a GSList containing the names of the decoders as strings.
Definition at line 39 of file decoder.c.
References pd_list.
Referenced by srd_decoder_get_by_id(), and srd_decoder_unload_all().
SRD_API int srd_decoder_load | ( | const char * | module_name | ) |
Load a protocol decoder module into the embedded Python interpreter.
name | The module name to be loaded. |
Definition at line 131 of file decoder.c.
References srd_decoder::annotations, srd_decoder::desc, srd_decoder::id, srd_decoder::license, srd_decoder::longname, mod_sigrokdecode, srd_decoder::name, srd_decoder::opt_probes, pd_list, srd_decoder::probes, py_attr_as_str(), srd_decoder::py_dec, srd_decoder::py_mod, py_strlist_to_char(), srd_dbg(), srd_err(), SRD_ERR_MALLOC, SRD_ERR_PYTHON, srd_exception_catch(), and SRD_OK.
Referenced by srd_decoder_load_all().
SRD_API int srd_decoder_load_all | ( | void | ) |
Load all installed protocol decoders.
Definition at line 373 of file decoder.c.
References srd_decoder_load(), srd_err(), SRD_ERR_DECODERS_DIR, and SRD_OK.
SRD_API int srd_decoder_unload | ( | struct srd_decoder * | dec | ) |
Unload decoder module.
dec | The struct srd_decoder to be unloaded. |
Definition at line 338 of file decoder.c.
References srd_decoder::desc, srd_decoder::id, srd_decoder::license, srd_decoder::longname, srd_decoder::name, srd_decoder::opt_probes, srd_decoder::probes, srd_decoder::py_dec, srd_decoder::py_mod, srd_dbg(), srd_inst_free_all(), and SRD_OK.
Referenced by srd_decoder_unload_all().
SRD_API int srd_decoder_unload_all | ( | void | ) |
Unload all loaded protocol decoders.
Definition at line 398 of file decoder.c.
References srd_decoder_list(), srd_decoder_unload(), and SRD_OK.
Referenced by srd_exit().
SRD_API int srd_exit | ( | void | ) |
Shutdown libsigrokdecode.
This frees all the memory allocated for protocol decoders and shuts down the Python interpreter.
This function should only be called if there was a (successful!) invocation of srd_init() before. Calling this function multiple times in a row, without any successful srd_init() calls in between, is not allowed.
Definition at line 119 of file controller.c.
References pd_list, srd_dbg(), srd_decoder_unload_all(), and SRD_OK.
SRD_API int srd_init | ( | const char * | path | ) |
Initialize libsigrokdecode.
This initializes the Python interpreter, and creates and initializes a "sigrokdecode" Python module.
Then, it searches for sigrok protocol decoder files (*.py) in the "decoders" subdirectory of the the sigrok installation directory. All decoders that are found are loaded into memory and added to an internal list of decoders, which can be queried via srd_decoders_list().
The caller is responsible for calling the clean-up function srd_exit(), which will properly shut down libsigrokdecode and free its allocated memory.
Multiple calls to srd_init(), without calling srd_exit() in between, are not allowed.
path | Path to an extra directory containing protocol decoders which will be added to the Python sys.path, or NULL. |
Definition at line 69 of file controller.c.
References PyInit_sigrokdecode(), srd_dbg(), srd_decoder_searchpath_add(), and SRD_OK.
|
read |
Find a decoder instance by its instance ID.
Only the bottom level of instances are searched – instances already stacked on top of another one will not be found.
inst_id | The instance ID to be found. |
Definition at line 513 of file controller.c.
References srd_decoder_inst::inst_id.
|
read |
Create a new protocol decoder instance.
id | Decoder 'id' field. |
options | GHashtable of options which override the defaults set in the decoder class. |
Definition at line 412 of file controller.c.
References srd_decoder_inst::dec_num_probes, srd_decoder_inst::dec_probemap, srd_decoder_inst::decoder, srd_decoder_inst::inst_id, srd_decoder::opt_probes, srd_decoder::probes, srd_decoder::py_dec, srd_decoder_inst::py_inst, srd_dbg(), srd_decoder_get_by_id(), srd_err(), srd_exception_catch(), srd_inst_option_set(), and SRD_OK.
SRD_API int srd_inst_option_set | ( | struct srd_decoder_inst * | di, |
GHashTable * | options | ||
) |
Set one or more options in a decoder instance.
Handled options are removed from the hash.
di | Decoder instance. |
options | A GHashTable of options to set. |
Definition at line 211 of file controller.c.
References srd_decoder_inst::decoder, srd_decoder::py_dec, srd_decoder_inst::py_inst, py_str_as_str(), srd_err(), SRD_ERR_ARG, SRD_ERR_PYTHON, srd_exception_catch(), and SRD_OK.
Referenced by srd_inst_new().
SRD_API int srd_inst_probe_set_all | ( | struct srd_decoder_inst * | di, |
GHashTable * | new_probes | ||
) |
Set all probes in a decoder instance.
This function sets all probes for the specified decoder instance, i.e., it overwrites any probes that were already defined (if any).
di | Decoder instance. |
probes | A GHashTable of probes to set. Key is probe name, value is the probe number. Samples passed to this instance will be arranged in this order. |
Definition at line 339 of file controller.c.
References srd_decoder_inst::dec_num_probes, srd_decoder_inst::dec_probemap, srd_decoder_inst::decoder, srd_decoder_inst::inst_id, srd_decoder::name, srd_decoder::opt_probes, srd_probe::order, srd_decoder::probes, srd_dbg(), srd_err(), SRD_ERR_ARG, SRD_ERR_MALLOC, and SRD_OK.
SRD_API int srd_inst_stack | ( | struct srd_decoder_inst * | di_from, |
struct srd_decoder_inst * | di_to | ||
) |
Stack a decoder instance on top of another.
di_from | The instance to move. |
di_to | The instance on top of which di_from will be stacked. |
Definition at line 484 of file controller.c.
References srd_decoder_inst::next_di, srd_err(), SRD_ERR_ARG, and SRD_OK.
SRD_API int srd_lib_version_age_get | ( | void | ) |
Definition at line 53 of file version.c.
References SRD_LIB_VERSION_AGE.
SRD_API int srd_lib_version_current_get | ( | void | ) |
Definition at line 43 of file version.c.
References SRD_LIB_VERSION_CURRENT.
SRD_API int srd_lib_version_revision_get | ( | void | ) |
Definition at line 48 of file version.c.
References SRD_LIB_VERSION_REVISION.
SRD_API const char* srd_lib_version_string_get | ( | void | ) |
Definition at line 58 of file version.c.
References SRD_LIB_VERSION_STRING.
SRD_API int srd_log_callback_set | ( | srd_log_callback_t | cb, |
void * | cb_data | ||
) |
Set the libsigrokdecode log callback to the specified function.
cb | Function pointer to the log callback function to use. Must not be NULL. |
cb_data | Pointer to private data to be passed on. This can be used by the caller to pass arbitrary data to the log functions. This pointer is only stored or passed on by libsigrokdecode, and is never used or interpreted in any way. The pointer is allowed to be NULL if the caller doesn't need/want to pass any data. |
Definition at line 142 of file log.c.
References srd_err(), SRD_ERR_ARG, and SRD_OK.
SRD_API int srd_log_callback_set_default | ( | void | ) |
SRD_API char* srd_log_logdomain_get | ( | void | ) |
SRD_API int srd_log_logdomain_set | ( | const char * | logdomain | ) |
Set the libsigrokdecode logdomain string.
logdomain | The string to use as logdomain for libsigrokdecode log messages from now on. Must not be NULL. The maximum length of the string is 30 characters (this does not include the trailing NUL-byte). Longer strings are silently truncated. In order to not use a logdomain, pass an empty string. The function makes its own copy of the input string, i.e. the caller does not need to keep it around. |
Definition at line 101 of file log.c.
References LOGDOMAIN_MAXLEN, srd_dbg(), srd_err(), SRD_ERR_ARG, and SRD_OK.
SRD_API int srd_log_loglevel_get | ( | void | ) |
SRD_API int srd_log_loglevel_set | ( | int | loglevel | ) |
Set the libsigrokdecode loglevel.
This influences the amount of log messages (debug messages, error messages, and so on) libsigrokdecode will output. Using SRD_LOG_NONE disables all messages.
Note that this function itself will also output log messages. After the loglevel has changed, it will output a debug message with SRD_LOG_DBG for example. Whether this message is shown depends on the (new) loglevel.
loglevel | The loglevel to set (SRD_LOG_NONE, SRD_LOG_ERR, SRD_LOG_WARN, SRD_LOG_INFO, SRD_LOG_DBG, or SRD_LOG_SPEW). |
Definition at line 63 of file log.c.
References srd_dbg(), srd_err(), SRD_ERR_ARG, SRD_LOG_SPEW, and SRD_OK.
SRD_API int srd_package_version_major_get | ( | void | ) |
Definition at line 23 of file version.c.
References SRD_PACKAGE_VERSION_MAJOR.
SRD_API int srd_package_version_micro_get | ( | void | ) |
Definition at line 33 of file version.c.
References SRD_PACKAGE_VERSION_MICRO.
SRD_API int srd_package_version_minor_get | ( | void | ) |
Definition at line 28 of file version.c.
References SRD_PACKAGE_VERSION_MINOR.
SRD_API const char* srd_package_version_string_get | ( | void | ) |
Definition at line 38 of file version.c.
References SRD_PACKAGE_VERSION_STRING.
SRD_API int srd_pd_output_callback_add | ( | int | output_type, |
srd_pd_output_callback_t | cb, | ||
void * | cb_data | ||
) |
Register/add a decoder output callback function.
The function will be called when a protocol decoder sends output back to the PD controller (except for Python objects, which only go up the stack).
output_type | The output type this callback will receive. Only one callback per output type can be registered. |
cb | The function to call. Must not be NULL. |
cb_data | Private data for the callback function. Can be NULL. |
Definition at line 787 of file controller.c.
References srd_pd_callback::cb, srd_pd_callback::cb_data, srd_pd_callback::output_type, srd_dbg(), srd_err(), SRD_ERR_MALLOC, and SRD_OK.
SRD_API int srd_session_send | ( | uint64_t | start_samplenum, |
const uint8_t * | inbuf, | ||
uint64_t | inbuflen | ||
) |
Send a chunk of logic sample data to a running decoder session.
start_samplenum | The sample number of the first sample in this chunk. |
inbuf | Pointer to sample data. |
inbuf | Length in bytes of the buffer. |
Definition at line 756 of file controller.c.
References srd_dbg(), srd_inst_decode(), and SRD_OK.
SRD_API int srd_session_start | ( | int | num_probes, |
int | unitsize, | ||
uint64_t | samplerate | ||
) |
Start a decoding session.
Decoders, instances and stack must have been prepared beforehand.
num_probes | The number of probes which the incoming feed will contain. |
unitsize | The number of bytes per sample in the incoming feed. |
samplerate | The samplerate of the incoming feed. |
Definition at line 713 of file controller.c.
References srd_decoder_inst::data_num_probes, srd_decoder_inst::data_samplerate, srd_decoder_inst::data_unitsize, srd_dbg(), srd_err(), SRD_ERR_PYTHON, srd_inst_start(), and SRD_OK.