Compare commits

...

3 Commits

Author SHA1 Message Date
anschrammh
34ad38d34a Started to write the module used to interact/communicate with the gadget bridge Android app.
The API will contain functions to send data to the app as well as a parser used to decode and extract data sent from the app.
It will internally use/access the NUS BLE service exposed by the ble_service.c file
2023-04-05 08:03:58 +02:00
anschrammh
0e1bed0452 Added the uint32_t type, will have to clean the mess up in this file someday 2023-04-05 07:59:12 +02:00
anschrammh
3fc2297f17 Updated the nano shell commands to use the new bluetooth modem start API which as the option to set the modem in bluetooth only mode 2023-04-05 07:58:09 +02:00
4 changed files with 141 additions and 19 deletions

11
app/ble/gadget_bridge.c Normal file
View File

@ -0,0 +1,11 @@
/**
* @file gadget_bridge.c
* @author Anatole SCHRAMM-HENRY
* @brief Source file implementing the API used to communicate/interact with the GadgetBridge Android application
* over BLE.
* @version 0.1
* @date 2023-04-05
*
* @copyright Copyright (c) 2023
*
*/

76
app/ble/gadget_bridge.h Normal file
View File

@ -0,0 +1,76 @@
/**
* @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 "wm_type_def.h"
typedef enum
{
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_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_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_e;
typedef enum
{
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;
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_mV, 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_NOTIFICATION_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();
#endif //GADGET_BRIDGE_H

View File

@ -99,7 +99,7 @@ static void tls_rtc_irq_cb(void *arg)
static void nus_data_rx_cb(const uint8_t *data, uint16_t length)
{
shell_printf("%s, received data : "NEW_LINE"#", __FUNCTION__);
//shell_printf("%s, received data : "NEW_LINE"#", __FUNCTION__);
for (uint16_t i = 0; i < length; i++)
{
@ -108,7 +108,7 @@ static void nus_data_rx_cb(const uint8_t *data, uint16_t length)
else
shell_putc(data[i]);
}
shell_puts("#"NEW_LINE);
//shell_puts("#"NEW_LINE);
}
int _system(const shell_cmd_t *pcmd, int argc, char *const argv[])
@ -581,20 +581,16 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
if(argc > 1)
{
if(strcmp(argv[1], "enable") == 0)
if(strcmp(argv[1], "enable") == 0 && argc == 4)
{
if(argc == 3)
{
bool result = ble_modem_on(true);
shell_printf("Enabling bluetooth modem with ble service : %d"NEW_LINE, result);
bool btOnly = atoi(argv[2]) == 1;
bool service = atoi(argv[3]) == 1;
bool result = ble_modem_on(btOnly, service);
shell_printf("Enabling bluetooth : %d with bt only : %d and service : %d"NEW_LINE, result, btOnly, service);
if(result)
ble_service_register_nus_data_rx_cb(&(nus_data_rx_cb));
}
else
{
shell_printf("Enabling bluetooth modem only : %d"NEW_LINE, ble_modem_on(false));
}
}
else if(strcmp(argv[1], "disable") == 0)
{
@ -632,9 +628,9 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
sprintf(cmd, "{\"t\":\"status\",\"bat\":%s,\"chg\":%s,\"volt\":%s} \n", argv[3], argv[4], argv[5]);
found = true;
}
else if(strcmp(argv[2], "findPhone") == 0)
else if(strcmp(argv[2], "find_phone") == 0)
{
strcpy(cmd, "{\"t\":\"findPhone\",\"n\":true} \n");
sprintf(cmd, "{\"t\":\"findPhone\",\"n\":%s} \n", argv[3]);
found = true;
}
else if(strcmp(argv[2], "music") == 0)
@ -647,6 +643,11 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
sprintf(cmd, "{\"t\":\"notify\",\"n\":\"%s\",\"id\":%s,\"tel\":\"%s\",\"msg\":\"%s\"} \n", argv[3], argv[4], argv[5], argv[6]);
found = true;
}
else if(strcmp(argv[2], "act") == 0)
{
sprintf(cmd, "{\"t\":\"act\",\"hrm\":%s,\"stp\":%s} \n", argv[3], argv[4]);
found = true;
}
if(found)
{
@ -654,7 +655,8 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
}
else
{
shell_printf("Unknown %s action, list of send_ble_notif actions :"NEW_LINE"toast \"msg\""NEW_LINE"bat \"XX%%\" 1|0 X.X"NEW_LINE"findPhone"NEW_LINE"music play|pause|previous|next"NEW_LINE"notify reply|dismiss_all id \"tel\" \"msg\""NEW_LINE, argv[2]);
shell_printf("Unknown %s action, list of send_ble_notif actions :"NEW_LINE"toast \"msg\""NEW_LINE"bat \"XX%%\" 1|0 X.X"NEW_LINE"find_phone true|false"NEW_LINE"music play|pause|previous|next"NEW_LINE"notify reply|dismiss_all id \"tel\" \"msg\""NEW_LINE
"act hrm steps"NEW_LINE, argv[2]);
}
}
else if(strcmp(argv[1], "up_conn_param") == 0)

View File

@ -51,7 +51,6 @@ typedef unsigned char INT8U;
#endif
typedef signed char INT8S;
//typedef unsigned char bool;
typedef unsigned char u8;
typedef signed char s8;
typedef unsigned short u16;
@ -78,25 +77,55 @@ typedef int int32_t;
typedef unsigned int uint32_t;
#endif
#ifdef int64
#undef int64
#endif
typedef long long int64;
#ifdef int64_t
#undef int64_t
#endif
typedef long long int64_t;
#ifdef uint64
#undef uint64
#endif
typedef unsigned long long uint64;
#ifdef uint64_t
#undef uint64_t
#endif
typedef unsigned long long uint64_t;
#ifdef int32
#undef int32
#endif
typedef int int32;
#ifdef int32_t
#undef int32_t
#endif
typedef int int32_t;
#ifdef uint32
#undef uint32
#endif
typedef unsigned int uint32;
#ifdef uint32_t
#undef uint32_t
#endif
typedef unsigned int uint32_t;
#ifdef int16
#undef int16
#endif
typedef short int16;
typedef short int16;
#ifdef uint16
#undef uint16
#endif
typedef unsigned short uint16;
typedef unsigned short uint16;
#ifdef ULONG
#undef ULONG
@ -108,6 +137,11 @@ typedef unsigned long ULONG;
#endif
typedef unsigned char u8_t;
#ifdef int8_t
#undef int8_t
#endif
typedef signed char int8_t;
#ifdef uint8_t
#undef uint8_t
#endif
@ -128,7 +162,6 @@ typedef unsigned short uint16_t;
#endif
typedef unsigned int u32_t;
#ifdef s8_t
#undef s8_t
#endif