34 m_device(
"NOT_EXIST"),
37 m_quitReadThread(false) {}
47 this->m_allocationSize = allocationSize;
49 this->m_device = device;
57 fd =
::open(device, O_RDWR | O_NOCTTY);
69 stat = tcgetattr(fd, &cfg);
96 stat = tcsetattr(fd, TCSANOW, &cfg);
109 stat = tcgetattr(fd, &t);
119 t.c_cflag |= CRTSCTS;
121 stat = tcsetattr(fd, TCSANOW, &t);
163 relayRate = B1000000;
168 relayRate = B1152000;
173 relayRate = B1500000;
178 relayRate = B2000000;
183 relayRate = B2500000;
188 relayRate = B3000000;
193 relayRate = B3500000;
198 relayRate = B4000000;
202 FW_ASSERT(
false, static_cast<FwAssertArgType>(baud));
206 struct termios newtio;
208 stat = tcgetattr(fd, &newtio);
232 newtio.c_cflag |= CS8 | CLOCAL | CREAD;
236 newtio.c_cflag |= (PARENB | PARODD);
239 newtio.c_cflag |= PARENB;
242 newtio.c_cflag &=
static_cast<unsigned int>(~PARENB);
250 stat = cfsetispeed(&newtio, static_cast<speed_t>(relayRate));
258 stat = cfsetospeed(&newtio, static_cast<speed_t>(relayRate));
273 newtio.c_iflag = INPCK;
276 (void)tcflush(fd, TCIFLUSH);
279 stat = tcsetattr(fd, TCSANOW, &newtio);
299 if (this->m_fd != -1) {
300 (void)close(this->m_fd);
308 void LinuxUartDriver ::run_handler(
FwIndexType portNum, U32 context) {
315 if (this->m_fd == -1 || serBuffer.
getData() ==
nullptr || serBuffer.
getSize() == 0) {
318 unsigned char* data = serBuffer.
getData();
320 size_t xferSize =
static_cast<size_t>(serBuffer.
getSize());
322 ssize_t stat = ::write(this->m_fd, data, xferSize);
324 if (-1 == stat || static_cast<size_t>(stat) != xferSize) {
329 this->m_bytesSent +=
static_cast<FwSizeType>(stat);
339 void LinuxUartDriver ::serialReadTaskEntry(
void* ptr) {
344 while (!comp->m_quitReadThread) {
345 Fw::Buffer buff = comp->allocate_out(0, comp->m_allocationSize);
348 if (buff.
getData() ==
nullptr) {
350 comp->log_WARNING_HI_NoBuffers(_arg);
352 comp->recv_out(0, buff, status);
364 while ((stat == 0) && !comp->m_quitReadThread) {
365 stat =
static_cast<int>(::read(comp->m_fd, buff.
getData(),
static_cast<size_t>(buff.
getSize())));
374 comp->log_WARNING_HI_ReadError(_arg, stat);
376 }
else if (stat > 0) {
377 buff.
setSize(static_cast<U32>(stat));
379 comp->m_bytesReceived +=
static_cast<FwSizeType>(stat);
384 comp->recv_out(0, buff, status);
392 Os::Task::Arguments arguments(task, serialReadTaskEntry,
this, priority, stackSize, cpuAffinity);
398 this->m_quitReadThread =
true;
402 return m_readTask.
join();
void ready_out(FwIndexType portNum) const
Invoke output port ready.
PlatformSizeType FwSizeType
void setSize(FwSizeType size)
void tlmWrite_BytesRecv(FwSizeType arg, Fw::Time _tlmTime=Fw::Time()) const
bool isConnected_ready_OutputPort(FwIndexType portNum) const
Status start(const Arguments &arguments) override
start the task
Error occurred, retrying may succeed.
Auto-generated base for LinuxUartDriver component.
void log_WARNING_HI_WriteError(const Fw::StringBase &device, I32 error)
void start(FwTaskPriorityType priority=Os::Task::TASK_PRIORITY_DEFAULT, Os::Task::ParamType stackSize=Os::Task::TASK_DEFAULT, Os::Task::ParamType cpuAffinity=Os::Task::TASK_DEFAULT)
bool open(const char *const device, UartBaudRate baud, UartFlowControl fc, UartParity parity, FwSizeType allocationSize)
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer) const
Invoke output port deallocate.
Status returned by the send call.
message sent/received okay
Status join() override
block until the task has ended
Operation worked as expected.
void quitReadThread()
Quit thread.
void log_WARNING_HI_OpenError(const Fw::StringBase &device, I32 error, const Fw::StringBase &name) const
void log_ACTIVITY_HI_PortOpened(const Fw::StringBase &device) const
PlatformTaskPriorityType FwTaskPriorityType
The type of task priorities used.
FwSizeType ParamType
backwards-compatible parameter type
LinuxUartDriver(const char *const compName)
FwSizeType getSize() const
UartBaudRate
Configure UART parameters.
PlatformIndexType FwIndexType
#define FW_ASSERT_NO_OVERFLOW(value, T)
C++ header for working with basic fprime types.
static Status delay(const Fw::TimeInterval &interval)
delay the current task
void tlmWrite_BytesSent(FwSizeType arg, Fw::Time _tlmTime=Fw::Time()) const
Os::Task::Status join()
Join thread.