Library examples

The VCP library includes the following examples (folder vcp/code/source_examples):

Example Use Connection Required mode
main_cfg Routes and guidance variables Serial Normal
main_cmd Phase, mode, navigation mode, variables, fly to, wind and position commands Serial Normal
main_ev Events Serial Normal
main_tlm Telemetry Serial, UDP multicast or direct UDP Normal or maintenance
main_file_download File and log download Serial, UDP multicast or direct UDP Maintenance
main_vcpfdr Log listing Serial -


Launching the examples

Windows (Visual Studio)

The arguments of the example (for instance, the COM port) are specified in Visual Studio as project arguments, following the next steps:

  1. Right click on project → Properties.
  1. Configuration properties → Debugging → Command Arguments.

Linux

Run the example from a terminal (root password required), where /dev/ttyUSB0 is the serial port generated when Veronte is connected:

sudo ./main_xxx /dev/ttyUSB0

Arguments

  • main_cfg, main_cmd, main_ev and main_vcpfdr receive the serial port:
main_cfg <serial-port>
  • main_tlm and main_file_download receive the connection type:
main_tlm serial <serial-port>
main_tlm udp multicast <multicast-ip> <rx-port> <tx-port>
main_tlm udp direct <unicast-ip> <rx-port> <tx-port>

main_file_download serial <serial-port> <partition> <file-index> <output-file>
main_file_download udp multicast <multicast-ip> <rx-port> <tx-port> <partition> <file-index> <output-file>
main_file_download udp direct <unicast-ip> <rx-port> <tx-port> <partition> <file-index> <output-file>

udp multicast is used to connect through Veronte Link and udp direct to connect to a Veronte SIL. See Connection with computer.

Exit codes

All the examples return the same codes (VCP::Exit_code, defined in Exit_code.h):

Code Name Description
0exit_okExecution completed successfully
-1exit_invalid_argumentsCommand line arguments are invalid
-2exit_serial_init_failedSerial port could not be initialized
-3exit_udp_init_failedUDP socket could not be initialized
-4exit_discovery_failedNo discovery response received before timeout
-5exit_maintenance_requiredAutopilot is not in maintenance mode
-6exit_output_file_open_failedOutput file could not be opened
-7exit_transfer_start_failedFile transfer (upload/download) could not be started
-8exit_transfer_failedFile transfer (upload/download) did not complete successfully
-9exit_config_unavailableRequired configuration could not be obtained from the autopilot
-10exit_normal_mode_requiredAutopilot is not in normal execution mode
-11exit_firmware_incompatibleVCP library and autopilot firmware versions are not compatible
-12exit_discovery_version_incompatibleDiscovery message version is not compatible
-13exit_unexpected_responseAutopilot answered with a response that does not match the request


Common code

Serial port

This code gets the serial port used by a Veronte device and initializes it:

// Serial port instance
Serial& serial = Serial::get_instance();
// Get default port
const char* port = Serial::get_default_port();
// Get port as argument
if (argc == 2)
{
    port = argv[1];
}
// Init serial port
if (!serial.init(port))
{
    printf("Failed to initialize serial port\n");
    serial.close();
    return VCP::exit_serial_init_failed;
}

Discovery step

The command manager (Base::Commgr) is a singleton, and messages are registered by STANAG message type. The discovery receiver is added to the command manager to discover the address of the Veronte device:

Base::Commgr& commgr = Base::Commgr::get_instance();    // Command manager instance
Media::Discovery discovery(commgr);                     // Discovery instance
commgr.add_rx_tx(Base::Stanag_msg_type::stg_discovery, discovery);

After this, it is possible to discover the device and its address. The discovery is retried every second, and the example gives up after 10 seconds:

Base::Timeout tout_max(10.0F);
Base::Timeout tout(1.0F);
discovery.discover();
while (!discovery.get_status().received && !tout_max.expired())
{
    if (tout.expired())
    {
        discovery.discover();
        tout.start();
    }
    VCP::send_receive(serial, commgr.get_router(), commgr.get_ports().eports);
}

VCP::send_receive receives the router and the port of the command manager. eports is used to communicate directly with the Veronte device (Embention extended STANAG); sports is used through Veronte Link's UDP multicast (standard STANAG).

Addresses are 32-bit values (Base::Address). The address of the discovered device is discovery.get_status().addr, and it is used as destination address by the file and configuration managers:

Media::Filecom filecom(commgr, Base::Address(commgr.get_address()), 10.0F);
Media::Cfgmgr  cfgmgr (commgr, Base::Address(commgr.get_address()), 10.0F);
filecom.set_dest_uaddress(discovery.get_status().addr);
cfgmgr.set_dest_uaddress(discovery.get_status().addr);

