broadcaster.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 BROADCASTER_H
  11. #define BROADCASTER_H
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. /*-------------------------------------------------------------------
  17. * INCLUDES
  18. */
  19. /*-------------------------------------------------------------------
  20. * CONSTANTS
  21. */
  22. /** @defgroup GAPROLE_PROFILE_PARAMETERS GAP Role Parameters
  23. * @{
  24. */
  25. #define GAPROLE_PROFILEROLE 0x300 //!< Reading this parameter will return GAP Role type. Read Only. Size is uint8.
  26. #define GAPROLE_BD_ADDR 0x301 //!< Device's Address. Read Only. Size is uint8[B_ADDR_LEN]. This item is read from the controller.
  27. #define GAPROLE_ADVERT_ENABLED 0x302 //!< Enable/Disable Advertising. Read/Write. Size is uint8. Default is TRUE=Enabled.
  28. #define GAPROLE_ADVERT_OFF_TIME 0x303 //!< Advertising Off Time for Limited advertisements (in milliseconds). Read/Write. Size is uint16. Default is 30 seconds.
  29. #define GAPROLE_ADVERT_DATA 0x304 //!< Advertisement Data. Read/Write. Size is uint8[B_MAX_ADV_LEN]. Default is "02:01:01", which means that it is a Limited Discoverable Advertisement.
  30. #define GAPROLE_SCAN_RSP_DATA 0x305 //!< Scan Response Data. Read/Write. Size is uint8[B_MAX_ADV_LEN]. Defaults to all 0.
  31. #define GAPROLE_ADV_EVENT_TYPE 0x306 //!< Advertisement Type. Read/Write. Size is uint8. Default is GAP_ADTYPE_ADV_IND (defined in GAP.h).
  32. #define GAPROLE_ADV_DIRECT_TYPE 0x307 //!< Direct Advertisement Address Type. Ready/Write. Size is uint8. Default is ADDRTYPE_PUBLIC (defined in GAP.h).
  33. #define GAPROLE_ADV_DIRECT_ADDR 0x308 //!< Direct Advertisement Address. Read/Write. Size is uint8[B_ADDR_LEN]. Default is NULL.
  34. #define GAPROLE_ADV_CHANNEL_MAP 0x309 //!< Which channels to advertise on. Read/Write Size is uint8. Default is GAP_ADVCHAN_ALL (defined in GAP.h)
  35. #define GAPROLE_ADV_FILTER_POLICY 0x30A //!< Filter Policy. Ignored when directed advertising is used. Read/Write. Size is uint8. Default is GAP_FILTER_POLICY_ALL (defined in GAP.h).
  36. /** @} End GAPROLE_PROFILE_PARAMETERS */
  37. /*-------------------------------------------------------------------
  38. * TYPEDEFS
  39. */
  40. /**
  41. * GAP Broadcaster Role States.
  42. */
  43. typedef enum
  44. {
  45. GAPROLE_INIT = 0, //!< Waiting to be started
  46. GAPROLE_STARTED, //!< Started but not advertising
  47. GAPROLE_ADVERTISING, //!< Currently Advertising
  48. GAPROLE_WAITING, //!< Device is started but not advertising, is in waiting period before advertising again
  49. GAPROLE_ERROR //!< Error occurred - invalid state
  50. } gaprole_States_t;
  51. /*-------------------------------------------------------------------
  52. * MACROS
  53. */
  54. /*-------------------------------------------------------------------
  55. * Profile Callbacks
  56. */
  57. /**
  58. * Callback when the device has been started. Callback event to
  59. * the Notify of a state change.
  60. */
  61. typedef void (*gapRolesStateNotify_t)( gaprole_States_t newState );
  62. /**
  63. * Callback when the device has read an new RSSI value during a connection.
  64. */
  65. typedef void (*gapRolesRssiRead_t)( int8 newRSSI );
  66. /**
  67. * Callback structure - must be setup by the application and used when gapRoles_StartDevice() is called.
  68. */
  69. typedef struct
  70. {
  71. gapRolesStateNotify_t pfnStateChange; //!< Whenever the device changes state
  72. gapRolesRssiRead_t pfnRssiRead; //!< When a valid RSSI is read from controller
  73. } gapRolesCBs_t;
  74. /*-------------------------------------------------------------------
  75. * API FUNCTIONS
  76. */
  77. /**
  78. * @defgroup GAPROLES_BROADCASTER_API GAP Broadcaster Role API Functions
  79. *
  80. * @{
  81. */
  82. /**
  83. * @brief Set a GAP Role parameter.
  84. *
  85. * NOTE: You can call this function with a GAP Parameter ID and it will set the
  86. * GAP Parameter. GAP Parameters are defined in (gap.h). Also,
  87. * the "len" field must be set to the size of a "uint16" and the
  88. * "pValue" field must point to a "uint16".
  89. *
  90. * @param param - Profile parameter ID: @ref GAPROLE_PROFILE_PARAMETERS
  91. * @param len - length of data to write
  92. * @param pValue - pointer to data to write. This is dependent on
  93. * the parameter ID and WILL be cast to the appropriate
  94. * data type (example: data type of uint16 will be cast to
  95. * uint16 pointer).
  96. *
  97. * @return SUCCESS or INVALIDPARAMETER (invalid paramID)
  98. */
  99. extern bStatus_t GAPRole_SetParameter( uint16 param, uint8 len, void *pValue );
  100. /**
  101. * @brief Get a GAP Role parameter.
  102. *
  103. * NOTE: You can call this function with a GAP Parameter ID and it will get a
  104. * GAP Parameter. GAP Parameters are defined in (gap.h). Also, the
  105. * "pValue" field must point to a "uint16".
  106. *
  107. * @param param - Profile parameter ID: @ref GAPROLE_PROFILE_PARAMETERS
  108. * @param pValue - pointer to location to get the value. This is dependent on
  109. * the parameter ID and WILL be cast to the appropriate
  110. * data type (example: data type of uint16 will be cast to
  111. * uint16 pointer).
  112. *
  113. * @return SUCCESS or INVALIDPARAMETER (invalid paramID)
  114. */
  115. extern bStatus_t GAPRole_GetParameter( uint16 param, void *pValue );
  116. /**
  117. * @brief Does the device initialization. Only call this function once.
  118. *
  119. * @param pAppCallbacks - pointer to application callbacks.
  120. *
  121. * @return SUCCESS or bleAlreadyInRequestedMode
  122. */
  123. extern bStatus_t GAPRole_StartDevice( gapRolesCBs_t *pAppCallbacks );
  124. /**
  125. * @} End GAPROLES_BROADCASTER_API
  126. */
  127. /*-------------------------------------------------------------------
  128. * TASK FUNCTIONS - Don't call these. These are system functions.
  129. */
  130. /**
  131. * @internal
  132. *
  133. * @brief Initialization function for the GAP Role Task.
  134. * This is called during initialization and should contain
  135. * any application specific initialization (ie. hardware
  136. * initialization/setup, table initialization, power up
  137. * notificaiton ... ).
  138. *
  139. * @param the ID assigned by OSAL. This ID should be
  140. * used to send messages and set timers.
  141. *
  142. * @return void
  143. */
  144. extern void GAPRole_Init( uint8 task_id );
  145. /**
  146. * @internal
  147. *
  148. * @brief GAP Role Task event processor.
  149. * This function is called to process all events for the task.
  150. * Events include timers, messages and any other user defined
  151. * events.
  152. *
  153. * @param task_id - The OSAL assigned task ID.
  154. * @param events - events to process. This is a bit map and can
  155. * contain more than one event.
  156. *
  157. * @return events not processed
  158. */
  159. extern uint16 GAPRole_ProcessEvent( uint8 task_id, uint16 events );
  160. /*-------------------------------------------------------------------
  161. -------------------------------------------------------------------*/
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif /* BROADCASTER_H */