提交 8ab0af85 编写于 作者: L leo 提交者: Lu Wang

[breeze] Sync with gerrit breeze changes, including 1. Breeze APIs and...

[breeze] Sync with gerrit breeze changes, including 1. Breeze APIs and examples 2.Breeze 3 libs 3. Breeze HAL APIs. (#747)
上级 024f0915
......@@ -10,11 +10,19 @@
#define SOFTWARE_VERSION "0.2.0"
#define SOFTWARE_VERSION_LEN 5
#if 1
#define PRODUCT_ID 213226
#define DEVICE_SECRET "cNwnA4W7amnkgG6s8zGXSJD3nI1c7kO1"
#define DEVICE_NAME "112233445566"
#define PRODUCT_KEY "b1XVhqfan1X"
#define PRODUCT_SECRET "iX6XqAjaCTXBv4h3"
#else
#define PRODUCT_ID 619359
#define DEVICE_SECRET "XtwYkcdFLHSdrzZSjNV1IhpIFhRduHLr"
#define DEVICE_NAME "ABCDEF12345678"
#define PRODUCT_KEY "a1aIpTlmQ2b"
#define PRODUCT_SECRET "xpxzSuaKhMXVzzSm"
#endif
static bool ble_connected = false;
......@@ -96,11 +104,6 @@ static void alink_work(void *arg)
init_alink.set_cb = set_dev_status_handler;
init_alink.get_cb = get_dev_status_handler;
init_alink.apinfo_cb = apinfo_handler;
#ifdef CONFIG_AIS_OTA
init_alink.enable_ota = true;
#endif
init_alink.enable_auth = true;
init_alink.auth_type = ALI_AUTH_BY_PRODUCT_SECRET;
init_alink.secret_len = strlen(DEVICE_SECRET);
memcpy(init_alink.secret, DEVICE_SECRET, init_alink.secret_len);
......@@ -132,7 +135,7 @@ int application_start(void)
#ifdef CONTINUE_BEL_ADV
aos_post_delayed_action(5000, adv_work, NULL);
#endif
aos_loop_run();
breeze_event_dispatcher();
return 0;
}
......@@ -11,6 +11,7 @@ $(NAME)_COMPONENTS := yloop bluetooth.breeze cli
GLOBAL_DEFINES += DEBUG
GLOBAL_DEFINES += CONFIG_BLE_LINK_PARAMETERS
#GLOBAL_DEFINES += CONFIG_BT_SMP
#GLOBAL_DEFINES += CONFIG_MODEL_SECURITY
GLOBAL_DEFINES += BUILD_AOS
......@@ -28,4 +29,4 @@ GLOBAL_DEFINES += APPEND_USER_ADV
endif
GLOBAL_INCLUDES += ../
\ No newline at end of file
GLOBAL_INCLUDES += ../
......@@ -321,10 +321,10 @@ int application_start(int argc, char **argv)
};
if (combo_init() == 0) {
breeze_awss_start(apinfo_ready_handler, &dinfo);
breeze_awss_init(apinfo_ready_handler, &dinfo);
}
breeze_event_dispatcher();
breeze_awss_start();
return 0;
}
......@@ -13,6 +13,8 @@
#include <aos/list.h>
#include <dis.h>
#define BLE_TX_INDICATION_COMPLETED 0
static void (*g_indication_txdone)(uint8_t res);
struct bt_conn *g_conn = NULL;
ais_bt_init_t * bt_init_info = NULL;
......@@ -306,6 +308,20 @@ enum
AIS_ATTR_NUM,
};
static void ble_event_handler(input_event_t *event, void *priv_data)
{
if (event->type != EV_BLE) {
return;
}
switch (event->code) {
case BLE_TX_INDICATION_COMPLETED:
g_indication_txdone(0);
break;
default:
break;
}
}
ais_err_t ble_stack_init(ais_bt_init_t *info)
{
int err;
......@@ -380,6 +396,8 @@ ais_err_t ble_stack_init(ais_bt_init_t *info)
bt_gatt_service_register(&ais_svc);
dis_init("AIS", "AliOSThings");
aos_register_event_filter(EV_BLE, ble_event_handler, NULL);
return AIS_ERR_SUCCESS;
}
......@@ -421,7 +439,7 @@ static void indicate_cb(struct bt_conn *conn, const struct bt_gatt_attr *attr,
}
}
ais_err_t ble_send_indication(uint8_t *p_data, uint16_t length)
ais_err_t ble_send_indication(uint8_t *p_data, uint16_t length, void (*txdone)(uint8_t res))
{
int err;
struct bt_gatt_indicate_params *ind_params;
......@@ -454,6 +472,8 @@ ais_err_t ble_send_indication(uint8_t *p_data, uint16_t length)
aos_free(param);
return AIS_ERR_GATT_INDICATE_FAIL;
} else {
g_indication_txdone = txdone;
aos_post_event(EV_BLE, BLE_TX_INDICATION_COMPLETED, 1);
return AIS_ERR_SUCCESS;
}
}
......
......@@ -40,122 +40,6 @@ long long os_now_ms()
return aos_now_ms();
}
typedef struct event_ctx_s
{
os_event_cb_t cb;
void *priv;
} event_ctx_t;
int os_post_event(os_event_type_t type, os_event_code_t code,
unsigned long value)
{
uint16_t atype, acode;
unsigned long avalue;
switch (type) {
case OS_EV_BLE:
atype = EV_BLE;
break;
case OS_EV_COMBO:
atype = EV_BZ_COMBO;
break;
case OS_EV_AUTH:
atype = EV_BZ_AUTH;
break;
default:
break;
}
/* Since type is already remapped, it's OK to use code and value without
* remapp */
acode = code;
avalue = value;
return aos_post_event(atype, acode, avalue);
}
static void event_helper(input_event_t *event, void *priv)
{
os_event_t oevt;
os_event_cb_t cb;
event_ctx_t *ctx;
if (!event || !priv) {
printf("Error: invalid argument (%s).\r\n", __func__);
return;
}
ctx = (event_ctx_t *)priv;
cb = ctx->cb;
switch (event->type) {
case EV_BLE:
oevt.type = OS_EV_BLE;
break;
case EV_BZ_COMBO:
oevt.type = OS_EV_COMBO;
break;
case EV_BZ_AUTH:
oevt.type = OS_EV_AUTH;
break;
default:
printf("Error: invaid event type.\r\n");
return -1;
}
oevt.code = event->code;
oevt.value = event->value;
cb(&oevt, ctx->priv);
/* Do NOT free the ctx, since one event may want be triggered multiple
* times. */
/* ??aos_free(ctx);?? */
}
/* TODO: one type may be registered multiple times, so more than one ctx should
* be managed. */
int os_register_event_filter(os_event_type_t type, os_event_cb_t cb, void *priv)
{
uint16_t atype;
event_ctx_t *ctx;
ctx = aos_malloc(sizeof(event_ctx_t));
if (!ctx) {
printf("Failed to allocate mm for event (type %d)\r\n", type);
return -1;
}
switch (type) {
case OS_EV_BLE:
atype = EV_BLE;
break;
case OS_EV_COMBO:
atype = EV_BZ_COMBO;
break;
case OS_EV_AUTH:
atype = EV_BZ_AUTH;
break;
default:
break;
}
ctx->cb = cb;
ctx->priv = priv;
return aos_register_event_filter(atype, event_helper, ctx);
}
void os_post_delayed_action(int ms, void (*action)(void *arg), void *arg)
{
aos_post_delayed_action(ms, action, arg);
}
void os_start_event_dispatcher()
{
aos_loop_run();
}
int os_kv_set(const char *key, const void *value, int len, int sync)
{
return 0;
......@@ -170,3 +54,8 @@ int os_kv_del(const char *key)
{
return 0;
}
int os_rand(void)
{
return 0;
}
......@@ -293,7 +293,7 @@ ais_err_t ble_send_notification(uint8_t *p_data, uint16_t length);
* @parma[in] length data length.
* @return 0 on success, erro code if failure.
*/
ais_err_t ble_send_indication(uint8_t *p_data, uint16_t length);
ais_err_t ble_send_indication(uint8_t *p_data, uint16_t length, void (*txdone)(uint8_t res));
/**
* API to disconnect BLE connection.
......
......@@ -110,49 +110,6 @@ void os_msleep(int ms);
*/
long long os_now_ms();
/**
* Post an asynchronous event. The implementation must ensure
* the event can be receviced by the event filter.
*
* @param[in] type event type.
* @param[in] code event code.
* @param[in] value event value.
*
* @return the operation status, 0 is OK, others is error.
*/
int os_post_event(os_event_type_t type, os_event_code_t code,
unsigned long value);
/**
* Register system event filter callback. The callback is expected to be
* called once the event is post/triggered.
*
* Note: it's implementation dependent how the events are dispatched.
* e.g. event dispatcher as a distinguished thread, or in a main loop.
*
* @param[in] type event type interested.
* @param[in] cb system event callback.
* @param[in] priv private data past to cb.
*
* @return the operation status, 0 is OK, others is error.
*/
int os_register_event_filter(os_event_type_t type, os_event_cb_t cb,
void *priv);
/**
* Post a delayed action to be executed in event thread.
*
* @param[in] ms milliseconds to wait, -1 means don't care.
* @param[in] action action to be executed.
* @param[in] arg private data past to action.
*/
void os_post_delayed_action(int ms, void (*action)(void *arg), void *arg);
/**
* Start a event thread.
*/
void os_start_event_dispatcher();
/**
* Add a new KV pair.
*
......@@ -189,4 +146,11 @@ int os_kv_get(const char *key, void *buffer, int *buffer_len);
*/
int os_kv_del(const char *key);
/**
* Generate random number.
*
* @return random value implemented by platform.
*/
int os_rand(void);
#endif
......@@ -31,12 +31,6 @@ typedef enum
NONE
} breeze_event_t;
typedef enum
{
ALI_AUTH_BY_PRODUCT_SECRET, /**< Authentication by product secret. */
ALI_AUTH_BY_DEVICE_SECRET, /**< Authentication by device secret. */
} ali_auth_type_t;
typedef struct
{
char ssid[32 + 1];
......@@ -85,6 +79,14 @@ typedef void (*set_dev_status_cb)(uint8_t *buffer, uint32_t length);
*/
typedef void (*get_dev_status_cb)(uint8_t *buffer, uint32_t length);
/**
* @brief Callback when ap info obtained.
*
* @param[out] model @n ap info struct.
* @return None.
* @see None.
* @note This API should be implemented by user and will be called by SDK.
*/
typedef void (*apinfo_ready_cb)(breeze_apinfo_t *ap);
/**
......@@ -105,9 +107,6 @@ struct device_config
char product_secret[STR_PROD_SEC_LEN];
uint8_t product_secret_len;
char version[STR_VER_LEN];
bool enable_ota;
bool enable_auth;
ali_auth_type_t auth_type;
dev_status_changed_cb status_changed_cb;
set_dev_status_cb set_cb;
get_dev_status_cb get_cb;
......@@ -132,6 +131,27 @@ int breeze_start(struct device_config *dev_conf);
*/
int breeze_end(void);
/**
* @brief Initialize breeze awss module.
*
* @param[in] cb The callback to be called by breeze SDK when AP info ready.
* @param[in] info The device information required by breeze SDK.
* @return None.
* @see None.
*/
void breeze_awss_init(apinfo_ready_cb cb, breeze_dev_info_t *info);
/**
* @brief Start breeze awss process.
*
* @param None.
* @return None.
* @see None.
*
* @note When this API is called, do not call breeze_start anymore.
*/
void breeze_awss_start();
/**
* @brief Post device status.
*
......@@ -191,16 +211,6 @@ void breeze_append_adv_data(uint8_t *data, uint32_t len);
*/
void breeze_restart_advertising();
/**
* @brief Start breeze awss process.
*
* @param[in] cb The callback to be called by breeze SDK when AP info ready.
* @param[in] info The device information required by breeze SDK.
* @return None.
* @see None.
* @note When this API is called, do not call breeze_start anymore.
*/
void breeze_awss_start(apinfo_ready_cb cb, breeze_dev_info_t *info);
#if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册