diff --git a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp index 3c975735..f52b6b1e 100644 --- a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp +++ b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp @@ -453,9 +453,12 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) { } deviceFile = uartCookie->getDeviceFile(); uartDeviceMapIter = uartDeviceMap.find(deviceFile); - int fd = uartDeviceMapIter->second.fileDescriptor; - tcflush(fd, TCIFLUSH); - return RETURN_OK; + if(uartDeviceMapIter != uartDeviceMap.end()) { + int fd = uartDeviceMapIter->second.fileDescriptor; + tcflush(fd, TCIFLUSH); + return RETURN_OK; + } + return RETURN_FAILED; } ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) { @@ -468,9 +471,12 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) { } deviceFile = uartCookie->getDeviceFile(); uartDeviceMapIter = uartDeviceMap.find(deviceFile); - int fd = uartDeviceMapIter->second.fileDescriptor; - tcflush(fd, TCOFLUSH); - return RETURN_OK; + if(uartDeviceMapIter != uartDeviceMap.end()) { + int fd = uartDeviceMapIter->second.fileDescriptor; + tcflush(fd, TCOFLUSH); + return RETURN_OK; + } + return RETURN_FAILED; } ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) { @@ -483,9 +489,12 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) { } deviceFile = uartCookie->getDeviceFile(); uartDeviceMapIter = uartDeviceMap.find(deviceFile); - int fd = uartDeviceMapIter->second.fileDescriptor; - tcflush(fd, TCIOFLUSH); - return RETURN_OK; + if(uartDeviceMapIter != uartDeviceMap.end()) { + int fd = uartDeviceMapIter->second.fileDescriptor; + tcflush(fd, TCIOFLUSH); + return RETURN_OK; + } + return RETURN_FAILED; } void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) {