datarecord.h File Reference

Implementation of Datarecord concept defined by ASTERIX. More...

#include "category.h"
#include "uap.h"
#include "fspec.h"
#include "dataitem.h"
#include "match.h"
#include "type.h"
Include dependency graph for datarecord.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_datarecord_t
 Datarecord. More...
 
struct  ast_datarecord_ex_t
 Extracted datarecord. More...
 
struct  ast_datarecord_modifier_t
 Datarecord modifier. More...
 

Macros

#define AST_MAX_DATAITEMS   32
 
#define AST_DATARECORD_HEX_HTML_PREFERED_CHARS   (AST_MAX_DATAITEMS * AST_MAX_DATAITEM_SIZE * 12 + 128)
 Prefered number of chars of datarecord hexadecimal HTML snippet. More...
 
#define AST_DATARECORD_DETAIL_HTML_PREFERED_CHARS   20480
 Prefered number of chars of data item detail description HTML snippet. More...
 
#define AST_KEYSTR_PREFERRED_CHARS   25
 Prefered number of chars of keyword string. More...
 

Functions

ast_datarecord_t ast_datarecord_decode (const unsigned char *buffer, const size_t bufsize, const ast_category_t category, const ast_uap_t uap)
 Datarecord decode function. More...
 
ast_datarecord_t ast_datarecord_encode (unsigned char *const buffer, const size_t bufsize, const ast_datarecord_ex_t xdr)
 Datarecord encode function. More...
 
ast_datarecord_t ast_datarecord_copy (unsigned char *buffer, const size_t bufsize, const ast_datarecord_t src)
 Datarecord copy function. More...
 
ast_datarecord_t ast_datarecord_modify (unsigned char *buffer, const size_t bufsize, const ast_datarecord_t src, const ast_datarecord_modifier_t mod)
 Datarecord modiy function. More...
 
void ast_datarecord_get_hex_html (char *html, const size_t html_size, const ast_datarecord_t dr)
 Function to get a html snippet of the raw datarecord data in hexadecimal format. More...
 
void ast_datarecord_get_detail_html (char *detail, const size_t detail_size, const ast_datarecord_t dr)
 Function to get a html snippet of detailed description of dataitem. More...
 
bool ast_datarecord_contain_keyword (const ast_datarecord_t dr, const ast_keyword_t keyword)
 Check if datarecord contains specified keywork type. More...
 
bool ast_datarecord_match_keyword (const ast_datarecord_t dr, const ast_keyword_t keyword, const char *challenge, bool case_sensitive)
 Match a specified keyword in the datarecord. More...
 
bool ast_datarecord_get_keyword (char *keystr, const size_t keystr_size, const ast_datarecord_t dr, const ast_keyword_t keyword)
 Get keyword summary string from specified datarecord. More...
 
ast_sacsic_t ast_datarecord_get_sacsic (const ast_datarecord_t dr)
 Get SAC/SIC from specified datarecord. More...
 
ast_timeofday_t ast_datarecord_get_timeofday (const ast_datarecord_t dr)
 Get time of day from specified datarecord. More...
 
ast_msgtype_t ast_datarecord_get_msgtype (const ast_datarecord_t dr)
 Get message type from specified datarecord. More...
 
ast_tracknum_t ast_datarecord_get_tracknum (const ast_datarecord_t dr)
 Get track number from specified datarecord. More...
 
ast_squawk_t ast_datarecord_get_squawk (const ast_datarecord_t dr)
 Get Mode-3/A code from specified datarecord. More...
 
ast_callsign_t ast_datarecord_get_callsign (const ast_datarecord_t dr)
 Get callsign from specified datarecord. More...
 
ast_icaoaddr_t ast_datarecord_get_icaoaddr (const ast_datarecord_t dr)
 Get ICAO 24-bit address from specified datarecord. More...
 
ast_coordinate_t ast_datarecord_get_coordinate (const ast_datarecord_t dr)
 Get WGS-84 coordinate from specified datarecord. More...
 
ast_altitude_t ast_datarecord_get_flightlevel (const ast_datarecord_t dr)
 Get flight level from specified datarecord. More...
 
ast_polar_coordinate_t ast_datarecord_get_polarcoord (const ast_datarecord_t dr)
 Get polar coordinate from specified datarecord. More...
 
ast_heading_t ast_datarecord_get_heading (const ast_datarecord_t dr)
 Get heading from specified datarecord. More...
 
ast_speed_t ast_datarecord_get_speed (const ast_datarecord_t dr)
 Get speed from specified datarecord. More...
 

Detailed Description

