Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

sn_nsdl.c File Reference

sn_nsdl.c File Reference

Nano service device library. More...

Go to the source code of this file.

Functions

static int32_t sn_nsdl_internal_coap_send (struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr)
 To send NSDL messages.
static void sn_nsdl_resolve_nsp_address (struct nsdl_s *handle)
 Resolves NSP server address.
int8_t sn_nsdl_build_registration_body (struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration)
 To build GRS resources to registration message payload.
static uint16_t sn_nsdl_calculate_registration_body_size (struct nsdl_s *handle, uint8_t updating_registeration, int8_t *error)
 Calculates registration message payload size.
static int8_t sn_nsdl_local_rx_function (struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr)
 If received message is reply for the message that NSDL has been sent, it is processed here.
static int8_t sn_nsdl_resolve_ep_information (struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr)
 Resolves endpoint information from received CoAP message.
int8_t sn_nsdl_destroy (struct nsdl_s *handle)
 This function releases all allocated memory in mbed Device C Client library.
uint16_t sn_nsdl_register_endpoint (struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr, const char *uri_query_parameters)
 Registers endpoint to mbed Device Server.
int32_t sn_nsdl_unregister_endpoint (struct nsdl_s *handle)
 Sends unregister-message to mbed Device Server.
int32_t sn_nsdl_update_registration (struct nsdl_s *handle, uint8_t *lt_ptr, uint8_t lt_len)
 Update the registration with mbed Device Server.
int8_t sn_nsdl_set_endpoint_location (struct nsdl_s *handle, uint8_t *location_ptr, uint8_t location_len)
 Sets the location receievd from Device Server.
void sn_nsdl_nsp_lost (struct nsdl_s *handle)
 A function to inform mbed Device C client library if application detects a fault in mbed Device Server registration.
int8_t sn_nsdl_is_ep_registered (struct nsdl_s *handle)
 Checks if endpoint is registered.
char * sn_nsdl_get_version (void)
 Version query function.
int8_t sn_nsdl_process_coap (struct nsdl_s *handle, uint8_t *packet_ptr, uint16_t packet_len, sn_nsdl_addr_s *src_ptr)
 To push CoAP packet to mbed Device C Client library.
int8_t sn_nsdl_exec (struct nsdl_s *handle, uint32_t time)
 CoAP retransmission function.
int8_t set_NSP_address (struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type)
 This function is used to set the mbed Device Server address given by an application.
int8_t sn_nsdl_send_coap_message (struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr)
 Send an outgoing CoAP request.
int8_t sn_nsdl_handle_block2_response_internally (struct nsdl_s *handle, uint8_t build_response)
 This function change the state whether CoAP library sends the block 2 response automatically or not.
int8_t sn_nsdl_clear_coap_sent_blockwise_messages (struct nsdl_s *handle)
 Clears the sent blockwise messages from the linked list.
sn_coap_hdr_ssn_nsdl_build_response (struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code)
 Prepares generic response packet from a request packet.
sn_coap_options_list_ssn_nsdl_alloc_options_list (struct nsdl_s *handle, sn_coap_hdr_s *coap_msg_ptr)
 Allocates and initializes options list structure.
void sn_nsdl_release_allocated_coap_msg_mem (struct nsdl_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr)
 Releases memory of given CoAP message.
int8_t sn_nsdl_set_retransmission_parameters (struct nsdl_s *handle, uint8_t resending_count, uint8_t resending_interval)
 If re-transmissions are enabled, this function changes resending count and interval.
int8_t sn_nsdl_set_retransmission_buffer (struct nsdl_s *handle, uint8_t buffer_size_messages, uint16_t buffer_size_bytes)
 If re-transmissions are enabled, this function changes message retransmission queue size.
int8_t sn_nsdl_set_block_size (struct nsdl_s *handle, uint16_t block_size)
 If block transfer is enabled, this function changes the block size.
int8_t sn_nsdl_set_duplicate_buffer_size (struct nsdl_s *handle, uint8_t message_count)
 If dublicate message detection is enabled, this function changes buffer size.
void * sn_nsdl_get_context (const struct nsdl_s *const handle)
 Get the application defined context parameter for given handle.
int8_t sn_nsdl_clear_coap_resending_queue (struct nsdl_s *handle)
 Clean confirmable message list.
void sn_nsdl_print_coap_data (sn_coap_hdr_s *coap_header_ptr, bool outgoing)
 Utility function to print all the CoAP header parameters.
