diff options
-rw-r--r-- | lora_pkt_fwd/src/lora_pkt_fwd.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c index 08aaf43..85be120 100644 --- a/lora_pkt_fwd/src/lora_pkt_fwd.c +++ b/lora_pkt_fwd/src/lora_pkt_fwd.c @@ -340,7 +340,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 @@ -378,7 +377,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) { @@ -403,8 +404,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; @@ -481,11 +480,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++; } @@ -500,7 +498,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]; |