Snorktracker
 All Data Structures Files Functions Variables Macros Pages
Public Member Functions | Protected Attributes
MySerial Class Reference

#include <Serial.h>

Inheritance diagram for MySerial:

Public Member Functions

 MySerial (StringList &li, bool &dbg, uint8_t receivePin, uint8_t transmitPin, bool inverse_logic=false)
 
virtual int read ()
 
virtual size_t write (uint8_t byte)
 

Protected Attributes

char inData [255]
 Helper data for a serial write.
 
int inIdx
 How many bytes are written.
 
char outData [255]
 Helper data for a serial read.
 
int outIdx
 How many bytes are read.
 
StringListlogInfos
 Hook pointer for the data logging.
 
bool & debug
 Enable or disable the hooking.
 

Detailed Description

Helper class to hook the SoftwareSerial calls to log the information for the console.

Definition at line 26 of file Serial.h.

Constructor & Destructor Documentation

MySerial::MySerial ( StringList li,
bool &  dbg,
uint8_t  receivePin,
uint8_t  transmitPin,
bool  inverse_logic = false 
)

Constructor

Definition at line 46 of file Serial.h.

47  : SoftwareSerial(receivePin, transmitPin, inverse_logic)
48  , inIdx(0)
49  , outIdx(0)
50  , logInfos(li)
51  , debug(dbg)
52 {
53 }
StringList & logInfos
Hook pointer for the data logging.
Definition: Serial.h:33
int outIdx
How many bytes are read.
Definition: Serial.h:32
bool & debug
Enable or disable the hooking.
Definition: Serial.h:34
int inIdx
How many bytes are written.
Definition: Serial.h:30

Member Function Documentation

int MySerial::read ( )
virtual

Virtual function call on read operations. We check for incomming calls.

Definition at line 58 of file Serial.h.

References StringList::addTail(), debug, inData, inIdx, and logInfos.

59 {
60  int ret = SoftwareSerial::read();
61 
62  if (ret >= 0 && debug) {
63  char c = (char) ret;
64 
65  if (c != '\r' && c != '\n') {
66  if (inIdx < 250) {
67  inData[inIdx++] = c;
68  }
69  } else {
70  if (inIdx > 0) {
71  inData[inIdx] = 0;
72 
73  String info = (String) F("< ") + (String) inData;
74  logInfos.addTail(info);
75  // Pass thrue to the default Serial for debugging
76  Serial.println(info);
77  }
78  inIdx = 0;
79  }
80  }
81 
82  return ret;
83 }
StringList & logInfos
Hook pointer for the data logging.
Definition: Serial.h:33
char inData[255]
Helper data for a serial write.
Definition: Serial.h:29
bool & debug
Enable or disable the hooking.
Definition: Serial.h:34
int inIdx
How many bytes are written.
Definition: Serial.h:30
void addTail(String newInfo)
Definition: StringList.h:112
size_t MySerial::write ( uint8_t  byte)
virtual

Virtual function call on write operations

Definition at line 86 of file Serial.h.

References StringList::addTail(), debug, logInfos, outData, and outIdx.

87 {
88  size_t ret = SoftwareSerial::write(byte);
89 
90  if (debug) {
91  char c = (char)byte;
92 
93  if (c != '\r' && c != '\n') {
94  if (outIdx < 250) {
95  outData[outIdx++] = c;
96  }
97  } else {
98  if (outIdx > 0) {
99  outData[outIdx] = 0;
100 
101  String info = (String) F("> ") + (String)outData;
102 
103  logInfos.addTail(info);
104  // Pass thrue to the default Serial for debugging
105  Serial.println(info);
106  }
107  outIdx = 0;
108  }
109  }
110  return ret;
111 }
StringList & logInfos
Hook pointer for the data logging.
Definition: Serial.h:33
int outIdx
How many bytes are read.
Definition: Serial.h:32
char outData[255]
Helper data for a serial read.
Definition: Serial.h:31
bool & debug
Enable or disable the hooking.
Definition: Serial.h:34
void addTail(String newInfo)
Definition: StringList.h:112

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