[feat] add check for sig fault
This commit is contained in:
parent
0f8d44f9a3
commit
2163ed9417
@ -30,6 +30,7 @@ void device_init(void)
|
||||
{
|
||||
flag.filter = data_ltc1867.calc_flag;
|
||||
flag.concentration = flag.filter;
|
||||
flag.gas_fault = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
void system_init(void)
|
||||
|
||||
@ -102,7 +102,11 @@ const uint8_t * const modbus_map_ro[] = {
|
||||
[OFFSET_MAIN + 61] = (uint8_t *)(&bitmap_main->gasn_avail_bitmap) + 2,
|
||||
[OFFSET_MAIN + 62] = (uint8_t *)(&bitmap_main->gasn_avail_bitmap) + 1,
|
||||
[OFFSET_MAIN + 63] = (uint8_t *)(&bitmap_main->gasn_avail_bitmap) + 0,
|
||||
[(OFFSET_MAIN + 64) ... (OFFSET_MAIN + 511)] = (uint8_t *)0,
|
||||
[OFFSET_MAIN + 64] = (uint8_t *)(&flag.gas_fault) + 3,
|
||||
[OFFSET_MAIN + 65] = (uint8_t *)(&flag.gas_fault) + 2,
|
||||
[OFFSET_MAIN + 66] = (uint8_t *)(&flag.gas_fault) + 1,
|
||||
[OFFSET_MAIN + 67] = (uint8_t *)(&flag.gas_fault) + 0,
|
||||
[(OFFSET_MAIN + 68) ... (OFFSET_MAIN + 511)] = (uint8_t *)0,
|
||||
|
||||
[OFFSET_GAS1 + 0] = (uint8_t *)(&bitmap_main->gas1_sub_id) + 3,
|
||||
[OFFSET_GAS1 + 1] = (uint8_t *)(&bitmap_main->gas1_sub_id) + 2,
|
||||
|
||||
@ -177,6 +177,7 @@ struct flag_s {
|
||||
uint32_t filter;
|
||||
uint32_t concentration;
|
||||
uint32_t filter_climb;
|
||||
uint32_t gas_fault;
|
||||
};
|
||||
|
||||
extern const uint8_t * const modbus_map_ro[];
|
||||
|
||||
@ -175,6 +175,69 @@ void filter_window_process(void)
|
||||
}
|
||||
}
|
||||
|
||||
static int flag_for_sig_init_error(uint8_t ch, uint32_t sig)
|
||||
{
|
||||
const struct lookup_table_s *p; /* just for reduce text char in code */
|
||||
float temp, temp_quantum;
|
||||
float k; /* delta_b = y1 + (y2 - y1) / (x2 - x1) * (temp - x1) */
|
||||
float sig_fixed;
|
||||
uint8_t idx_t = 0; /* temperature index */
|
||||
|
||||
if (data_gas_info.id[ch] == GAS_ID_INVALID) {
|
||||
return 0;
|
||||
}
|
||||
/* step1: initialization variable */
|
||||
p = &((*bitmap_gas)[ch].lookup_table);
|
||||
temp = (float)(device_data.detector_temperature);
|
||||
|
||||
/* step2: get temperature index */
|
||||
for (idx_t = 0; idx_t < p->temperature_points; idx_t++) {
|
||||
if (temp < p->detector_temperature[idx_t]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idx_t == 0) {
|
||||
idx_t = 1; /* temperature is less than lowest temperature */
|
||||
} else if (idx_t >= p->temperature_points) {
|
||||
idx_t = p->temperature_points - 1; /* temperature is more than highest temperature */
|
||||
} else {
|
||||
/* calc with linear relation */
|
||||
}
|
||||
|
||||
/* step3: calc const variable of temperature */
|
||||
temp = temp - p->detector_temperature[idx_t - 1];
|
||||
temp_quantum = p->detector_temperature[idx_t] - p->detector_temperature[idx_t - 1];
|
||||
|
||||
/* step4: calc sig0 value by temperature */
|
||||
k = ((float)(p->sig[0][idx_t]) - (float)(p->sig[0][idx_t - 1])) / temp_quantum;
|
||||
sig_fixed = k * temp + p->sig[0][idx_t - 1];
|
||||
|
||||
/* laset sig > sig_fixed * 80% */
|
||||
if (sig < sig_fixed * 0.8f) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void flag_for_sig_init_error_process(void)
|
||||
{
|
||||
uint32_t flag_fault = 0xFFFFFFFF;
|
||||
|
||||
for (uint8_t ch = 0; ch < 4; ch++) {
|
||||
if (data_gas_info.id[ch] == GAS_ID_INVALID) {
|
||||
flag_fault |= (1 << ch);
|
||||
continue;
|
||||
}
|
||||
if (flag_for_sig_init_error(ch, data_filter[ch].window_output)) {
|
||||
flag_fault |= (1 << ch);
|
||||
} else {
|
||||
flag_fault &= ~(1 << ch);
|
||||
}
|
||||
}
|
||||
flag.gas_fault = flag_fault;
|
||||
}
|
||||
|
||||
void filter_output_process(void)
|
||||
{
|
||||
if (flag.filter_climb > 0) {
|
||||
@ -186,10 +249,13 @@ void filter_output_process(void)
|
||||
flag.filter_climb--;
|
||||
}
|
||||
}
|
||||
if (flag.filter_climb == 0) {
|
||||
flag_for_sig_init_error_process();
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
if (data_gas_info.id[i] == 0xFFFFFFFF) {
|
||||
if (data_gas_info.id[i] == GAS_ID_INVALID) {
|
||||
device_data.gas_sig[i] = 0;
|
||||
} else {
|
||||
device_data.gas_sig[i] = data_filter[i].window_output;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user