Note

Without set_dest_uaddress, Filecom ignores all the responses.

If the discovery fails, the examples check the cause:

Media::Discovery_status st = discovery.get_status();
if (st.cfg_last != Base::lst_normal)
{
    // UAV is not in normal execution mode (VCP::exit_normal_mode_required)
}
if (!discovery.is_compatible(st.sysver.ver))
{
    // VCP library and target firmware are not compatible (VCP::exit_firmware_incompatible)
}
if (st.mver != 0)
{
    // Discovery message version is not compatible (VCP::exit_discovery_version_incompatible)
}

cfg_last indicates the mode of the device (Base::lst_normal or Base::lst_maintenance).

Configuration (main_cfg)

This example requires the Veronte device to be in normal mode. Otherwise, it returns VCP::exit_normal_mode_required.

After the discovery, the file manager and the configuration manager are registered in the command manager:

commgr.add_rx_tx(Base::Stanag_msg_type::stg_filecom, filecom);
commgr.add_rx_tx(Base::Stanag_msg_type::stg_config, cfgmgr);

Then, the example shows a menu with the following options:

--- Choose operation ---
1. Send Routes
2. Send Guidance Variables
3. Receive Guidance Variables
4. Receive MFmgr
0. Exit
  • Send Routes: uploads a route to the device (Base::Cfg::cfg_troute, 67).
  • Send Guidance Variables: uploads the operation guidance variables (Base::Cfg::cfg_oprvars, 5).
  • Receive Guidance Variables: downloads the operation guidance variables (Base::Cfg::cfg_oprvars, 5) and prints the value of the first one.
  • Receive MFmgr: downloads the meta feature manager file (Base::Cfg::cfg_mfmgr, 148) and prints the custom name of the first operation feature.

Route creation

The route is built with set_point, set_line and set_arc, using Base::Feature::build_abs and Vpgnc::Speed_cfg. Coordinates (longitude, latitude) are in radians:

Tllhcompressed f0, f1, f4;
Tllh v0, v1, v4;

// Coordinates - lon, lat (rad), height
v0 = { { -0.01001664582567 , 0.66831910249822 }, 150 };
v1 = { { -0.00964887929879 , 0.66830908013813 }, 150 };
v4 = { { -0.00964855555555 , 0.66825555555555 }, 150 };
f0.set(v0);
f1.set(v1);
f4.set(v4);

Base::Patchset_route route;
Vpgnc::Speed_cfg speed;
speed.set_speed_type(Vpgnc::Speed_cfg::st_arrival);
route.route.set_point(0, Base::Feature::build_abs(f4), -1, speed);
route.route.set_line(1, Base::Feature::build_abs(f0), 2, speed);
route.route.set_arc(2, Base::Feature::build_abs(f1), 250.0F, 250.0F, 0, 3, speed);

(This snippet only shows part of the route; check main_cfg.cpp for the full code.)

Uploading the route

The file is uploaded with Filecom and then loaded with Cfgmgr:

Uint64 uuid_file = rand();  // Random identification number of the file transaction
bool sending_file = true;
if (filecom.upload(route, Base::Cfg::cfg_troute) &&
    cfgmgr.load(uuid_file, Base::Cfg::cfg_troute))
{
    while (sending_file)
    {
        VCP::send_receive(serial, commgr.get_router(), commgr.get_ports().eports);
        if (!filecom.step() && filecom.is_successful())
        {
            // True until the whole configuration transaction has finished
            sending_file = cfgmgr.step();
        }
    }
}

Uploading guidance variables

The guidance variables are uploaded in the same way, using Base::Cfg::cfg_oprvars. In the example, reftun is a tunable array with the operation guidance variables (check main_cfg.cpp):

if (filecom.upload(Base::Tunbuild::build(reftun), Base::Cfg::cfg_oprvars) &&
    cfgmgr.load(uuid_file, Base::Cfg::cfg_oprvars))
{
    while (sending_file)
    {
        VCP::send_receive(serial, commgr.get_router(), commgr.get_ports().eports);
        if (!filecom.step() && filecom.is_successful())
        {
            sending_file = cfgmgr.step();
        }
    }
}

Downloading files

To receive a file, filecom.download is used:

if (filecom.download(Base::Tunbuild::build(reftun), Base::Cfg::cfg_oprvars))
{
    while (sending_file)
    {
        VCP::send_receive(serial, commgr.get_router(), commgr.get_ports().eports);
        if (!filecom.step())
        {
            sending_file = false;
        }
    }
}

Commands (main_cmd)

This example requires the Veronte device to be in normal mode.

After the discovery, the configuration manager is registered in the command manager, and the example shows a menu with the following commands: set phase, set navigation mode, set mode, set/get user variables (Real, Uint16 and bool), fly to, set wind speed, set position and get phase.

