Skip to content

Commit

Permalink
developing...
Browse files Browse the repository at this point in the history
  • Loading branch information
ka9q committed Aug 5, 2023
1 parent 4b1ad8a commit d911ae4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
3 changes: 3 additions & 0 deletions dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void dump_metadata(uint8_t const * const buffer,int length,bool newline){
case CMD_CNT:
printf("commands %'llu",(long long unsigned)decode_int(cp,optlen));
break;
case BLOCKS_SINCE_POLL:
printf("last poll %'llu blocks",(long long unsigned)decode_int(cp,optlen));
break;
case GPS_TIME:
{
char tbuf[100];
Expand Down
1 change: 1 addition & 0 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,5 +901,6 @@ int downconvert(struct demod *demod){
}
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()
demod->blocks_since_poll++;
return 0;
}
2 changes: 1 addition & 1 deletion radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ struct demod {
float rate;
} deemph;

long long blocks_since_poll; // Used for averaging signal levels
uint64_t blocks_since_poll; // Used for averaging signal levels

pthread_t sap_thread;
pthread_t rtcp_thread;
Expand Down
5 changes: 4 additions & 1 deletion radio_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ static int encode_radio_status(struct frontend const *frontend,struct demod cons
encode_float(&bp,KAISER_BETA,demod->filter.kaiser_beta); // Dimensionless

// BASEBAND_POWER is now the average since last poll
float bb_power = demod->sig.bb_energy / demod->blocks_since_poll;
float bb_power = NAN;
if(demod->blocks_since_poll > 0)
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);
Expand Down
31 changes: 25 additions & 6 deletions tune.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ int Mcast_ttl = 5;
int IP_tos = 0;
const char *App_path;
int Verbose;
char *Radio = NULL;
char *Locale = "en_US.UTF-8";
char const *Radio = NULL;
char const *Locale = "en_US.UTF-8";
char const *Iface;
char const *Mode = "am";
uint32_t Ssrc;

struct sockaddr_storage Control_address;
int Status_sock = -1;
int Control_sock = -1;

char Optstring[] = "hvl:r:s:";
char Optstring[] = "hi:vl:r:s:";
struct option Options[] = {
{"help", no_argument, NULL, 'h'},
{"iface", required_argument, NULL, 'i'},
{"mode", required_argument, NULL, 'm'},
{"ssrc", required_argument, NULL, 's'},
{"radio", required_argument, NULL, 'r'},
{"locale", required_argument, NULL, 'l'},
Expand All @@ -53,6 +57,12 @@ int main(int argc,char *argv[]){
int c;
while((c = getopt_long(argc,argv,Optstring,Options,NULL)) != -1){
switch(c){
case 'i':
Iface = optarg;
break;
case 'm':
Mode = optarg;
break;
case 's':
Ssrc = strtol(optarg,NULL,0);
break;
Expand Down Expand Up @@ -86,17 +96,18 @@ int main(int argc,char *argv[]){
fprintf(stderr,"--ssrc not specified\n");
exit(1);
}

{
char iface[1024];
resolve_mcast(Radio,&Control_address,DEFAULT_STAT_PORT,iface,sizeof(iface));
Status_sock = listen_mcast(&Control_address,iface);
char const *ifc = (Iface != NULL) ? Iface : iface;

Status_sock = listen_mcast(&Control_address,ifc);

if(Status_sock == -1){
fprintf(stderr,"Can't open Status_sock socket to radio control channel %s: %s\n",Radio,strerror(errno));
exit(1);
}
Control_sock = connect_mcast(&Control_address,iface,Mcast_ttl,IP_tos);
Control_sock = connect_mcast(&Control_address,ifc,Mcast_ttl,IP_tos);
if(Control_sock == -1){
fprintf(stderr,"Can't open cmd socket to radio control channel %s: %s\n",Radio,strerror(errno));
exit(1);
Expand All @@ -123,13 +134,21 @@ int main(int argc,char *argv[]){
else if(f < 100000) // 2000-99999.999 can only be kHz
f = f*1e3;

// Begin polling SSRC to ensure the multicast group is up and radiod is listening
// Does the ssrc already exist?

// Now send command

uint8_t buffer[8192];
uint8_t *bp = buffer;

*bp++ = 1; // Generate command packet
sent_tag = random();
encode_int(&bp,COMMAND_TAG,sent_tag);
encode_int(&bp,OUTPUT_SSRC,Ssrc);
if(Mode != NULL)
encode_string(&bp,PRESET,Mode,strlen(Mode));

sent_freq = f;
encode_double(&bp,RADIO_FREQUENCY,sent_freq); // Hz
encode_eol(&bp);
Expand Down

0 comments on commit d911ae4

Please sign in to comment.