/* * sizeGIS.c * Compile with gcc -Wall atmel_generic.c ihex.c srecord.c sizeGIS.c -o sizeGIS * * Very straight forward program that makes use of atmel_generic.h, ihex.h, and srecord.h. * This program counts the total number of data bytes stored in an Atmel Generic, * Intel HEX, or Motorola S-Record formatted file--useful for finding out exactly how * much memory the formatted file will use when it is flashed/transferred/downloaded/etc. * * Author: Vanya A. Sergeev * * Public Domain * */ #include #include #include "srecord.h" #include "atmel_generic.h" #include "ihex.h" int main (int argc, const char * argv[]) { FILE *fp; AtmelGenericRecord arec; IHexRecord irec; SRecord srec; int recordCount = 0, dataByteSum = 0; if (argc < 3) { fprintf(stderr, "Usage: %s \n", argv[0]); fprintf(stderr, "This program counts the total number of data bytes stored in an Atmel Generic, "); fprintf(stderr, "Intel HEX, or Motorola S-Record formatted file--useful for finding out exactly how "); fprintf(stderr, "much memory the formatted file will use when it is flashed/transferred/downloaded/etc.\n\n"); fprintf(stderr, " can be generic, ihex, or srecord.\n"); fprintf(stderr, " is the path to the file containing the records.\n"); return -1; } fp = fopen(argv[2], "r"); if (fp == NULL) { perror("Error opening file!"); return -1; } if (strcasecmp(argv[1], "generic") == 0) { while (Read_AtmelGenericRecord(&arec, fp) == ATMEL_GENERIC_OK) { recordCount++; dataByteSum += 2; /* Data field in every Atmel Generic record is a word (2 bytes) */ } } else if (strcasecmp(argv[1], "ihex") == 0) { while (Read_IHexRecord(&irec, fp) == IHEX_OK) { /* Only count data records */ if (irec.type == IHEX_TYPE_00) { recordCount++; dataByteSum += irec.dataLen; } } } else if (strcasecmp(argv[1], "srecord") == 0) { while (Read_SRecord(&srec, fp) == SRECORD_OK) { /* Only count data records */ if (srec.type == SRECORD_TYPE_S1 || srec.type == SRECORD_TYPE_S2 || srec.type == SRECORD_TYPE_S3) { recordCount++; dataByteSum += srec.dataLen; } } } else { fprintf(stderr, "Invalid file format specified!\n"); fclose(fp); return -1; } printf("Number of data records: %d\n", recordCount); printf("Number of data bytes: %d\n", dataByteSum); fclose(fp); return 0; }