[Tinyos-devel] Customizing your simulations in TOSSIM

Konrad Iwanicki iwanicki at few.vu.nl
Thu May 7 04:33:14 PDT 2009


Hi all,

For me, it is often the case that I want to extend TOSSIM with custom 
functionality, for example, to interact with the motes and gather 
statistics. To date, I have been doing that by modifying the TOSSIM code 
directly. However, as you can imagine, this is troublesome if several 
people are working on the same application; you have to make sure that, 
in addition to the application code, they also have the same TOSSIM 
code. It is far better if the additional custom simulation code resides 
in the application directory (it is typically application-specific).

Therefore, to solve this problem, I would like propose a 2-line 
modification to the TOSSIM make system, the details of which you can 
find below.

Essentially, the modification introduces variable $(CUSTOMSIMOBJFILE) 
into the TOSSIM make system. If the application Makefile does not define 
this variable, there is no effect. However, if the application Makefile 
makes the variable point to an object file with a custom simulation 
support code, that object file will be linked with the TOSSIM library. 
You can do this, for example, in the following way (this is *NOT* the 
proposed modification to the TOSSIM make system; the modification is 
below the example):

************************************************************
* Example usage of the modification (application Makefile) *
************************************************************

COMPONENT=ApplicationComponentC

# If you do not have your custom code,
# just comment or remove the line below.
CUSTOMSIMOBJFILE = custom-sim-support.o

CLEAN_EXTRA += $(CUSTOMSIMOBJFILE)

include $(MAKERULES)

# Tells the compiler how to create the custom
# object file (optional if you build your custom
# code in a different way).
$(CUSTOMSIMOBJFILE): custom-sim-support.cpp
	@echo "  compiling additional custom code supporting TOSSIM simulations"
	$(GPP) -c $(PLATFORM_CC_FLAGS) $(PLATFORM_FLAGS) -o $@ $(OPTFLAGS) 
$(CFLAGS) $< -I$(PYDIR) -I$(SIMDIR)



***********************************
* Modification to the make system *
***********************************


FILE: sim.extra
---------------

line 65:
sim-exe: builddir $(BUILD_EXTRA_DEPS) FORCE

becomes:
sim-exe: builddir $(BUILD_EXTRA_DEPS) $(CUSTOMSIMOBJFILE) FORCE

line 76 (tab at the beginning):
	$(GPP) $(PLATFORM_BUILD_FLAGS) $(PLATFORM_CC_FLAGS) $(PYOBJFILE) 
$(OBJFILE) $(CXXOBJFILE) $(HASHOBJFILE) $(PLATFORM_LIB_FLAGS) -o 
$(SHARED_OBJECT)

becomes (tab at the beginning):
	$(GPP) $(PLATFORM_BUILD_FLAGS) $(PLATFORM_CC_FLAGS) $(PYOBJFILE) 
$(OBJFILE) $(CXXOBJFILE) $(HASHOBJFILE) $(CUSTOMSIMOBJFILE) 
$(PLATFORM_LIB_FLAGS) -o $(SHARED_OBJECT)


By analogy:

FILE: sim-fast.extra
--------------------

line 58:
sim-exe: builddir $(BUILD_EXTRA_DEPS) FORCE

becomes:
sim-exe: builddir $(BUILD_EXTRA_DEPS) $(CUSTOMSIMOBJFILE) FORCE

line 69 (tab at the beginning):
	$(GPP) $(PLATFORM_BUILD_FLAGS) $(PLATFORM_CC_FLAGS) $(PYOBJFILE) 
$(OBJFILE) $(CXXOBJFILE) $(HASHOBJFILE) $(PLATFORM_LIB_FLAGS) -o 
$(SHARED_OBJECT)

becomes (tab at the beginning):
	$(GPP) $(PLATFORM_BUILD_FLAGS) $(PLATFORM_CC_FLAGS) $(PYOBJFILE) 
$(OBJFILE) $(CXXOBJFILE) $(HASHOBJFILE) $(CUSTOMSIMOBJFILE) 
$(PLATFORM_LIB_FLAGS) -o $(SHARED_OBJECT)


FILE: sim-fast.extra
--------------------

line 104:
sim-exe: builddir $(BUILD_EXTRA_DEPS) FORCE

becomes:
sim-exe: builddir $(BUILD_EXTRA_DEPS) $(CUSTOMSIMOBJFILE) FORCE

line 121 (tab at the beginning):
	$(GPP) $(PLATFORM_BUILD_FLAGS) $(PLATFORM_CC_FLAGS) $(PYOBJFILE) 
$(OBJFILE) $(CXXOBJFILE) $(HASHOBJFILE) $(CSFOBJFILE) $(SFOBJFILE) 
$(THROTTLEOBJFILE)  $(PLATFORM_LIB_FLAGS) $(LIBS) -o $(SHARED_OBJECT)

becomes (tab at the beginning):
	$(GPP) $(PLATFORM_BUILD_FLAGS) $(PLATFORM_CC_FLAGS) $(PYOBJFILE) 
$(OBJFILE) $(CXXOBJFILE) $(HASHOBJFILE) $(CSFOBJFILE) $(SFOBJFILE) 
$(THROTTLEOBJFILE) $(CUSTOMSIMOBJFILE) $(PLATFORM_LIB_FLAGS) $(LIBS) -o 
$(SHARED_OBJECT)



If the modifications seems useful, could somebody check it in to the CVS?

Take care,
--
- Konrad Iwanicki.


More information about the Tinyos-devel mailing list