/[H7]/branches/linux-serial/server/main.cpp
ViewVC logotype

Diff of /branches/linux-serial/server/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 66 by torben, Mon Feb 5 20:34:51 2007 UTC revision 67 by torben, Tue Feb 6 23:37:39 2007 UTC
# Line 6  Line 6 
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  {  {
# Line 17  void my_pause() Line 19  void my_pause()
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  }  }

Legend:
Removed from v.66  
changed lines
  Added in v.67

  ViewVC Help
Powered by ViewVC 1.1.20