没改
This commit is contained in:
parent
0c7475e0d3
commit
e970474420
@ -20,10 +20,6 @@
|
||||
#include "wifi_boarding_internal.h"
|
||||
#include "wifi_boarding_utils.h"
|
||||
|
||||
//helloyifa
|
||||
#include "../iot/iot_sleep_helper.h"
|
||||
#include "../iot/iot_lamp.h"
|
||||
#include "spi_led.h"
|
||||
|
||||
static ble_boarding_info_t *s_ble_boarding_info = NULL;
|
||||
static beken_semaphore_t s_ble_sema = NULL;
|
||||
@ -453,11 +449,10 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
bk_ble_gatts_get_attr_value(param->handle, &buff_size, &tmp_buff);
|
||||
|
||||
wboard_loge("state: %s", param->value);
|
||||
char recv [param->len];
|
||||
os_memcpy((char *)recv, param->value, param->len);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>ָ<EFBFBD><D6B8>
|
||||
char* ptr;
|
||||
if (NULL != (ptr = strstr((char *)recv, "AT+SSID"))){
|
||||
if (NULL != (ptr = strstr((char *)param->value, "AT+SSID"))){
|
||||
wboard_loge("start scan wifi!!");
|
||||
//<2F>ص<EFBFBD>
|
||||
if (s_ble_boarding_info && s_ble_boarding_info->scan_wifi_cb)
|
||||
@ -465,7 +460,7 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
s_ble_boarding_info->scan_wifi_cb();
|
||||
}
|
||||
}
|
||||
if (NULL != (ptr = strstr((char *)recv, "AT+SCAN"))){
|
||||
if (NULL != (ptr = strstr((char *)param->value, "AT+SCAN"))){
|
||||
wboard_loge("start scan wifi!!");
|
||||
//<2F>ص<EFBFBD>
|
||||
if (s_ble_boarding_info && s_ble_boarding_info->scan_wifi_cb)
|
||||
@ -474,14 +469,14 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != (ptr = strstr((char *)recv, "AT+WIFI"))){
|
||||
if (NULL != (ptr = strstr((char *)param->value, "AT+WIFI"))){
|
||||
wboard_loge("recv wifi info!!");
|
||||
|
||||
char m_ssid[64] = {0};
|
||||
char m_pwd [64] = {0};
|
||||
memset(m_ssid,0,sizeof(m_ssid));
|
||||
memset(m_pwd,0,sizeof(m_pwd));
|
||||
sscanf((char *)recv,"AT+WIFI=%[^,],%[^,]", m_ssid,m_pwd);
|
||||
sscanf((char *)param->value,"AT+WIFI=%[^,],%[^,]", m_ssid,m_pwd);
|
||||
wboard_loge("%s %s ",m_ssid,m_pwd);
|
||||
//<2F><><EFBFBD><EFBFBD>SSID
|
||||
if(strlen(m_ssid) > 0){
|
||||
@ -527,221 +522,10 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 7.蓝牙控制音量
|
||||
* AT+VOLUME=100 (0-100)
|
||||
* 回复:AT+VOLUME=OK
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+VOLUME")))
|
||||
{
|
||||
wboard_loge("AT+VOLUME!!");
|
||||
uint8_t str_respone[32] = {0};
|
||||
memset(str_respone, 0, sizeof(str_respone));
|
||||
|
||||
char volume[12] = {0};
|
||||
memset(volume, 0, sizeof(volume));
|
||||
sscanf((char *)recv, "AT+VOLUME=%s", volume);
|
||||
if (strcmp(volume, "?") == 0)
|
||||
{
|
||||
// 返回当前音量
|
||||
}
|
||||
else
|
||||
{
|
||||
// 设置音量
|
||||
// int v = atoi(volume);
|
||||
}
|
||||
sprintf((char *)str_respone, "%s", "AT+VOLUME=OK");
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
/**
|
||||
* 蓝牙控制灯光亮度
|
||||
* AT+BRIGHT=100 (0-100)
|
||||
* 回复:AT+BRIGHT=OK
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+BRIGHT")))
|
||||
{
|
||||
wboard_loge("AT+BRIGHT!!");
|
||||
uint8_t str_respone[32] = {0};
|
||||
memset(str_respone, 0, sizeof(str_respone));
|
||||
char bright[12] = {0};
|
||||
memset(bright, 0, sizeof(bright));
|
||||
sscanf((char *)recv, "AT+BRIGHT=%s", bright);
|
||||
if (strcmp(bright, "?") == 0)
|
||||
{
|
||||
// 返回当前亮度
|
||||
sprintf((char *)str_respone, "%s", "AT+BRIGHT=100");
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
else
|
||||
{
|
||||
int brightness = atoi(bright);
|
||||
ws2812_set_all_led_brightness(brightness);
|
||||
sprintf((char *)str_respone, "%s", "AT+BRIGHT=OK");
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 蓝牙控制打开关闭助眠仪
|
||||
* AT+SLEEP_EN=1 (0-关闭 1-打开)
|
||||
* 回复:AT+SLEEP_EN=OK
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+SLEEP_EN")))
|
||||
{
|
||||
wboard_loge("AT+SLEEP_EN!!");
|
||||
uint8_t str_respone[32] = {0};
|
||||
memset(str_respone, 0, sizeof(str_respone));
|
||||
|
||||
char enable[12] = {0};
|
||||
memset(enable, 0, sizeof(enable));
|
||||
sscanf((char *)recv, "AT+SLEEP_EN=%s", enable);
|
||||
if (strcmp(enable, "?") == 0)
|
||||
{
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_EN=1");
|
||||
}
|
||||
else
|
||||
{
|
||||
int open = atoi(enable);
|
||||
if(open){
|
||||
sleep_helper_open();
|
||||
}else{
|
||||
sleep_helper_close();
|
||||
}
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_EN=OK");
|
||||
}
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
/**
|
||||
* 蓝牙控制助眠仪模式
|
||||
* 发送:AT+SLEEP_MODE=1 (1-3 代表3种模式)
|
||||
* 回复:AT+SLEEP_MODE=OK
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+SLEEP_MODE")))
|
||||
{
|
||||
wboard_loge("AT+SLEEP_MODE!!");
|
||||
uint8_t str_respone[32] = {0};
|
||||
memset(str_respone, 0, sizeof(str_respone));
|
||||
char mode[12] = {0};
|
||||
memset(mode, 0, sizeof(mode));
|
||||
sscanf((char *)recv, "AT+SLEEP_MODE=%s", mode);
|
||||
if (strcmp(mode, "?") == 0)
|
||||
{
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_MODE=1");
|
||||
}
|
||||
else
|
||||
{
|
||||
int v = atoi(mode);
|
||||
switch(v){
|
||||
case 1:
|
||||
sleep_helper_set_mode(SLEEP_MODE_1);
|
||||
break;
|
||||
case 2:
|
||||
sleep_helper_set_mode(SLEEP_MODE_1);
|
||||
break;
|
||||
case 3:
|
||||
sleep_helper_set_mode(SLEEP_MODE_1);
|
||||
break;
|
||||
}
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_MODE=OK");
|
||||
}
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
|
||||
/**
|
||||
* 蓝牙控制助眠仪超时时间
|
||||
* 发送:AT+SLEEP_TIMEOUT=1 (0-30 分钟)
|
||||
* 回复:AT+SLEEP_TIMEOUT=OK
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+SLEEP_TIMEOUT")))
|
||||
{
|
||||
wboard_loge("AT+SLEEP_TIMEOUT!!");
|
||||
uint8_t str_respone[32] = {0};
|
||||
memset(str_respone, 0, sizeof(str_respone));
|
||||
char mode[12] = {0};
|
||||
memset(mode, 0, sizeof(mode));
|
||||
sscanf((char *)recv, "AT+SLEEP_TIMEOUT=%s", mode);
|
||||
if (strcmp(mode, "?") == 0)
|
||||
{
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_TIMEOUT=10");
|
||||
}
|
||||
else
|
||||
{
|
||||
int v = atoi(mode);
|
||||
sleep_helper_set_timeout(v);
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_MODE=OK");
|
||||
}
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
/*
|
||||
*11.蓝牙控制助眠仪工作等级
|
||||
发送: AT+SLEEP_LEVEL=1 (1-9 代表9个等级强度)
|
||||
回复: AT+SLEEP_LEVEL=OK
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+SLEEP_LEVEL")))
|
||||
{
|
||||
wboard_loge("AT+SLEEP_LEVEL!!");
|
||||
uint8_t str_respone[32] = {0};
|
||||
memset(str_respone, 0, sizeof(str_respone));
|
||||
char level[12] = {0};
|
||||
memset(level, 0, sizeof(level));
|
||||
sscanf((char *)recv, "AT+SLEEP_LEVEL=%s", level);
|
||||
if (strcmp(level, "?") == 0)
|
||||
{
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_LEVEL=1");
|
||||
}
|
||||
else
|
||||
{
|
||||
int v = atoi(level);
|
||||
sleep_helper_set_level(v);
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_LEVEL=OK");
|
||||
}
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
/**
|
||||
* 蓝牙控制OTA
|
||||
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+OTA")))
|
||||
{
|
||||
wboard_loge("AT+OTA!!");
|
||||
uint8_t str_respone[32] = {0};
|
||||
memset(str_respone, 0, sizeof(str_respone));
|
||||
// char ota_url[128] = {0};
|
||||
// memset(ota_url, 0, sizeof(ota_url));
|
||||
// sscanf((char *)recv, "AT+OTA=%s", ota_url);
|
||||
|
||||
// 2. 查找等号位置
|
||||
char *equal_pos = strchr((char *)param->value, '=');
|
||||
if (equal_pos != NULL)
|
||||
{
|
||||
// 3. 计算等号后子串长度
|
||||
int len = strlen(equal_pos + 1); // +1跳过等号本身
|
||||
|
||||
// 4. 动态分配内存
|
||||
char *ota_url = (char *)malloc(len + 1); // +1存放结束符'\0'
|
||||
|
||||
// 5. 复制子串并添加结束符
|
||||
strncpy(ota_url, equal_pos + 1, len);
|
||||
ota_url[len] = '\0'; // 确保字符串终止
|
||||
|
||||
sprintf((char *)str_respone, "%s", "AT+OTA=OK");
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
if (strlen(ota_url) > 0)
|
||||
{
|
||||
wboard_loge("OTA-->%s", ota_url);
|
||||
wboard_loge("OTA--len >%d", strlen(ota_url));
|
||||
ws2812_led_start_ota();
|
||||
lamp_http_ota_start(ota_url);
|
||||
free(ota_url);
|
||||
}
|
||||
}
|
||||
|
||||
// int v = atoi(mode);
|
||||
// sleep_helper_set_timeout(v);
|
||||
}
|
||||
//wifi_boarding_notify(param->value,param->len);
|
||||
}
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
wboard_loge("invalid write handle %d", param->handle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user