Skip to content

SX1276 radio: reported SNR is wrong #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dbarthel-ol opened this issue Jul 5, 2016 · 4 comments
Closed

SX1276 radio: reported SNR is wrong #104

dbarthel-ol opened this issue Jul 5, 2016 · 4 comments

Comments

@dbarthel-ol
Copy link

dbarthel-ol commented Jul 5, 2016

The SX1276 radio chip has a register containing the SNR after frame reception. This register value must be divided by 4 (taking sign into account) to yield the real SNR value in dB. This is correctly computed in src/radio/sx1276/sx1276.c and temporarily stored in the snr variable (around lines 1505-1516), but the result is not stored back into SX1276.Settings.LoRaPacketHandler.SnrValue. Therefore upper layers get an incorrect value.
I will provide a pull request for that.
I suspect SX1272 is affected similarly.

@Mobiak
Copy link

Mobiak commented Jul 5, 2016

As I agree with you, this issue already came up in issue #75.

@mluis1
Copy link
Contributor

mluis1 commented Jul 5, 2016

Thanks for your comments. But as already answered in issue #75 the current implementation is correct according to the LoRaWAN specification.

What we usually do is to perform the conversion to dB in the main application as shown in the example below.

static void McpsIndication( McpsIndication_t *mcpsIndication )
{
    if( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK )
    {
        return;
    }

    switch( mcpsIndication->McpsIndication )
    {
        case MCPS_UNCONFIRMED:
        {
            break;
        }
        case MCPS_CONFIRMED:
        {
            break;
        }
        case MCPS_PROPRIETARY:
        {
            break;
        }
        case MCPS_MULTICAST:
        {
            break;
        }
        default:
            break;
    }

    // Check Multicast
    // Check Port
    // Check Datarate
    // Check FramePending
    // Check Buffer
    // Check BufferSize
    // Check Rssi
    // Check Snr
    // Check RxSlot
    LoRaMacDownlinkStatus.Rssi = mcpsIndication->Rssi;
    if( mcpsIndication->Snr & 0x80 ) // The SNR sign bit is 1
    {
        // Invert and divide by 4
        LoRaMacDownlinkStatus.Snr = ( ( ~mcpsIndication->Snr + 1 ) & 0xFF ) >> 2;
        LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr;
    }
    else
    {
        // Divide by 4
        LoRaMacDownlinkStatus.Snr = ( mcpsIndication->Snr & 0xFF ) >> 2;
    }
    LoRaMacDownlinkStatus.DownlinkCounter++;
    LoRaMacDownlinkStatus.RxData = mcpsIndication->RxData;
    LoRaMacDownlinkStatus.Port = mcpsIndication->Port;
    LoRaMacDownlinkStatus.Buffer = mcpsIndication->Buffer;
    LoRaMacDownlinkStatus.BufferSize = mcpsIndication->BufferSize;

    if( ComplianceTest.Running == true )
    {
        ComplianceTest.DownLinkCounter++;
    }

    if( mcpsIndication->RxData == true )
    {
...
}

@shpasser
Copy link

According to the data sheet of sx1276 the SNR value read from the device register is in twos complement format, why not just divide the value by 4?

@zxl-ben
Copy link

zxl-ben commented Jun 24, 2017

@shpasser As I agree with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants