Commit e929c8ad authored by Bjørn Inge Hanssen's avatar Bjørn Inge Hanssen Committed by GitHub
Browse files

Merge pull request #53 from NordicSemiconductor/feature/baudrate

Add optional command line argument for specifying baud rate
parents a231a287 54084b3c
......@@ -26,16 +26,16 @@
#include <string.h>
#ifdef _WIN32
#define UART_PORT_NAME "COM1"
#define BAUD_RATE 1000000 /**< The baud rate to be used for serial communication with nRF5 device. */
#define DEFAULT_UART_PORT_NAME "COM1"
#define DEFAULT_BAUD_RATE 1000000 /**< The baud rate to be used for serial communication with nRF5 device. */
#endif
#ifdef __APPLE__
#define UART_PORT_NAME "/dev/tty.usbmodem00000"
#define BAUD_RATE 115200 /* 1M baud rate is not supported on MacOS */
#define DEFAULT_UART_PORT_NAME "/dev/tty.usbmodem00000"
#define DEFAULT_BAUD_RATE 115200 /* 1M baud rate is not supported on MacOS */
#endif
#ifdef __linux__
#define UART_PORT_NAME "/dev/ttyACM0"
#define BAUD_RATE 1000000
#define DEFAULT_UART_PORT_NAME "/dev/ttyACM0"
#define DEFAULT_BAUD_RATE 1000000
#endif
......@@ -470,13 +470,13 @@ static void on_exchange_mtu_response(const ble_gattc_evt_t * const p_ble_gattc_e
*
* @return The new transport adapter.
*/
static adapter_t * adapter_init(char * serial_port)
static adapter_t * adapter_init(char * serial_port, uint32_t baud_rate)
{
physical_layer_t * phy;
data_link_layer_t * data_link_layer;
transport_layer_t * transport_layer;
phy = sd_rpc_physical_layer_create_uart(serial_port, BAUD_RATE, SD_RPC_FLOW_CONTROL_NONE,
phy = sd_rpc_physical_layer_create_uart(serial_port, baud_rate, SD_RPC_FLOW_CONTROL_NONE,
SD_RPC_PARITY_NONE);
data_link_layer = sd_rpc_data_link_layer_create_bt_three_wire(phy, 100);
transport_layer = sd_rpc_transport_layer_create(data_link_layer, 100);
......@@ -895,27 +895,42 @@ static void ble_evt_dispatch(adapter_t * adapter, ble_evt_t * p_ble_evt)
/**@brief Function for application main entry.
*
* @param[in] argc Number of arguments (program expects 0 or 1 arguments).
* @param[in] argv The serial port of the target nRF5 device (Optional).
* @param[in] argv The serial port and baud rate of the target nRF5 device (Optional).
*/
int main(int argc, char * argv[])
{
uint32_t error_code;
char * serial_port;
char * serial_port = DEFAULT_UART_PORT_NAME;
uint32_t baud_rate = DEFAULT_BAUD_RATE;
uint8_t cccd_value = 0;
if (argc > 1)
if (argc > 2)
{
serial_port = argv[1];
if (strcmp(argv[2], "1000000") == 0)
{
baud_rate = 1000000;
}
else if (strcmp(argv[2], "115200") == 0)
{
baud_rate = 115200;
}
else
{
printf("Supported baud rate values are: 115200, 1000000\n");
fflush(stdout);
}
}
else
if (argc > 1)
{
serial_port = UART_PORT_NAME;
serial_port = argv[1];
}
printf("Serial port used: %s\n", serial_port);
printf("Baud rate used: %d\n", baud_rate);
fflush(stdout);
m_adapter = adapter_init(serial_port);
m_adapter = adapter_init(serial_port, baud_rate);
sd_rpc_log_handler_severity_filter_set(m_adapter, SD_RPC_LOG_INFO);
error_code = sd_rpc_open(m_adapter, status_handler, ble_evt_dispatch, log_handler);
......
......@@ -34,16 +34,16 @@
#endif
#ifdef _WIN32
#define UART_PORT_NAME "COM1"
#define BAUD_RATE 1000000 /**< The baud rate to be used for serial communication with nRF5 device. */
#define DEFAULT_UART_PORT_NAME "COM1"
#define DEFAULT_BAUD_RATE 1000000 /**< The baud rate to be used for serial communication with nRF5 device. */
#endif
#ifdef __APPLE__
#define UART_PORT_NAME "/dev/tty.usbmodem00000"
#define BAUD_RATE 115200 /* 1M baud rate is not supported on MacOS */
#define DEFAULT_UART_PORT_NAME "/dev/tty.usbmodem00000"
#define DEFAULT_BAUD_RATE 115200 /* 1M baud rate is not supported on MacOS */
#endif
#ifdef __linux__
#define UART_PORT_NAME "/dev/ttyACM0"
#define BAUD_RATE 1000000
#define DEFAULT_UART_PORT_NAME "/dev/ttyACM0"
#define DEFAULT_BAUD_RATE 1000000
#endif
#define ADVERTISING_INTERVAL_40_MS 64 /**< 0.625 ms = 40 ms */
......@@ -231,13 +231,13 @@ static void ble_evt_dispatch(adapter_t * adapter, ble_evt_t * p_ble_evt)
*
* @return The new transport adapter.
*/
static adapter_t * adapter_init(char * serial_port)
static adapter_t * adapter_init(char * serial_port, uint32_t baud_rate)
{
physical_layer_t * phy;
data_link_layer_t * data_link_layer;
transport_layer_t * transport_layer;
phy = sd_rpc_physical_layer_create_uart(serial_port, BAUD_RATE, SD_RPC_FLOW_CONTROL_NONE,
phy = sd_rpc_physical_layer_create_uart(serial_port, baud_rate, SD_RPC_FLOW_CONTROL_NONE,
SD_RPC_PARITY_NONE);
data_link_layer = sd_rpc_data_link_layer_create_bt_three_wire(phy, 100);
transport_layer = sd_rpc_transport_layer_create(data_link_layer, 100);
......@@ -589,26 +589,42 @@ static uint32_t heart_rate_measurement_send()
/**@brief Function for application main entry.
*
* @param[in] argc Number of arguments (program expects 0 or 1 arguments).
* @param[in] argv The serial port of the target nRF5 device (Optional).
* @param[in] argv The serial port and baud rate of the target nRF5 device (Optional).
*/
int main(int argc, char * argv[])
{
uint32_t error_code;
char * serial_port;
char * serial_port = DEFAULT_UART_PORT_NAME;
uint32_t baud_rate = DEFAULT_BAUD_RATE;
uint8_t cccd_value = 0;
if (argc > 1)
if (argc > 2)
{
serial_port = argv[1];
if (strcmp(argv[2], "1000000") == 0)
{
baud_rate = 1000000;
}
else if (strcmp(argv[2], "115200") == 0)
{
baud_rate = 115200;
}
else
{
printf("Supported baud rate values are: 115200, 1000000\n");
fflush(stdout);
}
}
else
if (argc > 1)
{
serial_port = UART_PORT_NAME;
serial_port = argv[1];
}
printf("Serial port used: %s\n", serial_port);
printf("Baud rate used: %d\n", baud_rate);
fflush(stdout);
m_adapter = adapter_init(serial_port);
m_adapter = adapter_init(serial_port, baud_rate);
sd_rpc_log_handler_severity_filter_set(m_adapter, SD_RPC_LOG_INFO);
error_code = sd_rpc_open(m_adapter, status_handler, ble_evt_dispatch, log_handler);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment