Simplified outputlevel code

Removed_REF_marker
erikkaashoek 5 years ago
parent 082e465a2e
commit f45fd2927e

@ -914,7 +914,11 @@ void send_region(const char *t, int x, int y, int w, int h)
void send_buffer(uint8_t * buf, int s)
{
if (SDU1.config->usbp->state == USB_ACTIVE) {
streamWrite(shell_stream, (void*) buf, s);
while (s > 0) {
streamWrite(shell_stream, (void*) buf, (s > 128 ? 128 : s));
buf = buf+128;
s -= 128;
}
streamWrite(shell_stream, (void*)"ch> \r\n", 6);
}
}

@ -255,9 +255,9 @@ void set_extra_lna(int t);
// ------------------------------- sa_core.c ----------------------------------
extern float level_min(void);
extern float level_max(void);
extern float level_range(void);
extern float level_min;
extern float level_max;
extern float level_range;
extern const char * const unit_string[];
#ifdef TINYSA4

@ -331,7 +331,6 @@ VNA_SHELL_FUNCTION(cmd_if)
VNA_SHELL_FUNCTION(cmd_zero)
{
if (argc != 1) {
usage:
shell_printf("usage: zero {level}\r\n%ddBm\r\n", config.ext_zero_level);
return;
} else {

@ -74,23 +74,21 @@ static freq_t real_old_freq[4] = { 0, 0, 0, 0};
const float si_drive_dBm [] = {-41, -30, -21, -17, -12, -11, -10, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -3 , -2, -1.5, -1, -0.5, 0};
const float adf_drive_dBm[] = {-15,-12,-9,-6};
const uint8_t drive_register[] = {0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
float *drive_dBm = (float *) adf_drive_dBm;
#else
const int8_t drive_dBm [16] = {-38, -32, -30, -27, -24, -19, -15, -12, -5, -2, 0, 3, 6, 9, 12, 16};
#endif
#ifdef TINYSA4
#define SWITCH_ATTENUATION (setting.mode == M_GENHIGH && config.high_out_adf4350 ? 0 : 37 - config.switch_offset)
#define SWITCH_ATTENUATION ((setting.mode == M_GENHIGH && config.high_out_adf4350) ? 40 : 37 - config.switch_offset)
//#define POWER_OFFSET -18 // Max level with all enabled
//#define POWER_RANGE 70
#define MAX_DRIVE (setting.mode == M_GENHIGH && config.high_out_adf4350 ? 3 : 18)
#define MIN_DRIVE (setting.mode == M_GENHIGH && config.high_out_adf4350 ? 0: 2)
#define MAX_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 3 : 18)
#define MIN_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 0: 2)
//#define SL_GENHIGH_LEVEL_MIN -15
//#define SL_GENHIGH_LEVEL_RANGE 9
#define SL_GENHIGH_LEVEL_MIN drive_dBm[MIN_DRIVE]
#define SL_GENHIGH_LEVEL_MIN (drive_dBm[MIN_DRIVE] - (config.high_out_adf4350 ? 0: 37 - config.switch_offset))
#define SL_GENHIGH_LEVEL_MAX drive_dBm[MAX_DRIVE]
#define SL_GENLOW_LEVEL_MIN -104
@ -112,6 +110,10 @@ const int8_t drive_dBm [16] = {-38, -32, -30, -27, -24, -19, -15, -12, -5, -2, 0
#define RECEIVE_SWITCH_ATTENUATION 21 // TODO differentiate for tinySA3 and tinySA4
float level_min;
float level_max;
float level_range;
//int setting.refer = -1; // Off by default
const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000};
@ -179,7 +181,6 @@ void reset_settings(int m)
setting.attenuate_x2 = 0; // These should be initialized consistently
setting.rx_drive=MAX_DRIVE; // And this
setting.atten_step = 0; // And this, only used in low output mode
setting.level = level_max(); // This is the level with above settings.
setting.rbw_x10 = 0;
setting.average = 0;
#ifdef TINYSA4
@ -287,6 +288,9 @@ void reset_settings(int m)
#endif
setting.correction_frequency = config.low_correction_frequency;
setting.correction_value = config.low_correction_value;
level_min = SL_GENLOW_LEVEL_MIN + config.low_level_output_offset;
level_max = SL_GENLOW_LEVEL_MAX + config.low_level_output_offset;
level_range = level_max - level_min;
break;
case M_HIGH:
set_sweep_frequency(ST_START, minFreq);
@ -313,8 +317,12 @@ void reset_settings(int m)
setting.step_delay_mode = SD_FAST;
setting.correction_frequency = config.high_correction_frequency;
setting.correction_value = config.high_correction_value;
level_min = SL_GENHIGH_LEVEL_MIN + config.high_level_output_offset;
level_max = SL_GENHIGH_LEVEL_MAX + config.high_level_output_offset;
level_range = level_max - level_min;
break;
}
setting.level = level_max; // This is the level with above settings.
for (uint8_t i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_DISABLED;
markers[i].mtype = M_NORMAL;
@ -621,6 +629,7 @@ void set_auto_reflevel(bool v)
setting.auto_reflevel = v;
}
#if 0
float level_min(void)
{
int l;
@ -645,6 +654,7 @@ float level_range(void)
r = level_max() - level_min();
return r;
}
#endif
static pureRSSI_t get_signal_path_loss(void){
#ifdef TINYSA4
@ -708,7 +718,7 @@ float get_attenuation(void)
{
float actual_attenuation = setting.attenuate_x2 / 2.0;
if (setting.mode == M_GENLOW) {
return (float)( level_max() - actual_attenuation + BELOW_MAX_DRIVE(setting.rx_drive) - ( setting.atten_step ? SWITCH_ATTENUATION : 0) );
return (float)( level_max - actual_attenuation + BELOW_MAX_DRIVE(setting.rx_drive) - ( setting.atten_step ? SWITCH_ATTENUATION : 0) );
} else if (setting.atten_step) {
if (setting.mode == M_LOW)
return actual_attenuation + RECEIVE_SWITCH_ATTENUATION;
@ -722,7 +732,7 @@ void set_attenuation(float a) // Is used both only in high/low input mode
{
#if 0
if (setting.mode == M_GENLOW) {
a = a - level_max(); // Move to zero for max power
a = a - level_max; // Move to zero for max power
if (a > 0)
a = 0;
if( a < - SWITCH_ATTENUATION) {
@ -1171,8 +1181,8 @@ void set_offset(float offset)
{
setting.offset = offset;
int min,max;
min = level_min();
max = min + level_range();
min = level_min;
max = min + level_range;
plot_printf(low_level_help_text, sizeof low_level_help_text, "%+d..%+d", min + (int)offset, max + (int)offset);
redraw_request|=REDRAW_AREA;
dirty = true; // No HW update required, only status panel refresh but need to ensure the cached value is updated in the calculation of the RSSI
@ -2263,7 +2273,7 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
a += PURE_TO_float(get_frequency_correction(f));
if (a != old_a) {
old_a = a;
a = a - level_max(); // convert to all settings maximum power output equals a = zero
a = a - level_max; // convert to all settings maximum power output equals a = zero
if (a < -SWITCH_ATTENUATION) {
a = a + SWITCH_ATTENUATION;
#ifdef TINYSA3
@ -2304,7 +2314,7 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
}
}
else if (setting.mode == M_GENHIGH) {
float a = setting.level - level_max();
float a = setting.level - level_max;
if (a <= -SWITCH_ATTENUATION) {
setting.atten_step = true;
a = a + SWITCH_ATTENUATION;
@ -2312,7 +2322,10 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
SI4432_Sel = SI4432_LO ;
set_switch_receive();
#else
enable_rx_output(false);
if (config.high_out_adf4350)
ADF4351_enable_aux_out(false);
else
enable_rx_output(false);
#endif
} else {
setting.atten_step = false;
@ -2320,12 +2333,15 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
SI4432_Sel = SI4432_LO ;
set_switch_transmit();
#else
enable_rx_output(true);
if (config.high_out_adf4350)
ADF4351_enable_aux_out(true);
else
enable_rx_output(true);
#endif
}
unsigned int d = MIN_DRIVE;
while (drive_dBm[d] - level_max() < a && d < MAX_DRIVE) // Find level equal or above requested level
while (drive_dBm[d] - level_max < a && d < MAX_DRIVE) // Find level equal or above requested level
d++;
// if (d == 8 && v < -12) // Round towards closest level
// d = 7;
@ -2335,8 +2351,11 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
SI4432_Sel = SI4432_LO ;
SI4432_Drive(d);
#endif
#ifdef __SI4463__
SI4463_set_output_level(d);
#ifdef TINYSA4
if (config.high_out_adf4350)
ADF4351_aux_drive(d);
else
SI4463_set_output_level(d);
#endif
}

@ -1892,7 +1892,7 @@ draw_menu_buttons(const menuitem_t *menu)
}
goto draw_divider;
} else if (menu[i].data == KM_LOWOUTLEVEL) {
local_slider_positions = ((get_level() - level_min()) * (MENU_FORM_WIDTH-8)) / level_range() + OFFSETX+4;
local_slider_positions = ((get_level() - level_min) * (MENU_FORM_WIDTH-8)) / level_range + OFFSETX+4;
for (int i=0; i <= 4; i++) {
ili9341_drawstring(step_text[i], button_start+12 + i * MENU_FORM_WIDTH/5, y+button_height-9);
}
@ -1905,7 +1905,7 @@ draw_menu_buttons(const menuitem_t *menu)
local_slider_positions = button_start;
ili9341_blitBitmap(local_slider_positions - 4, y, 7, 5, slider_bitmap);
} else if (menu[i].data == KM_HIGHOUTLEVEL) {
local_slider_positions = ((get_level() - level_min() ) * (MENU_FORM_WIDTH-8)) / level_range() + OFFSETX+4;
local_slider_positions = ((get_level() - level_min ) * (MENU_FORM_WIDTH-8)) / level_range + OFFSETX+4;
goto draw_slider;
}
}
@ -2070,7 +2070,7 @@ menu_select_touch(int i, int pos)
check_frequency_slider(slider_freq);
}
} else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_LOWOUTLEVEL) {
uistat.value = setting.offset + ((touch_x - OFFSETX+4) * level_range() ) / (MENU_FORM_WIDTH-8) + level_min() ;
uistat.value = setting.offset + ((touch_x - OFFSETX+4) * level_range ) / (MENU_FORM_WIDTH-8) + level_min ;
apply_step:
set_keypad_value(keypad);
apply:
@ -2079,7 +2079,7 @@ menu_select_touch(int i, int pos)
// }
// } else if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK && menu[i].reference == menu_sdrive_acb) {
} else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_HIGHOUTLEVEL) {
set_level( (touch_x - OFFSETX+4) *(level_range()) / (MENU_FORM_WIDTH-8) + level_min() );
set_level( (touch_x - OFFSETX+4) *(level_range) / (MENU_FORM_WIDTH-8) + level_min );
goto apply;
}
keypad_mode = old_keypad_mode;

@ -2223,10 +2223,10 @@ static void fetch_numeric_target(void)
case KM_LOWOUTLEVEL:
uistat.value = get_level(); // compensation for dB offset during low output mode
float end_level = ((int32_t)uistat.value)+setting.level_sweep;
if (end_level < level_min())
end_level = level_min();
if (end_level > level_max())
end_level = level_max();
if (end_level < level_min)
end_level = level_min;
if (end_level > level_max)
end_level = level_max;
uistat.value += setting.offset;
end_level += setting.offset;
if (setting.level_sweep != 0)

Loading…
Cancel
Save

Powered by TurnKey Linux.