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:
Timofei Istomin 2015-05-28 21:51:02 +02:00
parent eae25d622d
commit 034a97eed2
4 changed files with 13 additions and 7 deletions

View File

@ -198,7 +198,7 @@ public class CC2420RadioPacketConverter {
System.arraycopy(data, 6 /* skipping preamble+synch+len */, originalData, 0, originalLen); System.arraycopy(data, 6 /* skipping preamble+synch+len */, originalData, 0, originalLen);
if (len < 0) { if (len < 0) {
/*logger.warn("No cross-level conversion available: negative packet length");*/ /*logger.warn("No cross-level conversion available: negative packet length");*/
return new ConvertedRadioPacket(new byte[0], originalData); return null;
} }
byte convertedData[] = new byte[len]; byte convertedData[] = new byte[len];
System.arraycopy(data, pos, convertedData, 0, len); System.arraycopy(data, pos, convertedData, 0, len);

View File

@ -99,6 +99,7 @@ public class Msp802154Radio extends Radio implements CustomDataRadio {
public void receivedByte(byte data) { public void receivedByte(byte data) {
if (!isTransmitting()) { if (!isTransmitting()) {
lastEvent = RadioEvent.TRANSMISSION_STARTED; lastEvent = RadioEvent.TRANSMISSION_STARTED;
lastOutgoingPacket = null;
isTransmitting = true; isTransmitting = true;
len = 0; len = 0;
expMpduLen = 0; expMpduLen = 0;
@ -139,10 +140,12 @@ public class Msp802154Radio extends Radio implements CustomDataRadio {
if (((expMpduLen & 0x80) == 0) && len == expMpduLen + 6 && isSynchronized) { if (((expMpduLen & 0x80) == 0) && len == expMpduLen + 6 && isSynchronized) {
lastOutgoingPacket = CC2420RadioPacketConverter.fromCC2420ToCooja(buffer); lastOutgoingPacket = CC2420RadioPacketConverter.fromCC2420ToCooja(buffer);
lastEvent = RadioEvent.PACKET_TRANSMITTED; if (lastOutgoingPacket != null) {
//logger.debug("----- 802.15.4 PACKET TRANSMITTED -----"); lastEvent = RadioEvent.PACKET_TRANSMITTED;
setChanged(); //logger.debug("----- 802.15.4 PACKET TRANSMITTED -----");
notifyObservers(); setChanged();
notifyObservers();
}
isSynchronized = false; isSynchronized = false;
} }
} }

View File

@ -76,7 +76,8 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
if (radio.getLastPacketReceived() != null) if (radio.getLastPacketReceived() != null)
receivedPacket(radio.getLastPacketReceived()); receivedPacket(radio.getLastPacketReceived());
} else if (radio.getLastEvent() == Radio.RadioEvent.TRANSMISSION_FINISHED) { } else if (radio.getLastEvent() == Radio.RadioEvent.TRANSMISSION_FINISHED) {
sentPacket(radio.getLastPacketTransmitted()); if (radio.getLastPacketTransmitted() != null)
sentPacket(radio.getLastPacketTransmitted());
} }
} }
}; };

View File

@ -517,10 +517,12 @@ public class RadioLogger extends VisPlugin {
return; return;
} }
final RadioConnectionLog loggedConn = new RadioConnectionLog(); final RadioConnectionLog loggedConn = new RadioConnectionLog();
loggedConn.packet = conn.getSource().getLastPacketTransmitted();
if (loggedConn.packet == null)
return;
loggedConn.startTime = conn.getStartTime(); loggedConn.startTime = conn.getStartTime();
loggedConn.endTime = simulation.getSimulationTime(); loggedConn.endTime = simulation.getSimulationTime();
loggedConn.connection = conn; loggedConn.connection = conn;
loggedConn.packet = conn.getSource().getLastPacketTransmitted();
java.awt.EventQueue.invokeLater(new Runnable() { java.awt.EventQueue.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {