added possibility to interfere with radio receptions "in the future" - reduces code complexity for radio mediums
This commit is contained in:
parent
cb7dbad086
commit
b25f16936b
2 changed files with 52 additions and 26 deletions
|
@ -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.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;
|
package se.sics.cooja.contikimote.interfaces;
|
||||||
|
@ -97,8 +97,9 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
|
||||||
|
|
||||||
private boolean transmitting = false;
|
private boolean transmitting = false;
|
||||||
|
|
||||||
private int transmissionEndTime = 0;
|
private int transmissionEndTime = -1;
|
||||||
private int receptionEndTime = 0;
|
private int interferenceEndTime = -1;
|
||||||
|
private int receptionEndTime = -1;
|
||||||
|
|
||||||
private RadioEvent lastEvent = RadioEvent.UNKNOWN;
|
private RadioEvent lastEvent = RadioEvent.UNKNOWN;
|
||||||
private int lastEventTime = 0;
|
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
|
* 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
|
* one tick to complete. The system is unlocked by delivering the received
|
||||||
* data to the mote.
|
* data to the mote.
|
||||||
*
|
|
||||||
* @see #receivePacket(byte[])
|
|
||||||
*/
|
*/
|
||||||
private void lockInReceivingMode() {
|
private void lockInReceivingMode() {
|
||||||
// If mote is inactive, try to wake it up
|
// 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) {
|
public void receivePacket(byte[] data, int endTime) {
|
||||||
|
if (isInterfered())
|
||||||
|
return;
|
||||||
|
if (isReceiving())
|
||||||
|
return;
|
||||||
|
|
||||||
lockInReceivingMode();
|
lockInReceivingMode();
|
||||||
|
|
||||||
receptionEndTime = endTime;
|
receptionEndTime = endTime;
|
||||||
|
@ -212,8 +216,14 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
|
||||||
if (myMote.getState() != Mote.State.ACTIVE) {
|
if (myMote.getState() != Mote.State.ACTIVE) {
|
||||||
if (RAISES_EXTERNAL_INTERRUPT)
|
if (RAISES_EXTERNAL_INTERRUPT)
|
||||||
myMote.setState(Mote.State.ACTIVE);
|
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;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock (if locked)
|
// Unlock (if locked)
|
||||||
|
@ -229,22 +239,26 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
|
||||||
this.notifyObservers();
|
this.notifyObservers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void interferReception(int endTime) {
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
// Unlock (if locked)
|
// Unlock (if locked)
|
||||||
myMoteMemory.setByteValueOf("simReceiving", (byte) 0);
|
myMoteMemory.setByteValueOf("simReceiving", (byte) 0);
|
||||||
|
|
||||||
// Reset data
|
// Reset data
|
||||||
myMoteMemory.setIntValueOf("simInSize", 0);
|
myMoteMemory.setIntValueOf("simInSize", 0);
|
||||||
|
|
||||||
lastEvent = RadioEvent.RECEPTION_INTERFERED;
|
// Save interference end time (if updated)
|
||||||
lastEventTime = myMote.getSimulation().getSimulationTime();
|
interferenceEndTime = Math.max(interferenceEndTime, endTime);
|
||||||
this.setChanged();
|
|
||||||
this.notifyObservers();
|
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() {
|
public double getCurrentSignalStrength() {
|
||||||
|
@ -256,10 +270,10 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doActionsBeforeTick() {
|
public void doActionsBeforeTick() {
|
||||||
// Do nothing
|
// Check if we need to release Contiki lock and deliver packet data
|
||||||
|
if (isLockedAtReceiving() && myMote.getSimulation().getSimulationTime() >= receptionEndTime) {
|
||||||
if (isLockedAtReceiving() && myMote.getSimulation().getSimulationTime() >= receptionEndTime)
|
|
||||||
deliverPacket();
|
deliverPacket();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doActionsAfterTick() {
|
public void doActionsAfterTick() {
|
||||||
|
@ -297,7 +311,7 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface {
|
||||||
|
|
||||||
lastEventTime = myMote.getSimulation().getSimulationTime();
|
lastEventTime = myMote.getSimulation().getSimulationTime();
|
||||||
lastEvent = RadioEvent.TRANSMISSION_FINISHED;
|
lastEvent = RadioEvent.TRANSMISSION_FINISHED;
|
||||||
// TODO Memory consumption of transmitted packet?
|
// TODO Energy consumption of transmitted packet?
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
this.notifyObservers();
|
this.notifyObservers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja.interfaces;
|
||||||
|
@ -71,7 +71,7 @@ public abstract class Radio extends MoteInterface {
|
||||||
public abstract byte[] getLastPacketReceived();
|
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.
|
* this time, the packet will be delivered ok.
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
|
@ -104,12 +104,24 @@ public abstract class Radio extends MoteInterface {
|
||||||
public abstract boolean isReceiving();
|
public abstract boolean isReceiving();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If any packet has been received but not yet taken care of, this packet will
|
* If a packet is being received, it will be interfered and dropped. The
|
||||||
* be removed. This method can be used to simulate significant interference
|
* interference will continue until the given time, during which no other
|
||||||
* during transmissions.
|
* 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
|
* @return Current surrounding signal strength
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue