LibMISB - Examples - Library basic usage
LibMISB |
---|
![]() |
Introduction |
Supported Standards |
Getting Started |
Examples |
Evaluating |
Contact Us |
Testing library
This library has an example that you can execute. This example is a metadata converter that can encode or decode metadata. If you want to encode, the input file must respect one of the supported formats and will return a binary file with metadata encoded. On the other hand, if you want to decode the program receives a binary file and converts it to the format file selected. Currently JSON format is supported for the input and output encoding files.
The executable is located on /misb-library/examples/misb/
or if you want to compile and execute the example file out of the project. The path of the example is located on /misb-library/examples/misb/misb-converter.cpp
. To compile the example we suggest you follow the next Makefile:
FLAGS:=`pkg-config --cflags --libs misb-0.0`
misb-converter: misb-converter.cpp
g++ -o misb-converter misb-converter.cpp $(FLAGS)
The input JSON file that is going to be used is as follows:
{
"key": "060E2B34020B01010E01030101000000",
"items": [
{
"tag": "2",
"value": "Oct. 24, 2008. 00:13:29.913"
},
{
"tag": "3",
"value": "MISSION01"
},
{
"tag": "4",
"value": "AF-101"
},
{
"tag": "5",
"value": "159.97436"
},
{
"tag": "15",
"value": "14190.7195"
},
{
"tag": "48",
"value": [
{
"tag": "2",
"value": "1"
},
{
"tag": "4",
"value": "TS/SI/CompartmentA//"
},
{
"tag": "5",
"value": "FOUO"
}
]
},
{
"tag": "74",
"value": [
{
"tag": "2",
"value": "Apr. 19, 2001. 04:25:21.000"
},
{
"tag": "101",
"value": [
{
"tag": "targetId",
"value": "1234"
},
{
"tag": "1",
"value": "409600"
},
{
"tag": "3",
"value": "409600"
},
{
"tag": "5",
"value": "80"
},
{
"tag": "102",
"value": [
{
"tag": "1",
"value": "Aircraft"
},
{
"tag": "2",
"value": "Aircraft"
}
]
}
]
},
{
"tag": "4",
"value": "6"
},
{
"tag": "6",
"value": "14"
},
{
"tag": "7",
"value": "78000"
},
{
"tag": "8",
"value": "1280"
},
{
"tag": "9",
"value": "720"
}
]
},
{
"tag": "94",
"value": "0170:F592-F023-7336-4AF8-AA91-62C0-0F2E-B2DA/16B7-4341-0008-41A0-BE36-5B5A-B96A-3645:D3"
},
{
"tag": "96",
"value": "13,898.5463"
},
{
"tag": "104",
"value": "34,567.35"
}
]
}
Or alternitevly if you want to use the 0903 standard:
{
"key": "060E2B34020B01010E01030306000000",
"items": [
{
"tag": "2",
"value": "Apr. 19, 2001. 04:25:21.000"
},
{
"tag": "101",
"value": [
{
"tag": "targetId",
"value": "1234"
},
{
"tag": "1",
"value": "409600"
},
{
"tag": "3",
"value": "409600"
},
{
"tag": "5",
"value": "80"
},
{
"tag": "targetId",
"value": "1235"
},
{
"tag": "1",
"value": "409601"
},
{
"tag": "3",
"value": "409601"
}
]
},
{
"tag": "6",
"value": "2"
}
]
}
And for standard 0102 the example file is the following:
{
"key": "060E2B34020301010E01030302000000",
"items": [
{
"tag": "2",
"value": "1"
},
{
"tag": "4",
"value": "TS/SI/CompartmentA//"
},
{
"tag": "5",
"value": "FOUO"
}
]
}
The following command is executed to perform the encoding. The--encode flag indicates that encoding is to be performed. The -i flag indicates the input file, where the metadata must be raw without encoding. On the other hand, the -o flag indicates the output file, which contains the encoded bytes in a binary file. The --verbose flag shows the KLV bytes encoded on the terminal.
./misb-converter --verbose --encode -i misb_ST0601_sample.json -o klv.bin
For standards 0903 and 0102 you can use the following commands:
./misb-converter --verbose --encode -i misb_ST0903_sample.json -o klv.bin
./misb-converter --verbose --encode -i misb_ST0102_sample.json -o klv.bin
Once the command is executed (with the --verbose
flag), the KLV bytes are displayed. The 0601 klv.bin file contains the encoded bytes.
INFO 6 14 43 52 2 11 1 1 14 1 3 1 1 0 0 0 129 190 2 8 0 4 89 249 174 32 34 168 3 9 77 73 83 83 73 79 78 48 49 4 6 65 70 45 49 48 49 5 2 113 194 15 2 194 33 48 31 2 1 1 4 20 84 83 47 83 73 47 67 111 109 112 97 114 116 109 101 110 116 65 47 47 5 4 70 79 85 79 74 61 2 8 0 3 130 73 56 108 166 64 101 21 20 137 82 1 3 6 64 0 3 3 6 64 0 5 1 80 102 3 78 47 65 4 2 0 6 6 3 0 0 14 7 3 78 47 65 8 3 0 5 0 9 3 0 2 208 1 2 245 199 94 34 69 54 106 185 90 91 54 190 160 65 8 0 65 67 183 22 218 178 46 15 192 98 145 170 248 74 54 115 35 240 146 245 112 1 96 6 0 217 42 47 105 68 104 4 69 69 172 204 65 1 19 1 2 200 198
Decode command
The following command is executed to perform the decoding. The --decode flag indicates that decoding is to be performed. The -i flag indicates the input file, where the metadata must be encoded. The -o flag indicates the output file containing the decoded metadata.
The encoded bytes found inside the 0601 klv.bin file are:
6 14 43 52 2 11 1 1 14 1 3 1 1 0 0 0 129 190 2 8 0 4 89 249 174 32 34 168 3 9 77 73 83 83 73 79 78 48 49 4 6 65 70 45 49 48 49 5 2 113 194 15 2 194 33 48 31 2 1 1 4 20 84 83 47 83 73 47 67 111 109 112 97 114 116 109 101 110 116 65 47 47 5 4 70 79 85 79 74 61 2 8 0 3 130 73 56 108 166 64 101 21 20 137 82 1 3 6 64 0 3 3 6 64 0 5 1 80 102 3 78 47 65 4 2 0 6 6 3 0 0 14 7 3 78 47 65 8 3 0 5 0 9 3 0 2 208 1 2 245 199 94 34 69 54 106 185 90 91 54 190 160 65 8 0 65 67 183 22 218 178 46 15 192 98 145 170 248 74 54 115 35 240 146 245 112 1 96 6 0 217 42 47 105 68 104 4 69 69 172 204 65 1 19 1 2 200 198
./misb-converter --decode -i klv.bin -o output.json
Once the command is executed, it reports that a decoded file was generated. The content of the output.json file is
{
"key": "060E2B34020B01010E01030101000000",
"items": [
{
"tag": "2",
"value": "Oct. 24, 2008. 00:13:29.913"
},
{
"tag": "3",
"value": "MISSION01"
},
{
"tag": "4",
"value": "AF-101"
},
{
"tag": "5",
"value": "159.97436"
},
{
"tag": "15",
"value": "14190.7195"
},
{
"tag": "48",
"value": [
{
"tag": "2",
"value": "1"
},
{
"tag": "4",
"value": "TS/SI/CompartmentA//"
},
{
"tag": "5",
"value": "FOUO"
}
]
},
{
"tag": "74",
"value": [
{
"tag": "2",
"value": "Apr. 19, 2001. 04:25:21.000"
},
{
"tag": "101",
"value": [
{
"tag": "targetId",
"value": "1234"
},
{
"tag": "1",
"value": "409600"
},
{
"tag": "3",
"value": "409600"
},
{
"tag": "5",
"value": "80"
},
{
"tag": "102",
"value": [
{
"tag": "1",
"value": "Aircraft"
},
{
"tag": "2",
"value": "Aircraft"
}
]
}
]
},
{
"tag": "4",
"value": "6"
},
{
"tag": "6",
"value": "14"
},
{
"tag": "7",
"value": "78000"
},
{
"tag": "8",
"value": "1280"
},
{
"tag": "9",
"value": "720"
}
]
},
{
"tag": "94",
"value": "0170:F592-F023-7336-4AF8-AA91-62C0-0F2E-B2DA/16B7-4341-0008-41A0-BE36-5B5A-B96A-3645:D3"
},
{
"tag": "96",
"value": "13,898.5463"
},
{
"tag": "104",
"value": "34,567.35"
}
]
}
and for the 0903 and 0102 respectively:
{
"key": "060E2B34020B01010E01030306000000",
"items": [
{
"tag": "2",
"value": "Apr. 19, 2001. 04:25:21.000"
},
{
"tag": "101",
"value": [
{
"tag": "id",
"value": "1234"
},
{
"tag": "1",
"value": "409600"
},
{
"tag": "3",
"value": "409600"
},
{
"tag": "5",
"value": "80"
},
{
"tag": "id",
"value": "1235"
},
{
"tag": "1",
"value": "409601"
},
{
"tag": "3",
"value": "409601"
}
]
},
{
"tag": "6",
"value": "2"
},
{
"tag": "4",
"value": "6"
}
]
}
{
"key": "060E2B34020301010E01030302000000",
"items": [
{
"tag": "2",
"value": "1"
},
{
"tag": "4",
"value": "TS/SI/CompartmentA//"
},
{
"tag": "5",
"value": "FOUO"
}
]
}
As seen here some extra flags can be present after the decoding process since the encoding might add required tags to the encoding.
API example
To test the encoding and decoding functionality using the internal API with the Metadata class and not using input and output files, you can execute the following command:
./misb-converter-API
Once the command is executed, the encoded bytes and the tags after the decoding process will be shown.
INFO Encoded bytes: 6 e 2b 34 2 b 1 1 e 1 3 1 1 0 0 0 43 2 8 0 4 59 f9 ae 20 22 a8 3 9 4d 49 53 53 49 4f 4e 30 31 4 6 41 46 2d 31 30 31 5 2 6b 6 30 19 2 1 1 4 14 54 53 2f 53 49 2f 43 6f 6d 70 61 72 74 6d 65 6e 74 41 2f 2f 41 1 13 1 2 4d 69
INFO Decoded tags: {tag: 2, value: Oct. 24, 2008. 00:13:29.913}, {tag: 3, value: MISSION01}, {tag: 4, value: AF-101}, {tag: 5, value: 150.504005}, {tag: 48, value: [ {tag: 2, value: 1}, {tag: 4, value: TS/SI/CompartmentA//},]}, {tag: 65, value: 19},
Logging
You can enable the debugging using SetLogLevel in your application with the LibMISB. For example:
libmisb::LibMisb libmisb;
libmisb.SetLogLevel(LIBMISB_DEBUG);