comparison simtool/hlread.c @ 7:4360a7906f34

reversed nibbles parsing functions factored out into libcommon
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 23:56:13 +0000
parents 2071b28cd0c7
children 4c570522de5d
comparison
equal deleted inserted replaced
6:2c72709e0891 7:4360a7906f34
2 * This module implements some high-level or user-friendly read commands. 2 * This module implements some high-level or user-friendly read commands.
3 */ 3 */
4 4
5 #include <sys/types.h> 5 #include <sys/types.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "simresp.h" 7 #include "simresp.h"
9 #include "curfile.h" 8 #include "curfile.h"
10 #include "file_id.h" 9 #include "file_id.h"
11
12 encode_hex_digit(d)
13 unsigned d;
14 {
15 if (d <= 9)
16 return(d + '0');
17 else
18 return(d - 10 + 'A');
19 }
20
21 decode_reversed_nibbles(bytes, nbytes, dest)
22 u_char *bytes;
23 unsigned nbytes;
24 char *dest;
25 {
26 u_char *sp;
27 char *dp;
28 unsigned n, c;
29
30 sp = bytes;
31 dp = dest;
32 for (n = 0; n < nbytes; n++) {
33 c = *sp & 0xF;
34 *dp++ = encode_hex_digit(c);
35 c = *sp >> 4;
36 *dp++ = encode_hex_digit(c);
37 sp++;
38 }
39 }
40 10
41 cmd_iccid() 11 cmd_iccid()
42 { 12 {
43 int rc; 13 int rc;
44 char buf[21]; 14 char buf[21];