summaryrefslogtreecommitdiff
path: root/test/navigation/test-map-viewer-control.py
blob: 1588f5df055a5fe2ea36cc70b4433e6a7ffc7e11 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/python

"""
**************************************************************************
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
* \copyright Copyright (C) 2015, Mentor Graphics
*
* \file test-map-viewer-control.py
*
* \brief This simple test shows how the mapviewer 
*        could be easily tested using a python script
*
* \author Marco Residori <marco.residori@mentor_graphics.com>
* \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:
* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add some methods
*
* @licence end@
**************************************************************************
"""

import dbus
import gobject
import time

#import pdb; pdb.set_trace()

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

MAIN_MAP = 0x0010
SPLIT_SCREEN = 0x0011

#constants used by the script
HORIZONTAL_SIZE = 800
VERTICAL_SIZE = 480

print '\n--------------------------'
print 'MapViewerControl Test'
print '--------------------------\n'

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

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

#get session handle
ret = session_interface.CreateSession(dbus.String("test mapviewer"))
sessionhandle=ret[1]
print 'Session handle: ' + str(sessionhandle)

sessionstatus = session_interface.GetSessionStatus(dbus.UInt32(sessionhandle));
print 'Session status: ' + str(sessionstatus)

sessionlist = session_interface.GetAllSessions();
print 'Active sessions = ' + str(len(sessionlist))

MapViewerControl_obj = bus.get_object('org.genivi.mapviewer.MapViewerControl','/org/genivi/mapviewer')
MapViewerControl_interface = dbus.Interface(MapViewerControl_obj, dbus_interface='org.genivi.mapviewer.MapViewerControl')

#get mapviewer handle
ret = MapViewerControl_interface.CreateMapViewInstance( \
  dbus.UInt32(sessionhandle), \
  dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \
  dbus.Int32(MAIN_MAP))
mapviewerhandle=ret[1]

print 'MapView handle: ' + str(mapviewerhandle)

# Bern
lat1 = 46.9479
lon1 = 7.4446
alt1 = 0

time.sleep(2)

print 'Stop following the car position' 
MapViewerControl_interface.SetFollowCarMode( \
    dbus.UInt32(sessionhandle), \
    dbus.UInt32(mapviewerhandle), \
    dbus.Boolean(False))

print 'Set center in Bern(' + str(lat1) + ',' + str(lon1) + ')' 
MapViewerControl_interface.SetTargetPoint( \
    dbus.UInt32(sessionhandle), \
    dbus.UInt32(mapviewerhandle), \
    dbus.Struct((dbus.Double(lat1),dbus.Double(lon1),dbus.Double(alt1))))

# Get current position
targetPoint = MapViewerControl_interface.GetTargetPoint( \
    dbus.UInt32(mapviewerhandle) )

lat2 = targetPoint[0]
lon2 = targetPoint[1]
alt2 = targetPoint[2]

print 'Get center -> (' + str(lat2) + ',' + str(lon2) + ')'  

if round(lat1,4) != round(lat2,4) :
    print '\nTest Failed:' + str(round(lat1,4)) + '!=' + str(round(lat2,4))  + '\n' 

if round(lon1,4) != round(lon2,4) :
    print '\nTest Failed:' + str(round(lon1,4)) + '!=' + str(round(lon2,4))  + '\n' 

if round(alt1,4) != round(alt2,4) :
    print '\nTest Failed:' + str(round(alt1,4)) + '!=' + str(round(alt2,4))  + '\n'

print 'Zoom in'
MapViewerControl_interface.SetMapViewScaleByDelta( \
    dbus.UInt32(sessionhandle), \
    dbus.UInt32(mapviewerhandle), \
    dbus.Int16(1))

time.sleep(3)

print 'Zoom in'
MapViewerControl_interface.SetMapViewScaleByDelta( \
    dbus.UInt32(sessionhandle), \
    dbus.UInt32(mapviewerhandle), \
    dbus.Int16(1))

time.sleep(3)

print 'Zoom out'
MapViewerControl_interface.SetMapViewScaleByDelta( \
    dbus.UInt32(sessionhandle), \
    dbus.UInt32(mapviewerhandle), \
    dbus.Int16(-1))

time.sleep(3)

print 'Zoom out'
MapViewerControl_interface.SetMapViewScaleByDelta( \
    dbus.UInt32(sessionhandle), \
    dbus.UInt32(mapviewerhandle), \
    dbus.Int16(-1))

time.sleep(3)

MapViewerControl_interface.ReleaseMapViewInstance( \
  dbus.UInt32(sessionhandle), \
  dbus.UInt32(mapviewerhandle))

session_interface.DeleteSession(sessionhandle)

print '\nTest Finished\n'