BSB Developer Docs
Loading...
Searching...
No Matches
ble_service.h File Reference

Public api for ble services. More...

#include "../ble_log.h"
#include "../ble_intercom_types.h"
#include "ble_service_config_types.h"
#include <furi.h>

Go to the source code of this file.

Data Structures

struct  BleServiceObjectResult
 Represents service processing result. More...
 

Typedefs

typedef struct BleServiceObject BleServiceObject
 Opaque BleServiceObject type declaration.
 
typedef struct BleServiceObjectMessage BleServiceObjectMessage
 Opaque BleServiceObjectMessage type declaration.
 

Functions

BleServiceObject * ble_service_alloc (const BleServiceConfig *service_config, FuriMessageQueue *message_queue, IntercomChannel *intercom_ch)
 Allocate service instance using predefined config.
 
BleServiceObjectResult ble_service_process (BleServiceObjectMessage *instance)
 Process events related to service.
 
void ble_service_process_mailbox (BleServiceObject *instance, const BleIntercomFrameGeneric *input_frame)
 Process intercom frames addressed to the service from other side.
 
bool ble_service_is_ready (BleServiceObject *instance)
 Returns service status.
 
const char * ble_service_get_name (BleServiceObject *instance)
 Returns service name.
 
void ble_service_get_error (BleServiceObject *instance, FuriString *error)
 Returns error message.
 
void ble_service_enqueue_init (BleServiceObject *instance)
 Enqueue initialize command during startup in order to init service.
 
void ble_service_enqueue_run (BleServiceObject *instance)
 Enqueue run command in order to call service specific logic.
 
void ble_service_deinit (BleServiceObject *instance)
 Enqueue deinit command.
 
void ble_service_write_data (BleServiceObject *instance, uint8_t index, const void *data, const size_t data_size)
 Write data to service.
 
void ble_service_register_update_callback (BleServiceObject *instance, uint16_t index, BleDataUpdatedCallback cb, void *ctx)
 Register update callback for selected characteristic inside of a service.
 
void ble_service_register_transmission_done_callback (BleServiceObject *instance, uint16_t index, BleDataTransmitDoneCallback cb, void *ctx)
 Register transmission done callback for selected characteristic inside of a service.
 

Detailed Description

Public api for ble services.

Function Documentation

◆ ble_service_alloc()

BleServiceObject * ble_service_alloc ( const BleServiceConfig * service_config,
FuriMessageQueue * message_queue,
IntercomChannel * intercom_ch )

Allocate service instance using predefined config.

Parameters
[in]service_configpredefined config which describes service and its internals
[in]message_queuequeue which all services use for processing events
[in]intercom_chintercom channel for sending data to other side
Returns
pointer to service instance

◆ ble_service_deinit()

void ble_service_deinit ( BleServiceObject * instance)

Enqueue deinit command.

This is used on unrecoverable error handling in order to shut down service with all internals.

Parameters
[in]instancepointer to the BleServiceObject instance

◆ ble_service_enqueue_init()

void ble_service_enqueue_init ( BleServiceObject * instance)

Enqueue initialize command during startup in order to init service.

Init command is emulated using pre-filled input frame buffer which after that will be processed ble_service_process and result in BleServiceCommandInit execution

Parameters
[in]instancepointer to the BleServiceObject instance

◆ ble_service_enqueue_run()

void ble_service_enqueue_run ( BleServiceObject * instance)

Enqueue run command in order to call service specific logic.

Parameters
[in]instancepointer to the BleServiceObject instance

◆ ble_service_get_error()

void ble_service_get_error ( BleServiceObject * instance,
FuriString * error )

Returns error message.

Called when service processing ends up with an error, error message is then printed to logs

Parameters
[in]instancepointer to the BleServiceObject instance
[out]errorpre-allocated error string buffer

◆ ble_service_get_name()

const char * ble_service_get_name ( BleServiceObject * instance)

Returns service name.

Parameters
[in]instancepointer to the BleServiceObject instance
Returns
service name string pointer

◆ ble_service_is_ready()

bool ble_service_is_ready ( BleServiceObject * instance)

Returns service status.

Used during init in order to check that all services initialized correctly and are ready to run

Parameters
[in]instancepointer to the BleServiceObject instance
Returns
true when service is ready, otherwise false

◆ ble_service_process()

BleServiceObjectResult ble_service_process ( BleServiceObjectMessage * instance)

Process events related to service.

This method is called from message queue handler and it can be called in three cases:

  1. Internal event happened inside and service enqueued run in order to be able to process this event
  2. Incoming frame for this service was received from the other side
  3. Incoming frame was emulated in order to send command (init) to this service
Parameters
[in]instancepointer to the BleServiceObjectMessage instance which is used internally
Returns
BleServiceObjectResult where information about service processing is stored

◆ ble_service_process_mailbox()

void ble_service_process_mailbox ( BleServiceObject * instance,
const BleIntercomFrameGeneric * input_frame )

Process intercom frames addressed to the service from other side.

This method if called from intercom_rx callback which must be as fast as possible, therefore it only copies frame payload to internal service frame buffer, enqueues further service processing and returns

Parameters
[in]instancepointer to the BleServiceObject instance
[in]input_framepointer to frame received from other side

◆ ble_service_register_transmission_done_callback()

void ble_service_register_transmission_done_callback ( BleServiceObject * instance,
uint16_t index,
BleDataTransmitDoneCallback cb,
void * ctx )

Register transmission done callback for selected characteristic inside of a service.

Parameters
[in]instancepointer to the BleServiceObject instance
[in]indexcharacteristic index where data should be placed
[in]cbpointer to transmission done callback function
[in]ctxtransmission done callback context

◆ ble_service_register_update_callback()

void ble_service_register_update_callback ( BleServiceObject * instance,
uint16_t index,
BleDataUpdatedCallback cb,
void * ctx )

Register update callback for selected characteristic inside of a service.

Parameters
[in]instancepointer to the BleServiceObject instance
[in]indexcharacteristic index where data should be placed
[in]cbpointer to update callback function
[in]ctxupdate callback context

◆ ble_service_write_data()

void ble_service_write_data ( BleServiceObject * instance,
uint8_t index,
const void * data,
const size_t data_size )

Write data to service.

Calling this method stores data inside of selected characteristic and enqueues service processing, which then will send data the other side

Parameters
[in]instancepointer to the BleServiceObject instance
[in]indexcharacteristic index where data should be placed
[in]datapayload
[in]data_sizepayload size