Don't generate a zero-length packet in case of errors.
The packet converter used to generate packets of length zero when it encountered errors during conversion. This caused exceptions in packet analyzers. Now the converter returns null in case of error. Appropriate checks have been added to the code that uses the return value.
This commit is contained in:
parent
eae25d622d
commit
034a97eed2
4 changed files with 13 additions and 7 deletions
|
@ -198,7 +198,7 @@ public class CC2420RadioPacketConverter {
|
|||
System.arraycopy(data, 6 /* skipping preamble+synch+len */, originalData, 0, originalLen);
|
||||
if (len < 0) {
|
||||
/*logger.warn("No cross-level conversion available: negative packet length");*/
|
||||
return new ConvertedRadioPacket(new byte[0], originalData);
|
||||
return null;
|
||||
}
|
||||
byte convertedData[] = new byte[len];
|
||||
System.arraycopy(data, pos, convertedData, 0, len);
|
||||
|
|
|
@ -99,6 +99,7 @@ public class Msp802154Radio extends Radio implements CustomDataRadio {
|
|||
public void receivedByte(byte data) {
|
||||
if (!isTransmitting()) {
|
||||
lastEvent = RadioEvent.TRANSMISSION_STARTED;
|
||||
lastOutgoingPacket = null;
|
||||
isTransmitting = true;
|
||||
len = 0;
|
||||
expMpduLen = 0;
|
||||
|
@ -139,10 +140,12 @@ public class Msp802154Radio extends Radio implements CustomDataRadio {
|
|||
|
||||
if (((expMpduLen & 0x80) == 0) && len == expMpduLen + 6 && isSynchronized) {
|
||||
lastOutgoingPacket = CC2420RadioPacketConverter.fromCC2420ToCooja(buffer);
|
||||
lastEvent = RadioEvent.PACKET_TRANSMITTED;
|
||||
//logger.debug("----- 802.15.4 PACKET TRANSMITTED -----");
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
if (lastOutgoingPacket != null) {
|
||||
lastEvent = RadioEvent.PACKET_TRANSMITTED;
|
||||
//logger.debug("----- 802.15.4 PACKET TRANSMITTED -----");
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
isSynchronized = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,8 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
|
|||
if (radio.getLastPacketReceived() != null)
|
||||
receivedPacket(radio.getLastPacketReceived());
|
||||
} else if (radio.getLastEvent() == Radio.RadioEvent.TRANSMISSION_FINISHED) {
|
||||
sentPacket(radio.getLastPacketTransmitted());
|
||||
if (radio.getLastPacketTransmitted() != null)
|
||||
sentPacket(radio.getLastPacketTransmitted());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -517,10 +517,12 @@ public class RadioLogger extends VisPlugin {
|
|||
return;
|
||||
}
|
||||
final RadioConnectionLog loggedConn = new RadioConnectionLog();
|
||||
loggedConn.packet = conn.getSource().getLastPacketTransmitted();
|
||||
if (loggedConn.packet == null)
|
||||
return;
|
||||
loggedConn.startTime = conn.getStartTime();
|
||||
loggedConn.endTime = simulation.getSimulationTime();
|
||||
loggedConn.connection = conn;
|
||||
loggedConn.packet = conn.getSource().getLastPacketTransmitted();
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
Loading…
Reference in a new issue