mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-11-01 10:06:11 +00:00
BLE ANS service - Use sysinit.
X-Original-Commit: 32b0d33a3a409668e9199c9bb6c28a8f5db3d374
This commit is contained in:
@@ -79,9 +79,7 @@ int ble_svc_ans_new_alert_add(uint8_t cat_id,
|
||||
const char * info_str);
|
||||
int ble_svc_ans_unr_alert_add(uint8_t cat_id);
|
||||
|
||||
int ble_svc_ans_init(struct ble_hs_cfg *cfg,
|
||||
uint8_t initial_new_alert_cat,
|
||||
uint8_t initial_unr_alert_cat);
|
||||
void ble_svc_ans_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,3 +29,6 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- net/nimble/host
|
||||
|
||||
pkg.init_function: ble_svc_ans_init
|
||||
pkg.init_stage: 3
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_gap.h"
|
||||
#include "services/ans/ble_svc_ans.h"
|
||||
@@ -347,44 +349,6 @@ ble_svc_ans_unr_alert_add(uint8_t cat_id)
|
||||
return ble_svc_ans_unr_alert_notify(cat_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the ANS with initial values for enabled categories
|
||||
* for new and unread alert characteristics. Bitwise or the
|
||||
* catagory bitmasks to enable multiple catagories.
|
||||
*
|
||||
* XXX: We should technically be able to change the new alert and
|
||||
* unread alert catagories when we have no active connections.
|
||||
*
|
||||
* @param cfg The host configuration
|
||||
* @param initial_new_alert_cat Initial supported new alert category
|
||||
* bitmask.
|
||||
* @param initial_unr_alert_cat Initial supported unread alert category
|
||||
* bitmask.
|
||||
*
|
||||
* @return 0 on success, non-zero error code otherwise.
|
||||
*/
|
||||
int
|
||||
ble_svc_ans_init(struct ble_hs_cfg *cfg, uint8_t initial_new_alert_cat,
|
||||
uint8_t initial_unr_alert_cat)
|
||||
{
|
||||
int rc;
|
||||
|
||||
ble_svc_ans_new_alert_cat = initial_new_alert_cat;
|
||||
ble_svc_ans_unr_alert_cat = initial_unr_alert_cat;
|
||||
|
||||
rc = ble_gatts_count_cfg(ble_svc_ans_defs, cfg);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_gatts_add_svcs(ble_svc_ans_defs);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new alert notification to the given category with the
|
||||
* given info string.
|
||||
@@ -465,3 +429,28 @@ ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the ANS with initial values for enabled categories
|
||||
* for new and unread alert characteristics. Bitwise or the
|
||||
* catagory bitmasks to enable multiple catagories.
|
||||
*
|
||||
* XXX: We should technically be able to change the new alert and
|
||||
* unread alert catagories when we have no active connections.
|
||||
*
|
||||
* @return 0 on success, non-zero error code otherwise.
|
||||
*/
|
||||
void
|
||||
ble_svc_ans_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_gatts_count_cfg(ble_svc_ans_defs);
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
|
||||
rc = ble_gatts_add_svcs(ble_svc_ans_defs);
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
|
||||
ble_svc_ans_new_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_NEW_ALERT_CAT);
|
||||
ble_svc_ans_unr_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_UNR_ALERT_CAT);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
syscfg.defs:
|
||||
BLE_SVC_ANS_NEW_ALERT_CAT:
|
||||
description: "Initial supported new alert category bitmask."
|
||||
value: 0
|
||||
|
||||
BLE_SVC_ANS_UNR_ALERT_CAT:
|
||||
description: "Initial supported unread alert category bitmask."
|
||||
value: 0
|
||||
Reference in New Issue
Block a user