2017-05-18 01:10 PM
In I-CUBE-LRWAN V1.1.0 RegionCommon.c there's a function that returns the next duty cycle delay as follows:
TimerTime_t RegionCommonUpdateBandTimeOff( bool dutyCycle, Band_t* bands, uint8_t nbBands )
{ TimerTime_t nextTxDelay = ( TimerTime_t )( -1 );// Update bands Time OFF
for( uint8_t i = 0; i < nbBands; i++ ) { if( dutyCycle == true ) { if( bands[i].TimeOff <= TimerGetElapsedTime( bands[i].LastTxDoneTime ) ) {bands[i].TimeOff = 0;
} if( bands[i].TimeOff != 0 ) { nextTxDelay = MIN( bands[i].TimeOff - TimerGetElapsedTime( bands[i].LastTxDoneTime ), nextTxDelay ); } } else { nextTxDelay = 0; bands[i].TimeOff = 0; } } return nextTxDelay;}
This compares the period between the last transmission for the band and now with the duty cycle timeoff period, returning the next transmission delay period to comply with the duty cycle.
TimerTime_t is a 32 bit unsigned integer
So the first line
TimerTime_t nextTxDelay = ( TimerTime_t )( -1 );
casts a signed to an unsigned integer, effectively setting it to a very large number 0xFFFFFFFF i.e. a huge delay.
So my question is, is that intentional? If so, for what purpose, how does it work? I would like to understand this code better.
Many thanks in advance, Ron.
Solved! Go to Solution.
2017-05-20 08:57 PM
Yes, so either there or in the original routine you should return 0 when the MIN() value is still 0xFFFFFFFF
Then the 100% duty case should schedule the transmission immediately.
2017-05-18 01:38 PM
Isn't it a way of indicating there are no usable entries in the table? Looks to be a purposeful setting of a maximal value (size agnostic)
2017-05-18 04:01 PM
Thanks Clive for responding so quickly. Yes, I agree it doesn't look like a typo. What you suggest could make sense if the very large value was being conditionally checked downstream, which I haven't seen (in any case a horrible way to flag a table entry!).
Although I haven't been able to trace the behaviour right through properly, it looks like that value is being used to setup a transmission delay timer. When a 100% duty cycle is configured for band 0 (IN865 region, which has a single band), the MAC seems to get stuck forever in a transmission delayed state (16).
2017-05-18 06:41 PM
It's clearly constructed to allow for downstream code to catch the empty list, or no usable values, whether it does so is a whole other matter.
There's quite a lot of egregious code in I-CUBE-LRWAN, stuff that blocks, interrupt priorities backarseward, etc.
I'll browse this path later, I'm mainly building pingers and listeners at the moment, in the 902-928 MHz band.
2017-05-18 07:00 PM
Hi Clive, thanks again. The stack is certainly convoluted to trace through.
The Aussie 915MHz band, regional code seems to work ok, pretty similar to the USA region and a lot less complex than EU868, which the IN865 region profile is based upon. I was really hoping to use IN865 'out of the box', apart from some simple frequency changes to suit KotahiNet (kotahi.net) in New Zealand, which uses the 864 to 870 MHz ISM band (there's also a 915 MHz ISM band available, similar to Aus). Typically though it doesn't seem to be panning out so easily! We've developed several LoRaWAN sensor monitoring end devices, with good success so far. Do please let me know if you get a chance to work your way through more of the stack and find anything interesting. Cheers, Ron.
2017-05-18 10:04 PM
ScheduleTx() in LoRaMac.c needs to pick some default, it takes zero as 'now'. It needs to constrain the maximum by checking the (-1) value, and either pick some default delay or send immediately.
2017-05-20 01:07 AM
Hi Clive. So this is missing logic? Currently in ScheduleTx there is no test for 0xFFFFFFFF (-1) then do something sensible, rather dutyCycleTimeOff is being set to 0xFFFFFFFF (as shown by a PRINTF %lu statement), so transmission is effectively delayed forever!
2017-05-20 08:57 PM
Yes, so either there or in the original routine you should return 0 when the MIN() value is still 0xFFFFFFFF
Then the 100% duty case should schedule the transmission immediately.
2017-05-20 09:05 PM
Right, so absence of that logic is effectively a bug.