Implementation of Datarecord concept defined by ASTERIX.

Macro Definition Documentation

◆ AST_DATARECORD_DETAIL_HTML_PREFERED_CHARS

#define AST_DATARECORD_DETAIL_HTML_PREFERED_CHARS   20480

Prefered number of chars of data item detail description HTML snippet.

◆ AST_DATARECORD_HEX_HTML_PREFERED_CHARS

#define AST_DATARECORD_HEX_HTML_PREFERED_CHARS   (AST_MAX_DATAITEMS * AST_MAX_DATAITEM_SIZE * 12 + 128)

Prefered number of chars of datarecord hexadecimal HTML snippet.

◆ AST_KEYSTR_PREFERRED_CHARS

#define AST_KEYSTR_PREFERRED_CHARS   25

Prefered number of chars of keyword string.

Examples
example.c.

◆ AST_MAX_DATAITEMS

#define AST_MAX_DATAITEMS   32

Function Documentation

◆ ast_datarecord_contain_keyword()

bool ast_datarecord_contain_keyword ( const ast_datarecord_t  dr,
const ast_keyword_t  keyword 
)

Check if datarecord contains specified keywork type.

Parameters
drdatarecord to check
keywordkeyword type
Returns
true if contain, false if not contain

◆ ast_datarecord_copy()

ast_datarecord_t ast_datarecord_copy ( unsigned char *  buffer,
const size_t  bufsize,
const ast_datarecord_t  src 
)

Datarecord copy function.

Parameters
bufferBuffer to write destination datarecord data
bufsizeBuffer size
srcOriginal data record, must be valid

This function will copy original data record, to specified buffer. If all fields in data record has been successfully copied, the returned datarecord will be marked as "valid". If any error occurs, the returned datarecord will be marked as "invalid".

◆ ast_datarecord_decode()

ast_datarecord_t ast_datarecord_decode ( const unsigned char *  buffer,
const size_t  bufsize,
const ast_category_t  category,
const ast_uap_t  uap 
)

Datarecord decode function.

Parameters
bufferBuffer to read datarecord data
bufsizeBuffer size
categoryData category
uapUser application profile (UAP) used to decode data

This function will read and check data against specified uap, and return decoded datarecord. If data can be successfully decoded, the returned datarecord will be marked as "valid". If any error occurs, the returned datarecord will be marked as "invalid".

◆ ast_datarecord_encode()

ast_datarecord_t ast_datarecord_encode ( unsigned char *const  buffer,
const size_t  bufsize,
const ast_datarecord_ex_t  xdr 
)

Datarecord encode function.

Parameters
bufferBuffer to write encoded datarecord data
bufsizeBuffer size
xdrExtracted datarecord container
Returns
Encorded datarecord

This function will check dataitems contained in xdr, encode them and write encoded data to buffer. If all data items are successfully encoded, the returned datarecord will be marked as "valid". If any error occurs, the returned datarecord will be marked as "invalid".

◆ ast_datarecord_get_callsign()

ast_callsign_t ast_datarecord_get_callsign ( const ast_datarecord_t  dr)

Get callsign from specified datarecord.

Parameters
drdatarecord to get
Returns
the callsign, if doesn't exist, it will be set to invalid

◆ ast_datarecord_get_coordinate()

ast_coordinate_t ast_datarecord_get_coordinate ( const ast_datarecord_t  dr)

Get WGS-84 coordinate from specified datarecord.

Parameters
drdatarecord to get
Returns
coord WGS-84 coordinate, if coordinate doesn't exist, the cordinate will be set to invalid

◆ ast_datarecord_get_detail_html()

void ast_datarecord_get_detail_html ( char *  detail,
const size_t  detail_size,
const ast_datarecord_t  dr 
)

Function to get a html snippet of detailed description of dataitem.

Parameters
detailBuffer to save the html snippet
detail_sizeBuffer size
drDatarecord

The returned html fragment contains only basic elements used in html body, such as <br/> <h> <table>....

This function will return only semantics markups, some elements will cantaion class name, and it's recomanded the libary user to use CSS to format the html style.

◆ ast_datarecord_get_flightlevel()

ast_altitude_t ast_datarecord_get_flightlevel ( const ast_datarecord_t  dr)

Get flight level from specified datarecord.

Parameters
drdatarecord to get
Returns
level, if level doesn't exist, the level will be set to invalid

◆ ast_datarecord_get_heading()

ast_heading_t ast_datarecord_get_heading ( const ast_datarecord_t  dr)

Get heading from specified datarecord.

Parameters
drdatarecord to get
Returns
heading, if both magnetic and geographic headings don't exist, the heading will be set to invalid

