Print all digits of frequency.

This commit is contained in:
Serge Vakulenko 2018-08-24 21:09:52 -07:00
parent dbbcbdaaa0
commit 37592a6554
2 changed files with 76 additions and 36 deletions

48
md380.c
View File

@ -472,10 +472,16 @@ static void print_freq(FILE *out, unsigned data)
(data >> 20) & 15, (data >> 16) & 15,
(data >> 12) & 15, (data >> 8) & 15);
if ((data & 0xff) == 0)
putc(' ', out);
else
if ((data & 0xff) == 0) {
fputs(" ", out);
} else {
fprintf(out, "%d", (data >> 4) & 15);
if ((data & 0x0f) == 0) {
fputs(" ", out);
} else {
fprintf(out, "%d", data & 15);
}
}
}
@ -546,6 +552,25 @@ static int freq_to_hz(uint32_t bcd)
return (((((((a*10 + b) * 10 + c) * 10 + d) * 10 + e) * 10 + f) * 10 + g) * 10 + h) * 10;
}
//
// Print frequency as MHz.
//
static void print_mhz(FILE *out, uint32_t hz)
{
if (hz % 1000000 == 0)
fprintf(out, "%-8u", hz / 1000000);
else if (hz % 100000 == 0)
fprintf(out, "%-8.1f", hz / 1000000.0);
else if (hz % 10000 == 0)
fprintf(out, "%-8.2f", hz / 1000000.0);
else if (hz % 1000 == 0)
fprintf(out, "%-8.3f", hz / 1000000.0);
else if (hz % 100 == 0)
fprintf(out, "%-8.4f", hz / 1000000.0);
else
fprintf(out, "%-8.5f", hz / 1000000.0);
}
//
// Print the transmit offset or frequency.
//
@ -558,19 +583,14 @@ static void print_offset(FILE *out, uint32_t rx_bcd, uint32_t tx_bcd)
if (delta == 0) {
fprintf(out, "+0 ");
} else if (delta > 0 && delta/50000 <= 255) {
if (delta % 1000000 == 0)
fprintf(out, "+%-7u", delta / 1000000);
else
fprintf(out, "+%-7.3f", delta / 1000000.0);
fprintf(out, "+");
print_mhz(out, delta);
} else if (delta < 0 && -delta/50000 <= 255) {
delta = - delta;
if (delta % 1000000 == 0)
fprintf(out, "-%-7u", delta / 1000000);
else
fprintf(out, "-%-7.3f", delta / 1000000.0);
fprintf(out, "-");
print_mhz(out, -delta);
} else {
// Cross band mode.
fprintf(out, " %-7.4f", tx_hz / 1000000.0);
fprintf(out, " ");
print_mhz(out, tx_hz);
}
}

48
uv380.c
View File

@ -496,10 +496,16 @@ static void print_freq(FILE *out, unsigned data)
(data >> 20) & 15, (data >> 16) & 15,
(data >> 12) & 15, (data >> 8) & 15);
if ((data & 0xff) == 0)
putc(' ', out);
else
if ((data & 0xff) == 0) {
fputs(" ", out);
} else {
fprintf(out, "%d", (data >> 4) & 15);
if ((data & 0x0f) == 0) {
fputs(" ", out);
} else {
fprintf(out, "%d", data & 15);
}
}
}
@ -570,6 +576,25 @@ static int freq_to_hz(uint32_t bcd)
return (((((((a*10 + b) * 10 + c) * 10 + d) * 10 + e) * 10 + f) * 10 + g) * 10 + h) * 10;
}
//
// Print frequency as MHz.
//
static void print_mhz(FILE *out, uint32_t hz)
{
if (hz % 1000000 == 0)
fprintf(out, "%-8u", hz / 1000000);
else if (hz % 100000 == 0)
fprintf(out, "%-8.1f", hz / 1000000.0);
else if (hz % 10000 == 0)
fprintf(out, "%-8.2f", hz / 1000000.0);
else if (hz % 1000 == 0)
fprintf(out, "%-8.3f", hz / 1000000.0);
else if (hz % 100 == 0)
fprintf(out, "%-8.4f", hz / 1000000.0);
else
fprintf(out, "%-8.5f", hz / 1000000.0);
}
//
// Print the transmit offset or frequency.
//
@ -582,19 +607,14 @@ static void print_offset(FILE *out, uint32_t rx_bcd, uint32_t tx_bcd)
if (delta == 0) {
fprintf(out, "+0 ");
} else if (delta > 0 && delta/50000 <= 255) {
if (delta % 1000000 == 0)
fprintf(out, "+%-7u", delta / 1000000);
else
fprintf(out, "+%-7.3f", delta / 1000000.0);
fprintf(out, "+");
print_mhz(out, delta);
} else if (delta < 0 && -delta/50000 <= 255) {
delta = - delta;
if (delta % 1000000 == 0)
fprintf(out, "-%-7u", delta / 1000000);
else
fprintf(out, "-%-7.3f", delta / 1000000.0);
fprintf(out, "-");
print_mhz(out, -delta);
} else {
// Cross band mode.
fprintf(out, " %-7.4f", tx_hz / 1000000.0);
fprintf(out, " ");
print_mhz(out, tx_hz);
}
}