aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-06-06 15:48:45 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-06-06 15:48:45 +0900
commit281014c341563a8d4634eb34da6c9a5069fa7eb8 (patch)
treee136a8ac8e72a6e79779a0ef82078fc31bb10350
parent30f2f2c6b74b32479f75333bd42a31a6a25a832b (diff)
add demo flag
-rw-r--r--src/api.cpp45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/api.cpp b/src/api.cpp
index 0a00183..b2c0417 100644
--- a/src/api.cpp
+++ b/src/api.cpp
@@ -21,6 +21,8 @@ static void StartDemoCarlaclient(afb_api_t api);
static const char GpsEventName[] = "gps/setlocation";
static const char CarlaEventName[] = "carlaclient/positionUpdated";
+static bool demoflag = false;
+
/**
* Variable declaration
*/
@@ -599,18 +601,22 @@ void sendevent(){
int len = sizeof(latitude)/sizeof(char*);
printf("Naviservice: len====== %d \n",len);
for (int i=0;i<len;i++){
- struct json_object* obj = json_object_new_object();
- const char * lat = latitude[i];
- const char * lon = longitude[i];
- const char * speed = carspeed;
- json_object_object_add(obj, "latitude", json_object_new_string(lat));
- json_object_object_add(obj, "longitude", json_object_new_string(lon));
- json_object_object_add(obj, "carSpeed", json_object_new_string(speed));
- printf("lat %s lon %s speed %s \n",lat,lon,speed);
- // AFB_API_NOTICE(api, "Get gps date.Latitude %s Longitude %s", lat, lon);
- afb_event_push(gps_event, obj);
- // sleep(1);
- usleep(300*1000);
+ if (demoflag == true){
+ struct json_object* obj = json_object_new_object();
+ const char * lat = latitude[i];
+ const char * lon = longitude[i];
+ const char * speed = carspeed;
+ json_object_object_add(obj, "latitude", json_object_new_string(lat));
+ json_object_object_add(obj, "longitude", json_object_new_string(lon));
+ json_object_object_add(obj, "carSpeed", json_object_new_string(speed));
+ printf("lat %s lon %s speed %s \n",lat,lon,speed);
+ // AFB_API_NOTICE(api, "Get gps date.Latitude %s Longitude %s", lat, lon);
+ afb_event_push(gps_event, obj);
+ // sleep(1);
+ usleep(300*1000);
+ } else {
+ break;
+ }
}
}
/**
@@ -677,12 +683,26 @@ void OnRequestNavicoreSetDestDir(afb_req_t req)
void OnRequestNavicoreStartGuidance(afb_req_t req)
{
AFB_REQ_NOTICE(req, "OnRequestNavicoreStartGuidance");
+ demoflag = true;
// StartDemoCarlaclient(req->api);
sendevent();
afb_req_success(req, NULL, NULL);
}
/**
+ * @brief navicore_cancelguidance request callback
+ * @param[in] req Request from server
+ */
+void OnRequestNavicoreCancelGuidance(afb_req_t req)
+{
+ AFB_REQ_NOTICE(req, "OnRequestNavicoreCancelGuidance");
+ demoflag = false;
+ // StopDemoCarlaclient(req->api);
+
+ afb_req_success(req, NULL, NULL);
+}
+
+/**
* @brief subscribe request callback
* @param[in] req Request from server
*/
@@ -1000,6 +1020,7 @@ const afb_verb_t verbs[] =
{ verb : "navicore_arrivedest", callback : OnRequestNavicoreArriveDest },
{ verb : "navicore_setdestdir", callback : OnRequestNavicoreSetDestDir },
{ verb : "navicore_startguidance", callback : OnRequestNavicoreStartGuidance },
+ { verb : "navicore_cancelguidance", callback : OnRequestNavicoreCancelGuidance },
{ verb : "subscribe", callback : subscribe },
{ verb : "unsubscribe", callback : unsubscribe },
{ verb : NULL }