Skip to content

Commit fff5caa

Browse files
authored
Add verbose mode attribute handling (COVESA#292)
dlt_user_log_write_*_attr() enables to writing these types, but also support adding "attributes" for them, i.e. a "name" and a "unit". Signed-off-by: Martin Willers <[email protected]>
1 parent 87eb30a commit fff5caa

File tree

7 files changed

+1376
-531
lines changed

7 files changed

+1376
-531
lines changed

Diff for: doc/dlt_for_developers.md

+33
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,19 @@ if (dlt_user_log_write_start(&ctx, &ctxdata, DLT_LOG_INFO) > 0) {
631631
}
632632
```
633633

634+
#### Attributes
635+
636+
In verbose mode, log message arguments can contain attributes. A "name" attribute
637+
describes the purpose or semantics of an argument, and a "unit" attribute
638+
describes its unit (if applicable - not all argument data types support having
639+
a "unit" attribute).
640+
641+
```
642+
dlt_user_log_write_float64_attr(&myctxdata, 4.2, "speed", "m/s");
643+
```
644+
645+
In non-verbose mode, these attributes are not added to the message.
646+
634647
### Logging parameters
635648

636649
The following parameter types can be used. Multiple parameters can be added to
@@ -640,25 +653,45 @@ exceed 1390 bytes, including the DLT message header.
640653
Type | Description
641654
--- | ---
642655
DLT\_STRING(TEXT) | String
656+
DLT\_STRING\_ATTR(TEXT,NAME) | String (with attribute)
643657
DLT\_SIZED\_STRING(TEXT,LENGTH) | String with known length
658+
DLT\_SIZED\_STRING\_ATTR(TEXT,LENGTH,NAME) | String with known length (with attribute)
644659
DLT\_CSTRING(TEXT) | Constant string (not sent in non-verbose mode)
660+
DLT\_CSTRING\_ATTR(TEXT,NAME) | Constant string (with attribute; not sent in non-verbose mode)
645661
DLT\_SIZED\_CSTRING(TEXT,LENGTH) | Constant string with known length (not sent in non-verbose mode)
662+
DLT\_SIZED\_CSTRING\_ATTR(TEXT,LENGTH,NAME) | Constant string with known length (with attribute; not sent in non-verbose mode)
646663
DLT\_UTF8(TEXT) | Utf8-encoded string
664+
DLT\_UTF8\_ATTR(TEXT,NAME) | Utf8-encoded string (with attribute)
647665
DLT\_SIZED\_UTF8(TEXT,LENGTH) | Utf8-encoded string with known length
666+
DLT\_SIZED\_UTF8\_ATTR(TEXT,LENGTH,NAME) | Utf8-encoded string with known length (with attribute)
648667
DLT\_RAW(BUF,LENGTH) | Raw buffer
668+
DLT\_RAW\_ATTR(BUF,LENGTH,NAME) | Raw buffer (with attribute)
649669
DLT\_INT(VAR) | Integer variable, dependent on platform
670+
DLT\_INT\_ATTR(VAR,NAME,UNIT) | Integer variable, dependent on platform (with attributes)
650671
DLT\_INT8(VAR) |Integer 8 Bit variable
672+
DLT\_INT8\_ATTR(VAR,NAME,UNIT) |Integer 8 Bit variable (with attributes)
651673
DLT\_INT16(VAR) | Integer 16 Bit variable
674+
DLT\_INT16\_ATTR(VAR,NAME,UNIT) | Integer 16 Bit variable (with attributes)
652675
DLT\_INT32(VAR) | Integer 32 Bit variable
676+
DLT\_INT32\_ATTR(VAR,NAME,UNIT) | Integer 32 Bit variable (with attributes)
653677
DLT\_INT64(VAR) | Integer 64 bit variable
678+
DLT\_INT64\_ATTR(VAR,NAME,UNIT) | Integer 64 bit variable (with attributes)
654679
DLT\_UINT(VAR) | Unsigned integer variable
680+
DLT\_UINT\_ATTR(VAR,NAME,UNIT) | Unsigned integer variable (with attributes)
655681
DLT\_UINT8(VAR) | Unsigned 8 Bit integer variable
682+
DLT\_UINT8\_ATTR(VAR,NAME,UNIT) | Unsigned 8 Bit integer variable (with attributes)
656683
DLT\_UINT16(VAR) |Unsigned 16 Bit integer variable
684+
DLT\_UINT16\_ATTR(VAR,NAME,UNIT) |Unsigned 16 Bit integer variable (with attributes)
657685
DLT\_UINT32(VAR) | Unsigned 32 Bit integer variable
686+
DLT\_UINT32\_ATTR(VAR,NAME,UNIT) | Unsigned 32 Bit integer variable (with attributes)
658687
DLT\_UINT64(VAR) | Unsigned 64 bit integer variable
688+
DLT\_UINT64\_ATTR(VAR,NAME,UNIT) | Unsigned 64 bit integer variable (with attributes)
659689
DLT\_BOOL(VAR) | Boolean variable
690+
DLT\_BOOL\_ATTR(VAR,NAME) | Boolean variable (with attribute)
660691
DLT\_FLOAT32(VAR) | Float 32 Bit variable
692+
DLT\_FLOAT32\_ATTR(VAR,NAME,UNIT) | Float 32 Bit variable (with attributes)
661693
DLT\_FLOAT64(VAR) | Float 64 Bit variable
694+
DLT\_FLOAT64\_ATTR(VAR,NAME,UNIT) | Float 64 Bit variable (with attributes)
662695
DLT\_HEX8(UINT\_VAR) | 8 Bit hex value
663696
DLT\_HEX16(UINT\_VAR) | 16 Bit hex value
664697
DLT\_HEX32(UINT\_VAR) | 32 Bit hex value

Diff for: include/dlt/dlt_common.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

7676
# include <netinet/in.h>
7777
# include <stdio.h>
78+
# include <stdbool.h>
7879
# ifdef __linux__
7980
# include <linux/limits.h>
8081
# include <sys/socket.h>
@@ -89,8 +90,10 @@
8990

9091
# if defined(__GNUC__)
9192
# define PURE_FUNCTION __attribute__((pure))
93+
# define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, a, b)))
9294
# else
9395
# define PURE_FUNCTION /* nothing */
96+
# define PRINTF_FORMAT(a,b) /* nothing */
9497
# endif
9598

9699
# if !defined (__WIN32__) && !defined(_MSC_VER)
@@ -1170,6 +1173,13 @@ void dlt_log_set_fifo_basedir(const char *pipe_dir);
11701173
* @param level the level
11711174
*/
11721175
void dlt_log_set_level(int level);
1176+
1177+
/**
1178+
* Set whether to print "name" and "unit" attributes in console output
1179+
* @param state true = with attributes, false = without attributes
1180+
*/
1181+
void dlt_print_with_attributes(bool state);
1182+
11731183
/**
11741184
* Initialize (external) logging facility
11751185
* @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file, 3 = log to stderr
@@ -1180,7 +1190,7 @@ void dlt_log_init(int mode);
11801190
* @param format format string for message
11811191
* @return negative value if there was an error or the total number of characters written is returned on success
11821192
*/
1183-
int dlt_user_printf(const char *format, ...);
1193+
int dlt_user_printf(const char *format, ...) PRINTF_FORMAT(1,2);
11841194
/**
11851195
* Log ASCII string with null-termination to (external) logging facility
11861196
* @param prio priority (see syslog() call)

Diff for: include/dlt/dlt_user.h.in

+216
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,21 @@ DltReturnValue dlt_user_log_write_finish(DltContextData *log);
313313
*/
314314
DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data);
315315

316+
/**
317+
* Write a boolean parameter with "name" attribute into a DLT log message.
318+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
319+
* Finish building a log message by calling dlt_user_log_write_finish.
320+
*
321+
* If @a name is NULL, this function will add an attribute field with length 0
322+
* and no content to the message.
323+
*
324+
* @param log pointer to an object containing information about logging context data
325+
* @param data boolean parameter written into log message (mapped to uint8)
326+
* @param name the "name" attribute (or NULL)
327+
* @return value from DltReturnValue enum
328+
*/
329+
DltReturnValue dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name);
330+
316331
/**
317332
* Write a float parameter into a DLT log message.
318333
* dlt_user_log_write_start has to be called before adding any attributes to the log message.
@@ -333,6 +348,38 @@ DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data);
333348
*/
334349
DltReturnValue dlt_user_log_write_float64(DltContextData *log, double data);
335350

351+
/**
352+
* Write a float parameter with attributes into a DLT log message.
353+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
354+
* Finish building a log message by calling dlt_user_log_write_finish.
355+
*
356+
* If @a name or @a unit is NULL, this function will add a corresponding attribute field with length 0
357+
* and no content to the message for that attribute.
358+
*
359+
* @param log pointer to an object containing information about logging context data
360+
* @param data float32_t parameter written into log message
361+
* @param name the "name" attribute (or NULL)
362+
* @param unit the "unit" attribute (or NULL)
363+
* @return value from DltReturnValue enum
364+
*/
365+
DltReturnValue dlt_user_log_write_float32_attr(DltContextData *log, float32_t data, const char *name, const char *unit);
366+
367+
/**
368+
* Write a double parameter with attributes into a DLT log message.
369+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
370+
* Finish building a log message by calling dlt_user_log_write_finish.
371+
*
372+
* If @a name or @a unit is NULL, this function will add a corresponding attribute field with length 0
373+
* and no content to the message for that attribute.
374+
*
375+
* @param log pointer to an object containing information about logging context data
376+
* @param data float64_t parameter written into log message
377+
* @param name the "name" attribute (or NULL)
378+
* @param unit the "unit" attribute (or NULL)
379+
* @return value from DltReturnValue enum
380+
*/
381+
DltReturnValue dlt_user_log_write_float64_attr(DltContextData *log, float64_t data, const char *name, const char *unit);
382+
336383
/**
337384
* Write a uint parameter into a DLT log message.
338385
* dlt_user_log_write_start has to be called before adding any attributes to the log message.
@@ -347,6 +394,26 @@ DltReturnValue dlt_user_log_write_uint16(DltContextData *log, uint16_t data);
347394
DltReturnValue dlt_user_log_write_uint32(DltContextData *log, uint32_t data);
348395
DltReturnValue dlt_user_log_write_uint64(DltContextData *log, uint64_t data);
349396

397+
/**
398+
* Write a uint parameter with attributes into a DLT log message.
399+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
400+
* Finish building a log message by calling dlt_user_log_write_finish.
401+
*
402+
* If @a name or @a unit is NULL, this function will add a corresponding attribute field with length 0
403+
* and no content to the message for that attribute.
404+
*
405+
* @param log pointer to an object containing information about logging context data
406+
* @param data unsigned int parameter written into log message
407+
* @param name the "name" attribute (or NULL)
408+
* @param unit the "unit" attribute (or NULL)
409+
* @return value from DltReturnValue enum
410+
*/
411+
DltReturnValue dlt_user_log_write_uint_attr(DltContextData *log, unsigned int data, const char *name, const char *unit);
412+
DltReturnValue dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char *unit);
413+
DltReturnValue dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit);
414+
DltReturnValue dlt_user_log_write_uint32_attr(DltContextData *log, uint32_t data, const char *name, const char *unit);
415+
DltReturnValue dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit);
416+
350417
/**
351418
* Write a uint parameter into a DLT log message. The output will be formatted as given by the parameter type.
352419
* dlt_user_log_write_start has to be called before adding any attributes to the log message.
@@ -384,6 +451,27 @@ DltReturnValue dlt_user_log_write_int8(DltContextData *log, int8_t data);
384451
DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data);
385452
DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data);
386453
DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data);
454+
455+
/**
456+
* Write an int parameter with attributes into a DLT log message.
457+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
458+
* Finish building a log message by calling dlt_user_log_write_finish.
459+
*
460+
* If @a name or @a unit is NULL, this function will add a corresponding attribute field with length 0
461+
* and no content to the message for that attribute.
462+
*
463+
* @param log pointer to an object containing information about logging context data
464+
* @param data int parameter written into log message
465+
* @param name the "name" attribute (or NULL)
466+
* @param unit the "unit" attribute (or NULL)
467+
* @return value from DltReturnValue enum
468+
*/
469+
DltReturnValue dlt_user_log_write_int_attr(DltContextData *log, int data, const char *name, const char *unit);
470+
DltReturnValue dlt_user_log_write_int8_attr(DltContextData *log, int8_t data, const char *name, const char *unit);
471+
DltReturnValue dlt_user_log_write_int16_attr(DltContextData *log, int16_t data, const char *name, const char *unit);
472+
DltReturnValue dlt_user_log_write_int32_attr(DltContextData *log, int32_t data, const char *name, const char *unit);
473+
DltReturnValue dlt_user_log_write_int64_attr(DltContextData *log, int64_t data, const char *name, const char *unit);
474+
387475
/**
388476
* Write a null terminated ASCII string into a DLT log message.
389477
* dlt_user_log_write_start has to be called before adding any attributes to the log message.
@@ -449,6 +537,101 @@ DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *t
449537
*/
450538
DltReturnValue dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length);
451539

540+
/**
541+
* Write a null-terminated ASCII string with "name" attribute into a DLT log message.
542+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
543+
* Finish building a log message by calling dlt_user_log_write_finish.
544+
*
545+
* If @a name is NULL, this function will add an attribute field with length 0
546+
* and no content to the message.
547+
*
548+
* @param log pointer to an object containing information about logging context data
549+
* @param text pointer to the parameter written into log message containing null termination
550+
* @param name the "name" attribute (or NULL)
551+
* @return value from DltReturnValue enum
552+
*/
553+
DltReturnValue dlt_user_log_write_string_attr(DltContextData *log, const char *text, const char *name);
554+
555+
/**
556+
* Write a potentially non-null-terminated ASCII string with "name" attribute into a DLT log message.
557+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
558+
* Finish building a log message by calling dlt_user_log_write_finish.
559+
*
560+
* If @a name is NULL, this function will add an attribute field with length 0
561+
* and no content to the message.
562+
*
563+
* @param log pointer to an object containing information about logging context data
564+
* @param text pointer to the parameter written into log message
565+
* @param length length in bytes of @a text (without any termination character)
566+
* @param name the "name" attribute (or NULL)
567+
* @return value from DltReturnValue enum
568+
*/
569+
DltReturnValue dlt_user_log_write_sized_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name);
570+
571+
/**
572+
* Write a constant, null-terminated ASCII string with "name" attribute into a DLT log message.
573+
* In non-verbose mode, this parameter will not be sent at all.
574+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
575+
* Finish building a log message by calling dlt_user_log_write_finish.
576+
*
577+
* If @a name is NULL, this function will add an attribute field with length 0
578+
* and no content to the message.
579+
*
580+
* @param log pointer to an object containing information about logging context data
581+
* @param text pointer to the parameter written into log message containing null termination
582+
* @param name the "name" attribute (or NULL)
583+
* @return value from DltReturnValue enum
584+
*/
585+
DltReturnValue dlt_user_log_write_constant_string_attr(DltContextData *log, const char *text, const char *name);
586+
587+
/**
588+
* Write a constant, potentially non-null-terminated ASCII string with "name" attribute into a DLT log message.
589+
* In non-verbose mode, this parameter will not be sent at all.
590+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
591+
* Finish building a log message by calling dlt_user_log_write_finish.
592+
*
593+
* If @a name is NULL, this function will add an attribute field with length 0
594+
* and no content to the message.
595+
*
596+
* @param log pointer to an object containing information about logging context data
597+
* @param text pointer to the parameter written into log message containing null termination
598+
* @param length length in bytes of @a text (without any termination character)
599+
* @param name the "name" attribute (or NULL)
600+
* @return value from DltReturnValue enum
601+
*/
602+
DltReturnValue dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name);
603+
604+
/**
605+
* Write a null-terminated UTF-8 string with "name" attribute into a DLT log message.
606+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
607+
* Finish building a log message by calling dlt_user_log_write_finish.
608+
*
609+
* If @a name is NULL, this function will add an attribute field with length 0
610+
* and no content to the message.
611+
*
612+
* @param log pointer to an object containing information about logging context data
613+
* @param text pointer to the parameter written into log message containing null termination
614+
* @param name the "name" attribute (or NULL)
615+
* @return value from DltReturnValue enum
616+
*/
617+
DltReturnValue dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name);
618+
619+
/**
620+
* Write a potentially non-null-terminated UTF-8 string with "name" attribute into a DLT log message.
621+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
622+
* Finish building a log message by calling dlt_user_log_write_finish.
623+
*
624+
* If @a name is NULL, this function will add an attribute field with length 0
625+
* and no content to the message.
626+
*
627+
* @param log pointer to an object containing information about logging context data
628+
* @param text pointer to the parameter written into log message
629+
* @param length length in bytes of @a text (without any termination character)
630+
* @param name the "name" attribute (or NULL)
631+
* @return value from DltReturnValue enum
632+
*/
633+
DltReturnValue dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name);
634+
452635
/**
453636
* Write a binary memory block into a DLT log message.
454637
* dlt_user_log_write_start has to be called before adding any attributes to the log message.
@@ -472,6 +655,39 @@ DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t
472655
*/
473656
DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, uint16_t length, DltFormatType type);
474657

658+
/**
659+
* Write a binary memory block with "name" attribute into a DLT log message.
660+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
661+
* Finish building a log message by calling dlt_user_log_write_finish.
662+
*
663+
* If @a name is NULL, this function will add an attribute field with length 0
664+
* and no content to the message.
665+
*
666+
* @param log pointer to an object containing information about logging context data
667+
* @param data pointer to the parameter written into log message.
668+
* @param length length in bytes of the parameter written into log message
669+
* @param name the "name" attribute (or NULL)
670+
* @return value from DltReturnValue enum
671+
*/
672+
DltReturnValue dlt_user_log_write_raw_attr(DltContextData *log, const void *data, uint16_t length, const char *name);
673+
674+
/**
675+
* Write a binary memory block with "name" attribute into a DLT log message.
676+
* dlt_user_log_write_start has to be called before adding any parameters to the log message.
677+
* Finish building a log message by calling dlt_user_log_write_finish.
678+
*
679+
* If @a name is NULL, this function will add an attribute field with length 0
680+
* and no content to the message.
681+
*
682+
* @param log pointer to an object containing information about logging context data
683+
* @param data pointer to the parameter written into log message.
684+
* @param length length in bytes of the parameter written into log message
685+
* @param type the format information
686+
* @param name the "name" attribute (or NULL)
687+
* @return value from DltReturnValue enum
688+
*/
689+
DltReturnValue dlt_user_log_write_raw_formatted_attr(DltContextData *log, const void *data, uint16_t length, DltFormatType type, const char *name);
690+
475691
/**
476692
* Trace network message
477693
* @param handle pointer to an object containing information about one special logging context

0 commit comments

Comments
 (0)