forked from 47-studio-org/openbmc-acm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
acm_extra.c
66 lines (58 loc) · 1.62 KB
/
acm_extra.c
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
/*************************************************************************************
(C) Copyright (2012-2021) Hewlett PAckard Enterprise Development LP
\*************************************************************************************
File: acm_extra.c
Objective:
Support functions
**************************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/poll.h>
#include <fcntl.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <systemd/sd-bus.h>
#include <errno.h>
#include "acm.h"
extern ACM_BLK_INDX acm_idx[];
void dumphex(const void *data, int size)
{
char ascii[17];
int i,j;
ascii[16] = '\0';
for(i = 0; i < size; ++i)
{
printf("%02X ", ((unsigned char *)data)[i]);
if(((unsigned char *)data)[i] >= ' ' && ((unsigned char *)data)[i] <= '~')
{
ascii[i % 16] = ((unsigned char *)data)[i];
}
else
{
ascii[i % 16] = '.';
}
if((i+1) % 8 == 0 || i+1 == size)
{
printf(" ");
if((i + 1) % 16 == 0)
{
printf("| %s \n", ascii);
}
else if(i+1 == size)
{
ascii[(i+1) % 16] = '\0';
if((i + 1) % 16 <= 8)
{
printf(" ");
}
for(j = (i+1) % 16; j < 16; ++j)
{
printf(" ");
}
printf("| %s \n", ascii);
}
}
}
}