Jackson-gjh commented on code in PR #3989: URL: https://github.com/apache/nuttx-apps/pull/3989#discussion_r4502598089
########## examples/nimble_bleess/bleess_gatt.c: ########## @@ -0,0 +1,188 @@ +/**************************************************************************** + * apps/examples/nimble_bleess/bleess_gatt.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdio.h> + +#include "host/ble_hs.h" +#include "host/ble_uuid.h" +#include "services/gatt/ble_svc_gatt.h" + +#include "bleess.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const ble_uuid16_t g_bleess_service_uuid = + BLE_UUID16_INIT(BLEESS_SERVICE_UUID); +static const ble_uuid16_t g_bleess_temperature_uuid = + BLE_UUID16_INIT(BLEESS_TEMPERATURE_UUID); +static const ble_uuid16_t g_bleess_humidity_uuid = + BLE_UUID16_INIT(BLEESS_HUMIDITY_UUID); + +static int16_t g_bleess_temperature_centi = 2400; +static uint16_t g_bleess_humidity_centi = 5000; +static uint16_t g_bleess_temperature_handle; +static uint16_t g_bleess_humidity_handle; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int bleess_gatt_access(uint16_t connection_handle, + uint16_t attribute_handle, + FAR struct ble_gatt_access_ctxt *context, + FAR void *arg) +{ + FAR const ble_uuid_t *uuid = context->chr->uuid; + uint16_t encoded_temperature; + uint8_t value[2]; + + UNUSED(connection_handle); + UNUSED(attribute_handle); + UNUSED(arg); + + if (context->op != BLE_GATT_ACCESS_OP_READ_CHR) + { + return BLE_ATT_ERR_WRITE_NOT_PERMITTED; + } + + if (ble_uuid_cmp(uuid, &g_bleess_temperature_uuid.u) == 0) + { + encoded_temperature = (uint16_t)g_bleess_temperature_centi; + value[0] = (uint8_t)encoded_temperature; + value[1] = (uint8_t)(encoded_temperature >> 8); + } + else if (ble_uuid_cmp(uuid, &g_bleess_humidity_uuid.u) == 0) + { + value[0] = (uint8_t)g_bleess_humidity_centi; + value[1] = (uint8_t)(g_bleess_humidity_centi >> 8); + } + else + { + return BLE_ATT_ERR_UNLIKELY; + } + + if (os_mbuf_append(context->om, value, sizeof(value)) != 0) + { + return BLE_ATT_ERR_INSUFFICIENT_RES; + } + + return 0; +} + +static const struct ble_gatt_svc_def g_bleess_services[] = +{ + { Review Comment: Thanks, fixed. The service definition was located after the first private function, so nxstyle did not recognize it as a private data initializer. I moved the table into the Private Data section, added the required forward declaration, and reformatted the initializer using the existing nimble_bleprph layout. tools/checkpatch.sh -f now passes for all three C files and the header, and bleess_gatt.c was recompiled successfully with the ESP32-C6 build command. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
