mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
client done
This commit is contained in:
@ -8,43 +8,34 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
/** (used by multi and sls)
|
||||
* reads a short int raw data file
|
||||
* @param infile input file stream
|
||||
/**
|
||||
* @param data array of data values
|
||||
* @param nch number of channels
|
||||
* @param offset start channel value
|
||||
* @returns OK or FAIL if it could not read the file or data=NULL
|
||||
*/
|
||||
int readDataFile(std::ifstream &infile, short int *data, int nch,
|
||||
int offset = 0);
|
||||
|
||||
/** (used by multi and sls)
|
||||
* reads a short int rawdata file
|
||||
* @param fname name of the file to be read
|
||||
/**
|
||||
* @param data array of data value
|
||||
* @param nch number of channels
|
||||
* @returns OK or FAIL if it could not read the file or data=NULL
|
||||
*/
|
||||
int readDataFile(std::string fname, short int *data, int nch);
|
||||
|
||||
/** (used by multi and sls)
|
||||
* writes a short int raw data file
|
||||
* @param outfile output file stream
|
||||
std::vector<char> readBinaryFile(const std::string &fname,
|
||||
const std::string &errorPrefix);
|
||||
|
||||
/**
|
||||
* @param nch number of channels
|
||||
* @param data array of data values
|
||||
* @param offset start channel number
|
||||
* @returns OK or FAIL if it could not write the file or data=NULL
|
||||
*/
|
||||
int writeDataFile(std::ofstream &outfile, int nch, short int *data,
|
||||
int offset = 0);
|
||||
|
||||
/** (used by multi and sls)
|
||||
* writes a short int raw data file
|
||||
* @param fname of the file to be written
|
||||
/**
|
||||
* @param nch number of channels
|
||||
* @param data array of data values
|
||||
* @returns OK or FAIL if it could not write the file or data=NULL
|
||||
*/
|
||||
int writeDataFile(std::string fname, int nch, short int *data);
|
||||
|
||||
|
@ -254,7 +254,8 @@ enum detFuncs {
|
||||
F_GET_READOUT_SPEED,
|
||||
F_SET_READOUT_SPEED,
|
||||
F_GET_KERNEL_VERSION,
|
||||
F_PROGRAM_KERNEL,
|
||||
F_UPDATE_KERNEL,
|
||||
F_UPDATE_DETECTOR_SERVER,
|
||||
|
||||
NUM_DET_FUNCTIONS,
|
||||
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
|
||||
@ -611,7 +612,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
|
||||
case F_GET_READOUT_SPEED: return "F_GET_READOUT_SPEED";
|
||||
case F_SET_READOUT_SPEED: return "F_SET_READOUT_SPEED";
|
||||
case F_GET_KERNEL_VERSION: return "F_GET_KERNEL_VERSION";
|
||||
case F_PROGRAM_KERNEL: return "F_PROGRAM_KERNEL";
|
||||
case F_UPDATE_DETECTOR_SERVER: return "F_UPDATE_DETECTOR_SERVER";
|
||||
|
||||
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
|
||||
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";
|
||||
|
@ -53,6 +53,48 @@ int readDataFile(std::string fname, short int *data, int nch) {
|
||||
return iline;
|
||||
}
|
||||
|
||||
std::vector<char> readBinaryFile(const std::string &fname,
|
||||
const std::string &errorPrefix) {
|
||||
// check if it exists
|
||||
struct stat st;
|
||||
if (stat(fname.c_str(), &st) != 0) {
|
||||
throw sls::RuntimeError(errorPrefix +
|
||||
std::string(": file does not exist"));
|
||||
}
|
||||
|
||||
FILE *fp = fopen(fname.c_str(), "rb");
|
||||
if (fp == nullptr) {
|
||||
throw sls::RuntimeError(errorPrefix +
|
||||
std::string(": Could not open file: ") + fname);
|
||||
}
|
||||
|
||||
// get file size to print progress
|
||||
if (fseek(fp, 0, SEEK_END) != 0) {
|
||||
throw sls::RuntimeError(errorPrefix +
|
||||
std::string(": Seek error in src file"));
|
||||
}
|
||||
size_t filesize = ftell(fp);
|
||||
if (filesize <= 0) {
|
||||
throw sls::RuntimeError(errorPrefix +
|
||||
std::string(": Could not get length of file"));
|
||||
}
|
||||
rewind(fp);
|
||||
|
||||
std::vector<char> buffer(filesize, 0);
|
||||
if (fread(buffer.data(), sizeof(char), filesize, fp) != filesize) {
|
||||
throw sls::RuntimeError(errorPrefix +
|
||||
std::string(": Could not read file"));
|
||||
}
|
||||
|
||||
if (fclose(fp) != 0) {
|
||||
throw sls::RuntimeError(errorPrefix +
|
||||
std::string(": Could not close file"));
|
||||
}
|
||||
|
||||
LOG(logDEBUG1) << "Read file into memory";
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int writeDataFile(std::ofstream &outfile, int nch, short int *data,
|
||||
int offset) {
|
||||
if (data == nullptr)
|
||||
|
Reference in New Issue
Block a user