* HAL: Fixed scheduled downlink time precision by taking the tx start delay into
account.
* HAL: Fixed timestamp correction calculation for BW250 & BW500
* HAL: Fixed possible buffer overflow in lgw_receive() function
* HAL: Keep packet received in RX buffer when the buffer allocated to receive
the packets is too small. Remaining packets will be fetched on the next
lgw_receive calls (aligned on SX1301 behaviour).
This commit is contained in:
Michael Coracin 2019-09-20 11:06:37 +02:00
commit 5942224602
10 changed files with 217 additions and 122 deletions

View file

@ -69,11 +69,13 @@ void usage(void) {
//printf("Library version information: %s\n", lgw_version_info());
printf( "Available options:\n");
printf( " -h print this help\n");
printf( " -k <uint> Concentrator clock source (Radio A or Radio B) [0..1]\n");
printf( " -r <uint> Radio type (1255, 1257, 1250)\n");
printf( " -a <float> Radio A RX frequency in MHz\n");
printf( " -b <float> Radio B RX frequency in MHz\n");
printf( " -n <uint> number of packet received with CRC OK for each HAL start/stop loop\n");
printf( " -k <uint> Concentrator clock source (Radio A or Radio B) [0..1]\n");
printf( " -r <uint> Radio type (1255, 1257, 1250)\n");
printf( " -a <float> Radio A RX frequency in MHz\n");
printf( " -b <float> Radio B RX frequency in MHz\n");
printf( " -n <uint> Number of packet received with CRC OK for each HAL start/stop loop\n");
printf( " -z <uint> Size of the RX packet array to be passed to lgw_receive()\n");
printf( " -m <uint> Channel frequency plan mode [0:LoRaWAN-like, 1:Same frequency for all channels (-400000Hz on RF0)]\n");
}
/* -------------------------------------------------------------------------- */
@ -94,31 +96,47 @@ int main(int argc, char **argv)
unsigned int arg_u;
uint8_t clocksource = 0;
lgw_radio_type_t radio_type = LGW_RADIO_TYPE_NONE;
uint8_t max_rx_pkt = 16;
struct lgw_conf_board_s boardconf;
struct lgw_conf_rxrf_s rfconf;
struct lgw_conf_rxif_s ifconf;
struct lgw_pkt_rx_s rxpkt[16];
unsigned long nb_pkt_crc_ok = 0, nb_loop = 1, cnt_loop;
unsigned long nb_pkt_crc_ok = 0, nb_loop = 0, cnt_loop;
int nb_pkt;
const int32_t channel_if[9] = {
uint8_t channel_mode = 0; /* LoRaWAN-like */
const int32_t channel_if_mode0[9] = {
-400000,
-200000,
0,
-400000,
-200000,
0,
200000,
400000,
-200000 /* lora service */
-400000,
-200000,
-400000 /* lora service */
};
const uint8_t channel_rfchain[9] = { 1, 1, 1, 0, 0, 0, 0, 0, 1 };
const int32_t channel_if_mode1[9] = {
-400000,
-400000,
-400000,
-400000,
-400000,
-400000,
-400000,
-400000,
-400000 /* lora service */
};
const uint8_t channel_rfchain_mode0[9] = { 1, 1, 1, 0, 0, 0, 0, 0, 1 };
const uint8_t channel_rfchain_mode1[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* parse command line options */
while ((i = getopt (argc, argv, "ha:b:k:r:n:")) != -1) {
while ((i = getopt (argc, argv, "ha:b:k:r:n:z:m:")) != -1) {
switch (i) {
case 'h':
usage();
@ -179,6 +197,24 @@ int main(int argc, char **argv)
nb_loop = arg_u;
}
break;
case 'z': /* <uint> Size of the RX packet array to be passed to lgw_receive() */
i = sscanf(optarg, "%u", &arg_u);
if (i != 1) {
printf("ERROR: argument parsing of -z argument. Use -h to print help\n");
return EXIT_FAILURE;
} else {
max_rx_pkt = arg_u;
}
break;
case 'm':
i = sscanf(optarg, "%u", &arg_u);
if ((i != 1) || (arg_u > 1)) {
printf("ERROR: argument parsing of -m argument. Use -h to print help\n");
return EXIT_FAILURE;
} else {
channel_mode = arg_u;
}
break;
default:
printf("ERROR: argument parsing\n");
usage();
@ -231,10 +267,18 @@ int main(int argc, char **argv)
/* set configuration for LoRa multi-SF channels (bandwidth cannot be set) */
memset(&ifconf, 0, sizeof(ifconf));
for (i = 0; i < 9; i++) {
for (i = 0; i < 8; i++) {
ifconf.enable = true;
ifconf.rf_chain = channel_rfchain[i];
ifconf.freq_hz = channel_if[i];
if (channel_mode == 0) {
ifconf.rf_chain = channel_rfchain_mode0[i];
ifconf.freq_hz = channel_if_mode0[i];
} else if (channel_mode == 1) {
ifconf.rf_chain = channel_rfchain_mode1[i];
ifconf.freq_hz = channel_if_mode1[i];
} else {
printf("ERROR: channel mode not supported\n");
return EXIT_FAILURE;
}
ifconf.datarate = DR_LORA_SF7;
if (lgw_rxif_setconf(i, &ifconf) != LGW_HAL_SUCCESS) {
printf("ERROR: failed to configure rxif %d\n", i);
@ -242,6 +286,22 @@ int main(int argc, char **argv)
}
}
/* set configuration for LoRa Service channel */
memset(&ifconf, 0, sizeof(ifconf));
ifconf.rf_chain = channel_rfchain_mode0[i];
ifconf.freq_hz = channel_if_mode0[i];
ifconf.datarate = DR_LORA_SF7;
ifconf.bandwidth = BW_250KHZ;
if (lgw_rxif_setconf(8, &ifconf) != LGW_HAL_SUCCESS) {
printf("ERROR: failed to configure rxif for LoRa service channel\n");
return EXIT_FAILURE;
}
/* set the buffer size to hold received packets */
struct lgw_pkt_rx_s rxpkt[max_rx_pkt];
printf("INFO: rxpkt buffer size is set to %u\n", max_rx_pkt);
printf("INFO: Select channel mode %u\n", channel_mode);
/* Loop until user quits */
cnt_loop = 0;
while( (quit_sig != 1) && (exit_sig != 1) )
@ -264,14 +324,13 @@ int main(int argc, char **argv)
/* Loop until we have enough packets with CRC OK */
printf("Waiting for packets...\n");
nb_pkt_crc_ok = 0;
while ((nb_pkt_crc_ok < nb_loop) && (quit_sig != 1) && (exit_sig != 1)) {
while (((nb_pkt_crc_ok < nb_loop) || nb_loop == 0) && (quit_sig != 1) && (exit_sig != 1)) {
/* fetch N packets */
nb_pkt = lgw_receive(ARRAY_SIZE(rxpkt), rxpkt);
if (nb_pkt == 0) {
wait_ms(10);
} else {
printf("Received %d packets\n", nb_pkt);
for (i = 0; i < nb_pkt; i++) {
if (rxpkt[i].status == STAT_CRC_OK) {
nb_pkt_crc_ok += 1;
@ -294,6 +353,7 @@ int main(int argc, char **argv)
}
printf("\n");
}
printf("Received %d packets (total:%lu)\n", nb_pkt, nb_pkt_crc_ok);
}
}