DUREX-Prog.c
1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "DUREX.h"
#include "Hal.h"
DUREX_numBytes_t numBytes = 0;
DUREX_data_t data = "";
DUREX_numPackets_t numPackets = 0;
DUREX_messageAvailable_t messageAvailable = 0;
uint8_t lastMessageAck = 1;
void main() {
Hal_init();
DUREX_start();
Hal_idleLoop();
}
/* -------- SCHEMA CALLBACKS -------- */
void processMessage()
{
if(!strcmp(data,"Hello"))
{
memcpy(data,"Hello",6);
numBytes = 6;
numPackets = 1;
}
}
void DUREX_connectHandler(void)
{
Hal_connected();
}
void DUREX_disconnectHandler(void)
{
Hal_disconnected();
}
void DUREX_numBytes_fetch(DUREX_numBytes_t* const output)
{
*output = numBytes;
}
void DUREX_numBytes_store(DUREX_numBytes_t* const input)
{
numBytes = *input;
}
void DUREX_data_fetch(DUREX_data_t output)
{
memcpy(output,data,numBytes);
}
void DUREX_data_store(DUREX_data_t input)
{
memcpy(data,input,numBytes);
}
void DUREX_numPackets_fetch(DUREX_numPackets_t* const output)
{
*output = numPackets;
}
void DUREX_numPackets_store(DUREX_numPackets_t* const input)
{
numPackets = *input;
}
void DUREX_messageAvailable_fetch(DUREX_messageAvailable_t* const output)
{
*output = messageAvailable;
}
void DUREX_messageAvailable_store(DUREX_messageAvailable_t* const input)
{
messageAvailable = *input;
if(messageAvailable == DUREX_TRUE)
{
led1_on();
lastMessageAck = 0;
messageAvailable = DUREX_FALSE;
DUREX_messageAvailable_indicate();
processMessage();
messageAvailable = DUREX_TRUE;
DUREX_messageAvailable_indicate();
}
else if(messageAvailable == DUREX_FALSE)
{
led1_off();
lastMessageAck = 1;
}
}