rpp0 / gr-lora

GNU Radio blocks for receiving LoRa modulated radio messages using SDR
GNU General Public License v3.0
525 stars 113 forks source link

Add sync words to queue in Encoder! #85

Open wwwzrb opened 5 years ago

wwwzrb commented 5 years ago

` // Add sync words to queue

    uint8_t sync_word = 0x12;
    uint32_t sync_offset_1 = ((sync_word & 0xf0) >> 4) * pow(2, conf.tap.channel.sf) * d_osr / 32;

    uint32_t sync_offset_2 = (sync_word & 0x0f) * pow(2, conf.tap.channel.sf) * d_osr / 32;

    transmit_chirp(true, conf.tap.channel.sf, sync_offset_1);

    transmit_chirp(true, conf.tap.channel.sf, sync_offset_2);`

In the encoder part, I cannot understand why the beginning position for sync_word 0x01 is 1x2^7x8/32=32 and for sync_word 0x02 is 2x2^7x8/32=64 when adding sync word chirp.

The spreading factor is 7 and d_osr is 8. In 1Mhz sampling rate, shouldn't the chirp beginning position of 1 and 2 be 1xd_osr(8) and 2xd_osr(16) respectively?

Backup-Toaster commented 4 years ago

Hey, I'm sure this is long dead, but I thought I would post here for posterity. (This was an issue that held me up for a week!)

I think that this part of the code is a bug. I have replaced the defintions of sync_offset_1 and sync_offset_2 :

uint32_t sync_offset_1 = 8 * ((sync_word & 0xf0) >> 4);
uint32_t sync_offset_2 = 8 * (sync_word & 0x0f);

The inspiration for this actually came from Bastille's gr-lora implementation of the sync symbols. For all spreading factors this will convert 0x12 to produce symbols of 8 and 16.

Now I have tested that this choice of sync word and above code works when transmitted to an SX1301. The sync word itself is derived from the SX1267 transmit packet (through some rather painstaking IQ sample copy and pasting). I believe that some examples from Bastille's implementation use a codeword of 0x18, so perhaps there is some variation in hardware, but 0x12 worked fine for me.

I am working on a pull request that should contain these changes.

rpp0 commented 4 years ago

Hi, are you sure that you correctly configured your SDR? The values stated by the OP assume an OSR of 8. If we make the same assumption about the snippet you provided, only 128 out of the 512 available bins would be used, which does not seem logical to me. The current encoder implementation can send the static packet successfully to a RN2483.

As a concrete example, suppose we have 2^7 = 128 bins and an OSR of 8, then the number of samples per chirp is 1024. Only half of the symbol is actually used (which can be verified by sending 0xff as sync word), so we have 512 samples. Each shift of the sync word shifts the symbol by 32 samples, and we have 16 values. So, 0x00 maps to 0, 0x01 to 32, etc.