Cellular: Check if serial is supported

Baud rate can be only changed if BufferedSerial (or Serial in general) object is supported
pull/12804/head
Kimmo Vaisanen 2020-04-14 12:52:56 +03:00
parent 64bc9d9dd7
commit 214df550c0
2 changed files with 14 additions and 2 deletions

View File

@ -598,7 +598,10 @@ nsapi_error_t AT_CellularDevice::clear()
nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate)
{
nsapi_error_t error = set_baud_rate_impl(baud_rate);
nsapi_error_t error;
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN)
error = set_baud_rate_impl(baud_rate);
if (error) {
tr_warning("Baudrate was not changed to desired value: %d", baud_rate);
@ -609,6 +612,12 @@ nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate)
// Give some time before starting using the UART with the new baud rate
rtos::ThisThread::sleep_for(3000);
#else
// Currently ATHandler only supports BufferedSerial based communication and
// if serial is disabled, baud rate cannot be set
tr_warn("set_baud_rate: Serial not supported");
error = NSAPI_ERROR_UNSUPPORTED;
#endif
return error;
}

View File

@ -1545,6 +1545,9 @@ void ATHandler::write_hex_string(const char *str, size_t size)
void ATHandler::set_baud(int baud_rate)
{
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN)
static_cast<BufferedSerial *>(_fileHandle)->set_baud(baud_rate);
#else
tr_error("Device does not support BufferedSerial");
#endif
}