Mesh handler

If you look at the previous code, we associated a handler object with mMeshService that is responsible for receiving responses from CSRMesh. It is better to extend a custom class that inherits the handler class for your custom implementation. The messages received by the handler are defined in the MeshService class. For example, when an association message is caught by the handler, it will have the value of MeshService.MESSAGE_DEVICE_ASSOCIATED. So in order to write a handler for this kind of response, you need to write code like the following:

public void handleMessage(Message msg) {
switch (msg.what) {
case MeshService.MESSAGE_DEVICE_ASSOCIATED :
Do something here...
break;
}
}

Since these are messages coming back from CSRMesh devices, they might have some data associated with them. In order to retrieve that data, you can use tags like the following:

case MeshService.MESSAGE_DEVICE_ASSOCIATED: {
// New device has been associated and is telling us its device id.
// Request supported models before adding to DeviceStore, and the UI.
int deviceId = msg.getData().getInt(MeshService.EXTRA_DEVICE_ID);
int uuidHash = msg.getData().getInt(MeshService.EXTRA_UUIDHASH_31);
Log.d(TAG, "New device associated with id " + String.format("0x%x", deviceId));
break;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.98.71