MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / dump_hex

Function dump_hex

src/debug.c:82–125  ·  view source on GitHub ↗

* \brief Do a hex dump of the unsigned char array. * * \param ptr Pointer to a character array. * \param size Number of chars to words to dump. * * Prints the hex dump to `stderr` via rig_debug(): * * ``` * 0000 4b 30 30 31 34 35 30 30 30 30 30 30 30 35 30 32 K001450000000502 * 0010 30 30 0d 0a 00.. * ``` */

Source from the content-addressed store, hash-verified

80 * ```
81 */
82void dump_hex(const unsigned char ptr[], size_t size)
83{
84 /* example
85 * 0000 4b 30 30 31 34 35 30 30 30 30 30 30 30 35 30 32 K001450000000502
86 * 0010 30 30 0d 0a 00..
87 */
88 char line[4 + 4 + 3 * DUMP_HEX_WIDTH + 4 + DUMP_HEX_WIDTH + 1];
89 int i;
90
91 if (!rig_need_debug(RIG_DEBUG_TRACE))
92 {
93 return;
94 }
95
96 line[sizeof(line) - 1] = '\0';
97
98 for (i = 0; i < size; ++i)
99 {
100 unsigned char c;
101
102 if (i % DUMP_HEX_WIDTH == 0)
103 {
104 /* new line */
105 SNPRINTF(line + 0, sizeof(line), "%04x", i);
106 memset(line + 4, ' ', sizeof(line) - 4 - 1);
107 }
108
109 c = ptr[i];
110
111 /* hex print */
112 sprintf(line + 8 + 3 * (i % DUMP_HEX_WIDTH), "%02x", c);
113 line[8 + 3 * (i % DUMP_HEX_WIDTH) + 2] = ' '; /* no \0 */
114
115 /* ascii print */
116 line[8 + 3 * DUMP_HEX_WIDTH + 4 + (i % DUMP_HEX_WIDTH)] = (c >= ' '
117 && c < 0x7f) ? c : '.';
118
119 /* actually print the line */
120 if (i + 1 == size || (i && i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH - 1))
121 {
122 rig_debug(RIG_DEBUG_TRACE, "%s\n", line);
123 }
124 }
125}
126
127/*! @} */
128

Callers 15

tci1x_openFunction · 0.85
micom_read_frameFunction · 0.85
codan_transactionFunction · 0.85
xiegu_rig_openFunction · 0.85
icom_one_transactionFunction · 0.85
icf8101_get_split_vfoFunction · 0.85
ft817_get_freqFunction · 0.85
frameParseFunction · 0.85
frameParseFunction · 0.85
frameParseFunction · 0.85
frameParseFunction · 0.85
frameParseFunction · 0.85

Calls 2

rig_need_debugFunction · 0.85
rig_debugFunction · 0.85

Tested by

no test coverage detected