diff options
author | <philippe colliot> | 2016-04-12 18:04:29 +0200 |
---|---|---|
committer | <philippe colliot> | 2016-04-12 18:04:29 +0200 |
commit | a8db6575908491ea4f7a9bdb9a615b2355f98bcd (patch) | |
tree | 9a905d5e8fb3314f2335b5614bc1408f1e74c15f /test | |
parent | 8a16eebc37dd4ede671b5d21bcc80c7d71c13215 (diff) | |
download | navigation-a8db6575908491ea4f7a9bdb9a615b2355f98bcd.tar.gz |
Add some scripts for testing and fix issue with W3C POC
Diffstat (limited to 'test')
-rw-r--r-- | test/html-based-panel/README.md | 4 | ||||
-rw-r--r-- | test/html-based-panel/node-cpp-lbs-modules/PositioningEnhancedPositionWrapper.cpp | 9 | ||||
-rw-r--r-- | test/html-based-panel/node-cpp-lbs-modules/package.json | 7 | ||||
-rw-r--r-- | test/html-based-panel/server.js | 186 | ||||
-rw-r--r-- | test/html-based-panel/simulation-panel.html | 171 | ||||
-rw-r--r-- | test/resource/high-tank-level.log | 1 | ||||
-rw-r--r-- | test/resource/initialization.log | 1 | ||||
-rw-r--r-- | test/resource/low-tank-level.log | 1 | ||||
-rw-r--r-- | test/resource/start.log | 1 | ||||
-rw-r--r-- | test/resource/test-positioning.log | 1 | ||||
-rwxr-xr-x | test/script/set-position.py | 76 | ||||
-rwxr-xr-x | test/script/set-vehicle-info.py | 76 | ||||
-rwxr-xr-x | test/script/simulation-launch.py | 41 | ||||
-rwxr-xr-x | test/script/test-positioning.py | 265 | ||||
-rw-r--r-- | test/script/test-vehicle-info.py | 278 |
15 files changed, 226 insertions, 892 deletions
diff --git a/test/html-based-panel/README.md b/test/html-based-panel/README.md index 8b76b66..6cdac84 100644 --- a/test/html-based-panel/README.md +++ b/test/html-based-panel/README.md @@ -19,11 +19,7 @@ npm install node-cpp-lbs-modules/node-cpp-lbs-modules-0.1.0.tgz To test: Intall additional modules for nodejs: -<<<<<<< HEAD npm install http url fs path socket.io gcontext python-shell enum -======= -npm install http url fs path socket.io ->>>>>>> branch 'master' of ssh://git-genivi@git.projects.genivi.org/lbs/navigation-application.git Run the server: diff --git a/test/html-based-panel/node-cpp-lbs-modules/PositioningEnhancedPositionWrapper.cpp b/test/html-based-panel/node-cpp-lbs-modules/PositioningEnhancedPositionWrapper.cpp index 03a3d81..413e3c0 100644 --- a/test/html-based-panel/node-cpp-lbs-modules/PositioningEnhancedPositionWrapper.cpp +++ b/test/html-based-panel/node-cpp-lbs-modules/PositioningEnhancedPositionWrapper.cpp @@ -37,14 +37,6 @@ v8::Persistent<v8::Function> PositioningEnhancedPositionWrapper::signalPositionU void PositioningEnhancedPositionWrapper::PositionUpdate(const uint64_t& changedValues) { v8::HandleScope scope; -<<<<<<< HEAD - const int argc = 2; - uint64to32 data; - data.full = changedValues; - v8::Handle<v8::Value> argv[argc]; - argv[0] = v8::Local<v8::Value>::New(v8::Uint32::New(data.p.high)); - argv[1] = v8::Local<v8::Value>::New(v8::Uint32::New(data.p.low)); -======= const unsigned argc = 2; uint64to32 data; data.full = changedValues; @@ -52,7 +44,6 @@ void PositioningEnhancedPositionWrapper::PositionUpdate(const uint64_t& changedV argv[0] = v8::Local<v8::Value>::New(v8::Uint32::New(data.p.high)); argv[1] = v8::Local<v8::Value>::New(v8::Uint32::New(data.p.low)); ->>>>>>> branch 'master' of ssh://git-genivi@git.projects.genivi.org/lbs/navigation-application.git v8::Persistent<v8::Function> fct = static_cast<v8::Function*>(*signalPositionUpdate); fct->Call(v8::Context::GetCurrent()->Global(), argc, argv); } diff --git a/test/html-based-panel/node-cpp-lbs-modules/package.json b/test/html-based-panel/node-cpp-lbs-modules/package.json index bef0cfc..2ae0a08 100644 --- a/test/html-based-panel/node-cpp-lbs-modules/package.json +++ b/test/html-based-panel/node-cpp-lbs-modules/package.json @@ -17,17 +17,10 @@ "url": "0.11.0", "fs": "0.0.2", "path": "", -<<<<<<< HEAD "socket.io": "1.4.5", "gcontext": "0.0.2", "python-shell": "0.4.0", "enum": "2.3.0" -======= - "webidl2": "2.0.11", - "escodegen": "1.8.0", - "socket.io": "1.4.5", - "gcontext": "0.0.2" ->>>>>>> branch 'master' of ssh://git-genivi@git.projects.genivi.org/lbs/navigation-application.git }, "devDependencies": { "chai": "~3.5.0", diff --git a/test/html-based-panel/server.js b/test/html-based-panel/server.js index 63f9a9b..487096b 100644 --- a/test/html-based-panel/server.js +++ b/test/html-based-panel/server.js @@ -4,7 +4,7 @@ * * \copyright Copyright (C) 2016, PCA Peugeot Citroen * -* \file server.js +* \file main.cpp * * \brief This file is part of the Navigation Web API proof of concept. * @@ -33,12 +33,11 @@ var url = require('url'); var fs = require('fs'); var path = require('path'); var gcontext = require('gcontext'); -<<<<<<< HEAD var python_shell = require('python-shell'); var Enum = require('enum'); // Configuration of the python script for simulating log replayer data -var python_script_enum = new Enum(['START', 'INITIALIZATION', 'HIGH_TANK_LEVEL', 'LOW_TANK_LEVEL']); +var python_script_enum = new Enum({'START': 1, 'INITIALIZATION': 2, 'HIGH_TANK_LEVEL': 3, 'LOW_TANK_LEVEL': 4}); var python_script_options = { mode: 'text', pythonPath: '/usr/bin/python3', @@ -59,35 +58,35 @@ var i_fuelStopAdvisorWrapper = new fuelStopAdvisorWrapper.FuelStopAdvisorWrapper var port = 8080; var hostname = '127.0.0.1'; var server = http.createServer(function(req, res) { - var page = url.parse(req.url).pathname; - var full_path = path.join(process.cwd(),page); - // Check if page exists (for the moment only index.html) - fs.exists(full_path,function(exists){ + var page = url.parse(req.url).pathname; + var full_path = path.join(process.cwd(),page); + // Check if page exists (for the moment only index.html) + fs.exists(full_path,function(exists){ if(!exists){ - res.writeHeader(404, {"Content-Type": "text/plain"}); - res.write("404 Not Found\n"); + res.writeHeader(404, {"Content-Type": "text/plain"}); + res.write("404 Not Found\n"); res.end(); } else{ - fs.readFile(full_path, "binary", function(err, file) { - if(err) { - res.writeHeader(500, {"Content-Type": "text/plain"}); - res.write(err + "\n"); - res.end(); - - } - else{ - res.writeHeader(200); - res.write(file, "binary"); - res.end(); - } - }); - } - }); + fs.readFile(full_path, "binary", function(err, file) { + if(err) { + res.writeHeader(500, {"Content-Type": "text/plain"}); + res.write(err + "\n"); + res.end(); + + } + else{ + res.writeHeader(200); + res.write(file, "binary"); + res.end(); + } + }); + } + }); }); // Launch server -server.listen(port); +server.listen(port); // Load socket.io and connect it to the server var io = require('socket.io').listen(server); @@ -167,12 +166,7 @@ socket_simulation.on('connection', function (client) { switch(message.request) { case "LogReplayerScenario": console.log('Message received: Request-->', message.request +' Parameters-->' + message.parameters); - if(python_script_enum.has(message.parameters)) { - python_script_options.args = [python_script_enum.get(message.parameters).key]; - } else { - console.log("Could not find " + message.parameters + " scenario"); - client.emit('feedback', "Could not find " + message.method + " function"); - } + python_script_options.args = [message.parameters]; break; default: console.log("Could not find " + message.interface); @@ -184,132 +178,10 @@ socket_simulation.on('connection', function (client) { // Timer setInterval(function(){ python_shell.run('simulation-launch.py', python_script_options, function (err, results) { - if (err) throw err; - }); -======= - -// Requirements of LBS add-on modules -var positioningEnhancedPositionWrapper = require(resource.generatedNodejsModulePath+'/PositioningEnhancedPositionWrapper'); -var fuelStopAdvisorWrapper = require(resource.generatedNodejsModulePath+'/FuelStopAdvisorWrapper'); - -// Create instances -var i_positioningEnhancedPositionWrapper = new positioningEnhancedPositionWrapper.PositioningEnhancedPositionWrapper(); -var i_fuelStopAdvisorWrapper = new fuelStopAdvisorWrapper.FuelStopAdvisorWrapper(); - -// Create and init server -var port = 8080; -var hostname = '127.0.0.1'; -var server = http.createServer(function(req, res) { - var page = url.parse(req.url).pathname; - var full_path = path.join(process.cwd(),page); - // Check if page exists (for the moment only index.html) - fs.exists(full_path,function(exists){ - if(!exists){ - res.writeHeader(404, {"Content-Type": "text/plain"}); - res.write("404 Not Found\n"); - res.end(); - } - else{ - fs.readFile(full_path, "binary", function(err, file) { - if(err) { - res.writeHeader(500, {"Content-Type": "text/plain"}); - res.write(err + "\n"); - res.end(); - - } - else{ - res.writeHeader(200); - res.write(file, "binary"); - res.end(); - } - }); - } - }); -}); - -// Launch server -server.listen(port); - -// Load socket.io and connect it to the server -var io = require('socket.io').listen(server); - -// Manage socket for the namespace /simulation -var socket_simulation = io.of('/simulation'); -// signals -function positionUpdate(changedValues) { - console.log('positionUpdate: ' + changedValues); - socket_simulation.emit('positioning_signal', {signal: 'positionUpdate', data: changedValues}); -} -var setPositionUpdateListener = i_positioningEnhancedPositionWrapper.setPositionUpdateListener(positionUpdate); -function tripDataUpdated(changedValues) { - console.log('tripDataUpdated: ' + changedValues); - socket_simulation.emit('demonstrator_signal', {signal: 'tripDataUpdated', data: changedValues}); -} -var setTripDataUpdatedListener = i_fuelStopAdvisorWrapper.setTripDataUpdatedListener(tripDataUpdated); -function fuelStopAdvisorWarning(changedValues) { - console.log('fuelStopAdvisorWarning: ' + changedValues); - socket_simulation.emit('demonstrator_signal', {signal: 'fuelStopAdvisorWarning', data: changedValues}); -} -var setFuelStopAdvisorWarningListener = i_fuelStopAdvisorWrapper.setFuelStopAdvisorWarningListener(fuelStopAdvisorWarning); -function tripDataResetted(changedValues) { - console.log('tripDataResetted: ' + changedValues); - socket_simulation.emit('demonstrator_signal', {signal: 'tripDataResetted', data: changedValues}); -} -var setTripDataResettedListener = i_fuelStopAdvisorWrapper.setTripDataResettedListener(tripDataResetted); - -// Start the gmainloop (to be done after the initialisation of listeners ! -gcontext.init(); - -// connection -socket_simulation.on('connection', function (client) { - console.log('Client connected'); - client.on('positioning_request', function (message) { - switch(message.interface) { - case "PositioningEnhancedPosition": - console.log('Message received: Interface-->' + message.interface +' Method-->', message.method +' Parameters-->' + message.parameters); - if (message.method in i_positioningEnhancedPositionWrapper && typeof i_positioningEnhancedPositionWrapper[message.method] === "function") { - var data = i_positioningEnhancedPositionWrapper[message.method](message.parameters); - if(data) { - client.emit('positioning_answer', {request: message.method, answer: data}); - } - } - else { - console.log("Could not find " + message.method + " function"); - client.emit('feedback', "Could not find " + message.method + " function"); - } - break; - default: - console.log("Could not find " + message.interface); - client.emit('feedback', "Could not find " + message.interface); - } - }); - client.on('demonstrator_request', function (message) { - switch(message.interface) { - case "FuelStopAdvisor": - console.log('Message received: Interface-->' + message.interface +' Method-->', message.method +' Parameters-->' + message.parameters); - if (message.method in i_fuelStopAdvisorWrapper && typeof i_fuelStopAdvisorWrapper[message.method] === "function") { - var data = i_fuelStopAdvisorWrapper[message.method](message.parameters); - if(data) { - console.log('data' + data); - client.emit('demonstrator_answer', {request: message.method, answer: data}); - } - } - else { - console.log("Could not find " + message.method + " function"); - client.emit('feedback', "Could not find " + message.method + " function"); - } - break; - default: - console.log("Could not find " + message.interface); - client.emit('feedback', "Could not find " + message.interface); - } - }); -}); - -// Timer -setInterval(function(){ -//console.log('tick'); ->>>>>>> branch 'master' of ssh://git-genivi@git.projects.genivi.org/lbs/navigation-application.git + if (err) throw err; +// console.log('results: %j', results); + }); + console.log('Refresh simulated values') }, 1000); // Log info diff --git a/test/html-based-panel/simulation-panel.html b/test/html-based-panel/simulation-panel.html index 54d91b7..afa08f5 100644 --- a/test/html-based-panel/simulation-panel.html +++ b/test/html-based-panel/simulation-panel.html @@ -7,6 +7,7 @@ <!-- to be fixed, use relative paths --> <script type="text/javascript" src="./node_modules/socket.io/node_modules/socket.io-client/socket.io.js"></script> <script type="text/javascript" src="./node_modules/webidl2/lib/webidl2.js"></script> +<script type="text/javascript" src="./node_modules/enum/enum-2.3.0.js"></script> </head> <body> <header> @@ -19,7 +20,6 @@ VERSION: <h id="version"></h><br> </section> <section> -<<<<<<< HEAD <form> STEP: <input type="radio" name="step" onchange="stepChange(this);" value="START" checked> START @@ -139,6 +139,8 @@ socket_simulation.on('demonstrator_signal', function(message) { } }) +<!-- scenarii --> +var scenarii = new Enum({'START': 1, 'INITIALIZATION': 2, 'HIGH_TANK_LEVEL': 3, 'LOW_TANK_LEVEL': 4}); <!-- initialization --> var today=new Date(); @@ -192,175 +194,10 @@ function tripDataUpdated(number) { <!-- some other functions --> function stepChange(button) { - var data = button.value; + var data = scenarii.get(button.value).key; socket_simulation.emit('panel_request', {request: 'LogReplayerScenario', parameters: [data]}); } -======= -STEP: <p id="step"></p> -<div style="float: left; width: 360px;"> -<table style="width:100%"> - <caption>Inputs</caption> - <col width="200"> - <col width="100"> - <col width="60"> - <tr> - <td>Engine speed</td> - <td id=engine_speed></td> - <td>RPM</td> - </tr> - <tr> - <td>Tank</td> - <td id=tank></td> - <td>L</td> - </tr> - <tr> - <td>Fuel instant</td> - <td id=fuel_instant></td> - <td>L/H</td> - </tr> - <tr> - <td>Vehicle speed</td> - <td id=vehicle_speed></td> - <td>KM/H</td> - </tr> - <tr> - <td>Latitude</td> - <td id=latitude></td> - <td>deg</td> - </tr> - <tr> - <td>Longitude</td> - <td id=longitude></td> - <td>deg</td> - </tr> -</table> -</div> -<div style="float: left; width: 300px; padding:10px;"> -<table style="width:100%"> - <caption>Status</caption> - <col width="200"> - <col width="100"> - <tr> - <td>Guidance</td> - <td id=guidance_status></td> - </tr> - <tr> - <td>Simulation</td> - <td id=simulation_status></td> - </tr> - <tr> - <td>FSA warning</td> - <td id=warning_status></td> - </tr> - <tr> - <td>Tank distance</td> - <td id=tank_distance></td> - </tr> - <tr> - <td>Enhanced tank distance</td> - <td id=enhanced_tank_distance></td> - </tr> -</table> -</div> -</section> - -<footer> -Copyright © PCA Peugeot Citroen -</footer> - -<script type="text/javascript"> - -<!-- sockets management --> -var socket_simulation = io.connect('http://localhost:8080/simulation'); //namespace simulation -socket_simulation.on('feedback', function(message) { - alert('Message received from the server : ' + message); -}) - -socket_simulation.on('positioning_answer', function(message) { - if(message.request === 'getPositionInfo') - { - getPositionInfoReturn(message.answer); - } -}) - -socket_simulation.on('positioning_signal', function(message) { - if(message.signal === 'positionUpdate') - { - positionUpdate(message.data); - } -}) - -socket_simulation.on('demonstrator_answer', function(message) { - if(message.request === 'getVersion') - { - getVersionReturn(message.answer); - } else { - if(message.request === 'getPositionInfo') - { - getPositionInfoReturn(message.answer); - } - } -}) - -socket_simulation.on('demonstrator_signal', function(message) { - if(message.signal === 'tripDataUpdated') - { - tripDataUpdated(message.data); - } -}) - - -<!-- initialization --> -var today=new Date(); -document.getElementById("start_time").innerHTML=today; - -getVersion(); - -<!-- getters --> -function getVersion() { - socket_simulation.emit('demonstrator_request', {interface: 'FuelStopAdvisor', method: 'getVersion', parameters: []}); -} -function getVersionReturn(answer) { - document.getElementById("version").innerHTML=answer[3]; -} -function getPositionInfo() { - socket_simulation.emit('positioning_request', {interface: 'PositioningEnhancedPosition', method: 'getPositionInfo', parameters: [0,27]}); -} -function getPositionInfoReturn(answer) { - for ( var i=1; i<answer.length; i++ ) { - //nb: first entry is the timestamp - switch(answer[i].key_lsb) - { - case 1: - document.getElementById("latitude").innerHTML=answer[i].value; - break; - case 2: - document.getElementById("longitude").innerHTML=answer[i].value; - break; - } - } -} -function getInstantData() { - socket_simulation.emit('demonstrator_request', {interface: 'FuelStopAdvisor', method: 'getInstantData', parameters: []}); -} -function getInstantDataReturn(answer) { -alert('Message received from the server : ' + answer); -} - -<!-- setters --> - -<!-- signals --> -function positionUpdate(changedValues) { - getPositionInfo(); -} - -function tripDataUpdated(number) { - getInstantData(); -} - -<!-- some other functions --> ->>>>>>> branch 'master' of ssh://git-genivi@git.projects.genivi.org/lbs/navigation-application.git </script> </body> </html> diff --git a/test/resource/high-tank-level.log b/test/resource/high-tank-level.log index 5e7f15c..c89cda9 100644 --- a/test/resource/high-tank-level.log +++ b/test/resource/high-tank-level.log @@ -16,7 +16,6 @@ 0,0$GVVEHVER,0,0,0 1000,0$GVGNSP,1000,46.201839,6.146647,0,0X03 1000,0$GVSNSVEHSP,1000,90.00,0X01 -1000,0$GVGNSC,1000,11.111111,0,27.000000,0X05 1000,0$GVVEHENGSPEED,2000,0X01 1000,0$GVVEHFUELLEVEL,30,0X01 1000,0$GVVEHFUELCONS,1500,0X01 diff --git a/test/resource/initialization.log b/test/resource/initialization.log index 5bf332d..4d94743 100644 --- a/test/resource/initialization.log +++ b/test/resource/initialization.log @@ -16,7 +16,6 @@ 0,0$GVVEHVER,0,0,0 1000,0$GVGNSP,1000,46.201839,6.146647,0,0X03 1000,0$GVSNSVEHSP,1000,0.00,0X01 -1000,0$GVGNSC,1000,11.111111,0,27.000000,0X05 1000,0$GVVEHENGSPEED,800,0X01 1000,0$GVVEHFUELLEVEL,30,0X01 1000,0$GVVEHFUELCONS,100,0X01 diff --git a/test/resource/low-tank-level.log b/test/resource/low-tank-level.log index c827a98..919eb28 100644 --- a/test/resource/low-tank-level.log +++ b/test/resource/low-tank-level.log @@ -16,7 +16,6 @@ 0,0$GVVEHVER,0,0,0 1000,0$GVGNSP,1000,46.201839,6.146647,0,0X03 1000,0$GVSNSVEHSP,1000,90.00,0X01 -1000,0$GVGNSC,1000,11.111111,0,27.000000,0X05 1000,0$GVVEHENGSPEED,2000,0X01 1000,0$GVVEHFUELLEVEL,15,0X01 1000,0$GVVEHFUELCONS,1500,0X01 diff --git a/test/resource/start.log b/test/resource/start.log index d74d181..0167cd1 100644 --- a/test/resource/start.log +++ b/test/resource/start.log @@ -16,7 +16,6 @@ 0,0$GVVEHVER,0,0,0 1000,0$GVGNSP,1000,46.201839,6.146647,0,0X03 1000,0$GVSNSVEHSP,1000,0.00,0X01 -1000,0$GVGNSC,1000,11.111111,0,27.000000,0X05 1000,0$GVVEHENGSPEED,0,0X01 1000,0$GVVEHFUELLEVEL,30,0X01 1000,0$GVVEHFUELCONS,0,0X01 diff --git a/test/resource/test-positioning.log b/test/resource/test-positioning.log index 9780465..029dee2 100644 --- a/test/resource/test-positioning.log +++ b/test/resource/test-positioning.log @@ -9,5 +9,4 @@ 0,0$GVSNSVER,2,0,0 1000,0$GVGNSP,1000,46.201839,6.146647,0,0X03 1000,0$GVSNSVEHSP,1000,0.00,0X01 -1000,0$GVGNSC,1000,11.111111,0,27.000000,0X05 diff --git a/test/script/set-position.py b/test/script/set-position.py new file mode 100755 index 0000000..74c6de1 --- /dev/null +++ b/test/script/set-position.py @@ -0,0 +1,76 @@ +#!/usr/bin/python3 + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2014, PCA Peugeot Citroen +* +* \file set-position.py +* +* \brief This script sets a position, thru the logreplayer. +* +* \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: +* 7-11-2014, Philippe Colliot, Add some parameters (host address) +* +* @licence end@ +************************************************************************** +""" +import sys,tty,termios,select,pygame,gi,time,re,argparse +import pdb + +from pygame.locals import * +from threading import Timer +from configTests import * +from enum import IntEnum +from gi.repository import GObject + +class Step(IntEnum): + START = 0 + END = 4 + +# Define some constants +KEYBOARD_PERIODICITY = 1000 #in ms +LOCAL_HOST = '127.0.0.1' + +def getKeyboard(): + global step + + for event in pygame.event.get(): + if event.type == QUIT: + sys.exit(0) + + # get the keyboard input + pygame.event.pump() + keys = pygame.key.get_pressed() + if keys[K_x]: + step=Step.END + + if step==Step.START: + launch("test-positioning.log",host) + elif step==Step.END: + displayStatus( 'End test ' ) + loop.quit() + else: + displayStatus( 'error' ) + pygame.quit() + loop.quit() + return True + +# Main program begins here + +# Initialize the game engine +pygame.init() +host = LOCAL_HOST +step = Step.START +GObject.timeout_add(KEYBOARD_PERIODICITY,getKeyboard) +loop = GObject.MainLoop() +loop.run() diff --git a/test/script/set-vehicle-info.py b/test/script/set-vehicle-info.py new file mode 100755 index 0000000..95ad5ff --- /dev/null +++ b/test/script/set-vehicle-info.py @@ -0,0 +1,76 @@ +#!/usr/bin/python3 + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2014, PCA Peugeot Citroen +* +* \file set-position.py +* +* \brief This script sets vehicle infos, thru the logreplayer. +* +* \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: +* 7-11-2014, Philippe Colliot, Add some parameters (host address) +* +* @licence end@ +************************************************************************** +""" +import sys,tty,termios,select,pygame,gi,time,re,argparse +import pdb + +from pygame.locals import * +from threading import Timer +from configTests import * +from enum import IntEnum +from gi.repository import GObject + +class Step(IntEnum): + START = 0 + END = 4 + +# Define some constants +KEYBOARD_PERIODICITY = 1000 #in ms +LOCAL_HOST = '127.0.0.1' + +def getKeyboard(): + global step + + for event in pygame.event.get(): + if event.type == QUIT: + sys.exit(0) + + # get the keyboard input + pygame.event.pump() + keys = pygame.key.get_pressed() + if keys[K_x]: + step=Step.END + + if step==Step.START: + launch("test-vehicle-info.log",host) + elif step==Step.END: + displayStatus( 'End test ' ) + loop.quit() + else: + displayStatus( 'error' ) + pygame.quit() + loop.quit() + return True + +# Main program begins here + +# Initialize the game engine +pygame.init() +host = LOCAL_HOST +step = Step.START +GObject.timeout_add(KEYBOARD_PERIODICITY,getKeyboard) +loop = GObject.MainLoop() +loop.run() diff --git a/test/script/simulation-launch.py b/test/script/simulation-launch.py new file mode 100755 index 0000000..b69743d --- /dev/null +++ b/test/script/simulation-launch.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2014, PCA Peugeot Citroen +* +* \file simulation-launch.py +* +* \brief This script is part of the FSA scenario. +* +* \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: +* 7-11-2014, Philippe Colliot, Add some parameters (host address) +* +* @licence end@ +************************************************************************** +""" +import sys,tty,termios + +from configTests import * + +# Define some constants +LOCAL_HOST = '127.0.0.1' + +simulation_files = {'START': "start.log", 'INITIALIZATION': "initialization.log", 'HIGH_TANK_LEVEL': "high-tank-level.log", 'LOW_TANK_LEVEL': "low-tank-level.log"}; + +# Main program begins here +host = LOCAL_HOST + +launch(simulation_files[sys.argv[1]],host) + + diff --git a/test/script/test-positioning.py b/test/script/test-positioning.py deleted file mode 100755 index 0559e51..0000000 --- a/test/script/test-positioning.py +++ /dev/null @@ -1,265 +0,0 @@ -#!/usr/bin/python3 - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2014, PCA Peugeot Citroen -* -* \file test-positioning.py -* -* \brief This script is part of the FSA scenario. -* -* \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: -* 7-11-2014, Philippe Colliot, Add some parameters (host address) -* -* @licence end@ -************************************************************************** -""" -import sys,tty,termios,select,pygame,gi,time,dbus,re,argparse -import pdb - -from pygame.locals import * -from threading import Timer -from configTests import * -from enum import IntEnum -from dbus.mainloop.glib import DBusGMainLoop -from traceback import print_exc -from gi.repository import GObject - -class Step(IntEnum): - START = 0 - END = 4 - -class Genivi(IntEnum): - ENHANCEDPOSITIONSERVICE_LATITUDE = 0x00000001 - ENHANCEDPOSITIONSERVICE_LONGITUDE = 0x00000002 - ENHANCEDPOSITIONSERVICE_ALTITUDE = 0x00000004 - FUELSTOPADVISOR_TANK_DISTANCE = 0x0022 - FUELSTOPADVISOR_ENHANCED_TANK_DISTANCE = 0x0024 - NAVIGATIONCORE_ACTIVE = 0x0060 - NAVIGATIONCORE_INACTIVE = 0x0061 - NAVIGATIONCORE_SIMULATION_STATUS_NO_SIMULATION = 0x0220 - NAVIGATIONCORE_SIMULATION_STATUS_RUNNING = 0x0221 - NAVIGATIONCORE_SIMULATION_STATUS_PAUSED = 0x0222 - NAVIGATIONCORE_SIMULATION_STATUS_FIXED_POSITION = 0x0223 - NAVIGATIONCORE_LATITUDE = 0x00a0 - NAVIGATIONCORE_LONGITUDE = 0x00a1 - -# Define some colors -BLACK = ( 0, 0, 0) -WHITE = ( 255, 255, 255) -BLUE = ( 0, 0, 255) -GREEN = ( 0, 255, 0) -RED = ( 255, 0, 0) -YELLOW = ( 255, 222, 0) - -# Define some constants -PI = 3.141592653 -KEYBOARD_PERIODICITY = 200 #in ms -GET_DBUS_PERIODICITY = 500 #in ms -FUEL_CONVERSION = (3.6/GET_DBUS_PERIODICITY) -SPEED_CONVERSION = (36.0/GET_DBUS_PERIODICITY) - -# Item location on the screen -STATUS_LOCATION = (100,10) -STEP_LOCATION = (100,68) -ENGINE_SPEED_LOCATION = (150,118) -FUEL_LEVEL_LOCATION = (150,175) -FUEL_INSTANT_CONSUMPTION_LOCATION = (150,238) -VEHICLE_SPEED_LOCATION = (150,287) -LATITUDE_LOCATION = (64,340) -LONGITUDE_LOCATION = (185,340) -GUIDANCE_STATUS_LOCATION = (380,118) -SIMULATION_STATUS_LOCATION = (380,175) -FUEL_STOP_ADVISOR_WARNING_LOCATION = (380,238) -FUEL_STOP_ADVISOR_TANK_DISTANCE_LOCATION = (380,287) -FUEL_STOP_ADVISOR_ENHANCED_TANK_DISTANCE_LOCATION = (380,340) - -# Defaults -LOCAL_HOST = '127.0.0.1' - -def display(string,location,fontColor,fontBackground): - global args - text = font.render(string, True, fontColor, fontBackground) - textRect = text.get_rect() - textRect.topleft = location - screen.blit(text, textRect) - -def logVerbose(data,value): - if args.ver==True: - print (data,": ",value) - -def displayStatus(string): - display(string,STATUS_LOCATION,WHITE,BLUE) - -def displayStep(string): - display(' ',STEP_LOCATION,YELLOW,BLACK) - display(string,STEP_LOCATION,YELLOW,BLACK) - -def displayEngineSpeed(string): - display(string,ENGINE_SPEED_LOCATION,YELLOW,BLACK) - logVerbose("EngineSpeed",string) - -def displayFuelLevel(string): - display(string,FUEL_LEVEL_LOCATION,YELLOW,BLACK) - -def displayFuelInstant(string): - display(string,FUEL_INSTANT_CONSUMPTION_LOCATION,YELLOW,BLACK) - -def displayVehicleSpeed(string): - display(string,VEHICLE_SPEED_LOCATION,YELLOW,BLACK) - -def displayLatitude(string): - display(string,LATITUDE_LOCATION,YELLOW,BLACK) - -def displayLongitude(string): - display(string,LONGITUDE_LOCATION,YELLOW,BLACK) - -def displayGuidanceStatus(string): - display(string,GUIDANCE_STATUS_LOCATION,YELLOW,BLACK) - -def displaySimulationStatus(string): - display(string,SIMULATION_STATUS_LOCATION,YELLOW,BLACK) - -def displayFuelStopAdvisorWarning(string): - display(string,FUEL_STOP_ADVISOR_WARNING_LOCATION,YELLOW,BLACK) - -def displayFuelStopAdvisorTankDistance(string): - display(string,FUEL_STOP_ADVISOR_TANK_DISTANCE_LOCATION,YELLOW,BLACK) - -def displayFuelStopAdvisorEnhancedTankDistance(string): - display(string,FUEL_STOP_ADVISOR_ENHANCED_TANK_DISTANCE_LOCATION,YELLOW,BLACK) - -def refresh(): - pygame.display.update() - -def initDisplay(): - displayStatus('') - displayStep('') - displayEngineSpeed('0') - displayFuelLevel('0') - displayFuelInstant('0') - displayLatitude('0') - displayLongitude('0') - displayVehicleSpeed('0') - displayGuidanceStatus('OFF') - displaySimulationStatus('OFF') - displayFuelStopAdvisorWarning('-----') - displayFuelStopAdvisorTankDistance('-----') - displayFuelStopAdvisorEnhancedTankDistance('-----') - -def getKeyboard(): - global step - - for event in pygame.event.get(): - if event.type == QUIT: - sys.exit(0) - - # get the keyboard input - pygame.event.pump() - keys = pygame.key.get_pressed() - if keys[K_x]: - step=Step.END - - return True - -def getDbus(): - global step - global host - - # manage the logreplayer depending on the step - if step==Step.START: - launch("test-positioning.log",host) - elif step==Step.END: - displayStatus( 'End test ' ) - loop.quit() - else: - displayStatus( 'error' ) - pygame.quit() - loop.quit() - - displayStep( str(step.name) ) - - # refresh screen - refresh() - - return True - -def enhancedPositionPositionUpdateHandler(arg): - time.sleep(.050) - # get the position - enhancedPosition = enhancedPositionInterface.GetPositionInfo(arg) - if (arg & Genivi.ENHANCEDPOSITIONSERVICE_LATITUDE) == Genivi.ENHANCEDPOSITIONSERVICE_LATITUDE: - latitude=float(enhancedPosition[1][dbus.UInt64(Genivi.ENHANCEDPOSITIONSERVICE_LATITUDE)]) - displayLatitude("{:.3f}".format(latitude)) - if (arg & Genivi.ENHANCEDPOSITIONSERVICE_LONGITUDE) == Genivi.ENHANCEDPOSITIONSERVICE_LONGITUDE: - longitude=float(enhancedPosition[1][dbus.UInt64(Genivi.ENHANCEDPOSITIONSERVICE_LONGITUDE)]) - displayLongitude("{:.3f}".format(longitude)) - -# Main program begins here -parser = argparse.ArgumentParser(description='Test positioning.') -parser.add_argument('-v','--ver',action='store_true', help='Print log messages') -parser.add_argument('-r','--rem',action='store', dest='host', help='Set remote host address') -args = parser.parse_args() - -if args.host != None: - host = args.host -else: - host = LOCAL_HOST - -# Initialize the game engine -pygame.init() - -# Initialize the screen -background = pygame.image.load("dashboard.png") -backgroundRect = background.get_rect() -size = (width, height) = background.get_size() -screen = pygame.display.set_mode( size ) -pygame.display.set_caption('Test positioning') -screen.blit(background,backgroundRect) -font = pygame.font.SysFont('Calibri', 25, True, False) -initDisplay() - -# Initialize DBus loop as the main loop -DBusGMainLoop(set_as_default=True) - -# Connect on the bus -dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -if host == LOCAL_HOST: - dbusConnectionBus = dbus.SessionBus() -else: - dbusConnectionBus = dbus.bus.BusConnection("tcp:host=" + host +",port=4000") - -# 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() - sys.exit(1) -enhancedPositionInterface = dbus.Interface(enhancedPositionObject, "org.genivi.positioning.EnhancedPosition") -dbusConnectionBus.add_signal_receiver(enhancedPositionPositionUpdateHandler, dbus_interface = "org.genivi.positioning.EnhancedPosition", signal_name = "PositionUpdate") - -displayStatus( 'Start positioning test' ) - -refresh() - -# start -step = Step.START -GObject.timeout_add(KEYBOARD_PERIODICITY,getKeyboard) -GObject.timeout_add(GET_DBUS_PERIODICITY,getDbus) - -loop = GObject.MainLoop() -loop.run() - - - diff --git a/test/script/test-vehicle-info.py b/test/script/test-vehicle-info.py deleted file mode 100644 index 465f69f..0000000 --- a/test/script/test-vehicle-info.py +++ /dev/null @@ -1,278 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2014, PCA Peugeot Citroen -* -* \file test-vehicle-info.py -* -* \brief This script is part of the FSA scenario. -* -* \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: -* 7-11-2014, Philippe Colliot, Add some parameters (host address) -* -* @licence end@ -************************************************************************** -""" -import sys,tty,termios,select,pygame,gi,time,dbus,re,argparse -import pdb - -from pygame.locals import * -from threading import Timer -from configTests import * -from enum import IntEnum -from dbus.mainloop.glib import DBusGMainLoop -from traceback import print_exc -from gi.repository import GObject - -class Step(IntEnum): - START = 0 - END = 4 - -class Genivi(IntEnum): - ENHANCEDPOSITIONSERVICE_LATITUDE = 0x0020 - ENHANCEDPOSITIONSERVICE_LONGITUDE = 0x0021 - ENHANCEDPOSITIONSERVICE_ALTITUDE = 0x0022 - FUELSTOPADVISOR_TANK_DISTANCE = 0x0022 - FUELSTOPADVISOR_ENHANCED_TANK_DISTANCE = 0x0024 - NAVIGATIONCORE_ACTIVE = 0x0060 - NAVIGATIONCORE_INACTIVE = 0x0061 - NAVIGATIONCORE_SIMULATION_STATUS_NO_SIMULATION = 0x0220 - NAVIGATIONCORE_SIMULATION_STATUS_RUNNING = 0x0221 - NAVIGATIONCORE_SIMULATION_STATUS_PAUSED = 0x0222 - NAVIGATIONCORE_SIMULATION_STATUS_FIXED_POSITION = 0x0223 - NAVIGATIONCORE_LATITUDE = 0x00a0 - NAVIGATIONCORE_LONGITUDE = 0x00a1 - -# Define some colors -BLACK = ( 0, 0, 0) -WHITE = ( 255, 255, 255) -BLUE = ( 0, 0, 255) -GREEN = ( 0, 255, 0) -RED = ( 255, 0, 0) -YELLOW = ( 255, 222, 0) - -# Define some constants -PI = 3.141592653 -KEYBOARD_PERIODICITY = 200 #in ms -GET_DBUS_PERIODICITY = 1000 #in ms -FUEL_CONVERSION = (3.6/GET_DBUS_PERIODICITY) -SPEED_CONVERSION = (36.0/GET_DBUS_PERIODICITY) - -# Item location on the screen -STATUS_LOCATION = (100,10) -STEP_LOCATION = (100,68) -ENGINE_SPEED_LOCATION = (150,118) -FUEL_LEVEL_LOCATION = (150,175) -FUEL_INSTANT_CONSUMPTION_LOCATION = (150,238) -VEHICLE_SPEED_LOCATION = (150,287) -LATITUDE_LOCATION = (64,340) -LONGITUDE_LOCATION = (185,340) -GUIDANCE_STATUS_LOCATION = (380,118) -SIMULATION_STATUS_LOCATION = (380,175) -FUEL_STOP_ADVISOR_WARNING_LOCATION = (380,238) -FUEL_STOP_ADVISOR_TANK_DISTANCE_LOCATION = (380,287) -FUEL_STOP_ADVISOR_ENHANCED_TANK_DISTANCE_LOCATION = (380,340) - -# Defaults -LOCAL_HOST = '127.0.0.1' - -def display(string,location,fontColor,fontBackground): - global args - text = font.render(string, True, fontColor, fontBackground) - textRect = text.get_rect() - textRect.topleft = location - screen.blit(text, textRect) - -def logVerbose(data,value): - if args.ver==True: - print (data,": ",value) - -def displayStatus(string): - display(string,STATUS_LOCATION,WHITE,BLUE) - -def displayStep(string): - display(' ',STEP_LOCATION,YELLOW,BLACK) - display(string,STEP_LOCATION,YELLOW,BLACK) - -def displayEngineSpeed(string): - display(string,ENGINE_SPEED_LOCATION,YELLOW,BLACK) - logVerbose("EngineSpeed",string) - -def displayFuelLevel(string): - display(string,FUEL_LEVEL_LOCATION,YELLOW,BLACK) - -def displayFuelInstant(string): - display(string,FUEL_INSTANT_CONSUMPTION_LOCATION,YELLOW,BLACK) - -def displayVehicleSpeed(string): - display(string,VEHICLE_SPEED_LOCATION,YELLOW,BLACK) - -def displayLatitude(string): - display(string,LATITUDE_LOCATION,YELLOW,BLACK) - -def displayLongitude(string): - display(string,LONGITUDE_LOCATION,YELLOW,BLACK) - -def displayGuidanceStatus(string): - display(string,GUIDANCE_STATUS_LOCATION,YELLOW,BLACK) - -def displaySimulationStatus(string): - display(string,SIMULATION_STATUS_LOCATION,YELLOW,BLACK) - -def displayFuelStopAdvisorWarning(string): - display(string,FUEL_STOP_ADVISOR_WARNING_LOCATION,YELLOW,BLACK) - -def displayFuelStopAdvisorTankDistance(string): - display(string,FUEL_STOP_ADVISOR_TANK_DISTANCE_LOCATION,YELLOW,BLACK) - -def displayFuelStopAdvisorEnhancedTankDistance(string): - display(string,FUEL_STOP_ADVISOR_ENHANCED_TANK_DISTANCE_LOCATION,YELLOW,BLACK) - -def refresh(): - pygame.display.update() - -def initDisplay(): - displayStatus('') - displayStep('') - displayEngineSpeed('0') - displayFuelLevel('0') - displayFuelInstant('0') - displayLatitude('0') - displayLongitude('0') - displayVehicleSpeed('0') - displayGuidanceStatus('OFF') - displaySimulationStatus('OFF') - displayFuelStopAdvisorWarning('-----') - displayFuelStopAdvisorTankDistance('-----') - displayFuelStopAdvisorEnhancedTankDistance('-----') - -def getKeyboard(): - global step - - for event in pygame.event.get(): - if event.type == QUIT: - sys.exit(0) - - # get the keyboard input - pygame.event.pump() - keys = pygame.key.get_pressed() - if keys[K_x]: - step=Step.END - - return True - -def getDbus(): - global step - global host - - # manage the logreplayer depending on the step - if step==Step.START: - launch("test-vehicle-info.log",host) - elif step==Step.END: - displayStatus( 'End test ' ) - loop.quit() - else: - displayStatus( 'error' ) - pygame.quit() - loop.quit() - - # get the values on amb - engineSpeed = ambEngineSpeedInterface.GetSpeed() - displayEngineSpeed(str(int(engineSpeed[0]))) - fuelLevel = ambFuelInterface.GetLevel() - displayFuelLevel(str(int(fuelLevel[0]))) - fuelInstCons = ambFuelInterface.GetInstantConsumption() - displayFuelInstant("{:.2f}".format(int(fuelInstCons[0])*FUEL_CONVERSION)) - odometer = ambOdometerInterface.GetOdometer() - displayVehicleSpeed(str(int(odometer[0])*SPEED_CONVERSION)) - - displayStep( str(step.name) ) - - # refresh screen - refresh() - - return True - -# Main program begins here -parser = argparse.ArgumentParser(description='Test vehicle info.') -parser.add_argument('-v','--ver',action='store_true', help='Print log messages') -parser.add_argument('-r','--rem',action='store', dest='host', help='Set remote host address') -args = parser.parse_args() - -if args.host != None: - host = args.host -else: - host = LOCAL_HOST - -# Initialize the game engine -pygame.init() - -# Initialize the screen -background = pygame.image.load("dashboard.png") -backgroundRect = background.get_rect() -size = (width, height) = background.get_size() -screen = pygame.display.set_mode( size ) -pygame.display.set_caption('Test vehicle info') -screen.blit(background,backgroundRect) -font = pygame.font.SysFont('Calibri', 25, True, False) -initDisplay() - -# Initialize DBus loop as the main loop -DBusGMainLoop(set_as_default=True) - -# Connect on the bus -dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -if host == LOCAL_HOST: - dbusConnectionBus = dbus.SessionBus() -else: - dbusConnectionBus = dbus.bus.BusConnection("tcp:host=" + host +",port=4000") - -# Automotive message broker -try: - ambObject = dbusConnectionBus.get_object("org.automotive.message.broker", "/") -except dbus.DBusException: - print ("connection to Automotive message broker failed") - print_exc() - sys.exit(1) -ambInterface = dbus.Interface(ambObject, "org.automotive.Manager") - -# Get the object path to retrieve Engine Speed -engineSpeedPath = ambInterface.FindObject("EngineSpeed"); -ambEngineSpeed = dbusConnectionBus.get_object("org.automotive.message.broker", engineSpeedPath[0]) -ambEngineSpeedInterface = dbus.Interface(ambEngineSpeed, "org.automotive.EngineSpeed") - -# Get the object path to retrieve Fuel Level and Instant consumption -fuelPath = ambInterface.FindObject("Fuel"); -ambFuel = dbusConnectionBus.get_object("org.automotive.message.broker", fuelPath[0]) -ambFuelInterface = dbus.Interface(ambFuel, "org.automotive.Fuel") - -# Get the object path to retrieve Odometer -odometerPath = ambInterface.FindObject("Odometer"); -ambOdometer = dbusConnectionBus.get_object("org.automotive.message.broker", odometerPath[0]) -ambOdometerInterface = dbus.Interface(ambOdometer, "org.automotive.Odometer") - -displayStatus( 'Start simulation' ) - -refresh() - -# start -step = Step.START -GObject.timeout_add(KEYBOARD_PERIODICITY,getKeyboard) -GObject.timeout_add(GET_DBUS_PERIODICITY,getDbus) - -loop = GObject.MainLoop() -loop.run() - - - |