public String createVTG(SignalKModel model) {
    if (model.getValue(vessels_dot_self_dot + nav_courseOverGroundMagnetic) != null
        || model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue) != null
        || model.getValue(vessels_dot_self_dot + nav_speedOverGround) != null) {
      VTGSentence sen = (VTGSentence) sf.createParser(TalkerId.II, SentenceId.VTG);
      sen.setMode(FaaMode.AUTOMATIC);
      if (model.getValue(vessels_dot_self_dot + nav_courseOverGroundMagnetic) != null)
        sen.setMagneticCourse(
            Math.toDegrees(
                (double) model.getValue(vessels_dot_self_dot + nav_courseOverGroundMagnetic)));
      if (model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue) != null)
        sen.setTrueCourse(
            Math.toDegrees(
                (double) model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue)));
      if (model.getValue(vessels_dot_self_dot + nav_speedOverGround) != null) {
        sen.setSpeedKmh(
            (double) model.getValue(vessels_dot_self_dot + nav_speedOverGround) * MS_TO_KM);
        sen.setSpeedKnots(
            (double) model.getValue(vessels_dot_self_dot + nav_speedOverGround) * MS_TO_KNOTS);
      }

      return sen.toSentence();
    }
    return null;
  }
 // RMC,GLL, GGA = position
 public String createRMC(SignalKModel model) {
   if (model.get(vessels_dot_self_dot + nav_position_latitude) != null
       && model.get(vessels_dot_self_dot + nav_position_longitude) != null) {
     RMCSentence sen = (RMCSentence) sf.createParser(TalkerId.GP, SentenceId.RMC);
     sen.setDate(new Date());
     sen.setStatus(DataStatus.ACTIVE);
     sen.setMode(FaaMode.AUTOMATIC);
     sen.setPosition(
         new Position(
             (double) model.get(vessels_dot_self_dot + nav_position_latitude),
             (double) model.get(vessels_dot_self_dot + nav_position_longitude)));
     if (model.getValue(vessels_dot_self_dot + nav_speedOverGround) != null) {
       sen.setSpeed(
           (double) model.getValue(vessels_dot_self_dot + nav_speedOverGround) * MS_TO_KNOTS);
     }
     if (model.get(vessels_dot_self_dot + nav_courseOverGroundTrue) != null) {
       sen.setCourse(
           Math.toDegrees(
               (double) model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue)));
     }
     if (model.get(vessels_dot_self_dot + nav_magneticVariation) != null) {
       Double variation = (Double) model.getValue(vessels_dot_self_dot + nav_magneticVariation);
       if (variation != null) {
         sen.setVariation(Math.toDegrees(Math.abs(variation)));
         sen.setDirectionOfVariation((variation < 0) ? CompassPoint.WEST : CompassPoint.EAST);
       }
     }
     return sen.toSentence();
   }
   return null;
 }
Пример #3
0
  @Test
  public void testSendingUpdate() throws Exception {
    // fill the model with data
    SignalKModel model = SignalKModelFactory.getMotuTestInstance();

    // model = Util.populateModel(model, new
    // File("src/test/resources/samples/basicModel.txt"));

    // create STOMP connection
    StompConnection connection = new StompConnection();
    connection.open("localhost", 61613);
    logger.debug("Opened STOMP socket, connecting.. ");
    StompFrame connect = connection.connect("system", "manager");
    // StompFrame connect = connection.receive();
    if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) {
      throw new Exception("Not connected");
    }
    logger.debug("connected" + connect.getHeaders());

    HashMap<String, String> headers = new HashMap<String, String>();

    // headers.put(WebsocketConstants.CONNECTION_KEY, uuid);
    connection.send(
        "/queue/signalk.put",
        FileUtils.readFileToString(
            new File("src/test/resources/samples/windAngleUpdate.json.txt")));
    latch.await(2, TimeUnit.SECONDS);
    assertEquals(338.0, model.getValue(vessels_dot_self_dot + env_wind_angleApparent));
    assertEquals(6.8986404, model.getValue(vessels_dot_self_dot + env_wind_speedApparent));
    // disconnect
    connection.disconnect();
  }
  // @Override
  public void handle(SignalKModel node) throws IOException {
    if (node.getFullData().size() == 0) return;
    if (logger.isDebugEnabled()) logger.debug("SignalkModelProcessor  updating " + node);

    signalkModel.putAll(node.getFullData());
    if (node.getSubMap(SignalKConstants.CONFIG) != null) {
      SignalKModelFactory.saveConfig(signalkModel);
    }
    if (logger.isDebugEnabled()) logger.debug(signalkModel);
  }
  public String createHDT(SignalKModel model) {
    if (model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue) != null) {
      HDTSentence sen = (HDTSentence) sf.createParser(TalkerId.II, SentenceId.HDT);
      sen.setHeading(
          Math.toDegrees((double) model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue)));

      return sen.toSentence();
    }
    return null;
  }
Пример #6
0
  @Test
  public void testSubscribe() throws Exception {
    // fill the model with data
    SignalKModel model = SignalKModelFactory.getMotuTestInstance();
    model.putAll(TestHelper.getBasicModel().getFullData());

    // create STOMP connection
    StompConnection connection = new StompConnection();
    connection.open("localhost", 61613);
    logger.debug("Opened STOMP socket, connecting.. ");
    StompFrame connect = connection.connect("system", "manager");
    // StompFrame connect = connection.receive();
    if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) {
      throw new Exception("Not connected");
    }
    logger.debug("connected" + connect.getHeaders());

    // create a private receive queue
    String uuid = UUID.randomUUID().toString();
    connection.subscribe(
        "/queue/signalk." + uuid + ".vessels.motu.navigation", Subscribe.AckModeValues.AUTO);

    // subscribe
    Json subMsg =
        getSubscribe(
            "vessels." + SignalKConstants.self, "navigation", 1000, 0, FORMAT_DELTA, POLICY_FIXED);
    subMsg.set(
        nz.co.fortytwo.signalk.util.ConfigConstants.OUTPUT_TYPE,
        nz.co.fortytwo.signalk.util.ConfigConstants.OUTPUT_STOMP);
    subMsg.set(WebsocketConstants.CONNECTION_KEY, uuid);
    HashMap<String, String> headers = new HashMap<String, String>();

    // queue>signalk.3202a939-1681-4a74-ad4b-3a90212e4f33.vessels.motu.navigation
    // set private queue to receive data
    headers.put("reply-to", "/queue/signalk." + uuid + ".vessels.motu.navigation");
    headers.put(WebsocketConstants.CONNECTION_KEY, uuid);
    connection.send("/queue/signalk.put", subMsg.toString(), null, headers);

    // listen for messages
    StompFrame message = connection.receive();
    logger.debug("Body: " + message.getBody());
    assertNotNull(message);
    Json reply = Json.read(message.getBody());

    assertNotNull(reply.at(SignalKConstants.CONTEXT));
    assertNotNull(reply.at(SignalKConstants.UPDATES));
    // unsubscribe
    subMsg =
        getSubscribe(
            "vessels." + SignalKConstants.self, "navigation", 1000, 0, FORMAT_DELTA, POLICY_FIXED);
    connection.send("/queue/signalk.subscribe", subMsg.toString(), null, headers);
    connection.unsubscribe("/queue/signalk." + uuid + ".vessels.motu.navigation");
    // disconnect
    connection.disconnect();
  }
 // depth below Transducer
 public String createDBT(SignalKModel model) {
   if (model.getValue(vessels_dot_self_dot + env_depth_belowTransducer) != null) {
     DBTSentence sen = (DBTSentence) sf.createParser(TalkerId.II, SentenceId.DBT);
     sen.setDepth((double) model.getValue(vessels_dot_self_dot + env_depth_belowTransducer));
     sen.setFeet(
         (double) model.getValue(vessels_dot_self_dot + env_depth_belowTransducer) * MTR_TO_FEET);
     sen.setFathoms(
         (double) model.getValue(vessels_dot_self_dot + env_depth_belowTransducer)
             * MTR_TO_FATHOM);
     return sen.toSentence();
   }
   return null;
 }
 public String createHDG(SignalKModel model) {
   if (model.getValue(vessels_dot_self_dot + nav_courseOverGroundMagnetic) != null) {
     HDGSentence sen = (HDGSentence) sf.createParser(TalkerId.II, SentenceId.HDG);
     sen.setHeading(
         Math.toDegrees(
             (double) model.getValue(vessels_dot_self_dot + nav_courseOverGroundMagnetic)));
     if (model.getValue(vessels_dot_self_dot + nav_magneticVariation) != null)
       sen.setVariation(
           Math.toDegrees((double) model.getValue(vessels_dot_self_dot + nav_magneticVariation)));
     return sen.toSentence();
   }
   return null;
 }
 public String createGLL(SignalKModel model) {
   if (model.get(vessels_dot_self_dot + nav_position_latitude) != null
       && model.get(vessels_dot_self_dot + nav_position_longitude) != null) {
     GLLSentence sen = (GLLSentence) sf.createParser(TalkerId.GP, SentenceId.GLL);
     sen.setTime(new Time());
     sen.setStatus(DataStatus.ACTIVE);
     sen.setPosition(
         new Position(
             (double) model.get(vessels_dot_self_dot + nav_position_latitude),
             (double) model.get(vessels_dot_self_dot + nav_position_longitude)));
     return sen.toSentence();
   }
   return null;
 }
Пример #10
0
  @Test
  public void testSendingGetFull() throws Exception {
    // fill the model with data
    SignalKModel model = SignalKModelFactory.getMotuTestInstance();
    model.putAll(TestHelper.getBasicModel().getFullData());

    // create STOMP connection
    StompConnection connection = new StompConnection();
    connection.open("localhost", 61613);
    logger.debug("Opened STOMP socket, connecting.. ");
    StompFrame connect = connection.connect("system", "manager");
    // StompFrame connect = connection.receive();
    if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) {
      throw new Exception("Not connected");
    }
    logger.debug("connected" + connect.getHeaders());

    // create a private receive queue
    String uuid = UUID.randomUUID().toString();
    connection.subscribe(
        "/queue/signalk." + uuid + "." + vessels_dot_self_dot + env_wind,
        Subscribe.AckModeValues.AUTO);
    latch.await(2, TimeUnit.SECONDS);
    // send list
    Json subMsg =
        getGet("vessels." + SignalKConstants.self, env_wind + ".*", SignalKConstants.FORMAT_FULL);
    HashMap<String, String> headers = new HashMap<String, String>();
    logger.debug("sending" + subMsg);
    // queue>signalk.3202a939-1681-4a74-ad4b-3a90212e4f33.vessels.motu.navigation
    // set private queue to receive data
    headers.put("reply-to", "/queue/signalk." + uuid + dot + vessels_dot_self_dot + env_wind);
    headers.put(WebsocketConstants.CONNECTION_KEY, uuid);
    connection.send("/queue/signalk.put", subMsg.toString(), null, headers);

    // listen for messages
    StompFrame message = connection.receive();
    logger.debug("Body: " + message.getBody());
    assertNotNull(message);
    Json reply = Json.read(message.getBody());

    assertNotNull(reply.at(SignalKConstants.vessels));
    assertNotNull(reply.at(SignalKConstants.vessels).at(SignalKConstants.self).at(env).at("wind"));
    // unsubscribe
    connection.unsubscribe("/queue/signalk." + uuid + "." + vessels_dot_self_dot + env_wind);
    // disconnect
    connection.disconnect();
  }
  public void process(Exchange exchange) throws Exception {

    if (exchange.getIn().getBody() == null) return;
    if (logger.isDebugEnabled())
      logger.debug("Processing, class=" + exchange.getIn().getBody().getClass());
    // TODO: add more filters here
    if (exchange.getIn().getBody() instanceof Json) {
      Json json = (Json) exchange.getIn().getBody();
      // remove _arduino
      try {
        json.at(SignalKConstants.vessels).at(SignalKConstants.self).delAt("_arduino");
      } catch (NullPointerException npe) {
      }
      // remove _config
      try {
        json.at(SignalKConstants.vessels).at(SignalKConstants.self).delAt("_config");
      } catch (NullPointerException npe) {
      }

      exchange.getIn().setBody(json.toString());
    }
    if (exchange.getIn().getBody() instanceof SignalKModel) {
      SignalKModel model = (SignalKModel) exchange.getIn().getBody();
      // remove _arduino
      try {
        model.put(SignalKConstants.vessels_dot_self_dot + "_arduino", null);
      } catch (NullPointerException npe) {
      }
      // remove _config
      try {
        model.put(SignalKConstants.vessels_dot_self_dot + "_config", null);
      } catch (NullPointerException npe) {
      }

      exchange.getIn().setBody(ser.write(model));
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Outputting:" + exchange.getIn().getHeaders());
      logger.debug("Outputting:" + exchange.getIn());
    }
  }
 // Heading HDG, HDM, HDT, VHW
 public String createVHW(SignalKModel model) {
   if (model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue) != null
       || model.getValue(vessels_dot_self_dot + nav_speedOverGround) != null
       || model.getValue(vessels_dot_self_dot + nav_courseOverGroundMagnetic) != null) {
     VHWSentence sen = (VHWSentence) sf.createParser(TalkerId.II, SentenceId.VHW);
     if (model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue) != null)
       sen.setHeading(
           Math.toDegrees(
               (double) model.getValue(vessels_dot_self_dot + nav_courseOverGroundTrue)));
     if (model.getValue(vessels_dot_self_dot + nav_courseOverGroundMagnetic) != null)
       sen.setMagneticHeading(
           Math.toDegrees((double) model.getValue(vessels_dot_self_dot + nav_speedOverGround)));
     if (model.getValue(vessels_dot_self_dot + nav_speedOverGround) != null)
       sen.setSpeedKnots(
           (double) model.getValue(vessels_dot_self_dot + nav_speedOverGround) * MS_TO_KNOTS);
     return sen.toSentence();
   }
   return null;
 }
 // MWV - Wind Speed and Angle
 public String createMWVApparent(SignalKModel model) {
   if (model.getValue(vessels_dot_self_dot + env_wind_angleApparent) != null
       || model.getValue(vessels_dot_self_dot + env_wind_speedApparent) != null) {
     MWVSentence sen = (MWVSentence) sf.createParser(TalkerId.II, SentenceId.MWV);
     sen.setStatus(DataStatus.ACTIVE);
     if (model.getValue(vessels_dot_self_dot + env_wind_angleApparent) != null)
       sen.setAngle(
           Math.toDegrees((double) model.getValue(vessels_dot_self_dot + env_wind_angleApparent)));
     sen.setTrue(false);
     if (model.getValue(vessels_dot_self_dot + env_wind_speedApparent) != null)
       sen.setSpeed(
           (double) model.getValue(vessels_dot_self_dot + env_wind_speedApparent) * MS_TO_KNOTS);
     sen.setSpeedUnit(Units.KNOT);
     return sen.toSentence();
   }
   return null;
 }
 public String createMWVTrue(SignalKModel model) {
   if (model.getValue(vessels_dot_self_dot + env_wind_directionTrue) != null
       || model.getValue(vessels_dot_self_dot + env_wind_speedTrue) != null) {
     MWVSentence sen = (MWVSentence) sf.createParser(TalkerId.II, SentenceId.MWV);
     sen.setStatus(DataStatus.ACTIVE);
     if (model.getValue(vessels_dot_self_dot + env_wind_directionTrue) != null)
       sen.setAngle(
           Math.toDegrees((double) model.getValue(vessels_dot_self_dot + env_wind_directionTrue)));
     sen.setTrue(true);
     if (model.getValue(vessels_dot_self_dot + env_wind_speedTrue) != null) {
       double speed =
           (double) model.getValue(vessels_dot_self_dot + env_wind_speedTrue) * MS_TO_KNOTS;
       if (speed < 0.0) speed = 0.0;
       sen.setSpeed(
           (double) model.getValue(vessels_dot_self_dot + env_wind_speedTrue) * MS_TO_KNOTS);
     }
     sen.setSpeedUnit(Units.KNOT);
     return sen.toSentence();
   }
   return null;
 }