May 2021 Tests
Dependencies: SX127x sx12xx_hal
main.cpp@0:44fb2db84011, 2019-02-20 (annotated)
- Committer:
- LoRaToolbox
- Date:
- Wed Feb 20 07:27:34 2019 +0000
- Revision:
- 0:44fb2db84011
- Child:
- 1:b277f5a65c1c
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LoRaToolbox | 0:44fb2db84011 | 1 | #include "radio.h" |
LoRaToolbox | 0:44fb2db84011 | 2 | |
LoRaToolbox | 0:44fb2db84011 | 3 | #if defined(SX127x_H) |
LoRaToolbox | 0:44fb2db84011 | 4 | #define BW_KHZ 500 |
LoRaToolbox | 0:44fb2db84011 | 5 | #define SPREADING_FACTOR 11 |
LoRaToolbox | 0:44fb2db84011 | 6 | #define CF_HZ 912000000 |
LoRaToolbox | 0:44fb2db84011 | 7 | #define TX_DBM 20 |
LoRaToolbox | 0:44fb2db84011 | 8 | #elif defined(SX126x_H) |
LoRaToolbox | 0:44fb2db84011 | 9 | #define BW_KHZ 500 |
LoRaToolbox | 0:44fb2db84011 | 10 | #define SPREADING_FACTOR 10 |
LoRaToolbox | 0:44fb2db84011 | 11 | #define CF_HZ 915000000 |
LoRaToolbox | 0:44fb2db84011 | 12 | #define TX_DBM (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14) |
LoRaToolbox | 0:44fb2db84011 | 13 | #elif defined(SX128x_H) |
LoRaToolbox | 0:44fb2db84011 | 14 | #define BW_KHZ 200 |
LoRaToolbox | 0:44fb2db84011 | 15 | #define SPREADING_FACTOR 7 |
LoRaToolbox | 0:44fb2db84011 | 16 | #define CF_HZ 2487000000 |
LoRaToolbox | 0:44fb2db84011 | 17 | #define TX_DBM 6 |
LoRaToolbox | 0:44fb2db84011 | 18 | #endif |
LoRaToolbox | 0:44fb2db84011 | 19 | |
LoRaToolbox | 0:44fb2db84011 | 20 | /**********************************************************************/ |
LoRaToolbox | 0:44fb2db84011 | 21 | volatile bool txDone; |
LoRaToolbox | 0:44fb2db84011 | 22 | |
LoRaToolbox | 0:44fb2db84011 | 23 | void txDoneCB() |
LoRaToolbox | 0:44fb2db84011 | 24 | { |
LoRaToolbox | 0:44fb2db84011 | 25 | txDone = true; |
LoRaToolbox | 0:44fb2db84011 | 26 | } |
LoRaToolbox | 0:44fb2db84011 | 27 | |
LoRaToolbox | 0:44fb2db84011 | 28 | void rxDoneCB(uint8_t size, float rssi, float snr) |
LoRaToolbox | 0:44fb2db84011 | 29 | { |
LoRaToolbox | 0:44fb2db84011 | 30 | } |
LoRaToolbox | 0:44fb2db84011 | 31 | |
LoRaToolbox | 0:44fb2db84011 | 32 | const RadioEvents_t rev = { |
LoRaToolbox | 0:44fb2db84011 | 33 | /* Dio0_top_half */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 34 | /* TxDone_topHalf */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 35 | /* TxDone_botHalf */ txDoneCB, |
LoRaToolbox | 0:44fb2db84011 | 36 | /* TxTimeout */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 37 | /* RxDone */ rxDoneCB, |
LoRaToolbox | 0:44fb2db84011 | 38 | /* RxTimeout */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 39 | /* RxError */ NULL, |
LoRaToolbox | 0:44fb2db84011 | 40 | /* FhssChangeChannel */NULL, |
LoRaToolbox | 0:44fb2db84011 | 41 | /* CadDone */ NULL |
LoRaToolbox | 0:44fb2db84011 | 42 | }; |
LoRaToolbox | 0:44fb2db84011 | 43 | |
LoRaToolbox | 0:44fb2db84011 | 44 | int main() |
LoRaToolbox | 0:44fb2db84011 | 45 | { |
LoRaToolbox | 0:44fb2db84011 | 46 | uint8_t seq = 0; |
LoRaToolbox | 0:44fb2db84011 | 47 | |
LoRaToolbox | 0:44fb2db84011 | 48 | printf("\r\nreset-tx "); |
LoRaToolbox | 0:44fb2db84011 | 49 | |
LoRaToolbox | 0:44fb2db84011 | 50 | Radio::Init(&rev); |
LoRaToolbox | 0:44fb2db84011 | 51 | |
LoRaToolbox | 0:44fb2db84011 | 52 | Radio::Standby(); |
LoRaToolbox | 0:44fb2db84011 | 53 | Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1); |
LoRaToolbox | 0:44fb2db84011 | 54 | Radio::SetChannel(CF_HZ); |
LoRaToolbox | 0:44fb2db84011 | 55 | |
LoRaToolbox | 0:44fb2db84011 | 56 | Radio::set_tx_dbm(TX_DBM); |
LoRaToolbox | 0:44fb2db84011 | 57 | |
LoRaToolbox | 0:44fb2db84011 | 58 | // preambleLen, fixLen, crcOn, invIQ |
LoRaToolbox | 0:44fb2db84011 | 59 | Radio::LoRaPacketConfig(8, false, true, false); |
LoRaToolbox | 0:44fb2db84011 | 60 | |
LoRaToolbox | 0:44fb2db84011 | 61 | printf("\n"); |
LoRaToolbox | 0:44fb2db84011 | 62 | |
LoRaToolbox | 0:44fb2db84011 | 63 | printf("%02d \r\n\n", seq); |
LoRaToolbox | 0:44fb2db84011 | 64 | |
LoRaToolbox | 0:44fb2db84011 | 65 | for (;;) { |
LoRaToolbox | 0:44fb2db84011 | 66 | Radio::radio.tx_buf[0] = seq; /* set payload */ |
LoRaToolbox | 0:44fb2db84011 | 67 | txDone = false; |
LoRaToolbox | 0:44fb2db84011 | 68 | Radio::Send(10, 0, 0, 0); /* begin transmission */ |
LoRaToolbox | 0:44fb2db84011 | 69 | |
LoRaToolbox | 0:44fb2db84011 | 70 | //printf("sent\r\n\n"); |
LoRaToolbox | 0:44fb2db84011 | 71 | while (!txDone) { |
LoRaToolbox | 0:44fb2db84011 | 72 | Radio::service(); |
LoRaToolbox | 0:44fb2db84011 | 73 | } |
LoRaToolbox | 0:44fb2db84011 | 74 | |
LoRaToolbox | 0:44fb2db84011 | 75 | //printf("got-tx-done\r\n\n"); |
LoRaToolbox | 0:44fb2db84011 | 76 | |
LoRaToolbox | 0:44fb2db84011 | 77 | wait(0.5); /* throttle sending rate */ |
LoRaToolbox | 0:44fb2db84011 | 78 | seq++; /* change payload */ |
LoRaToolbox | 0:44fb2db84011 | 79 | printf("%02d \r\n\n", seq); |
LoRaToolbox | 0:44fb2db84011 | 80 | |
LoRaToolbox | 0:44fb2db84011 | 81 | |
LoRaToolbox | 0:44fb2db84011 | 82 | } |
LoRaToolbox | 0:44fb2db84011 | 83 | } |