summaryrefslogtreecommitdiff
path: root/src/poi-service
diff options
context:
space:
mode:
author <philippe colliot>2015-07-31 17:35:52 +0200
committer <philippe colliot>2015-07-31 17:35:52 +0200
commitac409b558640628fc6f1f6950f21445191806b17 (patch)
tree3ae89254b7371d1bee2fce6c8f949ed7502c880b /src/poi-service
parentad37685c632afe2129082ff6a76e5c243dda6a18 (diff)
downloadpoi-service-ac409b558640628fc6f1f6950f21445191806b17.tar.gz
[POISERVICE] Add/remove category and POI tested, still need to test
search, some math functions added お疲れ様 !
Diffstat (limited to 'src/poi-service')
-rw-r--r--src/poi-service/poi-common/poi-common-data-model.h22
-rw-r--r--src/poi-service/poi-common/poi-common-math.cpp77
-rw-r--r--src/poi-service/poi-common/poi-common-math.h47
-rw-r--r--src/poi-service/poi-manager-server/CMakeLists.txt2
-rw-r--r--src/poi-service/poi-manager-server/poi-manager-server-stub.cpp155
-rw-r--r--src/poi-service/poi-manager-server/poi-manager-server-stub.h9
6 files changed, 206 insertions, 106 deletions
diff --git a/src/poi-service/poi-common/poi-common-data-model.h b/src/poi-service/poi-common/poi-common-data-model.h
index 8adc3e1..de68ffd 100644
--- a/src/poi-service/poi-common/poi-common-data-model.h
+++ b/src/poi-service/poi-common/poi-common-data-model.h
@@ -37,6 +37,12 @@ typedef uint32_t attributeId_t;
typedef uint32_t handleId_t;
typedef uint8_t camId_t;
+typedef struct
+{
+ double latitude;
+ double longitude;
+ int altitude;
+} geocoordinate3D_t;
enum ATTRIBUTE_LIST{
ATTRIBUTE_SOURCE = 0,
@@ -94,7 +100,6 @@ typedef struct
std::vector<categoryId_t> childList; //list of children
} poi_category_common_t;
-
// some defines to be used by the test
#define ALL_CATEGORIES 0
#define INVALID_CATEGORY 0x00
@@ -115,17 +120,22 @@ typedef struct
#define POI_LOCATION_LATITUDE 48.779839
#define POI_LOCATION_LONGITUDE 2.217260
#define POI_LOCATION_ALTITUDE 120
-#define LEFT_BOTTOM_LOCATION_LATITUDE 48.76
-#define LEFT_BOTTOM_LOCATION_LONGITUDE 2.22
-#define RIGHT_TOP_LOCATION_LATITUDE 48.78
-#define RIGHT_TOP_LOCATION_LONGITUDE 2.20
+#define SEARCH_CENTER_LOCATION_LATITUDE 48.76
+#define SEARCH_CENTER_LOCATION_LONGITUDE 2.22
+#define SEARCH_CENTER_LOCATION_ALTITUDE 100
+#define SEARCH_RADIUS 200 //in tens of meters
+#define SEARCH_STRING "Sweet"
#define LANGUAGE_CODE "fra"
#define COUNTRY_CODE "FRA"
#define SCRIPT_CODE "Latn"
-#define SEARCH_STRING "Sweet"
#define MEDIASET 1
#define PARENT_ID 0
+#define SEARCH_HANDLE 1
+#define SEARCH_MAX_SIZE 50
+
+#define NO_HANDLE 0
+
#endif
diff --git a/src/poi-service/poi-common/poi-common-math.cpp b/src/poi-service/poi-common/poi-common-math.cpp
new file mode 100644
index 0000000..e7c1706
--- /dev/null
+++ b/src/poi-service/poi-common/poi-common-math.cpp
@@ -0,0 +1,77 @@
+/**
+* @licence app begin@
+* SPDX-License-Identifier: MPL-2.0
+*
+* \copyright Copyright (C) 2013-2015, PCA Peugeot Citroen
+*
+* \file poi-common-math.cpp
+*
+* \brief This file is part of the poi proof of concept.
+*
+* \author Philippe Colliot <philippe.colliot@mpsa.com>
+*
+* \version 1.1
+*
+* This Source Code Form is subject to the terms of the
+* Mozilla Public License (MPL), 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/.
+*
+* For further information see http://www.genivi.org/.
+*
+* List of changes:
+* <date>, <name>, <description of change>
+*
+* @licence end@
+*/
+
+#include "poi-common-math.h"
+
+double calculateAngle(const uint32_t radius)
+ {
+ //N is the point on the sphere for the origin
+ //M is a point of the sphere at the distance radius (NM = radius)
+ //O is the center of the earth
+ //ON=OM so the triangle is isosceles
+ //alpha is the angle ON,OM
+ //beta is the angle NM,NO
+ //OM*sin(alpha)=NM*sin(beta)
+ //alpha+beta+beta=PI (because of isoceles)
+ //beta=(PI-alpha)/2
+ //sin(beta) = cos(alpha/2)
+ //sin(alpha)=2*sin(alpha/2)*cos(alpha/2)
+ //alpha=2*arcsin(NM/(2*OM))
+
+ //earth is considered to be a perfect spĥere, in order to simplify calculation
+ const double PI = 4.0*atan(1.0);
+ const double earth=6378137; //IUGG value for the equatorial radius of the Earth in m
+ double angle;
+ angle=2*asin(radius/(2*earth));
+ angle = (angle*180)/PI; //in degrees
+ return(angle);
+ }
+
+uint32_t calculateDistance(const geocoordinate3D_t origin, const geocoordinate3D_t target)
+ {
+ //this piece of software is based on an haversine formula given by:
+ // - Doctors Rick and Peterson, The Math Forum
+ // http://mathforum.org/dr.math/
+ // haversine of angle A is (1-cos(A))/2 that is equal to sin^2(A/2)
+
+ //earth is considered to be a perfect spĥere, in order to simplify calculation
+ const double PI = 4.0*atan(1.0);
+ const double earth=6378137; //IUGG value for the equatorial radius of the Earth in m
+ geocoordinate3D_t pointA, pointB;
+ double buffer;
+
+ pointA.latitude = origin.latitude * (PI/180);
+ pointA.longitude = origin.longitude * (PI/180);
+ pointB.latitude = target.latitude * (PI/180);
+ pointB.longitude = target.longitude * (PI/180);
+
+ buffer= pow(sin((pointA.latitude-pointB.latitude)/2.0),2.0)+cos(pointA.latitude)*cos(pointB.latitude)*pow(sin((pointA.longitude-pointB.longitude)/2),2);
+ buffer = 2*atan2(sqrt(buffer),sqrt(1.0-buffer));
+ buffer=earth*buffer;
+ return ((uint32_t) buffer); //return distance in meters
+ }
+
diff --git a/src/poi-service/poi-common/poi-common-math.h b/src/poi-service/poi-common/poi-common-math.h
new file mode 100644
index 0000000..2f27c1d
--- /dev/null
+++ b/src/poi-service/poi-common/poi-common-math.h
@@ -0,0 +1,47 @@
+/**
+* @licence app begin@
+* SPDX-License-Identifier: MPL-2.0
+*
+* \copyright Copyright (C) 2013-2015, PCA Peugeot Citroen
+*
+* \file poi-common-math.h
+*
+* \brief This file is part of the poi proof of concept.
+*
+* \author Philippe Colliot <philippe.colliot@mpsa.com>
+*
+* \version 1.1
+*
+* This Source Code Form is subject to the terms of the
+* Mozilla Public License (MPL), 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/.
+*
+* For further information see http://www.genivi.org/.
+*
+* List of changes:
+* <date>, <name>, <description of change>
+*
+* @licence end@
+*/
+#ifndef __POICOMMONMATH_H__
+#define __POICOMMONMATH_H__
+
+#include <stdbool.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <iostream>
+#include <cmath>
+#include <typeinfo>
+#include <vector>
+#include "poi-common-data-model.h"
+
+double calculateAngle(const uint32_t radius);
+
+uint32_t calculateDistance(const geocoordinate3D_t origin, const geocoordinate3D_t target);
+
+
+#endif
diff --git a/src/poi-service/poi-manager-server/CMakeLists.txt b/src/poi-service/poi-manager-server/CMakeLists.txt
index 6f79838..c832967 100644
--- a/src/poi-service/poi-manager-server/CMakeLists.txt
+++ b/src/poi-service/poi-manager-server/CMakeLists.txt
@@ -51,7 +51,7 @@ pkg_check_modules(GLIBMM glibmm-2.4)
pkg_check_modules(GOBJECT gobject-2.0)
# Source Files
-FILE(GLOB PRJ_LOCAL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
+FILE(GLOB PRJ_LOCAL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${COMMON_DIR}/*.cpp)
FILE(GLOB PRJ_COMMON_SRCS ${COMMON_DIR}/*.cpp)
add_subdirectory(${FRANCA_DIR}/poiservice "${CMAKE_CURRENT_BINARY_DIR}/franca")
diff --git a/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp b/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp
index 91250ee..9184aa7 100644
--- a/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp
+++ b/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp
@@ -1223,6 +1223,8 @@ PoiManagerServerStub::PoiManagerServerStub() {
m_centerLocation.setAltitude(30);
mp_sqlRequest = new sqlRequest;
+
+ m_search_handle = NO_HANDLE;
}
PoiManagerServerStub::~PoiManagerServerStub() {
@@ -1393,122 +1395,79 @@ void PoiManagerServerStub::removePOIs(const std::shared_ptr<CommonAPI::ClientId>
}
}
-void PoiManagerServerStub::run()
+void PoiManagerServerStub::poiSearchStarted(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, uint16_t _maxSize, ::org::genivi::navigation::NavigationTypes::Coordinate3D _location, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::CategoryAndRadius> _poiCategories, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeDetails> _poiAttributes, std::string _inputString, uint16_t _sortOption, poiSearchStartedReply_t _reply)
{
-}
+ POIServiceTypes::CategoryAndRadius categoryAndRadius;
+ size_t index;
+ string categoryName;
+ double angle;
+ NavigationTypes::Coordinate3D leftBottomLocation, rightTopLocation;
+ std::vector<POIServiceTypes::POI_ID> poiIDList;
-bool PoiManagerServerStub::initDatabase(const char* poiDatabaseFileName)
-{
- mp_sqlRequest->setDatabase(poiDatabaseFileName);
- refreshCategoryList(); //read the database and buffer the category list locally
+ //For the moment, just search for one category
+ categoryAndRadius = _poiCategories.at(0);
-// return test();
+ //First step is to check the consistency of the request
+ for(index=0;index<m_availableCategoryTable.size();index++)
+ {
+ if ((m_availableCategoryTable.at(index)).id == categoryAndRadius.getId())
+ {
+ categoryName = (m_availableCategoryTable.at(index)).name;
+ break;
+ }
+ }
+ if (index>=m_availableCategoryTable.size())
+ {
+ //no id found, error to be sent
+ fireSearchStatusChangedEvent(_poiSearchHandle,POIServiceTypes::SearchStatusState::INVALID);
+ return;
+ }
- return true; //maybe add some check of the file here
-}
+ //calculate the angle
+ angle = calculateAngle(categoryAndRadius.getRadius()*10); // radius unit is 10 m
-bool PoiManagerServerStub::test()
-{
- // test: create a new category, with a new attribute and add a poi under this category
- POIServiceTypes::CAMCategory category;
- POIServiceTypes::Details categoryDetails;
- POIServiceTypes::CategoryAttribute categoryAttribute;
- std::vector<POIServiceTypes::CategoryAttribute> categoryAttributeList;
- std::vector<POIServiceTypes::CategoryID> categoryParentsId;
-
- POIServiceTypes::CategoryID categoryId;
- POIServiceTypes::POI_ID poiId;
- std::vector<POIServiceTypes::POI_ID> poiIdList;
-
- POIServiceTypes::PoiAddedDetails poi;
- POIServiceTypes::PoiAttribute poiAttribute;
- std::vector<POIServiceTypes::PoiAttribute> poiAttributeList;
-
- NavigationTypes::Coordinate3D left_bottom_location,right_top_location,location;
- std::string str;
-
- categoryDetails = category.getDetails();
- categoryDetails.setName(NEW_CATEGORY_NAME);
- categoryParentsId = categoryDetails.getParentsId();
- categoryParentsId.clear();
- categoryParentsId.push_back(PARENT_ID);
- categoryDetails.setParentsId(categoryParentsId);
- category.setDetails(categoryDetails); //new category
-
- categoryAttributeList = category.getAttributes();
- categoryAttributeList.clear();
- categoryAttribute.setId(ATTRIBUTE_PHONE);
- categoryAttribute.setName(ATTRIBUTE_PHONE_NAME); //existing attribute
- categoryAttributeList.push_back(categoryAttribute);
- categoryAttribute.setId(ATTRIBUTE_CREDIT_CARD); //new attribute id
- categoryAttribute.setName(ATTRIBUTE_CREDIT_CARD_NAME); //new attribute
- categoryAttributeList.push_back(categoryAttribute);
- category.setAttributes(categoryAttributeList);
-
- poi.setName(POI_NAME);
-
- location.setLatitude(POI_LOCATION_LATITUDE);
- location.setLongitude(POI_LOCATION_LONGITUDE);
- location.setAltitude(POI_LOCATION_ALTITUDE);
- poi.setLocation(location);
-
- poiAttributeList = poi.getAttributes();
- poiAttributeList.clear();
- poiAttribute.setId(ATTRIBUTE_ADDRCITY);
- POIServiceTypes::AttributeValue vs(string(NEW_CITY_NAME));
- poiAttribute.setValue(vs);
- poiAttributeList.push_back(poiAttribute);
- poiAttribute.setId(ATTRIBUTE_STARS);
- POIServiceTypes::AttributeValue v(NEW_STARS_VALUE);
- poiAttribute.setValue(v);
- poiAttributeList.push_back(poiAttribute);
- poi.setAttributes(poiAttributeList);
-
- left_bottom_location.setLatitude(LEFT_BOTTOM_LOCATION_LATITUDE);
- left_bottom_location.setLongitude(LEFT_BOTTOM_LOCATION_LONGITUDE);
- right_top_location.setLatitude(RIGHT_TOP_LOCATION_LATITUDE);
- right_top_location.setLongitude(RIGHT_TOP_LOCATION_LONGITUDE);
-
- // Create category, create poi, search, remove poi, remove category
- if (mp_sqlRequest->createCategory(category,categoryId) != sqlRequest::OK)
- return false;
+ leftBottomLocation.setLatitude(_location.getLatitude() - angle);
+ leftBottomLocation.setLongitude(_location.getLongitude() - angle);
+ rightTopLocation.setLatitude(_location.getLatitude() + angle);
+ rightTopLocation.setLongitude(_location.getLongitude() + angle);
- refreshCategoryList(); //read the database and buffer the category list locally
- if (mp_sqlRequest->createPoi(categoryId,poi,poiId) != sqlRequest::OK)
- return false;
+ m_search_handle = _poiSearchHandle; //for the moment, only one handle is managed
- str = SEARCH_STRING;
- if (mp_sqlRequest->searchPoi(category.getDetails().getName(),str,left_bottom_location,right_top_location,poiIdList) != sqlRequest::OK)
- return false;
+ fireSearchStatusChangedEvent(_poiSearchHandle,POIServiceTypes::SearchStatusState::SEARCHING);
- if (mp_sqlRequest->removePoi(poiId) != sqlRequest::OK)
- return false;
+ mp_sqlRequest->searchPoi(categoryName,_inputString, leftBottomLocation, rightTopLocation, poiIDList);
- if (mp_sqlRequest->removeCategory(categoryId) != sqlRequest::OK)
- return false;
+ fireSearchStatusChangedEvent(_poiSearchHandle,POIServiceTypes::SearchStatusState::FINISHED);
- refreshCategoryList(); //read the database and buffer the category list locally
+}
- // Create category, create poi, remove category (auto remove orphan poi), search
- if (mp_sqlRequest->createCategory(category,categoryId) != sqlRequest::OK)
- return false;
+void PoiManagerServerStub::poiSearchCanceled(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, poiSearchCanceledReply_t _reply)
+{
+ m_search_handle = NO_HANDLE;
+ fireSearchStatusChangedEvent(_poiSearchHandle,POIServiceTypes::SearchStatusState::NOT_STARTED);
+}
- refreshCategoryList(); //read the database and buffer the category list locally
+void PoiManagerServerStub::resultListRequested(const std::shared_ptr<CommonAPI::ClientId> _client, uint8_t _camId, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeID> _attributes, resultListRequestedReply_t _reply)
+{
- if (mp_sqlRequest->createPoi(categoryId,poi,poiId) != sqlRequest::OK)
- return false;
+}
- if (mp_sqlRequest->removeCategory(categoryId) != sqlRequest::OK)
- return false;
+void PoiManagerServerStub::poiDetailsRequested(const std::shared_ptr<CommonAPI::ClientId> _client, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::POI_ID> _source_id, poiDetailsRequestedReply_t _reply)
+{
- refreshCategoryList(); //read the database and buffer the category list locally
+}
- str = SEARCH_STRING;
- if (mp_sqlRequest->searchPoi(category.getDetails().getName(),str,left_bottom_location,right_top_location,poiIdList) != sqlRequest::POI_ID_NOT_EXIST)
- return false;
+void PoiManagerServerStub::run()
+{
+}
- return true;
+bool PoiManagerServerStub::initDatabase(const char* poiDatabaseFileName)
+{
+ mp_sqlRequest->setDatabase(poiDatabaseFileName);
+ refreshCategoryList(); //read the database and buffer the category list locally
+
+ return true; //maybe add some check of the file here
}
// refresh the buffer that contains the categories related data, called each time a category is added or removed
diff --git a/src/poi-service/poi-manager-server/poi-manager-server-stub.h b/src/poi-service/poi-manager-server/poi-manager-server-stub.h
index 48f283c..26830d1 100644
--- a/src/poi-service/poi-manager-server/poi-manager-server-stub.h
+++ b/src/poi-service/poi-manager-server/poi-manager-server-stub.h
@@ -37,6 +37,8 @@
#include "poi-common-data-model.h"
+#include "poi-common-math.h"
+
using namespace std;
using namespace v0_1::org::genivi::navigation::poiservice;
using namespace org::genivi::navigation;
@@ -199,6 +201,10 @@ public:
void removeCategories(const std::shared_ptr<CommonAPI::ClientId> _client, std::vector< POIServiceTypes::CategoryID> _categories, removeCategoriesReply_t _reply);
void addPOIs(const std::shared_ptr<CommonAPI::ClientId> _client, POIServiceTypes::CategoryID _unique_id, std::vector< POIServiceTypes::PoiAddedDetails> _poiList, addPOIsReply_t _reply);
void removePOIs(const std::shared_ptr<CommonAPI::ClientId> _client, std::vector< POIServiceTypes::POI_ID> _ids, removePOIsReply_t _reply);
+ void poiSearchStarted(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, uint16_t _maxSize, ::org::genivi::navigation::NavigationTypes::Coordinate3D _location, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::CategoryAndRadius> _poiCategories, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeDetails> _poiAttributes, std::string _inputString, uint16_t _sortOption, poiSearchStartedReply_t _reply);
+ void poiSearchCanceled(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, poiSearchCanceledReply_t _reply);
+ void resultListRequested(const std::shared_ptr<CommonAPI::ClientId> _client, uint8_t _camId, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeID> _attributes, resultListRequestedReply_t _reply);
+ void poiDetailsRequested(const std::shared_ptr<CommonAPI::ClientId> _client, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::POI_ID> _source_id, poiDetailsRequestedReply_t _reply);
void run();
@@ -214,6 +220,8 @@ private:
POIServiceTypes::CategoryID m_rootCategory;
NavigationTypes::Coordinate3D m_centerLocation;
+ NavigationTypes::Handle m_search_handle;
+
sqlRequest* mp_sqlRequest;
void refreshCategoryList();
@@ -225,7 +233,6 @@ private:
return !(iss >> f >> t).fail();
}
- bool test();
};
#endif /* POIMANAGERSERVERSTUBIMPL_H_ */