FreeCalypso > hg > freecalypso-sw
comparison rvinterf/trdump.c @ 126:811b138f1bed
rvtdump utility written, compiles
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 31 Oct 2013 19:59:16 +0000 |
parents | |
children | f4f0c8738dcb |
comparison
equal
deleted
inserted
replaced
125:17c1e2a38418 | 126:811b138f1bed |
---|---|
1 /* | |
2 * This module implements the basic dump of any incoming packets | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include "pktmux.h" | |
8 | |
9 extern u_char rxpkt[]; | |
10 extern size_t rxpkt_len; | |
11 | |
12 void | |
13 print_presumed_string(str, len) | |
14 u_char *str; | |
15 size_t len; | |
16 { | |
17 int i, c; | |
18 | |
19 for (i = 0; i < len; i++) { | |
20 c = str[i]; | |
21 if (c & 0x80) { | |
22 putchar('M'); | |
23 putchar('-'); | |
24 c &= 0x7F; | |
25 } | |
26 if (c < 0x20) { | |
27 putchar('^'); | |
28 putchar(c + '@'); | |
29 } else if (c == 0x7F) { | |
30 putchar('^'); | |
31 putchar('?'); | |
32 } else | |
33 putchar(c); | |
34 } | |
35 } | |
36 | |
37 void | |
38 print_rv_trace() | |
39 { | |
40 int i; | |
41 | |
42 /* the SWE static ID is sent MSB first */ | |
43 for (i = 1; i <= 4; i++) | |
44 printf("%02X", rxpkt[i]); | |
45 /* severity level */ | |
46 printf(" %d ", rxpkt[5]); | |
47 print_presumed_string(rxpkt + 6, rxpkt_len - 6); | |
48 putchar('\n'); | |
49 } | |
50 | |
51 void | |
52 print_l1_trace() | |
53 { | |
54 fputs("L1: ", stdout); | |
55 print_presumed_string(rxpkt + 1, rxpkt_len - 1); | |
56 putchar('\n'); | |
57 } | |
58 | |
59 void | |
60 print_rx_packet() | |
61 { | |
62 int i; | |
63 | |
64 switch (rxpkt[0]) { | |
65 case RVT_RV_HEADER: | |
66 print_rv_trace(); | |
67 return; | |
68 case RVT_L1_HEADER: | |
69 print_l1_trace(); | |
70 return; | |
71 } | |
72 /* default case: print the whole packet in hex as an unknown */ | |
73 fputs("UNK:", stdout); | |
74 for (i = 0; i < rxpkt_len; i++) | |
75 printf(" %02X", rxpkt[i]); | |
76 putchar('\n'); | |
77 } |