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();
53 int UDP::run(MessageQueue* tcommandMessageQueue)
55 if (threadIsActive()) return 1;
56 log->log("UDP", Log::DEBUG, "Starting UDP command server");
60 commandMessageQueue = tcommandMessageQueue;
61 ds = new DatagramSocket(2000);
65 log->log("UDP", Log::DEBUG, "DSock init error");
72 log->log("UDP", Log::DEBUG, "Thread start error");
77 log->log("UDP", Log::DEBUG, "UDP command server started");
81 void UDP::threadMethod()
88 retval = ds->waitforMessage(1);
92 log->log("UDP", Log::CRIT, "Wait for packet error");
102 processRequest((UCHAR*)ds->getData(), ds->getDataLength());
108 void UDP::processRequest(UCHAR* data, int length)
110 log->log("UDP", Log::DEBUG, "Got request");
112 char* temp = new char[length + 1];
113 memcpy(temp, data, length);
115 int command = atoi(temp);
118 log->log("UDP", Log::DEBUG, "Command %i recieved", command);
121 Message *m = new Message();
122 m->to = commandMessageQueue;
123 m->message = Message::UDP_BUTTON;
124 m->parameter.num = command;
125 commandMessageQueue->postMessage(m);
129 void dump(unsigned char* data, USHORT size)
131 printf("Size = %u\n", size);
138 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",
139 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
140 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14], data[c+15],
141 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]),
142 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]));
150 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",
151 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
152 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14],
153 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]),
154 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]));
158 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",
159 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
160 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13],
161 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]),
162 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]));
166 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",
167 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
168 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12],
169 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]),
170 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]));
174 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",
175 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
176 data[c+8], data[c+9], data[c+10], data[c+11],
177 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]),
178 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]));
182 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c\n",
183 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
184 data[c+8], data[c+9], data[c+10],
185 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]),
186 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]));
190 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c\n",
191 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
192 data[c+8], data[c+9],
193 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]),
194 dcc(data[c+8]), dcc(data[c+9]));
198 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c\n",
199 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
201 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]),
206 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c\n",
207 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
208 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]));
212 printf(" %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c\n",
213 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6],
214 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]));
218 printf(" %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c\n",
219 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5],
220 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]));
224 printf(" %02X %02X %02X %02X %02X %c%c%c%c%c\n",
225 data[c], data[c+1], data[c+2], data[c+3], data[c+4],
226 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]));
230 printf(" %02X %02X %02X %02X %c%c%c%c\n",
231 data[c], data[c+1], data[c+2], data[c+3],
232 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]));
236 printf(" %02X %02X %02X %c%c%c\n",
237 data[c], data[c+1], data[c+2],
238 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]));
242 printf(" %02X %02X %c%c\n",
244 dcc(data[c]), dcc(data[c+1]));
258 unsigned char dcc(UCHAR c)
260 if (isspace(c)) return ' ';
261 if (isprint(c)) return c;