public class JseMetaWearBoard extends Object implements MetaWearBoard
MetaWearBoard
interface using only standard Java APIs. Platform specific functionality
is abstracted with the IO
and BtleGatt
interfaces.MetaWearBoard.Module, MetaWearBoard.UnexpectedDisconnectHandler
METABOOT_SERVICE, METAWEAR_GATT_SERVICE, METAWEAR_NOTIFY_CHAR
Constructor and Description |
---|
JseMetaWearBoard(BtleGatt gatt,
IO io,
String macAddress,
String libVersion)
Constructs a JseMetaWearBoard object
|
Modifier and Type | Method and Description |
---|---|
Task<Boolean> |
checkForFirmwareUpdateAsync()
Checks if there is a newer version of the firmware available for your board.
|
Task<Void> |
connectAsync()
Establishes a Bluetooth Low Energy connection to the MetaWear board
|
Task<Void> |
connectAsync(long delay)
Establishes a Bluetooth Low Energy connection to the MetaWear board
|
Task<AnonymousRoute[]> |
createAnonymousRoutesAsync()
Reads the current state of the board and creates anonymous routes based on what data is being logged
|
void |
deserialize()
Restore serialized state from the local disk if available
|
void |
deserialize(InputStream ins)
Restore serialized state from the provided input stream
|
Task<Void> |
disconnectAsync()
Disconnects from the board and cancels pending
MetaWearBoard.connectAsync() tasks |
Task<File> |
downloadFirmwareAsync(String version)
Downloads the specific firmware release for the board to your local device.
|
Task<List<File>> |
downloadFirmwareUpdateFilesAsync()
Retrieves the files needed to update the board to the latest available firmware.
|
Task<List<File>> |
downloadFirmwareUpdateFilesAsync(String version)
Retrieves the files needed to update the board to the specific firmware version.
|
Task<File> |
downloadLatestFirmwareAsync()
Downloads the latest firmware release for the board to your local device.
|
Task<org.json.JSONObject> |
dumpModuleInfo(org.json.JSONObject partial)
Queries all info registers.
|
Task<String> |
findLatestAvailableFirmwareAsync()
Checks if a newer firmware version is available for the current board.
|
String |
getFirmware() |
String |
getMacAddress()
Retrieves the MAC address of the board
|
Model |
getModel()
Determines the board model of the currently connected device
|
String |
getModelNumber() |
String |
getModelString()
Same behavior as
MetaWearBoard.getModel() except the returned value is a friendly name rather than an enum |
<T extends MetaWearBoard.Module> |
getModule(Class<T> moduleClass)
Retrieves a reference to the requested module if supported.
|
<T extends MetaWearBoard.Module> |
getModuleOrThrow(Class<T> moduleClass)
Retrieves a reference to the requested module if supported, throws a checked exception if the function fails.
|
boolean |
inMetaBootMode()
Checks if the board is in the MetaBoot (bootloader) mode.
|
boolean |
isConnected()
Gets the connection state
|
void |
loadBoardAttributes() |
Observer |
lookupObserver(int id)
Retrieves an observer
|
Route |
lookupRoute(int id)
Retrieves a route
|
void |
onUnexpectedDisconnect(MetaWearBoard.UnexpectedDisconnectHandler handler)
Set a handler for unexpected disconnects
|
Task<Byte> |
readBatteryLevelAsync()
Reads the battery level characteristic
|
Task<DeviceInformation> |
readDeviceInformationAsync()
Reads supported characteristics from the Device Information service
|
Task<Integer> |
readRssiAsync()
Reads the current RSSI value
|
void |
serialize()
Serialize object state and write the state to the local disk
|
void |
serialize(OutputStream outs)
Serialize object state and write the state to the provided output stream
|
void |
tearDown()
Removes all routes and resources allocated on the board (observers, data processors, timers, and loggers)
|
public String getFirmware()
public String getModelNumber()
public Model getModel()
MetaWearBoard
getModel
in interface MetaWearBoard
public String getModelString()
MetaWearBoard
MetaWearBoard.getModel()
except the returned value is a friendly name rather than an enumgetModelString
in interface MetaWearBoard
public String getMacAddress()
MetaWearBoard
getMacAddress
in interface MetaWearBoard
public Task<Integer> readRssiAsync()
MetaWearBoard
readRssiAsync
in interface MetaWearBoard
public Task<Byte> readBatteryLevelAsync()
MetaWearBoard
readBatteryLevelAsync
in interface MetaWearBoard
public Task<DeviceInformation> readDeviceInformationAsync()
MetaWearBoard
readDeviceInformationAsync
in interface MetaWearBoard
public Task<List<File>> downloadFirmwareUpdateFilesAsync(String version)
MetaWearBoard
downloadFirmwareUpdateFilesAsync
in interface MetaWearBoard
version
- Firmware revision to download, null to retrieve the latest versionpublic Task<List<File>> downloadFirmwareUpdateFilesAsync()
MetaWearBoard
downloadFirmwareUpdateFilesAsync
in interface MetaWearBoard
public Task<String> findLatestAvailableFirmwareAsync()
MetaWearBoard
findLatestAvailableFirmwareAsync
in interface MetaWearBoard
public Task<File> downloadFirmwareAsync(String version)
MetaWearBoard
downloadFirmwareAsync
in interface MetaWearBoard
version
- Firmware revision to download, null to retrieve the latest versionpublic Task<File> downloadLatestFirmwareAsync()
MetaWearBoard
downloadLatestFirmwareAsync
in interface MetaWearBoard
public Task<Boolean> checkForFirmwareUpdateAsync()
MetaWearBoard
checkForFirmwareUpdateAsync
in interface MetaWearBoard
public void loadBoardAttributes() throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public Task<Void> connectAsync()
MetaWearBoard
connectAsync
in interface MetaWearBoard
public Task<Void> connectAsync(long delay)
MetaWearBoard
connectAsync
in interface MetaWearBoard
delay
- How long to wait (in milliseconds) before attempting to connectpublic Task<Void> disconnectAsync()
MetaWearBoard
MetaWearBoard.connectAsync()
tasksdisconnectAsync
in interface MetaWearBoard
public void onUnexpectedDisconnect(MetaWearBoard.UnexpectedDisconnectHandler handler)
MetaWearBoard
onUnexpectedDisconnect
in interface MetaWearBoard
handler
- Handler for unexpected disconnectspublic boolean isConnected()
MetaWearBoard
isConnected
in interface MetaWearBoard
public boolean inMetaBootMode()
MetaWearBoard
inMetaBootMode
in interface MetaWearBoard
public <T extends MetaWearBoard.Module> T getModule(Class<T> moduleClass)
MetaWearBoard
getModule
in interface MetaWearBoard
T
- Runtime type the return value is casted asmoduleClass
- Module class to lookuppublic <T extends MetaWearBoard.Module> T getModuleOrThrow(Class<T> moduleClass) throws UnsupportedModuleException
MetaWearBoard
getModuleOrThrow
in interface MetaWearBoard
T
- Runtime type the return value is casted asmoduleClass
- ModuleId class to lookupUnsupportedModuleException
- If the requested module is not supported or the board is in MetaBoot modepublic Route lookupRoute(int id)
MetaWearBoard
lookupRoute
in interface MetaWearBoard
id
- Numerical ID to look uppublic Observer lookupObserver(int id)
MetaWearBoard
lookupObserver
in interface MetaWearBoard
id
- Numerical ID to look uppublic void tearDown()
MetaWearBoard
tearDown
in interface MetaWearBoard
public void serialize() throws IOException
MetaWearBoard
serialize
in interface MetaWearBoard
IOException
- If the internal OutputStream throws an exceptionpublic void serialize(OutputStream outs) throws IOException
MetaWearBoard
serialize
in interface MetaWearBoard
outs
- Output stream to write toIOException
- If the provided OutputStream throws an exceptionpublic void deserialize() throws IOException, ClassNotFoundException
MetaWearBoard
deserialize
in interface MetaWearBoard
IOException
- If the internal InputStream throws an exceptionClassNotFoundException
- Class of a serialized object cannot be foundpublic void deserialize(InputStream ins) throws IOException, ClassNotFoundException
MetaWearBoard
deserialize
in interface MetaWearBoard
ins
- Input stream to read fromIOException
- If the provided InputStream throws an exceptionClassNotFoundException
- Class of a serialized object cannot be foundpublic Task<org.json.JSONObject> dumpModuleInfo(org.json.JSONObject partial)
MetaWearBoard
dumpModuleInfo
in interface MetaWearBoard
partial
- Map of previously queries module info results, set to null to query all modulespublic Task<AnonymousRoute[]> createAnonymousRoutesAsync()
MetaWearBoard
createAnonymousRoutesAsync
in interface MetaWearBoard