Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
* Fixed compilation warnings reported by latest versions of GCC
* Reworked handling of temperature sensor
* Clean-up of unused files
* Added instructions and configuration files for packet forwarder auto-start
with systemd
* Added SX1250 radio calibration at startup
  • Loading branch information
mcoracin committed Aug 29, 2019
1 parent e63d9a3 commit df5cf56
Show file tree
Hide file tree
Showing 25 changed files with 275 additions and 279 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.2
5 changes: 1 addition & 4 deletions libloragw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ inc/config.h: ../VERSION library.cfg
# Debug options
@echo " #define DEBUG_AUX $(DEBUG_AUX)" >> $@
@echo " #define DEBUG_SPI $(DEBUG_SPI)" >> $@
@echo " #define DEBUG_I2C $(DEBUG_SPI)" >> $@
@echo " #define DEBUG_I2C $(DEBUG_I2C)" >> $@
@echo " #define DEBUG_REG $(DEBUG_REG)" >> $@
@echo " #define DEBUG_HAL $(DEBUG_HAL)" >> $@
@echo " #define DEBUG_GPS $(DEBUG_GPS)" >> $@
Expand All @@ -71,9 +71,6 @@ inc/config.h: ../VERSION library.cfg
@echo " #define DEBUG_RAD $(DEBUG_RAD)" >> $@
@echo " #define DEBUG_CAL $(DEBUG_CAL)" >> $@
@echo " #define DEBUG_SX1302 $(DEBUG_SX1302)" >> $@
# Configuration options
@echo " #define BYPASS_FW_INIT $(BYPASS_FW_INIT)" >> $@
@echo " #define FPGA_BOARD_16_CH $(FPGA_BOARD_16_CH)" >> $@
# end of file
@echo "#endif" >> $@
@echo "*** Configuration seems ok ***"
Expand Down
7 changes: 7 additions & 0 deletions libloragw/inc/loragw_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@ int lgw_get_instcnt(uint32_t * inst_cnt_us);
*/
int lgw_get_eui(uint64_t * eui);

/**
@brief Return the temperature measured by the LoRa concentrator sensor
@param temperature The temperature measured, in degree celcius
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
*/
int lgw_get_temperature(float * temperature);

/**
@brief Allow user to check the version/options of the library once compiled
@return pointer on a human-readable null terminated string
Expand Down
8 changes: 4 additions & 4 deletions libloragw/inc/loragw_stts751.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* -------------------------------------------------------------------------- */
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */

#define I2C_PORT_TEMP_SENSOR_1 0x39
#define I2C_PORT_TEMP_SENSOR_2 0x3B
#define I2C_PORT_TEMP_SENSOR_0 0x39 /* STTS751-0DP3F */
#define I2C_PORT_TEMP_SENSOR_1 0x3B /* STTS751-1DP3F */

/* -------------------------------------------------------------------------- */
/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
Expand All @@ -44,14 +44,14 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
@param TODO
@return TODO
*/
int lgw_stts751_configure(void);
int stts751_configure(int i2c_fd, uint8_t i2c_addr);

/**
@brief TODO
@param TODO
@return TODO
*/
int lgw_stts751_get_temperature(float * temperature);
int stts751_get_temperature(int i2c_fd, uint8_t i2c_addr, float * temperature);

#endif

Expand Down
1 change: 1 addition & 0 deletions libloragw/inc/loragw_sx1250.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
/* --- PUBLIC TYPES --------------------------------------------------------- */

