1 // Copyright 2017 AW SOFTWARE CO.,LTD
2 // Copyright 2017 AISIN AW CO.,LTD
4 #include "genivi/navicore.h"
5 #include "genivi/genivi-navicore-constants.h"
6 #include "genivi_request.h"
9 #include <dbus-c++-1/dbus-c++/dbus.h>
14 GeniviRequest::~GeniviRequest()
16 delete (Navicore*)navicore_;
21 * @brief DBus session creation
23 void GeniviRequest::CreateDBusSession( )
27 static DBus::BusDispatcher dispatcher;
28 DBus::default_dispatcher = &dispatcher;
29 DBus::Connection conn = DBus::Connection::SessionBus();
31 navicore_ = new Navicore(conn, "/org/genivi/navicore", "org.agl.naviapi");
33 catch(const std::exception& e)
35 fprintf(stderr, "Error:%s\n", e.what());
40 * @brief Check connection status
41 * @return Presence / absence of connection
43 bool GeniviRequest::CheckSession()
45 if(this->navicore_ == NULL)
47 this->CreateDBusSession();
52 // Get connection status
53 DBus::Connection conn = ((Navicore*)navicore_)->conn();
54 bool isConnect = conn.connected();
56 // If it is not connected, it issues an error
59 fprintf(stderr, "Service has no session.\n");
64 catch(const std::exception& e)
66 fprintf(stderr, "Error:%s\n", e.what());
72 * @brief Call GeniviAPI GetPosition to get information
73 * @param[in] valuesToReturn Key arrangement of information acquired from Genivi
74 * @return Map information on key and value of information acquired from Genivi
76 std::map< int32_t, double > GeniviRequest::NavicoreGetPosition( const std::vector< int32_t >& valuesToReturn )
78 std::map< int32_t, double > ret;
87 std::map< int32_t, ::DBus::Struct< uint8_t, ::DBus::Variant > >::iterator it;
88 std::map< int32_t, ::DBus::Struct< uint8_t, ::DBus::Variant > > PosList =
89 ((Navicore*)navicore_)->GetPosition(valuesToReturn);
90 for (it = PosList.begin(); it != PosList.end(); it++)
92 if (it->first == NAVICORE_LATITUDE || it->second._1 == NAVICORE_LATITUDE)
94 ret[it->first] = it->second._2.reader().get_double();
96 else if (it->first == NAVICORE_LONGITUDE || it->second._1 == NAVICORE_LONGITUDE)
98 ret[it->first] = it->second._2.reader().get_double();
100 else if (it->first == NAVICORE_HEADING || it->second._1 == NAVICORE_HEADING)
102 ret[it->first] = it->second._2.reader().get_uint32();
104 #if 0 // no supported
105 else if (it->first == NAVICORE_TIMESTAMP || it->second._1 == NAVICORE_TIMESTAMP)
107 ret[it->first] = it->second._2.reader().get_uint32();
109 else if (it->first == NAVICORE_SPEED || it->second._1 == NAVICORE_SPEED)
111 ret[it->first] = it->second._2.reader().get_int32();
114 else if (it->first == NAVICORE_SIMULATION_MODE || it->second._1 == NAVICORE_SIMULATION_MODE)
116 ret[it->first] = it->second._2.reader().get_bool();
120 catch(const std::exception& e)
122 fprintf(stderr, "Error:%s\n", e.what());
129 * @brief Call GeniviAPI GetPosition to get information
130 * @return Route handle acquired from Genivi
132 std::vector< uint32_t > GeniviRequest::NavicoreGetAllRoutes( void )
134 if( !CheckSession() )
136 std::vector< uint32_t > no_route;
140 std::vector< uint32_t > allRoutes;
143 allRoutes = ((Navicore*)navicore_)->GetAllRoutes();
145 catch(const std::exception& e)
147 fprintf(stderr, "Error:%s\n", e.what());
155 * @brief Call GeniviAPI GetPosition to get information
156 * @param[in] sessionHandle Session handle
157 * @return Route handle acquired from Genivi
159 uint32_t GeniviRequest::NavicoreCreateRoute( const uint32_t& sessionHandle )
161 if( !CheckSession() )
166 uint32_t routeHandle = 0;
169 routeHandle = ((Navicore*)navicore_)->CreateRoute(sessionHandle);
171 catch(const std::exception& e)
173 fprintf(stderr, "Error:%s\n", e.what());
180 * @brief Call GeniviAPI PauseSimulation
181 * @param[in] sessionHandle Session handle
183 void GeniviRequest::NavicorePauseSimulation( const uint32_t& sessionHandle )
185 if( !CheckSession() )
192 ((Navicore*)navicore_)->PauseSimulation(sessionHandle);
194 catch(const std::exception& e)
196 fprintf(stderr, "Error:%s\n", e.what());
202 * @brief Call GeniviAPI SetSimulationMode
203 * @param[in] sessionHandle Session handle
204 * @param[in] activate Simulation mode enabled / disabled
206 void GeniviRequest::NavicoreSetSimulationMode( const uint32_t& sessionHandle, const bool& activate )
208 if( !CheckSession() )
215 ((Navicore*)navicore_)->SetSimulationMode(sessionHandle, activate);
217 catch(const std::exception& e)
219 fprintf(stderr, "Error:%s\n", e.what());
225 * @brief Call GeniviAPI SetSimulationMode
226 * @param[in] sessionHandle Session handle
227 * @param[in] routeHandle Route handle
229 void GeniviRequest::NavicoreCancelRouteCalculation( const uint32_t& sessionHandle, const uint32_t& routeHandle )
231 if( !CheckSession() )
238 ((Navicore*)navicore_)->CancelRouteCalculation(sessionHandle, routeHandle);
240 catch(const std::exception& e)
242 fprintf(stderr, "Error:%s\n", e.what());
247 * @brief Call GeniviAPI SetWaypoints
248 * @param[in] sessionHandle Session handle
249 * @param[in] routeHandle Route handle
250 * @param[in] startFromCurrentPosition Whether or not to draw a route from the position of the vehicle
251 * @param[in] waypointsList Destination coordinates
253 void GeniviRequest::NavicoreSetWaypoints( const uint32_t& sessionHandle, const uint32_t& routeHandle,
254 const bool& startFromCurrentPosition, const std::vector<Waypoint>& waypointsList )
256 if( !CheckSession() )
261 std::vector<Waypoint>::const_iterator it;
262 std::vector< std::map< int32_t, ::DBus::Struct< uint8_t, ::DBus::Variant > > > wpl;
264 fprintf(stdout, "session: %d, route: %d, startFromCurrentPosition: %d\n",
265 sessionHandle, routeHandle, startFromCurrentPosition);
267 for (it = waypointsList.begin(); it != waypointsList.end(); it++)
269 std::map< int32_t, ::DBus::Struct< uint8_t, ::DBus::Variant > > Point;
270 ::DBus::Struct< uint8_t, ::DBus::Variant > VarLat, VarLon;
272 VarLat._1 = NAVICORE_LATITUDE;
273 VarLat._2.writer().append_double(std::get<0>(*it));
274 fprintf(stdout, "VarLat._1 : %x, VarLat._2 : %lf\n", VarLat._1, VarLat._2.reader().get_double());
276 VarLon._1 = NAVICORE_LONGITUDE;
277 VarLon._2.writer().append_double(std::get<1>(*it));
278 fprintf(stdout, "VarLon._1 : %x, VarLon._2 : %lf\n", VarLon._1, VarLon._2.reader().get_double());
280 Point[NAVICORE_LATITUDE] = VarLat;
281 Point[NAVICORE_LONGITUDE] = VarLon;
283 wpl.push_back(Point);
288 ((Navicore*)navicore_)->SetWaypoints(sessionHandle, routeHandle, startFromCurrentPosition, wpl);
290 catch(const std::exception& e)
292 fprintf(stderr, "Error:%s\n", e.what());
297 * @brief Call GeniviAPI CalculateRoute
298 * @param[in] sessionHandle Session handle
299 * @param[in] routeHandle Route handle
301 void GeniviRequest::NavicoreCalculateRoute( const uint32_t& sessionHandle, const uint32_t& routeHandle )
303 if( !CheckSession() )
310 ((Navicore*)navicore_)->CalculateRoute(sessionHandle, routeHandle);
312 catch(const std::exception& e)
314 fprintf(stderr, "Error:%s\n", e.what());
320 * @brief Call GeniviAPI CalculateRoute
321 * @return Map information on key and value of information acquired from Genivi
323 std::map<uint32_t, std::string> GeniviRequest::NavicoreGetAllSessions()
325 std::map<uint32_t, std::string> ret;
327 if( !CheckSession() )
332 std::vector< ::DBus::Struct< uint32_t, std::string > > ncAllSessions;
333 std::vector< ::DBus::Struct< uint32_t, std::string > >::iterator it;
337 ncAllSessions = ((Navicore*)navicore_)->GetAllSessions();
338 for (it = ncAllSessions.begin(); it != ncAllSessions.end(); it++)
340 ret[it->_1] = it->_2;
343 catch(const std::exception& e)
345 fprintf(stderr, "Error:%s\n", e.what());