For example, the phase change command is built as follows:

bool build_phasecmd(Media::Cfgmgr& cfgmgr, Uint16 v)
{
    static Base::Phasecmd cmd(v);
    cmd.d = v;
    return cfgmgr.set_cmd(&cmd, cmd.cfg_id);
}

And it is sent as follows:

bool sending_cmd = true;
if (build_phasecmd(cfgmgr, 0))     // Change to phase 0
{
    while (sending_cmd)
    {
        VCP::send_receive(serial, commgr.get_router(), commgr.get_ports().eports);
        sending_cmd = cfgmgr.step();    // Sends the command and waits for the answer
    }
    // Force data flush
    VCP::send_flush(serial, commgr.get_router(), commgr.get_ports().eports);
}

To read a value from the device, cfgmgr.get_cmd is used. When Veronte answers, the received object is filled:

Base::Phasecmd cmd_phase;
cfgmgr.get_cmd(&cmd_phase, cmd_phase.cfg_id);

Events (main_ev)

This example requires the Veronte device to be in normal mode.

It sends an event to the device, building the packet directly through the Espkt interface with message type Base::Stanag_msg_type::stg_event, and waits for the response:

Espkt epkt;
Spkt_hdr shdr;
shdr.src = Base::Address(2);                    // Source address
shdr.dst = discovery.get_status().addr;         // Destination address
shdr.mtype = Base::Stanag_msg_type::stg_event;  // Message type

Base::Spkt& pkt = epkt.get_as_spkt();
pkt.set_hdr(shdr);

Base::Espkt_hdr::Flags flags;
flags.crypted = false;
epkt.set_flags(flags);

Event event(event_id, req_id);
{
    Base::Spkt::Mutator m(pkt);
    event.cget(m.os);       // Serialize the event into the payload
}

commgr.send(epkt);
commgr.add_rx(Base::Stanag_msg_type::stg_event, event);  // Handle the response

The event ID must match the event configured in Veronte. The response includes the enabled, user and license flags of the event.

Telemetry (main_tlm)

This example works in normal and maintenance mode, through serial, direct UDP (SIL) or UDP multicast (Veronte Link).

Telemetry is sent by default by Veronte devices. However, the application needs the telemetry configuration of the autopilot to decode the vectors.

In this example, the communication is done through a VCP::File_hlp object: file_hlp.comm_step() sends and receives the pending data through the selected connection (serial or UDP).

The example:

  1. Performs the discovery.
  2. Downloads the telemetry configuration from the autopilot (Base::Cfg::cfg_telemetry, 60):
Telemetryrx tm(Base::Address(commgr.get_address()));
if (filecom.download(tm, Base::Cfg::cfg_telemetry))
{
    while (sending_file)
    {
        file_hlp.comm_step();
        if (!filecom.step())
        {
            sending_file = false;
        }
    }
}
  1. Only after that, registers the telemetry receiver in the command manager and receives telemetry for 30 seconds:
commgr.add_rx(Base::Stanag_msg_type::stg_telemetry, tm);
while (!telemetry_timeout.expired())
{
    file_hlp.comm_step();
}

If the configuration cannot be downloaded, the example returns VCP::exit_config_unavailable.

Command prompt

When the configuration is downloaded, the example prints the table of telemetry vectors:

Telemetry configuration received: N vectors detected.
Index      Hash (hex)           Variable Fields
-----      ----------           ----------------
[ 0] 0xXXXXXXXX - (N fields): [ID:X Type:X], [ID:X Type:X], ...

Then, for each telemetry packet received:

 [0xHASH] (t s) -
OK

Other possible messages are:

  • Hash 0x… not found in configuration: the hash of the received vector is not in the downloaded configuration.
  • Telemetry for address X ignored (mine: Y): the packet is addressed to another address.

File download (main_file_download)

This example requires the Veronte device to be in maintenance mode. Otherwise, it returns VCP::exit_maintenance_required. It works through serial, direct UDP (SIL) or UDP multicast (Veronte Link).

It downloads the file with index <file-index> from the partition <partition> of the device and saves it in <output-file>:

VCP::Output_file output(output_path);
bool transfer_active = filecom.download_file(output, file_index, static_cast<Uint8>(partition));
while (transfer_active)
{
    file_hlp.comm_step();
    transfer_active = filecom.step();
}
output.close();

Log listing (main_vcpfdr)

This example downloads the index of log files of the device (file 1992) and prints the ID, time and size of each log. Then, it reads the header (first block) of each log from partition 3 and prints its date.

To download a complete log file, use main_file_download.


© 2026 Embention. All rights reserved.