log.c
static void print_line(const uint8_t *buf, size_t line_size,
                       size_t line_number)
{
  /* Buffers to hold whole line of bytes representation */

  char hex_data[LOG_HEX_DATA_SIZE + 1] = {0};
  char char_data[LOG_CHAR_DATA_SIZE + 1] = {0};

  /* Calculate buf address value */

  const unsigned int ADDRESS = LOG_LINE_SIZE * line_number;

  /* Fill data buffers with bytes represenations */

  for (size_t char_num = 0; char_num < line_size; ++char_num)
    {
      unsigned char current_byte = (char)*buf++;
      char *current_hex_pos = hex_data + char_num * LOG_SINGLE_HEX_DATA_SIZE;
      char *current_char_pos = char_data + char_num;

      sprintf(current_hex_pos, "%02x ", current_byte);

      /* Check if current_byte is printable or not */

      if (current_byte < 0x20 || current_byte >= 0x7f)
        {
          current_byte = '.';
        }

      *current_char_pos = current_byte;
    }

  /* Print single line to stderr */

  fprintf(stderr, "0x%04x: %-*s %s\n", ADDRESS, LOG_HEX_DATA_SIZE, hex_data,
          char_data);
}
/*****************************************************************************
 * Name: print_line
 *
 * Description:
 *   Prints line_size bytes of buf prefixed by line_number in a nice format
 *
 * Input Parameters:
 *   buf        : Pointer to memory to print
 *   line_size  : How many bytes from buf to print
 *   line_number: Line number to prefix line with
 ****************************************************************************/
print_line
Description:
Prints line_size bytes of buf prefixed by line_number in a nice format

Input Parameters:
buf        : Pointer to memory to print
line_size  : How many bytes from buf to print
line_number: Line number to prefix line with
print_line Description : Prints line_size bytes of buf prefixed by line_number in a nice format Input Parameters : buf : Pointer to memory to print line_size : How many bytes from buf to print line_number : Line number to prefix line with
static void print_line(const uint8_t *buf, size_t line_size,
                       size_t line_number)
{
  char hex_data[LOG_HEX_DATA_SIZE + 1] = {0};
  char char_data[LOG_CHAR_DATA_SIZE + 1] = {0};
  const unsigned int ADDRESS = LOG_LINE_SIZE * line_number;
  for (size_t char_num = 0; char_num < line_size; ++char_num)
    {
      unsigned char current_byte = (char)*buf++;
      char *current_hex_pos = hex_data + char_num * LOG_SINGLE_HEX_DATA_SIZE;
      char *current_char_pos = char_data + char_num;
      sprintf(current_hex_pos, "%02x ", current_byte);
      if (current_byte < 0x20 || current_byte >= 0x7f)
        {
          current_byte = '.';
        }
      *current_char_pos = current_byte;
    }
  fprintf(stderr, "0x%04x: %-*s %s\n", ADDRESS, LOG_HEX_DATA_SIZE, hex_data,
          char_data);
}
static void print_line ( const uint8_t * buf , size_t line_size , size_t line_number ) { char hex_data [ LOG_HEX_DATA_SIZE + 1 ] = { 0 } ; char char_data [ LOG_CHAR_DATA_SIZE + 1 ] = { 0 } ; const unsigned int ADDRESS = LOG_LINE_SIZE * line_number ; for ( size_t char_num = 0 ; char_num < line_size ; ++ char_num ) { unsigned char current_byte = ( char ) * buf ++ ; char * current_hex_pos = hex_data + char_num * LOG_SINGLE_HEX_DATA_SIZE ; char * current_char_pos = char_data + char_num ; sprintf ( current_hex_pos , " " , current_byte ) ; if ( current_byte < 0x20 || current_byte >= 0x7f ) { current_byte = ' ' ; } * current_char_pos = current_byte ; } fprintf ( stderr , " \n " , ADDRESS , LOG_HEX_DATA_SIZE , hex_data , char_data ) ; }
Name: print_line
 Description:
   Prints line_size bytes of buf prefixed by line_number in a nice format
Name : print_line Description : Prints line_size bytes of buf prefixed by line_number in a nice format
/* Buffers to hold whole line of bytes representation */ /* Calculate buf address value */ /* Fill data buffers with bytes represenations */ /* Check if current_byte is printable or not */ /* Print single line to stderr */