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