diff --git a/d868uv.c b/d868uv.c index 9516425..c0d94a5 100644 --- a/d868uv.c +++ b/d868uv.c @@ -1456,20 +1456,17 @@ static void setup_channel(int i, int mode, char *name, double rx_mhz, double tx_ memset(ch, 0, sizeof(channel_t)); ascii_decode(ch->name, name, 16, 0); - //TODO -#if 0 - ch->rx_frequency = freq_to_bcd(rx_mhz); + ch->rx_frequency = mhz_to_ghefcdab(rx_mhz); if (tx_mhz > rx_mhz) { ch->repeater_mode = RM_TXPOS; - ch->tx_offset = offset_to_bcd(tx_mhz - rx_mhz); + ch->tx_offset = mhz_to_ghefcdab(tx_mhz - rx_mhz); } else if (tx_mhz < rx_mhz) { ch->repeater_mode = RM_TXNEG; - ch->tx_offset = offset_to_bcd(rx_mhz - tx_mhz); + ch->tx_offset = mhz_to_ghefcdab(rx_mhz - tx_mhz); } else { ch->repeater_mode = RM_SIMPLEX; ch->tx_offset = 0; } -#endif ch->channel_mode = mode; ch->power = power; diff --git a/gd77.c b/gd77.c index 5db2433..03a7536 100644 --- a/gd77.c +++ b/gd77.c @@ -707,8 +707,8 @@ static void setup_channel(int i, int mode, char *name, double rx_mhz, double tx_ ch->tot = tot; ch->scan_list_index = scanlist; ch->group_list_index = grouplist; - ch->rx_frequency = mhz_to_bcd(rx_mhz); - ch->tx_frequency = mhz_to_bcd(tx_mhz); + ch->rx_frequency = mhz_to_abcdefgh(rx_mhz); + ch->tx_frequency = mhz_to_abcdefgh(tx_mhz); ch->ctcss_dcs_receive = rxtone; ch->ctcss_dcs_transmit = txtone; diff --git a/md380.c b/md380.c index 010ae86..c961d4d 100644 --- a/md380.c +++ b/md380.c @@ -592,8 +592,8 @@ static void setup_channel(int i, int mode, char *name, double rx_mhz, double tx_ ch->tot = tot; ch->scan_list_index = scanlist; ch->group_list_index = grouplist; - ch->rx_frequency = mhz_to_bcd(rx_mhz); - ch->tx_frequency = mhz_to_bcd(tx_mhz); + ch->rx_frequency = mhz_to_abcdefgh(rx_mhz); + ch->tx_frequency = mhz_to_abcdefgh(tx_mhz); ch->ctcss_dcs_receive = rxtone; ch->ctcss_dcs_transmit = txtone; diff --git a/rd5r.c b/rd5r.c index 95ca239..ce6d661 100644 --- a/rd5r.c +++ b/rd5r.c @@ -711,8 +711,8 @@ static void setup_channel(int i, int mode, char *name, double rx_mhz, double tx_ ch->tot = tot; ch->scan_list_index = scanlist; ch->group_list_index = grouplist; - ch->rx_frequency = mhz_to_bcd(rx_mhz); - ch->tx_frequency = mhz_to_bcd(tx_mhz); + ch->rx_frequency = mhz_to_abcdefgh(rx_mhz); + ch->tx_frequency = mhz_to_abcdefgh(tx_mhz); ch->ctcss_dcs_receive = rxtone; ch->ctcss_dcs_transmit = txtone; diff --git a/util.c b/util.c index fa435de..e2b47d1 100644 --- a/util.c +++ b/util.c @@ -483,19 +483,41 @@ void print_freq(FILE *out, unsigned data) // // Convert frequency in MHz from floating point to // a binary coded decimal format (8 digits). +// Format: abcdefgh // -unsigned mhz_to_bcd(double mhz) +unsigned mhz_to_abcdefgh(double mhz) { unsigned hz = iround(mhz * 1000000.0); + unsigned a = (hz / 100000000) % 10; + unsigned b = (hz / 10000000) % 10; + unsigned c = (hz / 1000000) % 10; + unsigned d = (hz / 100000) % 10; + unsigned e = (hz / 10000) % 10; + unsigned f = (hz / 1000) % 10; + unsigned g = (hz / 100) % 10; + unsigned h = (hz / 10) % 10; - return ((hz / 100000000) % 10) << 28 | - ((hz / 10000000) % 10) << 24 | - ((hz / 1000000) % 10) << 20 | - ((hz / 100000) % 10) << 16 | - ((hz / 10000) % 10) << 12 | - ((hz / 1000) % 10) << 8 | - ((hz / 100) % 10) << 4 | - ((hz / 10) % 10); + return a << 28 | b << 24 | c << 20 | d << 16 | e << 12 | f << 8 | g << 4 | h; +} + +// +// Convert frequency in MHz from floating point to +// a binary coded decimal format (8 digits). +// Format: ghefcdab +// +unsigned mhz_to_ghefcdab(double mhz) +{ + unsigned hz = iround(mhz * 1000000.0); + unsigned a = (hz / 100000000) % 10; + unsigned b = (hz / 10000000) % 10; + unsigned c = (hz / 1000000) % 10; + unsigned d = (hz / 100000) % 10; + unsigned e = (hz / 10000) % 10; + unsigned f = (hz / 1000) % 10; + unsigned g = (hz / 100) % 10; + unsigned h = (hz / 10) % 10; + + return g << 28 | h << 24 | e << 20 | f << 16 | c << 12 | d << 8 | a << 4 | b; } // diff --git a/util.h b/util.h index 358a065..37dd07e 100644 --- a/util.h +++ b/util.h @@ -87,7 +87,8 @@ int is_file(char *filename); // Convert frequency in MHz from floating point to // a binary coded decimal format (8 digits). // -unsigned mhz_to_bcd(double mhz); +unsigned mhz_to_abcdefgh(double mhz); +unsigned mhz_to_ghefcdab(double mhz); // // Get a binary value of the parameter: On/Off, diff --git a/uv380.c b/uv380.c index 7a451f6..a4c901c 100644 --- a/uv380.c +++ b/uv380.c @@ -648,8 +648,8 @@ static void setup_channel(int i, int mode, char *name, double rx_mhz, double tx_ ch->scan_list_index = scanlist; ch->group_list_index = grouplist; ch->squelch = squelch; - ch->rx_frequency = mhz_to_bcd(rx_mhz); - ch->tx_frequency = mhz_to_bcd(tx_mhz); + ch->rx_frequency = mhz_to_abcdefgh(rx_mhz); + ch->tx_frequency = mhz_to_abcdefgh(tx_mhz); ch->ctcss_dcs_receive = rxtone; ch->ctcss_dcs_transmit = txtone; ch->power = power;