observer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * @file
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. #ifndef OBSERVER_H
  11. #define OBSERVER_H
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. /*********************************************************************
  17. * INCLUDES
  18. */
  19. #include "bcomdef.h"
  20. #include "OSAL.h"
  21. #include "gap.h"
  22. /*********************************************************************
  23. * CONSTANTS
  24. */
  25. /** @defgroup GAPOBSERVERROLE_PROFILE_PARAMETERS GAP Observer Role Parameters
  26. * @{
  27. */
  28. #define GAPOBSERVERROLE_BD_ADDR 0x400 //!< Device's Address. Read Only. Size is uint8[B_ADDR_LEN]. This item is read from the controller.
  29. #define GAPOBSERVERROLE_MAX_SCAN_RES 0x401 //!< Maximum number of discover scan results to receive. Default is 0 = unlimited.
  30. /** @} End GAPOBSERVERROLE_PROFILE_PARAMETERS */
  31. /*********************************************************************
  32. * VARIABLES
  33. */
  34. /*********************************************************************
  35. * MACROS
  36. */
  37. /*********************************************************************
  38. * TYPEDEFS
  39. */
  40. /**
  41. * Observer Event Structure
  42. */
  43. typedef union
  44. {
  45. gapEventHdr_t gap; //!< GAP_MSG_EVENT and status.
  46. gapDeviceInitDoneEvent_t initDone; //!< GAP initialization done.
  47. gapDeviceInfoEvent_t deviceInfo; //!< Discovery device information event structure.
  48. gapDevDiscEvent_t discCmpl; //!< Discovery complete event structure.
  49. } gapObserverRoleEvent_t;
  50. /**
  51. * RSSI Read Callback Function
  52. */
  53. typedef void (*pfnGapObserverRoleRssiCB_t)
  54. (
  55. uint16 connHandle, //!< Connection handle.
  56. int8 rssi //!< New RSSI value.
  57. );
  58. /**
  59. * Observer Event Callback Function
  60. */
  61. typedef void (*pfnGapObserverRoleEventCB_t)
  62. (
  63. gapObserverRoleEvent_t *pEvent //!< Pointer to event structure.
  64. );
  65. /**
  66. * Observer Callback Structure
  67. */
  68. typedef struct
  69. {
  70. pfnGapObserverRoleRssiCB_t rssiCB; //!< RSSI callback.
  71. pfnGapObserverRoleEventCB_t eventCB; //!< Event callback.
  72. } gapObserverRoleCB_t;
  73. /*********************************************************************
  74. * VARIABLES
  75. */
  76. /*********************************************************************
  77. * API FUNCTIONS
  78. */
  79. /*-------------------------------------------------------------------
  80. * Observer Profile Public APIs
  81. */
  82. /**
  83. * @defgroup OBSERVER_PROFILE_API Observer Profile API Functions
  84. *
  85. * @{
  86. */
  87. /**
  88. * @brief Start the device in Observer role. This function is typically
  89. * called once during system startup.
  90. *
  91. * @param pAppCallbacks - pointer to application callbacks
  92. *
  93. * @return SUCCESS: Operation successful.<BR>
  94. * bleAlreadyInRequestedMode: Device already started.<BR>
  95. */
  96. extern bStatus_t GAPObserverRole_StartDevice( gapObserverRoleCB_t *pAppCallbacks );
  97. /**
  98. * @brief Set a parameter in the Observer Profile.
  99. *
  100. * @param param - profile parameter ID: @ref GAPOBSERVERROLE_PROFILE_PARAMETERS
  101. * @param len - length of data to write
  102. * @param pValue - pointer to data to write. This is dependent on
  103. * the parameter ID and WILL be cast to the appropriate
  104. * data type.
  105. *
  106. * @return SUCCESS: Operation successful.<BR>
  107. * INVALIDPARAMETER: Invalid parameter ID.<BR>
  108. */
  109. extern bStatus_t GAPObserverRole_SetParameter( uint16 param, uint8 len, void *pValue );
  110. /**
  111. * @brief Get a parameter in the Observer Profile.
  112. *
  113. * @param param - profile parameter ID: @ref GAPOBSERVERROLE_PROFILE_PARAMETERS
  114. * @param pValue - pointer to buffer to contain the read data
  115. *
  116. * @return SUCCESS: Operation successful.<BR>
  117. * INVALIDPARAMETER: Invalid parameter ID.<BR>
  118. */
  119. extern bStatus_t GAPObserverRole_GetParameter( uint16 param, void *pValue );
  120. /**
  121. * @brief Start a device discovery scan.
  122. *
  123. * @param mode - discovery mode: @ref GAP_DEVDISC_MODE_DEFINES
  124. * @param activeScan - TRUE to perform active scan
  125. * @param whiteList - TRUE to only scan for devices in the white list
  126. *
  127. * @return SUCCESS: Discovery scan started.<BR>
  128. * bleIncorrectMode: Invalid profile role.<BR>
  129. * bleAlreadyInRequestedMode: Not available.<BR>
  130. */
  131. extern bStatus_t GAPObserverRole_StartDiscovery( uint8 mode, uint8 activeScan, uint8 whiteList );
  132. /**
  133. * @brief Cancel a device discovery scan.
  134. *
  135. * @return SUCCESS: Cancel started.<BR>
  136. * bleInvalidTaskID: Not the task that started discovery.<BR>
  137. * bleIncorrectMode: Not in discovery mode.<BR>
  138. */
  139. extern bStatus_t GAPObserverRole_CancelDiscovery( void );
  140. /**
  141. * @}
  142. */
  143. /*-------------------------------------------------------------------
  144. * TASK API - These functions must only be called by OSAL.
  145. */
  146. /**
  147. * @internal
  148. *
  149. * @brief Observer Profile Task initialization function.
  150. *
  151. * @param taskId - Task ID.
  152. *
  153. * @return void
  154. */
  155. extern void GAPObserverRole_Init( uint8 taskId );
  156. /**
  157. * @internal
  158. *
  159. * @brief Observer Profile Task event processing function.
  160. *
  161. * @param taskId - Task ID
  162. * @param events - Events.
  163. *
  164. * @return events not processed
  165. */
  166. extern uint16 GAPObserverRole_ProcessEvent( uint8 taskId, uint16 events );
  167. /*********************************************************************
  168. *********************************************************************/
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif /* OBSERVER_H */