Project

General

Profile

Statistics
| Revision:

root / branches / simulator / projects / simulator / simulator / core / logger.c @ 1068

History | View | Annotate | Download (890 Bytes)

1 1068 ayeager
#include "logger.h"
2
#include "robot.h"
3
#include <stdio.h>
4
5
6
int setLogFile(char *name)
7
{
8
        file = fopen(name, "a+");
9
        if(file == 0)
10
                return -1;
11
12
        return 0;
13
}
14
15
void commit(Robot* robot, int index, int timeStep)
16
{
17
        if(!file)
18
        {
19
                return;
20
        }
21
        if(fwrite(&timeStep, sizeof(int), 1, file) < 1)
22
        {
23
                printf("Logging Error\n");
24
                return;
25
        }
26
        if(fwrite(&index, sizeof(int), 1, file) < 1)
27
        {
28
                printf("Logging Error\n");
29
                return;
30
        }
31
        if(fwrite(robot, sizeof(Robot), 1, file) < 1)
32
        {
33
                printf("Logging Error\n");
34
                return;
35
        }
36
}
37
38
int getStep()
39
{
40
        int toReturn;
41
42
        if(!file)
43
        {
44
                return 0;
45
        }
46
47
        if(fread(&toReturn, sizeof(int), 1, file) < 1)
48
        {
49
                printf("Logging Error\n");
50
                return -1;
51
        }
52
        return toReturn;
53
}
54
55
int getLog(Robot* robot)
56
{
57
        if(!file)
58
        {
59
                return 0;
60
        }
61
        if(fread(robot, sizeof(Robot), 1, file) < 1)
62
        {
63
                printf("Logging Error\n");
64
                return -1;
65
        }
66
        return 0;
67
}