diff --git a/Tangible/tangibleInterface.c b/Tangible/tangibleInterface.c index 98e5d2f..9a138f4 100644 --- a/Tangible/tangibleInterface.c +++ b/Tangible/tangibleInterface.c @@ -11,7 +11,8 @@ #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]; @@ -20,22 +21,38 @@ bool sleep = true; //Etat de l'interface : true = mode sommeil / false = mode ev void request(uint8 rq [2]) { - uint8 com = rq [0] && 0xE0; - uint16 per = rq[0] && 0x1F; + + 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: - // ici renvoi 0b001 0000000000000 ou 0000000000001 si eveillé ou sommeil via TCP + printf("REQUEST STATUS"); break; case 2: if (per == 0x0001) - sleep = false; + { + sleep = false; + printf("MODE EVEILLE"); + } else if (per == 0x0000) - sleep = true; + { + sleep = true; + printf("MODE SOMMEIL"); + } + comMem[0] = rq[0]; comMem[1] = rq [1]; //save break; case 3: @@ -63,6 +80,8 @@ int main(void) 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)) @@ -76,10 +95,11 @@ int main(void) while(1) { - if((datasize=recvfrom(sUDP,buf,sizeof(buf),addr,&port)) == 3) - { - request(buf); - } + /* if((datasize=recvfrom(sUDP,buf,sizeof(buf),addr,&port)) == 3) */ + /* { */ + /* request(comtest); */ + /* } */ + request(comtest); } close(sTCP); close(sUDP); -- libgit2 0.21.2