Updated the gadget bridge parser sources to test the new features
This commit is contained in:
parent
cf50df7468
commit
e6b1595bae
@ -16,6 +16,7 @@
|
||||
#include <string.h>
|
||||
#include "ble_service.h"
|
||||
#include "wm_mem.h"
|
||||
#include "utils.h"
|
||||
|
||||
/* Internal enum definition */
|
||||
typedef enum gadget_bridge_parser_fsm
|
||||
@ -30,6 +31,9 @@ typedef enum gadget_bridge_parser_fsm
|
||||
GADGET_BRIDGE_PARSER_FSM_FOUND_TITLE,
|
||||
GADGET_BRIDGE_PARSER_FSM_PARSING_TITLE_CONTENT,
|
||||
|
||||
GADGET_BRIDGE_PARSER_FSM_FOUND_SUBJECT,
|
||||
GADGET_BRIDGE_PARSER_FSM_PARSING_SUBJECT_BODY_CONTENT,
|
||||
|
||||
GADGET_BRIDGE_PARSER_FSM_FOUND_ID_SRC,
|
||||
GADGET_BRIDGE_PARSER_FSM_FOUND_SRC_BODY,
|
||||
GADGET_BRIDGE_PARSER_FSM_PARSING_BODY_CONTENT,
|
||||
@ -243,7 +247,7 @@ static bool _parser_extract_bool(char *start, char *end, bool *data);
|
||||
gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
||||
{
|
||||
if(!_gadget_bridge_internals.new_data) return GADGET_BRIDGE_PARSER_CODE_OK;
|
||||
char *start = NULL, *end = NULL;
|
||||
char *start = NULL, *end = NULL, *end2 = NULL; // end2 is used when more than one next tag is possible
|
||||
bool free_some_space = false;
|
||||
gadget_bridge_parser_code_e to_return = GADGET_BRIDGE_PARSER_CODE_PARSING;
|
||||
|
||||
@ -426,10 +430,20 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
||||
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
||||
break;
|
||||
case GADGET_BRIDGE_PARSER_FSM_FOUND_ID_SRC:
|
||||
if((start = strstr(_gadget_bridge_internals.buffer, "src:"))
|
||||
&& (end = strstr(_gadget_bridge_internals.buffer, ",title")))
|
||||
if((start = strstr(_gadget_bridge_internals.buffer, "src:")) &&
|
||||
((end = strstr(_gadget_bridge_internals.buffer, ",title")) || (end2 = strstr(_gadget_bridge_internals.buffer, ",subject"))))
|
||||
{
|
||||
//printf("###Found TITLE\n");
|
||||
if((end && !end2) || (end != NULL && end < end2))
|
||||
{
|
||||
//printf("###Found TITLE\n");
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_FOUND_TITLE;
|
||||
}
|
||||
else if((!end && end2) || (end2 != NULL && end2 < end))
|
||||
{
|
||||
//printf("###Found SUBJECT\n");
|
||||
end = end2;
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_FOUND_SUBJECT;
|
||||
}
|
||||
|
||||
_parser_extract_src(start + 5, end - 1);
|
||||
|
||||
@ -438,7 +452,6 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
||||
_parser_free_buffer(
|
||||
end -_gadget_bridge_internals.buffer
|
||||
);
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_FOUND_TITLE;
|
||||
}
|
||||
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||
@ -485,7 +498,7 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
||||
// Then we have a very long title, in this case we juste keep the max set up
|
||||
else if(!end && _gadget_bridge_internals.buffer_content_size >= GADGET_BRIDGE_PARSER_MAX_TITLE_SIZE)
|
||||
{
|
||||
printf("###NOTIFICATION (MAX TITLE SIZE)\n");
|
||||
//printf("###NOTIFICATION (MAX TITLE SIZE)\n");
|
||||
|
||||
_parser_extract_char_str(_gadget_bridge_internals.buffer, _gadget_bridge_internals.buffer + GADGET_BRIDGE_PARSER_MAX_TITLE_SIZE, &_gadget_bridge_internals.event_data.notification.title);
|
||||
|
||||
@ -510,6 +523,10 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
||||
_parser_free_buffer(
|
||||
start -_gadget_bridge_internals.buffer
|
||||
);
|
||||
|
||||
if(_gadget_bridge_internals.event_data.notification.notification_type == GADGET_BRIDGE_NOTIFICATION_TYPE_GADGET_BRIDGE)
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_PARSING_SUBJECT_BODY_CONTENT;
|
||||
else
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_PARSING_BODY_CONTENT;
|
||||
}
|
||||
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
||||
@ -574,6 +591,63 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
||||
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
||||
}
|
||||
break;
|
||||
case GADGET_BRIDGE_PARSER_FSM_PARSING_SUBJECT_BODY_CONTENT:
|
||||
{
|
||||
end = strstr(_gadget_bridge_internals.buffer, ",sender");
|
||||
if(end)
|
||||
{
|
||||
// We don't care about the sender nor the tel tag
|
||||
//printf("###TEST NOTIFICATION Type done\n");
|
||||
|
||||
_parser_extract_char_str(_gadget_bridge_internals.buffer, end - 1, &_gadget_bridge_internals.event_data.notification.body);
|
||||
|
||||
// We remove the parsed part from the buffer
|
||||
end += 7;
|
||||
_parser_free_buffer(
|
||||
end -_gadget_bridge_internals.buffer
|
||||
);
|
||||
|
||||
// If a callback was registered, we call it and pass the data to it
|
||||
if(_gadget_bridge_internals.parser_event_callback)
|
||||
{
|
||||
_gadget_bridge_internals.parser_event_callback(&_gadget_bridge_internals.event_data);
|
||||
}
|
||||
|
||||
// Free the allocated data
|
||||
_free_event_data();
|
||||
|
||||
// The end of the road for this object
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||
}
|
||||
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||
// Then we have a very long body, in this case we juste keep the max set up
|
||||
else if(!end && _gadget_bridge_internals.buffer_content_size >= GADGET_BRIDGE_PARSER_MAX_BODY_SIZE)
|
||||
{
|
||||
//printf("###TEST NOTIFICATION (MAX BODY SIZE) Type done\n");
|
||||
|
||||
_parser_extract_char_str(_gadget_bridge_internals.buffer, _gadget_bridge_internals.buffer + GADGET_BRIDGE_PARSER_MAX_BODY_SIZE, &_gadget_bridge_internals.event_data.notification.body);
|
||||
|
||||
// We remove the parsed part from the buffer
|
||||
_parser_free_buffer(
|
||||
GADGET_BRIDGE_PARSER_MAX_BODY_SIZE + 1
|
||||
);
|
||||
|
||||
// If a callback was registered, we call it and pass the data to it
|
||||
if(_gadget_bridge_internals.parser_event_callback)
|
||||
{
|
||||
_gadget_bridge_internals.parser_event_callback(&_gadget_bridge_internals.event_data);
|
||||
}
|
||||
|
||||
// Free the allocated data
|
||||
_free_event_data();
|
||||
|
||||
// The end of the road for this object
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||
}
|
||||
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
||||
}
|
||||
break;
|
||||
/*case GADGET_BRIDGE_PARSER_FSM_FOUND_ID_BODY:
|
||||
if((start = strstr(_gadget_bridge_internals.buffer, "body:"))
|
||||
&& (end = strstr(_gadget_bridge_internals.buffer, ",sender")))
|
||||
@ -631,6 +705,24 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
||||
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||
break;*/
|
||||
case GADGET_BRIDGE_PARSER_FSM_FOUND_SUBJECT:
|
||||
if((start = strstr(_gadget_bridge_internals.buffer, "subject:")))
|
||||
{
|
||||
//printf("###Parsing SUBJECT content\n");
|
||||
|
||||
// We remove the parsed part from the buffer
|
||||
start += 9;
|
||||
_parser_free_buffer(
|
||||
start -_gadget_bridge_internals.buffer
|
||||
);
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_PARSING_TITLE_CONTENT;
|
||||
}
|
||||
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||
else if(_gadget_bridge_internals.buffer_content_size > GADGET_BRIDGE_PARSER_BUFFER_THRESHOLD)
|
||||
free_some_space = true;
|
||||
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
||||
break;
|
||||
case GADGET_BRIDGE_PARSER_FSM_FOUND_CALL:
|
||||
if((start = strstr(_gadget_bridge_internals.buffer, "cmd:"))
|
||||
&& (end = strstr(_gadget_bridge_internals.buffer, ",name")))
|
||||
@ -1151,6 +1243,7 @@ const char *gadget_bridge_notification_type_2_str(gadget_bridge_notification_typ
|
||||
{
|
||||
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_SMS)
|
||||
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL)
|
||||
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_GADGET_BRIDGE)
|
||||
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN)
|
||||
default:
|
||||
return "Unknown notification type";
|
||||
@ -1326,6 +1419,8 @@ static void _parser_extract_src(char *start, char *end)
|
||||
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_SMS;
|
||||
else if(strcmp(start, "E-mail") == 0)
|
||||
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL;
|
||||
else if(strcmp(start, "Gadgetbridge") == 0)
|
||||
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_GADGET_BRIDGE;
|
||||
else
|
||||
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN;
|
||||
|
||||
|
@ -129,6 +129,7 @@ typedef enum gadget_bridge_notification_type
|
||||
{
|
||||
GADGET_BRIDGE_NOTIFICATION_TYPE_SMS = 0,
|
||||
GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL,
|
||||
GADGET_BRIDGE_NOTIFICATION_TYPE_GADGET_BRIDGE,
|
||||
GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN,
|
||||
} gadget_bridge_notification_type_e;
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "task.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "app_common.h"
|
||||
#include "app_utils.h"
|
||||
#include "nano_shell_interface.h"
|
||||
#include "wm_gpio_afsel.h"
|
||||
#include "wm_cpu.h"
|
||||
@ -182,7 +183,7 @@ static void nus_data_rx_cb(const uint8_t *data, uint16_t length)
|
||||
gadget_bridge_parser_code_e code;
|
||||
while((code = gadget_bridge_parser_run()) == GADGET_BRIDGE_PARSER_CODE_PARSING);
|
||||
shell_printf("Gadget bridge parser code : %s"NEW_LINE, gadget_bridge_parser_code_2_str(code));
|
||||
tls_bt_ctrl_sleep(false);
|
||||
//ble_modem_wake();
|
||||
//shell_puts("#"NEW_LINE);
|
||||
}
|
||||
|
||||
@ -655,13 +656,11 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
void tls_bt_controller_sleep_enter_cb(uint32_t sleep_duration_ms)
|
||||
{
|
||||
//shell_printf("BT CTRL sleep for %u"NEW_LINE, sleep_duration_ms);
|
||||
//tls_bt_ctrl_wakeup();
|
||||
}
|
||||
|
||||
void tls_bt_controller_sleep_exit_cb(void)
|
||||
{
|
||||
//shell_printf("BT CTRL wakeup"NEW_LINE);
|
||||
//tls_bt_ctrl_sleep(false);
|
||||
}
|
||||
|
||||
int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
@ -707,6 +706,17 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
{
|
||||
shell_printf("MTU exchange request : %d"NEW_LINE, ble_service_request_mtu_exchange());
|
||||
}
|
||||
else if(strcmp(argv[1], "mac_addr") == 0)
|
||||
{
|
||||
const uint8_t *mac = ble_service_get_device_mac_address();
|
||||
shell_printf("The device MAC address is : %02X:%02X:%02X:%02X:%02X:%02X"NEW_LINE,
|
||||
mac[5],
|
||||
mac[4],
|
||||
mac[3],
|
||||
mac[2],
|
||||
mac[1],
|
||||
mac[0]);
|
||||
}
|
||||
else if(strcmp(argv[1], "send_ble_notif") == 0 && argc > 2)
|
||||
{
|
||||
char cmd[200] = "";
|
||||
@ -853,7 +863,8 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
if(argc == 3)
|
||||
{
|
||||
bool sleeping = strtoul(argv[2], NULL, 10);
|
||||
shell_printf("BLE modem set to sleeping : %d"NEW_LINE, tls_bt_ctrl_sleep(sleeping));
|
||||
bool status = sleeping ? ble_modem_sleep() : ble_modem_wake();
|
||||
shell_printf("BLE modem set to sleeping : %d"NEW_LINE, status);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "ble_modem_wake") == 0)
|
||||
@ -880,13 +891,20 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
shell_printf("List of bluetooth actions :"NEW_LINE"enable 0|1 0|1"NEW_LINE"disable"NEW_LINE"start_demo"NEW_LINE"stop_demo"NEW_LINE"send_ble_notif toast \"msg\"|bat \"%%\"|findPhone|music|notify"NEW_LINE"mtu_exch"NEW_LINE
|
||||
shell_printf("List of bluetooth actions :"NEW_LINE
|
||||
"enable 0|1 0|1"NEW_LINE
|
||||
"disable"NEW_LINE
|
||||
"start_demo"NEW_LINE
|
||||
"stop_demo"NEW_LINE
|
||||
"send_ble_notif toast \"msg\"|bat \"%%\"|findPhone|music|notify"NEW_LINE
|
||||
"mtu_exch"NEW_LINE
|
||||
"up_conn_param itvl_min itvl_max latency supervision_timeout min_ce_len max_ce_len"NEW_LINE
|
||||
"ble_tx_power 1|2|3|4|5"NEW_LINE
|
||||
"bt_tx_power 1|2|3|4|5"NEW_LINE
|
||||
"ble_modem_sleep 1|0"NEW_LINE
|
||||
"ble_modem_wake"NEW_LINE
|
||||
"ble_modem_mode bt|bt_wifi"NEW_LINE);
|
||||
"ble_modem_mode bt|bt_wifi"NEW_LINE
|
||||
"mac_addr"NEW_LINE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -925,6 +943,24 @@ int _exit_remote_access(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _utils(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
{
|
||||
if(argc > 1)
|
||||
{
|
||||
if(strcmp(argv[1], "random") == 0)
|
||||
{
|
||||
uint32_t random = random_gen_6_digit();
|
||||
shell_printf("Random 6 digit number is : %u"NEW_LINE, random);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shell_printf("List of %s actions :"NEW_LINE
|
||||
"random"NEW_LINE, argv[0]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NANO_SHELL_ADD_CMD(bus,
|
||||
_bus,
|
||||
"Command to interact with the SPI bus",
|
||||
@ -977,3 +1013,7 @@ NANO_SHELL_ADD_CMD(exit,
|
||||
_exit_remote_access,
|
||||
"Disconnect from Nano-Shell remote access",
|
||||
" Use this command to disconnect from Nano-Shell remote access"NEW_LINE);
|
||||
NANO_SHELL_ADD_CMD(utils,
|
||||
_utils,
|
||||
"Command used to test various utils functions",
|
||||
" Use this command to try various utility functions out lilke random and more"NEW_LINE);
|
||||
|
Loading…
Reference in New Issue
Block a user