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
|
#!/usr/bin/python
"""
**************************************************************************
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
* \copyright Copyright (C) 2014, PCA Peugeot Citroen
*
* \file intensive-testing.py
*
* \brief This script tests the enhanced position by using the logreplayer at a given frame rate.
*
* \author Philippe Colliot <philippe.colliot@mpsa.com>
*
* \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 sys,tty,termios,select,gobject,time,dbus,re,argparse,subprocess,signal
from subprocess import call
from subprocess import Popen
from threading import Timer
from enum import Enum
from dbus.mainloop.glib import DBusGMainLoop
from traceback import print_exc
# Define some constants
DURATION_TESTING = 20000 #in ms
PATH_LOGFILES='./'
def startEnhancedPositionServer():
global pathEnhancedposition
enhancedposition=pathEnhancedposition + 'enhanced-position-service'
arguments='> /dev/null 2>&1 &'
pid = Popen([enhancedposition, arguments])
return pid
def launchLog(file):
global pathLogreplayer
logreplayer=pathLogreplayer + 'log-replayer'
file=PATH_LOGFILES + file
arguments='> /dev/null 2>&1 &'
call([logreplayer, file, arguments])
class Genivi(Enum):
ENHANCEDPOSITIONSERVICE_LATITUDE = 0x0020
ENHANCEDPOSITIONSERVICE_LONGITUDE = 0x0021
ENHANCEDPOSITIONSERVICE_ALTITUDE = 0x0022
def loopDbus():
global testCounter
# launch the logreplayer with test file
launchLog("test.log")
# get the geolocation
geoLocation = enhancedPositionInterface.GetData(dbus.Array([Genivi.ENHANCEDPOSITIONSERVICE_LATITUDE,Genivi.ENHANCEDPOSITIONSERVICE_LONGITUDE]))
latitude=float(geoLocation[dbus.UInt16(Genivi.ENHANCEDPOSITIONSERVICE_LATITUDE)])
longitude=float(geoLocation[dbus.UInt16(Genivi.ENHANCEDPOSITIONSERVICE_LONGITUDE)])
testCounter += 1
print str(testCounter), str(latitude), str(longitude)
if testCounter >= maxLoopTesting:
cleanExit()
return True
def cleanExit():
global enhancedpositionPid
enhancedpositionPid.kill()
sys.exit(1)
def exitProg(signum, frame):
# restore the original signal handler and exit
signal.signal(signal.SIGINT, original_sigint)
cleanExit()
# Main program begins here
parser = argparse.ArgumentParser(description='Intensive testing of enhanced position.')
parser.add_argument('-p','--path',action='store', dest='path', help='Path for the bin of positioning')
parser.add_argument('-f','--frame',action='store', dest='frame', type=int, help='Number of messages per second')
args = parser.parse_args()
if args.path == None:
pathEnhancedposition='../../src/navigation/bin/positioning/enhanced-position-service/src/'
pathLogreplayer='../../src/navigation/bin/positioning/log-replayer/src/'
else:
pathEnhancedposition = args.path + 'bin/positioning/enhanced-position-service/src/'
pathLogreplayer= args.path + 'bin/positioning/log-replayer/src/'
if args.frame == None:
periodicityTesting = 200 #in ms
else:
periodicityTesting = 1000/args.frame #in ms
maxLoopTesting = DURATION_TESTING/periodicityTesting
# Start the enhanced position server
enhancedpositionPid = startEnhancedPositionServer()
time.sleep(.5)
# Initialize DBus loop as the main loop
DBusGMainLoop(set_as_default=True)
# Connect on the bus
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
dbusConnectionBus = dbus.SessionBus()
# Enhanced position
try:
enhancedPositionObject = dbusConnectionBus.get_object("org.genivi.positioning.EnhancedPosition", "/org/genivi/positioning/EnhancedPosition")
except dbus.DBusException:
print "connection to Enhanced position failed"
print_exc()
cleanExit()
enhancedPositionInterface = dbus.Interface(enhancedPositionObject, "org.genivi.positioning.EnhancedPosition")
# Start
testCounter=0
original_sigint = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, exitProg)
gobject.timeout_add(periodicityTesting,loopDbus)
loop = gobject.MainLoop()
loop.run()
|