summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Reiss <jreiss@multitech.com>2020-03-20 09:11:25 -0500
committerJason Reiss <jreiss@multitech.com>2020-03-20 09:11:25 -0500
commitea028e8048d55367a52365087f9e3928746c55a5 (patch)
treed3c28fb745071653bcf35bff7f05c93051796390
parentb3a4461b3dfc5588111a88fd735d058888b8d3d4 (diff)
parentdea57d6f29246434173c33c56850708c51fc5b23 (diff)
downloadlora_gateway_mtac_full-ea028e8048d55367a52365087f9e3928746c55a5.tar.gz
lora_gateway_mtac_full-ea028e8048d55367a52365087f9e3928746c55a5.tar.bz2
lora_gateway_mtac_full-ea028e8048d55367a52365087f9e3928746c55a5.zip
Merge branch 'master' of gitlab.multitech.net:lora_enterprise/lora_gateway_mtac_full5.0.1-mts-5
-rw-r--r--libloragw/Makefile6
-rw-r--r--libloragw/inc/loragw_fpga.h3
-rw-r--r--libloragw/inc/loragw_hal.h10
-rw-r--r--libloragw/inc/loragw_reg.h11
-rw-r--r--libloragw/src/loragw_fpga.c29
-rw-r--r--libloragw/src/loragw_gps.c3
-rw-r--r--libloragw/src/loragw_hal.c39
-rw-r--r--libloragw/src/loragw_reg.c38
-rw-r--r--libloragw/src/loragw_spi.native.c2
-rw-r--r--libloragw/tst/test_loragw_cal.c44
-rw-r--r--libloragw/tst/test_loragw_gps.c4
-rw-r--r--libloragw/tst/test_loragw_hal.c31
-rw-r--r--libloragw/tst/test_loragw_reg.c59
-rw-r--r--libloragw/tst/test_loragw_spi.c119
-rw-r--r--util_lbt_test/src/util_lbt_test.c39
-rw-r--r--util_pkt_logger/src/util_pkt_logger.c9
-rw-r--r--util_spectral_scan/src/util_spectral_scan.c44
-rw-r--r--util_spi_stress/src/util_spi_stress.c39
-rw-r--r--util_tx_continuous/src/util_tx_continuous.c94
-rw-r--r--util_tx_test/src/util_tx_test.c22
20 files changed, 487 insertions, 158 deletions
diff --git a/libloragw/Makefile b/libloragw/Makefile
index 4575bdc..7e95eca 100644
--- a/libloragw/Makefile
+++ b/libloragw/Makefile
@@ -1,6 +1,6 @@
### get external defined data
-LIBLORAGW_VERSION := `cat ../VERSION`
+LIBLORAGW_VERSION := $(shell git describe)
include library.cfg
### constant symbols
@@ -10,7 +10,7 @@ CROSS_COMPILE ?=
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
-CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I. -isystem =/usr/include/gps
+CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I. -isystem =/usr/include/gps -DLIBLORAGW_VERSION=\"$(LIBLORAGW_VERSION)\"
OBJDIR = obj
INCLUDES = $(wildcard inc/*.h)
@@ -31,7 +31,7 @@ clean:
### transpose library.cfg into a C header file : config.h
-inc/config.h: ../VERSION library.cfg
+inc/config.h: library.cfg
@echo "*** Checking libloragw library configuration ***"
@rm -f $@
#File initialization
diff --git a/libloragw/inc/loragw_fpga.h b/libloragw/inc/loragw_fpga.h
index 46246b6..722438c 100644
--- a/libloragw/inc/loragw_fpga.h
+++ b/libloragw/inc/loragw_fpga.h
@@ -135,7 +135,6 @@ int lgw_fpga_reg_wb(uint16_t register_id, uint8_t *data, uint16_t size);
*/
int lgw_fpga_reg_rb(uint16_t register_id, uint8_t *data, uint16_t size);
-int lgw_set_attenuation(float attenuation);
-
+int lgw_set_attenuation(uint8_t *attn);
#endif
/* --- EOF ------------------------------------------------------------------ */
diff --git a/libloragw/inc/loragw_hal.h b/libloragw/inc/loragw_hal.h
index e1e4644..f6dc8dc 100644
--- a/libloragw/inc/loragw_hal.h
+++ b/libloragw/inc/loragw_hal.h
@@ -177,6 +177,7 @@ enum lgw_radio_type_e {
struct lgw_conf_board_s {
bool lorawan_public; /*!> Enable ONLY for *public* networks using the LoRa MAC protocol */
uint8_t clksrc; /*!> Index of RF chain which provides clock to concentrator */
+ uint8_t max_tx_power; /*!> Max power limit for transmitting packets */
};
/**
@@ -259,7 +260,7 @@ struct lgw_pkt_tx_s {
uint8_t tx_mode; /*!> select on what event/time the TX is triggered */
uint32_t count_us; /*!> timestamp or delay in microseconds for TX trigger */
uint8_t rf_chain; /*!> through which RF chain will the packet be sent */
- int8_t rf_power; /*!> TX power, in dBm */
+ float rf_power; /*!> TX power, in dBm */
uint8_t modulation; /*!> modulation to use for the packet */
uint8_t bandwidth; /*!> modulation bandwidth (LoRa only) */
uint32_t datarate; /*!> TX datarate (baudrate for FSK, SF for LoRa) */
@@ -416,13 +417,6 @@ const char* lgw_version_info(void);
*/
uint32_t lgw_time_on_air(struct lgw_pkt_tx_s *packet);
-/**
-@brief Set the attenuation for sending packets to get the exact power level
-@param attenuation is in dB, it can be between 0-31.75
-@return LGW_HAL_ERROR if the operation failed, LGW_HAL_SUCCESS else
-*/
-int lgw_set_attenuation(float attenuation);
-
#endif
/* --- EOF ------------------------------------------------------------------ */
diff --git a/libloragw/inc/loragw_reg.h b/libloragw/inc/loragw_reg.h
index 1e98efa..4dd9edb 100644
--- a/libloragw/inc/loragw_reg.h
+++ b/libloragw/inc/loragw_reg.h
@@ -403,14 +403,17 @@ uint8_t read_fpga_version();
@param version number provided to check through the validated list
@return status true/false
*/
-bool check_fpga_version(uint8_t version);
+bool fpga_version_supported();
+
+/**
+@brief Check if the LoRa FPGA uses an attenuator for transmitting packets
+@return status true/false
+*/
+bool fpga_supports_attenuator();
/**
@brief Connect LoRa concentrator by opening SPI link
-@param spi_only indicates if we only want to create the SPI connexion to the
concentrator, or if we also want to reset it and configure the FPGA (if present)
-@param tx_notch_filter TX notch filter frequency to be set in the FPGA (only
-used with SX1301AP2 reference design).
@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR)
*/
int lgw_connect(bool spi_only, uint32_t tx_notch_freq);
diff --git a/libloragw/src/loragw_fpga.c b/libloragw/src/loragw_fpga.c
index ce1c9c6..63c6d3b 100644
--- a/libloragw/src/loragw_fpga.c
+++ b/libloragw/src/loragw_fpga.c
@@ -175,9 +175,14 @@ int lgw_fpga_configure(uint32_t tx_notch_freq) {
DEBUG_MSG("ERROR: Failed to configure FPGA polarity\n");
return LGW_REG_ERROR;
}
- /* Set Attenuator mode to be used for the full card*/
- if (fpga_version == 32) {
- lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_MODE, 0);
+ }
+
+ /* Set Attenuator mode to 1 to allow it to use it*/
+ if (fpga_supports_attenuator()) {
+ x = lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_MODE, 1);
+ if (x != LGW_REG_SUCCESS) {
+ DEBUG_MSG("ERROR: Failed to configure Attenuator mode\n");
+ return LGW_REG_ERROR;
}
}
@@ -361,17 +366,21 @@ int lgw_fpga_reg_rb(uint16_t register_id, uint8_t *data, uint16_t size) {
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-int lgw_set_attenuation(float attenuation) {
- int i;
- int32_t val;
- if (attenuation > 31.75 || attenuation < 0) {
+int lgw_set_attenuation(uint8_t *attn) {
+ if (*attn > 127) {
return LGW_HAL_ERROR;
}
- i = lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_VALUE, (uint8_t)(attenuation * LGW_RF_ATTN_CONV_CONST));
+ int i;
+ /* The max value allowed for 7 bits of a register */
+ uint8_t max_attn = 127;
+
+ /* Shifting the float value to apply get the adjusted integer */
+ uint8_t shifted_attn = (uint8_t)(*attn * LGW_RF_ATTN_CONV_CONST);
- i = lgw_fpga_reg_r(LGW_FPGA_RF_ATTN_VALUE, &val);
+ /* The attenuator value is bit 0-6 of the register hence must be limited to 127 */
+ uint8_t reg_attn = max_attn ^ ((shifted_attn ^ max_attn) & -(shifted_attn < max_attn));
+ i = lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_VALUE, reg_attn);
if (i == LGW_REG_SUCCESS) {
- DEBUG_PRINTF("INFO: Attenuator set to %u \n", (uint8_t)val);
return LGW_HAL_SUCCESS;
} else {
return LGW_HAL_ERROR;
diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c
index 3aad031..19c2f83 100644
--- a/libloragw/src/loragw_gps.c
+++ b/libloragw/src/loragw_gps.c
@@ -89,8 +89,6 @@ static bool gps_lock_ok = false;
static char gps_mod = 'N'; /* GPS mode (N no fix, A autonomous, D differential) */
static short gps_sat = 0; /* number of satellites used for fix */
-static struct termios ttyopt_restore;
-
/* -------------------------------------------------------------------------- */
/* --- PRIVATE FUNCTIONS DECLARATION ---------------------------------------- */
@@ -255,7 +253,6 @@ int str_chop(char *s, int buff_size, char separator, int *idx_ary, int max_idx)
int lgw_gps_enable(struct gps_data_t *gpsdata, struct fixsource_t *source) {
unsigned int flags;
- fd_set fds;
flags = WATCH_ENABLE;
flags |= WATCH_RAW;
flags |= WATCH_NMEA;
diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c
index d77c693..c723be9 100644
--- a/libloragw/src/loragw_hal.c
+++ b/libloragw/src/loragw_hal.c
@@ -135,6 +135,7 @@ static uint64_t fsk_sync_word= 0xC194C1; /* default FSK sync word (ALIGNED RIGHT
static bool lorawan_public = false;
static uint8_t rf_clkout = 0;
+static uint8_t max_tx_power = 32; /* default uncalibrated max tx power */
static struct lgw_tx_gain_lut_s txgain_lut = {
.size = 2,
@@ -423,8 +424,12 @@ int lgw_board_setconf(struct lgw_conf_board_s conf) {
/* set internal config according to parameters */
lorawan_public = conf.lorawan_public;
rf_clkout = conf.clksrc;
-
- DEBUG_PRINTF("Note: board configuration; lorawan_public:%d, clksrc:%d\n", lorawan_public, rf_clkout);
+ if (fpga_supports_attenuator()) {
+ max_tx_power = conf.max_tx_power;
+ DEBUG_PRINTF("Note: board configuration; lorawan_public:%d, clksrc:%d, max_tx_power:%d\n", lorawan_public, rf_clkout, max_tx_power);
+ } else {
+ DEBUG_PRINTF("Note: board configuration; lorawan_public:%d, clksrc:%d \n", lorawan_public, rf_clkout);
+ }
return LGW_HAL_SUCCESS;
}
@@ -1414,27 +1419,30 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) {
/* interpretation of TX power */
- if (read_fpga_version() == 32) {
- for (pow_index = 0; pow_index < txgain_lut.size-1; pow_index++) {
- if (txgain_lut.lut[pow_index].rf_power >= pkt_data.rf_power) {
- x = lgw_set_attenuation((float)(txgain_lut.lut[pow_index].rf_power - pkt_data.rf_power));
- if (x != LGW_HAL_SUCCESS) {
- DEBUG_MSG("ERROR: Failed to set attenuation value\n");
- return LGW_HAL_ERROR;
- }
- break;
- }
+ if (fpga_supports_attenuator()) {
+ /* Power is set to max and the attenuator brings down the level to match the packet's request */
+ target_mix_gain = 15; /* Mixer gain is not used for setting power*/
+ lgw_reg_w(LGW_TX_GAIN, 0); /* Dig gain is not used for setting power */
+ uint8_t attn = (uint8_t)(max_tx_power - pkt_data.rf_power);
+ x = lgw_set_attenuation(&attn);
+ if (x != LGW_HAL_SUCCESS) {
+ DEBUG_MSG("ERROR: Failed to set attenuation value\n");
+ return LGW_HAL_ERROR;
}
} else {
+ /* Power is matched from the txgain_lut */
for (pow_index = txgain_lut.size-1; pow_index > 0; pow_index--) {
if (txgain_lut.lut[pow_index].rf_power <= pkt_data.rf_power) {
break;
}
}
+
+ /* loading TX imbalance correction */
+ target_mix_gain = txgain_lut.lut[pow_index].mix_gain;
+ /* Set digital gain from LUT */
+ lgw_reg_w(LGW_TX_GAIN, txgain_lut.lut[pow_index].dig_gain);
}
- /* loading TX imbalance correction */
- target_mix_gain = txgain_lut.lut[pow_index].mix_gain;
if (pkt_data.rf_chain == 0) { /* use radio A calibration table */
lgw_reg_w(LGW_TX_OFFSET_I, cal_offset_a_i[target_mix_gain - 8]);
lgw_reg_w(LGW_TX_OFFSET_Q, cal_offset_a_q[target_mix_gain - 8]);
@@ -1443,9 +1451,6 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) {
lgw_reg_w(LGW_TX_OFFSET_Q, cal_offset_b_q[target_mix_gain - 8]);
}
- /* Set digital gain from LUT */
- lgw_reg_w(LGW_TX_GAIN, txgain_lut.lut[pow_index].dig_gain);
-
/* fixed metadata, useful payload and misc metadata compositing */
transfer_size = TX_METADATA_NB + pkt_data.size; /* */
payload_offset = TX_METADATA_NB; /* start the payload just after the metadata */
diff --git a/libloragw/src/loragw_reg.c b/libloragw/src/loragw_reg.c
index e707838..5991384 100644
--- a/libloragw/src/loragw_reg.c
+++ b/libloragw/src/loragw_reg.c
@@ -48,7 +48,8 @@ Maintainer: Sylvain Miermont
#define PAGE_ADDR 0x00
#define PAGE_MASK 0x03
-const uint8_t FPGA_VERSION[] = { 28, 31, 32, 33 , 34, 35, 37 }; /* several versions could be supported */
+const uint8_t FPGA_VERSIONS_SUPPORTED[] = { 28, 31, 32, 33, 34, 35, 37 }; /* several versions could be supported */
+const uint8_t FPGA_VERSIONS_SUPPORTING_ATTENUATOR[] = { 32, 34, 35, 37 }; /* defines lgw_send power interpretation */
/*
auto generated register mapping for C code : 11-Jul-2013 13:20:40
@@ -488,21 +489,34 @@ int reg_r_align32(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target
/* Read the FPGA version */
uint8_t read_fpga_version() {
- uint8_t u = 0;
- uint8_t spi_stat = lgw_spi_r(lgw_spi_target, LGW_SPI_MUX_MODE1, LGW_SPI_MUX_TARGET_FPGA, loregs[LGW_VERSION].addr, &u);
- if (spi_stat != LGW_SPI_SUCCESS) {
- DEBUG_MSG("ERROR READING VERSION REGISTER\n");
- return LGW_REG_ERROR;
- }
- return u;
+ uint8_t u = 0;
+ uint8_t spi_stat = lgw_spi_r(lgw_spi_target, LGW_SPI_MUX_MODE1, LGW_SPI_MUX_TARGET_FPGA, loregs[LGW_VERSION].addr, &u);
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ DEBUG_MSG("ERROR READING VERSION REGISTER\n");
+ return LGW_REG_ERROR;
+ }
+ return u;
}
/* Verify the FPGA version is supported */
-bool check_fpga_version(uint8_t version) {
+bool fpga_version_supported() {
+ int i;
+
+ for (i = 0; i < (int)(sizeof FPGA_VERSIONS_SUPPORTED); i++) {
+ if (FPGA_VERSIONS_SUPPORTED[i] == read_fpga_version() ) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/* Check if the FPGA uses an attenuator for transmitting packets*/
+bool fpga_supports_attenuator() {
int i;
- for (i = 0; i < (int)(sizeof FPGA_VERSION); i++) {
- if (FPGA_VERSION[i] == version ) {
+ for (i = 0; i < (int)(sizeof FPGA_VERSIONS_SUPPORTING_ATTENUATOR); i++) {
+ if (FPGA_VERSIONS_SUPPORTING_ATTENUATOR[i] == read_fpga_version() ) {
return true;
}
}
@@ -537,7 +551,7 @@ int lgw_connect(bool spi_only, uint32_t tx_notch_freq) {
DEBUG_MSG("ERROR READING VERSION REGISTER\n");
return LGW_REG_ERROR;
}
- if (check_fpga_version(u) != true) {
+ if (fpga_version_supported(u) != true) {
/* We failed to read expected FPGA version, so let's assume there is no FPGA */
DEBUG_PRINTF("INFO: no FPGA detected or version not supported (v%u)\n", u);
lgw_spi_mux_mode = LGW_SPI_MUX_MODE0;
diff --git a/libloragw/src/loragw_spi.native.c b/libloragw/src/loragw_spi.native.c
index 2380ecb..a26fc22 100644
--- a/libloragw/src/loragw_spi.native.c
+++ b/libloragw/src/loragw_spi.native.c
@@ -73,7 +73,7 @@ int lgw_spi_set_path(const char *path) {
}
}
-
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* SPI initialization and configuration */
int lgw_spi_open(void **spi_target_ptr) {
diff --git a/libloragw/tst/test_loragw_cal.c b/libloragw/tst/test_loragw_cal.c
index 533d189..60c5ce7 100644
--- a/libloragw/tst/test_loragw_cal.c
+++ b/libloragw/tst/test_loragw_cal.c
@@ -31,12 +31,13 @@ Maintainer: Sylvain Miermont
#include <signal.h> /* sigaction */
#include <math.h> /* cos */
#include <unistd.h> /* getopt access */
+#include <getopt.h> /* getopt_long */
#include "loragw_hal.h"
#include "loragw_reg.h"
#include "loragw_aux.h"
#include "loragw_radio.h"
-
+#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
/* --- PRIVATE MACROS ------------------------------------------------------- */
@@ -99,13 +100,14 @@ void usage (void);
void usage(void) {
printf("Library version information: %s\n", lgw_version_info());
printf( "Available options:\n");
- printf( " -h print this help\n");
- printf( " -a <float> Radio A frequency in MHz\n");
- printf( " -b <float> Radio B frequency in MHz\n");
- printf( " -r <int> Radio type (SX1255:1255, SX1257:1257)\n");
- printf( " -n <uint> Number of calibration iterations\n");
- printf( " -k <int> Concentrator clock source (0:radio_A, 1:radio_B(default))\n");
- printf( " -t <int> Radio to run TX calibration on (0:None(default), 1:radio_A, 2:radio_B, 3:both)\n");
+ printf( " -h print this help\n");
+ printf( " -a <float> Radio A frequency in MHz\n");
+ printf( " -b <float> Radio B frequency in MHz\n");
+ printf( " -r <int> Radio type (SX1255:1255, SX1257:1257)\n");
+ printf( " -n <uint> Number of calibration iterations\n");
+ printf( " -k <int> Concentrator clock source (0:radio_A, 1:radio_B(default))\n");
+ printf( " -t <int> Radio to run TX calibration on (0:None(default), 1:radio_A, 2:radio_B, 3:both)\n");
+ printf(" --path <string> path of SPIDEV e.g. /dev/spidev0.0\n");
}
/* -------------------------------------------------------------------------- */
@@ -142,8 +144,16 @@ int main(int argc, char **argv)
uint8_t tx_enable = 0;
int nb_cal = 5;
+ /* Parameter parsing */
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"path", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+ char arg_s[64];
+
/* parse command line options */
- while ((i = getopt (argc, argv, "ha:b:r:n:k:t:")) != -1) {
+ while ((i = getopt_long (argc, argv, "ha:b:r:n:k:t:", long_options, &option_index)) != -1) {
switch (i) {
case 'h':
usage();
@@ -190,6 +200,22 @@ int main(int argc, char **argv)
sscanf(optarg, "%i", &xi);
tx_enable = (uint8_t)xi;
break;
+ case 0:
+ if (strcmp(long_options[option_index].name,"path") == 0) {
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
+ return -1;
+ }
+ else {
+ lgw_spi_set_path(arg_s);
+ }
+ }
+ else {
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return -1;
+ }
+ break;
default:
printf("ERROR: argument parsing\n");
usage();
diff --git a/libloragw/tst/test_loragw_gps.c b/libloragw/tst/test_loragw_gps.c
index 6e644f8..fd8c61b 100644
--- a/libloragw/tst/test_loragw_gps.c
+++ b/libloragw/tst/test_loragw_gps.c
@@ -146,11 +146,9 @@ int main()
/* serial variables */
char serial_buff[128]; /* buffer to receive GPS data */
- size_t wr_idx = 0; /* pointer to end of chars in buffer */
- int gps_tty_dev; /* file descriptor to the serial port of the GNSS module */
/* NMEA/UBX variables */
- enum gps_msg latest_msg; /* keep track of latest NMEA/UBX message parsed */
+ enum gps_msg latest_msg = UNKNOWN; /* keep track of latest NMEA/UBX message parsed */
fd_set fds;
char delim[4] = "$";
diff --git a/libloragw/tst/test_loragw_hal.c b/libloragw/tst/test_loragw_hal.c
index e2fee5e..37e8b42 100644
--- a/libloragw/tst/test_loragw_hal.c
+++ b/libloragw/tst/test_loragw_hal.c
@@ -30,7 +30,9 @@ Maintainer: Sylvain Miermont
#include <string.h> /* memset */
#include <signal.h> /* sigaction */
#include <unistd.h> /* getopt access */
+#include <getopt.h> /* getopt_long */
+#include "loragw_spi.h"
#include "loragw_hal.h"
#include "loragw_reg.h"
#include "loragw_aux.h"
@@ -78,6 +80,7 @@ void usage(void) {
printf( " -t <float> Radio TX frequency in MHz\n");
printf( " -r <int> Radio type (SX1255:1255, SX1257:1257)\n");
printf( " -k <int> Concentrator clock source (0: radio_A, 1: radio_B(default))\n");
+ printf(" --path <string> path of SPIDEV e.g. /dev/spidev0.0\n");
}
/* -------------------------------------------------------------------------- */
@@ -107,8 +110,16 @@ int main(int argc, char **argv)
double xd = 0.0;
int xi = 0;
+ /* Parameter parsing */
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"path", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+ char arg_s[64];
+
/* parse command line options */
- while ((i = getopt (argc, argv, "ha:b:t:r:k:")) != -1) {
+ while ((i = getopt_long (argc, argv, "ha:b:r:n:k:t:", long_options, &option_index)) != -1) {
switch (i) {
case 'h':
usage();
@@ -145,6 +156,22 @@ int main(int argc, char **argv)
sscanf(optarg, "%i", &xi);
clocksource = (uint8_t)xi;
break;
+ case 0:
+ if (strcmp(long_options[option_index].name,"path") == 0) {
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
+ return -1;
+ }
+ else {
+ lgw_spi_set_path(arg_s);
+ }
+ }
+ else {
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return -1;
+ }
+ break;
default:
printf("ERROR: argument parsing\n");
usage();
@@ -307,7 +334,7 @@ int main(int argc, char **argv)
if (i == LGW_HAL_SUCCESS) {
printf("*** Concentrator started ***\n");
} else {
- printf("*** Impossible to start concentrator ***\n");
+ printf("*** Unable to start concentrator ***\n");
return -1;
}
diff --git a/libloragw/tst/test_loragw_reg.c b/libloragw/tst/test_loragw_reg.c
index 37a6f5a..6248a1b 100644
--- a/libloragw/tst/test_loragw_reg.c
+++ b/libloragw/tst/test_loragw_reg.c
@@ -19,15 +19,27 @@ Maintainer: Sylvain Miermont
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
+#include <getopt.h> /* getopt_long */
+#include "loragw_hal.h"
#include "loragw_reg.h"
+#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
/* --- MAIN FUNCTION -------------------------------------------------------- */
#define BURST_TEST_LENGTH 8192
-int main()
+/* describe command line options */
+void usage(void) {
+ printf("Library version information: %s\n", lgw_version_info());
+ printf( "Available options:\n");
+ printf( " -h print this help\n");
+ printf(" --path <string> path of SPIDEV e.g. /dev/spidev0.0\n");
+}
+
+int main(int argc, char **argv)
{
int32_t read_value, test_value;
uint16_t lfsr;
@@ -35,9 +47,52 @@ int main()
uint8_t burst_buffin[BURST_TEST_LENGTH];
int i;
+ /* Parameter parsing */
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"path", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+ char arg_s[64];
+
+ /* parse command line options */
+ while ((i = getopt_long (argc, argv, "h", long_options, &option_index)) != -1) {
+ switch (i) {
+ case 'h':
+ usage();
+ return -1;
+ break;
+ case 0:
+ if (strcmp(long_options[option_index].name,"path") == 0) {
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
+ return -1;
+ }
+ else {
+ lgw_spi_set_path(arg_s);
+ }
+ }
+ else {
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return -1;
+ }
+ break;
+ default:
+ printf("ERROR: argument parsing\n");
+ usage();
+ return -1;
+ }
+ }
+
+
printf("Beginning of test for loragw_reg.c\n");
- lgw_connect(false, 129E3);
+ int result = lgw_connect(false, 129E3);
+ if (result == -1) {
+ printf("ERROR: Failed to connect to the board\n");
+ return -1;
+ }
/* 2 SPI transactions:
-> 0x80 0x00 <- 0x00 0x00 forcing page 0
-> 0x01 0x00 <- 0x00 0x64 checking version
diff --git a/libloragw/tst/test_loragw_spi.c b/libloragw/tst/test_loragw_spi.c
index 872a075..4d06eaa 100644
--- a/libloragw/tst/test_loragw_spi.c
+++ b/libloragw/tst/test_loragw_spi.c
@@ -19,8 +19,11 @@ Maintainer: Sylvain Miermont
/* --- DEPENDANCIES --------------------------------------------------------- */
#include <stdint.h>
+#include <string.h>
#include <stdio.h>
+#include <getopt.h> /* getopt_long */
+#include "loragw_hal.h"
#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
@@ -37,7 +40,7 @@ Maintainer: Sylvain Miermont
/* -------------------------------------------------------------------------- */
/* --- MAIN FUNCTION -------------------------------------------------------- */
-int main()
+int main(int argc, char **argv)
{
int i;
void *spi_target = NULL;
@@ -46,37 +49,119 @@ int main()
uint8_t datain[BURST_TEST_SIZE];
uint8_t spi_mux_mode = LGW_SPI_MUX_MODE0;
+ /* Parameter parsing */
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"path", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+ char arg_s[64];
+
+ while ((i = getopt_long (argc, argv, "h", long_options, &option_index)) != -1) {
+ switch (i) {
+ case 'h':
+ printf("~~~ Library version string~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
+ printf(" %s\n", lgw_version_info());
+ printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
+ printf(" --path <string> Path of SPIDEV e.g. /dev/spidev0.0\n");
+ printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
+ return 0;
+ break;
+
+ case 0:
+ if (strcmp(long_options[option_index].name,"path") == 0) {
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
+ return LGW_SPI_ERROR;
+ }
+ else {
+ lgw_spi_set_path(arg_s);
+ }
+ }
+ else {
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return LGW_SPI_ERROR;
+ }
+ break;
+
+ default:
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return LGW_SPI_ERROR;
+ }
+ }
+
for (i = 0; i < BURST_TEST_SIZE; ++i) {
dataout[i] = 0x30 + (i % 10); /* ASCCI code for 0 -> 9 */
datain[i] = 0x23; /* garbage data, to be overwritten by received data */
}
printf("Beginning of test for loragw_spi.c\n");
- lgw_spi_open(&spi_target);
+
+ int spi_stat = lgw_spi_open(&spi_target);
+
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ printf("ERROR: Unable to connect to concentrator\n");
+ return LGW_SPI_ERROR;
+ }
/* normal R/W test */
- for (i = 0; i < TIMING_REPEAT; ++i)
- lgw_spi_w(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0xAA, 0x96);
- for (i = 0; i < TIMING_REPEAT; ++i)
- lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data);
+ for (i = 0; i < TIMING_REPEAT; ++i) {
+ spi_stat = lgw_spi_w(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0xAA, 0x96);
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ printf("ERROR: Failed write normal R/W test\n");
+ return LGW_SPI_ERROR;
+ }
+ }
+ for (i = 0; i < TIMING_REPEAT; ++i) {
+ spi_stat = lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data);
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ printf("ERROR: Failed read normal R/W test\n");
+ return LGW_SPI_ERROR;
+ }
+ }
/* burst R/W test, small bursts << LGW_BURST_CHUNK */
- for (i = 0; i < TIMING_REPEAT; ++i)
- lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, dataout, 16);
- for (i = 0; i < TIMING_REPEAT; ++i)
- lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, datain, 16);
+ for (i = 0; i < TIMING_REPEAT; ++i) {
+ spi_stat = lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, dataout, 16);
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ printf("ERROR: Failed write small burst R/W test\n");
+ return LGW_SPI_ERROR;
+ }
+ }
+ for (i = 0; i < TIMING_REPEAT; ++i) {
+ spi_stat = lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, datain, 16);
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ printf("ERROR: Failed read small burst R/W test\n");
+ return LGW_SPI_ERROR;
+ }
+ }
/* burst R/W test, large bursts >> LGW_BURST_CHUNK */
- for (i = 0; i < TIMING_REPEAT; ++i)
- lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, dataout, ARRAY_SIZE(dataout));
- for (i = 0; i < TIMING_REPEAT; ++i)
- lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, datain, ARRAY_SIZE(datain));
+ for (i = 0; i < TIMING_REPEAT; ++i) {
+ spi_stat = lgw_spi_wb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, dataout, ARRAY_SIZE(dataout));
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ printf("ERROR: Failed write large burst R/W test\n");
+ return LGW_SPI_ERROR;
+ }
+ }
+ for (i = 0; i < TIMING_REPEAT; ++i) {
+ spi_stat = lgw_spi_rb(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x5A, datain, ARRAY_SIZE(datain));
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ printf("ERROR: Failed read large burst R/W test\n");
+ return LGW_SPI_ERROR;
+ }
+ }
/* last read (blocking), just to be sure no to quit before the FTDI buffer is flushed */
- lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data);
- printf("data received (simple read): %d\n",data);
-
+ spi_stat = lgw_spi_r(spi_target, spi_mux_mode, LGW_SPI_MUX_TARGET_SX1301, 0x55, &data);
+ if (spi_stat != LGW_SPI_SUCCESS) {
+ printf("ERROR: Failed to read last block\n");
+ return LGW_SPI_ERROR;
+ }
lgw_spi_close(spi_target);
+
+ printf("data received (simple read): %d\n",data);
printf("End of test for loragw_spi.c\n");
return 0;
diff --git a/util_lbt_test/src/util_lbt_test.c b/util_lbt_test/src/util_lbt_test.c
index 1c8b185..f143a92 100644
--- a/util_lbt_test/src/util_lbt_test.c
+++ b/util_lbt_test/src/util_lbt_test.c
@@ -31,12 +31,15 @@ Maintainer: Michael Coracin
#include <signal.h> /* sigaction */
#include <unistd.h> /* getopt access */
#include <stdlib.h> /* rand */
+#include <string.h> /* strncmp */
+#include <getopt.h> /* getopt_long */
#include "loragw_aux.h"
#include "loragw_reg.h"
#include "loragw_hal.h"
#include "loragw_radio.h"
#include "loragw_fpga.h"
+#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
/* --- PRIVATE MACROS & CONSTANTS ------------------------------------------- */
@@ -75,11 +78,12 @@ static void sig_handler(int sigio) {
/* describe command line options */
void usage(void) {
printf("Available options:\n");
- printf(" -h print this help\n");
- printf(" -f <float> frequency in MHz of the first LBT channel\n");
- printf(" -o <int> offset in dB to be applied to the SX127x RSSI [-128..127]\n");
- printf(" -r <int> target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n");
- printf(" -s <uint> scan time in µs for all 8 LBT channels [128,5000]\n");
+ printf(" -h print this help\n");
+ printf(" -f <float> frequency in MHz of the first LBT channel\n");
+ printf(" -o <int> offset in dB to be applied to the SX127x RSSI [-128..127]\n");
+ printf(" -r <int> target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n");
+ printf(" -s <uint> scan time in µs for all 8 LBT channels [128,5000]\n");
+ printf(" --path <string> path of SPIDEV e.g. /dev/spidev0.0\n");
}
/* -------------------------------------------------------------------------- */
@@ -89,7 +93,12 @@ int main(int argc, char **argv)
{
int i;
int xi = 0;
-
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"path", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+ char arg_s[64];
/* in/out variables */
double f1 = 0.0;
uint32_t f_init = 0; /* in Hz */
@@ -105,7 +114,7 @@ int main(int argc, char **argv)
uint32_t freq_offset;
/* parse command line options */
- while ((i = getopt (argc, argv, "h:f:s:r:o:")) != -1) {
+ while ((i = getopt_long (argc, argv, "h:f:s:r:o:", long_options, &option_index)) != -1) {
switch (i) {
case 'h':
usage();
@@ -152,6 +161,22 @@ int main(int argc, char **argv)
rssi_offset = (int8_t)xi;
}
break;
+
+ case 0:
+ if (strcmp(long_options[option_index].name,"path") == 0) {
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ else {
+ lgw_spi_set_path(arg_s);
+ }
+ } else {
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ break;
default:
MSG("ERROR: argument parsing use -h option for help\n");
usage();
diff --git a/util_pkt_logger/src/util_pkt_logger.c b/util_pkt_logger/src/util_pkt_logger.c
index 38a50f7..638fde2 100644
--- a/util_pkt_logger/src/util_pkt_logger.c
+++ b/util_pkt_logger/src/util_pkt_logger.c
@@ -36,6 +36,7 @@ Maintainer: Sylvain Miermont
#include "parson.h"
#include "loragw_hal.h"
+#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
/* --- PRIVATE MACROS ------------------------------------------------------- */
@@ -336,6 +337,14 @@ int parse_gateway_configuration(const char * conf_file) {
MSG("INFO: gateway MAC address is configured to %016llX\n", ull);
}
+ str = json_object_get_string(conf, "spi_device");
+ if (str != NULL) {
+ MSG("INFO: SPI device is configured to \"%s\"\n", str);
+ lgw_spi_set_path(str);
+ } else {
+ MSG("INFO: SPI device is not valid\"%s\"\n", str);
+ }
+
json_value_free(root_val);
return 0;
}
diff --git a/util_spectral_scan/src/util_spectral_scan.c b/util_spectral_scan/src/util_spectral_scan.c
index cbc8377..090dc22 100644
--- a/util_spectral_scan/src/util_spectral_scan.c
+++ b/util_spectral_scan/src/util_spectral_scan.c
@@ -31,12 +31,14 @@ Maintainer: Michael Coracin
#include <unistd.h> /* getopt */
#include <string.h>
#include <signal.h>
+#include <getopt.h> /* getopt_long */
#include "loragw_aux.h"
#include "loragw_reg.h"
#include "loragw_hal.h"
#include "loragw_radio.h"
#include "loragw_fpga.h"
+#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
/* --- MACROS & CONSTANTS --------------------------------------------------- */
@@ -115,18 +117,26 @@ int main( int argc, char ** argv )
uint16_t rssi_cumu;
float rssi_thresh[] = {0.1,0.3,0.5,0.8,1};
+ /* Parameter parsing */
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"path", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+
/* Parse command line options */
- while((i = getopt(argc, argv, "hf:n:b:l:o:")) != -1) {
+ while ((i = getopt_long (argc, argv, "hf:n:b:l:o:p:", long_options, &option_index)) != -1) {
switch (i) {
case 'h':
- printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
- printf(" -f <float>:<float>:<float> Frequency vector to scan in MHz (start:step:stop)\n");
- printf(" start>%3.3f step>%1.3f stop<%3.3f\n", MIN_FREQ/1e6, MIN_STEP_FREQ/1e6, MAX_FREQ/1e6);
- printf(" -b <uint> Channel bandwidth in KHz [25,50,100,125,200,250,500]\n");
- printf(" -n <uint> Total number of RSSI points [1..65535]\n");
- printf(" -o <int> Offset in dB to be applied to the SX127x RSSI [-128..127]\n");
- printf(" -l <char> Log file name\n");
- printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
+ printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
+ printf(" -f <float>:<float>:<float> Frequency vector to scan in MHz (start:step:stop)\n");
+ printf(" start>%3.3f step>%1.3f stop<%3.3f\n", MIN_FREQ/1e6, MIN_STEP_FREQ/1e6, MAX_FREQ/1e6);
+ printf(" -b <uint> Channel bandwidth in KHz [25,50,100,125,200,250,500]\n");
+ printf(" -n <uint> Total number of RSSI points [1..65535]\n");
+ printf(" -o <int> Offset in dB to be applied to the SX127x RSSI [-128..127]\n");
+ printf(" -l <string> Log file name\n");
+ printf(" --path <string> path of SPIDEV e.g. /dev/spidev0.0\n");
+ printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
return EXIT_SUCCESS;
case 'f': /* -f <float>:<float>:<float> Frequency vector to scan in MHz, start:step:stop */
@@ -206,6 +216,22 @@ int main( int argc, char ** argv )
}
break;
+ case 0:
+ if (strcmp(long_options[option_index].name,"path") == 0) {
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ else {
+ lgw_spi_set_path(arg_s);
+ }
+ } else {
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ break;
+
default:
printf("ERROR: argument parsing options. -h for help.\n");
return EXIT_FAILURE;
diff --git a/util_spi_stress/src/util_spi_stress.c b/util_spi_stress/src/util_spi_stress.c
index 6cc5f04..6e703d9 100644
--- a/util_spi_stress/src/util_spi_stress.c
+++ b/util_spi_stress/src/util_spi_stress.c
@@ -25,14 +25,17 @@ Maintainer: Sylvain Miermont
#endif
#include <stdint.h> /* C99 types */
+#include <string.h> /* strncmp */
#include <stdbool.h> /* bool type */
#include <stdio.h> /* printf fprintf sprintf fopen fputs */
#include <signal.h> /* sigaction */
#include <unistd.h> /* getopt access */
#include <stdlib.h> /* rand */
+#include <getopt.h> /* getopt_long */
#include "loragw_reg.h"
+#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
/* --- PRIVATE MACROS ------------------------------------------------------- */
@@ -77,8 +80,9 @@ static void sig_handler(int sigio) {
/* describe command line options */
void usage(void) {
MSG( "Available options:\n");
- MSG( " -h print this help\n");
- MSG( " -t <int> specify which test you want to run (1-4)\n");
+ MSG( " -h Print this help\n");
+ MSG( " -t <uint> Specify which test you want to run (1-4)\n");
+ MSG( " --path <string> Path of SPIDEV e.g. /dev/spidev0.0\n");
}
/* -------------------------------------------------------------------------- */
@@ -105,8 +109,15 @@ int main(int argc, char **argv)
uint8_t test_buff[BUFF_SIZE];
uint8_t read_buff[BUFF_SIZE];
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"path", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+ char arg_s[64];
+
/* parse command line options */
- while ((i = getopt (argc, argv, "ht:")) != -1) {
+ while ((i = getopt_long (argc, argv, "ht:", long_options, &option_index)) != -1) {
switch (i) {
case 'h':
usage();
@@ -123,6 +134,24 @@ int main(int argc, char **argv)
}
break;
+ case 0:
+ if (strcmp(long_options[option_index].name,"path") == 0) {
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ else {
+ lgw_spi_set_path(arg_s);
+ }
+ }
+ else {
+ MSG("ERROR: argument parsing use -h option for help\n");
+ usage();
+ return EXIT_FAILURE;
+ }
+ break;
+
default:
MSG("ERROR: argument parsing use -h option for help\n");
usage();
@@ -142,7 +171,7 @@ int main(int argc, char **argv)
/* start SPI link */
i = lgw_connect(false, DEFAULT_TX_NOTCH_FREQ);
if (i != LGW_REG_SUCCESS) {
- MSG("ERROR: lgw_connect() did not return SUCCESS");
+ MSG("ERROR: Unable to connect to the concentrator\n");
return EXIT_FAILURE;
}
@@ -160,7 +189,7 @@ int main(int argc, char **argv)
}
}
if (error) {
- printf("error during the %ith iteration: write 0x%02X, read 0x%02X\n", i+1, test_value, read_value);
+ printf("Error during the %ith iteration: write 0x%02X, read 0x%02X\n", i+1, test_value, read_value);
printf("Repeat read of target register:");
for (i=0; i<READS_WHEN_ERROR; ++i) {
lgw_reg_r(LGW_IMPLICIT_PAYLOAD_LENGHT, &read_value);
diff --git a/util_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c
index 7768c22..aeaae8d 100644
--- a/util_tx_continuous/src/util_tx_continuous.c
+++ b/util_tx_continuous/src/util_tx_continuous.c
@@ -37,6 +37,7 @@ Maintainer: Matthieu Leurent
#include "loragw_hal.h"
#include "loragw_reg.h"
#include "loragw_aux.h"
+#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
/* --- MACROS & CONSTANTS --------------------------------------------------- */
@@ -59,7 +60,7 @@ Maintainer: Matthieu Leurent
#define DEFAULT_FDEV_KHZ 25
#define DEFAULT_BT 2
#define DEFAULT_NOTCH_FREQ 129000U
-#define DEFAULT_ATTENUATION 0.0
+#define DEFAULT_ATTENUATION 0
/* -------------------------------------------------------------------------- */
/* --- GLOBAL VARIABLES ----------------------------------------------------- */
@@ -97,6 +98,7 @@ int main(int argc, char **argv)
{"bt", 1, 0, 0},
{"notch", 1, 0, 0},
{"attn", 1, 0, 0},
+ {"path", 1, 0, 0},
{0, 0, 0, 0}
};
unsigned int arg_u;
@@ -109,7 +111,7 @@ int main(int argc, char **argv)
uint8_t g_dac = DEFAULT_DAC_GAIN;
uint8_t g_mix = DEFAULT_MIXER_GAIN;
uint8_t g_pa = DEFAULT_PA_GAIN;
- float g_atten = DEFAULT_ATTENUATION;
+ uint8_t g_atten = DEFAULT_ATTENUATION;
char mod[64] = DEFAULT_MODULATION;
uint8_t sf = DEFAULT_SF;
unsigned int bw_khz = DEFAULT_BW_KHZ;
@@ -117,7 +119,6 @@ int main(int argc, char **argv)
uint8_t fdev_khz = DEFAULT_FDEV_KHZ;
uint8_t bt = DEFAULT_BT;
uint32_t tx_notch_freq = DEFAULT_NOTCH_FREQ;
-
int32_t offset_i, offset_q;
/* RF configuration (TX fail if RF chain is not enabled) */
@@ -149,7 +150,8 @@ int main(int argc, char **argv)
printf(" --br <float> FSK bitrate in kbps, [0.5:250]\n");
printf(" --fdev <uint> FSK frequency deviation in kHz, [1:250]\n");
printf(" --bt <uint> FSK gaussian filter BT trim, [0:3]\n");
- printf(" --attn <float> Attenuator value in dB, Full Card Only [0.0:31.75]\n");
+ printf(" --attn <uint> Attenuator value in dB, required LGA module or MTAC full card\n");
+ printf(" --path <string> Path of SPIDEV e.g. /dev/spidev0.0\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
return EXIT_SUCCESS;
break;
@@ -267,50 +269,59 @@ int main(int argc, char **argv)
}
}
else if (strcmp(long_options[option_index].name,"attn") == 0) {
- i = sscanf(optarg, "%f", &arg_f);
- if ((i != 1) || (arg_f < 0.0) || (arg_f > 31.75)) {
- printf("ERROR: argument parsing of --br argument. Use -h to print help\n");
+ i = sscanf(optarg, "%u", &arg_u);
+ if ((i != 1) || (arg_u > 127) ) {
+ printf("ERROR: argument parsing of --attn argument. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ else {
+ g_atten = arg_u;
+ }
+ } else if (strcmp(long_options[option_index].name,"path") == 0) {
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
return EXIT_FAILURE;
}
else {
- g_atten = arg_f;
+ lgw_spi_set_path(arg_s);
}
- }
+ }
else {
printf("ERROR: argument parsing options. Use -h to print help\n");
return EXIT_FAILURE;
}
break;
- case 'f':
- i = sscanf(optarg, "%f", &arg_f);
- if ((i != 1) || (arg_f < 1)) {
- printf("ERROR: argument parsing of -f argument. Use -h to print help\n");
- return EXIT_FAILURE;
- }
- else {
- freq_hz = (uint32_t)((arg_f * 1e6) + 0.5);
- }
- break;
-
- case 'r':
- i = sscanf(optarg, "%u", &arg_u);
- switch (arg_u) {
- case 1255:
- radio_type = LGW_RADIO_TYPE_SX1255;
- break;
- case 1257:
- radio_type = LGW_RADIO_TYPE_SX1257;
- break;
- default:
- printf("ERROR: argument parsing of -r argument. Use -h to print help\n");
+ case 'f':
+ i = sscanf(optarg, "%f", &arg_f);
+ if ((i != 1) || (arg_f < 1)) {
+ printf("ERROR: argument parsing of -f argument. Use -h to print help\n");
return EXIT_FAILURE;
- }
- break;
+ }
+ else {
+ freq_hz = (uint32_t)((arg_f * 1e6) + 0.5);
+ }
+ break;
- default:
- printf("ERROR: argument parsing options. Use -h to print help\n");
- return EXIT_FAILURE;
+ case 'r':
+ i = sscanf(optarg, "%u", &arg_u);
+ switch (arg_u) {
+ case 1255:
+ radio_type = LGW_RADIO_TYPE_SX1255;
+ break;
+ case 1257:
+ radio_type = LGW_RADIO_TYPE_SX1257;
+ break;
+ default:
+ printf("ERROR: argument parsing of -r argument. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ break;
+
+ default:
+ printf("ERROR: argument parsing options. Use -h to print help\n");
+ return EXIT_FAILURE;
}
}
@@ -362,9 +373,10 @@ int main(int argc, char **argv)
txpkt.freq_hz = freq_hz;
txpkt.tx_mode = IMMEDIATE;
txpkt.rf_chain = TX_RF_CHAIN;
- txpkt.rf_power = 0;
- if (read_fpga_version() == 32) {
- i = lgw_set_attenuation(g_atten);
+ if (fpga_supports_attenuator()) {
+ txpkt.rf_power = 32 - g_atten;
+ } else {
+ txpkt.rf_power = 0;
}
if (strcmp(mod, "FSK") == 0) {
@@ -437,6 +449,10 @@ int main(int argc, char **argv)
printf("ERROR: undefined radio type\n");
break;
}
+
+ if (fpga_supports_attenuator()) {
+ printf("Attenuation : %d dB\n", g_atten);
+ }
printf("Frequency: %4.3f MHz\n", freq_hz/1e6);
printf("TX Gains: Digital:%d DAC:%d Mixer:%d PA:%d\n", g_dig, g_dac, g_mix, g_pa);
if (strcmp(mod, "CW") != 0) {
diff --git a/util_tx_test/src/util_tx_test.c b/util_tx_test/src/util_tx_test.c
index 74c163f..0ac8244 100644
--- a/util_tx_test/src/util_tx_test.c
+++ b/util_tx_test/src/util_tx_test.c
@@ -37,6 +37,7 @@ Maintainer: Sylvain Miermont
#include "loragw_hal.h"
#include "loragw_reg.h"
#include "loragw_aux.h"
+#include "loragw_spi.h"
/* -------------------------------------------------------------------------- */
/* --- PRIVATE MACROS ------------------------------------------------------- */
@@ -147,11 +148,12 @@ void usage(void) {
printf(" -i send packet using inverted modulation polarity\n");
printf(" -t <uint> pause between packets (ms)\n");
printf(" -x <int> nb of times the sequence is repeated (-1 loop until stopped)\n");
- printf(" --lbt-freq <float> lbt first channel frequency in MHz\n");
- printf(" --lbt-nbch <uint> lbt number of channels [1..8]\n");
- printf(" --lbt-sctm <uint> lbt scan time in usec to be applied to all channels [128, 5000]\n");
- printf(" --lbt-rssi <int> lbt rssi target in dBm [-128..0]\n");
- printf(" --lbt-rssi-offset <int> rssi offset in dB to be applied to SX127x RSSI [-128..127]\n");
+ printf(" --lbt-freq <float> lbt first channel frequency in MHz\n");
+ printf(" --lbt-nbch <uint> lbt number of channels [1..8]\n");
+ printf(" --lbt-sctm <uint> lbt scan time in usec to be applied to all channels [128, 5000]\n");
+ printf(" --lbt-rssi <int> lbt rssi target in dBm [-128..0]\n");
+ printf(" --lbt-rssi-offset <int> rssi offset in dB to be applied to SX127x RSSI [-128..127]\n");
+ printf(" --path <string> path of SPIDEV e.g. /dev/spidev0.0\n");
}
/* -------------------------------------------------------------------------- */
@@ -213,6 +215,7 @@ int main(int argc, char **argv)
{"lbt-rssi", required_argument, 0, 0},
{"lbt-nbch", required_argument, 0, 0},
{"lbt-rssi-offset", required_argument, 0, 0},
+ {"path", required_argument, 0, 0},
{0, 0, 0, 0}
};
@@ -469,6 +472,15 @@ int main(int argc, char **argv)
usage();
return EXIT_FAILURE;
}
+ } else if (strcmp(long_options[option_index].name,"path") == 0) { /* <string> Path to spi device */
+ i = sscanf(optarg, "%s", arg_s);
+ if ((i != 1) || (strncmp(arg_s, "/dev/", 5 ) != 0)) {
+ printf("ERROR: argument parsing of --path argument. Use -h to print help\n");
+ return EXIT_FAILURE;
+ }
+ else {
+ lgw_spi_set_path(arg_s);
+ }
}
break;
default: