⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rf_test.c

📁 ti-Chipcon CC2430 zigbee Soc应用开发源码实例。包括rf,powermodes,clockmodes底层驱动源码。有了这些实例,包括误码率测试等。对你更好的理解和应用这颗芯片
💻 C
📖 第 1 页 / 共 2 页
字号:
    res = radioSend(&sendBuffer, 1, remoteAddr, DO_ACK);
    sendBall(ORIENTED_RIGHT);
    YLED = LED_OFF;

    if(res == TRUE)
    {
      // this first packet is ack'ed
      // send another packet
      res = radioReceive(&buffer, &length, PING_PONG_TIMEOUT, &sender);
    }

    if(res == TRUE)
    {
      // the second packet is ack'ed
      receiveBall(ORIENTED_RIGHT);
      lcdUpdate((char *)"OK!", (char *)"");
      printRSSI(buffer[length]);
    }
    else
    {
      lcdUpdate((char *)"Failed...", (char *)"");
      waitVisible(CLEARLY_VISIBLE);
    }

    waitVisible(CLEARLY_VISIBLE);
  }
}


/******************************************************************************
* @fn  perTestMode
*
* @brief
*      Function for performing a packet error rate (PER) test.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void perTestMode(void)
{
  byte sendBuffer;
  char lcdLine[16];

  byte *receiveBuffer;
  byte length;
  byte res;
  byte sender;

  uint8  per;
  uint16 failed, correct;

  failed = correct = 0;

  // send a packet to check that we have a receiver available
  sendBuffer = PER_TEST_REQUEST;
  res = radioSend(&sendBuffer, sizeof(sendBuffer), remoteAddr, DO_ACK);

  if(res == TRUE)
  {
    // we found a receiver, continue with packets
    sprintf(lcdLine, (char *)"Correct: %d", correct);
    lcdUpdateLine(LINE1, lcdLine);
    sprintf(lcdLine, (char *)"Failed : %d", failed);
    lcdUpdateLine(LINE2, lcdLine);

    while( (correct + failed) < PER_TOTAL_PACKET_NUMBER && !stopApplication() )
    {
      if( radioReceive(&receiveBuffer, &length, PER_RECEIVE_TIMEOUT, &sender) )
      {
        // a packet is received
        correct++;
        sprintf(lcdLine, (char *)"Correct: %d", correct);
        lcdUpdateLine(LINE1, lcdLine);
      }
      else
      {
        // a packet isn't received, radioReceive timeout
        failed++;
        sprintf(lcdLine, (char *)"Failed : %d", failed);
        lcdUpdateLine(LINE2, lcdLine);
      }
    }

    per = (float)failed/(float)PER_TOTAL_PACKET_NUMBER * 100;
    sprintf(lcdLine, (char *)"PER: %d%%", per);
    lcdUpdateLine(LINE1, lcdLine);
    sprintf(lcdLine, (char *)"(%d / %d)", failed, PER_TOTAL_PACKET_NUMBER);
    lcdUpdateLine(LINE2, lcdLine);
  }
  else
  {
    lcdUpdate((char *)"Reciever Node",(char *)"Unreachable!");
  }

  haltApplicationWithLED();

  return;
}


/******************************************************************************
* @fn  receiveMode
*
* @brief
*      Function for receiving data.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void receiveMode(void)
{
  byte *receiveBuffer;
  byte length;
  byte res;
  byte sender;

  pingPongInit();

  while( !stopApplication() )
  {
    res = radioReceive(&receiveBuffer, &length, RECEIVE_TIMEOUT, &sender);

    if(res == TRUE)
    {
      GLED = LED_ON;
      if(*receiveBuffer == PING_PONG_REQUEST)
      {
        pingPongResponse();
      }
      else if(*receiveBuffer == PER_TEST_REQUEST)
      {
        conductPerTest();
      }
      else
      {
        printRSSI(receiveBuffer[length]);
        showState();
      }
    }
    else
    {
      lcdUpdate((char *)"Waiting",(char *)"");
      GLED = LED_OFF;
    }

    GLED = LED_OFF;
  }
  return;
}


/******************************************************************************
* @fn  showState
*
* @brief
*      Print "Sending" or "Receiving" on LINE1.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void showState(void)
{
   if (RxTxState == SEND){
      lcdUpdateLine(LINE1, (char *)"Sending");
   }
   else{
      lcdUpdateLine(LINE1, (char *)"Receiving");
   }
   halWait(0xFF);
}


/******************************************************************************
* @fn  pingPongResponse
*
* @brief
*      Handles response to pingpong.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void pingPongResponse(void)
{
  byte transmitBuffer;

  receiveBall(ORIENTED_LEFT);
  halWait(1);
  YLED = LED_ON;
  transmitBuffer = PING_PONG_RESPONSE;
  radioSend(&transmitBuffer, 1, remoteAddr, DO_NOT_ACK);
  sendBall(ORIENTED_LEFT);
  YLED = LED_OFF;
}


/******************************************************************************
* @fn  conductPerTest
*
* @brief
*      Sends 1000 packets to calculate PER.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void conductPerTest(void)
{
  word i;
  word sendBuffer[2];
  char lcdLine[16];

  lcdUpdate((char *)"PER test", (char *)"");

  sendBuffer[1] = PER_TOTAL_PACKET_NUMBER;

  for( i = 1; i < PER_TOTAL_PACKET_NUMBER + 1 && !stopApplication(); i++ )
  {
    halWait(15);
    sendBuffer[0] = i;
    sprintf(lcdLine, (char *)"Sending: %d", i);
    lcdUpdateLine(LINE2, lcdLine);

    radioSend((byte*) sendBuffer, sizeof(sendBuffer), remoteAddr, DO_NOT_ACK);
  }
}


/******************************************************************************
* @fn  printRSSI
*
* @brief
*      Printing RSSI on the LCD-display.
*
* Parameters:
*
* @param  int8 rssi
*         New RSSI value.
*
*
* @return void
*
******************************************************************************/
void printRSSI(int8 rssi)
{
   char rssiString[16];
   // -45 is RSSI_OFFSET from the data sheet
   sprintf(rssiString,  (char const *)"%d dBm", rssi - 45);

   lcdUpdateLine(LINE2, rssiString);
}


