Help converting CANoe logfile to EXCEL readable .txt file

This is a discussion on Help converting CANoe logfile to EXCEL readable .txt file within the C Programming forums, part of the General Programming Boards category; Adak, the inputfile i need to use is this .txt file: Code: date Tue May 26 03:12:51 pm 2009 base ...

  1. #16
    Registered User
    Join Date
    Aug 2009
    Posts
    9
    Adak,

    the inputfile i need to use is this .txt file:

    Code:
    date Tue May 26 03:12:51 pm 2009
    base hex  timestamps absolute
    no internal events logged
    // version 7.0.0
       0.000000    EnvGearDown  := 1
       0.000000    EnvGearDown  := 0
       0.000000    EnvGearDown  := 1
       0.000000    EnvGearDown  := 0
       0.000000    EnvGearDown  := 1
       0.000000    EnvGearDown  := 0
       0.000000    EnvGearDown  := 1
       0.000000    EnvGearDown  := 0
       0.000000    EnvGearDown  := 1
       0.000000    EnvGearDown  := 0
       0.000000    EnvGwSwitchIgnition := 2
       0.000000    EnvGwSwitchIgnition := 0
       2.000000    EnvGwSwitchIgnition := 1
       3.000000    EnvGwSwitchIgnition := 2
       3.100158 1  110             Tx   d 3 02 00 00
       3.100158    EnvDashboardEngESPDsp_ := 1
       3.100158    EnvDashboardEngABSDsp_ := 1
       3.100158    EnvDashboardEngOilDsp_ := 1
       3.100158    EnvDashboardEngWaterDsp_ := 1
       3.100158    EnvDashboardEngBaterryDsp_ := 1
       3.100158    EnvBusCommActiveDsp := 1
       3.120180 1  1A0             Tx   d 4 00 00 00 00
       3.120300 1  1F0             Tx   d 1 00
       3.120416 1  1F1             Tx   d 1 00
       3.140180 1  1A0             Tx   d 4 00 00 00 00
       3.150120 1  1F0             Tx   d 1 00
       3.150236 1  1F1             Tx   d 1 00
       3.160180 1  1A0             Tx   d 4 00 00 00 00
       3.180180 1  1A0             Tx   d 4 00 00 00 00
       3.180300 1  1F0             Tx   d 1 00
       3.180416 1  1F1             Tx   d 1 00
       3.200158 1  110             Tx   d 3 02 00 00
       3.200338 1  1A0             Tx   d 4 00 00 00 00
       3.205529 1  41A             Tx   d 4 1A 01 01 FF
       3.205529    EnvNMReceiver26 := 1a
       3.205529    EnvNMStatusDsp26 := 1
       3.210120 1  1F0             Tx   d 1 00
       3.210236 1  1F1             Tx   d 1 00
    The Output file is also a .txt file and should look like this:

    Code:
    time	id	dlc	byte0	byte1	byte2	byte3	byte4	byte5	byte6	byte7
    3.100158	110	3	02	00	00
    3.120180	1A0	4	00	00	00	00
    3.120300	1F0	1	00
    3.120416	1F1	1	00
    3.140180	1A0	4	00	00	00	00
    3.150120	1F0	1	00
    3.150236	1F1	1	00
    3.160180	1A0	4	00	00	00	00
    3.180180	1A0	4	00	00	00	00
    3.180300	1F0	1	00
    3.180416	1F1	1	00
    3.200158	110	3	02	00	00
    3.200338	1A0	4	00	00	00	00
    3.205529	41A	4	1A	01	01	FF
    3.210120	1F0	1	00
    3.210236	1F1	1	00
    So when i import the contents of the Output file to EXCEL the tabs create a saperation of the data in collums.

    The variables i whould like to work with are :

    time, id, dlc and bytes (mabey even byte0 to 7 seperate if that doesn't make it complicated)

    so in the outputfile the variables should be printed like this:

    time[tab]id[tab]dlc[tab]byte0[tab]byte1[tab]byte2[tab]byte3[tab]byte4[tab]byte5[tab]byte6[tab]byte7


    With the following content:

     Time absolute time CAN message was received.
     ID 11-bits identifier of CAN message(hexadecimal)
     Length number of bytes in CAN message (decimal)
     ByteX Byte value of relevant byte in CAN message (hexadecimal)

    I hope u now understand the concept of the assignment.

    As far as i'm concerned i only have to "filter out" the relavant data, in other words the line's in wich Tx shows up.

    And i have to print the "fitered" data to a new file in the correct form.

    In theory at least that doesn't sound that complicated at all.

    In practice, wel like i said i'm a noob

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It's really not that difficult, and I've exported data for Excel before.

    Do you have your variables being selected from the data accurately, yet? That's the first step, and like I said, when you're just getting a program started, put off the details, like tabs and such.

    You need them at that stage, like a rotting Albatross around your neck. And don't worry, all the tabs and such will be there, at the end.

  3. #18
    Registered User
    Join Date
    Aug 2009
    Posts
    9
    Quote Originally Posted by itCbitC View Post
    Separate the array named "bytes" into its components using strtok()
    Assemble the components together with sprintf() delimited by tabs
    And finally fprintf() the entire assembled array in one fell swoop

    Here's my 2c
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char *argv[])
    {
        FILE *fpin, *fpout;
        char flin[256], flout[256];
    
        char *p, line[256], x[256];
        char s1[50], s2[50], s3[50];
    
        printf("Input filename: ");
        scanf("%s", flin);
        fpin = fopen(flin, "r");
    
        printf("Output filename: ");
        scanf("%s", flout);
        fpout = fopen(flout, "w");
    
        while(fgets(line, 256, fpin))
            if (sscanf(line, "%s%*s%s Tx %*s %[^\n]", s1, s2, s3) == 3) {
                sprintf(x, "%s\t%s", s1, s2);
                for (p = strtok(s3, " "); p; p = strtok(NULL, " "))
                    sprintf(x, "%s\t%s", x, p);
                fprintf(fpout, "%s\n", x);
            }
        fclose(fpin);
        fclose(fpout);
        return 0;
    }
    itCbitC or Adak or any other,

    i've used itCbitC's example and got a working Code now but i just need some clarification on the Code itCbitC posted.

    Can someone please give some comment on the code so i know what's been done and wich variables are what and so on.

    I want to use the working code i now have but i have to comment on everything myself so my lecturer can see i understand what i'm doing.

    I think its not a big deal that i'm useng commands wich weren't covered in class as long as i understand them and can explane what i'm doing.


    So please can someone clarify itCbitC's code?

  4. #19
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Hmm... so strtok() hasn't been covered in class either.

    Walk along s3[] and replace all embedded spaces with tabs.
    (assumes s3[] data fields are separated by a single space as there will be formatting issues if they aren't and would require more code to align)

    Now fprintf() the three arrays s1[] s2[] and s3[] separated by tabs.

  5. #20
    Registered User
    Join Date
    Aug 2009
    Posts
    9
    Quote Originally Posted by itCbitC View Post
    Hmm... so strtok() hasn't been covered in class either.

    Walk along s3[] and replace all embedded spaces with tabs.
    (assumes s3[] data fields are separated by a single space as there will be formatting issues if they aren't and would require more code to align)

    Now fprintf() the three arrays s1[] s2[] and s3[] separated by tabs.
    No strtok() hasn't been covered but that's a function i understand now because i looked it up in C reference on the net an it isn't that difficult

    So i understand you split the 3rd string into tokens where there's a space character.

    There are some other things i don't quite get tho.

    I specified everything i don't get with /* ????? */ in my comments so maybe u could have a look at my code and explane?

    Here's my code:

    Code:
    
    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char *argv[])		/* int main ?????????????? */
    {
        FILE *fpin, *fpout;					/* declare input and output file pointer */
        char flin[256], flout[256];			/* declare input and output file name string */
    
        char *s, line[256], x[256];			/* declare pointer to ?????, and ????? */
        char tijd[50], id[50], bytes[50];	/* declare time, id and bytes string */
    
    																											
    		printf("This program converts standard Vector CANoe log files to Ecxel readable files\n\nPlease specify source filename:");			/* print programheader with programfunction and ask for input filename */
    		scanf("%s",flin);																													/* read input filename */
    	
    		/* does inputfile exist ? */
    
    		if ((fpin = fopen(flin, "r"))== NULL)																								/* if can not open inputfile for reading */
    		{
    			printf("Cannot open source file!\n");																							/* show cannot open input */
    			return 1;																						
    		}
    
    		/* if inputfile does exist */
    
    		else
    		{
    			printf("Please specify destination filename:");																					/* ask to specify destination filename */
    			scanf("%s",flout);																												/* read output filename */
    			fpout = fopen(flout, "w");																										/* open outputfile for writing */
    			fprintf(fpout,"time\tid\tdlc\tbyte0\tbyte1\tbyte2\tbyte3\tbyte4\tbyte5\tbyte6\tbyte7\n");										/* print data header in outputfile */
    
    		}
    
    
    		while(fgets(line, 256, fpin))		/* while string from inputfile is ??????? */
    		{
    
    		        if (sscanf(line, "%s%*s%s Tx %*s %[^\n]", tijd, id, bytes) == 3)		/* ??????????? */
    			{
              		  		sprintf(x, "%s\t%s", tijd, id);									/* print string time and id to file */
                			for ( s= strtok(bytes, " "); s; s = strtok(NULL, " "))			/* split bytes string into byteX when there's a space character */
                    		sprintf(x, "%s\t%s", x, s);								/* print ???? string to file */
                			fprintf(fpout, "%s\n", x);								/* ??????????????? */
            		}
    		}
        		
    		fclose(fpin);			/* close inputfile */
        	fclose(fpout);			/* close outputfile */
        	return 0;
    }
    I also would like to know how i can separate the first character i'm now putting in the bytes string to a new variable called dlc?

    The output now is ok but the first characters that are put in the outputfile from the bytes string are actually the dlc data.

    When i can ad this dlc variable in the code and put the first characters that are now in the bytes string in this dlc variable i have everything seperated like it should be.

    then i can sprintf(x, "%s\t%s\t%s", tijd, id, dlc); and handle the bytes string in the same way i'm doing now.

    Can you help me out with this?

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I copied/pasted your input file and program, but this is all I get for output:

    Code:
    time	id	dlc	byte0	byte1	byte2	byte3	byte4	byte5	byte6	byte7
    	00
    	00
    	00
    	00
    	00
    	00
    	00
    	00
    	00
    	00
    	00
    	00
    	00
    	FF
    	00
    	00
    Obviously, something didn't copy correctly if you're so close to having the right output.

    I would have used a simpler sscanf() line, and used multiple lines to make it easier to understand and to de-bug. It's a bit of a stretch to see a beginner with a one line sscanf() line, like that.

  7. #22
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by turbofizzl View Post
    No strtok() hasn't been covered but that's a function i understand now because i looked it up in C reference on the net an it isn't that difficult

    So i understand you split the 3rd string into tokens where there's a space character.
    No need for strtok(), "walk along" the last array s3[] replacing each blank with a '\t' until you reach the string terminator '\0'.
    Quote Originally Posted by turbofizzl View Post
    There are some other things i don't quite get tho.

    I specified everything i don't get with /* ????? */ in my comments so maybe u could have a look at my code and explane?
    Indent and format the code so it doesn't scroll off the right hand side as it makes it so much harder to see what's going on. Try spaces instead of tabs for proper indentation.
    Quote Originally Posted by turbofizzl View Post
    Here's my code:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main(void)		/* no arguments to main so void is ok! */
    {
    ...
    }
    I also would like to know how i can separate the first character i'm now putting in the bytes string to a new variable called dlc?

    The output now is ok but the first characters that are put in the outputfile from the bytes string are actually the dlc data.

    When i can ad this dlc variable in the code and put the first characters that are now in the bytes string in this dlc variable i have everything seperated like it should be.

    then i can sprintf(x, "%s\t%s\t%s", tijd, id, dlc); and handle the bytes string in the same way i'm doing now.

    Can you help me out with this?
    Add another control string to the sscanf() format argument to capture the dlc field and you should be all set.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21