COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
serial_listen.cpp File Reference
Include dependency graph for serial_listen.cpp:

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)
6 {
7  bool xonxoff = false;
8  bool rtscts = false;
9  string name = "/dev/ttyUSB0";
10  int32_t baud = 115200;
11  size_t parity = 0;
12  size_t bits = 8;
13  size_t stop = 1;
14 
15  switch (argc)
16  {
17  case 7:
18  if (!strcmp(argv[6], "rtscts"))
19  {
20  rtscts = true;
21  }
22  if (!strcmp(argv[6], "xonxoff"))
23  {
24  xonxoff = true;
25  }
26  case 6:
27  stop = atoi(argv[5]);
28  case 5:
29  parity = atoi(argv[4]);
30  case 4:
31  bits = atoi(argv[3]);
32  case 3:
33  baud = atol(argv[2]);
34  case 2:
35  name = argv[1];
36  }
37 
38  Serial *port = new Serial(name, baud, bits, parity, stop);
39  port->set_flowcontrol(rtscts, xonxoff);
40  port->set_timeout(4.);
41 
42  size_t readcount = 0;
43  size_t errorcount = 0;
44  size_t timeoutcount = 0;
45  int32_t lastresult = 0;
46  int32_t result;
48  do
49  {
50  result = port->get_char();
51  if (result >= 0)
52  {
53  ++readcount;
54  if (result != lastresult)
55  {
56  lastresult = result;
57  double lap = et.lap();
58  printf("%f %f: Read %lu %c(%0x) @ %f BPS: %lu Errors: %lu Timeouts\n", et.split(), lap, readcount, result, result, readcount/lap, errorcount, timeoutcount);
59  readcount = 0;
60  errorcount = 0;
61  timeoutcount = 0;
62  }
63  }
64  else
65  {
66  if (result == SERIAL_ERROR_TIMEOUT)
67  {
68  ++timeoutcount;
69  }
70  else
71  {
72  printf("%f: %s\n", et.split(), cosmos_error_string(result).c_str());
73  ++errorcount;
74  }
75  }
76  } while (1);
77 
78 }
#define SERIAL_ERROR_TIMEOUT
Definition: cosmos-errno.h:171
static string port
Definition: add_radio.cpp:16
Definition: serialclass.h:43
ElapsedTime et
Definition: agent_cpu_device_test.cpp:51
int32_t get_char()
Definition: serialclass.cpp:987
string cosmos_error_string(int32_t cosmos_errno)
Definition: cosmos-errno.cpp:45
double lap()
Lap Time.
Definition: elapsedtime.cpp:145
string name
Definition: cubesat2obj.cpp:6
Definition: elapsedtime.h:62
int32_t set_timeout(int, double timeout)
Definition: serialclass.cpp:515
int32_t set_flowcontrol(bool rtscts, bool xonxoff)
Definition: serialclass.cpp:386
double split()
ElapsedTime::split, gets the current elapsed time since the start()
Definition: elapsedtime.cpp:234