COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
serial_talk.cpp File Reference
Include dependency graph for serial_talk.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  uint16_t endcount = .5 * baud;
15  double duration = 1.;
16 
17  switch (argc)
18  {
19  case 8:
20  if (!strcmp(argv[7], "rtscts"))
21  {
22  rtscts = true;
23  }
24  if (!strcmp(argv[7], "xonxoff"))
25  {
26  xonxoff = true;
27  }
28  case 7:
29  stop = atoi(argv[6]);
30  case 6:
31  parity = atoi(argv[5]);
32  case 5:
33  bits = atoi(argv[4]);
34  case 4:
35  duration = atof(argv[3]);
36  case 3:
37  baud = atol(argv[2]);
38  case 2:
39  name = argv[1];
40  }
41 
42  endcount = duration * baud / (bits + parity + stop + 1.);
43  Serial *port = new Serial(name, baud, bits, parity, stop);
44  port->set_flowcontrol(rtscts, xonxoff);
45 
46  size_t writecount = 0;
47  size_t twritecount = 0;
48  size_t errorcount = 0;
49  size_t timeoutcount = 0;
50  int32_t result;
53  for (uint8_t i=1; i<255; ++i)
54  {
55  vector <uint8_t> data;
56  for (size_t j=0; j<endcount; ++j)
57  {
58  data.push_back(i);
59  }
60  writecount = 0;
61  do
62  {
63  result = port->put_data(&data[writecount], data.size() - writecount);
64  if (result > 0)
65  {
66  writecount += result;
67  twritecount += result;
68  }
69  else
70  {
71  if (result == SERIAL_ERROR_TIMEOUT)
72  {
73  ++timeoutcount;
74  }
75  else
76  {
77  ++errorcount;
78  }
79  COSMOS_SLEEP(.001);
80  }
81  } while (result < 0 || writecount < data.size());
82  printf("%lf %hhu: %lu/%lu Writes @ %.0lf BPS Errors: %lu Timeouts: %lu\n", tet.split(), i, writecount, twritecount, writecount/tet.lap(), errorcount, timeoutcount);
83  tet.reset();
84  }
85  result = port->put_char(4);
86 
87  printf("\n%lf Writes: %lu @ %lf BPS Errors: %lu Timeouts: %lu\n", et.split(), twritecount, twritecount/et.split(), errorcount, timeoutcount);
88 
89 }
#define SERIAL_ERROR_TIMEOUT
Definition: cosmos-errno.h:171
static string port
Definition: add_radio.cpp:16
int32_t put_data(vector< uint8_t > data)
Definition: serialclass.cpp:707
int i
Definition: rw_test.cpp:37
Definition: serialclass.h:43
ElapsedTime et
Definition: agent_cpu_device_test.cpp:51
int32_t put_char(uint8_t c)
Definition: serialclass.cpp:609
static ElapsedTime tet
Definition: agent_file4.cpp:137
double lap()
Lap Time.
Definition: elapsedtime.cpp:145
string name
Definition: cubesat2obj.cpp:6
Definition: elapsedtime.h:62
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
void reset()
ElapsedTime::reset.
Definition: elapsedtime.cpp:278