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

Get uint value from option #22

Merged
merged 1 commit into from
Nov 27, 2017

Conversation

NZSmartie
Copy link
Contributor

A Simple feature to store the uint value of an CoAP_option_t into a pointer argument

@niondir
Copy link
Member

niondir commented Nov 27, 2017

So thanks for the PR. Looks straight forward.

May I ask where you needed this? - Just for the purpose of documentation here :)

@niondir niondir merged commit 4a8087d into lobaro:master Nov 27, 2017
@NZSmartie
Copy link
Contributor Author

I use it in a request callback to quickly get the Accept option value and check if the client accepts support content types.
main/resources/leds.c:71:

_coap.message_get_option( request, kCoapOptionAccept, &accept_option );
    while( accept_option != NULL )
    {
        if( _coap.option_get_uint( accept_option, &accept ) != kCoapOK )
            break;
        if( accept == kCoapContentTypeApplicationJson )
            break;
        
        if( _coap.option_get_next( &accept_option ) != kCoapOK )
            break;
}

main/interfaces/lobaro-coap.c:429:

static CoapResult_t coap_option_get_uint( const CoapOption_t option, uint32_t* value )
{
    return CoAP_GetUintFromOption( option, value ) == COAP_OK ? kCoapOK : kCoapError;
}

main/interfaces/lobaro-coap.c:401:

static CoapResult_t coap_message_get_option( const CoapMessage_t message, const uint16_t option_number, CoapOption_t *option ){
    const CoAP_Message_t *pMsg = (CoAP_Message_t*)message;
    *option = NULL;

    CoAP_option_t *pOpt = CoAP_FindOptionByNumber( (CoAP_Message_t*)pMsg, option_number );
    if( pOpt == NULL )
        return kCoapError;

    *option = (CoapOption_t)pOpt;
    return kCoapOK;
}

@NZSmartie NZSmartie deleted the feature/GetUintFromOption branch November 28, 2017 02:57
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

Successfully merging this pull request may close these issues.

2 participants