uint8_t sn_nsdl_get_retransmission_count (struct nsdl_s *handle)
 Returns retransmission coint.

Detailed Description

Nano service device library.

Definition in file sn_nsdl.c.


Function Documentation

int8_t set_NSP_address ( struct nsdl_s *  handle,
uint8_t *  NSP_address,
uint8_t  address_length,
uint16_t  port,
sn_nsdl_addr_type_e  address_type 
)

This function is used to set the mbed Device Server address given by an application.

Parameters:
*handlePointer to nsdl-library handle
Returns:
0 Success
-1 Failed to indicate that internal address pointer is not allocated (call nsdl_init() first).

Definition at line 1780 of file sn_nsdl.c.

sn_coap_options_list_s* sn_nsdl_alloc_options_list ( struct nsdl_s *  handle,
sn_coap_hdr_s coap_msg_ptr 
)

Allocates and initializes options list structure.

Parameters:
*handlePointer to library handle
*coap_msg_ptris pointer to CoAP message that will contain the options

If the message already has a pointer to an option structure, that pointer is returned, rather than a new structure being allocated.

Returns:
Return value is pointer to the CoAP options structure.
In following failure cases NULL is returned:
-Failure in given pointer (= NULL)
-Failure in memory allocation (malloc() returns NULL)

Definition at line 2045 of file sn_nsdl.c.

int8_t sn_nsdl_build_registration_body ( struct nsdl_s *  handle,
sn_coap_hdr_s message_ptr,
uint8_t  updating_registeration 
)

To build GRS resources to registration message payload.

Parameters:
*handlePointer to nsdl-library handle
*message_ptrPointer to CoAP message header
Returns:
SN_NSDL_SUCCESS = 0, Failed = -1

Definition at line 985 of file sn_nsdl.c.

sn_coap_hdr_s* sn_nsdl_build_response ( struct nsdl_s *  handle,
sn_coap_hdr_s coap_packet_ptr,
uint8_t  msg_code 
)

Prepares generic response packet from a request packet.

This function allocates memory for the resulting sn_coap_hdr_s

Parameters:
*handlePointer to library handle
*coap_packet_ptrThe request packet pointer
msg_coderesponse messages code
Returns:
*coap_packet_ptr The allocated and pre-filled response packet pointer NULL Error in parsing the request

Definition at line 2036 of file sn_nsdl.c.

static uint16_t sn_nsdl_calculate_registration_body_size ( struct nsdl_s *  handle,
uint8_t  updating_registeration,
int8_t *  error 
) [static]

Calculates registration message payload size.

Parameters:
*handlePointer to nsdl-library handle
*updating_registerationPointer to list of GRS resources
*errorError code, SN_NSDL_SUCCESS or SN_NSDL_FAILURE
Returns:
Needed payload size

Definition at line 1187 of file sn_nsdl.c.

int8_t sn_nsdl_clear_coap_resending_queue ( struct nsdl_s *  handle )

Clean confirmable message list.

Parameters:
*handlePointer to library handle
Returns:
0 = success, -1 = failure

Definition at line 2131 of file sn_nsdl.c.

int8_t sn_nsdl_clear_coap_sent_blockwise_messages ( struct nsdl_s *  handle )

Clears the sent blockwise messages from the linked list.

Parameters:
*handlePointer to library handle
Returns:
0 = success, -1 = failure

Definition at line 1922 of file sn_nsdl.c.

int8_t sn_nsdl_destroy ( struct nsdl_s *  handle )

This function releases all allocated memory in mbed Device C Client library.

Parameters:
*handlePointer to nsdl-library handle

Definition at line 133 of file sn_nsdl.c.

int8_t sn_nsdl_exec ( struct nsdl_s *  handle,
uint32_t  time 
)

CoAP retransmission function.

Used to give execution time for the mbed Device C Client library for retransmissions.

Parameters:
*handlePointer to nsdl-library handle
timeTime in seconds.
Returns:
0 Success
-1 Failure

Definition at line 873 of file sn_nsdl.c.

void* sn_nsdl_get_context ( const struct nsdl_s *const   handle )

Get the application defined context parameter for given handle.

This is useful for example when interfacing with c++ objects where a pointer to object is set as the context, and in the callback functions the context pointer can be used to call methods for the correct instance of the c++ object.

Parameters:
*handlePointer to library handle
Returns:
Pointer to the application defined context

Definition at line 2122 of file sn_nsdl.c.

