Code carte émettrice (WRonski et Deleau)
Dependencies: mbed BufferedSerial SX1276GenericLib HTU21D
Revision 13:7b3468fd31be, committed 2019-04-14
- Comitter:
- Adam06
- Date:
- Sun Apr 14 16:04:40 2019 +0000
- Parent:
- 12:f3bdcf35751e
- Commit message:
- emetteur
Changed in this revision
diff -r f3bdcf35751e -r 7b3468fd31be BufferedSerial.lib --- a/BufferedSerial.lib Thu Feb 14 10:34:00 2019 +0000 +++ b/BufferedSerial.lib Sun Apr 14 16:04:40 2019 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/sam_grove/code/BufferedSerial/#a0d37088b405 +https://mbed.org/users/sam_grove/code/BufferedSerial/#7e5e866edd3d
diff -r f3bdcf35751e -r 7b3468fd31be SX1276GenericPingPong/GenericPingPong.cpp --- a/SX1276GenericPingPong/GenericPingPong.cpp Thu Feb 14 10:34:00 2019 +0000 +++ b/SX1276GenericPingPong/GenericPingPong.cpp Sun Apr 14 16:04:40 2019 +0000 @@ -54,6 +54,9 @@ #define RX_TIMEOUT_VALUE 3500 // in ms +#define IDENTIFIANT1 0x02 +#define IDENTIFIANT2 0x03 + //#define BUFFER_SIZE 32 // Define the payload size here #define BUFFER_SIZE 64 // Define the payload size here @@ -88,9 +91,8 @@ */ SX1276Generic *Radio; - -const uint8_t PingMsg[] = { 'A', 'A', 'A', 'A', 'P', 'I', 'N', 'G'};// "PING"; -const uint8_t PongMsg[] = { 'B', 'B', 'B', 'B', 'P', 'O', 'N', 'G'};// "PONG"; +const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING"; +const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG"; uint16_t BufferSize = BUFFER_SIZE; uint8_t *Buffer; @@ -219,156 +221,38 @@ Radio->Rx( RX_TIMEOUT_VALUE ); - HTU21D temphumid(PB_14, PB_13); //Temp humid sensor || SDA, SCL + HTU21D temphumid(PB_14, PB_13); //temperaturevalue humid sensor || SDA, SCL + int sample_ctemp; + int sample_humid; + + while( 1 ) { #ifdef TARGET_STM32L4 WatchDogUpdate(); #endif - - switch( State ) + while(1) { - case RX: - *led3 = 0; - if( isMaster == true ) - { - if( BufferSize > 0 ) - { - if( memcmp(Buffer, PongMsg, sizeof(PongMsg)) == 0 ) - { - *led = !*led; - dprintf( "...Pong" ); - // Send the next PING frame - memcpy(Buffer, PingMsg, sizeof(PingMsg)); - // We fill the buffer with numbers for the payload - for( i = sizeof(PingMsg); i < BufferSize; i++ ) - { - Buffer[i] = i - sizeof(PingMsg); - } - wait_ms( 10 ); - Radio->Send( Buffer, BufferSize ); - } - else if( memcmp(Buffer, PingMsg, sizeof(PingMsg)) == 0 ) - { // A master already exists then become a slave - dprintf( "...Ping" ); - *led = !*led; - isMaster = false; - // Send the next PONG frame - memcpy(Buffer, PongMsg, sizeof(PongMsg)); - // We fill the buffer with numbers for the payload - for( i = sizeof(PongMsg); i < BufferSize; i++ ) - { - Buffer[i] = i - sizeof(PongMsg); - } - wait_ms( 10 ); - Radio->Send( Buffer, BufferSize ); - } - else // valid reception but neither a PING or a PONG message - { // Set device as master ans start again - isMaster = true; - Radio->Rx( RX_TIMEOUT_VALUE ); - } - } - } - else - { - if( BufferSize > 0 ) - { - if( memcmp(Buffer, PingMsg, sizeof(PingMsg)) == 0 ) - { - *led = !*led; - dprintf( "...Ping" ); - // Send the reply to the PING string - memcpy(Buffer, PongMsg, sizeof(PongMsg)); - // We fill the buffer with numbers for the payload - int sample_ctemp = temphumid.sample_ctemp(); - printf("Temp = %d\n\r", sample_ctemp); - char data[BUFFER_SIZE -8]; - sprintf(data,"%d",sample_ctemp); - for( i = 0; i < sizeof(data); i++ ) - { - Buffer[i+sizeof(PongMsg)] = data[i]; - } - wait_ms( 10 ); - Radio->Send( Buffer, BufferSize ); - } - else // valid reception but not a PING as expected - { // Set device as master and start again - //isMaster = true; - Radio->Rx( RX_TIMEOUT_VALUE ); - } - } - } - State = LOWPOWER; - break; - case TX: - *led3 = 1; - if( isMaster == true ) - { - dprintf("Ping..." ); - } - else - { - dprintf("Pong..." ); - } - Radio->Rx( RX_TIMEOUT_VALUE ); - State = LOWPOWER; - break; - case RX_TIMEOUT: - if( isMaster == true ) - { - // Send the next PING frame - memcpy(Buffer, PingMsg, sizeof(PingMsg)); - for( i = sizeof(PingMsg); i < BufferSize; i++ ) - { - Buffer[i] = i - sizeof(PingMsg); - } - wait_ms( 10 ); - Radio->Send( Buffer, BufferSize ); - } - else - { - Radio->Rx( RX_TIMEOUT_VALUE ); - } - State = LOWPOWER; - break; - case RX_ERROR: - // We have received a Packet with a CRC error, send reply as if packet was correct - if( isMaster == true ) - { - // Send the next PING frame - memcpy(Buffer, PingMsg, sizeof(PingMsg)); - for( i = 4; i < BufferSize; i++ ) - { - Buffer[i] = i - 4; - } - wait_ms( 10 ); - Radio->Send( Buffer, BufferSize ); - } - else - { - // Send the next PONG frame - memcpy(Buffer, PongMsg, sizeof(PongMsg)); - for( i = sizeof(PongMsg); i < BufferSize; i++ ) - { - Buffer[i] = i - sizeof(PongMsg); - } - wait_ms( 10 ); - Radio->Send( Buffer, BufferSize ); - } - State = LOWPOWER; - break; - case TX_TIMEOUT: - Radio->Rx( RX_TIMEOUT_VALUE ); - State = LOWPOWER; - break; - case LOWPOWER: - sleep(); - break; - default: - State = LOWPOWER; - break; - } + sample_ctemp = temphumid.sample_ctemp(); //valeur de la température en dégrés celsius + sample_humid = temphumid.sample_humid(); //valeur de l'humidité + memcpy(Buffer, PingMsg, sizeof(PingMsg)); + uint8_t temperaturevalue = sample_ctemp; + uint8_t humidityvalue = sample_humid; + for(int i = sizeof(PingMsg); i < BufferSize; i++) //on rempli le buffer + { + Buffer[i] = i - sizeof(PingMsg); + } + Buffer[2] = IDENTIFIANT1; //les identifiants servent à indentifier la carte client et serveur + Buffer[3] = IDENTIFIANT2; + Buffer[5]=temperaturevalue; //on met au bon endroit du buffer les valeurs des capteurs + Buffer[6]=humidityvalue; + wait(0.01); + Radio->Send(Buffer, BufferSize); //envoi du message + dprintf("La Temperature est de : %d degres celsius",temperaturevalue); + dprintf("L'Humidite est de : %d ", humidityvalue); + wait(2); + + } } }
diff -r f3bdcf35751e -r 7b3468fd31be main.cpp --- a/main.cpp Thu Feb 14 10:34:00 2019 +0000 +++ b/main.cpp Sun Apr 14 16:04:40 2019 +0000 @@ -4,6 +4,7 @@ * Licensed under the Apache License, Version 2.0); */ #include "main.h" + #include "HTU21D.h" DigitalOut myled(LED1); BufferedSerial *ser;