PAS CO2 Sensor  1.0.3
C++ library for Infineon Photoacoustic Spectroscopy (PAS) XENSIV™ CO2 miniaturized sensor
pas-co2-uart.hpp
Go to the documentation of this file.
1 
10 #ifndef PAS_CO2_UART_HPP_
11 #define PAS_CO2_UART_HPP_
12 
13 #include "pas-co2-conf.hpp"
14 
15 #if IS_INTF(PAS_CO2_INTF_UART)
16 
17 #include <stdint.h>
18 #include "pas-co2-sbus.hpp"
19 #include "pas-co2-pal-uart.hpp"
20 
21 #undef UART
22 
23 namespace pasco2
24 {
25 
31 class UART : public SBus
32 {
33  public:
34 
35  static const uint32_t dfltBaudrateBps = 9600;
37  UART (UARTPAL * const uartpal,
38  uint32_t baudrateBps = dfltBaudrateBps);
39  ~UART (void);
40 
41  Error_t init (void);
42  Error_t deinit (void);
43 
44  Error_t write (const uint8_t regAddr,
45  const uint8_t * data,
46  uint16_t length);
47  Error_t read (const uint8_t regAddr,
48  uint8_t * data,
49  uint16_t length);
50  Proto_t getProtocol(void) { return BUS_PROTO_UART; };
51 
52  private:
53 
54  UARTPAL * const uartpal;
55 
56  uint32_t baudrateBps;
57  static const UARTPAL::DataBits_t dataBits = UARTPAL::UART_8BITS;
58  static const UARTPAL::Parity_t parity = UARTPAL::UART_PARITY_NONE;
59  static const UARTPAL::StopBits_t stopBits = UARTPAL::UART_1STOPBIT;
60 
61  protected:
62 
63  char uint4ToHexChar (const uint8_t uint4);
64 
65  virtual void assembleWriteRequestFrame (const uint8_t regAddr,
66  const uint8_t regVal,
67  char * frame);
68 
69  virtual void assembleReadRequestFrame (const uint8_t regAddr,
70  char * frame);
71 
72  virtual uint8_t disassembleReadReplyFrame (const char * frame);
73 
74  virtual bool isAckFrame (const char * frame,
75  const uint8_t len);
76 
77  virtual bool isNackFrame (const char * frame,
78  const uint8_t len);
79 
80 };
81 
87 // extern UART pasco2_uart;
88 
89 }
90 
91 #endif
92 #endif
virtual bool isAckFrame(const char *frame, const uint8_t len)
Checks if a frame is an ack reply frame.
Definition: pas-co2-uart.cpp:325
StopBits_t
Definition: pas-co2-pal-uart.hpp:66
Error_t init(void)
Initializes the I2C interface.
Definition: pas-co2-uart.cpp:52
virtual uint8_t disassembleReadReplyFrame(const char *frame)
Disassembles the read response frame.
Definition: pas-co2-uart.cpp:284
virtual bool isNackFrame(const char *frame, const uint8_t len)
Checks if a frame is an nack reply frame.
Definition: pas-co2-uart.cpp:354
PAS CO2 Serial Interface.
Parity_t
Definition: pas-co2-pal-uart.hpp:54
PAS CO2 UART Platform Abstraction Layer.
Definition: pas-co2-uart.hpp:31
Definition: pas-co2-i2c.hpp:21
char uint4ToHexChar(const uint8_t uint4)
Converts an unsigned 4 bits integer to its hexadecimal ascii value.
Definition: pas-co2-uart.cpp:210
Error_t
Definition: pas-co2-types.hpp:24
Definition: pas-co2-sbus.hpp:23
Definition: pas-co2-pal-uart.hpp:32
Error_t read(const uint8_t regAddr, uint8_t *data, uint16_t length)
Reads data from a register or set of consecutive registers.
Definition: pas-co2-uart.cpp:155
Proto_t
Definition: pas-co2-sbus.hpp:31
virtual void assembleWriteRequestFrame(const uint8_t regAddr, const uint8_t regVal, char *frame)
Assembles the register write request frame.
Definition: pas-co2-uart.cpp:231
DataBits_t
Definition: pas-co2-pal-uart.hpp:40
Definition: pas-co2-pal-uart.hpp:45
Definition: pas-co2-pal-uart.hpp:56
virtual void assembleReadRequestFrame(const uint8_t regAddr, char *frame)
Assembles the register read request frame.
Definition: pas-co2-uart.cpp:260
~UART(void)
UUART interface desconstructor.
Definition: pas-co2-uart.cpp:37
Error_t write(const uint8_t regAddr, const uint8_t *data, uint16_t length)
Writes data to a register or set of consecutive registers.
Definition: pas-co2-uart.cpp:97
UART(UARTPAL *const uartpal, uint32_t baudrateBps=dfltBaudrateBps)
UART interface constructor.
Definition: pas-co2-uart.cpp:25
static const uint32_t dfltBaudrateBps
Definition: pas-co2-uart.hpp:35
Error_t deinit(void)
Deinitializes the serial interface.
Definition: pas-co2-uart.cpp:73
Proto_t getProtocol(void)
Gets the specific serial protocol.
Definition: pas-co2-uart.hpp:50
PAS CO2 Library Configuration.
Definition: pas-co2-pal-uart.hpp:68
Definition: pas-co2-sbus.hpp:34