summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Reiss <jreiss@multitech.com>2021-02-02 09:09:24 -0600
committerJason Reiss <jreiss@multitech.com>2021-02-02 09:09:24 -0600
commit9e756ddc166ed7f5c1dc1cf62d467d44561479ca (patch)
tree7680aae8180284cd4188c2fc616e791211c78439
parenta79fc6674a93347b8db0696239da4d57bf6b1da9 (diff)
downloadpacket_forwarder_mtac_full-9e756ddc166ed7f5c1dc1cf62d467d44561479ca.tar.gz
packet_forwarder_mtac_full-9e756ddc166ed7f5c1dc1cf62d467d44561479ca.tar.bz2
packet_forwarder_mtac_full-9e756ddc166ed7f5c1dc1cf62d467d44561479ca.zip
reduce LUT temperature file size4.0.4
-rw-r--r--lora_pkt_fwd/src/lora_pkt_fwd.c136
1 files changed, 68 insertions, 68 deletions
diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c
index c438ca3..e3c08cf 100644
--- a/lora_pkt_fwd/src/lora_pkt_fwd.c
+++ b/lora_pkt_fwd/src/lora_pkt_fwd.c
@@ -340,12 +340,12 @@ void thread_spectralscan(void);
#define TEMP_LUT_SIZE_MAX 13
+
/**
@struct lgw_tx_alt_gain_s
@brief Structure containing all gains of Tx chain
*/
struct lgw_tx_alt_gain_s {
- float dig_gain[4];/*!> RF power output measured at each dig setting 0-3 */
uint8_t pa_gain; /*!> 2 bits, control of the external PA (SX1301 I/O) */
uint8_t dac_gain; /*!> 2 bits, control of the radio DAC */
uint8_t mix_gain; /*!> 4 bits, control of the radio mixer */
@@ -357,9 +357,9 @@ struct lgw_tx_alt_gain_s {
@brief Structure defining the Tx gain LUT
*/
struct lgw_tx_alt_gain_lut_s {
- struct lgw_tx_alt_gain_s lut[TX_GAIN_LUT_SIZE_MAX]; /*!> Array of Tx gain struct */
- int8_t temp;
- uint8_t size; /*!> Number of LUT indexes */
+ float dig_gain[64];
+ int8_t temp;
+ uint8_t size; /*!> Number of LUT indexes */
};
/**
@@ -367,8 +367,9 @@ struct lgw_tx_alt_gain_lut_s {
@brief Structure defining the Tx gain LUT
*/
struct lgw_tx_temp_lut_s {
- struct lgw_tx_alt_gain_lut_s lut[TEMP_LUT_SIZE_MAX]; /*!> Array of Tx gain struct */
- uint8_t size; /*!> Number of LUT indexes */
+ struct lgw_tx_alt_gain_s base[TX_GAIN_LUT_SIZE_MAX]; /*!> Array of Tx gain struct */
+ struct lgw_tx_alt_gain_lut_s lut[TEMP_LUT_SIZE_MAX]; /*!> Array of Tx gain struct */
+ uint8_t size; /*!> Number of LUT indexes */
};
struct lgw_tx_temp_lut_s tx_temp_lut;
@@ -380,8 +381,8 @@ void lookup_power_settings(float tx_pwr, int8_t* rf_power, int8_t* dig_gain) {
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)) {
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].lut[j].dig_gain[h] && (tx_pwr - tx_temp_lut.lut[i].lut[j].dig_gain[h]) < min_diff) {
- min_diff = (tx_pwr - tx_temp_lut.lut[i].lut[j].dig_gain[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) {
+ min_diff = (tx_pwr - tx_temp_lut.lut[i].dig_gain[j*4+h]);
*rf_power = j;
*dig_gain = h;
}
@@ -425,70 +426,69 @@ void load_temp_lookup() {
exit(EXIT_FAILURE);
}
+ /* point to the gateway configuration object */
+ conf_obj = json_object_get_object(json_value_get_object(root_val), "LUT-BASE");
+ if (conf_obj == NULL) {
+ return;
+ }
+
temp_comp_enabled = true;
- int index = 0;
- for (int temp = -60; temp <= 100; temp++) {
- snprintf(param_name, sizeof param_name, "LUT%i", temp); /* compose parameter path inside JSON structure */
- /* point to the gateway configuration object */
- conf_obj = json_object_get_object(json_value_get_object(root_val), param_name);
- if (conf_obj == NULL) {
+ for (i = 0; i < TX_GAIN_LUT_SIZE_MAX; i++) {
+ snprintf(param_name, sizeof param_name, "tx_lut_%i", i); /* compose parameter path inside JSON structure */
+ conf_lut_obj = json_object_get_object(conf_obj, param_name); /* fetch value (if possible) */
+ if (conf_lut_obj == NULL) {
+ MSG("INFO: no configuration for tx gain lut %i\n", i);
continue;
}
+ tx_temp_lut.size++; /* update TX LUT size based on JSON object found in configuration file */
+ /* there is an object to configure that TX gain index, let's parse it */
+ snprintf(param_name, sizeof param_name, "tx_lut_%i.pa_gain", i);
+ val = json_object_dotget_value(conf_obj, param_name);
+ if (json_value_get_type(val) == JSONNumber) {
+ tx_temp_lut.base[i].pa_gain = (uint8_t)json_value_get_number(val);
+ } else {
+ MSG("WARNING: Data type for %s[%d] seems wrong, please check\n", param_name, i);
+ tx_temp_lut.base[i].pa_gain = 0;
+ }
+ snprintf(param_name, sizeof param_name, "tx_lut_%i.dac_gain", i);
+ val = json_object_dotget_value(conf_obj, param_name);
+ if (json_value_get_type(val) == JSONNumber) {
+ tx_temp_lut.base[i].dac_gain = (uint8_t)json_value_get_number(val);
+ } else {
+ tx_temp_lut.base[i].dac_gain = 3; /* This is the only dac_gain supported for now */
+ }
+ snprintf(param_name, sizeof param_name, "tx_lut_%i.mix_gain", i);
+ val = json_object_dotget_value(conf_obj, param_name);
+ if (json_value_get_type(val) == JSONNumber) {
+ tx_temp_lut.base[i].mix_gain = (uint8_t)json_value_get_number(val);
+ } else {
+ MSG("WARNING: Data type for %s[%d] seems wrong, please check\n", param_name, i);
+ tx_temp_lut.base[i].mix_gain = 0;
+ }
+ snprintf(param_name, sizeof param_name, "tx_lut_%i.rf_power", i);
+ val = json_object_dotget_value(conf_obj, param_name);
+ if (json_value_get_type(val) == JSONNumber) {
+ tx_temp_lut.base[i].rf_power = (int8_t)json_value_get_number(val);
+ } else {
+ MSG("WARNING: Data type for %s[%d] seems wrong, please check\n", param_name, i);
+ tx_temp_lut.base[i].rf_power = 0;
+ }
+ }
- tx_temp_lut.lut[index].temp = temp;
-
- for (i = 0; i < TX_GAIN_LUT_SIZE_MAX; i++) {
- snprintf(param_name, sizeof param_name, "tx_lut_%i", i); /* compose parameter path inside JSON structure */
- conf_lut_obj = json_object_get_object(conf_obj, param_name); /* fetch value (if possible) */
- if (conf_lut_obj == NULL) {
- MSG("INFO: no configuration for tx gain lut %i\n", i);
- continue;
- }
- tx_temp_lut.lut[index].size++; /* update TX LUT size based on JSON object found in configuration file */
- /* there is an object to configure that TX gain index, let's parse it */
- snprintf(param_name, sizeof param_name, "tx_lut_%i.pa_gain", i);
- val = json_object_dotget_value(conf_obj, param_name);
- if (json_value_get_type(val) == JSONNumber) {
- tx_temp_lut.lut[index].lut[i].pa_gain = (uint8_t)json_value_get_number(val);
- } else {
- MSG("WARNING: Data type for %s[%d] seems wrong, please check\n", param_name, i);
- tx_temp_lut.lut[index].lut[i].pa_gain = 0;
- }
- snprintf(param_name, sizeof param_name, "tx_lut_%i.dac_gain", i);
- val = json_object_dotget_value(conf_obj, param_name);
- if (json_value_get_type(val) == JSONNumber) {
- tx_temp_lut.lut[index].lut[i].dac_gain = (uint8_t)json_value_get_number(val);
- } else {
- tx_temp_lut.lut[index].lut[i].dac_gain = 3; /* This is the only dac_gain supported for now */
- }
- snprintf(param_name, sizeof param_name, "tx_lut_%i.mix_gain", i);
- val = json_object_dotget_value(conf_obj, param_name);
- if (json_value_get_type(val) == JSONNumber) {
- tx_temp_lut.lut[index].lut[i].mix_gain = (uint8_t)json_value_get_number(val);
- } else {
- MSG("WARNING: Data type for %s[%d] seems wrong, please check\n", param_name, i);
- tx_temp_lut.lut[index].lut[i].mix_gain = 0;
- }
- snprintf(param_name, sizeof param_name, "tx_lut_%i.rf_power", i);
- val = json_object_dotget_value(conf_obj, param_name);
- if (json_value_get_type(val) == JSONNumber) {
- tx_temp_lut.lut[index].lut[i].rf_power = (int8_t)json_value_get_number(val);
- } else {
- MSG("WARNING: Data type for %s[%d] seems wrong, please check\n", param_name, i);
- tx_temp_lut.lut[index].lut[i].rf_power = 0;
- }
-
- conf_array = json_object_get_array(conf_lut_obj, "dig_gain");
- if (conf_array != NULL) {
- for (int j = 0; j < 4; j++) {
- /* Get lut channel configuration object from array */
- tx_temp_lut.lut[index].lut[i].dig_gain[j] = (float)json_array_get_number(conf_array, j);
- }
+ int index = 0;
+ for (int temp = -60; temp <= 100; temp++) {
+ 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;
+ 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;
}
+ index++;
}
-
- index++;
}
}
@@ -855,9 +855,9 @@ static int parse_SX1301_configuration(const char * conf_file) {
MSG("INFO: Loading temperature compensated LUT values\n");
for (i = 0; i < TX_GAIN_LUT_SIZE_MAX; i++) {
- txlut.lut[i].rf_power = tx_temp_lut.lut[0].lut[i].rf_power;
- txlut.lut[i].pa_gain = tx_temp_lut.lut[0].lut[i].pa_gain;
- txlut.lut[i].mix_gain = tx_temp_lut.lut[0].lut[i].mix_gain;
+ txlut.lut[i].rf_power = tx_temp_lut.base[i].rf_power;
+ txlut.lut[i].pa_gain = tx_temp_lut.base[i].pa_gain;
+ txlut.lut[i].mix_gain = tx_temp_lut.base[i].mix_gain;
txlut.lut[i].dig_gain = 0;
txlut.lut[i].dac_gain = 3;
MSG("LUT %d RF: %d PA: %d MIX: %d DIG: %d DAC: %d\n", i, txlut.lut[i].rf_power, txlut.lut[i].pa_gain, txlut.lut[i].mix_gain, txlut.lut[i].dig_gain, txlut.lut[i].dac_gain);