2 Copyright 2006 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "messagequeue.h"
28 //void dump(unsigned char* data, USHORT size);
29 //unsigned char dcc(UCHAR c);
33 log = Log::getInstance();
44 if (!initted) return 1;
45 if (threadIsActive()) threadCancel();
52 int UDP::run(MessageQueue* tcommandMessageQueue)
54 if (threadIsActive()) return 1;
55 log->log("UDP", Log::DEBUG, "Starting UDP command server");
59 commandMessageQueue = tcommandMessageQueue;
60 ds = new DatagramSocket(2000);
64 log->log("UDP", Log::DEBUG, "DSock init error");
71 log->log("UDP", Log::DEBUG, "Thread start error");
76 log->log("UDP", Log::DEBUG, "UDP command server started");
80 void UDP::threadMethod()
87 retval = ds->waitforMessage(1);
91 log->log("UDP", Log::CRIT, "Wait for packet error");
101 processRequest((UCHAR*)ds->getData(), ds->getDataLength());
107 void UDP::processRequest(UCHAR* data, int length)
109 log->log("UDP", Log::DEBUG, "Got request");
111 char* temp = new char[length + 1];
112 memcpy(temp, data, length);
114 int command = atoi(temp);
117 log->log("UDP", Log::DEBUG, "Command %i recieved", command);
120 Message *m = new Message();
121 m->to = commandMessageQueue;
122 m->message = Message::UDP_BUTTON;
123 m->parameter = command;
124 commandMessageQueue->postMessage(m);
128 void dump(unsigned char* data, USHORT size)
130 printf("Size = %u\n", size);
137 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
138 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
139 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14], data[c+15],
140 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]),
141 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]), dcc(data[c+14]), dcc(data[c+15]));
149 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
150 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
151 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14],
152 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]),
153 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]), dcc(data[c+14]));
157 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
158 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
159 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13],
160 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]),
161 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]));
165 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c%c\n",
166 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
167 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12],
168 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]),
169 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]));
173 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c\n",
174 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
175 data[c+8], data[c+9], data[c+10], data[c+11],
176 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]),
177 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]));
181 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c\n",
182 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
183 data[c+8], data[c+9], data[c+10],
184 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]),
185 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]));
189 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c\n",
190 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
191 data[c+8], data[c+9],
192 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]),
193 dcc(data[c+8]), dcc(data[c+9]));
197 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c\n",
198 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
200 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]),
205 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c\n",
206 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
207 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]));
211 printf(" %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c\n",
212 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6],
213 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]));
217 printf(" %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c\n",
218 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5],
219 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]));
223 printf(" %02X %02X %02X %02X %02X %c%c%c%c%c\n",
224 data[c], data[c+1], data[c+2], data[c+3], data[c+4],
225 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]));
229 printf(" %02X %02X %02X %02X %c%c%c%c\n",
230 data[c], data[c+1], data[c+2], data[c+3],
231 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]));
235 printf(" %02X %02X %02X %c%c%c\n",
236 data[c], data[c+1], data[c+2],
237 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]));
241 printf(" %02X %02X %c%c\n",
243 dcc(data[c]), dcc(data[c+1]));
257 unsigned char dcc(UCHAR c)
259 if (isspace(c)) return ' ';
260 if (isprint(c)) return c;