diff options
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/fuel-stop-advisor/fuel-stop-advisor.cpp | 8 | ||||
-rw-r--r-- | src/genivilogreplayer/genivilogreplayerplugin.cpp | 43 | ||||
-rw-r--r-- | src/genivilogreplayer/genivilogreplayerplugin.h | 6 | ||||
-rw-r--r-- | src/patches/amb_allow_sessionbus.patch | 77 | ||||
-rwxr-xr-x | src/script/build.sh | 24 | ||||
-rwxr-xr-x | src/script/run | 15 | ||||
-rw-r--r-- | test/resource/test-positioning.log | 13 | ||||
-rw-r--r-- | test/resource/test-vehicle-info.log | 14 | ||||
-rwxr-xr-x | test/script/configTests.py | 2 | ||||
-rw-r--r-- | test/script/test-positioning.py | 264 | ||||
-rw-r--r-- | test/script/test-vehicle-info.py | 277 |
12 files changed, 718 insertions, 27 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ee1afcb..2a75eb5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,7 @@ set (create_file cmake -E touch) # Check if navigation-service stuff with the right version has been cloned and do it if necessary set(navigation-service_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/navigation) set(navigation-service_URL http://git.projects.genivi.org/lbs/navigation.git) -set(navigation-service_VERSION 0d18b1e85db88795675235322d6c500d262410d9) +set(navigation-service_VERSION c8bb70af8b6e8fa0dc8530800adbd2b7cbffc293) if (EXISTS ${navigation-service_SRC_DIR}) execute_process( diff --git a/src/fuel-stop-advisor/fuel-stop-advisor.cpp b/src/fuel-stop-advisor/fuel-stop-advisor.cpp index 0e4be83..29e0179 100644 --- a/src/fuel-stop-advisor/fuel-stop-advisor.cpp +++ b/src/fuel-stop-advisor/fuel-stop-advisor.cpp @@ -2,11 +2,13 @@ #include <glib.h> #include <stdio.h> #include <unistd.h> + #include "fuel-stop-advisor.h" #include "constants.h" #include "amb.h" #include "ctripcomputer.h" #include <boost/variant/get.hpp> + #include "genivi-navigationcore-constants.h" #include "genivi-navigationcore-routing_proxy.h" @@ -15,7 +17,7 @@ static DBus::Connection *conn; static class FuelStopAdvisor *server; static GMainLoop *loop; -#define dbgprintf(...) realdbgprintf (__FILE__, __LINE__, __VA_ARGS__) +#define dbgprintf(...) printf(__VA_ARGS__); #if (!DEBUG_ENABLED) #undef dbgprintf @@ -309,7 +311,7 @@ class FuelStopAdvisor { double distance=0; dbgprintf("routeHandle %d\n",routeHandle); - if (routeHandle) { + if (routeHandle) { std::vector< std::map< uint16_t, ::DBus::Variant > > RouteShape; std::vector< uint16_t > valuesToReturn; uint32_t totalNumberOfSegments; @@ -460,7 +462,7 @@ class FuelStopAdvisor void SetRouteHandle(const uint32_t& routeHandle) { dbgprintf("SetRouteHandle %d\n",routeHandle); - this->routeHandle=routeHandle; + this->routeHandle=routeHandle; updateEnhancedDistance(); } diff --git a/src/genivilogreplayer/genivilogreplayerplugin.cpp b/src/genivilogreplayer/genivilogreplayerplugin.cpp index dd6a683..0c259f9 100644 --- a/src/genivilogreplayer/genivilogreplayerplugin.cpp +++ b/src/genivilogreplayer/genivilogreplayerplugin.cpp @@ -5,6 +5,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <boost/assert.hpp> +#include <boost/lexical_cast.hpp> #include <listplusplus.h> @@ -20,12 +21,15 @@ DLT_DECLARE_CONTEXT(gContext); #define BUFLEN 256 #define PORT 9932 +const char* id = "326011dd-65cd-4be6-a75e-3e8d46a05510"; + void *updatePropertiesThread(gpointer data) { GeniviLogReplayerPlugin* src = (GeniviLogReplayerPlugin*)data; src->updateProperties(); } + GeniviLogReplayerPlugin::GeniviLogReplayerPlugin(AbstractRoutingEngine* re, map<string, string> config) :AbstractSource(re, config) { @@ -55,7 +59,7 @@ extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<str const string GeniviLogReplayerPlugin::uuid() { - return "326011dd-65cd-4be6-a75e-3e8d46a05510"; + return id; } @@ -68,16 +72,33 @@ void GeniviLogReplayerPlugin::getPropertyAsync(AsyncPropertyReply *reply) #endif if(contains(mSupported,reply->property)) - { - // retrieve the value - replyQueue.push_back(reply); - } + { + // retrieve the value + if(reply->property == VehicleProperty::EngineSpeed) + { + reply->value = &enginespeed; + } + else if(reply->property == VehicleProperty::FuelLevel) + { + reply->value = &fuellevel; + } + else if(reply->property == VehicleProperty::FuelConsumption) + { + reply->value = &fuelcons; + } + else if(reply->property == VehicleProperty::Odometer) + { + reply->value = &odometer; + } + reply->success = true; + } else // your property request is not supported { reply->value = NULL; reply->success = false; - reply->completed(reply); + reply->error = AsyncPropertyReply::InvalidOperation; } + reply->completed(reply); } void GeniviLogReplayerPlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply) @@ -124,7 +145,7 @@ int GeniviLogReplayerPlugin::supportedOperations() return Get; } -// new values are receive through a socket from the logreplayer +// new values are received through a socket from the logreplayer // data is updated when received int GeniviLogReplayerPlugin::updateProperties() { @@ -169,7 +190,7 @@ int GeniviLogReplayerPlugin::updateProperties() // update AMB property accordingly to the message if(!strcmp(msgId, "GVVEHENGSPEED")) { - VehicleProperty::EngineSpeedType enginespeed(msgValue); + enginespeed.setValue(msgValue); routingEngine->updateProperty(&enginespeed, uuid()); #ifdef DLT LOG_DEBUG(gContext,"GeniviLogReplayer: GVVEHENGSPEED - Message ID, value: %s , %d", msgId,msgValue); @@ -180,19 +201,19 @@ int GeniviLogReplayerPlugin::updateProperties() } else if(!strcmp(msgId, "GVVEHFUELLEVEL")) { - VehicleProperty::FuelLevelType fuellevel(msgValue); + fuellevel.setValue(msgValue); routingEngine->updateProperty(&fuellevel, uuid()); DebugOut(0)<<"GVVEHFUELLEVEL - Message ID, value: "<<msgId<<","<<msgValue<<endl; } else if (!strcmp(msgId, "GVVEHFUELCONS")) { - VehicleProperty::FuelConsumptionType fuelcons(msgValue); + fuelcons.setValue(msgValue); routingEngine->updateProperty(&fuelcons, uuid()); DebugOut(0)<<"GVVEHFUELCONS - Message ID, value: "<<msgId<<","<<msgValue<<endl; } else if (!strcmp(msgId, "GVVEHTOTALODO")) { - VehicleProperty::OdometerType odometer(msgValue); + odometer.setValue(msgValue); routingEngine->updateProperty(&odometer, uuid()); DebugOut(0)<<"GVVEHTOTALODO - Message ID, value: "<<msgId<<","<<msgValue<<endl; } diff --git a/src/genivilogreplayer/genivilogreplayerplugin.h b/src/genivilogreplayer/genivilogreplayerplugin.h index 98613a7..14edc74 100644 --- a/src/genivilogreplayer/genivilogreplayerplugin.h +++ b/src/genivilogreplayer/genivilogreplayerplugin.h @@ -38,10 +38,14 @@ private: std::map<VehicleProperty::Property, PropertyInfo> propertyInfoMap; std::string device; - std::list<AsyncPropertyReply*> replyQueue; PropertyList mRequests; PropertyList mSupported; + VehicleProperty::EngineSpeedType enginespeed; + VehicleProperty::FuelLevelType fuellevel; + VehicleProperty::FuelConsumptionType fuelcons; + VehicleProperty::OdometerType odometer; + // listening loop management and thread GThread *thread; bool statusRunning = false; diff --git a/src/patches/amb_allow_sessionbus.patch b/src/patches/amb_allow_sessionbus.patch index 78918d7..084b0e8 100644 --- a/src/patches/amb_allow_sessionbus.patch +++ b/src/patches/amb_allow_sessionbus.patch @@ -1,3 +1,67 @@ +diff --git a/RELEASE.md b/RELEASE.md +index af011cd..f4f81d6 100644 +--- a/RELEASE.md ++++ b/RELEASE.md +@@ -15,8 +15,8 @@ Changes: + - [websocket plugin] protocol changes: getSupportedEventTypes is getSupported. 'data' changed type to array of objects + instead of array of strings. See plugins/websocket/protocol + - Removed old ButtonEvent interface as it conflicted with the new ButtonEvent. +-- Extensive documentation improvements. Plugin docs install to /usr/share/doc/packages/automotive-message-broker/0.13/plugins/. +-- Bluemonkey JS API docs /usr/share/doc/packages/automotive-message-broker/0.13/plugins/bluemonkey/html/. ++- Extensive documentation improvements. Plugin docs install to /usr/local/share/doc/packages/automotive-message-broker/0.13/plugins/. ++- Bluemonkey JS API docs /usr/local/share/doc/packages/automotive-message-broker/0.13/plugins/bluemonkey/html/. + + Fixes: + - [DBus plugin] Fix exporting properties in zones that really don't have support +diff --git a/plugins/common/bluetooth5.cpp b/plugins/common/bluetooth5.cpp +index f836b42..5bdbd2f 100644 +--- a/plugins/common/bluetooth5.cpp ++++ b/plugins/common/bluetooth5.cpp +@@ -6,6 +6,8 @@ + #include <gio/gunixfdlist.h> + #include <string> + ++GBusType bustype=G_BUS_TYPE_SYSTEM; ++ + static const gchar introspection_xml[] = + "<node>" + " <interface name='org.bluez.Profile1'>" +@@ -121,7 +123,7 @@ std::string findDevice(std::string address, std::string adapterPath="") + std::string objectPath; + + GError * proxyError = nullptr; +- auto managerProxy = amb::make_super(g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, ++ auto managerProxy = amb::make_super(g_dbus_proxy_new_for_bus_sync(bustype, G_DBUS_PROXY_FLAGS_NONE, NULL, + "org.bluez", + "/", + "org.freedesktop.DBus.ObjectManager", +@@ -215,7 +217,7 @@ Bluetooth5::Bluetooth5() + + GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, "org.bluez.Profile1"); + +- mConnection = amb::make_super(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &errorBus)); ++ mConnection = amb::make_super(g_bus_get_sync(bustype, nullptr, &errorBus)); + + auto errorBusPtr = amb::make_super(errorBus); + +@@ -308,7 +310,7 @@ void Bluetooth5::connect(ConnectedCallback onconnectedCallback) + + GError* error = nullptr; + +- auto deviceProxyPtr = amb::make_super(g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,G_DBUS_PROXY_FLAGS_NONE,NULL, ++ auto deviceProxyPtr = amb::make_super(g_dbus_proxy_new_for_bus_sync(bustype,G_DBUS_PROXY_FLAGS_NONE,NULL, + "org.bluez", mPath.c_str(), "org.bluez.Device1", nullptr, &error)); + + auto errorPtr = amb::make_super(error); +@@ -341,7 +343,7 @@ void Bluetooth5::disconnect() + { + GError* error = nullptr; + +- auto deviceProxyPtr = amb::make_super(g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,G_DBUS_PROXY_FLAGS_NONE,NULL, ++ auto deviceProxyPtr = amb::make_super(g_dbus_proxy_new_for_bus_sync(bustype,G_DBUS_PROXY_FLAGS_NONE,NULL, + "org.bluez", mPath.c_str(), "org.bluez.Device1", nullptr, &error)); + + auto errorPtr = amb::make_super(error); diff --git a/plugins/dbus/abstractdbusinterface.cpp b/plugins/dbus/abstractdbusinterface.cpp index f4c575c..684b8ff 100644 --- a/plugins/dbus/abstractdbusinterface.cpp @@ -123,3 +187,16 @@ index 352961b..601ff18 100755 managerObject = bus.get_object("org.automotive.message.broker", "/"); managerInterface = dbus.Interface(managerObject, "org.automotive.Manager") +diff --git a/xwalk/vehicle.cc b/xwalk/vehicle.cc +index cea8480..9708341 100644 +--- a/xwalk/vehicle.cc ++++ b/xwalk/vehicle.cc +@@ -295,7 +295,7 @@ Vehicle::Vehicle(common::Instance* instance) + + GError* error = nullptr; + +- dbus_connection_ = amb::make_super(g_bus_get_sync(G_BUS_TYPE_SYSTEM, ++ dbus_connection_ = amb::make_super(g_bus_get_sync(bustype, + nullptr, + &error)); + diff --git a/src/script/build.sh b/src/script/build.sh index 93ec390..8912b26 100755 --- a/src/script/build.sh +++ b/src/script/build.sh @@ -25,12 +25,15 @@ source fsa-config.sh # by default no ilm lm=0 +# by default no debug +dbg=0 + + #-------------------------------------------------------------------------- # Compiler Flags #-------------------------------------------------------------------------- # modify the following flags as needed: #-------------------------------------------------------------------------- -FUEL_STOP_ADVISOR_FLAGS='-DWITH_DEBUG=OFF' usage() { echo "Usage: ./build.sh [command]" @@ -38,6 +41,7 @@ usage() { echo "command:" echo " make Build" echo " makelm Build with layer manager" + echo " maked Build in debug mode" echo " clean Clean the bin" echo " src-clean Clean the cloned sources and the bin" echo " clone Clone the sources" @@ -76,11 +80,14 @@ build() { # Build the navigation service (including DBus files generation) cd $NAVIGATION_SERVICE_BUILD_SCRIPT_DIR if [ $lm -eq 0 ]; then - bash ./build.sh make $NAVIGATION_SERVICE_BIN_DIR $POSITIONING_SRC_DIR $IVI_LAYER_MANAGER_SRC_DIR + if [ $dbg -eq 0 ]; then + bash ./build.sh make $NAVIGATION_SERVICE_BIN_DIR $POSITIONING_SRC_DIR $IVI_LAYER_MANAGER_SRC_DIR + else + bash ./build.sh maked $NAVIGATION_SERVICE_BIN_DIR $POSITIONING_SRC_DIR $IVI_LAYER_MANAGER_SRC_DIR + fi else - bash ./build.sh makelm $NAVIGATION_SERVICE_BIN_DIR $POSITIONING_SRC_DIR $IVI_LAYER_MANAGER_SRC_DIR + bash ./build.sh makelm $NAVIGATION_SERVICE_BIN_DIR $POSITIONING_SRC_DIR $IVI_LAYER_MANAGER_SRC_DIR fi - cd $TOP_BIN_DIR mkdir -p $FUEL_STOP_ADVISOR cd $FUEL_STOP_ADVISOR_BIN_DIR @@ -90,11 +97,12 @@ build() { mkdir -p $AUTOMOTIVE_MESSAGE_BROKER cd $AUTOMOTIVE_MESSAGE_BROKER_BIN_DIR cmake $AUTOMOTIVE_MESSAGE_BROKER_SRC_DIR && make + sudo make install cd $TOP_BIN_DIR mkdir -p $LOG_REPLAYER cd $LOG_REPLAYER_BIN_DIR - cmake $LOG_REPLAYER_SRC_DIR && make + cmake $FUEL_STOP_ADVISOR_FLAGS $LOG_REPLAYER_SRC_DIR && make cd $TOP_BIN_DIR mkdir -p $GENIVI_LOGREPLAYER @@ -132,10 +140,16 @@ if [ $# -ge 1 ]; then if [ $1 = help ]; then usage elif [ $1 = make ]; then + FUEL_STOP_ADVISOR_FLAGS='-DWITH_DEBUG=OFF' build elif [ $1 = makelm ]; then + FUEL_STOP_ADVISOR_FLAGS='-DWITH_DEBUG=OFF' lm=1 build + elif [ $1 = maked ]; then + FUEL_STOP_ADVISOR_FLAGS='-DWITH_DEBUG=ON' + dbg=1 + build elif [ $1 = clean ]; then clean elif [ $1 = src-clean ]; then diff --git a/src/script/run b/src/script/run index ab09450..9d55331 100755 --- a/src/script/run +++ b/src/script/run @@ -112,7 +112,7 @@ enhpos=1 #enhanced position server enabled replayer=1 #replayer enabled lm=0 #layer manager disabled wm="" #to store the current window manager (in case of start with the layer manager) -verbose=0 #no debug or log messages +verbose=0 #no debug or log messages displayed center="4612 N 0608 E" # hmi panel launched @@ -206,7 +206,7 @@ then # Create Window OpenGL (Default gtk_drawing_area) export NAVIT_GRAPHICS=opengl - # Graphics OpneGL Platfrom + # Graphics OpenGL Platfrom export NAVIT_PLATFORM=wayland # ILM library path(for hmi-launcher& genivi_mapviewer_mapviewercontrol.cxx) @@ -229,7 +229,12 @@ set -e #exit on error now # start the automotive message broker and wait for dbus service cd $AUTOMOTIVE_MESSAGE_BROKER_BIN_DIR -run "Automotive Message Broker" ./ambd/ambd > /dev/null 2>&1 --config $GENIVI_LOGREPLAYER_SRC_DIR/logreplayerconfig +if [ "$verbose" = "1" ] +then + run "Automotive Message Broker" ./ambd/ambd --config $GENIVI_LOGREPLAYER_SRC_DIR/logreplayerconfig +else + run "Automotive Message Broker" ./ambd/ambd > /dev/null 2>&1 --config $GENIVI_LOGREPLAYER_SRC_DIR/logreplayerconfig +fi wait_for_service org.automotive.message.broker / # start the poi server and wait for dbus service @@ -261,8 +266,8 @@ wait_for_service org.genivi.navigationcore.Routing /org/genivi/navigationcore wait_for_service org.genivi.navigationcore.Session /org/genivi/navigationcore if [ "$replayer" = 1 ] -then # start the log replayer (of the fsa) - run "Log Replayer" $LOG_REPLAYER_BIN_DIR/src/$LOG_REPLAYER > /dev/null 2>&1 $POSITIONING_LOG_REPLAYER_SRC_DIR/logs/geneve-cologny.log +then # start the log replayer (of the fsa) with a sample log file + run "Log Replayer" $LOG_REPLAYER_BIN_DIR/src/$LOG_REPLAYER $POSITIONING_LOG_REPLAYER_SRC_DIR/logs/geneve-cologny.log fi sleep 3 # need a sleep here (to be improved) diff --git a/test/resource/test-positioning.log b/test/resource/test-positioning.log new file mode 100644 index 0000000..9780465 --- /dev/null +++ b/test/resource/test-positioning.log @@ -0,0 +1,13 @@ +#SPDX-License-Identifier: CC-BY-SA-4.0 +#Log file for the FSA simulator +#GNS version 2.0.0 +#SNS version 2.0.0 +#localization geneve cologny +#vehicle speed 0 km/h +#step 1000 ms +0,0$GVGNSVER,2,0,0 +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/resource/test-vehicle-info.log b/test/resource/test-vehicle-info.log new file mode 100644 index 0000000..de1893a --- /dev/null +++ b/test/resource/test-vehicle-info.log @@ -0,0 +1,14 @@ +#SPDX-License-Identifier: CC-BY-SA-4.0 +#Log file for the FSA simulator +#VEH version 0.0.0 (alpha) +#engine speed 2000 RPM +#ignition key ON (Not Applicable) +#fuel level 30 l +#fuel consumption 5.4 l/h so 1500 µl/1000 ms (6 l/100) +#step 1000 ms +#totalodo is used for simulating distance step in cm +0,0$GVVEHVER,0,0,0 +1000,0$GVVEHENGSPEED,2000,0X01 +1000,0$GVVEHFUELLEVEL,30,0X01 +1000,0$GVVEHFUELCONS,1500,0X01 +1000,0$GVVEHTOTALODO,2500,0x01 diff --git a/test/script/configTests.py b/test/script/configTests.py index 6c5dcd0..788ceb2 100755 --- a/test/script/configTests.py +++ b/test/script/configTests.py @@ -36,7 +36,7 @@ def launch(file,host): FNULL = open(os.devnull,'w') logreplayer=PATH_LOGREPLAYER + 'log-replayer' file=PATH_LOGFILES + file - call([logreplayer, file, host], stdout=FNULL, stderr=FNULL) + call([logreplayer, file, host]) diff --git a/test/script/test-positioning.py b/test/script/test-positioning.py new file mode 100644 index 0000000..79a2473 --- /dev/null +++ b/test/script/test-positioning.py @@ -0,0 +1,264 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @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 = 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(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(.100) + # 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 new file mode 100644 index 0000000..c840c66 --- /dev/null +++ b/test/script/test-vehicle-info.py @@ -0,0 +1,277 @@ +#!/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(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.GetEngineSpeed() + 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() + + + |