34 #include "lib/simEnvChange.h"
37 #define FLAG_FILE_CLOSED 0
38 #define FLAG_FILE_OPEN 1
47 static struct filestate file;
49 const struct simInterface cfs_interface;
52 #define CFS_BUF_SIZE 4000
53 char simCFSData[CFS_BUF_SIZE] = { 0 };
54 char simCFSChanged = 0;
56 int simCFSWritten = 0;
62 if(file.flag == FLAG_FILE_CLOSED) {
63 file.flag = FLAG_FILE_OPEN;
66 file.fileptr = file.endptr;
79 file.flag = FLAG_FILE_CLOSED;
83 cfs_read(
int f,
void *buf,
unsigned int len)
85 if(file.flag == FLAG_FILE_OPEN && file.access &
CFS_READ) {
86 if(file.fileptr + len >= file.endptr) {
87 len = file.endptr - file.fileptr;
89 memcpy(buf, &simCFSData[file.fileptr], len);
100 cfs_write(
int f,
const void *buf,
unsigned int len)
102 if(file.flag == FLAG_FILE_OPEN && file.access &
CFS_WRITE) {
103 if(file.fileptr + len > CFS_BUF_SIZE) {
104 len = CFS_BUF_SIZE - file.fileptr;
105 printf(
"cfs-cooja.c: warning: write truncated\n");
107 memcpy(&simCFSData[file.fileptr], buf, len);
110 simCFSWritten += len;
111 if(file.fileptr > file.endptr) {
112 file.endptr = file.fileptr;
123 if(file.flag == FLAG_FILE_OPEN) {
129 file.fileptr = file.endptr + o;
131 if(file.fileptr >= 0 && file.fileptr <= CFS_BUF_SIZE) {
132 if(file.fileptr > file.endptr) {
133 file.endptr = file.fileptr;
144 memset(simCFSData, 0,
sizeof(simCFSData));
166 doInterfaceActionsBeforeTick(
void)
171 doInterfaceActionsAfterTick(
void)
175 SIM_INTERFACE(cfs_interface,
176 doInterfaceActionsBeforeTick,
177 doInterfaceActionsAfterTick);