📄 pc_radio.c
字号:
/****************************************************************************
PC Radio.c
Title: ACCERLEROMETER.c
This application is used in conjunction with the 13192SARD SDK.
Out of reset if any pushbutton is pressed the device becomes a transmitter.
Otherwise the radio receives only.
TX: The transmitter is constantly monitoring the XYZ axis of the
accelerometers. This data is formatted and sent over the
air at the hardcoded channel in the format:
x{Data}y{data}z{data}
When the data is sent LED4 is toggled.
RX: When the RX radio receives the x{Data}y{data}z{data} packet the packet is
forwarded to the SCI port on the 13192SARD in the same format.
The UART is set to 38400 8-N-1 with no flow control. When a xyz packet
is received the LED3 is toggled.
On the 13192SARD make sure that jumpers are placed in 1-2, 3-4, and 11-12.
This connects the XYZ voltages to ADC channel 0,1,7.
$Author: b06900 $
$Date: 2008/03/05 22:48:47 $
$Name: $
****************************************************************************/
#include <hidef.h> /* for EnableInterrupts macro */
#include "pub_def.h"
#include "APP_SMAC_API.h"
#include "freescale_radio_hardware.h"
#include "SCI.h"
#include "kbi.h"
#include "drivers.h"
#include "accelerometer.h"
#include "ledFunctions.h"
/////////////////////////////
/* note: Buad Rate = 38400 */
/////////////////////////////
/* Enums, types */
/* Global Variables */
INT8 gi8AppStatus = 0;
INT8 gi8PCRadioState = 0;
UINT8 gu8Channel = CHANNEL_NUMBER;
tRxPacket gsRxPacket;
UINT8 gau8TxDataBuffer[16];
tAccelCal sCalValues;
tTxPacket gsTxPacket;
char gua8sciString[7];
UINT8 gau8RxDataBuffer[16];
UINT16 gu16msTimer = 0;
UINT8 gu8RTxMode;
UINT16 gu16timerEvent[2];
UINT16 gu16Events;
extern UINT8 gu8SCIData[128];
extern UINT8 gu8SCIDataFlag;
/**************************************************************
* Function: RX_accel
* Parameters: none
* Return: none
*
* This is the main thread of execution when no button is pressed
* on reset.
**************************************************************/
void PC_Radio_App(void) {
EnableInterrupts;
gua8sciString[0] = 'x';
gua8sciString[2] = 'y';
gua8sciString[4] = 'z';
/**************************************************************
* RX_accel main loop
**************************************************************/
switch (gi8PCRadioState)
{
case IDLE_STATE:
/*Switch to RECEIVER_ALWAYS_ON */
gi8PCRadioState = RECEIVER_ALWAYS_ON;
break;
case RECEIVER_ALWAYS_ON:
MLMERXEnableRequest(&gsRxPacket, 0);
LOW_POWER_WHILE();
break;
case SEND_PING_ACK_STATE:
gau8TxDataBuffer[0] = 'p';
gau8TxDataBuffer[1] = gu8Channel;
gau8TxDataBuffer[2] = sCalValues.NxOff;
gau8TxDataBuffer[3] = sCalValues.NxMax;
gau8TxDataBuffer[4] = sCalValues.NyOff;
gau8TxDataBuffer[5] = sCalValues.NyMax;
gau8TxDataBuffer[6] = sCalValues.NzOff;
gau8TxDataBuffer[7] = sCalValues.NzMax;
gsTxPacket.u8DataLength = 8;
(void)MCPSDataRequest(&gsTxPacket);
gi8PCRadioState = RECEIVER_ALWAYS_ON;
break;
/* Should not get here. */
default:
gi8PCRadioState = RECEIVER_ALWAYS_ON;
}
if (gu8SCIDataFlag == 1)
{
switch (gu8SCIData[0]) {
/* Initial Handshake from the PC GUI */
case 'R':
SCITransmitStr("N");
break;
/* Send the PC application "xNyNzN" */
case 'V':
//// SCITransmitArray(gu8TxAccelState, 6);
SCITransmitArray(gua8sciString, 6);
break;
/* Received Cal Factor "K" + 9 cal Bytes */
case 'K':
/* Not Implememted */
break;
/* Received Request for bytes - rsp with "k" + 6 cal bytes */
case 'k':
/* Not Implememted */
break;
/* Current Query */
case 'C':
SCIStartTransmit('c');
SCIStartTransmit(gu8Channel);
break;
}
gu8SCIDataFlag = 0;
}
}
/**************************************************************
* Function: MCPS_data_indication
* Parameters: gsRxPacket_t
* Return: none
*
* This is the callback function for when a valid packet has been
* decoded by the radio. The valid packet is passed to the app
* via this MCPS_data_indication callback function. All the data
* resides in the gsRxPacket in this function but is also passed
* back to the main via gsRxPacket in the main/RX_accel thread.
* This routine is in the interrupt processing call stack. It
* is not recommended to call other radio functions here.
**************************************************************/
void MCPSDataIndication(tRxPacket *gsRxPacket)
{
/*
* Place your code here to handle a mac layer data indication.
* RX packet is in the global structure
* gsRxPacket.dataLength and gsRxPacket.data
*/
if (gsRxPacket->u8Status == SUCCESS)
{
switch (gsRxPacket->pu8Data[0]) {
case 'x':
case 'X':
gua8sciString[1] = gsRxPacket->pu8Data[1];
LED1 ^= 1;
break;
case 'y':
case 'Y':
gua8sciString[3] = gsRxPacket->pu8Data[1];
LED1 ^= 1;
break;
case 'z':
case 'Z':
gua8sciString[5] = gsRxPacket->pu8Data[1];
LED1 ^= 1;
break;
case 'P':
LED2 ^= 1; LED1 = LED_OFF; /*Toggle LED2 and turn off activity to match Remote */
if (gsRxPacket->pu8Data[2] & PING_ACK) {
gi8PCRadioState = SEND_PING_ACK_STATE;
}
if (gsRxPacket->pu8Data[2] == PING_NO_OPTIONS) {
LED4 = LED_OFF;
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
}
if (gsRxPacket->pu8Data[2] == PING_BATTERYSAVE_BUZZER_ON) {
LED4 = LED_ON;
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_ON;
delay(30);
BUZZER = BUZZER_OFF;
#endif
}
if (gsRxPacket->pu8Data[2] == PING_BATTERYSAVE_BUZZER_OFF) {
LED4 = LED_OFF;
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
}
if ((gsRxPacket->pu8Data[1] == FREEFALL_STATE) &&
gsRxPacket->pu8Data[2] != PING_FREEFALL)
{
LED4 = LED_OFF;
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
}
break;
case XYZ_STATE:
break;
case FREEFALL_STATE:
if (gsRxPacket->pu8Data[1] == PING_FREEFALL) {
LED4 = LED_ON;
#if BUZZER_ENABLED==TRUE
delay(50);
BUZZER = BUZZER_ON;
delay(50);
BUZZER = BUZZER_OFF;
#endif
}
break;
case SHOCK_STATE:
switch (gsRxPacket->pu8Data[1]) {
case X_AXIS:
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_ON;
#endif
LED4 = LED_ON;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
LED4 = LED_OFF;
delay(10);
break;
case Y_AXIS:
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_ON;
#endif
LED4 = LED_ON;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
LED4 = LED_OFF;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_ON;
#endif
LED4 = LED_ON;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
LED4 = LED_OFF;
delay(10);
break;
case Z_AXIS:
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_ON;
#endif
LED4 = LED_ON;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
LED4 = LED_OFF;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_ON;
#endif
LED4 = LED_ON;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
LED4 = LED_OFF;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_ON;
#endif
LED4 = LED_ON;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
LED4 = LED_OFF;
delay(10);
break;
}
break;
case ANTITHEFT_STATE:
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_ON;
#endif
LED4 = LED_ON;
delay(10);
#if BUZZER_ENABLED==TRUE
BUZZER = BUZZER_OFF;
#endif
LED4 = LED_OFF;
break;
}
}
/* Turn Radio Back on for next packet */
gi8PCRadioState = RECEIVER_ALWAYS_ON;
}
void MLMEMC13192ResetIndication (void)
{
/* Not implemented. */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -