Created
March 14, 2014 06:09
-
-
Save tejainece/9542840 to your computer and use it in GitHub Desktop.
TinyOS send point2point 802.15.4 compliant message using non-beacon enabled direct transmission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef __APP_PROFILE_H | |
| #define __APP_PROFILE_H | |
| enum { | |
| RADIO_CHANNEL = 0xC, | |
| PAN_ID = 0x3332, | |
| MY_ADDRESS = 0x6287, | |
| OT_ADDRESS = 0x6288 | |
| }; | |
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| COMPONENT=Send_p2p_D_N154C | |
| CFLAGS += -I$(shell pwd)/.. | |
| # To use the TKN15.4 MAC instead of a platform's default MAC protocol first | |
| # include the TinyOS "Makerules" file as usual ... | |
| include $(MAKERULES) | |
| # ... and then include the TKN15.4 "Makefile.include" file. That's all. | |
| # Hint: type "make <platform> verbose" to see the aggregate include path. | |
| include $(TOSDIR)/lib/mac/tkn154/Makefile.include |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| configuration Send_p2p_D_N154C | |
| { | |
| } implementation { | |
| components MainC, LedsC, Ieee802154NonBeaconEnabledC as MAC; | |
| components Send_p2p_D_N154P as App; | |
| components new Timer62500C() as Timer1; | |
| MainC.Boot <- App; | |
| App.MCPS_DATA -> MAC; | |
| App.Frame -> MAC; | |
| App.Packet -> MAC; | |
| App.DataTimer -> Timer1; | |
| App.Leds -> LedsC; | |
| App.MLME_RESET -> MAC; | |
| App.MLME_SET -> MAC; | |
| App.MLME_GET -> MAC; | |
| App.MLME_START -> MAC; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "TKN154.h" | |
| #include "app_profile.h" | |
| module Send_p2p_D_N154P | |
| { | |
| uses { | |
| interface Boot; | |
| interface MLME_RESET; | |
| interface MLME_START; | |
| interface MLME_SET; | |
| interface MLME_GET; | |
| interface MCPS_DATA; | |
| interface IEEE154Frame as Frame; | |
| interface Leds; | |
| interface Packet; | |
| interface Timer<T62500hz> as DataTimer; | |
| } | |
| } implementation { | |
| message_t frame; | |
| uint8_t *payloadRegion; | |
| uint8_t m_payloadLen; | |
| char payload[] = "__TestIndirect, Coordinator talking now!"; | |
| void sendDirectData(); | |
| event void Boot.booted() { | |
| m_payloadLen = strlen(payload); | |
| payloadRegion = call Packet.getPayload(&frame, m_payloadLen); | |
| if (m_payloadLen <= call Packet.maxPayloadLength()){ | |
| memcpy(payloadRegion, payload, m_payloadLen); | |
| call MLME_RESET.request(TRUE); | |
| } | |
| } | |
| event void MLME_RESET.confirm(ieee154_status_t status) | |
| { | |
| if (status != IEEE154_SUCCESS) | |
| return; | |
| call MLME_SET.macShortAddress(MY_ADDRESS); | |
| call MLME_SET.macAssociationPermit(FALSE); | |
| call MLME_SET.macRxOnWhenIdle(TRUE); | |
| call MLME_START.request( | |
| PAN_ID, // PANId | |
| RADIO_CHANNEL, // LogicalChannel | |
| 0, // ChannelPage, | |
| 0, // StartTime, | |
| 15, // BeaconOrder | |
| 15, // SuperframeOrder | |
| TRUE, // PANCoordinator | |
| FALSE, // BatteryLifeExtension | |
| FALSE, // CoordRealignment | |
| NULL, // no realignment security | |
| NULL // no beacon security | |
| ); | |
| } | |
| void sendDirectData(){ | |
| ieee154_address_t deviceAddress; | |
| deviceAddress.shortAddress = OT_ADDRESS; | |
| call Frame.setAddressingFields( | |
| &frame, | |
| ADDR_MODE_SHORT_ADDRESS, // SrcAddrMode, | |
| ADDR_MODE_SHORT_ADDRESS, // DstAddrMode, | |
| PAN_ID, // DstPANId, | |
| &deviceAddress, // DstAddr, | |
| NULL // security | |
| ); | |
| call MCPS_DATA.request( | |
| &frame, // frame, | |
| strlen(payload), // payloadLength, | |
| 0, // msduHandle, | |
| TX_OPTIONS_ACK // TxOptions, | |
| ); | |
| call Leds.led1Toggle(); | |
| } | |
| event void MLME_START.confirm(ieee154_status_t status) { | |
| call DataTimer.startPeriodic(50000U); | |
| } | |
| event void DataTimer.fired(){ | |
| call Leds.led0Toggle(); | |
| sendDirectData(); | |
| } | |
| event void MCPS_DATA.confirm( | |
| message_t *msg, | |
| uint8_t msduHandle, | |
| ieee154_status_t status, | |
| uint32_t Timestamp | |
| ) | |
| { | |
| if(status == IEEE154_TRANSACTION_EXPIRED){ | |
| call Leds.led0Toggle(); | |
| }else if (status == IEEE154_SUCCESS){ | |
| } | |
| } | |
| event message_t* MCPS_DATA.indication ( message_t* frame__ ){ | |
| return frame__; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment