d4d5bb6d
henyxia
Bus working
|
1
2
3
4
5
6
7
8
9
10
11
|
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include "printx.h"
#include "ui.h"
#include "nfc.h"
|
ac0ae6b0
henyxia
HVC can now use t...
|
12
|
#include "hvc.h"
|
d4d5bb6d
henyxia
Bus working
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#define CMD_MAX 70
int bus;
bool busFree = true;
bool busStop = false;
void stopBus()
{
busStop = true;
}
void processCmd(char* buffer)
{
buffer[strlen(buffer)-1]='\0';
if(strcmp(buffer, "quit") == 0 || strcmp(buffer, "exit") == 0)
{
printx(INFO, BUS, "Exit request receved, processing ...\n");
stopNFC();
|
ac0ae6b0
henyxia
HVC can now use t...
|
32
|
stopHVC();
|
d4d5bb6d
henyxia
Bus working
|
33
34
35
|
stopBus();
stopUI();
}
|
ac0ae6b0
henyxia
HVC can now use t...
|
36
37
|
else if(strcmp(buffer, "setpumpon") == 0)
{
|
846585f9
henyxia
Fixed some printx
|
38
|
printx(INFO, BUS, "Setting PUMP ON\n");
|
ac0ae6b0
henyxia
HVC can now use t...
|
39
40
41
42
|
setPumpWantedState(true);
}
else if(strcmp(buffer, "setpumpoff") == 0)
{
|
846585f9
henyxia
Fixed some printx
|
43
|
printx(INFO, BUS, "Setting PUMP OFF\n");
|
ac0ae6b0
henyxia
HVC can now use t...
|
44
45
46
47
|
setPumpWantedState(false);
}
else if(strcmp(buffer, "setheaton") == 0)
{
|
846585f9
henyxia
Fixed some printx
|
48
|
printx(INFO, BUS, "Setting HEAT ON\n");
|
ac0ae6b0
henyxia
HVC can now use t...
|
49
50
51
52
|
setHeatWantedState(true);
}
else if(strcmp(buffer, "setheatoff") == 0)
{
|
846585f9
henyxia
Fixed some printx
|
53
|
printx(INFO, BUS, "Setting HEAT OFF\n");
|
ac0ae6b0
henyxia
HVC can now use t...
|
54
55
|
setHeatWantedState(false);
}
|
5dd66ab0
henyxia
Added timer optio...
|
56
57
|
else if(strcmp(buffer, "setheaton5s") == 0)
{
|
846585f9
henyxia
Fixed some printx
|
58
|
printx(INFO, BUS, "Setting HEAT ON for 5 secs\n");
|
5dd66ab0
henyxia
Added timer optio...
|
59
60
61
62
63
|
setHeatTimer(5);
setHeatWantedState(true);
}
else if(strcmp(buffer, "setpumpon5s") == 0)
{
|
846585f9
henyxia
Fixed some printx
|
64
|
printx(INFO, BUS, "Setting PUMP ON for 5 secs\n");
|
5dd66ab0
henyxia
Added timer optio...
|
65
66
67
|
setPumpTimer(5);
setPumpWantedState(true);
}
|
846585f9
henyxia
Fixed some printx
|
68
69
70
71
72
73
|
else if(strcmp(buffer, "setheaton35s") == 0)
{
printx(INFO, BUS, "Setting HEAT ON for 35 secs\n");
setHeatTimer(35);
setHeatWantedState(true);
}
|
ac0ae6b0
henyxia
HVC can now use t...
|
74
75
|
//printx(DEBUG, BUS, "STRLEN : %d and strcmp ret %d", strlen(buffer), strcmp(buffer, "quit"));
|
d4d5bb6d
henyxia
Bus working
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
}
void* processBus(void* we)
{
bus = open("bus.log", O_RDWR);
char buffer[CMD_MAX];
printx(DEBUG, BUS, "Waiting for events\n");
while(!busStop)
{
while(busFree);
while(!busFree);
printx(DEBUG, BUS, "Event receved !\n");
busFree = false;
lseek(bus, 0, SEEK_SET);
|
846585f9
henyxia
Fixed some printx
|
90
91
|
read(bus, buffer, CMD_MAX);
//printx(DEBUG, BUS, "Data read %d\n", read(bus, buffer, CMD_MAX));
|
d4d5bb6d
henyxia
Bus working
|
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
ftruncate(bus, 0);
sync();
processCmd(buffer);
busFree = true;
printx(DEBUG, BUS, buffer);
}
return NULL;
}
bool initBus()
{
bus = creat("bus.log", 0666);
if(bus == -1)
{
printf("Unable to open the bus file\n");
return false;
}
return true;
}
void sendToBus(char* cmd)
{
while(!busFree);
busFree = false;
ftruncate(bus, 0);
ftruncate(bus, CMD_MAX);
lseek(bus, 0, SEEK_SET);
dprintf(bus, "%s\n", cmd);
busFree = true;
}
|