public class JseMetaWearBoard extends java.lang.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,
java.lang.String macAddress,
java.lang.String libVersion)
Constructs a JseMetaWearBoard object
|
Modifier and Type | Method and Description |
---|---|
bolts.Task<java.lang.Boolean> |
checkForFirmwareUpdateAsync()
Checks if there is a newer version of the firmware available for your board.
|
bolts.Task<java.lang.Void> |
connectAsync()
Establishes a Bluetooth Low Energy connection to the MetaWear board
|
bolts.Task<java.lang.Void> |
connectAsync(long delay)
Establishes a Bluetooth Low Energy connection to the MetaWear board
|
bolts.Task<java.lang.Void> |
connectWithRetryAsync(int retries)
Establishes a Bluetooth Low Energy connection to the MetaWear board
|
bolts.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(java.io.InputStream ins)
Restore serialized state from the provided input stream
|
bolts.Task<java.lang.Void> |
disconnectAsync()
Disconnects from the board and cancels pending
MetaWearBoard.connectAsync() tasks |
bolts.Task<java.io.File> |
downloadFirmwareAsync(java.lang.String version)
Downloads the specific firmware release for the board to your local device.
|
bolts.Task<java.util.List<java.io.File>> |
downloadFirmwareUpdateFilesAsync()
Retrieves the files needed to update the board to the latest available firmware.
|
bolts.Task<java.util.List<java.io.File>> |
downloadFirmwareUpdateFilesAsync(java.lang.String version)
Retrieves the files needed to update the board to the specific firmware version.
|
bolts.Task<java.util.List<java.io.File>> |
downloadFirmwareUpdateFilesAsyncV2()
Retrieves the files needed to update the board to the latest available firmware.
|
bolts.Task<java.util.List<java.io.File>> |
downloadFirmwareUpdateFilesAsyncV2(java.lang.String version)
Variant of
MetaWearBoard.downloadFirmwareUpdateFilesAsyncV2() that lets the caller specify which firmware version to download |
bolts.Task<java.io.File> |
downloadLatestFirmwareAsync()
Downloads the latest firmware release for the board to your local device.
|
bolts.Task<org.json.JSONObject> |
dumpModuleInfo(org.json.JSONObject partial)
Queries all info registers.
|
bolts.Task<java.lang.String> |
findLatestAvailableFirmwareAsync()
Checks if a newer firmware version is available for the current board.
|
java.lang.String |
getFirmware() |
java.lang.String |
getMacAddress()
Retrieves the MAC address of the board
|
Model |
getModel()
Determines the board model of the currently connected device
|
java.lang.String |
getModelNumber() |
java.lang.String |
getModelString()
Same behavior as
MetaWearBoard.getModel() except the returned value is a friendly name rather than an enum |
<T extends MetaWearBoard.Module> |
getModule(java.lang.Class<T> moduleClass)
Retrieves a reference to the requested module if supported.
|
<T extends MetaWearBoard.Module> |
getModuleOrThrow(java.lang.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
|
bolts.Task<java.lang.Byte> |
readBatteryLevelAsync()
Reads the battery level characteristic
|
bolts.Task<DeviceInformation> |
readDeviceInformationAsync()
Reads supported characteristics from the Device Information service
|
bolts.Task<java.lang.Integer> |
readRssiAsync()
Reads the current RSSI value
|
void |
serialize()
Serialize object state and write the state to the local disk
|
void |
serialize(java.io.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 java.lang.String getFirmware()
public java.lang.String getModelNumber()
public Model getModel()
MetaWearBoard
getModel
in interface MetaWearBoard
public java.lang.String getModelString()
MetaWearBoard
MetaWearBoard.getModel()
except the returned value is a friendly name rather than an enumgetModelString
in interface MetaWearBoard
public java.lang.String getMacAddress()
MetaWearBoard
getMacAddress
in interface MetaWearBoard
public bolts.Task<java.lang.Integer> readRssiAsync()
MetaWearBoard
readRssiAsync
in interface MetaWearBoard
public bolts.Task<java.lang.Byte> readBatteryLevelAsync()
MetaWearBoard
readBatteryLevelAsync
in interface MetaWearBoard
public bolts.Task<DeviceInformation> readDeviceInformationAsync()
MetaWearBoard
readDeviceInformationAsync
in interface MetaWearBoard
public bolts.Task<java.util.List<java.io.File>> downloadFirmwareUpdateFilesAsync(java.lang.String version)
MetaWearBoard
downloadFirmwareUpdateFilesAsync
in interface MetaWearBoard
version
- Firmware revision to download, null to retrieve the latest versionpublic bolts.Task<java.util.List<java.io.File>> downloadFirmwareUpdateFilesAsync()
MetaWearBoard
downloadFirmwareUpdateFilesAsync
in interface MetaWearBoard
public bolts.Task<java.util.List<java.io.File>> downloadFirmwareUpdateFilesAsyncV2(java.lang.String version)
MetaWearBoard
MetaWearBoard.downloadFirmwareUpdateFilesAsyncV2()
that lets the caller specify which firmware version to downloaddownloadFirmwareUpdateFilesAsyncV2
in interface MetaWearBoard
version
- Firmware revision to download, null to retrieve the latest versionpublic bolts.Task<java.util.List<java.io.File>> downloadFirmwareUpdateFilesAsyncV2()
MetaWearBoard
MetaWearBoard.inMetaBootMode()
.downloadFirmwareUpdateFilesAsyncV2
in interface MetaWearBoard
public bolts.Task<java.lang.String> findLatestAvailableFirmwareAsync()
MetaWearBoard
findLatestAvailableFirmwareAsync
in interface MetaWearBoard
public bolts.Task<java.io.File> downloadFirmwareAsync(java.lang.String version)
MetaWearBoard
downloadFirmwareAsync
in interface MetaWearBoard
version
- Firmware revision to download, null to retrieve the latest versionpublic bolts.Task<java.io.File> downloadLatestFirmwareAsync()
MetaWearBoard
downloadLatestFirmwareAsync
in interface MetaWearBoard
public bolts.Task<java.lang.Boolean> checkForFirmwareUpdateAsync()
MetaWearBoard
checkForFirmwareUpdateAsync
in interface MetaWearBoard
public void loadBoardAttributes() throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public bolts.Task<java.lang.Void> connectAsync()
MetaWearBoard
connectAsync
in interface MetaWearBoard
public bolts.Task<java.lang.Void> connectWithRetryAsync(int retries)
MetaWearBoard
connectWithRetryAsync
in interface MetaWearBoard
retries
- Number of retry attempts before completing the task with an errorpublic bolts.Task<java.lang.Void> connectAsync(long delay)
MetaWearBoard
connectAsync
in interface MetaWearBoard
delay
- How long to wait (in milliseconds) before attempting to connectpublic bolts.Task<java.lang.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(java.lang.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(java.lang.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 java.io.IOException
MetaWearBoard
serialize
in interface MetaWearBoard
java.io.IOException
- If the internal OutputStream throws an exceptionpublic void serialize(java.io.OutputStream outs) throws java.io.IOException
MetaWearBoard
serialize
in interface MetaWearBoard
outs
- Output stream to write tojava.io.IOException
- If the provided OutputStream throws an exceptionpublic void deserialize() throws java.io.IOException, java.lang.ClassNotFoundException
MetaWearBoard
deserialize
in interface MetaWearBoard
java.io.IOException
- If the internal InputStream throws an exceptionjava.lang.ClassNotFoundException
- Class of a serialized object cannot be foundpublic void deserialize(java.io.InputStream ins) throws java.io.IOException, java.lang.ClassNotFoundException
MetaWearBoard
deserialize
in interface MetaWearBoard
ins
- Input stream to read fromjava.io.IOException
- If the provided InputStream throws an exceptionjava.lang.ClassNotFoundException
- Class of a serialized object cannot be foundpublic bolts.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 bolts.Task<AnonymousRoute[]> createAnonymousRoutesAsync()
MetaWearBoard
createAnonymousRoutesAsync
in interface MetaWearBoard