Example

Dependencies:   FXAS21002 FXOS8700Q

Committer:
maygup01
Date:
Tue Nov 19 09:49:38 2019 +0000
Revision:
0:11cc2b7889af
Example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maygup01 0:11cc2b7889af 1 /*
maygup01 0:11cc2b7889af 2 * Copyright (c) 2011-2015 ARM Limited. All rights reserved.
maygup01 0:11cc2b7889af 3 * SPDX-License-Identifier: Apache-2.0
maygup01 0:11cc2b7889af 4 * Licensed under the Apache License, Version 2.0 (the License); you may
maygup01 0:11cc2b7889af 5 * not use this file except in compliance with the License.
maygup01 0:11cc2b7889af 6 * You may obtain a copy of the License at
maygup01 0:11cc2b7889af 7 *
maygup01 0:11cc2b7889af 8 * http://www.apache.org/licenses/LICENSE-2.0
maygup01 0:11cc2b7889af 9 *
maygup01 0:11cc2b7889af 10 * Unless required by applicable law or agreed to in writing, software
maygup01 0:11cc2b7889af 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
maygup01 0:11cc2b7889af 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
maygup01 0:11cc2b7889af 13 * See the License for the specific language governing permissions and
maygup01 0:11cc2b7889af 14 * limitations under the License.
maygup01 0:11cc2b7889af 15 */
maygup01 0:11cc2b7889af 16 #ifndef GRS_H_
maygup01 0:11cc2b7889af 17 #define GRS_H_
maygup01 0:11cc2b7889af 18
maygup01 0:11cc2b7889af 19
maygup01 0:11cc2b7889af 20 #ifdef __cplusplus
maygup01 0:11cc2b7889af 21 extern "C" {
maygup01 0:11cc2b7889af 22 #endif
maygup01 0:11cc2b7889af 23
maygup01 0:11cc2b7889af 24
maygup01 0:11cc2b7889af 25 #define SN_GRS_RESOURCE_ALREADY_EXISTS -2
maygup01 0:11cc2b7889af 26 #define SN_GRS_INVALID_PATH -3
maygup01 0:11cc2b7889af 27 #define SN_GRS_LIST_ADDING_FAILURE -4
maygup01 0:11cc2b7889af 28 #define SN_GRS_RESOURCE_UPDATED -5
maygup01 0:11cc2b7889af 29
maygup01 0:11cc2b7889af 30 #define ACCESS_DENIED -6
maygup01 0:11cc2b7889af 31
maygup01 0:11cc2b7889af 32 #define SN_GRS_DELETE_METHOD 0
maygup01 0:11cc2b7889af 33 #define SN_GRS_SEARCH_METHOD 1
maygup01 0:11cc2b7889af 34
maygup01 0:11cc2b7889af 35 #define SN_GRS_DEFAULT_ACCESS 0x0F
maygup01 0:11cc2b7889af 36
maygup01 0:11cc2b7889af 37 #define SN_NDSL_RESOURCE_NOT_REGISTERED 0
maygup01 0:11cc2b7889af 38 #define SN_NDSL_RESOURCE_REGISTERING 1
maygup01 0:11cc2b7889af 39 #define SN_NDSL_RESOURCE_REGISTERED 2
maygup01 0:11cc2b7889af 40 #define SN_NDSL_RESOURCE_DELETE 3
maygup01 0:11cc2b7889af 41
maygup01 0:11cc2b7889af 42 /***** Structs *****/
maygup01 0:11cc2b7889af 43
maygup01 0:11cc2b7889af 44 typedef struct sn_grs_version_ {
maygup01 0:11cc2b7889af 45 uint8_t major_version;
maygup01 0:11cc2b7889af 46 uint8_t minor_version;
maygup01 0:11cc2b7889af 47 uint8_t build;
maygup01 0:11cc2b7889af 48 } sn_grs_version_s;
maygup01 0:11cc2b7889af 49
maygup01 0:11cc2b7889af 50 typedef NS_LIST_HEAD(sn_nsdl_dynamic_resource_parameters_s, link) resource_list_t;
maygup01 0:11cc2b7889af 51
maygup01 0:11cc2b7889af 52 struct grs_s {
maygup01 0:11cc2b7889af 53 struct coap_s *coap;
maygup01 0:11cc2b7889af 54
maygup01 0:11cc2b7889af 55 void *(*sn_grs_alloc)(uint16_t);
maygup01 0:11cc2b7889af 56 void (*sn_grs_free)(void *);
maygup01 0:11cc2b7889af 57 uint8_t (*sn_grs_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *);
maygup01 0:11cc2b7889af 58 int8_t (*sn_grs_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *);
maygup01 0:11cc2b7889af 59
maygup01 0:11cc2b7889af 60 uint16_t resource_root_count;
maygup01 0:11cc2b7889af 61 resource_list_t resource_root_list;
maygup01 0:11cc2b7889af 62 };
maygup01 0:11cc2b7889af 63
maygup01 0:11cc2b7889af 64
maygup01 0:11cc2b7889af 65 struct nsdl_s {
maygup01 0:11cc2b7889af 66 uint32_t update_register_token;
maygup01 0:11cc2b7889af 67 uint32_t register_token;
maygup01 0:11cc2b7889af 68 uint32_t unregister_token;
maygup01 0:11cc2b7889af 69 uint32_t bootstrap_token;
maygup01 0:11cc2b7889af 70 uint32_t token_seed;
maygup01 0:11cc2b7889af 71 unsigned int sn_nsdl_endpoint_registered:1;
maygup01 0:11cc2b7889af 72 unsigned int is_bs_server:1;
maygup01 0:11cc2b7889af 73
maygup01 0:11cc2b7889af 74 struct grs_s *grs;
maygup01 0:11cc2b7889af 75 sn_nsdl_ep_parameters_s *ep_information_ptr; // Endpoint parameters, Name, Domain etc..
maygup01 0:11cc2b7889af 76 sn_nsdl_addr_s server_address; // server address information
maygup01 0:11cc2b7889af 77 /* Application definable context. This is useful for example when interfacing with c++ objects where a pointer to object is set as the
maygup01 0:11cc2b7889af 78 * context, and in the callback functions the context pointer can be used to call methods for the correct instance of the c++ object. */
maygup01 0:11cc2b7889af 79 void *context;
maygup01 0:11cc2b7889af 80
maygup01 0:11cc2b7889af 81 void *(*sn_nsdl_alloc)(uint16_t);
maygup01 0:11cc2b7889af 82 void (*sn_nsdl_free)(void *);
maygup01 0:11cc2b7889af 83 uint8_t (*sn_nsdl_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *);
maygup01 0:11cc2b7889af 84 uint8_t (*sn_nsdl_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *);
maygup01 0:11cc2b7889af 85 uint8_t (*sn_nsdl_auto_obs_token_callback)(struct nsdl_s *, const char*, uint8_t*);
maygup01 0:11cc2b7889af 86 };
maygup01 0:11cc2b7889af 87
maygup01 0:11cc2b7889af 88 /***** Function prototypes *****/
maygup01 0:11cc2b7889af 89 /**
maygup01 0:11cc2b7889af 90 * \fn extern grs_s *sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t,
maygup01 0:11cc2b7889af 91 * sn_nsdl_addr_s *), uint8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *),
maygup01 0:11cc2b7889af 92 * sn_grs_mem_s *sn_memory)
maygup01 0:11cc2b7889af 93 *
maygup01 0:11cc2b7889af 94 * \brief GRS library initialize function.
maygup01 0:11cc2b7889af 95 *
maygup01 0:11cc2b7889af 96 * This function initializes GRS and CoAP.
maygup01 0:11cc2b7889af 97 *
maygup01 0:11cc2b7889af 98 * \param sn_grs_tx_callback A function pointer to a transmit callback function. Should return 1 when succeed, 0 when failed
maygup01 0:11cc2b7889af 99 * \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
maygup01 0:11cc2b7889af 100 * upper level (NSDL) to be proceed.
maygup01 0:11cc2b7889af 101 * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free.
maygup01 0:11cc2b7889af 102 *
maygup01 0:11cc2b7889af 103 * \return success pointer to handle, failure = NULL
maygup01 0:11cc2b7889af 104 *
maygup01 0:11cc2b7889af 105 */
maygup01 0:11cc2b7889af 106 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,
maygup01 0:11cc2b7889af 107 sn_nsdl_addr_s *),
maygup01 0:11cc2b7889af 108 int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *),
maygup01 0:11cc2b7889af 109 void *(*sn_grs_alloc)(uint16_t),
maygup01 0:11cc2b7889af 110 void (*sn_grs_free)(void *));
maygup01 0:11cc2b7889af 111
maygup01 0:11cc2b7889af 112 extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_first_resource(struct grs_s *handle);
maygup01 0:11cc2b7889af 113 extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_next_resource(struct grs_s *handle,
maygup01 0:11cc2b7889af 114 const sn_nsdl_dynamic_resource_parameters_s *sn_grs_current_resource);
maygup01 0:11cc2b7889af 115 extern int8_t sn_grs_process_coap(struct nsdl_s *handle,
maygup01 0:11cc2b7889af 116 sn_coap_hdr_s *coap_packet_ptr,
maygup01 0:11cc2b7889af 117 sn_nsdl_addr_s *src);
maygup01 0:11cc2b7889af 118 extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_search_resource(struct grs_s *handle,
maygup01 0:11cc2b7889af 119 const char *path,
maygup01 0:11cc2b7889af 120 uint8_t search_method);
maygup01 0:11cc2b7889af 121 extern int8_t sn_grs_destroy(struct grs_s *handle);
maygup01 0:11cc2b7889af 122 extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle,
maygup01 0:11cc2b7889af 123 sn_nsdl_addr_s *address_ptr,
maygup01 0:11cc2b7889af 124 sn_coap_hdr_s *coap_hdr_ptr);
maygup01 0:11cc2b7889af 125 extern int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res);
maygup01 0:11cc2b7889af 126 extern int8_t sn_grs_pop_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res);
maygup01 0:11cc2b7889af 127 extern int8_t sn_grs_delete_resource(struct grs_s *handle, const char *path);
maygup01 0:11cc2b7889af 128 extern void sn_grs_mark_resources_as_registered(struct nsdl_s *handle);
maygup01 0:11cc2b7889af 129
maygup01 0:11cc2b7889af 130 #ifdef __cplusplus
maygup01 0:11cc2b7889af 131 }
maygup01 0:11cc2b7889af 132 #endif
maygup01 0:11cc2b7889af 133
maygup01 0:11cc2b7889af 134
maygup01 0:11cc2b7889af 135
maygup01 0:11cc2b7889af 136
maygup01 0:11cc2b7889af 137 #endif /* GRS_H_ */