From 00a85e8b4d47e1839c3fa7a2a956d3039e1175a2 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Tue, 11 Jun 2019 18:17:15 +0900 Subject: fix bug hudtbt can not get information --- include/navigation_info.h | 6 ++++++ src/api.cpp | 39 +++++++++++++++++++++++++++++++++++++-- src/navigation_info.cpp | 10 ++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/include/navigation_info.h b/include/navigation_info.h index acdd93e..a0c9f49 100644 --- a/include/navigation_info.h +++ b/include/navigation_info.h @@ -25,6 +25,9 @@ private: /* getAllroutes */ uint32_t mRoutes; //current route count + /* GetDirState */ + char mCurrentState[256]; //current direction state info + /* getdestination */ char mDestLatitude[256]; //Destination latitude info char mDestLongitude[256]; //Destination longitude info @@ -52,6 +55,9 @@ public: void setNaviInfoCurrentHeading( char* heading ); char* getNaviInfoCurrentHeading(); + void setNaviInfoCurrentDirState( char* state ); + char* getNaviInfoCurrentDirState(); + void setNaviInfoAllRoutes( char* route ); uint32_t getNaviInfoAllRoutes(); diff --git a/src/api.cpp b/src/api.cpp index b2c0417..4814cd7 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -39,6 +39,7 @@ static afb_event_t adddest_event; static afb_event_t gps_event; static afb_event_t getdestdir_event; static afb_event_t heading_event; +static afb_event_t cancelguidance_event; void sendevent(); /** * @brief navicore_getposition request callback @@ -664,6 +665,8 @@ void OnRequestNavicoreSetDestDir(afb_req_t req) afb_req_success(req, NULL, NULL); + navigationInfo->setNaviInfoCurrentDirState(const_cast(state)); + struct json_object* response_json = json_object_new_object(); AFB_REQ_NOTICE(req, "OnRequestNavicoreSetDestDir"); @@ -675,7 +678,28 @@ void OnRequestNavicoreSetDestDir(afb_req_t req) afb_event_push(getdestdir_event, response_json); } +/** + * @brief navicore_getcurrentdestdir request callback + * @param[in] req Request from server + */ +void OnRequestNavicoreGetCurrentDestDir(afb_req_t req) +{ + struct json_object* response_json = json_object_new_array(); + struct json_object* obj = json_object_new_object(); + + char* current_dirstate = navigationInfo->getNaviInfoCurrentDirState(); + + json_object_object_add(obj, "CurrentDirState", json_object_new_string(current_dirstate)); + + 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_getcurrentdestdir"); + + AFB_API_NOTICE(req->api, "<-- End %s()", __func__); +} /** * @brief navicore_startguidance request callback * @param[in] req Request from server @@ -698,7 +722,7 @@ void OnRequestNavicoreCancelGuidance(afb_req_t req) AFB_REQ_NOTICE(req, "OnRequestNavicoreCancelGuidance"); demoflag = false; // StopDemoCarlaclient(req->api); - + afb_event_push(cancelguidance_event, NULL); afb_req_success(req, NULL, NULL); } @@ -756,6 +780,11 @@ void subscribe(afb_req_t req) afb_req_success(req, NULL, NULL); return; } + else if(value && !strcasecmp(value, "cancelguidance")){ + afb_req_subscribe(req, cancelguidance_event); + afb_req_success(req, NULL, NULL); + return; + } afb_req_fail(req, "failed", "Invalid event"); } @@ -813,6 +842,11 @@ void unsubscribe(afb_req_t req) afb_req_success(req, NULL, NULL); return; } + else if(value && !strcasecmp(value, "cancelguidance")){ + afb_req_unsubscribe(req, cancelguidance_event); + afb_req_success(req, NULL, NULL); + return; + } afb_req_fail(req, "failed", "Invalid event"); } @@ -988,7 +1022,7 @@ int init(afb_api_t api) gps_event = afb_api_make_event(afbBindingV3root,"navicore_gps"); 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"); // SubscribeGps(api); // SubscribeCarlaclient(api); @@ -1019,6 +1053,7 @@ const afb_verb_t verbs[] = { verb : "navicore_stopdemo", callback : OnRequestNavicoreStopDemo }, { verb : "navicore_arrivedest", callback : OnRequestNavicoreArriveDest }, { verb : "navicore_setdestdir", callback : OnRequestNavicoreSetDestDir }, + { verb : "navicore_getcurrentdestdir", callback : OnRequestNavicoreGetCurrentDestDir }, { verb : "navicore_startguidance", callback : OnRequestNavicoreStartGuidance }, { verb : "navicore_cancelguidance", callback : OnRequestNavicoreCancelGuidance }, { verb : "subscribe", callback : subscribe }, diff --git a/src/navigation_info.cpp b/src/navigation_info.cpp index 9e89bc5..2ab5afa 100644 --- a/src/navigation_info.cpp +++ b/src/navigation_info.cpp @@ -55,6 +55,16 @@ char* NavigationInfo::getNaviInfoCurrentHeading() return mCurrentHeading; } +void NavigationInfo::setNaviInfoCurrentDirState( char* state ) +{ + strcpy(mCurrentState,state); +} + +char* NavigationInfo::getNaviInfoCurrentDirState() +{ + return mCurrentState; +} + void NavigationInfo::setNaviInfoAllRoutes( char* route ) { mRoutes = stoi(route); -- cgit 1.2.3-korg