summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Muck <christian.muck@bmw.de>2011-10-18 14:00:49 +0200
committerChristian Muck <christian.muck@bmw.de>2011-10-18 14:00:49 +0200
commit0567c9ba8dc6d76cf2aeba88539a78511975483a (patch)
tree0efe63439a7ee94ff3529ff642c26b67e34aca37 /src
parentc14ff33f94913a5ad5a58b46facfa95705b7cfc4 (diff)
downloadDLT-daemon-0567c9ba8dc6d76cf2aeba88539a78511975483a.tar.gz
Added install target and files for filetransfer in the cmakelists . Fixed little bug in test filetransfer. Added filetransfer documentation and example program.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/examples/CMakeLists.txt10
-rw-r--r--src/examples/dlt-example-filetransfer.c168
-rwxr-xr-xsrc/tests/CMakeLists.txt6
-rw-r--r--src/tests/dlt-test-filetransfer.c37
4 files changed, 204 insertions, 17 deletions
diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt
index 6ea331d..6d903e0 100755
--- a/src/examples/CMakeLists.txt
+++ b/src/examples/CMakeLists.txt
@@ -51,7 +51,15 @@ ENDIF(GPROF_DLT_EXAMPLES)
target_link_libraries(dlt-example-user-func dlt)
set_target_properties(dlt-example-user-func PROPERTIES LINKER_LANGUAGE C)
-install(TARGETS dlt-example-user dlt-example-user-func
+set(dlt_example_filetransfer_SRCS dlt-example-filetransfer)
+add_executable( dlt-example-filetransfer ${dlt_example_filetransfer_SRCS})
+IF(GPROF_DLT_EXAMPLES)
+ SET(CMAKE_C_FLAGS "-pg")
+ENDIF(GPROF_DLT_EXAMPLES)
+target_link_libraries(dlt-example-filetransfer dlt dlt-filetransfer )
+set_target_properties(dlt-example-filetransfer PROPERTIES LINKER_LANGUAGE C)
+
+install(TARGETS dlt-example-user dlt-example-user-func dlt-example-filetransfer
RUNTIME DESTINATION bin
COMPONENT base)
diff --git a/src/examples/dlt-example-filetransfer.c b/src/examples/dlt-example-filetransfer.c
new file mode 100644
index 0000000..4c6b12b
--- /dev/null
+++ b/src/examples/dlt-example-filetransfer.c
@@ -0,0 +1,168 @@
+#include "dlt/dlt_filetransfer.h" /*Needed for transferring files with the dlt protocol*/
+#include "dlt/dlt.h" /*Needed for dlt logging*/
+
+
+#define MAXSTRLEN 1024
+
+#define FLTR_APP_DESC "Filetransfer application"
+#define FLTR_CONTEXT_DESC "Filetransfer context"
+
+#define FLTR_APP "FLTR"
+#define FLTR_CONTEXT "FLTR"
+
+#define TIMEOUT 1
+
+//!Declare some context for the file transfer. It's not a must have to do this, but later you can set a filter on this context in the dlt viewer.
+DLT_DECLARE_CONTEXT(fileContext);
+
+
+/**
+ * Print usage information of tool.
+ */
+void usage()
+{
+ char version[255];
+
+ dlt_get_version(version);
+
+ printf("Usage: dlt-example-filetransfer [options] <command>\n");
+ printf("Filetransfer example");
+ printf("%s \n", version);
+ printf("Command:\n");
+ printf("-f file - File to transfer (absolute path)\n");
+ printf("Options:\n");
+ printf("-a apid - Set application id to apid (default: FLTR)\n");
+ printf("-c ctid - Set context id to ctid (default: FLTR)\n");
+ printf("-t ms - Timeout between file packages in ms (minimum 1 ms)\n");
+ printf("-d - Flag to delete the file after the transfer (default: false)\n");
+ printf("-i - Flag to log file infos to DLT before transfer file (default: false)\n");
+ printf("-h - This help\n");
+
+}
+
+
+//!Main program dlt-test-filestransfer starts here
+int main(int argc, char* argv[])
+{
+ char str[MAXSTRLEN];
+ int opt, timeout, dltResult;;
+
+ char apid[DLT_ID_SIZE];
+ char ctid[DLT_ID_SIZE];
+
+ char version[255];
+
+ int dflag = 0;
+ int iflag = 0;
+ char *fvalue = 0;
+ char *tvalue = 0;
+
+ dlt_set_id(apid, FLTR_APP);
+ dlt_set_id(ctid, FLTR_CONTEXT);
+
+ while ((opt = getopt(argc, argv, "idf:t:a:c:h")) != -1)
+ {
+ switch (opt)
+ {
+ case 'd':
+ {
+ dflag = 1;
+ break;
+ }
+ case 'i':
+ {
+ iflag = 1;
+ break;
+ }
+ case 'f':
+ {
+ fvalue = optarg;
+ break;
+ }
+ case 't':
+ {
+ tvalue = optarg;
+ break;
+ }
+ case 'a':
+ {
+ dlt_set_id(apid,optarg);
+ break;
+ }
+ case 'c':
+ {
+ dlt_set_id(ctid,optarg);
+ break;
+ }
+ case 'h':
+ {
+ usage();
+ break;
+ }
+ case '?':
+ {
+ if (optopt == 'a' || optopt == 'c' || optopt == 'f' || optopt == 't')
+ {
+ fprintf (stderr, "Option -%c requires an argument.\n", optopt);
+ }
+ else if (isprint (optopt))
+ {
+ fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+ }
+ else
+ {
+ fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
+ }
+ /* unknown or wrong option used, show usage information and terminate */
+ usage();
+ return -1;
+ }
+ }
+ }
+
+ if (tvalue)
+ {
+ timeout = atoi(tvalue);
+ }
+ else
+ {
+ timeout = TIMEOUT;
+ }
+
+ if (!fvalue)
+ {
+ usage();
+ return -1;
+ }
+
+ //Register the application at the dlt-daemon
+ dltResult = DLT_REGISTER_APP(apid,FLTR_APP_DESC);
+
+ //Register the context of the main program at the dlt-daemon
+ dltResult = DLT_REGISTER_CONTEXT(fileContext,ctid,FLTR_CONTEXT_DESC);
+
+ //More details in corresponding methods
+ if( dltResult == 0 ){
+ if( iflag )
+ {
+ dlt_user_log_file_infoAbout(&fileContext,fvalue);
+ }
+
+ if( dlt_user_log_file_complete(&fileContext,fvalue,dflag,timeout) < 0 )
+ {
+ printf("File couldn't be transferred. Please check the dlt log messages.\n");
+ }
+
+ }
+ else
+ {
+ printf("Filetransfer didn't start...error with dlt daemon. Please check the daemon.\n");
+ }
+
+ //Unregister the context in which the file transfer happened from the dlt-daemon
+ DLT_UNREGISTER_CONTEXT(fileContext);
+ //Unregister the context of the main program from the dlt-daemon
+ DLT_UNREGISTER_APP();
+
+ return 0;
+}
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 94a931e..c12642e 100755
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -91,6 +91,10 @@ ENDIF(GPROF_DLT_TESTS)
target_link_libraries(dlt-test-filetransfer dlt)
set_target_properties(dlt-test-filetransfer PROPERTIES LINKER_LANGUAGE C)
-install(TARGETS dlt-test-user dlt-test-client dlt-test-stress-user dlt-test-stress-client dlt-test-stress dlt-test-internal
+install(TARGETS dlt-test-user dlt-test-client dlt-test-stress-user dlt-test-stress-client dlt-test-stress dlt-test-internal dlt-test-filetransfer
RUNTIME DESTINATION bin
COMPONENT base)
+
+INSTALL(FILES dlt-test-filetransfer-file dlt-test-filetransfer-image.png
+ DESTINATION share/dlt-filetransfer
+)
diff --git a/src/tests/dlt-test-filetransfer.c b/src/tests/dlt-test-filetransfer.c
index 7c43058..0218737 100644
--- a/src/tests/dlt-test-filetransfer.c
+++ b/src/tests/dlt-test-filetransfer.c
@@ -12,7 +12,11 @@ char *file1;
//!Image which will be transferred.
char *file2;
//!Not existing file which will be transferred.
-char *file3;
+char *file3_1;
+//!Not existing file which will be transferred.
+char *file3_2;
+//!Not existing file which will be transferred.
+char *file3_3;
//!Just some variables
int i,countPackages, transferResult, dltResult;
@@ -32,8 +36,11 @@ int main(void)
//Second file is a picture
file2 = "dlt-test-filetransfer-image.png";
//Third file doesn't exist. Just to test the reaction when the file isn't available.
- file3 = "dlt-test-filetransfer-doesntExist";
-
+ file3_1 = "dlt-test-filetransfer-doesntExist_1";
+ //Third file doesn't exist. Just to test the reaction when the file isn't available.
+ file3_2 = "dlt-test-filetransfer-doesntExist_2";
+ //Third file doesn't exist. Just to test the reaction when the file isn't available.
+ file3_3 = "dlt-test-filetransfer-doesntExist_3";
//Register the application at the dlt-daemon
dltResult = DLT_REGISTER_APP("FLTR","Test Application filetransfer");
@@ -262,16 +269,16 @@ int testF2P2(){
int testF3P1(){
//Just some log to the main context
- DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3));
+ DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3_1));
//Here's the line where the dlt file transfer is called. The method call needs a context, the absolute file path, will the file be deleted after transfer and the timeout between the packages
- transferResult = dlt_user_log_file_complete(&fileContext,file3,0,20);
+ transferResult = dlt_user_log_file_complete(&fileContext,file3_1,0,20);
if(transferResult < 0)
{
//Error expected because file doesn't exist
//printf("Error: dlt_user_log_file_complete\n");
//Just some log to the main context
- DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3));
+ DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3_1));
return transferResult;
}
return transferResult;
@@ -282,28 +289,28 @@ int testF3P1(){
int testF3P2(){
//Get the information how many packages have the file
- countPackages = dlt_user_log_file_packagesCount(&fileContext,file3);
+ countPackages = dlt_user_log_file_packagesCount(&fileContext,file3_2);
if(countPackages < 0 )
{
//Error expected because file doesn't exist
//printf("Error: dlt_user_log_file_packagesCount\n");
//Just some log to the main context
- DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3));
+ DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3_2));
return -1;
}
//Just some log to the main context
- DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3));
+ DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3_2));
//Logs the header of the file transfer. For more details see Mainpage.c.
//The header gives information about the file serial number, filename (with absolute path), filesize, packages of file, buffer size
- transferResult = dlt_user_log_file_header(&fileContext,file3);
+ transferResult = dlt_user_log_file_header(&fileContext,file3_2);
if( transferResult >= 0){
//Loop to log all packages
for(i=1;i<=countPackages;i++)
{
//Logs one single package to the file context
- transferResult = dlt_user_log_file_data(&fileContext,file3,i,20);
+ transferResult = dlt_user_log_file_data(&fileContext,file3_2,i,20);
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_data\n");
@@ -313,7 +320,7 @@ int testF3P2(){
//Logs the end of the file transfer. For more details see Mainpage.c
//The end gives just information about the file serial number but is needed to signal that the file transfer has correctly finished and needed for the file transfer plugin of the dlt viewer.
- transferResult = dlt_user_log_file_end(&fileContext,file3,0);
+ transferResult = dlt_user_log_file_end(&fileContext,file3_2,0);
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_end\n");
@@ -329,16 +336,16 @@ int testF3P2(){
int testF3P3(){
//Just some log to the main context
- DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P2"),DLT_STRING(file3));
+ DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P2"),DLT_STRING(file3_3));
//Here's the line where the dlt file file info is called. The method call logs some information to dlt about the file, filesize, file serial number and number of packages
- transferResult = dlt_user_log_file_infoAbout(&fileContext,file3);
+ transferResult = dlt_user_log_file_infoAbout(&fileContext,file3_3);
if(transferResult < 0)
{
//Error expected because file doesn't exist
//printf("Error: dlt_user_log_file_infoAbout\n");
//Just some log to the main context
- DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P2"),DLT_STRING(file3));
+ DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P2"),DLT_STRING(file3_3));
return transferResult;
}