summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-01-02 13:41:52 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-01-02 13:41:52 -0600
commit583ef0e2aa87d5e0c7ca71b3a681c801ff7b952a (patch)
tree3b9931117bf9eca8a24a730a2d0d99e8a5462cd8
parentf870877782ba8a279580f2df0ab7c244a4849ab0 (diff)
downloadlora_gateway_mtac_full-583ef0e2aa87d5e0c7ca71b3a681c801ff7b952a.tar.gz
lora_gateway_mtac_full-583ef0e2aa87d5e0c7ca71b3a681c801ff7b952a.tar.bz2
lora_gateway_mtac_full-583ef0e2aa87d5e0c7ca71b3a681c801ff7b952a.zip
Added spi path as a command line option for util_tx_continuous and test_loragw_spi
-rw-r--r--libloragw/src/loragw_spi.native.c2
-rw-r--r--libloragw/tst/test_loragw_spi.c118
-rw-r--r--util_tx_continuous/src/util_tx_continuous.c15
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 <stdint.h>
#include <stdio.h>
+#include <getopt.h> /* 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 <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_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 <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, 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;
@@ -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;