|
@@ -1,80 +1,80 @@
|
|
|
-#include "com_ble.h"
|
|
|
-#include "com_dec.h"
|
|
|
-
|
|
|
-
|
|
|
-static int _on_write(uint16_t con_handle, uint16_t handle, uint32_t flag, uint8_t* datas, uint16_t len);
|
|
|
-
|
|
|
-const uint8_t _service_uuid16[2]={0xa0, 0xfa};
|
|
|
-static const gatts_uuid_base_st _service_uuid_base = {
|
|
|
- .type = BLE_GATTS_UUID_TYPE_16BIT,
|
|
|
- .uuid = _service_uuid16,
|
|
|
-};
|
|
|
-static gatts_service_base_st _service_gatts_base;
|
|
|
-
|
|
|
-const uint8_t _tx_uuid16[2]={0xa1, 0xfa};
|
|
|
-static const gatts_uuid_base_st _tx_uuid_base = {
|
|
|
- .props = ATT_WRITE_WITHOUT_RESPONSE | ATT_READ,
|
|
|
- .type = BLE_GATTS_UUID_TYPE_16BIT,
|
|
|
- .uuid = _tx_uuid16,
|
|
|
-};
|
|
|
-
|
|
|
-const uint8_t _rx_uuid16[2]={0xa2, 0xfa};
|
|
|
-static const gatts_uuid_base_st _rx_uuid_base = {
|
|
|
- .props = ATT_NOTIFY | ATT_READ,
|
|
|
- .type = BLE_GATTS_UUID_TYPE_16BIT,
|
|
|
- .uuid = _rx_uuid16,
|
|
|
-};
|
|
|
-static gatts_service_base_st _rx_gatts_base;
|
|
|
-
|
|
|
-static ble_gatt_characteristic_cb_info_t _tx_write_base_cb_info = {
|
|
|
- .att_callback_func = _on_write,
|
|
|
-};
|
|
|
-
|
|
|
-static ble_gatt_characteristic_cb_info_t _rx_notify_base_cb_info = {
|
|
|
- .client_config = GATT_CLIENT_CONFIG_NOTIFY,
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-int com_ble_init(void)
|
|
|
-{
|
|
|
-
|
|
|
- int ret = 0;
|
|
|
-
|
|
|
- ret = ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
|
|
|
- _service_uuid_base.uuid,
|
|
|
- _service_uuid_base.type,
|
|
|
- &_service_gatts_base.handle);
|
|
|
-
|
|
|
- ret = ble_gatts_characteristic_add(_tx_uuid_base.uuid,
|
|
|
- _tx_uuid_base.type,
|
|
|
- _tx_uuid_base.props,
|
|
|
- NULL,
|
|
|
- &_tx_write_base_cb_info);
|
|
|
-
|
|
|
- ret = ble_gatts_characteristic_add(_rx_uuid_base.uuid,
|
|
|
- _rx_uuid_base.type,
|
|
|
- _rx_uuid_base.props,
|
|
|
- &_rx_gatts_base.handle,
|
|
|
- &_rx_notify_base_cb_info);
|
|
|
-
|
|
|
- return ret;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int _on_write(uint16_t con_handle, uint16_t handle, uint32_t flag, uint8_t* datas, uint16_t len)
|
|
|
-{
|
|
|
-
|
|
|
- com_dec_on_recv(datas, len);
|
|
|
-
|
|
|
- return 0;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void com_ble_notify(uint8_t* buf, uint8_t len)
|
|
|
-{
|
|
|
-
|
|
|
- ble_tx_notify(_rx_gatts_base.handle, buf, len);
|
|
|
-
|
|
|
-}
|
|
|
+#include "com_ble.h"
|
|
|
+#include "com_dec.h"
|
|
|
+
|
|
|
+
|
|
|
+static int _on_write(uint16_t con_handle, uint16_t handle, uint32_t flag, uint8_t* datas, uint16_t len);
|
|
|
+
|
|
|
+const uint8_t _service_uuid16[2]={0xa0, 0xfa};
|
|
|
+static const gatts_uuid_base_st _service_uuid_base = {
|
|
|
+ .type = BLE_GATTS_UUID_TYPE_16BIT,
|
|
|
+ .uuid = _service_uuid16,
|
|
|
+};
|
|
|
+static gatts_service_base_st _service_gatts_base;
|
|
|
+
|
|
|
+const uint8_t _tx_uuid16[2]={0xa1, 0xfa};
|
|
|
+static const gatts_uuid_base_st _tx_uuid_base = {
|
|
|
+ .props = ATT_WRITE_WITHOUT_RESPONSE | ATT_READ,
|
|
|
+ .type = BLE_GATTS_UUID_TYPE_16BIT,
|
|
|
+ .uuid = _tx_uuid16,
|
|
|
+};
|
|
|
+
|
|
|
+const uint8_t _rx_uuid16[2]={0xa2, 0xfa};
|
|
|
+static const gatts_uuid_base_st _rx_uuid_base = {
|
|
|
+ .props = ATT_NOTIFY | ATT_READ,
|
|
|
+ .type = BLE_GATTS_UUID_TYPE_16BIT,
|
|
|
+ .uuid = _rx_uuid16,
|
|
|
+};
|
|
|
+static gatts_service_base_st _rx_gatts_base;
|
|
|
+
|
|
|
+static ble_gatt_characteristic_cb_info_t _tx_write_base_cb_info = {
|
|
|
+ .att_callback_func = _on_write,
|
|
|
+};
|
|
|
+
|
|
|
+static ble_gatt_characteristic_cb_info_t _rx_notify_base_cb_info = {
|
|
|
+ .client_config = GATT_CLIENT_CONFIG_NOTIFY,
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+int com_ble_init(void)
|
|
|
+{
|
|
|
+
|
|
|
+ int ret = 0;
|
|
|
+
|
|
|
+ ret = ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
|
|
|
+ _service_uuid_base.uuid,
|
|
|
+ _service_uuid_base.type,
|
|
|
+ &_service_gatts_base.handle);
|
|
|
+
|
|
|
+ ret = ble_gatts_characteristic_add(_tx_uuid_base.uuid,
|
|
|
+ _tx_uuid_base.type,
|
|
|
+ _tx_uuid_base.props,
|
|
|
+ NULL,
|
|
|
+ &_tx_write_base_cb_info);
|
|
|
+
|
|
|
+ ret = ble_gatts_characteristic_add(_rx_uuid_base.uuid,
|
|
|
+ _rx_uuid_base.type,
|
|
|
+ _rx_uuid_base.props,
|
|
|
+ &_rx_gatts_base.handle,
|
|
|
+ &_rx_notify_base_cb_info);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+static int _on_write(uint16_t con_handle, uint16_t handle, uint32_t flag, uint8_t* datas, uint16_t len)
|
|
|
+{
|
|
|
+
|
|
|
+ com_dec_on_recv(datas, len);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void com_ble_notify(uint8_t* buf, uint8_t len)
|
|
|
+{
|
|
|
+
|
|
|
+ ble_tx_notify(_rx_gatts_base.handle, buf, len);
|
|
|
+
|
|
|
+}
|