#include "ble_scanner.h"
#ifdef DUALMCU_INTERFACE
#endif
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define DEBUG_LOG_MODULE_NAME "BLE SCANNER"
#define DEBUG_LOG_MAX_LEVEL LVL_INFO
#define BLE_SCANNER_CONFIG_REQ_EP 13
#define BLE_SCANNER_CONFIG_REPLY_EP 14
#define BLE_SCANNER_DATA_EP 18
typedef enum
{
SCANNER_CMD_DISABLE = 0,
SCANNER_CMD_ENABLE = 1,
SCANNER_CMD_ENABLE_PERIODIC = 2
} scanner_cmd_e;
typedef struct __attribute__ ((__packed__))
{
uint8_t channel;
} enable_payload_t;
typedef struct __attribute__ ((__packed__))
{
uint16_t period_s;
uint16_t scan_length_s;
uint8_t channel;
} enable_periodic_payload_t;
typedef struct __attribute__((packed))
{
uint32_t id;
uint8_t cmd_id;
union
{
enable_payload_t enable;
enable_periodic_payload_t enable_periodic;
} payload;
} cmd_t;
typedef struct __attribute__((packed))
{
uint32_t id;
uint8_t res;
} response_t;
{
const uint8_t pattern_enocean[] = {0x4C, 0x2E, 0x00, 0x00, 0x15};
!memcmp(pattern_enocean, packet->
payload,
sizeof(pattern_enocean));
}
const shared_data_item_t * item,
{
Ble_scanner_res_e res;
cmd_t * cmd_p;
response_t response;
Ble_scanner_scanning_config_t conf;
{
}
cmd_p = (cmd_t *) data->
bytes;
switch (cmd_p->cmd_id)
{
case SCANNER_CMD_DISABLE:
res = Ble_scanner_stop();
break;
case SCANNER_CMD_ENABLE:
conf.type = BLE_SCANNER_SCANNING_TYPE_ALWAYS;
conf.channel = cmd_p->payload.enable.channel;
res = Ble_scanner_start(&conf);
res,
conf.channel);
break;
case SCANNER_CMD_ENABLE_PERIODIC:
conf.type = BLE_SCANNER_SCANNING_TYPE_PERIODIC;
conf.period_s = cmd_p->payload.enable_periodic.period_s;
conf.scan_length_s = cmd_p->payload.enable_periodic.scan_length_s;
conf.channel = cmd_p->payload.enable_periodic.channel;
res = Ble_scanner_start(&conf);
LOG(
LVL_INFO,
"Enable periodic = %d (%ds every %ds on channel=%d))",
res,
conf.scan_length_s,
conf.period_s,
conf.channel);
break;
default:
}
response.id = cmd_p->id;
response.res = res;
.
bytes = (uint8_t *) &response,
.num_bytes = sizeof(response),
.src_endpoint = BLE_SCANNER_CONFIG_REPLY_EP,
.dest_endpoint = BLE_SCANNER_CONFIG_REPLY_EP
};
}
static shared_data_item_t ble_scanner_control =
{
.cb = ble_scanner_configuration_cb,
.filter =
{
.src_endpoint = BLE_SCANNER_CONFIG_REQ_EP,
.dest_endpoint = BLE_SCANNER_CONFIG_REQ_EP,
.multicast_cb = NULL
}
};
volatile uint32_t tempo = 0;
static size_t on_beacon_received(Ble_scanner_beacon_t beacons[],
size_t beacons_available)
{
.
bytes = (uint8_t *) beacons,
.num_bytes = sizeof(Ble_scanner_beacon_t) - BLE_SCANNER_MAX_BEACON_SIZE + beacons[0].length,
.src_endpoint = BLE_SCANNER_DATA_EP,
.dest_endpoint = BLE_SCANNER_DATA_EP
};
return 1;
}
{
#ifdef DUALMCU_INTERFACE
#else
{
return;
}
#endif
Ble_scanner_init(ble_scanner_filter, on_beacon_received);
}