1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
// Copyright 2017 AW SOFTWARE CO.,LTD
// Copyright 2017 AISIN AW CO.,LTD
#include <json-c/json.h>
#include <traces.h>
#include "JsonRequestGenerator.h"
/**
* @brief Generate request for navicore_getposition
* @param valuesToReturn Key information you want to obtain
* @return json string
*/
std::string JsonRequestGenerator::CreateRequestGetPosition(const std::vector< int32_t >& valuesToReturn)
{
std::vector< int32_t >::const_iterator itr;
struct json_object* request_json = json_object_new_object();
struct json_object* json_array = json_object_new_array();
for (itr = valuesToReturn.begin(); itr != valuesToReturn.end(); itr++)
{
json_object_array_add(json_array, json_object_new_int(*itr));
}
json_object_object_add(request_json, "valuesToReturn", json_array);
TRACE_DEBUG("CreateRequestGetPosition request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
/**
* @brief Generate request for navicore_getallroutes
* @return json strin
*/
std::string JsonRequestGenerator::CreateRequestGetAllRoutes()
{
// Request is empty and OK
struct json_object* request_json = json_object_new_object();
TRACE_DEBUG("CreateRequestGetAllRoutes request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
/**
* @brief Generate request for navicore_createroute
* @param sessionHandle session handle
* @return json string
*/
std::string JsonRequestGenerator::CreateRequestCreateRoute(const uint32_t* sessionHandle)
{
struct json_object* request_json = json_object_new_object();
json_object_object_add(request_json, "sessionHandle", json_object_new_int(*sessionHandle));
TRACE_DEBUG("CreateRequestCreateRoute request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
/**
* @brief Generate request for navicore_pausesimulation
* @param sessionHandle session handle
* @return json string
*/
std::string JsonRequestGenerator::CreateRequestPauseSimulation(const uint32_t* sessionHandle)
{
struct json_object* request_json = json_object_new_object();
// sessionHandle
json_object_object_add(request_json, "sessionHandle", json_object_new_int(*sessionHandle));
TRACE_DEBUG("CreateRequestPauseSimulation request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
/**
* @brief Generate request for navicore_pausesimulation
* @param sessionHandle session handle
* @param active Simulation state
* @return json string
*/
std::string JsonRequestGenerator::CreateRequestSetSimulationMode(const uint32_t* sessionHandle, const bool* activate)
{
struct json_object* request_json = json_object_new_object();
// "sessionHandle"
json_object_object_add(request_json, "sessionHandle", json_object_new_int(*sessionHandle));
// "simulationMode"
json_object_object_add(request_json, "simulationMode", json_object_new_boolean(*activate));
TRACE_DEBUG("CreateRequestSetSimulationMode request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
/**
* @brief Generate request for navicore_pausesimulation
* @param sessionHandle session handle
* @param routeHandle route handle
* @return json string
*/
std::string JsonRequestGenerator::CreateRequestCancelRouteCalculation(const uint32_t* sessionHandle, const uint32_t* routeHandle)
{
struct json_object* request_json = json_object_new_object();
// "sessionHandle"
json_object_object_add(request_json, "sessionHandle", json_object_new_int(*sessionHandle));
// "route"
json_object_object_add(request_json, "route", json_object_new_int(*routeHandle));
TRACE_DEBUG("CreateRequestCancelRouteCalculation request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
/**
* @brief Generate request for navicore_setwaypoints
* @param sessionHandle session handle
* @param routeHandle route handle
* @return json string
*/
std::string JsonRequestGenerator::CreateRequestSetWaypoints(const uint32_t* sessionHandle, const uint32_t* routeHandle,
const bool* startFromCurrentPosition, const std::vector<naviapi::Waypoint>* waypointsList)
{
naviapi::Waypoint destWp;
struct json_object* request_json = json_object_new_object();
struct json_object* json_array = json_object_new_array();
// "sessionHandle"
json_object_object_add(request_json, "sessionHandle", json_object_new_int(*sessionHandle));
// "route"
json_object_object_add(request_json, "route", json_object_new_int(*routeHandle));
// "startFromCurrentPosition"
json_object_object_add(request_json, "startFromCurrentPosition", json_object_new_boolean(*startFromCurrentPosition));
// "latitude", "longitude"
std::vector<naviapi::Waypoint>::const_iterator it;
for (it = waypointsList->begin(); it != waypointsList->end(); ++it)
{
struct json_object* destpoint = json_object_new_object();
double latitude = std::get<0>(*it);
json_object_object_add(destpoint, "latitude", json_object_new_double(latitude));
double longitude = std::get<1>(*it);
json_object_object_add(destpoint, "longitude", json_object_new_double(longitude));
json_object_array_add(json_array, destpoint);
}
json_object_object_add(request_json, "", json_array);
TRACE_DEBUG("CreateRequestSetWaypoints request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
/**
* @brief Generate request for navicore_calculateroute
* @param sessionHandle session handle
* @param routeHandle route handle
* @return json string
*/
std::string JsonRequestGenerator::CreateRequestCalculateroute(const uint32_t* sessionHandle, const uint32_t* routeHandle)
{
struct json_object* request_json = json_object_new_object();
// "sessionHandle"
json_object_object_add(request_json, "sessionHandle", json_object_new_int(*sessionHandle));
// "route"
json_object_object_add(request_json, "route", json_object_new_int(*routeHandle));
TRACE_DEBUG("CreateRequestCalculateroute request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
/**
* @brief Generate request for navicore_getallsessions
* @return json string
*/
std::string JsonRequestGenerator::CreateRequestGetAllSessions()
{
// Request is empty and OK
struct json_object* request_json = json_object_new_object();
TRACE_DEBUG("CreateRequestGetAllSessions request_json:\n%s\n", json_object_to_json_string(request_json));
return std::string( json_object_to_json_string( request_json ) );
}
|