Hey Guy's
I've had some help and am getting along alot better now.
Just two minor issues left.
I now put all the data bytes in one array called bytes, now i have to think of some way to separate the data bytes into byte 0 to 7 seperated by tabs in the outputfile.
I also created an array for the Data Length Code or dlc but when i print the content to the output file it seems the same as the id array i created.
This should not be the case.
However i discovered that the first characters of the bytes array i print in the outputfile are the characters that should be in the dlc array.
So in some way i have to get these characters in the correct dlc array and seperate the successive data bytes with tabs.
But how???
I really am stuck again.
In the end it should look somewhat 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've tried all kinds of things to solve this last problem but all i seem to get are errors.
Help, Help, Help!!!
This i my Code thusfar:
(I've left out dlc in the fprintf because otherwise i get double data in the outputfile)
Code:
#include <stdio.h>
void
leesbytes(char bytes[], FILE *fpin)
{
int i=0;
int c;
//spaties overslaan
do c = fgetc(fpin);
while( c==' ' );
while( i<64 && c!=EOF && c!='\n' )
{
bytes[i]=c;
i++;
c = fgetc(fpin);
}
bytes[i]=0;
}
int
leesveld(char veld[], FILE *fpin)
{
int i=0;
int c;
//spaties overslaan
do c = fgetc(fpin);
while( c==' ' );
//in lezen tot een spatie of newline of einde bestand
while( i<32 && c!=EOF && c!='\n' && c!=' ')
{
veld[i]=c;
i++;
c = fgetc(fpin);
}
//einde streng met NUL
veld[i]=0;
return c;
}
int main(void)
{
FILE *fpin, *fpout;
char flin[256],flout[256];
int rel;
char tijd[32],id[32],dlc[32],bytes[128];
char kolom2[32],Tx[32],kolom6[32];
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)
{
printf("Cannot open source file <%s>!\n",flin); /* if not, 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 */
fprintf(fpout,"time\tid\tdlc\tbyte0\tbyte1\tbyte2\tbyte3\tbyte4\tbyte5\tbyte6\tbyte7\n");
}
if( fpout==NULL )
{
printf("Cannot open Destination file <%s>\n",flout); /* if not, show cannot open output */
return 1;
}
rel = 0;
while( rel!=EOF )// lezen tot een EOF
{
rel = leesveld(tijd, fpin);
if( rel != '\n' )
{
rel = leesveld(kolom2, fpin);
if( rel != '\n' )
{
rel = leesveld(id, fpin);
if( rel != '\n' )
{
rel = leesveld(Tx, fpin);
if( rel != '\n' )
{
if( strcmp( Tx, "Tx")==0 )//als het 5de veld Tx is
{
leesveld(kolom6, fpin);
leesbytes(bytes, fpin);
fprintf(fpout,"%s\t%s\t%s\n",tijd,id,bytes);
}
}
}
}
}
}//einde while, einde bestand
fclose(fpin); /* close inputfile */
fclose(fpout); /* close outputfile */
return 0;
}
My Output with this Code is:
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
Where there's a space now next to the id colum there should be tabs.
so everywhere after *
3.100158 110 3* 02* 00* 00
Then everything is in seperate colums like it should be.
I really hope someone can help me out because i'm so close to my end goal and i can't seem to get it right.
This is all thats in the way of me getting a nice few weeks of holliday.
Otherwise i should have left by now