/* wait for a button press... */ do { FHSS_ACTIVE( nwk_pllBackgrounder( false ) ); /* manage FHSS */ //等待按键按下,当按键按下后发出Link信号,并等待连接 if (BSP_BUTTON1() || BSP_BUTTON2()) { break; } } while (1);
linkTo(); while (1) ; }
static void linkTo() { uint8_t msg[2], delay = 0;
while (SMPL_SUCCESS != SMPL_Link(&sLinkID1)) //等待连接的过程中,LED1和LED2闪烁 {
/* blink LEDs until we link successfully */ toggleLED(1); toggleLED(2); SPIN_ABOUT_A_SECOND; /* manages FHSS implicitly */ }
/* we're linked. turn off red LED. received messages will toggle the green LED. */ if (BSP_LED2_IS_ON()) //当连接成功,Talker的LED2熄灭,而LED1继续亮 { toggleLED(2); }
#ifndef FREQUENCY_HOPPING
/* turn on RX. default is RX off. */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); #endif
/* put LED to toggle in the message */ msg[0] = 2; /* toggle red */ while (1) { SPIN_ABOUT_A_SECOND; /* manages FHSS implicitly */ if (delay > 0x00) { SPIN_ABOUT_A_SECOND; /* manages FHSS implicitly */ } if (delay > 0x01) { SPIN_ABOUT_A_SECOND; /* manages FHSS implicitly */ } if (delay > 0x02) { SPIN_ABOUT_A_SECOND; /* manages FHSS implicitly */ }
/* delay longer and longer -- then start over */ delay = (delay+1) & 0x03;
/* put the sequence ID in the message */ msg[1] = ++sTxTid; SMPL_Send(sLinkID1, msg, sizeof(msg)); } }
/* is the callback for the link ID we want to handle? */ if (port == sLinkID1) {
/* yes. go get the frame. we know this call will succeed. */ if ((SMPL_SUCCESS == SMPL_Receive(sLinkID1, msg, &len)) && len) {
/* Check the application sequence number to detect
* late or missing frames...
*/ tid = *(msg+1); if (tid) { if (tid > sRxTid) {
/* turn on LEDs. */ if (!BSP_LED2_IS_ON()) //刚上电时,Listener的LED1和LED2同时亮 { toggleLED(2); } if (!BSP_LED1_IS_ON()) { toggleLED(1); }
/* wait for a button press... */ do { FHSS_ACTIVE( nwk_pllBackgrounder( false ) ); /* manage FHSS */ if (BSP_BUTTON1() || BSP_BUTTON2()) // 等待按键被按下,当按键按下... { break; } } while (1);
linkFrom(); while (1) ; }
static void linkFrom() { uint8_t msg[2], tid = 0;
/* Turn off one LED so we can tell the device is now listening.
* Received messages will toggle the other LED.
*/ toggleLED(1); //当按键按下,Listener的LED1熄灭,LED2继续亮,并进入侦听Link信息状态
/* listen for link forever... */ while (1) {
/* SMPL_LinkListen handles FHSS implicittly */ if (SMPL_SUCCESS == SMPL_LinkListen(&sLinkID2)) { break; //侦听Link信息成功,退出循环 } }
/* turn on LED1 on the peer in response to receiving a frame. */ *msg = 0x01;
/* turn on RX. default is RX off. */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); while (1) { FHSS_ACTIVE( nwk_pllBackgrounder( false ) ); /* manage FHSS */
if (sSemaphore) { *(msg+1) = ++tid; SMPL_Send(sLinkID2, msg, 2);
/* is the callback for the link ID we want to handle? */ if (port == sLinkID2) {
/* yes. go get the frame. we know this call will succeed. */ if ((SMPL_SUCCESS == SMPL_Receive(sLinkID2, msg, &len)) && len)//我觉得 if (SMPL_SUCCESS == SMPL_Receive(sLinkID2, msg, &len)) { //就可以了,接收成功就好了,不理解后面为什么要和len相与???求指导!
/* Check the application sequence number to detect
* late or missing frames...
*/ tid = *(msg+1); if (tid) //当连接成功之后,Talker向Listen发送确认信息,那时msg[1]就已经是1了,所以tid没有可能是0的,所以觉得else之后的是多余??? //求指导!!! { if (tid > sRxTid) //当第一次数据交换之后,tid=++sTxTid(已经是1了),而此时sRxTid=0,即使多次数据交换之后,tid也总是大于sRxTid的,即 { //tid > sRxTid总为真,这里是不是也是多余啊????严重求指导!!! toggleLED(*msg); sRxTid = tid; } } else {
if (sRxTid) { toggleLED(*msg); sRxTid = tid; } }
/* Post to the semaphore to let application know so it sends
* the reply
*/ sSemaphore = 1; return 1; } } return 0;