[riot-notifications] [RIOT-OS/RIOT] ble/nimble: add scanner submodule and example application (#11281)

Martine Lenders notifications at github.com
Wed Mar 27 17:54:36 CET 2019


miri64 requested changes on this pull request.

Code looks fine, just some style nitpicks and spelling errors pointed out.

> +
+#include "xtimer.h"
+#include "shell.h"
+#include "shell_commands.h"
+
+#include "nimble_scanner.h"
+#include "nimble_scanlist.h"
+
+/* default scan duration (1s) */
+#define DEFAULT_DURATION        (1000000U)
+
+int _cmd_scan(int argc, char **argv)
+{
+    uint32_t timeout = DEFAULT_DURATION;
+
+    if ((argc == 2) && memcmp(argv[1], "help", 4) == 0) {

parens

> +    uint32_t timeout = DEFAULT_DURATION;
+
+    if ((argc == 2) && memcmp(argv[1], "help", 4) == 0) {
+        printf("usage: %s [timeout in ms]\n", argv[0]);
+        return 0;
+    }
+    if (argc >= 2) {
+        timeout = (uint32_t)(atoi(argv[1]) * 1000);
+    }
+
+    nimble_scanlist_clear();
+    printf("Scanning for %ums now ...", (unsigned)(timeout / 1000));
+    nimble_scanner_start();
+    xtimer_usleep(timeout);
+    nimble_scanner_stop();
+    puts(" dome\n\nResults:");

`done`

> +}
+
+void nimble_scanner_stop(void)
+{
+    if (ble_gap_disc_active() == 1) {
+        int res = ble_gap_disc_cancel();
+        /* the above should always succeed */
+        assert(res == 0);
+        (void)res;
+    }
+}
+
+int nimble_scanner_status(void)
+{
+    return (ble_gap_disc_active()) ?
+                            NIMBLE_SCANNER_SCANNING : NIMBLE_SCANNER_STOPPED;

Reeeally nitpicky , but the indentation looks a bit of here.

> +}
+
+void nimble_scanner_stop(void)
+{
+    if (ble_gap_disc_active() == 1) {
+        int res = ble_gap_disc_cancel();
+        /* the above should always succeed */
+        assert(res == 0);
+        (void)res;
+    }
+}
+
+int nimble_scanner_status(void)
+{
+    return (ble_gap_disc_active()) ?
+                            NIMBLE_SCANNER_SCANNING : NIMBLE_SCANNER_STOPPED;

Independent from the indentation: I usually do something like that for multiline ternary operators:

```C
    return (ble_gap_disc_active())
         ? NIMBLE_SCANNER_SCANNING
         : NIMBLE_SCANNER_STOPPED;
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11281#pullrequestreview-219591761
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190327/f115cf9b/attachment-0001.html>


More information about the notifications mailing list