Skip to content

Commit df5cf56

Browse files
committed
v1.0.2
* 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
1 parent e63d9a3 commit df5cf56

25 files changed

+275
-279
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
1.0.2

libloragw/Makefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ inc/config.h: ../VERSION library.cfg
6262
# Debug options
6363
@echo " #define DEBUG_AUX $(DEBUG_AUX)" >> $@
6464
@echo " #define DEBUG_SPI $(DEBUG_SPI)" >> $@
65-
@echo " #define DEBUG_I2C $(DEBUG_SPI)" >> $@
65+
@echo " #define DEBUG_I2C $(DEBUG_I2C)" >> $@
6666
@echo " #define DEBUG_REG $(DEBUG_REG)" >> $@
6767
@echo " #define DEBUG_HAL $(DEBUG_HAL)" >> $@
6868
@echo " #define DEBUG_GPS $(DEBUG_GPS)" >> $@
@@ -71,9 +71,6 @@ inc/config.h: ../VERSION library.cfg
7171
@echo " #define DEBUG_RAD $(DEBUG_RAD)" >> $@
7272
@echo " #define DEBUG_CAL $(DEBUG_CAL)" >> $@
7373
@echo " #define DEBUG_SX1302 $(DEBUG_SX1302)" >> $@
74-
# Configuration options
75-
@echo " #define BYPASS_FW_INIT $(BYPASS_FW_INIT)" >> $@
76-
@echo " #define FPGA_BOARD_16_CH $(FPGA_BOARD_16_CH)" >> $@
7774
# end of file
7875
@echo "#endif" >> $@
7976
@echo "*** Configuration seems ok ***"

libloragw/inc/loragw_hal.h

+7
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ int lgw_get_instcnt(uint32_t * inst_cnt_us);
445445
*/
446446
int lgw_get_eui(uint64_t * eui);
447447

448+
/**
449+
@brief Return the temperature measured by the LoRa concentrator sensor
450+
@param temperature The temperature measured, in degree celcius
451+
@return LGW_HAL_ERROR id the operation failed, LGW_HAL_SUCCESS else
452+
*/
453+
int lgw_get_temperature(float * temperature);
454+
448455
/**
449456
@brief Allow user to check the version/options of the library once compiled
450457
@return pointer on a human-readable null terminated string

libloragw/inc/loragw_stts751.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
3333
/* -------------------------------------------------------------------------- */
3434
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
3535

36-
#define I2C_PORT_TEMP_SENSOR_1 0x39
37-
#define I2C_PORT_TEMP_SENSOR_2 0x3B
36+
#define I2C_PORT_TEMP_SENSOR_0 0x39 /* STTS751-0DP3F */
37+
#define I2C_PORT_TEMP_SENSOR_1 0x3B /* STTS751-1DP3F */
3838

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

4949
/**
5050
@brief TODO
5151
@param TODO
5252
@return TODO
5353
*/
54-
int lgw_stts751_get_temperature(float * temperature);
54+
int stts751_get_temperature(int i2c_fd, uint8_t i2c_addr, float * temperature);
5555

5656
#endif
5757

libloragw/inc/loragw_sx1250.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
3535
/* --- PUBLIC TYPES --------------------------------------------------------- */
3636

