From 74b90f9feeddf9c3c80e833448d7bed0e5236347 Mon Sep 17 00:00:00 2001 From: Anatole SCHRAMM Date: Thu, 6 Apr 2023 14:12:29 +0200 Subject: [PATCH] Finished to define the API, started to implement some of it --- app/ble/gadget_bridge.c | 39 ++++++++++++++++++++++++++++++++++++- app/ble/gadget_bridge.h | 43 ++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/app/ble/gadget_bridge.c b/app/ble/gadget_bridge.c index 9f50236..c790d47 100644 --- a/app/ble/gadget_bridge.c +++ b/app/ble/gadget_bridge.c @@ -8,4 +8,41 @@ * * @copyright Copyright (c) 2023 * - */ \ No newline at end of file + */ + +#include "gadget_bridge.h" +#include +#include "ble_service.h" + +/* Internal function definition */ +const char *_gadget_bridge_toast_type_2_str(gadget_bridge_toast_type_e toast_type); + +bool gadget_bridge_send_toast(gadget_bridge_toast_type_e toast_type, const char *message) +{ + if(!message || !strlen(message)) + return true; + + bool to_return = true; + to_return &= ble_service_send_nus_data((const uint8_t *)"{\"t\":\"", 6); + to_return &= ble_service_send_nus_data((const uint8_t *)_gadget_bridge_toast_type_2_str(toast_type), strlen(_gadget_bridge_toast_type_2_str(toast_type))); + to_return &= ble_service_send_nus_data((const uint8_t *)"\",\"msg\",\"", 9); + to_return &= ble_service_send_nus_data((const uint8_t *)message, strlen(message)); + to_return &= ble_service_send_nus_data((const uint8_t *)"\"}\n", 3); + + return to_return; +} + +/* Internal function declaration */ +const char *_gadget_bridge_toast_type_2_str(gadget_bridge_toast_type_e toast_type) +{ + switch(toast_type) + { + case GADGET_BRIDGE_TOAST_TYPE_ERROR: + return "error"; + case GADGET_BRIDGE_TOAST_TYPE_WARN: + return "warn"; + case GADGET_BRIDGE_TOAST_TYPE_INFO: + default: + return "info"; + } +} \ No newline at end of file diff --git a/app/ble/gadget_bridge.h b/app/ble/gadget_bridge.h index 74d37e5..6f70468 100644 --- a/app/ble/gadget_bridge.h +++ b/app/ble/gadget_bridge.h @@ -15,14 +15,14 @@ #include "wm_type_def.h" -typedef enum +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; +} gadget_bridge_toast_type_e; -typedef enum +typedef enum gadget_bridge_music_control { GADGET_BRIDGE_MUSIC_CONTROL_PLAY = 0, GADGET_BRIDGE_MUSIC_CONTROL_PAUSE, @@ -33,9 +33,9 @@ typedef enum GADGET_BRIDGE_MUSIC_CONTROL_VOLUMEDOWN, GADGET_BRIDGE_MUSIC_CONTROL_FORWARD, GADGET_BRIDGE_MUSIC_CONTROL_REWIND, -} GADGET_BRIDGE_MUSIC_CONTROL_e; +} gadget_bridge_music_control_e; -typedef enum +typedef enum gadget_bridge_call_action { GADGET_BRIDGE_CALL_ACTION_ACCEPT = 0, GADGET_BRIDGE_CALL_ACTION_END, @@ -44,18 +44,35 @@ typedef enum GADGET_BRIDGE_CALL_ACTION_REJECT, GADGET_BRIDGE_CALL_ACTION_START, GADGET_BRIDGE_CALL_ACTION_IGNORE, -} GADGET_BRIDGE_CALL_ACTION_e; +} gadget_bridge_call_action_e; -typedef enum +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; +} gadget_bridge_notification_action_e; -bool gadget_bridge_send_toast(GADGET_BRIDGE_TOAST_TYPE_e toast_type, const char *message); +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 struct http_header +{ + const char *key; + const char *value; +} http_header_t; + +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); @@ -63,14 +80,14 @@ bool gadget_bridge_send_battery_status(uint8_t battery_level_in_percent, float b 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_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_call(gadget_bridge_call_action_e call_action); -bool gadget_bridge_handle_notification(GADGET_BRIDGE_NOTIFICATION_ACTION_e notification_action, uint64_t handle, const char *phone_number, const char *message); +bool gadget_bridge_handle_notification(gadget_bridge_call_action_e notification_action, uint64_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(); +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); #endif //GADGET_BRIDGE_H \ No newline at end of file