LibMISB/Examples/Library basic usage: Difference between revisions

From RidgeRun Developer Wiki
No edit summary
No edit summary
 
(29 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<noinclude>
{{LibMISB/Head|previous=Examples|next=Examples/GStreamer_Application|metakeywords=}}
</noinclude>
== 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.


<noinclude>
The executable is located on <code>/misb-library/examples/misb/</code> or if you want to compile and execute the example file out of the project. The path of the example is located on <code>/misb-library/examples/misb/misb-converter.cpp</code>. To compile the example we suggest you follow the next Makefile:
{{LibMISB/Head|previous=Getting_Started/How_to_compile|next=|keywords=}}
<syntaxhighlight lang=Makefile>
</noinclude>
FLAGS:=`pkg-config --cflags --libs misb-0.0`
misb-converter: misb-converter.cpp
g++ -o misb-converter misb-converter.cpp $(FLAGS)
</syntaxhighlight>
 
The input JSON file that is going to be used is as follows:
 
<syntaxhighlight lang=json>
{
  "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"
    }
  ]
}
</syntaxhighlight>
 
Or alternitevly if you want to use the 0903 standard:
<syntaxhighlight lang=json>
{
    "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"
      }
    ]
  }


</syntaxhighlight>




== Dependencies ==
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.
Your build environment will need the following packages installed in order to build LibMISB:
* jansson
* cpputest
* doxygen
* meson


== Apt Get Installation ==
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
sudo apt-get install \
./misb-converter --verbose --encode -i misb_ST0601_sample.json -o klv.bin
libjansson-dev \
</syntaxhighlight>
cpputest \
or
doxygen \
<syntaxhighlight lang=bash>
python3 \
./misb-converter --verbose --encode -i misb_ST0903_sample.json -o klv.bin
python3-pip \
ninja-build
</syntaxhighlight>
</syntaxhighlight>


== Meson Installation ==
Follow the next command to install Meson:


<syntaxhighlight lang=bash>
Once the command is executed (with the <code>--verbose</code> flag), the KLV bytes are displayed. The 0601 klv.bin file contains the encoded bytes.
pip3 install --user 'meson<=0.60.3' --force-reinstall
 
<syntaxhighlight>
INFO    6 14 43 52 2 11 1 1 14 1 3 1 1 0 0 0 44 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 65 1 17 1 2 164 125
</syntaxhighlight>
</syntaxhighlight>


If meson doesn't work, try reboot.
=== Decode command ===
Important: Meson version must be less or equal to 0.60.3. You can verify Meson version with the following 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:  
<syntaxhighlight>
6 14 43 52 2 11 1 1 14 1 3 1 1 0 0 0 44 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 65 1 17 1 2 164 125
</syntaxhighlight>


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
meson --version
./misb-converter --decode -i klv.bin -o output.json
</syntaxhighlight>
</syntaxhighlight>


== LibMISB ==
Once the command is executed, it reports that a decoded file was generated. The content of the output.json file is
LibMISB is a [https://mesonbuild.com/ Meson] project. This makes it easy to build software packages for a variety of operating systems and platforms, including embedded devices.
=== '''Building LibMISB''' ===


You can run the following commands:
<syntaxhighlight lang=json>
<syntaxhighlight lang=bash>
{
meson builddir
  "key": "060E2B34020B01010E01030101000000",
ninja -C builddir
  "items": [
    {
      "tag": "2",
      "value": "Oct. 24, 2008. 00:13:29.913"
    },
    {
      "tag": "3",
      "value": "MISSION01"
    },
    {
      "tag": "4",
      "value": "AF-101"
    },
    {
      "tag": "5",
      "value": "159.974365"
    },
    {
      "tag": "15",
      "value": "14190.719463"
    },
    {
      "tag": "65",
      "value": "17"
    }
  ]
}
</syntaxhighlight>
</syntaxhighlight>


Specify meson --prefix $INSTALL_PATH build, if you want the build to be configured for installation in a directory other than /usr/local.
and for the 0903:


== '''Installing the Binaries''' ==
<syntaxhighlight lang=json>
Once the ninja -C build commands completes, you can install the generated binaries:
{
<syntaxhighlight lang=bash>
  "key": "060E2B34020B01010E01030306000000",
ninja -C builddir install
  "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"
    }
  ]
}
</syntaxhighlight>
</syntaxhighlight>


If you are trying to install to a system location you will need to run with sudo privileges.  
As seen here some extra flags can be present after the decoding process since the encoding might add required tags to the encoding.
<syntaxhighlight lang=bash>
 
sudo ninja -C builddir install
== Logging ==
 
You can enable the debugging using '''SetLogLevel''' in your application with the LibMISB. For example:
 
<syntaxhighlight lang=cpp>
  libmisb::LibMisb libmisb;
  libmisb.SetLogLevel(LIBMISB_DEBUG);
</syntaxhighlight>
</syntaxhighlight>
<noinclude>{{LibMISB/Foot|Examples|Examples/Add_data_to_MPEG_Transport_Stream}}</noinclude>

Latest revision as of 15:23, 19 September 2024



Previous: Examples Index Next: Examples/GStreamer_Application





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"
    }
  ]
}

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"
      }
    ]
  }


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

or

./misb-converter --verbose --encode -i misb_ST0903_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 44 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 65 1 17 1 2 164 125

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 44 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 65 1 17 1 2 164 125
./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.974365"
    },
    {
      "tag": "15",
      "value": "14190.719463"
    },
    {
      "tag": "65",
      "value": "17"
    }
  ]
}

and for the 0903:

{
  "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"
    }
  ]
}

As seen here some extra flags can be present after the decoding process since the encoding might add required tags to the encoding.

Logging

You can enable the debugging using SetLogLevel in your application with the LibMISB. For example:

  libmisb::LibMisb libmisb;
  libmisb.SetLogLevel(LIBMISB_DEBUG);


Previous: Examples Index Next: Examples/Add_data_to_MPEG_Transport_Stream