Commit bb11e508671cbd520d9373b8756fc7ba69cbcc06
1 parent
df742988
tangible test
Showing
1 changed file
with
31 additions
and
11 deletions
Show diff stats
Tangible/tangibleInterface.c
@@ -11,7 +11,8 @@ | @@ -11,7 +11,8 @@ | ||
11 | 11 | ||
12 | #define MAC_SIZE 6 | 12 | #define MAC_SIZE 6 |
13 | #define IPV4_SIZE 4 | 13 | #define IPV4_SIZE 4 |
14 | - | 14 | +bool isComMem = false; |
15 | +uint8 comMem[2]; //Commande en mémoire | ||
15 | SOCKET sUDP=0; | 16 | SOCKET sUDP=0; |
16 | SOCKET sTCP=1; | 17 | SOCKET sTCP=1; |
17 | uint8_t addr[IPV4_SIZE]; | 18 | uint8_t addr[IPV4_SIZE]; |
@@ -20,22 +21,38 @@ bool sleep = true; //Etat de l'interface : true = mode sommeil / false = mode ev | @@ -20,22 +21,38 @@ bool sleep = true; //Etat de l'interface : true = mode sommeil / false = mode ev | ||
20 | 21 | ||
21 | void request(uint8 rq [2]) | 22 | void request(uint8 rq [2]) |
22 | { | 23 | { |
23 | - uint8 com = rq [0] && 0xE0; | ||
24 | - uint16 per = rq[0] && 0x1F; | 24 | + |
25 | + if (!isComMem) //Aucune commande en mémoire | ||
26 | + { | ||
27 | + isComMem = true; | ||
28 | + comMem[0] = rq[0]; comMem[1] = rq [1]; | ||
29 | + } | ||
30 | + | ||
31 | + uint8 com = rq [0] && 0xE0; // récupération de la commande | ||
32 | + uint16 per = rq[0] && 0x1F; // récupération du pourcentage | ||
25 | per = per << 8; | 33 | per = per << 8; |
26 | per += rq[1]; | 34 | per += rq[1]; |
27 | - | 35 | + per = (100*per)/8192; //2^13 = 100 % |
36 | + | ||
28 | switch(com) | 37 | switch(com) |
29 | { | 38 | { |
39 | + | ||
30 | case 0: | 40 | case 0: |
31 | - // ici renvoi 0b001 0000000000000 ou 0000000000001 si eveillé ou sommeil via TCP | 41 | + printf("REQUEST STATUS"); |
32 | break; | 42 | break; |
33 | 43 | ||
34 | case 2: | 44 | case 2: |
35 | if (per == 0x0001) | 45 | if (per == 0x0001) |
36 | - sleep = false; | 46 | + { |
47 | + sleep = false; | ||
48 | + printf("MODE EVEILLE"); | ||
49 | + } | ||
37 | else if (per == 0x0000) | 50 | else if (per == 0x0000) |
38 | - sleep = true; | 51 | + { |
52 | + sleep = true; | ||
53 | + printf("MODE SOMMEIL"); | ||
54 | + } | ||
55 | + comMem[0] = rq[0]; comMem[1] = rq [1]; //save | ||
39 | break; | 56 | break; |
40 | 57 | ||
41 | case 3: | 58 | case 3: |
@@ -63,6 +80,8 @@ int main(void) | @@ -63,6 +80,8 @@ int main(void) | ||
63 | uint8 buf[2]; | 80 | uint8 buf[2]; |
64 | uint16 datasize; | 81 | uint16 datasize; |
65 | 82 | ||
83 | + | ||
84 | + uint8 comtest[2] = {0b00000000,0b00000000} | ||
66 | init_printf(); | 85 | init_printf(); |
67 | ethernet_init(mac,ip,gateway,mask); | 86 | ethernet_init(mac,ip,gateway,mask); |
68 | if (!socket(sUDP,Sn_MR_UDP,2020,0)) | 87 | if (!socket(sUDP,Sn_MR_UDP,2020,0)) |
@@ -76,10 +95,11 @@ int main(void) | @@ -76,10 +95,11 @@ int main(void) | ||
76 | 95 | ||
77 | while(1) | 96 | while(1) |
78 | { | 97 | { |
79 | - if((datasize=recvfrom(sUDP,buf,sizeof(buf),addr,&port)) == 3) | ||
80 | - { | ||
81 | - request(buf); | ||
82 | - } | 98 | + /* if((datasize=recvfrom(sUDP,buf,sizeof(buf),addr,&port)) == 3) */ |
99 | + /* { */ | ||
100 | + /* request(comtest); */ | ||
101 | + /* } */ | ||
102 | + request(comtest); | ||
83 | } | 103 | } |
84 | close(sTCP); | 104 | close(sTCP); |
85 | close(sUDP); | 105 | close(sUDP); |