2000-10-01 12:52:17 +00:00
|
|
|
|
2013-05-07 21:35:06 -05:00
|
|
|
/*
|
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 09:02:12 +02:00
|
|
|
* Very simple test program to check BCD conversion against some other --SF
|
2000-10-01 12:52:17 +00:00
|
|
|
* This is mainly to test freq2bcd and bcd2freq functions.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-20 17:37:24 +02:00
|
|
|
#include "hamlib/config.h"
|
2005-01-25 00:22:14 +00:00
|
|
|
|
2000-10-01 12:52:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2025-07-20 17:37:24 +02:00
|
|
|
#include "hamlib/rig.h"
|
2001-02-11 23:25:37 +00:00
|
|
|
#include "misc.h"
|
2000-10-01 12:52:17 +00:00
|
|
|
|
2002-09-06 14:12:35 +00:00
|
|
|
#define MAXDIGITS 32
|
2000-10-01 12:52:17 +00:00
|
|
|
|
2017-08-09 13:09:55 -05:00
|
|
|
int main(int argc, char *argv[])
|
2000-10-01 12:52:17 +00:00
|
|
|
{
|
2017-08-09 13:09:55 -05:00
|
|
|
unsigned char b[(MAXDIGITS + 1) / 2];
|
2026-07-28 00:50:35 -05:00
|
|
|
char hex[] = "x";
|
2017-08-09 13:09:55 -05:00
|
|
|
freq_t f = 0;
|
|
|
|
|
int digits = 10;
|
|
|
|
|
int i;
|
|
|
|
|
|
2017-10-06 18:58:42 -05:00
|
|
|
if (argc != 2 && argc != 3)
|
|
|
|
|
{
|
2017-08-09 13:09:55 -05:00
|
|
|
fprintf(stderr, "Usage: %s <freq> [digits]\n", argv[0]);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-28 00:50:35 -05:00
|
|
|
if (to_hex(0, NULL, sizeof(hex), hex) != 0 || hex[0] != '\0')
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Empty hexadecimal output is not terminated\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 13:09:55 -05:00
|
|
|
f = (freq_t)atoll(argv[1]);
|
|
|
|
|
|
2017-10-06 18:58:42 -05:00
|
|
|
if (argc > 2)
|
|
|
|
|
{
|
2017-08-09 13:09:55 -05:00
|
|
|
digits = atoi(argv[2]);
|
|
|
|
|
|
2017-10-06 18:58:42 -05:00
|
|
|
if (digits > MAXDIGITS)
|
|
|
|
|
{
|
2017-08-09 13:09:55 -05:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("Little Endian mode\n");
|
|
|
|
|
printf("Frequency: %"PRIfreq"\n", f);
|
|
|
|
|
to_bcd(b, f, digits);
|
|
|
|
|
printf("BCD: %2.2x", b[0]);
|
|
|
|
|
|
2017-10-06 18:58:42 -05:00
|
|
|
for (i = 1; i < (digits + 1) / 2; i++)
|
|
|
|
|
{
|
2017-08-09 13:09:55 -05:00
|
|
|
printf(",%2.2x", b[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 10:13:02 -05:00
|
|
|
// cppcheck-suppress *
|
2017-08-09 13:09:55 -05:00
|
|
|
printf("\nResult after recoding: %"PRIll"\n", (int64_t)from_bcd(b, digits));
|
|
|
|
|
|
|
|
|
|
printf("\nBig Endian mode\n");
|
|
|
|
|
printf("Frequency: %"PRIfreq"\n", f);
|
|
|
|
|
to_bcd_be(b, f, digits);
|
|
|
|
|
printf("BCD: %2.2x", b[0]);
|
|
|
|
|
|
2017-10-06 18:58:42 -05:00
|
|
|
for (i = 1; i < (digits + 1) / 2; i++)
|
|
|
|
|
{
|
2017-08-09 13:09:55 -05:00
|
|
|
printf(",%2.2x", b[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("\nResult after recoding: %"PRIll"\n",
|
|
|
|
|
(int64_t)from_bcd_be(b, digits));
|
|
|
|
|
|
|
|
|
|
return 0;
|
2000-10-01 12:52:17 +00:00
|
|
|
}
|