-
Notifications
You must be signed in to change notification settings - Fork 1
/
rwc_nst_test_cTest_rxTest.cpp
124 lines (104 loc) · 3.08 KB
/
rwc_nst_test_cTest_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
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
122
123
/*
Module: rwc_nst_test_cTest_rxTest.cpp
Function:
cTest::rxTest() implementation
Copyright notice and License:
See LICENSE file accompanying this project.
Author:
Terry Moore, MCCI Corporation 2019
*/
#include "rwc_nst_test_cTest.h"
#include "rwc_nst_test.h"
// receive test driver
bool cTest::rxTest(
bool fEntry
)
{
if (fEntry)
{
this->m_fStopTest = false;
this->m_Rx.Timeout = ms2osticks(this->m_params.RxTimeout);
this->m_Rx.fContinuous = this->m_Rx.Timeout == 0;
this->m_Rx.fTimedOut = false;
this->m_Rx.Count = 0;
this->m_Rx.fReceiving = false;
this->m_RxDigOut.setOutput(this->m_params.RxDigOut, true);
gCatena.SafePrintf("Start RX test: capturing raw downlink ");
if (m_Rx.fContinuous)
gCatena.SafePrintf("until canceled by `count` command");
else
gCatena.SafePrintf("for %u milliseconds", this->m_params.RxTimeout);
if (this->m_RxDigOut.isEnabled())
{
gCatena.SafePrintf(" pulsing digital I/O %d", this->m_params.RxDigOut);
}
gCatena.SafePrintf(
".\n"
"At RWC5020, select NST>Signal Generator, then Run.\n"
);
// setup LMIC and print settings
this->setupLMIC(this->m_params);
// if there's a timeout, start it.
if (! m_Rx.fContinuous)
{
// when a timeout happens, this function is called.
auto const timeoutFn = [](osjob_t *job)
{
os_radio(RADIO_RST);
delay(1);
os_clearCallback(&LMIC.osjob);
gTest.m_Rx.fTimedOut = true;
};
os_setTimedCallback(
&m_Rx.TimeoutJob,
os_getTime() + this->m_Rx.Timeout,
timeoutFn
);
}
}
// now, evaluate state
os_runloop_once();
if (this->m_fStopTest)
{
this->rxTestStop();
gCatena.SafePrintf(
"\nRX test stopped: received messages: %u.\n",
this->m_Rx.Count
);
return true;
}
else if (this->m_Rx.fTimedOut)
{
this->rxTestStop();
gCatena.SafePrintf(
"\nRX test complete: received messages: %u.\n",
this->m_Rx.Count
);
return true;
}
else
{
if (! this->m_Rx.fReceiving)
{
// set the coallback processor.
LMIC.osjob.func = [](osjob_t *job)
{
if (LMIC.dataLen > 0)
++gTest.m_Rx.Count;
gCatena.SafePrintf(".");
gTest.m_Rx.fReceiving = false;
gTest.m_fsm.eval();
};
LMIC.rxtime = os_getTime();
this->m_Rx.fReceiving = true;
os_radio(RADIO_RXON);
}
return false;
}
}
void cTest::rxTestStop()
{
os_radio(RADIO_RST);
os_clearCallback(&LMIC.osjob);
os_clearCallback(&this->m_Rx.TimeoutJob);
}