/******************************************************************************
* @fn  getFrequency
*
* @brief
*      Get current frequency.
*
* Parameters:
*
* @param  void
*
* @return uint32
*         Current frequency.
*
******************************************************************************/
uint32 getFrequency(void)
{
   char *menuText[] = {(char*)" 2405", (char*)" 2410", (char*)" 2415", (char*)" 2420", (char*)" 2425", (char*)" 2430", (char*)" 2435", (char*)" 2440", (char*)" 2445", (char*)" 2450", (char*)" 2455", (char*)" 2460", (char*)" 2465", (char*)" 2470", (char*)" 2475", (char*)" 2480", (char*)" 2485"};
   uint8 selection;

   selection = lcdMenu(menuText, 17);
   if(selection != ABORT_MENU)
   {
      return ((uint32)2405000 + (uint32)5000*selection);
   }
   else
   {
      return ((uint32)2405000);
   }
}


/******************************************************************************
* @fn  getAddress
*
* @brief
*      Get current address.
*
* Parameters:
*
* @param  uint8 a
*
* @return uint8
*
******************************************************************************/
uint8 getAddress(uint8 a)
{
   uint8 address = a;
   char line[16];
   JOYSTICK_DIRECTION jsv;

   while(getJoystickDirection() != CENTRED);

   while((jsv = getJoystickDirection()) != RIGHT)
   {
      while(getJoystickDirection() != CENTRED);

      if(jsv == UP)
      {
         address++;
      }
      else if (jsv == DOWN)
      {
         address--;
      }

      sprintf(line,(char *)"Address: %d     ",address);
      lcdUpdateLine(LINE2, line);
   }
   return address;
}


/******************************************************************************
* @fn  clockmodes_init
*
* @brief
*     Setup for incorperating the functions in this
*     module with the menu
*
* Parameters:
*
* @param  APPLICATION *a
*         Main application
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void rf_test_init(APPLICATION *a)
{
   a->menuText = (char *)"RF Test";
   a->description = (char *)"Radio comm.";
   a->main_func = rf_test_main;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -