From e17924a367e6008c669b31f4dcf82ccfee7d3877 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Thu, 3 Oct 2019 14:31:05 -0500 Subject: Changed makefile libloragw_version to based on git describe --- libloragw/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libloragw/Makefile b/libloragw/Makefile index 4575bdc..6edeb46 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 -- cgit v1.2.3 From c05674a9613e5acd5e0bdee9d1298a780189a459 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Tue, 29 Oct 2019 14:40:59 -0500 Subject: Added support for attenuator for LGA modules and full cards --- libloragw/inc/loragw_hal.h | 1 + libloragw/inc/loragw_reg.h | 11 +++++++---- libloragw/src/loragw_fpga.c | 2 +- libloragw/src/loragw_hal.c | 29 ++++++++++++++--------------- libloragw/src/loragw_reg.c | 38 ++++++++++++++++++++++++++------------ 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/libloragw/inc/loragw_hal.h b/libloragw/inc/loragw_hal.h index 15bf918..fda8908 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 */ }; /** 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..279a3b8 100644 --- a/libloragw/src/loragw_fpga.c +++ b/libloragw/src/loragw_fpga.c @@ -176,7 +176,7 @@ int lgw_fpga_configure(uint32_t tx_notch_freq) { return LGW_REG_ERROR; } /* Set Attenuator mode to be used for the full card*/ - if (fpga_version == 32) { + if (fpga_supports_attenuator()) { lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_MODE, 0); } } diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c index a891fbf..48bc3b0 100644 --- a/libloragw/src/loragw_hal.c +++ b/libloragw/src/loragw_hal.c @@ -1414,27 +1414,29 @@ 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 */ + x = lgw_set_attenuation((float)(32.0 - pkt_data.rf_power)); + 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 +1445,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; -- cgit v1.2.3 From 963a35fe0d6668e5b66d6bd1ff9659be8bf7d7bd Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Tue, 29 Oct 2019 16:48:34 -0500 Subject: Changed tx power to be limited from max tx power variable --- libloragw/src/loragw_hal.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c index 48bc3b0..88bd874 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,13 @@ 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; + printf("-------MAX TX POWER %d\n", 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; } @@ -1418,7 +1424,7 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) { /* 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 */ - x = lgw_set_attenuation((float)(32.0 - pkt_data.rf_power)); + x = lgw_set_attenuation((float)(max_tx_power - pkt_data.rf_power)); if (x != LGW_HAL_SUCCESS) { DEBUG_MSG("ERROR: Failed to set attenuation value\n"); return LGW_HAL_ERROR; -- cgit v1.2.3 From 408ecd322635e37c710006c95a22dddc455e7f08 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Thu, 31 Oct 2019 11:17:13 -0500 Subject: Fixed lora attenuator mode --- libloragw/inc/config.h | 11 +++++++++++ libloragw/inc/loragw_fpga.h | 3 +-- libloragw/inc/loragw_hal.h | 9 +-------- libloragw/src/loragw_fpga.c | 30 +++++++++++++++++++---------- libloragw/src/loragw_hal.c | 4 ++-- util_tx_continuous/src/util_tx_continuous.c | 13 +++++++------ 6 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 libloragw/inc/config.h diff --git a/libloragw/inc/config.h b/libloragw/inc/config.h new file mode 100644 index 0000000..9b96c5f --- /dev/null +++ b/libloragw/inc/config.h @@ -0,0 +1,11 @@ +#ifndef _LORAGW_CONFIGURATION_H +#define _LORAGW_CONFIGURATION_H + #define LIBLORAGW_VERSION "0.1-16-gc05674a" + #define DEBUG_AUX 0 + #define DEBUG_SPI 0 + #define DEBUG_REG 0 + #define DEBUG_HAL 0 + #define DEBUG_GPS 0 + #define DEBUG_GPIO + #define DEBUG_LBT 0 +#endif diff --git a/libloragw/inc/loragw_fpga.h b/libloragw/inc/loragw_fpga.h index 46246b6..d5b6f9d 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(float *attn); #endif /* --- EOF ------------------------------------------------------------------ */ diff --git a/libloragw/inc/loragw_hal.h b/libloragw/inc/loragw_hal.h index fda8908..f5a6183 100644 --- a/libloragw/inc/loragw_hal.h +++ b/libloragw/inc/loragw_hal.h @@ -260,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) */ @@ -415,13 +415,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/src/loragw_fpga.c b/libloragw/src/loragw_fpga.c index 279a3b8..368fe37 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_supports_attenuator()) { - 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,22 @@ 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(float *attn) { + if (*attn < 0) { return LGW_HAL_ERROR; } - i = lgw_fpga_reg_w(LGW_FPGA_RF_ATTN_VALUE, (uint8_t)(attenuation * LGW_RF_ATTN_CONV_CONST)); + int i; + int32_t val; + /* 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_hal.c b/libloragw/src/loragw_hal.c index 88bd874..386bd6d 100644 --- a/libloragw/src/loragw_hal.c +++ b/libloragw/src/loragw_hal.c @@ -426,7 +426,6 @@ int lgw_board_setconf(struct lgw_conf_board_s conf) { rf_clkout = conf.clksrc; if (fpga_supports_attenuator()) { max_tx_power = conf.max_tx_power; - printf("-------MAX TX POWER %d\n", 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); @@ -1424,7 +1423,8 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) { /* 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 */ - x = lgw_set_attenuation((float)(max_tx_power - pkt_data.rf_power)); + float attn = (float)(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; diff --git a/util_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c index 7768c22..275c3eb 100644 --- a/util_tx_continuous/src/util_tx_continuous.c +++ b/util_tx_continuous/src/util_tx_continuous.c @@ -149,7 +149,7 @@ int main(int argc, char **argv) printf(" --br FSK bitrate in kbps, [0.5:250]\n"); printf(" --fdev FSK frequency deviation in kHz, [1:250]\n"); printf(" --bt FSK gaussian filter BT trim, [0:3]\n"); - printf(" --attn Attenuator value in dB, Full Card Only [0.0:31.75]\n"); + printf(" --attn Attenuator value in dB, required LGA module or MTAC full card\n"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); return EXIT_SUCCESS; break; @@ -268,8 +268,8 @@ 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"); + if ((i != 1) || (arg_f < 0.0) ) { + printf("ERROR: argument parsing of --attn argument. Use -h to print help\n"); return EXIT_FAILURE; } else { @@ -362,9 +362,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.0 - g_atten; + } else { + txpkt.rf_power = 0.0; } if (strcmp(mod, "FSK") == 0) { -- cgit v1.2.3 From f870877782ba8a279580f2df0ab7c244a4849ab0 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Fri, 15 Nov 2019 14:02:18 -0600 Subject: Changed attenuator power to be int instead of float --- libloragw/inc/loragw_fpga.h | 2 +- libloragw/src/loragw_fpga.c | 2 +- libloragw/src/loragw_hal.c | 2 +- util_tx_continuous/src/util_tx_continuous.c | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libloragw/inc/loragw_fpga.h b/libloragw/inc/loragw_fpga.h index d5b6f9d..722438c 100644 --- a/libloragw/inc/loragw_fpga.h +++ b/libloragw/inc/loragw_fpga.h @@ -135,6 +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 *attn); +int lgw_set_attenuation(uint8_t *attn); #endif /* --- EOF ------------------------------------------------------------------ */ diff --git a/libloragw/src/loragw_fpga.c b/libloragw/src/loragw_fpga.c index 368fe37..906f4b5 100644 --- a/libloragw/src/loragw_fpga.c +++ b/libloragw/src/loragw_fpga.c @@ -366,7 +366,7 @@ int lgw_fpga_reg_rb(uint16_t register_id, uint8_t *data, uint16_t size) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -int lgw_set_attenuation(float *attn) { +int lgw_set_attenuation(uint8_t *attn) { if (*attn < 0) { return LGW_HAL_ERROR; } diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c index 386bd6d..9355cb8 100644 --- a/libloragw/src/loragw_hal.c +++ b/libloragw/src/loragw_hal.c @@ -1423,7 +1423,7 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) { /* 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 */ - float attn = (float)(max_tx_power - pkt_data.rf_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"); diff --git a/util_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c index 275c3eb..54d77f7 100644 --- a/util_tx_continuous/src/util_tx_continuous.c +++ b/util_tx_continuous/src/util_tx_continuous.c @@ -59,7 +59,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 ----------------------------------------------------- */ @@ -109,7 +109,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; @@ -267,13 +267,13 @@ 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) ) { + i = sscanf(optarg, "%u", &arg_u); + if ((i != 1) || (arg_f > 127) ) { printf("ERROR: argument parsing of --attn argument. Use -h to print help\n"); return EXIT_FAILURE; } else { - g_atten = arg_f; + g_atten = arg_u; } } else { @@ -363,9 +363,9 @@ int main(int argc, char **argv) txpkt.tx_mode = IMMEDIATE; txpkt.rf_chain = TX_RF_CHAIN; if (fpga_supports_attenuator()) { - txpkt.rf_power = 32.0 - g_atten; + txpkt.rf_power = 32 - g_atten; } else { - txpkt.rf_power = 0.0; + txpkt.rf_power = 0; } if (strcmp(mod, "FSK") == 0) { -- cgit v1.2.3 From 583ef0e2aa87d5e0c7ca71b3a681c801ff7b952a Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Thu, 2 Jan 2020 13:41:52 -0600 Subject: Added spi path as a command line option for util_tx_continuous and test_loragw_spi --- libloragw/src/loragw_spi.native.c | 2 +- libloragw/tst/test_loragw_spi.c | 118 ++++++++++++++++++++++++---- util_tx_continuous/src/util_tx_continuous.c | 15 +++- 3 files changed, 115 insertions(+), 20 deletions(-) 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_spi.c b/libloragw/tst/test_loragw_spi.c index 872a075..9489d3c 100644 --- a/libloragw/tst/test_loragw_spi.c +++ b/libloragw/tst/test_loragw_spi.c @@ -20,7 +20,9 @@ Maintainer: Sylvain Miermont #include #include +#include /* getopt_long */ +#include "loragw_hal.h" #include "loragw_spi.h" /* -------------------------------------------------------------------------- */ @@ -37,7 +39,7 @@ Maintainer: Sylvain Miermont /* -------------------------------------------------------------------------- */ /* --- MAIN FUNCTION -------------------------------------------------------- */ -int main() +int main(int argc, char **argv) { int i; void *spi_target = NULL; @@ -46,37 +48,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 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_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c index 54d77f7..b8b59e9 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 --------------------------------------------------- */ @@ -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; @@ -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) */ @@ -150,6 +151,7 @@ int main(int argc, char **argv) printf(" --fdev FSK frequency deviation in kHz, [1:250]\n"); printf(" --bt FSK gaussian filter BT trim, [0:3]\n"); printf(" --attn Attenuator value in dB, required LGA module or MTAC full card\n"); + printf(" --path Path of SPIDEV e.g. /dev/spidev0.0\n"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); return EXIT_SUCCESS; break; @@ -275,7 +277,16 @@ int main(int argc, char **argv) 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 { + lgw_spi_set_path(arg_s); + } + } else { printf("ERROR: argument parsing options. Use -h to print help\n"); return EXIT_FAILURE; -- cgit v1.2.3 From a0a94c3336574482d16fa910e94d7f07bba60123 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Thu, 2 Jan 2020 13:57:50 -0600 Subject: Added spidev to the commandline options for the util_spi_stress --- util_spi_stress/src/util_spi_stress.c | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/util_spi_stress/src/util_spi_stress.c b/util_spi_stress/src/util_spi_stress.c index 6cc5f04..c33f18f 100644 --- a/util_spi_stress/src/util_spi_stress.c +++ b/util_spi_stress/src/util_spi_stress.c @@ -31,6 +31,7 @@ Maintainer: Sylvain Miermont #include /* sigaction */ #include /* getopt access */ #include /* rand */ +#include /* getopt_long */ #include "loragw_reg.h" @@ -77,8 +78,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 specify which test you want to run (1-4)\n"); + MSG( " -h Print this help\n"); + MSG( " -t Specify which test you want to run (1-4)\n"); + MSG( " --path Path of SPIDEV e.g. /dev/spidev0.0\n"); } /* -------------------------------------------------------------------------- */ @@ -105,8 +107,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 +132,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 +169,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 +187,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 Date: Fri, 24 Jan 2020 13:22:57 -0600 Subject: Bug fix for util tx continuous's attn setting and added spi path option for util tx test --- util_tx_continuous/src/util_tx_continuous.c | 4 ++-- util_tx_test/src/util_tx_test.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/util_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c index b8b59e9..591054a 100644 --- a/util_tx_continuous/src/util_tx_continuous.c +++ b/util_tx_continuous/src/util_tx_continuous.c @@ -150,7 +150,7 @@ int main(int argc, char **argv) printf(" --br FSK bitrate in kbps, [0.5:250]\n"); printf(" --fdev FSK frequency deviation in kHz, [1:250]\n"); printf(" --bt FSK gaussian filter BT trim, [0:3]\n"); - printf(" --attn Attenuator value in dB, required LGA module or MTAC full card\n"); + printf(" --attn Attenuator value in dB, required LGA module or MTAC full card\n"); printf(" --path Path of SPIDEV e.g. /dev/spidev0.0\n"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); return EXIT_SUCCESS; @@ -270,7 +270,7 @@ int main(int argc, char **argv) } else if (strcmp(long_options[option_index].name,"attn") == 0) { i = sscanf(optarg, "%u", &arg_u); - if ((i != 1) || (arg_f > 127) ) { + if ((i != 1) || (arg_u > 127) ) { printf("ERROR: argument parsing of --attn argument. Use -h to print help\n"); return EXIT_FAILURE; } 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 pause between packets (ms)\n"); printf(" -x nb of times the sequence is repeated (-1 loop until stopped)\n"); - printf(" --lbt-freq lbt first channel frequency in MHz\n"); - printf(" --lbt-nbch lbt number of channels [1..8]\n"); - printf(" --lbt-sctm lbt scan time in usec to be applied to all channels [128, 5000]\n"); - printf(" --lbt-rssi lbt rssi target in dBm [-128..0]\n"); - printf(" --lbt-rssi-offset rssi offset in dB to be applied to SX127x RSSI [-128..127]\n"); + printf(" --lbt-freq lbt first channel frequency in MHz\n"); + printf(" --lbt-nbch lbt number of channels [1..8]\n"); + printf(" --lbt-sctm lbt scan time in usec to be applied to all channels [128, 5000]\n"); + printf(" --lbt-rssi lbt rssi target in dBm [-128..0]\n"); + printf(" --lbt-rssi-offset rssi offset in dB to be applied to SX127x RSSI [-128..127]\n"); + printf(" --path 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) { /* 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: -- cgit v1.2.3 From d14d5e0766f7190cd3f6d91003e8d3f356f91359 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Fri, 24 Jan 2020 13:57:31 -0600 Subject: Added spi path to util lbt test --- util_lbt_test/src/util_lbt_test.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/util_lbt_test/src/util_lbt_test.c b/util_lbt_test/src/util_lbt_test.c index 1c8b185..16af7ac 100644 --- a/util_lbt_test/src/util_lbt_test.c +++ b/util_lbt_test/src/util_lbt_test.c @@ -31,12 +31,14 @@ Maintainer: Michael Coracin #include /* sigaction */ #include /* getopt access */ #include /* rand */ +#include /* strncmp */ #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 ------------------------------------------- */ @@ -76,10 +78,11 @@ static void sig_handler(int sigio) { void usage(void) { printf("Available options:\n"); printf(" -h print this help\n"); - printf(" -f frequency in MHz of the first LBT channel\n"); - printf(" -o offset in dB to be applied to the SX127x RSSI [-128..127]\n"); - printf(" -r target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n"); - printf(" -s scan time in µs for all 8 LBT channels [128,5000]\n"); + printf(" -f frequency in MHz of the first LBT channel\n"); + printf(" -o offset in dB to be applied to the SX127x RSSI [-128..127]\n"); + printf(" -r target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n"); + printf(" -s scan time in µs for all 8 LBT channels [128,5000]\n"); + printf(" -p path of SPIDEV e.g. /dev/spidev0.0\n"); } /* -------------------------------------------------------------------------- */ @@ -89,7 +92,7 @@ int main(int argc, char **argv) { int i; int xi = 0; - + char arg_s[64]; /* in/out variables */ double f1 = 0.0; uint32_t f_init = 0; /* in Hz */ @@ -105,7 +108,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 (argc, argv, "h:f:s:r:o:p:")) != -1) { switch (i) { case 'h': usage(); @@ -142,6 +145,16 @@ int main(int argc, char **argv) rssi_target_dBm = xi; } break; + case 'p': + 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; case 'o': /* -o SX127x RSSI offset [-128..127] */ i = sscanf(optarg, "%i", &xi); if((i != 1) || (xi < -128) || (xi > 127)) { -- cgit v1.2.3 From a9459f3548725e50b6d22ad04074fe2610be8808 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Fri, 24 Jan 2020 15:12:18 -0600 Subject: Added spi_device option to util_pkt_logger --- util_pkt_logger/src/util_pkt_logger.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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; } -- cgit v1.2.3 From c08bf1d60c88179d791678a2db6db61f87fea032 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Fri, 24 Jan 2020 15:31:21 -0600 Subject: Added spi device option to util spectral scan --- util_spectral_scan/src/util_spectral_scan.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/util_spectral_scan/src/util_spectral_scan.c b/util_spectral_scan/src/util_spectral_scan.c index cbc8377..91a358f 100644 --- a/util_spectral_scan/src/util_spectral_scan.c +++ b/util_spectral_scan/src/util_spectral_scan.c @@ -37,6 +37,7 @@ Maintainer: Michael Coracin #include "loragw_hal.h" #include "loragw_radio.h" #include "loragw_fpga.h" +#include "loragw_spi.h" /* -------------------------------------------------------------------------- */ /* --- MACROS & CONSTANTS --------------------------------------------------- */ @@ -116,7 +117,7 @@ int main( int argc, char ** argv ) float rssi_thresh[] = {0.1,0.3,0.5,0.8,1}; /* Parse command line options */ - while((i = getopt(argc, argv, "hf:n:b:l:o:")) != -1) { + while((i = getopt(argc, argv, "hf:n:b:l:o:p:")) != -1) { switch (i) { case 'h': printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); @@ -126,6 +127,7 @@ int main( int argc, char ** argv ) printf(" -n Total number of RSSI points [1..65535]\n"); printf(" -o Offset in dB to be applied to the SX127x RSSI [-128..127]\n"); printf(" -l Log file name\n"); + printf(" -p path of SPIDEV e.g. /dev/spidev0.0\n"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); return EXIT_SUCCESS; @@ -206,6 +208,16 @@ int main( int argc, char ** argv ) } break; + case 'p': /* -p Path for spi device */ + j = sscanf(optarg, "%s", arg_s); + if (j != 1) { + printf("ERROR: argument parsing of -p argument. -h for help.\n"); + return EXIT_FAILURE; + } else { + lgw_spi_set_path(arg_s); + } + break; + default: printf("ERROR: argument parsing options. -h for help.\n"); return EXIT_FAILURE; -- cgit v1.2.3 From 60296026590d64f61766896cf770e69e3bfb185c Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Fri, 24 Jan 2020 16:11:32 -0600 Subject: Changed lgw version to use git describe --- libloragw/Makefile | 4 ++-- libloragw/inc/config.h | 11 ----------- libloragw/src/loragw_fpga.c | 3 +-- libloragw/src/loragw_gps.c | 1 - libloragw/tst/test_loragw_spi.c | 1 + util_spi_stress/src/util_spi_stress.c | 2 ++ 6 files changed, 6 insertions(+), 16 deletions(-) delete mode 100644 libloragw/inc/config.h diff --git a/libloragw/Makefile b/libloragw/Makefile index 6edeb46..7e95eca 100644 --- a/libloragw/Makefile +++ b/libloragw/Makefile @@ -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/config.h b/libloragw/inc/config.h deleted file mode 100644 index 9b96c5f..0000000 --- a/libloragw/inc/config.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _LORAGW_CONFIGURATION_H -#define _LORAGW_CONFIGURATION_H - #define LIBLORAGW_VERSION "0.1-16-gc05674a" - #define DEBUG_AUX 0 - #define DEBUG_SPI 0 - #define DEBUG_REG 0 - #define DEBUG_HAL 0 - #define DEBUG_GPS 0 - #define DEBUG_GPIO - #define DEBUG_LBT 0 -#endif diff --git a/libloragw/src/loragw_fpga.c b/libloragw/src/loragw_fpga.c index 906f4b5..63c6d3b 100644 --- a/libloragw/src/loragw_fpga.c +++ b/libloragw/src/loragw_fpga.c @@ -367,11 +367,10 @@ int lgw_fpga_reg_rb(uint16_t register_id, uint8_t *data, uint16_t size) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ int lgw_set_attenuation(uint8_t *attn) { - if (*attn < 0) { + if (*attn > 127) { return LGW_HAL_ERROR; } int i; - int32_t val; /* The max value allowed for 7 bits of a register */ uint8_t max_attn = 127; diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index 3aad031..bd728b6 100644 --- a/libloragw/src/loragw_gps.c +++ b/libloragw/src/loragw_gps.c @@ -255,7 +255,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/tst/test_loragw_spi.c b/libloragw/tst/test_loragw_spi.c index 9489d3c..4d06eaa 100644 --- a/libloragw/tst/test_loragw_spi.c +++ b/libloragw/tst/test_loragw_spi.c @@ -19,6 +19,7 @@ Maintainer: Sylvain Miermont /* --- DEPENDANCIES --------------------------------------------------------- */ #include +#include #include #include /* getopt_long */ diff --git a/util_spi_stress/src/util_spi_stress.c b/util_spi_stress/src/util_spi_stress.c index c33f18f..6e703d9 100644 --- a/util_spi_stress/src/util_spi_stress.c +++ b/util_spi_stress/src/util_spi_stress.c @@ -25,6 +25,7 @@ Maintainer: Sylvain Miermont #endif #include /* C99 types */ +#include /* strncmp */ #include /* bool type */ #include /* printf fprintf sprintf fopen fputs */ @@ -34,6 +35,7 @@ Maintainer: Sylvain Miermont #include /* getopt_long */ #include "loragw_reg.h" +#include "loragw_spi.h" /* -------------------------------------------------------------------------- */ /* --- PRIVATE MACROS ------------------------------------------------------- */ -- cgit v1.2.3 From 1f3107208237455215c840956a371c195b68fee7 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 13:52:13 -0600 Subject: Added printing of attenuator setting info to util tx continuous --- util_tx_continuous/src/util_tx_continuous.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c index 591054a..e3b3179 100644 --- a/util_tx_continuous/src/util_tx_continuous.c +++ b/util_tx_continuous/src/util_tx_continuous.c @@ -449,6 +449,7 @@ int main(int argc, char **argv) printf("ERROR: undefined radio type\n"); break; } + 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) { -- cgit v1.2.3 From 24cd1e066310ebabe6968c28d9ee2cd87bd28e26 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 13:54:31 -0600 Subject: Added guard around printing attenuator setting --- util_tx_continuous/src/util_tx_continuous.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c index e3b3179..6cf2999 100644 --- a/util_tx_continuous/src/util_tx_continuous.c +++ b/util_tx_continuous/src/util_tx_continuous.c @@ -449,7 +449,10 @@ int main(int argc, char **argv) printf("ERROR: undefined radio type\n"); break; } - printf("Attenuation : %d dB\n", g_atten); + + 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) { -- cgit v1.2.3 From 9eb0233d94d05b89d8dab1ad192f5010d1282341 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 14:39:58 -0600 Subject: Changed getopt path option to conform with other utilities --- util_lbt_test/src/util_lbt_test.c | 46 +++++++++++++++--------- util_tx_continuous/src/util_tx_continuous.c | 54 ++++++++++++++--------------- 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/util_lbt_test/src/util_lbt_test.c b/util_lbt_test/src/util_lbt_test.c index 16af7ac..f143a92 100644 --- a/util_lbt_test/src/util_lbt_test.c +++ b/util_lbt_test/src/util_lbt_test.c @@ -32,6 +32,7 @@ Maintainer: Michael Coracin #include /* getopt access */ #include /* rand */ #include /* strncmp */ +#include /* getopt_long */ #include "loragw_aux.h" #include "loragw_reg.h" @@ -77,12 +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 frequency in MHz of the first LBT channel\n"); - printf(" -o offset in dB to be applied to the SX127x RSSI [-128..127]\n"); - printf(" -r target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n"); - printf(" -s scan time in µs for all 8 LBT channels [128,5000]\n"); - printf(" -p path of SPIDEV e.g. /dev/spidev0.0\n"); + printf(" -h print this help\n"); + printf(" -f frequency in MHz of the first LBT channel\n"); + printf(" -o offset in dB to be applied to the SX127x RSSI [-128..127]\n"); + printf(" -r target RSSI: signal strength target used to detect if the channel is clear or not [-128..0]\n"); + printf(" -s scan time in µs for all 8 LBT channels [128,5000]\n"); + printf(" --path path of SPIDEV e.g. /dev/spidev0.0\n"); } /* -------------------------------------------------------------------------- */ @@ -92,6 +93,11 @@ 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; @@ -108,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:p:")) != -1) { + while ((i = getopt_long (argc, argv, "h:f:s:r:o:", long_options, &option_index)) != -1) { switch (i) { case 'h': usage(); @@ -145,16 +151,6 @@ int main(int argc, char **argv) rssi_target_dBm = xi; } break; - case 'p': - 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; case 'o': /* -o SX127x RSSI offset [-128..127] */ i = sscanf(optarg, "%i", &xi); if((i != 1) || (xi < -128) || (xi > 127)) { @@ -165,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_tx_continuous/src/util_tx_continuous.c b/util_tx_continuous/src/util_tx_continuous.c index 6cf2999..aeaae8d 100644 --- a/util_tx_continuous/src/util_tx_continuous.c +++ b/util_tx_continuous/src/util_tx_continuous.c @@ -293,35 +293,35 @@ int main(int argc, char **argv) } 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; } } -- cgit v1.2.3 From ac8d94851bb1a0bb22cd9815a483e8ed2a99e8f5 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 15:06:52 -0600 Subject: Added spi path option to test_loragw_cal --- libloragw/tst/test_loragw_cal.c | 44 ++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) 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 /* sigaction */ #include /* cos */ #include /* getopt access */ +#include /* 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 Radio A frequency in MHz\n"); - printf( " -b Radio B frequency in MHz\n"); - printf( " -r Radio type (SX1255:1255, SX1257:1257)\n"); - printf( " -n Number of calibration iterations\n"); - printf( " -k Concentrator clock source (0:radio_A, 1:radio_B(default))\n"); - printf( " -t 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 Radio A frequency in MHz\n"); + printf( " -b Radio B frequency in MHz\n"); + printf( " -r Radio type (SX1255:1255, SX1257:1257)\n"); + printf( " -n Number of calibration iterations\n"); + printf( " -k Concentrator clock source (0:radio_A, 1:radio_B(default))\n"); + printf( " -t Radio to run TX calibration on (0:None(default), 1:radio_A, 2:radio_B, 3:both)\n"); + printf(" --path 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(); -- cgit v1.2.3 From febb8372c248a11007eee7ea0267178f0dec61ee Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 15:14:42 -0600 Subject: Added spi path option to test loragw hal --- libloragw/tst/test_loragw_hal.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/libloragw/tst/test_loragw_hal.c b/libloragw/tst/test_loragw_hal.c index e2fee5e..3bdd7b2 100644 --- a/libloragw/tst/test_loragw_hal.c +++ b/libloragw/tst/test_loragw_hal.c @@ -30,7 +30,9 @@ Maintainer: Sylvain Miermont #include /* memset */ #include /* sigaction */ #include /* getopt access */ +#include /* 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 Radio TX frequency in MHz\n"); printf( " -r Radio type (SX1255:1255, SX1257:1257)\n"); printf( " -k Concentrator clock source (0: radio_A, 1: radio_B(default))\n"); + printf(" --path 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; } -- cgit v1.2.3 From 228116b1958515947d208149cccbb8c9a9a6ab83 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 15:49:47 -0600 Subject: Changed util spectral scan path parameter to match other utilities --- util_spectral_scan/src/util_spectral_scan.c | 46 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/util_spectral_scan/src/util_spectral_scan.c b/util_spectral_scan/src/util_spectral_scan.c index 91a358f..090dc22 100644 --- a/util_spectral_scan/src/util_spectral_scan.c +++ b/util_spectral_scan/src/util_spectral_scan.c @@ -31,6 +31,7 @@ Maintainer: Michael Coracin #include /* getopt */ #include #include +#include /* getopt_long */ #include "loragw_aux.h" #include "loragw_reg.h" @@ -116,19 +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:p:")) != -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 :: 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 Channel bandwidth in KHz [25,50,100,125,200,250,500]\n"); - printf(" -n Total number of RSSI points [1..65535]\n"); - printf(" -o Offset in dB to be applied to the SX127x RSSI [-128..127]\n"); - printf(" -l Log file name\n"); - printf(" -p path of SPIDEV e.g. /dev/spidev0.0\n"); - printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + printf(" -f :: 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 Channel bandwidth in KHz [25,50,100,125,200,250,500]\n"); + printf(" -n Total number of RSSI points [1..65535]\n"); + printf(" -o Offset in dB to be applied to the SX127x RSSI [-128..127]\n"); + printf(" -l Log file name\n"); + printf(" --path path of SPIDEV e.g. /dev/spidev0.0\n"); + printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); return EXIT_SUCCESS; case 'f': /* -f :: Frequency vector to scan in MHz, start:step:stop */ @@ -208,13 +216,19 @@ int main( int argc, char ** argv ) } break; - case 'p': /* -p Path for spi device */ - j = sscanf(optarg, "%s", arg_s); - if (j != 1) { - printf("ERROR: argument parsing of -p argument. -h for help.\n"); - return EXIT_FAILURE; + 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 { - lgw_spi_set_path(arg_s); + printf("ERROR: argument parsing options. Use -h to print help\n"); + return EXIT_FAILURE; } break; -- cgit v1.2.3 From dea57d6f29246434173c33c56850708c51fc5b23 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 3 Feb 2020 16:17:19 -0600 Subject: Added spi dev option to reg utility and added error checking for lgw_connect, cleaned up unused variables in src_loragw_gps.c --- libloragw/src/loragw_gps.c | 2 -- libloragw/tst/test_loragw_gps.c | 4 +-- libloragw/tst/test_loragw_hal.c | 2 +- libloragw/tst/test_loragw_reg.c | 59 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index bd728b6..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 ---------------------------------------- */ 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 3bdd7b2..37e8b42 100644 --- a/libloragw/tst/test_loragw_hal.c +++ b/libloragw/tst/test_loragw_hal.c @@ -30,7 +30,7 @@ Maintainer: Sylvain Miermont #include /* memset */ #include /* sigaction */ #include /* getopt access */ -#include /* getopt_long */ +#include /* getopt_long */ #include "loragw_spi.h" #include "loragw_hal.h" 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 #include +#include +#include /* 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 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 -- cgit v1.2.3