Updated GadgetBridge parser standalone project
This commit is contained in:
parent
4d8b0d359d
commit
be27501e08
@ -21,6 +21,12 @@
|
||||
|
||||
bool ble_service_send_nus_data(const uint8_t *data, uint16_t length)
|
||||
{
|
||||
printf("Sent nus data :#");
|
||||
for(uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
putchar(data[i]);
|
||||
}
|
||||
printf("#\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -97,6 +103,7 @@ static time_t _unix_timestamp = 0;
|
||||
/* Internal function definition */
|
||||
static const char *_gadget_bridge_toast_type_2_str(gadget_bridge_toast_type_e toast_type);
|
||||
static const char *_gadget_bridge_music_control_2_str(gadget_bridge_music_control_e music_control);
|
||||
static const char *_gadget_bridge_notification_action_2_str(gadget_bridge_notification_action_e notification_action);
|
||||
static const char *_gadget_bridge_http_request_method_2_str(gadget_bridge_http_request_method_e http_request_method);
|
||||
static void _parser_free_buffer(uint16_t length);
|
||||
static void _free_event_data(void);
|
||||
@ -142,8 +149,8 @@ bool gadget_bridge_send_battery_status(uint8_t battery_level_in_percent, float b
|
||||
bool to_return = true;
|
||||
char num_2_str[30] = "";
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"{\"t\":\"status\",\"bat\":", 20);
|
||||
sprintf(num_2_str, "%u,\"chg\":%u,\"volt\":%.3f} \n", battery_level_in_percent, is_charging, battery_level_in_V);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, strlen(num_2_str));
|
||||
int length = sprintf(num_2_str, "%u,\"chg\":%u,\"volt\":%.3f} \n", battery_level_in_percent, is_charging, battery_level_in_V);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, length);
|
||||
|
||||
return to_return;
|
||||
}
|
||||
@ -170,6 +177,41 @@ bool gadget_bridge_send_music_control(gadget_bridge_music_control_e music_contro
|
||||
return to_return;
|
||||
}
|
||||
|
||||
bool gadget_bridge_send_notification_action(gadget_bridge_notification_action_e notification_action, uint32_t handle, const char *phone_number, const char *message)
|
||||
{
|
||||
bool to_return = true;
|
||||
char num_2_str[11] = "";
|
||||
|
||||
// There is no point sending a reply without an actual message
|
||||
if(notification_action == GADGET_BRIDGE_NOTIFICATION_ACTION_REPLY && !message)
|
||||
return false;
|
||||
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"{\"t\":\"notify\",\"n\":\"", 19);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)_gadget_bridge_notification_action_2_str(notification_action), strlen(_gadget_bridge_notification_action_2_str(notification_action)));
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"\",\"id\":", 7);
|
||||
|
||||
int length = sprintf(num_2_str, "%u", handle);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, length);
|
||||
|
||||
if(notification_action == GADGET_BRIDGE_NOTIFICATION_ACTION_REPLY)
|
||||
{
|
||||
if(phone_number)
|
||||
{
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)",\"tel\":\"", 8);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)phone_number, strlen(phone_number));
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"\"", 1);
|
||||
}
|
||||
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)",\"msg\":\"", 8);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)message, strlen(message));
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"\"", 1);
|
||||
}
|
||||
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"} \n", 3);
|
||||
|
||||
return to_return;
|
||||
}
|
||||
|
||||
bool gadget_bridge_send_activity_data(uint16_t heart_rate_in_bpm, uint32_t step_count)
|
||||
{
|
||||
bool to_return = true;
|
||||
@ -177,13 +219,13 @@ bool gadget_bridge_send_activity_data(uint16_t heart_rate_in_bpm, uint32_t step_
|
||||
//{\"t\":\"act\",\"hrm\":%s,\"stp\":%s} \n
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"{\"t\":\"act\",\"hrm\":", 17);
|
||||
|
||||
sprintf(num_2_str, "%u", heart_rate_in_bpm);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, strlen(num_2_str));
|
||||
int length = sprintf(num_2_str, "%u", heart_rate_in_bpm);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, length);
|
||||
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)",\"stp\":", 7);
|
||||
|
||||
sprintf(num_2_str, "%u", step_count);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, strlen(num_2_str));
|
||||
length = sprintf(num_2_str, "%u", step_count);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, length);
|
||||
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"} \n", 3);
|
||||
|
||||
@ -194,10 +236,10 @@ bool gadget_bridge_send_http_request(uint32_t id, const char *url, gadget_bridge
|
||||
{
|
||||
bool to_return = true;
|
||||
char num_2_str[11] = "";
|
||||
sprintf(num_2_str, "%u", id);
|
||||
int length = sprintf(num_2_str, "%u", id);
|
||||
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"{\"t\":\"http\",\"id\":\"", 18);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, strlen(num_2_str));
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)num_2_str, length);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"\",\"url\":\"", 9);
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)url, strlen(url));
|
||||
to_return &= ble_service_send_nus_data((const uint8_t *)"\",\"method\":\"", 12);
|
||||
@ -1313,6 +1355,24 @@ static const char *_gadget_bridge_music_control_2_str(gadget_bridge_music_contro
|
||||
}
|
||||
}
|
||||
|
||||
static const char *_gadget_bridge_notification_action_2_str(gadget_bridge_notification_action_e notification_action)
|
||||
{
|
||||
switch(notification_action)
|
||||
{
|
||||
case GADGET_BRIDGE_NOTIFICATION_ACTION_DISMISS_ALL:
|
||||
return "dismiss_all";
|
||||
case GADGET_BRIDGE_NOTIFICATION_ACTION_OPEN:
|
||||
return "open";
|
||||
case GADGET_BRIDGE_NOTIFICATION_ACTION_MUTE:
|
||||
return "mute";
|
||||
case GADGET_BRIDGE_NOTIFICATION_ACTION_REPLY:
|
||||
return "reply";
|
||||
case GADGET_BRIDGE_NOTIFICATION_ACTION_DISMISS:
|
||||
default :
|
||||
return "dismiss";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *_gadget_bridge_http_request_method_2_str(gadget_bridge_http_request_method_e http_request_method)
|
||||
{
|
||||
switch(http_request_method)
|
||||
|
@ -249,16 +249,27 @@ bool gadget_bridge_send_find_phone(bool find_phone);
|
||||
/**
|
||||
* @brief Sends a command to control the music playback of the phone through GadgetBridge.
|
||||
*
|
||||
* @param music_control an enumeration value indicating the action to perform:
|
||||
* @param music_control an enumeration value indicating the action to perform :
|
||||
* PLAY, PAUSE, NEXT, PREVIOUS, VOLUMEUP etc..
|
||||
* @return true if the command was successfully sent.
|
||||
* @return false otherwise.
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @brief Sends a command to perform an action to the specified received notification.
|
||||
*
|
||||
* @param notification_action an enumeration value indicating the action to perform on the notification :
|
||||
* DISMISS, DISMISS_ALL, OPEN, MUTE and REPLY.
|
||||
* @param handle the notification's handle.
|
||||
* @param phone_number a string containing a phone number to send the REPLY to or NULL to use the same number as the notification.
|
||||
* @param message a string containing the message to send to a REPLY action, can be NULL if the action is different.
|
||||
* @return true if the command was successfully sent.
|
||||
* @return false otherwise.
|
||||
*/
|
||||
bool gadget_bridge_send_notification_action(gadget_bridge_notification_action_e notification_action, uint32_t handle, const char *phone_number, const char *message);
|
||||
|
||||
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_handle_call(gadget_bridge_call_action_e call_action);
|
||||
|
||||
/**
|
||||
* @brief Sends the provided activity data to GadgetBridge. This will then be displayed
|
||||
|
@ -50,19 +50,19 @@
|
||||
<stdlib.h>
|
||||
<string.h>
|
||||
|
||||
1697540423 source:d:\users\think\documents\w800_smart_watch\src\gadget_bridge_parser\gadget_bridge.c
|
||||
1701721954 source:d:\users\think\documents\w800_smart_watch\src\gadget_bridge_parser\gadget_bridge.c
|
||||
"gadget_bridge.h"
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
<string.h>
|
||||
<assert.h>
|
||||
|
||||
1696487243 d:\users\think\documents\w800_smart_watch\src\gadget_bridge_parser\gadget_bridge.h
|
||||
1701721690 d:\users\think\documents\w800_smart_watch\src\gadget_bridge_parser\gadget_bridge.h
|
||||
<stdint.h>
|
||||
<stdbool.h>
|
||||
<time.h>
|
||||
|
||||
1697572727 source:d:\users\think\documents\w800_smart_watch\src\gadget_bridge_parser\main.c
|
||||
1701722229 source:d:\users\think\documents\w800_smart_watch\src\gadget_bridge_parser\main.c
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
<string.h>
|
||||
|
@ -2,19 +2,19 @@
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="gadget_bridge.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="gadget_bridge.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="4496" topLine="288" />
|
||||
<Cursor1 position="784" topLine="6" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="gadget_bridge.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="gadget_bridge.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="35064" topLine="963" />
|
||||
<Cursor1 position="4496" topLine="118" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="main.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="main.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="11548" topLine="333" />
|
||||
<Cursor1 position="12856" topLine="343" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
|
@ -379,5 +379,12 @@ int main()
|
||||
//gadget_bridge_parser_debug();
|
||||
}
|
||||
|
||||
gadget_bridge_send_notification_action(GADGET_BRIDGE_NOTIFICATION_ACTION_DISMISS, 1, NULL, NULL);
|
||||
gadget_bridge_send_notification_action(GADGET_BRIDGE_NOTIFICATION_ACTION_DISMISS_ALL, 2, NULL, NULL);
|
||||
gadget_bridge_send_notification_action(GADGET_BRIDGE_NOTIFICATION_ACTION_MUTE, 3, NULL, NULL);
|
||||
gadget_bridge_send_notification_action(GADGET_BRIDGE_NOTIFICATION_ACTION_OPEN, 4, NULL, NULL);
|
||||
gadget_bridge_send_notification_action(GADGET_BRIDGE_NOTIFICATION_ACTION_REPLY, 5, NULL, "Salut mon bichon");
|
||||
gadget_bridge_send_notification_action(GADGET_BRIDGE_NOTIFICATION_ACTION_REPLY, 6, "0601020304", "Salut mon bichon");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user