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
23 //void dump(unsigned char* data, USHORT size);
24 //unsigned char dcc(UCHAR c);
28 log = Log::getInstance();
39 if (!initted) return 1;
40 if (threadIsActive()) threadCancel();
47 int UDP::run(MessageQueue* tcommandMessageQueue)
49 if (threadIsActive()) return 1;
50 log->log("UDP", Log::DEBUG, "Starting UDP command server");
54 commandMessageQueue = tcommandMessageQueue;
55 ds = new DatagramSocket(2000);
59 log->log("UDP", Log::DEBUG, "DSock init error");
66 log->log("UDP", Log::DEBUG, "Thread start error");
71 log->log("UDP", Log::DEBUG, "UDP command server started");
75 void UDP::threadMethod()
83 retval = ds->waitforMessage(0);
85 log->log("UDP", Log::DEBUG, "Wait for packet");
87 retval = ds->waitforMessage(1);
92 log->log("UDP", Log::CRIT, "Wait for packet error");
101 processRequest((UCHAR*)ds->getData(), ds->getDataLength());
106 void UDP::processRequest(UCHAR* data, int length)
108 log->log("UDP", Log::DEBUG, "Got request");
110 char* temp = new char[length + 1];
111 memcpy(temp, data, length);
113 int command = atoi(temp);
116 log->log("UDP", Log::DEBUG, "Command %i recieved", command);
119 Message *m = new Message();
120 m->to = commandMessageQueue;
121 m->message = Message::UDP_BUTTON;
122 m->parameter = command;
123 commandMessageQueue->postMessage(m);
127 void dump(unsigned char* data, USHORT size)
129 printf("Size = %u\n", size);
136 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",
137 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
138 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14], data[c+15],
139 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]),
140 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]));
148 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",
149 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
150 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14],
151 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]),
152 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]));
156 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",
157 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
158 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13],
159 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]),
160 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]));
164 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",
165 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
166 data[c+8], data[c+9], data[c+10], data[c+11], data[c+12],
167 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]),
168 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]));
172 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",
173 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
174 data[c+8], data[c+9], data[c+10], data[c+11],
175 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]),
176 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]));
180 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c\n",
181 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
182 data[c+8], data[c+9], data[c+10],
183 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]),
184 dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]));
188 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c\n",
189 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
190 data[c+8], data[c+9],
191 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]),
192 dcc(data[c+8]), dcc(data[c+9]));
196 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c\n",
197 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
199 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]),
204 printf(" %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c\n",
205 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7],
206 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]));
210 printf(" %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c\n",
211 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6],
212 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]));
216 printf(" %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c\n",
217 data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5],
218 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]));
222 printf(" %02X %02X %02X %02X %02X %c%c%c%c%c\n",
223 data[c], data[c+1], data[c+2], data[c+3], data[c+4],
224 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]));
228 printf(" %02X %02X %02X %02X %c%c%c%c\n",
229 data[c], data[c+1], data[c+2], data[c+3],
230 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]));
234 printf(" %02X %02X %02X %c%c%c\n",
235 data[c], data[c+1], data[c+2],
236 dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]));
240 printf(" %02X %02X %c%c\n",
242 dcc(data[c]), dcc(data[c+1]));
256 unsigned char dcc(UCHAR c)
258 if (isspace(c)) return ' ';
259 if (isprint(c)) return c;