-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodebackup.txt
More file actions
121 lines (87 loc) · 3.02 KB
/
Nodebackup.txt
File metadata and controls
121 lines (87 loc) · 3.02 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
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
/*
* ANDES Lab - University of California, Merced
This class provides the basic functions of a network node.
*
* @author UCM ANDES Lab
* @date 2013/09/03
*Adam Pluguez CSE160 Project2 Updated 2/21/19
*/
#include <Timer.h>
#include "includes/command.h"
#include "includes/packet.h"
#include "includes/CommandMsg.h"
#include "includes/sendInfo.h"
#include "includes/channels.h"
#include "includes/moteN.h"
module Node{
uses interface Boot;
uses interface SplitControl as AMControl;
uses interface Receive;
uses interface SimpleSend as Sender;
uses interface CommandHandler;
uses interface NeighborDiscovery;
uses interface Flooding;
uses interface Routing;
}
implementation{
uint8_t sequence = 0;
pack sendPackage;
// Prototypes
void makePack(pack *Package, uint16_t src, uint16_t dest, uint16_t TTL, uint16_t Protocol, uint16_t seq, uint8_t *payload, uint8_t length);
bool checkSentList(pack *Package);
event void Boot.booted(){
call AMControl.start();
dbg(GENERAL_CHANNEL, "Booted\n");
call NeighborDiscovery.run();
}
event void AMControl.startDone(error_t err){
if(err == SUCCESS){
dbg(GENERAL_CHANNEL, "Radio On\n");
//call NeighborDiscovery.run();
//call Routing.createTable();
}else{
//Retry until successful
call AMControl.start();
}
}
event void AMControl.stopDone(error_t err){}
event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){
dbg(GENERAL_CHANNEL, "Packet Received\n");
if(len==sizeof(pack)){
pack* myMsg=(pack*) payload;
dbg(GENERAL_CHANNEL, "Package Payload %s\n", myMsg->payload);
return msg;
}
dbg(GENERAL_CHANNEL, "Unknown Packet Type %d\n", len);
return msg;
}
event void CommandHandler.ping(uint16_t destination, uint8_t *payload){
dbg(GENERAL_CHANNEL, "PING EVENT \n");
makePack(&sendPackage, TOS_NODE_ID, destination, 20, PROTOCOL_PING, ++sequence, payload, PACKET_MAX_PAYLOAD_SIZE);
call Sender.send(sendPackage, destination);
//call Flooding.floodSend(sendPackage, destination);
}
event void CommandHandler.printNeighbors(){
call NeighborDiscovery.printNeighbors();
}
event void CommandHandler.printRouteTable(){
//call Routing.printRouteTable();
call Routing.printLinkState();
}
event void CommandHandler.printLinkState(){
call Routing.printLinkState();
}
event void CommandHandler.printDistanceVector(){}
event void CommandHandler.setTestServer(){}
event void CommandHandler.setTestClient(){}
event void CommandHandler.setAppServer(){}
event void CommandHandler.setAppClient(){}
void makePack(pack *Package, uint16_t src, uint16_t dest, uint16_t TTL, uint16_t protocol, uint16_t seq, uint8_t* payload, uint8_t length){
Package->src = src;
Package->dest = dest;
Package->TTL = TTL;
Package->seq = seq;
Package->protocol = protocol;
memcpy(Package->payload, payload, length);
}
}