?? rf_test.c
字號:
/******************************************************************************
Filename: rf_test.c
Target: cc2430
Revised: 16/12-2005
Revision: 1.0
Description:
This file provides 4 small tests which demonstrates use of the radio.
******************************************************************************/
#include "app_ex.h"
#include "cul.h"
#include "pingPong.h"
#include "menu.h"
#include "string.h"
#define ADDRESS_0 0x01
#define ADDRESS_1 0x02
#define SEND 0
#define RECEIVE 1
#define SINGLE 0
#define CONTINUOUS 1
#define PING_PONG 2
#define PER_TEST 3
#define EXIT 4
#define RECEIVE_TIMEOUT 1200
#define PING_PONG_TIMEOUT 1200
#define PING_PONG_REQUEST 0x80
#define PING_PONG_RESPONSE 0x40
#define PER_RECEIVE_TIMEOUT 10000
#define PER_TOTAL_PACKET_NUMBER 1000
#define PER_TEST_REQUEST 0x20
void initRfTest(void);
void rf_test_main(void);
void receivePacket(UINT8 *receiveByte);
void sendPacket(UINT8 sendByte);
void printAddress(UINT8 address);
void printRSSI(INT8 rssi);
UINT32 getFrequency(void);
UINT8 getAddress(UINT8 a);
void waitVisible(BOOL visibility);
void receiveMode(void);
void singleMode(void);
void contionuousMode(void);
void pingPongMode(void);
void perTestMode(void);
void showState(void);
void conductPerTest(void);
void pingPongResponse(void);
void SendTestDisp( void );
//UINT8 address0; //my adresse
//UINT8 address1; //other adress
UINT8 RxTxState;
UINT8 myAddr;
UINT8 remoteAddr;
BOOL remoteAddressSet = FALSE;
BOOL myAddressSet = FALSE;
//*********************************************************************************
//函數名:void MenuMenuDisp( void )
//功能:主菜單顯示
//輸入:無
//輸出:無
//*********************************************************************************
void SendTestDisp( void )
{
INT8U sel;
/*
if(LanguageSel == 1)
{
strcpy((char*)MenuItem[0] ,"1:Single ");
strcpy((char*)MenuItem[1] ,"2:Continous ");
strcpy((char*)MenuItem[2] ,"3:PER Test ");
}
else
{
strcpy((char*)MenuItem[0] ,"1:單次發送 ");
strcpy((char*)MenuItem[1] ,"2:連續發送 ");
strcpy((char*)MenuItem[2] ,"3:誤碼率測試 ");
}
*/
strcpy((char*)MenuItem[0] ,"1:Single ");
strcpy((char*)MenuItem[1] ,"2:Continous ");
strcpy((char*)MenuItem[2] ,"3:PER Test ");
FirstItem = 0;
NowItem = 0;
while(1)
{
sel = DrawMenu(MenuItem , 3);
if(sel == 0)
{
halWait(10);
singleMode();
}
else if(sel == 1)
{
halWait(10);
contionuousMode();
}
else if(sel == 2)
{
halWait(10);
perTestMode();
}
else if(sel == 0xff)
{
YLED = LED_OFF;//GLED = LED_OFF
/*
if(LanguageSel == 1)
{
strcpy((char*)MenuItem[0] ,"1:Sender ");
strcpy((char*)MenuItem[1] ,"2:Receiver ");
strcpy((char*)MenuItem[2] ,"3:Set_Freq ");
strcpy((char*)MenuItem[3] ,"4:Set_MeAddr ");
strcpy((char*)MenuItem[4] ,"5:Set_RemoteAdd ");
}
else
{
strcpy((char*)MenuItem[0] ,"1:發送模式 ");
strcpy((char*)MenuItem[1] ,"2:接收模式 ");
strcpy((char*)MenuItem[2] ,"3:設定頻道 ");
strcpy((char*)MenuItem[3] ,"4:設定本機地址 ");
strcpy((char*)MenuItem[4] ,"5:設定目的地址 ");
}
*/
strcpy((char*)MenuItem[0] ,"1:Sender ");
strcpy((char*)MenuItem[1] ,"2:Receiver ");
strcpy((char*)MenuItem[2] ,"3:Set_Freq ");
strcpy((char*)MenuItem[3] ,"4:Set_MeAddr ");
strcpy((char*)MenuItem[4] ,"5:Set_RemoteAdd ");
FirstItem = 0;
NowItem = 0;
break;
}
}
}
//*********************************************************************************
//函數名:void MenuMenuDisp( void )
//功能:主菜單顯示
//輸入:無
//輸出:無
//*********************************************************************************
void RfTestDisp( void )
{
INT8U sel;
UINT32 frequency = 2405000;
/*
if(LanguageSel == 1)
{
strcpy((char*)MenuItem[0] ,"1:Sender ");
strcpy((char*)MenuItem[1] ,"2:Receiver ");
strcpy((char*)MenuItem[2] ,"3:Set_Freq ");
strcpy((char*)MenuItem[3] ,"4:Set_MeAddr ");
strcpy((char*)MenuItem[4] ,"5:Set_RemoteAdd ");
}
else
{
strcpy((char*)MenuItem[0] ,"1:發送模式 ");
strcpy((char*)MenuItem[1] ,"2:接收模式 ");
strcpy((char*)MenuItem[2] ,"3:設定頻道 ");
strcpy((char*)MenuItem[3] ,"4:設定本機地址 ");
strcpy((char*)MenuItem[4] ,"5:設定目的地址 ");
}
*/
strcpy((char*)MenuItem[0] ,"1:Sender ");
strcpy((char*)MenuItem[1] ,"2:Receiver ");
strcpy((char*)MenuItem[2] ,"3:Set_Freq ");
strcpy((char*)MenuItem[3] ,"4:Set_MeAddr ");
strcpy((char*)MenuItem[4] ,"5:Set_RemoteAdd ");
FirstItem = 0;
NowItem = 0;
remoteAddressSet = FALSE;
myAddressSet = FALSE;
INIT_RLED();
INIT_YLED();
while(1)
{
sel = DrawMenu(MenuItem , 5 );
if(sel == 0)
{
if(myAddressSet == FALSE)
{
myAddr = ADDRESS_0;
}
if(remoteAddressSet == FALSE)
{
remoteAddr = ADDRESS_1;
}
radioInit(frequency, myAddr);
INT_GLOBAL_ENABLE(INT_ON);
SendTestDisp();
}
else if(sel == 1)
{
if(myAddressSet == FALSE)
{
myAddr = ADDRESS_1;
}
if(remoteAddressSet == FALSE)
{
remoteAddr = ADDRESS_0;
}
halWait(10);
radioInit(frequency, myAddr);
INT_GLOBAL_ENABLE(INT_ON);
halWait(10);
receiveMode();
}
else if(sel == 2)
{
frequency = getFrequency();
}
else if(sel == 3)
{
myAddr = getAddress(myAddr);
myAddressSet = TRUE;
}
else if(sel == 4)
{
remoteAddr = getAddress(remoteAddr);
remoteAddressSet = TRUE;;
}
else if(sel == 0xff)
{
TopDisp = 1;
break;
}
}
}
/******************************************************************************
* @fn singleMode
*
* @brief
* Function for transferring one packet
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
void singleMode(void)
{
BYTE sendBuffer[] = "Hello";
BOOL res;
ClearScreen();
Print(0,5,"--singlemode-- ",1);
/*
if(LanguageSel == 1)
{
Print6(2,20,"OK for START ",1);
}
else
{
Print(2,10,"按OK鍵開始: ",1);
}
*/
Print6(2,20,"OK for START ",1);
Rectangle(2 , 4 , 108 , 7);
while(TRUE)
{
if(ScanKey() == K_OK)
{
while(ScanKey() != 0xff);
Print(2,10," ",1);
YLED = LED_ON;
res = radioSend(sendBuffer, sizeof(sendBuffer), remoteAddr, DO_ACK);
YLED = LED_OFF;
if(res == TRUE)
{
//GLED = LED_ON;
Print(5,10," OK ",1);
waitVisible(CLEARLY_VISIBLE);
//GLED = LED_OFF;
return;
}
else
{
//GLED = LED_OFF;
/*
if(LanguageSel == 1)
{
Print(5,10,"Failed...",1);
}
else
{
Print(5,10,"失敗... ",1);
}
*/
Print(5,10,"Failed...",1);
waitVisible(CLEARLY_VISIBLE);
//GLED = LED_OFF;
return;
}
}
}
}
/******************************************************************************
* @fn contionuousMode
*
* @brief
* Function for transferring packets until stopped by user.
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
void contionuousMode(void)
{
INT8U i;
BOOL res;
INT8U count;
BYTE sendBuffer[] = "Hello";
ClearScreen();
Print(0,5,"-contionumode-",1);
Rectangle(10 , 3 , 118 , 6);
while(!stopApplication()){
//GLED = LED_OFF;
YLED = LED_ON;
res = radioSend(sendBuffer, sizeof(sendBuffer), remoteAddr, DO_ACK);
YLED = LED_OFF;
if(res == TRUE)
{
if(++count > 1)
{
//GLED = LED_ON;
Print(4,56,"OK",1);
if(count >=250)
{
count = 2;
}
}
//printRSSI();
}
else
{
count = 0;
//GLED = LED_OFF;
/*
if(LanguageSel == 1)
{
Print(4,10,"Failed...",1);
}
else
{
Print(4,10,"失敗...",1);
}
*/
Print(4,10,"Failed...",1);
}
for(i=0; i<10; i++)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -