|
|
|
@ -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);
|
|
|
|
|