Skip to content

Error in function that maps channel to frequency for non-advertising channels #10

Description

@andyparkins
uint8_t channel_resolver_get_frequency(uint8_t channel)
{
   // ...
    freq = channel + (channel < 11 ? 2 : 3) * 2; // Spec Vol. 6, Part B, 1.4.1

    return freq;
}

I think this is missing braces. The function returns different results from the referenced table in 6.B.1.4.1.

For example: channel 36 should be 2478MHz. The above equation returns 36 + 3*2 = 42 (which becomes 2042MHz not 2478MHz in the radio peripheral).

I suspect the issue is simply the slight thinko of a missing pair of parenthises:

freq = (channel + (channel < 11 ? 2 : 3)) * 2; // Spec Vol. 6, Part B, 1.4.1

Some test points:

  • channel 0 maps to (0+2)*2 = 4. Correct.
  • channel 10 maps to (10+2)*2 = 24. Correct.
  • channel 11 maps to (11+3)*2 = 28. Correct.
  • channel 36 maps to (36+3)*2 = 78. Correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions