136 lines
3.3 KiB
Java
136 lines
3.3 KiB
Java
package com.ckkj.water.espBle;
|
||
|
||
import android.os.Build;
|
||
|
||
import com.espressif.provisioning.ESPConstants;
|
||
|
||
/**
|
||
* @author fengxiaoyang
|
||
* @date 2026/6/4
|
||
* @description 蓝牙配网配置管理类
|
||
*/
|
||
public class ProvisionConfig {
|
||
|
||
/**
|
||
* ESP BLE Service UUID
|
||
*/
|
||
public static final String SERVICE_UUID =
|
||
"0000ffff-0000-1000-8000-00805f9b34fb";
|
||
|
||
/**
|
||
* ESP BLE Characteristic UUID for writes
|
||
*/
|
||
public static final String CHARACTERISTIC_UUID =
|
||
"0000ff01-0000-1000-8000-00805f9b34fb";
|
||
|
||
/**
|
||
* ESP BLE Characteristic UUID for notifications
|
||
*/
|
||
public static final String NOTIFY_UUID =
|
||
"0000ff02-0000-1000-8000-00805f9b34fb";
|
||
|
||
/**
|
||
* 设备传输的协议类型
|
||
*/
|
||
public static final String TRANSPORT_BLE = "ble";
|
||
|
||
/**
|
||
* 设备前缀 (用于过滤设备)
|
||
*/
|
||
public static final String DEVICE_PREFIX = "PROV_";
|
||
|
||
/**
|
||
* 安全类型 - SECURITY_0 (无安全)
|
||
*/
|
||
public static final int SECURITY_0 = ESPConstants.SecurityType.SECURITY_0.ordinal();
|
||
|
||
/**
|
||
* 安全类型 - SECURITY_1 (推荐)
|
||
*/
|
||
public static final int SECURITY_1 = ESPConstants.SecurityType.SECURITY_1.ordinal();
|
||
|
||
/**
|
||
* 默认安全类型
|
||
*/
|
||
public static final int DEFAULT_SECURITY = SECURITY_1;
|
||
|
||
/**
|
||
* 默认 PoP,需和 ESP 固件保持一致
|
||
*/
|
||
public static final String DEFAULT_PROOF_OF_POSSESSION = "abcd1234";
|
||
|
||
/**
|
||
* Security2 使用的默认用户名
|
||
*/
|
||
public static final String DEFAULT_USER_NAME = "";
|
||
|
||
/**
|
||
* 连接超时时间 (毫秒)
|
||
*/
|
||
public static final int CONNECTION_TIMEOUT = 30000;
|
||
|
||
/**
|
||
* 配网超时时间 (毫秒)
|
||
*/
|
||
public static final int PROVISION_TIMEOUT = 120000;
|
||
|
||
public static final int ERROR_NOT_INITIALIZED = 1000;
|
||
|
||
public static final int ERROR_INVALID_DEVICE = 1001;
|
||
|
||
public static final int ERROR_CONNECT_TIMEOUT = 1002;
|
||
|
||
public static final int ERROR_CONNECT_FAILED = 1003;
|
||
|
||
public static final int ERROR_NOT_CONNECTED = 1004;
|
||
|
||
public static final int ERROR_SESSION_FAILED = 1005;
|
||
|
||
public static final int ERROR_WIFI_CONFIG_FAILED = 1006;
|
||
|
||
public static final int ERROR_WIFI_APPLY_FAILED = 1007;
|
||
|
||
public static final int ERROR_PROVISION_FAILED = 1008;
|
||
|
||
public static final int ERROR_PROVISION_TIMEOUT = 1009;
|
||
|
||
public static final int ERROR_WIFI_SCAN_FAILED = 1010;
|
||
|
||
/**
|
||
* 配网版本 (可根据实际固件调整)
|
||
*/
|
||
public static final String VERSION = "v1.1";
|
||
|
||
/**
|
||
* 生成蓝牙扫描过滤器
|
||
* @return 服务UUID数组
|
||
*/
|
||
public static String[] getScanServiceUuids() {
|
||
return new String[]{SERVICE_UUID};
|
||
}
|
||
|
||
/**
|
||
* 生成设备前缀过滤器 (用于过滤非ESP设备)
|
||
* @return 设备前缀
|
||
*/
|
||
public static String getDevicePrefix() {
|
||
return DEVICE_PREFIX;
|
||
}
|
||
|
||
/**
|
||
* 获取当前Android版本号
|
||
* @return Android版本号
|
||
*/
|
||
public static int getAndroidVersion() {
|
||
return Build.VERSION.SDK_INT;
|
||
}
|
||
|
||
/**
|
||
* 检查是否为Android 10及以上版本
|
||
* @return true 表示支持
|
||
*/
|
||
public static boolean isAndroid10OrAbove() {
|
||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
|
||
}
|
||
}
|