6 |
|
|
7 |
#include "../H7Serial.h" |
#include "../H7Serial.h" |
8 |
#include "serialthread.h" |
#include "serialthread.h" |
9 |
|
#include "serverthread.h" |
10 |
|
|
11 |
|
#include "globalstorage.h" |
12 |
|
|
13 |
void my_pause() |
void my_pause() |
14 |
{ |
{ |
19 |
|
|
20 |
int main(int argc, char* argv[]) |
int main(int argc, char* argv[]) |
21 |
{ |
{ |
22 |
CH7Serial serial; |
CH7Serial& serialPort = GlobalStorage::instance()->serialPort; |
23 |
boost::mutex writeMutex; |
|
24 |
|
SerialThread& serial = GlobalStorage::instance()->serialThread; |
25 |
|
ServerThread server; |
26 |
|
// GlobalStorage::instance()->serialThread = &serial; |
27 |
|
|
28 |
try |
try |
29 |
{ |
{ |
30 |
serial.open("/dev/ttyS0", CSerial::Baud9600); |
serialPort.open("/dev/ttyS0", CSerial::Baud9600); |
31 |
} |
} |
32 |
catch(std::exception&e ) |
catch(std::exception&e ) |
33 |
{ |
{ |
34 |
std::cout << "Error opening serial port : " << e.what() << std::endl; |
std::cout << "Error opening serial port : " << e.what() << std::endl; |
35 |
|
exit(1); |
36 |
|
} |
37 |
|
|
38 |
|
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 |
|
|
49 |
SerialThread serialThreadFunction(serial, writeMutex); |
|
50 |
boost::thread serialT(serialThreadFunction); |
|
51 |
|
boost::thread serialThread(serial); |
52 |
|
boost::thread serverThread(server); |
53 |
|
|
54 |
my_pause(); |
my_pause(); |
55 |
|
|
56 |
serialThreadFunction.stop(); |
serial.stop(); |
57 |
while(!serialThreadFunction.stopped()) |
server.stop(); |
58 |
|
while(!serial.stopped() && !server.stopped() ) |
59 |
usleep(10000); |
usleep(10000); |
60 |
} |
} |