|
@@ -35,6 +35,7 @@ import org.iotivity.oc.OcUtils;
|
|
|
import org.iotivity.OCUuidUtil;
|
|
|
import org.iotivity.OCUuid;
|
|
|
import org.iotivity.OCVirtualDevice;
|
|
|
+import org.iotivity.oc.OcVirtualDevice;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
@@ -83,7 +84,7 @@ public class BridgeServer {
|
|
|
|
|
|
public void initBridgeServer() {
|
|
|
|
|
|
- this.addLightVirtualOCFServer(LIGHT_UUID, "Light Switch", "ocf");
|
|
|
+ //this.addLightVirtualOCFServer(LIGHT_UUID, "Light Switch", "ocf");
|
|
|
//this.addVirtualOCFClient(CLIENT_UUID, "Virtual OCF Client", "ocf");
|
|
|
|
|
|
this.loadPairwisedDeviceUUIDs();
|
|
@@ -112,55 +113,73 @@ public class BridgeServer {
|
|
|
for (int index = 1; index <= vod_count; index++) {
|
|
|
OCVirtualDevice vod = OCBridge.getVirtualDeviceInfo(index);
|
|
|
if (vod != null) {
|
|
|
- OCBridge.removeVirtualDevice(vod.getIndex());
|
|
|
- OCBridge.deleteVirtualDevice(vod.getIndex()); // Note :This includes OCMain.resetDevice(index);
|
|
|
+ OCBridge.removeVirtualDevice(vod.getIndex()); // Note : This removes vod in vods_list and shutdown connectivity
|
|
|
+ OCBridge.deleteVirtualDevice(vod.getIndex()); // Note : This removes piid, core device, vod map at index and OCMain.resetDevice(index);
|
|
|
Log.d(TAG, "Virtual OCF Device [" + vod.getIndex() + "] was reset!");
|
|
|
}
|
|
|
}
|
|
|
//TODO : need to check Memory data
|
|
|
bridge.clearVirtualOCFDeviceList();
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteVirtualOCFDevice(String device_sn) {
|
|
|
+ int vod_count = OCBridge.getVirtualDeviceCount();
|
|
|
+ Log.d(TAG, "Virtual OCF Device Count = [" + vod_count + "], Core Device Nums = ["+OCCoreRes.getNumDevices()+"] ");
|
|
|
+ for (int index = 1; index <= vod_count; index++) {
|
|
|
+ OCVirtualDevice vod = OCBridge.getVirtualDeviceInfo(index);
|
|
|
+ if (vod != null && OCUuidUtil.bytesToString(vod.getId()).equalsIgnoreCase(device_sn)) {
|
|
|
+ this.deleteVirtualOCFDevice((int)vod.getIndex());
|
|
|
+ Log.d(TAG, "Virtual OCF Device [" + vod.getIndex() + "] was deleted!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public void deleteVirtualOCFDevice(int vod_index) {
|
|
|
- OCBridge.removeVirtualDevice(vod_index);
|
|
|
- OCBridge.deleteVirtualDevice(vod_index); // Note : This includes OCMain.resetDevice(index);
|
|
|
+ OCBridge.removeVirtualDevice(vod_index); // Note : This removes vod in vods_list and shutdown connectivity
|
|
|
+ OCBridge.deleteVirtualDevice(vod_index); // Note : This removes piid, core device, vod map at index and OCMain.resetDevice(index);
|
|
|
|
|
|
//TODO : need to check Memory data
|
|
|
bridge.removeVirtualOCFDevice(vod_index);
|
|
|
}
|
|
|
|
|
|
- public void resetDevice(int device_index) {
|
|
|
+ public void removeVirtualOCFDevices() {
|
|
|
|
|
|
- if(device_index < 0) return ;
|
|
|
+ ArrayList<VirtualOCFDevice> vods = (ArrayList<VirtualOCFDevice>)bridge.getVirtualOCFDeviceList().clone();
|
|
|
+ for(VirtualOCFDevice vod : vods) {
|
|
|
+ this.removeVirtualOCFDevice(vod.getVODIndex());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- OCDeviceInfo info = OCCoreRes.getDeviceInfo(device_index);
|
|
|
- if(info == null) return ;
|
|
|
- if(device_index == Bridge.BRIDGE_INDEX) {
|
|
|
- if (info != null) {
|
|
|
- Log.d(TAG, "Bridge Server[" + Bridge.BRIDGE_INDEX + "] DeviceId = " + OCUuidUtil.uuidToString(info.getDi())
|
|
|
- + " will reset");
|
|
|
- }
|
|
|
- this.resetBridgeServer();
|
|
|
+ public void removeVirtualOCFDevice(int vod_index) {
|
|
|
|
|
|
- } else if(device_index > 0) {
|
|
|
- OCVirtualDevice vod = OCBridge.getVirtualDeviceInfo(device_index);
|
|
|
- if (info != null) {
|
|
|
- Log.d(TAG, "Virtual OCF Server/Client[" + vod.getIndex() + "] DeviceId = " + OCUuidUtil.uuidToString(info.getDi())
|
|
|
- + ", echoname = " + vod.getEconame() + " will reset");
|
|
|
+ OCVirtualDevice vod_light = OCBridge.getVirtualDeviceInfo(vod_index);
|
|
|
+ if(vod_light != null) {
|
|
|
+ Log.d(TAG, "Virtual Server[" + vod_light.getIndex() + "] "
|
|
|
+ + ", DeviceId = " + OCUuidUtil.bytesToString(vod_light.getId())
|
|
|
+ + ", Econame = " + vod_light.getEconame() + ", Name = " + vod_light.getEconame()
|
|
|
+ + " will be removed");
|
|
|
+
|
|
|
+ int ret = OCBridge.removeVirtualDevice(vod_index);
|
|
|
+ if (ret >=0) {
|
|
|
+ bridge.removeVirtualOCFDevice(vod_index);
|
|
|
}
|
|
|
- //this.resetVirtualOCFDevice(device_index);
|
|
|
- OCMain.resetDevice(device_index);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void resetVirtualOCFDevices() {
|
|
|
- int dev_count = (int)OCCoreRes.getNumDevices();
|
|
|
- Log.d(TAG, "Core Device Nums = ["+dev_count+"] ");
|
|
|
- for (int index = 1; index < dev_count; index++) {
|
|
|
- OCDeviceInfo dev = OCCoreRes.getDeviceInfo(index);
|
|
|
- if (dev != null) {
|
|
|
- this.resetDevice(index);
|
|
|
- Log.d(TAG, "Core OCF Device [" + index + "] "+dev.getName()+" was reset!");
|
|
|
+
|
|
|
+ int dev_count = OCBridge.getVirtualDeviceCount();
|
|
|
+ Log.d(TAG, "VOD Nums = ["+dev_count+"], Core Res Nums = ["+OCCoreRes.getNumDevices()+"]");
|
|
|
+ for (int index = 1 ; index <= dev_count; index++) {
|
|
|
+ OCVirtualDevice vod = OCBridge.getVirtualDeviceInfo(index);
|
|
|
+ Log.d(TAG, "VODs Device [" + index + ", "+vod.getIndex()+", vod_id="+OCUuidUtil.bytesToString(vod.getId())+ "]");
|
|
|
+ OCDeviceInfo info = OCCoreRes.getDeviceInfo(index);
|
|
|
+ if(vod != null && info != null) {
|
|
|
+ Log.d(TAG, "Core Device [" + index + ", "+vod.getIndex()+" piid="+OCUuidUtil.uuidToString(info.getPiid())+ "]");
|
|
|
+ if(info.getName() != null) {
|
|
|
+ Log.d(TAG, "VODs Device [" + index + ", " + vod.getIndex() + "], " + vod.getEconame() + ", " + info.getName() + " will be reset!");
|
|
|
+ this.resetDevice(index);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -201,15 +220,25 @@ public class BridgeServer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void deleteVirtualOCFDevice(String device_sn) {
|
|
|
- int vod_count = OCBridge.getVirtualDeviceCount();
|
|
|
- Log.d(TAG, "Virtual OCF Device Count = [" + vod_count + "], Core Device Nums = ["+OCCoreRes.getNumDevices()+"] ");
|
|
|
- for (int index = 1; index <= vod_count; index++) {
|
|
|
- OCVirtualDevice vod = OCBridge.getVirtualDeviceInfo(index);
|
|
|
- if (vod != null && OCUuidUtil.bytesToString(vod.getId()).equalsIgnoreCase(device_sn)) {
|
|
|
- this.deleteVirtualOCFDevice((int)vod.getIndex());
|
|
|
- Log.d(TAG, "Virtual OCF Device [" + vod.getIndex() + "] was deleted!");
|
|
|
+ public void resetDevice(int device_index) {
|
|
|
+
|
|
|
+ if(device_index < 0) return ;
|
|
|
+
|
|
|
+ OCDeviceInfo info = OCCoreRes.getDeviceInfo(device_index);
|
|
|
+ if(info == null) return ;
|
|
|
+ if(device_index == Bridge.BRIDGE_INDEX) {
|
|
|
+ Log.d(TAG, "Bridge Server[" + Bridge.BRIDGE_INDEX + "] DeviceId = " + OCUuidUtil.uuidToString(info.getDi())
|
|
|
+ + " will reset");
|
|
|
+ this.resetBridgeServer();
|
|
|
+
|
|
|
+ } else if(device_index > 0) {
|
|
|
+ OCVirtualDevice vod = OCBridge.getVirtualDeviceInfo(device_index);
|
|
|
+ if (vod != null) {
|
|
|
+ Log.d(TAG, "Virtual OCF Server/Client[" + vod.getIndex() + "] DeviceId = " + OCUuidUtil.uuidToString(info.getDi())
|
|
|
+ + ", echoname = " + vod.getEconame() + ", name = "+info.getName()+" will be reset");
|
|
|
}
|
|
|
+ //this.resetVirtualOCFDevice(device_index);
|
|
|
+ OCMain.resetDevice(device_index);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -257,8 +286,8 @@ public class BridgeServer {
|
|
|
OCVirtualDevice vod_info = OCBridge.getVirtualDeviceInfo(vod_index);
|
|
|
Log.d(TAG, "VOD Info = " + vod_info);
|
|
|
if (vod_info != null) {
|
|
|
- Log.d(TAG, "Virtual Server[" + vod_info.getIndex() + "] "
|
|
|
- + " DeviceId = " + OCUuidUtil.bytesToString(vod_info.getId())
|
|
|
+ Log.d(TAG, "Virtual Server [" + vod_info.getIndex() + "] "
|
|
|
+ + " Virtual Device Id = " + OCUuidUtil.bytesToString(vod_info.getId())
|
|
|
+ ", Econame = " + vod_info.getEconame() + ", Name = " + dev_info.getName()
|
|
|
+ " was added");
|
|
|
|
|
@@ -273,7 +302,7 @@ public class BridgeServer {
|
|
|
// set immutable device id for Platform Independent Identifier (piid)
|
|
|
OCMain.setImmutableDeviceIdentifier(vod_index, OCUuidUtil.stringToUuid(virtual_di));
|
|
|
Log.d(TAG, "Virtual Server [" + vod_info.getIndex() + "] "
|
|
|
- + ", Virtual Device Id = " + virtual_di
|
|
|
+ + " Virtual Device Id = " + virtual_di
|
|
|
+ ", Device Id = " + OCUuidUtil.uuidToString(dev_info.getDi())
|
|
|
+ ", Device Piid = " + OCUuidUtil.uuidToString(dev_info.getPiid()));
|
|
|
|
|
@@ -323,8 +352,8 @@ public class BridgeServer {
|
|
|
OCVirtualDevice vod_info = OCBridge.getVirtualDeviceInfo(vod_index);
|
|
|
Log.d(TAG, "VOD Info = "+ vod_info);
|
|
|
if(vod_info != null) {
|
|
|
- Log.d(TAG, "Virtual Server[" + vod_info.getIndex() + "] "
|
|
|
- + " DeviceId = " + OCUuidUtil.bytesToString(vod_info.getId())
|
|
|
+ Log.d(TAG, "Virtual Server [" + vod_info.getIndex() + "] "
|
|
|
+ + " Virtual Device Id = " + OCUuidUtil.bytesToString(vod_info.getId())
|
|
|
+ ", Econame = " + vod_info.getEconame() + ", Name = " + dev_info.getName()
|
|
|
+ " was added");
|
|
|
|
|
@@ -366,30 +395,14 @@ public class BridgeServer {
|
|
|
|
|
|
// set immutable device id for Platform Independent Identifier (piid)
|
|
|
OCMain.setImmutableDeviceIdentifier(vod_index, OCUuidUtil.stringToUuid(virtual_di));
|
|
|
- Log.d(TAG, "Virtual Server [" + vod_info.getIndex() + "] "
|
|
|
- + ", Virtual Device Id = " + virtual_di
|
|
|
+ Log.d(TAG, "Virtual Device [" + vod_info.getIndex() + "] "
|
|
|
+ + " Virtual Device Id = " + virtual_di
|
|
|
+ ", Device Id = " + OCUuidUtil.uuidToString(dev_info.getDi())
|
|
|
+ ", Device Piid = " + OCUuidUtil.uuidToString(dev_info.getPiid()));
|
|
|
|
|
|
// Add Light OCF Device IDD
|
|
|
- byte[] idd_bytes = getFileBytes("idds/virtual_ocf_device_light_IDD.cbor"); // example : "virtual_ocf_device_light_IDD.cbor"
|
|
|
- OCIntrospection.setIntrospectionData(vod_index, idd_bytes);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void removeLightVirtualOCFDevice(int vod_index) {
|
|
|
-
|
|
|
- OCVirtualDevice vod_light = OCBridge.getVirtualDeviceInfo(vod_index);
|
|
|
- if(vod_light != null) {
|
|
|
- Log.d(TAG, "Virtual Server[" + vod_light.getIndex() + "] "
|
|
|
- + ", DeviceId = " + OCUuidUtil.bytesToString(vod_light.getId())
|
|
|
- + ", Econame = " + vod_light.getEconame() + ", Name = " + vod_light.getEconame()
|
|
|
- + " will be removed");
|
|
|
-
|
|
|
- int ret = OCBridge.removeVirtualDevice(vod_index);
|
|
|
- if (ret >=0) {
|
|
|
- bridge.removeVirtualOCFDevice(vod_index);
|
|
|
+ //byte[] idd_bytes = getFileBytes("idds/virtual_ocf_device_light_IDD.cbor"); // example : "virtual_ocf_device_light_IDD.cbor"
|
|
|
+ //OCIntrospection.setIntrospectionData(vod_index, idd_bytes);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -406,8 +419,8 @@ public class BridgeServer {
|
|
|
OCDeviceInfo dev_info = OCCoreRes.getDeviceInfo(vod_index);
|
|
|
OCVirtualDevice vod_client = OCBridge.getVirtualDeviceInfo(vod_index);
|
|
|
if(vod_client != null){
|
|
|
- Log.d(TAG, "Virtual Client[" + vod_client.getIndex() + "] "
|
|
|
- + " DeviceId = " + OCUuidUtil.bytesToString(vod_client.getId())
|
|
|
+ Log.d(TAG, "Virtual Client [" + vod_client.getIndex() + "] "
|
|
|
+ + " Virtual Device Id = " + OCUuidUtil.bytesToString(vod_client.getId())
|
|
|
+ ", Econame = " + vod_client.getEconame() + ", Name = " + dev_info.getName()
|
|
|
+ " was added");
|
|
|
|
|
@@ -417,6 +430,14 @@ public class BridgeServer {
|
|
|
vod.setDiscovered(true);
|
|
|
vod.setAddedToBridge(true);
|
|
|
bridge.addOrReplaceVirtualOCFDevice(vod);
|
|
|
+
|
|
|
+ // set immutable device id for Platform Independent Identifier (piid)
|
|
|
+ OCMain.setImmutableDeviceIdentifier(vod_index, uuid);
|
|
|
+ Log.d(TAG, "Virtual Device [" + vod_client.getIndex() + "] "
|
|
|
+ + " Virtual Device Id = " + device_uuid
|
|
|
+ + ", Device Id = " + OCUuidUtil.uuidToString(dev_info.getDi())
|
|
|
+ + ", Device Piid = " + OCUuidUtil.uuidToString(dev_info.getPiid()));
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -473,7 +494,7 @@ public class BridgeServer {
|
|
|
|
|
|
OCDeviceInfo info = OCCoreRes.getDeviceInfo(vod_index);
|
|
|
if(OCBridge.removeVirtualDevice(vod_index) == 0) {
|
|
|
- Log.d(TAG, "Virtual OCF Server/Client[" + vod.getVODIndex() + "] DeviceId = " + OCUuidUtil.uuidToString(info.getDi())
|
|
|
+ Log.d(TAG, "Virtual OCF Server/Client [" + vod.getVODIndex() + "] DeviceId = " + OCUuidUtil.uuidToString(info.getDi())
|
|
|
+ ", echoname = " + vod.getEcoName() + " was removed from the bridge");
|
|
|
} else {
|
|
|
Log.d(TAG, "Failed to remove Virtual OCF Server/Client["+vod_index+"] "+info.getName()+" from the bridge");
|
|
@@ -481,6 +502,26 @@ public class BridgeServer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void disconnectAllVirtualDevices() {
|
|
|
+
|
|
|
+ for (VirtualOCFDevice vod : bridge.getVirtualOCFDeviceList()) {
|
|
|
+ Log.d(TAG, "disconnect All Virtual Devices.");
|
|
|
+ if (vod != null) {
|
|
|
+
|
|
|
+ vod.setDiscovered(false);
|
|
|
+ vod.setAddedToBridge(false);
|
|
|
+
|
|
|
+ OCDeviceInfo info = OCCoreRes.getDeviceInfo(vod.getVODIndex());
|
|
|
+ if (OCBridge.removeVirtualDevice(vod.getVODIndex()) == 0) {
|
|
|
+ Log.d(TAG, "Virtual OCF Server/Client [" + vod.getVODIndex() + "] DeviceId = " + OCUuidUtil.uuidToString(info.getDi())
|
|
|
+ + ", echoname = " + vod.getEcoName() + " was removed from the bridge");
|
|
|
+ } else {
|
|
|
+ Log.d(TAG, "Failed to remove Virtual OCF Server/Client[" + vod.getVODIndex() + "] " + info.getName() + " from the bridge");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/* These APIs are related to online pairwised devices */
|
|
|
public ArrayList<OcRemoteDevice> getPairwisedDevices() {
|
|
|
return pairwised_devices;
|