--- branches/linux-serial/server/serverthread.cpp 2007/02/07 00:14:52 68 +++ branches/linux-serial/server/serverthread.cpp 2007/02/07 00:24:04 69 @@ -28,6 +28,58 @@ } } +void ServerThread::parsePackage(std::string str) +{ + if ( str == "100") + { + std::ostringstream tmp; + + if (store->led3) + tmp << "111|"; + else + tmp << "110|"; + + if (store->led4) + tmp << "121|"; + else + tmp << "120|"; + + if (store->led5) + tmp << "131|"; + else + tmp << "130|"; + + if (store->switch2) + tmp << "141|"; + else + tmp << "140|"; + + if (store->switch3) + tmp << "151|"; + else + tmp << "150|"; + + tmp << ( store->temp + 4000) << "|"; + tmp << ( store->potmeter+2000) << "|"; + conn << tmp.str(); + } else { + + boost::mutex::scoped_lock lock(store->writeMutex); + if (str == "111") + store->commands.push( WriteCommand(0,1) ); + else if (str == "110") + store->commands.push( WriteCommand(0,0) ); + else if (str == "121") + store->commands.push( WriteCommand(1,1) ); + else if (str == "120") + store->commands.push( WriteCommand(1,0) ); + else if (str == "131") + store->commands.push( WriteCommand(2,1) ); + else if (str == "130") + store->commands.push( WriteCommand(2,0) ); + } +} + void ServerThread::operator()() { mStopped = false; @@ -68,54 +120,6 @@ cout << "Got " << str.size() << " bytes :" << str << endl; do { - if ( str == "100") - { - std::ostringstream tmp; - - if (store->led3) - tmp << "111|"; - else - tmp << "110|"; - - if (store->led4) - tmp << "121|"; - else - tmp << "120|"; - - if (store->led5) - tmp << "131|"; - else - tmp << "130|"; - - if (store->switch2) - tmp << "141|"; - else - tmp << "140|"; - - if (store->switch3) - tmp << "151|"; - else - tmp << "150|"; - - tmp << ( store->temp + 4000) << "|"; - tmp << ( store->potmeter+2000) << "|"; - conn << tmp.str(); - } else { - - boost::mutex::scoped_lock lock(store->writeMutex); - if (str == "111") - store->commands.push( WriteCommand(0,1) ); - else if (str == "110") - store->commands.push( WriteCommand(0,0) ); - else if (str == "121") - store->commands.push( WriteCommand(1,1) ); - else if (str == "120") - store->commands.push( WriteCommand(1,0) ); - else if (str == "131") - store->commands.push( WriteCommand(2,1) ); - else if (str == "130") - store->commands.push( WriteCommand(2,0) ); - } } while (str.length } str = "";