uint8_t sn_nsdl_get_retransmission_count ( struct nsdl_s *  handle )

Returns retransmission coint.

Parameters:
*handlePointer to library handle
Returns:
Retransmission count

Definition at line 2554 of file sn_nsdl.c.

char* sn_nsdl_get_version ( void   )

Version query function.

Used to retrieve the version information from the mbed Device C Client library.

Returns:
Pointer to library version string

Definition at line 684 of file sn_nsdl.c.

int8_t sn_nsdl_handle_block2_response_internally ( struct nsdl_s *  handle,
uint8_t  build_response 
)

This function change the state whether CoAP library sends the block 2 response automatically or not.

Parameters:
*handlePointer to NSDL library handle
handle_response1 if CoAP library handles the response sending otherwise 0.
Returns:
0 = success, -1 = failure

Definition at line 1912 of file sn_nsdl.c.

static int32_t sn_nsdl_internal_coap_send ( struct nsdl_s *  handle,
sn_coap_hdr_s coap_header_ptr,
sn_nsdl_addr_s dst_addr_ptr 
) [static]

To send NSDL messages.

Stores message id?s and message description to catch response from NSP server

Parameters:
*handlePointer to nsdl-library handle
*coap_header_ptrPointer to the CoAP message header to be sent
*dst_addr_ptrPointer to the address structure that contains destination address information
message_descriptionMessage description to be stored to list for waiting response
Returns:
message id, <=0 if failed

Definition at line 905 of file sn_nsdl.c.

int8_t sn_nsdl_is_ep_registered ( struct nsdl_s *  handle )

Checks if endpoint is registered.

Parameters:
*handlePointer to nsdl-library handle
Returns:
1 Endpoint registration is done successfully
0 Endpoint is not registered

Definition at line 518 of file sn_nsdl.c.

static int8_t sn_nsdl_local_rx_function ( struct nsdl_s *  handle,
sn_coap_hdr_s coap_packet_ptr,
sn_nsdl_addr_s address_ptr 
) [static]

If received message is reply for the message that NSDL has been sent, it is processed here.

Else, packet will be sent to application.

Parameters:
*handlePointer to nsdl-library handle
*coap_packet_ptrPointer to received CoAP packet
*address_ptrPointer to source address struct
Returns:
SN_NSDL_SUCCESS = 0, Failed = -1

Definition at line 1632 of file sn_nsdl.c.

void sn_nsdl_nsp_lost ( struct nsdl_s *  handle )

A function to inform mbed Device C client library if application detects a fault in mbed Device Server registration.

Parameters:
*handlePointer to nsdl-library handle

After calling this function sn_nsdl_is_ep_registered() will return "not registered".

Definition at line 508 of file sn_nsdl.c.

void sn_nsdl_print_coap_data ( sn_coap_hdr_s coap_header_ptr,
bool  outgoing 
)

Utility function to print all the CoAP header parameters.

Parameters:
*coap_header_ptrCoAP header
outgoingIf True, package is going to be sent to server otherwise receiving

Definition at line 2274 of file sn_nsdl.c.

int8_t sn_nsdl_process_coap ( struct nsdl_s *  handle,
uint8_t *  packet_ptr,
uint16_t  packet_len,
sn_nsdl_addr_s src_ptr 
)

To push CoAP packet to mbed Device C Client library.

Used to push an CoAP packet to mbed Device C Client library for processing.

Parameters:
*handlePointer to nsdl-library handle
*packetPointer to a uint8_t array containing the packet (including the CoAP headers). After successful execution this array may contain the response packet.
*packet_lenPointer to length of the packet. After successful execution this array may contain the length of the response packet.
*srcPointer to packet source address information. After successful execution this array may contain the destination address of the response packet.
Returns:
0 Success
-1 Failure

Definition at line 695 of file sn_nsdl.c.

uint16_t sn_nsdl_register_endpoint ( struct nsdl_s *  handle,
sn_nsdl_ep_parameters_s endpoint_info_ptr,
const char *  uri_query_parameters 
)

Registers endpoint to mbed Device Server.

Parameters:
*handlePointer to nsdl-library handle
*endpoint_info_ptrContains endpoint information.
*uri_query_parametersUri query parameters.
Returns:
registration message ID, 0 if failed

Definition at line 222 of file sn_nsdl.c.

void sn_nsdl_release_allocated_coap_msg_mem ( struct nsdl_s *  handle,
sn_coap_hdr_s freed_coap_msg_ptr 
)

