carte réceptrice (Wronski et Deleau)
Dependencies: mbed BufferedSerial SX1276GenericLib HTU21D
Revision 13:e0f2f772ebf1, committed 2019-04-14
- Comitter:
- Adam06
- Date:
- Sun Apr 14 16:06:10 2019 +0000
- Parent:
- 12:f3bdcf35751e
- Commit message:
- re
Changed in this revision
diff -r f3bdcf35751e -r e0f2f772ebf1 BufferedSerial.lib --- a/BufferedSerial.lib Thu Feb 14 10:34:00 2019 +0000 +++ b/BufferedSerial.lib Sun Apr 14 16:06:10 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 e0f2f772ebf1 SX1276GenericPingPong/GenericPingPong.cpp --- a/SX1276GenericPingPong/GenericPingPong.cpp Thu Feb 14 10:34:00 2019 +0000 +++ b/SX1276GenericPingPong/GenericPingPong.cpp Sun Apr 14 16:06:10 2019 +0000 @@ -1,10 +1,4 @@ -/* - * This file contains a copy of the master content sx1276PingPong - * with adaption for the SX1276Generic environment - * (c) 2017 Helmut Tschemernjak - * 30826 Garbsen (Hannover) Germany - */ - + #include "mbed.h" #include "PinMap.h" #include "GenericPingPong.h" @@ -12,6 +6,7 @@ #include "main.h" #include "HTU21D.h" +HTU21D temphumid(PB_9,PB_8); #ifdef FEATURE_LORA /* Set this flag to '1' to display debug messages on the console */ @@ -49,14 +44,15 @@ #else #error "Please define a modem in the compiler options." -#endif +#endif -#define RX_TIMEOUT_VALUE 3500 // in ms +#define RX_TIMEOUT_VALUE 3500 // in ms //#define BUFFER_SIZE 32 // Define the payload size here #define BUFFER_SIZE 64 // Define the payload size here - +#define IDENTIFIANT1 0x02 +#define IDENTIFIANT2 0x03 /* * Global variables declarations */ @@ -87,10 +83,13 @@ * Global variables declarations */ SX1276Generic *Radio; +int sample_ctemp; +int sample_humid; +//sample_ftemp = temphumid.sample_ftemp(); -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; @@ -98,7 +97,7 @@ DigitalOut *led3; -int SX1276PingPong() +int SX1276PingPong() { #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) DigitalOut *led = new DigitalOut(LED2); @@ -115,12 +114,12 @@ #ifdef B_L072Z_LRWAN1_LORA Radio = new SX1276Generic(NULL, MURATA_SX1276, - LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET, - LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5, - LORA_ANT_RX, LORA_ANT_TX, LORA_ANT_BOOST, LORA_TCXO); + LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET, + LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5, + LORA_ANT_RX, LORA_ANT_TX, LORA_ANT_BOOST, LORA_TCXO); #else // RFM95 Radio = new SX1276Generic(NULL, RFM95_SX1276, - LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET, + LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET, LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5); #endif @@ -146,8 +145,8 @@ RadioEvents.RxTimeout = OnRxTimeout; if (Radio->Init( &RadioEvents ) == false) { while(1) { - dprintf("Radio could not be detected!"); - wait( 1 ); + dprintf("Radio could not be detected!"); + wait( 1 ); } } @@ -162,7 +161,7 @@ dprintf(" > Board Type: SX1276MB1LAS <"); case MURATA_SX1276: if (DEBUG_MESSAGE) - dprintf(" > Board Type: MURATA_SX1276_STM32L0 <"); + dprintf(" > Board Type: MURATA_SX1276_STM32L0 <"); break; case RFM95_SX1276: if (DEBUG_MESSAGE) @@ -172,7 +171,7 @@ dprintf(" > Board Type: unknown <"); } - Radio->SetChannel(RF_FREQUENCY ); + Radio->SetChannel(RF_FREQUENCY ); #if USE_MODEM_LORA == 1 @@ -184,13 +183,13 @@ Radio->SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, LORA_CODINGRATE, LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, - LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, + LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, LORA_IQ_INVERSION_ON, 2000 ); Radio->SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0, - LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, + LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, LORA_IQ_INVERSION_ON, true ); #elif USE_MODEM_FSK == 1 @@ -213,13 +212,11 @@ #endif if (DEBUG_MESSAGE) - dprintf("Starting Ping-Pong loop"); + dprintf("Starting Ping-Pong loop"); Radio->Rx( RX_TIMEOUT_VALUE ); - - HTU21D temphumid(PB_14, PB_13); //Temp humid sensor || SDA, SCL while( 1 ) { #ifdef TARGET_STM32L4 @@ -229,7 +226,7 @@ switch( State ) { case RX: - *led3 = 0; + *led3 = 0; if( isMaster == true ) { if( BufferSize > 0 ) @@ -240,27 +237,27 @@ dprintf( "...Pong" ); // Send the next PING frame memcpy(Buffer, PingMsg, sizeof(PingMsg)); - // We fill the buffer with numbers for the payload + // We fill the buffer with numbers for the payload for( i = sizeof(PingMsg); i < BufferSize; i++ ) { Buffer[i] = i - sizeof(PingMsg); } - wait_ms( 10 ); + 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" ); + dprintf( "" ); *led = !*led; isMaster = false; // Send the next PONG frame memcpy(Buffer, PongMsg, sizeof(PongMsg)); - // We fill the buffer with numbers for the payload + // We fill the buffer with numbers for the payload for( i = sizeof(PongMsg); i < BufferSize; i++ ) { Buffer[i] = i - sizeof(PongMsg); } - wait_ms( 10 ); + wait_ms( 10 ); Radio->Send( Buffer, BufferSize ); } else // valid reception but neither a PING or a PONG message @@ -280,21 +277,17 @@ 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++ ) + // We fill the buffer with numbers for the payload + for( i = sizeof(PongMsg); i < BufferSize; i++ ) { - Buffer[i+sizeof(PongMsg)] = data[i]; + Buffer[i] = i - sizeof(PongMsg); } 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; + isMaster = true; Radio->Rx( RX_TIMEOUT_VALUE ); } } @@ -305,7 +298,7 @@ *led3 = 1; if( isMaster == true ) { - dprintf("Ping..." ); + //dprintf("Ping..." ); } else { @@ -323,7 +316,7 @@ { Buffer[i] = i - sizeof(PingMsg); } - wait_ms( 10 ); + wait_ms( 10 ); Radio->Send( Buffer, BufferSize ); } else @@ -363,7 +356,7 @@ State = LOWPOWER; break; case LOWPOWER: - sleep(); + sleep(); break; default: State = LOWPOWER; @@ -377,7 +370,7 @@ Radio->Sleep( ); State = TX; if (DEBUG_MESSAGE) - dprintf("> OnTxDone"); + dprintf(""); } void OnRxDone(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) @@ -386,9 +379,16 @@ BufferSize = size; memcpy( Buffer, payload, BufferSize ); State = RX; - if (DEBUG_MESSAGE) - dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr); - dump("Data:", payload, size); + sample_ctemp = temphumid.sample_ctemp(); + sample_humid = temphumid.sample_humid(); + if (DEBUG_MESSAGE){ + if(Buffer[2] == IDENTIFIANT1 && Buffer[3] == IDENTIFIANT2) { //IDENTIFIANT1 et IDENTIFIANT2 sont déclarés en #define + dprintf("Temperature %d",Buffer[5]); + dprintf("Humidite %d",Buffer[6]); + dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr); + //dump("Data:", payload, size); + } + } } void OnTxTimeout(void *radio, void *userThisPtr, void *userData) @@ -397,7 +397,7 @@ Radio->Sleep( ); State = TX_TIMEOUT; if(DEBUG_MESSAGE) - dprintf("> OnTxTimeout"); + dprintf(""); } void OnRxTimeout(void *radio, void *userThisPtr, void *userData) @@ -407,7 +407,7 @@ Buffer[BufferSize-1] = 0; State = RX_TIMEOUT; if (DEBUG_MESSAGE) - dprintf("> OnRxTimeout"); + dprintf(""); } void OnRxError(void *radio, void *userThisPtr, void *userData) @@ -415,7 +415,7 @@ Radio->Sleep( ); State = RX_ERROR; if (DEBUG_MESSAGE) - dprintf("> OnRxError"); + dprintf(""); } -#endif +#endif \ No newline at end of file
diff -r f3bdcf35751e -r e0f2f772ebf1 main.cpp --- a/main.cpp Thu Feb 14 10:34:00 2019 +0000 +++ b/main.cpp Sun Apr 14 16:06:10 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;