mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-03 20:54:18 +00:00
extracted cli stdin usage
This commit is contained in:
parent
8f74874871
commit
2e62db4a2a
@ -68,11 +68,9 @@ EXAMPLES = \
|
||||
spp_and_le_counter \
|
||||
spp_counter \
|
||||
spp_streamer \
|
||||
hsp_ag_test \
|
||||
hsp_hs_test \
|
||||
|
||||
# requires termios / command line support
|
||||
EXAMPLES_CLI = ble_peripheral ble_peripheral_sm_minimal l2cap_test ancs_client classic_test bnep_test
|
||||
EXAMPLES_CLI = ble_peripheral ble_peripheral_sm_minimal ble_central_test l2cap_test ancs_client classic_test bnep_test hsp_ag_test hsp_hs_test
|
||||
|
||||
# .o for .c
|
||||
CORE_OBJ = $(CORE:.c=.o)
|
||||
@ -131,6 +129,32 @@ gap_inquiry_and_bond: ${CORE_OBJ} ${COMMON_OBJ} gap_inquiry_and_bond.c
|
||||
panu_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} panu_demo.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
gatt_browser: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${SM_REAL_OBJ} gatt_browser.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
gatt_battery_query: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${SM_REAL_OBJ} gatt_battery_query.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
ancs_client: ancs_client.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${GATT_CLIENT_OBJ} ${SM_REAL_OBJ} ${BTSTACK_ROOT}/ble/ancs_client_lib.c ancs_client.c
|
||||
${CC} $(filter-out ancs_client.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
|
||||
# CLI Examples
|
||||
ble_peripheral: profile.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_REAL_OBJ} ble_peripheral.o
|
||||
${CC} $(filter-out profile.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
ble_peripheral_sm_minimal: profile.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_MINIMAL_OBJ} ble_peripheral.c
|
||||
${CC} $(filter-out profile.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
ble_central_test: ${CORE_OBJ} ${COMMON_OBJ} ${SM_REAL_OBJ} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ble_central_test.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
hsp_ag_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_ag.o hsp_ag_test.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
hsp_hs_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_hs.o hsp_hs_test.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
l2cap_test: ${CORE_OBJ} ${COMMON_OBJ} l2cap_test.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
@ -143,26 +167,6 @@ bnep_test: ${CORE_OBJ} ${COMMON_OBJ} bnep_test.c
|
||||
ble_client: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${SM_REAL} ble_client.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
gatt_browser: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${SM_REAL_OBJ} gatt_browser.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
gatt_battery_query: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${SM_REAL_OBJ} gatt_battery_query.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
ancs_client: ancs_client.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${GATT_CLIENT_OBJ} ${SM_REAL_OBJ} ${BTSTACK_ROOT}/ble/ancs_client_lib.c ancs_client.c
|
||||
${CC} $(filter-out ancs_client.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
ble_peripheral: profile.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_REAL_OBJ} ble_peripheral.o
|
||||
${CC} $(filter-out profile.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
ble_peripheral_sm_minimal: profile.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_MINIMAL_OBJ} ble_peripheral.c
|
||||
${CC} $(filter-out profile.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
hsp_ag_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_ag.o hsp_ag_test.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
hsp_hs_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_hs.o hsp_hs_test.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
clean:
|
||||
rm -f ${EXAMPLES}
|
||||
|
@ -64,7 +64,8 @@
|
||||
#include "att_server.h"
|
||||
#include "gap_le.h"
|
||||
#include "le_device_db.h"
|
||||
|
||||
#include "stdin_support.h"
|
||||
|
||||
#define HEARTBEAT_PERIOD_MS 1000
|
||||
|
||||
// test profile
|
||||
@ -927,24 +928,6 @@ static int get_oob_data_callback(uint8_t addres_type, bd_addr_t addr, uint8_t *
|
||||
return 1;
|
||||
}
|
||||
|
||||
static data_source_t stdin_source;
|
||||
void setup_cli(){
|
||||
|
||||
struct termios term = {0};
|
||||
if (tcgetattr(0, &term) < 0)
|
||||
perror("tcsetattr()");
|
||||
term.c_lflag &= ~ICANON;
|
||||
term.c_lflag &= ~ECHO;
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
perror("tcsetattr ICANON");
|
||||
|
||||
stdin_source.fd = 0; // stdin
|
||||
stdin_source.process = &stdin_process;
|
||||
run_loop_add_data_source(&stdin_source);
|
||||
}
|
||||
|
||||
#if defined(HAVE_UART_CSR) || defined(HAVE_UART_CC256x)
|
||||
static hci_uart_config_t hci_uart_config = {
|
||||
// "/dev/tty.usbserial-A40081HW",
|
||||
@ -983,7 +966,7 @@ int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
att_dump_attributes();
|
||||
|
||||
setup_cli();
|
||||
btstack_stdin_setup(stdin_process);
|
||||
|
||||
gap_random_address_set_update_period(300000);
|
||||
gap_random_address_set_mode(GAP_RANDOM_ADDRESS_RESOLVABLE);
|
||||
|
@ -66,6 +66,7 @@
|
||||
#include "hci_dump.h"
|
||||
#include "l2cap.h"
|
||||
#include "pan.h"
|
||||
#include "stdin_support.h"
|
||||
|
||||
// prototypes
|
||||
static void show_usage();
|
||||
@ -73,7 +74,7 @@ static void show_usage();
|
||||
// Configuration for PTS
|
||||
static bd_addr_t pts_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
|
||||
//static bd_addr_t pts_addr = {0xE0,0x06,0xE6,0xBB,0x95,0x79}; // Ole Thinkpad
|
||||
// static bd_addr_t other_addr = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
|
||||
// static bd_addr_t other_addr = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x16};
|
||||
static bd_addr_t other_addr = { 0,0,0,0,0,0};
|
||||
// broadcast
|
||||
static bd_addr_t broadcast_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
@ -100,9 +101,6 @@ static uint16_t bnep_cid = 0;
|
||||
static uint8_t network_buffer[BNEP_MTU_MIN];
|
||||
static size_t network_buffer_len = 0;
|
||||
|
||||
/** Testig User Interface **/
|
||||
static data_source_t stdin_source;
|
||||
|
||||
static uint16_t setup_ethernet_header(int src_compressed, int dst_compressed, int broadcast, uint16_t network_protocol_type){
|
||||
// setup packet
|
||||
int pos = 0;
|
||||
@ -188,6 +186,8 @@ static void send_arp_probe_ipv4(){
|
||||
pos += 6;
|
||||
memcpy(&network_buffer[pos], requested_address, 4);
|
||||
pos += 4;
|
||||
// magically, add some extra bytes for Ethernet padding
|
||||
pos += 18;
|
||||
send_buffer(pos);
|
||||
}
|
||||
|
||||
@ -207,6 +207,43 @@ static void send_dns_request(){
|
||||
|
||||
}
|
||||
|
||||
static void send_some_ipv6_packet(){
|
||||
|
||||
bd_addr_t an_addr = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x16};
|
||||
memcpy(other_addr, an_addr, 6);
|
||||
|
||||
int pos = setup_ethernet_header(1, 0, 0, 0x86DD); // IPv6
|
||||
uint8_t ipv6_packet[] = {
|
||||
0x60, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x02,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x16, 0x3a, 0x00, 0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x8f, 0x00, 0xf3, 0xa2,
|
||||
0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x60, 0x7b, 0x87
|
||||
};
|
||||
memcpy(&network_buffer[pos], ipv6_packet, sizeof(ipv6_packet));
|
||||
pos += sizeof(ipv6_packet);
|
||||
send_buffer(pos);
|
||||
}
|
||||
|
||||
static void send_some_ipv6_packet_2(){
|
||||
|
||||
bd_addr_t an_addr = { 0x33, 0x33, 0xFF, 0x60, 0x7B, 0x87};
|
||||
memcpy(other_addr, an_addr, 6);
|
||||
|
||||
int pos = setup_ethernet_header(1, 0, 0, 0x86DD); // IPv6
|
||||
uint8_t ipv6_packet[] = {
|
||||
0x60, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3a, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x02,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x60, 0x7b,
|
||||
0x87, 0x87, 0x00, 0xb6, 0x64, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x80, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x5e, 0xf3, 0x70, 0xff, 0xfe, 0x60, 0x7b, 0x87
|
||||
};
|
||||
memcpy(&network_buffer[pos], ipv6_packet, sizeof(ipv6_packet));
|
||||
pos += sizeof(ipv6_packet);
|
||||
send_buffer(pos);
|
||||
}
|
||||
|
||||
static void show_usage(){
|
||||
|
||||
printf("\n--- Bluetooth BNEP Test Console ---\n");
|
||||
@ -224,6 +261,8 @@ static void show_usage(){
|
||||
printf("2 - send DNS request\n");
|
||||
printf("4 - send IPv4 ARP request\n");
|
||||
printf("6 - send IPv6 ARP request\n");
|
||||
printf("9 - send some IPv6 packet\n");
|
||||
printf("0 - send some IPv6 packet 2\n");
|
||||
printf("---\n");
|
||||
printf("Ctrl-c - exit\n");
|
||||
printf("---\n");
|
||||
@ -270,6 +309,14 @@ static int stdin_process(struct data_source *ds){
|
||||
printf("Sending IPv6 ARP Probe\n");
|
||||
send_arp_probe_ipv6();
|
||||
break;
|
||||
case '9':
|
||||
printf("Sending some IPv6 packet\n");
|
||||
send_some_ipv6_packet();
|
||||
break;
|
||||
case '0':
|
||||
printf("Sending some IPv6 packet 2\n");
|
||||
send_some_ipv6_packet_2();
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
break;
|
||||
@ -278,25 +325,6 @@ static int stdin_process(struct data_source *ds){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_cli(){
|
||||
|
||||
struct termios term = {0};
|
||||
if (tcgetattr(0, &term) < 0)
|
||||
perror("tcsetattr()");
|
||||
term.c_lflag &= ~ICANON;
|
||||
term.c_lflag &= ~ECHO;
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
perror("tcsetattr ICANON");
|
||||
|
||||
stdin_source.fd = 0; // stdin
|
||||
stdin_source.process = &stdin_process;
|
||||
run_loop_add_data_source(&stdin_source);
|
||||
|
||||
show_usage();
|
||||
}
|
||||
|
||||
/*************** PANU client routines *********************/
|
||||
|
||||
static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
|
||||
@ -397,7 +425,7 @@ int btstack_main(int argc, const char * argv[]){
|
||||
/* Turn on the device */
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
setup_cli();
|
||||
btstack_stdin_setup(stdin_process);
|
||||
|
||||
/* Start mainloop */
|
||||
run_loop_execute();
|
||||
|
@ -63,6 +63,7 @@
|
||||
#include "sdp.h"
|
||||
#include "sdp_query_rfcomm.h"
|
||||
#include "sm.h"
|
||||
#include "stdin_support.h"
|
||||
|
||||
void show_usage();
|
||||
|
||||
@ -777,25 +778,6 @@ void sdp_create_dummy_service(uint8_t *service, const char *name){
|
||||
de_add_data(service, DE_STRING, strlen(name), (uint8_t *) name);
|
||||
}
|
||||
|
||||
|
||||
static data_source_t stdin_source;
|
||||
void setup_cli(){
|
||||
|
||||
struct termios term = {0};
|
||||
if (tcgetattr(0, &term) < 0)
|
||||
perror("tcsetattr()");
|
||||
term.c_lflag &= ~ICANON;
|
||||
term.c_lflag &= ~ECHO;
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
perror("tcsetattr ICANON");
|
||||
|
||||
stdin_source.fd = 0; // stdin
|
||||
stdin_source.process = &stdin_process;
|
||||
run_loop_add_data_source(&stdin_source);
|
||||
}
|
||||
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
@ -838,7 +820,7 @@ int btstack_main(int argc, const char * argv[]){
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
setup_cli();
|
||||
btstack_stdin_setup(stdin_process);
|
||||
|
||||
// set one-shot timer
|
||||
// timer_source_t heartbeat;
|
||||
|
@ -65,7 +65,8 @@
|
||||
#include "sdp.h"
|
||||
#include "debug.h"
|
||||
#include "hsp_ag.h"
|
||||
|
||||
#include "stdin_support.h"
|
||||
|
||||
static uint8_t hsp_service_buffer[150];
|
||||
static uint8_t rfcomm_channel_nr = 1;
|
||||
|
||||
@ -77,10 +78,6 @@ static char hs_cmd_buffer[100];
|
||||
// prototypes
|
||||
static void show_usage();
|
||||
|
||||
|
||||
// Testig User Interface
|
||||
static data_source_t stdin_source;
|
||||
|
||||
static void show_usage(){
|
||||
printf("\n--- Bluetooth HSP AudioGateway Test Console ---\n");
|
||||
printf("---\n");
|
||||
@ -152,24 +149,6 @@ static int stdin_process(struct data_source *ds){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_cli(){
|
||||
struct termios term = {0};
|
||||
if (tcgetattr(0, &term) < 0)
|
||||
perror("tcsetattr()");
|
||||
term.c_lflag &= ~ICANON;
|
||||
term.c_lflag &= ~ECHO;
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
perror("tcsetattr ICANON");
|
||||
|
||||
stdin_source.fd = 0; // stdin
|
||||
stdin_source.process = &stdin_process;
|
||||
run_loop_add_data_source(&stdin_source);
|
||||
|
||||
show_usage();
|
||||
}
|
||||
|
||||
// Audio Gateway routines
|
||||
void packet_handler(uint8_t * event, uint16_t event_size){
|
||||
switch (event[2]) {
|
||||
@ -219,7 +198,8 @@ int btstack_main(int argc, const char * argv[]){
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
setup_cli();
|
||||
btstack_stdin_setup(stdin_process);
|
||||
|
||||
// go!
|
||||
run_loop_execute();
|
||||
return 0;
|
||||
|
@ -59,7 +59,8 @@
|
||||
#include "btstack_memory.h"
|
||||
#include "hci_dump.h"
|
||||
#include "l2cap.h"
|
||||
|
||||
#include "stdin_support.h"
|
||||
|
||||
void show_usage();
|
||||
|
||||
// static bd_addr_t remote = {0x04,0x0C,0xCE,0xE4,0x85,0xD3};
|
||||
@ -154,23 +155,6 @@ int stdin_process(struct data_source *ds){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static data_source_t stdin_source;
|
||||
void setup_cli(){
|
||||
|
||||
struct termios term = {0};
|
||||
if (tcgetattr(0, &term) < 0)
|
||||
perror("tcsetattr()");
|
||||
term.c_lflag &= ~ICANON;
|
||||
term.c_lflag &= ~ECHO;
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
perror("tcsetattr ICANON");
|
||||
|
||||
stdin_source.fd = 0; // stdin
|
||||
stdin_source.process = &stdin_process;
|
||||
run_loop_add_data_source(&stdin_source);
|
||||
}
|
||||
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
@ -185,7 +169,7 @@ int btstack_main(int argc, const char * argv[]){
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
setup_cli();
|
||||
btstack_stdin_setup(stdin_process);
|
||||
run_loop_execute();
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
BTSTACK_ROOT = ../..
|
||||
POSIX_ROOT= ${BTSTACK_ROOT}/platforms/posix
|
||||
|
||||
CORE += main.c
|
||||
CORE += main.c stdin_support.c
|
||||
|
||||
COMMON += hci_transport_h2_libusb.c run_loop_posix.c remote_device_db_fs.c
|
||||
|
||||
|
||||
@ -24,9 +25,10 @@ CFLAGS += $(shell pkg-config libusb-1.0 --cflags)
|
||||
LDFLAGS += $(shell pkg-config libusb-1.0 --libs)
|
||||
endif
|
||||
|
||||
# Command Line examples require porting to win32, so only build on other = unix-ish hosts
|
||||
# Command Line examples require porting to win32, so only build on other unix-ish hosts
|
||||
ifneq ($(OS),Windows_NT)
|
||||
EXAMPLES += ${EXAMPLES_CLI}
|
||||
CFLAGS += -I${POSIX_ROOT}/src
|
||||
endif
|
||||
|
||||
EXAMPLES += sam3u_benchmark
|
||||
|
@ -55,10 +55,17 @@
|
||||
#include "btstack_memory.h"
|
||||
#include "hci.h"
|
||||
#include "hci_dump.h"
|
||||
#include "stdin_support.h"
|
||||
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
|
||||
static void sigint_handler(int param){
|
||||
|
||||
#ifndef _WIN32
|
||||
// reset anyway
|
||||
btstack_stdin_reset();
|
||||
#endif
|
||||
|
||||
log_info(" <= SIGINT received, shutting down..\n");
|
||||
hci_power_control(HCI_POWER_OFF);
|
||||
hci_close();
|
||||
@ -87,6 +94,6 @@ int main(int argc, const char * argv[]){
|
||||
signal(SIGINT, sigint_handler);
|
||||
|
||||
btstack_main(argc, argv);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user