Releases memory of given CoAP message.

Note!!! Does not release Payload part

Parameters:
*handlePointer to library handle
*freed_coap_msg_ptris pointer to released CoAP message

Definition at line 2053 of file sn_nsdl.c.

static int8_t sn_nsdl_resolve_ep_information ( struct nsdl_s *  handle,
sn_coap_hdr_s coap_packet_ptr 
) [static]

Resolves endpoint information from received CoAP message.

Parameters:
*handlePointer to nsdl-library handle
*coap_packet_ptrPointer to received CoAP message
Returns:
SN_NSDL_SUCCESS = 0, Failed = -1

Definition at line 1724 of file sn_nsdl.c.

static void sn_nsdl_resolve_nsp_address ( struct nsdl_s *  handle ) [static]

Resolves NSP server address.

Parameters:
*handlePointer to nsdl-library handle
Note:
Application must set NSP address with set_nsp_address

Definition at line 951 of file sn_nsdl.c.

int8_t sn_nsdl_send_coap_message ( struct nsdl_s *  handle,
sn_nsdl_addr_s address_ptr,
sn_coap_hdr_s coap_hdr_ptr 
)

Send an outgoing CoAP request.

Parameters:
*handlePointer to nsdl-library handle
*address_ptrPointer to source address struct
*coap_hdr_ptrPointer to CoAP message to be sent
Returns:
0 Success
-1 Failure

Definition at line 1900 of file sn_nsdl.c.

int8_t sn_nsdl_set_block_size ( struct nsdl_s *  handle,
uint16_t  block_size 
)

If block transfer is enabled, this function changes the block size.

Parameters:
*handlePointer to library handle
uint16_tblock_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes
Returns:
0 = success, -1 = failure

Definition at line 2082 of file sn_nsdl.c.

int8_t sn_nsdl_set_duplicate_buffer_size ( struct nsdl_s *  handle,
uint8_t  message_count 
)

If dublicate message detection is enabled, this function changes buffer size.

Parameters:
*handlePointer to library handle
uint8_tmessage_count max number of messages saved for duplicate control
Returns:
0 = success, -1 = failure

Definition at line 2090 of file sn_nsdl.c.

int8_t sn_nsdl_set_endpoint_location ( struct nsdl_s *  handle,
uint8_t *  location_ptr,
uint8_t  location_len 
)

Sets the location receievd from Device Server.

Parameters:
*handlePointer to nsdl-library handle
*lt_ptrPointer to location value string , eg. "s322j4k"
lt_lenLength of the location string
Returns:
success, <0 if failed

Definition at line 494 of file sn_nsdl.c.

int8_t sn_nsdl_set_retransmission_buffer ( struct nsdl_s *  handle,
uint8_t  buffer_size_messages,
uint16_t  buffer_size_bytes 
)

If re-transmissions are enabled, this function changes message retransmission queue size.

Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled.

Parameters:
*handlePointer to library handle
uint8_tbuffer_size_messages queue size - maximum number of messages to be saved to queue
uint8_tbuffer_size_bytes queue size - maximum size of messages saved to queue
Returns:
0 = success, -1 = failure

Definition at line 2072 of file sn_nsdl.c.

int8_t sn_nsdl_set_retransmission_parameters ( struct nsdl_s *  handle,
uint8_t  resending_count,
uint8_t  resending_interval 
)

If re-transmissions are enabled, this function changes resending count and interval.

Parameters:
*handlePointer to library handle
uint8_tresending_count max number of resendings for message
uint8_tresending_intervall message resending intervall in seconds
Returns:
0 = success, -1 = failure

Definition at line 2062 of file sn_nsdl.c.

int32_t sn_nsdl_unregister_endpoint ( struct nsdl_s *  handle )

Sends unregister-message to mbed Device Server.

Parameters:
*handlePointer to nsdl-library handle
Returns:
unregistration message ID, 0 if failed

Definition at line 310 of file sn_nsdl.c.

int32_t sn_nsdl_update_registration ( struct nsdl_s *  handle,
uint8_t *  lt_ptr,
uint8_t  lt_len 
)

Update the registration with mbed Device Server.

Parameters:
*handlePointer to nsdl-library handle
*lt_ptrPointer to lifetime value string in ascii form, eg. "1200"
lt_lenLength of the lifetime string
Returns:
registration update message ID, <0 if failed

Definition at line 385 of file sn_nsdl.c.