Merge remote-tracking branch 'upstream/IoTS-1.0.0-M3' into IoTS-1.0.0-M2

# Conflicts:
#	components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneRealTimeService.java
charithag 9 years ago
commit b18c1aa00b

@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.device.DeviceType;
import org.wso2.carbon.apimgt.annotations.device.feature.Feature;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.iot.DeviceValidator;
@ -29,13 +28,8 @@ import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConsta
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.DroneController;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.impl.DroneControllerImpl;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.concurrent.ConcurrentHashMap;
@ -57,11 +51,10 @@ public class DroneControllerService {
--------------------------------------------------------------------------------------- */
@Path("controller/register/{owner}/{deviceId}/{ip}/{port}")
@POST
public String registerDeviceIP(@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
public Response registerDeviceIP(@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
@PathParam("ip") String deviceIP,
@PathParam("port") String devicePort,
@Context HttpServletResponse response,
@Context HttpServletRequest request) {
@Context HttpServletResponse response) {
String result;
log.info("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: " + owner);
String deviceHttpEndpoint = deviceIP + ":" + devicePort;
@ -72,17 +65,16 @@ public class DroneControllerService {
log.debug(result);
}
log.info(owner + deviceId + deviceIP + devicePort );
return result;
return Response.ok(Response.Status.OK.getStatusCode()).build();
}
@Path("controller/send_command")
@POST
@Feature( code="send_command", name="Send Command", type="operation",
description="Send Commands to Drone")
/*@Feature( code="send_command", name="Send Command", type="operation",
description="Send Commands to Drone")*/
public Response droneController(@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
@QueryParam("action") String action, @QueryParam("duration") String duration,
@QueryParam("speed") String speed){
@FormParam("action") String action, @FormParam("duration") String duration,
@FormParam("speed") String speed){
try {
DeviceValidator deviceValidator = new DeviceValidator();
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,

@ -11,7 +11,7 @@
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -21,15 +21,11 @@ package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.iot.DeviceManagement;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport.DroneAnalyzerXMPPConnector;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.trasformer.MessageTransformer;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
@ -48,8 +44,7 @@ public class DroneRealTimeService {
}
messageController = new MessageTransformer();
xmppConnector = new DroneAnalyzerXMPPConnector(messageController);
if (XmppConfig.getInstance().isEnabled()) {
if (!XmppConfig.getInstance().isEnabled()){
xmppConnector.connect();
} else {
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, DroneAnalyzerXMPPConnector not started.");
@ -84,24 +79,23 @@ public class DroneRealTimeService {
@OnMessage
public void onMessage(String message, Session session){
try {
while(true){
if((messageController !=null) && (!messageController.isEmptyQueue())){
String message1 = messageController.getMessage();
session.getBasicRemote().sendText(message1);
try{
if((messageController !=null) && (!messageController.isEmptyQueue())){
String message1 = messageController.getMessage();
session.getBasicRemote().sendText(message1);
}
Thread.sleep(DroneConstants.MINIMUM_TIME_DURATION);
} catch (IOException ex) {
log.error(ex.getMessage() + "\n" + ex);
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
}
Thread.sleep(DroneConstants.MINIMUM_TIME_DURATION);
}
} catch (IOException ex) {
log.error(ex.getMessage() + "\n" + ex);
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
}
}
@OnClose
public void onClose(Session session){
try {
xmppConnector.disconnect();
log.info("XMPP connection is disconnected");

@ -35,33 +35,29 @@ public class DroneAnalyzerXMPPConnector extends XMPPTransportHandler {
private static Log log = LogFactory.getLog(DroneAnalyzerXMPPConnector.class);
private static String xmppServerIP;
private static int xmppServerPort;
private static String xmppAdminUsername;
private static String xmppAdminPassword;
private static String xmppAdminAccountJID;
private MessageTransformer messageTransformer;
private ScheduledFuture<?> connectorServiceHandler;
private ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
public DroneAnalyzerXMPPConnector(MessageTransformer messageTransformer) {
super(XmppConfig.getInstance().getXmppServerIP(),
XmppConfig.getInstance().getSERVER_CONNECTION_PORT());
super(XmppConfig.getInstance().getXmppServerIP(),XmppConfig.getInstance().getSERVER_CONNECTION_PORT());
this.messageTransformer = messageTransformer;
}
@Override
public void connect() {
Runnable connector = new Runnable() {
@Override
public void run() {
if (!isConnected()) {
try {
initConnector();
connectToServer();
loginToServer(xmppAdminUsername, xmppAdminPassword, null);
setFilterOnReceiver(DroneConstants.DEVICE_ID+ "@" + xmppServerIP);
setFilterOnReceiver(xmppAdminAccountJID);
} catch (TransportHandlerException e) {
if (log.isDebugEnabled()) {
log.warn("Connection/Login to XMPP server at: " + server + " as " +
@ -84,18 +80,28 @@ public class DroneAnalyzerXMPPConnector extends XMPPTransportHandler {
@Override
public void processIncomingMessage(Message message) throws TransportHandlerException {
String from = message.getFrom();
String subject = message.getSubject();
String inbound_message = message.getBody();
int indexOfAt = from.indexOf("@");
int indexOfSlash = from.indexOf("/");
String deviceId = from.substring(0, indexOfAt);
String resource = from.substring(indexOfSlash + 1, from.length());
if ((inbound_message != null)&&(resource.equals(DroneConstants.MESSAGE_RESOURCE)) ){
messageTransformer.messageTranslater(inbound_message);
} else {
log.error("Message is empty or it is not belongs to "+ DroneConstants.DEVICE_ID);
try{
String from = message.getFrom();
String inbound_message = message.getBody();
int indexOfSlash = from.indexOf("/");
if(indexOfSlash==0){
if(log.isDebugEnabled()){
log.debug("Required resource not available.");
}
}else{
String resource = from.substring(indexOfSlash + 1, from.length());
if ((inbound_message != null)&&(resource.equals(DroneConstants.MESSAGE_RESOURCE)) ){
messageTransformer.messageTranslater(inbound_message);
} else {
if(log.isDebugEnabled()){
log.debug("Message is empty or it is not belongs to " + xmppAdminUsername);
}
}
}
}catch(ArrayIndexOutOfBoundsException e){
log.error("Wrong message format: input message", e);
}catch(RuntimeException e){
log.error("Unexpected error has been occurred, ", e);
}
}
@ -117,18 +123,15 @@ public class DroneAnalyzerXMPPConnector extends XMPPTransportHandler {
log.warn("Unable to 'STOP' connection to XMPP server at: " + server +
" for user - " + xmppAdminUsername);
}
try {
Thread.sleep(timeoutInterval);
} catch (InterruptedException e1) {
log.error("XMPP-Terminator: Thread Sleep Interrupt Exception for "
+ DroneConstants.DEVICE_TYPE + " type.", e1);
}
}
}
};
Thread terminatorThread = new Thread(stopConnection);
terminatorThread.setDaemon(true);
terminatorThread.start();

@ -35,11 +35,11 @@ public class MessageTransformer {
private Log log = LogFactory.getLog(MessageTransformer.class);
private CircularFifoQueue<String> sharedQueue;
private String outbound_message_format_for_simulator = "{\"quatanium_val\":[%f, %f, %f, %f]," +
"\"basicParam\":{\"velocity\":[%f, %f, %f], \"global_location\":[%f, %f, %f]},\"battery_level\":%f, \"device_type\":\"IRIS_DRONE\"}";
private String outbound_message_format_for_iris_drone = "{\"quatanium_val\":[%f, %f, %f]," +
private String outboundMessageFormatForSimulator = "{\"quatanium_val\":[%f, %f, %f, %f]," +
"\"basicParam\":{\"velocity\":[%f, %f, %f], \"global_location\":[%f, %f, %f]},\"battery_level\":%f, \"device_type\":\"SIMULATOR\"}";
private String outboundMessageFormatForIrisDrone = "{\"quatanium_val\":[%f, %f, %f]," +
"\"basicParam\":{\"velocity\":[%f, %f, %f], \"global_location\":[%f, %f, %f]},\"battery_level\":%f," +
"\"device_type\":\"SIMULATOR\"}";
"\"device_type\":\"IRIS_DRONE\"}";
public MessageTransformer(){
sharedQueue = new CircularFifoQueue<String>(DroneConstants.MAXIMUM_BUFFERE_SIZE_OF_SHARED_QUEUE);
@ -47,19 +47,18 @@ public class MessageTransformer {
private void messageTranslaterForSimulator(JsonNode inbound_message){
JsonNode node = inbound_message;
String outbound_message;
String outboundMessage;
try {
JsonNode velocity = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(MessageConfig.OUT_BASIC_PARAM_VELOCITY);
JsonNode global_location = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(
JsonNode globalLocation = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(
MessageConfig.OUT_BASIC_PARAM_GLOBAL_LOCATION);
JsonNode quatanium_vals = node.get(MessageConfig.OUT_QUATANNIM_VAL);
JsonNode battery_level = node.get(MessageConfig.OUT_BATTERY_LEVEL);
outbound_message = String.format(outbound_message_format_for_simulator, sTd(quatanium_vals.get(0)),
sTd(quatanium_vals.get(1)), sTd(quatanium_vals.get(2)), sTd(quatanium_vals.get(0)),
sTd(velocity.get(0)), sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(global_location.get(0)),
sTd(global_location.get(1)), sTd(global_location.get(2)), sTd(battery_level));
sharedQueue.add(outbound_message);
JsonNode quataniumVals = node.get(MessageConfig.OUT_QUATANNIM_VAL);
JsonNode batteryLevel = node.get(MessageConfig.OUT_BATTERY_LEVEL);
outboundMessage = String.format(outboundMessageFormatForSimulator, sTd(quataniumVals.get(0)),
sTd(quataniumVals.get(1)), sTd(quataniumVals.get(2)), sTd(quataniumVals.get(0)),
sTd(velocity.get(0)), sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(globalLocation.get(0)),
sTd(globalLocation.get(1)), sTd(globalLocation.get(2)), sTd(batteryLevel));
sharedQueue.add(outboundMessage);
} catch (Exception e) {
log.error(e.getMessage()+",\n"+ e);
}
@ -67,19 +66,19 @@ public class MessageTransformer {
private void messageTranslaterForIRISDrone(JsonNode inbound_message){
JsonNode node = inbound_message;
String outbound_message;
String outboundMessage;
try {
JsonNode velocity = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(MessageConfig.OUT_BASIC_PARAM_VELOCITY);
JsonNode global_location = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(
JsonNode globalLocation = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(
MessageConfig.OUT_BASIC_PARAM_GLOBAL_LOCATION);
JsonNode quatanium_vals = node.get(MessageConfig.OUT_QUATANNIM_VAL);
JsonNode battery_level = node.get(MessageConfig.OUT_BATTERY_LEVEL);
outbound_message = String.format(outbound_message_format_for_iris_drone, sTd(quatanium_vals.get(0)),
sTd(quatanium_vals.get(1)), sTd(quatanium_vals.get(2)), sTd(velocity.get(0)),
sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(global_location.get(0)),
sTd(global_location.get(1)), sTd(global_location.get(2)), sTd(battery_level));
sharedQueue.add(outbound_message);
JsonNode quataniumVals = node.get(MessageConfig.OUT_QUATANNIM_VAL);
JsonNode batteryLevel = node.get(MessageConfig.OUT_BATTERY_LEVEL);
outboundMessage = String.format(outboundMessageFormatForIrisDrone, sTd(quataniumVals.get(0)),
sTd(quataniumVals.get(1)), sTd(quataniumVals.get(2)), sTd(velocity.get(0)),
sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(globalLocation.get(0)),
sTd(globalLocation.get(1)), sTd(globalLocation.get(2)), sTd(batteryLevel));
sharedQueue.add(outboundMessage);
}catch (Exception e) {
log.error(e.getMessage()+",\n"+ e);
@ -87,20 +86,22 @@ public class MessageTransformer {
}
public void messageTranslater(String inbound_message){
JsonNode actualMessage = null;
JsonNode actualMessage;
ObjectMapper objectMapper = new ObjectMapper();
try {
actualMessage = objectMapper.readValue(inbound_message, JsonNode.class);
JsonNode deviceType = actualMessage.get(MessageConfig.IN_DEVICE_TYPE);
switch (deviceType.getTextValue()) {
case MessageConfig.IN_IRIS_DRONE:
messageTranslaterForIRISDrone(actualMessage);
break;
case MessageConfig.IN_SIMULATOR:
messageTranslaterForSimulator(actualMessage);
break;
default:
if(log.isDebugEnabled()){
log.debug("Wrong message format");
}
}
} catch (JsonProcessingException e) {
log.error("Incoming message might be corrupted, "+ e);

@ -19,16 +19,11 @@
package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.util;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException;
import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport.DroneAnalyzerXMPPConnector;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.DroneController;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.exception.DroneAnalyzerException;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport.DroneAnalyzerXMPPConnector;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
import java.io.File;
@ -36,7 +31,6 @@ import java.io.File;
public class DroneAnalyzerServiceUtils {
private static final String SUPER_TENANT = "carbon.super";
private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature";
private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneAnalyzerServiceUtils.class);
public static void sendCommandViaXMPP(String deviceOwner, String deviceId, String resource,
@ -46,8 +40,7 @@ public class DroneAnalyzerServiceUtils {
String xmppServerDomain = XmppConfig.getInstance().getXmppEndpoint();
int indexOfChar = xmppServerDomain.lastIndexOf(File.separator);
if (indexOfChar != -1) {
xmppServerDomain = xmppServerDomain.substring((indexOfChar + 1),
xmppServerDomain.length());
xmppServerDomain = xmppServerDomain.substring((indexOfChar + 1), xmppServerDomain.length());
}
indexOfChar = xmppServerDomain.indexOf(":");
if (indexOfChar != -1) {
@ -58,80 +51,46 @@ public class DroneAnalyzerServiceUtils {
droneXMPPConnector.publishDeviceData(clientToConnect, message, "CONTROL-REQUEST");
}
public static boolean sendControlCommand(DroneController controller, String deviceId, String action, double speed, double duration)
public static boolean sendControlCommand(DroneController controller, String deviceId, String action,
double speed, double duration)
throws DeviceManagementException {
boolean control_state = false;
boolean controlState = false;
try{
switch (action){
case DroneConstants.TAKE_OFF:
control_state = controller.takeoff();
controlState = controller.takeoff();
break;
case DroneConstants.LAND:
control_state = controller.land();
controlState = controller.land();
break;
case DroneConstants.BACK:
control_state = controller.back(speed, duration);
controlState = controller.back(speed, duration);
break;
case DroneConstants.CLOCK_WISE:
control_state = controller.clockwise(speed, duration);
controlState = controller.clockwise(speed, duration);
break;
case DroneConstants.COUNTER_CLOCKWISE:
control_state = controller.conterClockwise(speed, duration);
controlState = controller.conterClockwise(speed, duration);
break;
case DroneConstants.DOWN:
control_state = controller.down(speed, duration);
controlState = controller.down(speed, duration);
break;
case DroneConstants.FRONT:
control_state = controller.back(speed, duration);
controlState = controller.back(speed, duration);
break;
case DroneConstants.FORWARD:
control_state = controller.clockwise(speed, duration);
controlState = controller.clockwise(speed, duration);
break;
case DroneConstants.UP:
control_state = controller.up(speed, duration);
controlState = controller.up(speed, duration);
break;
default:
log.error("Invalid command");
break;
}
}catch(Exception e){
log.error(e.getMessage()+ "\n"+ e);
}
return control_state;
}
public static boolean publishToDAS(String owner, String deviceId, float temperature) {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ctx.setTenantDomain(SUPER_TENANT, true);
DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx.getOSGiService(
DeviceAnalyticsService.class, null);
Object metdaData[] = {owner, DroneConstants.DEVICE_TYPE, deviceId,
System.currentTimeMillis()};
Object payloadData[] = {temperature};
try {
deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", metdaData,
new Object[0], payloadData);
} catch (DataPublisherConfigurationException e) {
return false;
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return true;
return controlState;
}
public static CertificateManagementService getCertificateManagementService() throws
DroneAnalyzerException {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
CertificateManagementService certificateManagementService = (CertificateManagementService)
ctx.getOSGiService(CertificateManagementService.class, null);
if (certificateManagementService == null) {
String msg = "EnrollmentService is not initialized";
log.error(msg);
throw new DroneAnalyzerException(msg);
}
return certificateManagementService;
}
}

@ -27,8 +27,6 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.impl.DroneAnalyzerManagerService;
import org.wso2.carbon.device.mgt.iot.service.DeviceTypeService;
/**
* @scr.component name="org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.internal
* .DroneAnalyzerManagementServiceComponent"

@ -33,6 +33,7 @@ DEVICE_OWNER = configParser.get('Device-Configurations', 'owner')
DEVICE_ID = configParser.get('Device-Configurations', 'deviceId')
XMPP_EP = configParser.get('Device-Configurations', 'xmpp-ep')
AUTH_TOKEN = configParser.get('Device-Configurations', 'auth-token')
DEVICE_PASSWORD = configParser.get('Device-Configurations', 'auth-token')
CONTROLLER_CONTEXT = configParser.get('Device-Configurations', 'controller-context')
HTTPS_EP = configParser.get('Device-Configurations', 'https-ep')
HTTP_EP = configParser.get('Device-Configurations', 'http-ep')

@ -23,9 +23,9 @@ import util
XMPP_ENDPOINT = util.XMPP_EP.split(":")
XMPP_IP = XMPP_ENDPOINT[1].replace('//', '')
XMPP_PORT = int(XMPP_ENDPOINT[2])
MESSAGE_TO = "admin"
XMPP_OWN = util.DEVICE_OWNER
XMPP_PWD = util.DEVICE_ID
MESSAGE_TO = util.DEVICE_OWNER
XMPP_PWD = util.DEVICE_PASSWORD
XMPP_OWN = util.DEVICE_ID
XMPP_RESOURCE = "drone_current_status"
XMPP_JID = MESSAGE_TO + "@" + XMPP_IP + "/" + XMPP_RESOURCE

@ -66,7 +66,7 @@ while true; do
done
cp deviceConfig.properties ./src
./src/IRIS+DroneStatistics.py -i $push_interval -b $baud -c $connection_target
python ./src/IRIS+DroneStatistics.py -i $push_interval -b $baud -c $connection_target
if [ $? -ne 0 ]; then
echo "Could not start the service..."

@ -169,3 +169,52 @@
.navbar {
border-radius: 0;
}
.circle {
background: none repeat scroll 0 0 #191919;
border-radius: 50px;
height: 50px;
padding: 10px;
width: 50px;
color: #fff;
}
.padding-top-double {
padding-top: 20px;
}
.padding-double {
padding: 20px;
}
.grey {
color: #333;
}
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #7f7f7f;
margin: 1em 0;
padding: 0;
opacity: 0.2;
}
.light-grey {
color: #7c7c7c;
}
.uppercase {
text-transform: uppercase;
}
.grey-bg {
background-color: #f6f4f4;
}
path {
stroke: black;
stroke-width: 2;
fill: none;
}
.axis path, .axis line {
fill: none;
stroke: #ccc;
stroke-width: 2;
shape-rendering: crispEdges;
}

@ -15,21 +15,19 @@
* specific language governing permissions and limitations
* under the License.
*/
//TODO this needs to a private resource
var config_api = function () {
var config_api = this;
var domain = "localhost";
var port = "9793";
var context_controller = "/drone_analyzer/DroneAnalyzerServiceUnitManager/controller/send_command";
var context_controller = "/drone_analyzer/controller/send_command";
config_api.config_3dobject_holder = "#virtualDrone";
config_api.realtime_plotting_update_interval = 30;
config_api.realtime_plotting_totalPoints = 30;
config_api.realtime_plotting_data_window = {};
config_api.effectController = {uy: 70.0, uz: 15.0, ux: 10.0, fx: 2.0, fz: 15.0, Tmax: 1};
config_api.drone_control = "http://" + domain + ":" + port + "/" + context_controller;
config_api.drone_control = context_controller;
config_api.drone_controlType = "POST";
config_api.drone_controlDataType = "json";
config_api.web_socket_endpoint = "ws://localhost:9763/drone_analyzer/datastream/drone_status";
config_api.web_socket_endpoint = "/drone_analyzer/datastream/drone_status";
config_api.modules_status = {
"realtimePlotting": false,
"sensorReadings": false,

@ -16,7 +16,7 @@
* under the License.
*/
object_maker.init(config_api.config_3dobject_holder, $("#objectHolder").width(), $("#objectHolder").width()/2);
object_maker.init(config_api.config_3dobject_holder, $("#objectHolder").width(), $("#objectHolder").width()/1.5);
object_maker.animate();
var flight_dynamics = new flight_dynamics();
$("#window_size").slider({
@ -58,7 +58,6 @@ $('.btn-minimize').click(function (e) {
if ($target.is(':visible')) {
if ($(this).parent().attr('id') === "RealtimePlotting") {
plotting.forceToRedraw(function (status) {
d3.select("#realtimechart").select("svg").remove();
plotting.realtime_plotting("#realtimechart", "#range_min", "#range_max", "#window_update_value",
600, $("#realtimechart").height(), "#window_size_current_value",
@ -71,33 +70,40 @@ $('.btn-minimize').click(function (e) {
$('#connectionOpen').on('click', function () {
$('#connectionOpen').toggleClass('active');
});
$("#xmppConnectionOpen").on('click', function () {
$('#xmppConnectionOpen').toggleClass('active');
if ($('#xmppConnectionOpen').html() === "Start") {
sendMessage();
$('#xmppConnectionOpen').html("Stop");
sendMessage("Start the process", function(state){
console.log("sending message to server..."+ state);
if(state<2){
$('#xmppConnectionOpen').html("Stop");
}else{
$('#xmppConnectionOpen').html("Start");
}
});
} else if ($('#xmppConnectionOpen').html() === "Stop") {
closeSocket();
$('#xmppConnectionOpen').html("Start");
$("#connectionOpen").html("Connect to server").removeClass("btn btn-info").addClass("btn btn-primary");
closeSocket(function(state){
console.log("closing WebSocket..."+ state);
if(state<2){
$('#xmppConnectionOpen').html("Stop");
}else{
$('#xmppConnectionOpen').html("Start");
}
});
$("#connectionOpen").html("Connect to XMPP Server").removeClass("btn btn-info").addClass("btn btn-primary");
}
});
$('.btn-minimize').parent().parent().next('.box-content').hide();
var webSocket;
config_api.realtime_plotting_data_window["attitude"] = new Queue();
var current_status = {};
function openSocket() {
if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED) {
function openSocket(wssAddress) {
if (webSocket !== undefined && webSocket.readyState == 1) {
writeResponse("WebSocket is already opened.");
} else {
webSocket = new WebSocket(config_api.web_socket_endpoint);
webSocket = new WebSocket(wssAddress+config_api.web_socket_endpoint);
}
webSocket.onopen = function (event) {
if (event === undefined) {
@ -121,15 +127,20 @@ function openSocket() {
writeResponse("Message has been corrupted.");
}
};
}
function sendMessage(message) {
webSocket.send(message);
function sendMessage(message, callback) {
if(webSocket.readyState<2){
webSocket.send(message);
}
callback(webSocket.readyState);
}
function closeSocket() {
webSocket.close();
function closeSocket(callback) {
if(webSocket.readyState<2){
webSocket.close();
}
callback(webSocket.readyState);
}
function writeResponse(text) {
@ -137,8 +148,6 @@ function writeResponse(text) {
}
window.onbeforeunload = function () {
webSocket.onclose = function () {
};
webSocket.close()
webSocket.close();
};

@ -17,7 +17,7 @@
*/
$("#module_control button").click(function (index) {
console.log("Asking Server to send the " + $(this).attr('id') + " command to Ar Drone");
var url = config_api.drone_control + "?action=" + $(this).attr('id') + "&speed=6&duration=7";
var url = config_api.drone_control;
ajax_handler.ajaxRequest(url, config_api.drone_controlType, {action: $(this).attr('id'), speed: 7, duration: 7},
config_api.drone_controlDataType, function (data, status) {
console.log(JSON.stringify(data));

@ -15,32 +15,30 @@
* specific language governing permissions and limitations
* under the License.
*/
var flight_dynamics = function () {
var api = this;
api.processingMessage = function (sender_message) {
JSON.stringify(sender_message);
if(sender_message.battery_level!= undefined){
$("#battery_level_holder").width( parseInt(sender_message.battery_level)+"%" );
$("#battery_level").html(sender_message.battery_level+"%");
}
if (sender_message.quatanium_val != undefined) {
current_status = object_maker.get_heading_attitude_bank(sender_message.quatanium_val);
object_maker.set_heading_attitude_bank(current_status);
$("#imageTop").animate({rotate: '' + (180 / Math.PI) * 2.890456 + 'deg'}, 2);
}
$("#imageTop").delay(2).animate({rotate: '45deg'}, 2);
if (config_api.modules_status.angleOfRotation_2 || config_api.modules_status.angleOfRotation_1) {
console.log(JSON.stringify(current_status));
object_maker.set_bank("#imageTop", current_status.bank);
object_maker.set_heading("#imageBackSecond", current_status.heading);
}
if (config_api.modules_status.realtimePlotting) {
if (current_status[$('#plotting_attribute').val()] != undefined) {
plotting.pushData(current_status[$('#plotting_attribute').val()]);
}
}
if (sender_message.basicParam != undefined) {
if (sender_message.basicParam.velocity != undefined) {
var velocity = sender_message.basicParam.velocity;

@ -1,64 +1,12 @@
{{#zone "topCss"}}
{{css "css/main-app.css" }}
<style type="text/css">
.circle {
background: none repeat scroll 0 0 #191919;
border-radius: 50px;
height: 50px;
padding: 10px;
width: 50px;
color: #fff;
}
.padding-top-double {
padding-top: 20px;
}
.padding-double {
padding: 20px;
}
.grey {
color: #333;
}
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #7f7f7f;
margin: 1em 0;
padding: 0;
opacity: 0.2;
}
.light-grey {
color: #7c7c7c;
}
.uppercase {
text-transform: uppercase;
}
.grey-bg {
background-color: #f6f4f4;
}
path {
stroke: black;
stroke-width: 2;
fill: none;
}
.axis path, .axis line {
fill: none;
stroke: #ccc;
stroke-width: 2;
shape-rendering: crispEdges;
}
</style>
{{/zone}}
<div class=" row">
<div class="box col-md-12">
<div>
<div class="col-md-2 col-sm-2 col-xs-1">
<button class="btn btn-primary" data-dismiss="modal" id="connectionOpen"
onclick="openSocket();">Connect to server</button>
onclick="openSocket('{{wssAddress}}');">Connect to XMPP Server</button>
</div>
<div class="col-md-2 col-sm-2 col-xs-1">
<button class="btn btn-primary" data-dismiss="modal" id="xmppConnectionOpen">Start</button>
@ -69,27 +17,23 @@
<div class="col-md-4 col-sm-2 col-xs-2">
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0"
aria-valuemax="100" style="width: 0%;">
0%
aria-valuemax="100" style="width: 0%;" id="battery_level_holder">
<p id="battery_level">0%</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<!-- <div class="row">
<div class="box col-md-12">
<div class="box-inner">
<div class="box-header well">
<h2><i class="glyphicon glyphicon-info-sign"></i> Controller </h2>
<div class="box-icon">
<a href="#" class="btn btn-setting btn-round btn-default"><i
class="glyphicon glyphicon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round btn-default"><i
class="glyphicon glyphicon-chevron-up" ></i></a>
<a href="#" class="btn btn-close btn-round btn-default"><i
class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content row" id="module_control">
@ -141,7 +85,7 @@
</div>
</div>
</div>
</div>
</div>-->
<div class="row">
<div class="box col-md-12">
<div class="box col-md-4">
@ -150,12 +94,8 @@
<h2><i class="glyphicon glyphicon-list"></i> Angle of Rotation</h2>
<div class="box-icon" id="AngleOfRotation_1">
<a href="#" class="btn btn-setting btn-round btn-default"><i
class="glyphicon glyphicon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round btn-default"><i
class="glyphicon glyphicon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round btn-default"><i
class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content" style="position: relative;" id="objectHolder">
@ -170,12 +110,8 @@
<div class="box-header well" data-original-title="" >
<div class="box-icon" id="AngleOfRotation_2">
<a href="#" class="btn btn-setting btn-round btn-default"><i
class="glyphicon glyphicon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round btn-default"><i
class="glyphicon glyphicon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round btn-default"><i
class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content" >
@ -196,12 +132,8 @@
<div class="box-header well" data-original-title="" >
<div class="box-icon" id="AngleOfRotation_3">
<a href="#" class="btn btn-setting btn-round btn-default"><i
class="glyphicon glyphicon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round btn-default"><i
class="glyphicon glyphicon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round btn-default"><i
class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content" >
@ -224,12 +156,8 @@
<h2><i class="glyphicon glyphicon-list"></i>Live Video Stream</h2>
<div class="box-icon" id="LiveVideoStream">
<a href="#" class="btn btn-setting btn-round btn-default"><i
class="glyphicon glyphicon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round btn-default"><i
class="glyphicon glyphicon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round btn-default"><i
class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content">
@ -248,20 +176,16 @@
<div class="box-header well" data-original-title="" >
<h2><i class="glyphicon glyphicon-list"></i>Sensor Readings</h2>
<div class="box-icon" id="SensorReadings">
<a href="#" class="btn btn-setting btn-round btn-default"><i
class="glyphicon glyphicon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round btn-default"><i
class="glyphicon glyphicon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round btn-default"><i
class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content" id="basicSensoReading">
<div>
<p>Location latitude: <label id="locationLat"></label></br>
<p>Location</br> latitude: <label id="locationLat"></label></br>
longitude: <label id="locationLog"></label></br>
altitudes: <label id="locationAlt"></label></p>
<p> Velocity: x :<label id="velocityx"></label></br>
<p> Velocity:</br> x :<label id="velocityx"></label></br>
y : <label id="velocityy"></label></br>
z : <label id="velocityz"></label></p>
<p> Battery Voltage:<label id="battery_voltage"></label></p>
@ -275,12 +199,8 @@
<h2><i class="glyphicon glyphicon-list-alt"></i>Realtime Plotting</h2>
<div class="box-icon" id="RealtimePlotting">
<a href="#" class="btn btn-setting btn-round btn-default"><i
class="glyphicon glyphicon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round btn-default"><i
class="glyphicon glyphicon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round btn-default"><i
class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content">
@ -310,8 +230,6 @@
</div>
</div>
</div>
{{#zone "bottomJs"}}
{{js "/js/d3.min.js" }}
{{js "/js/3dobject_controller/three.min.js" }}

@ -16,27 +16,10 @@
* under the License.
*/
function onRequest (context) {
/*var log = new Log("detail.js");
var deviceType = request.getParameter("type");
var deviceId = request.getParameter("id");
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/modules/device.js").deviceModule;
var device = deviceModule.viewDevice(deviceType, deviceId);
if (device) {
var viewModel = {};
var deviceInfo = device.properties.DEVICE_INFO;
if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) {
deviceInfo = parse(stringify(deviceInfo));
viewModel.system = device.properties.IMEI;
viewModel.machine = "Virtual Firealarm";
viewModel.vendor = device.properties.VENDOR;
}
device.viewModel = viewModel;
}
context.device = device;
return context;
}*/
var log = new Log("statistics.js");
var serverAddress = require("/app/modules/serverAddress.js").serverAddress;
var wssAddress = serverAddress.getWSSAddress();
var httpsAddress = serverAddress.getHPPSTSAddress();
var device = context.unit.params.device;
return { "device": device, "wssAddress": wssAddress, "httpsAddress": httpsAddress};
}
Loading…
Cancel
Save