diff --git a/src/drv/fmReadCoeff.c b/src/drv/fmReadCoeff.c index 90d2410b4f75e6d80f7dc80265131018ef211377..597780b7ec3f55189eb1b30450a943b951f9afd2 100644 --- a/src/drv/fmReadCoeff.c +++ b/src/drv/fmReadCoeff.c @@ -30,9 +30,9 @@ #include "fm10Gen.h" #include "fmReadCoeff.h" #include "crc.h" +#include "util/user/check_file_crc.h" int getwords( char*, char*[], int ); -extern int checkFileCrc( char* ); /* Cat string and make upper case */ static char* diff --git a/src/epics/edcu/standalone_edcu.cc b/src/epics/edcu/standalone_edcu.cc index e4c277b5323cdf2bdcaac8be2a12539be090ac78..f453d9cba9644ca458672d399a613d6672aa99f3 100644 --- a/src/epics/edcu/standalone_edcu.cc +++ b/src/epics/edcu/standalone_edcu.cc @@ -58,6 +58,7 @@ extern "C" { #include "gps.hh" #include "args.h" #include "simple_pv.h" +#include "util/user/check_file_crc.h" #include <iostream> @@ -248,8 +249,6 @@ private: // Function prototypes // **************************************************************************************** -int checkFileCrc( const char* ); - typedef union edc_data_t { int16_t data_int16; @@ -1170,31 +1169,6 @@ edcuInitialize( const std::string& mbuf_name, return EdcuClock( sync_source, delay_ms ); } -/// Common routine to check file CRC. -/// @param[in] *fName Name of file to check. -/// @return File CRC or -1 if file not found. -int -checkFileCrc( const char* fName ) -{ - char buffer[ 256 ]; - FILE* pipePtr; - struct stat statBuf; - long chkSum = -99999; - strcpy( buffer, "cksum " ); - strcat( buffer, fName ); - if ( !stat( fName, &statBuf ) ) - { - if ( ( pipePtr = popen( buffer, "r" ) ) != NULL ) - { - fgets( buffer, 256, pipePtr ); - pclose( pipePtr ); - sscanf( buffer, "%ld", &chkSum ); - } - return ( chkSum ); - } - return ( -1 ); -} - std::pair< std::string, int > parse_address( const std::string& str ) { diff --git a/src/epics/seq/main.cc b/src/epics/seq/main.cc index acdaa35467493f5d3e564209f4b7ae02267e52ac..88cd9227a1c5cdd5fb0b4090684ef4179c771346 100644 --- a/src/epics/seq/main.cc +++ b/src/epics/seq/main.cc @@ -52,6 +52,7 @@ extern "C" { #include "math.h" #include "rcgversion.h" #include "sdf_file_loaded.h" +#include "util/user/check_file_crc.h" #define epicsExportSharedSymbols #include "asLib.h" @@ -294,7 +295,6 @@ using ADDRESS = dbAddr; // Function prototypes **************************************************************************************** -extern "C" int checkFileCrc(const char *); bool isAlarmChannelRaw(const char *); int checkFileMod( const char* , time_t* , int ); unsigned int filtCtrlBitConvert(unsigned int); @@ -785,29 +785,7 @@ checkFileMod( const char* fName, time_t* last_mod_time, int gettime ) } } -/// Common routine to check file CRC. -/// @param[in] *fName Name of file to check. -/// @return File CRC or -1 if file not found. -extern "C" int checkFileCrc(const char *fName) { - char cbuf[128]; - char *cp; - int flen = 0; - int clen = 0; - unsigned int crc = 0; - FILE *fp = fopen(fName, "r"); - if (fp == NULL) { - return 0; - } - while ((cp = fgets(cbuf, 128, fp)) != NULL) { - clen = strlen(cbuf); - flen += clen; - crc = crc_ptr(cbuf, clen, crc); - } - crc = crc_len(flen, crc); - fclose(fp); - return crc; -} /// Quick convert of filter switch settings to match SWMASK /// @param[in] v UINT32 representation of filter module switch setting. diff --git a/src/epics/seq/sdf_monitor.c b/src/epics/seq/sdf_monitor.c index 13d3cfe38c2635b9a50ee99c6d883b86ea95749f..cab7c70b588da56043a098d4ebe373d13825ea39 100644 --- a/src/epics/seq/sdf_monitor.c +++ b/src/epics/seq/sdf_monitor.c @@ -44,6 +44,7 @@ of this distribution. #include "cadef.h" #include "fb.h" #include "../../drv/gpstime/gpstime.h" +#include "util/user/check_file_crc.h" #define GSDF_MAX_CHANS 30000 // Gloabl variables **************************************************************************************** @@ -57,7 +58,6 @@ char statelogfilename[128]; unsigned char naughtyList[GSDF_MAX_CHANS][64]; // Function prototypes **************************************************************************************** -int checkFileCrc(char *); void getSdfTime(char *); void logFileEntry(char *); @@ -444,29 +444,6 @@ void gsdfInitialize(char *shmem_fname) } - -/// Common routine to check file CRC. -/// @param[in] *fName Name of file to check. -/// @return File CRC or -1 if file not found. -int checkFileCrc(char *fName) -{ -char buffer[256]; -FILE *pipePtr; -struct stat statBuf; -long chkSum = -99999; - strcpy(buffer, "cksum "); - strcat(buffer, fName); - if (!stat(fName, &statBuf) ) { - if ((pipePtr = popen(buffer, "r")) != NULL) { - fgets(buffer, 256, pipePtr); - pclose(pipePtr); - sscanf(buffer, "%ld", &chkSum); - } - return(chkSum); - } - return(-1); -} - /// Routine for reading GPS time from model EPICS record. /// @param[out] timestring Pointer to char string in which GPS time is to be written. void getSdfTime(char *timestring) diff --git a/src/include/util/user/check_file_crc.h b/src/include/util/user/check_file_crc.h new file mode 100644 index 0000000000000000000000000000000000000000..f756df0f4a579d03330fd6e59346585ca3cedec1 --- /dev/null +++ b/src/include/util/user/check_file_crc.h @@ -0,0 +1,56 @@ +// +// Created by jonathan.hanks on 3/30/22. +// + +#ifndef DAQD_TRUNK_CHECK_FILE_CRC_H +#define DAQD_TRUNK_CHECK_FILE_CRC_H + +#include <stdio.h> +#include <string.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#include "crc.h" + + +/// Common routine to check file CRC. +/// @param[in] *fName Name of file to check. +/// @return File CRC or -1 if file not found. +static inline int +checkFileCrc( const char* fName ) +{ + char cbuf[ 128 ]; + char* cp = 0; + int flen = 0; + int clen = 0; + unsigned int crc = 0; + FILE* fp = NULL; + + if ( !fName ) + { + return -1; + } + fp = fopen( fName, "r" ); + if ( fp == NULL ) + { + return -1; + } + + while ( ( cp = fgets( cbuf, 128, fp ) ) != NULL ) + { + clen = strlen( cbuf ); + flen += clen; + crc = crc_ptr( cbuf, clen, crc ); + } + crc = crc_len( flen, crc ); + fclose( fp ); + return crc; +} + +#ifdef __cplusplus +} +#endif + +#endif // DAQD_TRUNK_CHECK_FILE_CRC_H