Introduction


In this guide, we will walk through the creation of a Global Waypoint list using the List Manager service such that the constructed list can be executed by the Global Waypoint List Driver service.


We assume that there is a component capable of sending messages. 


openjaus::core_v1_1::Base client("GlobalWaypointListDriverClient");



To construct the waypoint list, we create a series of SetGlobalWaypoint messages and then populate the SetElement message with the waypoints. 


// Constructing a waypoint list
std::vector<openjaus::mobility_v1_0::SetGlobalWaypoint> waypoints;

openjaus::mobility_v1_0::SetGlobalWaypoint waypoint1;
waypoint1.setPresenceVector(openjaus::mobility_v1_0::SetGlobalWaypoint::PV_NO_FIELDS); // [1]
waypoint1.setLatitude_deg("28.375534");
waypoint1.setLongitude_deg("-81.549223");
waypoints.push_back(waypoint1);

openjaus::mobility_v1_0::SetGlobalWaypoint waypoint2;
waypoint2.setPresenceVector(openjaus::mobility_v1_0::SetGlobalWaypoint::PV_NO_FIELDS); // [1]
waypoint2.setLatitude_deg("28.472023");
waypoint2.setLongitude_deg("-81.471535");
waypoints.push_back(waypoint2);

openjaus::mobility_v1_0::SetGlobalWaypoint waypoint3;
waypoint3.setPresenceVector(openjaus::mobility_v1_0::SetGlobalWaypoint::PV_NO_FIELDS); // [1]
waypoint3.setLatitude_deg("28.776959");
waypoint3.setLongitude_deg("-81.356944");
waypoints.push_back(waypoint3);


openjaus::mobility_v1_0::SetElement* setElementMessage = openjaus::mobility_v1_0::SetElement();
openjaus::mobility_v1_0::ElementListRefArray& elementList = setElementMessage->getElementList();

for (size_t i = 0; i < waypoints.size(); i++)
{
    openjaus::mobility_v1_0::ElementRecord elementRecord;

    if (i == 0)
    {
        elementRecord.setPreviousUID(0); // First element in the list
    }
    else
    {
        elementRecord.setPreviousUID(i);
    }

    elementRecord.setElementUID(i + 1);

    if (i == (waypoints.size() - 1))
    {
        elementRecord.setNextUID(0); // Last element in the list
    }
    else
    {
        elementRecord.setNextUID(i + 2);
    }

    openjaus::mobility_v1_0::ElementDataBlob& dataBlob = elementRecord.getElementData();

    openjaus::system::Transportable* transportable = waypoint1.getPayload();
    openjaus::system::Buffer buffer(transportable->length());
    openjaus::system::BufferWriter& writer = buffer.getWriter();
    writer.clear();
    transportable->to(writer);

    dataBlob.setPayload(openjaus::mobility_v1_0::ElementDataBlob::JAUS_MESSAGE, buffer);
    elementList.add(elementRecord);
}

client.sendMessage(setElementMessage);


Notes:

[1] We recommend that you always disable all optional fields and then only enable the fields being used.

[2] The first and last elements on the list are indicated by setting the previousUID and nextUID to 0 as appropriate.

[3] We manually serialize the message before setting the ElementDataBlob payload.



To update the waypoint list, we recommend deleting the entire list and creating the new list from scratch. Although, it is possible to manipulate the list in place, this is the easiest approach.


openjaus::mobility_v1_0::DeleteElement* deleteElementMessage = openjaus::mobility_v1_0::DeleteElement();
deleteElementMessage->setRequestID(100); // [1]

openjaus::mobility_v1_0::DeleteElementList& deleteList = deleteElementMessage->getDeleteElementList();
openjaus::model::fields::UnsignedShort deleteElementUID;
deleteElementUID.setValue(65535); // Delete all elements
deleteList.add(deleteElementUID);

client.sendMessage(deleteElementMessage);


Notes:

[1] The request id can be used by you client code to verify that the elements have been deleted.