星闪(NearLink),中国原生的新一代无线短距通信技术。面向万物互联时代,星闪引入关键技术和创新理念,赋予智能终端新的连接方式。与传统短距传输技术方案相比,星闪在功耗、速度、覆盖范围和连接性能全面领先,可以在智能终端、智能家居、智能汽车、智能制造等各类细分场景下实现更极致的用户体验
SLE UART Server端:
点击工具栏中的“系统配置”,打开配置界面.
选择Enable SLE UART Server sample
Application --->
[] Enable Sample.
[ ] Enable the Sample of peripheral.
[] Enable the Sample of products.
[ ] Enable all the sample of product, it's just for build.
[ ] Support BLE UART sample.
[*] Support SLE UART sample.
SLE UART Sample Configuration --->
Select sle uart type (Enable SLE UART Server sample.) --->
(X) Enable SLE UART Server sample.
( ) Enable SLE UART Client sample.
按下"Save"键保存配置。
关键代码,位于application\samples\products\sle_uart\sle_uart.c中
static void ssaps_server_write_request_cbk(uint8_t server_id, uint16_t conn_id, ssaps_req_write_cb_t *write_cb_para,
errcode_t status)
{
osal_printk("%s ssaps write request callback cbk server_id:%x, conn_id:%x, handle:%x, status:%x\\r\\n",
SLE_UART_SERVER_LOG, server_id, conn_id, write_cb_para->handle, status);
if ((write_cb_para->length > 0) && write_cb_para->value) {
osal_printk("\\n sle uart recived data : %s\\r\\n", write_cb_para->value);
uapi_uart_write(CONFIG_SLE_UART_BUS, (uint8_t *)write_cb_para->value, write_cb_para->length, 0);
}
}
static void sle_uart_server_read_int_handler(const void *buffer, uint16_t length, bool error)
{
unused(error);
if (sle_uart_client_is_connected()) {
#ifdef CONFIG_SAMPLE_SUPPORT_LOW_LATENCY_TYPE
g_buff_data_valid = 1;
g_uart_buff_len = 0;
(void)memcpy_s(g_buff, SLE_UART_SERVER_SEND_BUFF_MAX_LEN, buffer, length);
g_uart_buff_len = length;
#else
sle_uart_server_send_report_by_handle(buffer, length);
#endif
} else {
osal_printk("%s sle client is not connected! \\r\\n", SLE_UART_SERVER_LOG);
}
}
static void *sle_uart_server_task(const char *arg)
{
sle_uart_server_init(ssaps_server_read_request_cbk, ssaps_server_write_request_cbk);
...
errcode_t ret = uapi_uart_register_rx_callback(CONFIG_SLE_UART_BUS,
UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE,
1, sle_uart_server_read_int_handler);
}
在
application\samples\products\sle_uart\sle_uart_server\sle_uart_server.c文件static void sle_pair_complete_cbk(uint16_t conn_id, const sle_addr_t *addr, errcode_t status)
函数中增加:
if (status == ERRCODE_SUCC) {
example_led_control_entry();
}
在
application\samples\products\sle_uart\sle_uart_server\sle_uart_server.c文件`增加
typedef enum {
EXAMPLE_CONTORL_LED_EXIT = 0x00,
EXAMPLE_CONTORL_LED_MAINBOARD_LED_ON = 0x01,
EXAMPLE_CONTORL_LED_MAINBOARD_LED_OFF = 0x02,
EXAMPLE_CONTORL_LED_MAINBOARD_LED_blinky = 0x03,
} example_control_led_type_t;
static int example_led_control_task(const char *arg)
{
unused(arg);
example_control_led_type_t last_led_operation = EXAMPLE_CONTORL_LED_MAINBOARD_LED_blinky;
PRINT("[SLE Server] start led control task\\r\\n");
while (1)
{
(void)osal_msleep(5000);
if (last_led_operation == EXAMPLE_CONTORL_LED_MAINBOARD_LED_blinky) {
uint8_t write_req_data[] = { 'L', 'E', 'D', ' *', 'O', 'N'};
example_sle_server_send_notify_by_handle(write_req_data, sizeof(write_req_data));
last_led_operation = EXAMPLE_CONTORL_LED_MAINBOARD_LED_ON;} else if (last_led_operation == EXAMPLE_CONTORL_LED_MAINBOARD_LED_ON) {uint8_t write_req_data[] = { 'L', 'E', 'D', '* ', 'O', 'F', 'F'};example_sle_server_send_notify_by_handle(write_req_data, sizeof(write_req_data));
last_led_operation = EXAMPLE_CONTORL_LED_MAINBOARD_LED_OFF;} else if (last_led_operation == EXAMPLE_CONTORL_LED_MAINBOARD_LED_OFF) {uint8_t write_req_data[] = { 'L', 'E', 'D', '_', 'B', 'L'};example_sle_server_send_notify_by_handle(write_req_data, sizeof(write_req_data));last_led_operation = EXAMPLE_CONTORL_LED_MAINBOARD_LED_blinky;}
}
return 0;
}
static void example_led_control_entry(void)
{
osal_task *task_handle = NULL;
osal_kthread_lock();
task_handle = osal_kthread_create((osal_kthread_handler)example_led_control_task, 0, "LedControlTask",
LED_CONTROL_TASK_STACK_SIZE);
if (task_handle != NULL) {
osal_kthread_set_priority(task_handle, LED_CONTROL_TASK_PRIO);
osal_kfree(task_handle);
}
osal_kthread_unlock();
}
编译操作:
INFO:root:section_name section_size
INFO:root:startup 424
INFO:root:.sysintcall.init 52
INFO:root:.patch 2344
INFO:root:.rom_ram_cb_text 1816
INFO:root:.plat_romdata 212
INFO:root:.wifi_romdata 98
INFO:root:.btc_romdata 672
INFO:root:.btc_text_tcm 7206
INFO:root:.patch_on_tcm 1528
INFO:root:.btc_data_tcm 57
INFO:root:.wifi_data_tcm 3408
INFO:root:.plat_text_sram 10884
INFO:root:.patch_on_sram 2520
INFO:root:.plat_text_flash 177004
INFO:root:.wifi_text_flash 585302
INFO:root:.patch_on_flash 1908
INFO:root:.btc_text_flash 131560
INFO:root:.bth_text_flash 231140
INFO:root:.radar_text_flash 32012
INFO:root:.radar_ai_text_flash 5868
INFO:root:.text 42040
INFO:root:.btc_data_flash 4896
INFO:root:.bth_data_flash 2364
INFO:root:.data 380
INFO:root:total_size: 1245695
INFO:root:
INFO:root:++++++++++++++++++++++++++++++end buildAnalyzer++++++++++++++++++++++++++++++
project analysis Done!
================================ [SUCCESS] Took 109.83 seconds ================================
* 终端将被任务重用,按任意键关闭。
写入server 端星闪开发板
Client 端:
点击工具栏中的“系统配置”,打开配置界面.
选择Enable SLE UART Client sample
Application --->
[] Enable Sample.
[ ] Enable the Sample of peripheral.
[] Enable the Sample of products.
[ ] Enable all the sample of product, it's just for build.
[ ] Support BLE UART sample.
[*] Support SLE UART sample.
SLE UART Sample Configuration --->
Select sle uart type (Enable SLE UART Server sample.) --->
() Enable SLE UART Server sample.
(X ) Enable SLE UART Client sample.
按下"Save"键保存配置。
关键代码,位于application\samples\products\sle_uart\sle_uart.c中
void sle_uart_notification_cb(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *data,
errcode_t status)
{
unused(client_id);
unused(conn_id);
unused(status);
osal_printk("\\n sle uart recived data : %s\\r\\n", data->data);
uapi_uart_write(CONFIG_SLE_UART_BUS, (uint8_t *)(data->data), data->data_len, 0);
}
void sle_uart_indication_cb(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *data,
errcode_t status)
{
unused(client_id);
unused(conn_id);
unused(status);
osal_printk("\\n sle uart recived data : %s\\r\\n", data->data);
uapi_uart_write(CONFIG_SLE_UART_BUS, (uint8_t *)(data->data), data->data_len, 0);
}
static void sle_uart_client_read_int_handler(const void *buffer, uint16_t length, bool error)
{
unused(error);
ssapc_write_param_t *sle_uart_send_param = get_g_sle_uart_send_param();
uint16_t g_sle_uart_conn_id = get_g_sle_uart_conn_id();
sle_uart_send_param->data_len = length;
sle_uart_send_param->data = (uint8_t *)buffer;
ssapc_write_req(0, g_sle_uart_conn_id, sle_uart_send_param);
}
static void *sle_uart_client_task(const char *arg)
{
unused(arg);
uart_init_pin();
uart_init_config();
uapi_uart_unregister_rx_callback(CONFIG_SLE_UART_BUS);
errcode_t ret = uapi_uart_register_rx_callback(CONFIG_SLE_UART_BUS,
UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE,
1, sle_uart_client_read_int_handler);
sle_uart_client_init(sle_uart_notification_cb, sle_uart_indication_cb);
if (ret != ERRCODE_SUCC) {
osal_printk("Register uart callback fail.");
return NULL;
}
return NULL;
}
在application\samples\products\sle_uart\sle_uart.c
文件 void sle_uart_notification_cb(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *data,errcode_t status)`函数中增加:
if (data->data_len == strlen("LED_ON") && data->data[0] == 'L' && data->data[1] =='E' && data->data[2] == 'D' &&
data->data[3] == '_' && data->data[4] == 'O' && data->data[5] == 'N' ) {
last_led_operation = EXAMPLE_CONTORL_LED_MAINBOARD_LED_ON;
}
if (data->data_len == strlen("LED_OFF") && data->data[0] == 'L' && data->data[1] =='E' && data->data[2] == 'D' &&
data->data[3] == '_' && data->data[4] == 'O' && data->data[5] == 'F' && data->data[6] == 'F' ) {
last_led_operation = EXAMPLE_CONTORL_LED_MAINBOARD_LED_OFF;
}
if (data->data_len == strlen("LED_ON") && data->data[0] == 'L' && data->data[1] =='E' && data->data[2] == 'D' &&
data->data[3] == '_' && data->data[4] == 'B' && data->data[5] == 'L' ) {
last_led_operation = EXAMPLE_CONTORL_LED_MAINBOARD_LED_blinky;
}
在
在application\samples\products\sle_uart\sle_uart.c
文件 #elif defined(CONFIG_SAMPLE_SUPPORT_SLE_UART_CLIENT)
之后
增加:
typedef enum {
EXAMPLE_CONTORL_LED_EXIT = 0x00,
EXAMPLE_CONTORL_LED_MAINBOARD_LED_ON = 0x01,
EXAMPLE_CONTORL_LED_MAINBOARD_LED_OFF = 0x02,
EXAMPLE_CONTORL_LED_MAINBOARD_LED_blinky = 0x03,
} example_control_led_type_t;
example_control_led_type_t last_led_operation = EXAMPLE_CONTORL_LED_EXIT;
选择案例:点击工具栏中的“系统配置”选项,选择Application目录,勾选“Enable Sample”、“Enable the Sample of peripheral”以及需要要编译的BLINK,并保存。
在application\samples\peripheral\blinky\blinky_cmsis.c文件中 while (1) {
下面变更为如下程序:
if(last_led_operation&1){uapi_gpio_set_val(CONFIG_BLINKY_PIN, GPIO_LEVEL_HIGH);}
else {uapi_gpio_set_val(CONFIG_BLINKY_PIN, GPIO_LEVEL_LOW);}osal_msleep(CONFIG_BLINKY_DURATION_MS);if(last_led_operation==1){uapi_gpio_set_val(CONFIG_BLINKY_PIN, GPIO_LEVEL_HIGH);}else {uapi_gpio_set_val(CONFIG_BLINKY_PIN, GPIO_LEVEL_LOW);}osal_msleep(CONFIG_BLINKY_DURATION_MS);printf("Test BLINKY\\r\\n");//PRINT("Test BLINKY\\r\\n");write("BLINKY"); print();i++;if(i>10){i=0;osal_printk("Hello BearPi! %d \\r\\n",i);}``````
程序前加入
`extern volatile example_control_led_type_t last_led_operation;```
编译操作:
NFO:root:
INFO:root:section_name section_size
INFO:root:startup 428
INFO:root:.sysintcall.init 52
INFO:root:.patch 2344
INFO:root:.rom_ram_cb_text 1816
INFO:root:.plat_romdata 212
INFO:root:.wifi_romdata 98
INFO:root:.btc_romdata 672
INFO:root:.btc_text_tcm 7206
INFO:root:.patch_on_tcm 1528
INFO:root:.btc_data_tcm 57
INFO:root:.wifi_data_tcm 3408
INFO:root:.plat_text_sram 10884
INFO:root:.patch_on_sram 2520
INFO:root:.plat_text_flash 177108
INFO:root:.wifi_text_flash 585302
INFO:root:.patch_on_flash 1908
INFO:root:.btc_text_flash 131560
INFO:root:.bth_text_flash 233004
INFO:root:.radar_text_flash 32012
INFO:root:.radar_ai_text_flash 5868
INFO:root:.text 42040
INFO:root:.btc_data_flash 4896
INFO:root:.bth_data_flash 2372
INFO:root:.data 380
INFO:root:total_size: 1247675
INFO:root:
INFO:root:++++++++++++++++++++++++++++++end buildAnalyzer++++++++++++++++++++++++++++++
project analysis Done!
================================ [SUCCESS] Took 178.29 seconds ================================```
写入Client端
先开server端电再开Client端电
Client端