Leo Merel
/
APP4
APP4
Fork of rtos_basic by
Revision 15:872151771dec, committed 2018-10-22
- Comitter:
- leomerel
- Date:
- Mon Oct 22 21:16:22 2018 +0000
- Parent:
- 14:42a7d108b134
- Child:
- 16:a163a7c0315b
- Commit message:
- allo
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Oct 21 21:54:28 2018 +0000 +++ b/main.cpp Mon Oct 22 21:16:22 2018 +0000 @@ -3,16 +3,28 @@ DigitalOut dout(p18); InterruptIn button(p5); -DigitalOut led(LED1); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); DigitalOut flash(LED4); +DigitalIn pin12(p12); int periode = 10; //10ms +int periode_reception = 30; bool PREAMBULE[] = {0,1,0,1,0,1,0,1}; bool START_END[] = {0,1,1,1,1,1,1,0}; Thread envoi_t; Thread reception_t; -Mutex mutex; -Mail<bool,16> mailbox; +Thread detection_t; + +typedef struct { + int time; + bool front; +} message_t; + +Mail<message_t,16> mail_box; +Timer timer; +int etat; bool messageUtile[64] = {0,0,1,0,1,1,1,0, 1,0,1,0,0,0,0,0, @@ -117,16 +129,26 @@ //Envoi d'une trame ---------------------------------------------------------------------------------------------------------------- void envoiTrame(){ - int length3 = sizeof(messageUtile); - bool message3[length3+6*8]; - bool manchester3[(length3+6*8)*2]; - - creationTrame(message3,length3); - convertMessageToManchester(manchester3, message3,length3+6*8); - - for(int i=0; i<sizeof(manchester3); i++){ - dout = manchester3[i]; - Thread::wait(periode); + bool app=false; + while(1){ + /*int length3 = sizeof(messageUtile); + bool message3[length3+6*8]; + bool manchester3[(length3+6*8)*2]; + + creationTrame(message3,length3); + convertMessageToManchester(manchester3, message3,length3+6*8);*/ + + if(pin12 && !app){ + bool manchester3[16] = {0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0}; + app=true; + for(int i=0; i<sizeof(manchester3); i++){ + dout = manchester3[i]; + Thread::wait(periode); + } + } + else if(!pin12 && app){ + app=false; + } } } @@ -143,18 +165,73 @@ return crc; } +bool preambule[8]; //detection du préambule void detectionPreambule() { + int compteur = 0; + int prev_time; + int t; while(1){ - printf("\r\n C'est bon \r\n"); - mutex.lock(); + osEvent evt = mail_box.get(); + if (evt.status == osEventMail) { + message_t *f = (message_t*)evt.value.p; + //printf("%d",*f); + led3 = f->front; + t = f->time; + if(f->front == 0){ + if(etat==0){ + compteur=0; + timer.start(); + printf("%d Time : %d , compteur: %d\r\n", f->front, t, compteur); + preambule[compteur] = f->front; + etat = 1; + } + else if(etat==2){ + if((t-prev_time)<=35 && (t-prev_time)>=25){ + printf("%d Time : %d , compteur: %d\r\n", f->front, t, compteur); + preambule[compteur] = f->front; + } + } + } + else if(f->front==1){ + if(etat ==1){ + if((t-prev_time)<=35 && (t-prev_time)>=25){ + printf("%d Time : %d , compteur: %d\r\n", f->front, t, compteur); + preambule[compteur] = f->front; + etat = 2; + } + else{ + etat=0; + } + } + else if(etat ==2){ + if((t-prev_time)<=35 && (t-prev_time)>=25){ + printf("%d Time : %d , compteur: %d\r\n", f->front, t, compteur); + preambule[compteur] = f->front; + } + } + + } + prev_time = t; + mail_box.free(f); + compteur++; + } + printf("----------------- compteur: %d, temps: %d\r\n", compteur, t); + if(compteur ==8){ + etat = 0; + for(int i=0; i<sizeof(preambule);i++){ + if(i>0 && i%2 == 0){ + printf(" "); + } + printf("%d", preambule[i]); + } + printf("\r\n"); + } } } //reception des trames void receptionTrames(){ - printf("\r\n C'est bon 2 \r\n"); - } //decode Manchester ------------------------------------------------------------------------------------------------------------------ @@ -168,9 +245,22 @@ //desassemblage des trames -void flip() { - led = !led; +void rise() { + led1 = !led1; //printf("\r\n C'est bon \r\n"); + message_t *a = mail_box.alloc(); + a->time = timer.read_ms();; + a->front = 0; + mail_box.put(a); +} + +void fall() { + led2 = !led2; + //printf("\r\n C'est bon \r\n"); + message_t *a = mail_box.alloc(); + a->time = timer.read_ms();; + a->front = 1; + mail_box.put(a); } @@ -231,9 +321,13 @@ } printf("\r\n"); + + envoi_t.start(envoiTrame); reception_t.start(receptionTrames); - button.rise(&flip); // attach the address of the flip function to the rising edge + detection_t.start(detectionPreambule); + button.rise(&rise); // attach the address of the flip function to the rising edge + button.fall(&fall); while(1) { // wait around, interrupts will interrupt this! flash = !flash; wait(0.25);