From 490bc6c5cbf512be9c2fe6c2b6802a9b7aa5d1b2 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 6 Mar 2014 03:06:15 +0100 Subject: [PATCH] [cooja] plugins/VariableWatcher: fixed handling of unknown variable sizes --- .../contikios/cooja/plugins/VariableWatcher.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/VariableWatcher.java b/tools/cooja/java/org/contikios/cooja/plugins/VariableWatcher.java index c485d1bf6..503fe3851 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/VariableWatcher.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/VariableWatcher.java @@ -254,7 +254,7 @@ public class VariableWatcher extends VisPlugin implements MotePlugin { String currentItem = (String)varNameCombo.getSelectedItem(); /* If item did not changed, skip! */ - if (currentItem.equals(lastItem)) { + if (currentItem == null || currentItem.equals(lastItem)) { return; } lastItem = currentItem; @@ -265,7 +265,19 @@ public class VariableWatcher extends VisPlugin implements MotePlugin { /* calculate number of elements required to show the value in the given size */ updateNumberOfValues(); varAddressField.setText(String.format("0x%04x", moteMemory.getVariableAddress(currentItem))); - varSizeField.setText(String.valueOf(moteMemory.getVariableSize(currentItem))); + long size = moteMemory.getVariableSize(currentItem); + /* Disable buttons if variable reported size < 1, activate otherwise */ + if (size < 1) { + varSizeField.setText("N/A"); + readButton.setEnabled(false); + monitorButton.setEnabled(false); + writeButton.setEnabled(false); + } else { + varSizeField.setText(String.valueOf(size)); + readButton.setEnabled(true); + monitorButton.setEnabled(true); + writeButton.setEnabled(true); + } } catch (UnknownVariableException ex) { ((JTextField) varNameCombo.getEditor().getEditorComponent()).setForeground(Color.RED);