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;
 }
Ejemplo n.º 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();
  }
  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;
  }
 // 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;
 }
 // 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;
 }