ZigBee Spy node..
Basically what Im trying to do now is to build a table with the source ID and Destination ID on all transmiter and reciever.
The Spy reciever would only listens to the network and transmit data back to the computer hyperterminal via the com port.
problem is how do i edit this code so that a table with source ID and Destination ID table can be sent to hyperterminal
CODE:
/**************************************************************
* Device Program Operation
* June 30, 04
* This program performs the following:
* On power-up or reset, the LEDs will "walk" for 1 second to indicate
* the unit is a device. Next, the security number (i.e. SECURITY) LED
* is flashed on for 1 second to identify the selection.
* The unit then pauses and waits for the operator to select a desired
* u8Channel by pressing the corresponding pushbutton. The selected u8Channel
* will flash on the LED for 1 second.
* The unit again pauses and waits for the opertor to select the desired
* device number by pressing the corresponding pushbutton, The selected
* device number will flash on the LED for 1 second.
* Initialization of the device is now complete.
* To use the device:
* Any pushbutton may be depressed to toggle the status of the
* corresponding LED. This is for local control.
* If addressed (and if the SECURITY matches), the controller may
* request any LED to toggle, or the controller may request the status
* of an individual LED.
* The device will retransmit any data received and intended for another device
* within the SECURITY grouping, acting as a repeater.
* The device has a unique "security" number (i.e. SECURITY) and device
* number (i.e. u8DeviceNum).
* The program assumes all LEDs are connected to the same PORT.
* The target platform may be selected in the pub_def.h file.
* Many application specific details are in lighting_demo_device.h.
* Notes on the optional buzzer:
* If the optional buzzer is used, it may chirp on to indicate contention
* with another 802.15.4 device.
*
* $Author: a20639 $
* $Date: 2005/09/09 15:02:45 $
* $Name: $
**************************************************************/
/**************************************************************
* Includes
**************************************************************/
#include /* for EnableInterrupts macro */
#include "device_header.h" /* include peripheral declarations */
#include "pub_def.h"
#include "mcu_hw_config.h"
#include "MC13192_hw_config.h"
#include "simple_mac.h"
#include "bootloader user api.h"
#include "lighting_demo_device.h"
/**************************************************************
* Data definitions
**************************************************************/
byte gu8RTxMode; /* Current mode of the MC13192 XCVR */
byte LEDS; /* LED on/off information */
byte rxcount;
/**************************************************************
* Main Program
**************************************************************/
void main(void)
{
tTxPacket sTxPacket;
tRxPacket sRxPacket;
byte au8RxDataBuffer[26];
byte au8TxDataBuffer[26];
/* Initialize variables */
UINT16 u16LEDOldTime = 0;
UINT16 u16RTXOldTime = 0;
UINT16 u16PBOldTime = 0;
UINT16 u16OldTime = 0;
UINT16 u16NewTime = 0;
UINT16 u16LagTime1 = 0;
UINT16 u16LagTime2 = 0;
UINT16 u16Count = 0;
UINT8 u8PBState = 0;
UINT8 u8AppStatus = 0;
UINT8 u8GetLed = 0;
UINT8 u8Crap = 0;
UINT8 u8XcvrMode = 0;
UINT8 u8LEDStatus = 1;
UINT8 u8DeviceNum = 1;
UINT8 u8DeviceLed = u8DeviceNum;
UINT8 u8LightLed = 0x05; /* initial */
UINT8 u8Garbage = 0;
UINT8 u8Channel = 1;
UINT8 u8LastDsn = 0xFF;
UINT8 u8Count1 = 0;
UINT8 u8RfIcVersion=0;
sTxPacket.u8DataLength = 0;
sTxPacket.pu8Data = &au8TxDataBuffer[0];
sRxPacket.u8DataLength = 0;
sRxPacket.pu8Data = &au8RxDataBuffer[0];
sRxPacket.u8MaxDataLength = 30;
sRxPacket.u8Status = 0;
MCUInit();
MC13192Init();
/* Begin init */
rxcount = 0x00; /* Number of times device received the same request */
LED1DIR = 1; /* LED directions */
LED2DIR = 1;
LED3DIR = 1;
LED4DIR = 1;
MLMESetMC13192ClockRate(MC13192_CLKO_FREQ); /* 8 MHz bus clock (see lighting_demo_device.h) */
UseExternalClock();
/******************************************************************
To adjust output power call the MLME_MC13192_PA_output_adjust() with:
MAX_POWER (+3 to +5dBm)
NOMINAL_POWER (0 dBm)
MIN_POWER ~(-16dBm)
or somewhere custom ? (0-15, 11 (NOMINAL_POWER) being Default power)
******************************************************************/
//MLMEMC13192PAOutputAdjust(MAX_POWER); //Set MAX power setting
MLMEMC13192PAOutputAdjust(MIN_POWER); //Set MIN power setting
//MLMEMC13192PAOutputAdjust(NOMINAL_POWER); //Set Nominal power setting
/* Application init */
SRTISC=SRTISC&~0x07; /* Disable wake up timer. */
SPMSC2=SPMSC2&~0x03; /* Enable deep sleep mode stop3. */
TPM1SC = 0x0F; /* Timer divide by 128. (16uS timebase for 8MHz bus clock). */
PB0PU = 1; /* Pushbutton directions and pull-ups */
PB0DIR = 0;
PB1PU = 1;
PB1DIR = 0;
PB2PU = 1;
PB2DIR = 0;
PB3PU = 1;
PB3DIR = 0;
KBI1SC_KBIMOD = 0;
KBI1SC_KBI1E =0; /* Pushbutton interrupts not used */
PB0IE =0;
PB1IE =0;
PB2IE =0;
PB3IE =0;
#ifdef BOOTLOADER_ENABLED
boot_init(); //Initialize the bootloader.
#endif BOOTLOADER_ENABLED
#ifdef BOOTLOADER_ENABLED
boot_call(); //Check for user request to run bootloader.
//App will not return, if Bootloader is requested.
#endif BOOTLOADER_ENABLED
#if defined (AXM_0308C)
BUZZDIR = 1; /* Optional buzzer and off */
BUZZ = 0;
#endif
/* Enable all interrupts and ready to go */
MC13192_IRQ_IE_BIT = 1;
EnableInterrupts;
/* "Walk" LEDs to indicate this is a device. */
LedDrive(0x01);
MCUDelay (WALKON);
LedDrive(0x02);
MCUDelay (WALKON);
LedDrive(0x03);
MCUDelay (WALKON);
LedDrive(0x04);
MCUDelay (WALKON);
/* LEDs off for a short */
LedDrive(u8LightLed);
MCUDelay (LONGFLASHOFF);
/* Allow SECURITY LED to glow for a short. Indicates Group. */
LedDrive(SECURITY);
MCUDelay(LONGFLASHON);
/* Now all LEDs off. */
LedDrive(u8LightLed);
/* Wait for user to select the u8Channel. */
while ((PB0 == 1) && (PB1 == 1) && (PB2 == 1) && (PB3 == 1)); /* All PBs released */
MCUDelay(DEBOUNCE); /* PB pushed. Wait for debounce. */
if (PB0 == 0)
{
u8Channel = 1;
}
if (PB1 == 0)
{
u8Channel = 2;
}
if (PB2 == 0)
{
u8Channel = 3;
}
if (PB3 == 0)
{
u8Channel = 4;
}
while ((PB0 ==0) || (PB1 ==0) || (PB2 ==0) || (PB3 ==0)); /* A PB is still depressed */
MCUDelay(DEBOUNCE); /* All PBs released. Wait for debounce. */
LedDrive(u8Channel); /* Display selected u8Channel. */
MCUDelay(LONGFLASHON);
LedDrive(u8LightLed); /* LEDs off. */
/* Set u8Channel */
MLMESetChannelRequest(((u8Channel-1)<<2) + (u8Channel-1)); /* Set the selected u8Channel. */
/* Wait for user to select the u8DeviceNum. */
while ((PB0 == 1) && (PB1 == 1) && (PB2 == 1) && (PB3 == 1)); /* All PBs released */
MCUDelay(DEBOUNCE); /* PB pushed. Wait for debounce. */
if (PB0 == 0)
{
u8DeviceNum = 1;
}
if (PB1 == 0)
{
u8DeviceNum = 2;
}
if (PB2 == 0)
{
u8DeviceNum = 3;
}
if (PB3 == 0)
{
u8DeviceNum = 4;
}
while ((PB0 ==0) || (PB1 ==0) || (PB2 ==0) || (PB3 ==0)); /* A PB is still depressed */
MCUDelay(DEBOUNCE); /* All PBs released. Wait for debounce. */
LedDrive(u8DeviceNum); /* Display selected device number. */
u8DeviceLed = u8DeviceNum;
if (u8DeviceNum == 1) /* Set repeater TDMA values */
{
u16LagTime1 = 63; /* 1ms */
}
if (u8DeviceNum == 2)
{
u16LagTime1 = 250; /* 4ms */
}
if (u8DeviceNum == 3)
{
u16LagTime1 = 625; /* 10ms */
}
if (u8DeviceNum == 4)
{
u16LagTime1 = 1188; /* 19ms */
}
u16LagTime2 = 2563-u16LagTime1; /* 41ms - value */
/* Assumes total time for Rx extraction and Tx is 1-3mS */
/* Maximum lag is 4+3+10+3+19+3 or 42mS */
/* Minimum lag time is 1+1 or 2mS */
MCUDelay(LONGFLASHON);
LedDrive(u8LightLed); /* LEDs off. Initialization complete. */
/* Init timer vars and global LEDS */
u16LEDOldTime = MCUReadTmr1 ();
u16RTXOldTime = u16LEDOldTime;
LEDS = LEDPORT; /* Initialize LEDS to the actual port setting */
MLMERXEnableRequest(&sRxPacket, 0x); /* Activate the receiver */
/**************************************************************
* Main While Loop - Runs continously
**************************************************************/
for (;;)
{
/* u8PBState=0 is waiting for a PB to be pushed. */
/* u8PBState=1 is waiting for a PB high-to-low debounce. */
/* u8PBState=2 is waiting for PBs to ALL be released. */
/* u8PBState=3 is waiting for a PB low-to-high debounce. */
u16NewTime = MCUReadTmr1 ();
if ((u8PBState == 0) && ((PB0 ==0) || (PB1 ==0) || (PB2 ==0) || (PB3 ==0))) /* A PB is depressed */
{
u8PBState = 1;
u16PBOldTime = u16NewTime;
}
if (u8PBState == 1)
{
if ((u16NewTime-u16PBOldTime) > DEBOUNCE) /* H-L debounce complete */
{
u8PBState = 2; /* Update LEDS. A bit funky. */
if (PB0 == 0)
{
LED1 ^=1;
}
if (PB1 == 0)
{
LED2 ^=1;
}
if (PB2 == 0)
{
LED3 ^=1;
}
if (PB3 == 0)
{
LED4 ^=1;
}
u16PBOldTime = u16NewTime;
}
}
if (u8PBState == 2)
{
if ((PB0 == 1) && (PB1 == 1) && (PB2 == 1) && (PB3 == 1)) /* All PBs released */
{
u16PBOldTime = u16NewTime;
u8PBState = 3;
}
}
if (u8PBState == 3)
{
if ((u16NewTime-u16PBOldTime) > DEBOUNCE) /* L-H debounce complete */
{
u8PBState = 0;
}
}
if (gu8RTxMode == IDLE_MODE) /* RX is now done */
{
u16RTXOldTime = u16NewTime;
u8XcvrMode = 0; /* Assume packet not intended for us */
/* Check for code bytes match and successful packet reception */
if ((sRxPacket.u8Status == SUCCESS) && (au8RxDataBuffer[0] == 0xE1) && (au8RxDataBuffer[1] == 0xCC) && (au8RxDataBuffer[2] == SECURITY))
{
if (au8RxDataBuffer[3] == u8DeviceLed) /* Packet is for me. */
{
if ((au8RxDataBuffer[5] == u8LastDsn)) /* Re-received? */
{
rxcount++;
}
else
{
rxcount = 1;
u8LastDsn = au8RxDataBuffer[5]; /* Update last dsn */
}
if ((au8RxDataBuffer[7] == TOGGLECMD) && (rxcount == 1)) /* TOGGLE and not repeated */
/* Toggle selected LED */
{
if (au8RxDataBuffer[4] == 1)
{
LED1 ^=1;
}
if (au8RxDataBuffer[4] == 2)
{
LED2 ^=1;
}
if (au8RxDataBuffer[4] == 3)
{
LED3 ^=1;
}
if (au8RxDataBuffer[4] == 4)
{
LED4 ^=1;
}
}
u8XcvrMode = 2; /* ACKBACK required */
if (au8RxDataBuffer[7] == QUERYCMD) /* Just a query */
{
u8XcvrMode = 3; /* QUERYBACK required */
}
}
else /* repeat */
{
u8LastDsn = au8RxDataBuffer[5]; /* Update last dsn */
for (u8Count1=0; u8Count1 {
au8TxDataBuffer[u8Count1] = au8RxDataBuffer[u8Count1];
}
au8TxDataBuffer[sRxPacket.u8DataLength] = u8DeviceLed;
sTxPacket.u8DataLength = sRxPacket.u8DataLength+1;
u16NewTime = MCUReadTmr1 ();
u16RTXOldTime = u16NewTime;
while ((u16NewTime-u16RTXOldTime) < u16LagTime1)
{
u16NewTime = MCUReadTmr1 ();
}
MCPSDataRequest(&sTxPacket);
u16NewTime = MCUReadTmr1 ();
u16RTXOldTime = u16NewTime;
while ((u16NewTime-u16RTXOldTime) < u16LagTime2)
{
u16NewTime = MCUReadTmr1 ();
}
MLMERXEnableRequest(&sRxPacket, 0x); /* back to on */
}
}
else
{
u16Count = 0;
while (u16Count < SHORTFLASHCOUNT) /* Flash all LEDs on/off a few times to indicate conflict */
{
#if defined (AXM_0308C)
BUZZ = 1; /* optional buzz to indicate conflict */
#endif
u16OldTime = MCUReadTmr1 ();
u16NewTime = u16OldTime;
while ((u16NewTime-u16OldTime) < SHORTFLASHON)
{
u16NewTime = MCUReadTmr1 ();
}
#if defined (AXM_0308C)
BUZZ = 0;
#endif
u16OldTime = MCUReadTmr1 ();
u16NewTime = u16OldTime;
while ((u16NewTime-u16OldTime) < SHORTFLASHOFF)
{
u16NewTime = MCUReadTmr1 ();
}
u16Count ++;
}
MLMERXEnableRequest(&sRxPacket, 0x); /* back to on */
}
}
if ((u8XcvrMode == 2) || (u8XcvrMode == 3)) /* reply after a delay for TDD. Sends the u8LightLed on/off anyway */
{
u8XcvrMode = 0; /* When done, back to mode 0 */
u8GetLed = PackLed(au8RxDataBuffer[4]);
for (u8Count1=0; u8Count1 {
au8TxDataBuffer[u8Count1] = au8RxDataBuffer[u8Count1];
}
if (au8RxDataBuffer[7] == TOGGLECMD)
{
au8TxDataBuffer[7] = ACKBACK;
}
else
{
au8TxDataBuffer[7] = QUERYBACK;
}
au8TxDataBuffer[sRxPacket.u8DataLength] = 'D';
au8TxDataBuffer[4] = u8GetLed;
au8TxDataBuffer[6] = rxcount;
sTxPacket.u8DataLength = sRxPacket.u8DataLength+1;
u16NewTime = MCUReadTmr1 ();
u16RTXOldTime = u16NewTime;
/* Dwell for possible repeats. */
while ((u16NewTime-u16RTXOldTime) < DWELLTIME) /* 46mS */
{
u16NewTime = MCUReadTmr1 ();
}
MCPSDataRequest(&sTxPacket);
u16NewTime = MCUReadTmr1 ();
u16RTXOldTime = u16NewTime;
while ((u16NewTime-u16RTXOldTime) < DWELLTIME2) /* 44mS */
{
u16NewTime = MCUReadTmr1 ();
}
u16RTXOldTime = u16NewTime;
MLMERXEnableRequest(&sRxPacket, 0x); /* back to on */
}
}
}
/**************************************************************
* Function: LED driver
* Parameters: state. 1-4 is light only that LED. 5 is turn all off, 6 is all on.
* Return: none
**************************************************************/
void LedDrive (UINT8 state)
{
switch (state)
{
case 0x01:
LED1 = 0;
LED2 = 1;
LED3 = 1;
LED4 = 1;
break;
case 0x02:
LED1 = 1;
LED2 = 0;
LED3 = 1;
LED4 = 1;
break;
case 0x03:
LED1 = 1;
LED2 = 1;
LED3 = 0;
LED4 = 1;
break;
case 0x04:
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 0;
break;
case 0x05:
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 1;
break;
case 0x06:
LED1 = 0;
LED2 = 0;
LED3 = 0;
LED4 = 0;
break;
}
return;
}
/**************************************************************
* Function: LED state return
* Returns LED state. 0xFF is on, 0x00 is off.
**************************************************************/
UINT8 PackLed (UINT8 lednum)
{
switch (lednum)
{
case 0x01:
if (LED1 == 0)
{
return 0xFF;
}
else
{
return 0x00;
}
break;
case 0x02:
if (LED2 == 0)
{
return 0xFF;
}
else
{
return 0x00;
}
break;
case 0x03:
if (LED3 == 0)
{
return 0xFF;
}
else
{
return 0x00;
}
break;
case 0x04:
if (LED4 == 0)
{
return 0xFF;
}
else
{
return 0x00;
}
break;
}
return 0x55;
}
/**************************************************************
* Function: Received data handler
* Parameters: tRxPacket
**************************************************************/
void MCPSDataIndication(tRxPacket *sRxPacket)
/* Just a direct return. Main loop will handle it. */
{
}
/**************************************************************
* Function: MC13192 reset handler (not yet implemented)
* Parameters: none
**************************************************************/
void MLMEMC13192ResetIndication (void)
{
LED1 = 0;
LED2 = 0;
LED3 = 0;
LED4 = 0;
for(;;);
}
/**************************************************************
* Function: Read MCU timer.
* Parameters: none
* Return: 16-bit timer value.
**************************************************************/
UINT16 MCUReadTmr1(void)
{
UINT16 w; /* w[0] is MSB, w[1] is LSB */
((UINT8*)&w)[0] = TPM1CNTH; /* MSB */
((UINT8*)&w)[1] = TPM1CNTL; /* LSB */
return w;
}
/**************************************************************
* Function: Delay.
* Parameters: Delay u16Count
* Return: none.
**************************************************************/
void MCUDelay (UINT16 delay_t)
{
UINT16 u16MCUOldTime;
UINT16 u16MCUNewTime;
u16MCUOldTime = MCUReadTmr1();
u16MCUNewTime = u16MCUOldTime;
while ((u16MCUNewTime-u16MCUOldTime) < delay_t)
{
u16MCUNewTime = MCUReadTmr1();
}
}
Status:
Open May 20, 2010 - 05:02 AM
computer, code, Time, application, Flash, peripheral, zigbee, codewarrior, programming
Add New Comment