mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
nrf8001: added new BLE module with broadcasting example
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
This commit is contained in:
@ -24,6 +24,7 @@ add_executable (mpu9150-example mpu9150-example.cxx)
|
||||
add_executable (maxds3231m-example maxds3231m.cxx)
|
||||
add_executable (max31723-example max31723.cxx)
|
||||
add_executable (max5487-example max5487.cxx)
|
||||
add_executable (nrf8001-broadcast-example nrf8001_broadcast.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -46,6 +47,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/mpu9150)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/maxds3231m)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max31723)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max5487)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/nrf8001)
|
||||
|
||||
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -73,3 +75,4 @@ target_link_libraries (mpu9150-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (maxds3231m-example maxds3231m ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max31723-example max31723 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max5487-example max5487 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf8001-broadcast-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
177
examples/nrf8001_broadcast.cxx
Normal file
177
examples/nrf8001_broadcast.cxx
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "nrf8001.h"
|
||||
#include "nrf8001_broadcast.h"
|
||||
#include <lib_aci.h>
|
||||
#include <aci_setup.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
|
||||
static services_pipe_type_mapping_t
|
||||
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
|
||||
#else
|
||||
#define NUMBER_OF_PIPES 0
|
||||
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
|
||||
*/
|
||||
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
|
||||
|
||||
/**
|
||||
* aci_struct that will contain
|
||||
* total initial credits
|
||||
* current credit
|
||||
* current state of the aci (setup/standby/active/sleep)
|
||||
* open remote pipe pending
|
||||
* close remote pipe pending
|
||||
* Current pipe available bitmap
|
||||
* Current pipe closed bitmap
|
||||
* Current connection interval, slave latency and link supervision timeout
|
||||
* Current State of the the GATT client (Service Discovery)
|
||||
* Status of the bond (R) Peer address
|
||||
*/
|
||||
static struct aci_state_t aci_state;
|
||||
|
||||
/**
|
||||
* Temporary buffers for sending ACI commands
|
||||
*/
|
||||
static hal_aci_evt_t aci_data;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_aci_setup () {
|
||||
/**
|
||||
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
|
||||
*/
|
||||
if (NULL != services_pipe_type_mapping) {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
|
||||
} else {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
|
||||
}
|
||||
|
||||
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
|
||||
aci_state.aci_setup_info.setup_msgs = setup_msgs;
|
||||
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
init_aci_setup ();
|
||||
init_local_interfaces (&aci_state, 10, 8, 4);
|
||||
|
||||
while (1) {
|
||||
static bool setup_required = false;
|
||||
if (lib_aci_event_get (&aci_state, &aci_data)) {
|
||||
aci_evt_t * aci_evt;
|
||||
aci_evt = &aci_data.evt;
|
||||
|
||||
switch(aci_evt->evt_opcode) {
|
||||
/**
|
||||
As soon as you reset the nRF8001 you will get an ACI Device Started Event
|
||||
*/
|
||||
case ACI_EVT_DEVICE_STARTED: {
|
||||
aci_state.data_credit_available = aci_evt->params.device_started.credit_available;
|
||||
switch(aci_evt->params.device_started.device_mode) {
|
||||
case ACI_DEVICE_SETUP:
|
||||
/**
|
||||
When the device is in the setup mode
|
||||
*/
|
||||
printf ("Evt Device Started: Setup\n");
|
||||
setup_required = true;
|
||||
break;
|
||||
|
||||
case ACI_DEVICE_STANDBY:
|
||||
printf ("Evt Device Started: Standby\n");
|
||||
lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */);
|
||||
printf ("Broadcasting started\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break; //ACI Device Started Event
|
||||
|
||||
case ACI_EVT_CMD_RSP:
|
||||
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
|
||||
printf ("ACI_EVT_CMD_RSP\n");
|
||||
while (1);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CONNECTED:
|
||||
printf ("ACI_EVT_CONNECTED\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
printf ("ACI_EVT_PIPE_STATUS\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
if (ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status) {
|
||||
printf ("Broadcasting timed out\n");
|
||||
} else {
|
||||
printf ("Evt Disconnected. Link Loss\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
printf ("ACI_EVT_DATA_RECEIVED\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_HW_ERROR:
|
||||
printf ("ACI_EVT_HW_ERROR\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setup_required) {
|
||||
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
|
||||
setup_required = false;
|
||||
}
|
||||
}
|
||||
usleep (100);
|
||||
}
|
||||
|
||||
close_local_interfaces (&aci_state);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
93
examples/nrf8001_broadcast.h
Normal file
93
examples/nrf8001_broadcast.h
Normal file
@ -0,0 +1,93 @@
|
||||
#include "hal_platform.h"
|
||||
#include "aci.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#define PIPE_GAP_DEVICE_NAME_SET 1
|
||||
|
||||
#define NUMBER_OF_PIPES 1
|
||||
|
||||
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
}
|
||||
|
||||
#define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_MIN_CONN_INT 0xffff /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific maximum*/
|
||||
#define GAP_PPCP_SLAVE_LATENCY 0
|
||||
#define GAP_PPCP_CONN_TIMEOUT 0xffff /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
|
||||
|
||||
#define NB_SETUP_MESSAGES 13
|
||||
#define SETUP_MESSAGES_CONTENT {\
|
||||
{0x00,\
|
||||
{\
|
||||
0x07,0x06,0x00,0x00,0x03,0x02,0x41,0xd7,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0x64,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x38,0x02,0xff,0x02,0x58,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x05,0x06,0x10,0x54,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
|
||||
0x02,0x28,0x03,0x01,0x0e,0x03,0x00,0x00,0x2a,0x04,0x14,0x0b,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x62,0x63,0x61,0x73,0x74,0x63,0x73,0x65,0x6d,0x69,\
|
||||
0x2e,0x04,0x04,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x38,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x00,0x00,0x04,0x04,\
|
||||
0x05,0x05,0x00,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x54,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,0x04,0x01,0xff,0xff,0xff,0xff,0x00,0x00,0xff,\
|
||||
0xff,0x04,0x04,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x04,0x06,0x20,0x70,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x0d,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0x60,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0xf0,0x00,0x03,0x4c,0xf2,\
|
||||
},\
|
||||
},\
|
||||
}
|
Reference in New Issue
Block a user