Simulated product dispenser

Dependencies:   HTS221

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

Committer:
JimCarver
Date:
Thu Oct 25 14:00:12 2018 +0000
Revision:
4:e518dde96e59
Parent:
0:6b753f761943
Simulated dispenser

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimCarver 0:6b753f761943 1 /*
JimCarver 0:6b753f761943 2 * Copyright (c) 2011-2015 ARM Limited. All rights reserved.
JimCarver 0:6b753f761943 3 * SPDX-License-Identifier: Apache-2.0
JimCarver 0:6b753f761943 4 * Licensed under the Apache License, Version 2.0 (the License); you may
JimCarver 0:6b753f761943 5 * not use this file except in compliance with the License.
JimCarver 0:6b753f761943 6 * You may obtain a copy of the License at
JimCarver 0:6b753f761943 7 *
JimCarver 0:6b753f761943 8 * http://www.apache.org/licenses/LICENSE-2.0
JimCarver 0:6b753f761943 9 *
JimCarver 0:6b753f761943 10 * Unless required by applicable law or agreed to in writing, software
JimCarver 0:6b753f761943 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
JimCarver 0:6b753f761943 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JimCarver 0:6b753f761943 13 * See the License for the specific language governing permissions and
JimCarver 0:6b753f761943 14 * limitations under the License.
JimCarver 0:6b753f761943 15 */
JimCarver 0:6b753f761943 16
JimCarver 0:6b753f761943 17 /**
JimCarver 0:6b753f761943 18 * \file sn_coap_protocol.h
JimCarver 0:6b753f761943 19 *
JimCarver 0:6b753f761943 20 * \brief CoAP C-library User protocol interface header file
JimCarver 0:6b753f761943 21 */
JimCarver 0:6b753f761943 22
JimCarver 0:6b753f761943 23 #ifdef __cplusplus
JimCarver 0:6b753f761943 24 extern "C" {
JimCarver 0:6b753f761943 25 #endif
JimCarver 0:6b753f761943 26
JimCarver 0:6b753f761943 27 #ifndef SN_COAP_PROTOCOL_H_
JimCarver 0:6b753f761943 28 #define SN_COAP_PROTOCOL_H_
JimCarver 0:6b753f761943 29
JimCarver 0:6b753f761943 30 #include "sn_coap_header.h"
JimCarver 0:6b753f761943 31
JimCarver 0:6b753f761943 32 /**
JimCarver 0:6b753f761943 33 * \fn struct coap_s *sn_coap_protocol_init(void* (*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void*),
JimCarver 0:6b753f761943 34 uint8_t (*used_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *),
JimCarver 0:6b753f761943 35 int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *)
JimCarver 0:6b753f761943 36 *
JimCarver 0:6b753f761943 37 * \brief Initializes CoAP Protocol part. When using libNsdl, sn_nsdl_init() calls this function.
JimCarver 0:6b753f761943 38 *
JimCarver 0:6b753f761943 39 * \param *used_malloc_func_ptr is function pointer for used memory allocation function.
JimCarver 0:6b753f761943 40 *
JimCarver 0:6b753f761943 41 * \param *used_free_func_ptr is function pointer for used memory free function.
JimCarver 0:6b753f761943 42 *
JimCarver 0:6b753f761943 43 * \param *used_tx_callback_ptr function callback pointer to tx function for sending coap messages
JimCarver 0:6b753f761943 44 *
JimCarver 0:6b753f761943 45 * \param *used_rx_callback_ptr used to return CoAP header struct with status COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED
JimCarver 0:6b753f761943 46 * when re-sendings exceeded. If set to NULL, no error message is returned.
JimCarver 0:6b753f761943 47 *
JimCarver 0:6b753f761943 48 * \return Pointer to handle when success
JimCarver 0:6b753f761943 49 * Null if failed
JimCarver 0:6b753f761943 50 */
JimCarver 0:6b753f761943 51
JimCarver 0:6b753f761943 52 extern struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *),
JimCarver 0:6b753f761943 53 uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *),
JimCarver 0:6b753f761943 54 int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *));
JimCarver 0:6b753f761943 55
JimCarver 0:6b753f761943 56 /**
JimCarver 0:6b753f761943 57 * \fn int8_t sn_coap_protocol_destroy(void)
JimCarver 0:6b753f761943 58 *
JimCarver 0:6b753f761943 59 * \brief Frees all memory from CoAP protocol part
JimCarver 0:6b753f761943 60 *
JimCarver 0:6b753f761943 61 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 62 *
JimCarver 0:6b753f761943 63 * \return Return value is always 0
JimCarver 0:6b753f761943 64 */
JimCarver 0:6b753f761943 65 extern int8_t sn_coap_protocol_destroy(struct coap_s *handle);
JimCarver 0:6b753f761943 66
JimCarver 0:6b753f761943 67 /**
JimCarver 0:6b753f761943 68 * \fn int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, void *param)
JimCarver 0:6b753f761943 69 *
JimCarver 0:6b753f761943 70 * \brief Builds Packet data from given CoAP header structure to be sent
JimCarver 0:6b753f761943 71 *
JimCarver 0:6b753f761943 72 * \param *dst_addr_ptr is pointer to destination address where CoAP message
JimCarver 0:6b753f761943 73 * will be sent (CoAP builder needs that information for message resending purposes)
JimCarver 0:6b753f761943 74 *
JimCarver 0:6b753f761943 75 * \param *dst_packet_data_ptr is pointer to destination of built Packet data
JimCarver 0:6b753f761943 76 *
JimCarver 0:6b753f761943 77 * \param *src_coap_msg_ptr is pointer to source of built Packet data
JimCarver 0:6b753f761943 78 *
JimCarver 0:6b753f761943 79 * \param param void pointer that will be passed to tx/rx function callback when those are called.
JimCarver 0:6b753f761943 80 *
JimCarver 0:6b753f761943 81 * \return Return value is byte count of built Packet data.\n
JimCarver 0:6b753f761943 82 * Note: If message is blockwised, all payload is not sent at the same time\n
JimCarver 0:6b753f761943 83 * In failure cases:\n
JimCarver 0:6b753f761943 84 * -1 = Failure in CoAP header structure\n
JimCarver 0:6b753f761943 85 * -2 = Failure in given pointer (= NULL)\n
JimCarver 0:6b753f761943 86 * -3 = Failure in Reset message\n
JimCarver 0:6b753f761943 87 * -4 = Failure in Resending message store\n
JimCarver 0:6b753f761943 88 * If there is not enough memory (or User given limit exceeded) for storing
JimCarver 0:6b753f761943 89 * resending messages, situation is ignored.
JimCarver 0:6b753f761943 90 */
JimCarver 0:6b753f761943 91 extern int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, void *param);
JimCarver 0:6b753f761943 92
JimCarver 0:6b753f761943 93 /**
JimCarver 0:6b753f761943 94 * \fn sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr, uint16_t packet_data_len, uint8_t *packet_data_ptr)
JimCarver 0:6b753f761943 95 *
JimCarver 0:6b753f761943 96 * \brief Parses received CoAP message from given Packet data
JimCarver 0:6b753f761943 97 *
JimCarver 0:6b753f761943 98 * \param *src_addr_ptr is pointer to source address of received CoAP message
JimCarver 0:6b753f761943 99 * (CoAP parser needs that information for Message acknowledgement)
JimCarver 0:6b753f761943 100 *
JimCarver 0:6b753f761943 101 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 102 *
JimCarver 0:6b753f761943 103 * \param packet_data_len is length of given Packet data to be parsed to CoAP message
JimCarver 0:6b753f761943 104 *
JimCarver 0:6b753f761943 105 * \param *packet_data_ptr is pointer to source of Packet data to be parsed to CoAP message
JimCarver 0:6b753f761943 106 *
JimCarver 0:6b753f761943 107 * \param param void pointer that will be passed to tx/rx function callback when those are called.
JimCarver 0:6b753f761943 108 *
JimCarver 0:6b753f761943 109 * \return Return value is pointer to parsed CoAP message structure. This structure includes also coap_status field.\n
JimCarver 0:6b753f761943 110 * In following failure cases NULL is returned:\n
JimCarver 0:6b753f761943 111 * -Given NULL pointer\n
JimCarver 0:6b753f761943 112 * -Failure in parsed header of non-confirmable message\ŋ
JimCarver 0:6b753f761943 113 * -Out of memory (malloc() returns NULL)
JimCarver 0:6b753f761943 114 */
JimCarver 0:6b753f761943 115 extern sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr, uint16_t packet_data_len, uint8_t *packet_data_ptr, void *);
JimCarver 0:6b753f761943 116
JimCarver 0:6b753f761943 117 /**
JimCarver 0:6b753f761943 118 * \fn int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time)
JimCarver 0:6b753f761943 119 *
JimCarver 0:6b753f761943 120 * \brief Sends CoAP messages from re-sending queue, if there is any.
JimCarver 0:6b753f761943 121 * Cleans also old messages from the duplication list and from block receiving list
JimCarver 0:6b753f761943 122 *
JimCarver 0:6b753f761943 123 * This function can be called e.g. once in a second but also more frequently.
JimCarver 0:6b753f761943 124 *
JimCarver 0:6b753f761943 125 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 126 *
JimCarver 0:6b753f761943 127 * \param current_time is System time in seconds. This time is
JimCarver 0:6b753f761943 128 * used for message re-sending timing and to identify old saved data.
JimCarver 0:6b753f761943 129 *
JimCarver 0:6b753f761943 130 * \return 0 if success
JimCarver 0:6b753f761943 131 * -1 if failed
JimCarver 0:6b753f761943 132 */
JimCarver 0:6b753f761943 133
JimCarver 0:6b753f761943 134 extern int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time);
JimCarver 0:6b753f761943 135
JimCarver 0:6b753f761943 136 /**
JimCarver 0:6b753f761943 137 * \fn int8_t sn_coap_protocol_set_block_size(uint16_t block_size)
JimCarver 0:6b753f761943 138 *
JimCarver 0:6b753f761943 139 * \brief If block transfer is enabled, this function changes the block size.
JimCarver 0:6b753f761943 140 *
JimCarver 0:6b753f761943 141 * \param uint16_t block_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes
JimCarver 0:6b753f761943 142 * \return 0 = success
JimCarver 0:6b753f761943 143 * -1 = failure
JimCarver 0:6b753f761943 144 */
JimCarver 0:6b753f761943 145 extern int8_t sn_coap_protocol_set_block_size(struct coap_s *handle, uint16_t block_size);
JimCarver 0:6b753f761943 146
JimCarver 0:6b753f761943 147 /**
JimCarver 0:6b753f761943 148 * \fn int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count)
JimCarver 0:6b753f761943 149 *
JimCarver 0:6b753f761943 150 * \brief If dublicate message detection is enabled, this function changes buffer size.
JimCarver 0:6b753f761943 151 *
JimCarver 0:6b753f761943 152 * \param uint8_t message_count max number of messages saved for duplicate control
JimCarver 0:6b753f761943 153 * \return 0 = success
JimCarver 0:6b753f761943 154 * -1 = failure
JimCarver 0:6b753f761943 155 */
JimCarver 0:6b753f761943 156 extern int8_t sn_coap_protocol_set_duplicate_buffer_size(struct coap_s *handle, uint8_t message_count);
JimCarver 0:6b753f761943 157
JimCarver 0:6b753f761943 158 /**
JimCarver 0:6b753f761943 159 * \fn int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_intervall)
JimCarver 0:6b753f761943 160 *
JimCarver 0:6b753f761943 161 * \brief If re-transmissions are enabled, this function changes resending count and interval.
JimCarver 0:6b753f761943 162 *
JimCarver 0:6b753f761943 163 * \param uint8_t resending_count max number of resendings for message
JimCarver 0:6b753f761943 164 * \param uint8_t resending_intervall message resending intervall in seconds
JimCarver 0:6b753f761943 165 * \return 0 = success, -1 = failure
JimCarver 0:6b753f761943 166 */
JimCarver 0:6b753f761943 167 extern int8_t sn_coap_protocol_set_retransmission_parameters(struct coap_s *handle,
JimCarver 0:6b753f761943 168 uint8_t resending_count, uint8_t resending_interval);
JimCarver 0:6b753f761943 169
JimCarver 0:6b753f761943 170 /**
JimCarver 0:6b753f761943 171 * \fn int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes)
JimCarver 0:6b753f761943 172 *
JimCarver 0:6b753f761943 173 * \brief If re-transmissions are enabled, this function changes message retransmission queue size.
JimCarver 0:6b753f761943 174 * Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled.
JimCarver 0:6b753f761943 175 *
JimCarver 0:6b753f761943 176 * \param uint8_t buffer_size_messages queue size - maximum number of messages to be saved to queue
JimCarver 0:6b753f761943 177 * \param uint8_t buffer_size_bytes queue size - maximum size of messages saved to queue
JimCarver 0:6b753f761943 178 * \return 0 = success, -1 = failure
JimCarver 0:6b753f761943 179 */
JimCarver 0:6b753f761943 180 extern int8_t sn_coap_protocol_set_retransmission_buffer(struct coap_s *handle,
JimCarver 0:6b753f761943 181 uint8_t buffer_size_messages, uint16_t buffer_size_bytes);
JimCarver 0:6b753f761943 182
JimCarver 0:6b753f761943 183 /**
JimCarver 0:6b753f761943 184 * \fn void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle)
JimCarver 0:6b753f761943 185 *
JimCarver 0:6b753f761943 186 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 187 *
JimCarver 0:6b753f761943 188 * \brief If re-transmissions are enabled, this function removes all messages from the retransmission queue.
JimCarver 0:6b753f761943 189 */
JimCarver 0:6b753f761943 190 extern void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle);
JimCarver 0:6b753f761943 191
JimCarver 0:6b753f761943 192 /**
JimCarver 0:6b753f761943 193 * \fn sn_coap_protocol_block_remove
JimCarver 0:6b753f761943 194 *
JimCarver 0:6b753f761943 195 * \brief Remove saved block data. Can be used to remove the data from RAM to enable storing it to other place.
JimCarver 0:6b753f761943 196 *
JimCarver 0:6b753f761943 197 * \param handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 198 * \param source_address Addres from where the block has been received.
JimCarver 0:6b753f761943 199 * \param payload_length Length of the coap payload of the block.
JimCarver 0:6b753f761943 200 * \param payload Coap payload of the block.
JimCarver 0:6b753f761943 201 *
JimCarver 0:6b753f761943 202 */
JimCarver 0:6b753f761943 203 extern void sn_coap_protocol_block_remove(struct coap_s *handle, sn_nsdl_addr_s *source_address, uint16_t payload_length, void *payload);
JimCarver 0:6b753f761943 204
JimCarver 0:6b753f761943 205 /**
JimCarver 0:6b753f761943 206 * \fn sn_coap_protocol_remove_sent_blockwise_message
JimCarver 0:6b753f761943 207 *
JimCarver 0:6b753f761943 208 * \brief Remove sent blockwise message from the linked list.
JimCarver 0:6b753f761943 209 *
JimCarver 0:6b753f761943 210 * \param handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 211 * \param message_id Message id to be removed.
JimCarver 0:6b753f761943 212 *
JimCarver 0:6b753f761943 213 */
JimCarver 0:6b753f761943 214 extern void sn_coap_protocol_remove_sent_blockwise_message(struct coap_s *handle, uint16_t message_id);
JimCarver 0:6b753f761943 215
JimCarver 0:6b753f761943 216 /**
JimCarver 0:6b753f761943 217 * \fn void sn_coap_protocol_delete_retransmission(struct coap_s *handle)
JimCarver 0:6b753f761943 218 *
JimCarver 0:6b753f761943 219 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 220 * \msg_id message ID to be removed
JimCarver 0:6b753f761943 221 * \return returns 0 when success, -1 for invalid parameter, -2 if message was not found
JimCarver 0:6b753f761943 222 *
JimCarver 0:6b753f761943 223 * \brief If re-transmissions are enabled, this function removes message from retransmission buffer.
JimCarver 0:6b753f761943 224 */
JimCarver 0:6b753f761943 225 extern int8_t sn_coap_protocol_delete_retransmission(struct coap_s *handle, uint16_t msg_id);
JimCarver 0:6b753f761943 226
JimCarver 0:6b753f761943 227 /**
JimCarver 0:6b753f761943 228 * \fn int8_t sn_coap_convert_block_size(uint16_t block_size)
JimCarver 0:6b753f761943 229 *
JimCarver 0:6b753f761943 230 * \brief Utility function to convert block size.
JimCarver 0:6b753f761943 231 *
JimCarver 0:6b753f761943 232 * \param block_size Block size to convert.
JimCarver 0:6b753f761943 233 *
JimCarver 0:6b753f761943 234 * \return Value of range 0 - 6
JimCarver 0:6b753f761943 235 */
JimCarver 0:6b753f761943 236 extern int8_t sn_coap_convert_block_size(uint16_t block_size);
JimCarver 0:6b753f761943 237
JimCarver 0:6b753f761943 238 /**
JimCarver 0:6b753f761943 239 * \fn int8_t sn_coap_protocol_handle_block2_response_internally(struct coap_s *handle, uint8_t handle_response)
JimCarver 0:6b753f761943 240 *
JimCarver 0:6b753f761943 241 * \brief This function change the state whether CoAP library sends the block 2 response automatically or not.
JimCarver 0:6b753f761943 242 *
JimCarver 0:6b753f761943 243 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 244 * \param handle_response 1 if CoAP library handles the response sending otherwise 0.
JimCarver 0:6b753f761943 245 *
JimCarver 0:6b753f761943 246 * \return 0 = success, -1 = failure
JimCarver 0:6b753f761943 247 */
JimCarver 0:6b753f761943 248 extern int8_t sn_coap_protocol_handle_block2_response_internally(struct coap_s *handle, uint8_t handle_response);
JimCarver 0:6b753f761943 249
JimCarver 0:6b753f761943 250 /**
JimCarver 0:6b753f761943 251 * \fn void sn_coap_protocol_clear_sent_blockwise_messages(struct coap_s *handle)
JimCarver 0:6b753f761943 252 *
JimCarver 0:6b753f761943 253 * \brief This function clears all the sent blockwise messages from the linked list.
JimCarver 0:6b753f761943 254 *
JimCarver 0:6b753f761943 255 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 256 */
JimCarver 0:6b753f761943 257 extern void sn_coap_protocol_clear_sent_blockwise_messages(struct coap_s *handle);
JimCarver 0:6b753f761943 258
JimCarver 0:6b753f761943 259 /**
JimCarver 0:6b753f761943 260 * \fn void sn_coap_protocol_send_rst(struct coap_s *handle, uint16_t msg_id, sn_nsdl_addr_s *addr_ptr, void *param)
JimCarver 0:6b753f761943 261 *
JimCarver 0:6b753f761943 262 * \brief This function sends a RESET message.
JimCarver 0:6b753f761943 263 *
JimCarver 0:6b753f761943 264 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 265 * \param msg_id Message id.
JimCarver 0:6b753f761943 266 * \param addr_ptr Pointer to destination address where CoAP message will be sent
JimCarver 0:6b753f761943 267 * \param param Pointer that will be passed to tx function callback
JimCarver 0:6b753f761943 268 */
JimCarver 0:6b753f761943 269 extern void sn_coap_protocol_send_rst(struct coap_s *handle, uint16_t msg_id, sn_nsdl_addr_s *addr_ptr, void *param);
JimCarver 0:6b753f761943 270
JimCarver 0:6b753f761943 271 /**
JimCarver 0:6b753f761943 272 * \fn uint16_t sn_coap_protocol_get_configured_blockwise_size(struct coap_s *handle)
JimCarver 0:6b753f761943 273 *
JimCarver 0:6b753f761943 274 * \brief Get configured CoAP payload blockwise size
JimCarver 0:6b753f761943 275 *
JimCarver 0:6b753f761943 276 * \param *handle Pointer to CoAP library handle
JimCarver 0:6b753f761943 277 */
JimCarver 0:6b753f761943 278 extern uint16_t sn_coap_protocol_get_configured_blockwise_size(struct coap_s *handle);
JimCarver 0:6b753f761943 279
JimCarver 0:6b753f761943 280 #endif /* SN_COAP_PROTOCOL_H_ */
JimCarver 0:6b753f761943 281
JimCarver 0:6b753f761943 282 #ifdef __cplusplus
JimCarver 0:6b753f761943 283 }
JimCarver 0:6b753f761943 284 #endif