tangibleInterface.c
1.92 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include "serial.h"
#include "ethernet.h"
#include "w5100.h"
#include "socket.h"
#define MAC_SIZE 6
#define IPV4_SIZE 4
bool isComMem = false;
uint8 comMem[2]; //Commande en mémoire
SOCKET sUDP=0;
SOCKET sTCP=1;
uint8_t addr[IPV4_SIZE];
uint16_t port;
bool sleep = true; //Etat de l'interface : true = mode sommeil / false = mode eveillé
void request(uint8 rq [2])
{
if (!isComMem) //Aucune commande en mémoire
{
isComMem = true;
comMem[0] = rq[0]; comMem[1] = rq [1];
}
uint8 com = rq [0] && 0xE0; // récupération de la commande
uint16 per = rq[0] && 0x1F; // récupération du pourcentage
per = per << 8;
per += rq[1];
per = (100*per)/8192; //2^13 = 100 %
switch(com)
{
case 0:
printf("REQUEST STATUS");
break;
case 2:
if (per == 0x0001)
{
sleep = false;
printf("MODE EVEILLE");
}
else if (per == 0x0000)
{
sleep = true;
printf("MODE SOMMEIL");
}
comMem[0] = rq[0]; comMem[1] = rq [1]; //save
break;
case 3:
break;
case 4:
break;
case 5:
break;
}
}
int main(void)
{
uint8_t mac[MAC_SIZE] = {0xA0,0xBD,0xCD,0xDD,0xED,0xFD};
uint8_t ip[IPV4_SIZE] = {172,26,145,205};
uint8_t gateway[4] = {172,26,145,254};
uint8_t mask[4] = {255,255,255,0};
uint8 buf[2];
uint16 datasize;
uint8 comtest[2] = {0b00000000,0b00000000}
init_printf();
ethernet_init(mac,ip,gateway,mask);
if (!socket(sUDP,Sn_MR_UDP,2020,0))
{
return -1;
}
if (!socket(sTCP,Sn_MR_TCP,2020,0))
{
return -1;
}
while(1)
{
/* if((datasize=recvfrom(sUDP,buf,sizeof(buf),addr,&port)) == 3) */
/* { */
/* request(comtest); */
/* } */
request(comtest);
}
close(sTCP);
close(sUDP);
return 0;
}