Skip to content

Commit

Permalink
Send baseband signal level averaged over poll duration
Browse files Browse the repository at this point in the history
  • Loading branch information
ka9q committed Aug 5, 2023
1 parent 2f7ca67 commit 4b1ad8a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,9 @@ int downconvert(struct demod *demod){
buffer[n] *= step_osc(&demod->fine);
energy += cnrmf(buffer[n]);
}
demod->sig.bb_power = energy / N;
energy /= N;
demod->sig.bb_power = energy;
demod->sig.bb_energy += energy;
}
demod->filter.bin_shift = shift; // We need this in any case (not really?)
demod->sig.n0 = estimate_noise(demod,-shift); // Negative, just like compute_tuning. Note: must follow execute_filter_output()
Expand Down
3 changes: 3 additions & 0 deletions radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ struct demod {
// Signal levels & status, common to all demods
struct {
float bb_power; // Average power of signal after filter but before digital gain, power ratio
float bb_energy; // Integrated indefinitely until a status poll
float foffset; // Frequency offset Hz (FM, coherent AM, dsb)
float snr; // From PLL in linear, moments in FM
float n0; // per-demod N0 (experimental)
Expand Down Expand Up @@ -273,6 +274,8 @@ struct demod {
float rate;
} deemph;

long long blocks_since_poll; // Used for averaging signal levels

pthread_t sap_thread;
pthread_t rtcp_thread;
pthread_t demod_thread;
Expand Down
11 changes: 8 additions & 3 deletions radio_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern struct demod const *Dynamic_demod;
extern dictionary const *Modetable;


static int send_radio_status(struct frontend const *frontend,struct demod const *demod,int full);
static int send_radio_status(struct frontend const *frontend,struct demod *demod,int full);
static int decode_radio_commands(struct demod *demod,uint8_t const *buffer,int length);
static int encode_radio_status(struct frontend const *frontend,struct demod const *demod,uint8_t *packet, int len);

Expand Down Expand Up @@ -95,12 +95,13 @@ void *radio_status(void *arg){
return NULL;
}

static int send_radio_status(struct frontend const *frontend,struct demod const *demod,int full){
static int send_radio_status(struct frontend const *frontend,struct demod *demod,int full){
uint8_t packet[2048];

Metadata_packets++;
int const len = encode_radio_status(frontend,demod,packet,sizeof(packet));
send(Status_fd,packet,len,0);
demod->blocks_since_poll = 0;

return 0;
}
Expand Down Expand Up @@ -521,7 +522,9 @@ static int encode_radio_status(struct frontend const *frontend,struct demod cons
encode_int64(&bp,OUTPUT_DATA_PACKETS,demod->output.rtp.packets);
encode_float(&bp,KAISER_BETA,demod->filter.kaiser_beta); // Dimensionless

encode_float(&bp,BASEBAND_POWER,power2dB(demod->sig.bb_power)); // power -> dB
// BASEBAND_POWER is now the average since last poll
float bb_power = demod->sig.bb_energy / demod->blocks_since_poll;
encode_float(&bp,BASEBAND_POWER,power2dB(bb_power)); // power -> dB
encode_float(&bp,OUTPUT_LEVEL,power2dB(demod->output.level)); // power ratio -> dB
encode_int64(&bp,OUTPUT_SAMPLES,demod->output.samples);
encode_float(&bp,HEADROOM,voltage2dB(demod->output.headroom)); // amplitude -> dB
Expand All @@ -546,6 +549,8 @@ static int encode_radio_status(struct frontend const *frontend,struct demod cons
encode_float(&bp,TP1,demod->tp1);
if(!isnan(demod->tp2))
encode_float(&bp,TP2,demod->tp2);
encode_int64(&bp,BLOCKS_SINCE_POLL,demod->blocks_since_poll);

encode_eol(&bp);

return bp - packet;
Expand Down
1 change: 1 addition & 0 deletions status.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ enum status_type {
FE_LOW_EDGE, // edges of front end filter
FE_HIGH_EDGE,
FE_ISREAL, // Boolean, true -> front end uses real sampling, false -> front end uses complex
BLOCKS_SINCE_POLL, // Blocks since last poll
};

int encode_string(uint8_t **bp,enum status_type type,void const *buf,unsigned int buflen);
Expand Down

0 comments on commit 4b1ad8a

Please sign in to comment.