Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
- bugfix: fixed some range checks that did not prevent segfaults
- test: removed systematic register dump in test_loragw_hal.c
- modified Makefiles for easier cross-compilation
- added root README and removed TXT extension of other READMEs
  • Loading branch information
Sylvain Miermont committed Dec 12, 2013
1 parent 0d3fcab commit b665027
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 80 deletions.
54 changes: 54 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
�2013 Semtech-Cycleo

Lora Gateway HAL project
=========================

1. Core library: libloragw
---------------------------

This directory contains the sources of the library to build a gateway based on
a Semtech Lora multi-channel RF receiver.
Once compiled all the code is contained in the libloragw.a file that will be
statically linked (ie. integrated in the final executable).

The library also comes with a bunch of basic tests programs that are used to
test the different sub-modules of the library.

2. Helper programs
-------------------

Those programs are included in the project to provide examples on how to use
the HAL library, and to help the system builder test different parts of it.

### 2.1. loragw_band_survey ###

This software is used to scan the RF band and measure background RSSI and some
measurement of interferer pattern.

### 2.2. loragw_pkt_logger ###

This software is used to set up a Lora concentrator using a JSON configuration
file and then record all the packets received in a log file, indefinitely, until
the user stops the application.

### 2.3. loragw_spi_stress ###

This software is used to check the reliability of the link between the host
platform (on which the program is run) and the Lora concentrator register file
that is the interface through which all interaction with the Lora concentrator
happens.

### 2.4. loragw_tx_test ###

This software is used to send test packets with a Lora concentrator. The packets
contain little information, on no protocol (ie. MAC address) information but
can be used to assess the functionality of a gateway downlink using other
gateways as receivers.


*EOF*
19 changes: 10 additions & 9 deletions libloragw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
include library.cfg

# constant symbols
CROSS_COMPILE=
CC=gcc
CFLAGS=-O2 -Wall -Wextra -Iinc -I.
C99FLAGS=-O2 -Wall -Wextra -std=c99 -Iinc -I.
Expand Down Expand Up @@ -43,35 +44,35 @@ endif
# static library

libloragw.a: obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
ar rcs libloragw.a obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
$(CROSS_COMPILE)ar rcs libloragw.a obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o

# library module target

obj/loragw_aux.o: .conf_ok src/loragw_aux.c inc/loragw_aux.h
$(CC) -c $(CFLAGS) src/loragw_aux.c -o obj/loragw_aux.o $(FLAG_AUX)
$(CROSS_COMPILE)$(CC) -c $(CFLAGS) src/loragw_aux.c -o obj/loragw_aux.o $(FLAG_AUX)

obj/loragw_spi.o: .conf_ok src/loragw_spi.native.c src/loragw_spi.ftdi.c inc/loragw_spi.h
ifeq ($(LGW_PHY),native)
$(CC) -c $(C99FLAGS) src/loragw_spi.native.c -o obj/loragw_spi.o $(FLAG_SPI)
$(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_spi.native.c -o obj/loragw_spi.o $(FLAG_SPI)
endif
ifeq ($(LGW_PHY),ftdi)
$(CC) -c $(C99FLAGS) src/loragw_spi.ftdi.c -o obj/loragw_spi.o $(FLAG_SPI)
$(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_spi.ftdi.c -o obj/loragw_spi.o $(FLAG_SPI)
endif

obj/loragw_reg.o: .conf_ok src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h
$(CC) -c $(C99FLAGS) src/loragw_reg.c -o obj/loragw_reg.o $(FLAG_REG)
$(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_reg.c -o obj/loragw_reg.o $(FLAG_REG)

obj/loragw_hal.o: .conf_ok VERSION src/loragw_hal.c src/arb_fw.var src/agc_fw.var inc/loragw_hal.h inc/loragw_reg.h inc/loragw_spi.h inc/loragw_aux.h
$(CC) -c $(C99FLAGS) src/loragw_hal.c -o obj/loragw_hal.o -D LGW_PHY="\"$(LGW_PHY)\"" $(FLAG_HAL)
$(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_hal.c -o obj/loragw_hal.o -D LGW_PHY="\"$(LGW_PHY)\"" $(FLAG_HAL)

# test programs

test_loragw_spi: tst/test_loragw_spi.c obj/loragw_spi.o
$(CC) $(C99FLAGS) tst/test_loragw_spi.c obj/loragw_spi.o -o test_loragw_spi $(LDFLAGS)
$(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_spi.c obj/loragw_spi.o -o test_loragw_spi $(LDFLAGS)

test_loragw_reg: tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o
$(CC) $(C99FLAGS) tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o -o test_loragw_reg $(LDFLAGS)
$(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o -o test_loragw_reg $(LDFLAGS)

test_loragw_hal: tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
$(CC) $(C99FLAGS) tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o -o test_loragw_hal $(LDFLAGS)
$(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o -o test_loragw_hal $(LDFLAGS)

55 changes: 55 additions & 0 deletions libloragw/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Lora Gateway HAL library
=========================

1. Content of subdirectories
-----------------------------

### 1.1. doc ###

Contains the user manual, licensing informations, udev rules, etc.

### 1.2. inc ###

Contain C header files for the different sub-modules of the library.

You *MUST* include loragw_hal.h in your application.
You *MAY* include loragw_reg.h in your application if you need direct registers
access.

### 1.3. obj ###

Contained the compiled intermediary objects.

### 1.4. src ###

Contain library C sources.

### 1.5. tst ###

Contain the C sources for test programs to validate SPI link, register access
and hardware functionality.

2. Legal notice
----------------

The information presented in this project documentation does not form part of
any quotation or contract, is believed to be accurate and reliable and may be
changed without notice. No liability will be accepted by the publisher for any
consequence of its use. Publication thereof does not convey nor imply any
license under patent or other industrial or intellectual property rights.
Semtech assumes no responsibility or liability whatsoever for any failure or
unexpected operation resulting from misuse, neglect improper installation,
repair or improper handling or unusual physical or electrical stress
including, but not limited to, exposure to parameters beyond the specified
maximum ratings or operation outside the specified range.

SEMTECH PRODUCTS ARE NOT DESIGNED, INTENDED, AUTHORIZED OR WARRANTED TO BE
SUITABLE FOR USE IN LIFE-SUPPORT APPLICATIONS, DEVICES OR SYSTEMS OR OTHER
CRITICAL APPLICATIONS. INCLUSION OF SEMTECH PRODUCTS IN SUCH APPLICATIONS IS
UNDERSTOOD TO BE UNDERTAKEN SOLELY AT THE CUSTOMER�S OWN RISK. Should a
customer purchase or use Semtech products for any such unauthorized
application, the customer shall indemnify and hold Semtech and its officers,
employees, subsidiaries, affiliates, and distributors harmless against all
claims, costs damages and attorney fees which could arise.

*EOF*
30 changes: 0 additions & 30 deletions libloragw/README.TXT

This file was deleted.

16 changes: 8 additions & 8 deletions libloragw/doc/MANUAL.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ started

A typical application flow for using the HAL is the following:

<configure the radios and IF+modems>
<start the Lora gateway>
loop {
<fetch packets that were received by the gateway>
<process, store and/or forward received packets>
<send packets through the gateway>
}
<stop the gateway>
<configure the radios and IF+modems>
<start the Lora gateway>
loop {
<fetch packets that were received by the gateway>
<process, store and/or forward received packets>
<send packets through the gateway>
}
<stop the gateway>

**/!\ Warning** The lgw_send function is non-blocking and returns while the
Lora gateway is still sending the packet, or even before the packet has started
Expand Down
20 changes: 13 additions & 7 deletions libloragw/src/loragw_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,13 @@ int lgw_rxrf_setconf(uint8_t rf_chain, struct lgw_conf_rxrf_s conf) {
return LGW_HAL_ERROR;
}

/* check input parameters */
if (rf_chain > LGW_RF_CHAIN_NB) {
/* check input range (segfault prevention) */
if (rf_chain >= LGW_RF_CHAIN_NB) {
DEBUG_MSG("ERROR: NOT A VALID RF_CHAIN NUMBER\n");
return LGW_HAL_ERROR;
}

/* check input parameters */
if (conf.freq_hz > rf_rx_upfreq[rf_chain]) {
DEBUG_MSG("ERROR: FREQUENCY TOO HIGH FOR THAT RF_CHAIN\n");
return LGW_HAL_ERROR;
Expand All @@ -483,6 +485,12 @@ int lgw_rxif_setconf(uint8_t if_chain, struct lgw_conf_rxif_s conf) {
return LGW_HAL_ERROR;
}

/* check input range (segfault prevention) */
if (if_chain >= LGW_IF_CHAIN_NB) {
DEBUG_PRINTF("ERROR: %d NOT A VALID IF_CHAIN NUMBER\n", if_chain);
return LGW_HAL_ERROR;
}

/* if chain is disabled, don't care about most parameters */
if (conf.enable == false) {
if_enable[if_chain] = false;
Expand All @@ -492,10 +500,6 @@ int lgw_rxif_setconf(uint8_t if_chain, struct lgw_conf_rxif_s conf) {
}

/* check 'general' parameters */
if (if_chain > LGW_IF_CHAIN_NB) {
DEBUG_PRINTF("ERROR: %d NOT A VALID IF_CHAIN NUMBER\n", if_chain);
return LGW_HAL_ERROR;
}
if (ifmod_config[if_chain] == IF_UNDEFINED) {
DEBUG_PRINTF("ERROR: IF CHAIN %d NOT CONFIGURABLE\n", if_chain);
}
Expand Down Expand Up @@ -954,11 +958,13 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) {
return LGW_HAL_ERROR;
}

/* check input variables */
/* check input range (segfault prevention) */
if (pkt_data.rf_chain >= LGW_RF_CHAIN_NB) {
DEBUG_MSG("ERROR: INVALID RF_CHAIN TO SEND PACKETS\n");
return LGW_HAL_ERROR;
}

/* check input variables */
if (rf_enable[pkt_data.rf_chain] == false) {
DEBUG_MSG("ERROR: SELECTED RF_CHAIN IS DISABLED\n");
return LGW_HAL_ERROR;
Expand Down
21 changes: 13 additions & 8 deletions libloragw/tst/test_loragw_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ int main()
unsigned long loop_cnt = 0;
uint8_t status_var = 0;

FILE * reg_dump = NULL;

/* configure signal handling */
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
Expand Down Expand Up @@ -180,14 +178,21 @@ int main()
printf("*** Library version information ***\n%s\n***\n", lgw_version_info());

/* connect, configure and start the Lora gateway */
lgw_start();
i = lgw_start();
if (i == LGW_HAL_SUCCESS) {
printf("*** Concentrator started ***\n");
} else {
printf("*** Impossible to start concentrator ***\n");
return -1;
}

/* once configured, dump content of registers to a file, for reference */
reg_dump = fopen("reg_dump.log", "w");
if (reg_dump != NULL) {
lgw_reg_check(reg_dump);
fclose(reg_dump);
}
// FILE * reg_dump = NULL;
// reg_dump = fopen("reg_dump.log", "w");
// if (reg_dump != NULL) {
// lgw_reg_check(reg_dump);
// fclose(reg_dump);
// }

while ((quit_sig != 1) && (exit_sig != 1)) {
loop_cnt++;
Expand Down
6 changes: 3 additions & 3 deletions loragw_band_survey/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
APP_NAME=loragw_band_survey

### constant symbols

CROSS_COMPILE=
CC=gcc
CFLAGS=-O2 -Wall -Wextra -Iinc
C99FLAGS=-O2 -Wall -Wextra -std=c99 -Iinc
Expand Down Expand Up @@ -31,7 +31,7 @@ clean:
### main program compilation and assembly

obj/$(APP_NAME).o: src/$(APP_NAME).c src/rssi_fw.var
$(CC) -c $(C99FLAGS) -o obj/$(APP_NAME).o $(LGW_INC) src/$(APP_NAME).c $(FLAG_AUX)
$(CROSS_COMPILE)$(CC) -c $(C99FLAGS) -o obj/$(APP_NAME).o $(LGW_INC) src/$(APP_NAME).c $(FLAG_AUX)

$(APP_NAME): $(LGW_PATH)/libloragw.a obj/$(APP_NAME).o
$(CC) -o $(APP_NAME) obj/$(APP_NAME).o -L$(LGW_PATH) $(LGW_LNK)
$(CROSS_COMPILE)$(CC) -o $(APP_NAME) obj/$(APP_NAME).o -L$(LGW_PATH) $(LGW_LNK)
File renamed without changes.
8 changes: 4 additions & 4 deletions loragw_pkt_logger/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
APP_NAME=loragw_pkt_logger

### constant symbols

CROSS_COMPILE=
CC=gcc
CFLAGS=-O2 -Wall -Wextra -Iinc
C99FLAGS=-O2 -Wall -Wextra -std=c99 -Iinc
Expand All @@ -29,12 +29,12 @@ clean:
### sub-modules compilation

obj/parson.o: src/parson.c
$(CC) -c $(C99FLAGS) -o obj/parson.o $(LGW_INC) src/parson.c $(FLAG_AUX)
$(CROSS_COMPILE)$(CC) -c $(C99FLAGS) -o obj/parson.o $(LGW_INC) src/parson.c $(FLAG_AUX)

### main program compilation and assembly

obj/$(APP_NAME).o: src/$(APP_NAME).c
$(CC) -c $(C99FLAGS) -o obj/$(APP_NAME).o $(LGW_INC) src/$(APP_NAME).c $(FLAG_AUX)
$(CROSS_COMPILE)$(CC) -c $(C99FLAGS) -o obj/$(APP_NAME).o $(LGW_INC) src/$(APP_NAME).c $(FLAG_AUX)

$(APP_NAME): $(LGW_PATH)/libloragw.a obj/$(APP_NAME).o obj/parson.o
$(CC) -o $(APP_NAME) obj/$(APP_NAME).o obj/parson.o -L$(LGW_PATH) $(LGW_LNK)
$(CROSS_COMPILE)$(CC) -o $(APP_NAME) obj/$(APP_NAME).o obj/parson.o -L$(LGW_PATH) $(LGW_LNK)
File renamed without changes.
6 changes: 3 additions & 3 deletions loragw_spi_stress/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
APP_NAME=loragw_spi_stress

### constant symbols

CROSS_COMPILE=
CC=gcc
CFLAGS=-O2 -Wall -Wextra -Iinc
C99FLAGS=-O2 -Wall -Wextra -std=c99 -Iinc
Expand All @@ -29,7 +29,7 @@ clean:
### main program compilation and assembly

obj/$(APP_NAME).o: src/$(APP_NAME).c
$(CC) -c $(C99FLAGS) -o obj/$(APP_NAME).o $(LGW_INC) src/$(APP_NAME).c $(FLAG_AUX)
$(CROSS_COMPILE)$(CC) -c $(C99FLAGS) -o obj/$(APP_NAME).o $(LGW_INC) src/$(APP_NAME).c $(FLAG_AUX)

$(APP_NAME): $(LGW_PATH)/libloragw.a obj/$(APP_NAME).o
$(CC) -o $(APP_NAME) obj/$(APP_NAME).o -L$(LGW_PATH) $(LGW_LNK)
$(CROSS_COMPILE)$(CC) -o $(APP_NAME) obj/$(APP_NAME).o -L$(LGW_PATH) $(LGW_LNK)
Loading

0 comments on commit b665027

Please sign in to comment.