DreisamLib SDK Development Documentation
1. Overview
DreisamLib is an SDK designed for device connection and data interaction (such as blood glucose data synchronization and real-time acquisition). It provides core capabilities including device binding, login, connection management, data synchronization, and heartbeat detection, and is suitable for scenarios involving interaction with blood glucose monitoring devices.2. Initialization
2.1 Pre-initialization
Function Description
Cold start experience of the App.- Function: SDK pre-initialization, must be called in the main thread of the
Application.onCreatefunction. - Features:
- Minimal time consumption, does not affect the first cold start experience of the App.
- Does not collect device information.
- Parameter:
context- Application context (Application instance).
Parameter Description
| Parameter Name | Type | Description |
|---|---|---|
| context | Application | Application context of the app |
Usage Example
2.2 Official Initialization
Function Description
Complete the core initialization of the SDK, to be called afterwards with minimal time consumption, without affecting the main thread, and it must be called.Parameter Description
| Parameter Name | Type | Description |
|---|---|---|
| appdId | String | Unique application identifier obtained from the development platform |
| builder | DreisamLibBuilder | Initialization configuration builder |
Usage Example
2.3 Initialization Configuration Class (DreisamLibBuilder)
| Method | Description | Parameter |
|---|---|---|
| setHideLog(boolean hideLog) | Set whether to hide logs | hideLog: true (hide, default) / false (show) |
| isHideLog() | Get the log hiding status | - |
3. Core Function Interfaces
3.1 Connection Precondition Check
Function Description
Check preconditions for device connection such as system authorization and network authentication. Developers can also perform permission checks on their own according to the Demo.Parameter Description
| Parameter Name | Type | Description |
|---|---|---|
| listener | OnPreCheckListener | Precondition check listener |
Listener (OnPreCheckListener)
| Callback Method | Description | Parameter |
|---|---|---|
| onSystemPermissionChanged(boolean granted, List<String> missingPermissions) | Callback for system authorization status change | granted: whether authorization is passed; missingPermissions: list of missing permissions |
3.2 Login
Function Description
User login, associate user platform Token with regional information.Parameter Description
| Parameter Name | Type | Description |
|---|---|---|
| areaCode | String | Regional code |
| userToken | String | User platform Token |
| listener | OnLoginListener | Login result callback |
Listener(OnLoginListener)
| Callback Method | Description | Parameter |
|---|---|---|
| loginFail(int code,String msg) | Login failed | code: error code; msg: error |
| loginSucc(boolean hasAvailableDevice, DrisamDeviceModel deviceInfoModel) | Login succeeded | deviceInfoModel:Device information;hasAvailableDevice:Whether there are available devices |
Device Information Model (DrisamDeviceModel)
| Field | Type | Description |
|---|---|---|
| deviceSn | String | Device serial number |
| partnerId | String | Product ID |
| estimatedEndAt | Long | Device expiration timestamp |
| iconUrl | String | Product icon URL |
| status | Int | Device status (0: Unbound; 1: Bound; 2: Activated; 3: Expired) |
Note: After successful login, if hasAvailableDevice = true, it means there are available devices, and connection can be directly performed subsequently. If hasAvailableDevice = false, it means there are no available devices, and connection can only be called after successful device binding.
3.3 Logout
Function Description
Logout and clear all user data.3.4 Device Binding
Function Description
Bind a device with a specified name, and the binding process feeds back the status through a listener.Parameter Description
| Parameter Name | Type | Description |
|---|---|---|
| deviceName | String | Device name |
| listener | OnBindListener | Binding status listener |
Listener (OnBindListener)
| Callback Method | Description | Parameter |
|---|---|---|
| onBindFail(int code, String msg) | Binding failed | code: error code; msg: error message |
| onBindSuccess(DrisamDeviceModel deviceInfoModel) | Binding succeeded | deviceInfoModel: device information model |
| onBinding(DreisamBindingEnum bindingCode) | Binding in progress | bindingCode: binding status enumeration (Checking/Scaning/Connecting/Binding) |
Binding Status Enumeration (DreisamBindingEnum)
| Enumeration Value | Description |
|---|---|
| CHEACKING | Checking |
| SCANTING | Scanning |
| CONNECTING | Connecting |
| BINDTING | Binding |
Note: After successful binding, there is no need to call the connection method again, as the SDK internally implements the connection operation after binding.
3.5 Device Connection Management
3.5.1 Connect Device
Function Description
According to the information after login, if it returns that there are available devices, connect directly; if there are no available devices, go to bind.Note: The SDK internally implements an automatic reconnection logic, so developers do not need to handle disconnection and reconnection. Only business logic such as updating the UI is required. If the device is disconnected, the SDK will attempt to reconnect after 30 seconds. If the reconnection fails and the App is in the foreground, it will attempt to reconnect again after a delay until the connection is successful; if the App is in the background, frequent operations in the background will cause the application to be suspended due to Android system process management, and it will wait for the heartbeat packet to reconnect again.
3.5.2 Check Device Connection Status
Return Value
| Type | Description |
|---|---|
| boolean | true (Connected) / false (Disconnected) |
3.5.3 Disconnect Device
3.5.4 End Device Usage
Function Description
Users end the device cycle on their own, after which the device can no longer be used, and the result is fed back through a callback.3.5.5 Connection Status Monitoring
Listener (OnConnectListener)
| Callback Method | Description | Parameter |
|---|---|---|
| onConnecState(ConnectingState state) | Connection status change | state: connection status enumeration |
| onConnectSuccess() | Connection succeeded | - |
DreisamConnectEnum (Connection Status Enumeration)
| Enumeration Value | Description |
|---|---|
| AUTHENTICATION_FAIL | Authentication failed |
| LACK_PERMISSION | Permission missing |
| DEVICE_CONNECTING | Device connecting |
| SHOW_CONNECTING | Showing connecting status |
| BLE_OFF | Bluetooth off |
| NO_AVAILABLE_DEVICE | No available device |
| TOKEN_INVALID | Token invalid |
| DEVICE_FINISH | Device usage expired |
Note: Difference between DEVICE_CONNECTING and SHOW_CONNECTING:
DEVICE_CONNECTINGis called whenever the device is disconnectedSHOW_CONNECTINGis the connecting status displayed for users’ attention, and it is only called if the latest data is not up-to-date and the device is not yet connected.
3.6 Heartbeat Detection
3.6.1 Start Heartbeat Detection
Function Description
Used to detect the device connection status, executed every 5 minutes. If not connected, the SDK will try to reconnect to the device. Developers can also implement it on their own.3.6.2 Stop Heartbeat Detection
3.7 Data Interaction
3.7.1 Data Synchronization Monitoring
Function Description
The callback returns new data that the SDK has not synchronized with the device.Listener (OnSyncDatasCallBack)
| Callback Method | Description | Parameter |
|---|---|---|
| onSyncStart(int totalCount) | Synchronization started | totalCount: total amount of data to be synchronized |
| onSyncProgress(int progress) | Synchronization progress updated | progress: progress percentage (0-100) |
| onSyncComplete(boolean success, List<GlucoseBean> datas) | Synchronization completed | success: whether successful; datas: list of synchronized blood glucose data |
3.7.2 Real-Time Data Callback
Function Description
Data reported by the device, callback once every 3 minutes under normal conditions.Listener (OnAnalzeDatatListener)
| Callback Method | Description | Parameter |
|---|---|---|
| analzeData(GlucoseBean data) | Real-time blood glucose data callback | data: blood glucose data model |
3.7.3 Blood Glucose Data Model (GlucoseBean)
| Field | Type | Description |
|---|---|---|
| timeCreate | Long | Data creation timestamp (seconds) |
| timeSave | Long | Data saving timestamp (seconds) |
| packageNumber | Int | Data package number |
| glucose | Float | Blood glucose value |
| type | Int | Data type (1: Initial value/Normal value) |
| trend | Int | Blood glucose trend (1: Stable; 5: Rising obliquely; 10: Falling obliquely; 15: Rising vertically; 20: Falling vertically) |
| Auxiliary Method | Description | - |
| ---------- | ------ | - |
| printMessage() | Returns a formatted string of blood glucose data | - |
| getTimeCreateStrHM() | Returns the data creation time as a string in “Hour:Minute” format | - |
3.8 Log Monitoring
3.8.1 Connection Log Monitoring
Method Signature
Listener (OnConnectLogListener)
| Callback Method | Description | Parameter |
|---|---|---|
| onConnectLog(int state, String msg) | Connection log callback | state: log status code; msg: log information |
4. General Callback Interface
5.1 ValueCallBack<T>
| Method | Description | Parameter |
|---|---|---|
| succ(T t) | Operation success callback | t: data returned on success |
| fail(int code, String msg) | Operation failure callback | code: error code; msg: error message |
5. Usage Flow Example
Usage Flow Recommendations
- Call
preInit()inApplication.onCreate()for pre-initialization. - Call
initSDK()at an appropriate time to complete official initialization. - Call
checkPreConditions()to check preconditions. - Set necessary listeners (connection status, data synchronization, etc.).
- After preconditions are met, call
login(). If there are available devices, callconnectDevice()to connect the device; if there are no available devices, go tobind(). - After the device is successfully connected, data synchronization, historical data acquisition, or real-time data reception can be performed.
- When no longer in use, call
disconnect()to disconnect, and calllogout()to release resources if necessary.
