summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Reiss <jreiss@multitech.com>2020-12-04 15:47:56 -0600
committerJason Reiss <jreiss@multitech.com>2020-12-04 15:47:56 -0600
commit51a29e60bf52f9e14a37aba35b847b248343cc86 (patch)
tree1525bc150b0e08f91fb1b6ed315b0ed434b821aa
parenta65223c3c1fd0e28d7225bfae6ed68c83879d5e4 (diff)
downloadpacket_forwarder_mtac_full-51a29e60bf52f9e14a37aba35b847b248343cc86.tar.gz
packet_forwarder_mtac_full-51a29e60bf52f9e14a37aba35b847b248343cc86.tar.bz2
packet_forwarder_mtac_full-51a29e60bf52f9e14a37aba35b847b248343cc86.zip
Add temperature compensation matrix support
Add example temperature compensation to global_conf.json
-rw-r--r--lora_pkt_fwd/global_conf.json5
-rw-r--r--lora_pkt_fwd/src/lora_pkt_fwd.c105
2 files changed, 110 insertions, 0 deletions
diff --git a/lora_pkt_fwd/global_conf.json b/lora_pkt_fwd/global_conf.json
index 2d0948c..d73b50c 100644
--- a/lora_pkt_fwd/global_conf.json
+++ b/lora_pkt_fwd/global_conf.json
@@ -14,6 +14,11 @@
"sx127x_rssi_offset": -4 /* dB */
},
"antenna_gain": 0, /* antenna gain, in dBi */
+ "temperature_comp": {
+ "enabled": false,
+ "values": [ [-20,-2], [-10,-1], [0,0], [0,0] ],
+ "current_temp_file": "/var/run/lora/current_temp"
+ },
"radio_0": {
"enable": true,
"type": "SX1257",
diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c
index 34996d4..7ced41e 100644
--- a/lora_pkt_fwd/src/lora_pkt_fwd.c
+++ b/lora_pkt_fwd/src/lora_pkt_fwd.c
@@ -294,6 +294,14 @@ static struct jit_queue_s jit_queue;
/* Gateway specificities */
static int8_t antenna_gain = 0;
+#define TEMP_ADJ_MAX 4
+#define DEFAULT_TEMP_COMP_FILE "/var/run/lora/current_temp"
+static int16_t temp_comp_table[TEMP_ADJ_MAX][2] = { 0 };
+static char temp_comp_file[64] = {0};
+static int16_t temp_comp_value = 0;
+static int16_t temp_comp_adj = 0;
+static bool temp_comp_enabled = false;
+
/* TX capabilities */
static struct lgw_tx_gain_lut_s txlut; /* TX gain table */
static uint32_t tx_freq_min[LGW_RF_CHAIN_NB]; /* lowest frequency supported by TX chain */
@@ -330,6 +338,34 @@ void thread_spectralscan(void);
/* -------------------------------------------------------------------------- */
/* --- PRIVATE FUNCTIONS DEFINITION ----------------------------------------- */
+static void update_temp_comp_value() {
+ if (!temp_comp_enabled) {
+ return;
+ }
+ /* try to open file to read */
+ FILE *filePointer;
+ if (filePointer = fopen(temp_comp_file, "r")) {
+ int bufferLength = 4;
+ char buffer[bufferLength];
+
+ fgets(buffer, bufferLength, filePointer);
+ temp_comp_value = atoi(buffer);
+
+ int16_t adj_val = 0;
+
+ for (int i = 0; i < TEMP_ADJ_MAX; i++) {
+ if (temp_comp_table[i][0] <= temp_comp_value) {
+ adj_val = temp_comp_table[i][1];
+ }
+ }
+
+ temp_comp_adj = adj_val;
+
+ fclose(filePointer);
+ }
+
+}
+
static enum lgw_sx127x_rxbw_e map_bandwidth(uint32_t bandwidth) {
switch (bandwidth) {
case 25:
@@ -475,6 +511,7 @@ static int parse_SX1301_configuration(const char * conf_file) {
JSON_Value *root_val = NULL;
JSON_Object *conf_obj = NULL;
JSON_Object *conf_lbt_obj = NULL;
+ JSON_Object *conf_temp_comp_obj = NULL;
JSON_Object *conf_lbtchan_obj = NULL;
JSON_Value *val = NULL;
JSON_Array *conf_array = NULL;
@@ -619,6 +656,61 @@ static int parse_SX1301_configuration(const char * conf_file) {
}
MSG("INFO: antenna_gain %d dBi\n", antenna_gain);
+ conf_temp_comp_obj = json_object_get_object(conf_obj, "temperature_comp"); /* fetch value (if possible) */
+ if (conf_temp_comp_obj == NULL) {
+ MSG("INFO: no configuration for Temperature Compensation\n");
+ } else {
+ val = json_object_get_value(conf_temp_comp_obj, "enable"); /* fetch value (if possible) */
+ if (json_value_get_type(val) == JSONBoolean) {
+ temp_comp_enabled = (bool)json_value_get_boolean(val);
+ } else {
+ temp_comp_enabled = false;
+ }
+
+ if (temp_comp_enabled) {
+ MSG("INFO: Temperature Compensation enabled\n");
+
+ /* Current temperature path (optional) */
+ str = json_object_get_string(conf_temp_comp_obj, "current_temp_file");
+ if (str != NULL) {
+ strncpy(temp_comp_file, str, sizeof(temp_comp_file)-1);
+ MSG("INFO: Current temperature file is configured to \"%s\"\n", temp_comp_file);
+ } else {
+ strncpy(temp_comp_file, DEFAULT_TEMP_COMP_FILE, sizeof(temp_comp_file)-1);
+ }
+
+ /* load temp adj table */
+ int adj_count = 0;
+ conf_array = json_object_get_array(conf_temp_comp_obj, "values");
+ if (conf_array != NULL) {
+ adj_count = json_array_get_count( conf_array );
+
+ JSON_Array *temp_values = NULL;
+ for (i = 0; i < (int)adj_count; i++) {
+ /* Sanity check */
+ if (i >= TEMP_ADJ_MAX)
+ {
+ MSG("ERROR: Temp adj %d not supported, skip it\n", i );
+ break;
+ }
+
+ /* Get LBT channel configuration object from array */
+ temp_values = json_array_get_array(conf_array, i);
+ size_t cnt = json_array_get_count(temp_values);
+
+ if (cnt == 2) {
+ temp_comp_table[i][0] = (int16_t)json_array_get_number(temp_values, 0);
+ temp_comp_table[i][1] = (int16_t)json_array_get_number(temp_values, 1);
+ }
+ }
+ }
+
+ update_temp_comp_value();
+ } else {
+ MSG("INFO: Temperature Compensation disabled\n");
+ }
+ }
+
/* set configuration for tx gains */
memset(&txlut, 0, sizeof txlut); /* initialize configuration structure */
for (i = 0; i < TX_GAIN_LUT_SIZE_MAX; i++) {
@@ -1752,6 +1844,8 @@ int main(int argc, char** argv)
break;
}
+ /* read the currrent temperature */
+
pthread_mutex_unlock(&mx_concent);
if (i != LGW_HAL_SUCCESS) {
printf("# SX1301 time (PPS): unknown\n");
@@ -1759,6 +1853,12 @@ int main(int argc, char** argv)
printf("# SX1301 time (PPS): %u %u\n", trig_tstamp, page);
}
+ if (temp_comp_enabled) {
+ update_temp_comp_value();
+ printf("# Temperature: %i C\n", temp_comp_value);
+ printf("# Temp TxPow Adj: %i dB\n", temp_comp_adj);
+ }
+
jit_print_queue (&jit_queue, false, DEBUG_LOG);
printf("### [GPS] ###\n");
if (gps_enabled == true) {
@@ -2874,6 +2974,11 @@ void thread_down(void) {
}
}
+ if (temp_comp_enabled) {
+ txpkt.rf_power += (int8_t)temp_comp_adj;
+ MSG("INFO: Tx power temp adjusted to %d\n", (int)txpkt.rf_power);
+ }
+
/* Parse modulation (mandatory) */
str = json_object_get_string(txpk_obj, "modu");
if (str == NULL) {