summaryrefslogtreecommitdiff
path: root/test/navigation/test-route-calculation.py
blob: f26c31cc2f44f536f02d570d9c908ccdd9963674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python

"""
**************************************************************************
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
* \copyright Copyright (C) 2014, XS Embedded GmbH
*
* \file simulation-dashboard.py
*
* \brief This simple test shows how the route calculation 
*              could be easily tested using a python script
*
* \author Marco Residori <marco.residori@xse.de>
*
* \version 1.0
*
* 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:
* <date>, <name>, <description of change>
*
* @licence end@
**************************************************************************
"""


import dbus
import gobject
import dbus.mainloop.glib

#constants as defined in the Navigation API
LATITUDE = 0x00a0
LONGITUDE = 0x00a1
TOTAL_DISTANCE = 0x018f

print '\n--------------------------'
print 'Route Calculation Test'
print '--------------------------\n'

if __name__ == '__main__':
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 

#connect to session bus
bus = dbus.SessionBus()

#signal receiver
def catchall_route_calculation_signals_handler(routeHandle, status, percentage):
    print 'Route Calculation: ' + str(int(percentage)) + ' %'
    if int(percentage) == 100:
        #get route overview
        overview = routing_interface.GetRouteOverview(dbus.UInt32(routehandle),dbus.Array([dbus.UInt16(399)]))
        #retrieve distance 
        totalDistance = int(overview[dbus.UInt16(TOTAL_DISTANCE)])
        print 'Total Distance: ' + str(totalDistance) + ' m'
        #check distance
        if totalDistance < 100000 or totalDistance > 150000:
            print '\nTest FAILED\n'
        else:
            print '\nTest PASSED\n'
        loop.quit()

#add signal receiver
bus.add_signal_receiver(catchall_route_calculation_signals_handler, \
                        dbus_interface = "org.genivi.navigationcore.Routing", \
                        signal_name = "RouteCalculationProgressUpdate")

#timeout
def timeout():
    print 'Timeout Expired'
    print '\nTest FAILED\n'
    loop.quit()

session = bus.get_object('org.genivi.navigationcore.Session','/org/genivi/navigationcore')
session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigationcore.Session')

#get session handle
sessionhandle = session_interface.CreateSession(dbus.String("test route calculation"))
print 'Session handle: ' + str(sessionhandle)

routing_obj = bus.get_object('org.genivi.navigationcore.Routing','/org/genivi/navigationcore')
routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigationcore.Routing')

#get route handle
routehandle = routing_interface.CreateRoute(dbus.UInt32(sessionhandle)) 
print 'Route handle: ' + str(routehandle)

#route Zuerich->Bern (125Km)
lat1 = 47.3673
lon1 = 8.5500
lat2 = 46.9479
lon2 = 7.4446

print 'Calculating route from \
A(' + str(lat1) + ',' + str(lon1) + ') to \
B(' + str(lat2) + ',' + str(lon2) + ')' 

#set waypoints
routing_interface.SetWaypoints(dbus.UInt32(sessionhandle), \
                               dbus.UInt32(routehandle), \
                               dbus.Boolean(0), \
                               dbus.Array([ \
                                    dbus.Dictionary({dbus.UInt16(LATITUDE):dbus.Double(lat1),dbus.UInt16(LONGITUDE):dbus.Double(lon1)}), \
                                    dbus.Dictionary({dbus.UInt16(LATITUDE):dbus.Double(lat2),dbus.UInt16(LONGITUDE):dbus.Double(lon2)}) \
                               ]) \
                               )

#calculate route
routing_interface.CalculateRoute(dbus.UInt32(sessionhandle),dbus.UInt32(routehandle))

#main loop 
gobject.timeout_add(5000, timeout)
loop = gobject.MainLoop()
loop.run()