Revision 1128
Added library for wireless
logger.c | ||
---|---|---|
3 | 3 |
#include <stdio.h> |
4 | 4 |
|
5 | 5 |
|
6 |
int setLogFile(char *name)
|
|
6 |
int setWriteFile(char *name, char* worldName)
|
|
7 | 7 |
{ |
8 |
file = fopen(name, "a+"); |
|
8 |
file = fopen(name, "w"); |
|
9 |
|
|
9 | 10 |
if(file == 0) |
10 | 11 |
return -1; |
11 | 12 |
|
13 |
int size = strlen(worldName) + 1; |
|
14 |
if(fwrite(&size, sizeof(int), 1, file) < 1) |
|
15 |
{ |
|
16 |
fprintf(stderr, "Logging Error\n"); |
|
17 |
return -1; |
|
18 |
} |
|
19 |
|
|
20 |
if(fwrite(worldName, strlen(worldName) + 1, 1, file) < 1) |
|
21 |
{ |
|
22 |
fprintf(stderr, "Logging Error\n"); |
|
23 |
return -1; |
|
24 |
} |
|
25 |
|
|
12 | 26 |
return 0; |
13 | 27 |
} |
14 | 28 |
|
29 |
int setReadFile(char *name, char **worldName) |
|
30 |
{ |
|
31 |
file = fopen(name, "r"); |
|
32 |
if(file == 0) |
|
33 |
return -1; |
|
34 |
|
|
35 |
int size; |
|
36 |
if(fread(&size, sizeof(int), 1, file) < 1) |
|
37 |
{ |
|
38 |
fprintf(stderr, "Logging Error\n"); |
|
39 |
return -1; |
|
40 |
} |
|
41 |
|
|
42 |
*worldName = malloc(size); |
|
43 |
|
|
44 |
if(fread(*worldName, size, 1, file) < 1) |
|
45 |
{ |
|
46 |
fprintf(stderr, "Logging Error\n"); |
|
47 |
return -1; |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
51 |
|
|
15 | 52 |
void commit(Robot* robot, int index, int timeStep) |
16 | 53 |
{ |
17 | 54 |
if(!file) |
Also available in: Unified diff