diff --git a/include/dsd.h b/include/dsd.h index 02c0a17..f8a067c 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -958,7 +958,7 @@ bool Recv(int sockfd, char *buf); //rtl_fm udp tuning function void rtl_udp_tune(dsd_opts * opts, dsd_state * state, long int frequency); -bool GetCurrentFreq(int sockfd, long int freq); +long int GetCurrentFreq(int sockfd); bool SetFreq(int sockfd, long int freq); bool SetModulation(int sockfd, int bandwidth); //commands below unique to GQRX only, not usable on SDR++ diff --git a/src/dmr_csbk.c b/src/dmr_csbk.c index 10edf92..f28aec5 100644 --- a/src/dmr_csbk.c +++ b/src/dmr_csbk.c @@ -25,6 +25,8 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 uint64_t csbk_data = 0; int csbk = 0; + long int ccfreq = 0; + if(IrrecoverableErrors == 0 && CRCCorrect == 1) { @@ -254,11 +256,18 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //add string for ncurses terminal display - no par since slc doesn't carrry that value sprintf (state->dmr_site_parms, "TIII - %s N%d-S%d ", model_str, net, site); - //debug print - //fprintf (stderr, " Sys ID Code: [%04X]", sysidcode); + //if using rigctl we can set an unknown cc frequency by polling rigctl for the current frequency + if (opts->use_rigctl == 1 && state->p25_cc_freq == 0) //if not set from channel map 0 + { + ccfreq = GetCurrentFreq (opts->rigctl_sockfd); + if (ccfreq != 0) state->p25_cc_freq = ccfreq; + } uint16_t syscode = (uint16_t)ConvertBitIntoBytes(&cs_pdu_bits[40], 16); + + //debug print //fprintf (stderr, "\n SYSCODE: %016b", syscode); + //fprintf (stderr, " Sys ID Code: [%04X]", sysidcode); } //P_CLEAR @@ -562,6 +571,13 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 // state->dmr_vc_lcn = lcn; // state->dmr_vc_lsn = lcn * (tslot+1); + //if using rigctl we can set an unknown cc frequency by polling rigctl for the current frequency + if (opts->use_rigctl == 1 && state->p25_cc_freq == 0) //if not set from channel map 0 + { + ccfreq = GetCurrentFreq (opts->rigctl_sockfd); + if (ccfreq != 0) state->p25_cc_freq = ccfreq; + } + //shim in here for ncurses freq display when not trunking (playback, not live) if (opts->p25_trunk == 0 && state->trunk_chan_map[lcn] != 0) { diff --git a/src/dmr_flco.c b/src/dmr_flco.c index cbb1538..e13bde7 100644 --- a/src/dmr_flco.c +++ b/src/dmr_flco.c @@ -388,6 +388,8 @@ uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) { + long int ccfreq = 0; + int i; uint8_t slco_bytes[6]; //completed byte blocks for payload print for (i = 0; i < 5; i++) slco_bytes[i] = (uint8_t)ConvertBitIntoBytes(&slco_bits[i*8], 8); @@ -454,6 +456,12 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) fprintf (stderr, " C_SYS_PARMS - %s - Net ID: %d Site ID: %d - Reg Req: %d - CSC: %d ", model_str, net, site, reg, csc); //add string for ncurses terminal display - no par since slc doesn't carrry that value sprintf (state->dmr_site_parms, "TIII - %s N%d-S%d ", model_str, net, site); + //if using rigctl we can set an unknown cc frequency by polling rigctl for the current frequency + if (opts->use_rigctl == 1 && state->p25_cc_freq == 0) //if not set from channel map 0 + { + ccfreq = GetCurrentFreq (opts->rigctl_sockfd); + if (ccfreq != 0) state->p25_cc_freq = ccfreq; + } } else if (slco == 0x3) //P_SYS_Parms { @@ -481,6 +489,12 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) sprintf (state->dmr_branding_sub, "%s", "Con+ "); fprintf (stderr, " SLCO Connect Plus Control Channel - Net ID: %d Site ID: %d", con_netid, con_siteid); sprintf (state->dmr_site_parms, "N%d - S%d ", con_netid, con_siteid); + //if using rigctl we can set an unknown cc frequency by polling rigctl for the current frequency + if (opts->use_rigctl == 1 && state->p25_cc_freq == 0) //if not set from channel map 0 + { + ccfreq = GetCurrentFreq (opts->rigctl_sockfd); + if (ccfreq != 0) state->p25_cc_freq = ccfreq; + } } else if (slco == 0xF) diff --git a/src/dsd_main.c b/src/dsd_main.c index e26420f..88b7049 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -1919,8 +1919,6 @@ main (int argc, char **argv) if (opts.use_rigctl == 1) { opts.rigctl_sockfd = Connect(opts.rigctlhostname, opts.rigctlportno); - long int initfreq = 0; - GetCurrentFreq(opts.rigctl_sockfd, initfreq); } if((strncmp(opts.audio_in_dev, "tcp", 3) == 0)) //tcp socket input from SDR++ and others diff --git a/src/dsd_rigctl.c b/src/dsd_rigctl.c index 3f5c94c..fa03a06 100644 --- a/src/dsd_rigctl.c +++ b/src/dsd_rigctl.c @@ -100,46 +100,36 @@ bool Recv(int sockfd, char *buf) // // GQRX Protocol // -// bool GetCurrentFreq(int sockfd, freq_t *freq) -bool GetCurrentFreq(int sockfd, long int freq) //compatible with P25 freq storage +long int GetCurrentFreq(int sockfd) { + long int freq = 0; char buf[BUFSIZE]; char * ptr; char * token; Send(sockfd, "f\n"); - Recv(sockfd, buf); //buffer will contain a stored \n line break as well + Recv(sockfd, buf); - if (strcmp(buf, "RPRT 1") == 0 ) //sdr++ may return this in error - return false; + if (strcmp(buf, "RPRT 1") == 0 ) + return freq; - token = strtok (buf, "\n"); //remove line break \n from return buf string - freq = strtol (token, &ptr, 10); //number is base, as in base 2 is binary, base 10 is dec, base 16 hex - //fprintf (stderr, "\nRIGCTL Buffer: [%s]\n", buf); - //fprintf (stderr, "\nRIGCTL VFO Freq: [%ld]\n", freq); - return true; + token = strtok (buf, "\n"); + freq = strtol (token, &ptr, 10); + // fprintf (stderr, "\nRIGCTL VFO Freq: [%ld]\n", freq); + return freq; } -// bool SetFreq(int sockfd, freq_t freq) + bool SetFreq(int sockfd, long int freq) { char buf[BUFSIZE]; - sprintf (buf, "F %ld\n", freq); //llu + sprintf (buf, "F %ld\n", freq); Send(sockfd, buf); Recv(sockfd, buf); if (strcmp(buf, "RPRT 1") == 0 ) return false; - GetCurrentFreq(sockfd, freq); - - //freq_t freq_current = 0; - //long int freq_current = 0; - // do - // { - // GetCurrentFreq(sockfd, freq_current); - // } while (freq_current != freq); - return true; } @@ -154,8 +144,6 @@ bool SetModulation(int sockfd, int bandwidth) if (strcmp(buf, "RPRT 1") == 0 ) return false; - //GetCurrentFreq(sockfd, freq); - return true; } diff --git a/src/nxdn_element.c b/src/nxdn_element.c index 131962f..ed1ebac 100644 --- a/src/nxdn_element.c +++ b/src/nxdn_element.c @@ -378,6 +378,12 @@ void NXDN_decode_cch_info(dsd_opts * opts, dsd_state * state, uint8_t * Message) if (channel1sts & 0x20 || channel1sts & 0x8) //current or new only { if (freq1 != 0) state->p25_cc_freq = freq1; + //let's assume the frequency we are tuned to is the current control channel + else if (opts->use_rigctl == 1 && state->p25_cc_freq == 0) //if not set from channel map 0 or nxdn_channel_to_frequency and rigctl is available + { + freq1 = GetCurrentFreq (opts->rigctl_sockfd); + if (freq1 != 0) state->p25_cc_freq = freq1; + } } else if (channel1sts & 0x8) //Candidate Added {