added possibility to interfere with radio receptions "in the future" - reduces code complexity for radio mediums

This commit is contained in:
fros4943 2006-10-05 07:49:59 +00:00
parent cb7dbad086
commit b25f16936b
2 changed files with 52 additions and 26 deletions

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ContikiRadio.java,v 1.4 2006/10/02 15:38:44 fros4943 Exp $
* $Id: ContikiRadio.java,v 1.5 2006/10/05 07:49:59 fros4943 Exp $
*/
package se.sics.cooja.contikimote.interfaces;
@ -97,8 +97,9 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
private boolean transmitting = false;
private int transmissionEndTime = 0;
private int receptionEndTime = 0;
private int transmissionEndTime = -1;
private int interferenceEndTime = -1;
private int receptionEndTime = -1;
private RadioEvent lastEvent = RadioEvent.UNKNOWN;
private int lastEventTime = 0;
@ -179,8 +180,6 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
* have to, be used during a simulated data transfer that takes longer than
* one tick to complete. The system is unlocked by delivering the received
* data to the mote.
*
* @see #receivePacket(byte[])
*/
private void lockInReceivingMode() {
// If mote is inactive, try to wake it up
@ -201,6 +200,11 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
}
public void receivePacket(byte[] data, int endTime) {
if (isInterfered())
return;
if (isReceiving())
return;
lockInReceivingMode();
receptionEndTime = endTime;
@ -212,9 +216,15 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
if (myMote.getState() != Mote.State.ACTIVE) {
if (RAISES_EXTERNAL_INTERRUPT)
myMote.setState(Mote.State.ACTIVE);
if (myMote.getState() != Mote.State.ACTIVE)
if (myMote.getState() != Mote.State.ACTIVE) {
logger.fatal("Mote fell asleep during reception of packet, skipping packet!");
myMoteMemory.setByteValueOf("simReceiving", (byte) 0);
myMoteMemory.setIntValueOf("simInSize", 0);
this.setChanged();
this.notifyObservers();
return;
}
}
// Unlock (if locked)
myMoteMemory.setByteValueOf("simReceiving", (byte) 0);
@ -229,23 +239,27 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
this.notifyObservers();
}
/**
* Resets receive status. If a packet, or part of a packet, has been received
* but not yet taken care of in the Contiki system, this will be removed.
*/
public void interferReception() {
public void interferReception(int endTime) {
// Unlock (if locked)
myMoteMemory.setByteValueOf("simReceiving", (byte) 0);
// Reset data
myMoteMemory.setIntValueOf("simInSize", 0);
// Save interference end time (if updated)
interferenceEndTime = Math.max(interferenceEndTime, endTime);
if (lastEvent != RadioEvent.RECEPTION_INTERFERED) {
lastEvent = RadioEvent.RECEPTION_INTERFERED;
lastEventTime = myMote.getSimulation().getSimulationTime();
this.setChanged();
this.notifyObservers();
}
}
public boolean isInterfered() {
return interferenceEndTime >= myMote.getSimulation().getSimulationTime();
}
public double getCurrentSignalStrength() {
return myMoteMemory.getIntValueOf("simSignalStrength");
@ -256,11 +270,11 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
}
public void doActionsBeforeTick() {
// Do nothing
if (isLockedAtReceiving() && myMote.getSimulation().getSimulationTime() >= receptionEndTime)
// Check if we need to release Contiki lock and deliver packet data
if (isLockedAtReceiving() && myMote.getSimulation().getSimulationTime() >= receptionEndTime) {
deliverPacket();
}
}
public void doActionsAfterTick() {
// Check if radio hardware status changed
@ -297,7 +311,7 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
lastEventTime = myMote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.TRANSMISSION_FINISHED;
// TODO Memory consumption of transmitted packet?
// TODO Energy consumption of transmitted packet?
this.setChanged();
this.notifyObservers();
}

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: Radio.java,v 1.2 2006/10/02 15:10:57 fros4943 Exp $
* $Id: Radio.java,v 1.3 2006/10/05 07:51:19 fros4943 Exp $
*/
package se.sics.cooja.interfaces;
@ -71,7 +71,7 @@ public abstract class Radio extends MoteInterface {
public abstract byte[] getLastPacketReceived();
/**
* Receive given packet in given time. If reception is not interfered during
* Receive given packet. If reception is not interfered during
* this time, the packet will be delivered ok.
*
* @param data
@ -104,11 +104,23 @@ public abstract class Radio extends MoteInterface {
public abstract boolean isReceiving();
/**
* If any packet has been received but not yet taken care of, this packet will
* be removed. This method can be used to simulate significant interference
* during transmissions.
* If a packet is being received, it will be interfered and dropped. The
* interference will continue until the given time, during which no other
* radio traffic may be received. This method can be used to simulate
* significant interference during transmissions.
*
* @param endTime
* Time when interference stops
*/
public abstract void interferReception();
public abstract void interferReception(int endTime);
/**
* Returns true is this radio is currently hearing noise from another
* transmission.
*
* @return True if this radio is interfered
*/
public abstract boolean isInterfered();
/**
* @return Current surrounding signal strength