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(0);
91 log->log("UDP", Log::CRIT, "Wait for packet error");
100 processRequest((UCHAR*)ds->getData(), ds->getDataLength());
105 void UDP::processRequest(UCHAR* data, int length)
107 log->log("UDP", Log::DEBUG, "Got request");
109 char* temp = new char[length + 1];
110 memcpy(temp, data, length);
112 int command = atoi(temp);
115 log->log("UDP", Log::DEBUG, "Command %i recieved", command);
118 Message *m = new Message();
119 m->to = commandMessageQueue;
120 m->message = Message::UDP_BUTTON;
121 m->parameter = command;
122 commandMessageQueue->postMessage(m);
126 void dump(unsigned char* data, USHORT size)
128 printf("Size = %u\n", size);
135 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",
136 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
137 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14], data[c+15],
138 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]),
139 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]));
147 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",
148 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
149 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14],
150 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]),
151 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]));
155 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",
156 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
157 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13],
158 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]),
159 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]));
163 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",
164 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
165 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12],
166 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]),
167 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]));
171 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",
172 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
173 data[c+8], data[c+9], data[c+10], data[c+11],
174 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]),
175 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]));
179 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c\n",
180 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
181 data[c+8], data[c+9], data[c+10],
182 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]),
183 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]));
187 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c\n",
188 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
189 data[c+8], data[c+9],
190 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]),
191 dcc(data[c+8]), dcc(data[c+9]));
195 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c\n",
196 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
198 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]),
203 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c\n",
204 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
205 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 %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],
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]));
215 printf(" %02X %02X %02X %02X %02X %02X %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],
217 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]));
221 printf(" %02X %02X %02X %02X %02X %c%c%c%c%c\n",
222 data[c], data[c+1], data[c+2], data[c+3], data[c+4],
223 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]));
227 printf(" %02X %02X %02X %02X %c%c%c%c\n",
228 data[c], data[c+1], data[c+2], data[c+3],
229 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]));
233 printf(" %02X %02X %02X %c%c%c\n",
234 data[c], data[c+1], data[c+2],
235 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]));
239 printf(" %02X %02X %c%c\n",
241 dcc(data[c]), dcc(data[c+1]));
255 unsigned char dcc(UCHAR c)
257 if (isspace(c)) return ' ';
258 if (isprint(c)) return c;