Merge pull request #16839 from haukepetersen/opt_nimble_scannererrno

nimble/scanner: migrate to errno return values
This commit is contained in:
Martine Lenders 2021-09-17 16:22:29 +02:00 committed by GitHub
commit 7bf1fad7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 26 deletions

View File

@ -21,7 +21,9 @@
#ifndef NIMBLE_SCANNER_H #ifndef NIMBLE_SCANNER_H
#define NIMBLE_SCANNER_H #define NIMBLE_SCANNER_H
#include <errno.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#include "host/ble_hs.h" #include "host/ble_hs.h"
@ -29,16 +31,6 @@
extern "C" { extern "C" {
#endif #endif
/**
* @brief Return values used by this submodule
*/
enum {
NIMBLE_SCANNER_OK = 0,
NIMBLE_SCANNER_SCANNING = 1,
NIMBLE_SCANNER_STOPPED = 2,
NIMBLE_SCANNER_ERR = -1,
};
/** /**
* @brief Callback signature triggered by this module for each discovered * @brief Callback signature triggered by this module for each discovered
* advertising packet * advertising packet
@ -60,8 +52,7 @@ typedef void(*nimble_scanner_cb)(uint8_t type,
* default parameters * default parameters
* @param[in] disc_cb callback triggered of each received advertising packet * @param[in] disc_cb callback triggered of each received advertising packet
* *
* @return NIMBLE_SCANNER_OK on success * @return 0 on success
* @return NIMBLE_SCANNER_ERR if putting NimBLE into discovery mode failed
*/ */
int nimble_scanner_init(const struct ble_gap_disc_params *params, int nimble_scanner_init(const struct ble_gap_disc_params *params,
nimble_scanner_cb disc_cb); nimble_scanner_cb disc_cb);
@ -71,6 +62,9 @@ int nimble_scanner_init(const struct ble_gap_disc_params *params,
* *
* @note Scanning will run for ever unless stopped or unless a different * @note Scanning will run for ever unless stopped or unless a different
* scan duration is set with @ref nimble_scanner_set_scan_duration * scan duration is set with @ref nimble_scanner_set_scan_duration
*
* @return 0 on success
* @return -ECANCELED on error
*/ */
int nimble_scanner_start(void); int nimble_scanner_start(void);
@ -82,10 +76,13 @@ void nimble_scanner_stop(void);
/** /**
* @brief Get the current scanning status * @brief Get the current scanning status
* *
* @return NIMBLE_SCANNER_SCANNING if currently scanning * @return true if currently scanning
* @return NIMBLE_SCANNER_STOPPED if the scanner is stopped * @return false if the scanner is stopped
*/ */
int nimble_scanner_status(void); static inline bool nimble_scanner_is_active(void)
{
return ble_gap_disc_active();
}
/** /**
* @brief Set the duration for the scanning procedure. * @brief Set the duration for the scanning procedure.

View File

@ -61,11 +61,11 @@ int nimble_scanner_start(void)
&_scan_params, _on_scan_evt, NULL); &_scan_params, _on_scan_evt, NULL);
if (res != 0) { if (res != 0) {
DEBUG("[scanner] err: start failed (%i)\n", res); DEBUG("[scanner] err: start failed (%i)\n", res);
return NIMBLE_SCANNER_ERR; return -ECANCELED;
} }
} }
return NIMBLE_SCANNER_OK; return 0;
} }
void nimble_scanner_stop(void) void nimble_scanner_stop(void)
@ -78,13 +78,6 @@ void nimble_scanner_stop(void)
} }
} }
int nimble_scanner_status(void)
{
return (ble_gap_disc_active())
? NIMBLE_SCANNER_SCANNING
: NIMBLE_SCANNER_STOPPED;
}
void nimble_scanner_set_scan_duration(int32_t duration_ms) void nimble_scanner_set_scan_duration(int32_t duration_ms)
{ {
_scan_duration = duration_ms; _scan_duration = duration_ms;
@ -107,5 +100,5 @@ int nimble_scanner_init(const struct ble_gap_disc_params *params,
} }
_disc_cb = disc_cb; _disc_cb = disc_cb;
return NIMBLE_SCANNER_OK; return 0;
} }

View File

@ -296,7 +296,7 @@ static void _do_scan(nimble_scanner_cb cb, unsigned duration)
printf("err: duration must be > 0\n"); printf("err: duration must be > 0\n");
return; return;
} }
if (nimble_scanner_status() == NIMBLE_SCANNER_SCANNING) { if (nimble_scanner_is_active()) {
printf("err: scanner already active\n"); printf("err: scanner already active\n");
return; return;
} }