From: janhauer Date: Mon, 18 May 2009 17:13:02 +0000 (+0000) Subject: added test app X-Git-Tag: rc_6_tinyos_2_1_1~383 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=2f9c3c45850d79b81a2a5e6fa8ed6cdbcfe98f34 added test app --- diff --git a/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/README.txt b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/README.txt new file mode 100644 index 00000000..5a715ced --- /dev/null +++ b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/README.txt @@ -0,0 +1,46 @@ +README for TestAssociate +Author/Contact: tinyos-help@millennium.berkeley.edu + +Description: + +In this application one node takes the role of a PAN coordinator in a +nonbeacon-enabled 802.15.4 PAN; it switches its radio to receive mode and waits +for devices to request association to its PAN. Whenever a device tries to +associate, the PAN coordinator allows association and assigns to the device a +unique short address (starting from zero, incremented for every device +requesting association). + +A second node acts as a device; it switches to the pre-defined channel and +tries to associate to the PAN. A short time after association the device then +disassociates from the PAN. + +On the coordinator the second LED (Telos: green) is switched on whenever an +association request was successful and it is switched off, whenever a +disassociation request was received. On a device the second LED is switched on +while the device is associated to the PAN, and it is switched off after +disassociation. The first LED (Telos: red) is used for debugging, it denotes an +error in the protocol stack and should never be on. + +Tools: NONE + +Usage: + +1. Install the coordinator: + + $ cd coordinator; make install + +2. Install one (or more) devices: + + $ cd device; make install + +You can change some of the configuration parameters in app_profile.h + +Known bugs/limitations: + +- Many TinyOS 2 platforms do not have a clock that satisfies the + precision/accuracy requirements of the IEEE 802.15.4 standard (e.g. + 62.500 Hz, +-40 ppm in the 2.4 GHz band); in this case the MAC timing + is not standard compliant + +$Id$o + diff --git a/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/app_profile.h b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/app_profile.h new file mode 100644 index 00000000..bf986b55 --- /dev/null +++ b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/app_profile.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2008, Technische Universitaet Berlin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universitaet Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * - Revision ------------------------------------------------------------- + * $Revision$ + * $Date$ + * @author: Jan Hauer + * ======================================================================== + */ + +#ifndef __APP_PROFILE_H +#define __APP_PROFILE_H + +enum { + RADIO_CHANNEL = 26, + PAN_ID = 0x9678, + COORDINATOR_ADDRESS = 0x7722, +}; + +#endif diff --git a/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/Makefile b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/Makefile new file mode 100644 index 00000000..c4d5d67c --- /dev/null +++ b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/Makefile @@ -0,0 +1,3 @@ +COMPONENT=TestAssociateAppC +CFLAGS += -I$(shell pwd)/.. +include ../../../Makefile.include diff --git a/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/TestAssociateAppC.nc b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/TestAssociateAppC.nc new file mode 100644 index 00000000..19052340 --- /dev/null +++ b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/TestAssociateAppC.nc @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008, Technische Universitaet Berlin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universitaet Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * - Revision ------------------------------------------------------------- + * $Revision$ + * $Date$ + * @author: Jan Hauer + * ======================================================================== + */ + +configuration TestAssociateAppC +{ +} implementation { + components MainC, LedsC, Ieee802154NonBeaconEnabledC as MAC; + components TestCoordC as App; + + MainC.Boot <- App; + App.Leds -> LedsC; + App.MLME_RESET -> MAC; + App.MLME_SET -> MAC; + App.MLME_GET -> MAC; + + App.MLME_START -> MAC; + App.MLME_ASSOCIATE -> MAC; + App.MLME_DISASSOCIATE -> MAC; + App.MLME_COMM_STATUS -> MAC; +} diff --git a/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/TestCoordC.nc b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/TestCoordC.nc new file mode 100644 index 00000000..31930dc6 --- /dev/null +++ b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/coordinator/TestCoordC.nc @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2008, Technische Universitaet Berlin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universitaet Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * - Revision ------------------------------------------------------------- + * $Revision$ + * $Date$ + * @author: Jan Hauer + * ======================================================================== + */ + +#include "TKN154.h" +#include "app_profile.h" +module TestCoordC +{ + uses { + interface Boot; + interface MLME_RESET; + interface MLME_START; + interface MLME_ASSOCIATE; + interface MLME_DISASSOCIATE; + interface MLME_COMM_STATUS; + interface MLME_SET; + interface MLME_GET; + interface Leds; + } +} implementation { + + ieee154_address_t m_lastDevice; + uint16_t m_shortAddress; + + event void Boot.booted() { + call MLME_RESET.request(TRUE); + } + + event void MLME_RESET.confirm(ieee154_status_t status) + { + if (status != IEEE154_SUCCESS) + return; + call MLME_SET.macShortAddress(COORDINATOR_ADDRESS); + call MLME_SET.macAssociationPermit(TRUE); + 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 + ); + } + + event void MLME_START.confirm(ieee154_status_t status) { + // good, let's wait for association requests ... + } + + event void MLME_ASSOCIATE.indication ( + uint64_t DeviceAddress, + ieee154_CapabilityInformation_t CapabilityInformation, + ieee154_security_t *security + ) + { + call MLME_ASSOCIATE.response(DeviceAddress, m_shortAddress++, IEEE154_ASSOCIATION_SUCCESSFUL, 0); + } + + event void MLME_DISASSOCIATE.indication ( + uint64_t DeviceAddress, + ieee154_disassociation_reason_t DisassociateReason, + ieee154_security_t *security + ) + { + call Leds.led1Off(); + } + + + event void MLME_COMM_STATUS.indication ( + uint16_t PANId, + uint8_t SrcAddrMode, + ieee154_address_t SrcAddr, + uint8_t DstAddrMode, + ieee154_address_t DstAddr, + ieee154_status_t status, + ieee154_security_t *security + ) + { + if (status == IEEE154_SUCCESS){ + // association was successful + call Leds.led1On(); + m_lastDevice.extendedAddress = DstAddr.extendedAddress; + } else { + call Leds.led1Off(); + } + } + + event void MLME_DISASSOCIATE.confirm ( + ieee154_status_t status, + uint8_t DeviceAddrMode, + uint16_t DevicePANID, + ieee154_address_t DeviceAddress + ){} + + event void MLME_ASSOCIATE.confirm ( + uint16_t AssocShortAddress, + uint8_t status, + ieee154_security_t *security + ){} +} diff --git a/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/Makefile b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/Makefile new file mode 100644 index 00000000..c4d5d67c --- /dev/null +++ b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/Makefile @@ -0,0 +1,3 @@ +COMPONENT=TestAssociateAppC +CFLAGS += -I$(shell pwd)/.. +include ../../../Makefile.include diff --git a/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/TestAssociateAppC.nc b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/TestAssociateAppC.nc new file mode 100644 index 00000000..0ead6a30 --- /dev/null +++ b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/TestAssociateAppC.nc @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2008, Technische Universitaet Berlin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universitaet Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * - Revision ------------------------------------------------------------- + * $Revision$ + * $Date$ + * @author: Jan Hauer + * ======================================================================== + */ + +configuration TestAssociateAppC +{ +} implementation { + components MainC, LedsC, Ieee802154NonBeaconEnabledC as MAC, + new Timer62500C() as Timer; + components TestDeviceC as App; + + MainC.Boot <- App; + App.Leds -> LedsC; + App.MLME_RESET -> MAC; + App.MLME_SET -> MAC; + App.MLME_GET -> MAC; + App.DisassociateTimer -> Timer; + App.MLME_ASSOCIATE -> MAC; + App.MLME_DISASSOCIATE -> MAC; + App.MLME_COMM_STATUS -> MAC; + +} diff --git a/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/TestDeviceC.nc b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/TestDeviceC.nc new file mode 100644 index 00000000..87ec256a --- /dev/null +++ b/apps/tests/tkn154/nonbeacon-enabled/TestAssociate/device/TestDeviceC.nc @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2008, Technische Universitaet Berlin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universitaet Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * - Revision ------------------------------------------------------------- + * $Revision$ + * $Date$ + * @author: Jan Hauer + * ======================================================================== + */ +#include "TKN154.h" +#include "app_profile.h" +module TestDeviceC +{ + uses { + interface Boot; + interface MLME_RESET; + interface MLME_SET; + interface MLME_GET; + interface MLME_ASSOCIATE; + interface MLME_DISASSOCIATE; + interface MLME_COMM_STATUS; + interface Leds; + interface Timer as DisassociateTimer; + } +} implementation { + + ieee154_CapabilityInformation_t m_capabilityInformation; + void startApp(); + + event void Boot.booted() { + m_capabilityInformation.AlternatePANCoordinator = 0; + m_capabilityInformation.DeviceType = 0; + m_capabilityInformation.PowerSource = 0; + m_capabilityInformation.ReceiverOnWhenIdle = 0; + m_capabilityInformation.Reserved = 0; + m_capabilityInformation.SecurityCapability = 0; + m_capabilityInformation.AllocateAddress = 1; + call MLME_RESET.request(TRUE); + } + + event void MLME_RESET.confirm(ieee154_status_t status) + { + if (status == IEEE154_SUCCESS) + startApp(); + } + + void startApp() + { + ieee154_address_t coordAdr; + + coordAdr.shortAddress = COORDINATOR_ADDRESS; + call MLME_SET.macAutoRequest(FALSE); + call MLME_SET.macPANId(PAN_ID); + call MLME_SET.macCoordShortAddress(COORDINATOR_ADDRESS); + call MLME_ASSOCIATE.request( + RADIO_CHANNEL, + call MLME_GET.phyCurrentPage(), + ADDR_MODE_SHORT_ADDRESS, + PAN_ID, + coordAdr, + m_capabilityInformation, + NULL // security + ); + } + + event void MLME_ASSOCIATE.confirm ( + uint16_t AssocShortAddress, + uint8_t status, + ieee154_security_t *security + ) + { + if ( status == IEEE154_SUCCESS ){ + // we are now associated - set a timer for disassociation + call Leds.led1On(); + call DisassociateTimer.startOneShot(312500U); + } else { + startApp(); // retry + } + } + + event void DisassociateTimer.fired() + { + ieee154_address_t coordAdr; + coordAdr.shortAddress = COORDINATOR_ADDRESS; + if (call MLME_DISASSOCIATE.request ( + ADDR_MODE_SHORT_ADDRESS, + PAN_ID, + coordAdr, + IEEE154_DEVICE_WISHES_TO_LEAVE, + FALSE, + NULL + ) != IEEE154_SUCCESS) + call DisassociateTimer.startOneShot(312500U); + } + + event void MLME_DISASSOCIATE.confirm ( + ieee154_status_t status, + uint8_t DeviceAddrMode, + uint16_t DevicePANID, + ieee154_address_t DeviceAddress + ) + { + if (status == IEEE154_SUCCESS){ + call Leds.led1Off(); + } else { + call DisassociateTimer.startOneShot(312500U); + } + } + + event void MLME_ASSOCIATE.indication ( + uint64_t DeviceAddress, + ieee154_CapabilityInformation_t CapabilityInformation, + ieee154_security_t *security + ){} + + event void MLME_DISASSOCIATE.indication ( + uint64_t DeviceAddress, + ieee154_disassociation_reason_t DisassociateReason, + ieee154_security_t *security + ){} + + + event void MLME_COMM_STATUS.indication ( + uint16_t PANId, + uint8_t SrcAddrMode, + ieee154_address_t SrcAddr, + uint8_t DstAddrMode, + ieee154_address_t DstAddr, + ieee154_status_t status, + ieee154_security_t *security + ) {} +}