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

Wrong definition of COAP_MAX_TRANSMIT_WAIT #220

Closed
vuzunov opened this issue Jan 2, 2017 · 10 comments
Closed

Wrong definition of COAP_MAX_TRANSMIT_WAIT #220

vuzunov opened this issue Jan 2, 2017 · 10 comments

Comments

@vuzunov
Copy link

vuzunov commented Jan 2, 2017

The definition of COAP_MAX_TRANSMIT_WAIT in er-coap.h is wrong.
The caret is a binary XOR and not an operator for power calculation. Probably a pow() function shall be used instead.

@jvermillard
Copy link
Contributor

jvermillard commented Jan 2, 2017

in the CoAP RFC:
ACK_TIMEOUT * ((2 ** (MAX_RETRANSMIT + 1)) - 1) * ACK_RANDOM_FACTOR

in the wakaama code:

#define COAP_MAX_TRANSMIT_WAIT ((COAP_RESPONSE_TIMEOUT * ((2 ^ (COAP_MAX_RETRANSMIT + 1)) - 1) * COAP_ACK_RANDOM_FACTOR))

** was translated into ^ (XOR in C)
I suppose ** mean powerof

@vuzunov
Copy link
Author

vuzunov commented Jan 2, 2017

Indeed, it is 2 to the power of (MAX_RETRANSMIT + 1).

It doesn't really have much of an impact on the correct behavior, since it is only used to guard against registration failure due to datagram loss.

@jvermillard
Copy link
Contributor

Can you review the fix here: #222

@vuzunov
Copy link
Author

vuzunov commented Jan 2, 2017

Thats not quite correct. It has to be something like

#define COAP_MAX_TRANSMIT_WAIT ((COAP_RESPONSE_TIMEOUT * ( pow(2, (COAP_MAX_RETRANSMIT + 1) ) - 1) * COAP_ACK_RANDOM_FACTOR))

And then of course the function pow needs the math.h header included.

@jvermillard
Copy link
Contributor

I did it this way to avoid a dependency on math.h
using (COAP_MAX_RETRANSMIT + 1) * (COAP_MAX_RETRANSMIT + 1) in place of pow(2, (COAP_MAX_RETRANSMIT + 1))

@vuzunov
Copy link
Author

vuzunov commented Jan 2, 2017

That's what I thought too, but its not the same.
(COAP_MAX_RETRANSMIT + 1) * (COAP_MAX_RETRANSMIT + 1) is the same as (COAP_MAX_RETRANSMIT + 1) to the power of 2 and not 2 to the power of (COAP_MAX_RETRANSMIT + 1)

Alternatively a small pow function implementation might be added.

@jvermillard
Copy link
Contributor

jvermillard commented Jan 2, 2017

try 2 using bit shifting

@vuzunov
Copy link
Author

vuzunov commented Jan 2, 2017

That is definitely the more elegant solution 👍

@dnav
Copy link
Contributor

dnav commented Jan 3, 2017

Nice catch @vuzunov. How could I do that ?..
Thanks for the fix @jvermillard

dnav added a commit that referenced this issue Jan 3, 2017
Fix COAP_MAX_TRANSMIT_WAIT value - issue #220
@dnav
Copy link
Contributor

dnav commented Jan 3, 2017

Fixed by #222

@dnav dnav closed this as completed Jan 3, 2017
vslapik pushed a commit to vslapik/wakaama that referenced this issue Apr 20, 2017
vslapik pushed a commit to vslapik/wakaama that referenced this issue Apr 20, 2017
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