casaroli commented on code in PR #3989:
URL: https://github.com/apache/nuttx-apps/pull/3989#discussion_r4501775855


##########
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:
   `tools/checkpatch.sh` fails on this table: nxstyle reports 10 errors in 
lines 101-119 (for example "Bad left brace alignment" at 101 and "Garbage 
follows left bracket" at 116 and 119). The PR body says "`nxstyle` passed for 
all C and header files.".
   Fix: reformat the table until `tools/checkpatch.sh -f 
examples/nimble_bleess/bleess_gatt.c` passes.



-- 
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]

Reply via email to