aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-07-09 10:52:05 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-07-09 10:52:05 +0900
commit101db974a45feaf0819887121f638f7fd0eab3a9 (patch)
treeda4d8ca5ed96bc893ed5dc73f7fb5adcf7f096bf
parentfe7254f007b66664340d53276eb53da19fd3498c (diff)
add demo start position
-rw-r--r--config.xml.in2
-rw-r--r--include/navigation_info.h25
-rw-r--r--src/api.cpp181
-rw-r--r--src/binder_reply.cpp2
-rw-r--r--src/navigation_info.cpp57
5 files changed, 262 insertions, 5 deletions
diff --git a/config.xml.in b/config.xml.in
index e4a8a51..89297ec 100644
--- a/config.xml.in
+++ b/config.xml.in
@@ -16,7 +16,7 @@
</feature>
<feature name="urn:AGL:widget:required-api">
<param name="lib/libNaviAPIService.so" value="local" />
- <param name="192.168.123.11:4002/gps" value="tcp" />
+ <param name="192.168.123.11:4001/gps" value="tcp" />
<param name="192.168.123.11:4000/carlaclient" value="tcp" />
</feature>
</widget>
diff --git a/include/navigation_info.h b/include/navigation_info.h
index ea578ba..6b20ad4 100644
--- a/include/navigation_info.h
+++ b/include/navigation_info.h
@@ -25,6 +25,13 @@ private:
/* GetDirState */
char mCurrentState[256]; //current direction state info
+ /* GetTotalDistance and GetCumulativeDistance */
+ char mCurrentTotalDistance[256]; //current total distance info
+ char mCurrentCumulativeDistance[256]; //current cumulative distance info
+
+ /* GetGuidanceState */
+ char mGuidanceState[256]; //current guidance state info
+
/* getAllroutes */
uint32_t mRoutes; //current route count
@@ -38,6 +45,10 @@ private:
char mDemoDistance[256]; //the distance from current position(along the route)
char mDemoDirection[256]; //current car direction
+ /* guidance start position information */
+ char mGuidanceStartLatitude[256] = {0}; //guidance start latitude info
+ char mGuidanceStarLongitude[256] = {0};; //guidance start longitude info
+
public:
//get&set function for per members
void setNaviInfoSessionHandle( char* sessionHandle );
@@ -58,6 +69,15 @@ public:
void setNaviInfoCurrentDirState( char* state );
char* getNaviInfoCurrentDirState();
+ void setNaviInfoCurrentTotalDistance( char* totaldistance );
+ int getNaviInfoCurrentTotalDistance();
+
+ void setNaviInfoCurrentCumulativeDistance( char* cumulativedistance );
+ int getNaviInfoCurrentCumulativeDistance();
+
+ void setNaviInfoCurrentGuidanceState( char* state );
+ char* getNaviInfoCurrentGuidanceState();
+
void setNaviInfoAllRoutes( char* route );
uint32_t getNaviInfoAllRoutes();
@@ -78,5 +98,10 @@ public:
void setNaviInfoDemoDirection( char* direction );
char* getNaviInfoDemoDirection();
+
+ void setGuidanceStartLatitude(char* latitude);
+ char* getGuidanceStartLatitude();
+ void setGuidanceStartLongitude(char* longitude);
+ char* getGuidanceStartLongitude();
};
diff --git a/src/api.cpp b/src/api.cpp
index 8235124..3258d6b 100644
--- a/src/api.cpp
+++ b/src/api.cpp
@@ -40,6 +40,8 @@ static afb_event_t gps_event;
static afb_event_t getdestdir_event;
static afb_event_t heading_event;
static afb_event_t cancelguidance_event;
+static afb_event_t guidancestartpos_event;
+static afb_event_t getdistance_event;
/**
* @brief navicore_getposition request callback
@@ -633,7 +635,7 @@ void OnRequestNavicoreSetDestDir(afb_req_t req)
{
const char* state = afb_req_value(req, "state");
- AFB_REQ_NOTICE(req, "state = %s", state);
+ // AFB_REQ_NOTICE(req, "state = %s", state);
afb_req_success(req, NULL, NULL);
@@ -641,12 +643,12 @@ void OnRequestNavicoreSetDestDir(afb_req_t req)
struct json_object* response_json = json_object_new_object();
- AFB_REQ_NOTICE(req, "OnRequestNavicoreSetDestDir");
+ // AFB_REQ_NOTICE(req, "OnRequestNavicoreSetDestDir");
json_object_object_add(response_json, "state", json_object_new_string(state));
const char* response_json_str = json_object_to_json_string(response_json);
- AFB_REQ_NOTICE(req, "response_json_str = %s", response_json_str);
+ // AFB_REQ_NOTICE(req, "response_json_str = %s", response_json_str);
afb_event_push(getdestdir_event, response_json);
}
@@ -673,6 +675,72 @@ void OnRequestNavicoreGetCurrentDestDir(afb_req_t req)
//AFB_API_NOTICE(req->api, "<-- End %s()", __func__);
}
/**
+ * @brief navicore_setdistance request callback
+ * @param[in] req Request from server
+ */
+void OnRequestNavicoreSetDistance(afb_req_t req)
+{
+ const char* totaldistance = afb_req_value(req, "TotalDistance");
+ const char* cumulativedistance = afb_req_value(req, "CumulativeDistance");
+
+ //Type Conversion
+ char* newtotaldistance =new char[100];
+ string totaldistance_string;
+ int totaldistance_int;
+ char* newcumulativedistance =new char[100];
+ string cumulativedistance_string;
+ int cumulativedistance_int;
+ strcpy(newtotaldistance,totaldistance);
+ totaldistance_string = newtotaldistance;
+ totaldistance_int = atoi(totaldistance_string.c_str());
+ strcpy(newcumulativedistance,cumulativedistance);
+ cumulativedistance_string = newcumulativedistance;
+ cumulativedistance_int = atoi(cumulativedistance_string.c_str());
+
+ // AFB_REQ_NOTICE(req, "totaldistance = %s cumulativedistance = %s", totaldistance,cumulativedistance);
+
+ afb_req_success(req, NULL, NULL);
+
+ navigationInfo->setNaviInfoCurrentTotalDistance(const_cast<char*>(totaldistance));
+ navigationInfo->setNaviInfoCurrentCumulativeDistance(const_cast<char*>(cumulativedistance));
+
+ struct json_object* response_json = json_object_new_object();
+
+ // AFB_REQ_NOTICE(req, "OnRequestNavicoreSetDistance");
+
+ json_object_object_add(response_json, "totaldistance", json_object_new_int(totaldistance_int));
+ json_object_object_add(response_json, "cumulativedistance", json_object_new_int(cumulativedistance_int));
+
+ const char* response_json_str = json_object_to_json_string(response_json);
+ // AFB_REQ_NOTICE(req, "response_json_str = %s", response_json_str);
+
+ afb_event_push(getdistance_event, response_json);
+}
+/**
+ * @brief navicore_getcurrentdistance request callback
+ * @param[in] req Request from server
+ */
+void OnRequestNavicoreGetCurrentDistance(afb_req_t req)
+{
+ struct json_object* response_json = json_object_new_array();
+ struct json_object* obj = json_object_new_object();
+
+ int current_totaldistance = navigationInfo->getNaviInfoCurrentTotalDistance();
+ int current_cumulativedistance = navigationInfo->getNaviInfoCurrentCumulativeDistance();
+
+ json_object_object_add(obj, "CurrentTotalDistance", json_object_new_int(current_totaldistance));
+ json_object_object_add(obj, "CurrentCumulativeDistance", json_object_new_int(current_cumulativedistance));
+
+ json_object_array_add(response_json, obj);
+ const char* obj_str = json_object_to_json_string(obj);
+ //AFB_API_NOTICE(req->api, "obj_str = %s", obj_str);
+
+ // Return success to BinderClient
+ afb_req_success(req, response_json, "navicore_getcurrentdistance");
+
+ //AFB_API_NOTICE(req->api, "<-- End %s()", __func__);
+}
+/**
* @brief navicore_startguidance request callback
* @param[in] req Request from server
*/
@@ -681,6 +749,9 @@ void OnRequestNavicoreStartGuidance(afb_req_t req)
AFB_REQ_NOTICE(req, "OnRequestNavicoreStartGuidance");
StartDemoCarlaclient(req->api);
+ const char* state = "ture";
+ navigationInfo->setNaviInfoCurrentGuidanceState(const_cast<char*>(state));
+
afb_req_success(req, NULL, NULL);
}
@@ -692,6 +763,9 @@ void OnRequestNavicoreCancelGuidance(afb_req_t req)
{
AFB_REQ_NOTICE(req, "OnRequestNavicoreCancelGuidance");
StopDemoCarlaclient(req->api);
+
+ const char* state = "false";
+ navigationInfo->setNaviInfoCurrentGuidanceState(const_cast<char*>(state));
afb_event_push(cancelguidance_event, NULL);
@@ -699,6 +773,29 @@ void OnRequestNavicoreCancelGuidance(afb_req_t req)
}
/**
+ * @brief navicore_getcurrentguidancestate request callback
+ * @param[in] req Request from server
+ */
+void OnRequestNavicoreGetCurrentGuidanceState(afb_req_t req)
+{
+ struct json_object* response_json = json_object_new_array();
+ struct json_object* obj = json_object_new_object();
+
+ char* current_guidancestate = navigationInfo->getNaviInfoCurrentGuidanceState();
+
+ json_object_object_add(obj, "CurrentGuidanceState", json_object_new_string(current_guidancestate));
+
+ json_object_array_add(response_json, obj);
+ const char* obj_str = json_object_to_json_string(obj);
+ //AFB_API_NOTICE(req->api, "obj_str = %s", obj_str);
+
+ // Return success to BinderClient
+ afb_req_success(req, response_json, "navicore_getcurrentguidancestate");
+
+ //AFB_API_NOTICE(req->api, "<-- End %s()", __func__);
+}
+
+/**
* @brief navicore_demostate request callback
* @param[in] req Request from server
*/
@@ -719,6 +816,52 @@ void OnRequestNavicoreDemoState(afb_req_t req)
}
/**
+ * @brief navicore_settguidancestartpos request callback
+ * @param[in] req Request from server
+ */
+void OnRequestNavicoreSetGuidanceStartPos(afb_req_t req)
+{
+ const char* guidance_latitude = afb_req_value(req, "StartLatitude");
+ const char* guidance_longitude = afb_req_value(req, "StartLongitude");
+
+ navigationInfo->setGuidanceStartLatitude(const_cast<char*>(guidance_latitude));
+ navigationInfo->setGuidanceStartLongitude(const_cast<char*>(guidance_longitude));
+
+ afb_req_success(req, NULL, NULL);
+ //AFB_API_NOTICE(req->api, "OnRequestNavicoreSetGuidanceStartPos");
+
+ struct json_object* response_json = json_object_new_array();
+ struct json_object* obj = json_object_new_object();
+ json_object_object_add(obj, "StartLatitude", json_object_new_string(guidance_latitude));
+ json_object_object_add(obj, "StartLongitude", json_object_new_string(guidance_longitude));
+ json_object_array_add(response_json, obj);
+ afb_event_push(guidancestartpos_event, response_json);
+}
+
+/**
+ * @brief navicore_gettguidancestartpos request callback
+ * @param[in] req Request from server
+ */
+void OnRequestNavicoreGetGuidanceStartPos(afb_req_t req)
+{
+ //AFB_API_NOTICE(req->api, "OnRequestNavicoreGetGuidanceStartPos");
+
+ struct json_object* response_json = json_object_new_array();
+ struct json_object* obj = json_object_new_object();
+ json_object_object_add(obj, "StartLatitude", json_object_new_string(navigationInfo->getGuidanceStartLatitude()));
+ json_object_object_add(obj, "StartLongitude", json_object_new_string(navigationInfo->getGuidanceStartLongitude()));
+ json_object_array_add(response_json, obj);
+
+ const char* obj_str = json_object_to_json_string(obj);
+ //AFB_API_NOTICE(req->api, "obj_str = %s", obj_str);
+
+ // Return success to BinderClient
+ afb_req_success(req, response_json, "navicore_getguidancestartpos");
+
+ //AFB_API_NOTICE(req->api, "<-- End %s()", __func__);
+}
+
+/**
* @brief subscribe request callback
* @param[in] req Request from server
*/
@@ -777,6 +920,16 @@ void subscribe(afb_req_t req)
afb_req_success(req, NULL, NULL);
return;
}
+ else if(value && !strcasecmp(value, "setguidancestartpos")){
+ afb_req_subscribe(req, guidancestartpos_event);
+ afb_req_success(req, NULL, NULL);
+ return;
+ }
+ else if(value && !strcasecmp(value, "getdistance")){
+ afb_req_subscribe(req, getdistance_event);
+ afb_req_success(req, NULL, NULL);
+ return;
+ }
afb_req_fail(req, "failed", "Invalid event");
}
@@ -839,6 +992,16 @@ void unsubscribe(afb_req_t req)
afb_req_success(req, NULL, NULL);
return;
}
+ else if(value && !strcasecmp(value, "setguidancestartpos")){
+ afb_req_unsubscribe(req, guidancestartpos_event);
+ afb_req_success(req, NULL, NULL);
+ return;
+ }
+ else if(value && !strcasecmp(value, "getdistance")){
+ afb_req_unsubscribe(req, getdistance_event);
+ afb_req_success(req, NULL, NULL);
+ return;
+ }
afb_req_fail(req, "failed", "Invalid event");
}
@@ -856,6 +1019,11 @@ void OnRequestNavicoreGetRouteInfo(afb_req_t req)
uint32_t allroutes = navigationInfo->getNaviInfoAllRoutes();
json_object_object_add(obj, "AllRoutes", json_object_new_int(allroutes));
+ char* start_latitude = navigationInfo->getGuidanceStartLatitude();
+ char* start_longitude = navigationInfo->getGuidanceStartLongitude();
+ json_object_object_add(obj, "StartLatitude", json_object_new_string(start_latitude));
+ json_object_object_add(obj, "StartLongitude", json_object_new_string(start_longitude));
+
char* current_latitude = navigationInfo->getNaviInfoCurrentLatitude();
char* current_longitude = navigationInfo->getNaviInfoCurrentLongitude();
json_object_object_add(obj, "CurrentLatitude", json_object_new_string(current_latitude));
@@ -1033,6 +1201,8 @@ int init(afb_api_t api)
heading_event = afb_api_make_event(afbBindingV3root,"navicore_heading");
getdestdir_event = afb_api_make_event(afbBindingV3root,"navicore_getdestdir");
cancelguidance_event = afb_api_make_event(afbBindingV3root,"navicore_cancelguidance");
+ guidancestartpos_event = afb_api_make_event(afbBindingV3root, "navicore_setguidancestartpos");
+ getdistance_event = afb_api_make_event(afbBindingV3root,"navicore_getdistance");
SubscribeGps(api);
SubscribeCarlaclient(api);
@@ -1067,7 +1237,12 @@ const afb_verb_t verbs[] =
{ verb : "navicore_getcurrentdestdir", callback : OnRequestNavicoreGetCurrentDestDir },
{ verb : "navicore_startguidance", callback : OnRequestNavicoreStartGuidance },
{ verb : "navicore_cancelguidance", callback : OnRequestNavicoreCancelGuidance },
+ { verb : "navicore_getcurrentguidancestate",callback : OnRequestNavicoreGetCurrentGuidanceState },
{ verb : "navicore_demostate", callback : OnRequestNavicoreDemoState },
+ { verb : "navicore_setguidancestartpos", callback : OnRequestNavicoreSetGuidanceStartPos },
+ { verb : "navicore_getguidancestartpos", callback : OnRequestNavicoreGetGuidanceStartPos },
+ { verb : "navicore_setdistance", callback : OnRequestNavicoreSetDistance },
+ { verb : "navicore_getcurrentdistance",callback : OnRequestNavicoreGetCurrentDistance },
{ verb : "subscribe", callback : subscribe },
{ verb : "unsubscribe", callback : unsubscribe },
{ verb : NULL }
diff --git a/src/binder_reply.cpp b/src/binder_reply.cpp
index 172a22a..af79e7d 100644
--- a/src/binder_reply.cpp
+++ b/src/binder_reply.cpp
@@ -156,7 +156,7 @@ APIResponse BinderReply::ReplyNavicoreGetAllSessions( std::map<uint32_t, std::st
}
else
{
- fprintf(stderr, "invalid key.");
+ fprintf(stderr, "invalid key. \n");
json_object_put(obj);
}
}
diff --git a/src/navigation_info.cpp b/src/navigation_info.cpp
index 2ab5afa..7b12743 100644
--- a/src/navigation_info.cpp
+++ b/src/navigation_info.cpp
@@ -65,6 +65,44 @@ char* NavigationInfo::getNaviInfoCurrentDirState()
return mCurrentState;
}
+void NavigationInfo::setNaviInfoCurrentTotalDistance( char* totaldistance )
+{
+ strcpy(mCurrentTotalDistance,totaldistance);
+}
+
+int NavigationInfo::getNaviInfoCurrentTotalDistance()
+{
+ string totaldistance_string;
+ int totaldistance_int;
+ totaldistance_string = mCurrentTotalDistance;
+ totaldistance_int = atoi(totaldistance_string.c_str());
+ return totaldistance_int;
+}
+
+void NavigationInfo::setNaviInfoCurrentCumulativeDistance( char* cumulativedistance )
+{
+ strcpy(mCurrentCumulativeDistance,cumulativedistance);
+}
+
+int NavigationInfo::getNaviInfoCurrentCumulativeDistance()
+{
+ string cumulativedistance_string;
+ int cumulativedistance_int;
+ cumulativedistance_string = mCurrentCumulativeDistance;
+ cumulativedistance_int = atoi(cumulativedistance_string.c_str());
+ return cumulativedistance_int;
+}
+
+void NavigationInfo::setNaviInfoCurrentGuidanceState( char* state )
+{
+ strcpy(mGuidanceState,state);
+}
+
+char* NavigationInfo::getNaviInfoCurrentGuidanceState()
+{
+ return mGuidanceState;
+}
+
void NavigationInfo::setNaviInfoAllRoutes( char* route )
{
mRoutes = stoi(route);
@@ -133,4 +171,23 @@ void NavigationInfo::setNaviInfoDemoDirection( char* direction )
char* NavigationInfo::getNaviInfoDemoDirection()
{
return mDemoDirection;
+}
+
+void NavigationInfo::setGuidanceStartLatitude(char* latitude)
+{strcpy(mGuidanceStartLatitude,latitude);
+}
+
+char* NavigationInfo::getGuidanceStartLatitude()
+{
+ return mGuidanceStartLatitude;
+}
+
+void NavigationInfo::setGuidanceStartLongitude(char* longitude)
+{
+ strcpy(mGuidanceStarLongitude,longitude);
+}
+
+char* NavigationInfo::getGuidanceStartLongitude()
+{
+ return mGuidanceStarLongitude;
} \ No newline at end of file