dataitem.h
Go to the documentation of this file.
1 /*
2  * libasterix
3  * Copyright [2013-2020] SinoATC <http://www.sinoatc.com>.
4  * All Rights Reserved.
5  *
6  * NOTICE: All information contained herein is, and remains
7  * the property of SinoATC and its suppliers, if any.
8  * The intellectual and technical concepts contained herein
9  * are proprietary to Aerosys Corporation and its suppliers and may be
10  * covered by U.S. and Foreign Patents, patents in process,
11  * and are protected by trade secret or copyright law.
12  * Dissemination of this information or reproduction of this material
13  * is strictly forbidden unless prior written permission is obtained
14  * from SinoATC.
15  */
16 
23 #ifndef LIBASTERIX_DATAITEM_H
24 #define LIBASTERIX_DATAITEM_H
25 
26 #include <stddef.h>
27 #include <stdbool.h>
28 #include "platform.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
47 #define AST_MAP_DATAITEM_TYPE_EX(category_name, category_value, dataitem_name, dataitem_value) \
48  I ## category_name ## _ ## dataitem_name = category_value ## dataitem_value,
49 
53 #define SPF 999 //Special purpose field (SPF) maps to 999
54 #define REF 998 //Reserved extension filed (REF) maps to 998
55 //#define A01 901 //Dataitem I021/130 prior version 0.23 - Obsolete
56 #define A02 902 //Dataitem I021/130 version 0.24 ~ 0.26
57 #define A03 903 //Dataitem I021/040 prior version 0.26
58 #define A04 904 //Dataitem I021/131 prior version 0.26
59 #define A05 905 //Dataitem I021/090 prior version 0.26
60 #define A06 906 //Dataitem I021/210 prior version 0.26
61 #define A07 907 //Dataitem I021/271 version 1.0 ~ 2.1
62 #define A08 908 //Dateitem I021/200 prior version 0.26
63 
67 typedef enum _ast_dataitem_type_t
68 {
69  INULLITEM = 0,
70 
71  //For CAT001~CAT009
72 #define AST_MAP_DATAITEM_TYPE(category, dataitem) AST_MAP_DATAITEM_TYPE_EX(00 ## category, category, dataitem, dataitem)
73 
74  //Category 001
96 
97  //Category 002
110 
111  //Category 004
130 
131  //Category 008
144 
145  //For CAT010~CAT099
146 #undef AST_MAP_DATAITEM_TYPE
147 #define AST_MAP_DATAITEM_TYPE(category, dataitem) AST_MAP_DATAITEM_TYPE_EX(0 ## category, category, dataitem, dataitem)
148 
149  //Category 010
177 
178  //Category 019
189 
190  //Category 020
219 
220  //Category 021
275 
276  //Category 023
286 
287  //Category 033
305 
306  //Category 034
321 
322  //Category 048
351 
352  //Category 062
382 
383  //Category 065
391 
392  //For CAT100~CAT256
393 #undef AST_MAP_DATAITEM_TYPE
394 #define AST_MAP_DATAITEM_TYPE(category, dataitem) AST_MAP_DATAITEM_TYPE_EX(category, category, dataitem, dataitem)
395 
396  //Category 240
411 
413 
420 
422 typedef struct _ast_dataitem_t
423 {
424  const unsigned char* data;
425  size_t size;
426 
428 
429  bool valid;
431 
433 typedef struct _ast_dataitem_ex_t
434 {
436 
437  void* data;
439 
441 AST_API ast_dataitem_t ast_dataitem_decode(const unsigned char* buffer, const size_t bufsize, const ast_dataitem_type_t type);
442 
444 AST_API ast_dataitem_t ast_dataitem_encode(unsigned char* const buffer, const size_t bufsize, const ast_dataitem_ex_t xdi);
445 
447 AST_API ast_dataitem_t ast_dataitem_copy(unsigned char* const buffer, const size_t bufsize, const ast_dataitem_t src);
448 
450 #define AST_MAX_DATAITEM_SIZE 1024
451 
453 AST_API size_t ast_dataitem_get_size(const unsigned char* buffer, const size_t bufsize, const ast_dataitem_type_t type);
454 
456 AST_API size_t ast_dataitem_get_size_fixed(const unsigned char* buffer, const size_t bufsize, const size_t fix_size);
457 AST_API size_t ast_dataitem_get_size_fixed_1_byte(const unsigned char* buffer, const size_t bufsize);
458 AST_API size_t ast_dataitem_get_size_fixed_2_byte(const unsigned char* buffer, const size_t bufsize);
459 AST_API size_t ast_dataitem_get_size_fixed_3_byte(const unsigned char* buffer, const size_t bufsize);
460 AST_API size_t ast_dataitem_get_size_fixed_4_byte(const unsigned char* buffer, const size_t bufsize);
461 AST_API size_t ast_dataitem_get_size_fixed_5_byte(const unsigned char* buffer, const size_t bufsize);
462 AST_API size_t ast_dataitem_get_size_fixed_6_byte(const unsigned char* buffer, const size_t bufsize);
463 AST_API size_t ast_dataitem_get_size_fixed_7_byte(const unsigned char* buffer, const size_t bufsize);
464 AST_API size_t ast_dataitem_get_size_fixed_8_byte(const unsigned char* buffer, const size_t bufsize);
465 AST_API size_t ast_dataitem_get_size_fixed_9_byte(const unsigned char* buffer, const size_t bufsize);
466 AST_API size_t ast_dataitem_get_size_fixed_12_byte(const unsigned char* buffer, const size_t bufsize);
467 
469 AST_API size_t ast_dataitem_get_size_variable(const unsigned char* buffer, const size_t bufsize, const size_t max_size);
470 AST_API size_t ast_dataitem_get_size_var_1_byte(const unsigned char* buffer, const size_t bufsize);
471 AST_API size_t ast_dataitem_get_size_var_2_byte(const unsigned char* buffer, const size_t bufsize);
472 AST_API size_t ast_dataitem_get_size_var_3_byte(const unsigned char* buffer, const size_t bufsize);
473 AST_API size_t ast_dataitem_get_size_var_4_byte(const unsigned char* buffer, const size_t bufsize);
474 AST_API size_t ast_dataitem_get_size_var_5_byte(const unsigned char* buffer, const size_t bufsize);
475 AST_API size_t ast_dataitem_get_size_var_6_byte(const unsigned char* buffer, const size_t bufsize);
476 AST_API size_t ast_dataitem_get_size_var_23_byte(const unsigned char* buffer, const size_t bufsize);
477 AST_API size_t ast_dataitem_get_size_var_unlimited(const unsigned char* buffer, const size_t bufsize);
478 
480 AST_API size_t ast_dataitem_get_size_repeat(const unsigned char* buffer, const size_t bufsize, const size_t unit_size);
481 AST_API size_t ast_dataitem_get_size_rep_1_byte(const unsigned char* buffer, const size_t bufsize);
482 AST_API size_t ast_dataitem_get_size_rep_2_byte(const unsigned char* buffer, const size_t bufsize);
483 AST_API size_t ast_dataitem_get_size_rep_3_byte(const unsigned char* buffer, const size_t bufsize);
484 AST_API size_t ast_dataitem_get_size_rep_4_byte(const unsigned char* buffer, const size_t bufsize);
485 AST_API size_t ast_dataitem_get_size_rep_8_byte(const unsigned char* buffer, const size_t bufsize);
486 AST_API size_t ast_dataitem_get_size_rep_15_byte(const unsigned char* buffer, const size_t bufsize);
487 AST_API size_t ast_dataitem_get_size_rep_64_byte(const unsigned char* buffer, const size_t bufsize);
488 AST_API size_t ast_dataitem_get_size_rep_256_byte(const unsigned char* buffer, const size_t bufsize);
489 
490 
495 AST_API const char* ast_dataitem_get_name(const ast_dataitem_type_t type);
496 
498 #define AST_DATAITEM_SUMMARY_PREFERED_CHARS 256
499 
509 AST_API void ast_dataitem_get_summary(char* summary, const size_t summary_size, const ast_dataitem_t di);
510 
512 #define AST_DATAITEM_HEX_STR_PREFERED_CHARS (AST_MAX_DATAITEM_SIZE * 3)
513 
520 AST_API void ast_dataitem_get_hex_str(char* string, const size_t string_size, ast_dataitem_t di);
521 
523 #define AST_DATAITEM_HEX_HTML_PREFERED_CHARS (AST_MAX_DATAITEM_SIZE * 12 + 128)
524 
530 AST_API void ast_dataitem_get_hex_html(char* html, const size_t html_size, const ast_dataitem_t di);
531 
533 #define AST_DATAITEM_BIN_STR_PREFERED_CHARS (AST_MAX_DATAITEM_SIZE * 9)
534 
541 AST_API void ast_dataitem_get_bin_str(char* string, const size_t string_size, const ast_dataitem_t di);
542 
544 #define AST_DATAITEM_BIN_HTML_PREFERED_CHARS (AST_MAX_DATAITEM_SIZE * 128 + 64)
545 
551 AST_API void ast_dataitem_get_bin_html(char* html, const size_t html_size, const ast_dataitem_t di);
552 
554 #define AST_DATAITEM_DETAIL_HTML_PREFERED_CHARS (AST_DATAITEM_HEX_HTML_PREFERED_CHARS + AST_DATAITEM_BIN_HTML_PREFERED_CHARS + 20480)
555 
569 AST_API void ast_dataitem_get_detail_html(char* detail, const size_t detail_size, const ast_dataitem_t di);
570 
577 AST_API void ast_dataitem_get_detail_html_dummy(char* detail, const size_t detail_size, const ast_dataitem_t di);
578 
581 #ifdef __cplusplus
582  }
583 #endif // extern "C"
584 
585 #endif //LIBASTERIX_DATAITEM_H
586 
587 // vim:set ft=c.doxygen sw=2 sts=2 fenc=utf8:
size_t ast_dataitem_get_size_fixed_3_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_fixed_1_byte(const unsigned char *buffer, const size_t bufsize)
void ast_dataitem_get_summary(char *summary, const size_t summary_size, const ast_dataitem_t di)
Function to get summary of one dataitem.
Extracted dataitem.
Definition: dataitem.h:433
size_t ast_dataitem_get_size_var_5_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_fixed_8_byte(const unsigned char *buffer, const size_t bufsize)
#define A06
Definition: dataitem.h:60
#define AST_MAP_DATAITEM_TYPE_EX(category_name, category_value, dataitem_name, dataitem_value)
Macro used to map dataitem type.
Definition: dataitem.h:47
size_t ast_dataitem_get_size_rep_3_byte(const unsigned char *buffer, const size_t bufsize)
#define AST_API
Definition: platform.h:63
size_t ast_dataitem_get_size(const unsigned char *buffer, const size_t bufsize, const ast_dataitem_type_t type)
Function to get size of one dataitem.
size_t ast_dataitem_get_size_rep_256_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_rep_4_byte(const unsigned char *buffer, const size_t bufsize)
#define AST_MAP_DATAITEM_TYPE(category, dataitem)
Definition: dataitem.h:394
ast_dataitem_t ast_dataitem_copy(unsigned char *const buffer, const size_t bufsize, const ast_dataitem_t src)
Copy data item to binary buffer.
void ast_dataitem_get_hex_str(char *string, const size_t string_size, ast_dataitem_t di)
Function to get raw dataitem data in hexadecimal format.
size_t ast_dataitem_get_size_var_6_byte(const unsigned char *buffer, const size_t bufsize)
This file includes platform specific definitions.
size_t ast_dataitem_get_size_var_1_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_var_23_byte(const unsigned char *buffer, const size_t bufsize)
Null (Empty) dataitem.
Definition: dataitem.h:69
#define A04
Definition: dataitem.h:58
size_t ast_dataitem_get_size_fixed_7_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_rep_1_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_var_3_byte(const unsigned char *buffer, const size_t bufsize)
ast_dataitem_type_t type
Type of data item.
Definition: dataitem.h:435
#define A03
Definition: dataitem.h:57
size_t ast_dataitem_get_size_var_4_byte(const unsigned char *buffer, const size_t bufsize)
#define SPF
Definition: dataitem.h:53
size_t ast_dataitem_get_size_fixed_9_byte(const unsigned char *buffer, const size_t bufsize)
void * data
Pointer to extracted data of individual dataitem.
Definition: dataitem.h:437
const char * ast_dataitem_type_to_str(const ast_dataitem_type_t type)
Convert from ast_dataitem_type_t to C string.
size_t ast_dataitem_get_size_fixed_2_byte(const unsigned char *buffer, const size_t bufsize)
const char * ast_dataitem_get_name(const ast_dataitem_type_t type)
Function to get name of one dataitem.
void ast_dataitem_get_hex_html(char *html, const size_t html_size, const ast_dataitem_t di)
Function to get a html snippet of the raw dataitem data in hexadecimal format.
size_t ast_dataitem_get_size_fixed_4_byte(const unsigned char *buffer, const size_t bufsize)
ast_dataitem_t ast_dataitem_encode(unsigned char *const buffer, const size_t bufsize, const ast_dataitem_ex_t xdi)
Encode.
void ast_dataitem_get_detail_html(char *detail, const size_t detail_size, const ast_dataitem_t di)
Function to get a html snippet of detailed description of dataitem.
#define A02
Definition: dataitem.h:56
size_t ast_dataitem_get_size_fixed_6_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_fixed(const unsigned char *buffer, const size_t bufsize, const size_t fix_size)
Utility funciton to get fixed dataitem size.
size_t ast_dataitem_get_size_fixed_12_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_rep_64_byte(const unsigned char *buffer, const size_t bufsize)
void ast_dataitem_get_bin_str(char *string, const size_t string_size, const ast_dataitem_t di)
Function to get raw dataitem data in binary format.
const unsigned char * data
Address of data item.
Definition: dataitem.h:424
ast_dataitem_t ast_dataitem_decode(const unsigned char *buffer, const size_t bufsize, const ast_dataitem_type_t type)
Decode data item from binary data.
Dataitem.
Definition: dataitem.h:422
#define A07
Definition: dataitem.h:61
#define REF
Definition: dataitem.h:54
#define A08
Definition: dataitem.h:62
ast_dataitem_type_t
Definition of data item id in each category.
Definition: dataitem.h:67
#define A05
Definition: dataitem.h:59
size_t ast_dataitem_get_size_variable(const unsigned char *buffer, const size_t bufsize, const size_t max_size)
Utility funciton to get FX extendable dataitem size.
ast_dataitem_type_t type
Type of data item.
Definition: dataitem.h:427
size_t size
Size of data item.
Definition: dataitem.h:425
size_t ast_dataitem_get_size_rep_8_byte(const unsigned char *buffer, const size_t bufsize)
bool valid
True when data item is valid, means it's correctlly decoded/encoded.
Definition: dataitem.h:429
void ast_dataitem_get_detail_html_dummy(char *detail, const size_t detail_size, const ast_dataitem_t di)
Dummy get detail function.
size_t ast_dataitem_get_size_var_2_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_rep_2_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_fixed_5_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_repeat(const unsigned char *buffer, const size_t bufsize, const size_t unit_size)
Utility function to get repeated dataitem size.
size_t ast_dataitem_get_size_rep_15_byte(const unsigned char *buffer, const size_t bufsize)
size_t ast_dataitem_get_size_var_unlimited(const unsigned char *buffer, const size_t bufsize)
void ast_dataitem_get_bin_html(char *html, const size_t html_size, const ast_dataitem_t di)
Function to get a html snippet of the raw dataitem data in binary format.