Converting

Hello kvlclib

This example shows a simple conversion from .kme50 to .csv using kvlclib.

#include "kvlclib.h"
static void check(const char* s, int stat)
{
if (stat != kvlcOK){
printf("%s returned %d\n", s, stat);
exit(1);
}
}
int main()
{
KvlcStatus stat;
// Instantiate converter handle and specify output file + format specifier
stat = kvlcCreateConverter(&hnd, "outputfile.csv", KVLC_FILE_FORMAT_CSV);
check("kvlcCreateConverter", stat);
// Set the input file and specify input format
stat = kvlcSetInputFile(hnd, "inputfile.kme50", KVLC_FILE_FORMAT_KME50);
check("kvlcSetInputFile", stat);
// Convert file
do {
stat = kvlcConvertEvent(hnd);
if (stat == kvlcERR_FILE_EXISTS)
printf("File already exists!\n");
} while (stat == kvlcOK); // kvlcEOF when done
// Check if conversion terminated correctly
if (stat != kvlcEOF){
check("kvlcConvertEvent", stat);
}
// Check if overruns occured
stat = kvlcIsOverrunActive(hnd, &overrun);
check("kvlcIsOverrunActive", stat);
if (overrun){
printf("NOTE! The extracted data contained overrun.\n");
}
// Check for truncated CAN FD frames (dlc > 8)
stat = kvlcIsDataTruncated(hnd, &truncated);
check("kvlcIsDataTruncated", stat);
if (truncated){
printf("NOTE! The extracted data was truncated.\n");
}
// Destroy the converter
stat = kvlcDeleteConverter(hnd);
check("kvlcDeleteConverter", stat);
return 0;
}

As could be seen, kvlclib does not overwrite files by default. We had to check kvlcConvertEvent for kvlcERR_FILE_EXISTS.

stat = kvlcConvertEvent(hnd);
if (stat == kvlcERR_FILE_EXISTS)
printf("File already exists!\n");

If we want to enable automatic overwrites on the converter, we can set the property KVLC_PROPERTY_OVERWRITE.

int prop = 1;
stat = kvlcSetProperty(hnd, KVLC_PROPERTY_OVERWRITE, &prop, sizeof(int));
See also
Properties