summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/navigation/navigation-core/guidance-server-plugin/genivi_navigationcore_guidance.cxx50
-rw-r--r--src/navigation/navigation-core/routing-server-plugin/genivi_navigationcore_routing.cxx7
-rw-r--r--test/navigation/route.xml26
-rw-r--r--test/navigation/routes.xml43
-rwxr-xr-xtest/navigation/test-guidance-capi.py328
-rwxr-xr-xtest/navigation/test-guidance.py329
6 files changed, 710 insertions, 73 deletions
diff --git a/src/navigation/navigation-core/guidance-server-plugin/genivi_navigationcore_guidance.cxx b/src/navigation/navigation-core/guidance-server-plugin/genivi_navigationcore_guidance.cxx
index 45e563e..430ece7 100644
--- a/src/navigation/navigation-core/guidance-server-plugin/genivi_navigationcore_guidance.cxx
+++ b/src/navigation/navigation-core/guidance-server-plugin/genivi_navigationcore_guidance.cxx
@@ -116,11 +116,6 @@ class GuidanceObj
std::string m_kind_of_voice;
struct item *get_item(struct map_rect *mr);
struct map_rect *get_map_rect(void);
- void SetSimulationMode(uint32_t SessionHandle, bool Activate);
- void GetSimulationMode(bool& SimulationMode);
- void SetSimulationSpeed(uint32_t sessionHandle);
- void PauseGuidance(uint32_t sessionHandle);
- void ResumeGuidance(uint32_t sessionHandle);
void SetVoiceGuidance(const bool& activate, const std::string& voice);
void SetVoiceGuidanceSettings(const Guidance::PromptMode &promptMode);
Guidance::PromptMode GetVoiceGuidanceSettings();
@@ -204,6 +199,8 @@ class GuidanceServerStub : public GuidanceStubDefault
m_version.setVersionMinor(0);
m_version.setVersionMicro(0);
m_version.setDate("21-01-2014");
+
+ mp_guidance = NULL;
}
~GuidanceServerStub() {
@@ -388,7 +385,7 @@ GuidanceObj::GetDestinationInformation(uint32_t& Distance, uint32_t& TravelTime,
struct item *item;
if (!mr)
throw DBus::ErrorFailed("internal error:failed to get map rect");
- while (item=map_rect_get_item(mr)) {
+ while ((item=map_rect_get_item(mr))) {
if (item_coord_get(item, &c[idx], 1)) {
if (!idx) {
if (!item_attr_get(item, attr_destination_time, &destination_time))
@@ -538,7 +535,6 @@ GuidanceObj::GetManeuver(struct item *item, uint32_t& offsetOfManeuver, Guidance
maneuverData[maneuverDataAttribute] = maneuverDataValue;
}
-
void
GuidanceObj::GetGuidanceDetails(bool& voiceGuidance, bool& vehicleOnTheRoad, bool& isDestinationReached, Guidance::ManeuverPhase& maneuver)
{
@@ -584,7 +580,7 @@ GuidanceObj::GetManeuversList(const uint16_t& requestedNumberOfManeuvers, const
numberOfManeuvers = 0;
maneuverIndex = 0;
- while (item=get_item(mr)) { //scan the list of maneuvers of the route
+ while ((item=get_item(mr))) { //scan the list of maneuvers of the route
if (maneuverIndex >= maneuverOffset && maneuverIndex < maneuverOffset+requestedNumberOfManeuvers) {
Guidance::Maneuver maneuver;
std::vector<Guidance::ManeuverItem> items;
@@ -616,37 +612,6 @@ GuidanceObj::GetManeuversList(const uint16_t& requestedNumberOfManeuvers, const
map_rect_destroy(mr);
}
-void
-GuidanceObj::SetSimulationSpeed(uint32_t sessionHandle)
-{
- struct vehicle *vehicle=get_vehicle("demo:");
- if (vehicle && !m_paused)
- vehicle_set_attr(vehicle, &vehicle_speed);
-}
-
-void
-GuidanceObj::PauseGuidance(uint32_t sessionHandle)
-{
- struct vehicle *vehicle=get_vehicle("demo:");
- if (vehicle) {
- struct attr vehicle_speed0={attr_speed,(char *)0};
- vehicle_set_attr(vehicle, &vehicle_speed0);
- }
- m_paused=true;
-}
-
-void
-GuidanceObj::ResumeGuidance(uint32_t sessionHandle)
-{
- struct vehicle *vehicle=get_vehicle("demo:");
- GuidanceObj_Callback(this);
- if (vehicle)
- {
- vehicle_set_attr(vehicle, &vehicle_speed);
- }
- m_paused=false;
-}
-
void GuidanceObj::SetVoiceGuidance(const bool& activate, const std::string& voice)
{
m_voice_guidance = activate;
@@ -685,7 +650,6 @@ GuidanceObj::GetGuidanceStatus(Guidance::GuidanceStatus &guidanceStatus, Navigat
routeHandle=m_route_handle;
}
-
void
GuidanceObj_Callback(GuidanceObj *obj)
{
@@ -786,8 +750,8 @@ GuidanceObj::GuidanceObj(GuidanceServerStub *guidance, uint32_t SessionHandle, u
m_speechoutput=new SpeechOutput(*conn);
#endif
if (navit_get_attr(navit, attr_callback_list, &callback_list, NULL)) {
- callback_list_call_attr_4(callback_list.u.callback_list, attr_command, "navit_genivi_get_route", in, &ret, NULL);
- if (ret && ret[0] && ret[1] && ret[0]->type == attr_route && ret[1]->type == attr_vehicleprofile) {
+ callback_list_call_attr_4(callback_list.u.callback_list, attr_command, "navit_genivi_get_route", in, &ret, NULL);
+ if (ret && ret[0] && ret[1] && ret[0]->type == attr_route && ret[1]->type == attr_vehicleprofile) {
struct tracking *tracking=get_tracking();
m_route=*ret[0];
m_vehicleprofile=*ret[1];
@@ -798,7 +762,7 @@ GuidanceObj::GuidanceObj(GuidanceServerStub *guidance, uint32_t SessionHandle, u
vehicle_set_attr(demo, &m_route);
vehicle_set_attr(demo, &vehicle_speed);
}
- navigation_set_route(get_navigation(), m_route.u.route);
+ navigation_set_route(get_navigation(), m_route.u.route);
tracking_set_route(get_tracking(), m_route.u.route);
navigation_register_callback(get_navigation(), attr_navigation_speech, m_guidance_callback);
GuidanceObj_Callback(this);
diff --git a/src/navigation/navigation-core/routing-server-plugin/genivi_navigationcore_routing.cxx b/src/navigation/navigation-core/routing-server-plugin/genivi_navigationcore_routing.cxx
index 5032f36..0355d01 100644
--- a/src/navigation/navigation-core/routing-server-plugin/genivi_navigationcore_routing.cxx
+++ b/src/navigation/navigation-core/routing-server-plugin/genivi_navigationcore_routing.cxx
@@ -112,7 +112,7 @@ private:
struct tracking *get_tracking(void);
};
-static std::map<uint32_t, RoutingObj *> mp_handles;
+static std::map<NavigationTypes::Handle, RoutingObj *> mp_handles;
static bool commands_registered;
@@ -121,12 +121,12 @@ navit_genivi_get_route(struct navit *nav, char *function, struct attr **in, stru
{
if (!out || !in || !in[0])
return;
- if (!ATTR_IS_INT(in[0]->type))
+ if (!ATTR_IS_INT(in[0]->type))
return;
RoutingObj *obj=mp_handles[in[0]->u.num];
if (!obj)
return;
- *out=attr_generic_add_attr(*out, &obj->m_route);
+ *out=attr_generic_add_attr(*out, &obj->m_route);
*out=attr_generic_add_attr(*out, &obj->m_vehicleprofile);
}
@@ -465,7 +465,6 @@ class RoutingServerStub : public RoutingStubDefault
private:
CommonTypes::Version m_version;
- std::map<NavigationTypes::Handle, RoutingObj *> mp_handles;
};
diff --git a/test/navigation/route.xml b/test/navigation/route.xml
index aceb343..eecf596 100644
--- a/test/navigation/route.xml
+++ b/test/navigation/route.xml
@@ -1,36 +1,10 @@
<route-set country="Switzerland">
<route>
-<start>"Zuerich"</start>
-<destination>"Bern"</destination>
-<name>"Route ZÜRICH to BERN"</name>
-<handle>0</handle>
-</route>
-<route>
<start>"Geneve"</start>
<destination>"Neuchatel"</destination>
<name>"Route GENEVE to NEUCHATEL"</name>
<handle>0</handle>
</route>
-<route>
-<start>"Zuerich"</start>
-<destination>"Neuchatel"</destination>
-<name>"Route ZÜRICH to NEUCHATEL"</name>
-<handle>0</handle>
-</route>
-<route>
-<start>"Bern"</start>
-<destination>"Geneve"</destination>
-<name>"Route BERN to GENEVE"</name>
-<handle>0</handle>
-</route>
-<location name='"Zuerich"'>
-<latitude>47.367264</latitude>
-<longitude>8.550330</longitude>
-</location>
-<location name='"Bern"'>
-<latitude>46.948108</latitude>
-<longitude>7.444643</longitude>
-</location>
<location name='"Geneve"'>
<latitude>46.206659</latitude>
<longitude>6.1410842</longitude>
diff --git a/test/navigation/routes.xml b/test/navigation/routes.xml
new file mode 100644
index 0000000..aceb343
--- /dev/null
+++ b/test/navigation/routes.xml
@@ -0,0 +1,43 @@
+<route-set country="Switzerland">
+<route>
+<start>"Zuerich"</start>
+<destination>"Bern"</destination>
+<name>"Route ZÜRICH to BERN"</name>
+<handle>0</handle>
+</route>
+<route>
+<start>"Geneve"</start>
+<destination>"Neuchatel"</destination>
+<name>"Route GENEVE to NEUCHATEL"</name>
+<handle>0</handle>
+</route>
+<route>
+<start>"Zuerich"</start>
+<destination>"Neuchatel"</destination>
+<name>"Route ZÜRICH to NEUCHATEL"</name>
+<handle>0</handle>
+</route>
+<route>
+<start>"Bern"</start>
+<destination>"Geneve"</destination>
+<name>"Route BERN to GENEVE"</name>
+<handle>0</handle>
+</route>
+<location name='"Zuerich"'>
+<latitude>47.367264</latitude>
+<longitude>8.550330</longitude>
+</location>
+<location name='"Bern"'>
+<latitude>46.948108</latitude>
+<longitude>7.444643</longitude>
+</location>
+<location name='"Geneve"'>
+<latitude>46.206659</latitude>
+<longitude>6.1410842</longitude>
+</location>
+<location name='"Neuchatel"'>
+<latitude>46.990585</latitude>
+<longitude>6.928453</longitude>
+</location>
+</route-set><!--NB: don't use accent.-->
+
diff --git a/test/navigation/test-guidance-capi.py b/test/navigation/test-guidance-capi.py
new file mode 100755
index 0000000..80762ca
--- /dev/null
+++ b/test/navigation/test-guidance-capi.py
@@ -0,0 +1,328 @@
+#!/usr/bin/python
+
+"""
+**************************************************************************
+* @licence app begin@
+* SPDX-License-Identifier: MPL-2.0
+*
+* \copyright Copyright (C) 2016, XS Embedded GmbH, PCA Peugeot Citroen
+*
+* \file test-guidance-capi.py
+*
+* \brief This simple test shows how the guidance
+* could be easily tested using a python script
+*
+* \author Marco Residori <marco.residori@xse.de>
+* \author Philippe Colliot <philippe.colliot@mpsa.com>
+*
+* \version 1.1
+*
+* This Source Code Form is subject to the terms of the
+* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+# this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+* List of changes:
+*
+* @licence end@
+**************************************************************************
+"""
+
+import dbus
+import gobject
+import dbus.mainloop.glib
+from collections import namedtuple,defaultdict
+from _dbus_bindings import Int32
+from PIL.GimpGradientFile import SEGMENTS
+from xml.dom.minidom import parse
+import xml.dom.minidom
+import argparse
+import sys
+import errno
+import time
+
+#import pdb;pdb.set_trace()
+
+from pip import locations
+
+#constants as defined in the Navigation API
+GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0
+GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1
+GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e
+GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f
+GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147
+GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141
+GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142
+GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143
+GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144
+GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148
+GENIVI_NAVIGATIONCORE_TIME = 0x0149
+GENIVI_NAVIGATIONCORE_SPEED = 0x00a4
+GENIVI_NAVIGATIONCORE_ACTIVE = 0x0060
+
+#constants used into the script
+TIME_OUT = 10000
+HORIZONTAL_SIZE = 800
+VERTICAL_SIZE = 480
+MAIN_MAP = 0x0010
+NUMBER_OF_SEGMENTS = 500
+
+#add signal receivers
+def catchall_routing_routeCalculationProgressUpdate_handler(routeHandle, status, percentage):
+ print 'Route Calculation: ' + str(int(percentage)) + ' %'
+
+def catchall_routing_routeCalculationSuccessful_handler(routeHandle,unfullfilledPreferences):
+ global g_guidance_active
+ print 'Route Calculation Successfull: ' + str(routeHandle)
+ #get route overview
+ overview = g_routing_interface.getRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]))
+ #retrieve distance
+ totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)])
+ print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km'
+ totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])
+ m, s = divmod(totalTime[1], 60)
+ h, m = divmod(m, 60)
+ print "Total Time: %d:%02d:%02d" % (h, m, s)
+ #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments)
+ valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_TIME),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)]
+ numberOfSegments = NUMBER_OF_SEGMENTS
+ detailLevel = 0
+ offset = 0
+ ret = g_routing_interface.getRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(detailLevel),dbus.Array(valuesToReturn),dbus.UInt32(numberOfSegments),dbus.UInt32(offset))
+ print "Total number of segments: " + str(ret[0])
+ #len(ret[1]) is size
+ #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude
+ g_guidance_active = True
+# pdb.set_trace()
+# display_route(routeHandle)
+ launch_guidance(routeHandle)
+
+def catchall_session_sessionDeleted_handler(sessionHandle):
+ print('Session handle deleted: '+str(sessionHandle))
+ if sessionHandle == g_navigationcore_session_handle:
+ print 'Test PASSED'
+ else:
+ print 'Test FAILED'
+ loop.quit()
+
+def catchall_routing_routeDeleted_handler(routeHandle):
+ print('Route handle deleted: '+str(routeHandle))
+
+def catchall_guidance_guidanceStatusChanged_handler(guidanceStatus,routeHandle):
+ global g_guidance_active
+ print('Guidance status changed: '+str(guidanceStatus))
+ if guidanceStatus != GENIVI_NAVIGATIONCORE_ACTIVE and g_guidance_active == True:
+ g_guidance_active = False
+ route = g_current_route + 1
+ if route < routes.length:
+ launch_route_calculation(route)
+ else:
+ for i in range(routes.length):
+ g_routing_interface.deleteRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data))
+ g_navigationcore_session_interface.deleteSession(dbus.UInt32(g_navigationcore_session_handle))
+
+def catchall_guidance_positionOnRouteChanged_handler(offsetOnRoute):
+ print "Offset on route: " +str(offsetOnRoute)
+ ret = g_guidance_interface.getDestinationInformation()
+ print "Travel time: " +str(ret[1])
+ ret = g_guidance_interface.getManeuversList(dbus.UInt16(10),dbus.UInt32(0))
+ print "Number of maneuvers: " +str(ret[0])
+ g_mapmatchedposition_interface.setSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(False))
+ g_guidance_interface.stopGuidance(dbus.UInt32(g_navigationcore_session_handle))
+
+def catchall_mapmatchedposition_simulationStatusChanged_handler(simulationStatus):
+ print "Simulation status: " +str(simulationStatus)
+
+#timeout
+def timeout():
+ print 'Timeout Expired'
+ print '\nTest FAILED'
+ loop.quit()
+
+def display_route(route):
+ g_mapviewercontrol_interface.displayRoute( \
+ dbus.UInt32(g_mapviewer_sessionhandle), \
+ dbus.UInt32(g_mapviewer_maphandle), \
+ dbus.UInt32(route), \
+ dbus.Boolean(True))
+
+def launch_guidance(route):
+ g_mapmatchedposition_interface.setSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(True))
+ g_guidance_interface.startGuidance(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(route))
+# g_mapmatchedposition_interface.startSimulation(g_navigationcore_session_handle)
+
+def launch_route_calculation(route):
+ global g_current_route
+ global g_route_handle
+ global g_routing_interface
+ global g_navigationcore_session_handle
+ g_current_route = route
+ print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data
+ #get route handle
+ g_route_handle = g_routing_interface.createRoute(dbus.UInt32(g_navigationcore_session_handle))
+ routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle
+ print 'Route handle: ' + str(g_route_handle)
+ start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data
+ dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data
+ print 'Calculating route from \
+'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \
+'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')'
+ #set waypoints
+ waypointDoubleCapiType = 0x03
+ g_routing_interface.setWaypoints(dbus.UInt32(g_navigationcore_session_handle), \
+ dbus.UInt32(g_route_handle), \
+ dbus.Boolean(0), \
+ dbus.Array([ \
+ dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \
+ dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \
+ ]) \
+ )
+
+ #calculate route
+ g_routing_interface.calculateRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_route_handle))
+
+def createMapView():
+ global g_mapviewer_sessionhandle
+ global g_mapviewer_sessionstatus
+ global g_mapviewer_sessionlist
+ global g_mapviewer_maphandle
+
+ #get mapviewer session handle
+ g_mapviewer_sessionhandle = g_mapviewer_session_interface.createSession(dbus.String('test mapviewer'))
+ print 'Mapviewer session handle: ' + str(g_mapviewer_sessionhandle)
+
+ g_mapviewer_sessionstatus = g_mapviewer_session_interface.getSessionStatus(dbus.UInt32(g_mapviewer_sessionhandle));
+ print 'Mapviewer session status: ' + str(g_mapviewer_sessionstatus)
+
+ g_mapviewer_sessionlist = g_mapviewer_session_interface.getAllSessions();
+ print 'Mapviewer active sessions = ' + str(len(g_mapviewer_sessionlist))
+
+ #get mapviewer handle
+ g_mapviewer_maphandle = g_mapviewercontrol_interface.createMapViewInstance( \
+ dbus.UInt32(g_mapviewer_sessionhandle), \
+ dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \
+ dbus.Int32(MAIN_MAP))
+
+ print 'MapView handle: ' + str(g_mapviewer_maphandle)
+
+ time.sleep(2)
+
+ print 'Stop following the car position'
+ g_mapviewercontrol_interface.setFollowCarMode( \
+ dbus.UInt32(g_mapviewer_sessionhandle), \
+ dbus.UInt32(g_mapviewer_maphandle), \
+ dbus.Boolean(False))
+
+def deleteMapView():
+ g_mapviewercontrol_interface.releaseMapViewInstance( \
+ dbus.UInt32(g_mapviewer_sessionhandle), \
+ dbus.UInt32(g_mapviewer_maphandle))
+
+ g_mapviewer_session_interface.deleteSession(g_mapviewer_sessionhandle)
+
+
+print('--------------------------')
+print('Guidance Test')
+print('--------------------------')
+
+parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.')
+parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format')
+args = parser.parse_args()
+
+if args.routes == None:
+ print('route file is missing')
+ sys.exit(1)
+else:
+ try:
+ DOMTree = xml.dom.minidom.parse(args.routes)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ print('file not exists')
+ sys.exit(1)
+ route_set = DOMTree.documentElement
+
+print("Country : %s" % route_set.getAttribute("country"))
+
+routes = route_set.getElementsByTagName("route")
+
+#create dictionary with the locations
+locations = {}
+for location in route_set.getElementsByTagName("location"):
+ lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data]
+ locations[location.getAttribute("name")] = lat_long
+
+if __name__ == '__main__':
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+#connect to session bus
+bus = dbus.SessionBus()
+
+bus.add_signal_receiver(catchall_routing_routeCalculationProgressUpdate_handler, \
+ dbus_interface = "org.genivi.navigation.navigationcore.Routing", \
+ signal_name = "routeCalculationProgressUpdate")
+
+bus.add_signal_receiver(catchall_routing_routeCalculationSuccessful_handler, \
+ dbus_interface = "org.genivi.navigation.navigationcore.Routing", \
+ signal_name = "routeCalculationSuccessful")
+
+bus.add_signal_receiver(catchall_routing_routeDeleted_handler, \
+ dbus_interface = "org.genivi.navigation.navigationcore.Routing", \
+ signal_name = "routeDeleted")
+
+bus.add_signal_receiver(catchall_session_sessionDeleted_handler, \
+ dbus_interface = "org.genivi.navigation.navigationcore.Session", \
+ signal_name = "sessionDeleted")
+
+bus.add_signal_receiver(catchall_guidance_guidanceStatusChanged_handler, \
+ dbus_interface = "org.genivi.navigation.navigationcore.Guidance", \
+ signal_name = "guidanceStatusChanged")
+
+bus.add_signal_receiver(catchall_guidance_positionOnRouteChanged_handler, \
+ dbus_interface = "org.genivi.navigation.navigationcore.Guidance", \
+ signal_name = "positionOnRouteChanged")
+
+bus.add_signal_receiver(catchall_mapmatchedposition_simulationStatusChanged_handler, \
+ dbus_interface = "org.genivi.navigation.navigationcore.MapMatchedPosition", \
+ signal_name = "simulationStatusChanged")
+
+navigationcore_session_obj = bus.get_object('org.genivi.navigation.navigationcore.Session_Session','/Session')
+g_navigationcore_session_interface = dbus.Interface(navigationcore_session_obj, dbus_interface='org.genivi.navigation.navigationcore.Session')
+
+routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing_Routing','/Routing')
+g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing')
+
+guidance_obj = bus.get_object('org.genivi.navigation.navigationcore.Guidance_Guidance','/Guidance')
+g_guidance_interface = dbus.Interface(guidance_obj, dbus_interface='org.genivi.navigation.navigationcore.Guidance')
+
+mapviewer_session_obj = bus.get_object('org.genivi.navigation.mapviewer.Session_Session','/Session')
+g_mapviewer_session_interface = dbus.Interface(mapviewer_session_obj, dbus_interface='org.genivi.navigation.mapviewer.Session')
+
+g_mapviewercontrol_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl_MapViewerControl','/MapViewerControl')
+g_mapviewercontrol_interface = dbus.Interface(g_mapviewercontrol_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl')
+
+g_mapmatchedposition_obj = bus.get_object('org.genivi.navigation.navigationcore.MapMatchedPosition_MapMatchedPosition','/MapMatchedPosition')
+g_mapmatchedposition_interface = dbus.Interface(g_mapmatchedposition_obj, dbus_interface='org.genivi.navigation.navigationcore.MapMatchedPosition')
+
+#get navigationcore session handle
+g_navigationcore_session_handle = g_navigationcore_session_interface.createSession(dbus.String("test guidance"))
+print 'Navigation core session handle: ' + str(g_navigationcore_session_handle)
+
+#createMapView()
+
+g_current_route = 0
+g_guidance_active = False
+launch_route_calculation(0)
+
+#main loop
+gobject.timeout_add(TIME_OUT, timeout)
+loop = gobject.MainLoop()
+loop.run()
+
+#deleteMapView()
diff --git a/test/navigation/test-guidance.py b/test/navigation/test-guidance.py
new file mode 100755
index 0000000..95b2f66
--- /dev/null
+++ b/test/navigation/test-guidance.py
@@ -0,0 +1,329 @@
+#!/usr/bin/python
+
+"""
+**************************************************************************
+* @licence app begin@
+* SPDX-License-Identifier: MPL-2.0
+*
+* \copyright Copyright (C) 2016, XS Embedded GmbH, PCA Peugeot Citroen
+*
+* \file test-guidance.py
+*
+* \brief This simple test shows how the guidance
+* could be easily tested using a python script
+*
+* \author Marco Residori <marco.residori@xse.de>
+* \author Philippe Colliot <philippe.colliot@mpsa.com>
+*
+* \version 1.1
+*
+* This Source Code Form is subject to the terms of the
+* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+# this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+* List of changes:
+*
+* @licence end@
+**************************************************************************
+"""
+
+import dbus
+import gobject
+import dbus.mainloop.glib
+from collections import namedtuple,defaultdict
+from _dbus_bindings import Int32
+from PIL.GimpGradientFile import SEGMENTS
+from xml.dom.minidom import parse
+import xml.dom.minidom
+import argparse
+import sys
+import errno
+import time
+
+#import pdb;pdb.set_trace()
+
+from pip import locations
+
+#constants as defined in the Navigation API
+GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0
+GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1
+GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e
+GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f
+GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147
+GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141
+GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142
+GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143
+GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144
+GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148
+GENIVI_NAVIGATIONCORE_TIME = 0x0149
+GENIVI_NAVIGATIONCORE_SPEED = 0x00a4
+GENIVI_NAVIGATIONCORE_ACTIVE = 0x0060
+
+#constants used into the script
+TIME_OUT = 10000
+HORIZONTAL_SIZE = 800
+VERTICAL_SIZE = 480
+MAIN_MAP = 0x0010
+NUMBER_OF_SEGMENTS = 500
+
+#add signal receivers
+def catchall_routing_routeCalculationProgressUpdate_handler(routeHandle, status, percentage):
+ print 'Route Calculation: ' + str(int(percentage)) + ' %'
+
+def catchall_routing_routeCalculationSuccessful_handler(routeHandle,unfullfilledPreferences):
+ global g_guidance_active
+ print 'Route Calculation Successfull: ' + str(routeHandle)
+ #get route overview
+ overview = g_routing_interface.GetRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]))
+ #retrieve distance
+ totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)])
+ print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km'
+ totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])
+ m, s = divmod(totalTime[1], 60)
+ h, m = divmod(m, 60)
+ print "Total Time: %d:%02d:%02d" % (h, m, s)
+ #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments)
+ valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_TIME),
+ dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)]
+ numberOfSegments = NUMBER_OF_SEGMENTS
+ detailLevel = 0
+ offset = 0
+ ret = g_routing_interface.GetRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(detailLevel),dbus.Array(valuesToReturn),dbus.UInt32(numberOfSegments),dbus.UInt32(offset))
+ print "Total number of segments: " + str(ret[0])
+ #len(ret[1]) is size
+ #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude
+ g_guidance_active = True
+# pdb.set_trace()
+# display_route(routeHandle)
+ launch_guidance(routeHandle)
+
+def catchall_session_sessionDeleted_handler(sessionHandle):
+ print('Session handle deleted: '+str(sessionHandle))
+ if sessionHandle == g_navigationcore_session_handle:
+ print 'Test PASSED'
+ else:
+ print 'Test FAILED'
+ loop.quit()
+
+def catchall_routing_routeDeleted_handler(routeHandle):
+ print('Route handle deleted: '+str(routeHandle))
+
+def catchall_guidance_guidanceStatusChanged_handler(guidanceStatus,routeHandle):
+ global g_guidance_active
+ print('Guidance status changed: '+str(guidanceStatus))
+ if guidanceStatus != GENIVI_NAVIGATIONCORE_ACTIVE and g_guidance_active == True:
+ g_guidance_active = False
+ route = g_current_route + 1
+ if route < routes.length:
+ launch_route_calculation(route)
+ else:
+ for i in range(routes.length):
+ g_routing_interface.DeleteRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data))
+ g_navigationcore_session_interface.DeleteSession(dbus.UInt32(g_navigationcore_session_handle))
+
+def catchall_guidance_positionOnRouteChanged_handler(offsetOnRoute):
+ print "Offset on route: " +str(offsetOnRoute)
+ ret = g_guidance_interface.GetDestinationInformation()
+ print "Travel time: " +str(ret[1])
+ ret = g_guidance_interface.GetManeuversList(dbus.UInt16(10),dbus.UInt32(0))
+ print "Number of maneuvers: " +str(ret[0])
+ g_mapmatchedposition_interface.SetSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(False))
+ g_guidance_interface.StopGuidance(dbus.UInt32(g_navigationcore_session_handle))
+
+def catchall_mapmatchedposition_simulationStatusChanged_handler(simulationStatus):
+ print "Simulation status: " +str(simulationStatus)
+
+#timeout
+
+def timeout():
+ print 'Timeout Expired'
+ print '\nTest FAILED'
+ loop.quit()
+
+def display_route(route):
+ g_mapviewercontrol_interface.DisplayRoute( \
+ dbus.UInt32(g_mapviewer_sessionhandle), \
+ dbus.UInt32(g_mapviewer_maphandle), \
+ dbus.UInt32(route), \
+ dbus.Boolean(True))
+
+def launch_guidance(route):
+ g_mapmatchedposition_interface.SetSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(True))
+ g_guidance_interface.StartGuidance(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(route))
+# g_mapmatchedposition_interface.StartSimulation(g_navigationcore_session_handle)
+
+def launch_route_calculation(route):
+ global g_current_route
+ global g_route_handle
+ global g_routing_interface
+ global g_navigationcore_session_handle
+ g_current_route = route
+ print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data
+ #get route handle
+ g_route_handle = g_routing_interface.CreateRoute(dbus.UInt32(g_navigationcore_session_handle))
+ routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle
+ print 'Route handle: ' + str(g_route_handle)
+ start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data
+ dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data
+ print 'Calculating route from \
+'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \
+'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')'
+ #set waypoints
+ waypointDoubleCapiType = 0x03
+ g_routing_interface.SetWaypoints(dbus.UInt32(g_navigationcore_session_handle), \
+ dbus.UInt32(g_route_handle), \
+ dbus.Boolean(0), \
+ dbus.Array([ \
+ dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \
+ dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \
+ ]) \
+ )
+
+ #calculate route
+ g_routing_interface.CalculateRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_route_handle))
+
+def createMapView():
+ global g_mapviewer_sessionhandle
+ global g_mapviewer_sessionstatus
+ global g_mapviewer_sessionlist
+ global g_mapviewer_maphandle
+
+ #get mapviewer session handle
+ g_mapviewer_sessionhandle = g_mapviewer_session_interface.CreateSession(dbus.String('test mapviewer'))
+ print 'Mapviewer session handle: ' + str(g_mapviewer_sessionhandle)
+
+ g_mapviewer_sessionstatus = g_mapviewer_session_interface.GetSessionStatus(dbus.UInt32(g_mapviewer_sessionhandle));
+ print 'Mapviewer session status: ' + str(g_mapviewer_sessionstatus)
+
+ g_mapviewer_sessionlist = g_mapviewer_session_interface.GetAllSessions();
+ print 'Mapviewer active sessions = ' + str(len(g_mapviewer_sessionlist))
+
+ #get mapviewer handle
+ g_mapviewer_maphandle = g_mapviewercontrol_interface.CreateMapViewInstance( \
+ dbus.UInt32(g_mapviewer_sessionhandle), \
+ dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \
+ dbus.Int32(MAIN_MAP))
+
+ print 'MapView handle: ' + str(g_mapviewer_maphandle)
+
+ time.sleep(2)
+
+ print 'Stop following the car position'
+ g_mapviewercontrol_interface.SetFollowCarMode( \
+ dbus.UInt32(g_mapviewer_sessionhandle), \
+ dbus.UInt32(g_mapviewer_maphandle), \
+ dbus.Boolean(False))
+
+def deleteMapView():
+ g_mapviewercontrol_interface.ReleaseMapViewInstance( \
+ dbus.UInt32(g_mapviewer_sessionhandle), \
+ dbus.UInt32(g_mapviewer_maphandle))
+
+ g_mapviewer_session_interface.DeleteSession(g_mapviewer_sessionhandle)
+
+
+print('--------------------------')
+print('Guidance Test')
+print('--------------------------')
+
+parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.')
+parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format')
+args = parser.parse_args()
+
+if args.routes == None:
+ print('route file is missing')
+ sys.exit(1)
+else:
+ try:
+ DOMTree = xml.dom.minidom.parse(args.routes)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ print('file not exists')
+ sys.exit(1)
+ route_set = DOMTree.documentElement
+
+print("Country : %s" % route_set.getAttribute("country"))
+
+routes = route_set.getElementsByTagName("route")
+
+#create dictionary with the locations
+locations = {}
+for location in route_set.getElementsByTagName("location"):
+ lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data]
+ locations[location.getAttribute("name")] = lat_long
+
+if __name__ == '__main__':
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+#connect to session bus
+bus = dbus.SessionBus()
+
+bus.add_signal_receiver(catchall_routing_routeCalculationProgressUpdate_handler, \
+ dbus_interface = "org.genivi.navigationcore.Routing", \
+ signal_name = "RouteCalculationProgressUpdate")
+
+bus.add_signal_receiver(catchall_routing_routeCalculationSuccessful_handler, \
+ dbus_interface = "org.genivi.navigationcore.Routing", \
+ signal_name = "RouteCalculationSuccessful")
+
+bus.add_signal_receiver(catchall_routing_routeDeleted_handler, \
+ dbus_interface = "org.genivi.navigationcore.Routing", \
+ signal_name = "RouteDeleted")
+
+bus.add_signal_receiver(catchall_session_sessionDeleted_handler, \
+ dbus_interface = "org.genivi.navigationcore.Session", \
+ signal_name = "SessionDeleted")
+
+bus.add_signal_receiver(catchall_guidance_guidanceStatusChanged_handler, \
+ dbus_interface = "org.genivi.navigationcore.Guidance", \
+ signal_name = "GuidanceStatusChanged")
+
+bus.add_signal_receiver(catchall_guidance_positionOnRouteChanged_handler, \
+ dbus_interface = "org.genivi.navigationcore.Guidance", \
+ signal_name = "PositionOnRouteChanged")
+
+bus.add_signal_receiver(catchall_mapmatchedposition_simulationStatusChanged_handler, \
+ dbus_interface = "org.genivi.navigationcore.MapMatchedPosition", \
+ signal_name = "SimulationStatusChanged")
+
+navigationcore_session_obj = bus.get_object('org.genivi.navigationcore.Session','/org/genivi/navigationcore')
+g_navigationcore_session_interface = dbus.Interface(navigationcore_session_obj, dbus_interface='org.genivi.navigationcore.Session')
+
+routing_obj = bus.get_object('org.genivi.navigationcore.Routing','/org/genivi/navigationcore')
+g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigationcore.Routing')
+
+guidance_obj = bus.get_object('org.genivi.navigationcore.Guidance','/org/genivi/navigationcore')
+g_guidance_interface = dbus.Interface(guidance_obj, dbus_interface='org.genivi.navigationcore.Guidance')
+
+mapviewer_session_obj = bus.get_object('org.genivi.mapviewer.Session','/org/genivi/mapviewer')
+g_mapviewer_session_interface = dbus.Interface(mapviewer_session_obj, dbus_interface='org.genivi.mapviewer.Session')
+
+g_mapviewercontrol_obj = bus.get_object('org.genivi.mapviewer.MapViewerControl','/org/genivi/mapviewer')
+g_mapviewercontrol_interface = dbus.Interface(g_mapviewercontrol_obj, dbus_interface='org.genivi.mapviewer.MapViewerControl')
+
+g_mapmatchedposition_obj = bus.get_object('org.genivi.navigationcore.MapMatchedPosition','/org/genivi/navigationcore')
+g_mapmatchedposition_interface = dbus.Interface(g_mapmatchedposition_obj, dbus_interface='org.genivi.navigationcore.MapMatchedPosition')
+
+#get navigationcore session handle
+g_navigationcore_session_handle = g_navigationcore_session_interface.CreateSession(dbus.String("test guidance"))
+print 'Navigation core session handle: ' + str(g_navigationcore_session_handle)
+
+#createMapView()
+
+g_current_route = 0
+g_guidance_active = False
+launch_route_calculation(0)
+
+#main loop
+gobject.timeout_add(TIME_OUT, timeout)
+loop = gobject.MainLoop()
+loop.run()
+
+#deleteMapView()