⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ping_pong.c

📁 基于ZIGBEE无线网络的水表抄表程序 代码完整
💻 C
📖 第 1 页 / 共 2 页
字号:
//callback for anytime the Zero Endpoint RX handles a command
//user can use the APS functions to access the arguments
//and take additional action is desired.
//the callback occurs after the ZEP has already taken
//its action.
//================================================================================================
void usrZepRxCallback(void){

#ifdef LRWPAN_COORDINATOR
	if (aplGetRxCluster() == ZEP_END_DEVICE_ANNOUNCE) {
		//a new end device has announced itself, print out the
		//the neightbor table and address map
		dbgPrintNeighborTable();
	}
#endif

}
//================================================================================================
//函数名称:
//入口参数:无
//出口参数:无
//备注说明:
//callback from APS when packet is received
//user must do something with data as it is freed
//within the stack upon return.
//================================================================================================
void usrRxPacketCallback(void) {

	BYTE len, *ptr;

	conPrintROMString("User Data Packet Received: \n");
	conPrintROMString("SrcSADDR: ");
	conPrintUINT16(aplGetRxSrcSADDR());
	conPrintROMString(", DstEp: ");
	conPrintUINT8(aplGetRxDstEp());
	conPrintROMString(", Cluster: ");
	conPrintUINT8(aplGetRxCluster());
	conPrintROMString(", MsgLen: ");
	len = aplGetRxMsgLen();
	conPrintUINT8(len);
	conPrintROMString(",RSSI: ");
	conPrintUINT8(aplGetRxRSSI());
	conPCRLF();
	conPrintROMString("PingCnt: ");
	ptr = aplGetRxMsgData();

	conPrintUINT8(*ptr);     //1
        router_data[7] = *ptr;
	ptr++;
        conPrintUINT8(*ptr);     //2
        router_data[6] = *ptr;
	ptr++;
        conPrintUINT8(*ptr);     //3
        router_data[5] = *ptr;
	ptr++;
        conPrintUINT8(*ptr);     //4
        router_data[4] = *ptr;
	ptr++;
        conPrintUINT8(*ptr);     //5
        router_data[3] = *ptr;
	ptr++;
        conPrintUINT8(*ptr);     //6
        router_data[2] = *ptr;
	ptr++;
        conPrintUINT8(*ptr);     //7
        router_data[1] = *ptr;
	ptr++;
        conPrintUINT8(*ptr);     //8
        router_data[0] = *ptr;
                                                //use this source address as the next destination address
	//dstADDR.saddr = aplGetRxSrcSADDR();     //aplGetParentLongAddress();//
#ifdef LRWPAN_ROUTER
        REC_FLAG = 0;            //收到数据后非忙状态!
#endif
	conPCRLF();
        if   (EVB_LED1_STATE()) EVB_LED1_OFF();
        else                    EVB_LED1_ON( );
}

#ifdef LRWPAN_FFD
//Callback to user level to see if OK for this node
//to join - implement Access Control Lists here based
//upon IEEE address if desired
BOOL usrJoinVerifyCallback(LADDR *ptr, BYTE capinfo){\

#if 0      //set this to '1' if you want to test through a router
//only accept routers.
//only let routers join us if we are coord
#ifdef LRWPAN_COORDINATOR
if (LRWPAN_GET_CAPINFO_DEVTYPE(capinfo)) {
	//this is a router, let it join
	conPrintROMString("Accepting router\n");
	return TRUE;
}else {
	conPrintROMString("Rejecting non-router\n");
	return FALSE;
}
#else
return TRUE;
#endif

#else

return TRUE;

#endif

}

BOOL usrJoinNotifyCallback(LADDR *ptr){

	//allow anybody to join

	conPrintROMString("Node joined: ");
	conPrintLADDR(ptr);
	conPCRLF();
	DEBUG_PRINTNEIGHBORS(DBG_INFO);
	return TRUE;
}
#endif

//called when the slow timer interrupt occurs
#ifdef LRWPAN_ENABLE_SLOW_TIMER
void usrSlowTimerInt(void ) {}
#endif


//general interrupt callback , when this is called depends on the HAL layer.
void usrIntCallback(void){}


#pragma vector = P0INT_VECTOR
__interrupt void p0_isr( void )
{
  if( P0IFG&0X02 ){
      P0IFG &=0XFD;
      conPrintROMString("KEY_P01!")
  }
  P0IF = 0X00;
}
//================================================================================================
//函数名称:
//入口参数:无
//出口参数:无
//备注说明:
//================================================================================================
void   PingPong (void ) {

	//apsFSM();

	switch (ppState) {

			case PP_STATE_WAIT_FOR_RX:
				if   (EVB_LED1_STATE()) EVB_LED1_OFF();
                                else                    EVB_LED1_ON( );
				my_timer= halGetMACTimer();
				ppState = PP_STATE_SEND;
				break;

			case PP_STATE_SEND:
				if ((halMACTimerNowDelta(my_timer))> MSECS_TO_MACTICKS(PING_DELAY*1000)){
					MemDump();
					ppState = PP_STATE_WAIT_FOR_TX;

					aplSendMSG (
                                                APS_DSTMODE_SHORT,//APS_DSTMODE_LONG,//
						&dstADDR,         //目标地址
						2,                //dst EP
						1,                //cluster is ignored for direct message
						3,                //src EP
                                                #ifdef  LRWPAN_RFD
						&rfd_data[0],     //待发送数据首地址
                                                #endif

                                                #ifdef LRWPAN_ROUTER
                                                &router_data[0],  //待发送数据首地址
                                                #endif
						8,                //msg length
						apsGenTSN(),
						FALSE
                                        );                        //No APS ack requested
					ppState = PP_STATE_WAIT_FOR_TX;
                                        #ifdef LRWPAN_ROUTER
                                               REC_FLAG = 1;     //接收数据忙状态!
                                        #endif
				}
				break;

			case PP_STATE_WAIT_FOR_TX:
				if (apsBusy()) break;             //status not ready yet if busy.
				if (aplGetStatus() == LRWPAN_STATUS_SUCCESS) {
					ppState = PP_STATE_WAIT_FOR_RX;
					//compute the latency of this TX send operation
					//aplGetLastTxTime gets the time that the LAST tx operation finished.
					//this will be the latency of the TX stack operation only if no mac retries were required
					conPrintROMString("SEND OK!");
					conPCRLF();
				}else {
					conPrintROMString("Send failed!\n");
					my_timer= halGetMACTimer();
					ppState = PP_STATE_SEND;
				}
				break;
	}
}
//===================================================================================================================


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -