/****************************************************************************** * * Title : slinkDataConv.c * Version 0.0, * Description: * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include /****************************************************************************** * Definitions * ******************************************************************************/ #define SUCCESS (0) /****************************************************************************** * Static Function Declarations * ******************************************************************************/ /****************************************************************************** * Main * ******************************************************************************/ int main(int argc, char *argv[]){ FILE *txtFileHandle; FILE *binFileHandle; size_t bytesRead; char errorMessage[200]; int status; long FileSize, i; char txtFileName[300]; char binFileName[300]; char directory[300]; int hexValue; unsigned char binValue; unsigned char convertValue; int length, dirLength; char line[256]; unsigned int index, hex, slwen, slclk, slclkPrevious; memset(binFileName, 0, 300); memset(txtFileName, 0, 300); strcpy(txtFileName,argv[1]); /* get input hex file name (*.hex) */ printf("%s\n", txtFileName); /* create binary file name (*.bin) */ length=strlen(txtFileName)-4; strncpy(binFileName, txtFileName, length); strcat(binFileName,".bin"); printf("%s\n", binFileName); txtFileHandle = fopen (txtFileName, "r"); /* open text file for read */ binFileHandle = fopen (binFileName, "wb"); /* open binary file for write */ i=0; slclkPrevious=0; while(fgets(line,256,txtFileHandle) != NULL) { if((i++)<7) continue; status=sscanf(line,"%d %X %d %d", &index, &hex, &slwen, &slclk); if(status!=4){ break; } if(slwen==0){ fwrite (&hex, 4, 1, binFileHandle); } slclkPrevious=slclk; } /* close files */ status=fclose(txtFileHandle); status=fclose(binFileHandle); //printf("----- PRESS ANY KEY -------"); //getchar(); return(0); } /******************************************************************************/