Contiki: How to switch between different RPL objective functions? - contiki

In Contiki 3.0 it was possible to change the RPL objective function by modifying the file Makefile.rpl.
How to do this in Contiki 3.x or Contiki-NG?

You can do this through modifying the compile-time configuration. For example, to switch from the default RPL objective function (MRHOF) to OF0, add these lines to project-conf.h:
#define RPL_CONF_OF_OCP RPL_OCP_OF0 /* tells to use OF0 for DAGs rooted at this node */
#define RPL_CONF_SUPPORTED_OFS {&rpl_of0, &rpl_mrhof} /* tells to compile in support for both OF0 and MRHOF */
You can then verify that you are using the selected objective function with the viewconf tool:
$ make viewconf
...
##### "RPL_CONF_OF_OCP": __________________________ == RPL_OCP_OF0
...

Related

Lua ESP8266 script expecting extra =

I am trying to test a proximity sensor with my ESP8266, however the test code I am using keeps failing.
Whenever I run the code, I get an error: motion sensor.lua:1: '=' expected near 'int'
I should also mention I am using ESPlorer v0.2.0
const int PIRSensorOutPin = 2; //PIR Sensor OUT Pin
void setup() {
Serial.begin(9600);
pinMode(PIRSensorOutPin, INPUT);
}
void loop()
{
if (digitalRead(PIRSensorOutPin) == LOW)
{
Serial.println("Person detected!"); //Print to serial monitor
}
else {;}
}
What am I doing wrong?
The Lua interpreter doesn't understand C++.
You're running NodeMCU firmware which runs Lua files. But you're trying to run Arduino C++ code. That's not going to work. To run this code you would have to add ESP8266 support to your Arduino IDE, compile your code and flash it onto the ESP.
Alternatively write your code in Lua.
https://github.com/esp8266/Arduino
https://www.nodemcu.com/index_en.html
What am I doing wrong?
Using the wrong programming language.
NodeMCU wants to run Lua code and you're giving it C code instead, which just can't work.
How do I fix it? (implied)
You can use the arduino IDE to write C++ code for ESP8266, but since you already seem to have everything set up to run Lua code, I suggest just using that instead.
The C code you provided could be rewritten into Lua using the NodeMCU api like this:
local pin = 2 -- The number of the I/O Pin
local type = "down" -- Trigger on falling edge
-- https://nodemcu.readthedocs.io/en/master/modules/gpio/#gpiotrig
gpio.trig(pin, type, function()
print("Movement detected, proceding to exterminate!")
end)

Flex dropping predefined macro

