|
@@ -440,13 +440,13 @@ public class BridgeService extends IntentService {
|
|
|
JSONObject obj = new JSONObject(result_data);
|
|
|
if(obj != null) {
|
|
|
String tid = obj.getString("tid"); // Transaction Id
|
|
|
- String sn = obj.getString("sn"); // Serial Number (Device Id)
|
|
|
+ String sn = obj.getString("sn"); // Serial Number (Virtual Device Id)
|
|
|
String uri = obj.getString("uri"); // Resource URI
|
|
|
String res_type = obj.getString("res_type"); // GET, POST, PUT
|
|
|
String res_data = obj.getString("res_data"); // Properties
|
|
|
|
|
|
- VirtualOCFDevice device = bridgeServer.getVirtualOCFDevice(sn);
|
|
|
- device.addProperties(uri, res_data);
|
|
|
+ // Update Properties of the resource from result
|
|
|
+ bridgeServer.addOrUpdateVirtualOCFDeviceProperties(sn, uri, res_data);
|
|
|
}
|
|
|
} catch (JSONException e) {
|
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
@@ -482,8 +482,8 @@ public class BridgeService extends IntentService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String retrieveAllResources(String device_uuid) throws RemoteException {
|
|
|
- if(BridgeServer.LIGHT2_UUID.equalsIgnoreCase(device_uuid)) {
|
|
|
+ public String retrieveAllResources(String device_sn) throws RemoteException {
|
|
|
+ if(BridgeServer.LIGHT2_UUID.equalsIgnoreCase(device_sn)) {
|
|
|
return "[{\"n\":\"Light Switch\", \"uri\":\"/light\", \"rt\":[\"oic.r.switch.binary\"], \"if\":\"RW\"},\n" +
|
|
|
"{\"n\":\"Dimming Control\",\"uri\":\"/dimming\",\"rt\":[\"oic.r.light.dimming\"], \"if\":\"RW\"},\n" +
|
|
|
"{\"n\":\"Energy Consumption\", \"uri\":\"/EnergyConsumptionResURI\", \"rt\": [\"oic.r.energy.consumption\"], \"if\":\"S\"},\n" +
|
|
@@ -493,16 +493,24 @@ public class BridgeService extends IntentService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String doGetResourceProperties(String device_uuid, String resource_uri) throws RemoteException {
|
|
|
- if(BridgeServer.LIGHT2_UUID.equalsIgnoreCase(device_uuid)) {
|
|
|
+ public String doGetResourceProperties(String device_sn, String resource_uri) throws RemoteException {
|
|
|
+ if(BridgeServer.LIGHT2_UUID.equalsIgnoreCase(device_sn)) {
|
|
|
if("/light".equalsIgnoreCase(resource_uri)) {
|
|
|
- return "{\"n\":\"Light Switch\", \"value\":true}" ;
|
|
|
+ String props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource_uri) ;
|
|
|
+ if(props != null) return props ;
|
|
|
+ else return "{\"n\":\"Light Switch\", \"value\":true}" ;
|
|
|
} else if("/dimming".equalsIgnoreCase(resource_uri)) {
|
|
|
- return "{\"n\":\"Dimming Control\",\"dimmingSetting\":100,\"range\":100,\"step\":10}";
|
|
|
+ String props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource_uri) ;
|
|
|
+ if(props != null) return props ;
|
|
|
+ else return "{\"n\":\"Dimming Control\",\"dimmingSetting\":100,\"range\":100,\"step\":10}";
|
|
|
} else if("/EnergyConsumptionResURI".equalsIgnoreCase(resource_uri)) {
|
|
|
- return "{\"n\":\"Energy Consumption\",\"power\":200.1,\"energy\":3500.4}" ;
|
|
|
+ String props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource_uri) ;
|
|
|
+ if(props != null) return props ;
|
|
|
+ else return "{\"n\":\"Energy Consumption\",\"power\":200.1,\"energy\":3500.4}" ;
|
|
|
} else if("/ColourTemperatureResURI".equalsIgnoreCase(resource_uri)) {
|
|
|
- return "{\"n\":\"Color Temperature\", \"ct\":457, \"range\":1000, \"step\":1}" ;
|
|
|
+ String props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource_uri) ;
|
|
|
+ if(props != null) return props ;
|
|
|
+ else return "{\"n\":\"Color Temperature\", \"ct\":457, \"range\":1000, \"step\":1}" ;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
@@ -535,9 +543,9 @@ public class BridgeService extends IntentService {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private String makeResultData(String device_uuid, String uri, String data) {
|
|
|
+ private String makeResultData(String device_sn, String uri, String data) {
|
|
|
String res = "{\"tid\":\""+Utils.generateRandomID()+"\", " +
|
|
|
- "\"sn\":\""+device_uuid+"\", " +
|
|
|
+ "\"sn\":\""+device_sn+"\", " +
|
|
|
"\"uri\":\""+uri+"\", " +
|
|
|
"\"res_type\":\"POST\", " +
|
|
|
"\"res_data\":"+data+"}";
|
|
@@ -565,9 +573,13 @@ public class BridgeService extends IntentService {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- public String doGetLightControlResource(String device_uuid, String resource_uri) {
|
|
|
+ public String doGetLightControlResource(long device_index, String device_id, String resource_uri) {
|
|
|
try {
|
|
|
- String properties = lightBinder.doGetResourceProperties(device_uuid, resource_uri);
|
|
|
+ OCUuid piid = OCCoreRes.getDeviceInfo(device_index).getPiid();
|
|
|
+ String device_sn = OCUuidUtil.uuidToString(piid); // same with vod_id(Virtual Device Id) of VirtualOCFDevice
|
|
|
+
|
|
|
+ // doGetProperties with Light Control Service
|
|
|
+ String properties = lightBinder.doGetResourceProperties(device_sn, resource_uri);
|
|
|
return properties ;
|
|
|
} catch (RemoteException e) {
|
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
@@ -577,7 +589,7 @@ public class BridgeService extends IntentService {
|
|
|
|
|
|
public void doGetLightControlResources() {
|
|
|
|
|
|
- // TODO : doGetProperties with Light Control Service
|
|
|
+ Log.d(TAG, "SecheduledTaskInit : doGetLightControlResources() called.");
|
|
|
if(bridgeServer != null && lightBinder != null) {
|
|
|
ArrayList<VirtualOCFDevice> vods = bridgeServer.getVirtualOCFDeviceList();
|
|
|
for (VirtualOCFDevice vod : vods) {
|
|
@@ -586,7 +598,9 @@ public class BridgeService extends IntentService {
|
|
|
String device_sn = vod.getVirtualDeviceId();
|
|
|
for (OCFDevice.Resource resource : vod.getResources()) {
|
|
|
try {
|
|
|
- lightBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
|
|
|
+ // doGetProperties with Light Control Service
|
|
|
+ String properies = lightBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
|
|
|
+ bridgeServer.addOrUpdateVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies);
|
|
|
} catch (RemoteException e) {
|
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
|
}
|