Download presentation
Presentation is loading. Please wait.
1
Wireless Networks Lab – Wireless 2007/11/07 Chia-Hung Tsai
2
yctseng: 2 Lab5 FontalBSP LED UART Stack Wireless Application Queue API Hardware interrupt Mcps interrupt
3
yctseng: 3 PIB PAN Information Base Consist of a number of parameters used by MAC and Physical layers Access The mechanism that a network layer can used is reading (GET) and writing (Set)
4
yctseng: 4 MAC layer PIB access Get a handle to the PIB #include “mac_pib.h” PRIVATE void *s_pvMac; PRIVATE MAC_Pib_s *s_psMacPib; // Within application initialization function s_pvMac=pvAppApiGetMacHandle(); s_psMacPib=MAC_psPibGetHandle(s_pvMac); // An example of writing the BO in the PIB s_psMacPib->u8BeaconOrder = 5;
5
yctseng: 5 MAC layer PIB access Some attributes needs to be done using auxiliary functions
6
yctseng: 6 Transmit a Packet for MAC PIB Set a PAN ID Set the short address MAC_vPibSetPanId(s_pvMac, YOUR_PAN_ID); MAC_vPibSetShortAddr(s_pvMac, YOUR_SHORT_ADDR);
7
yctseng: 7 Physical layer PIB access PHY PIB parameter values can be returned to the network layer using the eAppApiPlmeGet routine can be changed by the network layer using the PLME-Set request primitive eAppApiPlmeSet routine
8
yctseng: 8 Physical layer PIB access example eAppApiPlmeGet eAppApiPlmeSet
9
yctseng: 9 Transmit a Packet for PHY PIB Set the transmitting channel eAppApiPlmeSet(PHY_PIB_ATTR_CURRENT_C HANNEL, YOUR_CHANNEL);
10
yctseng: 10 macRxOnWhenIdle Indication of whether the MAC sublayer is to enable its receiver during idle periods BeaconOlder default is set to 15 If BO is equal to 15, the value of macRxOnWhenIdle shall be considered relevant at all times MAC_vPibSetRxOnWhenIdle(s_pvMac, TRUE, FALSE);
11
yctseng: 11 Lab5 sample tx.c A counter application After triggering LEDs according to the counting value, it will send the value in a packet to rx node. rx.c When it receive a packet from tx node, it will parse the value in the packet and trigger its LEDs by the value. So, rx.c is still a counter application
12
yctseng: 12 Lab sample PUBLIC void AppColdStart(void) { InitSystem(); while (TRUE) { vAHI_CpuDoze(); }
13
yctseng: 13 Lab5 sample PRIVATE void InitSystem(void) { u32AHI_Init(); u32AppQApiInit(NULL, ReceiveISR, NULL); s_pvMac = pvAppApiGetMacHandle(); s_psMacPib = MAC_psPibGetHandle(s_pvMac); MAC_vPibSetPanId(s_pvMac, PAN_ID); MAC_vPibSetShortAddr(s_pvMac, RX); eAppApiPlmeSet(PHY_PIB_ATTR_CURRENT_CHANNEL, CHANNEL); MAC_vPibSetRxOnWhenIdle(s_pvMac, TRUE, FALSE); led_init(); led_on(LED0); led_on(LED1); }
14
yctseng: 14 Send packet PRIVATE void sendPacket(void) { MAC_McpsSyncCfm_s sMcpsSyncCfm; MAC_McpsReqRsp_s sMcpsReqRsp; uint8 *pu8Payload; sMcpsReqRsp.u8Type = MAC_MCPS_REQ_DATA; sMcpsReqRsp.u8ParamLength = sizeof(MAC_McpsReqData_s); sMcpsReqRsp.uParam.sReqData.u8Handle=0; sMcpsReqRsp.uParam.sReqData.sFrame.sSrcAddr.u8AddrMode=2; sMcpsReqRsp.uParam.sReqData.sFrame.sSrcAddr.u16PanId=PAN_ID; sMcpsReqRsp.uParam.sReqData.sFrame.sSrcAddr.uAddr.u16Short =TX; sMcpsReqRsp.uParam.sReqData.sFrame.sDstAddr.u8AddrMode=2; sMcpsReqRsp.uParam.sReqData.sFrame.sDstAddr.u16PanId=PAN_ID; sMcpsReqRsp.uParam.sReqData.sFrame.sDstAddr.uAddr.u16Short = RX; sMcpsReqRsp.uParam.sReqData.sFrame.u8TxOptions = 1; sMcpsReqRsp.uParam.sReqData.sFrame.u8SduLength = 1; pu8Payload = sMcpsReqRsp.uParam.sReqData.sFrame.au8Sdu; pu8Payload[0] = u8Value; vAppApiMcpsRequest(&sMcpsReqRsp, &sMcpsSyncCfm); }
15
yctseng: 15 Receive packet Step1: Poll the MCPS queue to get an interrupt PRIVATE void ReceiveISR(void) { MAC_McpsDcfmInd_s *psMcpsInd; // poll the MCPS queue do { psMcpsInd = psAppQApiReadMcpsInd(); if (psMcpsInd != NULL) { vProcessIncomingData(psMcpsInd); vAppQApiReturnMcpsIndBuffer(psMcpsInd); } } while (psMcpsInd != NULL); }
16
yctseng: 16 Receive packet Step2: Parse the interrupt to get data PRIVATE void vProcessIncomingData(MAC_McpsDcfmInd_s *psMcpsInd){ MAC_RxFrameData_s *psFrame; uint8 au8DeviceData[8]; if (psMcpsInd->u8Type == MAC_MCPS_IND_DATA) { psFrame = &psMcpsInd->uParam.sIndData.sFrame; …… // Store the received data for(i = 0; i < 8; i++) { au8DeviceData[i] = psFrame->au8Sdu[i]; }
17
yctseng: 17 MAC_Mcps In mac_sap.h typedef struct { uint8 u8Type; /* Indication type */ uint8 u8ParamLength; /* Parameter length in following union */ uint16 u16Pad; /* Padding to force alignment */ MAC_McpsDcfmIndParam_u uParam; /* Union of all possible Indications */ } MAC_McpsDcfmInd_s; typedef union { MAC_McpsCfmData_s sDcfmData; /* transmit data confirm */ MAC_McpsCfmPurge_s sDcfmPurge; /* purge confirm */ MAC_McpsIndData_s sIndData; /* data indication */ } MAC_McpsDcfmIndParam_u;
18
yctseng: 18 MAC_Mcps In mac_sap.h typedef struct { MAC_Addr_s sSrcAddr; /* Source address */ MAC_Addr_s sDstAddr; /* Destination address */ uint8 u8LinkQuality; /* Link quality of received frame */ uint8 u8SecurityUse; /* True if security was used */ uint8 u8AclEntry; /* Security suite used */ uint8 u8SduLength; /* Length of payload */ uint8 au8Sdu[MAC_MAX_DATA_PAYLOAD_LEN]; /* Payload */ } MAC_RxFrameData_s; typedef struct { MAC_RxFrameData_s sFrame; /* Frame received */ } MAC_McpsIndData_s;
19
yctseng: 19 Lab5 Implement a small game that is similar with the bonus part in Lab4 Using wireless to replace the UART Requirement Server node will be setting a number by hyper terminal through UART Client node will guess a number through UART and send this number to server node If client node is guessed a smaller number, server node will relay “the answer is bigger” to client node through wireless Else, if client node is guessed a bigger number, server node will reply “the answer is smaller” Else, reply “you are right”
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.