You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

79 lines
2.0 KiB

/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
/****************************************************************************
*
* This file is for ble spp client demo.
*
****************************************************************************/
#include "ble_spp_client_demo.h"
#include "key.h"
#include "driver/uart.h"
#define buffer_size 1024
static uint8_t rx_data_buffer[256];
int length = 0;
void motor_drive_hex_to_str(char *hex, int hex_len, char *str);
void pc_uart_init(uart_port_t uart_num, int tx_io_num, int rx_io_num)
{
uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_APB,
};
ESP_ERROR_CHECK(uart_driver_install(uart_num, buffer_size * 2, 0, 0, NULL, 0));
ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(uart_num, tx_io_num, rx_io_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
}
void pc_uart_receive(uart_port_t uart_num)
{
ESP_ERROR_CHECK(uart_get_buffered_data_len(uart_num, (size_t *)&length));
if (length != 0)
{
length = uart_read_bytes(uart_num, rx_data_buffer, length, 100);
ble_gattc_write_char((char *)rx_data_buffer, length);
}
}
void app_main(void)
{
ble_init();
key_init();
key_ble_send_cmd_reg(ble_gattc_write_char);
pc_uart_init(UART_NUM_2, 18, 23);
while (true)
{
key_schedule();
pc_uart_receive(UART_NUM_2);
}
}
void motor_drive_hex_to_str(char *hex, int hex_len, char *str)
{
int i, pos = 0;
for (i = (hex_len - 1); i >= 0; i--)
{
sprintf(str + pos, "%02x", hex[i]);
pos += 2;
}
}