8 int check_parameters(unsigned char* command
, int bytes
, int correct_min
, int correct_max
)
10 if(bytes
-1 < correct_min
|| bytes
-1 > correct_max
)
14 fprintf(stderr
, "Incorrect protocol command:");
15 for(i
=0; i
<bytes
; i
++)
16 fprintf(stderr
, " %02X", command
[i
]);
17 fprintf(stderr
, "\n");
24 int run_command(client_t
* client
, unsigned char* command
, int bytes
)
29 if(check_parameters(command
, bytes
, 0, 0))
33 case 0x1: // draw pixel
34 if(check_parameters(command
, bytes
, 3, 3))
35 draw_pixel(client
, command
[1], command
[2], command
[3]);
38 case 0x2: // draw line
39 if(check_parameters(command
, bytes
, 5, 5))
40 draw_line(client
, command
[1], command
[2], command
[3], command
[4], command
[5]);
43 case 0x8: // draw rectangle
44 if(check_parameters(command
, bytes
, 5, 5))
45 draw_rectangle(client
, command
[1], command
[2], command
[3], command
[4], command
[5]);
49 if(check_parameters(command
, bytes
, 6, 6))
50 draw_box(client
, command
[1], command
[2], command
[3], command
[4], command
[5], command
[6]);
54 if(check_parameters(command
, bytes
, 7, 7))
55 move_box(client
, command
[1], command
[2], command
[3], command
[4], command
[5], command
[6], command
[7]);
58 case 0x7: // set color
59 if(check_parameters(command
, bytes
, 4, 4))
60 set_color(client
, command
[1], command
[2], command
[3], command
[4]);
64 command
[bytes
] = 0; // I don't know why
65 // printf("command -> %s\n", &command[4]);
66 if(check_parameters(command
, bytes
, 6, 100))
67 write_text(client
, command
[1], command
[2], command
[3], command
[4], &command
[5]);
71 if(check_parameters(command
, bytes
, 3, 100000))
72 new_pixmap(client
, command
[1], bytes
- 2, &command
[2]);
75 case 0x6: // draw image
76 if(check_parameters(command
, bytes
, 3, 3))
77 draw_image(client
, command
[1], command
[2], command
[3]);
80 case 0x0A: // grab events
81 if(check_parameters(command
, bytes
, 5, 5))
82 grab_events(client
, command
[1], command
[2], command
[3], command
[4], command
[5]);
85 case 0xA0: // draw 3D box (DEPRECATED)
86 if(check_parameters(command
, bytes
, 4, 4))
87 draw_led_panel(client
, command
[1], command
[2], command
[3], command
[4]);
90 case 0xA1: // draw 3D box
91 if(check_parameters(command
, bytes
, 5, 5))
92 draw_panel(client
, command
[1], command
[2], command
[3], command
[4], command
[5]);
96 check_parameters(command
, bytes
, 2, 1);