#include <pas-co2-uart.hpp>
◆ UART()
UART interface constructor.
- Parameters
-
[in] | *uartpal | UART pal interface |
[in] | baudrateBps | Baudrate in bit per second. Default 19200 bps. Valid Range [9600, 19200]. |
- Precondition
- None
◆ ~UART()
UUART interface desconstructor.
- Precondition
- None
◆ init()
Initializes the I2C interface.
Initiliazes the host I2C peripheral and set its clock frequency
- Returns
- PAS CO2 error code
- Return values
-
OK | if success |
INTF_ERROR | if hardware interface error |
- Precondition
- None
Implements pasco2::SBus.
◆ deinit()
Deinitializes the serial interface.
- Returns
- PAS CO2 error code
- Return values
-
OK | if success |
INTF_ERROR | if error |
Implements pasco2::SBus.
◆ 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] | regAddr | Register start write address |
[in] | *data | Pointer to the data array to be written |
[in] | length | Number of registers to be written in the bus |
- Returns
- PAS CO2 error code
- Return values
-
OK | if success |
INTF_ERROR | if error |
- Precondition
- init()
Implements pasco2::SBus.
◆ 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] | regAddr | Register start read address |
[out] | *data | Pointer to the array that will store the read data |
[in] | length | Number of registers to be read from the bus |
- Returns
- PAS CO2 error code
- Return values
-
OK | if success |
INTF_ERROR | if error |
- Precondition
- init()
Implements pasco2::SBus.
◆ 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] | uint4 | Unsigned 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] | regAddr | Register address |
[in] | regVal | Register value to be written |
[out] | *frame | Pointer to store the assembled write frame |
- Returns
- void
◆ 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] | regAddr | Register address to be read |
[out] | *frame | Pointer to store the assembled read frame |
- Returns
- void
◆ 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] | *frame | Pointer 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] | *frame | Pointer to reply frame |
[in] | len | Frame length in number of bytes |
- Returns
- bool
- Return values
-
TRUE | if the frame is an ack frame |
FALSE | if 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] | *frame | Pointer to reply frame |
[in] | len | Frame length in number of bytes |
- Returns
- bool
- Return values
-
TRUE | if the frame is an ack frame |
FALSE | if the frame is NOT an ack frame |
◆ dfltBaudrateBps
const uint32_t pasco2::UART::dfltBaudrateBps = 9600 |
|
static |
The documentation for this class was generated from the following files: