Skip to content

Commit 9c3dab6

Browse files
committed
feat: BLE Enum gattc
1 parent 15641ef commit 9c3dab6

5 files changed

Lines changed: 745 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include <string.h>
2+
#include "argtable3/argtable3.h"
3+
#include "esp_console.h"
4+
#include "esp_log.h"
5+
#include "freertos/FreeRTOS.h"
6+
#include "freertos/task.h"
7+
#include "gattcmd_module.h"
8+
9+
#define GATTCMD_CMD_NAME "gattcmd_set_client"
10+
11+
static struct {
12+
struct arg_str* remote_addr;
13+
struct arg_end* end;
14+
} gattccmd_client_args;
15+
16+
static struct {
17+
struct arg_str* gatt;
18+
struct arg_str* value;
19+
struct arg_end* end;
20+
} gattccmd_write_args;
21+
22+
static int gattccmd_set_client(int argc, char** argv) {
23+
int nerrros = arg_parse(argc, argv, (void**) &gattccmd_client_args);
24+
if (nerrros != 0) {
25+
arg_print_errors(stderr, gattccmd_client_args.end, GATTCMD_CMD_NAME);
26+
return 1;
27+
}
28+
ESP_LOGI(GATTCMD_CMD_NAME, "Client: %s",
29+
gattccmd_client_args.remote_addr->sval[0]);
30+
gattcmd_module_set_remote_address(gattccmd_client_args.remote_addr->sval[0]);
31+
return 0;
32+
}
33+
34+
static int gattccmd_write(int argc, char** argv) {
35+
int nerrros = arg_parse(argc, argv, (void**) &gattccmd_write_args);
36+
if (nerrros != 0) {
37+
arg_print_errors(stderr, gattccmd_write_args.end, GATTCMD_CMD_NAME);
38+
return 1;
39+
}
40+
ESP_LOGI(GATTCMD_CMD_NAME, "Write Client: %s",
41+
gattccmd_write_args.gatt->sval[0]);
42+
gattcmd_module_gatt_write(gattccmd_write_args.gatt->sval[0],
43+
gattccmd_write_args.value->sval[0]);
44+
return 0;
45+
}
46+
47+
static int gattccmd_connect(int argc, char** argv) {
48+
gattcmd_module_connect();
49+
return 0;
50+
}
51+
52+
static int gattccmd_disconnect(int argc, char** argv) {
53+
gattcmd_module_disconnect();
54+
return 0;
55+
}
56+
57+
void gattccmd_register_cmd() {
58+
gattccmd_client_args.remote_addr =
59+
arg_str0(NULL, NULL, "<Address>", "BT Address");
60+
gattccmd_client_args.end = arg_end(1);
61+
62+
gattccmd_write_args.gatt =
63+
arg_str0(NULL, NULL, "<Gatt Address>", "BT Address");
64+
gattccmd_write_args.value = arg_str1(NULL, NULL, "<value>", "BT Address");
65+
gattccmd_write_args.end = arg_end(2);
66+
67+
esp_console_cmd_t gattccmd_set_client_cmd = {
68+
.command = GATTCMD_CMD_NAME,
69+
.help = "\nSet the client Address",
70+
.category = "BT",
71+
.hint = NULL,
72+
.func = &gattccmd_set_client,
73+
.argtable = &gattccmd_client_args};
74+
75+
esp_console_cmd_t gattccmd_write_cmd = {.command = "gattcmd_write",
76+
.help = "\nWrite to the GATT Address",
77+
.category = "BT",
78+
.hint = NULL,
79+
.func = &gattccmd_write,
80+
.argtable = &gattccmd_write_args};
81+
82+
esp_console_cmd_t gattcmd_connect_cmd = {.command = "gattcmd_connect",
83+
.help = "Connect to the BLE device",
84+
.category = "BT",
85+
.hint = NULL,
86+
.func = &gattccmd_connect,
87+
.argtable = NULL};
88+
89+
esp_console_cmd_t gattcmd_disconnect_cmd = {
90+
.command = "gattcmd_disconnect",
91+
.help = "Disconnect to the BLE device",
92+
.category = "BT",
93+
.hint = NULL,
94+
.func = &gattccmd_disconnect,
95+
.argtable = NULL};
96+
97+
ESP_ERROR_CHECK(esp_console_cmd_register(&gattccmd_set_client_cmd));
98+
ESP_ERROR_CHECK(esp_console_cmd_register(&gattcmd_connect_cmd));
99+
ESP_ERROR_CHECK(esp_console_cmd_register(&gattcmd_disconnect_cmd));
100+
ESP_ERROR_CHECK(esp_console_cmd_register(&gattccmd_write_cmd));
101+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifndef __GATTCMD_CMD_H
2+
#define __GATTCMD_CMD_H
3+
4+
void gattccmd_register_cmd();
5+
#endif

0 commit comments

Comments
 (0)