221 lines
6.4 KiB
C
221 lines
6.4 KiB
C
/**
|
|
* @file gadget_bridge.h
|
|
* @author Anatole SCHRAMM-HENRY
|
|
* @brief Header file exposing the API used to communicate/interact with the GadgetBridge Android application
|
|
* over BLE.
|
|
* @version 0.1
|
|
* @date 2023-04-04
|
|
*
|
|
* @copyright MIT
|
|
*
|
|
*/
|
|
|
|
#ifndef GADGET_BRIDGE_H
|
|
#define GADGET_BRIDGE_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <time.h>
|
|
|
|
/**
|
|
* @brief Size of the internal buffer used to store incoming data
|
|
* which needs to be parsed.
|
|
*
|
|
*/
|
|
#define GADGET_BRIDGE_PARSER_BUFFER_SIZE (300)
|
|
#define GADGET_BRIDGE_PARSER_BUFFER_THRESHOLD (100)
|
|
|
|
#define GADGET_BRIDGE_PARSER_MAX_BODY_SIZE (200)
|
|
#define GADGET_BRIDGE_PARSER_MAX_TITLE_SIZE (100)
|
|
|
|
typedef enum gadget_bridge_toast_type
|
|
{
|
|
GADGET_BRIDGE_TOAST_TYPE_INFO = 0,
|
|
GADGET_BRIDGE_TOAST_TYPE_WARN,
|
|
GADGET_BRIDGE_TOAST_TYPE_ERROR,
|
|
} gadget_bridge_toast_type_e;
|
|
|
|
typedef enum gadget_bridge_music_control
|
|
{
|
|
GADGET_BRIDGE_MUSIC_CONTROL_PLAY = 0,
|
|
GADGET_BRIDGE_MUSIC_CONTROL_PAUSE,
|
|
GADGET_BRIDGE_MUSIC_CONTROL_PLAYPAUSE,
|
|
GADGET_BRIDGE_MUSIC_CONTROL_NEXT,
|
|
GADGET_BRIDGE_MUSIC_CONTROL_PREVIOUS,
|
|
GADGET_BRIDGE_MUSIC_CONTROL_VOLUMEUP,
|
|
GADGET_BRIDGE_MUSIC_CONTROL_VOLUMEDOWN,
|
|
GADGET_BRIDGE_MUSIC_CONTROL_FORWARD,
|
|
GADGET_BRIDGE_MUSIC_CONTROL_REWIND,
|
|
} gadget_bridge_music_control_e;
|
|
|
|
typedef enum gadget_bridge_call_action
|
|
{
|
|
GADGET_BRIDGE_CALL_ACTION_ACCEPT = 0,
|
|
GADGET_BRIDGE_CALL_ACTION_END,
|
|
GADGET_BRIDGE_CALL_ACTION_INCOMING,
|
|
GADGET_BRIDGE_CALL_ACTION_OUTGOING,
|
|
GADGET_BRIDGE_CALL_ACTION_REJECT,
|
|
GADGET_BRIDGE_CALL_ACTION_START,
|
|
GADGET_BRIDGE_CALL_ACTION_IGNORE,
|
|
GADGET_BRIDGE_CALL_ACTION_UNKNOWN,
|
|
} gadget_bridge_call_action_e;
|
|
|
|
typedef enum gadget_bridge_notification_action
|
|
{
|
|
GADGET_BRIDGE_NOTIFICATION_ACTION_DISMISS = 0,
|
|
GADGET_BRIDGE_NOTIFICATION_ACTION_DISMISS_ALL,
|
|
GADGET_BRIDGE_NOTIFICATION_ACTION_OPEN,
|
|
GADGET_BRIDGE_NOTIFICATION_ACTION_MUTE,
|
|
GADGET_BRIDGE_NOTIFICATION_ACTION_REPLY,
|
|
} gadget_bridge_notification_action_e;
|
|
|
|
typedef enum gadget_bridge_http_request_method
|
|
{
|
|
GADGET_BRIDGE_HTTP_REQUEST_GET = 0,
|
|
GADGET_BRIDGE_HTTP_REQUEST_POST,
|
|
GADGET_BRIDGE_HTTP_REQUEST_HEAD,
|
|
GADGET_BRIDGE_HTTP_REQUEST_PUT,
|
|
GADGET_BRIDGE_HTTP_REQUEST_PATCH,
|
|
GADGET_BRIDGE_HTTP_REQUEST_DELETE,
|
|
|
|
} gadget_bridge_http_request_method_e;
|
|
|
|
typedef enum gadget_bridge_parser_code
|
|
{
|
|
GADGET_BRIDGE_PARSER_CODE_OK = 0,
|
|
GADGET_BRIDGE_PARSER_CODE_PARSING,
|
|
GADGET_BRIDGE_PARSER_CODE_BUFFER_FULL,
|
|
GADGET_BRIDGE_PARSER_CODE_DATA_TOO_LONG,
|
|
} gadget_bridge_parser_code_e;
|
|
|
|
typedef struct http_header
|
|
{
|
|
const char *key;
|
|
const char *value;
|
|
} http_header_t;
|
|
|
|
typedef enum gadget_bridge_event_type
|
|
{
|
|
GADGET_BRIDGE_EVENT_TYPE_NONE = 0,
|
|
GADGET_BRIDGE_EVENT_TYPE_SET_TIME,
|
|
GADGET_BRIDGE_EVENT_TYPE_NOTIFY,
|
|
GADGET_BRIDGE_EVENT_TYPE_CALL,
|
|
GADGET_BRIDGE_EVENT_TYPE_WEATHER,
|
|
GADGET_BRIDGE_EVENT_TYPE_FIND,
|
|
GADGET_BRIDGE_EVENT_TYPE_ACT,
|
|
GADGET_BRIDGE_EVENT_TYPE_MUSIC_INFO,
|
|
GADGET_BRIDGE_EVENT_TYPE_MUSIC_STATE,
|
|
GADGET_BRIDGE_EVENT_TYPE_UNKNOWN,
|
|
} gadget_bridge_event_type_e;
|
|
|
|
typedef enum gadget_bridge_notification_type
|
|
{
|
|
GADGET_BRIDGE_NOTIFICATION_TYPE_SMS = 0,
|
|
GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL,
|
|
GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN,
|
|
} gadget_bridge_notification_type_e;
|
|
|
|
typedef enum
|
|
{
|
|
GADGET_BRIDGE_MUSIC_STATE_PAUSE = 0,
|
|
GADGET_BRIDGE_MUSIC_STATE_PLAY,
|
|
GADGET_BRIDGE_MUSIC_STATE_UNKNOWN,
|
|
} gadget_bridge_music_state_e;
|
|
|
|
typedef struct gadget_bridge_event_data
|
|
{
|
|
gadget_bridge_event_type_e event_type;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
struct tm gm_time;
|
|
struct tm local_time;
|
|
int8_t time_zone;
|
|
} time;
|
|
struct
|
|
{
|
|
uint32_t handle;
|
|
gadget_bridge_notification_type_e notification_type;
|
|
char *title;
|
|
char *body;
|
|
} notification;
|
|
struct
|
|
{
|
|
char *phone_number;
|
|
char *contact;
|
|
gadget_bridge_call_action_e call_action;
|
|
} call;
|
|
struct
|
|
{
|
|
float temperature_celsius;
|
|
uint8_t humidity;
|
|
char *weather_desc;
|
|
float wind_speed_kmh;
|
|
uint16_t wind_dir;
|
|
char *location;
|
|
} weather;
|
|
struct
|
|
{
|
|
bool find;
|
|
} find;
|
|
struct
|
|
{
|
|
bool heart_rate_monitor;
|
|
bool steps;
|
|
uint8_t heart_rate_interval;
|
|
} act;
|
|
struct
|
|
{
|
|
gadget_bridge_music_state_e music_state;
|
|
uint16_t position_in_seconds;
|
|
uint8_t shuffle;
|
|
uint8_t repeat;
|
|
} music_state;
|
|
struct
|
|
{
|
|
char *artist;
|
|
char *track;
|
|
uint16_t duration_in_seconds;
|
|
} music_info;
|
|
};
|
|
} gadget_bridge_event_data_t;
|
|
|
|
typedef void (*parser_event_callback_t)(const gadget_bridge_event_data_t *gadget_bridge_event_data);
|
|
|
|
bool gadget_bridge_send_toast(gadget_bridge_toast_type_e toast_type, const char *message);
|
|
|
|
bool gadget_bridge_send_firmware_version(const char *fw1, const char *fw2);
|
|
|
|
bool gadget_bridge_send_battery_status(uint8_t battery_level_in_percent, float battery_level_in_V, bool is_charging);
|
|
|
|
bool gadget_bridge_send_find_phone(bool find_phone);
|
|
|
|
bool gadget_bridge_send_music_control(gadget_bridge_music_control_e music_control);
|
|
|
|
bool gadget_bridge_handle_call(gadget_bridge_call_action_e call_action);
|
|
|
|
bool gadget_bridge_handle_notification(gadget_bridge_call_action_e notification_action, uint32_t handle, const char *phone_number, const char *message);
|
|
|
|
bool gadget_bridge_send_activity_data(uint16_t heart_rate_in_bpm, uint32_t step_count);
|
|
|
|
bool gadget_bridge_send_http_request(uint32_t id, const char *url, gadget_bridge_http_request_method_e http_request_method, const char *http_body, const http_header_t *http_headers);
|
|
|
|
void gadget_bridge_parser_register_event_callback(parser_event_callback_t parser_event_callback);
|
|
|
|
gadget_bridge_parser_code_e gadget_bridge_parser_feed(const char *data, uint16_t length);
|
|
|
|
gadget_bridge_parser_code_e gadget_bridge_parser_run(void);
|
|
|
|
const char *gadget_bridge_parser_code_2_str(gadget_bridge_parser_code_e parser_code);
|
|
|
|
const char *gadget_bridge_event_type_2_str(gadget_bridge_event_type_e event_type);
|
|
|
|
const char *gadget_bridge_notification_type_2_str(gadget_bridge_notification_type_e notification_type);
|
|
|
|
const char *gadget_bridge_music_state_2_str(gadget_bridge_music_state_e music_state);
|
|
|
|
void gadget_bridge_parser_debug(void);
|
|
|
|
#endif //GADGET_BRIDGE_H
|