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
This commit is contained in:
parent
e63d9a345b
commit
df5cf56b74
|
@ -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)" >> $@
|
||||
|
@ -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 ***"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ----------------------------------------------------- */
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
|
@ -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 ---------------------------------------- */
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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(¤t_temperature);
|
||||
res = stts751_get_temperature(ts_fd, ts_addr, ¤t_temperature);
|
||||
if (res != LGW_I2C_SUCCESS) {
|
||||
printf("ERROR: failed to get current temperature\n");
|
||||
return LGW_HAL_ERROR;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,49 +74,31 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
|
|||
/* -------------------------------------------------------------------------- */
|
||||
/* --- INTERNAL SHARED VARIABLES -------------------------------------------- */
|
||||
|
||||
extern int lgw_i2c_target;
|
||||
uint8_t slave_addr;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* --- PRIVATE FUNCTIONS ---------------------------------------------------- */
|
||||
|
||||
int stts751_configure( int i2c_fd )
|
||||
{
|
||||
int err,err_1,err_2;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */
|
||||
|
||||
int stts751_configure(int i2c_fd, uint8_t i2c_addr) {
|
||||
int err;
|
||||
uint8_t val;
|
||||
|
||||
/* Check Input Params */
|
||||
if( i2c_fd <= 0 )
|
||||
{
|
||||
printf( "ERROR: invalid I2C file descriptor\n" );
|
||||
if (i2c_fd <= 0) {
|
||||
printf("ERROR: invalid I2C file descriptor\n");
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
|
||||
DEBUG_MSG("INFO: configuring STTS751 temperature sensor...\n");
|
||||
DEBUG_PRINTF("INFO: configuring STTS751 temperature sensor on 0x%02X...\n", i2c_addr);
|
||||
|
||||
/* Get product ID and test which sensor is mounted */
|
||||
err_1 = i2c_linuxdev_read( i2c_fd, I2C_PORT_TEMP_SENSOR_1, STTS751_REG_PROD_ID, &val );
|
||||
err_2 = i2c_linuxdev_read( i2c_fd, I2C_PORT_TEMP_SENSOR_2, STTS751_REG_PROD_ID, &val );
|
||||
|
||||
if ( (err_1 != 0) && (err_2 != 0) )
|
||||
{
|
||||
printf( "ERROR: failed to read I2C device 0x%02X (err=%i) or 0x%02X (err=%i) \n", I2C_PORT_TEMP_SENSOR_1, err_1, I2C_PORT_TEMP_SENSOR_2, err_2 );
|
||||
err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_PROD_ID, &val);
|
||||
if (err != 0) {
|
||||
DEBUG_PRINTF("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err);
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( err_1 == 0 )
|
||||
{
|
||||
slave_addr = I2C_PORT_TEMP_SENSOR_1;
|
||||
}
|
||||
if( err_2 == 0 )
|
||||
{
|
||||
slave_addr = I2C_PORT_TEMP_SENSOR_2;
|
||||
}
|
||||
}
|
||||
|
||||
switch( val )
|
||||
{
|
||||
switch (val) {
|
||||
case STTS751_0_PROD_ID:
|
||||
DEBUG_MSG("INFO: Product ID: STTS751-0\n");
|
||||
break;
|
||||
|
@ -129,44 +111,37 @@ int stts751_configure( int i2c_fd )
|
|||
}
|
||||
|
||||
/* Get Manufacturer ID */
|
||||
err = i2c_linuxdev_read( i2c_fd, slave_addr, STTS751_REG_MAN_ID, &val );
|
||||
if ( err != 0 )
|
||||
{
|
||||
printf( "ERROR: failed to read I2C device 0x%02X (err=%i)\n", slave_addr, err );
|
||||
err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_MAN_ID, &val);
|
||||
if (err != 0) {
|
||||
DEBUG_PRINTF("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err);
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
if ( val != ST_MAN_ID )
|
||||
{
|
||||
printf( "ERROR: Manufacturer ID: UNKNOWN\n" );
|
||||
if (val != ST_MAN_ID) {
|
||||
printf("ERROR: Manufacturer ID: UNKNOWN\n");
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEBUG_PRINTF("INFO: Manufacturer ID: 0x%02X\n", val);
|
||||
}
|
||||
|
||||
/* Get revision number */
|
||||
err = i2c_linuxdev_read( i2c_fd, slave_addr, STTS751_REG_REV_ID, &val );
|
||||
if ( err != 0 )
|
||||
{
|
||||
printf( "ERROR: failed to read I2C device 0x%02X (err=%i)\n", slave_addr, err );
|
||||
err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_REV_ID, &val);
|
||||
if (err != 0) {
|
||||
DEBUG_PRINTF("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err);
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
DEBUG_PRINTF("INFO: Revision number: 0x%02X\n", val);
|
||||
|
||||
/* Set conversion resolution to 12 bits */
|
||||
err = i2c_linuxdev_write( i2c_fd, slave_addr, STTS751_REG_CONF, 0x8C ); /* TODO: do not hardcode the whole byte */
|
||||
if ( err != 0 )
|
||||
{
|
||||
printf( "ERROR: failed to write I2C device 0x%02X (err=%i)\n", slave_addr, err );
|
||||
err = i2c_linuxdev_write(i2c_fd, i2c_addr, STTS751_REG_CONF, 0x8C); /* TODO: do not hardcode the whole byte */
|
||||
if (err != 0) {
|
||||
DEBUG_PRINTF("ERROR: failed to write I2C device 0x%02X (err=%i)\n", i2c_addr, err);
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
|
||||
/* Set conversion rate to 1 / second */
|
||||
err = i2c_linuxdev_write( i2c_fd, slave_addr, STTS751_REG_RATE, 0x04 );
|
||||
if ( err != 0 )
|
||||
{
|
||||
printf( "ERROR: failed to write I2C device 0x%02X (err=%i)\n", slave_addr, err );
|
||||
err = i2c_linuxdev_write(i2c_fd, i2c_addr, STTS751_REG_RATE, 0x04);
|
||||
if (err != 0) {
|
||||
DEBUG_PRINTF("ERROR: failed to write I2C device 0x%02X (err=%i)\n", i2c_addr, err);
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
|
||||
|
@ -175,54 +150,37 @@ int stts751_configure( int i2c_fd )
|
|||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
int stts751_get_temperature( int i2c_fd, float * temperature)
|
||||
{
|
||||
int stts751_get_temperature(int i2c_fd, uint8_t i2c_addr, float * temperature) {
|
||||
int err;
|
||||
uint8_t high_byte, low_byte;
|
||||
int8_t h;
|
||||
|
||||
/* Check Input Params */
|
||||
if( i2c_fd <= 0 )
|
||||
{
|
||||
printf( "ERROR: invalid I2C file descriptor\n" );
|
||||
if (i2c_fd <= 0) {
|
||||
printf("ERROR: invalid I2C file descriptor\n");
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
|
||||
/* Read Temperature LSB */
|
||||
err = i2c_linuxdev_read( i2c_fd, slave_addr, STTS751_REG_TEMP_L, &low_byte );
|
||||
if ( err != 0 )
|
||||
{
|
||||
printf( "ERROR: failed to read I2C device 0x%02X (err=%i)\n", slave_addr, err );
|
||||
err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_TEMP_L, &low_byte);
|
||||
if (err != 0) {
|
||||
printf("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err);
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
|
||||
/* Read Temperature MSB */
|
||||
err = i2c_linuxdev_read( i2c_fd, slave_addr, STTS751_REG_TEMP_H, &high_byte );
|
||||
if ( err != 0 )
|
||||
{
|
||||
printf( "ERROR: failed to read I2C device 0x%02X (err=%i)\n", slave_addr, err );
|
||||
err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_TEMP_H, &high_byte);
|
||||
if (err != 0) {
|
||||
printf("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err);
|
||||
return LGW_I2C_ERROR;
|
||||
}
|
||||
|
||||
h = (int8_t)high_byte;
|
||||
*temperature = ((h << 8) | low_byte) / 256.0;
|
||||
*temperature = ((h << 8) | low_byte) / 256.0;
|
||||
|
||||
DEBUG_PRINTF("Temperature: %f C (h:0x%02X l:0x%02X)\n", *temperature, high_byte, low_byte);
|
||||
|
||||
return LGW_I2C_SUCCESS;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */
|
||||
|
||||
int lgw_stts751_configure(void) {
|
||||
return stts751_configure(lgw_i2c_target);
|
||||
}
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
int lgw_stts751_get_temperature(float * temperature) {
|
||||
return stts751_get_temperature(lgw_i2c_target, temperature);
|
||||
}
|
||||
|
||||
/* --- EOF ------------------------------------------------------------------ */
|
||||
|
|
|
@ -202,13 +202,36 @@ int sx1250_setup(uint8_t rf_chain, uint32_t freq_hz) {
|
|||
int32_t freq_reg;
|
||||
uint8_t buff[16];
|
||||
|
||||
/* Set Radio in Standby mode */
|
||||
/* Set Radio in Standby for calibrations */
|
||||
buff[0] = (uint8_t)STDBY_RC;
|
||||
sx1250_write_command(rf_chain, SET_STANDBY, buff, 1);
|
||||
wait_ms(10);
|
||||
|
||||
/* Get status to check Standby mode has been properly set */
|
||||
buff[0] = 0x00;
|
||||
sx1250_read_command(rf_chain, GET_STATUS, buff, 1);
|
||||
if ((uint8_t)(TAKE_N_BITS_FROM(buff[0], 4, 3)) != 0x02) {
|
||||
printf("ERROR: Failed to set SX1250_%u in STANDBY_RC mode\n", rf_chain);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Run all calibrations (TCXO) */
|
||||
buff[0] = 0x7F;
|
||||
sx1250_write_command(rf_chain, CALIBRATE, buff, 1);
|
||||
wait_ms(10);
|
||||
|
||||
/* Set Radio in Standby with XOSC ON */
|
||||
buff[0] = (uint8_t)STDBY_XOSC;
|
||||
sx1250_write_command(rf_chain, SET_STANDBY, buff, 1);
|
||||
wait_ms(10);
|
||||
|
||||
/* Get status to check Standby mode has been properly set */
|
||||
buff[0] = 0x00;
|
||||
sx1250_read_command(rf_chain, GET_STATUS, buff, 1);
|
||||
if ((uint8_t)(TAKE_N_BITS_FROM(buff[0], 4, 3)) != 0x03) {
|
||||
printf("ERROR: Failed to set SX1250_%u in STANDBY_XOSC mode\n", rf_chain);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set Bitrate to maximum (to lower TX to FS switch time) */
|
||||
buff[0] = 0x06;
|
||||
|
|
|
@ -734,13 +734,8 @@ int sx1302_lora_modem_configure(uint32_t radio_freq_hz) {
|
|||
lgw_reg_w(SX1302_REG_OTP_MODEM_EN_0_MODEM_EN, 0xFF);
|
||||
|
||||
/* Enable limited modems */
|
||||
#if FPGA_BOARD_16_CH
|
||||
DEBUG_MSG("Configuring 8 limited-SF modems\n");
|
||||
lgw_reg_w(SX1302_REG_OTP_MODEM_EN_1_MODEM_EN, 0xFF);
|
||||
#else
|
||||
DEBUG_MSG("Configuring 4 limited-SF modems\n");
|
||||
lgw_reg_w(SX1302_REG_OTP_MODEM_EN_1_MODEM_EN, 0x0F);
|
||||
#endif
|
||||
|
||||
/* Configure coarse sync between correlators and modems */
|
||||
lgw_reg_w(SX1302_REG_RX_TOP_MODEM_SYNC_DELTA_MSB_MODEM_SYNC_DELTA, 0);
|
||||
|
@ -981,11 +976,6 @@ int sx1302_agc_load_firmware(const uint8_t *firmware) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
#if BYPASS_FW_INIT
|
||||
printf("Disable AGC init protocol\n");
|
||||
sx1302_agc_mailbox_write(2, 0xF7); /* To be done before fw starts */
|
||||
#endif
|
||||
|
||||
/* Release control over AGC MCU */
|
||||
lgw_reg_w(SX1302_REG_AGC_MCU_CTRL_HOST_PROG, 0x00);
|
||||
lgw_reg_w(SX1302_REG_AGC_MCU_CTRL_MCU_CLEAR, 0x00);
|
||||
|
@ -1090,11 +1080,6 @@ int sx1302_agc_start(uint8_t version, lgw_radio_type_t radio_type, uint8_t ana_g
|
|||
}
|
||||
DEBUG_PRINTF("AGC FW VERSION: %d\n", val);
|
||||
|
||||
#if BYPASS_FW_INIT
|
||||
printf("Bypass AGC init protocol\n");
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
/* Configure Radio A gains */
|
||||
sx1302_agc_mailbox_write(0, ana_gain); /* 0:auto agc*/
|
||||
sx1302_agc_mailbox_write(1, dec_gain);
|
||||
|
@ -1396,11 +1381,6 @@ int sx1302_arb_load_firmware(const uint8_t *firmware) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
#if BYPASS_FW_INIT
|
||||
printf("Disable ARB init protocol\n");
|
||||
sx1302_arb_debug_write(2, 0xF7); /* To be done before fw starts */
|
||||
#endif
|
||||
|
||||
/* Release control over ARB MCU */
|
||||
lgw_reg_w(SX1302_REG_ARB_MCU_CTRL_HOST_PROG, 0x00);
|
||||
lgw_reg_w(SX1302_REG_ARB_MCU_CTRL_MCU_CLEAR, 0x00);
|
||||
|
@ -1568,11 +1548,6 @@ int sx1302_arb_start(uint8_t version) {
|
|||
}
|
||||
DEBUG_PRINTF("ARB FW VERSION: %d\n", val);
|
||||
|
||||
#if BYPASS_FW_INIT
|
||||
printf("Bypass ARB init protocol\n");
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
/* Enable/disable ARB detect/modem alloc stats for the specified SF */
|
||||
sx1302_arb_set_debug_stats(true, DR_LORA_SF7);
|
||||
|
||||
|
@ -2106,7 +2081,6 @@ int sx1302_send(lgw_radio_type_t radio_type, struct lgw_tx_gain_lut_s * tx_lut,
|
|||
mod_bw = pkt_data->bandwidth;
|
||||
break;
|
||||
case MOD_CW:
|
||||
/* Intended fall-through */
|
||||
case MOD_FSK:
|
||||
mod_bw = (0x01 << 7) | pkt_data->bandwidth;
|
||||
break;
|
||||
|
|
|
@ -81,15 +81,9 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
|
|||
#define SX1302_PKT_TAIL_METADATA 14
|
||||
|
||||
/* modem IDs */
|
||||
#if FPGA_BOARD_16_CH
|
||||
#define SX1302_LORA_MODEM_ID_MAX 15
|
||||
#define SX1302_LORA_STD_MODEM_ID 16
|
||||
#define SX1302_FSK_MODEM_ID 17
|
||||
#else
|
||||
#define SX1302_LORA_MODEM_ID_MAX 11
|
||||
#define SX1302_LORA_STD_MODEM_ID 12
|
||||
#define SX1302_FSK_MODEM_ID 13
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* --- PRIVATE VARIABLES ---------------------------------------------------- */
|
||||
|
|
|
@ -605,6 +605,7 @@ int main(int argc, char **argv)
|
|||
boardconf.clksrc = clocksource;
|
||||
boardconf.full_duplex = false;
|
||||
strncpy(boardconf.spidev_path, spidev_path, sizeof boardconf.spidev_path);
|
||||
boardconf.spidev_path[sizeof boardconf.spidev_path - 1] = '\0'; /* ensure string termination */
|
||||
if (lgw_board_setconf(&boardconf) != LGW_HAL_SUCCESS) {
|
||||
printf("ERROR: failed to configure board\n");
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -180,6 +180,7 @@ int main(int argc, char **argv)
|
|||
boardconf.clksrc = clocksource;
|
||||
boardconf.full_duplex = false;
|
||||
strncpy(boardconf.spidev_path, spidev_path, sizeof boardconf.spidev_path);
|
||||
boardconf.spidev_path[sizeof boardconf.spidev_path - 1] = '\0'; /* ensure string termination */
|
||||
if (lgw_board_setconf(&boardconf) != LGW_HAL_SUCCESS) {
|
||||
printf("ERROR: failed to configure board\n");
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -273,6 +273,7 @@ int main(int argc, char **argv)
|
|||
boardconf.clksrc = clocksource;
|
||||
boardconf.full_duplex = false;
|
||||
strncpy(boardconf.spidev_path, spidev_path, sizeof boardconf.spidev_path);
|
||||
boardconf.spidev_path[sizeof boardconf.spidev_path - 1] = '\0'; /* ensure string termination */
|
||||
if (lgw_board_setconf(&boardconf) != LGW_HAL_SUCCESS) {
|
||||
printf("ERROR: failed to configure board\n");
|
||||
return EXIT_FAILURE;
|
||||
|
@ -319,7 +320,7 @@ int main(int argc, char **argv)
|
|||
/* blocking non-canonical read on serial port */
|
||||
ssize_t nb_char = read(gps_tty_dev, serial_buff + wr_idx, LGW_GPS_MIN_MSG_SIZE);
|
||||
if (nb_char <= 0) {
|
||||
printf("WARNING: [gps] read() returned value %d\n", nb_char);
|
||||
printf("WARNING: [gps] read() returned value %zd\n", nb_char);
|
||||
continue;
|
||||
}
|
||||
wr_idx += (size_t)nb_char;
|
||||
|
@ -332,7 +333,7 @@ int main(int argc, char **argv)
|
|||
size_t frame_size = 0;
|
||||
|
||||
/* Scan buffer for UBX sync char */
|
||||
if (serial_buff[rd_idx] == LGW_GPS_UBX_SYNC_CHAR) {
|
||||
if (serial_buff[rd_idx] == (char)LGW_GPS_UBX_SYNC_CHAR) {
|
||||
|
||||
/***********************
|
||||
* Found UBX sync char *
|
||||
|
@ -352,7 +353,7 @@ int main(int argc, char **argv)
|
|||
gps_process_sync();
|
||||
}
|
||||
}
|
||||
} else if(serial_buff[rd_idx] == LGW_GPS_NMEA_SYNC_CHAR) {
|
||||
} else if(serial_buff[rd_idx] == (char)LGW_GPS_NMEA_SYNC_CHAR) {
|
||||
/************************
|
||||
* Found NMEA sync char *
|
||||
************************/
|
||||
|
|
|
@ -202,6 +202,7 @@ int main(int argc, char **argv)
|
|||
boardconf.clksrc = clocksource;
|
||||
boardconf.full_duplex = false;
|
||||
strncpy(boardconf.spidev_path, spidev_path, sizeof boardconf.spidev_path);
|
||||
boardconf.spidev_path[sizeof boardconf.spidev_path - 1] = '\0'; /* ensure string termination */
|
||||
if (lgw_board_setconf(&boardconf) != LGW_HAL_SUCCESS) {
|
||||
printf("ERROR: failed to configure board\n");
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -416,6 +416,7 @@ int main(int argc, char **argv)
|
|||
boardconf.clksrc = clocksource;
|
||||
boardconf.full_duplex = false;
|
||||
strncpy(boardconf.spidev_path, spidev_path, sizeof boardconf.spidev_path);
|
||||
boardconf.spidev_path[sizeof boardconf.spidev_path - 1] = '\0'; /* ensure string termination */
|
||||
if (lgw_board_setconf(&boardconf) != LGW_HAL_SUCCESS) {
|
||||
printf("ERROR: failed to configure board\n");
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
{
|
||||
"SX130x_conf": {
|
||||
"spidev_path": "/dev/spidev0.0",
|
||||
"lorawan_public": true,
|
||||
"clksrc": 1,
|
||||
"antenna_gain": 0, /* antenna gain, in dBi */
|
||||
"full_duplex": true,
|
||||
"precision_timestamp": {
|
||||
"enable": false,
|
||||
"max_ts_metrics": 255,
|
||||
"nb_symbols": 1
|
||||
},
|
||||
"radio_0": {
|
||||
"enable": true,
|
||||
"type": "SX1257",
|
||||
"freq": 913800000,
|
||||
"rssi_offset": -196.0,
|
||||
"tx_enable": true,
|
||||
"tx_freq_min": 100000000,
|
||||
"tx_freq_max": 950000000,
|
||||
"tx_gain_lut":[
|
||||
{"rf_power": -6, "pa_gain": 0, "dac_gain": 3, "mix_gain": 8, "dig_gain": 0},
|
||||
{"rf_power": -3, "pa_gain": 0, "dac_gain": 3, "mix_gain": 10, "dig_gain": 0},
|
||||
{"rf_power": 0, "pa_gain": 0, "dac_gain": 3, "mix_gain": 12, "dig_gain": 0},
|
||||
{"rf_power": 3, "pa_gain": 1, "dac_gain": 3, "mix_gain": 8, "dig_gain": 0},
|
||||
{"rf_power": 6, "pa_gain": 1, "dac_gain": 3, "mix_gain": 10, "dig_gain": 0},
|
||||
{"rf_power": 10, "pa_gain": 1, "dac_gain": 3, "mix_gain": 12, "dig_gain": 0},
|
||||
{"rf_power": 11, "pa_gain": 1, "dac_gain": 3, "mix_gain": 13, "dig_gain": 0},
|
||||
{"rf_power": 12, "pa_gain": 2, "dac_gain": 3, "mix_gain": 9, "dig_gain": 0},
|
||||
{"rf_power": 13, "pa_gain": 1, "dac_gain": 3, "mix_gain": 15, "dig_gain": 0},
|
||||
{"rf_power": 14, "pa_gain": 2, "dac_gain": 3, "mix_gain": 10, "dig_gain": 0},
|
||||
{"rf_power": 16, "pa_gain": 2, "dac_gain": 3, "mix_gain": 11, "dig_gain": 0},
|
||||
{"rf_power": 20, "pa_gain": 3, "dac_gain": 3, "mix_gain": 9, "dig_gain": 0},
|
||||
{"rf_power": 23, "pa_gain": 3, "dac_gain": 3, "mix_gain": 10, "dig_gain": 0},
|
||||
{"rf_power": 25, "pa_gain": 3, "dac_gain": 3, "mix_gain": 11, "dig_gain": 0},
|
||||
{"rf_power": 26, "pa_gain": 3, "dac_gain": 3, "mix_gain": 12, "dig_gain": 0},
|
||||
{"rf_power": 27, "pa_gain": 3, "dac_gain": 3, "mix_gain": 14, "dig_gain": 0}
|
||||
]
|
||||
},
|
||||
"radio_1": {
|
||||
"enable": true,
|
||||
"type": "SX1257",
|
||||
"freq": 914600000,
|
||||
"rssi_offset": -196.0,
|
||||
"tx_enable": true,
|
||||
"tx_freq_min": 100000000,
|
||||
"tx_freq_max": 950000000,
|
||||
"tx_gain_lut":[
|
||||
{"rf_power": -6, "pa_gain": 0, "dac_gain": 3, "mix_gain": 8, "dig_gain": 0},
|
||||
{"rf_power": -3, "pa_gain": 0, "dac_gain": 3, "mix_gain": 10, "dig_gain": 0},
|
||||
{"rf_power": 0, "pa_gain": 0, "dac_gain": 3, "mix_gain": 12, "dig_gain": 0},
|
||||
{"rf_power": 3, "pa_gain": 1, "dac_gain": 3, "mix_gain": 8, "dig_gain": 0},
|
||||
{"rf_power": 6, "pa_gain": 1, "dac_gain": 3, "mix_gain": 10, "dig_gain": 0},
|
||||
{"rf_power": 10, "pa_gain": 1, "dac_gain": 3, "mix_gain": 12, "dig_gain": 0},
|
||||
{"rf_power": 11, "pa_gain": 1, "dac_gain": 3, "mix_gain": 13, "dig_gain": 0},
|
||||
{"rf_power": 12, "pa_gain": 2, "dac_gain": 3, "mix_gain": 9, "dig_gain": 0},
|
||||
{"rf_power": 13, "pa_gain": 1, "dac_gain": 3, "mix_gain": 15, "dig_gain": 0},
|
||||
{"rf_power": 14, "pa_gain": 2, "dac_gain": 3, "mix_gain": 10, "dig_gain": 0},
|
||||
{"rf_power": 16, "pa_gain": 2, "dac_gain": 3, "mix_gain": 11, "dig_gain": 0},
|
||||
{"rf_power": 20, "pa_gain": 3, "dac_gain": 3, "mix_gain": 9, "dig_gain": 0},
|
||||
{"rf_power": 23, "pa_gain": 3, "dac_gain": 3, "mix_gain": 10, "dig_gain": 0},
|
||||
{"rf_power": 25, "pa_gain": 3, "dac_gain": 3, "mix_gain": 11, "dig_gain": 0},
|
||||
{"rf_power": 26, "pa_gain": 3, "dac_gain": 3, "mix_gain": 12, "dig_gain": 0},
|
||||
{"rf_power": 27, "pa_gain": 3, "dac_gain": 3, "mix_gain": 14, "dig_gain": 0}
|
||||
]
|
||||
},
|
||||
"chan_multiSF_0": {"enable": true, "radio": 0, "if": -300000},
|
||||
"chan_multiSF_1": {"enable": true, "radio": 0, "if": -100000},
|
||||
"chan_multiSF_2": {"enable": true, "radio": 0, "if": 100000},
|
||||
"chan_multiSF_3": {"enable": true, "radio": 0, "if": 300000},
|
||||
"chan_multiSF_4": {"enable": true, "radio": 1, "if": -300000},
|
||||
"chan_multiSF_5": {"enable": true, "radio": 1, "if": -100000},
|
||||
"chan_multiSF_6": {"enable": true, "radio": 1, "if": 100000},
|
||||
"chan_multiSF_7": {"enable": true, "radio": 1, "if": 300000}
|
||||
},
|
||||
|
||||
"gateway_conf": {
|
||||
"gateway_ID": "AA555A0000000000",
|
||||
/* change with default server address/ports */
|
||||
"server_address": "localhost",
|
||||
"serv_port_up": 1750,
|
||||
"serv_port_down": 1750,
|
||||
/* adjust the following parameters for your network */
|
||||
"keepalive_interval": 10,
|
||||
"stat_interval": 30,
|
||||
"push_timeout_ms": 100,
|
||||
/* forward only valid packets */
|
||||
"forward_crc_valid": true,
|
||||
"forward_crc_error": false,
|
||||
"forward_crc_disabled": false
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
|
|||
#include <stdint.h> /* C99 types */
|
||||
#include <stdbool.h> /* bool type */
|
||||
#include <stdio.h> /* printf, fprintf, snprintf, fopen, fputs */
|
||||
#include <inttypes.h> /* PRIx64, PRIu64... */
|
||||
|
||||
#include <string.h> /* memset */
|
||||
#include <signal.h> /* sigaction */
|
||||
|
@ -333,6 +334,7 @@ static int parse_SX130x_configuration(const char * conf_file) {
|
|||
str = json_object_get_string(conf_obj, "spidev_path");
|
||||
if (str != NULL) {
|
||||
strncpy(boardconf.spidev_path, str, sizeof boardconf.spidev_path);
|
||||
boardconf.spidev_path[sizeof boardconf.spidev_path - 1] = '\0'; /* ensure string termination */
|
||||
} else {
|
||||
MSG("ERROR: spidev path must be configured in %s\n", conf_file);
|
||||
return -1;
|
||||
|
@ -774,6 +776,7 @@ static int parse_gateway_configuration(const char * conf_file) {
|
|||
str = json_object_get_string(conf_obj, "server_address");
|
||||
if (str != NULL) {
|
||||
strncpy(serv_addr, str, sizeof serv_addr);
|
||||
serv_addr[sizeof serv_addr - 1] = '\0'; /* ensure string termination */
|
||||
MSG("INFO: server hostname or IP address is configured to \"%s\"\n", serv_addr);
|
||||
}
|
||||
|
||||
|
@ -831,6 +834,7 @@ static int parse_gateway_configuration(const char * conf_file) {
|
|||
str = json_object_get_string(conf_obj, "gps_tty_path");
|
||||
if (str != NULL) {
|
||||
strncpy(gps_tty_path, str, sizeof gps_tty_path);
|
||||
gps_tty_path[sizeof gps_tty_path - 1] = '\0'; /* ensure string termination */
|
||||
MSG("INFO: GPS serial port path is configured to \"%s\"\n", gps_tty_path);
|
||||
}
|
||||
|
||||
|
@ -987,7 +991,8 @@ static int parse_debug_configuration(const char * conf_file) {
|
|||
/* Get log file configuration */
|
||||
str = json_object_get_string(conf_obj, "log_file");
|
||||
if (str != NULL) {
|
||||
strncpy(debugconf.log_file_name, str, strlen(str));
|
||||
strncpy(debugconf.log_file_name, str, sizeof debugconf.log_file_name);
|
||||
debugconf.log_file_name[sizeof debugconf.log_file_name - 1] = '\0'; /* ensure string termination */
|
||||
MSG("INFO: setting debug log file name to %s\n", debugconf.log_file_name);
|
||||
}
|
||||
|
||||
|
@ -1205,6 +1210,7 @@ int main(int argc, char ** argv)
|
|||
uint32_t trig_tstamp;
|
||||
uint32_t inst_tstamp;
|
||||
uint64_t eui;
|
||||
float temperature;
|
||||
|
||||
/* statistics variable */
|
||||
time_t t;
|
||||
|
@ -1388,7 +1394,7 @@ int main(int argc, char ** argv)
|
|||
if (i != LGW_HAL_SUCCESS) {
|
||||
printf("ERROR: failed to get concentrator EUI\n");
|
||||
} else {
|
||||
printf("INFO: concentrator EUI: 0x%016llX\n", eui);
|
||||
printf("INFO: concentrator EUI: 0x%016" PRIx64 "\n", eui);
|
||||
}
|
||||
|
||||
/* spawn threads to manage upstream and downstream */
|
||||
|
@ -1583,6 +1589,12 @@ int main(int argc, char ** argv)
|
|||
} else {
|
||||
printf("# GPS sync is disabled\n");
|
||||
}
|
||||
i = lgw_get_temperature(&temperature);
|
||||
if (i != LGW_HAL_SUCCESS) {
|
||||
printf("### Concentrator temperature unknown ###\n");
|
||||
} else {
|
||||
printf("### Concentrator temperature: %.0f C ###\n", temperature);
|
||||
}
|
||||
printf("##### END #####\n");
|
||||
|
||||
/* generate a JSON report (will be sent to server by upstream thread) */
|
||||
|
@ -1843,7 +1855,7 @@ void thread_up(void) {
|
|||
j = lgw_cnt2gps(local_ref, p->count_us, &pkt_gps_time);
|
||||
if (j == LGW_GPS_SUCCESS) {
|
||||
pkt_gps_time_ms = pkt_gps_time.tv_sec * 1E3 + pkt_gps_time.tv_nsec / 1E6;
|
||||
j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"tmms\":%llu", pkt_gps_time_ms); /* GPS time in milliseconds since 06.Jan.1980 */
|
||||
j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"tmms\":%" PRIu64 "", pkt_gps_time_ms); /* GPS time in milliseconds since 06.Jan.1980 */
|
||||
if (j > 0) {
|
||||
buff_index += j;
|
||||
} else {
|
||||
|
@ -3061,7 +3073,7 @@ void thread_gps(void) {
|
|||
/* blocking non-canonical read on serial port */
|
||||
ssize_t nb_char = read(gps_tty_fd, serial_buff + wr_idx, LGW_GPS_MIN_MSG_SIZE);
|
||||
if (nb_char <= 0) {
|
||||
MSG("WARNING: [gps] read() returned value %d\n", nb_char);
|
||||
MSG("WARNING: [gps] read() returned value %zd\n", nb_char);
|
||||
continue;
|
||||
}
|
||||
wr_idx += (size_t)nb_char;
|
||||
|
@ -3070,11 +3082,11 @@ void thread_gps(void) {
|
|||
* Scan buffer for UBX/NMEA sync chars and *
|
||||
* attempt to decode frame if one is found *
|
||||
*******************************************/
|
||||
while(rd_idx < wr_idx) {
|
||||
while (rd_idx < wr_idx) {
|
||||
size_t frame_size = 0;
|
||||
|
||||
/* Scan buffer for UBX sync char */
|
||||
if(serial_buff[rd_idx] == (char)LGW_GPS_UBX_SYNC_CHAR) {
|
||||
if (serial_buff[rd_idx] == (char)LGW_GPS_UBX_SYNC_CHAR) {
|
||||
|
||||
/***********************
|
||||
* Found UBX sync char *
|
||||
|
@ -3093,7 +3105,7 @@ void thread_gps(void) {
|
|||
gps_process_sync();
|
||||
}
|
||||
}
|
||||
} else if(serial_buff[rd_idx] == LGW_GPS_NMEA_SYNC_CHAR) {
|
||||
} else if (serial_buff[rd_idx] == (char)LGW_GPS_NMEA_SYNC_CHAR) {
|
||||
/************************
|
||||
* Found NMEA sync char *
|
||||
************************/
|
||||
|
@ -3114,7 +3126,7 @@ void thread_gps(void) {
|
|||
}
|
||||
}
|
||||
|
||||
if(frame_size > 0) {
|
||||
if (frame_size > 0) {
|
||||
/* At this point message is a checksum verified frame
|
||||
we're processed or ignored. Remove frame from buffer */
|
||||
rd_idx += frame_size;
|
||||
|
@ -3124,14 +3136,14 @@ void thread_gps(void) {
|
|||
}
|
||||
} /* ...for(rd_idx = 0... */
|
||||
|
||||
if(frame_end_idx) {
|
||||
if (frame_end_idx) {
|
||||
/* Frames have been processed. Remove bytes to end of last processed frame */
|
||||
memcpy(serial_buff, &serial_buff[frame_end_idx], wr_idx - frame_end_idx);
|
||||
wr_idx -= frame_end_idx;
|
||||
} /* ...for(rd_idx = 0... */
|
||||
|
||||
/* Prevent buffer overflow */
|
||||
if((sizeof(serial_buff) - wr_idx) < LGW_GPS_MIN_MSG_SIZE) {
|
||||
if ((sizeof(serial_buff) - wr_idx) < LGW_GPS_MIN_MSG_SIZE) {
|
||||
memcpy(serial_buff, &serial_buff[LGW_GPS_MIN_MSG_SIZE], wr_idx - LGW_GPS_MIN_MSG_SIZE);
|
||||
wr_idx -= LGW_GPS_MIN_MSG_SIZE;
|
||||
}
|
||||
|
|
|
@ -161,6 +161,15 @@ found in the `libtools` directory.
|
|||
|
||||
## 6. Changelog
|
||||
|
||||
### 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
|
||||
|
||||
### v1.0.1 ###
|
||||
|
||||
* Packet Forwarder: Updated TX gain LUT in global_conf.json.sx1250 with proper
|
||||
|
|
2
tools/systemd/lora_pkt_fwd.conf
Normal file
2
tools/systemd/lora_pkt_fwd.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
if $programname == 'lora_pkt_fwd' then /var/log/lora_pkt_fwd.log
|
||||
if $programname == 'lora_pkt_fwd' then ~
|
17
tools/systemd/lora_pkt_fwd.service
Normal file
17
tools/systemd/lora_pkt_fwd.service
Normal file
|
@ -0,0 +1,17 @@
|
|||
[Unit]
|
||||
Description=LoRa Packet Forwarder
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/home/pi/sx1302_hal/bin
|
||||
ExecStart=/home/pi/sx1302_hal/bin/lora_pkt_fwd -c /home/pi/sx1302_hal/bin/global_conf.json.sx1250
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
StandardOutput=syslog
|
||||
StandardError=syslog
|
||||
SyslogIdentifier=lora_pkt_fwd
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
58
tools/systemd/readme.md
Normal file
58
tools/systemd/readme.md
Normal file
|
@ -0,0 +1,58 @@
|
|||
/ _____) _ | |
|
||||
( (____ _____ ____ _| |_ _____ ____| |__
|
||||
\____ \| ___ | (_ _) ___ |/ ___) _ \
|
||||
_____) ) ____| | | || |_| ____( (___| | | |
|
||||
(______/|_____)_|_|_| \__)_____)\____)_| |_|
|
||||
(C)2019 Semtech
|
||||
|
||||
How to auto-start the with systemd
|
||||
==================================
|
||||
|
||||
## Create a new systemd service
|
||||
|
||||
Update the lora_pkt_fwd.service file with proper paths and options, then
|
||||
|
||||
```console
|
||||
sudo cp lora_pkt_fwd.service /etc/systemd/system
|
||||
```
|
||||
|
||||
### Enable the service for autostart with
|
||||
|
||||
```console
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable lora_pkt_fwd.service
|
||||
sudo reboot
|
||||
```
|
||||
|
||||
### The following commands to disable the service, manually start/stop it:
|
||||
|
||||
```console
|
||||
sudo systemctl disable lora_pkt_fwd.service
|
||||
```
|
||||
|
||||
```console
|
||||
sudo systemctl start lora_pkt_fwd.service
|
||||
```
|
||||
|
||||
```console
|
||||
sudo systemctl stop lora_pkt_fwd.service
|
||||
```
|
||||
|
||||
## Configure rsyslog to redirect the packet forwarder logs into a dedicated file
|
||||
|
||||
```console
|
||||
sudo cp lora_pkt_fwd.conf /etc/rsyslog.d
|
||||
sudo systemctl restart rsyslog
|
||||
```
|
||||
|
||||
### See the logs
|
||||
|
||||
```console
|
||||
sudo journalctl -u lora_pkt_fwd -f
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```console
|
||||
cat /var/log/lora_pkt_fwd.log
|
||||
```
|
|
@ -27,6 +27,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h> /* PRIx64, PRIu64... */
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
@ -146,17 +147,18 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
/* Configure the gateway */
|
||||
memset( &boardconf, 0, sizeof boardconf);
|
||||
memset(&boardconf, 0, sizeof boardconf);
|
||||
boardconf.lorawan_public = true;
|
||||
boardconf.clksrc = clocksource;
|
||||
boardconf.full_duplex = false;
|
||||
strncpy(boardconf.spidev_path, spidev_path, sizeof boardconf.spidev_path);
|
||||
boardconf.spidev_path[sizeof boardconf.spidev_path - 1] = '\0'; /* ensure string termination */
|
||||
if (lgw_board_setconf(&boardconf) != LGW_HAL_SUCCESS) {
|
||||
printf("ERROR: failed to configure board\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
memset( &rfconf, 0, sizeof rfconf);
|
||||
memset(&rfconf, 0, sizeof rfconf);
|
||||
rfconf.enable = true; /* rf chain 0 needs to be enabled for calibration to work on sx1257 */
|
||||
rfconf.freq_hz = 868500000; /* dummy */
|
||||
rfconf.type = radio_type;
|
||||
|
@ -166,7 +168,7 @@ int main(int argc, char **argv)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
memset( &rfconf, 0, sizeof rfconf);
|
||||
memset(&rfconf, 0, sizeof rfconf);
|
||||
rfconf.enable = (clocksource == 1) ? true : false;
|
||||
rfconf.freq_hz = 868500000; /* dummy */
|
||||
rfconf.type = radio_type;
|
||||
|
@ -187,7 +189,7 @@ int main(int argc, char **argv)
|
|||
if (x != LGW_HAL_SUCCESS) {
|
||||
printf("ERROR: failed to get concentrator EUI\n");
|
||||
} else {
|
||||
printf("\nINFO: concentrator EUI: 0x%016llX\n\n", eui);
|
||||
printf("\nINFO: concentrator EUI: 0x%016" PRIx64 "\n\n", eui);
|
||||
}
|
||||
|
||||
/* Stop the gateway */
|
||||
|
|
|
@ -24,6 +24,12 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 7
|
||||
#define FALL_THROUGH __attribute__ ((fallthrough))
|
||||
#else
|
||||
#define FALL_THROUGH ((void)0)
|
||||
#endif /* __GNUC__ >= 7 */
|
||||
|
||||
#include <stdint.h> /* C99 types */
|
||||
#include <stdio.h> /* printf, fprintf, sprintf, fopen, fputs */
|
||||
#include <stdlib.h> /* EXIT_* */
|
||||
|
@ -232,11 +238,13 @@ int main( int argc, char **argv )
|
|||
|
||||
case 'A':
|
||||
fwd_uplink = true;
|
||||
strncpy( serv_addr, optarg, strlen( optarg ));
|
||||
strncpy( serv_addr, optarg, sizeof serv_addr );
|
||||
serv_addr[sizeof serv_addr - 1] = '\0'; /* ensure string termination */
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
strncpy( serv_port_fwd, optarg, strlen( optarg ));
|
||||
strncpy( serv_port_fwd, optarg, sizeof serv_port_fwd );
|
||||
serv_port_fwd[sizeof serv_port_fwd - 1] = '\0'; /* ensure string termination */
|
||||
break;
|
||||
|
||||
case 'f': /* -f <float,float> target frequency in MHz */
|
||||
|
@ -252,7 +260,7 @@ int main( int argc, char **argv )
|
|||
{
|
||||
thread_params.freq_mhz[1] = arg_f2;
|
||||
}
|
||||
/* No break */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
if( (arg_f < 30.0) || (arg_f > 3000.0) )
|
||||
{
|
||||
|
@ -287,7 +295,7 @@ int main( int argc, char **argv )
|
|||
{
|
||||
thread_params.freq_step = arg_f_step;
|
||||
}
|
||||
/* No break */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
if( (arg_u == 0) || (arg_u > 100) )
|
||||
{
|
||||
|
@ -336,7 +344,7 @@ int main( int argc, char **argv )
|
|||
{
|
||||
thread_params.spread_factor[1] = (uint8_t)arg_u2;
|
||||
}
|
||||
/* No break */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
if( (arg_u < 5) || (arg_u > 12) )
|
||||
{
|
||||
|
@ -368,7 +376,8 @@ int main( int argc, char **argv )
|
|||
}
|
||||
else
|
||||
{
|
||||
strncpy( thread_params.coding_rate, arg_s, strlen(arg_s));
|
||||
strncpy( thread_params.coding_rate, arg_s, sizeof thread_params.coding_rate );
|
||||
thread_params.coding_rate[sizeof thread_params.coding_rate - 1] = '\0'; /* ensure string termination */
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -377,12 +386,12 @@ int main( int argc, char **argv )
|
|||
switch( j )
|
||||
{
|
||||
case 2:
|
||||
strncpy( thread_params.modulation_rf1, arg_s2, strlen(arg_s2));
|
||||
thread_params.modulation_rf1[strlen(arg_s2)] = '\0';
|
||||
/* No break */
|
||||
strncpy( thread_params.modulation_rf1, arg_s2, sizeof thread_params.modulation_rf1 );
|
||||
thread_params.modulation_rf1[sizeof thread_params.modulation_rf1 - 1] = '\0'; /* ensure string termination */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
strncpy( thread_params.modulation_rf0, arg_s, strlen(arg_s));
|
||||
thread_params.modulation_rf0[strlen(arg_s)] = '\0';
|
||||
strncpy( thread_params.modulation_rf0, arg_s, sizeof thread_params.modulation_rf0 );
|
||||
thread_params.modulation_rf0[sizeof thread_params.modulation_rf0 - 1] = '\0'; /* ensure string termination */
|
||||
break;
|
||||
default:
|
||||
parse_err = true;
|
||||
|
@ -430,7 +439,7 @@ int main( int argc, char **argv )
|
|||
{
|
||||
thread_params.rf_power[1] = (int8_t)arg_i2;
|
||||
}
|
||||
/* No break */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
if( (arg_i < -60) || (arg_i > 60) )
|
||||
{
|
||||
|
@ -465,7 +474,7 @@ int main( int argc, char **argv )
|
|||
{
|
||||
thread_params.preamb_size[1] = (uint16_t)arg_u2;
|
||||
}
|
||||
/* No break */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
if( (arg_u < 5) || (arg_u > 65535) )
|
||||
{
|
||||
|
@ -500,7 +509,7 @@ int main( int argc, char **argv )
|
|||
{
|
||||
thread_params.pl_size[1] = (uint8_t)arg_u2;
|
||||
}
|
||||
/* No break */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
if( arg_u > 255 )
|
||||
{
|
||||
|
@ -532,7 +541,7 @@ int main( int argc, char **argv )
|
|||
{
|
||||
case 2:
|
||||
thread_params.delay_ms[1] = (uint32_t)arg_u2;
|
||||
/* No break */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
thread_params.delay_ms[0] = (uint32_t)arg_u;
|
||||
break;
|
||||
|
@ -553,7 +562,7 @@ int main( int argc, char **argv )
|
|||
{
|
||||
case 2:
|
||||
thread_params.nb_loop[1] = (uint32_t)arg_u2;
|
||||
/* No break */
|
||||
FALL_THROUGH;
|
||||
case 1:
|
||||
thread_params.nb_loop[0] = (uint32_t)arg_u;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user