◆ ast_datarecord_get_hex_html()

void ast_datarecord_get_hex_html ( char *  html,
const size_t  html_size,
const ast_datarecord_t  dr 
)

Function to get a html snippet of the raw datarecord data in hexadecimal format.

The returned text will be an html table with data in the cells.

◆ ast_datarecord_get_icaoaddr()

ast_icaoaddr_t ast_datarecord_get_icaoaddr ( const ast_datarecord_t  dr)

Get ICAO 24-bit address from specified datarecord.

Parameters
drdatarecord to get
Returns
the ICAO 24-bit address, if doesn't exist, it will be set to invalid

◆ ast_datarecord_get_keyword()

bool ast_datarecord_get_keyword ( char *  keystr,
const size_t  keystr_size,
const ast_datarecord_t  dr,
const ast_keyword_t  keyword 
)

Get keyword summary string from specified datarecord.

Parameters
keystrthe summary string of specified keyword value
keystr_sizethe buffer size of keystr
drdatarecord to get
keywordkeyword type
Returns
true if keyword is found, false if keyword doesn't exist.

For different keyword, the summary string will include:

  • AST_KEYWORD_TRACKNUM, track number string. E.g. "912"
  • AST_KEYWORD_CALLSIGN, original non-trimed callsign string, in ASCII encoding. E.g. "CCA931 "
Examples
example.c.

◆ ast_datarecord_get_msgtype()

ast_msgtype_t ast_datarecord_get_msgtype ( const ast_datarecord_t  dr)

Get message type from specified datarecord.

Parameters
drdatarecord to get
Returns
the message type, if message type doesn't apply, it will be set to invalid

◆ ast_datarecord_get_polarcoord()

ast_polar_coordinate_t ast_datarecord_get_polarcoord ( const ast_datarecord_t  dr)

Get polar coordinate from specified datarecord.

Parameters
drdatarecord to get
Returns
Polar coordinate, if coordinate doesn't exist, the coordinate will be set to invalid

◆ ast_datarecord_get_sacsic()

ast_sacsic_t ast_datarecord_get_sacsic ( const ast_datarecord_t  dr)

Get SAC/SIC from specified datarecord.

Parameters
drdatarecord to get
Returns
the SAC/SIC, if SAC/SIC doesn't exist (only when datarecord is cruppted), it will be set to invalid

◆ ast_datarecord_get_speed()

ast_speed_t ast_datarecord_get_speed ( const ast_datarecord_t  dr)

Get speed from specified datarecord.

Parameters
drdatarecord to get
Returns
speed, if speed doesn't exist, the speed will be set to invalid

◆ ast_datarecord_get_squawk()

ast_squawk_t ast_datarecord_get_squawk ( const ast_datarecord_t  dr)

Get Mode-3/A code from specified datarecord.

Parameters
drdatarecord to get
Returns
the squawk, if doesn't exist, it will be set to invalid

◆ ast_datarecord_get_timeofday()

ast_timeofday_t ast_datarecord_get_timeofday ( const ast_datarecord_t  dr)

Get time of day from specified datarecord.

Parameters
drdatarecord to get
Returns
the time of day, if time doesn't exist, it will be set to invalid

◆ ast_datarecord_get_tracknum()

ast_tracknum_t ast_datarecord_get_tracknum ( const ast_datarecord_t  dr)

Get track number from specified datarecord.

Parameters
drdatarecord to get
Returns
the track number, if track number doesn't exist, it will be set to invalid

◆ ast_datarecord_match_keyword()

bool ast_datarecord_match_keyword ( const ast_datarecord_t  dr,
const ast_keyword_t  keyword,
const char *  challenge,
bool  case_sensitive 
)

Match a specified keyword in the datarecord.

Parameters
drdatarecord to match
keywordtype of keyword
challengec string of keyword
case_sensitivecase sensitive
Returns
true if successfully match; false if not

◆ ast_datarecord_modify()

ast_datarecord_t ast_datarecord_modify ( unsigned char *  buffer,
const size_t  bufsize,
const ast_datarecord_t  src,
const ast_datarecord_modifier_t  mod 
)

Datarecord modiy function.

Parameters
bufferBuffer to write modified datarecord data
bufsizeBuffer size
srcOriginal data record, must be valid
modData item modifier

This function will modify the original data record, according to data item modifier, and write modified data into buffer. For data items not specified by data modifier, the original one will be copied as is. If all data items can be successfully modifed, the returned datarecord will be marked as "valid". If any error occurs, the returned datarecord will be marked as "invalid".