PAS CO2 Sensor  1.0.3
C++ library for Infineon Photoacoustic Spectroscopy (PAS) XENSIV™ CO2 miniaturized sensor
pasco2::UART Class Reference

#include <pas-co2-uart.hpp>

Inheritance diagram for pasco2::UART:
Collaboration diagram for pasco2::UART:

Public Member Functions

 UART (UARTPAL *const uartpal, uint32_t baudrateBps=dfltBaudrateBps)
 UART interface constructor. More...
 
 ~UART (void)
 UUART interface desconstructor. More...
 
Error_t init (void)
 Initializes the I2C interface. More...
 
Error_t deinit (void)
 Deinitializes the serial interface. More...
 
Error_t write (const uint8_t regAddr, const uint8_t *data, uint16_t length)
 Writes data to a register or set of consecutive registers. More...
 
Error_t read (const uint8_t regAddr, uint8_t *data, uint16_t length)
 Reads data from a register or set of consecutive registers. More...
 
Proto_t getProtocol (void)
 Gets the specific serial protocol. More...
 

Static Public Attributes

static const uint32_t dfltBaudrateBps = 9600
 

Protected Member Functions

char uint4ToHexChar (const uint8_t uint4)
 Converts an unsigned 4 bits integer to its hexadecimal ascii value. More...
 
virtual void assembleWriteRequestFrame (const uint8_t regAddr, const uint8_t regVal, char *frame)
 Assembles the register write request frame. More...
 
virtual void assembleReadRequestFrame (const uint8_t regAddr, char *frame)
 Assembles the register read request frame. More...
 
virtual uint8_t disassembleReadReplyFrame (const char *frame)
 Disassembles the read response frame. More...
 
virtual bool isAckFrame (const char *frame, const uint8_t len)
 Checks if a frame is an ack reply frame. More...
 
virtual bool isNackFrame (const char *frame, const uint8_t len)
 Checks if a frame is an nack reply frame. More...
 

Additional Inherited Members

- Public Types inherited from pasco2::SBus
enum  Proto_t { BUS_PROTO_I2C = 0, BUS_PROTO_UART = 1 }
 

Constructor & Destructor Documentation

◆ UART()

UART::UART ( UARTPAL *const  uartpal,
uint32_t  baudrateBps = dfltBaudrateBps 
)

UART interface constructor.

Parameters
[in]*uartpalUART pal interface
[in]baudrateBpsBaudrate in bit per second. Default 19200 bps. Valid Range [9600, 19200].
Precondition
None

◆ ~UART()

UART::~UART ( void  )

UUART interface desconstructor.

Precondition
None

Member Function Documentation

◆ init()

Error_t UART::init ( void  )
virtual

Initializes the I2C interface.

Initiliazes the host I2C peripheral and set its clock frequency

Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif hardware interface error
Precondition
None

Implements pasco2::SBus.

Here is the call graph for this function:

◆ deinit()

Error_t UART::deinit ( void  )
virtual

Deinitializes the serial interface.

Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif error

Implements pasco2::SBus.

Here is the call graph for this function:

◆ write()

Error_t UART::write ( const uint8_t  memAddr,
const uint8_t *  data,
uint16_t  length 
)
virtual

Writes data to a register or set of consecutive registers.

Parameters
[in]regAddrRegister start write address
[in]*dataPointer to the data array to be written
[in]lengthNumber of registers to be written in the bus
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif error
Precondition
init()

Implements pasco2::SBus.

Here is the call graph for this function:

◆ read()

Error_t UART::read ( const uint8_t  memAddr,
uint8_t *  data,
uint16_t  length 
)
virtual

Reads data from a register or set of consecutive registers.

Parameters
[in]regAddrRegister start read address
[out]*dataPointer to the array that will store the read data
[in]lengthNumber of registers to be read from the bus
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif error
Precondition
init()

Implements pasco2::SBus.

Here is the call graph for this function:

◆ getProtocol()

Proto_t pasco2::UART::getProtocol ( void  )
inlinevirtual

Gets the specific serial protocol.

Returns
PAS CO2 serial protocol
Return values
BUS_PROTO_I2C
BUS_PROTO_UART

Implements pasco2::SBus.

◆ uint4ToHexChar()

char UART::uint4ToHexChar ( const uint8_t  uint4)
protected

Converts an unsigned 4 bits integer to its hexadecimal ascii value.

Parameters
[in]uint4Unsigned 4 bits integer
Returns
hexadecimal ascii value (char)

◆ assembleWriteRequestFrame()

void UART::assembleWriteRequestFrame ( const uint8_t  regAddr,
const uint8_t  regVal,
char *  frame 
)
protectedvirtual

Assembles the register write request frame.

The UART write request frames have the following structure:

         "w," + <ascii hex 2 char register address> + "," +
           <ascii hex 2 char register value> "\n"

         For example, in order to write 0xE2 in the register 0x0A, the corresponding
         char string will be: "w,0a,e2\n". 
         Also uppercase ascii letters are allowed
Parameters
[in]regAddrRegister address
[in]regValRegister value to be written
[out]*framePointer to store the assembled write frame
Returns
void
Here is the call graph for this function:

◆ assembleReadRequestFrame()

void UART::assembleReadRequestFrame ( const uint8_t  regAddr,
char *  frame 
)
protectedvirtual

Assembles the register read request frame.

The UART read request frames have the following structure:

         "w," + <ascii hex 2 char register address> + "\n"

         For example, in order to read the register 0x0E, the corresponding
         char string will be: "r,0e\n". 
         Also uppercase ascii letters are allowed
Parameters
[in]regAddrRegister address to be read
[out]*framePointer to store the assembled read frame
Returns
void
Here is the call graph for this function:

◆ disassembleReadReplyFrame()

uint8_t UART::disassembleReadReplyFrame ( const char *  frame)
protectedvirtual

Disassembles the read response frame.

The UART read response frames have the following structure:

         <ascii hex 2 char register value> + "\n"

         For example, a register with value 0xAB will reply the 
         frame: "ab\n". 
         Also uppercase ascii letters are allowed
Parameters
[in]*framePointer to read response frame
Returns
register value as unsigned 8 bits integer (uint8_t)

◆ isAckFrame()

bool UART::isAckFrame ( const char *  frame,
const uint8_t  len 
)
protectedvirtual

Checks if a frame is an ack reply frame.

The UART ack response frame is formed by the ascii ack value (0x06) followed by a new line character ('
' or 0xA). As hexadecimal, the array {0x06, 0xA}

Parameters
[in]*framePointer to reply frame
[in]lenFrame length in number of bytes
Returns
bool
Return values
TRUEif the frame is an ack frame
FALSEif the frame is NOT an ack frame

◆ isNackFrame()

bool UART::isNackFrame ( const char *  frame,
const uint8_t  len 
)
protectedvirtual

Checks if a frame is an nack reply frame.

The UART nack response frame is formed by the ascii nack value (0x15) followed by a new line character ('
' or 0xA). As hexadecimal, the array {0x15, 0xA}

Parameters
[in]*framePointer to reply frame
[in]lenFrame length in number of bytes
Returns
bool
Return values
TRUEif the frame is an ack frame
FALSEif the frame is NOT an ack frame

Member Data Documentation

◆ dfltBaudrateBps

const uint32_t pasco2::UART::dfltBaudrateBps = 9600
static

Default baudrate in bps


The documentation for this class was generated from the following files: