Skip to content
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

SetNextChannel can return 0 (immediate go-ahead) to ScheduleTx even if no channels enabled #39

Closed
jmalangoni opened this issue Jan 21, 2016 · 1 comment

Comments

@jmalangoni
Copy link

LoRaMac.c static TimerTime_t SetNextChannel( void ) returns 0 even if no channels are supported, if nextTxDelay is never assigned a value after initialization:

    if( nbEnabledChannels > 0 )
    {
        Channel = enabledChannels[randr( 0, nbEnabledChannels - 1 )];
#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
        DisableChannelInMask( Channel, ChannelsMaskRemaining );
#endif
        return 0;
    }
    else
    {
        // Protect the function of returning the initialization value of nextTxDelay
        return ( nextTxDelay == ( TimerTime_t )( -1 ) ) ? 0 : nextTxDelay;
    }

But if .TimeOff of all bands == 0 in the following...

// Update Aggregated duty cycle
    if( AggregatedTimeOff < ( curTime - AggregatedLastTxDoneTime ) )
    {
        AggregatedTimeOff = 0;

        // Update bands Time OFF
        for( uint8_t i = 0; i < LORA_MAX_NB_BANDS; i++ )
        {
            if( DutyCycleOn == true )
            {
                if( Bands[i].TimeOff < ( curTime - Bands[i].LastTxDoneTime ) )
                {
                    Bands[i].TimeOff = 0;
                }
                if( Bands[i].TimeOff != 0 )
                {
                    nextTxDelay = MIN( Bands[i].TimeOff -
                                       ( curTime - Bands[i].LastTxDoneTime ),
                                       nextTxDelay );
                }
            }
            else
            {
                nextTxDelay = 0;
                Bands[i].TimeOff = 0;
            }
        }

...then nextTxDelay == ( TimerTime_t )( -1 ), and if nbEnabledChannels == 0, the function returns 0. This is problematic since ScheduleTx then calls SendFrameOnChannel using the current Channel value, even though no channels are currently enabled.

One quick fix would be for SetNextChannel to return ( TimerTime_t )( -1 ), and then have ScheduleTx check for this as an error. Any problems with this?

@djaeckle
Copy link

Hi jmalangoni,

thanks for the report. I see your point. We will provide an update in the next release. I'm not sure yet, which solution we apply. But I think your quick fix should work.

@mluis1 mluis1 closed this as completed Mar 11, 2016
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

3 participants