Add battery status to form and freq_t

master
erikkaashoek 5 years ago
parent 224a96df63
commit 7c7fd57b16

@ -329,12 +329,12 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
else
state|=DEFAULT_PRESCISION;
//Get [length]
/*
if (c == 'l' || c == 'L') {
state|=IS_LONG;
// state|=IS_LONG; // Ignore Long
if (*fmt)
c = *fmt++;
}
/*
else if ((c >= 'A') && (c <= 'Z'))
state|=IS_LONG;
*/

@ -36,10 +36,10 @@
#include <string.h>
#include <math.h>
extern uint32_t minFreq;
extern uint32_t maxFreq;
uint32_t frequencyStart;
uint32_t frequencyStop;
extern freq_t minFreq;
extern freq_t maxFreq;
freq_t frequencyStart;
freq_t frequencyStop;
int32_t frequencyExtra;
#define START_MIN minFreq
#define STOP_MAX maxFreq
@ -92,7 +92,7 @@ static void apply_edelay_at(int i);
static void cal_interpolate(int s);
#endif
void update_frequencies(void);
static void set_frequencies(uint32_t start, uint32_t stop, uint16_t points);
static void set_frequencies(freq_t start, freq_t stop, uint16_t points);
static bool sweep(bool break_on_operation);
#ifdef __VNA__
static void transform_domain(void);
@ -357,6 +357,7 @@ VNA_SHELL_FUNCTION(cmd_pause)
(void)argc;
(void)argv;
pause_sweep();
draw_cal_status();
}
VNA_SHELL_FUNCTION(cmd_resume)
@ -424,7 +425,7 @@ adjust_gain(uint32_t newfreq)
}
#endif
int set_frequency(uint32_t freq)
int set_frequency(freq_t freq)
{
(void) freq;
#ifdef __VNA__
@ -590,7 +591,7 @@ VNA_SHELL_FUNCTION(cmd_freq)
if (argc != 1) {
goto usage;
}
uint32_t freq = my_atoui(argv[0]);
freq_t freq = my_atoui(argv[0]);
pause_sweep();
set_frequency(freq);
@ -1030,7 +1031,7 @@ void set_sweep_points(uint16_t points){
VNA_SHELL_FUNCTION(cmd_scan)
{
uint32_t start, stop;
freq_t start, stop;
uint32_t points = sweep_points;
uint32_t i;
if (argc < 2 || argc > 4) {
@ -1081,9 +1082,9 @@ update_marker_index(void)
for (m = 0; m < MARKERS_MAX; m++) {
if (!markers[m].enabled)
continue;
uint32_t f = markers[m].frequency;
uint32_t fstart = get_sweep_frequency(ST_START);
uint32_t fstop = get_sweep_frequency(ST_STOP);
freq_t f = markers[m].frequency;
freq_t fstart = get_sweep_frequency(ST_START);
freq_t fstop = get_sweep_frequency(ST_STOP);
if (f < fstart) {
markers[m].index = 0;
markers[m].frequency = fstart;
@ -1102,13 +1103,13 @@ update_marker_index(void)
}
}
void set_marker_frequency(int m, uint32_t f)
void set_marker_frequency(int m, freq_t f)
{
if (m < 0 || !markers[m].enabled)
return;
int i = 1;
markers[m].mtype &= ~M_TRACKING;
uint32_t s = (frequencies[1] - frequencies[0])/2;
freq_t s = (frequencies[1] - frequencies[0])/2;
while (i< sweep_points - 2){
if (frequencies[i]-s <= f && f < frequencies[i+1]-s) { // Avoid rounding error in s!!!!!!!
markers[m].index = i;
@ -1120,14 +1121,14 @@ void set_marker_frequency(int m, uint32_t f)
}
static void
set_frequencies(uint32_t start, uint32_t stop, uint16_t points)
set_frequencies(freq_t start, freq_t stop, uint16_t points)
{
uint32_t i;
uint32_t step = (points - 1);
uint32_t span = stop - start;
uint32_t delta = span / step;
uint32_t error = span % step;
uint32_t f = start, df = step>>1;
freq_t step = (points - 1);
freq_t span = stop - start;
freq_t delta = span / step;
freq_t error = span % step;
freq_t f = start, df = step>>1;
for (i = 0; i <= step; i++, f+=delta) {
frequencies[i] = f;
df+=error;
@ -1146,7 +1147,7 @@ set_frequencies(uint32_t start, uint32_t stop, uint16_t points)
void
update_frequencies(void)
{
uint32_t start, stop;
freq_t start, stop;
start = get_sweep_frequency(ST_START);
stop = get_sweep_frequency(ST_STOP);
@ -1160,7 +1161,7 @@ update_frequencies(void)
}
void
set_sweep_frequency(int type, uint32_t freq)
set_sweep_frequency(int type, freq_t freq)
{
#ifdef __VNA__
int cal_applied = cal_status & CALSTAT_APPLY;
@ -1196,9 +1197,9 @@ set_sweep_frequency(int type, uint32_t freq)
break;
case ST_CENTER:
setting.freq_mode |= FREQ_MODE_CENTER_SPAN;
uint32_t center = setting.frequency0 / 2 + setting.frequency1 / 2;
freq_t center = setting.frequency0 / 2 + setting.frequency1 / 2;
if (center != freq) {
uint32_t span = setting.frequency1 - setting.frequency0;
freq_t span = setting.frequency1 - setting.frequency0;
if (freq < START_MIN + span / 2) {
span = (freq - START_MIN) * 2;
}
@ -1212,7 +1213,7 @@ set_sweep_frequency(int type, uint32_t freq)
case ST_SPAN:
setting.freq_mode |= FREQ_MODE_CENTER_SPAN;
if (setting.frequency1 - setting.frequency0 != freq) {
uint32_t center = setting.frequency0 / 2 + setting.frequency1 / 2;
freq_t center = setting.frequency0 / 2 + setting.frequency1 / 2;
if (center < START_MIN + freq / 2) {
center = START_MIN + freq / 2;
}
@ -1239,12 +1240,12 @@ set_sweep_frequency(int type, uint32_t freq)
#endif
}
uint32_t
freq_t
get_sweep_frequency(int type)
{
// Obsolete, ensure correct start/stop, start always must be < stop
if (setting.frequency0 > setting.frequency1) {
uint32_t t = setting.frequency0;
freq_t t = setting.frequency0;
setting.frequency0 = setting.frequency1;
setting.frequency1 = t;
}
@ -1266,9 +1267,9 @@ VNA_SHELL_FUNCTION(cmd_sweep)
} else if (argc > 3) {
goto usage;
}
uint32_t value0 = 0;
uint32_t value1 = 0;
uint32_t value2 = 0;
freq_t value0 = 0;
freq_t value1 = 0;
freq_t value2 = 0;
if (argc >= 1) value0 = my_atoui(argv[0]);
if (argc >= 2) value1 = my_atoui(argv[1]);
if (argc >= 3) value2 = my_atoui(argv[2]);
@ -1965,7 +1966,7 @@ VNA_SHELL_FUNCTION(cmd_marker)
default:
// select active marker and move to index or frequency
markers[t].enabled = TRUE;
uint32_t value = my_atoui(argv[1]);
freq_t value = my_atoui(argv[1]);
markers[t].mtype &= ~M_TRACKING;
active_marker = t;
if (value > sweep_points)
@ -2889,12 +2890,12 @@ int main(void)
redraw_frame();
#ifdef TINYSA3
set_mode(M_HIGH);
set_sweep_frequency(ST_STOP, (uint32_t) 30000000);
set_sweep_frequency(ST_STOP, (freq_t) 30000000);
sweep(false);
osalThreadSleepMilliseconds(100);
set_mode(M_LOW);
set_sweep_frequency(ST_STOP, (uint32_t) 4000000);
set_sweep_frequency(ST_STOP, (freq_t) 4000000);
sweep(false);
#endif

@ -84,6 +84,7 @@
#define actual_t measured[TRACE_ACTUAL]
#define temp_t measured[TRACE_TEMP]
typedef uint32_t freq_t;
#define CORRECTION_POINTS 10 // Frequency dependent level correction table entries
typedef float measurement_t[TRACES_MAX][POINTS_COUNT];
@ -154,13 +155,13 @@ enum stimulus_type {
void set_sweep_points(uint16_t points);
void update_frequencies(void);
void set_sweep_frequency(int type, uint32_t frequency);
uint32_t get_sweep_frequency(int type);
void set_sweep_frequency(int type, freq_t frequency);
freq_t get_sweep_frequency(int type);
void my_microsecond_delay(int t);
float my_atof(const char *p);
int shell_printf(const char *fmt, ...);
void set_marker_frequency(int m, uint32_t f);
void set_marker_frequency(int m, freq_t f);
void toggle_sweep(void);
void toggle_mute(void);
void load_default_properties(void);
@ -203,8 +204,8 @@ extern const char *info_about[];
extern const char * const unit_string[];
extern uint8_t signal_is_AM;
extern const int reffer_freq[];
extern uint32_t minFreq;
extern uint32_t maxFreq;
extern freq_t minFreq;
extern freq_t maxFreq;
int level_is_calibrated(void);
void reset_settings(int);
void update_min_max_freq(void);
@ -271,7 +272,7 @@ void set_attack(int);
void set_noise(int);
void toggle_tracking_output(void);
extern int32_t frequencyExtra;
void set_10mhz(uint32_t);
void set_10mhz(freq_t);
void set_modulation(int);
void set_modulation_frequency(int);
int search_maximum(int m, int center, int span);
@ -504,29 +505,29 @@ typedef struct config {
int16_t touch_cal[4];
uint32_t _serial_speed;
#ifdef __VNA__
uint32_t harmonic_freq_threshold;
freq_t harmonic_freq_threshold;
#endif
uint16_t dac_value;
uint16_t vbat_offset;
float low_level_offset;
float high_level_offset;
uint32_t correction_frequency[CORRECTION_POINTS];
freq_t correction_frequency[CORRECTION_POINTS];
float correction_value[CORRECTION_POINTS];
uint32_t deviceid;
uint32_t setting_frequency_10mhz;
freq_t setting_frequency_10mhz;
uint16_t gridlines;
uint16_t hambands;
#ifdef TINYSA4
uint32_t frequency_IF2;
freq_t frequency_IF2;
#endif
int8_t _mode;
int8_t cor_am;
int8_t cor_wfm;
int8_t cor_nfm;
int8_t dummy;
uint32_t dummy;
// uint8_t _reserved[22];
uint32_t checksum;
freq_t checksum;
} config_t;
extern config_t config;
@ -575,7 +576,7 @@ typedef struct {
int8_t enabled;
int8_t mtype;
int16_t index;
uint32_t frequency;
freq_t frequency;
} marker_t;
#define MARKERS_MAX 4
@ -746,8 +747,8 @@ void show_version(void);
typedef struct setting
{
uint32_t magic;
// uint32_t _frequency0;
// uint32_t _frequency1;
// freq_t _frequency0;
// freq_t _frequency1;
int mode;
uint16_t _sweep_points;
int16_t attenuate_x2;
@ -768,7 +769,7 @@ typedef struct setting
int tracking;
int modulation;
int step_delay;
uint32_t frequency_step;
freq_t frequency_step;
int test;
int harmonic;
int decay;
@ -777,9 +778,9 @@ typedef struct setting
uint32_t vbw_x10;
int tracking_output;
int repeat;
uint32_t frequency0;
uint32_t frequency1;
uint32_t frequency_IF;
freq_t frequency0;
freq_t frequency1;
freq_t frequency_IF;
int freq_mode;
int measurement;
int refer;
@ -840,7 +841,7 @@ enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL };
#define REPEAT_TIME 111 // Time per extra repeat in uS
#define MEASURE_TIME 127 // Time per single point measurement with vbwstep =1 without step delay in uS
extern uint32_t frequencies[POINTS_COUNT];
extern freq_t frequencies[POINTS_COUNT];
extern const float unit_scale_value[];
extern const char * const unit_scale_text[];
@ -880,17 +881,17 @@ extern const char * const unit_scale_text[];
typedef struct properties {
uint32_t magic;
preset_t setting;
// uint32_t _frequency0;
// uint32_t _frequency1;
// freq_t _frequency0;
// freq_t _frequency1;
uint16_t _sweep_points;
#ifdef __VNA__
uint16_t _cal_status;
#endif
#ifdef __SA__
// uint32_t _frequency_IF; //IF frequency
// freq_t _frequency_IF; //IF frequency
#endif
// uint32_t _frequencies[POINTS_COUNT];
// freq_t _frequencies[POINTS_COUNT];
#ifdef __VNA__
float _cal_data[5][POINTS_COUNT][2];
float _electrical_delay; // picoseconds
@ -1107,7 +1108,7 @@ void wait_user(void);
void calibrate(void);
float to_dBm(float);
uint32_t calc_min_sweep_time_us(void);
pureRSSI_t perform(bool b, int i, uint32_t f, int e);
pureRSSI_t perform(bool b, int i, freq_t f, int e);
void interpolate_maximum(int m);
enum {

@ -42,7 +42,7 @@ void cell_draw_test_info(int x0, int y0);
static int16_t grid_offset;
static int16_t grid_width;
static int32_t grid_span;
static freq_t grid_span;
int16_t area_width = AREA_WIDTH_NORMAL;
int16_t area_height; // initialized in main() = AREA_HEIGHT_NORMAL;
@ -119,10 +119,10 @@ float2int(float v)
void update_grid(void)
{
uint32_t gdigit = 100000000;
uint32_t fstart = get_sweep_frequency(ST_START);
uint32_t fspan = get_sweep_frequency(ST_SPAN);
uint32_t grid;
freq_t gdigit = 100000000;
freq_t fstart = get_sweep_frequency(ST_START);
freq_t fspan = get_sweep_frequency(ST_SPAN);
freq_t grid;
if (fspan == 0) {
fspan = setting.actual_sweep_time_us; // Time in uS
@ -412,8 +412,8 @@ rectangular_grid(int x, int y)
#ifdef __HAM_BAND__
typedef const struct {
uint32_t start;
uint32_t stop;
freq_t start;
freq_t stop;
} ham_bands_t;
const ham_bands_t ham_bands[] =
@ -439,9 +439,9 @@ int ham_band(int x) // Search which index in the frequency tabled matches w
{
if (!config.hambands)
return false;
uint32_t f = frequencies[x];
freq_t f = frequencies[x];
int L = 0;
int R = (sizeof ham_bands)/sizeof(uint32_t) - 1;
int R = (sizeof ham_bands)/sizeof(freq_t) - 1;
while (L <= R) {
int m = (L + R) / 2;
if (ham_bands[m].stop < f)
@ -909,14 +909,14 @@ void trace_get_value_string( // Only used at one place
int t, char *buf, int len,
int i, float coeff[POINTS_COUNT],
int ri, int mtype,
uint32_t i_freq, uint32_t ref_freq)
freq_t i_freq, freq_t ref_freq)
{
(void) t;
float v;
char buf2[16];
char buf3[8];
char *ptr2 = buf2;
uint32_t dfreq = 0;
freq_t dfreq = 0;
float rlevel = 0;
int ii = i;
int unit_index = setting.unit;
@ -961,7 +961,7 @@ void trace_get_value_string( // Only used at one place
#endif
} else {
#if 0
uint32_t resolution = get_sweep_frequency(ST_SPAN);
freq_t resolution = get_sweep_frequency(ST_SPAN);
if (resolution <= 2000*POINTS_COUNT)
plot_printf(ptr2, sizeof(buf2) - 2, "%3.3f" , (dfreq + 500) / 1000000.0);
else if (resolution <= 20000*POINTS_COUNT)
@ -1957,10 +1957,10 @@ cell_draw_marker_info(int x0, int y0)
cell_drawstring(buf, xpos, ypos);
xpos += 13;
//trace_get_info(t, buf, sizeof buf);
uint32_t freq = frequencies[markers[mk].index];
freq_t freq = frequencies[markers[mk].index];
if (uistat.marker_delta && mk != active_marker) {
uint32_t freq1 = frequencies[markers[active_marker].index];
uint32_t delta = freq > freq1 ? freq - freq1 : freq1 - freq;
freq_t freq1 = frequencies[markers[active_marker].index];
freq_t delta = freq > freq1 ? freq - freq1 : freq1 - freq;
plot_printf(buf, sizeof buf, S_DELTA"%.9qHz", delta);
} else {
plot_printf(buf, sizeof buf, "%.10qHz", freq);
@ -1987,9 +1987,9 @@ cell_draw_marker_info(int x0, int y0)
cell_drawstring(buf, xpos, ypos);
xpos += 27;
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
uint32_t freq = frequencies[idx];
uint32_t freq1 = frequencies[idx0];
uint32_t delta = freq > freq1 ? freq - freq1 : freq1 - freq;
freq_t freq = frequencies[idx];
freq_t freq1 = frequencies[idx0];
freq_t delta = freq > freq1 ? freq - freq1 : freq1 - freq;
plot_printf(buf, sizeof buf, "%c%.13qHz", freq >= freq1 ? '+' : '-', delta);
} else {
plot_printf(buf, sizeof buf, "%Fs (%Fm)", time_of_index(idx) - time_of_index(idx0), distance_of_index(idx) - distance_of_index(idx0));
@ -2100,7 +2100,7 @@ static void cell_draw_marker_info(int x0, int y0)
for (int i = 0; i < MARKER_COUNT; i++) {
if (i == 3) {
if (setting.measurement == M_PASS_BAND) {
uint32_t f;
freq_t f;
if (markers[2].frequency>markers[1].frequency)
f = markers[2].frequency-markers[1].frequency;
else
@ -2141,7 +2141,7 @@ static void cell_draw_marker_info(int x0, int y0)
setting.unit = U_WATT;
float p = index_to_value(markers[0].index);
int h_i = 2;
uint32_t f = markers[0].frequency;
freq_t f = markers[0].frequency;
float h = 0.0;
while (f * h_i < frequencies[sweep_points-1]) {
if (search_maximum(1, f*h_i, 4*h_i) ) // use marker 1 for searching harmonics

@ -272,8 +272,8 @@ VNA_SHELL_FUNCTION(cmd_if)
shell_printf("usage: if {433M..435M}\r\n");
return;
} else {
uint32_t a = (uint32_t)my_atoi(argv[0]);
if (a!= 0 &&( a < (DEFAULT_IF - (uint32_t)2000000) || a>(DEFAULT_IF + (uint32_t)2000000)))
freq_t a = (freq_t)my_atoi(argv[0]);
if (a!= 0 &&( a < (DEFAULT_IF - (freq_t)2000000) || a>(DEFAULT_IF + (freq_t)2000000)))
goto usage;
setting.auto_IF = false;
set_IF(a);
@ -449,7 +449,7 @@ return; // Don't use!!!!
VNA_SHELL_FUNCTION(cmd_o)
{
(void) argc;
uint32_t value = my_atoi(argv[0]);
freq_t value = my_atoi(argv[0]);
if (VFO == 0)
setting.frequency_IF = value;
set_freq(VFO, value);
@ -489,7 +489,7 @@ VNA_SHELL_FUNCTION(cmd_a)
shell_printf("a=%u\r\n", frequencyStart);
return;
}
uint32_t value = my_atoui(argv[0]);
freq_t value = my_atoui(argv[0]);
frequencyStart = value;
}
@ -501,7 +501,7 @@ VNA_SHELL_FUNCTION(cmd_b)
shell_printf("b=%u\r\n", frequencyStop);
return;
}
uint32_t value = my_atoui(argv[0]);
freq_t value = my_atoui(argv[0]);
frequencyStop = value;
}
@ -542,11 +542,11 @@ void sweep_remote(void)
{
uint32_t i;
uint32_t step = (points - 1);
uint32_t span = frequencyStop - frequencyStart;
uint32_t delta = span / step;
uint32_t error = span % step;
uint32_t f = frequencyStart - setting.frequency_IF, df = step>>1;
uint32_t old_step = setting.frequency_step;
freq_t span = frequencyStop - frequencyStart;
freq_t delta = span / step;
freq_t error = span % step;
freq_t f = frequencyStart - setting.frequency_IF, df = step>>1;
freq_t old_step = setting.frequency_step;
setting.frequency_step = delta;
streamPut(shell_stream, '{');
dirty = true;
@ -638,7 +638,7 @@ VNA_SHELL_FUNCTION(cmd_correction)
return;
}
int i = my_atoi(argv[0]);
uint32_t f = my_atoui(argv[1]);
freq_t f = my_atoui(argv[1]);
float v = my_atof(argv[2]);
config.correction_frequency[i] = f;
config.correction_value[i] = v;
@ -648,7 +648,7 @@ VNA_SHELL_FUNCTION(cmd_correction)
VNA_SHELL_FUNCTION(cmd_scanraw)
{
uint32_t start, stop;
freq_t start, stop;
uint32_t points = sweep_points;
if (argc < 2 || argc > 3) {
shell_printf("usage: scanraw {start(Hz)} {stop(Hz)} [points]\r\n");
@ -668,12 +668,13 @@ VNA_SHELL_FUNCTION(cmd_scanraw)
// if (get_waterfall())
// disable_waterfall(); // display dma hangs when waterfall is enabled
uint32_t old_step = setting.frequency_step;
freq_t old_step = setting.frequency_step;
float f_step = (stop-start)/ points;
setting.frequency_step = (uint32_t)f_step;
setting.frequency_step = (freq_t)f_step;
streamPut(shell_stream, '{');
static uint32_t old_start=0, old_stop=0, old_points=0;
static freq_t old_start=0, old_stop=0;
static uint32_t old_points=0;
if (old_start != start || old_stop != stop || old_points != points) { // To prevent dirty for every sweep
dirty = true;
old_start = start;
@ -684,7 +685,7 @@ VNA_SHELL_FUNCTION(cmd_scanraw)
dirty = true;
for (uint32_t i = 0; i<points; i++) {
int val = perform(false, i, start +(uint32_t)(f_step * i), false) + float_TO_PURE_RSSI(EXT_ZERO_LEVEL);
int val = perform(false, i, start +(freq_t)(f_step * i), false) + float_TO_PURE_RSSI(EXT_ZERO_LEVEL);
if (operation_requested) // break on operation in perform
break;
streamPut(shell_stream, 'x');
@ -693,6 +694,7 @@ VNA_SHELL_FUNCTION(cmd_scanraw)
}
streamPut(shell_stream, '}');
setting.frequency_step = old_step;
dirty = true;
redraw_request = 0; // disable screen update in this mode
}

@ -34,13 +34,15 @@
int scandirty = true;
setting_t setting;
uint32_t frequencies[POINTS_COUNT];
freq_t frequencies[POINTS_COUNT];
uint16_t actual_rbw_x10 = 0;
uint16_t vbwSteps = 1;
uint32_t minFreq = 0;
uint32_t maxFreq = 520000000;
freq_t minFreq = 0;
freq_t maxFreq = 520000000;
static freq_t old_freq[4] = { 0, 0, 0, 0};
static freq_t real_old_freq[4] = { 0, 0, 0, 0};
//int setting.refer = -1; // Off by default
const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000};
@ -183,16 +185,11 @@ void reset_settings(int m)
}
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers[0].enabled = M_ENABLED;
setting._active_marker = 0;
set_sweep_points(POINTS_COUNT);
dirty = true;
}
//static uint32_t extra_vbw_step_time = 0;
//static uint32_t etra_repeat_time = 0;
//static uint32_t minimum_zero_span_sweep_time = 0;
//static uint32_t minimum_sweep_time = 0;
uint32_t calc_min_sweep_time_us(void) // Estimate minimum sweep time in uS, needed to calculate the initial delays for the RSSI before first sweep
{
uint32_t t;
@ -266,7 +263,7 @@ void set_gridlines(int d)
//int setting_frequency_10mhz = 10000000;
void set_10mhz(uint32_t f)
void set_10mhz(freq_t f)
{
if (f < 9000000 || f > 11000000)
return;
@ -379,7 +376,7 @@ void set_modulation(int m)
void set_modulation_frequency(int f)
{
if (100 <= f && f <= 6000) {
if (50 <= f && f <= 6000) {
setting.modulation_frequency = f;
dirty = true;
}
@ -683,7 +680,7 @@ void set_harmonic(int h)
{
setting.harmonic = h;
minFreq = 684000000.0;
if ((uint32_t)(setting.harmonic * 240000000)+434000000 > minFreq)
if ((freq_t)(setting.harmonic * 240000000)+434000000 > minFreq)
minFreq = setting.harmonic * 240000000.0+434000000.0;
maxFreq = 4360000000;
if (setting.harmonic != 0 && (960000000.0 * setting.harmonic + 434000000.0 )< 4360000000.0)
@ -1051,7 +1048,7 @@ void apply_settings(void) // Ensure all settings in the setting structure
#if 0
#define CORRECTION_POINTS 10
static const uint32_t correction_frequency[CORRECTION_POINTS] =
static const freq_t correction_frequency[CORRECTION_POINTS] =
{ 100000, 200000, 400000, 1000000, 2000000, 50000000, 100000000, 200000000, 300000000, 350000000 };
static const float correction_value[CORRECTION_POINTS] =
@ -1083,7 +1080,7 @@ void calculate_correction(void)
#pragma GCC push_options
#pragma GCC optimize ("Og") // "Os" causes problem
pureRSSI_t get_frequency_correction(uint32_t f) // Frequency dependent RSSI correction to compensate for imperfect LPF
pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI correction to compensate for imperfect LPF
{
if (!(setting.mode == M_LOW || setting.mode == M_GENLOW))
return(0.0);
@ -1096,7 +1093,7 @@ pureRSSI_t get_frequency_correction(uint32_t f) // Frequency dependent RSSI
return(scaled_correction_value[0] >> (SCALE_FACTOR - 5) );
f = f - config.correction_frequency[i-1];
#if 0
uint32_t m = (config.correction_frequency[i] - config.correction_frequency[i-1]) >> SCALE_FACTOR ;
freq_t m = (config.correction_frequency[i] - config.correction_frequency[i-1]) >> SCALE_FACTOR ;
float multi = (config.correction_value[i] - config.correction_value[i-1]) * (1 << (SCALE_FACTOR -1)) / (float)m;
float cv = config.correction_value[i-1] + ((f >> SCALE_FACTOR) * multi) / (float)(1 << (SCALE_FACTOR -1)) ;
#else
@ -1111,18 +1108,12 @@ pureRSSI_t get_frequency_correction(uint32_t f) // Frequency dependent RSSI
float peakLevel;
float min_level;
uint32_t peakFreq;
freq_t peakFreq;
int peakIndex;
float temppeakLevel;
int temppeakIndex;
static unsigned long old_freq[4] = { 0, 0, 0, 0};
static unsigned long real_old_freq[4] = { 0, 0, 0, 0};
// volatile int t;
//static uint32_t extra_vbw_step_time = 0;
//static uint32_t etra_repeat_time = 0;
//static uint32_t minimum_zero_span_sweep_time = 0;
//static uint32_t minimum_sweep_time = 0;
// volatile int t;
void setupSA(void)
{
@ -1184,9 +1175,9 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency
if (delta > OFFSET_LOWER_BOUND && delta < 79999) { // and requested frequency can be reached by using the offset registers
#if 0
if (real_old_freq[V] >= 480000000)
shell_printf("%d: Offs %q HW %d\r\n", SI4432_Sel, (uint32_t)(real_old_freq[V]+delta*2), real_old_freq[V]);
shell_printf("%d: Offs %q HW %d\r\n", SI4432_Sel, (freq_t)(real_old_freq[V]+delta*2), real_old_freq[V]);
else
shell_printf("%d: Offs %q HW %d\r\n", SI4432_Sel, (uint32_t)(real_old_freq[V]+delta*1), real_old_freq[V]);
shell_printf("%d: Offs %q HW %d\r\n", SI4432_Sel, (freq_t)(real_old_freq[V]+delta*1), real_old_freq[V]);
#endif
delta = delta * 4 / 625; // = 156.25; // Calculate and set the offset register i.s.o programming a new frequency
SI4432_Write_2_Byte(SI4432_FREQ_OFFSET1, (uint8_t)(delta & 0xff), (uint8_t)((delta >> 8) & 0x03));
@ -1195,7 +1186,7 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency
old_freq[V] = freq;
} else {
#ifdef __WIDE_OFFSET__
uint32_t target_f; // Impossible to use offset so set SI4432 to new frequency
freq_t target_f; // Impossible to use offset so set SI4432 to new frequency
if (freq < real_old_freq[V]) { // sweeping down
if (freq - 80000 >= 480000000) {
target_f = freq - 160000;
@ -1360,7 +1351,7 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (#
} else {
setting.vbw_x10 = 3000; // trick to get right default rbw in zero span mode
}
uint32_t temp_actual_rbw_x10 = setting.rbw_x10; // requested rbw , 32 bit !!!!!!
freq_t temp_actual_rbw_x10 = setting.rbw_x10; // requested rbw , 32 bit !!!!!!
if (temp_actual_rbw_x10 == 0) { // if auto rbw
if (setting.step_delay_mode==SD_FAST) { // if in fast scanning
if (setting.fast_speedup > 2)
@ -1618,7 +1609,7 @@ static void calculate_static_correction(void) // Calculate the
- setting.offset);
}
pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
{
int modulation_delay = 0;
int modulation_index = 0;
@ -1737,8 +1728,8 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking)
modulation_delay += config.cor_nfm; // -17 default
// modulation_index = 0; // default value
}
if ((setting.mode == M_GENLOW && f > ((uint32_t)480000000) - DEFAULT_IF) ||
(setting.mode == M_GENHIGH && f > ((uint32_t)480000000) ) )
if ((setting.mode == M_GENLOW && f > ((freq_t)480000000) - DEFAULT_IF) ||
(setting.mode == M_GENHIGH && f > ((freq_t)480000000) ) )
modulation_index += 2;
current_fm_modulation = (int *)fm_modulation[modulation_index];
f -= fm_modulation_offset[modulation_index]; // Shift output frequency
@ -1780,7 +1771,7 @@ modulation_again:
#endif
int t = 0;
do {
uint32_t lf = f;
freq_t lf = f;
if (vbwSteps > 1) { // Calculate sub steps
int offs_div10 = (t - (vbwSteps >> 1)) * 500 / 10; // steps of half the rbw
if ((vbwSteps & 1) == 0) // Uneven steps, center
@ -1796,7 +1787,7 @@ modulation_again:
if (/* MODE_INPUT(setting.mode) && */ i > 0 && FREQ_IS_CW()) // In input mode in zero span mode after first setting of the LO's
goto skip_LO_setting; // No more LO changes required, save some time and jump over the code
uint32_t local_IF;
freq_t local_IF;
spur_second_pass = false;
again: // Spur reduction jumps to here for second measurement
@ -1881,7 +1872,7 @@ modulation_again:
} else
#endif
{ // Else set LO ('s)
uint32_t target_f;
freq_t target_f;
if (setting.mode == M_LOW && !setting.tracking && S_STATE(setting.below_IF)) // if in low input mode and below IF
target_f = local_IF-lf; // set LO SI4432 to below IF frequency
else
@ -2119,7 +2110,7 @@ sweep_again: // stay in sweep loop when output mo
}
if (RSSI < AGC_RSSI_THRESHOLD)
agc_prev_rssi = -150;
uint32_t delta_freq = frequencies[i] - agc_peak_freq;
freq_t delta_freq = frequencies[i] - agc_peak_freq;
if (agc_peak_freq != 0 && delta_freq < 2000000) {
int max_gain = (-25 - agc_peak_rssi ) / 4;
auto_set_AGC_LNA(false, 16 + delta_freq * max_gain / 2000000 ); // enable LNA and stepwise gain
@ -2511,7 +2502,7 @@ sweep_again: // stay in sweep loop when output mo
#if 0
float v = actual_t[markers[m].index] - 10.0; // -10dB points
int index = markers[m].index;
uint32_t f = markers[m].frequency;
freq_t f = markers[m].frequency;
uint32_t s = actual_rbw_x10 * 200; // twice the selected RBW
int left = index, right = index;
while (t > 0 && actual_t[t+1] > v && markers[t].frequency > f - s) // Find left point
@ -2562,8 +2553,8 @@ sweep_again: // stay in sweep loop when output mo
markers[0].index = l;
markers[1].index = r;
}
uint32_t lf = frequencies[l];
uint32_t rf = frequencies[r];
freq_t lf = frequencies[l];
freq_t rf = frequencies[r];
markers[0].frequency = lf;
markers[1].frequency = rf;
@ -3203,8 +3194,8 @@ common_silent:
}
trace[TRACE_STORED].enabled = true;
set_reflevel(test_case[i].pass+10);
set_sweep_frequency(ST_CENTER, (uint32_t)(test_case[i].center * 1000000));
set_sweep_frequency(ST_SPAN, (uint32_t)(test_case[i].span * 1000000));
set_sweep_frequency(ST_CENTER, (freq_t)(test_case[i].center * 1000000));
set_sweep_frequency(ST_SPAN, (freq_t)(test_case[i].span * 1000000));
draw_cal_status();
}
@ -3299,7 +3290,7 @@ void self_test(int test)
setting.frequency_step = 30000;
if (setting.test_argument > 0)
setting.frequency_step=setting.test_argument;
uint32_t f = 400000; // Start search at 400kHz
freq_t f = 400000; // Start search at 400kHz
// int i = 0; // Index in spur table (temp_t)
set_RBW(setting.frequency_step/100);
last_spur = 0;
@ -3383,12 +3374,12 @@ void self_test(int test)
shell_printf("RBW = %f, ",setting.rbw_x10/10.0);
#if 0
set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw_x10 * 1000)); // Wide
set_sweep_frequency(ST_SPAN, (freq_t)(setting.rbw_x10 * 1000)); // Wide
#else
if (setting.rbw_x10 < 1000)
set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw_x10 * 5000)); // Narrow
set_sweep_frequency(ST_SPAN, (freq_t)(setting.rbw_x10 * 5000)); // Narrow
else
set_sweep_frequency(ST_SPAN, (uint32_t)(18000000));
set_sweep_frequency(ST_SPAN, (freq_t)(18000000));
#endif
test_acquire(TEST_RBW); // Acquire test
test_validate(TEST_RBW); // Validate test
@ -3410,9 +3401,9 @@ void self_test(int test)
setting.step_delay_mode = SD_NORMAL;
setting.step_delay = setting.step_delay * 4 / 5;
if (setting.rbw_x10 < 1000)
set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw_x10 * 5000));
set_sweep_frequency(ST_SPAN, (freq_t)(setting.rbw_x10 * 5000));
else
set_sweep_frequency(ST_SPAN, (uint32_t)(18000000));
set_sweep_frequency(ST_SPAN, (freq_t)(18000000));
// setting.repeat = 10;
test_acquire(TEST_RBW); // Acquire test
@ -3435,9 +3426,9 @@ void self_test(int test)
setting.offset_delay /= 2;
setting.spur_removal = S_OFF;
if (setting.rbw_x10 < 1000)
set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw_x10 * 5000)); // 50 times RBW
set_sweep_frequency(ST_SPAN, (freq_t)(setting.rbw_x10 * 5000)); // 50 times RBW
else
set_sweep_frequency(ST_SPAN, (uint32_t)(18000000)); // Limit to 18MHz
set_sweep_frequency(ST_SPAN, (freq_t)(18000000)); // Limit to 18MHz
// setting.repeat = 10;
test_acquire(TEST_RBW); // Acquire test
test_validate(TEST_RBW); // Validate test

@ -354,7 +354,7 @@ static int old_freq_band[2] = {-1,-1};
static int written[2]= {0,0};
#endif
void SI4432_Set_Frequency ( uint32_t Freq ) {
void SI4432_Set_Frequency ( freq_t Freq ) {
// int mode = SI4432_Read_Byte(0x02) & 0x03; // Disabled as unreliable
// SI4432_Write_Byte(0x07, 0x02); // Switch to tune mode
@ -848,7 +848,7 @@ extern int settingAttenuate;
//#define LEVEL(i, f, v) (v * (1-(fabs(f - frequencies[i])/actual_rbw/1000)))
float LEVEL(uint32_t i, uint32_t f, int v)
float LEVEL(uint32_t i, freq_t f, int v)
{
float dv;
float df = fabs((float)f - (float)i);

@ -156,8 +156,8 @@ void ADF4351_Setup(void);
void ADF4351_WriteRegister32(int channel, const uint32_t value);
uint32_t ADF4351_set_frequency(int channel, uint32_t freq, int drive_strength);
uint32_t ADF4351_prep_frequency(int channel, uint32_t freq, int drive_strength);
freq_t ADF4351_set_frequency(int channel, freq_t freq, int drive_strength);
freq_t ADF4351_prep_frequency(int channel, freq_t freq, int drive_strength);
//int ADF4351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength);
void ADF4351_Set(int channel);
void ADF4351_enable_output(void);

48
ui.c

@ -778,7 +778,7 @@ menu_stimulus_cb(int item, uint8_t data)
}
#endif
static uint32_t
static freq_t
get_marker_frequency(int marker)
{
if (marker < 0 || marker >= MARKERS_MAX)
@ -791,7 +791,7 @@ get_marker_frequency(int marker)
static UI_FUNCTION_CALLBACK(menu_marker_op_cb)
{
(void)item;
uint32_t freq = get_marker_frequency(active_marker);
freq_t freq = get_marker_frequency(active_marker);
if (freq == 0)
return; // no active marker
@ -809,12 +809,12 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb)
{
if (previous_marker == -1 || active_marker == previous_marker) {
// if only 1 marker is active, keep center freq and make span the marker comes to the edge
uint32_t center = get_sweep_frequency(ST_CENTER);
uint32_t span = center > freq ? center - freq : freq - center;
freq_t center = get_sweep_frequency(ST_CENTER);
freq_t span = center > freq ? center - freq : freq - center;
set_sweep_frequency(ST_SPAN, span * 2);
} else {
// if 2 or more marker active, set start and stop freq to each marker
uint32_t freq2 = get_marker_frequency(previous_marker);
freq_t freq2 = get_marker_frequency(previous_marker);
if (freq2 == 0)
return;
if (freq > freq2) {
@ -1234,6 +1234,7 @@ menu_move_back(void)
if (current_menu_is_form()) {
redraw_frame();
redraw_request |= REDRAW_BATTERY;
area_width = 0;
} else {
// redraw_frame();
@ -1269,6 +1270,7 @@ menu_push_submenu(const menuitem_t *submenu)
ensure_selection();
if (menu_is_form(submenu)) {
redraw_frame();
redraw_request |= REDRAW_BATTERY;
area_width = 0;
} else {
// redraw_frame();
@ -1901,17 +1903,17 @@ void set_keypad_value(int v)
set_numeric_value();
}
void check_frequency_slider(uint32_t slider_freq)
void check_frequency_slider(freq_t slider_freq)
{
if ( (maxFreq - minFreq) < (uint32_t)setting.slider_span ) {
if ( (maxFreq - minFreq) < (freq_t)setting.slider_span ) {
setting.slider_span = maxFreq - minFreq; // absolute mode with max step size
}
uint32_t half_span = setting.slider_span >> 1;
if (minFreq + (uint32_t)half_span > slider_freq) {
freq_t half_span = setting.slider_span >> 1;
if (minFreq + (freq_t)half_span > slider_freq) {
setting.slider_position -= (minFreq + half_span - slider_freq) / (setting.slider_span / (MENU_FORM_WIDTH-8)); // reposition if needed
}
if (maxFreq < slider_freq + (uint32_t)half_span) {
if (maxFreq < slider_freq + (freq_t)half_span) {
setting.slider_position += (slider_freq + half_span - maxFreq) / (setting.slider_span /(MENU_FORM_WIDTH-8)); // reposition if needed
}
}
@ -1967,12 +1969,12 @@ menu_select_touch(int i, int pos)
setting.slider_position = new_slider;
set_keypad_value(keypad);
dirty = false;
perform(false, 0, (uint32_t)uistat.value, false);
perform(false, 0, (freq_t)uistat.value, false);
draw_menu();
} else if (mode == SL_SPAN ){
uint32_t slider_freq;
freq_t slider_freq;
first_span:
slider_freq = (uint32_t) uistat.value;
slider_freq = (freq_t) uistat.value;
int pw=new_slider + LCD_WIDTH/2;
setting.slider_position = pw - LCD_WIDTH/2; // Show delta on slider
setting.slider_span = 10;
@ -1988,9 +1990,9 @@ menu_select_touch(int i, int pos)
setting.slider_span *= 2;
pw -= 12;
}
if ((uint32_t)setting.slider_span > (maxFreq - minFreq))
if ((freq_t)setting.slider_span > (maxFreq - minFreq))
setting.slider_span = (maxFreq - minFreq);
uint32_t old_minFreq = minFreq; // Save when in high mode
freq_t old_minFreq = minFreq; // Save when in high mode
minFreq = 0; // And set minFreq to 0 for span display
uistat.value = setting.slider_span;
set_keypad_value(keypad);
@ -2077,7 +2079,7 @@ menu_select_touch(int i, int pos)
step = setting.slider_span;
break;
}
if (step < 0 && get_sweep_frequency(ST_CENTER) < (uint32_t)(-step))
if (step < 0 && get_sweep_frequency(ST_CENTER) < (freq_t)(-step))
uistat.value = 0;
else
uistat.value = get_sweep_frequency(ST_CENTER) + step;
@ -2361,11 +2363,11 @@ lever_search_marker(int status)
// ex. 10942 -> 10000
// 6791 -> 5000
// 341 -> 200
static uint32_t
step_round(uint32_t v)
static freq_t
step_round(freq_t v)
{
// decade step
uint32_t x = 1;
freq_t x = 1;
for (x = 1; x*10 <= v; x*= 10)
;
@ -2381,9 +2383,9 @@ step_round(uint32_t v)
static void
lever_zoom_span(int status)
{
uint32_t span = get_sweep_frequency(ST_SPAN);
freq_t span = get_sweep_frequency(ST_SPAN);
if (uistat.auto_center_marker) {
uint32_t freq = get_marker_frequency(active_marker);
freq_t freq = get_marker_frequency(active_marker);
search_maximum(active_marker, freq, 10 );
if (freq != 0)
set_sweep_frequency(ST_CENTER, freq);
@ -2415,8 +2417,8 @@ lever_zoom_time(int status)
static void
lever_move(int status, int mode)
{
uint32_t center = get_sweep_frequency(mode);
uint32_t span = get_sweep_frequency(ST_SPAN);
freq_t center = get_sweep_frequency(mode);
freq_t span = get_sweep_frequency(ST_SPAN);
span = step_round(span / 3);
if (status & EVT_UP) {
set_sweep_frequency(mode, center + span);

@ -901,7 +901,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
markers[i].enabled = M_ENABLED;
markers[i].mtype = M_DELTA;// | M_TRACKING;
}
uint32_t center, span;
freq_t center, span;
markers[0].mtype = M_REFERENCE;// | M_TRACKING;
kp_help_text = "Frequency of signal";
ui_mode_keypad(KM_CENTER);
@ -2167,7 +2167,7 @@ static void fetch_numeric_target(void)
}
{
uint32_t x = uistat.value;
freq_t x = uistat.value;
int n = 0;
for (; x >= 10 && n < 9; n++)
x /= 10;
@ -2181,20 +2181,20 @@ set_numeric_value(void)
{
switch (keypad_mode) {
case KM_START:
set_sweep_frequency(ST_START, (uint32_t)uistat.value);
set_sweep_frequency(ST_START, (freq_t)uistat.value);
break;
case KM_STOP:
set_sweep_frequency(ST_STOP, (uint32_t)uistat.value);
set_sweep_frequency(ST_STOP, (freq_t)uistat.value);
break;
case KM_CENTER:
set_sweep_frequency(ST_CENTER, (uint32_t)uistat.value);
set_sweep_frequency(ST_CENTER, (freq_t)uistat.value);
break;
case KM_SPAN:
setting.modulation = MO_NONE;
set_sweep_frequency(ST_SPAN, (uint32_t)uistat.value);
set_sweep_frequency(ST_SPAN, (freq_t)uistat.value);
break;
case KM_CW:
set_sweep_frequency(ST_CW, (uint32_t)uistat.value);
set_sweep_frequency(ST_CW, (freq_t)uistat.value);
break;
case KM_SCALE:
user_set_scale(uistat.value);
@ -2272,7 +2272,7 @@ set_numeric_value(void)
set_gridlines(uistat.value);
break;
case KM_MARKER:
set_marker_frequency(active_marker, (uint32_t)uistat.value);
set_marker_frequency(active_marker, (freq_t)uistat.value);
break;
case KM_MODULATION:
set_modulation_frequency((int)uistat.value);

Loading…
Cancel
Save

Powered by TurnKey Linux.