From f1442dd3619c6478862b52f6ee022b8799a55bfe Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Tue, 17 Jun 2014 16:23:49 +0200 Subject: New macros for Format of Hex and Binary. Signed-off-by: Alexander Wenzel --- examples/README.txt | 1 + include/dlt/dlt_protocol.h | 2 ++ include/dlt/dlt_user.h | 26 ++++++++++++++++++++++++++ include/dlt/dlt_user_macros.h | 12 ++++++++++++ src/lib/dlt_user.c | 16 ++++++++++++++++ 5 files changed, 57 insertions(+) diff --git a/examples/README.txt b/examples/README.txt index fe42331..6599b7c 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -3,3 +3,4 @@ This folder contains several examples of applications using the DLT library. The Example1: Minimal DLT Example Example2: Non Verbose Mode Examples with different AppIdds and normal Strings Example3: Non Verbose Mode Examples with different AppIdds and constant strings +Example4: Different RAW data diff --git a/include/dlt/dlt_protocol.h b/include/dlt/dlt_protocol.h index 09e4adc..1bb5850 100755 --- a/include/dlt/dlt_protocol.h +++ b/include/dlt/dlt_protocol.h @@ -163,6 +163,8 @@ #define DLT_SCOD_ASCII 0x00000000 #define DLT_SCOD_UTF8 0x00008000 +#define DLT_SCOD_HEX 0x00010000 +#define DLT_SCOD_BIN 0x00018000 /* * Definitions of DLT services. diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index 44d1ca1..1ed7b25 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -101,6 +101,20 @@ typedef enum DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */ } DltLogLevelType; +/** + * Definitions of DLT Format + */ +typedef enum +{ + DLT_FORMAT_DEFAULT = 0x00, /**< no sepecial format */ + DLT_FORMAT_HEX8 = 0x01, /**< Hex 8 */ + DLT_FORMAT_HEX16 = 0x02, /**< Hex 16 */ + DLT_FORMAT_HEX32 = 0x03, /**< Hex 32 */ + DLT_FORMAT_HEX64 = 0x04, /**< Hex 64 */ + DLT_FORMAT_BIN8 = 0x05, /**< Binary 8 */ + DLT_FORMAT_BIN16 = 0x06 /**< Binary 16 */ +} DltFormatType; + /** * Definitions of DLT trace status */ @@ -398,6 +412,18 @@ int dlt_user_log_write_utf8_string(DltContextData *log, const char *text); */ int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length); +/** + * Write a binary memory block into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data pointer to the parameter written into log message. + * @param length length in bytes of the parameter written into log message. + * @param type the format information. + * @return negative value if there was an error + */ +int dlt_user_log_write_raw_formated(DltContextData *log,void *data,uint16_t length,DltFormatType type); + /** * Trace network message * @param handle pointer to an object containing information about one special logging context diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h index 8a186ae..a8ceaf4 100644 --- a/include/dlt/dlt_user_macros.h +++ b/include/dlt/dlt_user_macros.h @@ -294,6 +294,18 @@ extern DltContext CONTEXT; */ #define DLT_RAW(BUF,LEN) \ dlt_user_log_write_raw(&log,BUF,LEN) +#define DLT_HEX8(BUF,LEN) \ + dlt_user_log_write_raw_formated(&log,BUF,LEN,DLT_FORMAT_HEX8) +#define DLT_HEX16(BUF,LEN) \ + dlt_user_log_write_raw_formated(&log,BUF,LEN,DLT_FORMAT_HEX16) +#define DLT_HEX32(BUF,LEN) \ + dlt_user_log_write_raw_formated(&log,BUF,LEN,DLT_FORMAT_HEX32) +#define DLT_HEX64(BUF,LEN) \ + dlt_user_log_write_raw_formated(&log,BUF,LEN,DLT_FORMAT_HEX64) +#define DLT_BIN8(BUF,LEN) \ + dlt_user_log_write_raw_formated(&log,BUF,LEN,DLT_FORMAT_BIN8) +#define DLT_BIN16(BUF,LEN) \ + dlt_user_log_write_raw_formated(&log,BUF,LEN,DLT_FORMAT_BIN16) /** * Trace network message diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index bf63ed7..1ad4335 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -1301,6 +1301,11 @@ int dlt_user_log_write_finish(DltContextData *log) } int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length) +{ + return dlt_user_log_write_raw_formated(log,data,length,DLT_FORMAT_DEFAULT); +} + +int dlt_user_log_write_raw_formated(DltContextData *log,void *data,uint16_t length,DltFormatType type) { uint16_t arg_size; uint32_t type_info; @@ -1325,6 +1330,17 @@ int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length) /* Transmit type information */ type_info = DLT_TYPE_INFO_RAWD; + if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64) + { + type_info |= DLT_SCOD_HEX; + type_info += type; + } + else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16) + { + type_info |= DLT_SCOD_BIN; + type_info += type - DLT_FORMAT_BIN8 + 1; + } + memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); log->size += sizeof(uint32_t); -- cgit v1.2.1