STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
fake_air.c
Go to the documentation of this file.
1#include "fake_air.h"
2
3static uint32_t g_rx_ms;
4static uint32_t g_sleep_ms;
5
6void fake_air_configure(uint32_t rx_ms, uint32_t sleep_ms) {
7 g_rx_ms = rx_ms;
8 g_sleep_ms = sleep_ms;
9}
10
11bool fake_air_packet_heard(uint32_t cycle_offset_ms, uint32_t preamble_ms) {
12 if (preamble_ms == 0)
13 return false;
14 // A preamble longer than the sleep period must overlap some listen window.
15 if (preamble_ms > g_sleep_ms)
16 return true;
17
18 const uint32_t period = g_rx_ms + g_sleep_ms;
19 // Normalize to [0, period).
20 const uint32_t offset = cycle_offset_ms % period;
21
22 // The preamble occupies [offset, offset + preamble_ms) across one or more
23 // cycle periods. It overlaps the listen window [0, rx_ms) if:
24 // - it starts before the listen window ends (offset < rx_ms), OR
25 // - it wraps past the end of the cycle into the next listen window.
26 if (offset < g_rx_ms)
27 return true;
28 if (offset + preamble_ms > period)
29 return true;
30 return false;
31}
32
33float fake_air_average_current_ma(float rx_ma, float sleep_ua) {
34 const float period = (float)(g_rx_ms + g_sleep_ms);
35 return (rx_ma * (float)g_rx_ms + (sleep_ua / 1000.0f) * (float)g_sleep_ms) /
36 period;
37}
static uint32_t g_rx_ms
Definition fake_air.c:3
float fake_air_average_current_ma(float rx_ma, float sleep_ua)
Definition fake_air.c:33
void fake_air_configure(uint32_t rx_ms, uint32_t sleep_ms)
Definition fake_air.c:6
bool fake_air_packet_heard(uint32_t cycle_offset_ms, uint32_t preamble_ms)
Definition fake_air.c:11
static uint32_t g_sleep_ms
Definition fake_air.c:4