QP  0.7-SNAPSHOT
Control software for the ??SRT telescope
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
buffered-serial.h
1 #ifndef BUFSERIAL_H_LOADED
2 #define BUFSERIAL_H_LOADED 1
3 
4 #include <stdarg.h>
5 
6 #include "types.h"
7 
8 // The actual serial device
9 //extern HardwareSerial Serial;
10 //extern Serial_ Serial;
11 extern UARTClass Serial;
12 
13 
14 #define ITEM_CH 0
15 #define ITEM_INT 1
16 #define ITEM_FLOAT 2
17 #define ITEM_INVALID 3
18 
24 struct InputItem {
29  unsigned char type;
31  union item_data {
32  char c;
33  int i;
34  float f;
35  };
37  union item_data v;
38 };
39 
40 #define SERIALBUFSIZ 128
41 
88 private:
89  enum { unknown, comment, non_comment } line_type;
90  int n_discards;
91  void print_simple_float(const float f, const int dp);
92  void print_float(const float f, const int dp=3);
93  void print_string(const char* s);
94  void print_int(const int i, const int base);
95  void append_byte(const byte);
96 
97  public:
99  void init(void);
100  void logprintf(PGM_P format, ...);
101  void logvprintf(PGM_P format, va_list ap);
102 #undef putchar
103  int putchar(const int);
104 
105  int read_items_read_char(void);
106  InputItem* read_items_get(int* n);
107  void read_items_reset(void);
108  bool read_available(void);
109 
110  int count_discarded(void);
111 
112 #if PROVARINO
113  void display_serial_contents(void);
114  static void testenv_logprintf(PGM_P format, ...);
115 #endif
116 };
117 
118 #endif /* BUFSERIAL_H_LOADED */
int count_discarded(void)
Return the number of bytes discarded since the last call to this method.
Definition: buffered-serial.cpp:548
int read_items_read_char(void)
Read a character from Serial, and return the number of bytes actually read.
Definition: buffered-serial.cpp:167
InputItem * read_items_get(int *n)
Retrieve items from the Serial input.
Definition: buffered-serial.cpp:81
The BufferedSerial class mediates access to an underlying serial device.
Definition: buffered-serial.h:87
float f
a float
Definition: buffered-serial.h:34
void init(void)
Initialise the buffered-serial object, after the program is under way.
Definition: buffered-serial.cpp:38
The types of data that may be in an input item.
Definition: buffered-serial.h:31
The items read from the serial port.
Definition: buffered-serial.h:24
BufferedSerial()
Create a new BufferedSerial object, and initialise the underlying serial port.
Definition: buffered-serial.cpp:26
int i
an integer
Definition: buffered-serial.h:33
void logprintf(PGM_P format,...)
The logprintf function supports a simple printf-like syntax for writing data to the Serial port...
Definition: buffered-serial.cpp:299
union item_data v
The value of the item.
Definition: buffered-serial.h:37
int putchar(const int)
Append a single byte to the output.
Definition: buffered-serial.cpp:536
char c
a character
Definition: buffered-serial.h:32
void read_items_reset(void)
Reset the buffer of read items.
Definition: buffered-serial.cpp:95
void logvprintf(PGM_P format, va_list ap)
The logvprintf is the varargs companion to the logprintf function.
Definition: buffered-serial.cpp:325
unsigned char type
The type of the item, which is one of the types ITEM_CH, ITEM_INT, ITEM_FLOAT or ITEM_INVALID.
Definition: buffered-serial.h:29
bool read_available(void)
Return true if there is at least one byte available to be read.
Definition: buffered-serial.cpp:267