From a6f5b537d75b1a86238c105d168799763556db0b Mon Sep 17 00:00:00 2001 From: pahnjy Date: Fri, 10 Feb 2017 11:01:58 +0900 Subject: [PATCH] =?UTF-8?q?LWM2M=20Device=20=EC=A0=9C=EC=96=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#372?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../so/device/entity/LWM2MDeviceControl.java | 165 ++++++++++++++++++ .../icbms/so/device/entity/LWM2MProfile.java | 6 + .../so/device/logic/DeviceManagerLogic.java | 36 +++- .../so/device/proxy/DeviceControlProxy.java | 9 + .../icbms/so/device/proxy/DeviceSIProxy.java | 18 ++ .../icbms/so/device/util/ClientProfile.java | 4 + .../icbms/so/util/address/AddressStore.java | 10 +- .../so/util/conversion/DataConversion.java | 5 + 8 files changed, 248 insertions(+), 5 deletions(-) create mode 100644 so-device/src/main/java/com/pineone/icbms/so/device/entity/LWM2MDeviceControl.java create mode 100644 so-device/src/main/java/com/pineone/icbms/so/device/entity/LWM2MProfile.java diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/entity/LWM2MDeviceControl.java b/so-device/src/main/java/com/pineone/icbms/so/device/entity/LWM2MDeviceControl.java new file mode 100644 index 00000000..f285f3ee --- /dev/null +++ b/so-device/src/main/java/com/pineone/icbms/so/device/entity/LWM2MDeviceControl.java @@ -0,0 +1,165 @@ +package com.pineone.icbms.so.device.entity; + +/** + * LWM2M SO-SI Interface + * con 값으로 base64 인코딩후 추가. + */ +public class LWM2MDeviceControl { + // + /** + * 값 : execute + * 설명 : 고정 + */ + private String operation; + + /** + * 값 : /1024/12/1, /1024/12/3 중 제어 희망하는 항목 택1 + * 설명 : LED : /1024/12/1, SOUND : /1024/12/3 + + */ + private String resourceUri; + + /** + * 값 : led, sound 중 제어 희망하는 항목 택1 + * 설명 : + */ + private String displayName; + + /** + * 값 : 000001 + * 설명 : 디바이스 제조사 넘버 + */ + private String oui; + + /** + * 값 : LWM2M Client(raspberry) + * 설명 : 디바이스 모델 이름 + */ + private String modelName; + + /** + * 값 : 90:9F:33:EF:D8:ED + * 설명 : 디바이스 시리얼 넘버 + */ + private String sn; + + /** + * 값 : testlwm2mclient + * 설명 : 고정 + */ + private String authld; + + /** + * 값 : 1234567890abcdef1234567890abcdef + * 설명 : 고정 + */ + private String authPwd; + + /** + * 값 : 1 + * 설명 : 제어 값 + */ + private String sv; + + public LWM2MDeviceControl() { + } + + public LWM2MDeviceControl(String operation, String resourceUri, String displayName, String oui, String modelName, String sn, String authld, String authPwd, String sv) { + this.operation = operation; + this.resourceUri = resourceUri; + this.displayName = displayName; + this.oui = oui; + this.modelName = modelName; + this.sn = sn; + this.authld = authld; + this.authPwd = authPwd; + this.sv = sv; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getResourceUri() { + return resourceUri; + } + + public void setResourceUri(String resourceUri) { + this.resourceUri = resourceUri; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getOui() { + return oui; + } + + public void setOui(String oui) { + this.oui = oui; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getSn() { + return sn; + } + + public void setSn(String sn) { + this.sn = sn; + } + + public String getAuthld() { + return authld; + } + + public void setAuthld(String authld) { + this.authld = authld; + } + + public String getAuthPwd() { + return authPwd; + } + + public void setAuthPwd(String authPwd) { + this.authPwd = authPwd; + } + + public String getSv() { + return sv; + } + + public void setSv(String sv) { + this.sv = sv; + } + + @Override + public String toString() { + return "LWM2MDeviceControl{" + + "operation='" + operation + '\'' + + ", resourceUri='" + resourceUri + '\'' + + ", displayName='" + displayName + '\'' + + ", oui='" + oui + '\'' + + ", modelName='" + modelName + '\'' + + ", sn='" + sn + '\'' + + ", authld='" + authld + '\'' + + ", authPwd='" + authPwd + '\'' + + ", sv='" + sv + '\'' + + '}'; + } +} diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/entity/LWM2MProfile.java b/so-device/src/main/java/com/pineone/icbms/so/device/entity/LWM2MProfile.java new file mode 100644 index 00000000..252cdc6a --- /dev/null +++ b/so-device/src/main/java/com/pineone/icbms/so/device/entity/LWM2MProfile.java @@ -0,0 +1,6 @@ +package com.pineone.icbms.so.device.entity; + +public class LWM2MProfile { + // + public static final String SO_CONTROL_TYPE = "text/plain:0"; +} diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/logic/DeviceManagerLogic.java b/so-device/src/main/java/com/pineone/icbms/so/device/logic/DeviceManagerLogic.java index 6e1c2a06..deaf546d 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/logic/DeviceManagerLogic.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/logic/DeviceManagerLogic.java @@ -96,7 +96,24 @@ public String deviceExecute(String deviceId,String deviceCommand, String session } // SI를 제어할수 있는 DeviceControlMessage로 변환 - DeviceControlMessage deviceControlMessage = deviceDataConversion(deviceId,commandId,deviceCommand); + DeviceControlMessage deviceControlMessage = new DeviceControlMessage(); + LWM2MDeviceControl lwm2MDeviceControl = new LWM2MDeviceControl(); + if(device.getDeviceUri().contains("lwm2m")){ + lwm2MDeviceControl.setOperation("execute"); + lwm2MDeviceControl.setResourceUri("/1024/12/3"); + lwm2MDeviceControl.setDisplayName("sound"); + lwm2MDeviceControl.setOui("000001"); + lwm2MDeviceControl.setModelName("LWM2M Client(raspberry)"); + lwm2MDeviceControl.setSn("90:9F:33:EF:D8:ED"); + lwm2MDeviceControl.setAuthld("testlwm2mclient"); + lwm2MDeviceControl.setAuthPwd("1234567890abcdef1234567890abcdef"); + lwm2MDeviceControl.setSv(deviceCommand); + deviceControlMessage = lwm2mDeviceDataConversion(deviceId,commandId,deviceCommand); + } else { + deviceControlMessage = deviceDataConversion(deviceId,commandId,deviceCommand); + } + + logger.debug("DeviceControlMessage = " + deviceControlMessage.toString()); session = sessionStore.retrieveSessionDetail(localSessionId); @@ -109,7 +126,12 @@ public String deviceExecute(String deviceId,String deviceCommand, String session */ // Device 제어 요청 보냄. - ResultMessage resultMessage = deviceControlProxy.deviceControlRequest(contextAddress.getServerAddress(ContextAddress.SI_SERVER) + AddressStore.SI_CONTOL_URI,deviceControlMessage); + ResultMessage resultMessage = new ResultMessage(); + if(device.getDeviceUri().contains("lwm2m")){ + resultMessage = deviceControlProxy.lwm2mDeviceControlRequest(contextAddress.getServerAddress(ContextAddress.SI_SERVER) + AddressStore.SI_LWM2M_CONTOL_URI,deviceControlMessage,lwm2MDeviceControl); + } else { + resultMessage = deviceControlProxy.deviceControlRequest(contextAddress.getServerAddress(ContextAddress.SI_SERVER) + AddressStore.SI_CONTOL_URI,deviceControlMessage); + } logger.debug(LogPrint.LogMethodNamePrint() + " | Device Control Result : " + " , Device Uri = " + device.getDeviceUri() + " , Result : " + resultMessage + " , Session ID = " + sessionId); sessionDataUpdate(sessionStore,session,resultMessage.getCode(), DefaultSession.DEVICE_RESULT); /** @@ -267,6 +289,16 @@ private DeviceControlMessage deviceDataConversion(String deviceId, String comman return deviceControlMessage; } + private DeviceControlMessage lwm2mDeviceDataConversion(String deviceId, String commandId, String deviceCommand){ + DeviceControlMessage deviceControlMessage = new DeviceControlMessage(); + deviceControlMessage.set_uri(deviceId); + deviceControlMessage.set_commandId(commandId); + deviceControlMessage.set_command(ClientProfile.SI_CONTROL_LWM2M_SOUND); + deviceControlMessage.setCnf(ClientProfile.SO_CONTROL_JSON_TYPE); + deviceControlMessage.setCon(deviceCommand); + return deviceControlMessage; + } + private Device deviceRequest(String uri){ // return deviceICollectionProxy.findDeviceByID(uri); diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/proxy/DeviceControlProxy.java b/so-device/src/main/java/com/pineone/icbms/so/device/proxy/DeviceControlProxy.java index f4d54757..14bf5af3 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/proxy/DeviceControlProxy.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/proxy/DeviceControlProxy.java @@ -1,6 +1,7 @@ package com.pineone.icbms.so.device.proxy; import com.pineone.icbms.so.device.entity.DeviceControlMessage; +import com.pineone.icbms.so.device.entity.LWM2MDeviceControl; import com.pineone.icbms.so.device.entity.ResultMessage; /** @@ -17,6 +18,14 @@ public interface DeviceControlProxy { */ ResultMessage deviceControlRequest(String requestUrl, DeviceControlMessage deviceControlMessage); + /** + * Device 제어 요청 + * @param requestUrl + * @param deviceControlMessage + * @return + */ + ResultMessage lwm2mDeviceControlRequest(String requestUrl, DeviceControlMessage deviceControlMessage, LWM2MDeviceControl lwm2MDeviceControl); + /** * Device 구독 요청 * @param deviceUri diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/proxy/DeviceSIProxy.java b/so-device/src/main/java/com/pineone/icbms/so/device/proxy/DeviceSIProxy.java index 56360667..c6a8b8d1 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/proxy/DeviceSIProxy.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/proxy/DeviceSIProxy.java @@ -3,10 +3,12 @@ import com.google.gson.Gson; import com.pineone.icbms.so.device.entity.DeviceControlMessage; import com.pineone.icbms.so.device.entity.DeviceSubscriptionData; +import com.pineone.icbms.so.device.entity.LWM2MDeviceControl; import com.pineone.icbms.so.device.entity.ResultMessage; import com.pineone.icbms.so.device.util.ClientProfile; import com.pineone.icbms.so.util.address.AddressStore; import com.pineone.icbms.so.util.address.ContextAddress; +import com.pineone.icbms.so.util.conversion.DataConversion; import com.pineone.icbms.so.util.http.ClientService; import com.pineone.icbms.so.util.logprint.LogPrint; import org.codehaus.jackson.map.ObjectMapper; @@ -50,6 +52,22 @@ public ResultMessage deviceControlRequest(String requestUrl, DeviceControlMessag return resultMessage; } + @Override + public ResultMessage lwm2mDeviceControlRequest(String requestUrl, DeviceControlMessage deviceControlMessage, LWM2MDeviceControl lwm2MDeviceControl) { + logger.info("<================ LWM2M Device Control Request Start ================>"); + logger.debug(LogPrint.LogMethodNamePrint() + " | RequestUri = " + requestUrl + " , deviceControlMessage = " + deviceControlMessage.toString() + "LWM2MDeviceControl = " + lwm2MDeviceControl.toString()); + String lwm2mCon = DataConversion.base64incoding(new Gson().toJson(lwm2MDeviceControl)); + logger.debug(LogPrint.LogMethodNamePrint() + " | LWM2M Device Con = " + lwm2mCon); + deviceControlMessage.setCon(lwm2mCon); + String requestBody = new Gson().toJson(deviceControlMessage); + String responseData = clientService.requestPostServiceReceiveString(requestUrl, requestBody); + logger.debug(LogPrint.LogMethodNamePrint() + " | Device Control Request responseData = " + responseData); + ResultMessage resultMessage = parsingResultMessage(responseData); + logger.debug(LogPrint.LogMethodNamePrint() + " | Device Control Request Result = " + resultMessage); + logger.info("<================ LWM2M Device Control Request End ================>"); + return resultMessage; + } + @Override public String deviceSubscriptionRequest(String deviceUri, String commandId) { // diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/util/ClientProfile.java b/so-device/src/main/java/com/pineone/icbms/so/device/util/ClientProfile.java index db0b7998..00dce2d1 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/util/ClientProfile.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/util/ClientProfile.java @@ -8,6 +8,10 @@ public class ClientProfile { public static final String SI_CONTROL_ACTION = "Action"; public static final String SI_COMMAND_ID = "cmd_"; + // LWM2M control Data + public static final String SO_CONTROL_JSON_TYPE = "application/json:1"; + public static final String SI_CONTROL_LWM2M_SOUND = "sound__-1024-12-3"; + public static final String DEVICE_SERVICE_NOTI_TYPE = "http://www.iotoasis.org/ontology/AlarmFunctionality"; public static final String SERVICE_ALARM_TYPE = "Alarm"; diff --git a/so-util/src/main/java/com/pineone/icbms/so/util/address/AddressStore.java b/so-util/src/main/java/com/pineone/icbms/so/util/address/AddressStore.java index 43ce6d82..6610ccf2 100644 --- a/so-util/src/main/java/com/pineone/icbms/so/util/address/AddressStore.java +++ b/so-util/src/main/java/com/pineone/icbms/so/util/address/AddressStore.java @@ -28,9 +28,13 @@ public class AddressStore { public static final String RETRIEVE_NEXT_KEYBOARD="inquiry/next/keyboard"; // SI Command Data - public static final String SI_CONTOL_URI = "/si/control"; - public static final String SI_SUBSCRIPTION_URI = "/si/subscription/add"; - public static final String SI_SUBSCRIPTION_RELEASE_URI = "/si/subscription/del"; + public static final String SI_CONTOL_URI = "/si/control"; + public static final String SI_SUBSCRIPTION_URI = "/si/subscription/add"; + public static final String SI_SUBSCRIPTION_RELEASE_URI = "/si/subscription/del"; + + // SI LWM2M Data + public static final String SI_LWM2M_CONTOL_URI = "/si/ipe/lwm2m"; + //SDA Data public static final String SDA_DEVICE = "/device"; diff --git a/so-util/src/main/java/com/pineone/icbms/so/util/conversion/DataConversion.java b/so-util/src/main/java/com/pineone/icbms/so/util/conversion/DataConversion.java index a30cc267..3e03a976 100644 --- a/so-util/src/main/java/com/pineone/icbms/so/util/conversion/DataConversion.java +++ b/so-util/src/main/java/com/pineone/icbms/so/util/conversion/DataConversion.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import org.apache.commons.codec.binary.Base64; import org.codehaus.jackson.map.ObjectMapper; import java.io.IOException; @@ -59,5 +60,9 @@ public static List stringDataToList(String data){ return new Gson().fromJson(data,type); } + public static String base64incoding(String data){ + return new String(Base64.encodeBase64(data.getBytes())); + } + }