'+text+' | '+''+' | '+' |
Addresses %! addresses -+%! file-stats . \ No newline at end of file diff --git a/apps/webserver-nano/httpd-fs/status.shtml b/apps/webserver-nano/httpd-fs/status.shtml index d18b74e28..501203f0f 100644 --- a/apps/webserver-nano/httpd-fs/status.shtml +++ b/apps/webserver-nano/httpd-fs/status.shtml @@ -1,10 +1,14 @@ %! header -Neighbors
+ +Neighbors %! neighbors -Routes
+ +Routes %! routes -Sensors
+ +Sensors %! sensors -%! file-stats . +
Addresses
+
Addresses %! addresses -+%! file-stats . \ No newline at end of file diff --git a/apps/webserver-nano/httpd.c b/apps/webserver-nano/httpd.c index 7971832b8..234b76bb3 100644 --- a/apps/webserver-nano/httpd.c +++ b/apps/webserver-nano/httpd.c @@ -94,7 +94,6 @@ static PT_THREAD(send_file(struct httpd_state *s)) { PSOCK_BEGIN(&s->sout); - do { PSOCK_GENERATOR_SEND(&s->sout, generate, s); s->file.len -= s->len; @@ -488,11 +487,18 @@ httpd_appcall(void *state) PT_INIT(&s->outputpt); s->state = STATE_WAITING; s->timer = 0; +#if WEBSERVER_CONF_AJAX + s->ajax_timeout = WEBSERVER_CONF_TIMEOUT; +#endif handle_connection(s); } else if(s != NULL) { if(uip_poll()) { ++s->timer; - if(s->timer >= 20) { +#if WEBSERVER_CONF_AJAX + if(s->timer >= s->ajax_timeout) { +#else + if(s->timer >= WEBSERVER_CONF_TIMEOUT) { +#endif uip_abort(); memb_free(&conns, s); } diff --git a/apps/webserver-nano/httpd.h b/apps/webserver-nano/httpd.h index 3226a79b4..d10d389ef 100644 --- a/apps/webserver-nano/httpd.h +++ b/apps/webserver-nano/httpd.h @@ -76,6 +76,8 @@ #define WEBSERVER_CONF_CONNS 2 #define WEBSERVER_CONF_NAMESIZE 16 #define WEBSERVER_CONF_BUFSIZE 40 +/* Short tcp timeouts allow new connections sooner */ +#define WEBSERVER_CONF_TIMEOUT 20 /* Allow include in .shtml pages, e.g. %!: /header.html */ #define WEBSERVER_CONF_INCLUDE 1 /* Allow cgi in .shtml pages, e.g. %! file-stats . */ @@ -116,13 +118,13 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY]; #define WEBSERVER_CONF_LOG 0 /* Include referrer in log */ #define WEBSERVER_CONF_REFERER 0 - /*-----------------------------------------------------------------------------*/ #elif WEBSERVER_CONF_NANO==2 /* webserver-mini having more content */ #define WEBSERVER_CONF_CONNS 2 #define WEBSERVER_CONF_NAMESIZE 20 #define WEBSERVER_CONF_BUFSIZE 40 +#define WEBSERVER_CONF_TIMEOUT 20 /* Allow include in .shtml pages, e.g. %!: /header.html */ #define WEBSERVER_CONF_INCLUDE 1 /* Allow cgi in .shtml pages, e.g. %! file-stats . */ @@ -148,7 +150,7 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY]; //#define WEBSERVER_CONF_TICTACTOE 1 //Needs passquery of at least 10 chars #define WEBSERVER_CONF_AJAX 1 #define WEBSERVER_CONF_SHOW_ROOM 0 -//#define WEBSERVER_CONF_PASSQUERY 10 +#define WEBSERVER_CONF_PASSQUERY 10 #if WEBSERVER_CONF_PASSQUERY extern char httpd_query[WEBSERVER_CONF_PASSQUERY]; #endif @@ -171,6 +173,7 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY]; #define WEBSERVER_CONF_CONNS 6 #define WEBSERVER_CONF_NAMESIZE 20 #define WEBSERVER_CONF_BUFSIZE 40 +#define WEBSERVER_CONF_TIMEOUT 20 /* Allow include in .shtml pages, e.g. %!: /header.html */ #define WEBSERVER_CONF_INCLUDE 1 /* Allow cgi in .shtml pages, e.g. %! file-stats . */ @@ -285,6 +288,9 @@ struct httpd_state { #if WEBSERVER_CONF_LOADTIME clock_time_t pagetime; #endif +#if WEBSERVER_CONF_AJAX + uint16_t ajax_timeout; +#endif #if WEBSERVER_CONF_NEIGHBORS || WEBSERVER_CONF_ROUTES uint8_t starti,savei,startj,savej; #endif diff --git a/core/net/mac/contikimac.c b/core/net/mac/contikimac.c index 81640793e..d9c83e118 100644 --- a/core/net/mac/contikimac.c +++ b/core/net/mac/contikimac.c @@ -358,11 +358,14 @@ powercycle_turn_radio_on(void) static char powercycle(struct rtimer *t, void *ptr) { +#if SYNC_CYCLE_STARTS + static volatile rtimer_clock_t sync_cycle_start; + static volatile uint8_t sync_cycle_phase; +#endif + PT_BEGIN(&pt); #if SYNC_CYCLE_STARTS -static volatile rtimer_clock_t sync_cycle_start; -static volatile uint8_t sync_cycle_phase; sync_cycle_start = RTIMER_NOW(); #else cycle_start = RTIMER_NOW(); diff --git a/core/net/sicslowpan.c b/core/net/sicslowpan.c index 432c6831f..cfc11f943 100644 --- a/core/net/sicslowpan.c +++ b/core/net/sicslowpan.c @@ -179,9 +179,6 @@ void uip_log(char *msg); /** \name General variables * @{ */ -/** A pointer to the mac driver */ -const struct mac_driver *sicslowpan_mac; - #ifdef SICSLOWPAN_NH_COMPRESSOR /** A pointer to the additional compressor */ extern struct sicslowpan_nh_compressor SICSLOWPAN_NH_COMPRESSOR; @@ -1766,9 +1763,6 @@ input(void) void sicslowpan_init(void) { - /* remember the mac driver */ - sicslowpan_mac = &NETSTACK_MAC; - /* * Set out output function as the function to be called from uIP to * send a packet. diff --git a/core/net/sicslowpan.h b/core/net/sicslowpan.h index 2af071edf..c79ed2803 100644 --- a/core/net/sicslowpan.h +++ b/core/net/sicslowpan.h @@ -321,6 +321,5 @@ struct sicslowpan_nh_compressor { extern const struct network_driver sicslowpan_driver; -extern const struct mac_driver *sicslowpan_mac; #endif /* __SICSLOWPAN_H__ */ /** @} */ diff --git a/core/net/uip-nd6.c b/core/net/uip-nd6.c index 985703a8d..a52962aef 100644 --- a/core/net/uip-nd6.c +++ b/core/net/uip-nd6.c @@ -145,6 +145,7 @@ create_llao(uint8_t *llao, uint8_t type) { void uip_nd6_ns_input(void) { + uint8_t flags; PRINTF("Received NS from "); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINTF(" to "); @@ -154,8 +155,6 @@ uip_nd6_ns_input(void) PRINTF("\n"); UIP_STAT(++uip_stat.nd6.recv); - uint8_t flags; - #if UIP_CONF_IPV6_CHECKS if((UIP_IP_BUF->ttl != UIP_ND6_HOP_LIMIT) || (uip_is_addr_mcast(&UIP_ND6_NS_BUF->tgtipaddr)) || @@ -390,6 +389,11 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) void uip_nd6_na_input(void) { + uint8_t is_llchange; + uint8_t is_router; + uint8_t is_solicited; + uint8_t is_override; + PRINTF("Received NA from"); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINTF("to"); @@ -403,11 +407,11 @@ uip_nd6_na_input(void) * booleans. the three last one are not 0 or 1 but 0 or 0x80, 0x40, 0x20 * but it works. Be careful though, do not use tests such as is_router == 1 */ - uint8_t is_llchange = 0; - uint8_t is_router = ((UIP_ND6_NA_BUF->flagsreserved & UIP_ND6_NA_FLAG_ROUTER)); - uint8_t is_solicited = + is_llchange = 0; + is_router = ((UIP_ND6_NA_BUF->flagsreserved & UIP_ND6_NA_FLAG_ROUTER)); + is_solicited = ((UIP_ND6_NA_BUF->flagsreserved & UIP_ND6_NA_FLAG_SOLICITED)); - uint8_t is_override = + is_override = ((UIP_ND6_NA_BUF->flagsreserved & UIP_ND6_NA_FLAG_OVERRIDE)); #if UIP_CONF_IPV6_CHECKS diff --git a/examples/ipv6/native-border-router/border-router-rdc.c b/examples/ipv6/native-border-router/border-router-rdc.c index 5e4540714..78699122f 100644 --- a/examples/ipv6/native-border-router/border-router-rdc.c +++ b/examples/ipv6/native-border-router/border-router-rdc.c @@ -117,8 +117,10 @@ send_packet(mac_callback_t sent, void *ptr) } else { /* here we send the data over SLIP to the radio-chip */ - + size = 0; +#if SERIALIZE_ATTRIBUTES size = packetutils_serialize_atts(&buf[3], sizeof(buf) - 3); +#endif if(size < 0 || size + packetbuf_totlen() + 3 > sizeof(buf)) { PRINTF("br-rdc: send failed, too large header\n"); mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1); diff --git a/examples/ipv6/native-border-router/project-conf.h b/examples/ipv6/native-border-router/project-conf.h index 90576783a..2ab3cda7b 100644 --- a/examples/ipv6/native-border-router/project-conf.h +++ b/examples/ipv6/native-border-router/project-conf.h @@ -45,6 +45,8 @@ #undef WEBSERVER_CONF_CFS_CONNS #define WEBSERVER_CONF_CFS_CONNS 2 +#define SERIALIZE_ATTRIBUTES 1 + #define CMD_CONF_OUTPUT border_router_cmd_output #undef NETSTACK_CONF_RDC diff --git a/examples/ipv6/native-border-router/tun-bridge.c b/examples/ipv6/native-border-router/tun-bridge.c index 54d16339c..970b4cc79 100644 --- a/examples/ipv6/native-border-router/tun-bridge.c +++ b/examples/ipv6/native-border-router/tun-bridge.c @@ -125,13 +125,13 @@ void ifconf(const char *tundev, const char *ipaddr) { #ifdef linux - ssystem("ifconfig %s inet6 `hostname` up", tundev); + ssystem("ifconfig %s inet `hostname` up", tundev); ssystem("ifconfig %s add %s", tundev, ipaddr); #elif defined(__APPLE__) ssystem("ifconfig %s inet6 %s up", tundev, ipaddr); ssystem("sysctl -w net.inet.ip.forwarding=1"); #else - ssystem("ifconfig %s inet6 `hostname` %s up", tundev, ipaddr); + ssystem("ifconfig %s inet `hostname` %s up", tundev, ipaddr); ssystem("sysctl -w net.inet.ip.forwarding=1"); #endif /* !linux */ diff --git a/examples/ipv6/rpl-udp/udp-client.c b/examples/ipv6/rpl-udp/udp-client.c index 67e4de7e8..5a993e3c7 100644 --- a/examples/ipv6/rpl-udp/udp-client.c +++ b/examples/ipv6/rpl-udp/udp-client.c @@ -147,7 +147,9 @@ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic; static struct ctimer backoff_timer; +#if WITH_COMPOWER static int print = 0; +#endif PROCESS_BEGIN(); diff --git a/platform/cooja/Makefile.cooja b/platform/cooja/Makefile.cooja index e79fdbf1b..d4e80f182 100644 --- a/platform/cooja/Makefile.cooja +++ b/platform/cooja/Makefile.cooja @@ -106,9 +106,9 @@ ifdef SYMBOLS endif ## SYMBOLS ifdef REDEF_PRINTF @echo Redefining printf - -$(foreach OBJ,$^, objcopy --redefine-sym printf=log_printf $(OBJ); ) - -$(foreach OBJ,$^, objcopy --redefine-sym puts=log_puts $(OBJ); ) - -$(foreach OBJ,$^, objcopy --redefine-sym putchar=log_putchar $(OBJ); ) + -$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym printf=log_printf $(OBJ); ) + -$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym puts=log_puts $(OBJ); ) + -$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym putchar=log_putchar $(OBJ); ) endif ## REDEF_PRINTF $(LINK_COMMAND_1) $^ $(LINK_COMMAND_2) diff --git a/platform/cooja/dev/cooja-radio.c b/platform/cooja/dev/cooja-radio.c index 05aa7d49c..ca9552291 100644 --- a/platform/cooja/dev/cooja-radio.c +++ b/platform/cooja/dev/cooja-radio.c @@ -45,9 +45,11 @@ #include "dev/cooja-radio.h" #define COOJA_RADIO_BUFSIZE PACKETBUF_SIZE - #define CCA_SS_THRESHOLD -95 +#define WITH_TURNAROUND 1 +#define WITH_SEND_CCA 1 + const struct simInterface radio_interface; /* COOJA */ @@ -109,16 +111,16 @@ radio_off(void) static void doInterfaceActionsBeforeTick(void) { - if (!simRadioHWOn) { + if(!simRadioHWOn) { simInSize = 0; return; } - if (simReceiving) { + if(simReceiving) { simLastSignalStrength = simSignalStrength; return; } - if (simInSize > 0) { + if(simInSize > 0) { process_poll(&cooja_radio_process); } } @@ -133,7 +135,7 @@ radio_read(void *buf, unsigned short bufsize) { int tmp = simInSize; - if (simInSize == 0) { + if(simInSize == 0) { return 0; } if(bufsize < simInSize) { @@ -148,10 +150,25 @@ radio_read(void *buf, unsigned short bufsize) } /*---------------------------------------------------------------------------*/ static int +channel_clear(void) +{ + if(simSignalStrength > CCA_SS_THRESHOLD) { + return 0; + } + return 1; +} +/*---------------------------------------------------------------------------*/ +static int radio_send(const void *payload, unsigned short payload_len) { int radiostate = simRadioHWOn; + /* Simulate turnaround time of 1ms */ +#if WITH_TURNAROUND + simProcessRunValue = 1; + cooja_mt_yield(); +#endif /* WITH_TURNAROUND */ + if(!simRadioHWOn) { /* Turn on radio temporarily */ simRadioHWOn = 1; @@ -166,6 +183,13 @@ radio_send(const void *payload, unsigned short payload_len) return RADIO_TX_ERR; } + /* Transmit on CCA */ +#if WITH_SEND_CCA + if(!channel_clear()) { + return RADIO_TX_COLLISION; + } +#endif /* WITH_SEND_CCA */ + /* Copy packet data to temporary storage */ memcpy(simOutDataBuffer, payload, payload_len); simOutSize = payload_len; @@ -208,15 +232,6 @@ pending_packet(void) return !simReceiving && simInSize > 0; } /*---------------------------------------------------------------------------*/ -static int -channel_clear(void) -{ - if(simSignalStrength > CCA_SS_THRESHOLD) { - return 0; - } - return 1; -} -/*---------------------------------------------------------------------------*/ PROCESS_THREAD(cooja_radio_process, ev, data) { int len; diff --git a/platform/esb/contiki-conf.h b/platform/esb/contiki-conf.h index a577b7fe0..7b3ef0252 100644 --- a/platform/esb/contiki-conf.h +++ b/platform/esb/contiki-conf.h @@ -1,6 +1,10 @@ #ifndef __CONTIKI_CONF_H__ #define __CONTIKI_CONF_H__ +#define PLATFORM_HAS_LEDS 1 +#define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_HAS_BATTERY 1 + /* DCO speed resynchronization for more robust UART, etc. */ #define DCOSYNCH_CONF_ENABLED 1 #define DCOSYNCH_CONF_PERIOD 30 @@ -11,15 +15,6 @@ #define PROFILE_CONF_ON 0 #define ENERGEST_CONF_ON 1 -#ifdef __IAR_SYSTEMS_ICC__ -#define __MSP430F149__ 1 -#define __MSP430__ 1 -#define CC_CONF_INLINE -#define BV(x) (1 << x) -#else -#define CC_CONF_INLINE inline -#endif - #define HAVE_STDINT_H #include "msp430def.h" diff --git a/platform/esb/contiki-esb-main.c b/platform/esb/contiki-esb-main.c index 8267c0738..d052f453b 100644 --- a/platform/esb/contiki-esb-main.c +++ b/platform/esb/contiki-esb-main.c @@ -305,8 +305,6 @@ main(void) watchdog_start(); } } - - return 0; } /*---------------------------------------------------------------------------*/ /* char *arg_alloc(char size) {return NULL;} */ diff --git a/platform/exp5438/Makefile.exp5438 b/platform/exp5438/Makefile.exp5438 index 3f4d54820..a3e57fc90 100644 --- a/platform/exp5438/Makefile.exp5438 +++ b/platform/exp5438/Makefile.exp5438 @@ -1,19 +1,8 @@ # $Id: Makefile.z1,v 1.4 2010/11/07 08:40:24 enricmcalvo Exp $ # msp430flasher -n msp430x5437 -w "Firmware.txt" -v -z [VCC] -ifndef IAR -GCC=1 -endif - -ifdef GCC -CFLAGS+=-Os -g -else -IAR=1 -endif - ifdef IAR -CFLAGS+=-e --vla -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X --data_model small --double=32 -D__MSP430F5438A__ -CFLAGS += --diag_suppress=Pa050 +CFLAGS+=-e --vla -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X --data_model small --double=32 -D__MSP430F5438A__=1 #CFLAGS+=--no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F5438A__ -e --double=32 --dlib_config 'C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.0 Evaluation\430\LIB\DLIB\dl430xsfn.h' --core=430X --data_model=small -Ol --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 endif @@ -43,7 +32,7 @@ help: @echo make help - shows this help @echo make TARGET=exp5438 savetarget - stores selection of target to avoid using TARGET= on every make invokation @echo make program.upload - compiles and uploads program to connected board - @echo make program.upload GCC=1 - uses the mspgcc compiler instead of IAR + @echo make program.upload IAR=1 - uses the IAR compiler instead of mspgcc @echo make program.upload NODEID=x - uploads with node_id set to x CONTIKI_TARGET_DIRS = . dev apps net @@ -70,19 +59,12 @@ contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o} ifdef IAR STACKSIZE=300 -LDFLAGS_ELF=-B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -Felf -yn -s __program_start -D_STACK_SIZE=$(STACKSIZE) -D_DATA16_HEAP_SIZE=$(STACKSIZE) -D_DATA20_HEAP_SIZE=$(STACKSIZE) +LDFLAGSNO += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -s __program_start -D_STACK_SIZE=$(STACKSIZE) -D_DATA16_HEAP_SIZE=$(STACKSIZE) -D_DATA20_HEAP_SIZE=$(STACKSIZE) +LDFLAGS += $(LDFLAGSNO) -Felf -yn +endif -LDFLAGS_HEX=-B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -Fintel-extended -s __program_start -D_STACK_SIZE=$(STACKSIZE) -D_DATA16_HEAP_SIZE=$(STACKSIZE) -D_DATA20_HEAP_SIZE=$(STACKSIZE) - -LDFLAGS+=$(LDFLAGS_ELF) - -%.hex: %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a - $(LD) $(LDFLAGS_HEX) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ - -else %.hex: %.ihex mv $< $@ -endif %.upload: %.hex msp430flasher -n msp430x5438a -e ERASE_MAIN -w $< -v -z [VCC] diff --git a/platform/exp5438/cc2420-arch.c b/platform/exp5438/cc2420-arch.c index 090dd1611..044e894dd 100644 --- a/platform/exp5438/cc2420-arch.c +++ b/platform/exp5438/cc2420-arch.c @@ -31,19 +31,12 @@ #include "contiki.h" - -#ifdef __IAR_SYSTEMS_ICC__ -#includeNeighbors
+ +Neighbors %! neighbors -Routes
+ +Routes %! routes -Sensors
+ +Sensors %! sensors -%! file-stats . +
- * When an unhandled memory segment is set a new section is automatically + * When an non-existing memory segment is written, a new section is automatically * created for this segment. *
*
@@ -48,28 +47,36 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
private static Logger logger = Logger.getLogger(SectionMoteMemory.class);
private ArrayList" +
- StringUtils.hexDump(ba.mem, 4, 4) +
- "
";
- }
-
- String baString = ba.getParsedString();
- StringBuilder sb = new StringBuilder();
- sb.append("");
- while (baString.length() > 60) {
- sb.append(baString.substring(0, 60)).append("
");
- baString = baString.substring(60);
- };
- return sb.append(baString).append("").toString();
+ return
+ "" +
+ "Address: " + (ba.address==0?"null":String.format("%04x\n", ba.address)) +
+ StringUtils.hexDump(ba.mem, 4, 4) +
+ "
";
}
return super.getToolTipText(e);
@@ -417,7 +383,7 @@ public class BufferListener extends VisPlugin {
if (isSelected) {
bgColor = table.getSelectionBackground();
}
-
+
if (value instanceof BufferAccess && parser instanceof GraphicalParser) {
graphicalParserPanel.update((BufferAccess) value, (GraphicalParser)parser);
graphicalParserPanel.setBackground(bgColor);
@@ -425,7 +391,7 @@ public class BufferListener extends VisPlugin {
} else {
setBackground(bgColor);
}
-
+
return super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
}
@@ -593,7 +559,7 @@ public class BufferListener extends VisPlugin {
repaint();
}
});
-
+
logTable.setComponentPopupMenu(popupMenu);
/* Column width adjustment */
@@ -609,7 +575,11 @@ public class BufferListener extends VisPlugin {
simulation.getEventCentral().addMoteCountListener(logOutputListener = new MoteCountListener() {
public void moteWasAdded(Mote mote) {
/* Update title */
- startObserving(mote);
+ try {
+ startMonitoring(mote);
+ } catch (Exception e) {
+ logger.warn("Could not monitor buffer on: " + mote, e);
+ }
}
public void moteWasRemoved(Mote mote) {
/* Update title */
@@ -660,75 +630,151 @@ public class BufferListener extends VisPlugin {
setLocation(0, gui.getDesktopPane().getHeight() - 300);
}
- private boolean startObserving(Mote mote) {
- if (!(mote instanceof AbstractEmulatedMote)) {
- logger.fatal("Failed creating memory monitor: wrong mote type");
- return false;
- }
- AbstractEmulatedMote am = (AbstractEmulatedMote) mote;
- if (!(am.getMemory() instanceof AddressMemory)) {
- logger.fatal("Failed creating memory monitor: wrong memory type");
- return false;
- }
-
+ private boolean startMonitoring(Mote mote) throws Exception {
/* If this is a pointer buffer,
* we must observe both the pointer itself, and the pointed to memory */
- int address = buffer.getAddress(am);
- int size = buffer.getSize(am);
- if (address < 0 || size < 0 || size > MAX_BUFFER_SIZE) {
- logger.fatal("Failed start observing memory: bad addr/size: " + address + "/" + size);
- return false;
- }
-
- MemoryMonitor mm = startObservingMemory(am, address, size);
- if (mm == null) {
- return false;
- }
- boolean pointer = (buffer instanceof PointerBuffer);
- if (pointer) {
- int pointerAddress = ((PointerBuffer)buffer).getPointerAddress(am);
- /* Whenever the pointer changes, we re-register this observation */
- MemoryMonitor pointerMM = startObservingMemory(am, pointerAddress, 2);
- pointerMM.setPointer(true, mm);
- }
- return true;
- }
- private MemoryMonitor startObservingMemory(AbstractEmulatedMote mote, int address, int size) {
- MemoryMonitor mm = mote.createMemoryMonitor(meh);
- if (mm == null) {
- logger.fatal("Failed creating memory monitor: not implemented");
- return null;
- }
-
- boolean started = mm.start(address, size);
- if (!started) {
- logger.fatal("Failed creating memory monitor: could not start monitor");
- return null;
- }
-
- monitoredMemories.add(mm);
- /* TODO Don't keep pointed memories in this list.
- * Instead automatically unregister them from their parent memories. */
- if (!monitoredMotes.contains(mote)) {
- monitoredMotes.add(mote);
+ SegmentMemoryMonitor mm = buffer.createMemoryMonitor(this, mote);
+ memoryMonitors.add(mm);
+ if (!motes.contains(mote)) {
+ motes.add(mote);
}
updateTitle();
- return mm;
+ return true;
}
- private void stopObserving(Mote mote) {
- if (!(mote instanceof AbstractEmulatedMote)) {
- return;
+
+ public enum MemoryMonitorType { SEGMENT, POINTER, CONSTPOINTER };
+
+ static class PointerMemoryMonitor extends SegmentMemoryMonitor {
+ private SegmentMemoryMonitor segmentMonitor = null;
+ private int lastSegmentAddress = -1;
+ private final int pointerAddress;
+ private final int pointerSize;
+
+ public PointerMemoryMonitor(
+ BufferListener bl, Mote mote,
+ int pointerAddress, int pointerSize, int segmentSize)
+ throws Exception {
+ super(bl, mote, pointerAddress, pointerSize);
+ this.pointerAddress = pointerAddress;
+ this.pointerSize = pointerSize;
+
+ registerSegmentMonitor(segmentSize, false);
}
- for (MemoryMonitor mm: monitoredMemories.toArray(new MemoryMonitor[0])) {
- if (mm.getMote() == mote) {
- mm.stop();
- monitoredMemories.remove(mm);
+ private void registerSegmentMonitor(int size, boolean notify) throws Exception {
+ byte[] pointerValue = mote.getMemory().getMemorySegment(pointerAddress, pointerSize);
+ int segmentAddress = mote.getMemory().parseInt(pointerValue);
+
+ segmentMonitor = new SegmentMemoryMonitor(bl, mote, segmentAddress, size);
+ if (notify) {
+ segmentMonitor.memoryChanged(mote.getMemory(), MemoryEventType.WRITE, -1);
+ }
+ lastSegmentAddress = segmentAddress;
+ }
+
+ final public void memoryChanged(MoteMemory memory,
+ se.sics.cooja.MoteMemory.MemoryEventType type, int address) {
+ if (type == MemoryEventType.READ) {
+ return;
+ }
+
+ byte[] pointerValue = mote.getMemory().getMemorySegment(pointerAddress, pointerSize);
+ int segmentAddress = mote.getMemory().parseInt(pointerValue);
+ if (segmentAddress == lastSegmentAddress) {
+ return;
+ }
+
+ /* Pointer changed - we need to create new segment monitor */
+ segmentMonitor.dispose();
+ try {
+ registerSegmentMonitor(segmentMonitor.getSize(), true);
+ } catch (Exception e) {
+ logger.warn("Could not re-register memory monitor on: " + mote, e);
}
}
- monitoredMotes.remove(mote);
+ public MemoryMonitorType getType() {
+ return MemoryMonitorType.POINTER;
+ }
+
+ public void dispose() {
+ super.dispose();
+ segmentMonitor.dispose();
+ }
+ }
+
+ static class SegmentMemoryMonitor implements se.sics.cooja.MoteMemory.MemoryMonitor {
+ protected final BufferListener bl;
+ protected final Mote mote;
+
+ private final int address;
+ private final int size;
+
+ private byte[] oldData = null;
+
+ public SegmentMemoryMonitor(BufferListener bl, Mote mote, int address, int size)
+ throws Exception {
+ this.bl = bl;
+ this.mote = mote;
+ this.address = address;
+ this.size = size;
+
+ if (address != 0) {
+ if (!mote.getMemory().addMemoryMonitor(address, size, this)) {
+ throw new Exception("Could not register memory monitor on: " + mote);
+ }
+ }
+ }
+
+ public Mote getMote() {
+ return mote;
+ }
+ public int getAddress() {
+ return address;
+ }
+ public int getSize() {
+ return size;
+ }
+ public MemoryMonitorType getType() {
+ return MemoryMonitorType.SEGMENT;
+ }
+
+ public void dispose() {
+ if (address != 0) {
+ mote.getMemory().removeMemoryMonitor(address, size, this);
+ }
+ }
+
+ public void memoryChanged(MoteMemory memory, MemoryEventType type, int address) {
+ byte[] newData = getAddress()==0?null:mote.getMemory().getMemorySegment(getAddress(), getSize());
+ addBufferAccess(bl, mote, oldData, newData, type, this.address);
+ oldData = newData;
+ }
+
+ void addBufferAccess(BufferListener bl, Mote mote, byte[] oldData, byte[] newData, MemoryEventType type, int address) {
+ BufferAccess ba = new BufferAccess(
+ mote,
+ mote.getSimulation().getSimulationTime(),
+ address,
+ newData,
+ oldData,
+ type,
+ bl.withStackTrace
+ );
+ bl.logUpdateAggregator.add(ba);
+ }
+ }
+
+ private void stopObserving(Mote mote) {
+ for (SegmentMemoryMonitor mm: memoryMonitors.toArray(new SegmentMemoryMonitor[0])) {
+ if (mm.getMote() == mote) {
+ mm.dispose();
+ memoryMonitors.remove(mm);
+ }
+ }
+
+ motes.remove(mote);
updateTitle();
}
@@ -740,37 +786,16 @@ public class BufferListener extends VisPlugin {
private void updateTitle() {
if (buffer != null) {
- String bufferDesc = GUI.getDescriptionOf(buffer);
- /* Special buffer: Custom Variable/Custom Pointer */
- if (buffer.getClass() == CustomVariableBuffer.class) {
- int offset = ((CustomVariableBuffer)buffer).getOffset();
- if (offset > 0) {
- bufferDesc = "&" + ((CustomVariableBuffer)buffer).getVariable() + "[" + offset + "] (" + ((CustomVariableBuffer)buffer).getSize() + ")";
- } else {
- bufferDesc = ((CustomVariableBuffer)buffer).getVariable() + " (" + ((CustomVariableBuffer)buffer).getSize() + ")";
- }
- } else if (buffer.getClass() == CustomPointerBuffer.class) {
- int offset = ((CustomPointerBuffer)buffer).getOffset();
- bufferDesc = "*" + ((CustomPointerBuffer)buffer).getVariable() + " (" + ((CustomPointerBuffer)buffer).getSize() + ")";
- if (offset > 0) {
- bufferDesc = "*" + ((CustomPointerBuffer)buffer).getVariable() + "[" + offset + "] (" + ((CustomPointerBuffer)buffer).getSize() + ")";
- } else {
- bufferDesc = "*" + ((CustomPointerBuffer)buffer).getVariable() + " (" + ((CustomPointerBuffer)buffer).getSize() + ")";
- }
- }
-
- int count=0;
- for (MemoryMonitor mm: monitoredMemories) {
- if (mm.isPointer()) continue;
- count++;
- }
+ String status = buffer.getStatusString();
setTitle("Buffer Listener - " +
- bufferDesc + " - " +
- count + " buffers on " + monitoredMotes.size() + " motes");
+ ((status!=null)?status:GUI.getDescriptionOf(buffer)) + " " +
+ "- " + memoryMonitors.size() + " buffers on " + motes.size() + " motes");
}
}
public void closePlugin() {
+ if (hourTimeEvent != null) hourTimeEvent.remove();
+
/* Stop observing motes */
logUpdateAggregator.stop();
simulation.getEventCentral().removeMoteCountListener(logOutputListener);
@@ -814,18 +839,9 @@ public class BufferListener extends VisPlugin {
element = new Element("buffer");
element.setText(buffer.getClass().getName());
- /* Special buffer: Custom Variable/Custom Pointer */
- if (buffer.getClass() == CustomVariableBuffer.class) {
- element.setAttribute("variable", ((CustomVariableBuffer) buffer).getVariable());
- element.setAttribute("size", "" + ((CustomVariableBuffer) buffer).getSize());
- element.setAttribute("offset", "" + ((CustomVariableBuffer) buffer).getOffset());
- } else if (buffer.getClass() == CustomPointerBuffer.class) {
- element.setAttribute("variable", ((CustomPointerBuffer) buffer).getVariable());
- element.setAttribute("size", "" + ((CustomPointerBuffer) buffer).getSize());
- element.setAttribute("offset", "" + ((CustomPointerBuffer) buffer).getOffset());
- }
+ buffer.writeConfig(element);
config.add(element);
-
+
return config;
}
@@ -865,21 +881,15 @@ public class BufferListener extends VisPlugin {
}
} else if ("buffer".equals(name)) {
String bufferClassname = element.getText();
- Class extends Buffer> bufferClass =
+ Class extends Buffer> btClass =
simulation.getGUI().tryLoadClass(this, Buffer.class, bufferClassname);
- if (bufferClass == null) {
+ if (btClass == null) {
logger.warn("Could not create buffer parser: could not find class: " + bufferClassname);
} else {
-
- /* Special buffer: Custom Variable/Custom Pointer */
- if (bufferClass == CustomVariableBuffer.class ||
- bufferClass == CustomPointerBuffer.class) {
- String varName = element.getAttributeValue("variable");
- int varSize = Integer.parseInt(element.getAttributeValue("size"));
- int offset = Integer.parseInt(element.getAttributeValue("offset"));
- setBuffer(bufferClass, varName, varSize, offset);
- } else {
- setBuffer(bufferClass);
+ Buffer b = createBufferInstance(btClass);
+ if (b != null) {
+ b.applyConfig(element);
+ setBuffer(b);
}
}
}
@@ -907,13 +917,13 @@ public class BufferListener extends VisPlugin {
public boolean include(RowFilter.Entry extends Object, ? extends Object> entry) {
if (hideReads) {
int row = (Integer) entry.getIdentifier();
- if (logs.get(row).isRead) {
+ if (logs.get(row).type == MemoryEventType.READ) {
return false;
}
}
if (regexp != null) {
boolean pass = regexp.include(entry);
-
+
if (inverseFilter && pass) {
return false;
} else if (!inverseFilter && !pass) {
@@ -953,80 +963,63 @@ public class BufferListener extends VisPlugin {
});
}
- public class BufferAccess {
- public final AbstractEmulatedMote mote;
- public final long time;
-
- public final boolean isRead;
+ public static class BufferAccess {
+ public static final byte[] NULL_DATA = new byte[0];
- private MemoryMonitor mm;
- private int adr;
-
- public final String typeStr;
+ public final Mote mote;
+ public final long time;
+
+ public final byte[] mem;
+ private boolean[] accessedBitpattern = null;
+
+ public final MemoryEventType type;
public final String sourceStr;
public final String stackTrace;
- public final byte[] mem;
-
- private boolean[] accessedBitpattern = null;
-
+ public final int address;
+
public BufferAccess(
- long time, MemoryMonitor mm,
- MemoryEventType type, int adr, int data,
- BufferAccess previous) {
+ Mote mote, long time, int address, byte[] newData, byte[] oldData, MemoryEventType type, boolean withStackTrace) {
+ this.mote = mote;
this.time = time;
- this.mote = (AbstractEmulatedMote) mm.getMote();
- this.mm = mm;
- this.adr = adr;
- this.isRead = (type == MemoryEventType.READ);
- this.mem = mm.getMote().getMemory().getMemorySegment(mm.getAddress(), mm.getSize());
-
- /* Apply currently written data, if write operation */
- if (type == MemoryEventType.WRITE) {
- if (adr >= mm.getAddress() && adr < mm.getAddress() + mm.getSize()) {
- int offset = adr - mm.getAddress();
- byte now = (byte)(0xff&data);
- /*byte prev = mem[offset];*/
- /*logger.debug(String.format(
- "WRITE: 0x%02x: %02x -> %02x", adr, prev, now));*/
- mem[offset] = now;
- } else {
- logger.warn(String.format(
- "Write operation outside monitored addresses: %x !@ %x - %x",
- adr, mm.getAddress(), mm.getAddress()+mm.getSize()));
- }
- }
-
+ this.mem = newData==null?NULL_DATA:newData;
+ this.type = type;
+ this.address = address;
+
/* Generate diff bit pattern */
- if (previous != null) {
- accessedBitpattern = new boolean[previous.mem.length];
- for (int i=0; i < previous.mem.length; i++) {
- accessedBitpattern[i] = (previous.mem[i] != mem[i]);
+ if (newData != null && oldData != null) {
+ accessedBitpattern = new boolean[newData.length];
+ for (int i=0; i < newData.length; i++) {
+ accessedBitpattern[i] = (oldData[i] != mem[i]);
}
+ } else if (newData != null) {
+ accessedBitpattern = new boolean[newData.length];
+ Arrays.fill(accessedBitpattern, true);
}
-
- typeStr = type.toString();
- String s = mote.getPCString();
- sourceStr = s==null?"[unknown]":s;
- if (withStackTrace) {
- this.stackTrace = mote.getStackTrace();
+
+ if (mote instanceof AbstractEmulatedMote) {
+ String s = ((AbstractEmulatedMote)mote).getPCString();
+ sourceStr = s==null?"[unknown]":s;
+ if (withStackTrace) {
+ this.stackTrace = ((AbstractEmulatedMote)mote).getStackTrace();
+ } else {
+ this.stackTrace = null;
+ }
} else {
+ this.sourceStr = "[unknown]";
this.stackTrace = null;
}
}
- public Object getParsedData() {
- return parser.parse(mm, adr, this);
+ public String getAsHex() {
+ return String.format("%04x", address) + ":" + StringUtils.toHex(mem);
}
- public String getParsedString() {
- return StringUtils.toHex(mem);
- }
-
+
public boolean[] getAccessedBitpattern() {
return accessedBitpattern;
}
public String getType() {
- return typeStr;
+ return type.toString();
}
public Object getSource() {
@@ -1036,8 +1029,8 @@ public class BufferListener extends VisPlugin {
public String getID() {
return "ID:" + mote.getID();
}
-
- public String getTime() {
+
+ public String getTime(boolean formatTimeString, boolean hasHours) {
if (formatTimeString) {
long t = time;
long h = (t / TIME_HOUR);
@@ -1104,7 +1097,7 @@ public class BufferListener extends VisPlugin {
sb.append("\t");
if (parser instanceof GraphicalParser) {
BufferAccess ba = (BufferAccess) logTable.getValueAt(i, COLUMN_DATA);
- sb.append(ba.getParsedString());
+ sb.append(ba.getAsHex());
} else {
sb.append(logTable.getValueAt(i, COLUMN_DATA));
}
@@ -1153,20 +1146,20 @@ public class BufferListener extends VisPlugin {
}
int model = logTable.convertRowIndexToModel(view);
long time = logs.get(model).time;
-
+
Plugin[] plugins = simulation.getGUI().getStartedPlugins();
for (Plugin p: plugins) {
if (!(p instanceof TimeLine)) {
continue;
}
-
+
/* Select simulation time */
TimeLine plugin = (TimeLine) p;
plugin.trySelectTime(time);
}
}
};
-
+
private Action radioLoggerAction = new AbstractAction("in Radio Logger") {
private static final long serialVersionUID = -3041714249257346688L;
public void actionPerformed(ActionEvent e) {
@@ -1193,7 +1186,7 @@ public class BufferListener extends VisPlugin {
private Action showInAllAction = new AbstractAction("All") {
private static final long serialVersionUID = -8433490108577001803L;
{
- putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true));
+ putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true));
}
public void actionPerformed(ActionEvent e) {
@@ -1230,7 +1223,7 @@ public class BufferListener extends VisPlugin {
sb.append("\t");
if (parser instanceof GraphicalParser) {
BufferAccess ba = (BufferAccess) logTable.getValueAt(i, COLUMN_DATA);
- sb.append(ba.getParsedString());
+ sb.append(ba.getAsHex());
} else {
sb.append(logTable.getValueAt(i, COLUMN_DATA));
}
@@ -1260,7 +1253,7 @@ public class BufferListener extends VisPlugin {
sb.append("\t");
if (parser instanceof GraphicalParser) {
BufferAccess ba = (BufferAccess) logTable.getValueAt(i, COLUMN_DATA);
- sb.append(ba.getParsedString());
+ sb.append(ba.getAsHex());
} else {
sb.append(logTable.getValueAt(i, COLUMN_DATA));
}
@@ -1285,7 +1278,7 @@ public class BufferListener extends VisPlugin {
};
private void updateParserMenu() {
parserMenu.removeAll();
-
+
for (Class extends Parser> bpClass: bufferParsers) {
JCheckBoxMenuItem mi = new JCheckBoxMenuItem(GUI.getDescriptionOf(bpClass), bpClass==parser.getClass());
mi.putClientProperty("CLASS", bpClass);
@@ -1300,13 +1293,22 @@ public class BufferListener extends VisPlugin {
Class extends Buffer> btClass =
(Class extends Buffer>)
((JMenuItem) e.getSource()).getClientProperty("CLASS");
- setBuffer(btClass);
+
+ Buffer b = createBufferInstance(btClass);
+ if (b != null) {
+ if (b.configure(BufferListener.this)) {
+ setBuffer(b);
+ }
+ }
}
};
private void updateBufferMenu() {
bufferMenu.removeAll();
-
+
for (Class extends Buffer> btClass: bufferTypes) {
+ if (btClass == CustomVariableBuffer.class) {
+ bufferMenu.addSeparator();
+ }
JCheckBoxMenuItem mi = new JCheckBoxMenuItem(GUI.getDescriptionOf(btClass), btClass==buffer.getClass());
mi.putClientProperty("CLASS", btClass);
mi.addActionListener(bufferSelectedListener);
@@ -1325,32 +1327,37 @@ public class BufferListener extends VisPlugin {
logger.warn("Could not create buffer parser: " + e.getMessage(), e);
return;
}
-
+
parser = bp;
logTable.getColumnModel().getColumn(COLUMN_DATA).setHeaderValue(GUI.getDescriptionOf(bp));
repaint();
}
-
- private class VariableInfoComponent {
+ private static class BufferInput {
private JPanel mainPanel = new JPanel();
private JTextField textName = new JTextField();
private JTextField textSize = new JTextField();
private JTextField textOffset = new JTextField();
- public VariableInfoComponent(String name, String size, String offset) {
- textName.setText(name);
- textSize.setText(size);
- textOffset.setText(offset);
-
+ public BufferInput(String name, String size, String offset) {
mainPanel.setLayout(new GridLayout(3, 2, 5, 5));
- mainPanel.add(new JLabel("Variable name:"));
- mainPanel.add(textName);
- mainPanel.add(new JLabel("Buffer size (1-" + MAX_BUFFER_SIZE + "):"));
- mainPanel.add(textSize);
- mainPanel.add(new JLabel("Offset:"));
- mainPanel.add(textOffset);
+
+ if (name != null) {
+ textName.setText(name);
+ mainPanel.add(new JLabel("Symbol:"));
+ mainPanel.add(textName);
+ }
+ if (size != null) {
+ textSize.setText(size);
+ mainPanel.add(new JLabel("Size (1-" + MAX_BUFFER_SIZE + "):"));
+ mainPanel.add(textSize);
+ }
+ if (size != null) {
+ textOffset.setText(offset);
+ mainPanel.add(new JLabel("Offset"));
+ mainPanel.add(textOffset);
+ }
}
public String getName() {
return textName.getText();
@@ -1365,91 +1372,36 @@ public class BufferListener extends VisPlugin {
return mainPanel;
}
}
-
- private void setBuffer(Class extends Buffer> btClass) {
- setBuffer(btClass, null, -1, -1);
- }
- private void setBuffer(Class extends Buffer> btClass, String varName, int varSize, int varOffset) {
- /* Special buffer: Custom Variable/Custom Pointer */
- if ((btClass == CustomVariableBuffer.class || btClass == CustomPointerBuffer.class)
- && varName == null) {
- String d = (btClass == CustomVariableBuffer.class)?"Variable":"Pointer";
- /* Read variable name */
- String suggestName = GUI.getExternalToolsSetting("BUFFER_LISTENER_VARNAME", "node_id");
- String suggestSize = GUI.getExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "8");
- String suggestOffset = GUI.getExternalToolsSetting("BUFFER_LISTENER_VAROFFSET", "0");
- VariableInfoComponent infoComponent =
- new VariableInfoComponent(suggestName, suggestSize, suggestOffset);
-
- int result = JOptionPane.showConfirmDialog(BufferListener.this,
- infoComponent.getComponent(),
- d + " info",
- JOptionPane.OK_CANCEL_OPTION);
- if (result != JOptionPane.OK_OPTION) {
- /* Abort */
- return;
- }
- varName = infoComponent.getName();
- if (varName == null) {
- /* Abort */
- return;
- }
- try {
- varSize = Integer.parseInt(infoComponent.getSize());
- } catch (RuntimeException e) {
- logger.fatal("Failed parsing buffer size " + infoComponent.getSize() + ": " + e.getMessage(), e);
- /* Abort */
- return;
- }
- if (varSize < 1 || varSize > MAX_BUFFER_SIZE) {
- /* Abort */
- logger.fatal("Bad buffer size " + infoComponent.getSize() + ": min 1, max " + MAX_BUFFER_SIZE);
- return;
- }
- try {
- varOffset = Integer.parseInt(infoComponent.getOffset());
- } catch (RuntimeException e) {
- logger.fatal("Failed parsing buffer offset " + infoComponent.getOffset() + ": " + e.getMessage(), e);
- /* Abort */
- return;
- }
- }
-
- /* Generate buffer type */
- Buffer bt = null;
+ private static Buffer createBufferInstance(Class extends Buffer> btClass) {
try {
- bt = btClass.newInstance();
+ return btClass.newInstance();
} catch (InstantiationException e) {
logger.warn("Could not create buffer type: " + e.getMessage(), e);
- return;
+ return null;
} catch (IllegalAccessException e) {
logger.warn("Could not create buffer type: " + e.getMessage(), e);
+ return null;
+ }
+ }
+
+ private void setBuffer(Buffer buffer) {
+ if (buffer == null) {
return;
}
- /* Special buffer: Custom Variable/Custom Pointer */
- if (btClass == CustomVariableBuffer.class) {
- ((CustomVariableBuffer)bt).setInfo(varName, varSize, varOffset);
- GUI.setExternalToolsSetting("BUFFER_LISTENER_VARNAME", varName);
- GUI.setExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "" + varSize);
- GUI.setExternalToolsSetting("BUFFER_LISTENER_VAROFFSET", "" + varOffset);
- } else if (btClass == CustomPointerBuffer.class) {
- ((CustomPointerBuffer)bt).setInfo(varName, varSize, varOffset);
- GUI.setExternalToolsSetting("BUFFER_LISTENER_VARNAME", varName);
- GUI.setExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "" + varSize);
- GUI.setExternalToolsSetting("BUFFER_LISTENER_VAROFFSET", "" + varOffset);
- }
-
- buffer = bt;
+ this.buffer = buffer;
/* Reregister memory monitors */
for (Mote m: simulation.getMotes()) {
stopObserving(m);
}
for (Mote m: simulation.getMotes()) {
- /* TODO Check return values */
- startObserving(m);
+ try {
+ startMonitoring(m);
+ } catch (Exception e) {
+ logger.warn("Could not monitor buffer on: " + m, e);
+ }
}
/* Clear previous buffers, update gui */
@@ -1457,7 +1409,7 @@ public class BufferListener extends VisPlugin {
updateTitle();
repaint();
}
-
+
public static interface Parser {
/**
* @param mm Memory monitor
@@ -1465,11 +1417,11 @@ public class BufferListener extends VisPlugin {
* @param ba Buffer Access object
* @return String or custom graphical object
*/
- public Object parse(MemoryMonitor mm, int address, BufferAccess ba);
+ public Object parse(BufferAccess ba);
}
public static abstract class GraphicalParser implements Parser {
BufferAccess ba = null;
- public Object parse(MemoryMonitor mm, int address, BufferAccess ba) {
+ public Object parse(BufferAccess ba) {
this.ba = ba;
return ba;
}
@@ -1478,28 +1430,71 @@ public class BufferListener extends VisPlugin {
}
public static abstract class StringParser implements Parser {
- public Object parse(MemoryMonitor mm, int address, BufferAccess ba) {
- return parseString(mm,address,ba);
+ public Object parse(BufferAccess ba) {
+ return parseString(ba);
}
- /**
- * @param mm Memory monitor
- * @param address Address that changed. May not contain all changes
- * @param ba Buffer Access object
- * @return String representation
- */
- public abstract String parseString(MemoryMonitor mm, int address, BufferAccess ba);
+ public abstract String parseString(BufferAccess ba);
}
+
public static interface Buffer {
public int getAddress(Mote mote);
public int getSize(Mote mote);
-
- }
- public static interface PointerBuffer extends Buffer {
- public int getAddress(Mote mote);
- public int getSize(Mote mote);
- public int getPointerAddress(Mote mote);
+ public String getStatusString();
+
+ public SegmentMemoryMonitor createMemoryMonitor(BufferListener bl, Mote mote)
+ throws Exception;
+
+ /*
+ * Called when buffer is created by user to allow user input (AWT thread)
+ */
+ public boolean configure(BufferListener bl);
+
+ /*
+ * Called when buffer is created from config
+ */
+ public void applyConfig(Element element);
+
+ public void writeConfig(Element element);
+ }
+ public static abstract class AbstractBuffer implements Buffer {
+ public String getStatusString() {
+ return null;
+ }
+ public void writeConfig(Element element) {
+ }
+ public void applyConfig(Element element) {
+ }
+ public boolean configure(BufferListener bl) {
+ return true;
+ }
+ }
+
+ public static abstract class PointerBuffer extends AbstractBuffer {
+ public abstract int getPointerAddress(Mote mote);
+
+ public SegmentMemoryMonitor createMemoryMonitor(BufferListener bl, Mote mote)
+ throws Exception {
+ return new PointerMemoryMonitor(
+ bl,
+ mote,
+ getPointerAddress(mote),
+ mote.getMemory().getIntegerLength(),
+ getSize(mote)
+ );
+ }
+ }
+ public static abstract class SegmentBuffer extends AbstractBuffer {
+ public SegmentMemoryMonitor createMemoryMonitor(BufferListener bl, Mote mote)
+ throws Exception {
+ return new SegmentMemoryMonitor(
+ bl,
+ mote,
+ getAddress(mote),
+ getSize(mote)
+ );
+ }
}
public static boolean registerBufferParser(Class extends Parser> bpClass) {
@@ -1523,10 +1518,10 @@ public class BufferListener extends VisPlugin {
public static void unregisterBufferType(Class extends Buffer> btClass) {
bufferTypes.remove(btClass);
}
-
+
@ClassDescription("Byte array")
public static class ByteArrayParser extends StringParser {
- public String parseString(MemoryMonitor mm, int address, BufferAccess ba) {
+ public String parseString(BufferAccess ba) {
boolean[] diff = ba.getAccessedBitpattern();
if (diff == null) {
return StringUtils.toHex(ba.mem, 4); /* 00112233 00112233 .. */
@@ -1537,7 +1532,6 @@ public class BufferListener extends VisPlugin {
int group = 0;
for (int i=0; i < ba.mem.length; i++) {
if (inRed == diff[i]) {
- //logger.debug("same " + i);
sb.append(StringUtils.toHex(ba.mem[i]));
} else if (!inRed) {
/* Diff begins */
@@ -1565,27 +1559,28 @@ public class BufferListener extends VisPlugin {
return sb.toString();
}
}
-
+
@ClassDescription("Integer array")
public static class IntegerParser extends StringParser {
- public String parseString(MemoryMonitor mm, int address, BufferAccess ba) {
+ public String parseString(BufferAccess ba) {
StringBuilder sb = new StringBuilder();
- boolean[] diff = ba.getAccessedBitpattern();
-
+
+ int intLen = ba.mote.getMemory().getIntegerLength();
sb.append("");
- for (int i=0; i+1 < ba.mem.length;) {
- int val = 0;
+ for (int i=0; i < ba.mem.length/intLen; i++) {
+ byte[] mem = Arrays.copyOfRange(ba.mem, i*intLen,(i+1)*intLen);
+ boolean[] diff = Arrays.copyOfRange(ba.getAccessedBitpattern(), i*intLen,(i+1)*intLen);
+ int val = ba.mote.getMemory().parseInt(mem);
+
boolean red = false;
- if (diff != null && (diff[i] || diff[i+1])) {
- red = true;
+ for (boolean changed: diff) {
+ if (changed) red = true;
}
- val += ((ba.mem[i++] & 0xFF)) << 8;
- val += ((ba.mem[i++] & 0xFF)) << 0;
-
+
if (red) {
sb.append("");
}
- sb.append((Integer.reverseBytes(val) >> 16) + " ");
+ sb.append(val + " ");
if (red) {
sb.append("");
}
@@ -1597,7 +1592,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Terminated string")
public static class TerminatedStringParser extends StringParser {
- public String parseString(MemoryMonitor mm, int address, BufferAccess ba) {
+ public String parseString(BufferAccess ba) {
/* TODO Diff? */
int i;
for (i=0; i < ba.mem.length; i++) {
@@ -1613,7 +1608,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Printable characters")
public static class PrintableCharactersParser extends StringParser {
- public String parseString(MemoryMonitor mm, int address, BufferAccess ba) {
+ public String parseString(BufferAccess ba) {
/* TODO Diff? */
return new String(ba.mem).replaceAll("[^\\p{Print}]", "");
}
@@ -1621,7 +1616,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("IPv6 address")
public static class IPv6AddressParser extends StringParser {
- public String parseString(MemoryMonitor mm, int address, BufferAccess ba) {
+ public String parseString(BufferAccess ba) {
/* TODO Diff? */
if (ba.mem.length < 16) {
return "[must monitor at least 16 bytes]";
@@ -1639,7 +1634,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("IPv4 address")
public static class IPv4AddressParser extends StringParser {
- public String parseString(MemoryMonitor mm, int address, BufferAccess ba) {
+ public String parseString(BufferAccess ba) {
/* TODO Diff? */
if (ba.mem.length < 4) {
return "[must monitor at least 4 bytes]";
@@ -1655,7 +1650,7 @@ public class BufferListener extends VisPlugin {
return sb.toString();
}
}
-
+
static class GrapicalParserPanel extends JPanel {
private static final long serialVersionUID = -8375160571675638467L;
static final int XOFFSET = 0;
@@ -1672,7 +1667,7 @@ public class BufferListener extends VisPlugin {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.translate(XOFFSET, 0);
-
+
if (getWidth() > getPreferredSize().width + 10 ||
getWidth() < getPreferredSize().width - 10) {
double scale = 1.0*getWidth()/getPreferredSize().width;
@@ -1683,7 +1678,7 @@ public class BufferListener extends VisPlugin {
}
};
private GrapicalParserPanel graphicalParserPanel = new GrapicalParserPanel();
-
+
@ClassDescription("Graphical: Height")
public static class GraphicalHeight4BitsParser extends GraphicalParser {
public int getUnscaledWidth() {
@@ -1709,7 +1704,7 @@ public class BufferListener extends VisPlugin {
}
}
}
-
+
@ClassDescription("Graphical: Grayscale")
public static class GraphicalGrayscale4BitsParser extends GraphicalParser {
public int getUnscaledWidth() {
@@ -1732,141 +1727,276 @@ public class BufferListener extends VisPlugin {
}
}
}
-
+
@ClassDescription("Variable: node_id")
- public static class NodeIDBuffer implements Buffer {
+ public static class NodeIDBuffer extends SegmentBuffer {
public int getAddress(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists("node_id")) {
+ if (!mote.getMemory().variableExists("node_id")) {
return -1;
}
- return ((AddressMemory)mote.getMemory()).getVariableAddress("node_id");
+ return mote.getMemory().getVariableAddress("node_id");
}
public int getSize(Mote mote) {
- return 2;
+ return mote.getMemory().getIntegerLength();
}
+
}
-
+
@ClassDescription("Queuebuf 0 RAM")
- public static class Queuebuf0Buffer implements Buffer {
+ public static class Queuebuf0Buffer extends SegmentBuffer {
public int getAddress(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists("buframmem")) {
+ if (!mote.getMemory().variableExists("buframmem")) {
return -1;
}
int offset = 0;
- return ((AddressMemory)mote.getMemory()).getVariableAddress("buframmem") + offset;
+ return mote.getMemory().getVariableAddress("buframmem") + offset;
}
public int getSize(Mote mote) {
return 128;
}
}
-
+
@ClassDescription("packetbuf_aligned")
- public static class PacketbufBuffer implements Buffer {
+ public static class PacketbufBuffer extends SegmentBuffer {
public int getAddress(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists("packetbuf_aligned")) {
+ if (!mote.getMemory().variableExists("packetbuf_aligned")) {
return -1;
}
- return ((AddressMemory)mote.getMemory()).getVariableAddress("packetbuf_aligned");
+ return mote.getMemory().getVariableAddress("packetbuf_aligned");
}
public int getSize(Mote mote) {
return 128;
}
}
-
+
@ClassDescription("*packetbufptr")
- public static class PacketbufPointerBuffer implements PointerBuffer {
+ public static class PacketbufPointerBuffer extends PointerBuffer {
public int getPointerAddress(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists("packetbufptr")) {
+ if (!mote.getMemory().variableExists("packetbufptr")) {
return -1;
}
- return ((AddressMemory)mote.getMemory()).getVariableAddress("packetbufptr");
+ return mote.getMemory().getVariableAddress("packetbufptr");
}
public int getAddress(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists("packetbufptr")) {
+ if (!mote.getMemory().variableExists("packetbufptr")) {
return -1;
}
- return ((AddressMemory)mote.getMemory()).getIntValueOf("packetbufptr");
+ return mote.getMemory().getIntValueOf("packetbufptr");
}
public int getSize(Mote mote) {
return 128;
}
}
-
- @ClassDescription("Custom pointer")
- public static class CustomPointerBuffer implements PointerBuffer {
+
+ @ClassDescription("Pointer...")
+ public static class CustomPointerBuffer extends PointerBuffer {
public String variable;
public int size;
public int offset;
- public void setInfo(String variable, int size, int offset) {
- this.variable = variable;
- this.size = size;
- this.offset = offset;
- }
- public String getVariable() {
- return variable;
- }
- public int getSize() {
- return size;
- }
- public int getOffset() {
- return offset;
- }
-
public int getPointerAddress(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists(variable)) {
+ if (!mote.getMemory().variableExists(variable)) {
return -1;
}
- return ((AddressMemory)mote.getMemory()).getVariableAddress(variable);
+ return mote.getMemory().getVariableAddress(variable);
}
public int getAddress(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists(variable)) {
+ if (!mote.getMemory().variableExists(variable)) {
return -1;
}
- return ((AddressMemory)mote.getMemory()).getIntValueOf(variable)+offset;
+ return mote.getMemory().getIntValueOf(variable)+offset;
}
public int getSize(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists(variable)) {
+ if (!mote.getMemory().variableExists(variable)) {
return -1;
}
return size;
}
+
+ public String getStatusString() {
+ if (offset > 0) {
+ return "Pointer *" + variable + "[" + offset + "] (" + size + ")";
+ } else {
+ return "Pointer *" + variable + " (" + size + ")";
+ }
+ }
+
+ public void writeConfig(Element element) {
+ element.setAttribute("variable", variable);
+ element.setAttribute("size", "" + size);
+ element.setAttribute("offset", "" + offset);
+ }
+ public void applyConfig(Element element) {
+ variable = element.getAttributeValue("variable");
+ size = Integer.parseInt(element.getAttributeValue("size"));
+ offset = Integer.parseInt(element.getAttributeValue("offset"));
+ }
+ public boolean configure(BufferListener bl) {
+ String suggestName = GUI.getExternalToolsSetting("BUFFER_LISTENER_VARNAME", "node_id");
+ String suggestSize = GUI.getExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "2");
+ String suggestOffset = GUI.getExternalToolsSetting("BUFFER_LISTENER_VAROFFSET", "0");
+ BufferInput infoComponent =
+ new BufferInput(suggestName, suggestSize, suggestOffset);
+
+ int result = JOptionPane.showConfirmDialog(bl,
+ infoComponent.getComponent(),
+ "Symbol info",
+ JOptionPane.OK_CANCEL_OPTION);
+ if (result != JOptionPane.OK_OPTION) {
+ /* Abort */
+ return false;
+ }
+ variable = infoComponent.getName();
+ if (variable == null) {
+ return false;
+ }
+ try {
+ size = Integer.parseInt(infoComponent.getSize());
+ if (size < 1 || size > MAX_BUFFER_SIZE) {
+ /* Abort */
+ logger.fatal("Bad buffer size " + infoComponent.getSize() + ": min 1, max " + MAX_BUFFER_SIZE);
+ return false;
+ }
+ } catch (RuntimeException e) {
+ logger.fatal("Failed parsing buffer size " + infoComponent.getSize() + ": " + e.getMessage(), e);
+ return false;
+ }
+ try {
+ offset = Integer.parseInt(infoComponent.getOffset());
+ } catch (RuntimeException e) {
+ logger.fatal("Failed parsing buffer offset " + infoComponent.getOffset() + ": " + e.getMessage(), e);
+ /* Abort */
+ return false;
+ }
+
+ GUI.setExternalToolsSetting("BUFFER_LISTENER_VARNAME", variable);
+ GUI.setExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "" + size);
+ GUI.setExternalToolsSetting("BUFFER_LISTENER_VAROFFSET", "" + offset);
+ return true;
+ }
}
-
- @ClassDescription("Custom variable")
- public static class CustomVariableBuffer implements Buffer {
+
+ @ClassDescription("Symbol...")
+ public static class CustomVariableBuffer extends SegmentBuffer {
public String variable;
public int size;
public int offset;
- public void setInfo(String variable, int size, int offset) {
- this.variable = variable;
- this.size = size;
- this.offset = offset;
- }
- public String getVariable() {
- return variable;
- }
- public int getSize() {
- return size;
- }
- public int getOffset() {
- return offset;
- }
- public boolean isPointer() {
- return false;
- }
-
public int getAddress(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists(variable)) {
+ if (!mote.getMemory().variableExists(variable)) {
return -1;
}
- return ((AddressMemory)mote.getMemory()).getVariableAddress(variable)+offset;
+ return mote.getMemory().getVariableAddress(variable)+offset;
}
public int getSize(Mote mote) {
- if (!((AddressMemory)mote.getMemory()).variableExists(variable)) {
+ if (!mote.getMemory().variableExists(variable)) {
return -1;
}
return size;
}
+
+ public String getStatusString() {
+ if (offset > 0) {
+ return "Symbol &" + variable + "[" + offset + "] (" + size + ")";
+ } else {
+ return "Symbol " + variable + " (" + size + ")";
+ }
+ }
+
+ public void writeConfig(Element element) {
+ element.setAttribute("variable", variable);
+ element.setAttribute("size", "" + size);
+ element.setAttribute("offset", "" + offset);
+ }
+ public void applyConfig(Element element) {
+ variable = element.getAttributeValue("variable");
+ size = Integer.parseInt(element.getAttributeValue("size"));
+ offset = Integer.parseInt(element.getAttributeValue("offset"));
+ }
+ public boolean configure(BufferListener bl) {
+ String suggestName = GUI.getExternalToolsSetting("BUFFER_LISTENER_VARNAME", "node_id");
+ String suggestSize = GUI.getExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "2");
+ String suggestOffset = GUI.getExternalToolsSetting("BUFFER_LISTENER_VAROFFSET", "0");
+ BufferInput infoComponent =
+ new BufferInput(suggestName, suggestSize, suggestOffset);
+
+ int result = JOptionPane.showConfirmDialog(bl,
+ infoComponent.getComponent(),
+ "Symbol info",
+ JOptionPane.OK_CANCEL_OPTION);
+ if (result != JOptionPane.OK_OPTION) {
+ /* Abort */
+ return false;
+ }
+ variable = infoComponent.getName();
+ if (variable == null) {
+ return false;
+ }
+ try {
+ size = Integer.parseInt(infoComponent.getSize());
+ if (size < 1 || size > MAX_BUFFER_SIZE) {
+ /* Abort */
+ logger.fatal("Bad buffer size " + infoComponent.getSize() + ": min 1, max " + MAX_BUFFER_SIZE);
+ return false;
+ }
+ } catch (RuntimeException e) {
+ logger.fatal("Failed parsing buffer size " + infoComponent.getSize() + ": " + e.getMessage(), e);
+ return false;
+ }
+ try {
+ offset = Integer.parseInt(infoComponent.getOffset());
+ } catch (RuntimeException e) {
+ logger.fatal("Failed parsing buffer offset " + infoComponent.getOffset() + ": " + e.getMessage(), e);
+ /* Abort */
+ return false;
+ }
+ GUI.setExternalToolsSetting("BUFFER_LISTENER_VARNAME", variable);
+ GUI.setExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "" + size);
+ GUI.setExternalToolsSetting("BUFFER_LISTENER_VAROFFSET", "" + offset);
+ return true;
+ }
+ }
+
+ @ClassDescription("Integer...")
+ public static class CustomIntegerBuffer extends SegmentBuffer {
+ public String variable;
+ public int getAddress(Mote mote) {
+ if (!mote.getMemory().variableExists(variable)) {
+ return -1;
+ }
+ return mote.getMemory().getVariableAddress(variable);
+ }
+ public int getSize(Mote mote) {
+ return mote.getMemory().getIntegerLength();
+ }
+
+ public String getStatusString() {
+ return "Integer " + variable;
+ }
+
+ public void writeConfig(Element element) {
+ element.setAttribute("variable", variable);
+ }
+ public void applyConfig(Element element) {
+ variable = element.getAttributeValue("variable");
+ }
+ public boolean configure(BufferListener bl) {
+ String suggestName = GUI.getExternalToolsSetting("BUFFER_LISTENER_VARNAME", "node_id");
+ BufferInput infoComponent =
+ new BufferInput(suggestName, null, null);
+
+ int result = JOptionPane.showConfirmDialog(bl,
+ infoComponent.getComponent(),
+ "Symbol info",
+ JOptionPane.OK_CANCEL_OPTION);
+ if (result != JOptionPane.OK_OPTION) {
+ /* Abort */
+ return false;
+ }
+ variable = infoComponent.getName();
+ if (variable == null) {
+ return false;
+ }
+ GUI.setExternalToolsSetting("BUFFER_LISTENER_VARNAME", variable);
+ return true;
+ }
}
-
}
diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java b/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java
index e404a80ef..b0b4d1e0a 100644
--- a/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java
+++ b/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java
@@ -147,6 +147,11 @@ public abstract class AbstractRadioMedium extends RadioMedium {
conn.getSource().setCurrentSignalStrength(SS_STRONG);
}
for (Radio dstRadio : conn.getDestinations()) {
+ if (conn.getSource().getChannel() >= 0 &&
+ dstRadio.getChannel() >= 0 &&
+ conn.getSource().getChannel() != dstRadio.getChannel()) {
+ continue;
+ }
if (dstRadio.getCurrentSignalStrength() < SS_STRONG) {
dstRadio.setCurrentSignalStrength(SS_STRONG);
}
@@ -159,7 +164,11 @@ public abstract class AbstractRadioMedium extends RadioMedium {
if (intfRadio.getCurrentSignalStrength() < SS_STRONG) {
intfRadio.setCurrentSignalStrength(SS_STRONG);
}
-
+ if (conn.getSource().getChannel() >= 0 &&
+ intfRadio.getChannel() >= 0 &&
+ conn.getSource().getChannel() != intfRadio.getChannel()) {
+ continue;
+ }
if (!intfRadio.isInterfered()) {
/*logger.warn("Radio was not interfered");*/
intfRadio.interfereAnyReception();
diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java
index c0f273883..5981d4e80 100644
--- a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java
+++ b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java
@@ -287,6 +287,12 @@ public class UDGM extends AbstractRadioMedium {
conn.getSource().setCurrentSignalStrength(SS_STRONG);
}
for (Radio dstRadio : conn.getDestinations()) {
+ if (conn.getSource().getChannel() >= 0 &&
+ dstRadio.getChannel() >= 0 &&
+ conn.getSource().getChannel() != dstRadio.getChannel()) {
+ continue;
+ }
+
double dist = conn.getSource().getPosition().getDistanceTo(dstRadio.getPosition());
double maxTxDist = TRANSMITTING_RANGE
@@ -303,6 +309,12 @@ public class UDGM extends AbstractRadioMedium {
/* Set signal strength to below weak on interfered */
for (RadioConnection conn : conns) {
for (Radio intfRadio : conn.getInterfered()) {
+ if (conn.getSource().getChannel() >= 0 &&
+ intfRadio.getChannel() >= 0 &&
+ conn.getSource().getChannel() != intfRadio.getChannel()) {
+ continue;
+ }
+
double dist = conn.getSource().getPosition().getDistanceTo(intfRadio.getPosition());
double maxTxDist = TRANSMITTING_RANGE