Compare commits
6 Commits
2e243e3b29
...
meier/uart
Author | SHA1 | Date | |
---|---|---|---|
ecc445afa7 | |||
88769bb46c | |||
9c98f41a96 | |||
323008c64a | |||
866868b25f | |||
8ff09c95a6 |
@ -79,6 +79,7 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
||||
setStopBitOptions(&options, uartCookie);
|
||||
setDatasizeOptions(&options, uartCookie);
|
||||
setFixedOptions(&options);
|
||||
setUartMode(&options, *uartCookie);
|
||||
if(uartCookie->getInputShouldBeFlushed()) {
|
||||
tcflush(fd, TCIFLUSH);
|
||||
}
|
||||
@ -403,13 +404,13 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDevi
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
else if (bytesRead != static_cast<int>(requestLen)) {
|
||||
sif::debug << "UartComIF::requestReceiveMessage: Only read " << bytesRead <<
|
||||
if(uartCookie.isReplySizeFixed()) {
|
||||
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead <<
|
||||
" of " << requestLen << " bytes" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
else {
|
||||
iter->second.replyLen = bytesRead;
|
||||
}
|
||||
iter->second.replyLen = bytesRead;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -442,6 +443,51 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie,
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
|
||||
std::string deviceFile;
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if(uartCookie == nullptr) {
|
||||
sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl;
|
||||
return NULLPOINTER;
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCIFLUSH);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
|
||||
std::string deviceFile;
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if(uartCookie == nullptr) {
|
||||
sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl;
|
||||
return NULLPOINTER;
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCOFLUSH);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
|
||||
std::string deviceFile;
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if(uartCookie == nullptr) {
|
||||
sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl;
|
||||
return NULLPOINTER;
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCIOFLUSH);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) {
|
||||
UartModes uartMode = uartCookie.getUartMode();
|
||||
if(uartMode == UartModes::NON_CANONICAL) {
|
||||
|
@ -41,6 +41,21 @@ public:
|
||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||
size_t *size) override;
|
||||
|
||||
/**
|
||||
* @brief This function discards all data received but not read in the UART buffer.
|
||||
*/
|
||||
ReturnValue_t flushUartRxBuffer(CookieIF *cookie);
|
||||
|
||||
/**
|
||||
* @brief This function discards all data in the transmit buffer of the UART driver.
|
||||
*/
|
||||
ReturnValue_t flushUartTxBuffer(CookieIF *cookie);
|
||||
|
||||
/**
|
||||
* @brief This function discards both data in the transmit and receive buffer of the UART.
|
||||
*/
|
||||
ReturnValue_t flushUartTxAndRxBuf(CookieIF *cookie);
|
||||
|
||||
private:
|
||||
|
||||
using UartDeviceFile_t = std::string;
|
||||
|
@ -87,3 +87,11 @@ bool UartCookie::getInputShouldBeFlushed() {
|
||||
object_id_t UartCookie::getHandlerId() const {
|
||||
return this->handlerId;
|
||||
}
|
||||
|
||||
void UartCookie::setNoFixedSizeReply() {
|
||||
replySizeFixed = false;
|
||||
}
|
||||
|
||||
bool UartCookie::isReplySizeFixed() {
|
||||
return replySizeFixed;
|
||||
}
|
||||
|
@ -95,6 +95,14 @@ public:
|
||||
void setTwoStopBits();
|
||||
void setOneStopBit();
|
||||
|
||||
/**
|
||||
* Calling this function prevents the UartComIF to return failed if not all requested bytes
|
||||
* could be read. This is required by a device handler when the size of a reply is not known.
|
||||
*/
|
||||
void setNoFixedSizeReply();
|
||||
|
||||
bool isReplySizeFixed();
|
||||
|
||||
private:
|
||||
|
||||
const object_id_t handlerId;
|
||||
@ -107,6 +115,7 @@ private:
|
||||
uint8_t bitsPerWord = 8;
|
||||
uint8_t readCycles = 1;
|
||||
StopBits stopBits = StopBits::ONE_STOP_BIT;
|
||||
bool replySizeFixed = true;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user