I have the following flex source:
%{
#if !defined(__linux__) && !defined(__unix__)
/* Maybe on windows */
#endif
int num_chars = 0;
%}
%%
. ++num_chars;
%%
int main()
{
yylex();
printf("%d chars\n", num_chars);
return 0;
}
int yywrap()
{
return 1;
}
I generate a C file by the command flex flextest.l and compile the result with gcc -o fltest lex.yy.c
To my surprise, I get the following output:
flextest.l:2:37: error: operator "defined" requires an identifier
#if !defined(__linux__) && !defined(__unix__)
After further checking, the issue seems to be that flex has actually replaced __unix__ with the empty string, as shown by:
$ grep __linux_ lex.yy.c
#if !defined(__linux__) && !defined()
Why does this happen, and is it possible to avoid it?
It's actually m4 (the macro processor which is used by current versions of flex) which is expanding __unix__ to the empty string. The Gnu implementation of m4 defines certain symbols to empty macros so that they can be tested with ifdef.
Of course, it's (better said, it was) a bug in flex. Flex shouldn't allow m4 to expand macros within user content copied from the scanner definition file, and the current version of flex correctly arranges for the text included from the scanner description file to be quoted so that it will pass through m4 unmodified even if it happens to include a string which could be interpreted by m4 as a macro expansion.
The bug is certainly present in v2.5.39 and v2.6.1 of flex. I didn't test all previous versions, but I suppose it was introduced when flex was modified to use m4, which was v2.5.30 according to the NEWS file.
This particular quoting issue was fixed in v2.6.2 but the current version of flex (2.6.4) contains various other bug fixes, so I'd recommend you upgrade to the latest version.
If you really need a version which could work with both the buggy and the more recent versions of flex, you could use one of the two following hacks:
Find some other way to write __unix__. One possibility is the following
#define C(x,y) x##y
#define UNIX_ C(__un,ix__)
#if !defined(__linux__) && !UNIX_
That hack won't work with defined, since defined(UNIX_) tests whether UNIX_ is defined, not whether what it expands to is defined. But normally built-in symbols like __unix__ are actually defined to be 1, if they are defined, and the #if directive treats any identifier which is not #define'd as though it were 0, which means that you can usually leave use x instead of defined(x). (However, it will produce different results if there were a #define x 0 in effect, so it's not quite a perfect substitute.)
Flex, like many m4 applications, redefines m4's quote marks to be [[ and ]]. Both the buggy flex and the corrected versions substitute these quote marks with a rather elaborate sequence which effectively quotes the quote marks. However, the buggy version does not otherwise quote user-defined text, so macro substitutions will be performed in user text. (As mentioned, this is why __unix__ becomes the empty string.
In flex versions in which user-defined text is not quoted, it is possible to invoke the m4 macro which redefines quote marks. These new quote marks can then be used to quote the #if line, preventing macro substitution of __unix__. However, the quote definition must be restored, or it will completely wreck macro processing of the rest of the file. That's a bit tricky because it is impossible to write [[. (Flex will substitute it with a different string.)
The following seems to do the trick. Note that the macro invocations are placed inside C comments. The changequote macros will expand to an empty string, if they are expanded. But in flex versions since v2.6.2, user-supplied text is quoted, so the changequote macros will not be expanded. Putting them inside comments hides them from the C compiler.
%{
/*m4_changequote(<<,>>)<<*/
#if !defined(__linux__) && !defined(__unix__)
/*>>m4_changequote(<<[>><<[>>,<<]>><<]>>)*/
/* Maybe on windows */
#endif
(The m4 macro which changes quote marks is changequote but flex invokes m4 with the -P flag which changes builtins like changequote to m4_changequote. In the second call to changequote, the two [ which make up the [[ sign are individually quoted with the temporary << quote marks, which hides them from the code in flex which modifies use of [[.)
I don't know how reliable this hack is but it worked on the versions of flex which I had kicking around on my machine, including 2.5.4 (pre-M4) 2.5.39 (buggy), 2.6.1 (buggy), 2.6.2 (somewhat debugged) and 2.6.4 (more debugged).

manipulating leds with contiki program

I would like to know which library should I use to manipulate mote leds.
I tried to use Led Contiki Module but I don't know which header file include.
Is there someone who can help me ?
Look in the platform-conf.h in eg contiki/platform/sky/. There you'll find the definitions you can use, of eg LEDS_RED.
Then, in your application,
#include "leds.h"
...
leds_on(LEDS_RED);
leds_off(LEDS_GREEN);
leds_toggle(LEDS_RED);
leds_off(LEDS_ALL);
You can look in leds-arch.h to see how the implementations sets/get LED state.
e.g. at contiki-2.7/core/dev you can find leds.c and leds.h.
In leds.c are implemented functions for accessing LEDs, e.g. leds_on(...), leds_off(...).
In leds.h are inter alia specified names of LEDs and their number values, e.g. #define LEDS_GREEN 1
To your question: #include "dev/leds.h"

Sqlite 3.7.10 and static linking in Delphi

Latest version of Sqlite (3.7.10) wanted to link __msize function and since Delphi memory manager can not report the size of a memory block, I had to introduce a hack (d5 compatible)
function __msize(p: pointer): Cardinal;cdecl;
begin
Result:=PInteger(integer(p)-4)^-6;
end;
Are there other solutions inside Sqlite (defines?) or Delphi to fix this so no undocumented features are used.
Around line # 15195 in the source code, comment the following lines:
/*
** Windows systems have malloc_usable_size() but it is called _msize()
*/
#if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN
# define HAVE_MALLOC_USABLE_SIZE 1
# define malloc_usable_size _msize
#endif
into
/*
** Windows systems have malloc_usable_size() but it is called _msize()
#if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN
# define HAVE_MALLOC_USABLE_SIZE 1
# define malloc_usable_size _msize
#endif
*/
It will disable the memory reuse of SQLite3 malloc, and will rely on the better FastMM4 reallocmem() implementation.
See this commit e.g. for our Open Source implementation of SQLite3 static linking.
Additional information:
I think that we'd get rid of this issue in 3.7.11, as stated by this commit: a new SQLITE_WITHOUT_MSIZE global symbol will be added, and will be able to build the amalgamation source code without changing its content, just by setting the appropriate SQLITE_WITHOUT_MSIZE define. In the meanwhile, the easiest is to comment the above lines.
You can use SizeOfMem from JCL JclSysUtils unit.

What's the macro to distinguish ifort from other fortran compilers?

I'm working with Fortran code that has to work with various Fortran compilers (and is interacting with both C++ and Java code). Currently, we have it working with gfortran and g95, but I'm researching what it would take to get it working with ifort, and the first problem I'm having is figuring out how to determine in the source code whether it's using ifort or not.
For example, I currently have this piece of code:
#if defined(__GFORTRAN__)
// Macro to add name-mangling bits to fortran symbols. Currently for gfortran only
#define MODFUNCNAME(mod,fname) __ ## mod ## _MOD_ ## fname
#else
// Macro to add name-mangling bits to fortran symbols. Currently for g95 only
#define MODFUNCNAME(mod,fname) mod ## _MP_ ## fname
#endif // if __GFORTRAN__
What's the macro for ifort? I tried IFORT, but that wasn't right, and further guessing doesn't seem productive. I also tried reading the man page, using ifort -help, and Google.
You're after __INTEL_COMPILER, as defined in http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/win/compiler_f/bldaps_for/common/bldaps_use_presym.htm
According to their docs, they define __INTEL_COMPILER=910 . The 910 may be a version number, but you can probably just #ifdef on it.
I should note that ifort doesn't allow macros unless you explicity turn it on with the /fpp flag.

Resources