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; |
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 |
if ( str == "100") |
while (str.size() >= 3) |
125 |
{ |
{ |
126 |
std::ostringstream tmp; |
std::string package = str.substr(0,3); |
127 |
|
parsePackage(package, conn); |
|
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 << "140|"; |
|
|
else |
|
|
tmp << "141|"; |
|
|
|
|
|
if (store->switch3) |
|
|
tmp << "150|"; |
|
|
else |
|
|
tmp << "151|"; |
|
|
|
|
|
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) ); |
|
|
|
|
|
if (str == "110") |
|
|
store->commands.push( WriteCommand(0,0) ); |
|
|
|
|
|
if (str == "121") |
|
|
store->commands.push( WriteCommand(1,1) ); |
|
128 |
|
|
129 |
if (str == "120") |
str = str.substr(3, str.size()-3); |
130 |
store->commands.push( WriteCommand(1,0) ); |
|
|
|
|
|
if (str == "131") |
|
|
store->commands.push( WriteCommand(2,1) ); |
|
|
|
|
|
if (str == "130") |
|
|
store->commands.push( WriteCommand(2,0) ); |
|
131 |
} |
} |
132 |
} |
} |
133 |
str = ""; |
str = ""; |