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

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

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

revision 68 by torben, Wed Feb 7 00:14:52 2007 UTC revision 70 by torben, Wed Feb 7 08:03:48 2007 UTC
# Line 28  ServerThread::~ServerThread() Line 28  ServerThread::~ServerThread()
28          }          }
29  }  }
30    
31    void ServerThread::parsePackage(std::string str, TCPConnection& conn)
32    {
33            std::cout << "parsePackage: " << str << std::endl;
34    
35            GlobalStorage* store = GlobalStorage::instance();
36            if ( str == "100")
37            {
38                    std::ostringstream tmp;
39            
40                    if (store->led3)
41                            tmp << "111|";
42                    else
43                            tmp << "110|";
44    
45                    if (store->led4)
46                            tmp << "121|";
47                    else
48                            tmp << "120|";
49    
50                    if (store->led5)
51                            tmp << "131|";
52                    else
53                            tmp << "130|";
54    
55                    if (store->switch2)
56                            tmp << "141|";
57                    else
58                            tmp << "140|";
59    
60                    if (store->switch3)
61                            tmp << "151|";
62                    else
63                            tmp << "150|";
64    
65                    tmp << ( store->temp + 4000) << "|";
66                    tmp << ( store->potmeter+2000) << "|";
67                    conn << tmp.str();
68            } else {
69    
70                    boost::mutex::scoped_lock lock(store->writeMutex);
71                    if (str == "111")
72                            store->commands.push( WriteCommand(0,1) );
73                    else if (str == "110")
74                            store->commands.push( WriteCommand(0,0) );
75                    else if (str == "121")
76                            store->commands.push( WriteCommand(1,1) );
77                    else if (str == "120")
78                            store->commands.push( WriteCommand(1,0) );
79                    else if (str == "131")
80                            store->commands.push( WriteCommand(2,1) );
81                    else if (str == "130")
82                            store->commands.push( WriteCommand(2,0) );
83            }
84    }
85    
86  void ServerThread::operator()()  void ServerThread::operator()()
87  {  {
88          mStopped = false;          mStopped = false;
# Line 66  void ServerThread::operator()() Line 121  void ServerThread::operator()()
121                          if (str.size() >0)                          if (str.size() >0)
122                          {                          {
123                                  cout << "Got " << str.size() << " bytes :" << str << endl;                                  cout << "Got " << str.size() << " bytes :" << str << endl;
124                                  do                                  while (str.size() >= 3)
125                                  {                                  {
126                                          if ( str == "100")                                          std::string package = str.substr(0,3);
127                                          {                                          parsePackage(package, conn);
128                                                  std::ostringstream tmp;  
129                                            str = str.substr(3, str.size()-3);
130                                                                                    
131                                                  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  
132                          }                          }
133                          str = "";                          str = "";
134                  }                  }

Legend:
Removed from v.68  
changed lines
  Added in v.70

  ViewVC Help
Powered by ViewVC 1.1.20