-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrxtest.cpp
68 lines (62 loc) · 1.74 KB
/
rxtest.cpp
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
// Simple example that just sits there and prints every packet it receives
#include <cstdio>
#include <miosix.h>
#include "drivers/cc2520.h"
#include "drivers/timer.h"
#include "drivers/leds.h"
#include "flopsync_v3/protocol_constants.h"
int main()
{
lowPowerSetup();
led1::mode(miosix::Mode::OUTPUT);
#ifdef USE_VHT
Timer& timer=VHT::instance();
#else //USE_VHT
Timer& timer=Rtc::instance();
#endif //USE_VHT
Cc2520& transceiver=Cc2520::instance();
transceiver.setFrequency(2450);
transceiver.setMode(Cc2520::RX);
transceiver.setAutoFCS(true);
bool first=true;
int last=0;
int total=0;
int successful=0;
for(;;)
{
if(transceiver.isRxFrameDone()==1)
{
led1::high();
unsigned char frame[127];
unsigned char length=sizeof(frame);
transceiver.readFrame(length,frame);
printf("Received packet with RSSI=%ddBm\n",transceiver.getRssi());
miosix::memDump(frame,length);
if(length==120)
{
bool error=false;
for(int j=2;j<length;j++) if(frame[j]!=j) error=true;
int i=static_cast<int>(frame[0])<<8 | frame[1];
if(error==false && i>last)
{
if(first)
{
first=false;
last=i;
} else {
total+=i-last;
last=i;
successful++;
}
printf("correct packet with sequence %d received\n",i);
} else printf("packet content is not correct\n");
} else printf("length=%d is not correct\n",length);
if(total>0)
printf("received %d out of %d packets reception rate %5.1f%%\n",
successful,total,
static_cast<float>(successful)/static_cast<float>(total)*100);
puts("");
led1::low();
} else miosix::Thread::sleep(10);
}
}