From bff03e36c4ef0fe7f49403bbbcb49d48493293b7 Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Mon, 9 Dec 2013 13:52:31 +0100 Subject: Added new control message timezone. Signed-off-by: Alexander Wenzel --- include/dlt/dlt_common.h | 11 ++++++++ include/dlt/dlt_protocol.h | 1 + src/daemon/dlt-daemon.c | 23 +++++++++++++--- src/daemon/dlt-daemon.h | 1 + src/daemon/dlt.conf | 7 +++++ src/daemon/dlt_daemon_common.c | 60 +++++++++++++++++++++++++++++++++++++++++- src/daemon/dlt_daemon_common.h | 8 ++++++ 7 files changed, 107 insertions(+), 4 deletions(-) diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index 0740c9e..22710c7 100755 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -519,6 +519,17 @@ typedef struct char comid[DLT_ID_SIZE]; /**< communication interface */ } PACKED DltServiceConnectionInfo; +/** + * The structure of the DLT Service Timezone + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + int32_t timezone; /**< Timezone in seconds */ + uint8_t isdst; /**< Is daylight saving time */ +} PACKED DltServiceTimezone; + /** * Structure to store filter parameters. * ID are maximal four characters. Unused values are filled with zeros. diff --git a/include/dlt/dlt_protocol.h b/include/dlt/dlt_protocol.h index 7e941fe..09e4adc 100755 --- a/include/dlt/dlt_protocol.h +++ b/include/dlt/dlt_protocol.h @@ -189,6 +189,7 @@ #define DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW 0x14 /**< Service ID: Message buffer overflow */ #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_CALLSW_CINJECTION 0xFFF /**< Service ID: Message Injection (minimal ID) */ /* diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 00ac525..78d232f 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -209,6 +209,7 @@ int option_file_parser(DltDaemonLocal *daemon_local) daemon_local->timeoutOnSend = 4; daemon_local->flags.sendECUSoftwareVersion = 0; memset(daemon_local->flags.pathToECUSoftwareVersion, 0, sizeof(daemon_local->flags.pathToECUSoftwareVersion)); + daemon_local->flags.sendTimezone = 0; /* open configuration file */ if(daemon_local->flags.cvalue[0]) @@ -365,7 +366,11 @@ int option_file_parser(DltDaemonLocal *daemon_local) strncpy(daemon_local->flags.pathToECUSoftwareVersion,value,sizeof(daemon_local->flags.pathToECUSoftwareVersion) - 1); //printf("Option: %s=%s\n",token,value); } - + else if(strcmp(token,"SendTimezone")==0) + { + daemon_local->flags.sendTimezone = atoi(value); + //printf("Option: %s=%s\n",token,value); + } else { fprintf(stderr, "Unknown option: %s=%s\n",token,value); @@ -471,7 +476,7 @@ int main(int argc, char* argv[]) create_timer_fd(&daemon_local, 1, 1, &daemon_local.timer_timingpacket, "Timing packet"); // create fd for timer ecu version - if(daemon_local.flags.sendECUSoftwareVersion > 0) + if(daemon_local.flags.sendECUSoftwareVersion > 0 || daemon_local.flags.sendTimezone > 0) { //dlt_daemon_init_ecuversion(&daemon_local); create_timer_fd(&daemon_local, 60, 60, &daemon_local.timer_ecuversion, "ECU version"); @@ -2751,6 +2756,7 @@ void dlt_daemon_send_timingpacket(DltDaemon *daemon, DltDaemonLocal *daemon_loca { dlt_log(LOG_DEBUG, "timingpacket\n"); dlt_daemon_control_message_time(j, daemon, daemon_local->flags.vflag); + } } } @@ -2774,7 +2780,17 @@ void dlt_daemon_send_ecuversion(DltDaemon *daemon, DltDaemonLocal *daemon_local) && (j!=daemon_local->timer_timingpacket) && (j!=daemon_local->timer_ecuversion)) { dlt_log(LOG_DEBUG, "ecu_version\n"); - dlt_daemon_control_get_software_version(j, daemon, daemon_local->flags.vflag); + if(daemon_local->flags.sendECUSoftwareVersion > 0) + dlt_daemon_control_get_software_version(j, daemon, daemon_local->flags.vflag); + + if(daemon_local->flags.sendTimezone > 0) + { + // send timezone information + time_t t = time(NULL); + struct tm lt = {0}; + localtime_r(&t, <); + dlt_daemon_control_message_timezone(j,daemon,(int32_t) lt.tm_gmtoff,(uint8_t) lt.tm_isdst,daemon_local->flags.vflag); + } } } } @@ -2806,6 +2822,7 @@ int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_ dlt_daemon_control_message_connection_info(DLT_DAEMON_STORE_TO_BUFFER,daemon,DLT_CONNECTION_STATUS_DISCONNECTED,"",verbose); } + /** \} */ diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index 46321a7..b7ffb55 100755 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -105,6 +105,7 @@ typedef struct char loggingFilename[256]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */ int sendECUSoftwareVersion; /**< (Boolean) Send ECU software version perdiodically */ char pathToECUSoftwareVersion[256]; /**< (String: Filename) The file from which to read the ECU version from. */ + int sendTimezone; /**< (Boolean) Send Timezone perdiodically */ } DltDaemonFlags; /** diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf index e09129a..a079d3e 100644 --- a/src/daemon/dlt.conf +++ b/src/daemon/dlt.conf @@ -101,3 +101,10 @@ TimeOutOnSend = 4 # Absolute path to file storing version info - otherwise DLT version is used # PathToECUSoftwareVersion = + +######################################################################## +# Timezone info # +######################################################################## + +# Send periodic timezone info (Default: 0) +# SendTimezone = 0 \ No newline at end of file diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index bbd058d..df9ccbe 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -2631,7 +2631,7 @@ int dlt_daemon_control_message_unregister_context(int sock, DltDaemon *daemon, c resp->service_id = DLT_SERVICE_ID_UNREGISTER_CONTEXT; resp->status = DLT_SERVICE_RESPONSE_OK; dlt_set_id(resp->apid, apid); - dlt_set_id(resp->apid, ctid); + dlt_set_id(resp->ctid, ctid); dlt_set_id(resp->comid, comid); /* send message */ @@ -2704,3 +2704,61 @@ int dlt_daemon_control_message_connection_info(int sock, DltDaemon *daemon, uint return 0; } + +int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, int32_t timezone, uint8_t isdst, int verbose) +{ + DltMessage msg; + DltServiceTimezone *resp; + + PRINT_FUNCTION_VERBOSE(verbose); + + if (daemon==0) + { + return -1; + } + + /* initialise new message */ + if (dlt_message_init(&msg,0)==-1) + { + dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose); + return -1; + } + + /* prepare payload of data */ + msg.datasize = sizeof(DltServiceTimezone); + 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) + { + if (sock!=DLT_DAEMON_STORE_TO_BUFFER) + { + dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose); + } + return -1; + } + + resp = (DltServiceTimezone*) msg.databuffer; + resp->service_id = DLT_SERVICE_ID_TIMEZONE; + resp->status = DLT_SERVICE_RESPONSE_OK; + resp->timezone = timezone; + resp->isdst = isdst; + + /* send message */ + if(dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose)) + { + dlt_message_free(&msg,0); + return -1; + } + + /* free message */ + dlt_message_free(&msg,0); + + return 0; +} diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h index 46b59dd..f0a6be4 100644 --- a/src/daemon/dlt_daemon_common.h +++ b/src/daemon/dlt_daemon_common.h @@ -477,6 +477,14 @@ int dlt_daemon_control_message_unregister_context(int sock, DltDaemon *daemon, c * @param verbose if set to true verbose information is printed out. */ int dlt_daemon_control_message_connection_info(int sock, DltDaemon *daemon, uint8_t state, char* comid, int verbose); +/** + * Send control message connection info (add on to AUTOSAR standard) + * @param sock connection handle used for sending response + * @param daemon pointer to dlt daemon 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, int32_t timezone, uint8_t isdst, int verbose); #ifdef __cplusplus } -- cgit v1.2.1