F´ Flight Software - C/C++ Documentation  NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
UartFramer.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title UartFramer.cpp
3 // \author tcanham
4 // \brief cpp file for UartFramer component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 
15 #include "Fw/Types/BasicTypes.hpp"
16 #include "Fw/Types/Assert.hpp"
17 
18 namespace Drv {
19 
20  // ----------------------------------------------------------------------
21  // Construction, initialization, and destruction
22  // ----------------------------------------------------------------------
23 
26  const char *const compName
27  ) : UartFramerComponentBase(compName), m_size(0)
28  {
29 
30  }
31 
32  void UartFramer ::
34  const NATIVE_INT_TYPE instance
35  )
36  {
37  UartFramerComponentBase::init(instance);
38  }
39 
42  {
43 
44  }
45 
47 
48  FW_ASSERT(size > 0, size);
49  this->m_size = size;
50 
51  Fw::Buffer buff;
52  // request a buffer and pass it on to the UART for each requested
53  for (NATIVE_UINT_TYPE buffNum = 0; buffNum < number; buffNum++) {
54  buff = this->DeframerAllocate_out(0,this->m_size);
55  FW_ASSERT(buff.getSize() == size,buff.getSize(),size);
56  FW_ASSERT(buff.getData());
57  this->readBufferSend_out(0,buff);
58  }
59 
60  }
61 
62  // ----------------------------------------------------------------------
63  // Handler implementations for user-defined typed input ports
64  // ----------------------------------------------------------------------
65 
66  Drv::SendStatus UartFramer ::
67  Framer_handler(
68  const NATIVE_INT_TYPE portNum,
69  Fw::Buffer &sendBuffer
70  )
71  {
72  this->serialSend_out(0,sendBuffer);
73  this->FramerDeallocate_out(0,sendBuffer);
74  // no status from send, so return OK
75  return Drv::SendStatus::SEND_OK;
76  }
77 
78  void UartFramer ::
79  serialRecv_handler(
80  const NATIVE_INT_TYPE portNum,
81  Fw::Buffer &serBuffer,
82  Drv::SerialReadStatus &status
83  )
84  {
85 
86  Drv::RecvStatus outStat = Drv::RecvStatus::RECV_OK;
87  // Check the UART status
88  if (status != Drv::SerialReadStatus::SER_OK) {
89  outStat = Drv::RecvStatus::RECV_ERROR;
90  }
91 
92  // Forward buffer to deframer
93  this->Deframer_out(0,serBuffer,outStat);
94 
95  // allocate a replacement buffer and send it to
96  // the UART driver
97  Fw::Buffer newBuff = this->DeframerAllocate_out(0,this->m_size);
98  if (newBuff.getSize() != this->m_size) {
99  this->log_WARNING_HI_BuffErr();
100  } else {
101  this->readBufferSend_out(0,newBuff);
102  }
103 
104  }
105 
106 } // end namespace Drv
Fw::Buffer::getData
U8 * getData() const
Definition: Buffer.cpp:60
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:28
Drv
Definition: BlockDriver.hpp:11
Drv::UartFramer::allocate
void allocate(NATIVE_UINT_TYPE number, NATIVE_UINT_TYPE size)
Allocate pool of buffers for UART receive - BufferManager and UART.
Definition: UartFramer.cpp:46
Fw::Buffer
Definition: Buffer.hpp:43
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:27
Fw::Buffer::getSize
U32 getSize() const
Definition: Buffer.cpp:64
Drv::UartFramer::~UartFramer
~UartFramer()
Definition: UartFramer.cpp:41
UartFramer.hpp
Drv::UartFramer::init
void init(const NATIVE_INT_TYPE instance=0)
Definition: UartFramer.cpp:33
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Drv::UartFramer::UartFramer
UartFramer(const char *const compName)
Definition: UartFramer.cpp:25