example.c

This example program shows how to use libasterix.In this example we use decode, match, modify and encode functions to manipulate ASTERIX data. More details about this example.

// vim:set ft=c sw=2 sts=2 fenc=utf8:
/*
* libasterix
* Copyright [2013-2019] Aerosys Corporation (http://www.aerosys.cn/).
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of SinoATC and its suppliers, if any.
* The intellectual and technical concepts contained herein
* are proprietary to Aerosys Corporation and its suppliers and may be
* covered by U.S. and Foreign Patents, patents in process,
* and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from SinoATC.
*/
/*
* This example programe show the basic usage of libasterix.
* Please refer to API reference manual for dateiled information.
*/
//Include C standard library
#include <stdio.h>
#include <string.h>
#include <time.h>
//Include definition used on Windows platform
//This is needed when using GCC on Windows
#ifdef WINDOWS
#include <windows.h>
#endif
//Include header of libasterix
//Path should be adjusted according to your development enveronment
//A sample CAT048 data used by this sample program
unsigned char cat048_sample_data[] =
{
0x30, 0x00, 0x43, 0xff, 0xf7, 0x02, 0x20, 0x1b, 0x24, 0xd9, 0x35, 0xa0, 0x45, 0x18, 0x8e, 0x44,
0x20, 0xa3, 0x04, 0x69, 0xe0, 0x28, 0x05, 0xb8, 0x8a, 0x03, 0x80, 0x30, 0xe2, 0x77, 0xc7, 0x38,
0x20, 0x03, 0xbe, 0x80, 0x00, 0x30, 0xa8, 0x00, 0x00, 0x40, 0xff, 0xd8, 0xb7, 0x39, 0x60, 0x04,
0xe7, 0x50, 0xc5, 0xea, 0x51, 0x2f, 0x22, 0x1c, 0x45, 0x60, 0x00, 0x10, 0x07, 0xeb, 0x8b, 0x09,
0x46, 0x20, 0xf6
};
//A sample CAT062 data used by this sample program
unsigned char cat062_sample_data[] =
{
0x3E, 0x09, 0x4F, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x4C, 0xFF, 0xAB,
0x2B, 0x7D, 0xFF, 0x6E, 0x16, 0x29, 0x00, 0x98, 0xDE, 0xF7, 0x03, 0x47, 0xFF, 0x20, 0xFD, 0xD1,
0x00, 0x01, 0x07, 0xC1, 0x0F, 0xEC, 0x01, 0x01, 0x01, 0x10, 0x60, 0x00, 0x00, 0x08, 0x00, 0xC8,
0x00, 0xC8, 0xFF, 0x20, 0x84, 0xE8, 0xAB, 0x60, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03,
0x5D, 0xDE, 0x4E, 0xFF, 0xB4, 0x88, 0x5B, 0xFF, 0x74, 0x5F, 0xBE, 0x07, 0x56, 0xB5, 0x02, 0x14,
0x0D, 0xFF, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0x01, 0x9A, 0x01, 0x01, 0x01, 0x50, 0x20,
0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x84, 0xE8, 0xAE, 0x48, 0xBF, 0xCF, 0xAD, 0x03,
0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x4F, 0xFF, 0xBE, 0x4A, 0x58, 0xFF, 0x84, 0x50, 0xD3, 0x19,
0x1C, 0x69, 0x0D, 0x01, 0x40, 0x00, 0xD0, 0xFF, 0xEF, 0x00, 0xFD, 0x05, 0x6A, 0x03, 0x8B, 0x01,
0x01, 0x01, 0x10, 0x60, 0x03, 0x00, 0x40, 0x00, 0x70, 0x00, 0x70, 0x00, 0x00, 0x84, 0xE8, 0xAA,
0x40, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x50, 0xFF, 0xB5, 0xC0, 0x6E,
0xFF, 0x73, 0x86, 0x65, 0x06, 0x74, 0x66, 0x03, 0x8B, 0x30, 0xFE, 0xD3, 0xFC, 0xA2, 0x02, 0xFF,
0x07, 0xF0, 0x06, 0xC7, 0x01, 0x01, 0x01, 0x10, 0x60, 0x09, 0x00, 0x00, 0x05, 0xA0, 0x05, 0xA0,
0x00, 0x00, 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xFE, 0x7F, 0x89,
0x01, 0x37, 0xFF, 0x44, 0x00, 0x01, 0x07, 0x01, 0x08, 0xA1, 0x01, 0x01, 0x01, 0x10, 0x60, 0x00,
0x00, 0x00, 0x00, 0x74, 0x00, 0x74, 0xFF, 0xCB, 0x84, 0xE8, 0xB4, 0x60, 0xBF, 0xCF, 0xAD, 0x03,
0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x57, 0xFF, 0xBF, 0x52, 0x5E, 0xFF, 0x79, 0x7A, 0x0D, 0x0D,
0x34, 0xE2, 0x0E, 0xC5, 0x98, 0xFF, 0x62, 0x00, 0x0C, 0x01, 0x00, 0x04, 0x00, 0x0B, 0x56, 0x01,
0x01, 0x01, 0x10, 0x60, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x68, 0xFF, 0x7A, 0x84, 0xE8, 0xE3,
0x60, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x58, 0xFF, 0xCC, 0x88, 0x86,
0xFF, 0x76, 0xAB, 0x55, 0x0A, 0x76, 0x7C, 0x1E, 0x9B, 0x5D, 0xFF, 0x61, 0xFC, 0x9C, 0x03, 0xFF,
0x08, 0x95, 0x04, 0x6C, 0x01, 0x01, 0x01, 0x10, 0x60, 0x30, 0x00, 0x00, 0x05, 0xA0, 0x05, 0xA0,
0x00, 0x00, 0x84, 0xE8, 0xA1, 0x40, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE,
0x58, 0xFF, 0xD2, 0xC2, 0xDD, 0xFF, 0x6B, 0x0D, 0x23, 0xFD, 0x25, 0xE1, 0x26, 0x29, 0x64, 0xFD,
0xD8, 0x03, 0x1C, 0xFC, 0x04, 0x08, 0x33, 0x01, 0x4D, 0x01, 0x01, 0x01, 0x10, 0x60, 0x00, 0x00,
0x00, 0x05, 0xA0, 0x05, 0xA0, 0x00, 0x00, 0x84, 0xE8, 0xA0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 0x05, 0x08, 0xD8, 0x06, 0x37, 0x01, 0x01, 0x01, 0x10, 0x60, 0x0F, 0x00,
0x40, 0x00, 0xE4, 0x00, 0xE4, 0x00, 0x1F, 0x84, 0xE8, 0xAA, 0x40, 0xBF, 0xCF, 0xAD, 0x03, 0x00,
0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x5F, 0xFF, 0xC5, 0xDE, 0x8E, 0xFF, 0x79, 0x0B, 0x9A, 0x0C, 0xF5,
0x0B, 0x16, 0x96, 0x03, 0xFE, 0xFE, 0x03, 0xB1, 0x02, 0xFF, 0x08, 0x9C, 0x09, 0x23, 0x01, 0x01,
0x01, 0x10, 0x60, 0x00, 0x00, 0x00, 0x05, 0x50, 0x05, 0x50, 0x00, 0x00, 0x84, 0xE8, 0xA1, 0x60,
0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x5F, 0xFF, 0xB2, 0x2D, 0xE7, 0xFF,
0x63, 0x29, 0x9A, 0xF5, 0x03, 0x76, 0xFF, 0x30, 0xF1, 0xFF, 0x1B, 0xFD, 0x68, 0xFC, 0x01, 0x0B,
0x11, 0x10, 0xE1, 0x01, 0x01, 0x01, 0x10, 0x60, 0x00, 0x00, 0x00, 0x04, 0x60, 0x04, 0x60, 0x00,
0x00, 0xA4, 0xE8, 0xB3, 0x04, 0x6D, 0x60, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D,
0xDE, 0x60, 0xFF, 0xAF, 0x84, 0x2B, 0xFF, 0x73, 0x02, 0x19, 0x05, 0xC9, 0x4C, 0xFC, 0x23, 0x7B,
0x01, 0xE2, 0x03, 0x37, 0x04, 0xFE, 0x07, 0xF7, 0x03, 0x1B, 0x01, 0x01, 0x01, 0x10, 0x60, 0x0D,
0x00, 0x00, 0x05, 0x28, 0x05, 0x28, 0x00, 0x00, 0x84, 0xE8, 0xAB, 0x40, 0xBF, 0xCF, 0xAD, 0x03,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A, 0xFB, 0x0A, 0xCA, 0x01, 0x01,
0x01, 0x10, 0x60, 0x07, 0x00, 0x00, 0x06, 0x18, 0x06, 0x18, 0x00, 0x00, 0xA4, 0xE8, 0xAC, 0x06,
0x37, 0x40, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x61, 0xFF, 0xB2, 0xFD,
0x1A, 0xFF, 0x75, 0x78, 0x27, 0x08, 0x78, 0x3E, 0x00, 0x37, 0xF4, 0x00, 0xDC, 0xFF, 0xC9, 0xFF,
0x05, 0x04, 0x00, 0x12, 0xBB, 0x01, 0x01, 0x01, 0x10, 0x60, 0x00, 0x0D, 0x80, 0x00, 0x54, 0x00,
0x54, 0x00, 0x00, 0x84, 0xE8, 0xAD, 0x20, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D,
0xDE, 0x62, 0xFF, 0xBF, 0xD8, 0x86, 0xFF, 0x75, 0xF5, 0x51, 0x09, 0x55, 0xF3, 0x0F, 0x7F, 0x69,
0x03, 0xD1, 0x00, 0x71, 0xFE, 0x02, 0x06, 0xBB, 0x0D, 0x34, 0x01, 0x01, 0x01, 0x10, 0x60, 0x1E,
0x00, 0x00, 0x04, 0xD8, 0x04, 0xD8, 0x00, 0x00, 0x84, 0xE8, 0xAE, 0x40, 0xBF, 0xCF, 0xAD, 0x03,
0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x62, 0xFF, 0xBF, 0x36, 0xD1, 0xFF, 0x84, 0xC8, 0x66, 0x19,
0xB1, 0x4B, 0x0E, 0x13, 0x50, 0x01, 0x0B, 0xFF, 0x42, 0xFF, 0x01, 0x07, 0xDF, 0x0C, 0x98, 0x01,
0x01, 0x01, 0x10, 0x60, 0x00, 0x00, 0x08, 0x00, 0x28, 0x00, 0x29, 0xFF, 0x51, 0x84, 0xE8, 0xE1,
0x60, 0xBF, 0xCF, 0x8D, 0x03, 0x00, 0xE8, 0x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 0x01, 0x50, 0x20, 0x00, 0x40, 0x06, 0x78, 0x06, 0x78, 0x00, 0x00, 0x08, 0x0E,
0xC0, 0x04, 0x92, 0x84, 0xE8, 0x90, 0x44, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D,
0xDE, 0x66, 0xFF, 0xC4, 0x7B, 0xB9, 0xFF, 0x6E, 0xA5, 0x54, 0x01, 0x45, 0x0F, 0x15, 0x1E, 0x0F,
0x01, 0x19, 0xFF, 0xA0, 0x00, 0x00, 0x04, 0x00, 0x08, 0x60, 0x01, 0x01, 0x01, 0x10, 0x60, 0x18,
0x18, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0x84, 0xE8, 0xA1, 0x60, 0xBF, 0xCF, 0xAD, 0x03,
0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x66, 0xFF, 0xC5, 0x41, 0x00, 0xFF, 0x8C, 0xC4, 0xE5, 0x23,
0x1A, 0xE4, 0x14, 0xAC, 0x87, 0xFF, 0x15, 0xFF, 0x2F, 0x00, 0x00, 0x00, 0x6B, 0x04, 0x75, 0x01,
0x01, 0x01, 0x10, 0x60, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x84, 0x00, 0x41, 0x84, 0xE8, 0x9D,
0x60, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x67, 0xFF, 0xB5, 0x41, 0x88,
0xFF, 0x6D, 0xE0, 0xE8, 0x00, 0x64, 0xCC, 0x03, 0x01, 0xE3, 0xFD, 0x2E, 0xFE, 0x45, 0x0A, 0xE5,
0x07, 0xBF, 0x01, 0x9B, 0x01, 0x01, 0x01, 0x10, 0x60, 0x16, 0x00, 0x90, 0x06, 0x40, 0x06, 0x40,
0x00, 0x00, 0x84, 0xE8, 0x90, 0x40, 0xBF, 0x8F, 0x8D, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE,
0x67, 0xFF, 0xA6, 0x49, 0x1C, 0xFF, 0x6B, 0x18, 0xE2, 0xFD, 0x89, 0x59, 0xF1, 0x30, 0x33, 0x00,
0x32, 0xFF, 0xCD, 0x00, 0x00, 0x01, 0x74, 0x01, 0x01, 0x01, 0x30, 0x40, 0x14, 0x0C, 0x00, 0x28,
0x00, 0x00, 0xA4, 0xE8, 0xB2, 0x01, 0x41, 0x20, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03,
0x5D, 0xDE, 0x67, 0xFF, 0xB3, 0xCA, 0x8B, 0xFF, 0x69, 0xFD, 0x66, 0xFC, 0x3E, 0x4A, 0x01, 0x3F,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x92, 0x05, 0x70, 0x41, 0x01, 0x01, 0x50, 0x20,
0x00, 0x40, 0x06, 0x54, 0x06, 0x54, 0x00, 0x00, 0x84, 0xE8, 0xFB, 0x44, 0xBF, 0xCF, 0xAD, 0x03,
0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x69, 0xFF, 0xBD, 0x15, 0xA7, 0xFF, 0x7A, 0xD5, 0x8A, 0x0E,
0x9D, 0x03, 0x0C, 0x0F, 0x5B, 0xFF, 0x2F, 0x00, 0xA0, 0x02, 0xFE, 0x00, 0x40, 0x10, 0x5E, 0x01,
0x01, 0x01, 0x10, 0x60, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0xFF, 0xF7, 0x84, 0xE8, 0xE2,
0x60, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x6A, 0xFF, 0xC1, 0x05, 0x19,
0xFF, 0x8B, 0x7D, 0x01, 0x21, 0x47, 0x8B, 0x0F, 0xB8, 0xB7, 0xFF, 0x68, 0x00, 0xA2, 0x00, 0xFF,
0x00, 0x5E, 0x02, 0xA6, 0x01, 0x01, 0x01, 0x10, 0x60, 0x20, 0x00, 0x00, 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E8, 0xA1, 0x60, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8, 0x3C, 0x03, 0x5D, 0xDE, 0x6E,
0xFF, 0xC9, 0x2E, 0xB5, 0xFF, 0x84, 0xFE, 0x6D, 0x1A, 0xA0, 0x05, 0x19, 0xF7, 0x0C, 0x02, 0x24,
0x03, 0x16, 0xFF, 0x01, 0x08, 0x79, 0x09, 0x70, 0x01, 0x01, 0x01, 0x10, 0x60, 0x00, 0x00, 0x00,
0x05, 0xC8, 0x05, 0xC8, 0x00, 0x00, 0x84, 0xE8, 0xA5, 0x60, 0xBF, 0xCF, 0xAD, 0x03, 0x00, 0xE8,
0x3C, 0x03, 0x5D, 0xDE, 0x70, 0xFF, 0xB6, 0x7F, 0xDF, 0xFF, 0x74, 0x14, 0xA3, 0x07, 0x11, 0x2A,
0x04, 0x6C, 0x29, 0x00, 0x69, 0xFF, 0x0D, 0x03, 0xFF, 0x00, 0xC1, 0x08, 0xAE, 0x01, 0x01, 0x01,
0x10, 0x60, 0x07, 0x00, 0x00, 0x00, 0xC8, 0x00, 0xC8, 0xFF, 0xFF, 0x84, 0xE8, 0x90, 0x40,
};
/*
* **************************
* Decode ASTERIX data block
*
* We first decode an ASTERIX data block, and list all data records and data items included in it.
* **************************
*/
void example_decode(void)
{
//Here we use CAT062 sample data above, and standard UAP included in lib
ast_datablock_t db = ast_datablock_decode(cat062_sample_data, sizeof(cat062_sample_data), AST_UAP_STANDARD);
//Check if decodeing is successfully done
if(db.valid)
{
//Go through each data record
for (unsigned int i=0; i<db.n_datarecords; ++i)
{
//Get current data record
printf("Data record: %i\n", i);
//Go through each data item
for (unsigned int j=0; j<dr.n_dataitems; ++j)
{
//Get current data item
printf(" Data item: %2i\n", j);
//Print data item type
printf(" TYPE: %s\n", ast_dataitem_type_to_str(di.type));
//Print data item size
printf(" SIZE: %02zu\n", di.size);
//Print data item name
printf(" NAME: %s\n", ast_dataitem_get_name(di.type));
//Print data item summary
ast_dataitem_get_summary(summary, sizeof(summary), di);
printf(" DESC: %s\n", summary);
//Print data item data in hex string
ast_dataitem_get_hex_str(hexstr, sizeof(hexstr), di);
printf(" DATA: %s\n", hexstr);
//Print an empty line
printf("\n");
}
}
}
else
{
printf("Failed to decode datablock!\n");
}
}
/*
* **************************
* Match keywords in ASTERIX data block
*
* We then use match functions to find interesting fields in an data block.
* **************************
*/
void example_match(void)
{
//Here we use CAT062 sample data above, and standard UAP included in lib
ast_datablock_t db = ast_datablock_decode(cat062_sample_data, sizeof(cat062_sample_data), AST_UAP_STANDARD);
//Check if decodeing is successfully done
if(db.valid)
{
//Go through each data record
for (unsigned int i=0; i<db.n_datarecords; ++i)
{
//Get current data record
printf("Data record: %i\n", i);
//Prepare space for storing key and value
//List all supported keywords defined by enum ast_keyword_t
for (int j = AST_KEYWORD_SACSIC; j < AST_KEYWORD_LAST; ++j)
{
//Print key name
ast_keyword_to_str(key, sizeof(key), j);
printf(" Key:%s\t", key);
//Try to match this keyword in data record,
//and print its value when found.
if(ast_datarecord_get_keyword(value, sizeof(value), dr, j))
printf("Value:%s\n", value);
else
printf("Value:NOT_EXIST\n");
}
}
}
else
{
printf("Failed to decode datablock!\n");
}
}
/*
* **************************
* Modify SAC/SIC in ASTERIX data block
*
* We now extract SAC/SIC value from data record, change it to another one,
* and encode again to create a new data record and data block.
* **************************
*/
void example_modify(void)
{
//Here we use CAT048 sample data above, and standard UAP included in lib
ast_datablock_t db = ast_datablock_decode(cat048_sample_data, sizeof(cat048_sample_data), AST_UAP_STANDARD);
//Check if decodeing is successfully done
if(db.valid)
{
printf("New SAC\\SIC = 109\\250\n");
//print original data block
printf("Original Data:\n");
for(size_t i = 0; i < db.size; ++i)
{
printf("%.2X ", db.data[i]);
if((i + 1) % 16 == 0)
printf("\n");
}
printf("\n");
//Prepare new SAC/SIC data item
//In this case, it is I048/010
{
.valid = true,
.sac = 109,
.sic = 250,
};
//Prepare data modifier item
{
.data = (void*) &ddi,
};
//Prepare data modifier
{
};
mod.dataitems[0] = xdi;
//Allocate memory to store new data block
unsigned char buffer[256];
//Modify original data block
ast_datablock_t db_new = ast_datablock_modify(buffer, sizeof(buffer), db, mod);
//Check if modification is successfully done
if(db_new.valid)
{
//print new (modified) data block
printf("Modified Data:\n");
for(size_t i = 0; i < db_new.size; ++i)
{
printf("%.2X ", db_new.data[i]);
if((i + 1) % 16 == 0)
printf("\n");
}
printf("\n");
}
else
{
printf("Failed to modify datablcok\n");
}
}
else
{
printf("Failed to decode datablock!\n");
}
}
/*
* **************************
* Build and encode ASTERIX data block
*
* We now build an ASTERIX CAT021 data block from the scratch.
* In this case we need to prepare each data item one by one, and then use encode function
* to assemble them into a data record and data block.
* **************************
*/
void example_encode(void)
{
//Prepare container for data items
//In this example, we will use an old UAP for CAT021 v0.23
xdr.category = I021;
xdr.n_dataitems = 0;
//Prepare data item I021/010
ast_dataitem_021_010_t ddi_021_010 =
{
.valid = true,
.sac = 109,
.sic = 250,
};
//Prepare container item for I021/010
ast_dataitem_ex_t xdi_021_010 =
{
.data = (void*) &ddi_021_010,
};
//Add dataitem to container
xdr.dataitems[xdr.n_dataitems++] = xdi_021_010;
//Prepare data item I021/030
time_t now;
time(&now);
struct tm * tm_now = gmtime(&now);
ast_dataitem_021_030_t ddi_021_030 =
{
.valid = true,
.raw_time = 0,
.hour = tm_now->tm_hour,
.min = tm_now->tm_min,
.sec = tm_now->tm_sec,
.msec = 0,
};
//Prepare container item for I021/030
ast_dataitem_ex_t xdi_021_030 =
{
.data = (void*) &ddi_021_030,
};
//Add dataitem to container
xdr.dataitems[xdr.n_dataitems++] = xdi_021_030;
//Prepare data item I021/040
//In v0.23, the data item I021/040 use an old format which has been abondanded in new versions.
//Here we use a special data item I021/A03 represents the data item I021/040 defined by v0.23
ast_dataitem_021_A03_t ddi_021_040 =
{
.valid = true,
.diff_correction = false,
.ground = false,
.simulated = false,
.test = false,
.fixed_transponder = false,
.selected_altitude_capability = true,
.spi = false,
.altitude_capability = AST_ADSB_ALT_CAP_25FT,
};
//Prepare container item for I021/A03
ast_dataitem_ex_t xdi_021_040 =
{
.data = (void*) &ddi_021_040,
};
//Add dataitem to container
xdr.dataitems[xdr.n_dataitems++] = xdi_021_040;
//Prepare data item I021/080
ast_dataitem_021_080_t ddi_021_080 =
{
.valid = true,
.icao_address = 0x7E7E7E,
};
//Prepare container item for I021/080
ast_dataitem_ex_t xdi_021_080 =
{
.data = (void*) &ddi_021_080,
};
//Add dataitem to container
xdr.dataitems[xdr.n_dataitems++] = xdi_021_080;
//Prepare data item I021/130
ast_dataitem_021_130_t ddi_021_130 =
{
.valid = true,
.latitude = 38.02,
.longitude = 105.57,
};
//Prepare container item for I021/130
ast_dataitem_ex_t xdi_021_130 =
{
.data = (void*) &ddi_021_130,
};
//Add dataitem to container
xdr.dataitems[xdr.n_dataitems++] = xdi_021_130;
//Prepare data item I021/145
ast_dataitem_021_145_t ddi_021_145 =
{
.valid = true,
.raw_level = 310 * 4,
};
//Prepare container item for I021/145
ast_dataitem_ex_t xdi_021_145 =
{
.data = (void*) &ddi_021_145,
};
//Add dataitem to datarecord container
xdr.dataitems[xdr.n_dataitems++] = xdi_021_145;
//Now, all data items have been added to datarecord container
//Add datarecord to datablock container
xdb.category = xdr.category;
xdb.uap = xdr.uap;
xdb.n_datarecords = 1;
xdb.datarecords[0] = xdr;
//Now, datablock container is ready to be encoded
//Allocate memory to store new data block
unsigned char buffer[256];
//Encode data items and assemble them into data record and data block
ast_datablock_t db = ast_datablock_encode(buffer, 256, xdb);
//Check if encoding is successfully done
if(db.valid)
{
//print encoded data
printf("New Data Block:\n");
for(size_t i = 0; i < db.size; ++i)
{
printf("%.2X ", db.data[i]);
if((i + 1) % 16 == 0)
printf("\n");
}
printf("\n");
}
else
{
printf("Failed to encode datablock!\n");
}
}
/*
* Main entrance point of this example program
*/
int main(void)
{
//Start from here
printf("libasterix Example Program Start\n");
//Get license key
char key [256];
printf ("Input your license key: ");
fgets(key, sizeof(key), stdin);
//Init library
//Show library version
printf("Verison: %s\n", ast_library_version());
printf("Build: %s\n", ast_library_build());
printf("About: %s\n", ast_library_about());
printf("Contact: %s\n", ast_library_contact());
printf("\n");
//Run examples
example_decode();
example_match();
example_modify();
example_encode();
//Exit
return 0;
}