forked from UCMAndesLab/CSE160-Project-Skeleton-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.nc
More file actions
95 lines (75 loc) · 2.61 KB
/
Node.nc
File metadata and controls
95 lines (75 loc) · 2.61 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
/*
* ANDES Lab - University of California, Merced
* This class provides the basic functions of a network node.
*
* @author UCM ANDES Lab
* @date 2013/09/03
*
*/
#include <Timer.h>
#include "includes/command.h"
#include "includes/packet.h"
#include "includes/CommandMsg.h"
#include "includes/sendInfo.h"
#include "includes/channels.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; //Added
}
implementation{
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);
event void Boot.booted(){
call AMControl.start();
call NeighborDiscovery.start();
dbg(GENERAL_CHANNEL, "Booted\n");
}
event void AMControl.startDone(error_t err){
if(err == SUCCESS){
dbg(GENERAL_CHANNEL, "Radio On\n");
}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, 0, 0, 0, payload, PACKET_MAX_PAYLOAD_SIZE);
call Sender.send(sendPackage, destination);
}
event void CommandHandler.printNeighbors(){
dbg(GENERAL_CHANNEL, "Printing Neighbors...");
call NeighborDiscovery.print();
}
event void CommandHandler.printRouteTable(){}
event void CommandHandler.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);
}
}