app4
Dependencies: mbed-rtos mbed CRC16
Fork of S5info_APP2 by
Revision 26:6ffbf3161f6f, committed 2017-03-07
- Comitter:
- ericbisson
- Date:
- Tue Mar 07 19:56:37 2017 +0000
- Parent:
- 25:d0c348c3c85d
- Commit message:
- commit apr?s validation
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
uart.h | Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Mar 07 17:25:16 2017 +0000 +++ b/main.cpp Tue Mar 07 19:56:37 2017 +0000 @@ -25,6 +25,10 @@ signed char bit_sent; //position du bit de l'octet en cours d'envoi (du MSB au LSB) 7..0 bool bTimer1 = false; +bool bitSent[320]; +int length = 0; +bool IsFinish = false; + //encodage manchester bool codeManchester(bool bit, bool clock) { @@ -34,7 +38,9 @@ //Envoie de données bit par bit void send_data() { - out = codeManchester(((trame_sent[byte_sent_pos] >> bit_sent) & 0x01), bTimer1); + bitSent[length] = codeManchester(((trame_sent[byte_sent_pos] >> bit_sent) & 0x01), bTimer1); + out = bitSent[length]; + length++; if(bTimer1) { bit_sent--; @@ -48,6 +54,7 @@ { byte_sent_pos = 0; bTimer1 = false; + IsFinish = true; LPC_TIM1->TCR = 0; // disable Timer } } @@ -61,15 +68,13 @@ while (true) { ThreadLecture.signal_wait(1); + pc.printf("Message Recu :\n\r"); for (int i = lastpos; i < messageLength; i++) { pc.printf("%x",messageBuffer[i]); - if ((i % 11) == 0 && i > 0) - { - pc.printf("\n"); - } } + pc.printf("\n\rFin Message\n\r"); lastpos = messageLength; } } @@ -173,10 +178,15 @@ trame_sent[3] = taille; //Longueur du message (Max 33 caractères) //message - for (char i=0;i<taille;i++) + printf("\n\rMessage a envoyer :"); + printf(message); + for (int i=0;i<taille;i++) { trame_sent[taille + 4] = message[i]; + } + printf(" : Fin Message\n\r"); + printf("Result CRC : %x", resultCRC); //CRC16 trame_sent[taille + 4] = (resultCRC >> 8) & 0xFF; @@ -184,6 +194,7 @@ trame_sent[taille + 6] = END; //End trame_length = taille + 7; //Longueur de la trame + } //obtention du texte @@ -191,6 +202,10 @@ { while (true) { + + IsFinish = false; + length = 0; + char text[4] = {'a','l','l','o'}; unsigned char count = 4; @@ -242,5 +257,19 @@ while(true) { + if (IsFinish == true) + { + pc.printf("\n\rBits Envoyes : "); + for (int i=0;i<length;i++) + { + pc.printf("%d:",bitSent[i]); + if(i%16 == 15) + { + pc.printf("\n\r"); + } + } + pc.printf("Fin Bits Envoyes\n\r"); + IsFinish = false; + } } }; \ No newline at end of file
--- a/uart.h Tue Mar 07 17:25:16 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -#include <vector> -#include "mbed.h" -#include "CRC16.h" -using std::vector; - -#define RETURN_EMPTYVECTOR(x) return vector<x>(); -const char PREAMBULE = 0b01010101; -const char START = 0b01111110; -const char END = 0b01111110; -const char FLAGS = 0x00; -const char MAX_LENGTH = 80; -CRC16 mycrc16; - -vector<char> uart_read(Serial& COM) -{ - vector<char> result; - - while (COM.readable()) - { - result.push_back(COM.getc()); - wait_ms(1); // 9600 bits/secondes, donc ~0.1ms par bit - } - if (result.size() > 7) - { - // Validations de base - if (result[0] != PREAMBULE || - result[1] != START || - result[2] != result.size() - 7 || - result.back() != END) - { - RETURN_EMPTYVECTOR(char); - } - - // Calcul du CRC - unsigned short currentCRC = result[result.size()-2] + result[result.size()-3]<<8; - - vector<char> charge_utile(&result[4], &result[result.size()-4]); - - if (currentCRC != mycrc16.calculateCRC16(&charge_utile[0], charge_utile.size())) - { - RETURN_EMPTYVECTOR(char); - } - - return charge_utile; - } - RETURN_EMPTYVECTOR(char); -} \ No newline at end of file