Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
sn_grs.h
00001 /* 00002 * Copyright (c) 2011-2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef GRS_H_ 00017 #define GRS_H_ 00018 00019 00020 #ifdef __cplusplus 00021 extern "C" { 00022 #endif 00023 00024 00025 #define SN_GRS_RESOURCE_ALREADY_EXISTS -2 00026 #define SN_GRS_INVALID_PATH -3 00027 #define SN_GRS_LIST_ADDING_FAILURE -4 00028 #define SN_GRS_RESOURCE_UPDATED -5 00029 00030 #define ACCESS_DENIED -6 00031 00032 #define SN_GRS_DELETE_METHOD 0 00033 #define SN_GRS_SEARCH_METHOD 1 00034 00035 #define SN_GRS_DEFAULT_ACCESS 0x0F 00036 00037 #define SN_NDSL_RESOURCE_NOT_REGISTERED 0 00038 #define SN_NDSL_RESOURCE_REGISTERING 1 00039 #define SN_NDSL_RESOURCE_REGISTERED 2 00040 00041 /***** Structs *****/ 00042 00043 typedef struct sn_grs_version_ { 00044 uint8_t major_version; 00045 uint8_t minor_version; 00046 uint8_t build; 00047 } sn_grs_version_s; 00048 00049 typedef NS_LIST_HEAD(sn_nsdl_dynamic_resource_parameters_s, link) resource_list_t; 00050 00051 struct grs_s { 00052 struct coap_s *coap; 00053 00054 void *(*sn_grs_alloc)(uint16_t); 00055 void (*sn_grs_free)(void *); 00056 uint8_t (*sn_grs_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); 00057 int8_t (*sn_grs_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); 00058 00059 uint16_t resource_root_count; 00060 resource_list_t resource_root_list; 00061 }; 00062 00063 00064 struct nsdl_s { 00065 uint32_t update_register_token; 00066 uint32_t register_token; 00067 uint32_t unregister_token; 00068 uint32_t bootstrap_token; 00069 uint32_t token_seed; 00070 unsigned int sn_nsdl_endpoint_registered:1; 00071 unsigned int is_bs_server:1; 00072 00073 struct grs_s *grs; 00074 sn_nsdl_ep_parameters_s *ep_information_ptr; // Endpoint parameters, Name, Domain etc.. 00075 sn_nsdl_addr_s server_address; // server address information 00076 /* Application definable context. This is useful for example when interfacing with c++ objects where a pointer to object is set as the 00077 * context, and in the callback functions the context pointer can be used to call methods for the correct instance of the c++ object. */ 00078 void *context; 00079 00080 void *(*sn_nsdl_alloc)(uint16_t); 00081 void (*sn_nsdl_free)(void *); 00082 uint8_t (*sn_nsdl_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); 00083 uint8_t (*sn_nsdl_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); 00084 uint8_t (*sn_nsdl_auto_obs_token_callback)(struct nsdl_s *, const char*, uint8_t*); 00085 }; 00086 00087 /***** Function prototypes *****/ 00088 /** 00089 * \fn extern grs_s *sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, 00090 * sn_nsdl_addr_s *), uint8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *), 00091 * sn_grs_mem_s *sn_memory) 00092 * 00093 * \brief GRS library initialize function. 00094 * 00095 * This function initializes GRS and CoAP. 00096 * 00097 * \param sn_grs_tx_callback A function pointer to a transmit callback function. Should return 1 when succeed, 0 when failed 00098 * \param *sn_grs_rx_callback_ptr A function pointer to a receiving callback function. If received packet is not for GRS, it will be passed to 00099 * upper level (NSDL) to be proceed. 00100 * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free. 00101 * 00102 * \return success pointer to handle, failure = NULL 00103 * 00104 */ 00105 extern struct grs_s *sn_grs_init(uint8_t (*sn_grs_tx_callback_ptr)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, 00106 sn_nsdl_addr_s *), 00107 int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), 00108 void *(*sn_grs_alloc)(uint16_t), 00109 void (*sn_grs_free)(void *)); 00110 00111 extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_first_resource(struct grs_s *handle); 00112 extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_next_resource(struct grs_s *handle, 00113 const sn_nsdl_dynamic_resource_parameters_s *sn_grs_current_resource); 00114 extern int8_t sn_grs_process_coap(struct nsdl_s *handle, 00115 sn_coap_hdr_s *coap_packet_ptr, 00116 sn_nsdl_addr_s *src); 00117 extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_search_resource(struct grs_s *handle, 00118 const char *path, 00119 uint8_t search_method); 00120 extern int8_t sn_grs_destroy(struct grs_s *handle); 00121 extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, 00122 sn_nsdl_addr_s *address_ptr, 00123 sn_coap_hdr_s *coap_hdr_ptr); 00124 extern int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); 00125 extern int8_t sn_grs_pop_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); 00126 extern int8_t sn_grs_delete_resource(struct grs_s *handle, const char *path); 00127 extern void sn_grs_mark_resources_as_registered(struct nsdl_s *handle); 00128 00129 #ifdef __cplusplus 00130 } 00131 #endif 00132 00133 00134 00135 00136 #endif /* GRS_H_ */
Generated on Tue Jul 12 2022 19:12:15 by 1.7.2