getInstance
Returns the process-wide SDK singleton.
static IDockTool getInstance()Returns
IDockTool — shared non-null instance.
DockLib
v1.0.3
DockLib (com.urovo.docklib) is an Android library for UROVO SP35 cradle control over the device UART. Integrators use a single public facade, IDockTool, obtained via DockTool.getInstance().
Relative to 1.0.2.
| Symbol | Notes |
|---|---|
void flashLed(int count, int onIntervalMs, int offIntervalMs) | Configure LED test (alternate off) then runLedTest(). |
void flashLed(..., boolean alternate) | Same with red-green alternate flag. |
static String DockTool.getLibraryVersion() | Runtime SDK version. |
consumer-rules.pro | Includes SerialPort JNI keep rules for fat-AAR integrators. |
Relative to 1.0.1.
| Symbol | Notes |
|---|---|
upgradeFirmware(byte[], FirmwareUpgradeListener) | MCU OTA; returns post-update firmware version. |
FirmwareUpgradeListener / FirmwareUpgradeStage | OTA progress on the main thread. |
DockError OTA codes | OTA_BOOT_TIMEOUT, OTA_SETUP_FAILED, OTA_ERASE_FAILED, OTA_TRANSFER_FAILED, OTA_VERSION_READ. |
INVALID_ARGUMENT | Also covers OTA firmware size 1..0xD000 bytes. |
Relative to 1.0.0. Added unlock/LED/charge/identity reads, LED test parameters, rebootCradle, and layout id range 0..32.
First public IDockTool: link lifecycle, unlock, layout ids, LED enable, LED test run, firmware / hardware strings.
upgradeFirmwareDockLinkListener| Item | Requirement |
|---|---|
| Platform | Android |
| minSdk | 24 |
| Language | Java / Kotlin |
| Hardware | UROVO device with SP35 cradle UART |
Do not instantiate DockTool directly. Do not call SerialPortLibrary or raw UART from your app for cradle IAP; use upgradeFirmware only.
Add the release AAR (or the :DockLib module) to your app. minSdk 24.
Release builds that depend on DockLib (module or fat AAR) automatically merge consumer ProGuard rules from the AAR. Integrators do not need to copy these rules into the app.
Reference (shipped in consumer-rules.pro / AAR proguard.txt):
-keep class com.urovo.docklib.** { *; }
-keep interface com.urovo.docklib.** { *; }
-keep enum com.urovo.docklib.** { *; }
-keep class com.urovo.serial.** { *; }
-keep class com.urovo.hwserial.** { *; }
-keep class com.android.hw.SerialPort { *; }
-keepclasseswithmembernames class com.android.hw.SerialPort {
native <methods>;
}Call open() when your UI or service needs the cradle (e.g. Activity.onStart()). Call close() when done (e.g. onStop()).
| Method | Behavior |
|---|---|
open() | Starts the serial worker and opens the configured UART. Auto-reconnect is on by default. |
close() | Stops reconnect and releases the port (LinkState.CLOSED). |
isOpen() | true only when getLinkState() == ONLINE. |
setAutoReconnect(boolean) | When true, link loss moves to LOST and the worker retries. |
Most API calls require LinkState.ONLINE. If the port is still OPENING or LOST, synchronous methods throw DockException with PORT_NOT_OPEN. Use DockLinkListener or poll getLinkState() before business calls.
| API style | Caller thread | Callback thread |
|---|---|---|
Synchronous (setWallId, getFirmwareVersion, upgradeFirmware, …) | Blocks until the serial worker finishes (~1.5 s per simple call; OTA up to ~180 s) | N/A |
unlockCradle(UnlockCallback) | Returns immediately | onAck / onSuccess / onFailure on main thread |
upgradeFirmware(..., listener) | Blocks caller until OTA completes | FirmwareUpgradeListener.onProgress on main thread (listener may be null) |
Do not call blocking SDK methods on the main thread if the UI must stay responsive—use a background Executor.
Serialize access: Only one in-flight serial transaction at a time. While upgradeFirmware runs, do not call other IDockTool methods in parallel.
import com.urovo.docklib.MLog;
MLog.setLogEnabled(true);
MLog.setMinLevel(Log.DEBUG);
dock.setSerialTraceEnabled(true); // hex TX/RX, debug builds onlyFilter logcat: tag DockLib, messages prefixed with >>.
None.
import com.urovo.docklib.DockTool;
import com.urovo.docklib.DockException;
import com.urovo.docklib.IDockTool;
IDockTool dock = DockTool.getInstance();
String sdkVer = DockTool.getLibraryVersion();
@Override protected void onStart() {
super.onStart();
dock.open();
}
@Override protected void onStop() {
dock.close();
super.onStop();
}
// On a background thread when link is ONLINE:
try {
int wall = dock.getWallId();
String fw = dock.getFirmwareVersion();
} catch (DockException e) {
// e.getError() → DockError
}Returns the process-wide SDK singleton.
static IDockTool getInstance()IDockTool — shared non-null instance.
Returns DockLib SDK version string (e.g. "1.0.3"). Does not require open(). (since 1.0.3)
static String getLibraryVersion()String — SDK version from BuildConfig.LIBRARY_VERSION.
Start serial worker and connect.
void open() throws DockException| Code | Meaning | Handling |
|---|---|---|
PORT_NOT_OPEN | Port cannot be opened and reconnect is disabled | Check device UART / enable auto-reconnect |
Stop worker and release port.
void close()true iff getLinkState() == ONLINE.
boolean isOpen()boolean — link online flag.
Current serial link state.
LinkState getLinkState()LinkState — current state.
Enables or disables automatic reconnect after link loss. Default true.
void setAutoReconnect(boolean enable)| Name | Type | Description |
|---|---|---|
| enable | boolean | When true, link loss moves to LOST and the worker retries. |
Registers a listener for link state changes (callbacks on the main thread).
void addLinkListener(DockLinkListener listener)| Name | Type | Description |
|---|---|---|
| listener | DockLinkListener | Listener instance. |
Removes a previously registered link listener.
void removeLinkListener(DockLinkListener listener)| Name | Type | Description |
|---|---|---|
| listener | DockLinkListener | Previously registered listener. |
Enables TX/RX frame hex logging through MLog (prefix >>).
void setSerialTraceEnabled(boolean enable)| Name | Type | Description |
|---|---|---|
| enable | boolean | true to log each frame (debug builds only recommended). |
Sets unlock duration before unlockCradle (cmd 0xA9). Valid range 1..30.
void setUnlockTimeSeconds(int seconds) throws DockException| Name | Type | Description |
|---|---|---|
| seconds | int | Unlock duration in seconds, 1..30. |
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Out of range | Pass 1..30 |
PORT_NOT_OPEN | Link not ONLINE | Wait for ONLINE |
Reads unlock duration in seconds (cmd 0xAA). (since 1.0.1)
int getUnlockTimeSeconds() throws DockExceptionint — unlock duration seconds.
Sends unlock (cmd 0xA1) and reports ack / ok / fail via callback on the main thread.
void unlockCradle(UnlockCallback callback)| Name | Type | Description |
|---|---|---|
| callback | UnlockCallback | Must not be null; invoked on main thread. |
Sets LED enable/disable (cmd 0xAC).
void setLedEnabled(boolean enable) throws DockException| Name | Type | Description |
|---|---|---|
| enable | boolean | LED feature enable flag. |
Reads LED enable state (cmd 0xAD). (since 1.0.1)
boolean getLedEnabled() throws DockExceptionboolean — LED enable flag.
Reboots the cradle (cmd 0xB8). Does not run OTA by itself. (since 1.0.1)
void rebootCradle() throws DockExceptionWrites LED test ON time in milliseconds (cmd 0xAE). Range 0..5000. (since 1.0.1)
void setLedTestOnTimeMs(int ms) throws DockException| Name | Type | Description |
|---|---|---|
| ms | int | ON time 0..5000. |
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Out of range | Pass 0..5000 |
Writes LED test OFF time in milliseconds (cmd 0xAF). Range 0..5000. (since 1.0.1)
void setLedTestOffTimeMs(int ms) throws DockException| Name | Type | Description |
|---|---|---|
| ms | int | OFF time 0..5000. |
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Out of range | Pass 0..5000 |
Writes LED test blink count (cmd 0xB0). Range 1..100. (since 1.0.1)
void setLedTestCount(int count) throws DockException| Name | Type | Description |
|---|---|---|
| count | int | Blink count 1..100. |
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Out of range | Pass 1..100 |
Writes LED red-green alternate flag (cmd 0xB1). (since 1.0.1)
void setLedTestAlternate(boolean enable) throws DockException| Name | Type | Description |
|---|---|---|
| enable | boolean | Red-green alternate. |
Runs LED test (cmd 0xAB).
void runLedTest() throws DockExceptionConfigures LED test ON/OFF/count (and optional alternate) then runs the test. (since 1.0.3)
| Name | Type | Description |
|---|---|---|
| count | int | Blink count 1..100. |
| onIntervalMs | int | ON time 0..5000. |
| offIntervalMs | int | OFF time 0..5000. |
| alternate | boolean | Red-green alternate; three-arg overload uses false. |
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Out of range | Match count / time ranges above |
Stops LED test (cmd 0xB9, TURNOFF). (since 1.0.1)
void turnOffLedTest() throws DockExceptionWrites wall id (cmd 0xA3). Range 0..32.
void setWallId(int id) throws DockException| Name | Type | Description |
|---|---|---|
| id | int | Wall id 0..32. |
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Out of range | Pass 0..32 |
Reads wall id (cmd 0xA6).
int getWallId() throws DockExceptionint — wall id.
Writes row id (cmd 0xA4). Range 0..32.
void setRowId(int id) throws DockException| Name | Type | Description |
|---|---|---|
| id | int | Row id 0..32. |
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Out of range | Pass 0..32 |
Reads row id (cmd 0xA7).
int getRowId() throws DockExceptionint — row id.
Writes column id (cmd 0xA5). Range 0..32.
void setColId(int id) throws DockException| Name | Type | Description |
|---|---|---|
| id | int | Column id 0..32. |
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Out of range | Pass 0..32 |
Reads column id (cmd 0xA8).
int getColId() throws DockExceptionint — column id.
Writes host charge mode (cmd 0xB2). (since 1.0.1)
void setHostCharge(boolean fast) throws DockException| Name | Type | Description |
|---|---|---|
| fast | boolean | Host fast-charge flag. |
Reads host charge mode (cmd 0xB3). (since 1.0.1)
boolean getHostCharge() throws DockExceptionboolean — host fast-charge flag.
Reads cradle serial number (cmd 0xB5). May be empty. (since 1.0.1)
String getSerialNumber() throws DockExceptionString — serial text; may be "" if the cradle sends no text within the wait window.
Reads cradle model (cmd 0xB6). (since 1.0.1)
String getCradleModel() throws DockExceptionString — model text; may be empty.
Reads last error code (cmd 0xB7). (since 1.0.1)
int getLastErrorCode() throws DockExceptionint — cradle error byte (see Cradle last error codes).
Reads MCU firmware version string (cmd 0xA0).
String getFirmwareVersion() throws DockExceptionString — firmware string; may be empty.
Reads hardware revision string (cmd 0xA2).
String getHardwareRevision() throws DockExceptionString — hardware revision; may be empty.
Upgrades cradle MCU firmware via IAP + YMODEM (not the Android APK). (since 1.0.2)
Sends reboot (0xB8), waits up to 2 s for @BOOT@, transfers firmware, then reads the firmware version. Overall OTA budget is about 180 seconds.
| Name | Type | Description |
|---|---|---|
| firmware | byte[] | Raw .bin bytes, length 1..0xD000. |
| listener | FirmwareUpgradeListener | Optional; onProgress on main thread. May be null. |
String — firmware version string after successful update.
| Code | Meaning | Handling |
|---|---|---|
INVALID_ARGUMENT | Firmware size out of 1..0xD000 | Validate .bin size in app |
OTA_BOOT_TIMEOUT | No @BOOT@ within 2 s after reboot | Retry / check cradle |
OTA_SETUP_FAILED | filesize / verify failed after retries | Retry with valid image |
OTA_ERASE_FAILED | Flash erase failed or timed out | Retry |
OTA_TRANSFER_FAILED | No 'C' or YMODEM ACK failure | Retry transfer |
OTA_VERSION_READ | Transfer OK but version could not be read | Confirm on device |
Progress current / total are meaningful for ERASE (page) and TRANSFER (data packets); other stages use 0.
com.urovo.docklib.FirmwareUpgradeStage
| Value | Meaning |
|---|---|
REBOOT | Reboot into bootloader |
WAIT_BOOT | Waiting for @BOOT@ |
FILESIZE | Filesize handshake |
VERIFY | Image verify |
ERASE | Flash erase |
TRANSFER | YMODEM data transfer |
READ_VERSION | Read firmware version |
DONE | Complete |
com.urovo.docklib.UnlockCallback
Async unlock callbacks on the main thread.
void onAck()
void onSuccess()
void onFailure(DockError error)| Name | Type | Description |
|---|---|---|
| error | DockError | Failure reason in onFailure. |
com.urovo.docklib.FirmwareUpgradeListener
Optional OTA progress callback on the main thread. (since 1.0.2)
void onProgress(FirmwareUpgradeStage stage, int current, int total)| Name | Type | Description |
|---|---|---|
| stage | FirmwareUpgradeStage | Current OTA stage. |
| current | int | Progress current (meaningful for ERASE / TRANSFER). |
| total | int | Progress total (meaningful for ERASE / TRANSFER). |
com.urovo.docklib.DockLinkListener
Link state change listener (main thread).
void onLinkStateChanged(LinkState state)| Name | Type | Description |
|---|---|---|
| state | LinkState | New link state. |
com.urovo.docklib.LinkState
| Value | Meaning |
|---|---|
CLOSED | Port closed. |
OPENING | Connecting / reconnecting. |
ONLINE | Ready for transactions. |
LOST | Link dropped; reconnect if enabled. |
com.urovo.docklib.DockException
Checked exception for synchronous methods: DockError getError(), getMessage().
com.urovo.docklib.DockError
| Value | Meaning |
|---|---|
PORT_NOT_OPEN | Link not ONLINE. |
LINK_LOST | Connection dropped during a transaction. |
CHECKSUM | Frame XOR mismatch. |
TIMEOUT | Response timeout (framed commands). |
FRAME_FORMAT | Unparseable frame. |
INVALID_ARGUMENT | Out-of-range argument (including OTA size). |
UNLOCK_DENIED | Cradle rejected unlock. |
COMMAND_DENIED | Cradle rejected a write. |
OTA_BOOT_TIMEOUT | No @BOOT@ within 2 s after reboot. |
OTA_SETUP_FAILED | filesize / verify failed after retries. |
OTA_ERASE_FAILED | Flash erase failed or timed out. |
OTA_TRANSFER_FAILED | No 'C' or YMODEM ACK failure. |
OTA_VERSION_READ | Transfer succeeded but firmware version could not be read. |
com.urovo.docklib.CradleLastErrorCode
Values returned by getLastErrorCode(). Display mapping is the integrator's responsibility.
| Value | Meaning |
|---|---|
0x00 | No Error |
0x55 | Lock close error |
0x56 | Unlock error |
0x57 | System error |
0x58 | Serial error |
Master switch for SDK logging.
static void setLogEnabled(boolean on)| Name | Type | Description |
|---|---|---|
| on | boolean | Enable or disable logging. |
Android log level floor.
static void setMinLevel(int level)| Name | Type | Description |
|---|---|---|
| level | int | Android log level. |
Debug log (auto >> prefix).
static void d(String msg)Info log (auto >> prefix).
static void i(String msg)Warning log (auto >> prefix).
static void w(String msg)Error log; overload with throwable.
static void e(String msg)
static void e(String msg, Throwable t)Uppercase hex encoding of bytes.
static String toHex(byte[] data)String — uppercase hex.
Do not depend on com.urovo.docklib.protocol. or com.urovo.docklib.serial. except LinkState as returned by IDockTool.
dock.setUnlockTimeSeconds(10);
dock.setLedEnabled(true);
dock.unlockCradle(new UnlockCallback() {
@Override public void onAck() { }
@Override public void onSuccess() { }
@Override public void onFailure(DockError error) { }
});String model = dock.getCradleModel();
String hw = dock.getHardwareRevision();
String fw = dock.getFirmwareVersion();
String serial = dock.getSerialNumber();
int err = dock.getLastErrorCode();byte[] bin = ...; // load .bin from storage, 1..53248 bytes
FirmwareUpgradeListener progress = (stage, current, total) -> {
// update UI on main thread
};
try {
String newFw = dock.upgradeFirmware(bin, progress);
// show newFw in UI — SDK already read version from device
} catch (DockException e) {
switch (e.getError()) {
case OTA_BOOT_TIMEOUT:
case OTA_SETUP_FAILED:
case OTA_ERASE_FAILED:
case OTA_TRANSFER_FAILED:
case OTA_VERSION_READ:
case INVALID_ARGUMENT:
break;
default:
break;
}
}Pick a .bin with the system file picker in your app; pass bytes to upgradeFirmware only. YMODEM file name inside the protocol is fixed as firmware.bin.
Serial exclusivity — The SDK uses one worker thread and one UART. Gate UI so only one operation runs at a time. During OTA, other IDockTool calls will block or fail if invoked from another thread without your own gate.
OTA vs framed protocol — OTA temporarily leaves framed mode. Do not interleave framed commands while raw IAP is active; the SDK handles enter/exit internally.
.bin size — Valid range 1..0xD000 bytes. Validate in the app before calling the SDK.
No cancel during flash — Once upgradeFirmware starts, there is no supported cancel path; wait for success or DockException.
Do not use SerialPortLibrary for IAP — Integrators must use IDockTool.upgradeFirmware only.
Empty read strings — getFirmwareVersion, getHardwareRevision, getCradleModel, and getSerialNumber may return "" if the cradle sends no text within the SDK wait window.
DockLib(com.urovo.docklib)是面向 UROVO SP35 座充的 Android 库,通过设备 UART 进行控制。集成方通过 DockTool.getInstance() 获取唯一公开门面 IDockTool。
相对 1.0.2。
| Symbol | Notes |
|---|---|
void flashLed(int count, int onIntervalMs, int offIntervalMs) | 配置 LED 测试(alternate 关闭)并执行 runLedTest()。 |
void flashLed(..., boolean alternate) | 同上,可指定红绿交替。 |
static String DockTool.getLibraryVersion() | 运行时 SDK 版本。 |
consumer-rules.pro | 含 SerialPort JNI keep,fat AAR 集成方无需手抄 ProGuard。 |
相对 1.0.1。
| Symbol | Notes |
|---|---|
upgradeFirmware(byte[], FirmwareUpgradeListener) | MCU OTA;返回升级后固件版本。 |
FirmwareUpgradeListener / FirmwareUpgradeStage | 主线程 OTA 进度。 |
DockError OTA 错误码 | OTA_BOOT_TIMEOUT、OTA_SETUP_FAILED、OTA_ERASE_FAILED、OTA_TRANSFER_FAILED、OTA_VERSION_READ。 |
INVALID_ARGUMENT | 同时覆盖 OTA 固件大小 1..0xD000 字节。 |
相对 1.0.0。新增解锁/LED/充电/身份读取、LED 测试参数、rebootCradle,以及布局 ID 范围 0..32。
首个公开 IDockTool:链路生命周期、解锁、布局 ID、LED 使能、LED 测试启动、固件/硬件字符串。
upgradeFirmwareDockLinkListener| Item | Requirement |
|---|---|
| Platform | Android |
| minSdk | 24 |
| Language | Java / Kotlin |
| Hardware | 带 SP35 座充 UART 的 UROVO 设备 |
请勿直接构造 DockTool。请勿在应用中直接调用 SerialPortLibrary 或原始 UART 做座充 IAP;仅使用 upgradeFirmware。
将 release AAR(或 :DockLib 模块)加入应用。minSdk 24。
依赖 DockLib(模块或 fat AAR)的 Release 构建会自动合并 AAR 中的 consumer ProGuard 规则,集成方无需再抄规则。
参考(已写入 consumer-rules.pro / AAR proguard.txt):
-keep class com.urovo.docklib.** { *; }
-keep interface com.urovo.docklib.** { *; }
-keep enum com.urovo.docklib.** { *; }
-keep class com.urovo.serial.** { *; }
-keep class com.urovo.hwserial.** { *; }
-keep class com.android.hw.SerialPort { *; }
-keepclasseswithmembernames class com.android.hw.SerialPort {
native <methods>;
}在需要座充时调用 open()(例如 Activity.onStart()),结束时调用 close()(例如 onStop())。
| Method | Behavior |
|---|---|
open() | 启动串口工作线程并打开配置的 UART。默认开启自动重连。 |
close() | 停止重连并释放端口(LinkState.CLOSED)。 |
isOpen() | 仅当 getLinkState() == ONLINE 时为 true。 |
setAutoReconnect(boolean) | 为 true 时链路丢失进入 LOST 并由工作线程重试。 |
多数 API 要求 LinkState.ONLINE。若仍为 OPENING 或 LOST,同步方法抛出 DockException,错误码 PORT_NOT_OPEN。业务调用前请使用 DockLinkListener 或轮询 getLinkState()。
| API style | Caller thread | Callback thread |
|---|---|---|
同步(setWallId、getFirmwareVersion、upgradeFirmware 等) | 阻塞至串口工作线程完成(简单调用约 1.5 s;OTA 最长约 180 s) | 无 |
unlockCradle(UnlockCallback) | 立即返回 | onAck / onSuccess / onFailure 在主线程 |
upgradeFirmware(..., listener) | 阻塞至 OTA 结束 | FirmwareUpgradeListener.onProgress 在主线程(listener 可为 null) |
若 UI 需保持响应,不要在主线程调用阻塞 SDK 方法——使用后台 Executor。
串行访问: 同一时刻仅允许一笔串口事务。执行 upgradeFirmware 时不要并行调用其他 IDockTool 方法。
import com.urovo.docklib.MLog;
MLog.setLogEnabled(true);
MLog.setMinLevel(Log.DEBUG);
dock.setSerialTraceEnabled(true); // hex TX/RX,建议仅调试构建logcat 过滤:tag DockLib,消息前缀 >>。
无
import com.urovo.docklib.DockTool;
import com.urovo.docklib.DockException;
import com.urovo.docklib.IDockTool;
IDockTool dock = DockTool.getInstance();
String sdkVer = DockTool.getLibraryVersion();
@Override protected void onStart() {
super.onStart();
dock.open();
}
@Override protected void onStop() {
dock.close();
super.onStop();
}
// 链路 ONLINE 时在后台线程:
try {
int wall = dock.getWallId();
String fw = dock.getFirmwareVersion();
} catch (DockException e) {
// e.getError() → DockError
}返回进程内 SDK 单例。
static IDockTool getInstance()IDockTool — 非空共享实例。
返回 DockLib SDK 版本字符串(如 "1.0.3")。无需 open()。(since 1.0.3)
static String getLibraryVersion()String — 来自 BuildConfig.LIBRARY_VERSION 的 SDK 版本。
启动串口工作线程并连接。
void open() throws DockException| 错误码 | 含义 | 建议处理 |
|---|---|---|
PORT_NOT_OPEN | 无法打开端口且重连已关闭 | 检查 UART / 开启自动重连 |
停止工作线程并释放端口。
void close()仅当 getLinkState() == ONLINE 时为 true。
boolean isOpen()boolean — 链路是否在线。
当前串口链路状态。
LinkState getLinkState()LinkState — 当前状态。
启用或禁用断链后自动重连。默认 true。
void setAutoReconnect(boolean enable)| 参数 | 类型 | 说明 |
|---|---|---|
| enable | boolean | 为 true 时断链进入 LOST 并由工作线程重试。 |
注册链路状态监听(主线程回调)。
void addLinkListener(DockLinkListener listener)| 参数 | 类型 | 说明 |
|---|---|---|
| listener | DockLinkListener | 监听器实例。 |
移除已注册的链路监听。
void removeLinkListener(DockLinkListener listener)| 参数 | 类型 | 说明 |
|---|---|---|
| listener | DockLinkListener | 先前注册的监听器。 |
通过 MLog 启用 TX/RX 帧十六进制日志(前缀 >>)。
void setSerialTraceEnabled(boolean enable)| 参数 | 类型 | 说明 |
|---|---|---|
| enable | boolean | true 时记录每帧(建议仅调试构建)。 |
在 unlockCradle 前设置解锁时长(cmd 0xA9)。有效范围 1..30。
void setUnlockTimeSeconds(int seconds) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| seconds | int | 解锁秒数,1..30。 |
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 超出范围 | 传入 1..30 |
PORT_NOT_OPEN | 链路非 ONLINE | 等待 ONLINE |
读取解锁时长(秒)(cmd 0xAA)。(since 1.0.1)
int getUnlockTimeSeconds() throws DockExceptionint — 解锁秒数。
发送解锁(cmd 0xA1),经回调在主线程报告 ack / ok / fail。
void unlockCradle(UnlockCallback callback)| 参数 | 类型 | 说明 |
|---|---|---|
| callback | UnlockCallback | 不可为 null;在主线程回调。 |
设置 LED 使能(cmd 0xAC)。
void setLedEnabled(boolean enable) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| enable | boolean | LED 功能使能标志。 |
读取 LED 使能状态(cmd 0xAD)。(since 1.0.1)
boolean getLedEnabled() throws DockExceptionboolean — LED 使能标志。
重启座充(cmd 0xB8)。不会单独执行 OTA。(since 1.0.1)
void rebootCradle() throws DockException写入 LED 测试亮灯时长(毫秒)(cmd 0xAE)。范围 0..5000。(since 1.0.1)
void setLedTestOnTimeMs(int ms) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| ms | int | ON 时长 0..5000。 |
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 超出范围 | 传入 0..5000 |
写入 LED 测试灭灯时长(毫秒)(cmd 0xAF)。范围 0..5000。(since 1.0.1)
void setLedTestOffTimeMs(int ms) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| ms | int | OFF 时长 0..5000。 |
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 超出范围 | 传入 0..5000 |
写入 LED 测试闪烁次数(cmd 0xB0)。范围 1..100。(since 1.0.1)
void setLedTestCount(int count) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| count | int | 次数 1..100。 |
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 超出范围 | 传入 1..100 |
写入红绿交替标志(cmd 0xB1)。(since 1.0.1)
void setLedTestAlternate(boolean enable) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| enable | boolean | 红绿交替。 |
启动 LED 测试(cmd 0xAB)。
void runLedTest() throws DockException配置 LED 测试 ON/OFF/次数(及可选 alternate)后启动测试。(since 1.0.3)
| 参数 | 类型 | 说明 |
|---|---|---|
| count | int | 次数 1..100。 |
| onIntervalMs | int | ON 时长 0..5000。 |
| offIntervalMs | int | OFF 时长 0..5000。 |
| alternate | boolean | 红绿交替;三参数重载使用 false。 |
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 超出范围 | 按上表范围传参 |
停止 LED 测试(cmd 0xB9,TURNOFF)。(since 1.0.1)
void turnOffLedTest() throws DockException写入墙号(cmd 0xA3)。范围 0..32。
void setWallId(int id) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| id | int | 墙号 0..32。 |
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 超出范围 | 传入 0..32 |
读取墙号(cmd 0xA6)。
int getWallId() throws DockExceptionint — 墙号。
写入行号(cmd 0xA4)。范围 0..32。
void setRowId(int id) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| id | int | 行号 0..32。 |
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 超出范围 | 传入 0..32 |
读取行号(cmd 0xA7)。
int getRowId() throws DockExceptionint — 行号。
写入列号(cmd 0xA5)。范围 0..32。
void setColId(int id) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| id | int | 列号 0..32。 |
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 超出范围 | 传入 0..32 |
读取列号(cmd 0xA8)。
int getColId() throws DockExceptionint — 列号。
写入主机充电模式(cmd 0xB2)。(since 1.0.1)
void setHostCharge(boolean fast) throws DockException| 参数 | 类型 | 说明 |
|---|---|---|
| fast | boolean | 主机快充标志。 |
读取主机充电模式(cmd 0xB3)。(since 1.0.1)
boolean getHostCharge() throws DockExceptionboolean — 主机快充标志。
读取座充序列号(cmd 0xB5)。可能为空。(since 1.0.1)
String getSerialNumber() throws DockExceptionString — 序列号文本;等待窗口内无文本时可能为 ""。
读取座充型号(cmd 0xB6)。(since 1.0.1)
String getCradleModel() throws DockExceptionString — 型号文本;可能为空。
读取最近错误码(cmd 0xB7)。(since 1.0.1)
int getLastErrorCode() throws DockExceptionint — 座充错误字节(见 Cradle last error codes)。
读取 MCU 固件版本字符串(cmd 0xA0)。
String getFirmwareVersion() throws DockExceptionString — 固件字符串;可能为空。
读取硬件版本字符串(cmd 0xA2)。
String getHardwareRevision() throws DockExceptionString — 硬件版本;可能为空。
通过 IAP + YMODEM 升级座充 MCU 固件(非 Android APK)。(since 1.0.2)
发送重启(0xB8),最多等待 2 s 的 @BOOT@,传输 firmware,再读取固件版本。整体 OTA 预算约 180 秒。
| 参数 | 类型 | 说明 |
|---|---|---|
| firmware | byte[] | 原始 .bin 字节,长度 1..0xD000。 |
| listener | FirmwareUpgradeListener | 可选;onProgress 在主线程。可为 null。 |
String — 升级成功后的固件版本字符串。
| 错误码 | 含义 | 建议处理 |
|---|---|---|
INVALID_ARGUMENT | 固件大小超出 1..0xD000 | 应用侧校验 .bin 大小 |
OTA_BOOT_TIMEOUT | 重启后 2 s 内无 @BOOT@ | 重试 / 检查座充 |
OTA_SETUP_FAILED | filesize / verify 重试后仍失败 | 使用有效镜像重试 |
OTA_ERASE_FAILED | 擦除失败或超时 | 重试 |
OTA_TRANSFER_FAILED | 无 'C' 或 YMODEM ACK 失败 | 重试传输 |
OTA_VERSION_READ | 传输成功但无法读版本 | 在设备侧确认 |
进度 current / total 在 ERASE(页)与 TRANSFER(数据包)有意义;其他阶段为 0。
com.urovo.docklib.FirmwareUpgradeStage
| Value | Meaning |
|---|---|
REBOOT | 重启进入 bootloader |
WAIT_BOOT | 等待 @BOOT@ |
FILESIZE | 文件大小握手 |
VERIFY | 镜像校验 |
ERASE | Flash 擦除 |
TRANSFER | YMODEM 数据传输 |
READ_VERSION | 读取固件版本 |
DONE | 完成 |
com.urovo.docklib.UnlockCallback
异步解锁回调(主线程)。
void onAck()
void onSuccess()
void onFailure(DockError error)| 参数 | 类型 | 说明 |
|---|---|---|
| error | DockError | onFailure 中的失败原因。 |
com.urovo.docklib.FirmwareUpgradeListener
可选 OTA 进度回调(主线程)。(since 1.0.2)
void onProgress(FirmwareUpgradeStage stage, int current, int total)| 参数 | 类型 | 说明 |
|---|---|---|
| stage | FirmwareUpgradeStage | 当前 OTA 阶段。 |
| current | int | 当前进度(ERASE / TRANSFER 有意义)。 |
| total | int | 总进度(ERASE / TRANSFER 有意义)。 |
com.urovo.docklib.DockLinkListener
链路状态变更监听(主线程)。
void onLinkStateChanged(LinkState state)| 参数 | 类型 | 说明 |
|---|---|---|
| state | LinkState | 新链路状态。 |
com.urovo.docklib.LinkState
| Value | Meaning |
|---|---|
CLOSED | 端口已关闭。 |
OPENING | 连接 / 重连中。 |
ONLINE | 可进行事务。 |
LOST | 链路断开;若启用则重连。 |
com.urovo.docklib.DockException
同步方法的受检异常:DockError getError()、getMessage()。
com.urovo.docklib.DockError
| Value | Meaning |
|---|---|
PORT_NOT_OPEN | 链路非 ONLINE。 |
LINK_LOST | 事务过程中连接断开。 |
CHECKSUM | 帧 XOR 校验失败。 |
TIMEOUT | 帧命令响应超时。 |
FRAME_FORMAT | 帧无法解析。 |
INVALID_ARGUMENT | 参数越界(含 OTA 大小)。 |
UNLOCK_DENIED | 座充拒绝解锁。 |
COMMAND_DENIED | 座充拒绝写命令。 |
OTA_BOOT_TIMEOUT | 重启后 2 s 内无 @BOOT@。 |
OTA_SETUP_FAILED | filesize / verify 重试后失败。 |
OTA_ERASE_FAILED | Flash 擦除失败或超时。 |
OTA_TRANSFER_FAILED | 无 'C' 或 YMODEM ACK 失败。 |
OTA_VERSION_READ | 传输成功但无法读取固件版本。 |
com.urovo.docklib.CradleLastErrorCode
getLastErrorCode() 返回值。展示映射由集成方负责。
| Value | Meaning |
|---|---|
0x00 | No Error |
0x55 | Lock close error |
0x56 | Unlock error |
0x57 | System error |
0x58 | Serial error |
SDK 日志总开关。
static void setLogEnabled(boolean on)| 参数 | 类型 | 说明 |
|---|---|---|
| on | boolean | 启用或关闭日志。 |
Android 日志级别下限。
static void setMinLevel(int level)| 参数 | 类型 | 说明 |
|---|---|---|
| level | int | Android 日志级别。 |
Debug 日志(自动加 >> 前缀)。
static void d(String msg)Info 日志(自动加 >> 前缀)。
static void i(String msg)Warning 日志(自动加 >> 前缀)。
static void w(String msg)Error 日志;可带 Throwable。
static void e(String msg)
static void e(String msg, Throwable t)字节数组大写十六进制编码。
static String toHex(byte[] data)String — 大写十六进制。
请勿依赖 com.urovo.docklib.protocol. 或 com.urovo.docklib.serial.,LinkState(由 IDockTool 返回)除外。
dock.setUnlockTimeSeconds(10);
dock.setLedEnabled(true);
dock.unlockCradle(new UnlockCallback() {
@Override public void onAck() { }
@Override public void onSuccess() { }
@Override public void onFailure(DockError error) { }
});String model = dock.getCradleModel();
String hw = dock.getHardwareRevision();
String fw = dock.getFirmwareVersion();
String serial = dock.getSerialNumber();
int err = dock.getLastErrorCode();byte[] bin = ...; // 从存储加载 .bin,1..53248 字节
FirmwareUpgradeListener progress = (stage, current, total) -> {
// 在主线程更新 UI
};
try {
String newFw = dock.upgradeFirmware(bin, progress);
// UI 展示 newFw — SDK 已从设备读取版本
} catch (DockException e) {
switch (e.getError()) {
case OTA_BOOT_TIMEOUT:
case OTA_SETUP_FAILED:
case OTA_ERASE_FAILED:
case OTA_TRANSFER_FAILED:
case OTA_VERSION_READ:
case INVALID_ARGUMENT:
break;
default:
break;
}
}请在应用中用系统文件选择器选取 .bin,仅将字节传给 upgradeFirmware。协议内 YMODEM 文件名固定为 firmware.bin。
串口独占 — SDK 使用单工作线程与单一 UART。请在 UI 侧门控,保证同一时刻仅一笔操作。OTA 期间若另一线程无门控地调用其他 IDockTool 方法,可能阻塞或失败。
OTA 与帧协议 — OTA 期间会暂时离开帧模式。原始 IAP 进行时不要穿插帧命令;进入/退出由 SDK 内部处理。
.bin 大小 — 有效范围 1..0xD000 字节。调用 SDK 前请在应用侧校验。
烧录不可取消 — upgradeFirmware 启动后无支持的取消路径;等待成功或 DockException。
勿用 SerialPortLibrary 做 IAP — 集成方必须仅使用 IDockTool.upgradeFirmware。
空读字符串 — 若座充在 SDK 等待窗口内未返回文本,getFirmwareVersion、getHardwareRevision、getCradleModel、getSerialNumber 可能返回 ""。