Mostly minor fixes up until version 0.8.10.
[irreco.git] / irtrans / irserver / src / common / network.h
blob7c0378511e9ac88b5506c02c9bda3d59ad8d9d0d
1 /*
2 * Copyright (c) 2007, IRTrans GmbH
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of IRTrans GmbH nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY IRTrans GmbH ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL IRTrans GmbH BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #define PROTOCOL_VERSION 209
32 #define MAX_IR_DEVICES 256
35 #define COMMAND_SEND 1
36 #define COMMAND_LRNREM 2
37 #define COMMAND_LRNTIM 3
38 #define COMMAND_LRNCOM 4
39 #define COMMAND_CLOSE 5
40 #define COMMAND_STATUS 6
41 #define COMMAND_RESEND 7
42 #define COMMAND_LRNRAW 8
43 #define COMMAND_LRNRPT 9
44 #define COMMAND_LRNTOG 10
45 #define COMMAND_SETSTAT 11
46 #define COMMAND_LRNLONG 12
47 #define COMMAND_LRNRAWRPT 13
48 #define COMMAND_RELOAD 14
49 #define COMMAND_LCD 15
50 #define COMMAND_LEARNSTAT 16
51 #define COMMAND_TEMP 17
52 #define COMMAND_GETREMOTES 18
53 #define COMMAND_GETCOMMANDS 19
54 #define COMMAND_STORETRANS 20
55 #define COMMAND_LOADTRANS 21
56 #define COMMAND_SAVETRANS 22
57 #define COMMAND_FLASHTRANS 23
58 #define COMMAND_FUNCTIONS 24
59 #define COMMAND_TESTCOM 25
60 #define COMMAND_LONGSEND 26
61 #define COMMAND_SHUTDOWN 27
62 #define COMMAND_SENDCCF 28
63 #define COMMAND_LCDINIT 29
64 #define COMMAND_SETSWITCH 30
65 #define COMMAND_STATUSEX 31
66 #define COMMAND_RESET 32
67 #define COMMAND_DEVICEDATA 33
68 #define COMMAND_STARTCLOCK 34
69 #define COMMAND_LCDSTATUS 35
70 #define COMMAND_FUNCTIONEX 36
71 #define COMMAND_MCE_CHARS 37
72 #define COMMAND_SUSPEND 38
73 #define COMMAND_RESUME 39
74 #define COMMAND_DELETECOM 40
75 #define COMMAND_EMPTY 41
76 #define COMMAND_SETSTAT2 42
77 #define COMMAND_STATUSEXN 43
78 #define COMMAND_BRIGHTNESS 44
79 #define COMMAND_DEFINECHAR 45
80 #define COMMAND_STOREIRDB 46
81 #define COMMAND_FLASHIRDB 47
82 #define COMMAND_SAVEIRDB 48
83 #define COMMAND_LOADIRDB 49
84 #define COMMAND_LED 50
85 #define COMMAND_TRANSFILE 51
86 #define COMMAND_IRDBFILE 52
87 #define COMMAND_LISTBUS 53
88 #define COMMAND_SENDCCFSTR 54
89 #define COMMAND_LEARNDIRECT 55
90 #define COMMAND_TESTCOMEX 56
91 #define COMMAND_SENDCCFSTRS 57
92 #define COMMAND_SETSTATEX 58
93 #define COMMAND_DELETEREM 59
94 #define COMMAND_READ_ANALOG 60
95 #define COMMAND_RS232_SEND 61
96 #define COMMAND_SENDCCFLONG 62
98 #define COMMAND_ASCII 65
101 #define COMMAND_SENDSTRING 's' // 115
103 #define STATUS_MESSAGE 1
104 #define STATUS_TIMING 2
105 #define STATUS_DEVICEMODE 3
106 #define STATUS_RECEIVE 4
107 #define STATUS_LEARN 5
108 #define STATUS_REMOTELIST 6
109 #define STATUS_COMMANDLIST 7
110 #define STATUS_TRANSLATE 8
111 #define STATUS_FUNCTION 9
112 #define STATUS_DEVICEMODEEX 10
113 #define STATUS_DEVICEDATA 11
114 #define STATUS_LCDDATA 12
115 #define STATUS_FUNCTIONEX 13
116 #define STATUS_DEVICEMODEEXN 14
117 #define STATUS_IRDB 15
118 #define STATUS_TRANSLATIONFILE 16
119 #define STATUS_IRDBFILE 17
120 #define STATUS_BUSLIST 18
121 #define STATUS_LEARNDIRECT 19
122 #define STATUS_IRDBFLASH 20
123 #define STATUS_ANALOGINPUT 21
125 #define STATUS_ASCII 65
127 #define FILE_MODE_SAVE 0
128 #define FILE_MODE_SAVEAS 1
129 #define FILE_MODE_OVERWRITE 2
132 #pragma pack(1)
134 typedef struct {
135 uint32_t clientid;
136 int16_t statuslen;
137 int16_t statustype;
138 int16_t adress;
139 uint8_t align[2];
140 IRDATA ird;
141 } IRDATA_BUFFER;
143 typedef struct {
144 uint8_t mode;
145 uint8_t time_cnt;
146 uint8_t ir_repeat;
147 uint8_t repeat_pause;
148 uint16_t pause_len[TIME_LEN];
149 uint16_t pulse_len[TIME_LEN];
150 uint8_t data[CODE_LEN];
151 } TIMINGDATA;
153 typedef struct {
154 uint8_t netcommand;
155 uint8_t mode;
156 uint16_t timeout;
157 int32_t adress;
158 int8_t remote[80];
159 int8_t command[20];
160 uint8_t trasmit_freq;
161 } OLD_NETWORKCOMMAND;
164 typedef struct {
165 uint8_t netcommand;
166 uint8_t mode;
167 uint8_t lcdcommand;
168 uint8_t timeout;
169 int32_t adress;
170 uint8_t wid;
171 uint8_t hgt;
172 int8_t framebuffer[200];
173 } OLD_LCDCOMMAND;
176 typedef struct {
177 uint8_t netcommand;
178 uint8_t mode;
179 uint16_t timeout;
180 int32_t adress;
181 int32_t protocol_version;
182 int8_t remote[80];
183 int8_t command[20];
184 uint8_t trasmit_freq;
185 } NETWORKCOMMAND;
187 typedef struct {
188 uint8_t netcommand;
189 uint8_t mode;
190 uint16_t timeout;
191 int32_t adress;
192 int32_t protocol_version;
193 int8_t hotremote[80];
194 int8_t hotcommand[20];
195 int8_t hotremote_2[80];
196 int8_t hotcommand_2[20];
197 int32_t targetmask;
198 uint8_t extmode;
199 uint8_t extmode_2;
200 uint8_t extmode_3;
201 uint8_t extmode_4;
202 uint8_t wakeup_mac[6];
203 } MODUSCOMMAND;
206 // Adress:
207 // xxxx ffff Netmask
208 // xxx1 xxxx Netmask active Flag
209 // xxx6 xxxx LED select
210 // x7f8 xxxx Bus Select
211 // 38xx xxxx Extended LED select
212 // 8xxx xxxx Extended LED enable
213 // 4xxx xxxx Bus Broadcast
215 // xxxxxxxx xxxxxxxx 11111111 11111111 Netmask (wie bisher genutzt)
216 // xxxxxxxx xxxxxxx1 xxxxxxxx xxxxxxxx Netmask aktiv (wie bisher genutzt)
217 // xxxxxxxx xxxxx11x xxxxxxxx xxxxxxxx LED Auswahl (intern / extern)
218 // xxxxx111 11111xxx xxxxxxxx xxxxxxxx Bus Auswahl (mehrere USB / LAN Module; max: 0-255 = 256 Stück)
219 // 1x111xxx xxxxxxxx xxxxxxxx xxxxxxxx Auswahl mehrer externer LEDs - bis zu 8
220 // x1xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx Broadcast über alle USB / LAN Module
223 typedef struct {
224 uint32_t clientid;
225 int16_t statuslen;
226 int16_t statustype;
227 int8_t memsize[32];
228 int8_t flashsize[8];
229 int8_t remotes[8];
230 int8_t commands[8];
231 int8_t actions[8];
232 } IRDB_FLASHINFO;
235 typedef struct {
236 uint8_t netcommand;
237 uint8_t mode;
238 uint16_t timeout;
239 int32_t adress;
240 int32_t protocol_version;
241 uint8_t len;
242 uint8_t align;
243 uint16_t align2;
244 uint8_t data[256];
245 } SERCOMMAND;
248 typedef struct {
249 uint8_t netcommand;
250 uint8_t mode;
251 uint16_t timeout;
252 int32_t adress;
253 int32_t protocol_version;
254 uint16_t ccf_data[256];
255 } CCFCOMMAND;
257 typedef struct {
258 uint8_t netcommand;
259 uint8_t mode;
260 uint16_t timeout;
261 int32_t adress;
262 int32_t protocol_version;
263 uint16_t ccf_data[450];
264 } LONGCCFCOMMAND;
267 typedef struct {
268 uint8_t netcommand;
269 uint8_t mode;
270 uint16_t timeout;
271 int32_t adress;
272 int32_t protocol_version;
273 char ccf_data[1100];
274 byte repeatmode;
275 } CCFSTRINGCOMMAND;
277 typedef struct {
278 uint8_t netcommand;
279 uint8_t mode;
280 uint16_t timeout;
281 int32_t adress;
282 int32_t protocol_version;
283 char ccf_data[980];
284 byte repeatmode;
285 } CCFSTRINGCOMMAND_SHORT;
288 typedef struct {
289 uint8_t netcommand;
290 uint8_t mode;
291 uint8_t lcdcommand;
292 uint8_t timeout;
293 int32_t adress;
294 int32_t protocol_version;
295 uint8_t wid;
296 uint8_t hgt;
297 int8_t framebuffer[200];
298 } LCDCOMMAND;
301 typedef struct {
302 uint8_t netcommand;
303 uint8_t mode;
304 uint16_t timeout;
305 int32_t adress;
306 int32_t protocol_version;
307 int32_t number;
308 uint8_t setup;
309 uint8_t type;
310 uint8_t accelerator_timeout;
311 uint8_t accelerator_repeat;
312 uint16_t wait_timeout;
313 uint8_t remote_num;
314 uint8_t group_num;
315 int8_t remote[80];
316 int8_t command[20];
317 int32_t source_mask;
318 int32_t target_mask;
319 uint8_t multi_num;
320 uint8_t include_names;
321 uint8_t dummy[2];
322 } TRANSLATECOMMAND;
325 typedef struct {
326 int32_t send_mask;
327 uint8_t device_mode;
328 uint8_t extended_mode;
329 uint8_t extended_mode2;
330 uint8_t align;
331 uint16_t switch_mode;
332 uint16_t align2;
333 uint32_t features;
334 uint16_t align3;
335 int8_t version[10];
336 int8_t remote[80];
337 int8_t command[20];
338 } MODELINE;
340 typedef struct {
341 int32_t send_mask;
342 uint8_t device_mode;
343 uint8_t extended_mode;
344 uint8_t extended_mode2;
345 uint8_t align;
346 uint16_t switch_mode;
347 uint16_t switch_mode2;
348 uint32_t features;
349 uint8_t extended_mode3;
350 uint8_t extended_mode4;
351 int8_t version[10];
352 int8_t remote[80];
353 int8_t command[20];
354 int8_t remote2[80];
355 int8_t command2[20];
356 } MODELINEN;
358 typedef struct {
359 uint32_t clientid;
360 int16_t statuslen;
361 int16_t statustype;
362 int16_t adress;
363 uint8_t align[2];
364 int8_t data[32768];
365 } STATUSBUFFER;
367 typedef struct {
368 uint32_t clientid;
369 int16_t statuslen;
370 int16_t statustype;
371 int16_t adress;
372 uint8_t align[2];
373 int8_t data[256];
374 } DATABUFFER;
376 typedef struct {
377 uint32_t clientid;
378 int16_t statuslen;
379 int16_t statustype;
380 int32_t serno;
381 int32_t functions;
382 } FUNCTIONBUFFER;
384 typedef struct {
385 uint32_t clientid;
386 int16_t statuslen;
387 int16_t statustype;
388 ANALOG_INPUTS inputs;
389 } ANALOGBUFFER;
391 typedef struct {
392 uint32_t clientid;
393 int16_t statuslen;
394 int16_t statustype;
395 int32_t serno;
396 int32_t functions;
397 int8_t version[8];
398 } FUNCTIONBUFFEREX;
401 typedef struct {
402 uint32_t target_mask;
403 uint32_t source_mask;
404 int8_t name[80];
405 } REMOTELINE;
408 typedef struct {
409 uint32_t clientid;
410 int16_t statuslen;
411 int16_t statustype;
412 int16_t offset;
413 int16_t count_buffer;
414 int16_t count_total;
415 int16_t count_remaining;
416 REMOTELINE remotes[40];
417 } REMOTEBUFFER;
419 typedef struct {
420 uint32_t clientid;
421 int16_t statuslen;
422 int16_t statustype;
423 int16_t offset;
424 int16_t count_buffer;
425 int16_t count_total;
426 int16_t count_remaining;
427 int8_t commands[200][20];
428 } COMMANDBUFFER;
430 typedef struct {
431 uint32_t clientid;
432 int16_t statuslen;
433 int16_t statustype;
434 int16_t offset;
435 int16_t count_buffer;
436 int16_t count_total;
437 int16_t count_remaining;
438 TRANSLATECOMMAND trdata[30];
439 } TRANSLATEBUFFER;
442 typedef struct {
443 uint8_t netcommand;
444 uint8_t mode;
445 uint16_t timeout;
446 int32_t adress;
447 int32_t protocol_version;
448 int32_t number;
449 uint8_t relais;
450 uint8_t type;
451 uint8_t action_type;
452 uint8_t action_len;
453 int32_t remote_num;
454 int32_t command_num;
455 uint32_t ip;
456 uint16_t port;
457 uint16_t align;
458 int8_t remote[80];
459 int8_t command[20];
460 uint8_t action[256];
461 } IRDBCOMMAND;
463 typedef struct {
464 uint8_t netcommand;
465 uint8_t mode;
466 uint16_t timeout;
467 int32_t adress;
468 int32_t protocol_version;
469 int32_t number;
470 uint8_t active;
471 uint8_t type;
472 uint8_t dummy[2];
473 uint8_t default_action[100];
474 uint8_t err_status[20];
475 uint8_t ok_status[20];
476 uint8_t inputmode[4];
477 uint8_t min[4];
478 uint8_t max[4];
479 uint8_t hyst[4];
480 uint8_t minledsel[4];
481 uint8_t maxledsel[4];
482 int32_t minmask[4];
483 int32_t maxmask[4];
484 int8_t minremote[4][80];
485 int8_t mincommand[4][50];
486 int8_t maxremote[4][80];
487 int8_t maxcommand[4][50];
488 } IRDBHEADER;
492 typedef struct {
493 uint32_t clientid;
494 int16_t statuslen;
495 int16_t statustype;
496 int16_t offset;
497 int16_t count_buffer;
498 int16_t count_total;
499 int16_t count_remaining;
500 IRDBCOMMAND dbdata[12];
501 } IRDBBUFFER;
503 typedef struct {
504 uint32_t clientid;
505 int16_t statuslen;
506 int16_t statustype;
507 int16_t offset;
508 int16_t count_buffer;
509 int16_t count_total;
510 int16_t count_remaining;
511 IRDBHEADER header;
512 } IRDBHEADERBUFFER;
514 typedef struct {
515 uint32_t clientid;
516 int16_t statuslen;
517 int16_t statustype;
518 int16_t adress;
519 uint8_t align[2];
520 MODELINE stat[16];
521 } NETWORKMODE;
523 typedef struct {
524 uint32_t clientid;
525 int16_t statuslen;
526 int16_t statustype;
527 int16_t adress;
528 uint8_t align;
529 uint8_t count;
530 uint8_t dev_adr[8];
531 MODELINE stat[8][16];
532 } NETWORKMODEEX;
534 typedef struct {
535 uint32_t clientid;
536 int16_t statuslen;
537 int16_t statustype;
538 int16_t adress;
539 uint8_t offset;
540 uint8_t count;
541 uint8_t dev_adr[8];
542 MODELINEN stat[8][16];
543 } NETWORKMODEEXN;
545 typedef struct {
546 uint32_t clientid;
547 int16_t statuslen;
548 int16_t statustype;
549 int16_t adress;
550 uint16_t netstatus;
551 uint16_t statuslevel;
552 uint8_t align[2];
553 int8_t message[256];
554 } NETWORKSTATUS;
556 typedef struct {
557 uint32_t clientid;
558 int16_t statuslen;
559 int16_t statustype;
560 int16_t adress;
561 uint16_t netstatus;
562 uint16_t statuslevel;
563 uint8_t align;
564 uint8_t virtual_col;
565 uint8_t numcol;
566 uint8_t numrows;
567 uint8_t clockflag;
568 } NETWORKLCDSTAT;
570 typedef struct {
571 uint32_t clientid;
572 int16_t statuslen;
573 int16_t statustype;
574 int16_t adress;
575 uint8_t align[2];
576 TIMINGDATA timing;
577 } NETWORKTIMING;
579 typedef struct {
580 uint32_t clientid;
581 int16_t statuslen;
582 int16_t statustype;
583 int16_t adress;
584 uint16_t command_num;
585 int8_t remote[80];
586 int8_t command[20];
587 int8_t data[200];
588 } NETWORKRECV;
591 typedef struct {
592 uint32_t clientid;
593 int16_t statuslen;
594 int16_t statustype;
595 int16_t adress;
596 int16_t learnok;
597 int8_t remote[80];
598 int16_t num_timings;
599 int16_t num_commands;
600 int8_t received[CODE_LEN];
601 } NETWORKLEARNSTAT;
604 typedef struct {
605 SOCKET fd;
606 int32_t type;
607 int32_t mode;
608 uint32_t clientid;
609 uint32_t callno;
610 int8_t ip[20];
611 WSAEVENT event;
612 FILE *fp;
613 char filename[84];
614 int32_t timing;
615 uint8_t resend_load;
616 IRDATA ird;
617 NETWORKLEARNSTAT learnstatus;
618 int8_t restdata[sizeof (LCDCOMMAND)];
619 int32_t restlen;
620 int32_t restread;
621 } NETWORKCLIENT;
624 #define MODE_ASCII 1
627 #define TCP_PORT 21000
628 #define IRTRANS_PORT 21000
629 #define LIRC_PORT 8765
630 #define UDP_PORT 21000
631 #define WEB_PORT 80
632 #define ALTERNATE_WEB 8080
633 #define XAP_PORT 3639
636 #ifdef WIN32
637 #define CLIENT_COUNT MAXIMUM_WAIT_OBJECTS - 3
638 #endif
640 #ifdef LINUX
641 #define CLIENT_COUNT 64
642 #endif