PingPong_REC
Dependencies: mbed BufferedSerial SX1276GenericLib
SX1276GenericPingPong/GenericPingPong.cpp@12:e0677648aa14, 2019-03-14 (annotated)
- Committer:
- lenriquez389
- Date:
- Thu Mar 14 11:21:55 2019 +0000
- Revision:
- 12:e0677648aa14
- Parent:
- 11:9d7409ebfa57
RECEPTION ER4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:c43b6919ae15 | 1 | /* |
Helmut64 | 0:c43b6919ae15 | 2 | * This file contains a copy of the master content sx1276PingPong |
Helmut64 | 0:c43b6919ae15 | 3 | * with adaption for the SX1276Generic environment |
Helmut64 | 0:c43b6919ae15 | 4 | * (c) 2017 Helmut Tschemernjak |
Helmut64 | 0:c43b6919ae15 | 5 | * 30826 Garbsen (Hannover) Germany |
Helmut64 | 0:c43b6919ae15 | 6 | */ |
lenriquez389 | 12:e0677648aa14 | 7 | |
Helmut64 | 0:c43b6919ae15 | 8 | #include "mbed.h" |
Helmut64 | 0:c43b6919ae15 | 9 | #include "PinMap.h" |
Helmut64 | 0:c43b6919ae15 | 10 | #include "GenericPingPong.h" |
Helmut64 | 0:c43b6919ae15 | 11 | #include "sx1276-mbed-hal.h" |
Helmut64 | 0:c43b6919ae15 | 12 | #include "main.h" |
Helmut64 | 0:c43b6919ae15 | 13 | |
Helmut64 | 0:c43b6919ae15 | 14 | #ifdef FEATURE_LORA |
Helmut64 | 0:c43b6919ae15 | 15 | |
Helmut64 | 0:c43b6919ae15 | 16 | /* Set this flag to '1' to display debug messages on the console */ |
Helmut64 | 0:c43b6919ae15 | 17 | #define DEBUG_MESSAGE 1 |
Helmut64 | 0:c43b6919ae15 | 18 | |
Helmut64 | 0:c43b6919ae15 | 19 | /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */ |
Helmut64 | 0:c43b6919ae15 | 20 | #define USE_MODEM_LORA 1 |
Helmut64 | 0:c43b6919ae15 | 21 | #define USE_MODEM_FSK !USE_MODEM_LORA |
Helmut64 | 0:c43b6919ae15 | 22 | #define RF_FREQUENCY RF_FREQUENCY_868_1 // Hz |
Helmut64 | 0:c43b6919ae15 | 23 | #define TX_OUTPUT_POWER 14 // 14 dBm |
Helmut64 | 0:c43b6919ae15 | 24 | |
Helmut64 | 0:c43b6919ae15 | 25 | #if USE_MODEM_LORA == 1 |
Helmut64 | 0:c43b6919ae15 | 26 | |
Helmut64 | 7:6a8a82bfb0c6 | 27 | #define LORA_BANDWIDTH 125000 // LoRa default, details in SX1276::BandwidthMap |
Helmut64 | 0:c43b6919ae15 | 28 | #define LORA_SPREADING_FACTOR LORA_SF7 |
Helmut64 | 0:c43b6919ae15 | 29 | #define LORA_CODINGRATE LORA_ERROR_CODING_RATE_4_5 |
Helmut64 | 0:c43b6919ae15 | 30 | |
Helmut64 | 0:c43b6919ae15 | 31 | #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx |
Helmut64 | 0:c43b6919ae15 | 32 | #define LORA_SYMBOL_TIMEOUT 5 // Symbols |
Helmut64 | 0:c43b6919ae15 | 33 | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
lenriquez389 | 12:e0677648aa14 | 34 | #define LORA_FHSS_ENABLED false |
lenriquez389 | 12:e0677648aa14 | 35 | #define LORA_NB_SYMB_HOP 4 |
Helmut64 | 0:c43b6919ae15 | 36 | #define LORA_IQ_INVERSION_ON false |
Helmut64 | 0:c43b6919ae15 | 37 | #define LORA_CRC_ENABLED true |
lenriquez389 | 12:e0677648aa14 | 38 | |
Helmut64 | 0:c43b6919ae15 | 39 | #elif USE_MODEM_FSK == 1 |
Helmut64 | 0:c43b6919ae15 | 40 | |
Helmut64 | 0:c43b6919ae15 | 41 | #define FSK_FDEV 25000 // Hz |
Helmut64 | 0:c43b6919ae15 | 42 | #define FSK_DATARATE 19200 // bps |
Helmut64 | 0:c43b6919ae15 | 43 | #define FSK_BANDWIDTH 50000 // Hz |
Helmut64 | 0:c43b6919ae15 | 44 | #define FSK_AFC_BANDWIDTH 83333 // Hz |
Helmut64 | 0:c43b6919ae15 | 45 | #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx |
Helmut64 | 0:c43b6919ae15 | 46 | #define FSK_FIX_LENGTH_PAYLOAD_ON false |
Helmut64 | 0:c43b6919ae15 | 47 | #define FSK_CRC_ENABLED true |
lenriquez389 | 12:e0677648aa14 | 48 | |
Helmut64 | 0:c43b6919ae15 | 49 | #else |
lenriquez389 | 12:e0677648aa14 | 50 | #error "Please define a modem in the compiler options." |
lenriquez389 | 12:e0677648aa14 | 51 | #endif |
Helmut64 | 0:c43b6919ae15 | 52 | |
Helmut64 | 0:c43b6919ae15 | 53 | |
Helmut64 | 0:c43b6919ae15 | 54 | #define RX_TIMEOUT_VALUE 3500 // in ms |
Helmut64 | 0:c43b6919ae15 | 55 | |
Helmut64 | 0:c43b6919ae15 | 56 | //#define BUFFER_SIZE 32 // Define the payload size here |
Helmut64 | 0:c43b6919ae15 | 57 | #define BUFFER_SIZE 64 // Define the payload size here |
Helmut64 | 0:c43b6919ae15 | 58 | |
Helmut64 | 0:c43b6919ae15 | 59 | /* |
Helmut64 | 0:c43b6919ae15 | 60 | * Global variables declarations |
Helmut64 | 0:c43b6919ae15 | 61 | */ |
lenriquez389 | 12:e0677648aa14 | 62 | typedef enum { |
Helmut64 | 0:c43b6919ae15 | 63 | LOWPOWER = 0, |
lenriquez389 | 12:e0677648aa14 | 64 | TRAITEMENT, |
lenriquez389 | 12:e0677648aa14 | 65 | REPONSE |
Helmut64 | 0:c43b6919ae15 | 66 | } AppStates_t; |
Helmut64 | 0:c43b6919ae15 | 67 | |
Helmut64 | 0:c43b6919ae15 | 68 | volatile AppStates_t State = LOWPOWER; |
Helmut64 | 0:c43b6919ae15 | 69 | |
Helmut64 | 0:c43b6919ae15 | 70 | /*! |
Helmut64 | 0:c43b6919ae15 | 71 | * Radio events function pointer |
Helmut64 | 0:c43b6919ae15 | 72 | */ |
Helmut64 | 0:c43b6919ae15 | 73 | static RadioEvents_t RadioEvents; |
Helmut64 | 0:c43b6919ae15 | 74 | |
Helmut64 | 0:c43b6919ae15 | 75 | /* |
Helmut64 | 0:c43b6919ae15 | 76 | * Global variables declarations |
Helmut64 | 0:c43b6919ae15 | 77 | */ |
Helmut64 | 0:c43b6919ae15 | 78 | SX1276Generic *Radio; |
Helmut64 | 0:c43b6919ae15 | 79 | |
Helmut64 | 0:c43b6919ae15 | 80 | |
lenriquez389 | 12:e0677648aa14 | 81 | uint8_t SLV[] = { 'Z', 'Z'}; |
lenriquez389 | 12:e0677648aa14 | 82 | uint8_t MTR[] = { 'X','X'}; |
lenriquez389 | 12:e0677648aa14 | 83 | DigitalOut myled(LED1); |
Helmut64 | 0:c43b6919ae15 | 84 | uint16_t BufferSize = BUFFER_SIZE; |
Helmut64 | 0:c43b6919ae15 | 85 | uint8_t *Buffer; |
Helmut64 | 0:c43b6919ae15 | 86 | |
Helmut64 | 0:c43b6919ae15 | 87 | DigitalOut *led3; |
Helmut64 | 0:c43b6919ae15 | 88 | |
Helmut64 | 0:c43b6919ae15 | 89 | |
lenriquez389 | 12:e0677648aa14 | 90 | int SX1276PingPong() |
Helmut64 | 0:c43b6919ae15 | 91 | { |
Helmut64 | 0:c43b6919ae15 | 92 | #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) |
Helmut64 | 0:c43b6919ae15 | 93 | DigitalOut *led = new DigitalOut(LED2); |
bcostm | 11:9d7409ebfa57 | 94 | #elif defined(TARGET_NUCLEO_L073RZ) || defined(TARGET_DISCO_L072CZ_LRWAN1) |
Helmut64 | 0:c43b6919ae15 | 95 | DigitalOut *led = new DigitalOut(LED4); // RX red |
Helmut64 | 0:c43b6919ae15 | 96 | led3 = new DigitalOut(LED3); // TX blue |
Helmut64 | 0:c43b6919ae15 | 97 | #else |
Helmut64 | 0:c43b6919ae15 | 98 | DigitalOut *led = new DigitalOut(LED1); |
Helmut64 | 0:c43b6919ae15 | 99 | led3 = led; |
Helmut64 | 0:c43b6919ae15 | 100 | #endif |
lenriquez389 | 12:e0677648aa14 | 101 | |
Helmut64 | 0:c43b6919ae15 | 102 | Buffer = new uint8_t[BUFFER_SIZE]; |
Helmut64 | 0:c43b6919ae15 | 103 | *led3 = 1; |
Helmut64 | 0:c43b6919ae15 | 104 | |
Helmut64 | 0:c43b6919ae15 | 105 | #ifdef B_L072Z_LRWAN1_LORA |
Helmut64 | 0:c43b6919ae15 | 106 | Radio = new SX1276Generic(NULL, MURATA_SX1276, |
lenriquez389 | 12:e0677648aa14 | 107 | LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET, |
lenriquez389 | 12:e0677648aa14 | 108 | LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5, |
lenriquez389 | 12:e0677648aa14 | 109 | LORA_ANT_RX, LORA_ANT_TX, LORA_ANT_BOOST, LORA_TCXO); |
Helmut64 | 0:c43b6919ae15 | 110 | #else // RFM95 |
Helmut64 | 0:c43b6919ae15 | 111 | Radio = new SX1276Generic(NULL, RFM95_SX1276, |
lenriquez389 | 12:e0677648aa14 | 112 | LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET, |
lenriquez389 | 12:e0677648aa14 | 113 | LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5); |
Helmut64 | 0:c43b6919ae15 | 114 | |
Helmut64 | 0:c43b6919ae15 | 115 | #endif |
lenriquez389 | 12:e0677648aa14 | 116 | |
Helmut64 | 0:c43b6919ae15 | 117 | uint8_t i; |
Helmut64 | 0:c43b6919ae15 | 118 | |
lenriquez389 | 12:e0677648aa14 | 119 | |
Helmut64 | 0:c43b6919ae15 | 120 | dprintf("SX1276 Ping Pong Demo Application" ); |
Helmut64 | 0:c43b6919ae15 | 121 | dprintf("Freqency: %.1f", (double)RF_FREQUENCY/1000000.0); |
Helmut64 | 0:c43b6919ae15 | 122 | dprintf("TXPower: %d dBm", TX_OUTPUT_POWER); |
Helmut64 | 0:c43b6919ae15 | 123 | #if USE_MODEM_LORA == 1 |
Helmut64 | 8:3b0d7b4ff28f | 124 | dprintf("Bandwidth: %d Hz", LORA_BANDWIDTH); |
Helmut64 | 0:c43b6919ae15 | 125 | dprintf("Spreading factor: SF%d", LORA_SPREADING_FACTOR); |
Helmut64 | 0:c43b6919ae15 | 126 | #elif USE_MODEM_FSK == 1 |
Helmut64 | 0:c43b6919ae15 | 127 | dprintf("Bandwidth: %d kHz", FSK_BANDWIDTH); |
Helmut64 | 0:c43b6919ae15 | 128 | dprintf("Baudrate: %d", FSK_DATARATE); |
Helmut64 | 0:c43b6919ae15 | 129 | #endif |
Helmut64 | 0:c43b6919ae15 | 130 | // Initialize Radio driver |
Helmut64 | 0:c43b6919ae15 | 131 | RadioEvents.TxDone = OnTxDone; |
Helmut64 | 0:c43b6919ae15 | 132 | RadioEvents.RxDone = OnRxDone; |
Helmut64 | 0:c43b6919ae15 | 133 | RadioEvents.RxError = OnRxError; |
Helmut64 | 0:c43b6919ae15 | 134 | RadioEvents.TxTimeout = OnTxTimeout; |
lenriquez389 | 12:e0677648aa14 | 135 | RadioEvents.RxTimeout = OnRxTimeout; |
Helmut64 | 6:1b598b0e52e4 | 136 | if (Radio->Init( &RadioEvents ) == false) { |
Helmut64 | 6:1b598b0e52e4 | 137 | while(1) { |
lenriquez389 | 12:e0677648aa14 | 138 | dprintf("Radio could not be detected!"); |
lenriquez389 | 12:e0677648aa14 | 139 | wait( 1 ); |
Helmut64 | 6:1b598b0e52e4 | 140 | } |
Helmut64 | 0:c43b6919ae15 | 141 | } |
Helmut64 | 6:1b598b0e52e4 | 142 | |
lenriquez389 | 12:e0677648aa14 | 143 | |
Helmut64 | 0:c43b6919ae15 | 144 | switch(Radio->DetectBoardType()) { |
Helmut64 | 0:c43b6919ae15 | 145 | case SX1276MB1LAS: |
Helmut64 | 0:c43b6919ae15 | 146 | if (DEBUG_MESSAGE) |
Helmut64 | 0:c43b6919ae15 | 147 | dprintf(" > Board Type: SX1276MB1LAS <"); |
Helmut64 | 0:c43b6919ae15 | 148 | break; |
Helmut64 | 0:c43b6919ae15 | 149 | case SX1276MB1MAS: |
Helmut64 | 0:c43b6919ae15 | 150 | if (DEBUG_MESSAGE) |
Helmut64 | 0:c43b6919ae15 | 151 | dprintf(" > Board Type: SX1276MB1LAS <"); |
Helmut64 | 0:c43b6919ae15 | 152 | case MURATA_SX1276: |
Helmut64 | 0:c43b6919ae15 | 153 | if (DEBUG_MESSAGE) |
lenriquez389 | 12:e0677648aa14 | 154 | dprintf(" > Board Type: MURATA_SX1276_STM32L0 <"); |
Helmut64 | 0:c43b6919ae15 | 155 | break; |
Helmut64 | 0:c43b6919ae15 | 156 | case RFM95_SX1276: |
Helmut64 | 0:c43b6919ae15 | 157 | if (DEBUG_MESSAGE) |
Helmut64 | 0:c43b6919ae15 | 158 | dprintf(" > HopeRF RFM95xx <"); |
Helmut64 | 0:c43b6919ae15 | 159 | break; |
Helmut64 | 0:c43b6919ae15 | 160 | default: |
Helmut64 | 0:c43b6919ae15 | 161 | dprintf(" > Board Type: unknown <"); |
Helmut64 | 0:c43b6919ae15 | 162 | } |
Helmut64 | 0:c43b6919ae15 | 163 | |
lenriquez389 | 12:e0677648aa14 | 164 | Radio->SetChannel(RF_FREQUENCY ); |
Helmut64 | 0:c43b6919ae15 | 165 | |
Helmut64 | 0:c43b6919ae15 | 166 | #if USE_MODEM_LORA == 1 |
lenriquez389 | 12:e0677648aa14 | 167 | |
Helmut64 | 0:c43b6919ae15 | 168 | if (LORA_FHSS_ENABLED) |
Helmut64 | 0:c43b6919ae15 | 169 | dprintf(" > LORA FHSS Mode <"); |
Helmut64 | 0:c43b6919ae15 | 170 | if (!LORA_FHSS_ENABLED) |
Helmut64 | 0:c43b6919ae15 | 171 | dprintf(" > LORA Mode <"); |
Helmut64 | 0:c43b6919ae15 | 172 | |
Helmut64 | 0:c43b6919ae15 | 173 | Radio->SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, |
lenriquez389 | 12:e0677648aa14 | 174 | LORA_SPREADING_FACTOR, LORA_CODINGRATE, |
lenriquez389 | 12:e0677648aa14 | 175 | LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, |
lenriquez389 | 12:e0677648aa14 | 176 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
lenriquez389 | 12:e0677648aa14 | 177 | LORA_IQ_INVERSION_ON, 2000 ); |
lenriquez389 | 12:e0677648aa14 | 178 | |
Helmut64 | 0:c43b6919ae15 | 179 | Radio->SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, |
lenriquez389 | 12:e0677648aa14 | 180 | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
lenriquez389 | 12:e0677648aa14 | 181 | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0, |
lenriquez389 | 12:e0677648aa14 | 182 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
lenriquez389 | 12:e0677648aa14 | 183 | LORA_IQ_INVERSION_ON, true ); |
lenriquez389 | 12:e0677648aa14 | 184 | |
Helmut64 | 0:c43b6919ae15 | 185 | #elif USE_MODEM_FSK == 1 |
Helmut64 | 0:c43b6919ae15 | 186 | |
Helmut64 | 0:c43b6919ae15 | 187 | dprintf(" > FSK Mode <"); |
Helmut64 | 0:c43b6919ae15 | 188 | Radio->SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, |
lenriquez389 | 12:e0677648aa14 | 189 | FSK_DATARATE, 0, |
lenriquez389 | 12:e0677648aa14 | 190 | FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, |
lenriquez389 | 12:e0677648aa14 | 191 | FSK_CRC_ENABLED, 0, 0, 0, 2000 ); |
lenriquez389 | 12:e0677648aa14 | 192 | |
Helmut64 | 0:c43b6919ae15 | 193 | Radio->SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, |
lenriquez389 | 12:e0677648aa14 | 194 | 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, |
lenriquez389 | 12:e0677648aa14 | 195 | 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED, |
lenriquez389 | 12:e0677648aa14 | 196 | 0, 0, false, true ); |
lenriquez389 | 12:e0677648aa14 | 197 | |
Helmut64 | 0:c43b6919ae15 | 198 | #else |
Helmut64 | 0:c43b6919ae15 | 199 | |
Helmut64 | 0:c43b6919ae15 | 200 | #error "Please define a modem in the compiler options." |
Helmut64 | 0:c43b6919ae15 | 201 | |
Helmut64 | 0:c43b6919ae15 | 202 | #endif |
lenriquez389 | 12:e0677648aa14 | 203 | |
Helmut64 | 0:c43b6919ae15 | 204 | if (DEBUG_MESSAGE) |
lenriquez389 | 12:e0677648aa14 | 205 | dprintf("Starting Ping-Pong loop"); |
Helmut64 | 0:c43b6919ae15 | 206 | |
lenriquez389 | 12:e0677648aa14 | 207 | |
Helmut64 | 0:c43b6919ae15 | 208 | Radio->Rx( RX_TIMEOUT_VALUE ); |
lenriquez389 | 12:e0677648aa14 | 209 | |
lenriquez389 | 12:e0677648aa14 | 210 | while( 1 ) { |
Helmut64 | 0:c43b6919ae15 | 211 | #ifdef TARGET_STM32L4 |
Helmut64 | 0:c43b6919ae15 | 212 | WatchDogUpdate(); |
lenriquez389 | 12:e0677648aa14 | 213 | #endif |
lenriquez389 | 12:e0677648aa14 | 214 | //dprintf("%d",State); |
lenriquez389 | 12:e0677648aa14 | 215 | switch( State ) { |
lenriquez389 | 12:e0677648aa14 | 216 | |
lenriquez389 | 12:e0677648aa14 | 217 | case LOWPOWER: |
lenriquez389 | 12:e0677648aa14 | 218 | sleep(); |
lenriquez389 | 12:e0677648aa14 | 219 | //dprintf("Escuchando\n\r"); |
lenriquez389 | 12:e0677648aa14 | 220 | Radio->Rx( RX_TIMEOUT_VALUE ); |
lenriquez389 | 12:e0677648aa14 | 221 | break; |
lenriquez389 | 12:e0677648aa14 | 222 | case TRAITEMENT: |
lenriquez389 | 12:e0677648aa14 | 223 | Radio->Sleep( ); |
lenriquez389 | 12:e0677648aa14 | 224 | if( BufferSize > 0 ) { |
lenriquez389 | 12:e0677648aa14 | 225 | if(Buffer[0]==MTR[0] && Buffer[1]==MTR[1] && Buffer[2]==SLV[0] && Buffer[3]==SLV[1]){ |
lenriquez389 | 12:e0677648aa14 | 226 | dprintf("Me pedieron informacion\n\r"); |
lenriquez389 | 12:e0677648aa14 | 227 | *led3 = 0; |
lenriquez389 | 12:e0677648aa14 | 228 | myled=0; |
lenriquez389 | 12:e0677648aa14 | 229 | dump("Data:", Buffer, BufferSize); |
lenriquez389 | 12:e0677648aa14 | 230 | State=REPONSE; |
lenriquez389 | 12:e0677648aa14 | 231 | } |
lenriquez389 | 12:e0677648aa14 | 232 | else{ |
lenriquez389 | 12:e0677648aa14 | 233 | State=LOWPOWER; |
lenriquez389 | 12:e0677648aa14 | 234 | myled=1; |
lenriquez389 | 12:e0677648aa14 | 235 | wait_ms( 20 ); |
lenriquez389 | 12:e0677648aa14 | 236 | } |
lenriquez389 | 12:e0677648aa14 | 237 | } |
lenriquez389 | 12:e0677648aa14 | 238 | else{ |
lenriquez389 | 12:e0677648aa14 | 239 | State=LOWPOWER; |
lenriquez389 | 12:e0677648aa14 | 240 | } |
lenriquez389 | 12:e0677648aa14 | 241 | break; |
lenriquez389 | 12:e0677648aa14 | 242 | case REPONSE: |
lenriquez389 | 12:e0677648aa14 | 243 | //Radio->Sleep( ); |
lenriquez389 | 12:e0677648aa14 | 244 | |
lenriquez389 | 12:e0677648aa14 | 245 | Buffer[0]=SLV[0]; |
lenriquez389 | 12:e0677648aa14 | 246 | Buffer[1]=SLV[1]; |
lenriquez389 | 12:e0677648aa14 | 247 | Buffer[2]=MTR[0]; |
lenriquez389 | 12:e0677648aa14 | 248 | Buffer[3]=MTR[1]; |
lenriquez389 | 12:e0677648aa14 | 249 | for( i = 4; i < BufferSize; i++ ) { |
lenriquez389 | 12:e0677648aa14 | 250 | Buffer[i] = 0x50; |
Helmut64 | 0:c43b6919ae15 | 251 | } |
lenriquez389 | 12:e0677648aa14 | 252 | |
lenriquez389 | 12:e0677648aa14 | 253 | wait_ms( 20 ); |
Helmut64 | 0:c43b6919ae15 | 254 | Radio->Send( Buffer, BufferSize ); |
lenriquez389 | 12:e0677648aa14 | 255 | *led3 = 1; |
lenriquez389 | 12:e0677648aa14 | 256 | break; |
lenriquez389 | 12:e0677648aa14 | 257 | default: |
lenriquez389 | 12:e0677648aa14 | 258 | State = LOWPOWER; |
lenriquez389 | 12:e0677648aa14 | 259 | break; |
lenriquez389 | 12:e0677648aa14 | 260 | } |
Helmut64 | 0:c43b6919ae15 | 261 | } |
Helmut64 | 0:c43b6919ae15 | 262 | } |
Helmut64 | 0:c43b6919ae15 | 263 | |
bcostm | 11:9d7409ebfa57 | 264 | void OnTxDone(void *radio, void *userThisPtr, void *userData) |
Helmut64 | 0:c43b6919ae15 | 265 | { |
Helmut64 | 0:c43b6919ae15 | 266 | Radio->Sleep( ); |
lenriquez389 | 12:e0677648aa14 | 267 | State = LOWPOWER; |
Helmut64 | 0:c43b6919ae15 | 268 | if (DEBUG_MESSAGE) |
Helmut64 | 0:c43b6919ae15 | 269 | dprintf("> OnTxDone"); |
Helmut64 | 0:c43b6919ae15 | 270 | } |
Helmut64 | 0:c43b6919ae15 | 271 | |
bcostm | 11:9d7409ebfa57 | 272 | void OnRxDone(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) |
Helmut64 | 0:c43b6919ae15 | 273 | { |
Helmut64 | 0:c43b6919ae15 | 274 | Radio->Sleep( ); |
lenriquez389 | 12:e0677648aa14 | 275 | //BufferSize = size; |
Helmut64 | 0:c43b6919ae15 | 276 | memcpy( Buffer, payload, BufferSize ); |
lenriquez389 | 12:e0677648aa14 | 277 | State = TRAITEMENT; |
Helmut64 | 0:c43b6919ae15 | 278 | if (DEBUG_MESSAGE) |
Helmut64 | 0:c43b6919ae15 | 279 | dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr); |
lenriquez389 | 12:e0677648aa14 | 280 | //dump("Data:", payload, size); |
Helmut64 | 0:c43b6919ae15 | 281 | } |
Helmut64 | 0:c43b6919ae15 | 282 | |
bcostm | 11:9d7409ebfa57 | 283 | void OnTxTimeout(void *radio, void *userThisPtr, void *userData) |
Helmut64 | 0:c43b6919ae15 | 284 | { |
lenriquez389 | 12:e0677648aa14 | 285 | //*led3 = 0; |
lenriquez389 | 12:e0677648aa14 | 286 | Radio->Sleep( ); |
lenriquez389 | 12:e0677648aa14 | 287 | State = LOWPOWER; |
Helmut64 | 0:c43b6919ae15 | 288 | if(DEBUG_MESSAGE) |
Helmut64 | 0:c43b6919ae15 | 289 | dprintf("> OnTxTimeout"); |
Helmut64 | 0:c43b6919ae15 | 290 | } |
Helmut64 | 0:c43b6919ae15 | 291 | |
bcostm | 11:9d7409ebfa57 | 292 | void OnRxTimeout(void *radio, void *userThisPtr, void *userData) |
Helmut64 | 0:c43b6919ae15 | 293 | { |
lenriquez389 | 12:e0677648aa14 | 294 | //*led3 = 0; |
Helmut64 | 0:c43b6919ae15 | 295 | Radio->Sleep( ); |
Helmut64 | 0:c43b6919ae15 | 296 | Buffer[BufferSize-1] = 0; |
lenriquez389 | 12:e0677648aa14 | 297 | State = LOWPOWER; |
Helmut64 | 0:c43b6919ae15 | 298 | if (DEBUG_MESSAGE) |
Helmut64 | 0:c43b6919ae15 | 299 | dprintf("> OnRxTimeout"); |
Helmut64 | 0:c43b6919ae15 | 300 | } |
Helmut64 | 0:c43b6919ae15 | 301 | |
bcostm | 11:9d7409ebfa57 | 302 | void OnRxError(void *radio, void *userThisPtr, void *userData) |
Helmut64 | 0:c43b6919ae15 | 303 | { |
Helmut64 | 0:c43b6919ae15 | 304 | Radio->Sleep( ); |
lenriquez389 | 12:e0677648aa14 | 305 | State = LOWPOWER; |
Helmut64 | 0:c43b6919ae15 | 306 | if (DEBUG_MESSAGE) |
Helmut64 | 0:c43b6919ae15 | 307 | dprintf("> OnRxError"); |
Helmut64 | 0:c43b6919ae15 | 308 | } |
Helmut64 | 0:c43b6919ae15 | 309 | |
Helmut64 | 0:c43b6919ae15 | 310 | #endif |