aboutsummaryrefslogtreecommitdiff
path: root/common/8b10b_code_table.c
blob: df2623afc3705a3b9a5617b81171c917880196e4 (plain)
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
#include <stdio.h>
#include <string.h>

#include "8b10b.h"

static const char * const rc_names[] = {
    [K28_0] = "K.28.0",
    [K28_1] = "K.28.1",
    [K28_2] = "K.28.2",
    [K28_3] = "K.28.3",
    [K28_4] = "K.28.4",
    [K28_5] = "K.28.5",
    [K28_6] = "K.28.6",
    [K28_7] = "K.28.7",
    [K23_7] = "K.23.7",
    [K27_7] = "K.27.7",
    [K29_7] = "K.29.7",
    [K30_7] = "K.30.7",
};

int hex_to_uint(const char *s, size_t len) {
    if (len > 7)
        return -2;

    int acc = 0;
    for (int i=0; i<len; i++) {
        int digit = s[i];
        if ('0' <= digit && digit <= '9')
            digit -= '0';
        else if ('a' <= digit && digit <= 'f')
            digit -= 'a' - 0xa;
        else if ('A' <= digit && digit <= 'F')
            digit -= 'A' - 0xA;
        else return -1;
        acc = acc << 4 | digit;
    }

    return acc;
}

int main(void) {
    struct state_8b10b_enc st;

    printf("Comma symbols (RD -/+)\n");
    for (int i=1; i<K_CODES_LAST; i++) {
        st.rd = -1;
        int sym_neg = xfr_8b10b_encode(&st, -i);
        st.rd = +1;
        int sym_pos = xfr_8b10b_encode(&st, -i);
        printf("%s %010b %010b\n", rc_names[i], sym_neg, sym_pos);
    }

    printf("\n");
    printf("Data symbols (RD -/+)\n");
    for (int i=0; i<256; i++) {
        st.rd = -1;
        int sym_neg = xfr_8b10b_encode(&st, i);
        st.rd = +1;
        int sym_pos = xfr_8b10b_encode(&st, i);
        printf("%02x %010b %010b\n", i, sym_neg, sym_pos);
    }

    return 0;
}