#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,
{
(void) 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)
{
(void) 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;
}
{
(void) functions;
#ifdef DUALMCU_INTERFACE
#else
{
return;
}
#endif
Ble_scanner_init(ble_scanner_filter, on_beacon_received);
}
#define LVL_DEBUG
Macros to define several log levels: Debug, Info, Warning, Error.
#define LOG(level, fmt,...)
Print a log message if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.
dualmcu_lib_res_e Dualmcu_lib_init(uint32_t baudrate, bool flow_ctrl)
Initialize Dualmcu_lib.
Board-independent LED functions.
led_res_e Led_toggle(uint8_t led_id)
Toggle the given LED.
__STATIC_INLINE app_res_e configureNodeFromBuildParameters()
Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (f...
@ SHARED_DATA_NET_MODE_ALL
app_lib_data_send_res_e Shared_Data_sendData(app_lib_data_to_send_t *data, app_lib_data_data_sent_cb_f sent_cb)
Send data. The packet to send is represented as a app_lib_data_to_send_t struct.
app_res_e Shared_Data_addDataReceivedCb(shared_data_item_t *item)
Add a new packet received item to the list. If the item is already in the list it is only updated.
app_res_e Stack_State_startStack()
Start the stack.
List of global functions, passed to App_entrypoint()
BLE structure received from network. Used in callback function set with lib_beacon_rx->setBeaconRecei...
@ APP_LIB_DATA_QOS_NORMAL
app_lib_data_receive_res_e
Return value of data reception callback.
@ APP_LIB_DATA_RECEIVE_RES_HANDLED
@ APP_LIB_DATA_RECEIVE_RES_NOT_FOR_APP
A struct for lib_data->sendData().
Struct passed to data reception callback functions.