diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2014-09-11 16:14:07 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2014-09-11 16:24:43 +0200 |
commit | c8d990b893838b3263ac020b095f1a520908e815 (patch) | |
tree | dbc8f21021a6c478b4f0e5ddcf79afcd8c700646 | |
parent | 406f947a0f8dca7ac1fbdc6b1df2bbe37af1b669 (diff) | |
download | DLT-daemon-c8d990b893838b3263ac020b095f1a520908e815.tar.gz |
Added new API to send marker message from application.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rwxr-xr-x | include/dlt/dlt_common.h | 9 | ||||
-rwxr-xr-x | include/dlt/dlt_protocol.h | 1 | ||||
-rw-r--r-- | include/dlt/dlt_user.h | 5 | ||||
-rw-r--r-- | include/dlt/dlt_user_macros.h | 8 | ||||
-rw-r--r-- | src/daemon/dlt-daemon.c | 37 | ||||
-rwxr-xr-x | src/daemon/dlt-daemon.h | 1 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_client.c | 51 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_client.h | 11 | ||||
-rwxr-xr-x | src/examples/dlt-example-user.c | 16 | ||||
-rw-r--r-- | src/lib/dlt_user.c | 36 | ||||
-rwxr-xr-x | src/shared/dlt_user_shared_cfg.h | 1 |
11 files changed, 172 insertions, 4 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index d03eca8..a0d48f6 100755 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -531,6 +531,15 @@ typedef struct } PACKED DltServiceTimezone; /** + * The structure of the DLT Service Marker + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ +} PACKED DltServiceMarker; + +/** * Structure to store filter parameters. * ID are maximal four characters. Unused values are filled with zeros. * If every value as filter is valid, the id should be empty by having only zero values. diff --git a/include/dlt/dlt_protocol.h b/include/dlt/dlt_protocol.h index 1bb5850..b4fff5c 100755 --- a/include/dlt/dlt_protocol.h +++ b/include/dlt/dlt_protocol.h @@ -192,6 +192,7 @@ #define DLT_SERVICE_ID_UNREGISTER_CONTEXT 0xf01 /**< Service ID: Message unregister context */
#define DLT_SERVICE_ID_CONNECTION_INFO 0xf02 /**< Service ID: Message connection info */
#define DLT_SERVICE_ID_TIMEZONE 0xf03 /**< Service ID: Timezone */
+#define DLT_SERVICE_ID_MARKER 0xf04 /**< Service ID: Marker */
#define DLT_SERVICE_ID_CALLSW_CINJECTION 0xFFF /**< Service ID: Message Injection (minimal ID) */
/*
diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index 1ed7b25..7126b6a 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -713,6 +713,11 @@ int dlt_log_uint(DltContext *handle,DltLogLevelType loglevel, unsigned int data) */ int dlt_log_raw(DltContext *handle,DltLogLevelType loglevel, void *data,uint16_t length); +/** + * Write marker message to DLT. + * @return negative value if there was an error + */ +int dlt_log_marker(); /** * Forward a complete DLT message to the DLT daemon diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h index a8ceaf4..484350e 100644 --- a/include/dlt/dlt_user_macros.h +++ b/include/dlt/dlt_user_macros.h @@ -446,6 +446,14 @@ extern DltContext CONTEXT; } while(0) /** + * Send log message with marker. + */ +#define DLT_LOG_MARKER() \ + do { \ + dlt_log_marker(); \ + } while(0) + +/** * Switch to verbose mode * */ diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index c8b4703..1a98ca9 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -1473,6 +1473,14 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l } break; } + case DLT_USER_MESSAGE_MARKER: + { + if (dlt_daemon_process_user_message_marker(daemon, daemon_local, daemon_local->flags.vflag)==-1) + { + run_loop=0; + } + break; + } default: { dlt_log(LOG_ERR,"(Internal) Invalid user message type received!\n"); @@ -2345,6 +2353,35 @@ int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal * return 0; } +int dlt_daemon_process_user_message_marker(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +{ + PRINT_FUNCTION_VERBOSE(verbose); + + if ((daemon==0) || (daemon_local==0)) + { + dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_user_message_marker()\n"); + return -1; + } + + if (daemon_local->receiver.bytesRcvd < (int32_t)(sizeof(DltUserHeader))) + { + /* Not enough bytes received */ + return -1; + } + + /* Create automatic unregister context response for unregistered context */ + dlt_daemon_control_message_marker(DLT_DAEMON_SEND_TO_ALL,daemon,daemon_local,verbose); + + /* keep not read data in buffer */ + if (dlt_receiver_remove(&(daemon_local->receiver),sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogMode))==-1) + { + dlt_log(LOG_ERR,"Can't remove bytes from receiver for user message log mode\n"); + return -1; + } + + return 0; +} + int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) { int ret; diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index dfe4de3..022387a 100755 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -190,6 +190,7 @@ int dlt_daemon_process_user_message_log_shm(DltDaemon *daemon, DltDaemonLocal *d #endif
int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
+int dlt_daemon_process_user_message_marker(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
void dlt_daemon_timingpacket_thread(void *ptr);
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index 5f85b15..b0a11c9 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -1183,6 +1183,57 @@ int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLo return 0; } +int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +{ + DltMessage msg; + DltServiceMarker *resp; + + PRINT_FUNCTION_VERBOSE(verbose); + + if (daemon==0) + { + return -1; + } + + /* initialise new message */ + if (dlt_message_init(&msg,0)==-1) + { + return -1; + } + + /* prepare payload of data */ + msg.datasize = sizeof(DltServiceMarker); + if (msg.databuffer && (msg.databuffersize < msg.datasize)) + { + free(msg.databuffer); + msg.databuffer=0; + } + if (msg.databuffer == 0){ + msg.databuffer = (uint8_t *) malloc(msg.datasize); + msg.databuffersize = msg.datasize; + } + if (msg.databuffer==0) + { + return -1; + } + + resp = (DltServiceMarker*) msg.databuffer; + resp->service_id = DLT_SERVICE_ID_MARKER; + resp->status = DLT_SERVICE_RESPONSE_OK; + + /* send message */ + if(dlt_daemon_client_send_control_message(sock,daemon,daemon_local,&msg,"","", verbose)) + { + dlt_message_free(&msg,0); + return -1; + } + + /* free message */ + dlt_message_free(&msg,0); + + return 0; +} + void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose) { char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE]; diff --git a/src/daemon/dlt_daemon_client.h b/src/daemon/dlt_daemon_client.h index 34715c9..c9ceec4 100644 --- a/src/daemon/dlt_daemon_client.h +++ b/src/daemon/dlt_daemon_client.h @@ -154,15 +154,22 @@ int dlt_daemon_control_message_unregister_context(int sock, DltDaemon *daemon, D */ int dlt_daemon_control_message_connection_info(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, uint8_t state, char* comid, int verbose); /** - * Send control message connection info (add on to AUTOSAR standard) + * Send control message timezone (add on to AUTOSAR standard) * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure * @param daemon_local pointer to dlt daemon local structure - * @param timezone timezone on target * @param verbose if set to true verbose information is printed out. */ int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); /** + * Send control message marker (add on to AUTOSAR standard) + * @param sock connection handle used for sending response + * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure + * @param verbose if set to true verbose information is printed out. + */ +int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +/** * Process received control message from dlt client * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c index a01ea44..9c4a529 100755 --- a/src/examples/dlt-example-user.c +++ b/src/examples/dlt-example-user.c @@ -96,6 +96,7 @@ void usage() printf(" -n count Number of messages to be generated (Default: 10)\n"); printf(" -g Switch to non-verbose mode (Default: verbose mode)\n"); printf(" -a Enable local printing of DLT messages (Default: disabled)\n"); + printf(" -k Send marker message\n"); printf(" -m mode Set log mode 0=off,1=external,2=internal,3=both\n"); #ifdef DLT_TEST_ENABLE printf(" -c Corrupt user header\n"); @@ -111,6 +112,7 @@ int main(int argc, char* argv[]) { int gflag = 0; int aflag = 0; + int kflag = 0; #ifdef DLT_TEST_ENABLE int cflag = 0; char *svalue = 0; @@ -133,9 +135,9 @@ int main(int argc, char* argv[]) opterr = 0; #ifdef DLT_TEST_ENABLE - while ((c = getopt (argc, argv, "vgacd:f:n:m:z:s:")) != -1) + while ((c = getopt (argc, argv, "vgakcd:f:n:m:z:s:")) != -1) #else - while ((c = getopt (argc, argv, "vgad:f:n:m:")) != -1) + while ((c = getopt (argc, argv, "vgakd:f:n:m:")) != -1) #endif /* DLT_TEST_ENABLE */ { switch (c) @@ -150,6 +152,11 @@ int main(int argc, char* argv[]) aflag = 1; break; } + case 'k': + { + kflag = 1; + break; + } #ifdef DLT_TEST_ENABLE case 'c': { @@ -266,6 +273,11 @@ int main(int argc, char* argv[]) DLT_ENABLE_LOCAL_PRINT(); } + if (kflag) + { + DLT_LOG_MARKER(); + } + if (nvalue) { maxnum = atoi(nvalue); diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 1ad4335..7dfc913 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -97,6 +97,7 @@ static int dlt_user_log_send_register_context(DltContextData *log); static int dlt_user_log_send_unregister_context(DltContextData *log); static int dlt_send_app_ll_ts_limit(const char *appid, DltLogLevelType loglevel, DltTraceStatusType tracestatus); static int dlt_user_log_send_log_mode(DltUserLogMode mode); +static int dlt_user_log_send_marker(); static int dlt_user_print_msg(DltMessage *msg, DltContextData *log); static int dlt_user_log_check_user_message(void); static void dlt_user_log_reattach_to_daemon(void); @@ -2758,6 +2759,19 @@ int dlt_log_raw(DltContext *handle,DltLogLevelType loglevel, void *data,uint16_t return 0; } +int dlt_log_marker() +{ + if (dlt_user_initialised==0) + { + if (dlt_init()<0) + { + return -1; + } + } + + return dlt_user_log_send_marker(); +} + int dlt_verbose_mode(void) { if (dlt_user_initialised==0) @@ -3575,6 +3589,28 @@ int dlt_user_log_send_log_mode(DltUserLogMode mode) return ((ret==DLT_RETURN_OK)?0:-1); } +int dlt_user_log_send_marker() +{ + DltUserHeader userheader; + + DltReturnValue ret; + + /* set userheader */ + if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_MARKER)==-1) + { + return -1; + } + + if (dlt_user.dlt_is_file) + { + return 0; + } + + /* log to FIFO */ + ret=dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), 0, 0); + return ((ret==DLT_RETURN_OK)?0:-1); +} + int dlt_user_print_msg(DltMessage *msg, DltContextData *log) { uint8_t *databuffer_tmp; diff --git a/src/shared/dlt_user_shared_cfg.h b/src/shared/dlt_user_shared_cfg.h index b780439..36d628a 100755 --- a/src/shared/dlt_user_shared_cfg.h +++ b/src/shared/dlt_user_shared_cfg.h @@ -93,6 +93,7 @@ #define DLT_USER_MESSAGE_LOG_SHM 10
#define DLT_USER_MESSAGE_LOG_MODE 11
#define DLT_USER_MESSAGE_LOG_STATE 12
+#define DLT_USER_MESSAGE_MARKER 13
/* Internal defined values */ |