ARPDAS_QNX6 1.0
|
#include <SerSelector.h>
Public Member Functions | |
Ser_Sel (const char *path, int open_flags, int bufsz) | |
Ser_Sel () | |
~Ser_Sel () | |
void | init (const char *path, int open_flags, int bufsz) |
void | setup (int baud, int bits, char par, int stopbits, int min, int time) |
Protected Member Functions | |
int | fillbuf () |
void | consume (int nchars) |
void | flush_input () |
void | report_err (const char *msg,...) |
void | report_ok () |
int | not_found (unsigned char c) |
int | not_hex (unsigned short &hexval) |
int | not_int (int &val) |
int | not_str (const char *str, unsigned int len) |
int | not_str (const std::string &s) |
int | not_str (const char *str) |
int | not_float (float &val) |
Protected Attributes | |
unsigned int | nc |
unsigned int | cp |
unsigned char * | buf |
int | bufsize |
int | n_fills |
int | n_empties |
int | n_eagain |
int | n_eintr |
Private Member Functions | |
void | sersel_init () |
Private Attributes | |
int | n_errors |
int | n_suppressed |
int | total_errors |
int | total_suppressed |
A Selectee for monitoring a serial line.
Definition at line 40 of file SerSelector.h.
Ser_Sel::Ser_Sel | ( | const char * | path, |
int | open_flags, | ||
int | bufsz | ||
) |
path | The full path to the serial device. If path == NULL, the fd will not be opened. |
open_flags | Flags from <fcntl.h> passed to open() |
bufsz | The size buffer to be allocated. |
Definition at line 67 of file SerSelector.cc.
References init(), and sersel_init().
Ser_Sel::Ser_Sel | ( | ) |
Definition at line 73 of file SerSelector.cc.
References sersel_init().
Ser_Sel::~Ser_Sel | ( | ) |
Frees the allocated buffer and reports statistics.
Definition at line 117 of file SerSelector.cc.
References buf, free_memory, n_eagain, n_eintr, n_empties, n_fills, nl_error, total_errors, and total_suppressed.
void Ser_Sel::consume | ( | int | nchars | ) | [protected] |
Each call to consume() increments the n_empties counter which is reported at termination. If n_fills is much greater than n_empties, you may need to adjust your min and time settings for more efficient operation.
nchars | number of characters to remove from front of buffer |
Definition at line 218 of file SerSelector.cc.
int Ser_Sel::fillbuf | ( | ) | [protected] |
Reads characters from the device, reporting any errors. Guarantees that buf is NUL-terminated, and sets nc to the total number of characters. Each call to fillbuf() increments the n_fills counter, which is reported at termination
Definition at line 190 of file SerSelector.cc.
References buf, bufsize, Selectee::fd, n_eagain, n_eintr, n_fills, nc, and nl_error.
Referenced by flush_input().
void Ser_Sel::flush_input | ( | ) | [protected] |
void Ser_Sel::init | ( | const char * | path, |
int | open_flags, | ||
int | bufsz | ||
) |
path | The full path to the serial device. If path == NULL, the fd will not be opened. |
open_flags | Flags from <fcntl.h> passed to open() |
bufsz | The size buffer to be allocated. |
Definition at line 83 of file SerSelector.cc.
References buf, bufsize, Selectee::fd, Selectee::flags, new_memory(), Selector::Sel_Read, and tm_open_name().
Referenced by Ser_Sel().
int Ser_Sel::not_float | ( | float & | val | ) | [protected] |
Parsing utility function to convert a string in the input buffer to a float value. Updates cp to point just after the converted string on success.
val[out] | The converted value |
Definition at line 401 of file SerSelector.cc.
References buf, bufsize, cp, msg(), nc, nl_assert, and report_err().
int Ser_Sel::not_found | ( | unsigned char | c | ) | [protected] |
Parsing utility function that searches forward in the buffer for the specified start character. Updates cp to point just past the start char. If the character is not found, the buffer is emptied.
c | The search character |
Definition at line 289 of file SerSelector.cc.
References buf, cp, nc, and report_err().
int Ser_Sel::not_hex | ( | unsigned short & | hexval | ) | [protected] |
Parsing utility function to read in a hex integer starting at the current position. Integer may be proceeded by optional whitespace.
[out] | hexval | The integer value |
Definition at line 308 of file SerSelector.cc.
References buf, cp, nc, and report_err().
int Ser_Sel::not_int | ( | int & | val | ) | [protected] |
Parsing utility function to read in a decimal integer starting at the current position. Integer may be proceeded by optional whitespace and an optional sign.
[out] | val | The integer value |
Definition at line 332 of file SerSelector.cc.
References buf, cp, nc, and report_err().
int Ser_Sel::not_str | ( | const char * | str_in, |
unsigned int | len | ||
) | [protected] |
Parsing utility function to check that the string matches the input at the current position. On success, advances cp to just after the matched string. On failure, cp points to the first character that does not match. If only a partial record was received, that could be the NUL at the end of the buffer.
str | The comparison string. |
Definition at line 365 of file SerSelector.cc.
References ascii_escape(), buf, cp, nc, nl_error, and report_err().
Referenced by not_str().
int Ser_Sel::not_str | ( | const char * | str | ) | [protected] |
Definition at line 385 of file SerSelector.cc.
References not_str().
int Ser_Sel::not_str | ( | const std::string & | s | ) | [protected] |
Definition at line 389 of file SerSelector.cc.
References not_str().
void Ser_Sel::report_err | ( | const char * | fmt, |
... | |||
) | [protected] |
Reports the error message, provided the qualified error count is not above the limit. report_ok() will decrement the qualified error count. It is assumed that all messages are of severity MSG_ERR. Messages at other levels, either more or less severe, should be sent directly to msg().
Definition at line 250 of file SerSelector.cc.
References ascii_escape(), buf, msg(), msgv(), n_errors, n_suppressed, nc, QERR_THRESHOLD, total_errors, and total_suppressed.
Referenced by not_float(), not_found(), not_hex(), not_int(), and not_str().
void Ser_Sel::report_ok | ( | ) | [protected] |
Indicate that data has successfully been received.
Definition at line 273 of file SerSelector.cc.
References msg(), n_errors, and n_suppressed.
void Ser_Sel::sersel_init | ( | ) | [private] |
Definition at line 101 of file SerSelector.cc.
References buf, bufsize, cp, Selectee::fd, n_eagain, n_eintr, n_empties, n_errors, n_fills, n_suppressed, nc, total_errors, and total_suppressed.
Referenced by Ser_Sel().
void Ser_Sel::setup | ( | int | baud, |
int | bits, | ||
char | par, | ||
int | stopbits, | ||
int | min, | ||
int | time | ||
) |
Initializes the serial parameters for the device. The min and time parameters can be used to optimize reads. See tcsetattr VMIN and VTIME parameters for more information.
baud | The desired baud rate |
bits | number of data bits (5-8) |
par | 'n', 'e', 'o', 'm', 's' for none, even, odd, mark or space. |
stopbits | The number of stop bits: 1 or 2 |
min | The minimum number of characters to respond to |
time | The time gap value |
Definition at line 137 of file SerSelector.cc.
References Selectee::fd, and nl_error.
unsigned char* Ser_Sel::buf [protected] |
Definition at line 62 of file SerSelector.h.
Referenced by consume(), fillbuf(), init(), not_float(), not_found(), not_hex(), not_int(), not_str(), report_err(), sersel_init(), and ~Ser_Sel().
int Ser_Sel::bufsize [protected] |
Definition at line 63 of file SerSelector.h.
Referenced by fillbuf(), init(), not_float(), and sersel_init().
unsigned int Ser_Sel::cp [protected] |
Definition at line 61 of file SerSelector.h.
Referenced by consume(), flush_input(), not_float(), not_found(), not_hex(), not_int(), not_str(), and sersel_init().
int Ser_Sel::n_eagain [protected] |
Definition at line 65 of file SerSelector.h.
Referenced by fillbuf(), sersel_init(), and ~Ser_Sel().
int Ser_Sel::n_eintr [protected] |
Definition at line 65 of file SerSelector.h.
Referenced by fillbuf(), sersel_init(), and ~Ser_Sel().
int Ser_Sel::n_empties [protected] |
Definition at line 64 of file SerSelector.h.
Referenced by consume(), sersel_init(), and ~Ser_Sel().
int Ser_Sel::n_errors [private] |
Number of qualified errors. Decremented by report_ok()
Definition at line 69 of file SerSelector.h.
Referenced by report_err(), report_ok(), and sersel_init().
int Ser_Sel::n_fills [protected] |
Definition at line 64 of file SerSelector.h.
Referenced by fillbuf(), sersel_init(), and ~Ser_Sel().
int Ser_Sel::n_suppressed [private] |
Number of messages currently suppressed.
Definition at line 71 of file SerSelector.h.
Referenced by report_err(), report_ok(), and sersel_init().
unsigned int Ser_Sel::nc [protected] |
Definition at line 61 of file SerSelector.h.
Referenced by consume(), fillbuf(), flush_input(), not_float(), not_found(), not_hex(), not_int(), not_str(), report_err(), and sersel_init().
int Ser_Sel::total_errors [private] |
Total number of errors found.
Definition at line 73 of file SerSelector.h.
Referenced by report_err(), sersel_init(), and ~Ser_Sel().
int Ser_Sel::total_suppressed [private] |
Definition at line 74 of file SerSelector.h.
Referenced by report_err(), sersel_init(), and ~Ser_Sel().