--- branches/linux-serial/server/main.cpp 2007/02/06 21:47:56 66 +++ branches/linux-serial/server/main.cpp 2007/02/06 23:37:39 67 @@ -6,7 +6,9 @@ #include "../H7Serial.h" #include "serialthread.h" +#include "serverthread.h" +#include "globalstorage.h" void my_pause() { @@ -17,23 +19,42 @@ int main(int argc, char* argv[]) { - CH7Serial serial; - boost::mutex writeMutex; + CH7Serial& serialPort = GlobalStorage::instance()->serialPort; + + SerialThread& serial = GlobalStorage::instance()->serialThread; + ServerThread server; +// GlobalStorage::instance()->serialThread = &serial; + try { - serial.open("/dev/ttyS0", CSerial::Baud9600); + serialPort.open("/dev/ttyS0", CSerial::Baud9600); } catch(std::exception&e ) { std::cout << "Error opening serial port : " << e.what() << std::endl; + exit(1); + } + + try + { + GlobalStorage::instance()->server.start(9000); //listen on port 9000 + } + catch(...) + { + std::cout << "Could not listen on port 9000" << std::endl; + serialPort.close(); + exit(2); } - SerialThread serialThreadFunction(serial, writeMutex); - boost::thread serialT(serialThreadFunction); + + + boost::thread serialThread(serial); + boost::thread serverThread(server); my_pause(); - serialThreadFunction.stop(); - while(!serialThreadFunction.stopped()) + serial.stop(); + server.stop(); + while(!serial.stopped() && !server.stopped() ) usleep(10000); }