Data Structures
Reference for the main data structures used in NanoVNA-H firmware.
Measurement Data
Section titled “Measurement Data”measured Array
Section titled “measured Array”The primary measurement storage array:
extern float measured[2][SWEEP_POINTS_MAX][2];| Dimension | Index | Meaning |
|---|---|---|
First [2] | 0 | S11 (reflection) data |
| 1 | S21 (transmission) data | |
Second [SWEEP_POINTS_MAX] | 0..points-1 | Sweep point index |
Third [2] | 0 | Real part |
| 1 | Imaginary part |
Example access:
// Get S11 at sweep point 50float s11_re = measured[0][50][0];float s11_im = measured[0][50][1];
// Get S21 at sweep point 50float s21_re = measured[1][50][0];float s21_im = measured[1][50][1];Size by target:
| Target | SWEEP_POINTS_MAX | Array Size |
|---|---|---|
| F072 | 101 | 1,616 bytes |
| F303 | 401 | 6,416 bytes |
properties_t Structure
Section titled “properties_t Structure”Stores calibration data and sweep settings. Saved to flash in slots 0-4 (F072) or 0-6 (F303).
typedef struct properties { uint32_t magic; // PROPERTIES_MAGIC (0x434f4e54) freq_t _frequency0; // Sweep start frequency freq_t _frequency1; // Sweep stop frequency freq_t _cal_frequency0; // Calibration start frequency freq_t _cal_frequency1; // Calibration stop frequency freq_t _var_freq; // Frequency step (0 = auto) uint16_t _mode; // Time domain flags, display mode uint16_t _sweep_points; // Points in measurement sweep int8_t _current_trace; // Active trace (0-3, -1 disabled) int8_t _active_marker; // Active marker (0-7, -1 disabled) int8_t _previous_marker; // Previous marker for delta uint8_t _power; // Output power (0-3) uint8_t _cal_power; // Power used during calibration uint8_t _measure; // Measure module mode uint16_t _cal_sweep_points; // Points used in calibration uint16_t _cal_status; // Calibration status flags trace_t _trace[TRACES_MAX]; // Trace configurations (4) marker_t _markers[MARKERS_MAX]; // Marker configurations (8) uint8_t _reserved; uint8_t _velocity_factor; // Cable velocity (0-100%) float _electrical_delay[2]; // E-delay for S11, S21 (seconds) float _var_delay; // E-delay step for lever float _s21_offset; // S21 offset in dB float _portz; // Port Z renormalization float _cal_load_r; // Calibration LOAD R value uint32_t _reserved1[7]; float _cal_data[CAL_TYPE_COUNT][SWEEP_POINTS_MAX][2]; uint32_t checksum;} properties_t;Calibration Data
Section titled “Calibration Data”float _cal_data[CAL_TYPE_COUNT][SWEEP_POINTS_MAX][2];| Index | CAL_TYPE | Description |
|---|---|---|
| 0 | CAL_LOAD | Load standard measurement |
| 1 | CAL_OPEN | Open standard measurement |
| 2 | CAL_SHORT | Short standard measurement |
| 3 | CAL_THRU | Through standard measurement |
| 4 | CAL_ISOLN | Isolation measurement |
Calibration Status Flags
Section titled “Calibration Status Flags”#define CALSTAT_LOAD (1<<0) // Load data collected#define CALSTAT_OPEN (1<<1) // Open data collected#define CALSTAT_SHORT (1<<2) // Short data collected#define CALSTAT_THRU (1<<3) // Through data collected#define CALSTAT_ISOLN (1<<4) // Isolation data collected#define CALSTAT_ES (1<<5) // Source match error term#define CALSTAT_ER (1<<6) // Reflection tracking error term#define CALSTAT_ET (1<<7) // Transmission tracking error term#define CALSTAT_APPLY (1<<8) // Calibration is being applied#define CALSTAT_INTERPOLATED (1<<9) // Data is interpolated#define CALSTAT_ENHANCED_RESPONSE (1<<10) // Enhanced response calMode Flags
Section titled “Mode Flags”#define DOMAIN_MODE (1<<0) // 0=freq, 1=time#define TD_FUNC (0b11<<1)#define TD_FUNC_BANDPASS (0b00<<1)#define TD_FUNC_LOWPASS_IMPULSE (0b01<<1)#define TD_FUNC_LOWPASS_STEP (0b10<<1)#define TD_WINDOW (0b11<<3)#define TD_WINDOW_NORMAL (0b00<<3)#define TD_WINDOW_MINIMUM (0b01<<3)#define TD_WINDOW_MAXIMUM (0b10<<3)#define TD_CENTER_SPAN (1<<6) // Center/span vs start/stop#define TD_MARKER_TRACK (1<<7) // Marker tracking enabled#define TD_MARKER_DELTA (1<<8) // Delta marker modeconfig_t Structure
Section titled “config_t Structure”Device configuration stored separately from calibration. Survives calibration recall.
typedef struct config { uint32_t magic; // CONFIG_MAGIC (0x434f4e56) uint32_t _harmonic_freq_threshold; // Harmonic mode threshold int32_t _IF_freq; // IF frequency offset int16_t _touch_cal[4]; // Touch calibration corners uint16_t _vna_mode; // VNA mode flags uint16_t _dac_value; // DAC output value uint16_t _vbat_offset; // Battery voltage offset uint16_t _bandwidth; // Default bandwidth uint8_t _lever_mode; // Lever control mode uint8_t _brightness; // LCD brightness (F303) uint16_t _lcd_palette[MAX_PALETTE]; // Color palette (32 colors) uint32_t _serial_speed; // USART baud rate uint32_t _xtal_freq; // TCXO reference frequency float _measure_r; // Reference impedance uint8_t _band_mode; // Band selection mode uint8_t _reserved[3]; uint32_t checksum;} config_t;VNA Mode Flags
Section titled “VNA Mode Flags”enum { VNA_MODE_AUTO_NAME = 0, // Auto-generate filenames VNA_MODE_SMOOTH, // Smooth function type VNA_MODE_CONNECTION, // USB or serial console VNA_MODE_SEARCH, // Marker search (max/min) VNA_MODE_SHOW_GRID, // Show grid values VNA_MODE_DOT_GRID, // Dotted grid lines VNA_MODE_BACKUP, // Save settings on power-off VNA_MODE_FLIP_DISPLAY, // 180-degree flip VNA_MODE_SEPARATOR, // Decimal separator (./,) VNA_MODE_TIFF, // Screenshot format VNA_MODE_USB_UID // Use unique USB serial};trace_t Structure
Section titled “trace_t Structure”Configuration for each display trace.
typedef struct trace { uint8_t enabled; // 0=off, 1=on uint8_t type; // Trace type (0-29) uint8_t channel; // Data channel (0=S11, 1=S21) uint8_t smith_format; // Smith marker format (0-12) float scale; // Scale per division float refpos; // Reference position (0-8)} trace_t;Trace types: See Trace Types for complete list.
Constants:
#define TRACES_MAX 4 // Display traces#define STORED_TRACES 1 // Memory traces#define TRACE_INVALID -1 // No active tracemarker_t Structure
Section titled “marker_t Structure”Configuration for each marker.
typedef struct marker { uint8_t enabled; // 0=off, 1=on uint8_t reserved; uint16_t index; // Sweep point index freq_t frequency; // Frequency in Hz} marker_t;Constants:
#define MARKERS_MAX 8 // Maximum markers#define MARKER_INVALID -1 // No active markertrace_info_t Structure
Section titled “trace_info_t Structure”Display information for each trace type.
typedef struct trace_info { const char *name; // Display name const char *format; // Printf format for value const char *dformat; // Printf format for delta const char *symbol; // Unit symbol float refpos; // Default reference position float scale_unit; // Default scale per division get_value_cb_t get_value_cb; // Value calculation callback} trace_info_t;Used in: trace_info_list[MAX_TRACE_TYPE] (30 entries)
marker_info_t Structure
Section titled “marker_info_t Structure”Display information for Smith chart marker formats.
typedef struct marker_info { const char *name; // Format name const char *format; // Printf format get_value_cb_t get_re_cb; // Real value callback get_value_cb_t get_im_cb; // Imaginary value callback} marker_info_t;Used in: marker_info_list[MS_END] (13 entries)
Frequency Type
Section titled “Frequency Type”typedef uint32_t freq_t;All frequencies stored in Hz as unsigned 32-bit integers.
| Value | Frequency |
|---|---|
| 50000 | 50 kHz |
| 1000000 | 1 MHz |
| 100000000 | 100 MHz |
| 1500000000 | 1.5 GHz |
Audio Sample Type
Section titled “Audio Sample Type”typedef int16_t audio_sample_t;16-bit signed samples from the TLV320AIC3204 codec.
Buffer size:
#define AUDIO_SAMPLES_COUNT 48 // Samples per measurement#define AUDIO_BUFFER_LEN 96 // Left + right channelsGlobal Variables
Section titled “Global Variables”Current State
Section titled “Current State”extern config_t config; // Device configurationextern properties_t current_props; // Current calibration/settingsextern float measured[2][SWEEP_POINTS_MAX][2]; // Measurement dataextern uint8_t sweep_mode; // Sweep state flagsextern uint16_t lastsaveid; // Last saved slotConvenience Macros
Section titled “Convenience Macros”#define frequency0 current_props._frequency0#define frequency1 current_props._frequency1#define sweep_points current_props._sweep_points#define cal_status current_props._cal_status#define cal_data current_props._cal_data#define trace current_props._trace#define markers current_props._markers#define active_marker current_props._active_marker#define current_trace current_props._current_traceMemory Layout Summary
Section titled “Memory Layout Summary”| Structure | Size |
|---|---|
properties_t | ~6 KB |
config_t | ~100 bytes |
measured[] | 1,616 bytes |
spi_buffer[] | 4 KB |
RAM available: 16 KB
| Structure | Size |
|---|---|
properties_t | ~24 KB |
config_t | ~100 bytes |
measured[] | 6,416 bytes |
spi_buffer[] | 4 KB |
RAM available: 40 KB