-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add a modified version of chip_id.c that allows us to check the chip ID - this allows us to determine if the chip is sx1302 or sx1303
- Loading branch information
Showing
2 changed files
with
238 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
/* | ||
______ _ | ||
/ _____) _ | | | ||
( (____ _____ ____ _| |_ _____ ____| |__ | ||
\____ \| ___ | (_ _) ___ |/ ___) _ \ | ||
_____) ) ____| | | || |_| ____( (___| | | | | ||
(______/|_____)_|_|_| \__)_____)\____)_| |_| | ||
(C)2019 Semtech | ||
Description: | ||
Utility to get SX1302 chip EUI | ||
License: Revised BSD License, see LICENSE.TXT file include in the project | ||
*/ | ||
|
||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* --- DEPENDANCIES --------------------------------------------------------- */ | ||
|
||
/* fix an issue between POSIX and C99 */ | ||
#if __STDC_VERSION__ >= 199901L | ||
#define _XOPEN_SOURCE 600 | ||
#else | ||
#define _XOPEN_SOURCE 500 | ||
#endif | ||
|
||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <inttypes.h> /* PRIx64, PRIu64... */ | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <math.h> | ||
#include <signal.h> /* sigaction */ | ||
#include <getopt.h> /* getopt_long */ | ||
|
||
#include "loragw_hal.h" | ||
#include "loragw_reg.h" | ||
#include "loragw_aux.h" | ||
#include "loragw_sx1302.h" | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* --- PRIVATE MACROS ------------------------------------------------------- */ | ||
|
||
#define RAND_RANGE(min, max) (rand() % (max + 1 - min) + min) | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ | ||
|
||
#define COM_TYPE_DEFAULT LGW_COM_SPI | ||
#define COM_PATH_DEFAULT "/dev/spidev0.0" | ||
|
||
#define DEFAULT_CLK_SRC 0 | ||
#define DEFAULT_FREQ_HZ 868500000U | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* --- PRIVATE VARIABLES ---------------------------------------------------- */ | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* --- PRIVATE FUNCTIONS ---------------------------------------------------- */ | ||
|
||
/* describe command line options */ | ||
void usage(void) { | ||
printf("Library version information: %s\n", lgw_version_info()); | ||
printf("Available options:\n"); | ||
printf(" -h Print this help\n"); | ||
printf(" -u Set COM type as USB (default is SPI)\n"); | ||
printf(" -d [path] Path to the COM interface\n"); | ||
printf(" => default path: " COM_PATH_DEFAULT "\n"); | ||
printf(" -k <uint> Concentrator clock source (Radio A or Radio B) [0..1]\n"); | ||
printf(" -r <uint> Radio type (1255, 1257, 1250)\n"); | ||
} | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* --- MAIN FUNCTION -------------------------------------------------------- */ | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int i, x; | ||
unsigned int arg_u; | ||
uint8_t clocksource = 0; | ||
lgw_radio_type_t radio_type = LGW_RADIO_TYPE_SX1250; | ||
sx1302_model_id_t model_id; | ||
|
||
struct lgw_conf_board_s boardconf; | ||
struct lgw_conf_rxrf_s rfconf; | ||
uint64_t eui; | ||
|
||
/* SPI interfaces */ | ||
const char com_path_default[] = COM_PATH_DEFAULT; | ||
const char * com_path = com_path_default; | ||
lgw_com_type_t com_type = COM_TYPE_DEFAULT; | ||
|
||
/* Parameter parsing */ | ||
int option_index = 0; | ||
static struct option long_options[] = { | ||
{0, 0, 0, 0} | ||
}; | ||
|
||
/* parse command line options */ | ||
while ((i = getopt_long (argc, argv, "hud:k:r:", long_options, &option_index)) != -1) { | ||
switch (i) { | ||
case 'h': | ||
usage(); | ||
return -1; | ||
break; | ||
|
||
case 'u': | ||
com_type = LGW_COM_USB; | ||
break; | ||
|
||
case 'd': | ||
com_path = optarg; | ||
break; | ||
|
||
case 'r': /* <uint> Radio type */ | ||
i = sscanf(optarg, "%u", &arg_u); | ||
if ((i != 1) || ((arg_u != 1255) && (arg_u != 1257) && (arg_u != 1250))) { | ||
printf("ERROR: argument parsing of -r argument. Use -h to print help\n"); | ||
return EXIT_FAILURE; | ||
} else { | ||
switch (arg_u) { | ||
case 1255: | ||
radio_type = LGW_RADIO_TYPE_SX1255; | ||
break; | ||
case 1257: | ||
radio_type = LGW_RADIO_TYPE_SX1257; | ||
break; | ||
default: /* 1250 */ | ||
radio_type = LGW_RADIO_TYPE_SX1250; | ||
break; | ||
} | ||
} | ||
break; | ||
|
||
case 'k': /* <uint> Clock Source */ | ||
i = sscanf(optarg, "%u", &arg_u); | ||
if ((i != 1) || (arg_u > 1)) { | ||
printf("ERROR: argument parsing of -k argument. Use -h to print help\n"); | ||
return EXIT_FAILURE; | ||
} else { | ||
clocksource = (uint8_t)arg_u; | ||
} | ||
break; | ||
|
||
default: | ||
printf("ERROR: argument parsing\n"); | ||
usage(); | ||
return -1; | ||
} | ||
} | ||
|
||
if (com_type == LGW_COM_SPI) { | ||
/* Board reset */ | ||
if (system("./reset_lgw.sh start") != 0) { | ||
printf("ERROR: failed to reset SX1302, check your reset_lgw.sh script\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
/* Configure the gateway */ | ||
memset(&boardconf, 0, sizeof boardconf); | ||
boardconf.lorawan_public = true; | ||
boardconf.clksrc = clocksource; | ||
boardconf.full_duplex = false; | ||
boardconf.com_type = com_type; | ||
strncpy(boardconf.com_path, com_path, sizeof boardconf.com_path); | ||
boardconf.com_path[sizeof boardconf.com_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); | ||
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; | ||
rfconf.tx_enable = false; | ||
rfconf.single_input_mode = false; | ||
if (lgw_rxrf_setconf(0, &rfconf) != LGW_HAL_SUCCESS) { | ||
printf("ERROR: failed to configure rxrf 0\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
memset(&rfconf, 0, sizeof rfconf); | ||
rfconf.enable = (clocksource == 1) ? true : false; | ||
rfconf.freq_hz = 868500000; /* dummy */ | ||
rfconf.type = radio_type; | ||
rfconf.tx_enable = false; | ||
rfconf.single_input_mode = false; | ||
if (lgw_rxrf_setconf(1, &rfconf) != LGW_HAL_SUCCESS) { | ||
printf("ERROR: failed to configure rxrf 1\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
x = lgw_start(); | ||
if (x != 0) { | ||
printf("ERROR: failed to start the gateway\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
/* get the concentrator chip model */ | ||
x = sx1302_get_model_id(&model_id); | ||
if (x != LGW_HAL_SUCCESS) { | ||
printf("ERROR: failed to get concentrator chip model\n"); | ||
} else { | ||
printf("\nINFO: concentrator chip model ID: 0x%02X\n", model_id); | ||
} | ||
|
||
/* get the concentrator EUI */ | ||
x = lgw_get_eui(&eui); | ||
if (x != LGW_HAL_SUCCESS) { | ||
printf("ERROR: failed to get concentrator EUI\n"); | ||
} else { | ||
printf("\nINFO: concentrator EUI: 0x%016" PRIx64 "\n\n", eui); | ||
} | ||
|
||
/* Stop the gateway */ | ||
x = lgw_stop(); | ||
if (x != 0) { | ||
printf("ERROR: failed to stop the gateway\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if (com_type == LGW_COM_SPI) { | ||
/* Board reset */ | ||
if (system("./reset_lgw.sh stop") != 0) { | ||
printf("ERROR: failed to reset SX1302, check your reset_lgw.sh script\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/* --- EOF ------------------------------------------------------------------ */ |