implemented (but didn't test) remaining SwissTiming functions / parsers

This commit is contained in:
Axel Uhl committed 2011-09-30 17:13:55 +02:00
1 parent 7ecaa99e75
commit f93a4e1729
3 files changed
+86 -33

No files matched your search

@@ -72,7 +72,11 @@ public class SailMasterDummy implements Runnable {
transceiver.sendMessage("StartList|"+sections[1]+"|GER 8340,GER,Stanjek/Kleen|GER 8433,GER,Babendererde/Jacobs|GER 8299,GER,Elsner/Schulz", os);
}
} else if ("RaceTime".equals(sections[0])) {
if (sections[1].equals("4711")) {
transceiver.sendMessage("RaceTime|"+sections[1]+"|72498724937", os);
} else if (sections[1].equals("4712")) {
transceiver.sendMessage("RaceTime|"+sections[1]+"|61283761239", os);
}
} else if ("ClockAtMark".equals(sections[0])) {
} else if ("DistToMark".equals(sections[0])) {
@@ -21,10 +21,10 @@ public interface SailMasterConnector {
/**
* @param markIndex
* use -1 to obtain timings for all marks
* @return a map with the single mark requested by <code>markIndex</code> or all marks (in case of
* @return a map with the single mark index requested by <code>markIndex</code> or all mark indices (in case of
* <code>markIndex==-1</code>) as key; pairs of gap (TODO in milliseconds?) and boat ID as values.
*/
Map<Mark, Pair<Long, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException;
Map<Integer, Pair<Long, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException;
double getDistanceToMarkInMeters(String raceID, int markIndex, String boatID) throws UnknownHostException, IOException;
@@ -6,10 +6,12 @@ import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.swisstimingadapter.Competitor;
import com.sap.sailing.domain.swisstimingadapter.Course;
import com.sap.sailing.domain.swisstimingadapter.Mark;
@@ -47,7 +49,7 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
public Iterable<Race> getRaces() throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("RaceId");
String[] sections = response.getSections();
assertResponseType("RaceId", sections);
assertResponseType("RaceId", sections[0]);
List<Race> result = new ArrayList<Race>();
for (int i=1; i<sections.length; i++) {
String[] idAndDescription = sections[i].split(",");
@@ -60,8 +62,8 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
public Course getCourse(String raceID) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("CourseConfig|"+raceID);
String[] sections = response.getSections();
assertResponseType("CourseConfig", sections);
assertRaceID(raceID, sections);
assertResponseType("CourseConfig", sections[0]);
assertRaceID(raceID, sections[1]);
List<Mark> marks = new ArrayList<Mark>();
for (int i=2; i<sections.length; i++) {
String[] markDetails = sections[i].split(",");
@@ -70,16 +72,33 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
return new CourseImpl(raceID, marks);
}
private void assertRaceID(String raceID, String[] sections) {
if (!sections[1].equals(raceID)) {
throw new RuntimeException("Expected a "+sections[0]+" response for race ID "+raceID+
" but received one for "+sections[1]);
private void assertRaceID(String raceID, String section) {
if (!section.equals(raceID)) {
throw new RuntimeException("Expected race ID "+raceID+" but received "+section);
}
}
private void assertResponseType(String responseType, String[] sections) {
if (!sections[0].equals(responseType)) {
throw new RuntimeException("Expected a "+responseType+" response for a "+responseType+" request but got "+sections[0]);
private void assertMarkIndex(int markIndex, String section) {
if (Integer.valueOf(section).intValue() != markIndex) {
throw new RuntimeException("Expected marker index " + markIndex + " in response but received " + section);
}
}
private void assertBoatID(String boatID, String section) {
if (!section.equals(boatID)) {
throw new RuntimeException("Expected boat ID " + boatID + " in response but received " + section);
}
}
private void assertResponseType(String responseType, String section) {
if (!section.equals(responseType)) {
throw new RuntimeException("Expected a "+responseType+" response for a "+responseType+" request but got "+section);
}
}
private void assertLeg(String leg, String section) {
if (!section.equals(leg)) {
throw new RuntimeException("Expected leg " + leg + " in response but received " + section);
}
}
@@ -87,8 +106,8 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
public StartList getStartList(String raceID) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("StartList|"+raceID);
String[] sections = response.getSections();
assertResponseType("StartList", sections);
assertRaceID(raceID, sections);
assertResponseType("StartList", sections[0]);
assertRaceID(raceID, sections[1]);
ArrayList<Competitor> competitors = new ArrayList<Competitor>();
for (int i=2; i<sections.length; i++) {
String[] competitorDetails = sections[i].split(",");
@@ -98,38 +117,68 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
}
@Override
public TimePoint getStartTime(String raceID) {
// TODO Auto-generated method stub
return null;
public TimePoint getStartTime(String raceID) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("RaceTime|"+raceID);
String[] sections = response.getSections();
assertResponseType("RaceTime", sections[0]);
assertRaceID(raceID, sections[1]);
return new MillisecondsTimePoint(Long.valueOf(sections[2]));
}
@Override
public Map<Mark, Pair<Long, String>> getDeltaClockAtMark(String raceID, int markIndex) {
// TODO Auto-generated method stub
return null;
public Map<Integer, Pair<Long, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("ClockAtMark|"+raceID+"|"+markIndex);
String[] sections = response.getSections();
assertResponseType("ClockAtMark", sections[0]);
assertRaceID(raceID, sections[1]);
Map<Integer, Pair<Long, String>> result = new HashMap<Integer, Pair<Long,String>>();
for (int i=2; i<sections.length; i+=2) {
String[] markTimeDetail = sections[i+1].split(",");
result.put(Integer.valueOf(sections[i]), new Pair<Long, String>(Long.valueOf(markTimeDetail[0]), markTimeDetail[1]));
}
return result;
}
@Override
public double getDistanceToMarkInMeters(String raceID, int markIndex, String boatID) {
// TODO Auto-generated method stub
return 0;
public double getDistanceToMarkInMeters(String raceID, int markIndex, String boatID) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("DistToMark|"+raceID+"|"+markIndex+"|"+boatID);
String[] sections = response.getSections();
assertResponseType("DistToMark", sections[0]);
assertRaceID(raceID, sections[1]);
assertMarkIndex(markIndex, sections[2]);
assertBoatID(boatID, sections[3]);
return Double.valueOf(sections[4]);
}
@Override
public double getCurrentBoatSpeedInMetersPerSecond(String raceID, String boatID) {
// TODO Auto-generated method stub
return 0;
public double getCurrentBoatSpeedInMetersPerSecond(String raceID, String boatID) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("CurrentBoatSpeed|"+raceID+"|"+boatID);
String[] sections = response.getSections();
assertResponseType("CurrentBoatSpeed", sections[0]);
assertRaceID(raceID, sections[1]);
assertBoatID(boatID, sections[2]);
return Double.valueOf(sections[3]);
}
@Override
public double getAverageBoatSpeedInMetersPerSecond(String raceID, String leg, String boatID) {
// TODO Auto-generated method stub
return 0;
public double getAverageBoatSpeedInMetersPerSecond(String raceID, String leg, String boatID) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("AverageBoatSpeed|"+raceID+"|"+leg+"|"+boatID);
String[] sections = response.getSections();
assertResponseType("AverageBoatSpeed", sections[0]);
assertRaceID(raceID, sections[1]);
assertLeg(leg, sections[2]);
assertBoatID(boatID, sections[3]);
return Double.valueOf(sections[4]);
}
@Override
public double getDistanceBetweenBoatsInMeters(String raceID, String boatID1, String boatID2) {
// TODO Auto-generated method stub
return 0;
public double getDistanceBetweenBoatsInMeters(String raceID, String boatID1, String boatID2) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("DistBetweenBoats|"+raceID+"|"+boatID1+"|"+boatID2);
String[] sections = response.getSections();
assertResponseType("DistBetweenBoats", sections[0]);
assertRaceID(raceID, sections[1]);
assertBoatID(boatID1, sections[2]);
assertBoatID(boatID2, sections[3]);
return Double.valueOf(sections[4]);
}
}