Reputation: 1
I am trying to compile this code in contiki-3.0:
#include "contiki.h"
#include "net/netstack.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "sys/etimer.h"
#include "sys/ctimer.h"
#include "sys/log.h"
#include "random.h"
#include "net/rpl/rpl.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_INFO
static struct etimer periodic_timer;
static struct ctimer send_timer;
static uint16_t packets_sent = 0;
static uint16_t packets_received = 0;
static uint16_t overhead_packets = 0;
static clock_time_t delay_sum = 0;
static clock_time_t packet_time; // Define packet_time
PROCESS(node_process, "Node Process");
AUTOSTART_PROCESSES(&node_process);
static void send_packet(void *ptr) {
packets_sent++;
LOG_INFO("Sending packet %u\n", packets_sent);
/* Your packet sending logic here */
packet_time = clock_time(); // Set packet_time when sending the packet
// For overhead, simulate control packets being sent periodically
if(random_rand() % 2 == 0) {
overhead_packets++;
}
// Schedule next send
ctimer_reset(&send_timer);
}
static void packet_received(void) {
packets_received++;
clock_time_t delay = clock_time() - packet_time;
delay_sum += delay;
LOG_INFO("Packet received with delay %lu ms\n", (1000 * delay) / CLOCK_SECOND);
}
PROCESS_THREAD(node_process, ev, data)
{
PROCESS_BEGIN();
etimer_set(&periodic_timer, CLOCK_SECOND * 60);
ctimer_set(&send_timer, CLOCK_SECOND * 5, send_packet, NULL);
while(1) {
PROCESS_WAIT_EVENT();
if(etimer_expired(&periodic_timer)) {
// Log metrics
LOG_INFO("PDR: %u%%\n", (100 * packets_received) / packets_sent);
LOG_INFO("Average end-to-end delay: %lu ms\n", (1000 * delay_sum) / packets_received / CLOCK_SECOND);
LOG_INFO("Overhead packets: %u\n", overhead_packets);
// Reset timer
etimer_reset(&periodic_timer);
}
}
PROCESS_END();
}
And I am having an error:
> make my_node.sky TARGET=sky
mkdir obj_sky
CC ../../platform/sky/./contiki-sky-platform.c
CC ../../dev/sht11/sht11.c
../../dev/sht11/sht11.c: In function ‘sht11_init’:
../../dev/sht11/sht11.c:218:4: warning: #warning SHT11: DISABLING I2C BUS [-Wcpp]
CC ../../dev/sht11/sht11-sensor.c
CC ../../platform/sky/dev/light-sensor.c
CC ../../platform/sky/dev/battery-sensor.c
CC ../../platform/sky/dev/button-sensor.c
CC ../../platform/sky/dev/radio-sensor.c
CC ../../cpu/msp430/f1xxx/spi.c
CC ../../dev/ds2411/ds2411.c
CC ../../platform/sky/dev/xmem.c
CC ../../platform/sky/dev/i2c.c
CC ../../platform/sky/./node-id.c
CC ../../core/lib/sensors.c
CC ../../core/cfs/cfs-coffee.c
CC ../../dev/cc2420/cc2420.c
../../dev/cc2420/cc2420.c:528:3: warning: initialization from incompatible pointer type [enabled by default]
../../dev/cc2420/cc2420.c:528:3: warning: (near initialization for ‘cc2420_aes_128_driver.set_key’) [enabled by default]
../../dev/cc2420/cc2420.c: In function ‘cc2420_transmit’:
../../dev/cc2420/cc2420.c:659:24: warning: variable ‘sfd_timestamp’ set but not used [-Wunused-but-set-variable]
CC ../../cpu/msp430/./cc2420-arch.c
CC ../../cpu/msp430/./cc2420-arch-sfd.c
../../cpu/msp430/./cc2420-arch-sfd.c: In function ‘cc2420_timerb1_interrupt’:
../../cpu/msp430/./cc2420-arch-sfd.c:44:7: warning: variable ‘tbiv’ set but not used [-Wunused-but-set-variable]
CC ../../platform/sky/dev/sky-sensors.c
CC ../../cpu/msp430/./uip-ipchksum.c
CC ../../cpu/msp430/f1xxx/uart1.c
CC ../../cpu/msp430/./slip_uart1.c
CC ../../cpu/msp430/dev/uart1-putchar.c
CC ../../core/lib/me.c
CC ../../core/lib/me_tabs.c
CC ../../core/dev/slip.c
CC ../../core/lib/crc16.c
CC ../../cpu/msp430/f1xxx/msp430.c
CC ../../cpu/msp430/./flash.c
CC ../../cpu/msp430/f1xxx/clock.c
CC ../../core/dev/leds.c
CC ../../cpu/msp430/./leds-arch.c
CC ../../cpu/msp430/./watchdog.c
CC ../../cpu/msp430/./lpm.c
CC ../../cpu/msp430/./mtarch.c
CC ../../cpu/msp430/f1xxx/rtimer-arch.c
CC ../../core/loader/elfloader.c
CC ../../core/loader/elfloader-msp430.c
CC ../../core/loader/symtab.c
CC ../../core/net/rpl/rpl-icmp6.c
CC ../../core/net/rpl/rpl-of0.c
CC ../../core/net/rpl/rpl-dag.c
CC ../../core/net/rpl/rpl-timers.c
CC ../../core/net/rpl/rpl-ext-header.c
CC ../../core/net/rpl/rpl.c
CC ../../core/net/rpl/rpl-mrhof.c
CC ../../core/net/rpl/rpl-dag-root.c
CC ../../core/net/ip/slipdev.c
CC ../../core/net/ip/dhcpc.c
CC ../../core/net/ip/uip-packetqueue.c
CC ../../core/net/ip/tcp-socket.c
CC ../../core/net/ip/uip-debug.c
CC ../../core/net/ip/ip64-addr.c
CC ../../core/net/ip/uip-udp-packet.c
CC ../../core/net/ip/psock.c
CC ../../core/net/ip/tcpip.c
CC ../../core/net/ip/resolv.c
CC ../../core/net/ip/uip-nameserver.c
CC ../../core/net/ip/uip-split.c
CC ../../core/net/ip/udp-socket.c
CC ../../core/net/ip/simple-udp.c
CC ../../core/net/ip/uiplib.c
CC ../../core/sys/ctimer.c
CC ../../core/sys/autostart.c
CC ../../core/sys/energest.c
CC ../../core/sys/arg.c
CC ../../core/sys/stimer.c
CC ../../core/sys/etimer.c
CC ../../core/sys/compower.c
CC ../../core/sys/process.c
CC ../../core/sys/rtimer.c
CC ../../core/sys/mt.c
CC ../../core/sys/procinit.c
CC ../../core/sys/timer.c
CC ../../core/dev/serial-line.c
CC ../../core/dev/nullradio.c
CC ../../core/lib/settings.c
CC ../../core/lib/ifft.c
CC ../../core/lib/ringbuf.c
CC ../../core/lib/mmem.c
CC ../../core/lib/ccm-star.c
CC ../../core/lib/list.c
CC ../../core/lib/aes-128.c
CC ../../core/lib/trickle-timer.c
CC ../../core/lib/print-stats.c
CC ../../core/lib/memb.c
CC ../../core/lib/petsciiconv.c
CC ../../core/lib/gcr.c
CC ../../core/lib/assert.c
CC ../../core/lib/random.c
CC ../../core/net/ipv6/uip-icmp6.c
CC ../../core/net/ipv6/uip-ds6.c
CC ../../core/net/ipv6/uip-ds6-route.c
CC ../../core/net/ipv6/uip6.c
CC ../../core/net/ipv6/uip-ds6-nbr.c
CC ../../core/net/ipv6/uip-nd6.c
CC ../../core/net/ipv6/sicslowpan.c
CC ../../core/net/mac/nullmac.c
CC ../../core/net/mac/nullrdc-noframer.c
CC ../../core/net/mac/mac-sequence.c
CC ../../core/net/mac/nullrdc.c
CC ../../core/net/mac/framer-802154.c
CC ../../core/net/mac/frame802154.c
CC ../../core/net/mac/framer-nullmac.c
CC ../../core/net/mac/mac.c
CC ../../core/net/mac/csma.c
CC ../../core/net/mac/phase.c
CC ../../core/net/mac/framer.c
CC ../../core/net/queuebuf.c
CC ../../core/net/nbr-table.c
CC ../../core/net/packetbuf.c
CC ../../core/net/netstack.c
CC ../../core/net/linkaddr.c
CC ../../core/net/mac/contikimac/contikimac.c
CC ../../core/net/mac/contikimac/contikimac-framer.c
CC ../../core/net/mac/cxmac/cxmac.c
CC ../../core/net/llsec/nullsec.c
CC ../../core/net/llsec/anti-replay.c
CC ../../core/net/llsec/ccm-star-packetbuf.c
CC ../../core/net/llsec/noncoresec/noncoresec.c
CC symbols.c
AR contiki-sky.a
CC my_node.c
my_node.c: In function ‘send_packet’:
my_node.c:27:3: warning: implicit declaration of function ‘LOG_INFO’ [-Wimplicit-function-declaration]
my_node.c: At top level:
my_node.c:41:13: warning: ‘packet_received’ defined but not used [-Wunused-function]
CC ../../platform/sky/./contiki-sky-main.c
LD my_node.sky
my_node.co: In function `send_packet':
/home/user/contiki-3.0/examples/my_node/my_node.c:39: undefined reference to `LOG_INFO'
/home/user/contiki-3.0/examples/my_node/my_node.c:39: undefined reference to `LOG_INFO'
/home/user/contiki-3.0/examples/my_node/my_node.c:39: undefined reference to `LOG_INFO'
/home/user/contiki-3.0/examples/my_node/my_node.c:27: undefined reference to `LOG_INFO'
collect2: ld returned 1 exit status
../../Makefile.include:280: recipe for target 'my_node.sky' failed
make: *** [my_node.sky] Error 1
Process returned error code 2
rm my_node.co obj_sky/contiki-sky-main.o
This is the content of my Makefile:
CONTIKI_PROJECT = my_node
all: $(CONTIKI_PROJECT)
CONTIKI = ../..
# Include necessary modules
MODULES += core/net/rpl
MODULES += core/net/ip
# Add these lines to ensure logging is enabled
CFLAGS += -DLOG_CONF_LEVEL_RPL=LOG_LEVEL_INFO
CFLAGS += -DLOG_CONF_LEVEL_TCPIP=LOG_LEVEL_INFO
CFLAGS += -DLOG_CONF_LEVEL_IPV6=LOG_LEVEL_INFO
CFLAGS += -DLOG_CONF_LEVEL_MAC=LOG_LEVEL_INFO
CFLAGS += -DLOG_CONF_LEVEL_FRAMER=LOG_LEVEL_INFO
CFLAGS += -DLOG_CONF_LEVEL_APP=LOG_LEVEL_INFO
include $(CONTIKI)/Makefile.include
And the default Makefile.include of Contiki-3.0:
# -*- makefile -*-
ifndef CONTIKI
${error CONTIKI not defined! You must specify where Contiki resides}
endif
ifeq ($(TARGET),)
-include Makefile.target
ifeq ($(TARGET),)
${info TARGET not defined, using target 'native'}
TARGET=native
else
${info using saved target '$(TARGET)'}
endif
endif
ifeq ($(DEFINES),)
-include Makefile.$(TARGET).defines
ifneq ($(DEFINES),)
${info using saved defines '$(DEFINES)'}
endif
endif
ifndef HOST_OS
ifeq ($(OS),Windows_NT)
## TODO: detect more specific Windows set-ups,
## e.g. CygWin, MingW, VisualC, Watcom, Interix
HOST_OS := Windows
else
HOST_OS := $(shell uname)
endif
endif
#More debug information when running in CI
ifdef CI
ifeq ($(CI),true)
V = 1
endif
endif
usage:
@echo "make MAKETARGETS... [TARGET=(TARGET)] [savetarget] [targets]"
targets:
@ls -1 $(CONTIKI)/platform $(TARGETDIRS) | grep -v CVS
savetarget:
-@rm -f Makefile.target
@echo "saving Makefile.target"
@echo >Makefile.target "TARGET = $(TARGET)"
savedefines:
-@rm -f Makefile.$(TARGET).defines
@echo "saving Makefile.$(TARGET).defines"
@echo >Makefile.$(TARGET).defines "DEFINES = $(DEFINES)"
OBJECTDIR = obj_$(TARGET)
LOWERCASE = -abcdefghijklmnopqrstuvwxyz
UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ
TARGET_UPPERCASE := ${strip ${shell echo $(TARGET) | sed y!$(LOWERCASE)!$(UPPERCASE)!}}
CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1
MODULES += core/sys core/dev core/lib
# Include IPv6, IPv4, and/or Rime
HAS_STACK = 0
ifeq ($(CONTIKI_WITH_IPV4),1)
HAS_STACK = 1
CFLAGS += -DNETSTACK_CONF_WITH_IPV4=1
MODULES += core/net/ipv4 core/net/ip
endif
ifeq ($(CONTIKI_WITH_RIME),1)
HAS_STACK = 1
CFLAGS += -DNETSTACK_CONF_WITH_RIME=1
MODULES += core/net/rime
endif
# Make IPv6 the default stack
ifeq ($(HAS_STACK),0)
ifneq ($(CONTIKI_WITH_IPV6),0)
CONTIKI_WITH_IPV6 = 1
endif
endif
ifeq ($(CONTIKI_WITH_IPV6),1)
CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1
ifneq ($(CONTIKI_WITH_RPL),0)
CONTIKI_WITH_RPL = 1
endif
MODULES += core/net/ipv6 core/net/ip
endif
ifeq ($(CONTIKI_WITH_RPL),1)
CFLAGS += -DUIP_CONF_IPV6_RPL=1
MODULES += core/net/rpl
else
CFLAGS += -DUIP_CONF_IPV6_RPL=0
endif
CONTIKI_SOURCEFILES += $(CONTIKIFILES)
CONTIKIDIRS += ${addprefix $(CONTIKI)/core/,dev lib net net/llsec net/mac net/rime \
net/rpl sys cfs ctk lib/ctk loader . }
oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}}
CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}}
# Provide way to create $(OBJECTDIR) if it has been removed by make clean
$(OBJECTDIR):
mkdir $@
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
### Include application makefiles
ifdef APPS
APPDS = ${wildcard ${foreach DIR, $(APPDIRS), ${addprefix $(DIR)/, $(APPS)}}} \
${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \
${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)} \
$(APPS)}
APPINCLUDES = ${foreach APP, $(APPS), ${wildcard ${foreach DIR, $(APPDS), $(DIR)/Makefile.$(APP)}}}
-include $(APPINCLUDES)
APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)}
DSC_SOURCES = ${foreach APP, $(APPS), $($(APP)_dsc)}
CONTIKI_SOURCEFILES += $(APP_SOURCES) $(DSC_SOURCES)
endif
### Include target makefile (TODO Unsafe?)
target_makefile := $(wildcard $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET) ${foreach TDIR, $(TARGETDIRS), $(TDIR)/$(TARGET)/Makefile.$(TARGET)})
# Check if the target makefile exists, and create the object directory if necessary.
ifeq ($(strip $(target_makefile)),)
${error The target platform "$(TARGET)" does not exist (maybe it was misspelled?)}
else
ifneq (1, ${words $(target_makefile)})
${error More than one TARGET Makefile found: $(target_makefile)}
endif
include $(target_makefile)
endif
ifdef MODULES
UNIQUEMODULES = $(call uniq,$(MODULES))
MODULEDIRS = ${wildcard ${addprefix $(CONTIKI)/, $(UNIQUEMODULES)}}
MODULES_SOURCES = ${foreach d, $(MODULEDIRS), ${subst ${d}/,,${wildcard $(d)/*.c}}}
CONTIKI_SOURCEFILES += $(MODULES_SOURCES)
APPDS += $(MODULEDIRS)
endif
### Verbosity control. Use make V=1 to get verbose builds.
ifeq ($(V),1)
TRACE_CC =
TRACE_LD =
TRACE_AR =
TRACE_AS =
Q=
else
TRACE_CC = @echo " CC " $<
TRACE_LD = @echo " LD " $@
TRACE_AR = @echo " AR " $@
TRACE_AS = @echo " AS " $<
Q=@
endif
### Forward comma-separated list of arbitrary defines to the compiler
COMMA := ,
CFLAGS += ${addprefix -D,${subst $(COMMA), ,$(DEFINES)}}
### Setup directory search path for source and header files
CONTIKI_TARGET_DIRS_CONCAT = ${addprefix ${dir $(target_makefile)}, \
$(CONTIKI_TARGET_DIRS)}
CONTIKI_CPU_DIRS_CONCAT = ${addprefix $(CONTIKI_CPU)/, \
$(CONTIKI_CPU_DIRS)}
SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
$(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDS) ${dir $(target_makefile)}
vpath %.c $(SOURCEDIRS)
vpath %.S $(SOURCEDIRS)
CFLAGS += ${addprefix -I,$(SOURCEDIRS) $(CONTIKI)}
### Check for a git repo and pass version if found
### git.exe in Windows cmd shells may require no stderr redirection
ifndef RELSTR
RELSTR:=${shell git --git-dir ${CONTIKI}/.git describe --tags --always}
endif
ifneq ($(RELSTR),)
CFLAGS += -DCONTIKI_VERSION_STRING=\"Contiki-$(RELSTR)\"
endif
### Automatic dependency generation
ifneq ($(MAKECMDGOALS),clean)
-include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
$(PROJECT_SOURCEFILES:.c=.d)}
endif
### See http://make.paulandlesley.org/autodep.html#advanced
define FINALIZE_DEPENDENCY
cp $(@:.o=.d) $(@:.o=.$$$$); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \
rm -f $(@:.o=.$$$$)
endef
clean:
-rm -f *~ *core core *.srec \
*.lst *.map \
*.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \
*.ce *.co
rm -rf $(CLEAN)
-rm -rf $(OBJECTDIR)
distclean: clean
-rm -f ${addsuffix .$(TARGET),$(CONTIKI_PROJECT)}
-include $(CONTIKI)/platform/$(TARGET)/Makefile.customrules-$(TARGET)
ifndef CUSTOM_RULE_C_TO_CE
%.ce: %.c
$(TRACE_CC)
$(Q)$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
$(STRIP) --strip-unneeded -g -x $@
endif
ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
$(TRACE_CC)
$(Q)$(CC) $(CFLAGS) -MMD -c $< -o $@
@$(FINALIZE_DEPENDENCY)
endif
ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.S | $(OBJECTDIR)
$(TRACE_AS)
$(Q)$(AS) $(ASFLAGS) -o $@ $<
endif
ifndef CUSTOM_RULE_C_TO_O
%.o: %.c
$(TRACE_CC)
$(Q)$(CC) $(CFLAGS) -c $< -o $@
endif
ifndef CUSTOM_RULE_C_TO_CO
%.co: %.c
$(TRACE_CC)
$(Q)$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
endif
ifndef AROPTS
AROPTS = rcf
endif
ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
contiki-$(TARGET).a: $(CONTIKI_OBJECTFILES)
$(TRACE_AR)
$(Q)$(AR) $(AROPTS) $@ $^
endif
ifndef LD
LD = $(CC)
endif
ifndef CUSTOM_RULE_LINK
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
$(TRACE_LD)
$(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} \
${filter %.a,$^} $(TARGET_LIBFILES) -o $@
endif
%.ramprof: %.$(TARGET)
$(NM) -S -td --size-sort $< | grep -i " [abdrw] " | cut -d' ' -f2,4
%.flashprof: %.$(TARGET)
$(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4
# Don't treat %.$(TARGET) as an intermediate file because it is
# in fact the primary target.
.PRECIOUS: %.$(TARGET)
# Cancel the predefined implict rule for compiling and linking
# a single C source into a binary to force GNU make to consider
# the match-anything rule below instead.
%: %.c
# Match-anything pattern rule to allow the project makefiles to
# abstract from the actual binary name. It needs to contain some
# command in order to be a rule, not just a prerequisite.
%: %.$(TARGET)
@
Please help me to resolve the issue.
I am trying to get to compile the code on a mote in Cooja. The code will be responsible for collecting data: impact of packet delivery ratio, impact of average end to end delay and impact of overhead packets.
Upvotes: 0
Views: 128
Reputation: 1
I believe you are using Contiki-NG logging methods for a Contiki-OS implementation. We can use the LOG_ method family (LOG_INFO()
, LOG_ERR()
, etc.) as a base feature supported by Contiki-NG. You can check out the Contiki-NG Logging System Docs for more info. I believe that this support was only added in the transition between Contiki 3.0 to NG because 3.0 source code lacks the logging functions in its core/sys
.
The simplest method used for printing messages in the Mote Output window in Contiki 3.0's Cooja is the classic printf()
. Contiki 3.0 also dabbled with Logging methods with core/net/ip/uip-debug.h
, although it is normally just used for printing messages containing IPv6 and Link Layer addresses. You can know more details and see an example of this in the UDP IPv6 example as it uses uip-debug logging methods.
Just a reminder, you have to correctly include and define the methods you want to use:
For printf:
#include <stdio.h>
For uIP print messages (MODE
can be DEBUG_NONE
, DEBUG_PRINT
, DEBUG_ANNOTATE
or DEBUG_FULL
depending on your needs):
#define DEBUG MODE
#include "net/ip/uip-debug.h"
Upvotes: 0