File Formats & Automotive Data Acquisition 
by Lee R. Copp


Figure 1. 

Field Name                      Field Value

FORMAT                            BINARY
FILE_TYPE                         TIME_HISTORY
TIME_TYPE                         RESPONSE
CHANNELS                          35
SCALE.CHAN_1                      0.36639
DESC.CHAN_1                       LF SPINDLE F/A FORCE (VFX)
UNITS.CHAN_1                      LBS
DATE                              7-FEB-97  10:00:06
<Separator>
=FF
<Binary Data>
=82=FF=81=FF=88=FF=86=FF}=FF}=FF|=FF{=FF=80=FF=7F=FFx=FFv=FF{=FF~=FF{=FFv=
=FFr=FFx=FFy=FFs=FFv=FFz=FFx=FFy=FFw=FFu=FF{=FF~=FFz=FFx=FF=7F=FF=87=FF
.=FF=83=FF=82=FF=82=FF=87=FF=86=FF=84=FF=83=FF=82=FF...=FF=89=FF=8A=FF==89=FF=83=FF=86=FF=8B=FF=89=FF=8D=FF=8D=FF=89=FF=8F=FF=8E=FF=83=FF|=FFt=FF=
n=FFl=FFe=FFf=FFn
=FFn=FFk=FFa=FFY=FF_=FF_=FFZ=FF]=FFa=FFh=FFh=FF]=FFU=FFP=FFO=FFS=FFZ=FFa=FF=
a=FFd=FFg=FF`=FFU=FFL=FFO=FFZ=FFR=FFK=FFQ=FF
O=FFS=FFW=FFR=FFT=FFT=FFP=FFQ=FFN=FFJ=FFM=FFO=FFO=FFJ=FFF=FFL=FFN=FFH=FFH=
=FFF=FFC=FFQ=FF[=FFO=FFI=FFF=FFF=FF
Q=FFO=FFF=FFK=FFN=FFU=FF^=FFV=FFJ=FFH=FFP=FFU=FFM=FFI=FFH=FFF=FFQ=FFW=FFO=
=FFE=FFE=FFP=FFT=FFM=FFD=FF>=FFG
=FFS=FFQ=FFI=FFB=FF?=FFF=FFR=FFS=FFG=FFE=FFO=FFT=FFT=FFQ=FFH=FFD=FFL=FF\=FF=
a=FFU=FFN=FFP=FF\=FFh=FF_=FFS=FFU=FFZ
=FFd=FFl=FFi=FFa=FF_=FFg=FFm=FFj=FFf=FF`=FF\=FFg=FFn=FFe=FF^=FFZ=FFb=FFo=FF=
o=FFi=FFa=FF^=FFm=FFv=FFq=FFn=FFf=FFh=FFw=FFw=FFs=FFq
=FFh=FFk=FF{=FF=82=FFy=FFo=FFu=FF}=FF=82=FF=88=FF=81=FFw=FF=82=FF=8F=FF=95=
=FF=90=FF...=FF=83=FF

Listing One
#include "DataFileReader_MSC.h"
#define _ThisClass      DataFileReader_MSC
#define _NumBaseClass   0

DataFileReader_MSC::DataFileReader_MSC()
{
    // initialize class
    InitializeDataFileReaderClass_DFR();
}
DataFileReader_MSC::DataFileReader_MSC(
    char * pcharFileName)
{
    // initialize class
    InitializeDataFileReaderClass_DFR();
    // load file during construction
    LoadDataFile_DFR(pcharFileName);
}
DataFileReader_MSC::~DataFileReader_MSC()
{
    // free memory
    if (pvoid_FileBuffer)
    {
    // clear buffer
    delete[]pvoid_FileBuffer;
    pvoid_FileBuffer = NULL;
    }
    else {}
}
void * DataFileReader_MSC::GetDataPointer_DFR()
{
    // return pointer to start of data
    return(pvoid_DataStart);
}
unsigned long DataFileReader_MSC::GetFileSize_DFR()
{
    // return file size
    return(ul_FileSize);
}
void * DataFileReader_MSC::GetHeaderPointer_DFR()
{
    // return pointer to start of header
    return(pvoid_HeaderStart);
}
void DataFileReader_MSC::InitializeDataFileReaderClass_DFR()
{
    // set defaults
    pvoid_FileBuffer = NULL;
    pvoid_HeaderStart = NULL;
    pvoid_DataStart = NULL;
}
int DataFileReader_MSC::LoadDataFile_DFR(
    char * pcharFileName)
{
    // declare local variables
    FILE *hFile;
    int iReturn;
    // check for previously loaded file
    if (pvoid_FileBuffer)
    {
    // clear previous buffer
    delete[]pvoid_FileBuffer;
    pvoid_FileBuffer = NULL;
    }
    else {}
    // open file
    hFile = fopen(pcharFileName, "rb");
    if (hFile)          // valid stream returned from fopen function
    {
      // get file size
      fseek(hFile, 0L , SEEK_END);
      ul_FileSize = ftell(hFile);
      if (ul_FileSize > 0)                  // valid file size
      {
        // get memory for file
        pvoid_FileBuffer = new unsigned char [ul_FileSize];
        // load file into buffer
        rewind(hFile);
        if (fread(pvoid_FileBuffer,sizeof(unsigned char),ul_FileSize,hFile))
        {
          // set internal pointers
          pvoid_HeaderStart = pvoid_FileBuffer;
          pvoid_DataStart = pvoid_FileBuffer;

          // file loaded ok
          iReturn = FILE_OK_DFR;
        }
        else
        {
          // ERROR -- load failure
          iReturn = ERROR_FILE_LOAD_DFR;
        }
      }
      else
      {
        // ERROR -- seek failure
        iReturn = ERROR_FILE_SEEK_DFR;
      }
    }
    else
    {
    // ERROR -- file not opened
    iReturn = ERROR_FILE_OPEN_DFR;
    }
    // return results
    return(iReturn);
}
void DataFileReader_MSC::SetDataPointer_DFR(
    void *pvoidStart)
{
    // set internal pointer to start of data
    pvoid_DataStart = pvoidStart;
}
void DataFileReader_MSC::SetHeaderPointer_DFR(
    void *pvoidStart)
{
    // set internal pointer to start of header
    pvoid_HeaderStart = pvoidStart;
}
#undef _ThisClass
#undef _NumBaseClass


Listing Two
#include "datafilereader_msc.h"

// declare class
DataFileReader_MSC DataFile;

int main(int argc, char *argv[], char *env[])
{
  // declare local variables
  void * pvoidHeader;
  void * pvoidData;

  char * pcharHeader;
  char * pcharData;
  if (argc == 2)
  {
    if (!DataFile.LoadDataFile_DFR(argv[1]))
    {
      // set local header pointers
      pvoidHeader = DataFile.GetHeaderPointer_DFR();
      pcharHeader = (char*)pvoidHeader;
      // find data section
      pcharData = strstr(pcharHeader, "DATA");
      // update local & DataFileReader data pointers      
      pvoidData = (void*)pcharData;      
      DataFile.SetDataPointer_DFR(pvoidData);
      // print data section to console
      cout << pcharData;
    }
    else
    {
      // error loading file
      cout << "Dooh!!";
    }
  }
  return (0);
}

Listing Three
HEADER:

This section normally contains creation information (who/what/when/where/why) along with various data acqusition settings such as sample rates and sensor configurations for each channel.

DATA:

This section contains the binary data which was recorded.  It is normally written in a float or integer format which means the derived class must know how to interpret it correctly.


5


