Leo Merel
/
APP4
APP4
Fork of rtos_basic by
Diff: main.cpp
- Revision:
- 17:53d4674cb37f
- Parent:
- 16:a163a7c0315b
- Child:
- 18:5c26a8f38248
diff -r a163a7c0315b -r 53d4674cb37f main.cpp --- a/main.cpp Tue Oct 23 00:56:17 2018 +0000 +++ b/main.cpp Tue Oct 23 14:24:42 2018 +0000 @@ -52,7 +52,7 @@ bool r; void int_to_bin(bool bin[8], int length){ //Fonctionne int i = 0; - while(length >0 || i<8){ + while(length >0 && i<8){ r = length%2; length/=2; bin[7-i]=r; @@ -131,7 +131,7 @@ } //CRC16 unsigned short crc = crc16(messageUtile, (int)sizeof(messageUtile)); - printf("/r/n -----------------%d-------------/r/n", crc); + printf("\r\n -----------------CRC: %d-------------\r\n", crc); int_to_bin(bin, crc); for(int i=0; i<8; i++){ *message=bin[i]; @@ -282,33 +282,39 @@ mail_box.free(f); } - if(compteur ==8){ + if((compteur ==8) && (etat ==2)){ + etat = 3; for(int i=0; i<8;i++){ - if(preambule[i]!= PREAMBULE[i]) + if((preambule[i]!= PREAMBULE[i]) && (etat !=0 )) { etat =0; - printf("------FAIL------\r\n"); + printf("\r\n------Pas le bon PREAMBULE------\r\n"); } printf("%d", preambule[i]); } printf("\r\n"); - etat = 3; - printf("-----ETAT 3-----\r\n"); + if(etat != 0) + { + printf("-----ETAT 3-----\r\n"); + } } - else if(compteur ==16) { + else if((compteur ==16) && (etat == 3)) { + etat =4; for(int i=0; i<8;i++){ - if(start[i]!= START_END[i]) + if((start[i]!= START_END[i]) && (etat != 0)) { etat =0; - printf("------FAIL------\r\n"); + printf("\r\n------Pas le bon START------\r\n"); } printf("%d", start[i]); } printf("\r\n"); - etat =4; - printf("-----ETAT 4-----\r\n"); + if(etat != 0) + { + printf("-----ETAT 4-----\r\n"); + } } - else if(compteur==24) { + else if((compteur==24) && (etat ==4)) { for(int i=0; i<8;i++){ printf("%d", flag[i]); } @@ -316,7 +322,7 @@ etat =5; printf("-----ETAT 5 -----\r\n"); } - else if(compteur==32) { + else if((compteur==32) && (etat ==5)) { longInt=0; for(int i = 0; i<8; i++) { longInt = longInt*2+longueur[i]; @@ -325,7 +331,7 @@ etat =6; printf("-----ETAT 6 -----\r\n"); } - else if(compteur==32+longInt) { + else if((compteur==32+longInt) && (etat ==6)) { for(int i=0; i<longInt;i++){ printf("%d", message[i]); } @@ -334,28 +340,31 @@ printf("-----ETAT 7-----\r\n"); } - else if(compteur == 40 +longInt) { + else if((compteur == 40 +longInt) && (etat ==7)) { + etat =8; unsigned short crc = crc16(message, (int)sizeof(message)); - printf("/r/n -----------------%d-------------/r/n", crc); - int_to_bin(checksum, crc); + printf("\r\n -----------------CRC: %d-------------\r\n", crc); + int_to_bin(bin2, crc); for(int i=0; i<8;i++){ - printf("%d", checksum[i]); - /*if(bin[i] != checksum[i]) { + printf("%d", bin2[i]); + if((bin2[i] != checksum[i]) && (etat !=0)) { etat =0; - printf("------FAIL------\r\n"); - } */ + printf("\r\n------Pas le bon CRC------\r\n"); + } } printf("\r\n"); - etat =8; - printf("-----ETAT 8-----\r\n"); + if(etat != 0) + { + printf("-----ETAT 8-----\r\n"); + } } - else if(compteur == 48 +longInt) { + else if((compteur == 48 +longInt) && (etat ==8)) { for(int i=0; i<8;i++){ if(end[i]!= START_END[i]) { etat =0; - printf("------FAIL------\r\n"); + printf("\r\n------Pas le bon END------\r\n"); } printf("%d", end[i]); }