rewriting mote interfaces for faster simulation execution.

radio interface
This commit is contained in:
fros4943 2008-10-28 11:49:00 +00:00
parent ddcd54d24a
commit bee9a6d9ac

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ContikiRadio.java,v 1.20 2008/03/18 16:20:16 fros4943 Exp $ * $Id: ContikiRadio.java,v 1.21 2008/10/28 11:49:00 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote.interfaces; package se.sics.cooja.contikimote.interfaces;
@ -41,22 +41,22 @@ import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.contikimote.ContikiMoteInterface; import se.sics.cooja.contikimote.ContikiMoteInterface;
import se.sics.cooja.interfaces.PolledAfterActiveTicks;
import se.sics.cooja.interfaces.Position; import se.sics.cooja.interfaces.Position;
import se.sics.cooja.interfaces.Radio; import se.sics.cooja.interfaces.Radio;
import se.sics.cooja.radiomediums.UDGM;
/** /**
* This class represents a radio transceiver. In order to simulate different * Packet radio transceiver mote interface.
* transmission rates, the underlying Contiki system can be locked in either
* transmission or reception states (using multi-threading). When a transmission
* is initiated, it will automatically lock the Contiki system. When a packet is
* received by this radio the Contiki system, the entitiy transferring the
* packet may explicitly lock the radio in receiving mode. After some time it
* should then deliver the packet.
* *
* It needs read/write access to the following core variables: * To simulate transmission rates, the underlying Contiki system is
* locked in TX or RX states using multi-threading library.
*
* Contiki variables:
* <ul> * <ul>
* <li>char simTransmitting (1=mote radio is transmitting) * <li>char simTransmitting (1=mote radio is transmitting)
* <li>char simReceiving (1=mote radio is receiving) * <li>char simReceiving (1=mote radio is receiving)
* <li>char simInPolled
* <p> * <p>
* <li>int simInSize (size of received data packet) * <li>int simInSize (size of received data packet)
* <li>byte[] simInDataBuffer (data of received data packet) * <li>byte[] simInDataBuffer (data of received data packet)
@ -66,19 +66,26 @@ import se.sics.cooja.interfaces.Radio;
* <p> * <p>
* <li>char simRadioHWOn (radio hardware status (on/off)) * <li>char simRadioHWOn (radio hardware status (on/off))
* <li>int simSignalStrength (heard radio signal strength) * <li>int simSignalStrength (heard radio signal strength)
* <li>int simLastSignalStrength
* <li>char simPower (number indicating power output) * <li>char simPower (number indicating power output)
* <li>int simRadioChannel (number indicating current channel) * <li>int simRadioChannel (number indicating current channel)
* </ul> * </ul>
* <p> * <p>
* Dependency core interfaces are: *
* Core interface:
* <ul> * <ul>
* <li>radio_interface * <li>radio_interface
* </ul> * </ul>
* <p> * <p>
* *
* @author Fredrik Osterlind * This observable notifies at radio state changes during RX and TX.
*
* @see #getLastEvent()
* @see UDGM
*
* @author Fredrik Österlind
*/ */
public class ContikiRadio extends Radio implements ContikiMoteInterface { public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledAfterActiveTicks {
private Mote myMote; private Mote myMote;
private SectionMoteMemory myMoteMemory; private SectionMoteMemory myMoteMemory;
@ -125,8 +132,8 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
/** /**
* Creates an interface to the radio at mote. * Creates an interface to the radio at mote.
* *
* @param mote * @param mote Mote
* Radio's mote. *
* @see Mote * @see Mote
* @see se.sics.cooja.MoteInterfaceHandler * @see se.sics.cooja.MoteInterfaceHandler
*/ */
@ -144,8 +151,7 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
// Calculate energy consumption of a listening radio // Calculate energy consumption of a listening radio
if (energyListeningRadioPerTick < 0) { if (energyListeningRadioPerTick < 0) {
energyListeningRadioPerTick = ENERGY_CONSUMPTION_RADIO_mA energyListeningRadioPerTick = ENERGY_CONSUMPTION_RADIO_mA * 0.001;
* mote.getSimulation().getTickTimeInSeconds();
} }
radioOn = myMoteMemory.getByteValueOf("simRadioHWOn") == 1; radioOn = myMoteMemory.getByteValueOf("simRadioHWOn") == 1;
@ -312,13 +318,9 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
myMoteMemory.setByteValueOf("simReceiving", (byte) 1); myMoteMemory.setByteValueOf("simReceiving", (byte) 1);
} }
public void doActionsBeforeTick() {
}
public void doActionsAfterTick() { public void doActionsAfterTick() {
// Check if radio hardware status changed /* Check if radio hardware status changed */
if (radioOn != (myMoteMemory.getByteValueOf("simRadioHWOn") == 1)) { if (radioOn != (myMoteMemory.getByteValueOf("simRadioHWOn") == 1)) {
// Radio changed
radioOn = !radioOn; radioOn = !radioOn;
if (!radioOn) { if (!radioOn) {
@ -351,7 +353,8 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
this.notifyObservers(); this.notifyObservers();
} }
// Are we transmitting but should stop? /* Are we transmitting but should stop? */
/* TODO Use time events */
if (isTransmitting if (isTransmitting
&& myMote.getSimulation().getSimulationTime() >= transmissionEndTime) { && myMote.getSimulation().getSimulationTime() >= transmissionEndTime) {
myMoteMemory.setByteValueOf("simTransmitting", (byte) 0); myMoteMemory.setByteValueOf("simTransmitting", (byte) 0);