Project

General

Profile

Revision 60

Updated wireless library to add different channels.

View differences:

xbee.c
80 80
//XBee status
81 81
unsigned int xbee_panID = XBEE_PAN_DEFAULT;
82 82
unsigned int xbee_pending_panID = XBEE_PAN_DEFAULT;
83
int xbee_channel = XBEE_CHANNEL_DEFAULT;
84
int xbee_pending_channel = XBEE_CHANNEL_DEFAULT;
83 85
unsigned int xbee_address = 0;
84 86

  
85 87
/*Function Implementations*/
......
120 122
 * @param pan_id the PAN to join initially. Use XBEE_PAN_DEFAULT
121 123
 * to leave the PAN as it is initially.
122 124
 **/
123
void xbee_lib_init(int pan_id)
125
void xbee_lib_init(void)
124 126
{
125 127
	xbee_queue = queue_create();
126 128
	
......
158 160
	
159 161
	//wait to return until the address is set
160 162
	while (xbee_address == 0) xbee_get_packet(NULL);
161
	
162
	if (pan_id != XBEE_PAN_DEFAULT)
163
	{
164
		xbee_set_pan_id(pan_id);
165
		while (xbee_panID == XBEE_PAN_DEFAULT) xbee_get_packet(NULL);
166
	}
167 163
}
168 164

  
169 165
/**
......
594 590
		WL_DEBUG_PRINT(".\r\n");
595 591
		return;
596 592
	}
593

  
594
	if (command[0] == 'C' && command[1] == 'H')
595
	{
596
		xbee_channel = xbee_pending_channel;
597
		WL_DEBUG_PRINT("Channel set to ");
598
		WL_DEBUG_PRINT_INT(xbee_channel);
599
		WL_DEBUG_PRINT(".\r\n");
600
		return;
601
	}
597 602
	
598 603
	if (command[0] == 'M' && command[1] == 'Y' && extraLen != 0)
599 604
	{
......
678 683
}
679 684

  
680 685
/**
686
 * Set the channel the XBee is using.
687
 *
688
 * @param channel the channel the XBee will not use, 
689
 * between 0x0B and 0x1A
690
 *
691
 * @see xbee_get_channel
692
 **/
693
void xbee_set_channel(int channel)
694
{
695
	if (channel < 0x0B || channel > 0x1A)
696
	{
697
		WL_DEBUG_PRINT("Channel out of range.\r\n");
698
		return;
699
	}
700
	char s[3];
701
	s[0] = channel & 0xFF;
702
	s[1] = 0;
703
	xbee_pending_channel = channel;
704
	xbee_send_modify_at_command("CH", s);
705
}
706

  
707
/**
708
 * Returns the channel which the XBee is currently using.
709
 *
710
 * @return the channel the XBee is using
711
 *
712
 * @see xbee_set_channel
713
 **/
714
int xbee_get_channel(void)
715
{
716
	return xbee_channel;
717
}
718

  
719
/**
681 720
 * Get the 16-bit address of the XBee.
682 721
 * This is used to specify who to send messages to
683 722
 * and who messages are from.

Also available in: Unified diff