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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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()
88 retval = ds->waitforMessage(0);
90 log->log("UDP", Log::DEBUG, "Wait for packet");
92 retval = ds->waitforMessage(1);
97 log->log("UDP", Log::CRIT, "Wait for packet error");
100 else if (retval == 1)
106 processRequest((UCHAR*)ds->getData(), ds->getDataLength());
111 void UDP::processRequest(UCHAR* data, int length)
113 log->log("UDP", Log::DEBUG, "Got request");
115 char* temp = new char[length + 1];
116 memcpy(temp, data, length);
118 int command = atoi(temp);
121 log->log("UDP", Log::DEBUG, "Command %i recieved", command);
124 Message *m = new Message();
125 m->to = commandMessageQueue;
126 m->message = Message::UDP_BUTTON;
127 m->parameter = command;
128 commandMessageQueue->postMessage(m);
132 void dump(unsigned char* data, USHORT size)
134 printf("Size = %u\n", size);
141 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",
142 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
143 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14], data[c+15],
144 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]),
145 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]));
153 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",
154 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
155 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14],
156 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]),
157 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]));
161 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",
162 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
163 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13],
164 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]),
165 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]));
169 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",
170 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
171 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12],
172 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]),
173 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]));
177 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",
178 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
179 data[c+8], data[c+9], data[c+10], data[c+11],
180 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]),
181 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]));
185 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c\n",
186 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
187 data[c+8], data[c+9], data[c+10],
188 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]),
189 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]));
193 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c\n",
194 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
195 data[c+8], data[c+9],
196 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]),
197 dcc(data[c+8]), dcc(data[c+9]));
201 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c\n",
202 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
204 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]),
209 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c\n",
210 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
211 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]));
215 printf(" %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c\n",
216 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6],
217 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]));
221 printf(" %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c\n",
222 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5],
223 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]));
227 printf(" %02X %02X %02X %02X %02X %c%c%c%c%c\n",
228 data[c], data[c+1], data[c+2], data[c+3], data[c+4],
229 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]));
233 printf(" %02X %02X %02X %02X %c%c%c%c\n",
234 data[c], data[c+1], data[c+2], data[c+3],
235 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]));
239 printf(" %02X %02X %02X %c%c%c\n",
240 data[c], data[c+1], data[c+2],
241 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]));
245 printf(" %02X %02X %c%c\n",
247 dcc(data[c]), dcc(data[c+1]));
261 unsigned char dcc(UCHAR c)
263 if (isspace(c)) return ' ';
264 if (isprint(c)) return c;