Skip to content

File syn_uds_util.c

FileList > proto > syn_uds_util.c

Go to the source code of this file

SAE J2012 / ISO 15031-6 UDS Diagnostic Trouble Code (DTC) Utilities Implementation.

  • #include "syntropic/proto/syn_uds_util.h"
  • #include "syntropic/util/syn_fmt.h"
  • #include <ctype.h>
  • #include <string.h>

Public Functions

Type Name
bool syn_uds_dtc_from_str (const char * str, uint32_t * dtc_out)
Parse a 5, 6, or 7-character SAE J2012 DTC string into a 24-bit UDS integer.
bool syn_uds_dtc_to_str (uint32_t dtc, char * out_buf, size_t buf_size)
Format a 24-bit UDS integer into a standard SAE J2012 DTC display string.

Public Static Functions

Type Name
int hex_char_to_nibble (char c)
Convert single hex character to 4-bit nibble value.

Public Functions Documentation

function syn_uds_dtc_from_str

Parse a 5, 6, or 7-character SAE J2012 DTC string into a 24-bit UDS integer.

bool syn_uds_dtc_from_str (
    const char * str,
    uint32_t * dtc_out
) 

Accepts strings like: * "P0105" or "P010500" -> 0x010500 * "B111717" -> 0x911717 * "U013100" -> 0xC13100 * "C101000" -> 0x501000

Case-insensitive for prefix (p/c/b/u or P/C/B/U) and hex digits.

Parameters:

  • str Null-terminated SAE J2012 DTC string.
  • dtc_out [out] Destination for parsed 24-bit DTC value.

Returns:

true if successfully parsed, false on invalid format.


function syn_uds_dtc_to_str

Format a 24-bit UDS integer into a standard SAE J2012 DTC display string.

bool syn_uds_dtc_to_str (
    uint32_t dtc,
    char * out_buf,
    size_t buf_size
) 

Formats values like: * 0x010500 -> "P010500" * 0x911717 -> "B111717" * 0xC13100 -> "U013100"

Buffer must have a capacity of at least 8 bytes (7 chars + null terminator).

Parameters:

  • dtc 24-bit UDS DTC integer value.
  • out_buf Destination string buffer.
  • buf_size Capacity of output buffer (minimum 8 bytes).

Returns:

true if formatted successfully, false if buffer too small or NULL.


Public Static Functions Documentation

function hex_char_to_nibble

Convert single hex character to 4-bit nibble value.

static int hex_char_to_nibble (
    char c
) 

Parameters:

  • c Input character ('0'-'9', 'a'-'f', 'A'-'F').

Returns:

Nibble value (0-15), or -1 if invalid hex char.



The documentation for this class was generated from the following file src/syntropic/proto/syn_uds_util.c