First attempt at LoRa USB Tx

Dependencies:   BufferedSerial SX1276GenericLib mbed

Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * Copyright (c) 2017 Helmut Tschemernjak
00003  * 30826 Garbsen (Hannover) Germany
00004  * Licensed under the Apache License, Version 2.0);
00005  */
00006  #include "main.h"
00007 
00008 DigitalOut myled(LED1);
00009 BufferedSerial *ser;
00010 
00011 
00012 #ifdef FEATURE_LORA
00013 
00014 /* Set this flag to '1' to display debug messages on the console */
00015 #define DEBUG_MESSAGE   0
00016 
00017 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
00018 #define USE_MODEM_LORA  1
00019 #define USE_MODEM_FSK   !USE_MODEM_LORA
00020 #define RF_FREQUENCY            915000000//RF_FREQUENCY_868_1  // Hz
00021 #define TX_OUTPUT_POWER         20                  // 14 dBm
00022 
00023 #if USE_MODEM_LORA == 1
00024 
00025 #define LORA_BANDWIDTH          125000  // LoRa default, details in SX1276::BandwidthMap
00026 #define LORA_SPREADING_FACTOR   LORA_SF12
00027 #define LORA_CODINGRATE         LORA_ERROR_CODING_RATE_4_5
00028 
00029 #define LORA_PREAMBLE_LENGTH    8       // Same for Tx and Rx
00030 #define LORA_SYMBOL_TIMEOUT     5       // Symbols
00031 #define LORA_FIX_LENGTH_PAYLOAD_ON  false
00032 #define LORA_FHSS_ENABLED       false  
00033 #define LORA_NB_SYMB_HOP        4     
00034 #define LORA_IQ_INVERSION_ON    false
00035 #define LORA_CRC_ENABLED        true
00036     
00037 #elif USE_MODEM_FSK == 1
00038 
00039 #define FSK_FDEV                25000     // Hz
00040 #define FSK_DATARATE            19200     // bps
00041 #define FSK_BANDWIDTH           50000     // Hz
00042 #define FSK_AFC_BANDWIDTH       83333     // Hz
00043 #define FSK_PREAMBLE_LENGTH     5         // Same for Tx and Rx
00044 #define FSK_FIX_LENGTH_PAYLOAD_ON   false
00045 #define FSK_CRC_ENABLED         true
00046     
00047 #else
00048     #error "Please define a modem in the compiler options."
00049 #endif 
00050 
00051 
00052 #define RX_TIMEOUT_VALUE    8000//3500  // in ms
00053 
00054 //#define BUFFER_SIZE       32        // Define the payload size here
00055 #define BUFFER_SIZE         4//64        // Define the payload size here
00056 
00057 /*
00058  *  Global variables declarations
00059  */
00060 typedef enum
00061 {
00062     LOWPOWER = 0,
00063     IDLE,
00064     
00065     RX,
00066     RX_TIMEOUT,
00067     RX_ERROR,
00068     
00069     TX,
00070     TX_TIMEOUT,
00071     
00072     CAD,
00073     CAD_DONE
00074 } AppStates_t;
00075 
00076 volatile AppStates_t State = LOWPOWER;
00077 
00078 /*!
00079  * Radio events function pointer
00080  */
00081 static RadioEvents_t RadioEvents;
00082 
00083 /*
00084  *  Global variables declarations
00085  */
00086 SX1276Generic *Radio;
00087 
00088 
00089 //const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING";
00090 const uint8_t PingMsg[] = { 'P', 'I', 'N', 'G'};// "PING";
00091 //const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG";
00092 const uint8_t PongMsg[] = { 'P', 'O', 'N', 'G'};// "PONG";
00093 
00094 uint16_t BufferSize = BUFFER_SIZE;
00095 uint8_t *Buffer;
00096 
00097 DigitalOut *led3;
00098 DigitalOut *led = new DigitalOut(LED1);
00099 
00100 uint8_t i;
00101 bool isMaster = false;
00102 
00103 uint8_t SX1276DataTx[4];
00104 uint8_t SX1276DataRx[4]; 
00105 bool mode = false; // false is slave, true is master
00106 
00107 uint8_t serialRxBuffer[4];
00108 int main() {
00109     SystemClock_Config();
00110     ser = new BufferedSerial(USBTX, USBRX);
00111     ser->baud(115200);
00112     ser->format(8);
00113     ser->printf("Hello World\n\r");
00114     myled = 1;
00115     
00116     #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) )
00117     DigitalOut *led = new DigitalOut(LED2);
00118 #elif defined(TARGET_NUCLEO_L073RZ)
00119     DigitalOut *led = new DigitalOut(LED4);   // RX red
00120     led3 = new DigitalOut(LED3);  // TX blue
00121 #else
00122     DigitalOut *led = new DigitalOut(LED1);
00123     led3 = led;
00124 #endif
00125     
00126     Buffer = new  uint8_t[BUFFER_SIZE];
00127     *led3 = 1;
00128 
00129 #ifdef B_L072Z_LRWAN1_LORA
00130     Radio = new SX1276Generic(NULL, MURATA_SX1276,
00131             LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET,
00132             LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5,
00133             LORA_ANT_RX, LORA_ANT_TX, LORA_ANT_BOOST, LORA_TCXO);
00134 #else // RFM95
00135     Radio = new SX1276Generic(NULL, RFM95_SX1276,
00136             LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET,
00137             LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5);
00138 
00139 #endif
00140     
00141     
00142     isMaster = true;
00143     
00144     dprintf("SX1276 Ping Pong Demo Application" );
00145     dprintf("Freqency: %.1f", (double)RF_FREQUENCY/1000000.0);
00146     dprintf("TXPower: %d dBm",  TX_OUTPUT_POWER);
00147 #if USE_MODEM_LORA == 1
00148     dprintf("Bandwidth: %d Hz", LORA_BANDWIDTH);
00149     dprintf("Spreading factor: SF%d", LORA_SPREADING_FACTOR);
00150 #elif USE_MODEM_FSK == 1
00151     dprintf("Bandwidth: %d kHz",  FSK_BANDWIDTH);
00152     dprintf("Baudrate: %d", FSK_DATARATE);
00153 #endif
00154     // Initialize Radio driver
00155     RadioEvents.TxDone = OnTxDone;
00156     RadioEvents.RxDone = OnRxDone;
00157     RadioEvents.RxError = OnRxError;
00158     RadioEvents.TxTimeout = OnTxTimeout;
00159     RadioEvents.RxTimeout = OnRxTimeout;    
00160     if (Radio->Init( &RadioEvents ) == false) {
00161         while(1) {
00162             dprintf("Radio could not be detected!");
00163             wait( 1 );
00164         }
00165     }
00166 
00167     
00168     switch(Radio->DetectBoardType()) {
00169         case SX1276MB1LAS:
00170             if (DEBUG_MESSAGE)
00171                 dprintf(" > Board Type: SX1276MB1LAS <");
00172             break;
00173         case SX1276MB1MAS:
00174             if (DEBUG_MESSAGE)
00175                 dprintf(" > Board Type: SX1276MB1LAS <");
00176         case MURATA_SX1276:
00177             if (DEBUG_MESSAGE)
00178                 dprintf(" > Board Type: MURATA_SX1276_STM32L0 <");
00179             break;
00180         case RFM95_SX1276:
00181             if (DEBUG_MESSAGE)
00182                 dprintf(" > HopeRF RFM95xx <");
00183             break;
00184         default:
00185             dprintf(" > Board Type: unknown <");
00186     }
00187 
00188     Radio->SetChannel(RF_FREQUENCY ); 
00189 
00190 #if USE_MODEM_LORA == 1
00191     
00192     if (LORA_FHSS_ENABLED)
00193         dprintf("             > LORA FHSS Mode <");
00194     if (!LORA_FHSS_ENABLED)
00195         dprintf("             > LORA Mode <");
00196 
00197     Radio->SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
00198                          LORA_SPREADING_FACTOR, LORA_CODINGRATE,
00199                          LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
00200                          LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, 
00201                          LORA_IQ_INVERSION_ON, 2000 );
00202     
00203     Radio->SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
00204                          LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
00205                          LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
00206                          LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, 
00207                          LORA_IQ_INVERSION_ON, true );
00208                          
00209 #elif USE_MODEM_FSK == 1
00210 
00211     dprintf("              > FSK Mode <");
00212     Radio->SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0,
00213                          FSK_DATARATE, 0,
00214                          FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON,
00215                          FSK_CRC_ENABLED, 0, 0, 0, 2000 );
00216     
00217     Radio->SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
00218                          0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
00219                          0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED,
00220                          0, 0, false, true );
00221                          
00222 #else
00223 
00224 #error "Please define a modem in the compiler options."
00225 
00226 #endif
00227      
00228     if (DEBUG_MESSAGE)
00229         dprintf("Starting Tx loop"); 
00230 
00231         
00232     Radio->Rx( RX_TIMEOUT_VALUE );
00233     
00234     SX1276DataTx[0] = 0x0A;
00235     SX1276DataTx[1] = 0x0B;
00236     SX1276DataTx[2] = 0x0C;
00237     SX1276DataTx[3] = 0x0D;
00238     
00239     while(1)
00240     
00241     //SX1276PingPong();
00242         if(ser->readable() >= 1) {
00243         //if(0) {
00244             if(ser->getc() == '~') 
00245             {
00246                 for(int r=0; r<=3; r++){
00247                     while(ser->readable() == 0);
00248                     serialRxBuffer[r] = ser->getc();
00249                 }
00250                 //memcpy(serialRxBuffer, SX1276DataTx, 4);
00251                 ser->printf("Transmitting data: %x%x%x%x\n",serialRxBuffer[0], serialRxBuffer[1], serialRxBuffer[2], serialRxBuffer[3]);
00252                 //ser->printf("Transmitting data: %x%x%x%x\n\r",SX1276DataTx[0], SX1276DataTx[1], SX1276DataTx[2], SX1276DataTx[3]);
00253                 
00254                 SX1276Comm(serialRxBuffer, 1, 1); 
00255             }
00256             else {
00257                 //mode = 1;
00258                 //SX1276Comm(SX1276DataTx, 1, 1);
00259             }
00260         }                   
00261     
00262     
00263 }
00264 
00265 
00266 
00267 
00268 void SystemClock_Config(void)
00269 {
00270 #ifdef B_L072Z_LRWAN1_LORA
00271     /* 
00272      * The L072Z_LRWAN1_LORA clock setup is somewhat differnt from the Nucleo board.
00273      * It has no LSE.
00274      */
00275     RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
00276     RCC_OscInitTypeDef RCC_OscInitStruct = {0};
00277 
00278     /* Enable HSE Oscillator and Activate PLL with HSE as source */
00279     RCC_OscInitStruct.OscillatorType      = RCC_OSCILLATORTYPE_HSI;
00280     RCC_OscInitStruct.HSEState            = RCC_HSE_OFF;
00281     RCC_OscInitStruct.HSIState            = RCC_HSI_ON;
00282     RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
00283     RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_ON;
00284     RCC_OscInitStruct.PLL.PLLSource       = RCC_PLLSOURCE_HSI;
00285     RCC_OscInitStruct.PLL.PLLMUL          = RCC_PLLMUL_6;
00286     RCC_OscInitStruct.PLL.PLLDIV          = RCC_PLLDIV_3;
00287 
00288     if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
00289         // Error_Handler();
00290     }
00291 
00292     /* Set Voltage scale1 as MCU will run at 32MHz */
00293     __HAL_RCC_PWR_CLK_ENABLE();
00294     __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
00295 
00296     /* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
00297     while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {};
00298 
00299     /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
00300     clocks dividers */
00301     RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
00302     RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
00303     RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
00304     RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
00305     RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
00306     if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
00307         // Error_Handler();
00308     }
00309 #endif
00310 }
00311 
00312 void dump(const char *title, const void *data, int len, bool dwords)
00313 {
00314     dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len);
00315 
00316     int i, j, cnt;
00317     unsigned char *u;
00318     const int width = 16;
00319     const int seppos = 7;
00320 
00321     cnt = 0;
00322     u = (unsigned char *)data;
00323     while (len > 0) {
00324         ser->printf("%08x: ", (unsigned int)data + cnt);
00325         if (dwords) {
00326             unsigned int *ip = ( unsigned int *)u;
00327             ser->printf(" 0x%08x\r\n", *ip);
00328             u+= 4;
00329             len -= 4;
00330             cnt += 4;
00331             continue;
00332         }
00333         cnt += width;
00334         j = len < width ? len : width;
00335         for (i = 0; i < j; i++) {
00336             ser->printf("%2.2x ", *(u + i));
00337             if (i == seppos)
00338                 ser->putc(' ');
00339         }
00340         ser->putc(' ');
00341         if (j < width) {
00342             i = width - j;
00343             if (i > seppos + 1)
00344                 ser->putc(' ');
00345             while (i--) {
00346                 printf("%s", "   ");
00347             }
00348         }
00349         for (i = 0; i < j; i++) {
00350             int c = *(u + i);
00351             if (c >= ' ' && c <= '~')
00352                 ser->putc(c);
00353             else
00354                 ser->putc('.');
00355             if (i == seppos)
00356                 ser->putc(' ');
00357         }
00358         len -= width;
00359         u += width;
00360         ser->printf("\r\n");
00361     }
00362     ser->printf("--\r\n");
00363 }
00364 
00365 
00366 
00367 
00368 int SX1276PingPong() 
00369 {
00370 
00371     
00372     while( 1 )
00373     {
00374 #ifdef TARGET_STM32L4
00375         WatchDogUpdate();
00376 #endif
00377         
00378         switch( State )
00379         {
00380         case RX:
00381             *led3 = 0;
00382             if( isMaster == true )
00383             {
00384                 if( BufferSize > 0 )
00385                 {
00386                     if( memcmp(Buffer, PongMsg, sizeof(PongMsg)) == 0 )
00387                     {
00388                         *led = !*led;
00389                         dprintf( "...Pong" );
00390                         // Send the next PING frame            
00391                         memcpy(Buffer, PingMsg, sizeof(PingMsg));
00392                         // We fill the buffer with numbers for the payload 
00393                         for( i = sizeof(PingMsg); i < BufferSize; i++ )
00394                         {
00395                             Buffer[i] = i - sizeof(PingMsg);
00396                         }
00397                         //wait_ms( 10 ); 
00398                         Radio->Send( Buffer, BufferSize );
00399                     }
00400                     else if( memcmp(Buffer, PingMsg, sizeof(PingMsg)) == 0 )
00401                     { // A master already exists then become a slave
00402                         dprintf( "...Ping" );
00403                         *led = !*led;
00404                         isMaster = false;
00405                         // Send the next PONG frame
00406                         memcpy(Buffer, PongMsg, sizeof(PongMsg));        
00407                         // We fill the buffer with numbers for the payload 
00408                         for( i = sizeof(PongMsg); i < BufferSize; i++ )
00409                         {
00410                             Buffer[i] = i - sizeof(PongMsg);
00411                         }
00412                         //wait_ms( 10 ); 
00413                         Radio->Send( Buffer, BufferSize );
00414                     }
00415                     else // valid reception but neither a PING or a PONG message
00416                     {    // Set device as master ans start again
00417                         isMaster = true;
00418                         Radio->Rx( RX_TIMEOUT_VALUE );
00419                     }    
00420                 }
00421             }
00422             else
00423             {
00424                 if( BufferSize > 0 )
00425                 {
00426                     if( memcmp(Buffer, PingMsg, sizeof(PingMsg)) == 0 )
00427                     {
00428                         *led = !*led;
00429                         dprintf( "...Ping" );
00430                         // Send the reply to the PING string
00431                         memcpy(Buffer, PongMsg, sizeof(PongMsg));
00432                         // We fill the buffer with numbers for the payload 
00433                         for( i = sizeof(PongMsg); i < BufferSize; i++ )
00434                         {
00435                             Buffer[i] = i - sizeof(PongMsg);
00436                         }
00437                         //wait_ms( 10 );  
00438                         Radio->Send( Buffer, BufferSize );
00439                     }
00440                     else // valid reception but not a PING as expected
00441                     {    // Set device as master and start again
00442                         isMaster = true;
00443                         Radio->Rx( RX_TIMEOUT_VALUE );
00444                     }    
00445                 }
00446             }
00447             State = LOWPOWER;
00448             break;
00449         case TX:    
00450             *led3 = 1;
00451             if( isMaster == true )  
00452             {
00453                 dprintf("Ping..." );
00454             }
00455             else
00456             {
00457                 dprintf("Pong..." );
00458             }
00459             Radio->Rx( RX_TIMEOUT_VALUE );
00460             State = LOWPOWER;
00461             break;
00462         case RX_TIMEOUT:
00463             if( isMaster == true )
00464             {
00465                 // Send the next PING frame
00466                 memcpy(Buffer, PingMsg, sizeof(PingMsg));
00467                 for( i = sizeof(PingMsg); i < BufferSize; i++ )
00468                 {
00469                     Buffer[i] = i - sizeof(PingMsg);
00470                 }
00471                 //wait_ms( 10 ); 
00472                 Radio->Send( Buffer, BufferSize );
00473             }
00474             else
00475             {
00476                 Radio->Rx( RX_TIMEOUT_VALUE );  
00477             }             
00478             State = LOWPOWER;
00479             break;
00480         case RX_ERROR:
00481             // We have received a Packet with a CRC error, send reply as if packet was correct
00482             if( isMaster == true )
00483             {
00484                 // Send the next PING frame
00485                 memcpy(Buffer, PingMsg, sizeof(PingMsg));
00486                 for( i = 4; i < BufferSize; i++ )
00487                 {
00488                     Buffer[i] = i - 4;
00489                 }
00490                 //wait_ms( 10 );  
00491                 Radio->Send( Buffer, BufferSize );
00492             }
00493             else
00494             {
00495                 // Send the next PONG frame
00496                 memcpy(Buffer, PongMsg, sizeof(PongMsg));
00497                 for( i = sizeof(PongMsg); i < BufferSize; i++ )
00498                 {
00499                     Buffer[i] = i - sizeof(PongMsg);
00500                 }
00501                 //wait_ms( 10 );  
00502                 Radio->Send( Buffer, BufferSize );
00503             }
00504             State = LOWPOWER;
00505             break;
00506         case TX_TIMEOUT:
00507             Radio->Rx( RX_TIMEOUT_VALUE );
00508             State = LOWPOWER;
00509             break;
00510         case LOWPOWER:
00511             sleep();
00512             break;
00513         default:
00514             State = LOWPOWER;
00515             break;
00516         }    
00517     }
00518 }
00519 
00520 void OnTxDone(void *radio)
00521 {
00522     Radio->Sleep( );
00523     State = TX;
00524     if (DEBUG_MESSAGE)
00525         dprintf("> OnTxDone");
00526 }
00527 
00528 void OnRxDone(void *radio, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
00529 {
00530     Radio->Sleep( );
00531     BufferSize = size;
00532     memcpy( Buffer, payload, BufferSize );
00533     State = RX;
00534     if (DEBUG_MESSAGE)
00535         dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr);
00536     dump("Data:", payload, size);
00537 }
00538 
00539 void OnTxTimeout(void *radio)
00540 {
00541     *led3 = 0;
00542     Radio->Sleep( );
00543     State = TX_TIMEOUT;
00544     if(DEBUG_MESSAGE)
00545         dprintf("> OnTxTimeout");
00546 }
00547 
00548 void OnRxTimeout(void *radio)
00549 {
00550     *led3 = 0;
00551     Radio->Sleep( );
00552     Buffer[BufferSize-1] = 0;
00553     State = RX_TIMEOUT;
00554     if (DEBUG_MESSAGE)
00555         dprintf("> OnRxTimeout");
00556 }
00557 
00558 void OnRxError(void *radio)
00559 {
00560     Radio->Sleep( );
00561     State = RX_ERROR;
00562     if (DEBUG_MESSAGE)
00563         dprintf("> OnRxError");
00564 }
00565 
00566 #endif
00567 
00568 
00569 int SX1276Comm(uint8_t *commData, bool mode, bool ack)
00570 {    
00571     memcpy(Buffer, commData, sizeof(commData));
00572     Radio->Send( Buffer, BufferSize );
00573     wait_ms(500);
00574 /*
00575     switch( State ) {
00576         case RX:
00577             Radio->Rx( RX_TIMEOUT_VALUE );  
00578             
00579             //memcpy(Buffer, commData, sizeof(Buffer));
00580             //ser->printf("Rx Data\n\r", Buffer[0], Buffer[1], Buffer[2], Buffer[3]);
00581             memcpy(Buffer, commData, sizeof(commData));
00582             Radio->Send( Buffer, BufferSize );
00583             //State = LOWPOWER;
00584             break;
00585         case TX:
00586             
00587                 memcpy(Buffer, commData, sizeof(commData));
00588                 Radio->Send( Buffer, BufferSize );
00589            
00590             //State = LOWPOWER;
00591             break;
00592         case RX_TIMEOUT:
00593             
00594             
00595                 memcpy(Buffer, commData, sizeof(commData));
00596                 Radio->Send( Buffer, BufferSize );
00597             
00598             
00599             Radio->Rx( RX_TIMEOUT_VALUE );
00600             //State = LOWPOWER;
00601             break;
00602         case RX_ERROR:
00603             
00604            
00605                 memcpy(Buffer, commData, sizeof(commData));
00606                 Radio->Send( Buffer, BufferSize );
00607             
00608             wait_ms(10);
00609             Radio->Rx( RX_TIMEOUT_VALUE );
00610             //State = LOWPOWER;
00611             break;
00612         case TX_TIMEOUT:
00613             
00614                 memcpy(Buffer, commData, sizeof(commData));
00615                 Radio->Send( Buffer, BufferSize );
00616             
00617             //State = LOWPOWER;
00618             break;
00619         case LOWPOWER:
00620             sleep();
00621             break;
00622         default:
00623             //State = LOWPOWER;
00624             break;
00625     }
00626     */
00627 }