Team Walter / Mbed OS NonPingPong_PICO_LoRa

Dependencies:   SX1276GenericLib USBDevice

Fork of NonPingPong_PICO_LoRa by Walter Luu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GenericPingPong2.cpp Source File

GenericPingPong2.cpp

00001 /*
00002  * This file contains a copy of the master content sx1276PingPong
00003  * with adaption for the SX1276Generic environment
00004  * (c) 2017 Helmut Tschemernjak
00005  * 30826 Garbsen (Hannover) Germany
00006  */
00007  
00008 #include "mbed.h"
00009 #include "PinMap.h"
00010 #include "GenericPingPong2.h"
00011 #include "sx1276-mbed-hal.h"
00012 #include "main.h"
00013 #include "global_buffers.h" //adding this for development       
00014 
00015 #include "sx1276.h"
00016 
00017 #include "USBSerial.h"
00018 
00019 #ifdef FEATURE_LORA             // in main.cpp
00020 
00021 /* Set this flag to '1' to display debug messages on the console */
00022 #define DEBUG_MESSAGE   1
00023 
00024 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
00025 #define USE_MODEM_LORA  1
00026 #define USE_MODEM_FSK   !USE_MODEM_LORA
00027 #define RF_FREQUENCY            RF_FREQUENCY_915_0  // Hz
00028 #define TX_OUTPUT_POWER         1                  // 14 dBm
00029 
00030 #if USE_MODEM_LORA == 1
00031 
00032 #define LORA_BANDWIDTH          125000  // LoRa default, details in SX1276::BandwidthMap
00033 #define LORA_SPREADING_FACTOR   LORA_SF7
00034 #define LORA_CODINGRATE         LORA_ERROR_CODING_RATE_4_5
00035 
00036 #define LORA_PREAMBLE_LENGTH    8       // Same for Tx and Rx, default
00037 //#define LORA_PREAMBLE_LENGTH    5
00038 #define LORA_SYMBOL_TIMEOUT     5       // Symbols
00039 //#define LORA_SYMBOL_TIMEOUT     4       // Symbols
00040 
00041 #define LORA_FIX_LENGTH_PAYLOAD_ON  false
00042 #define LORA_FHSS_ENABLED       false  
00043 #define LORA_NB_SYMB_HOP        4     
00044 #define LORA_IQ_INVERSION_ON    false
00045 #define LORA_CRC_ENABLED        true
00046     
00047 #elif USE_MODEM_FSK == 1
00048 
00049 #define FSK_FDEV                25000     // Hz
00050 #define FSK_DATARATE            19200     // bps
00051 #define FSK_BANDWIDTH           50000     // Hz
00052 #define FSK_AFC_BANDWIDTH       83333     // Hz
00053 #define FSK_PREAMBLE_LENGTH     5         // Same for Tx and Rx
00054 #define FSK_FIX_LENGTH_PAYLOAD_ON   false
00055 #define FSK_CRC_ENABLED         true
00056     
00057 #else
00058     #error "Please define a modem in the compiler options."
00059 #endif 
00060 
00061 //#define RX_TIMEOUT_VALUE    3500  // in ms, default
00062 #define RX_TIMEOUT_VALUE    333 // in ms
00063 
00064 
00065 //#define BUFFER_SIZE       32        // Define the payload size here
00066 //#define BUFFER_SIZE         64        // Define the payload size here
00067 
00068 
00069 /*
00070  *  Global variables declarations
00071  */
00072 typedef enum
00073 {
00074     LOWPOWER = 0,
00075     IDLE,
00076     
00077     RX,
00078     RX_TIMEOUT,
00079     RX_ERROR,
00080     
00081     TX,
00082     TX_TIMEOUT,
00083     
00084     CAD,
00085     CAD_DONE
00086 } AppStates_t;
00087 
00088 volatile AppStates_t State = LOWPOWER;
00089 
00090 /*!
00091  * Radio events function pointer
00092  */
00093 static RadioEvents_t RadioEvents;
00094 
00095 /*
00096  *  Global variables declarations
00097  */
00098 SX1276Generic *Radio;
00099 
00100 
00101 //const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING";
00102 //const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG";
00103 
00104 //uint16_t BufferSize = BUFFER_SIZE;
00105 //uint8_t *Buffer;
00106 
00107 // Aliases for the buffers that are made in the main()
00108 uint8_t *BufferTx;
00109 uint8_t *BufferRx;
00110 USBSerial *ad;
00111 
00112 DigitalOut *led3;
00113 
00114 
00115 /*
00116 This function is in Devin's main function
00117 
00118 */
00119 int SX1276PingPongSetup(uint8_t *BufferTxFromMain, uint8_t *BufferRxFromMain, USBSerial *_ad) 
00120 {
00121     ad = _ad;
00122     
00123     ad->printf("TEST\r\n" );
00124     
00125 #if( defined ( TARGET_KL25Z ) || defined ( TARGET_Lad11U6X ) )
00126     DigitalOut *led = new DigitalOut(LED2);
00127 #elif defined(TARGET_NUCLEO_L073RZ) || defined(TARGET_DISCO_L072CZ_LRWAN1)
00128     DigitalOut *led = new DigitalOut(LED4);   // RX red
00129     led3 = new DigitalOut(LED3);  // TX blue
00130 #else
00131     DigitalOut *led = new DigitalOut(LED1);
00132 //    led = 0;
00133     led3 = led;
00134 #endif
00135     
00136     BufferTx = BufferTxFromMain;
00137     BufferRx = BufferRxFromMain;
00138     *led3 = 0;                      // change to 0
00139 
00140 #ifdef B_L072Z_LRWAN1_LORA
00141     Radio = new SX1276Generic(NULL, MURATA_SX1276,
00142             LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET,
00143             LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5,
00144             LORA_ANT_RX, LORA_ANT_TX, LORA_ANT_BOOST, LORA_TCXO);
00145 #else // RFM95
00146     Radio = new SX1276Generic(NULL, RFM95_SX1276,
00147             LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET,
00148             LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5);
00149 
00150 #endif
00151     
00152 //    dprintf("SX1276 Ping Pong Demo Application" );
00153     ad->printf("SX1276 Ping Pong Demo Application\r\n");
00154 //    dprintf("Freqency: %.1f", (double)RF_FREQUENCY/1000000.0);
00155      ad->printf("Freqency: %.1f\r\n", (double)RF_FREQUENCY/1000000.0);
00156 //    dprintf("TXPower: %d dBm",  TX_OUTPUT_POWER);
00157     ad->printf("TXPower: %d dBm\r\n",  TX_OUTPUT_POWER);
00158 #if USE_MODEM_LORA == 1
00159 //    dprintf("Bandwidth: %d Hz", LORA_BANDWIDTH);
00160     ad->printf("Bandwidth: %d Hz\r\n", LORA_BANDWIDTH);
00161 //    dprintf("Spreading factor: SF%d", LORA_SPREADING_FACTOR);
00162     ad->printf("Spreading factor: SF%d\r\n", LORA_SPREADING_FACTOR);
00163 #elif USE_MODEM_FSK == 1
00164 //    dprintf("Bandwidth: %d kHz",  FSK_BANDWIDTH);
00165     ad->printf("Bandwidth: %d kHz\r\n",  FSK_BANDWIDTH);
00166 //    dprintf("Baudrate: %d", FSK_DATARATE);
00167     ad->printf("Baudrate: %d\r\n", FSK_DATARATE);
00168 #endif
00169     // Initialize Radio driver
00170     RadioEvents.TxDone = OnTxDone;
00171     RadioEvents.RxDone = OnRxDone;
00172     RadioEvents.RxError = OnRxError;
00173     RadioEvents.TxTimeout = OnTxTimeout;
00174     RadioEvents.RxTimeout = OnRxTimeout;    
00175     if (Radio->Init( &RadioEvents ) == false) {
00176         while(1) {
00177 //          dprintf("Radio could not be detected!");
00178             ad->printf("Radio could not be detected!\r\n");
00179             wait( 1 );
00180         }
00181     }
00182 
00183     
00184     switch(Radio->DetectBoardType()) {
00185         case SX1276MB1LAS:
00186             if (DEBUG_MESSAGE)
00187                 ad->printf(" > Board Type: SX1276MB1LAS <\r\n");
00188             break;
00189         case SX1276MB1MAS:
00190             if (DEBUG_MESSAGE)
00191                 ad->printf(" > Board Type: SX1276MB1LAS <\r\n");
00192         case MURATA_SX1276:
00193             if (DEBUG_MESSAGE)
00194                 ad->printf(" > Board Type: MURATA_SX1276_STM32L0 <\r\n");
00195             break;
00196         case RFM95_SX1276:
00197             if (DEBUG_MESSAGE)
00198                 ad->printf(" > HopeRF RFM95xx <\r\n");
00199             break;
00200         default:
00201             ad->printf(" > Board Type: unknown <\r\n");
00202     }
00203 
00204     Radio->SetChannel(RF_FREQUENCY ); 
00205 
00206 #if USE_MODEM_LORA == 1
00207     
00208     if (LORA_FHSS_ENABLED)
00209         ad->printf("             > LORA FHSS Mode <\r\n");
00210     if (!LORA_FHSS_ENABLED)
00211         ad->printf("             > LORA Mode <\r\n");
00212     
00213     
00214     // Without this line, the default max payload length is only 64 bytes
00215     Radio->SetMaxPayloadLength(MODEM_LORA, 255);
00216 
00217     Radio->SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
00218                          LORA_SPREADING_FACTOR, LORA_CODINGRATE,
00219                          LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
00220                          LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, 
00221                          LORA_IQ_INVERSION_ON, 2000 );
00222     
00223     Radio->SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
00224                          LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
00225                          LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
00226                          LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, 
00227                          LORA_IQ_INVERSION_ON, true );
00228                          
00229 #elif USE_MODEM_FSK == 1
00230 
00231     ad->printf("              > FSK Mode <\n");
00232     Radio->SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0,
00233                          FSK_DATARATE, 0,
00234                          FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON,
00235                          FSK_CRC_ENABLED, 0, 0, 0, 2000 );
00236     
00237     Radio->SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
00238                          0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
00239                          0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED,
00240                          0, 0, false, true );
00241                          
00242 #else
00243 
00244 #error "Please define a modem in the compiler options."
00245 
00246 #endif
00247      
00248     if (DEBUG_MESSAGE)
00249         ad->printf("Starting Ping-Pong loop\r\n"); 
00250 
00251 #if MASTER == 1        
00252     Radio->Rx( RX_TIMEOUT_VALUE );  // initate Rx State for Master
00253 #endif
00254     
00255 return 0; //added by Walter due to "Control reaches end of non-void function"
00256 }
00257 
00258 
00259 bool SX1276MasterCheckForNewData(void)
00260 {
00261     bool new_data_available = false;
00262     switch( State )
00263     {
00264     case RX:
00265         if( BufferSizeRx > 0 )
00266         {
00267             new_data_available = true;
00268             wait_ms( 10 ); //do we need this?
00269             if (DEBUG_MESSAGE)
00270                 ad->printf( "State=RX\r\n" );
00271         }
00272         Radio->Rx( RX_TIMEOUT_VALUE );  
00273         State = LOWPOWER;
00274         break;
00275     case RX_TIMEOUT:
00276         wait_ms( 10 ); 
00277         if (DEBUG_MESSAGE)
00278                 ad->printf( "State=RX_TIMEOUT\r\n" );     
00279         Radio->Rx( RX_TIMEOUT_VALUE );    
00280         State = LOWPOWER;
00281         break;
00282     case RX_ERROR:
00283         // We have received a Packet with a CRC error, send reply as if packet was correct
00284         wait_ms( 10 );  
00285         if (DEBUG_MESSAGE)
00286                 ad->printf( "State=RX_ERROR\r\n" );
00287         Radio->Rx( RX_TIMEOUT_VALUE );
00288         State = LOWPOWER;
00289         break;
00290     case TX_TIMEOUT:
00291         if (DEBUG_MESSAGE)
00292                 ad->printf( "State=TX_TIMEOUT\r\n" );
00293         State = LOWPOWER;
00294         break;
00295     case LOWPOWER:
00296         sleep();
00297         break;
00298     default:
00299         sleep(); // TODO, should this be removed?
00300         break;
00301     }   
00302     return new_data_available; 
00303 }
00304 
00305 void SX1276SlaveSendData(void)
00306 {
00307     //wait_ms( 10 );  
00308     Radio->Send( BufferTx, BufferSizeTx );
00309     sleep();
00310 }
00311 
00312 /****************************************************************************************************************************************
00313  * 
00314  ****************************************************************************************************************************************/
00315 //int SX1276PingPong(void)
00316 //{
00317 //#if   MASTER == 1 // Master Device: Bluetooth Gateway
00318 //    bool isMaster = true;
00319 //#elif SLAVE == 1 // Slave Device: Robot
00320 //  bool isMaster = false;
00321 //#endif
00322 //  
00323 //    switch( State )
00324 //    {
00325 //    case RX:
00326 ////            *led3 = 0;              // uncommented
00327 //        if( isMaster == true )        // Master Device received payload from Slave
00328 //        {
00329 //            if( BufferSizeRx > 0 )
00330 //            {
00331 //                /* This checks if the ID of the received transaction is matching that of
00332 //                 * the slave device's ID. This is defined in the GenericPingPong.h
00333 //                 */
00334 //                if( memcmp(&BufferRx[rx_idx_signature], PongMsg, sizeof(PongMsg)) == 0 )
00335 //                {
00336 ////                        *led = !*led;    
00337 ////                        *led = 0;          // changed to 0
00338 //                  if (DEBUG_MESSAGE)
00339 //                      ad->printf( "...Pong\r\n" );
00340 //                    wait_ms( 10 ); 
00341 //                    Radio->Send( BufferTx, BufferSizeTx );
00342 //                } // memcmp != 0
00343 //                else // valid reception but not a PONG message
00344 //                {    // Set device as master and start again
00345 //                    isMaster = true;                  // new update
00346 //                    Radio->Rx( RX_TIMEOUT_VALUE );
00347 //                } // end of if memcmp
00348 //            } // end of if BufferSizeRx > 0
00349 //        } // end of isMaster == true
00350 //        else      // Slave Device received payload from Master
00351 //        {
00352 //            if( BufferSizeRx > 0 )
00353 //            {
00354 //                if( memcmp(BufferRx, PingMsg, sizeof(PingMsg)) == 0 )
00355 //                {
00356 ////                        *led = !*led;
00357 ////                            *led = 0            //changed to 0
00358 //                  if (DEBUG_MESSAGE)
00359 //                      ad->printf( "...Ping\r\n" );
00360 //                    wait_ms( 10 );  
00361 //                    Radio->Send( BufferTx, BufferSizeTx );
00362 //                }
00363 //                else // valid reception but not a PING as expected
00364 //                {    // Set device as slave and start again
00365 //                    isMaster = false;                 // new update
00366 //                    Radio->Rx( RX_TIMEOUT_VALUE );
00367 //                }    
00368 //            } // end of if BufferSizeRx > 0
00369 //        } // end of if (isMaster == True), end of checking devices
00370 //        
00371 //        State = LOWPOWER;     // back to LOWPOWER State
00372 //        
00373 //        break;
00374 //    case TX:    
00375 ////            *led3 = 0;      // change to 0
00376 //        if( isMaster == true )  // Master Device
00377 //        {
00378 //            if (DEBUG_MESSAGE)
00379 //              ad->printf("Ping...\r\n" );
00380 //        }
00381 //        else      // Slave Device
00382 //        {
00383 //            if (DEBUG_MESSAGE)
00384 //              ad->printf("Pong...\r\n" );
00385 //        }
00386 //        Radio->Rx( RX_TIMEOUT_VALUE );
00387 //        State = LOWPOWER;             // back to LOWPOWER State
00388 //        break;
00389 //    case RX_TIMEOUT:
00390 //        if( isMaster == true )        // Master Device
00391 //        {
00392 //            wait_ms( 10 ); 
00393 //            Radio->Send( BufferTx, BufferSizeTx );
00394 //        }
00395 //        else  // Slave Device
00396 //        {
00397 //            Radio->Rx( RX_TIMEOUT_VALUE );  
00398 //        }             
00399 //        State = LOWPOWER;         // back to LOWPOWER State
00400 //        break;
00401 //    case RX_ERROR:
00402 //        // We have received a Packet with a CRC error, send reply as if packet was correct
00403 //        if( isMaster == true )        // Master Device
00404 //        {
00405 //            // Send the next PING frame
00406 ////            memcpy(BufferTx, PingMsg, sizeof(PingMsg));
00407 ///*            
00408 //            for( i = 4; i < BufferSizeTx; i++ )
00409 //            {
00410 //                BufferTx[i] = i - 4;
00411 //            }
00412 //*/
00413 ////            fillPayloadWithGlobalBufs(BufferTx);
00414 //            wait_ms( 10 );  
00415 //            Radio->Send( BufferTx, BufferSizeTx );
00416 //        }
00417 //        else          // Slave Device
00418 //        {
00419 //            // Send the next PONG frame
00420 ////            memcpy(BufferTx, PongMsg, sizeof(PongMsg));
00421 ///*
00422 //            for( i = sizeof(PongMsg); i < BufferSizeTx; i++ )
00423 //            {
00424 //                BufferTx[i] = i - sizeof(PongMsg);
00425 //            }
00426 //*/
00427 //            wait_ms( 10 );  
00428 //            Radio->Send( BufferTx, BufferSizeTx );
00429 //        }
00430 //        State = LOWPOWER;     // Back to Low Power State
00431 //        break;
00432 //    case TX_TIMEOUT:
00433 //        Radio->Rx( RX_TIMEOUT_VALUE );
00434 //        State = LOWPOWER;
00435 //        break;
00436 //    case LOWPOWER:
00437 //      sleep();
00438 //        break;
00439 //    default:
00440 //        State = LOWPOWER;
00441 //        break;
00442 //    }    
00443 //}
00444 
00445 
00446 int TimeOnAirSend(void) {
00447 
00448     return  Radio->TimeOnAir( MODEM_LORA, sizeof(BufferSizeTx));
00449 
00450 }   
00451 
00452 
00453 int SX1276SensorSend(void) {
00454     
00455     switch( State )
00456     {
00457         case RX:
00458            // if( BufferSizeRx > 0 )
00459 //            {
00460 //                Radio->Send( BufferTx, BufferSizeTx );
00461 //                Radio->Rx( RX_TIMEOUT_VALUE );
00462 //          } // end of if BufferSizeRx > 0
00463             
00464             Radio->Send( BufferTx, BufferSizeTx );
00465             Radio->Rx( RX_TIMEOUT_VALUE );
00466             
00467             State = LOWPOWER;       // back to LOWPOWER State
00468             
00469         break;
00470     }   // end of switch statement
00471 }
00472 
00473 
00474 
00475 int SX1276GateWayReceive(int TimeOut) {
00476     
00477     switch( State )
00478     {
00479         case RX:
00480            // if( BufferSizeRx > 0 )
00481 //            {
00482 ////                Radio->Send( BufferTx, BufferSizeTx );
00483 //                Radio->Rx( RX_TIMEOUT_VALUE );
00484 //          } // end of if BufferSizeRx > 0
00485             
00486             
00487 //          Radio->Rx( RX_TIMEOUT_VALUE );
00488             
00489             Radio->Rx( TimeOut );
00490             
00491             State = LOWPOWER;       // back to LOWPOWER State
00492             
00493         break;
00494     }   // end of switch statement
00495 }
00496 
00497 
00498 
00499 
00500 //void OnTxDone(void *radio, void *userThisPtr, void *userData)
00501 //{
00502 //    Radio->Sleep( );
00503 //    State = TX;
00504 //    if (DEBUG_MESSAGE)
00505 //        dprintf("> OnTxDone");
00506 //}
00507 
00508 // moved to main
00509 void OnTxDone(void *radio, void *userThisPtr, void *userData)
00510 {
00511     Radio->Sleep( );
00512     State = TX;
00513     if (DEBUG_MESSAGE)
00514         //dprintf("> OnTxDone");
00515         ad->printf("> OnTxDone");
00516 }
00517 
00518 
00519 //void OnRxDone(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
00520 //{
00521 //    Radio->Sleep( );
00522 //    BufferSize = size;
00523 //    memcpy( Buffer, payload, BufferSize );
00524 //    State = RX;
00525 //    if (DEBUG_MESSAGE)
00526 //        dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr);
00527 //    dump("Data:", payload, size);
00528 //}
00529 
00530 // moved to main
00531 void OnRxDone(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
00532 {
00533     Radio->Sleep( );
00534     
00535     if(BufferSizeRx != size)
00536         memcpy( BufferRx, payload, size );
00537     else
00538         memcpy( BufferRx, payload, BufferSizeRx );
00539     State = RX;
00540     
00541     // Reset the RxTimeoutCount 
00542     RxTimeoutCount = 0;
00543 
00544     if (DEBUG_MESSAGE) {
00545         ad->printf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d\n", rssi, snr);
00546         dump("Data:", payload, size);
00547     }
00548 }
00549 
00550 //void OnTxTimeout(void *radio, void *userThisPtr, void *userData)
00551 //{
00552 //    *led3 = 0;
00553 //    Radio->Sleep( );
00554 //    State = TX_TIMEOUT;
00555 //    if(DEBUG_MESSAGE)
00556 //        dprintf("> OnTxTimeout");
00557 //}
00558 
00559 // moved to main
00560 void OnTxTimeout(void *radio, void *userThisPtr, void *userData)
00561 {
00562 //    *led3 = 0;
00563     Radio->Sleep( );
00564     State = TX_TIMEOUT;
00565     if(DEBUG_MESSAGE)
00566         ad->printf("> OnTxTimeout");
00567 }
00568 
00569 //void OnRxTimeout(void *radio, void *userThisPtr, void *userData)
00570 //{
00571 //    *led3 = 0;
00572 //    Radio->Sleep( );
00573 //    Buffer[BufferSize-1] = 0;
00574 //    State = RX_TIMEOUT;
00575 //    if (DEBUG_MESSAGE)
00576 //        dprintf("> OnRxTimeout");
00577 //}
00578 
00579 // moved to main
00580 void OnRxTimeout(void *radio, void *userThisPtr, void *userData)
00581 {
00582     Radio->Sleep( );
00583     BufferRx[BufferSizeRx-1] = 0;
00584     State = RX_TIMEOUT;
00585     if (DEBUG_MESSAGE)
00586         ad->printf("> OnRxTimeout\n");
00587         
00588     // Increment how many times a transmission times out\
00589     RxTimeoutCount = RxTimeoutCount + 1;
00590 }
00591 
00592 //void OnRxError(void *radio, void *userThisPtr, void *userData)
00593 //{
00594 //    Radio->Sleep( );
00595 //    State = RX_ERROR;
00596 //    if (DEBUG_MESSAGE)
00597 //        dprintf("> OnRxError");
00598 //}
00599 
00600 // moved to main
00601 void OnRxError(void *radio, void *userThisPtr, void *userData)
00602 {
00603     Radio->Sleep( );
00604     State = RX_ERROR;
00605     if (DEBUG_MESSAGE)
00606         ad->printf("> OnRxError\n");
00607         
00608     // Increment how many times a transmission times out\
00609     RxTimeoutCount = RxTimeoutCount + 1;
00610 }
00611 
00612 
00613 int numOfRxTimeouts()
00614 {
00615     return RxTimeoutCount;
00616 }
00617 
00618 
00619 
00620 
00621 #endif