1238603Sjoerg/* ---------------------------------------------------------------------------- 2238603Sjoerg * "THE BEER-WARE LICENSE" (Revision 42) (by Poul-Henning Kamp): 3238603Sjoerg * <joerg@FreeBSD.ORG> wrote this file. As long as you retain this notice you 4238603Sjoerg * can do whatever you want with this stuff. If we meet some day, and you think 5238603Sjoerg * this stuff is worth it, you can buy me a beer in return. Joerg Wunsch 6238603Sjoerg * ---------------------------------------------------------------------------- 7238603Sjoerg * 8238603Sjoerg * $FreeBSD$ 9238603Sjoerg */ 10238603Sjoerg 11238603Sjoerg/* 12238603Sjoerg * Helper functions common to all examples 13238603Sjoerg */ 14238603Sjoerg 15238603Sjoerg#include <stdio.h> 16238603Sjoerg#include <stdint.h> 17238603Sjoerg#include <stdlib.h> 18238603Sjoerg 19238603Sjoerg#include <libusb20.h> 20238603Sjoerg#include <libusb20_desc.h> 21238603Sjoerg 22257779Shselasky#include "util.h" 23238603Sjoerg 24238603Sjoerg/* 25238603Sjoerg * Print "len" bytes from "buf" in hex, followed by an ASCII 26238603Sjoerg * representation (somewhat resembling the output of hd(1)). 27238603Sjoerg */ 28238603Sjoergvoid 29238603Sjoergprint_formatted(uint8_t *buf, uint32_t len) 30238603Sjoerg{ 31238603Sjoerg int i, j; 32238603Sjoerg 33238603Sjoerg for (j = 0; j < len; j += 16) 34238603Sjoerg { 35238603Sjoerg printf("%02x: ", j); 36238603Sjoerg 37238603Sjoerg for (i = 0; i < 16 && i + j < len; i++) 38238603Sjoerg printf("%02x ", buf[i + j]); 39238603Sjoerg printf(" "); 40238603Sjoerg for (i = 0; i < 16 && i + j < len; i++) 41238603Sjoerg { 42238603Sjoerg uint8_t c = buf[i + j]; 43238603Sjoerg if(c >= ' ' && c <= '~') 44238603Sjoerg printf("%c", (char)c); 45238603Sjoerg else 46238603Sjoerg putchar('.'); 47238603Sjoerg } 48238603Sjoerg putchar('\n'); 49238603Sjoerg } 50238603Sjoerg} 51