Skip to content

Adding set baud rate routine #11783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "unity/unity.h"
#include "utest.h"
#include "tcp_tests.h"
#include "CellularDevice.h"

using namespace utest::v1;

Expand Down Expand Up @@ -119,6 +120,11 @@ void rcv_n_chk_against_rfc864_pattern(TCPSocket &sock)
void TCPSOCKET_RECV_100K()
{
SKIP_IF_TCP_UNSUPPORTED();

#ifdef MBED_CONF_APP_BAUD_RATE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be modem specific config?

CellularDevice::get_default_instance()->set_baud_rate(MBED_CONF_APP_BAUD_RATE);
#endif

TCPSocket sock;
if (_tcpsocket_connect_to_chargen_srv(sock) != NSAPI_ERROR_OK) {
TEST_FAIL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ set(unittest-test-sources
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/us_ticker_stub.cpp
stubs/UARTSerial_stub.cpp
stubs/SerialBase_stub.cpp
stubs/mbed_assert_stub.c
stubs/mbed_poll_stub.cpp
stubs/Timer_stub.cpp
Expand Down
4 changes: 4 additions & 0 deletions UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,7 @@ void ATHandler::set_send_delay(uint16_t send_delay)
{
}

void ATHandler::set_baud(int baud_rate)
{
}

10 changes: 10 additions & 0 deletions UNITTESTS/stubs/AT_CellularDevice_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,13 @@ nsapi_error_t AT_CellularDevice::clear()
{
return NSAPI_ERROR_OK;
}

nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate)
{
return NSAPI_ERROR_OK;
}

nsapi_error_t AT_CellularDevice::set_baud_rate_impl(int baud_rate)
{
return NSAPI_ERROR_OK;
}
4 changes: 4 additions & 0 deletions UNITTESTS/target_h/myCellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ class myCellularDevice : public CellularDevice {
{
return NSAPI_ERROR_OK;
}
nsapi_error_t set_baud_rate(int baud_rate)
{
return NSAPI_ERROR_OK;
}

void verify_timeout_array(const uint16_t timeout[], int array_len)
{
Expand Down
7 changes: 7 additions & 0 deletions features/cellular/framework/API/CellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@ class CellularDevice {
*/
virtual nsapi_error_t release_at_handler(ATHandler *at_handler) = 0;

/** Sets cellular modem to given baud rate
*
* @param baud_rate
* @return NSAPI_ERROR_OK on success, NSAPI_ERROR_DEVICE_ERROR on failure
*/
virtual nsapi_error_t set_baud_rate(int baud_rate) = 0;

protected:
friend class AT_CellularNetwork;
friend class AT_CellularContext;
Expand Down
6 changes: 6 additions & 0 deletions features/cellular/framework/AT/ATHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,3 +1612,9 @@ void ATHandler::write_hex_string(char *str, size_t size)
write(hexbuf, 2);
}
}

void ATHandler::set_baud(int baud_rate)
{
static_cast<UARTSerial *>(_fileHandle)->set_baud(baud_rate);
}

8 changes: 8 additions & 0 deletions features/cellular/framework/AT/ATHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <cstdarg>

#include "UARTSerial.h"

/**
* If application calls associated FileHandle only from single thread context
* then locking between AT command and response is not needed. However,
Expand Down Expand Up @@ -219,6 +221,12 @@ class ATHandler {
*/
void set_send_delay(uint16_t send_delay);

/** Sets UARTSerial filehandle to given baud rate
*
* @param baud_rate
*/
void set_baud(int baud_rate);

protected:
void event();
#if defined AT_HANDLER_MUTEX && defined MBED_CONF_RTOS_PRESENT
Expand Down
22 changes: 22 additions & 0 deletions features/cellular/framework/AT/AT_CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,25 @@ nsapi_error_t AT_CellularDevice::clear()

return err;
}

nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate)
{
nsapi_error_t error = set_baud_rate_impl(baud_rate);

if (error) {
tr_warning("Baudrate was not changed to desired value: %d", baud_rate);
return error;
}

_at->set_baud(baud_rate);

// Give some time before starting using the UART with the new baud rate
rtos::ThisThread::sleep_for(3000);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could poll with an AT command to make it more responsive?


return error;
}

nsapi_error_t AT_CellularDevice::set_baud_rate_impl(int baud_rate)
{
return _at->at_cmd_discard("+IPR", "=", "%d", baud_rate);
}
3 changes: 3 additions & 0 deletions features/cellular/framework/AT/AT_CellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class AT_CellularDevice : public CellularDevice {

virtual CellularContext *get_context_list() const;

virtual nsapi_error_t set_baud_rate(int baud_rate);

AT_CellularNetwork *_network;
AT_CellularSMS *_sms;
AT_CellularInformation *_information;
Expand All @@ -153,6 +155,7 @@ class AT_CellularDevice : public CellularDevice {
// Sets up parameters for AT handler, for now only the send delay and URCs.
// This kind of routine is needed for initialisation routines that are virtual and therefore cannot be called from constructor.
void setup_at_handler();
virtual nsapi_error_t set_baud_rate_impl(int baud_rate);

private:
void urc_nw_deact();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ nsapi_error_t QUECTEL_BC95::init()
return _at->unlock_return_error();
}

nsapi_error_t QUECTEL_BC95::set_baud_rate_impl(int baud_rate)
{
return _at->at_cmd_discard("+NATSPEED", "=", "%d%d%d%d%d%d%d", baud_rate, 30, 0, 2, 1, 0, 0);
}

#if MBED_CONF_QUECTEL_BC95_PROVIDE_DEFAULT
#include "UARTSerial.h"
CellularDevice *CellularDevice::get_default_instance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class QUECTEL_BC95 : public AT_CellularDevice {
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
virtual AT_CellularInformation *open_information_impl(ATHandler &at);
virtual nsapi_error_t set_baud_rate_impl(int baud_rate);
virtual nsapi_error_t init();

public: // NetworkInterface
Expand Down