summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/example4/example4.c27
-rw-r--r--include/dlt/dlt_user.h17
-rw-r--r--include/dlt/dlt_user_macros.h24
-rw-r--r--src/lib/dlt_user.c184
-rwxr-xr-xsrc/shared/dlt_common.c74
5 files changed, 303 insertions, 23 deletions
diff --git a/examples/example4/example4.c b/examples/example4/example4.c
index 0614c2e..4b7d862 100644
--- a/examples/example4/example4.c
+++ b/examples/example4/example4.c
@@ -65,23 +65,36 @@ int main()
DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_RAW"));
DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_RAW(buffer,256));
+ uint8_t uint8data = 0x2a;
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_UINT8"));
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_UINT8(uint8data));
+
+ uint8_t hex8data = 0x1a;
DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_HEX8"));
- DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX8(buffer,256));
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX8(hex8data));
+ uint16_t hex16data = 0x1ad3;
DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_HEX16"));
- DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX16(buffer,256));
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX16(hex16data));
+ uint32_t hex32data = 0x1abcd3e4;
DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_HEX32"));
- DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX32(buffer,256));
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX32(hex32data));
+ uint64_t hex64data = 0x17b4ddcf34eabb2a;
DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_HEX64"));
- DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX64(buffer,256));
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_HEX64(hex64data));
- DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_BIN8"));
- DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_BIN8(buffer,256));
+ uint8_t bin8data = 0xe2;
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_BIN8"));
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_BIN8(bin8data));
+ bin8data = 0x01;
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_BIN8"));
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_BIN8(bin8data));
+ uint16_t bin16data = 0x1234;
DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_STRING("DLT_BIN16"));
- DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_BIN16(buffer,256));
+ DLT_LOG(con_exa1,DLT_LOG_INFO,DLT_BIN16(bin16data));
usleep(1000);
diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h
index 8b088a8..10de203 100644
--- a/include/dlt/dlt_user.h
+++ b/include/dlt/dlt_user.h
@@ -361,6 +361,21 @@ int dlt_user_log_write_uint8(DltContextData *log, uint8_t data);
int dlt_user_log_write_uint16(DltContextData *log, uint16_t data);
int dlt_user_log_write_uint32(DltContextData *log, uint32_t data);
int dlt_user_log_write_uint64(DltContextData *log, uint64_t data);
+
+/**
+ * Write a uint parameter into a DLT log message. The output will be formatted as given by the parameter type.
+ * 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 unsigned int parameter written into log message.
+ * @param type The formatting type of the string output.
+ * @return negative value if there was an error
+ */
+int dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type);
+int dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type);
+int dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type);
+int dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t data, DltFormatType type);
+
/**
* Write a int parameter into a DLT log message.
* dlt_user_log_write_start has to be called before adding any attributes to the log message.
@@ -426,7 +441,7 @@ int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length);
* @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);
+int dlt_user_log_write_raw_formatted(DltContextData *log,void *data,uint16_t length,DltFormatType type);
/**
* Trace network message
diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h
index 484350e..600b33a 100644
--- a/include/dlt/dlt_user_macros.h
+++ b/include/dlt/dlt_user_macros.h
@@ -294,18 +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)
+#define DLT_HEX8(UINT_VAR) \
+ dlt_user_log_write_uint8_formatted(&log,UINT_VAR,DLT_FORMAT_HEX8)
+#define DLT_HEX16(UINT_VAR) \
+ dlt_user_log_write_uint16_formatted(&log,UINT_VAR,DLT_FORMAT_HEX16)
+#define DLT_HEX32(UINT_VAR) \
+ dlt_user_log_write_uint32_formatted(&log,UINT_VAR,DLT_FORMAT_HEX32)
+#define DLT_HEX64(UINT_VAR) \
+ dlt_user_log_write_uint64_formatted(&log,UINT_VAR,DLT_FORMAT_HEX64)
+#define DLT_BIN8(UINT_VAR) \
+ dlt_user_log_write_uint8_formatted(&log,UINT_VAR,DLT_FORMAT_BIN8)
+#define DLT_BIN16(UINT_VAR) \
+ dlt_user_log_write_uint16_formatted(&log,UINT_VAR,DLT_FORMAT_BIN16)
/**
* Trace network message
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 22283c2..fad3fa0 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -1310,10 +1310,10 @@ 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);
+ return dlt_user_log_write_raw_formatted(log,data,length,DLT_FORMAT_DEFAULT);
}
-int dlt_user_log_write_raw_formated(DltContextData *log,void *data,uint16_t length,DltFormatType type)
+int dlt_user_log_write_raw_formatted(DltContextData *log,void *data,uint16_t length,DltFormatType type)
{
uint16_t arg_size;
uint32_t type_info;
@@ -1627,6 +1627,186 @@ int dlt_user_log_write_uint64(DltContextData *log, uint64_t data)
return 0;
}
+int dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type)
+{
+ uint32_t type_info;
+
+ if (log==0)
+ {
+ return -1;
+ }
+
+ if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ if (dlt_user.verbose_mode)
+ {
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT;
+
+ if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64)
+ {
+ type_info |= DLT_SCOD_HEX;
+ }
+
+ else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16)
+ {
+ type_info |= DLT_SCOD_BIN;
+ }
+
+ memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
+ log->size += sizeof(uint32_t);
+ }
+
+ memcpy((log->buffer)+log->size,&data,sizeof(uint8_t));
+ log->size += sizeof(uint8_t);
+
+ log->args_num ++;
+
+ return 0;
+}
+
+int dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type)
+{
+ uint32_t type_info;
+
+ if (log==0)
+ {
+ return -1;
+ }
+
+ if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ if (dlt_user.verbose_mode)
+ {
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT;
+
+ if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64)
+ {
+ type_info |= DLT_SCOD_HEX;
+ }
+
+ else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16)
+ {
+ type_info |= DLT_SCOD_BIN;
+ }
+
+ memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
+ log->size += sizeof(uint32_t);
+ }
+
+ memcpy((log->buffer)+log->size,&data,sizeof(uint16_t));
+ log->size += sizeof(uint16_t);
+
+ log->args_num ++;
+
+ return 0;
+}
+
+int dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type)
+{
+ uint32_t type_info;
+
+ if (log==0)
+ {
+ return -1;
+ }
+
+ if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ if (dlt_user.verbose_mode)
+ {
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT;
+
+ if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64)
+ {
+ type_info |= DLT_SCOD_HEX;
+ }
+
+ else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16)
+ {
+ type_info |= DLT_SCOD_BIN;
+ }
+
+ memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
+ log->size += sizeof(uint32_t);
+ }
+
+ memcpy((log->buffer)+log->size,&data,sizeof(uint32_t));
+ log->size += sizeof(uint32_t);
+
+ log->args_num ++;
+
+ return 0;
+}
+
+int dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t data, DltFormatType type)
+{
+ uint32_t type_info;
+
+ if (log==0)
+ {
+ return -1;
+ }
+
+ if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ if (dlt_user.verbose_mode)
+ {
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ {
+ return -1;
+ }
+
+ type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT;
+
+ if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64)
+ {
+ type_info |= DLT_SCOD_HEX;
+ }
+
+ else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16)
+ {
+ type_info |= DLT_SCOD_BIN;
+ }
+
+ memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
+ log->size += sizeof(uint32_t);
+ }
+
+ memcpy((log->buffer)+log->size,&data,sizeof(uint64_t));
+ log->size += sizeof(uint64_t);
+
+ log->args_num ++;
+
+ return 0;
+}
+
int dlt_user_log_write_int(DltContextData *log, int data)
{
if (log==0)
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index dd4d74a..d0beb97 100755
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -3217,7 +3217,6 @@ int dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr,
int64_t value64f_tmp_int64i=0,value64f_tmp_int64i_swaped=0;
uint32_t quantisation_tmp = 0;
-
if ( (type_info & DLT_TYPE_INFO_STRG) && (((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_ASCII) || ((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_UTF8)) )
{
@@ -3271,6 +3270,79 @@ int dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr,
return -1;
snprintf(text+strlen(text),textlength-strlen(text),"%d",value8u);
}
+ else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_BIN == (type_info & DLT_TYPE_INFO_SCOD)))
+ {
+ if (DLT_TYLE_8BIT == (type_info & DLT_TYPE_INFO_TYLE))
+ {
+ DLT_MSG_READ_VALUE(value8u,*ptr,*datalength,uint8_t); /* No endian conversion necessary */
+ if((*datalength)<0)
+ return -1;
+ char binary[10] = {'\0'}; // e.g.: "0b1100 0010"
+ int i;
+ for (i = (1 << 7); i > 0; i >>= 1)
+ {
+ if ((1<<3) == i)
+ strcat(binary, " ");
+ strcat(binary, (i == (value8u & i)) ? "1" : "0");
+ }
+
+ snprintf(text+strlen(text),textlength-strlen(text),"0b%s",binary);
+ }
+ if (DLT_TYLE_16BIT == (type_info & DLT_TYPE_INFO_TYLE))
+ {
+ DLT_MSG_READ_VALUE(value16u,*ptr,*datalength,uint16_t);
+ if((*datalength)<0)
+ return -1;
+ char binary[20] = {'\0'}; // e.g.: "0b1100 0010 0011 0110"
+ int i;
+ for (i = (1 << 15); i > 0; i >>= 1)
+ {
+ if (((1<<3) == i) || ((1<<7) == i) || ((1<<11) == i))
+ strcat(binary, " ");
+ strcat(binary, (i == (value16u & i)) ? "1" : "0");
+ }
+
+ snprintf(text+strlen(text),textlength-strlen(text),"0b%s",binary);
+ }
+ }
+ else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_HEX == (type_info & DLT_TYPE_INFO_SCOD)))
+ {
+ if (DLT_TYLE_8BIT == (type_info & DLT_TYPE_INFO_TYLE))
+ {
+ DLT_MSG_READ_VALUE(value8u,*ptr,*datalength,uint8_t); /* No endian conversion necessary */
+ if((*datalength)<0)
+ return -1;
+ snprintf(text+strlen(text),textlength-strlen(text),"0x%02x",value8u);
+ }
+ if (DLT_TYLE_16BIT == (type_info & DLT_TYPE_INFO_TYLE))
+ {
+ DLT_MSG_READ_VALUE(value16u,*ptr,*datalength,uint16_t);
+ if((*datalength)<0)
+ return -1;
+ snprintf(text+strlen(text),textlength-strlen(text),"0x%04x",value16u);
+ }
+ if (DLT_TYLE_32BIT == (type_info & DLT_TYPE_INFO_TYLE))
+ {
+ DLT_MSG_READ_VALUE(value32u,*ptr,*datalength,uint32_t);
+ if((*datalength)<0)
+ return -1;
+ snprintf(text+strlen(text),textlength-strlen(text),"0x%08x",value32u);
+ }
+ if (DLT_TYLE_64BIT == (type_info & DLT_TYPE_INFO_TYLE))
+ {
+ *ptr += 4;
+ DLT_MSG_READ_VALUE(value32u,*ptr,*datalength,uint32_t);
+ if((*datalength)<0)
+ return -1;
+ snprintf(text+strlen(text),textlength-strlen(text),"0x%08x",value32u);
+ *ptr -= 8;
+ DLT_MSG_READ_VALUE(value32u,*ptr,*datalength,uint32_t);
+ if((*datalength)<0)
+ return -1;
+ snprintf(text+strlen(text),textlength-strlen(text),"%08x",value32u);
+ *ptr += 4;
+ }
+ }
else if ((type_info & DLT_TYPE_INFO_SINT) || (type_info & DLT_TYPE_INFO_UINT))
{
/* signed or unsigned argument received */