comparison ostc4pack/src/OSTC4pack_V4.cpp @ 699:01f40cb1057e

Cleanup warnings: The code still contained several warnings which have now been resolved. Big thank you to Thomas :-)
author Ideenmodellierer
date Tue, 18 Oct 2022 20:56:19 +0200
parents ad98da7e74f8
children
comparison
equal deleted inserted replaced
698:2c2b9c6eb089 699:01f40cb1057e
414 if (argc != 3) { 414 if (argc != 3) {
415 fprintf(stderr, "Usage: OSTC4pack_V4 <type> <bin file>\n"); 415 fprintf(stderr, "Usage: OSTC4pack_V4 <type> <bin file>\n");
416 return(-1); 416 return(-1);
417 } 417 }
418 418
419 FILE *fp, * fpout; 419 FILE *fp;
420 size_t len; 420 size_t len;
421 unsigned char buf[1050000]; 421 unsigned char buf[1050000];
422 char *file = argv[2]; 422 char *file = argv[2];
423 int type = atoi(argv[1]); 423 int type = atoi(argv[1]);
424 unsigned int pruefsumme; 424 unsigned int pruefsumme;
425 425
426 //write File with length and cheksum 426 //write File with length and cheksum
427 char filename[500], filenameout[510] ; 427 char filename[500], filenameout[511];
428 sprintf(filename,"%s",file); 428 sprintf(filename,"%s",file);
429 int filelength = strlen(filename); 429 int filelength = strlen(filename);
430 filename[filelength -4] = 0; 430 filename[filelength -4] = 0;
431 431
432 if (NULL == (fp = fopen(file, "rb"))) 432 if (NULL == (fp = fopen(file, "rb")))
433 { 433 {
434 printf("Unable to open %s for reading\n", file); 434 printf("Unable to open %s for reading\n", file);
435 return -1; 435 return -1;
436 } 436 }
437 len = fread(buf, sizeof(char), sizeof(buf), fp); 437 len = fread(buf, sizeof(char), sizeof(buf), fp);
438 printf("%d bytes read (hex: %#x )\n", len,len); 438 printf("%d bytes read (hex: %#x )\n", (uint32_t)len, (uint32_t)len);
439 // unsigned int checksum = crc32c_checksum(buf, len); 439 // unsigned int checksum = crc32c_checksum(buf, len);
440 unsigned int checksum = CRC_CalcBlockCRC((uint32_t *)buf, (uint32_t)(len/4)); 440 unsigned int checksum = CRC_CalcBlockCRC((uint32_t *)buf, (uint32_t)(len/4));
441 printf("The checksum of %s is %#x\n", file, checksum); 441 printf("The checksum of %s is %#x\n", file, checksum);
442 442
443 fclose(fp); 443 fclose(fp);
453 453
454 buf2[0] = 0xFF & (len >> 24);; 454 buf2[0] = 0xFF & (len >> 24);;
455 buf2[1] = 0xFF & (len >> 16);; 455 buf2[1] = 0xFF & (len >> 16);;
456 buf2[2] = 0xFF & (len >> 8); 456 buf2[2] = 0xFF & (len >> 8);
457 buf2[3] = 0xFF & len; 457 buf2[3] = 0xFF & len;
458 fpout = fopen(filenameout, "wb"); 458 fp = fopen(filenameout, "wb");
459 fwrite(buf2,sizeof(char),4,fp); 459 fwrite(buf2,sizeof(char),4,fp);
460 460
461 461
462 unsigned char buf3offset[4]; 462 unsigned char buf3offset[4];
463 unsigned char bufVersion[4]; 463 unsigned char bufVersion[4];
503 503
504 fwrite(bufVersion,sizeof(char),4,fp); 504 fwrite(bufVersion,sizeof(char),4,fp);
505 505
506 for(int i = 0;i <len;i++) 506 for(int i = 0;i <len;i++)
507 { 507 {
508 if(fwrite(&buf[i],1,1,fpout) != 1) 508 if(fwrite(&buf[i],1,1,fp) != 1)
509 printf("error writing\n"); 509 printf("error writing\n");
510 } 510 }
511 511
512 512
513 buf2[0] = 0xFF & (checksum >> 24);// & 0xFF000000; 513 buf2[0] = 0xFF & (checksum >> 24);// & 0xFF000000;
514 buf2[1] = 0xFF & (checksum >> 16); 514 buf2[1] = 0xFF & (checksum >> 16);
515 buf2[2] = 0xFF & (checksum >> 8); 515 buf2[2] = 0xFF & (checksum >> 8);
516 buf2[3] = 0xFF & checksum; 516 buf2[3] = 0xFF & checksum;
517 517
518 fwrite(buf2,sizeof(char),4,fp); 518 fwrite(buf2,sizeof(char),4,fp);
519 519
520 } 520 fclose(fp);
521 }