From 22c62ff3fe0c373bf2c3ef94b1fc30dbecb086c1 Mon Sep 17 00:00:00 2001 From: Jason Reiss Date: Thu, 1 Apr 2021 16:34:19 -0500 Subject: Check if temp is below lowest table. --- lora_pkt_fwd/src/lora_pkt_fwd.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lora_pkt_fwd/src/lora_pkt_fwd.c') diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c index a181ea7..87eaaa0 100644 --- a/lora_pkt_fwd/src/lora_pkt_fwd.c +++ b/lora_pkt_fwd/src/lora_pkt_fwd.c @@ -336,7 +336,6 @@ void thread_spectralscan(void); #define TEMP_LUT_SIZE_MAX 13 - /** @struct lgw_tx_alt_gain_s @brief Structure containing all gains of Tx chain @@ -374,7 +373,9 @@ void lookup_power_settings(float tx_pwr, int8_t* rf_power, int8_t* dig_gain) { float min_diff = 99; for (int i = 0; i < TEMP_LUT_SIZE_MAX; i++) { - if (i == TEMP_LUT_SIZE_MAX-1 || (tx_temp_lut.lut[i].temp <= temp_comp_value && tx_temp_lut.lut[i+1].temp > temp_comp_value)) { + // If the current temp is lower than the first temp or we reach the end of the table + if ((tx_temp_lut->dig[0].temp > tx_temp_lut->temp_comp_value || i == TEMP_LUT_SIZE_MAX-1) || + (tx_temp_lut.lut[i].temp <= temp_comp_value && tx_temp_lut.lut[i+1].temp > temp_comp_value)) { for (int j = 0; j < TX_GAIN_LUT_SIZE_MAX; j++) { for (int h = 0; h < 4; h++) { if (tx_pwr >= tx_temp_lut.lut[i].dig_gain[j*4+h] && (tx_pwr - tx_temp_lut.lut[i].dig_gain[j*4+h]) < min_diff) { @@ -399,8 +400,6 @@ void load_temp_lookup() { int i; char param_name[32]; /* used to generate variable parameter names */ - const char *str; /* used to store string value from JSON object */ - const char conf_obj_name[] = "SX1301_conf"; JSON_Value *root_val = NULL; JSON_Object *conf_obj = NULL; JSON_Object *conf_lut_obj = NULL; @@ -477,11 +476,10 @@ void load_temp_lookup() { snprintf(param_name, sizeof param_name, "LUT%i", temp); /* compose parameter path inside JSON structure */ conf_array = json_object_get_array(json_value_get_object(root_val), param_name); if (conf_array != NULL) { - tx_temp_lut.lut[index].temp = temp; + tx_temp_lut.lut[index].temp = temp; for (int j = 0; j < 64; j++) { /* Get lut channel configuration object from array */ - float val = (float)json_array_get_number(conf_array, j); - tx_temp_lut.lut[index].dig_gain[j] = val; + tx_temp_lut.lut[index].dig_gain[j] = (float)json_array_get_number(conf_array, j); } index++; } @@ -496,7 +494,7 @@ static void update_temp_comp_value() { /* try to open file to read */ FILE *filePointer; - if (filePointer = fopen(temp_comp_file, "r")) { + if ((filePointer = fopen(temp_comp_file, "r"))) { int bufferLength = 10; char buffer[bufferLength]; -- cgit v1.2.3