Pull request

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_URIBeacon by Bluetooth Low Energy

Committer:
rgrover1
Date:
Mon Mar 09 16:35:03 2015 +0000
Revision:
16:1daa78939a3b
Child:
17:e2c0a1696e39
updating the URIBeacon demo to the latest API for URIBeaconConfigService.; ; Hopefully the app has been simplified now.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 16:1daa78939a3b 1 /* mbed Microcontroller Library
rgrover1 16:1daa78939a3b 2 * Copyright (c) 2006-2015 ARM Limited
rgrover1 16:1daa78939a3b 3 *
rgrover1 16:1daa78939a3b 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 16:1daa78939a3b 5 * you may not use this file except in compliance with the License.
rgrover1 16:1daa78939a3b 6 * You may obtain a copy of the License at
rgrover1 16:1daa78939a3b 7 *
rgrover1 16:1daa78939a3b 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 16:1daa78939a3b 9 *
rgrover1 16:1daa78939a3b 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 16:1daa78939a3b 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 16:1daa78939a3b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 16:1daa78939a3b 13 * See the License for the specific language governing permissions and
rgrover1 16:1daa78939a3b 14 * limitations under the License.
rgrover1 16:1daa78939a3b 15 */
rgrover1 16:1daa78939a3b 16
rgrover1 16:1daa78939a3b 17 #include "pstorage.h"
rgrover1 16:1daa78939a3b 18 #include "nrf_error.h"
rgrover1 16:1daa78939a3b 19 #include "ConfigParamsPersistence.h"
rgrover1 16:1daa78939a3b 20
rgrover1 16:1daa78939a3b 21 static pstorage_handle_t pstorageHandle;
rgrover1 16:1daa78939a3b 22
rgrover1 16:1daa78939a3b 23 /* Dummy callback handler needed by Nordic's pstorage module. */
rgrover1 16:1daa78939a3b 24 static void pstorageNotificationCallback(pstorage_handle_t *p_handle,
rgrover1 16:1daa78939a3b 25 uint8_t op_code,
rgrover1 16:1daa78939a3b 26 uint32_t result,
rgrover1 16:1daa78939a3b 27 uint8_t * p_data,
rgrover1 16:1daa78939a3b 28 uint32_t data_len)
rgrover1 16:1daa78939a3b 29 {
rgrover1 16:1daa78939a3b 30 /* APP_ERROR_CHECK(result); */
rgrover1 16:1daa78939a3b 31 }
rgrover1 16:1daa78939a3b 32
rgrover1 16:1daa78939a3b 33 /* Platform-specific implementation for persistence on the nRF5x. Based on the
rgrover1 16:1daa78939a3b 34 * pstorage module provided by the Nordic SDK. */
rgrover1 16:1daa78939a3b 35 void loadURIBeaconConfigParams(URIBeaconConfigService::Params_t *paramsP)
rgrover1 16:1daa78939a3b 36 {
rgrover1 16:1daa78939a3b 37 pstorage_init();
rgrover1 16:1daa78939a3b 38 static pstorage_module_param_t pstorageParams = {
rgrover1 16:1daa78939a3b 39 .cb = pstorageNotificationCallback,
rgrover1 16:1daa78939a3b 40 .block_size = sizeof(URIBeaconConfigService::Params_t),
rgrover1 16:1daa78939a3b 41 .block_count = 1
rgrover1 16:1daa78939a3b 42 };
rgrover1 16:1daa78939a3b 43
rgrover1 16:1daa78939a3b 44 pstorage_register(&pstorageParams, &pstorageHandle);
rgrover1 16:1daa78939a3b 45 if (pstorage_load(reinterpret_cast<uint8_t *>(paramsP), &pstorageHandle, sizeof(URIBeaconConfigService::Params_t), 0) != NRF_SUCCESS) {
rgrover1 16:1daa78939a3b 46 // On failure zero out and let the service reset to defaults
rgrover1 16:1daa78939a3b 47 memset(paramsP, 0, sizeof(URIBeaconConfigService::Params_t));
rgrover1 16:1daa78939a3b 48 }
rgrover1 16:1daa78939a3b 49 }
rgrover1 16:1daa78939a3b 50
rgrover1 16:1daa78939a3b 51 /* Platform-specific implementation for persistence on the nRF5x. Based on the
rgrover1 16:1daa78939a3b 52 * pstorage module provided by the Nordic SDK. */
rgrover1 16:1daa78939a3b 53 void saveURIBeaconConfigParams(URIBeaconConfigService::Params_t *paramsP)
rgrover1 16:1daa78939a3b 54 {
rgrover1 16:1daa78939a3b 55 if (paramsP->persistenceSignature != URIBeaconConfigService::Params_t::MAGIC) {
rgrover1 16:1daa78939a3b 56 paramsP->persistenceSignature = URIBeaconConfigService::Params_t::MAGIC;
rgrover1 16:1daa78939a3b 57 pstorage_store(&pstorageHandle,
rgrover1 16:1daa78939a3b 58 reinterpret_cast<uint8_t *>(paramsP),
rgrover1 16:1daa78939a3b 59 sizeof(URIBeaconConfigService::Params_t),
rgrover1 16:1daa78939a3b 60 0 /* offset */);
rgrover1 16:1daa78939a3b 61 } else {
rgrover1 16:1daa78939a3b 62 pstorage_update(&pstorageHandle,
rgrover1 16:1daa78939a3b 63 reinterpret_cast<uint8_t *>(paramsP),
rgrover1 16:1daa78939a3b 64 sizeof(URIBeaconConfigService::Params_t),
rgrover1 16:1daa78939a3b 65 0 /* offset */);
rgrover1 16:1daa78939a3b 66 }
rgrover1 16:1daa78939a3b 67 }