1 |
torben |
60 |
#include <iostream> |
2 |
|
|
#include <string> |
3 |
|
|
|
4 |
|
|
#include <boost/thread/thread.hpp> |
5 |
|
|
#include <boost/thread/mutex.hpp> |
6 |
|
|
|
7 |
|
|
#include "../H7Serial.h" |
8 |
|
|
#include "serialthread.h" |
9 |
torben |
67 |
#include "serverthread.h" |
10 |
torben |
60 |
|
11 |
torben |
67 |
#include "globalstorage.h" |
12 |
torben |
60 |
|
13 |
|
|
void my_pause() |
14 |
|
|
{ |
15 |
|
|
char d[1]; |
16 |
|
|
std::cout << "Press enter to continue" << std::endl; |
17 |
|
|
std::cin.getline(d,1); |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
int main(int argc, char* argv[]) |
21 |
|
|
{ |
22 |
torben |
67 |
CH7Serial& serialPort = GlobalStorage::instance()->serialPort; |
23 |
|
|
|
24 |
|
|
SerialThread& serial = GlobalStorage::instance()->serialThread; |
25 |
|
|
ServerThread server; |
26 |
|
|
// GlobalStorage::instance()->serialThread = &serial; |
27 |
|
|
|
28 |
torben |
60 |
try |
29 |
|
|
{ |
30 |
torben |
67 |
serialPort.open("/dev/ttyS0", CSerial::Baud9600); |
31 |
torben |
60 |
} |
32 |
|
|
catch(std::exception&e ) |
33 |
|
|
{ |
34 |
|
|
std::cout << "Error opening serial port : " << e.what() << std::endl; |
35 |
torben |
67 |
exit(1); |
36 |
torben |
60 |
} |
37 |
|
|
|
38 |
torben |
67 |
try |
39 |
|
|
{ |
40 |
|
|
GlobalStorage::instance()->server.start(9000); //listen on port 9000 |
41 |
|
|
} |
42 |
|
|
catch(...) |
43 |
|
|
{ |
44 |
|
|
std::cout << "Could not listen on port 9000" << std::endl; |
45 |
|
|
serialPort.close(); |
46 |
|
|
exit(2); |
47 |
|
|
} |
48 |
torben |
60 |
|
49 |
torben |
67 |
|
50 |
|
|
|
51 |
|
|
boost::thread serialThread(serial); |
52 |
|
|
boost::thread serverThread(server); |
53 |
|
|
|
54 |
torben |
60 |
my_pause(); |
55 |
|
|
|
56 |
torben |
67 |
serial.stop(); |
57 |
|
|
server.stop(); |
58 |
|
|
while(!serial.stopped() && !server.stopped() ) |
59 |
torben |
60 |
usleep(10000); |
60 |
|
|
} |