typedef enum {
CALIBRATE = 0x89,
CALIBRATE_IMAGE = 0x98,
CLR_IRQ_STATUS = 0x02,
STOP_TIMER_ON_PREAMBLE = 0x9F,
Expand Down
7 changes: 2 additions & 5 deletions libloragw/library.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@

DEBUG_AUX= 0
DEBUG_SPI= 0
DEBUG_I2C= 0
DEBUG_REG= 0
DEBUG_HAL= 0
DEBUG_LBT= 0
DEBUG_GPS= 0
DEBUG_RAD= 0
DEBUG_CAL= 0
DEBUG_SX1302= 0

### Configuration options ###
BYPASS_FW_INIT = 0
FPGA_BOARD_16_CH = 1
DEBUG_SX1302= 0
61 changes: 42 additions & 19 deletions libloragw/src/loragw_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ static lgw_context_t lgw_context = {
/* File handle to write debug logs */
FILE * log_file = NULL;

/* File descriptor to I2C linux device */
int lgw_i2c_target = -1;
/* I2C temperature sensor handles */
static int ts_fd = -1;
static uint8_t ts_addr = 0xFF;

/* -------------------------------------------------------------------------- */
/* --- PRIVATE FUNCTIONS DECLARATION ---------------------------------------- */
Expand Down Expand Up @@ -233,6 +234,7 @@ int lgw_board_setconf(struct lgw_conf_board_s * conf) {
CONTEXT_BOARD.clksrc = conf->clksrc;
CONTEXT_BOARD.full_duplex = conf->full_duplex;
strncpy(CONTEXT_SPI, conf->spidev_path, sizeof CONTEXT_SPI);
CONTEXT_SPI[sizeof CONTEXT_SPI - 1] = '\0'; /* ensure string termination */

DEBUG_PRINTF("Note: board configuration: spidev_path: %s, lorawan_public:%d, clksrc:%d, full_duplex:%d\n", CONTEXT_SPI,
CONTEXT_LWAN_PUBLIC,
Expand Down Expand Up @@ -555,7 +557,8 @@ int lgw_debug_setconf(struct lgw_conf_debug_s * conf) {
}

if (conf->log_file_name != NULL) {
strncpy(CONTEXT_DEBUG.log_file_name, conf->log_file_name, strlen(conf->log_file_name));
strncpy(CONTEXT_DEBUG.log_file_name, conf->log_file_name, sizeof CONTEXT_DEBUG.log_file_name);
CONTEXT_DEBUG.log_file_name[sizeof CONTEXT_DEBUG.log_file_name - 1] = '\0'; /* ensure string termination */
}

return LGW_HAL_SUCCESS;
Expand All @@ -564,7 +567,7 @@ int lgw_debug_setconf(struct lgw_conf_debug_s * conf) {
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

int lgw_start(void) {
int i, err, err_id_1,err_id_2;
int i, err;
int reg_stat;

if (CONTEXT_STARTED == true) {
Expand Down Expand Up @@ -713,18 +716,21 @@ int lgw_start(void) {
dbg_init_gpio();
#endif

/* Open I2C */
err_id_1 = i2c_linuxdev_open(I2C_DEVICE, I2C_PORT_TEMP_SENSOR_1, &lgw_i2c_target);
err_id_2 = i2c_linuxdev_open(I2C_DEVICE, I2C_PORT_TEMP_SENSOR_2, &lgw_i2c_target);
if (((err_id_1 != 0) || (lgw_i2c_target <= 0)) && ((err_id_2 != 0) || (lgw_i2c_target <= 0))) {
printf("ERROR: failed to open I2C device %s (err=%i)\n", I2C_DEVICE, err);
return LGW_HAL_ERROR;
}

/* Configure the CoreCell temperature sensor */
if (lgw_stts751_configure() != LGW_I2C_SUCCESS) {
printf("ERROR: failed to configure temperature sensor\n");
return LGW_HAL_ERROR;
/* Try to configure temperature sensor STTS751-0DP3F */
ts_addr = I2C_PORT_TEMP_SENSOR_0;
i2c_linuxdev_open(I2C_DEVICE, ts_addr, &ts_fd);
err = stts751_configure(ts_fd, ts_addr);
if (err != LGW_I2C_SUCCESS) {
i2c_linuxdev_close(ts_fd);
ts_fd = -1;
/* Not found, try to configure temperature sensor STTS751-1DP3F */
ts_addr = I2C_PORT_TEMP_SENSOR_1;
i2c_linuxdev_open(I2C_DEVICE, ts_addr, &ts_fd);
err = stts751_configure(ts_fd, ts_addr);
if (err != LGW_I2C_SUCCESS) {
printf("ERROR: failed to configure the temperature sensor\n");
return LGW_HAL_ERROR;
}
}

/* set hal state */
Expand Down Expand Up @@ -753,10 +759,9 @@ int lgw_stop(void) {
lgw_disconnect();

DEBUG_MSG("INFO: Closing I2C\n");
err = i2c_linuxdev_close(lgw_i2c_target);
err = i2c_linuxdev_close(ts_fd);
if (err != 0) {
printf("ERROR: failed to close I2C device (err=%i)\n", err);
/* TODO: return error or not ? */
}

CONTEXT_STARTED = false;
Expand Down Expand Up @@ -790,7 +795,7 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
}

/* Get the current temperature for further RSSI compensation : TODO */
res = lgw_stts751_get_temperature(&current_temperature);
res = stts751_get_temperature(ts_fd, ts_addr, &current_temperature);
if (res != LGW_I2C_SUCCESS) {
printf("ERROR: failed to get current temperature\n");
return LGW_HAL_ERROR;
Expand Down Expand Up @@ -944,6 +949,8 @@ int lgw_abort_tx(uint8_t rf_chain) {
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

int lgw_get_trigcnt(uint32_t* trig_cnt_us) {
CHECK_NULL(trig_cnt_us);

*trig_cnt_us = sx1302_timestamp_counter(true);

return LGW_HAL_SUCCESS;
Expand All @@ -952,6 +959,8 @@ int lgw_get_trigcnt(uint32_t* trig_cnt_us) {
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

int lgw_get_instcnt(uint32_t* inst_cnt_us) {
CHECK_NULL(inst_cnt_us);

*inst_cnt_us = sx1302_timestamp_counter(false);

return LGW_HAL_SUCCESS;
Expand All @@ -960,6 +969,8 @@ int lgw_get_instcnt(uint32_t* inst_cnt_us) {
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

int lgw_get_eui(uint64_t* eui) {
CHECK_NULL(eui);

if (sx1302_get_eui(eui) != LGW_REG_SUCCESS) {
return LGW_HAL_ERROR;
}
Expand All @@ -968,6 +979,18 @@ int lgw_get_eui(uint64_t* eui) {

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

int lgw_get_temperature(float* temperature) {
CHECK_NULL(temperature);

if (stts751_get_temperature(ts_fd, ts_addr, temperature) != LGW_I2C_SUCCESS) {
return LGW_HAL_ERROR;
}

return LGW_HAL_SUCCESS;
}

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

const char* lgw_version_info() {
return lgw_version_string;
}
Expand Down
17 changes: 9 additions & 8 deletions libloragw/src/loragw_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
#include <unistd.h> /* lseek, close */
#include <fcntl.h> /* open */
#include <string.h> /* memset */
#include <errno.h> /* errno */

#include <sys/ioctl.h>
#include <linux/i2c.h>
Expand Down Expand Up @@ -55,18 +56,18 @@ int i2c_linuxdev_open(const char *path, uint8_t device_addr, int *i2c_fd) {

/* Check input variables */
if (path == NULL) {
DEBUG_MSG("ERROR: null pointer path");
DEBUG_MSG("ERROR: null pointer path\n");
return LGW_I2C_ERROR;
}
if (i2c_fd == NULL) {
DEBUG_MSG("ERROR: null pointer i2c_fd");
DEBUG_MSG("ERROR: null pointer i2c_fd\n");
return LGW_I2C_ERROR;
}

/* Open I2C device */
dev = open(path, O_RDWR);
if (dev < 0) {
DEBUG_PRINTF("ERROR: Failed to open I2C %s - %s", path, strerror(errno));
DEBUG_PRINTF("ERROR: Failed to open I2C %s - %s\n", path, strerror(errno));
return LGW_I2C_ERROR;
}

Expand All @@ -76,7 +77,7 @@ int i2c_linuxdev_open(const char *path, uint8_t device_addr, int *i2c_fd) {
return LGW_I2C_ERROR;
}

DEBUG_MSG("INFO: I2C port opened successfully");
DEBUG_PRINTF("INFO: I2C port opened successfully (%s, 0x%02X)\n", path, device_addr);
*i2c_fd = dev; /* return file descriptor index */

return LGW_I2C_SUCCESS;
Expand Down Expand Up @@ -105,7 +106,7 @@ int i2c_linuxdev_read(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_t
packets.nmsgs = 2;

if (ioctl(i2c_fd, I2C_RDWR, &packets) < 0) {
DEBUG_PRINTF("ERROR: Read from I2C Device failed (%d, 0x%02x, 0x%02x) - %s", i2c_fd, device_addr, reg_addr, strerror(errno));
DEBUG_PRINTF("ERROR: Read from I2C Device failed (%d, 0x%02x, 0x%02x) - %s\n", i2c_fd, device_addr, reg_addr, strerror(errno));
return LGW_I2C_ERROR;
}

Expand All @@ -131,7 +132,7 @@ int i2c_linuxdev_write(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_
packets.nmsgs = 1;

if (ioctl(i2c_fd, I2C_RDWR, &packets) < 0) {
DEBUG_PRINTF("ERROR: Write to I2C Device failed (%d, 0x%02x, 0x%02x) - %s", i2c_fd, device_addr, reg_addr, strerror(errno));
DEBUG_PRINTF("ERROR: Write to I2C Device failed (%d, 0x%02x, 0x%02x) - %s\n", i2c_fd, device_addr, reg_addr, strerror(errno));
return LGW_I2C_ERROR;
}

Expand All @@ -145,10 +146,10 @@ int i2c_linuxdev_close(int i2c_fd) {

i = close(i2c_fd);
if (i == 0) {
DEBUG_MSG("INFO: I2C port closed successfully");
DEBUG_MSG("INFO: I2C port closed successfully\n");
return LGW_I2C_SUCCESS;
} else {
DEBUG_PRINTF("ERROR: Failed to close I2C - %s", strerror(errno));
DEBUG_PRINTF("ERROR: Failed to close I2C - %s\n", strerror(errno));
return LGW_I2C_ERROR;
}
}
Expand Down
Loading

0 comments on commit df5cf56

Please sign in to comment.