From: Michal MalĂ˝ Date: Thu, 31 Jul 2014 15:56:00 +0000 (+0200) Subject: - Do not differentiate fixed and floating signals at all X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=8462904bcd5fcf9723af360c99ed7bfb02e72b52;p=libHPCS.git - Do not differentiate fixed and floating signals at all - Guess step for power and voltage --- diff --git a/libhpcs.c b/libhpcs.c index b418189..034294f 100644 --- a/libhpcs.c +++ b/libhpcs.c @@ -156,19 +156,21 @@ enum HPCS_RetCode hpcs_read_file(const char* filename, struct HPCS_MeasuredData* switch (mdata->file_type) { case HPCS_TYPE_CE_CCD: - pret = read_signal(datafile, &mdata->data, &mdata->data_count, CE_CCD_STEP, mdata->sampling_rate, SIGTYPE_FLOATING); + pret = read_signal(datafile, &mdata->data, &mdata->data_count, CE_CCD_STEP, mdata->sampling_rate); break; case HPCS_TYPE_CE_CURRENT: - pret = read_signal(datafile, &mdata->data, &mdata->data_count, guess_current_step(mdata), mdata->sampling_rate, SIGTYPE_FIXED); + pret = read_signal(datafile, &mdata->data, &mdata->data_count, guess_current_step(mdata), mdata->sampling_rate); break; case HPCS_TYPE_CE_DAD: - pret = read_signal(datafile, &mdata->data, &mdata->data_count, CE_DAD_STEP, mdata->sampling_rate, SIGTYPE_FIXED); + pret = read_signal(datafile, &mdata->data, &mdata->data_count, CE_DAD_STEP, mdata->sampling_rate); break; case HPCS_TYPE_CE_POWER: + case HPCS_TYPE_CE_VOLTAGE: + pret = read_signal(datafile, &mdata->data, &mdata->data_count, guess_elec_sigstep(mdata), mdata->sampling_rate); + break; case HPCS_TYPE_CE_PRESSURE: case HPCS_TYPE_CE_TEMPERATURE: - case HPCS_TYPE_CE_VOLTAGE: - pret = read_signal(datafile, &mdata->data, &mdata->data_count, CE_WORK_PARAM_STEP, mdata->sampling_rate, SIGTYPE_FIXED); + pret = read_signal(datafile, &mdata->data, &mdata->data_count, CE_WORK_PARAM_STEP, mdata->sampling_rate); break; case HPCS_TYPE_UNKNOWN: ret = HPCS_E_UNKNOWN_TYPE; @@ -237,6 +239,22 @@ static HPCS_step guess_current_step(const struct HPCS_MeasuredData* mdata) return CE_WORK_PARAM_STEP; } +static HPCS_step guess_elec_sigstep(const struct HPCS_MeasuredData* mdata) +{ + if (strcmp(mdata->cs_ver, CHEMSTAT_VER_B0625)) { + switch (mdata->file_type) { + case HPCS_TYPE_CE_POWER: + return CE_ENERGY_STEP; + default: + return CE_WORK_PARAM_OLD_STEP; + } + } + + + + return CE_WORK_PARAM_STEP; +} + static bool guess_p_meaning(const struct HPCS_MeasuredData* mdata) { if (strcmp(mdata->cs_ver, CHEMSTAT_VER_B0625) == 0) @@ -253,7 +271,7 @@ static void guess_sampling_rate(struct HPCS_MeasuredData* mdata) mdata->sampling_rate *= 10; break; default: - mdata->sampling_rate = 1.67; + mdata->sampling_rate = CE_WORK_PARAM_SAMPRATE; } } } @@ -472,7 +490,7 @@ static uint8_t month_to_number(const char* const month) } static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pairs, size_t* pairs_count, - const HPCS_step step, const double sampling_rate, const enum HPCS_SignalType sigtype) + const HPCS_step step, const double sampling_rate) { const double time_step = 1 / (60 * sampling_rate); size_t alloc_size = 60 * sampling_rate; @@ -550,33 +568,30 @@ static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pair PR_DEBUGF("Got marker at 0x%lx\n", segments_read - 1); continue; case DCHECK_NO_MARKER: - if (sigtype == SIGTYPE_FLOATING) { - /* Check for a sudden jump of value */ - if (raw[0] == BIN_MARKER_JUMP && raw[1] == BIN_MARKER_END) { - char lraw[4]; - int32_t _v; - - PR_DEBUGF("Value has jumped at 0x%lx\n", segments_read); - fread(lraw, LARGE_SEGMENT_SIZE, 1, datafile); - if (feof(datafile) || ferror(datafile)) { - free(*pairs); - *pairs = NULL; - return PARSE_E_CANT_READ; - } - - be_to_cpu(lraw); - _v = *(int32_t*)lraw; - value = _v * step; - goto write_value; + /* Check for a sudden jump of value */ + if (raw[0] == BIN_MARKER_JUMP && raw[1] == BIN_MARKER_END) { + char lraw[4]; + int32_t _v; + + PR_DEBUGF("Value has jumped at 0x%lx\n", segments_read); + fread(lraw, LARGE_SEGMENT_SIZE, 1, datafile); + if (feof(datafile) || ferror(datafile)) { + free(*pairs); + *pairs = NULL; + return PARSE_E_CANT_READ; } - } - int16_t _v; - be_to_cpu(raw); - _v = *(int16_t*)raw; - value += _v * step; + be_to_cpu(lraw); + _v = *(int32_t*)lraw; + value = _v * step; + } else { + int16_t _v; + + be_to_cpu(raw); + _v = *(int16_t*)raw; + value += _v * step; + } -write_value: (*pairs)[data_segments_read].time = time; (*pairs)[data_segments_read].value = value; data_segments_read++; diff --git a/libhpcs.h b/libhpcs.h index aea3e48..04e9042 100644 --- a/libhpcs.h +++ b/libhpcs.h @@ -32,11 +32,6 @@ enum HPCS_RetCode { HPCS_E_UNKNOWN_TYPE }; -enum HPCS_SignalType { - SIGTYPE_FIXED, - SIGTYPE_FLOATING -}; - struct HPCS_Date { uint32_t year; uint8_t month; diff --git a/libhpcs_p.h b/libhpcs_p.h index b8db66c..1d305bf 100644 --- a/libhpcs_p.h +++ b/libhpcs_p.h @@ -58,7 +58,12 @@ const char* MON_DEC_STR = "Dec"; const HPCS_step CE_CURRENT_STEP = 0.01; const HPCS_step CE_CCD_STEP = 0.0000596046450027643; const HPCS_step CE_DAD_STEP = 0.000476837158203; +const HPCS_step CE_ENERGY_STEP = 0.0000055555555; const HPCS_step CE_WORK_PARAM_STEP = 0.001; +const HPCS_step CE_WORK_PARAM_OLD_STEP = 0.000083333333; + +/* Hardcoded sampling rates */ +const double CE_WORK_PARAM_SAMPRATE = 1.67; /* Offsets containing data of interest in .ch files */ const HPCS_offset DATA_OFFSET_FILE_DESC = 0x15B; @@ -95,13 +100,14 @@ const char* HPCS_E__UNKNOWN_EC_STR = "Unknown error code."; static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_FileType* file_type, const bool p_means_pressure); static enum HPCS_DataCheckCode check_for_marker(const char* const segment, size_t* const next_marker_idx); static HPCS_step guess_current_step(const struct HPCS_MeasuredData* mdata); +static HPCS_step guess_elec_sigstep(const struct HPCS_MeasuredData *mdata); static bool guess_p_meaning(const struct HPCS_MeasuredData* mdata); static void guess_sampling_rate(struct HPCS_MeasuredData* mdata); static enum HPCS_ParseCode read_dad_wavelength(FILE* datafile, struct HPCS_Wavelength* const measured, struct HPCS_Wavelength* const reference); static uint8_t month_to_number(const char* const month); static enum HPCS_ParseCode read_date(FILE* datafile, struct HPCS_Date* const date); static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pairs, size_t* pairs_count, - const HPCS_step step, const double sampling_rate, const enum HPCS_SignalType sigtype); + const HPCS_step step, const double sampling_rate); static enum HPCS_ParseCode read_sampling_rate(FILE* datafile, double* sampling_rate); static enum HPCS_ParseCode read_string_at_offset(FILE* datafile, const HPCS_offset, char** const result);