implementation of the FR 1895363 (NMEA simulator)

advertisement
CAPCODE - IMPLEMENTATION OF THE FR 1895363 (NMEA SIMULATOR)
CAPCODE
subject CapCode
Title :implementation of the FR 1895363 (NMEA simulator)
Author : c.rosay
Document ID : Document1
Version : A
modified on : 2/18/2016 2:13:00 AM
IMPLEMENTATION OF THE FR 1895363 (NMEA SIMULATOR)
1 history of changes ............................................................................................... 2
2 document description .......................................................................................... 2
3 Document retrieval .............................................................................................. 2
Page 1 / 5
CAPCODE - IMPLEMENTATION OF THE FR 1895363 (NMEA SIMULATOR)
1 HISTORY OF CHANGES
date
version
subject
author
2 DOCUMENT DESCRIPTION
This document is the resolution documentation for the FR 1895363 (NMEA simulator
improvement: saving user’s data).
3 DOCUMENT RETRIEVAL
The last version of this document is available in html format in the documentation
section, subsection low level requirements.
4 DESCRIPTION OF THE FEATURE REQUEST
The modifications done are not saved.
Every time the simulator is launched, the default value (hard coded) are
set.
Implement a way to save the user's data and reload them at next start of
the NMEA simulator.
The data to be saved are:
- the relative wind direction and force
- the boat speed and bearing
- the boat position (WGS 63)
5 IMPLEMENTATION OF THE SOLUTION
2 solutions are possible:
1. to save the data in the capcode configuration file
2. to save the data is a specific simulator xml file (location to be defined)
in both cases each time the button Post Change is pressed, the all fields a sent to the
NMEA bus. This is done in the procedure postChanges() in the
SimulatorWindow.java of the package capcode.simulation.
Create a private procedure called saveChangesToPreferences() in the
SimulatorWindow.java of the package capcode.simulation.
Solution 2:
1) Reference a XMLParser from package capcode.xml (project capcode.basics).
2) Create a simulator.xml in configuration folder
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<preferences EXTERNAL_XML_VERSION="1.0">
<boat bearing="290" latitude="N43°24'56.878"
longitude="E003°37'12.150" speed="4"/>
<wind direction="330" force="14.5"/>
</preferences>
3) in SimulatorWindow.java create a saveChangestoPreferences() procedure
4) in postChange() call saveChangesToPreferences()
5) in initWindow(String title), implement the code that read the preference.
Page 2 / 5
CAPCODE - IMPLEMENTATION OF THE FR 1895363 (NMEA SIMULATOR)
6 CODING
Mylyn view of the changes performed on the code for this modification
XMLParser was also modified to change the coding of the XML file from ISO-8859-1
to UTF-8 to take into account the special char “°” (deg) for longitude and latitude.
This will create a side effect with the reading of ccmap, using the same XMLParser.
TODO: to check if the ccmap file are still readable.
List of changes:
7 VERIFICATION
Junit test case FR1895363 were created.
Result ok.
Coverage:
/**
* init the window
* @param title : title of the window
* modified to implement @tag FR_1895363
* (reading of the preferences)
*/
private void initWindow(String title){
simToolBox.setUpdator(this);
Page 3 / 5
CAPCODE - IMPLEMENTATION OF THE FR 1895363 (NMEA SIMULATOR)
getJFrame().setTitle(title);
XMLParser pref = new XMLParser();
try {
//@tag FR_1895363
//load the preferences
pref.load("configuration/simulator.xml");
//save the values
getJTextFieldWindForce().setText(pref.getElement("//wind").getAttribu
te("force"));
getJTextFieldWindDirection().setText(pref.getElement("//wind").getAtt
ribute("direction"));
getJTextFieldBoatSpeed().setText(pref.getElement("//boat").getAttribu
te("speed"));
getJTextFieldBoatBearing().setText(pref.getElement("//boat").getAttri
bute("bearing"));
getJTextFieldLongitude().setText(pref.getElement("//boat").getAttribu
te("longitude"));
getJTextFieldLatitude().setText(pref.getElement("//boat").getAttribut
e("latitude"));
pref.save();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setVisible(true);
}
/**
* post the changes to the simToolBox.
*
*/
public void postChanges() {
try {
simToolBox.boat.getAngle().setValue(
Double.parseDouble(jTextFieldBoatBearing.getText()));
simToolBox.boat.getSpeed().setValue(
Double.parseDouble(jTextFieldBoatSpeed.getText()));
simToolBox.boatOnGround.getAngle().setValue(
Double.parseDouble(jTextFieldBoatBearing.getText()));
simToolBox.boatOnGround.getSpeed().setValue(
Double.parseDouble(jTextFieldBoatSpeed.getText()));
simToolBox.magneticWindHeading.getAngle().setValue(
Double.parseDouble(jTextFieldWindDirection.getText()));
simToolBox.magneticWindHeading.getSpeed().setValue(
Page 4 / 5
CAPCODE - IMPLEMENTATION OF THE FR 1895363 (NMEA SIMULATOR)
Double.parseDouble(jTextFieldWindForce.getText()));
double trueWindBearing =
simToolBox.magneticWindHeading.getAngle()
.getValue()
- simToolBox.boat.getAngle().getValue();
simToolBox.trueWind.forceToDirectionAndSpeed(trueWindBearing,
simToolBox.magneticWindHeading.getSpeed().getValue());
simToolBox.trueWind.reverseComputation();
simToolBox.longitude.setAsString(jTextFieldLongitude.getText());
simToolBox.latitude.setAsString(jTextFieldLatitude.getText());
//save the preference every time a change is posted
//@tag FR_1895363
saveChangesToPreferences();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* save the changes to a preference file (xml)
* implementation of the @tag FR_1895363
*/
private void saveChangesToPreferences() {
//reference a XMLParser
XMLParser pref = new XMLParser();
try {
//load the preferences
pref.load("configuration/simulator.xml");
//save the values
pref.setAttribute(pref.getElement("//wind"),
getJTextFieldWindForce().getText());
pref.setAttribute(pref.getElement("//wind"),
getJTextFieldWindDirection().getText());
pref.setAttribute(pref.getElement("//boat"),
getJTextFieldBoatSpeed().getText());
pref.setAttribute(pref.getElement("//boat"),
getJTextFieldBoatBearing().getText());
pref.setAttribute(pref.getElement("//boat"),
getJTextFieldLongitude().getText());
pref.setAttribute(pref.getElement("//boat"),
getJTextFieldLatitude().getText());
pref.save();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
"force",
"direction",
"speed",
"bearing",
"longitude",
"latitude",
}
The exception cases were not covered.
Test case has to be upgrated to see how the software react in case of a bad or
missing simulator.xml file.
Page 5 / 5
Download