Reputation: 41
I am trying to test writing in a file in Contiki. here is the code I used :
#include "contiki.h"
#include <stdio.h>
#define LEN 256
PROCESS(test_process, "Coffee test process");
AUTOSTART_PROCESSES(&test_process);
PROCESS_THREAD(test_process, ev, data)
/**/
{
PROCESS_BEGIN();
FILE * fp;
int i;
/* open the file for writing*/
fp = fopen ("/home/user/contiki/examples/mySim/1.txt","w");
/* write 10 lines of text into the file stream*/
for(i = 0; i < 10;i++){
fprintf (fp, "This is line %d\n",i + 1);
}
/* close the file*/
fclose (fp);
PROCESS_END();
}
I get this error message after compiling in Cooja simulator:
test.c: In function ‘process_thread_test_process’: test.c:12:1: error: unknown type name ‘FILE’ test.c:15:4: warning: implicit declaration of function ‘fopen’ [-Wimplicit-function-declaration] test.c:15:7: warning: assignment makes pointer from integer without a cast [enabled by default] test.c:19:8: warning: implicit declaration of function ‘fprintf’ [-Wimplicit-function-declaration] test.c:19:8: warning: incompatible implicit declaration of built-in function ‘fprintf’ [enabled by default] test.c:23:4: warning: implicit declaration of function ‘fclose’ [-Wimplicit-function-declaration] make: *** [test.co] Error 1 Process returned error code 2
does anyone has any idea about the problem?
Upvotes: 1
Views: 432
Reputation: 8537
Contiki does not provide/support the POSIX file API, the same way it does not have many other things (POSIX sockets API, POSIX process creation and control API). Instead, it provides its own filesystem API ("protosockets" API, "protothreads" API etc.).
There are two filesystem implementations: CFS (Contiki File System) and Coffee. You can use the functions described in the Wiki page; they are analogues to low-level POSIX file API (e.g. cfs_open
is similar to POSIX open
, cfs_close
to POSIX close
and so on). There are no analogues for buffered I/O functionality (fopen
, fclose
) and the FILE
structure does not exist.
Upvotes: 3