File: testbcd.c

package info (click to toggle)
hamlib 4.6.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,984 kB
  • sloc: ansic: 262,996; sh: 6,135; cpp: 1,578; perl: 876; makefile: 855; python: 148; awk: 58; xml: 26
file content (68 lines) | stat: -rw-r--r-- 1,374 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

/*
 * Very simple test program to check BCD conversion against some other --SF
 * This is mainly to test freq2bcd and bcd2freq functions.
 */

#include <hamlib/config.h>

#include <stdio.h>
#include <stdlib.h>
#include <hamlib/rig.h>
#include "misc.h"

#define MAXDIGITS 32

int main(int argc, char *argv[])
{
    unsigned char b[(MAXDIGITS + 1) / 2];
    freq_t f = 0;
    int digits = 10;
    int i;

    if (argc != 2 && argc != 3)
    {
        fprintf(stderr, "Usage: %s <freq> [digits]\n", argv[0]);
        exit(1);
    }

    f = (freq_t)atoll(argv[1]);

    if (argc > 2)
    {
        digits = atoi(argv[2]);

        if (digits > MAXDIGITS)
        {
            exit(1);
        }
    }

    printf("Little Endian mode\n");
    printf("Frequency: %"PRIfreq"\n", f);
    to_bcd(b, f, digits);
    printf("BCD: %2.2x", b[0]);

    for (i = 1; i < (digits + 1) / 2; i++)
    {
        printf(",%2.2x", b[i]);
    }

    // cppcheck-suppress *
    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]);

    for (i = 1; i < (digits + 1) / 2; i++)
    {
        printf(",%2.2x", b[i]);
    }

    printf("\nResult after recoding: %"PRIll"\n",
           (int64_t)from_bcd_be(b, digits));

    return 0;
}