warn if forwarded data is null

This commit is contained in:
fros4943 2008-03-18 15:43:03 +00:00
parent 8b6fb0821a
commit 6e6857c6a6

View File

@ -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: AbstractRadioMedium.java,v 1.4 2008/03/18 12:57:04 fros4943 Exp $ * $Id: AbstractRadioMedium.java,v 1.5 2008/03/18 15:43:03 fros4943 Exp $
*/ */
package se.sics.cooja.radiomediums; package se.sics.cooja.radiomediums;
@ -231,7 +231,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
radioMediumObservable.setRadioMediumChanged(); radioMediumObservable.setRadioMediumChanged();
} else if (event == Radio.RadioEvent.CUSTOM_DATA_TRANSMITTED) { } else if (event == Radio.RadioEvent.CUSTOM_DATA_TRANSMITTED) {
/* Forward custom data */ /* Forward custom data, if any */
// Find corresponding connection of radio // Find corresponding connection of radio
RadioConnection connection = null; RadioConnection connection = null;
@ -241,21 +241,25 @@ public abstract class AbstractRadioMedium extends RadioMedium {
break; break;
} }
} }
if (connection == null) { if (connection == null) {
logger.fatal("Can't find active connection to forward byte in"); logger.fatal("Can't find active connection to forward custom data in");
} else { return;
Object data = ((CustomDataRadio) radio).getLastCustomDataTransmitted(); }
for (Radio dstRadio : connection.getDestinations()) { Object data = ((CustomDataRadio) radio).getLastCustomDataTransmitted();
if (dstRadio instanceof CustomDataRadio) { if (data == null) {
((CustomDataRadio) dstRadio).receiveCustomData(data); logger.fatal("Custom data object is null");
} return;
}
for (Radio dstRadio : connection.getDestinations()) {
if (dstRadio instanceof CustomDataRadio) {
((CustomDataRadio) dstRadio).receiveCustomData(data);
} }
} }
} else if (event == Radio.RadioEvent.PACKET_TRANSMITTED) { } else if (event == Radio.RadioEvent.PACKET_TRANSMITTED) {
/* Forward packet */ /* Forward packet, if any */
// Find corresponding connection of radio // Find corresponding connection of radio
RadioConnection connection = null; RadioConnection connection = null;
@ -265,17 +269,21 @@ public abstract class AbstractRadioMedium extends RadioMedium {
break; break;
} }
} }
if (connection == null) { if (connection == null) {
logger.fatal("Can't find active connection to forward byte in"); logger.fatal("Can't find active connection to forward packet in");
} else { return;
byte[] packetData = radio.getLastPacketTransmitted().getPacketData(); }
Radio srcRadio = connection.getSource(); RadioPacket packet = radio.getLastPacketTransmitted();
for (Radio dstRadio : connection.getDestinations()) { if (packet == null) {
if (!(srcRadio instanceof CustomDataRadio) || !(dstRadio instanceof CustomDataRadio)) { logger.fatal("Radio packet is null");
dstRadio.setReceivedPacket(new COOJARadioPacket(packetData)); return;
} }
Radio srcRadio = connection.getSource();
for (Radio dstRadio : connection.getDestinations()) {
if (!(srcRadio instanceof CustomDataRadio) || !(dstRadio instanceof CustomDataRadio)) {
dstRadio.setReceivedPacket(packet);
} }
} }
@ -308,7 +316,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
return; return;
} }
// Log any new finished connections // Log any newly finished connections
if (finishedConnections.size() > 0) { if (finishedConnections.size() > 0) {
lastTickConnections = new RadioConnection[finishedConnections.size()]; lastTickConnections = new RadioConnection[finishedConnections.size()];
for (int i = 0; i < finishedConnections.size(); i++) { for (int i = 0; i < finishedConnections.size(); i++) {