-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.cpp
92 lines (87 loc) · 1.7 KB
/
command.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "command.h"
/* Analyse le message et effectue les actions associees
* <> id : l'identifiant associe au message
* <> header : le type de message (en-tete)
* <> args : le tableau d'entier contenant les arguments
* */
// from, id_cmd, *args, sizeArgs
void cmd(int id, int header, int *args, int size){
/* On analyse le message en fonction de son type */
switch(header)
{
case QO_BOUGER_PEIGNE:
{
int res = 0;
long int goal = 0;
if (size < 2)
sendMessage(id, E_INVALID_PARAMETERS_NUMBERS);
else
{
goal = (long int)args[0]*(long int)1023/(long int)300;
res = bougerMoteur(goal, args[1], AX18_PEIGNE_G);
if(res > 0)
{
sendMessage(id, E_MERDE_AX18);
}
res = bougerMoteur(1023 - goal, args[1], AX18_PEIGNE_D);
if(res > 0)
{
sendMessage(id, E_MERDE_AX18);
}
}
break;
}
case QO_BOUGER_TRAPPE:
{
int res = 0;
long int goal = 0;
if (size < 2)
sendMessage(id, E_INVALID_PARAMETERS_NUMBERS);
else
{
goal = (long int)args[0]*(long int)1023/(long int)300;
res = bougerMoteur(goal, args[1], AX18_TRAPPE);
if(res > 0)
{
sendMessage(id, E_MERDE_AX18);
}
}
break;
}
case QO_ID:
{
sendMessage(id, "others");
break;
}
case QO_PING:
{
sendMessage(id, "pong");
break;
}
case QO_BALAIS:
{
if (size < 1)
sendMessage(id, E_INVALID_PARAMETERS_NUMBERS);
else
{
sendMessage(id,g_balais.set_pwm(args[0]));
}
break;
}
case QO_TAPIS:
{
if (size < 1)
sendMessage(id, E_INVALID_PARAMETERS_NUMBERS);
else
{
sendMessage(id,g_tapis.actionner(args[0]));
}
break;
}
default:
{
sendMessage(id,-1);
break;
}
}
}