3737
typedef enum {
38+
CALIBRATE = 0x89,
3839
CALIBRATE_IMAGE = 0x98,
3940
CLR_IRQ_STATUS = 0x02,
4041
STOP_TIMER_ON_PREAMBLE = 0x9F,

libloragw/library.cfg

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
DEBUG_AUX= 0
88
DEBUG_SPI= 0
9+
DEBUG_I2C= 0
910
DEBUG_REG= 0
1011
DEBUG_HAL= 0
1112
DEBUG_LBT= 0
1213
DEBUG_GPS= 0
1314
DEBUG_RAD= 0
1415
DEBUG_CAL= 0
15-
DEBUG_SX1302= 0
16-
17-
### Configuration options ###
18-
BYPASS_FW_INIT = 0
19-
FPGA_BOARD_16_CH = 1
16+
DEBUG_SX1302= 0

libloragw/src/loragw_hal.c

+42-19
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ static lgw_context_t lgw_context = {
179179
/* File handle to write debug logs */
180180
FILE * log_file = NULL;
181181

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

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

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

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

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

566569
int lgw_start(void) {
567-
int i, err, err_id_1,err_id_2;
570+
int i, err;
568571
int reg_stat;
569572

570573
if (CONTEXT_STARTED == true) {
@@ -713,18 +716,21 @@ int lgw_start(void) {
713716
dbg_init_gpio();
714717
#endif
715718

716-
/* Open I2C */
717-
err_id_1 = i2c_linuxdev_open(I2C_DEVICE, I2C_PORT_TEMP_SENSOR_1, &lgw_i2c_target);
718-
err_id_2 = i2c_linuxdev_open(I2C_DEVICE, I2C_PORT_TEMP_SENSOR_2, &lgw_i2c_target);
719-
if (((err_id_1 != 0) || (lgw_i2c_target <= 0)) && ((err_id_2 != 0) || (lgw_i2c_target <= 0))) {
720-
printf("ERROR: failed to open I2C device %s (err=%i)\n", I2C_DEVICE, err);
721-
return LGW_HAL_ERROR;
722-
}
723-
724-
/* Configure the CoreCell temperature sensor */
725-
if (lgw_stts751_configure() != LGW_I2C_SUCCESS) {
726-
printf("ERROR: failed to configure temperature sensor\n");
727-
return LGW_HAL_ERROR;
719+
/* Try to configure temperature sensor STTS751-0DP3F */
720+
ts_addr = I2C_PORT_TEMP_SENSOR_0;
721+
i2c_linuxdev_open(I2C_DEVICE, ts_addr, &ts_fd);
722+
err = stts751_configure(ts_fd, ts_addr);
723+
if (err != LGW_I2C_SUCCESS) {
724+
i2c_linuxdev_close(ts_fd);
725+
ts_fd = -1;
726+
/* Not found, try to configure temperature sensor STTS751-1DP3F */
727+
ts_addr = I2C_PORT_TEMP_SENSOR_1;
728+
i2c_linuxdev_open(I2C_DEVICE, ts_addr, &ts_fd);
729+
err = stts751_configure(ts_fd, ts_addr);
730+
if (err != LGW_I2C_SUCCESS) {
731+
printf("ERROR: failed to configure the temperature sensor\n");
732+
return LGW_HAL_ERROR;
733+
}
728734
}
729735

730736
/* set hal state */
@@ -753,10 +759,9 @@ int lgw_stop(void) {
753759
lgw_disconnect();
754760

755761
DEBUG_MSG("INFO: Closing I2C\n");
756-
err = i2c_linuxdev_close(lgw_i2c_target);
762+
err = i2c_linuxdev_close(ts_fd);
757763
if (err != 0) {
758764
printf("ERROR: failed to close I2C device (err=%i)\n", err);
759-
/* TODO: return error or not ? */
760765
}
761766

762767
CONTEXT_STARTED = false;
@@ -790,7 +795,7 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
790795
}
791796

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

946951
int lgw_get_trigcnt(uint32_t* trig_cnt_us) {
952+
CHECK_NULL(trig_cnt_us);
953+
947954
*trig_cnt_us = sx1302_timestamp_counter(true);
948955

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

954961
int lgw_get_instcnt(uint32_t* inst_cnt_us) {
962+
CHECK_NULL(inst_cnt_us);
963+
955964
*inst_cnt_us = sx1302_timestamp_counter(false);
956965

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

962971
int lgw_get_eui(uint64_t* eui) {
972+
CHECK_NULL(eui);
973+
963974
if (sx1302_get_eui(eui) != LGW_REG_SUCCESS) {
964975
return LGW_HAL_ERROR;
965976
}
@@ -968,6 +979,18 @@ int lgw_get_eui(uint64_t* eui) {
968979

969980
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
970981

982+
int lgw_get_temperature(float* temperature) {
983+
CHECK_NULL(temperature);
984+
985+
if (stts751_get_temperature(ts_fd, ts_addr, temperature) != LGW_I2C_SUCCESS) {
986+
return LGW_HAL_ERROR;
987+
}
988+
989+
return LGW_HAL_SUCCESS;
990+
}
991+
992+
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
993+
971994
const char* lgw_version_info() {
972995
return lgw_version_string;
973996
}

libloragw/src/loragw_i2c.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
2222
#include <unistd.h> /* lseek, close */
2323
#include <fcntl.h> /* open */
2424
#include <string.h> /* memset */
25+
#include <errno.h> /* errno */
2526

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

5657
/* Check input variables */
5758
if (path == NULL) {
58-
DEBUG_MSG("ERROR: null pointer path");
59+
DEBUG_MSG("ERROR: null pointer path\n");
5960
return LGW_I2C_ERROR;
6061
}
6162
if (i2c_fd == NULL) {
62-
DEBUG_MSG("ERROR: null pointer i2c_fd");
63+
DEBUG_MSG("ERROR: null pointer i2c_fd\n");
6364
return LGW_I2C_ERROR;
6465
}
6566

6667
/* Open I2C device */
6768
dev = open(path, O_RDWR);
6869
if (dev < 0) {
69-
DEBUG_PRINTF("ERROR: Failed to open I2C %s - %s", path, strerror(errno));
70+
DEBUG_PRINTF("ERROR: Failed to open I2C %s - %s\n", path, strerror(errno));
7071
return LGW_I2C_ERROR;
7172
}
7273

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

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

8283
return LGW_I2C_SUCCESS;
@@ -105,7 +106,7 @@ int i2c_linuxdev_read(int i2c_fd, uint8_t device_addr, uint8_t reg_addr, uint8_t
105106
packets.nmsgs = 2;
106107

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

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

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

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

146147
i = close(i2c_fd);
147148
if (i == 0) {
148-
DEBUG_MSG("INFO: I2C port closed successfully");
149+
DEBUG_MSG("INFO: I2C port closed successfully\n");
149150
return LGW_I2C_SUCCESS;
150151
} else {
151-
DEBUG_PRINTF("ERROR: Failed to close I2C - %s", strerror(errno));
152+
DEBUG_PRINTF("ERROR: Failed to close I2C - %s\n", strerror(errno));
152153
return LGW_I2C_ERROR;
153154
}
154155
}

0 commit comments

Comments
 (0)