-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendAckC.nc
120 lines (98 loc) · 3.26 KB
/
sendAckC.nc
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
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
/**
* Source file for implementation of module sendAckC in which
* the node 1 send a request to node 2 until it receives a response.
* The reply message contains a reading from the Fake Sensor.
*
* @author Luca Pietro Borsani
*/
#include "sendAck.h"
#include "Timer.h"
module sendAckC {
uses {
/****** INTERFACES *****/
interface Boot;
//interfaces for communication
//interface for timer
//other interfaces, if needed
//interface used to perform sensor reading (to get the value from a sensor)
interface Read<uint16_t>;
}
} implementation {
uint8_t counter=0;
uint8_t rec_id;
message_t packet;
void sendReq();
void sendResp();
//***************** Send request function ********************//
void sendReq() {
/* This function is called when we want to send a request
*
* STEPS:
* 1. Prepare the msg
* 2. Set the ACK flag for the message using the PacketAcknowledgements interface
* (read the docs)
* 3. Send an UNICAST message to the correct node
* X. Use debug statements showing what's happening (i.e. message fields)
*/
}
//****************** Task send response *****************//
void sendResp() {
/* This function is called when we receive the REQ message.
* Nothing to do here.
* `call Read.read()` reads from the fake sensor.
* When the reading is done it raise the event read one.
*/
call Read.read();
}
//***************** Boot interface ********************//
event void Boot.booted() {
dbg("boot","Application booted.\n");
/* Fill it ... */
}
//***************** SplitControl interface ********************//
event void SplitControl.startDone(error_t err){
/* Fill it ... */
}
event void SplitControl.stopDone(error_t err){
/* Fill it ... */
}
//***************** MilliTimer interface ********************//
event void MilliTimer.fired() {
/* This event is triggered every time the timer fires.
* When the timer fires, we send a request
* Fill this part...
*/
}
//********************* AMSend interface ****************//
event void AMSend.sendDone(message_t* buf,error_t err) {
/* This event is triggered when a message is sent
*
* STEPS:
* 1. Check if the packet is sent
* 2. Check if the ACK is received (read the docs)
* 2a. If yes, stop the timer. The program is done
* 2b. Otherwise, send again the request
* X. Use debug statements showing what's happening (i.e. message fields)
*/
}
//***************************** Receive interface *****************//
event message_t* Receive.receive(message_t* buf,void* payload, uint8_t len) {
/* This event is triggered when a message is received
*
* STEPS:
* 1. Read the content of the message
* 2. Check if the type is request (REQ)
* 3. If a request is received, send the response
* X. Use debug statements showing what's happening (i.e. message fields)
*/
}
//************************* Read interface **********************//
event void Read.readDone(error_t result, uint16_t data) {
/* This event is triggered when the fake sensor finish to read (after a Read.read())
*
* STEPS:
* 1. Prepare the response (RESP)
* 2. Send back (with a unicast message) the response
* X. Use debug statement showing what's happening (i.e. message fields)
*/
}