Committer:
jinu
Date:
Thu Feb 09 06:08:17 2017 +0000
Revision:
0:6ba9b94b8997
NRF51 serialization libraries for mDot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jinu 0:6ba9b94b8997 1 /* Copyright (c) Nordic Semiconductor ASA
jinu 0:6ba9b94b8997 2 * All rights reserved.
jinu 0:6ba9b94b8997 3 *
jinu 0:6ba9b94b8997 4 * Redistribution and use in source and binary forms, with or without modification,
jinu 0:6ba9b94b8997 5 * are permitted provided that the following conditions are met:
jinu 0:6ba9b94b8997 6 *
jinu 0:6ba9b94b8997 7 * 1. Redistributions of source code must retain the above copyright notice, this
jinu 0:6ba9b94b8997 8 * list of conditions and the following disclaimer.
jinu 0:6ba9b94b8997 9 *
jinu 0:6ba9b94b8997 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this
jinu 0:6ba9b94b8997 11 * list of conditions and the following disclaimer in the documentation and/or
jinu 0:6ba9b94b8997 12 * other materials provided with the distribution.
jinu 0:6ba9b94b8997 13 *
jinu 0:6ba9b94b8997 14 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
jinu 0:6ba9b94b8997 15 * contributors to this software may be used to endorse or promote products
jinu 0:6ba9b94b8997 16 * derived from this software without specific prior written permission.
jinu 0:6ba9b94b8997 17 *
jinu 0:6ba9b94b8997 18 * 4. This software must only be used in a processor manufactured by Nordic
jinu 0:6ba9b94b8997 19 * Semiconductor ASA, or in a processor manufactured by a third party that
jinu 0:6ba9b94b8997 20 * is used in combination with a processor manufactured by Nordic Semiconductor.
jinu 0:6ba9b94b8997 21 *
jinu 0:6ba9b94b8997 22 *
jinu 0:6ba9b94b8997 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
jinu 0:6ba9b94b8997 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
jinu 0:6ba9b94b8997 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
jinu 0:6ba9b94b8997 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
jinu 0:6ba9b94b8997 27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
jinu 0:6ba9b94b8997 28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
jinu 0:6ba9b94b8997 29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
jinu 0:6ba9b94b8997 30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
jinu 0:6ba9b94b8997 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
jinu 0:6ba9b94b8997 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jinu 0:6ba9b94b8997 33 */
jinu 0:6ba9b94b8997 34 #include "ble_gattc_struct_serialization.h"
jinu 0:6ba9b94b8997 35 #include "ble_struct_serialization.h"
jinu 0:6ba9b94b8997 36 #include "ble_serialization.h"
jinu 0:6ba9b94b8997 37 #include "app_util.h"
jinu 0:6ba9b94b8997 38 #include "ble_gattc.h"
jinu 0:6ba9b94b8997 39 #include "cond_field_serialization.h"
jinu 0:6ba9b94b8997 40 #include <string.h>
jinu 0:6ba9b94b8997 41
jinu 0:6ba9b94b8997 42 uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_t_enc(void const * const p_void_struct,
jinu 0:6ba9b94b8997 43 uint8_t * const p_buf,
jinu 0:6ba9b94b8997 44 uint32_t buf_len,
jinu 0:6ba9b94b8997 45 uint32_t * const p_index)
jinu 0:6ba9b94b8997 46 {
jinu 0:6ba9b94b8997 47 ble_gattc_evt_char_val_by_uuid_read_rsp_t * p_read =
jinu 0:6ba9b94b8997 48 (ble_gattc_evt_char_val_by_uuid_read_rsp_t *) p_void_struct;
jinu 0:6ba9b94b8997 49 uint32_t err_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 50
jinu 0:6ba9b94b8997 51 err_code = uint16_t_enc(&(p_read->count), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 52 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 53
jinu 0:6ba9b94b8997 54 err_code = uint16_t_enc(&(p_read->value_len), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 55 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 56
jinu 0:6ba9b94b8997 57 uint32_t i;
jinu 0:6ba9b94b8997 58 ble_gattc_handle_value_t * p_handle_value = &p_read->handle_value[0];
jinu 0:6ba9b94b8997 59
jinu 0:6ba9b94b8997 60 for (i = 0; i < p_read->count; i++)
jinu 0:6ba9b94b8997 61 {
jinu 0:6ba9b94b8997 62 err_code = uint16_t_enc(&(p_handle_value->handle), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 63 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 64
jinu 0:6ba9b94b8997 65 SER_ASSERT_LENGTH_LEQ(p_read->value_len, buf_len - *p_index);
jinu 0:6ba9b94b8997 66 memcpy(&p_buf[*p_index], p_handle_value->p_value, p_read->value_len);
jinu 0:6ba9b94b8997 67 *p_index += p_read->value_len;
jinu 0:6ba9b94b8997 68
jinu 0:6ba9b94b8997 69 p_handle_value++;
jinu 0:6ba9b94b8997 70 }
jinu 0:6ba9b94b8997 71
jinu 0:6ba9b94b8997 72 return err_code;
jinu 0:6ba9b94b8997 73 }
jinu 0:6ba9b94b8997 74
jinu 0:6ba9b94b8997 75 uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_t_dec(uint8_t const * const p_buf,
jinu 0:6ba9b94b8997 76 uint32_t buf_len,
jinu 0:6ba9b94b8997 77 uint32_t * const p_index,
jinu 0:6ba9b94b8997 78 uint32_t * const p_struct_size,
jinu 0:6ba9b94b8997 79 void * const p_void_struct)
jinu 0:6ba9b94b8997 80 {
jinu 0:6ba9b94b8997 81 ble_gattc_evt_char_val_by_uuid_read_rsp_t * p_read =
jinu 0:6ba9b94b8997 82 (ble_gattc_evt_char_val_by_uuid_read_rsp_t *) p_void_struct;
jinu 0:6ba9b94b8997 83 uint32_t err_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 84 uint16_t value_len;
jinu 0:6ba9b94b8997 85 uint16_t count;
jinu 0:6ba9b94b8997 86 uint32_t i;
jinu 0:6ba9b94b8997 87
jinu 0:6ba9b94b8997 88 SER_ASSERT_LENGTH_LEQ(4, buf_len - *p_index);
jinu 0:6ba9b94b8997 89 uint16_dec(p_buf, buf_len, p_index, &count);
jinu 0:6ba9b94b8997 90 uint16_dec(p_buf, buf_len, p_index, &value_len);
jinu 0:6ba9b94b8997 91
jinu 0:6ba9b94b8997 92 uint32_t total_struct_size = *p_struct_size;
jinu 0:6ba9b94b8997 93
jinu 0:6ba9b94b8997 94 //calculate the size of the struct
jinu 0:6ba9b94b8997 95 *p_struct_size = offsetof(ble_gattc_evt_char_val_by_uuid_read_rsp_t, handle_value[0]);
jinu 0:6ba9b94b8997 96 *p_struct_size += (uint8_t*)&(p_read->handle_value[count])-(uint8_t*)&(p_read->handle_value[0]);
jinu 0:6ba9b94b8997 97 *p_struct_size += value_len * count;
jinu 0:6ba9b94b8997 98
jinu 0:6ba9b94b8997 99 if (p_read)
jinu 0:6ba9b94b8997 100 {
jinu 0:6ba9b94b8997 101 p_read->value_len = value_len;
jinu 0:6ba9b94b8997 102 p_read->count = count;
jinu 0:6ba9b94b8997 103
jinu 0:6ba9b94b8997 104 ble_gattc_handle_value_t * p_handle_value;
jinu 0:6ba9b94b8997 105 uint8_t * p_value;
jinu 0:6ba9b94b8997 106
jinu 0:6ba9b94b8997 107 SER_ASSERT_LENGTH_LEQ(*p_struct_size, total_struct_size);
jinu 0:6ba9b94b8997 108
jinu 0:6ba9b94b8997 109 p_value = (uint8_t *)&p_read->handle_value[count];
jinu 0:6ba9b94b8997 110
jinu 0:6ba9b94b8997 111 for (i = 0; i < count; i++)
jinu 0:6ba9b94b8997 112 {
jinu 0:6ba9b94b8997 113 p_handle_value = (ble_gattc_handle_value_t *)&p_read->handle_value[i];
jinu 0:6ba9b94b8997 114 p_handle_value->p_value = p_value;
jinu 0:6ba9b94b8997 115
jinu 0:6ba9b94b8997 116 SER_ASSERT_LENGTH_LEQ(2, buf_len - *p_index);
jinu 0:6ba9b94b8997 117 uint16_dec(p_buf, buf_len, p_index, &(p_handle_value->handle));
jinu 0:6ba9b94b8997 118
jinu 0:6ba9b94b8997 119 SER_ASSERT_LENGTH_LEQ(p_read->value_len, buf_len - *p_index);
jinu 0:6ba9b94b8997 120 memcpy(p_handle_value->p_value, &p_buf[*p_index], p_read->value_len);
jinu 0:6ba9b94b8997 121 *p_index += p_read->value_len;
jinu 0:6ba9b94b8997 122
jinu 0:6ba9b94b8997 123 p_value += value_len;
jinu 0:6ba9b94b8997 124 }
jinu 0:6ba9b94b8997 125 }
jinu 0:6ba9b94b8997 126 else
jinu 0:6ba9b94b8997 127 {
jinu 0:6ba9b94b8997 128 *p_index += count * (value_len + 2);
jinu 0:6ba9b94b8997 129 }
jinu 0:6ba9b94b8997 130
jinu 0:6ba9b94b8997 131 return err_code;
jinu 0:6ba9b94b8997 132 }
jinu 0:6ba9b94b8997 133
jinu 0:6ba9b94b8997 134 uint32_t ble_gattc_evt_char_vals_read_rsp_t_enc(void const * const p_void_struct,
jinu 0:6ba9b94b8997 135 uint8_t * const p_buf,
jinu 0:6ba9b94b8997 136 uint32_t buf_len,
jinu 0:6ba9b94b8997 137 uint32_t * const p_index)
jinu 0:6ba9b94b8997 138 {
jinu 0:6ba9b94b8997 139 ble_gattc_evt_char_vals_read_rsp_t * p_read =
jinu 0:6ba9b94b8997 140 (ble_gattc_evt_char_vals_read_rsp_t *) p_void_struct;
jinu 0:6ba9b94b8997 141 uint32_t error_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 142
jinu 0:6ba9b94b8997 143 //Encode len
jinu 0:6ba9b94b8997 144 error_code = uint16_t_enc(&(p_read->len), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 145 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 146
jinu 0:6ba9b94b8997 147 //Encode values
jinu 0:6ba9b94b8997 148 SER_ASSERT_LENGTH_LEQ(p_read->len, buf_len - *p_index);
jinu 0:6ba9b94b8997 149 memcpy(&p_buf[*p_index], p_read->values, p_read->len);
jinu 0:6ba9b94b8997 150 *p_index += p_read->len;
jinu 0:6ba9b94b8997 151
jinu 0:6ba9b94b8997 152 return error_code;
jinu 0:6ba9b94b8997 153 }
jinu 0:6ba9b94b8997 154
jinu 0:6ba9b94b8997 155 uint32_t ble_gattc_evt_char_vals_read_rsp_t_dec(uint8_t const * const p_buf,
jinu 0:6ba9b94b8997 156 uint32_t buf_len,
jinu 0:6ba9b94b8997 157 uint32_t * const p_index,
jinu 0:6ba9b94b8997 158 void * const p_void_struct)
jinu 0:6ba9b94b8997 159 {
jinu 0:6ba9b94b8997 160 ble_gattc_evt_char_vals_read_rsp_t * p_read =
jinu 0:6ba9b94b8997 161 (ble_gattc_evt_char_vals_read_rsp_t *) p_void_struct;
jinu 0:6ba9b94b8997 162 uint32_t error_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 163
jinu 0:6ba9b94b8997 164 //Decode len
jinu 0:6ba9b94b8997 165 SER_ASSERT_LENGTH_LEQ(2, buf_len - *p_index);
jinu 0:6ba9b94b8997 166 uint16_dec(p_buf, buf_len, p_index, &(p_read->len));
jinu 0:6ba9b94b8997 167
jinu 0:6ba9b94b8997 168 //Decode values
jinu 0:6ba9b94b8997 169 SER_ASSERT_LENGTH_LEQ(p_read->len, buf_len - *p_index);
jinu 0:6ba9b94b8997 170 memcpy(p_read->values, &p_buf[*p_index], p_read->len);
jinu 0:6ba9b94b8997 171 *p_index += p_read->len;
jinu 0:6ba9b94b8997 172
jinu 0:6ba9b94b8997 173 return error_code;
jinu 0:6ba9b94b8997 174 }
jinu 0:6ba9b94b8997 175
jinu 0:6ba9b94b8997 176 uint32_t ble_gattc_handle_range_t_enc(void const * const p_void_struct,
jinu 0:6ba9b94b8997 177 uint8_t * const p_buf,
jinu 0:6ba9b94b8997 178 uint32_t buf_len,
jinu 0:6ba9b94b8997 179 uint32_t * const p_index)
jinu 0:6ba9b94b8997 180 {
jinu 0:6ba9b94b8997 181 ble_gattc_handle_range_t * p_range = (ble_gattc_handle_range_t *) p_void_struct;
jinu 0:6ba9b94b8997 182 uint32_t err_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 183
jinu 0:6ba9b94b8997 184 err_code = uint16_t_enc(&(p_range->start_handle), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 185 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 186
jinu 0:6ba9b94b8997 187 err_code = uint16_t_enc(&(p_range->end_handle), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 188 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 189
jinu 0:6ba9b94b8997 190 return err_code;
jinu 0:6ba9b94b8997 191 }
jinu 0:6ba9b94b8997 192
jinu 0:6ba9b94b8997 193 uint32_t ble_gattc_handle_range_t_dec(uint8_t const * const p_buf,
jinu 0:6ba9b94b8997 194 uint32_t buf_len,
jinu 0:6ba9b94b8997 195 uint32_t * const p_index,
jinu 0:6ba9b94b8997 196 void * const p_void_struct)
jinu 0:6ba9b94b8997 197 {
jinu 0:6ba9b94b8997 198 ble_gattc_handle_range_t * p_range = (ble_gattc_handle_range_t *) p_void_struct;
jinu 0:6ba9b94b8997 199 uint32_t err_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 200
jinu 0:6ba9b94b8997 201 SER_ASSERT_LENGTH_LEQ(4, buf_len - *p_index);
jinu 0:6ba9b94b8997 202 uint16_dec(p_buf, buf_len, p_index, &(p_range->start_handle));
jinu 0:6ba9b94b8997 203 uint16_dec(p_buf, buf_len, p_index, &(p_range->end_handle));
jinu 0:6ba9b94b8997 204
jinu 0:6ba9b94b8997 205 return err_code;
jinu 0:6ba9b94b8997 206 }
jinu 0:6ba9b94b8997 207
jinu 0:6ba9b94b8997 208
jinu 0:6ba9b94b8997 209 uint32_t ble_gattc_service_t_enc(void const * const p_void_struct,
jinu 0:6ba9b94b8997 210 uint8_t * const p_buf,
jinu 0:6ba9b94b8997 211 uint32_t buf_len,
jinu 0:6ba9b94b8997 212 uint32_t * const p_index)
jinu 0:6ba9b94b8997 213 {
jinu 0:6ba9b94b8997 214 uint32_t error_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 215 ble_gattc_service_t * p_service = (ble_gattc_service_t *) p_void_struct;
jinu 0:6ba9b94b8997 216
jinu 0:6ba9b94b8997 217 error_code = ble_uuid_t_enc(&(p_service->uuid), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 218 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 219 error_code = ble_gattc_handle_range_t_enc(&(p_service->handle_range), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 220 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 221
jinu 0:6ba9b94b8997 222 return error_code;
jinu 0:6ba9b94b8997 223 }
jinu 0:6ba9b94b8997 224
jinu 0:6ba9b94b8997 225 uint32_t ble_gattc_service_t_dec(uint8_t const * const p_buf,
jinu 0:6ba9b94b8997 226 uint32_t buf_len,
jinu 0:6ba9b94b8997 227 uint32_t * const p_index,
jinu 0:6ba9b94b8997 228 void * const p_void_struct)
jinu 0:6ba9b94b8997 229 {
jinu 0:6ba9b94b8997 230 uint32_t error_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 231 ble_gattc_service_t * p_service = (ble_gattc_service_t *) p_void_struct;
jinu 0:6ba9b94b8997 232
jinu 0:6ba9b94b8997 233 error_code = ble_uuid_t_dec(p_buf, buf_len, p_index, &(p_service->uuid));
jinu 0:6ba9b94b8997 234 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 235 error_code = ble_gattc_handle_range_t_dec(p_buf, buf_len, p_index, &(p_service->handle_range));
jinu 0:6ba9b94b8997 236 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 237
jinu 0:6ba9b94b8997 238 return error_code;
jinu 0:6ba9b94b8997 239 }
jinu 0:6ba9b94b8997 240
jinu 0:6ba9b94b8997 241 uint32_t ble_gattc_include_t_enc(void const * const p_void_struct,
jinu 0:6ba9b94b8997 242 uint8_t * const p_buf,
jinu 0:6ba9b94b8997 243 uint32_t buf_len,
jinu 0:6ba9b94b8997 244 uint32_t * const p_index)
jinu 0:6ba9b94b8997 245 {
jinu 0:6ba9b94b8997 246 uint32_t error_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 247 ble_gattc_include_t * p_include = (ble_gattc_include_t *) p_void_struct;
jinu 0:6ba9b94b8997 248
jinu 0:6ba9b94b8997 249 error_code = uint16_t_enc(&(p_include->handle), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 250 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 251 error_code = ble_gattc_service_t_enc(&(p_include->included_srvc), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 252 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 253
jinu 0:6ba9b94b8997 254 return error_code;
jinu 0:6ba9b94b8997 255 }
jinu 0:6ba9b94b8997 256
jinu 0:6ba9b94b8997 257 uint32_t ble_gattc_include_t_dec(uint8_t const * const p_buf,
jinu 0:6ba9b94b8997 258 uint32_t buf_len,
jinu 0:6ba9b94b8997 259 uint32_t * const p_index,
jinu 0:6ba9b94b8997 260 void * const p_void_struct)
jinu 0:6ba9b94b8997 261 {
jinu 0:6ba9b94b8997 262 uint32_t error_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 263 ble_gattc_include_t * p_include = (ble_gattc_include_t *) p_void_struct;
jinu 0:6ba9b94b8997 264
jinu 0:6ba9b94b8997 265 error_code = uint16_t_dec(p_buf, buf_len, p_index, &(p_include->handle));
jinu 0:6ba9b94b8997 266 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 267 error_code = ble_gattc_service_t_dec(p_buf, buf_len, p_index, &(p_include->included_srvc));
jinu 0:6ba9b94b8997 268 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 269
jinu 0:6ba9b94b8997 270 return error_code;
jinu 0:6ba9b94b8997 271 }
jinu 0:6ba9b94b8997 272
jinu 0:6ba9b94b8997 273 uint32_t ble_gattc_evt_rel_disc_rsp_t_enc(void const * const p_void_struct,
jinu 0:6ba9b94b8997 274 uint8_t * const p_buf,
jinu 0:6ba9b94b8997 275 uint32_t buf_len,
jinu 0:6ba9b94b8997 276 uint32_t * const p_index)
jinu 0:6ba9b94b8997 277 {
jinu 0:6ba9b94b8997 278 uint32_t error_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 279 uint32_t i;
jinu 0:6ba9b94b8997 280 ble_gattc_evt_rel_disc_rsp_t * p_rsp = (ble_gattc_evt_rel_disc_rsp_t *) p_void_struct;
jinu 0:6ba9b94b8997 281
jinu 0:6ba9b94b8997 282 error_code = uint16_t_enc(&(p_rsp->count), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 283 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 284
jinu 0:6ba9b94b8997 285 ble_gattc_include_t * p_include = (ble_gattc_include_t *) p_rsp->includes;
jinu 0:6ba9b94b8997 286
jinu 0:6ba9b94b8997 287 for (i = 0; i < p_rsp->count; i++)
jinu 0:6ba9b94b8997 288 {
jinu 0:6ba9b94b8997 289 error_code = ble_gattc_include_t_enc(p_include, p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 290 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 291
jinu 0:6ba9b94b8997 292 p_include++;
jinu 0:6ba9b94b8997 293 }
jinu 0:6ba9b94b8997 294
jinu 0:6ba9b94b8997 295 return error_code;
jinu 0:6ba9b94b8997 296 }
jinu 0:6ba9b94b8997 297
jinu 0:6ba9b94b8997 298 uint32_t ble_gattc_evt_rel_disc_rsp_t_dec(uint8_t const * const p_buf,
jinu 0:6ba9b94b8997 299 uint32_t buf_len,
jinu 0:6ba9b94b8997 300 uint32_t * const p_index,
jinu 0:6ba9b94b8997 301 void * const p_void_struct)
jinu 0:6ba9b94b8997 302 {
jinu 0:6ba9b94b8997 303 uint32_t error_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 304 ble_gattc_evt_rel_disc_rsp_t * p_rsp = (ble_gattc_evt_rel_disc_rsp_t *) p_void_struct;
jinu 0:6ba9b94b8997 305 uint16_t include_count;
jinu 0:6ba9b94b8997 306 uint32_t i;
jinu 0:6ba9b94b8997 307
jinu 0:6ba9b94b8997 308 error_code = uint16_t_dec(p_buf, buf_len, p_index, &include_count);
jinu 0:6ba9b94b8997 309 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 310 p_rsp->count = include_count;
jinu 0:6ba9b94b8997 311
jinu 0:6ba9b94b8997 312 ble_gattc_include_t * p_include = (ble_gattc_include_t *) p_rsp->includes;
jinu 0:6ba9b94b8997 313
jinu 0:6ba9b94b8997 314 for (i = 0; i < include_count; i++)
jinu 0:6ba9b94b8997 315 {
jinu 0:6ba9b94b8997 316 error_code = ble_gattc_include_t_dec(p_buf, buf_len, p_index, p_include);
jinu 0:6ba9b94b8997 317 SER_ASSERT(error_code == NRF_SUCCESS, error_code);
jinu 0:6ba9b94b8997 318
jinu 0:6ba9b94b8997 319 p_include++;
jinu 0:6ba9b94b8997 320 }
jinu 0:6ba9b94b8997 321
jinu 0:6ba9b94b8997 322 return error_code;
jinu 0:6ba9b94b8997 323 }
jinu 0:6ba9b94b8997 324
jinu 0:6ba9b94b8997 325 uint32_t ble_gattc_write_params_t_enc(void const * const p_void_write,
jinu 0:6ba9b94b8997 326 uint8_t * const p_buf,
jinu 0:6ba9b94b8997 327 uint32_t buf_len,
jinu 0:6ba9b94b8997 328 uint32_t * const p_index)
jinu 0:6ba9b94b8997 329 {
jinu 0:6ba9b94b8997 330 SER_ASSERT_NOT_NULL(p_void_write);
jinu 0:6ba9b94b8997 331 SER_ASSERT_NOT_NULL(p_buf);
jinu 0:6ba9b94b8997 332 SER_ASSERT_NOT_NULL(p_index);
jinu 0:6ba9b94b8997 333
jinu 0:6ba9b94b8997 334 uint32_t err_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 335
jinu 0:6ba9b94b8997 336 ble_gattc_write_params_t * p_write = (ble_gattc_write_params_t *)p_void_write;
jinu 0:6ba9b94b8997 337
jinu 0:6ba9b94b8997 338 err_code = uint8_t_enc(&(p_write->write_op), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 339 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 340
jinu 0:6ba9b94b8997 341 err_code = uint8_t_enc(&(p_write->flags), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 342 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 343
jinu 0:6ba9b94b8997 344 err_code = uint16_t_enc(&(p_write->handle), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 345 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 346
jinu 0:6ba9b94b8997 347 err_code = uint16_t_enc(&(p_write->offset), p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 348 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 349
jinu 0:6ba9b94b8997 350 err_code = len16data_enc(p_write->p_value, p_write->len, p_buf, buf_len, p_index);
jinu 0:6ba9b94b8997 351 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 352
jinu 0:6ba9b94b8997 353 return err_code;
jinu 0:6ba9b94b8997 354 }
jinu 0:6ba9b94b8997 355
jinu 0:6ba9b94b8997 356 uint32_t ble_gattc_write_params_t_dec(uint8_t const * const p_buf,
jinu 0:6ba9b94b8997 357 uint32_t buf_len,
jinu 0:6ba9b94b8997 358 uint32_t * const p_index,
jinu 0:6ba9b94b8997 359 void * const p_void_write)
jinu 0:6ba9b94b8997 360 {
jinu 0:6ba9b94b8997 361 SER_ASSERT_NOT_NULL(p_buf);
jinu 0:6ba9b94b8997 362 SER_ASSERT_NOT_NULL(p_index);
jinu 0:6ba9b94b8997 363 SER_ASSERT_NOT_NULL(p_void_write);
jinu 0:6ba9b94b8997 364
jinu 0:6ba9b94b8997 365 uint32_t err_code = NRF_SUCCESS;
jinu 0:6ba9b94b8997 366
jinu 0:6ba9b94b8997 367 ble_gattc_write_params_t * p_write = (ble_gattc_write_params_t *)p_void_write;
jinu 0:6ba9b94b8997 368
jinu 0:6ba9b94b8997 369 err_code = uint8_t_dec(p_buf, buf_len, p_index, &(p_write->write_op));
jinu 0:6ba9b94b8997 370 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 371
jinu 0:6ba9b94b8997 372 err_code = uint8_t_dec(p_buf, buf_len, p_index, &(p_write->flags));
jinu 0:6ba9b94b8997 373 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 374
jinu 0:6ba9b94b8997 375 err_code = uint16_t_dec(p_buf, buf_len, p_index, &(p_write->handle));
jinu 0:6ba9b94b8997 376 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 377
jinu 0:6ba9b94b8997 378 err_code = uint16_t_dec(p_buf, buf_len, p_index, &(p_write->offset));
jinu 0:6ba9b94b8997 379 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 380
jinu 0:6ba9b94b8997 381 err_code = len16data_dec(p_buf, buf_len, p_index, &(p_write->p_value), &(p_write->len));
jinu 0:6ba9b94b8997 382 SER_ASSERT(err_code == NRF_SUCCESS, err_code);
jinu 0:6ba9b94b8997 383
jinu 0:6ba9b94b8997 384 return err_code;
jinu 0:6ba9b94b8997 385 }
jinu 0:6ba9b94b8997 386