aboutsummaryrefslogtreecommitdiff
path: root/inc/bluetooth/profile/server/lns.h
blob: d4cf795395e79919cab0a26886a8a5b4b92ecda6 (plain)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/**
*****************************************************************************************
*     Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved.
*****************************************************************************************
  * @file     lns.h
  * @brief    Variables and interfaces for using Location And Navigation Service.
  * @details  Location And Navigation Service data structs and functions.
  * @author   ranhui
  * @date     2017-09-20
  * @version  v1.0
  * *************************************************************************************
  */

/* Define to prevent recursive inclusion */
#ifndef _LNS_SERVICE_DEF_H
#define _LNS_SERVICE_DEF_H

#ifdef __cplusplus
extern "C"  {
#endif      /* __cplusplus */

/* Add Includes here */
#include "profile_server.h"

/** @defgroup LNS Location And Navigation Service
  * @brief  Location And Navigation service
  * @details

    The Location and Navigation Service (LN Service) exposes location and navigation-related data from a
    Location and Navigation sensor (Server) intended for outdoor activity applications.

    Application shall register LN Service when initialization through @ref lns_add_service function.

    The LN Feature characteristic shall be used to describe the supported features of the Server.
    Reserved for Future Use (RFU) bits in the LN Feature characteristic value shall be set to 0.

    The Location and Speed characteristic is used to send location and speed related data.

    Application can send location and speed related data through @ref lns_location_and_speed_value_notify function.

    The Position Quality characteristic is used to send position quality-related data.

    If the LN Control Point is supported, profiles utilizing this service are required to ensure that the Client configures the LN Control Point characteristic for indications (i.e., via the Client
    Characteristic Configuration descriptor) at the first connection.
    Support for this characteristic is mandatory if the Server supports any of the features requiring control point procedures.

    The Navigation characteristic is used to send navigation-related data.
    Application can send navigation-related data through @ref lns_navigation_value_notify function.

    Application can set the parameters of LNS through @ref lns_set_parameter function.


  * @{
  */

/*============================================================================*
 *                         Macros
 *============================================================================*/
/** @defgroup LNS_Exported_Macros LNS Exported Macros
  * @brief
  * @{
  */


/** @defgroup LNS_LN_Feature LNS LN Feature
  * @{
  */
#define LN_FEATURE_INSTANTANEOUS_SPEED_SUPPORTED            BIT0
#define LN_FEATURE_TOTAL_DISTANCE_SUPPORTED                 BIT1
#define LN_FEATURE_LOCATION_SUPPORTED                       BIT2
#define LN_FEATURE_ELEVATION_SUPPORTED                      BIT3
#define LN_FEATURE_HEADING_SUPPORTED                        BIT4
#define LN_FEATURE_ROLLING_TIME_SUPPORTED                   BIT5
#define LN_FEATURE_UTC_TIME_SUPPORTED                       BIT6
#define LN_FEATURE_REMAINING_DISTANCE_SUPPORTED             BIT7
#define LN_FEATURE_REMAINING_VERTICAL_DISTANCE_SUPPORTED    BIT8
#define LN_FEATURE_ESTIMATED_TIME_OF_ARRIVAL_SUPPORTED      BIT9
#define LN_FEATURE_NUMBER_OF_BEACONS_IN_SOLUTION_SUPPORTED  BIT10
#define LN_FEATURE_NUMBER_OF_BEACONS_IN_VIEW_SUPPORTED      BIT11
#define LN_FEATURE_TIME_TO_FIRST_FIX_SUPPORTED              BIT12
#define LN_FEATURE_ESTIMATED_HORIZONTAL_POSITION_ERROR_SUPPORTED    BIT13
#define LN_FEATURE_ESTIMATED_VERTICAL_POSITION_ERROR_SUPPORTED      BIT14
#define LN_FEATURE_HORIZONTAL_DILUTION_OF_PRECISION_SUPPORTED       BIT15
#define LN_FEATURE_VERTICAL_DILUTION_OF_PRECISION_SUPPORTED         BIT16
#define LN_FEATURE_LOCATION_AND_SPEED_CHARACTERISTIC_CONTENT_MASKING_SUPPORTED  BIT17
#define LN_FEATURE_FIX_RATE_SETTING_SUPPORTED               BIT18
#define LN_FEATURE_ELEVATION_SETTING_SUPPORTED              BIT19
#define LN_FEATURE_POSITION_STATUS_SUPPORTED                BIT20
#define LN_FEATURE_RFU                                      BIT21
/** @} */

#define LNS_READ_POSITION_QUALITY_VALUE                     1

#define LNS_NOTIFY_INDICATE_LOCATION_AND_SPEED_ENABLE       1
#define LNS_NOTIFY_INDICATE_LOCATION_AND_SPEED_DISABLE      2
#define LNS_NOTIFY_INDICATE_CP_ENABLE                       3
#define LNS_NOTIFY_INDICATE_CP_DISABLE                      4
#define LNS_NOTIFY_INDICATE_NAVIGATION_ENABLE               5
#define LNS_NOTIFY_INDICATE_NAVIGATION_DISABLE              6

#define LNS_MAX_CTL_PNT_VALUE                               17

/** End of LNS_Exported_Macros
* @}
*/



/*============================================================================*
 *                         Types
 *============================================================================*/
/** @defgroup LNS_Exported_Types LNS Exported Types
  * @brief
  * @{
  */

typedef enum
{
    LNS_LAS_PARAM_INC_FLAG = 0x01,
    LNS_LAS_PARAM_INSTANTANEOUS_SPEED,
    LNS_LAS_PARAM_TOTAL_DISTANCE,
    LNS_LAS_PARAM_LOCATION_LATITUDE,
    LNS_LAS_PARAM_LOCATION_LONGITUDE,
    LNS_LAS_PARAM_ELEVATION,
    LNS_LAS_PARAM_HEADING,
    LNS_LAS_PARAM_ROLLING_TIME,
    LNS_LAS_PARAM_UTC_TIME,
    LNS_LAS_PARAM_POSITION_STATUS,
    LNS_LAS_PARAM_SPEED_AND_DISTANCE_FORMAT,
    LNS_LAS_PARAM_ELEVATION_SOURCE,
    LNS_LAS_PARAM_HEADING_SOURCE,

    LNS_NAVIGATION_PARAM_INC_FLAG = 0x11,
    LNS_NAVIGATION_PARAM_BEARING,
    LNS_NAVIGATION_PARAM_HEADING,
    LNS_NAVIGATION_PARAM_REMAINING_DISTANCE,
    LNS_NAVIGATION_PARAM_REMAINING_VERTICAL_DISTANCE,
    LNS_NAVIGATION_PARAM_ESTIMATED_TIME_OF_ARRIVAL,
    LNS_NAVIGATION_PARAM_POSITION_STATUS,
    LNS_NAVIGATION_PARAM_HEADING_SOURCE,
    LNS_NAVIGATION_PARAM_NAVIGATION_INDICATOR_TYPE,
    LNS_NAVIGATION_PARAM_WAYPOINT_REACHED,
    LNS_NAVIGATION_PARAM_DESTINATION_REACHED,

    LNS_PQ_PARAM_INC_FLAG = 0x20,
    LNS_PQ_PARAM_NUMBER_OF_BEACONS_IN_SOLUTION,
    LNS_PQ_PARAM_NUMBER_OF_BEACONS_IN_VIEW,
    LNS_PQ_PARAM_TIME_TO_FIRST_FIX,
    LNS_PQ_PARAM_EHPE,
    LNS_PQ_PARAM_EVPE,
    LNS_PQ_PARAM_HDOP,
    LNS_PQ_PARAM_VDOP,

    LNS_PARAM_LN_FEATURE_SUPPORT = 0x30,

    LNS_CP_PARA_NUMBER_OF_ROUTE = 0x41,
    LNS_CP_PARA_NAME_OF_ROUTE,

    LNS_PARAM_CTL_PNT_PROG_CLR = 0x51,
} T_LNS_PARAM_TYPE;

/* Add all public types here */
typedef struct
{
    uint16_t year;
    uint8_t month;
    uint8_t day;
    uint8_t hours;
    uint8_t minutes;
    uint8_t seconds;
} T_DATE_TIME;

/** Position Quality Value Flag */
typedef struct
{
    uint16_t number_of_beacons_in_solution_present: 1;
    uint16_t number_of_beacons_in_view_present: 1;
    uint16_t time_to_first_fix_present: 1;
    uint16_t ehpe_present: 1;
    uint16_t evpe_present: 1;
    uint16_t hdop_present: 1;
    uint16_t vdop_present: 1;
    uint16_t position_status: 2;
    uint16_t rfu: 7;
} T_POSITION_QUALITY_VALUE_FLAG;

/** Position Quality Value */
typedef struct
{
    T_POSITION_QUALITY_VALUE_FLAG flag;
    uint8_t number_of_beacons_in_solution;
    uint8_t number_of_beacons_in_view;
    uint16_t time_to_first_fix;
    uint32_t ehpe;
    uint32_t evpe;
    uint8_t hdop;
    uint8_t vdop;
} T_POSITION_QUALITY_VALUE;

typedef struct
{
    uint8_t location_and_speed_notify_enable: 1;
    uint8_t ln_cp_indicate_enable: 1;
    uint8_t navigation_enable: 1;
    uint8_t rfu: 5;
} T_LNS_NOTIFY_INDICATE_FLAG;

typedef struct
{
    uint16_t instantaneous_speed_present: 1;
    uint16_t total_distance_present: 1;
    uint16_t location_present: 1;
    uint16_t elevation_present: 1;
    uint16_t heading_present: 1;
    uint16_t rolling_time_present: 1;
    uint16_t utc_time_present: 1;
    uint16_t position_status: 2;
    uint16_t speed_and_distance_format: 1;
    uint16_t elevation_source: 2;
    uint16_t heading_source: 1;
    uint16_t rfu: 3;
} T_LOCATION_AND_SPEED_VALUE_FLAG;

/** Location and Speed Value */
typedef struct
{
    T_LOCATION_AND_SPEED_VALUE_FLAG flag;
    uint16_t instantaneous_speed;
    uint32_t total_distance; //uint24
    int32_t location_latitude; //sint32
    int32_t location_longitude;
    int32_t elevation;//sint24
    uint16_t heading;
    uint8_t rolling_time;
    T_DATE_TIME utc_time;
} LOCATION_AND_SPEED_VALUE;

/** Navigation Value */
typedef struct
{
    uint16_t remaining_distance_present: 1;
    uint16_t remaining_vertical_distance_present: 1;
    uint16_t estimated_time_of_arrival_present: 1;
    uint16_t position_status: 2;
    uint16_t heading_source: 1;
    uint16_t navigation_indicator_type: 1;
    uint16_t waypoint_reached: 1;
    uint16_t destination_reached: 1;
    uint16_t rfus: 7;
} T_NAVIGATION_VALUE_FLAG;

typedef struct
{
    T_NAVIGATION_VALUE_FLAG flag;
    uint16_t bearing;
    uint16_t heading;
    uint32_t reamining_distance;
    int32_t reamining_vertical_distance;
    T_DATE_TIME estimated_time_of_arrival;
} T_NAVIGATION_VALUE;

typedef enum
{
    LN_CP_OPCODE_RESERVED = 0,
    LN_CP_OPCODE_SET_CUMULATIVE_VALUE = 1,
    LN_CP_OPCODE_MASK_LOCATION_AND_SPEED_CHAR_CONTENT = 2,
    LN_CP_OPCODE_NAVIGATION_CONTROL = 3,
    LN_CP_OPCODE_REQUEST_NUMBER_OF_ROUTES = 4,
    LN_CP_OPCODE_REQUEST_NAME_OF_ROUTE = 5,
    LN_CP_OPCODE_SELECT_ROUTE = 6,
    LN_CP_OPCODE_SET_FIX_RATE = 7,
    LN_CP_OPCODE_SET_ELEVATION = 8,
    LN_CP_OPCODE_RESPONSE_CODE = 32
} T_LN_CP_OPCODE;


/**
 * @brief CSC Control Point data, variable length during connection, max can reach 17 bytes.
 *
 * CSC Control Point data used to store the Control Point Command received from the client.
*/
typedef struct
{
    uint8_t    cur_length;            /**<  length of current LNS Control Point data, . */
    uint8_t
    value[LNS_MAX_CTL_PNT_VALUE];            /**<  value of current LNS Control Point data, . */
} T_LNS_CONTROL_POINT;

/** @defgroup LNS_Callback_Data LNS Callback Data
  * @brief LNS data struct for notification data to application.
  * @{
  */
typedef union
{
    uint32_t cumulative_total_distance; //uint24
    uint16_t mask_location_and_speed;
    uint8_t  navigation_control;
    uint16_t  number_of_desired_route; //request_name_of_route
    uint16_t  select_route_desired_route_number;
    uint8_t  set_fix_rate;
    int32_t  set_elevation; //sint24
} T_LNS_CP_PARAMETER;

typedef struct
{
    T_LN_CP_OPCODE opcode;
    T_LNS_CP_PARAMETER cp_parameter;
} T_LNS_WRITE_MSG;

typedef union
{
    uint8_t notification_indification_index;
    uint8_t read_value_index;
    T_LNS_WRITE_MSG write;
} T_LNS_UPSTREAM_MSG_DATA;

/** LNS service data to inform application */
typedef struct
{
    T_SERVICE_CALLBACK_TYPE     msg_type;
    T_LNS_UPSTREAM_MSG_DATA    msg_data;
} T_LNS_CALLBACK_DATA;
/** @} */

/** End of LNS_Exported_Types
* @}
*/


/*============================================================================*
 *                         Functions
 *============================================================================*/
/** @defgroup LNS_Exported_Functions LNS Exported Functions
  * @brief
  * @{
  */

/**
  * @brief       Add location and navigation service to the BLE stack database.
  *
  *
  * @param[in]   p_func  Callback when service attribute was read, write or cccd update.
  * @return Service id generated by the BLE stack: @ref T_SERVER_ID.
  * @retval 0xFF Operation failure.
  * @retval others Service id assigned by stack.
  *
  * <b>Example usage</b>
  * \code{.c}
    void profile_init()
    {
     server_init(1);
     lns_id = lns_add_service(app_handle_profile_message);
    }
  * \endcode
  */
uint8_t lns_add_service(void *p_func);

/**
 * @brief       Set a Location And Navigation service parameter.
 *
 *              NOTE: You can call this function with a Location And Navigation service parameter type and it will set the
 *                      Location And Navigation service parameter.  Location And Navigation service parameters are defined
 *                      in @ref T_LNS_PARAM_TYPE.
 *                      If the "len" field sets to the size of a "uint16_t" ,the
 *                      "p_value" field must point to a data with type of "uint16_t".
 *
 * @param[in]   param_type   Location And Navigation service parameter type: @ref T_LNS_PARAM_TYPE
 * @param[in]   len       Length of data to write
 * @param[in]   p_value Pointer to data to write.  This is dependent on
 *                      the parameter type and WILL be cast to the appropriate
 *                      data type (For example: if data type of param is uint16_t, p_value will be cast to
 *                      pointer of uint16_t).
 *
 * @return Operation result.
 * @retval true Operation success.
 * @retval false Operation failure.
 *
 * <b>Example usage</b>
 * \code{.c}
    void test(void)
    {
        T_LOCATION_AND_SPEED_VALUE_FLAG flag;
        flag.instantaneous_speed_present = 1;
        flag.total_distance_present = 1;
        flag.location_present = 1;
        flag.elevation_present = 1;
        flag.heading_present = 1;
        flag.rolling_time_present = 1;
        flag.utc_time_present = 1;
        flag.position_status = 1;
        flag.speed_and_distance_format = 1;
        flag.elevation_source = 1;
        flag.heading_source = 1;
        flag.rfu = 0;

        lns_set_parameter(LNS_LAS_PARAM_INC_FLAG, 2, &flag);
    }
 * \endcode
 */
bool lns_set_parameter(T_LNS_PARAM_TYPE param_type, uint8_t len, void *p_value);

/**
 * @brief       Send location and speed value notification data.
 *              Application shall call @ref lns_set_parameter to set location and speed value first,
 *              and the call this api to send the notication value.
 *
 * @param[in]   conn_id  Connection id.
 * @param[in]   service_id  Service id.
 *
 * @return service id @ref T_SERVER_ID.
 *
 * <b>Example usage</b>
 * \code{.c}
    void test(void)
    {
        bool op_result;
        T_LOCATION_AND_SPEED_VALUE_FLAG flag;
        flag.instantaneous_speed_present = 1;
        flag.total_distance_present = 1;
        flag.location_present = 1;
        flag.elevation_present = 1;
        flag.heading_present = 1;
        flag.rolling_time_present = 1;
        flag.utc_time_present = 1;
        flag.position_status = 1;
        flag.speed_and_distance_format = 1;
        flag.elevation_source = 1;
        flag.heading_source = 1;
        flag.rfu = 0;

        lns_set_parameter(LNS_LAS_PARAM_INC_FLAG, 2, &flag);

        op_result = lns_location_and_speed_value_notify(p_parse_value->dw_param[0], lns_id);
    }
 * \endcode
 */
bool lns_location_and_speed_value_notify(uint8_t conn_id, T_SERVER_ID service_id);

/**
 * @brief       Send navigation value notification data.
 *              Application shall call @ref lns_set_parameter to set navigation value first,
 *              and the call this api to send the notication value.
 *
 * @param[in]   conn_id  Connection id.
 * @param[in]   service_id  Service id.
 *
 * @return service id @ref T_SERVER_ID.
 *
 * <b>Example usage</b>
 * \code{.c}
    void test(void)
    {
        bool op_result;

        T_NAVIGATION_VALUE_FLAG flag;
        flag.remaining_distance_present = 1;
        flag.remaining_vertical_distance_present = 1;
        flag.estimated_time_of_arrival_present = 1;
        flag.position_status = 1;
        flag.heading_source = 1;
        flag.navigation_indicator_type = 1;
        flag.waypoint_reached = 1;
        flag.destination_reached = 1;
        flag.rfus = 0;

        lns_set_parameter(LNS_NAVIGATION_PARAM_INC_FLAG, 2, &flag);

        op_result = lns_navigation_value_notify(p_parse_value->dw_param[0], lns_id);

    }
 * \endcode
 */
bool lns_navigation_value_notify(uint8_t conn_id, T_SERVER_ID service_id);

/** @} End of LNS_Exported_Functions */

/** @} End of LNS */

#ifdef __cplusplus
}
#endif

#endif // _LNS_SERVICE_DEF_H