forked from nanovna-v2/NanoVNA2-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cpp
71 lines (64 loc) · 1.46 KB
/
common.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
#include "common.hpp"
#include <string.h>
#define TRUE true
#define FALSE false
// NanoVNA Default settings
static const trace_t def_trace[TRACES_MAX] = {//enable, type, channel, reserved, scale, refpos
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
{ 1, TRC_LOGMAG, 1, 0, 1.0, 7.0 },
{ 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
{ 1, TRC_PHASE, 0, 0, 1.0, 4.0 }
};
static const marker_t def_markers[MARKERS_MAX] = {
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
};
void properties_t::setFieldsToDefault() {
magic = CONFIG_MAGIC;
_frequency0 = 100000000; // start = 100MHz
_frequency1 = 900000000; // end = 900MHz
_sweep_points = 101;
_cal_status = 0;
_electrical_delay = 0.0;
_velocity_factor = 0.7;
_active_marker = 0;
_domain_mode = 0;
_marker_smith_format = MS_RLC;
memset(_cal_data, 0, sizeof(_cal_data));
memcpy(_trace, def_trace, sizeof(_trace));
memcpy(_markers, def_markers, sizeof(_markers));
}
float my_atof(const char *p)
{
int neg = FALSE;
if (*p == '-')
neg = TRUE;
if (*p == '-' || *p == '+')
p++;
float x = atoi(p);
while (isdigit((int)*p))
p++;
if (*p == '.') {
float d = 1.0f;
p++;
while (isdigit((int)*p)) {
d /= 10;
x += d * (*p - '0');
p++;
}
}
if (*p == 'e' || *p == 'E') {
p++;
int exp = atoi(p);
while (exp > 0) {
x *= 10;
exp--;
}
while (exp < 0) {
x /= 10;
exp++;
}
}
if (neg)
x = -x;
return x;
}