Skip to content

[Bug]: unsigned integer = -20 - SNR based contention window can't work (?) #8430

Description

@korbinianbauer

Hardware

64-bit platforms

Firmware Version

any since the introduction of getCWsize() (?)

Description

I'm on the move and don't have the tools to properly debug this right now, so I might be totally wrong but...

RadioInterface::getCWsize(float snr) uses an unsigned integer type to store a negative number.

IMO this will result in map() always returning the maximum CW size of 8 and no preference for nodes with low SNR.

uint8_t RadioInterface::getCWsize(float snr)
{
    // The minimum value for a LoRa SNR
    const uint32_t SNR_MIN = -20;   //<--- That becomes 4294967276

    // The maximum value for a LoRa SNR
    const uint32_t SNR_MAX = 10;

    return map(snr, SNR_MIN, SNR_MAX, CWmin, CWmax);
}

I tried to recreate the behaviour in an online C++ compiler as a sanity check: https://onlinegdb.com/zTwCkEfEs

Results below.

Relevant log output

CW size for SNR = 10: DEBUG: map() called with inputs:
  x: 10
  in_min: 4294967276
  in_max: 10
  out_min: 3
  out_max: 8
-> 8
CW size for SNR = 5: DEBUG: map() called with inputs:
  x: 5
  in_min: 4294967276
  in_max: 10
  out_min: 3
  out_max: 8
-> 8
CW size for SNR = 0: DEBUG: map() called with inputs:
  x: 0
  in_min: 4294967276
  in_max: 10
  out_min: 3
  out_max: 8
-> 8
CW size for SNR = -5: DEBUG: map() called with inputs:
  x: -5
  in_min: 4294967276
  in_max: 10
  out_min: 3
  out_max: 8
-> 8
CW size for SNR = -10: DEBUG: map() called with inputs:
  x: -10
  in_min: 4294967276
  in_max: 10
  out_min: 3
  out_max: 8
-> 8
CW size for SNR = -15: DEBUG: map() called with inputs:
  x: -15
  in_min: 4294967276
  in_max: 10
  out_min: 3
  out_max: 8
-> 8
CW size for SNR = -20: DEBUG: map() called with inputs:
  x: -20
  in_min: 4294967276
  in_max: 10
  out_min: 3
  out_max: 8
-> 8


...Program finished with exit code 0
Press ENTER to exit console.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions