-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo_root.cpp
More file actions
112 lines (102 loc) · 4.4 KB
/
demo_root.cpp
File metadata and controls
112 lines (102 loc) · 4.4 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
/***************************************************************************
* Copyright (C) 2015 by Terraneo Federico *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or use *
* macros or inline functions from this file, or you compile this file *
* and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with the GNU General *
* Public License. This exception does not invalidate any other reasons *
* why a work based on this file might be covered by the GNU General *
* Public License. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <iostream>
#include "drivers/cc2520.h"
#include "drivers/timer.h"
#include "drivers/frame.h"
#include "drivers/leds.h"
#include "flopsync_v3/protocol_constants.h"
#include "flopsync_v3/flooder_root_node.h"
#include "flopsync_v3/synchronizer.h"
#include "board_setup.h"
#include "demo.h"
using namespace std;
void readSensor(Timer& timer, Cc2520& transceiver, unsigned long long& when, int node)
{
static int missed[numNodes]={0};
bool alreadyPrinted=false;
for(int i=0;i<sendCount;i++)
{
DemoPacket packet;
bool success=getPacketAt(timer,transceiver,&packet,sizeof(packet),
validateByNodeId[node],when,sendFrequencies[i]);
if(!success) missed[node]++;
when+=spacing;
if(!success || alreadyPrinted) continue;
unsigned long long timestamp=timer.getValue();
cout<<packet.nodeId<<' '
<<timestamp<<' '
<<decodeTemperature(packet.thermocoupleTemperature)<<' '
<<missed[node]<<' '
<<packet.flopsyncError<<' '
<<packet.flopsyncMissCount<<endl;
alreadyPrinted=true;
}
if(!alreadyPrinted)
{
unsigned long long timestamp=timer.getValue();
cout<<nodeIds[node]<<' '
<<timestamp<<' '
<<"NoPacketFromSensor "
<<missed[node]<<endl;
}
}
void readAllSensors(Timer& timer, Cc2520& transceiver, unsigned long long when)
{
when+=spacing; //First time used for sensing, next used for sending
for(int i=0;i<numNodes;i++)
readSensor(timer,transceiver,when,i);
cout<<"end"<<endl;
}
int main()
{
lowPowerSetup();
puts(experimentName);
//HIPEAC+EWSN demo stuff -- begin
// miosix::currentSense::enable::high();
// initAdc();
//HIPEAC+EWSN demo stuff -- end
Cc2520& transceiver=Cc2520::instance();
transceiver.setTxPower(Cc2520::P_5);
#ifndef USE_VHT
Timer& timer=Rtc::instance();
#else //USE_VHT
Timer& timer=VHT::instance();
#endif //USE_VHT
FlooderRootNode flooder(timer);
bool removeMe=false;
for(;;)
{
transceiver.setFrequency(2450);
removeMe^=1;
if(removeMe) miosix::ledOn(); else miosix::ledOff();
flooder.synchronize();
unsigned long long start=flooder.getMeasuredFrameStart();
for(unsigned long long t=start+initialDelay;t<start+nominalPeriod;t+=dataPeriod)
readAllSensors(timer,transceiver,t);
}
}