for (cnt_loop = 0; cnt_loop < nb_loop; cnt_loop++) {
/* 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);
}
/* connect, configure and start the LoRa concentrator */
x = lgw_start();
if (x != 0) {
printf("ERROR: failed to start the gateway\n");
return EXIT_FAILURE;
}
/* Send packets */
memset(&pkt, 0, sizeof pkt);
pkt.rf_chain = rf_chain;
pkt.freq_hz = ft;
pkt.rf_power = rf_power;
if (trig_delay == false) {
pkt.tx_mode = IMMEDIATE;
} else {
if (trig_delay_us == 0) {
pkt.tx_mode = ON_GPS;
} else {
pkt.tx_mode = TIMESTAMPED;
}
}
if ( strcmp( mod, "CW" ) == 0 ) {
pkt.modulation = MOD_CW;
pkt.freq_offset = freq_offset;
pkt.f_dev = fdev_khz;
}
else if( strcmp( mod, "FSK" ) == 0 ) {
pkt.modulation = MOD_FSK;
pkt.no_crc = false;
pkt.datarate = br_kbps * 1e3;
pkt.f_dev = fdev_khz;
} else {
pkt.modulation = MOD_LORA;
pkt.coderate = CR_LORA_4_5;
pkt.no_crc = true;
}
pkt.invert_pol = invert_pol;
pkt.preamble = preamble;
pkt.no_header = no_header;
pkt.payload[0] = 0x40; /* Confirmed Data Up */
pkt.payload[1] = 0xAB;
pkt.payload[2] = 0xAB;
pkt.payload[3] = 0xAB;
pkt.payload[4] = 0xAB;
pkt.payload[5] = 0x00; /* FCTrl */
pkt.payload[6] = 0; /* FCnt */
pkt.payload[7] = 0; /* FCnt */
pkt.payload[8] = 0x02; /* FPort */
for (i = 9; i < 255; i++) {
pkt.payload[i] = i;
}
for (i = 0; i < (int)nb_pkt; i++) {
if (trig_delay == true) {
if (trig_delay_us > 0) {
lgw_get_instcnt(&count_us);
printf("count_us:%u\n", count_us);
pkt.count_us = count_us + trig_delay_us;
printf("programming TX for %u\n", pkt.count_us);
} else {
printf("programming TX for next PPS (GPS)\n");
}
}
if( strcmp( mod, "LORA" ) == 0 ) {
pkt.datarate = (sf == 0) ? (uint8_t)RAND_RANGE(5, 12) : sf;
}
switch (bw_khz) {
case 125:
pkt.bandwidth = BW_125KHZ;
break;
case 250:
pkt.bandwidth = BW_250KHZ;
break;
case 500:
pkt.bandwidth = BW_500KHZ;
break;
default:
pkt.bandwidth = (uint8_t)RAND_RANGE(BW_125KHZ, BW_500KHZ);
break;
}
pkt.size = (size == 0) ? (uint8_t)RAND_RANGE(9, 255) : size;
pkt.payload[6] = (uint8_t)(i >> 0); /* FCnt */
pkt.payload[7] = (uint8_t)(i >> 8); /* FCnt */
x = lgw_send(&pkt);
if (x != 0) {
printf("ERROR: failed to send packet\n");
return EXIT_FAILURE;
}
/* wait for packet to finish sending */
do {
wait_ms(5);
lgw_status(pkt.rf_chain, TX_STATUS, &tx_status); /* get TX status */
} while ((tx_status != TX_FREE) && (quit_sig != 1) && (exit_sig != 1));
if ((quit_sig == 1) || (exit_sig == 1)) {
break;
}
printf("TX done\n");
}
printf( "\nNb packets sent: %u (%u)\n", i, cnt_loop + 1 );
/* Stop the gateway */
x = lgw_stop();
if (x != 0) {
printf("ERROR: failed to stop the gateway\n");
return EXIT_FAILURE;
}
/* 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);
}
}
printf("=========== Test End ===========\n");