/dongfang_FC_rewrite_tool/src/dongfang/mkt/RequestFrameVisitor.java |
---|
13,13 → 13,15 |
import dongfang.mkt.frames.MotorTestRequestFrame; |
import dongfang.mkt.frames.OSDDataRequestFrame; |
import dongfang.mkt.frames.ReadExternalControlRequestFrame; |
import dongfang.mkt.frames.ReadIMUConfigurationRequestFrame; |
import dongfang.mkt.frames.ReadParamSetRequestFrame; |
import dongfang.mkt.frames.ResetRequestFrame; |
import dongfang.mkt.frames.SetCompassHeadingRequestFrame; |
import dongfang.mkt.frames.SingleDisplayRequestFrame; |
import dongfang.mkt.frames.UniversalReadParamSetRequestFrame; |
import dongfang.mkt.frames.UniversalWriteParamSetRequestFrame; |
import dongfang.mkt.frames.VariablesRequestFrame; |
import dongfang.mkt.frames.VersionRequestFrame; |
import dongfang.mkt.frames.WriteIMUConfigurationRequestFrame; |
import dongfang.mkt.frames.WriteParamSetRequestFrame; |
public interface RequestFrameVisitor { |
// void visit(RequestFrame f) throws IOException; |
35,10 → 37,12 |
void visit(ExternalControlRequestFrame f) throws IOException; |
void visit(ResetRequestFrame f) throws IOException; |
void visit(ChangeParameterSetRequestFrame f) throws IOException; |
void visit(UniversalReadParamSetRequestFrame f) throws IOException; |
void visit(UniversalWriteParamSetRequestFrame f) throws IOException; |
void visit(ReadParamSetRequestFrame f) throws IOException; |
void visit(WriteParamSetRequestFrame f) throws IOException; |
void visit(SetCompassHeadingRequestFrame f) throws IOException; |
void visit(ReadExternalControlRequestFrame f) throws IOException; |
void visit(OSDDataRequestFrame f) throws IOException; |
void visit(CompassHeadingRequestFrame f) throws IOException; |
void visit(ReadIMUConfigurationRequestFrame f) throws IOException; |
void visit(WriteIMUConfigurationRequestFrame f) throws IOException; |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/comm/MKInputStream.java |
---|
16,10 → 16,12 |
import dongfang.mkt.frames.MotorTestResponseFrame; |
import dongfang.mkt.frames.OSDDataResponseFrame; |
import dongfang.mkt.frames.ReadExternalControlResponseFrame; |
import dongfang.mkt.frames.ReadIMUConfigurationResponseFrame; |
import dongfang.mkt.frames.ResponseFrame; |
import dongfang.mkt.frames.SetCompassHeadingResponseFrame; |
import dongfang.mkt.frames.UniversalReadParamSetResponseFrame; |
import dongfang.mkt.frames.UniversalWriteParamSetResponseFrame; |
import dongfang.mkt.frames.ReadParamSetResponseFrame; |
import dongfang.mkt.frames.WriteIMUConfigurationResponseFrame; |
import dongfang.mkt.frames.WriteParamSetResponseFrame; |
import dongfang.mkt.frames.VariablesResponseFrame; |
import dongfang.mkt.frames.VersionResponseFrame; |
225,6 → 227,21 |
result = f; |
break; |
} |
case 'I': { |
ReadIMUConfigurationResponseFrame f = new ReadIMUConfigurationResponseFrame(address); |
f.setConfigurationVersion(base64InputStream.readByte()); |
int length = base64InputStream.readByte(); |
f.setConfigurationSetLength(length); |
f.setData(base64InputStream.readBytes(length)); |
result = f; |
break; |
} |
case 'J': { |
WriteIMUConfigurationResponseFrame f = new WriteIMUConfigurationResponseFrame(address); |
f.setWasAccepted(base64InputStream.readByte()==1); |
result = f; |
break; |
} |
case 'k' : { |
CompassHeadingResponseFrame f = new CompassHeadingResponseFrame(address); |
base64InputStream.readSignedWords(2); |
314,7 → 331,7 |
break; |
} |
case 'S': { |
UniversalWriteParamSetResponseFrame f = new UniversalWriteParamSetResponseFrame(address); |
WriteParamSetResponseFrame f = new WriteParamSetResponseFrame(address); |
f.setParameterSetNumber(base64InputStream.readByte()); |
result = f; |
break; |
370,7 → 387,7 |
break; |
} |
case 'Q': |
UniversalReadParamSetResponseFrame f = new UniversalReadParamSetResponseFrame(address); |
ReadParamSetResponseFrame f = new ReadParamSetResponseFrame(address); |
f.setConfigurationSetNumber(base64InputStream.readByte()); |
f.setConfigurationVersion(base64InputStream.readByte()); |
int length = base64InputStream.readByte(); |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/comm/MKOutputStream.java |
---|
15,14 → 15,16 |
import dongfang.mkt.frames.MotorTestRequestFrame; |
import dongfang.mkt.frames.OSDDataRequestFrame; |
import dongfang.mkt.frames.ReadExternalControlRequestFrame; |
import dongfang.mkt.frames.ReadIMUConfigurationRequestFrame; |
import dongfang.mkt.frames.ReadParamSetRequestFrame; |
import dongfang.mkt.frames.RequestFrame; |
import dongfang.mkt.frames.ResetRequestFrame; |
import dongfang.mkt.frames.SetCompassHeadingRequestFrame; |
import dongfang.mkt.frames.SingleDisplayRequestFrame; |
import dongfang.mkt.frames.UniversalReadParamSetRequestFrame; |
import dongfang.mkt.frames.UniversalWriteParamSetRequestFrame; |
import dongfang.mkt.frames.VariablesRequestFrame; |
import dongfang.mkt.frames.VersionRequestFrame; |
import dongfang.mkt.frames.WriteIMUConfigurationRequestFrame; |
import dongfang.mkt.frames.WriteParamSetRequestFrame; |
public class MKOutputStream extends OutputStream implements RequestFrameVisitor { |
public class MKDataOutputStream { |
191,12 → 193,12 |
base64OutputStream.writeChars(f.getChararray()); |
} |
public void visit(UniversalReadParamSetRequestFrame f) throws IOException { |
public void visit(ReadParamSetRequestFrame f) throws IOException { |
writeByte('q'); |
base64OutputStream.writeByte(f.getConfigurationSetNumber()); |
} |
public void visit(UniversalWriteParamSetRequestFrame f) throws IOException { |
public void visit(WriteParamSetRequestFrame f) throws IOException { |
writeByte('s'); |
base64OutputStream.writeByte(f.getConfigurationSetNumber()); |
base64OutputStream.writeByte(f.getConfigurationVersionNumber()); |
217,4 → 219,15 |
writeByte('o'); |
base64OutputStream.writeByte(f.getAutoSendInterval()); |
} |
public void visit(ReadIMUConfigurationRequestFrame f) throws IOException { |
writeByte('i'); |
} |
public void visit(WriteIMUConfigurationRequestFrame f) throws IOException { |
writeByte('j'); |
base64OutputStream.writeByte(f.getConfigurationVersionNumber()); |
base64OutputStream.writeByte(f.getDataLength()); |
base64OutputStream.writeBytes(f.getData()); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/ConfigSet.java |
---|
File deleted |
\ No newline at end of file |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/ArrayEntry.java |
---|
0,0 → 1,46 |
package dongfang.mkt.configuration; |
public class ArrayEntry extends ParameterEntry { |
int length; |
boolean isDynamic; |
int[] values; |
ArrayEntry(String name, boolean isDynamic, int length) { |
super(name); |
this.isDynamic = isDynamic; |
this.length = length; |
} |
int[] getValue() { |
return values; |
} |
int setValue(int[] data, int offset) { |
values = new int[length]; |
System.arraycopy(data, offset, values, 0, length); |
return length; |
} |
int getByteCount() { |
return length; |
} |
String toStringWithValues() { |
StringBuilder result = new StringBuilder(name + ":\t{"); |
for (int i = 0; i < length; i++) { |
if (i != 0) |
result.append(","); |
result.append(values[i]); |
} |
result.append("}"); |
return result.toString(); |
} |
void toXML(StringBuilder result) { |
result.append(" <list name=\"" + name + "\">\n"); |
for (int i = 0; i < length; i++) { |
result.append(" <entry value=\"" + values[i] + "\"/>\n"); |
} |
result.append(" </list>\n"); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/BitSetEntry.java |
---|
0,0 → 1,44 |
package dongfang.mkt.configuration; |
public class BitSetEntry extends ParameterEntry { |
BitSetEntry(String name, String[] bitNames) { |
super(name); |
this.bitNames = bitNames; |
} |
int value; |
String[] bitNames; |
int getByteCount() { |
return 1; |
} |
int getValue() { |
return value; |
} |
int setValue(int[] data, int offset) { |
value = data[offset]; |
return getByteCount(); |
} |
String toStringWithValues() { |
StringBuilder result = new StringBuilder(name + "\t["); |
for (int i = 0; i < Math.min(bitNames.length, 8); i++) { |
if (i != 0) |
result.append(", "); |
result.append(bitNames[i] + ":" |
+ ((value & (1 << i)) != 0 ? "1" : "0")); |
} |
return result.toString(); |
} |
void toXML(StringBuilder result) { |
result.append(" <parameter name=\"" + name + "\">\n"); |
for (int i = 0; i < Math.min(bitNames.length, 8); i++) { |
result.append(" <bit name=\"" + bitNames[i] + "\" value=\"" |
+ ((value & (1 << i)) != 0 ? "1" : "0") + "\"/>\n"); |
} |
result.append(" </parameter>\n"); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/ConfigurationSet.java |
---|
0,0 → 1,82 |
package dongfang.mkt.configuration; |
import java.io.IOException; |
import java.util.ArrayList; |
import java.util.List; |
public abstract class ConfigurationSet { |
public static final int NUMBER_OF_VARIABLES = 8; |
protected int eepromVersion; |
protected List<ParameterEntry> entries = new ArrayList<ParameterEntry>(); |
public ConfigurationSet() { |
super(); |
} |
public List<ParameterEntry> getEntries() { |
return entries; |
} |
protected abstract int correctLengthToExcludeName(int length); |
protected abstract void setName(int[] data, int offset); |
protected abstract void outputName(StringBuilder sb); |
public void setData(int[] data) throws IOException { |
int offset = 0; |
int dataLength = correctLengthToExcludeName(data.length); |
if (dataLength != getByteCount()) { |
throw new IOException("The received number of databytes (" + dataLength + ") was not equal to the length of the declared parameter set(" + getByteCount()+")."); |
} |
for (ParameterEntry entry : entries) { |
offset += entry.setValue(data, offset); |
} |
setName(data, offset); |
} |
public int getByteCount() { |
int result = 0; |
for (ParameterEntry e : entries) { |
result += e.getByteCount(); |
} |
return result; |
} |
public String toStringWithValues() { |
StringBuilder result = new StringBuilder(); |
outputName(result); |
for (ParameterEntry entry : entries) { |
result.append(entry.toStringWithValues() + "\n"); |
} |
return result.toString(); |
} |
public String generateDynamicSubstitutionCode() { |
StringBuilder result = new StringBuilder( |
"const MMXLATION XLATIONS[] = {\n"); |
boolean hasEntries = false; |
for (ParameterEntry entry : entries) { |
if (entry instanceof DynamicByteEntry) { |
if (hasEntries) |
result.append(",\n"); |
else |
hasEntries = true; |
DynamicByteEntry de = (DynamicByteEntry) entry; |
result.append("{offsetof(ParamSet_t, "); |
result.append(de.getStaticCodeName()); |
result.append("), offsetof(DynamicParams_t, "); |
result.append(de.getDynamicCodeName()); |
result.append("),"); |
result.append(Integer.toString(de.getMinValue())); |
result.append(","); |
result.append(Integer.toString(de.getMaxValue())); |
result.append("}"); |
} |
} |
result.append("};"); |
return result.toString(); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/DynamicByteEntry.java |
---|
0,0 → 1,55 |
package dongfang.mkt.configuration; |
public class DynamicByteEntry extends StaticByteEntry { |
int minValue = 0; |
int maxValue = 255; |
String staticCodeName; |
String dynamicCodeName; |
DynamicByteEntry(String name) { |
super(name); |
} |
int getMinValue() { |
return minValue; |
} |
int getMaxValue() { |
return maxValue; |
} |
void setMinValue(int minValue) { |
this.minValue = minValue; |
} |
void setMaxValue(int maxValue) { |
this.maxValue = maxValue; |
} |
String getStaticCodeName() { |
return staticCodeName; |
} |
String getDynamicCodeName() { |
return dynamicCodeName; |
} |
void setStaticCodeName(String staticCodeName) { |
this.staticCodeName = staticCodeName; |
} |
void setDynamicCodeName(String dynamicCodeName) { |
this.dynamicCodeName = dynamicCodeName; |
} |
void toXML(StringBuilder result) { |
String s_value; |
int numberOfLowestVariable = 256 - ParameterSet.NUMBER_OF_VARIABLES; |
if (value >= numberOfLowestVariable) { |
s_value = "var" + (value - numberOfLowestVariable); |
} else |
s_value = Integer.toString(value); |
result.append(" <parameter name=\"" + name + "\" value=\"" |
+ s_value + "\"/>\n"); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/IMUConfiguration.java |
---|
0,0 → 1,138 |
package dongfang.mkt.configuration; |
import java.io.File; |
import java.io.IOException; |
import javax.xml.parsers.DocumentBuilder; |
import javax.xml.parsers.DocumentBuilderFactory; |
import javax.xml.parsers.ParserConfigurationException; |
import javax.xml.xpath.XPath; |
import javax.xml.xpath.XPathConstants; |
import javax.xml.xpath.XPathExpressionException; |
import javax.xml.xpath.XPathFactory; |
import org.w3c.dom.Document; |
import org.w3c.dom.Element; |
import org.w3c.dom.NodeList; |
import org.xml.sax.SAXException; |
public class IMUConfiguration extends ConfigurationSet { |
protected int correctLengthToExcludeName(int length) { |
return length; |
} |
protected void setName(int[] data, int length) {} |
protected void outputName(StringBuilder sb) { |
} |
public String toXML() { |
StringBuilder result = new StringBuilder(); |
result.append("<imuconfiguration eepromVersion=\"" + eepromVersion |
+ "\" length=\"" + getByteCount() + "\">\n"); |
for (int i = 0; i < entries.size(); i++) { |
ParameterEntry entry = entries.get(i); |
entry.toXML(result); |
} |
result.append("</imuconfiguration>\n"); |
return result.toString(); |
} |
public IMUConfiguration(int eepromVersion) { |
super(); |
this.eepromVersion = eepromVersion; |
} |
// This parses only for the purpose of naming and typing parameter sets! |
// It does not parse the section and default information, which could be |
// useful for GUIs etc. |
public static IMUConfiguration parseXMLIMUConfiguration(int version) |
throws IOException { |
String fileName = "configsets/templates/imuconfiguration_v" + version |
+ ".xml"; |
File f = new File(fileName); |
DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance(); |
saxfac.setValidating(false); |
try { |
DocumentBuilder bldr = saxfac.newDocumentBuilder(); |
Document doc = bldr.parse(f); |
XPath xpath = XPathFactory.newInstance().newXPath(); |
String s_eepromVersion = xpath.evaluate( |
"/imuconfigurationtemplate/@eepromVersion", doc); |
int eepromVersion = Integer.parseInt(s_eepromVersion); |
String s_declaredLength = xpath.evaluate( |
"/imuconfigurationtemplate/@length", doc); |
int declaredLength = Integer.parseInt(s_declaredLength); |
if (eepromVersion != version) { |
throw new IOException( |
"Version mismatch between file name (" |
+ fileName |
+ ") and the version in the imuconfigurationtemplate/@eepromVersion attribute(" |
+ s_eepromVersion + ")"); |
} |
IMUConfiguration result = new IMUConfiguration(eepromVersion); |
NodeList parameterNodes = (NodeList) xpath.evaluate( |
"/imuconfigurationtemplate/parameter", doc, |
XPathConstants.NODESET); |
for (int j = 0; j < parameterNodes.getLength(); j++) { |
Element parameterNode = (Element) parameterNodes.item(j); |
ParameterEntry entry; |
String s_name = parameterNode.getAttribute("name"); |
String s_type; |
if (parameterNode.hasAttribute("type")) { |
s_type = parameterNode.getAttribute("type"); |
} else { |
s_type = "static"; |
} |
if ("static".equals(s_type)) { |
entry = new StaticByteEntry(s_name); |
} else if ("dynamic".equals(s_type)) { |
throw new IOException("Dynamic parameters are not supported in IMU config."); |
} else if ("bitset".equals(s_type)) { |
NodeList bitNodes = (NodeList) xpath.evaluate("bit", |
parameterNode, XPathConstants.NODESET); |
String[] bitNames = new String[8]; |
for (int k = 0; k < 8; k++) { |
Element bitNode = (Element) bitNodes.item(k); |
if (bitNode != null) { |
bitNames[k] = bitNode.getAttribute("name"); |
} else { |
bitNames[k] = "Unused"; |
} |
} |
entry = new BitSetEntry(s_name, bitNames); |
} else { |
throw new IOException("Unknown parameter type: " + s_type); |
} |
result.entries.add(entry); |
} |
//result.name = "" + version; |
if (result.getByteCount() != declaredLength) { |
throw new IOException("The number of parameters in the set (" |
+ result.getEntries().size() |
+ ") was not equal to the declared length (" |
+ declaredLength + ")."); |
} |
return result; |
} catch (IOException ex) { |
throw ex; |
} catch (XPathExpressionException ex) { |
throw new IOException(ex); |
} catch (SAXException ex) { |
throw new IOException(ex); |
} catch (ParserConfigurationException ex) { |
throw new IOException(ex); |
} |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/ParameterEntry.java |
---|
0,0 → 1,25 |
package dongfang.mkt.configuration; |
public abstract class ParameterEntry { |
String name; |
ParameterEntry(String name) { |
this.name = name; |
} |
abstract int getByteCount(); |
abstract String toStringWithValues(); |
abstract void toXML(StringBuilder result); |
abstract int setValue(int[] data, int offset); |
public String getName() { |
return name; |
} |
public String getSection() { |
return name; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/ParameterSection.java |
---|
0,0 → 1,31 |
package dongfang.mkt.configuration; |
import java.util.ArrayList; |
import java.util.List; |
public class ParameterSection { |
String name, title; |
List<ParameterEntry> entries = new ArrayList<ParameterEntry>(); |
public ParameterSection(String name, String title) { |
this.name = name; |
this.title = title; |
} |
public void addConfigEntry(ParameterEntry e) { |
this.entries.add(e); |
} |
public List<ParameterEntry> getEntries() { |
return entries; |
} |
public String getName() { |
return name; |
} |
public String getTitle() { |
return title; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/ParameterSet.java |
---|
0,0 → 1,195 |
package dongfang.mkt.configuration; |
import java.io.File; |
import java.io.IOException; |
import java.util.ArrayList; |
import java.util.List; |
import javax.xml.parsers.DocumentBuilder; |
import javax.xml.parsers.DocumentBuilderFactory; |
import javax.xml.parsers.ParserConfigurationException; |
import javax.xml.xpath.XPath; |
import javax.xml.xpath.XPathConstants; |
import javax.xml.xpath.XPathExpressionException; |
import javax.xml.xpath.XPathFactory; |
import org.w3c.dom.Document; |
import org.w3c.dom.Element; |
import org.w3c.dom.NodeList; |
import org.xml.sax.SAXException; |
public class ParameterSet extends ConfigurationSet { |
public static final int NUMBER_OF_VARIABLES = 8; |
List<ParameterSection> declaredSections = new ArrayList<ParameterSection>(); |
protected String name; |
protected int correctLengthToExcludeName(int length) { |
return length - 12; |
} |
protected void setName(int[] data) { |
StringBuilder sbname = new StringBuilder(); |
for (int i = 0; i < 12; i++) { |
if (data[offset] == 0) |
break; |
sbname.append((char) data[offset++]); |
} |
name = sbname.toString(); |
} |
protected void outputName(StringBuilder sb) { |
sb.append(name + "\n"); |
} |
public List<ParameterSection> getDeclaredSections() { |
return declaredSections; |
} |
public String toXML() { |
StringBuilder result = new StringBuilder(); |
result.append("<parameterset eepromVersion=\"" + eepromVersion |
+ "\" length=\"" + getByteCount() + "\">\n"); |
for (int i = 0; i < entries.size(); i++) { |
ParameterEntry entry = entries.get(i); |
entry.toXML(result); |
} |
result.append("</parameterset>\n"); |
return result.toString(); |
} |
public ParameterSet(int eepromVersion) { |
super(); |
this.eepromVersion = eepromVersion; |
} |
// This parses only for the purpose of naming and typing parameter sets! |
// It does not parse the section and default information, which could be |
// useful for GUIs etc. |
public static ParameterSet parseXMLParameterSet(int version) |
throws IOException { |
String fileName = "configsets/templates/parameterset_v" + version |
+ ".xml"; |
File f = new File(fileName); |
DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance(); |
saxfac.setValidating(false); |
try { |
DocumentBuilder bldr = saxfac.newDocumentBuilder(); |
Document doc = bldr.parse(f); |
XPath xpath = XPathFactory.newInstance().newXPath(); |
String s_eepromVersion = xpath.evaluate( |
"/parametertemplate/@eepromVersion", doc); |
int eepromVersion = Integer.parseInt(s_eepromVersion); |
String s_declaredLength = xpath.evaluate( |
"/parametertemplate/@length", doc); |
int declaredLength = Integer.parseInt(s_declaredLength); |
if (eepromVersion != version) { |
throw new IOException( |
"Version mismatch between file name (" |
+ fileName |
+ ") and the version in the parametertemplate/@eepromVersion attribute(" |
+ s_eepromVersion + ")"); |
} |
ParameterSet result = new ParameterSet(eepromVersion); |
NodeList sectionNodes = (NodeList) xpath.evaluate( |
"/parametertemplate/section", doc, XPathConstants.NODESET); |
for (int i = 0; i < sectionNodes.getLength(); i++) { |
Element sectionNode = (Element) sectionNodes.item(i); |
ParameterSection section = new ParameterSection( |
sectionNode.getAttribute("name"), |
sectionNode.getAttribute("title")); |
result.declaredSections.add(section); |
NodeList parameterNodes = (NodeList) xpath.evaluate( |
"parameter", sectionNode, XPathConstants.NODESET); |
for (int j = 0; j < parameterNodes.getLength(); j++) { |
Element parameterNode = (Element) parameterNodes.item(j); |
ParameterEntry entry; |
if (!sectionNode.hasAttribute("name")) { |
throw new IOException("A parameter element (the " + j |
+ "th in section " |
+ sectionNode.getAttribute("name") |
+ ") had no name attribute!"); |
} |
String s_name = parameterNode.getAttribute("name"); |
String s_type; |
if (parameterNode.hasAttribute("type")) { |
s_type = parameterNode.getAttribute("type"); |
} else { |
s_type = "static"; |
} |
if ("static".equals(s_type)) { |
entry = new StaticByteEntry(s_name); |
} else if ("dynamic".equals(s_type)) { |
DynamicByteEntry de = new DynamicByteEntry(s_name); |
if (parameterNode.hasAttribute("minValue")) { |
de.setMinValue(Integer.parseInt(parameterNode |
.getAttribute("minValue"))); |
} |
if (parameterNode.hasAttribute("maxValue")) { |
de.setMinValue(Integer.parseInt(parameterNode |
.getAttribute("maxValue"))); |
} |
if (parameterNode.hasAttribute("staticCodeName")) { |
de.setStaticCodeName(parameterNode |
.getAttribute("staticCodeName")); |
} else |
de.setStaticCodeName(de.getName()); |
if (parameterNode.hasAttribute("dynamicCodeName")) { |
de.setDynamicCodeName(parameterNode |
.getAttribute("dynamicCodeName")); |
} else |
de.setDynamicCodeName(de.getName()); |
entry = de; |
} else if ("bitset".equals(s_type)) { |
NodeList bitNodes = (NodeList) xpath.evaluate("bit", |
parameterNode, XPathConstants.NODESET); |
String[] bitNames = new String[8]; |
for (int k = 0; k < 8; k++) { |
Element bitNode = (Element) bitNodes.item(k); |
if (bitNode != null) { |
bitNames[k] = bitNode.getAttribute("name"); |
} else { |
bitNames[k] = "Unused"; |
} |
} |
entry = new BitSetEntry(s_name, bitNames); |
} else { |
throw new IOException("Unknown parameter type: " |
+ s_type); |
} |
result.entries.add(entry); |
section.addConfigEntry(entry); |
} |
} |
result.name = "" + version; |
if (result.getByteCount() != declaredLength) { |
throw new IOException("The number of parameters in the set (" |
+ result.getEntries().size() |
+ ") was not equal to the declared length (" |
+ declaredLength + ")."); |
} |
return result; |
} catch (IOException ex) { |
throw ex; |
} catch (XPathExpressionException ex) { |
throw new IOException(ex); |
} catch (SAXException ex) { |
throw new IOException(ex); |
} catch (ParserConfigurationException ex) { |
throw new IOException(ex); |
} |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/UniversalReadParamSetResponseFrame.java |
---|
File deleted |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/UniversalWriteParamSetResponseFrame.java |
---|
File deleted |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/UniversalReadParamSetRequestFrame.java |
---|
File deleted |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/UniversalWriteParamSetRequestFrame.java |
---|
File deleted |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/ReadIMUConfigurationRequestFrame.java |
---|
0,0 → 1,18 |
package dongfang.mkt.frames; |
import java.io.IOException; |
import dongfang.mkt.RequestFrameVisitor; |
public class ReadIMUConfigurationRequestFrame extends RequestFrame { |
public ReadIMUConfigurationRequestFrame() { |
super(FC_ADDRESS); |
} |
@Override |
public void accept(RequestFrameVisitor o) throws IOException { |
o.visit(this); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/ReadIMUConfigurationResponseFrame.java |
---|
0,0 → 1,40 |
package dongfang.mkt.frames; |
public class ReadIMUConfigurationResponseFrame extends ResponseFrame { |
private int configurationVersion; |
private int length; |
private int[] data; |
public ReadIMUConfigurationResponseFrame(int address) { |
super(address); |
} |
@Override |
public boolean isResponseTo(RequestFrame r) { |
return r instanceof ReadIMUConfigurationRequestFrame; |
} |
public int getConfigurationVersion() { |
return configurationVersion; |
} |
public void setConfigurationVersion(int configurationVersion) { |
this.configurationVersion = configurationVersion; |
} |
public int getConfigurationSetLength() { |
return length; |
} |
public void setConfigurationSetLength(int configurationSetLength) { |
this.length = configurationSetLength; |
} |
public int[] getData() { |
return data; |
} |
public void setData(int[] data) { |
this.data = data; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/ReadParamSetRequestFrame.java |
---|
6,11 → 6,22 |
public class ReadParamSetRequestFrame extends RequestFrame { |
ReadParamSetRequestFrame(int address) { |
super(address); |
private int configurationSetNumber; |
public ReadParamSetRequestFrame() { |
super(FC_ADDRESS); |
} |
@Override |
public void accept(RequestFrameVisitor o) throws IOException { |
o.visit(this); |
} |
public int getConfigurationSetNumber() { |
return configurationSetNumber; |
} |
public void setConfigurationSetNumber(int number) { |
this.configurationSetNumber = number; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/ReadParamSetResponseFrame.java |
---|
0,0 → 1,49 |
package dongfang.mkt.frames; |
public class ReadParamSetResponseFrame extends ResponseFrame { |
private int configurationSetNumber; |
private int configurationVersion; |
private int length; |
private int[] data; |
public ReadParamSetResponseFrame(int address) { |
super(address); |
} |
@Override |
public boolean isResponseTo(RequestFrame r) { |
return r instanceof ReadParamSetRequestFrame; |
} |
public int getConfigurationSetNumber() { |
return configurationSetNumber; |
} |
public void setConfigurationSetNumber(int configurationSetNumber) { |
this.configurationSetNumber = configurationSetNumber; |
} |
public int getConfigurationVersion() { |
return configurationVersion; |
} |
public void setConfigurationVersion(int configurationVersion) { |
this.configurationVersion = configurationVersion; |
} |
public int getConfigurationSetLength() { |
return length; |
} |
public void setConfigurationSetLength(int configurationSetLength) { |
this.length = configurationSetLength; |
} |
public int[] getData() { |
return data; |
} |
public void setData(int[] data) { |
this.data = data; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/RequestFrameVisitor.java |
---|
17,8 → 17,8 |
void visit(ExternalControlRequestFrame f) throws IOException; |
void visit(ResetRequestFrame f) throws IOException; |
void visit(ChangeParameterSetRequestFrame f) throws IOException; |
void visit(UniversalReadParamSetRequestFrame f) throws IOException; |
void visit(UniversalWriteParamSetRequestFrame f) throws IOException; |
void visit(ReadParamSetRequestFrame f) throws IOException; |
void visit(WriteParamSetRequestFrame f) throws IOException; |
void visit(SetCompassHeadingRequestFrame f) throws IOException; |
void visit(ReadExternalControlRequestFrame f) throws IOException; |
void visit(OSDDataRequestFrame f) throws IOException; |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/WriteIMUConfigurationResponseFrame.java |
---|
0,0 → 1,23 |
package dongfang.mkt.frames; |
public class WriteIMUConfigurationResponseFrame extends ResponseFrame { |
private int parameterSetNumber; |
private boolean wasAccepted; |
public WriteIMUConfigurationResponseFrame(int address) { |
super(address); |
} |
@Override |
public boolean isResponseTo(RequestFrame r) { |
return r instanceof WriteIMUConfigurationRequestFrame; |
} |
public boolean wasAccepted() { |
return wasAccepted; |
} |
public void setWasAccepted(boolean wasAccepted) { |
this.wasAccepted = wasAccepted; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/WriteParamSetRequestFrame.java |
---|
6,11 → 6,44 |
public class WriteParamSetRequestFrame extends RequestFrame { |
WriteParamSetRequestFrame(int address) { |
super(address); |
private char[] name; |
private int[] data; |
private int configurationSetNumber; |
private int configurationVersionNumber; |
public WriteParamSetRequestFrame(int configurationVersionNumber, char[] name, int[] data) { |
super(FC_ADDRESS); |
this.configurationVersionNumber = configurationVersionNumber; |
this.name = name; |
this.data = data; |
} |
@Override |
public void accept(RequestFrameVisitor o) throws IOException { |
o.visit(this); |
} |
public int getConfigurationSetNumber() { |
return configurationSetNumber; |
} |
public void setConfigurationSetNumber(int n) { |
this.configurationSetNumber = n ; |
} |
public int getConfigurationVersionNumber() { |
return configurationVersionNumber; |
} |
public int getDataLength() { |
return data.length; |
} |
public int[] getData() { |
return data; |
} |
public char[] getName() { |
return name; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/WriteParamSetResponseFrame.java |
---|
0,0 → 1,26 |
package dongfang.mkt.frames; |
public class WriteParamSetResponseFrame extends ResponseFrame { |
private int parameterSetNumber; |
public WriteParamSetResponseFrame(int address) { |
super(address); |
} |
@Override |
public boolean isResponseTo(RequestFrame r) { |
return r instanceof WriteParamSetRequestFrame; |
} |
public void setParameterSetNumber(int parameterSetNumber) { |
this.parameterSetNumber = parameterSetNumber; |
} |
public int getParameterSetNumber() { |
return this.parameterSetNumber; |
} |
public boolean wasAccepted() { |
return parameterSetNumber != 0; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/main/CodeGenerator.java |
---|
2,11 → 2,12 |
import java.io.IOException; |
import dongfang.mkt.configuration.ConfigSet; |
import dongfang.mkt.configuration.ConfigurationSet; |
import dongfang.mkt.configuration.ParameterSet; |
public class CodeGenerator { |
static void generateDynamicSubstitutionCode(int paramSetVersion) throws IOException { |
ConfigSet cs = ConfigSet.parseXMLConfigSet(paramSetVersion); |
ConfigurationSet cs = ParameterSet.parseXMLConfigSet(paramSetVersion); |
System.out.println(cs.generateDynamicSubstitutionCode()); |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/main/IMUConfigurator.java |
---|
0,0 → 1,201 |
package dongfang.mkt.main; |
import java.io.FileInputStream; |
import java.io.FileWriter; |
import java.io.IOException; |
import java.io.InputStream; |
import javax.xml.parsers.DocumentBuilder; |
import javax.xml.parsers.DocumentBuilderFactory; |
import javax.xml.parsers.ParserConfigurationException; |
import javax.xml.xpath.XPath; |
import javax.xml.xpath.XPathConstants; |
import javax.xml.xpath.XPathExpressionException; |
import javax.xml.xpath.XPathFactory; |
import org.w3c.dom.Document; |
import org.w3c.dom.Element; |
import org.w3c.dom.NodeList; |
import org.xml.sax.SAXException; |
import dongfang.mkt.comm.FrameQueue; |
import dongfang.mkt.comm.MKConnection; |
import dongfang.mkt.comm.serial.RXTXSerialPort; |
import dongfang.mkt.configuration.IMUConfiguration; |
import dongfang.mkt.frames.ReadIMUConfigurationRequestFrame; |
import dongfang.mkt.frames.ReadIMUConfigurationResponseFrame; |
import dongfang.mkt.frames.WriteIMUConfigurationRequestFrame; |
import dongfang.mkt.frames.WriteIMUConfigurationResponseFrame; |
public class IMUConfigurator { |
private static void configure(String portIdentifier, WriteIMUConfigurationRequestFrame frame) throws IOException { |
MKConnection port = new RXTXSerialPort(); |
port.init(portIdentifier); |
FrameQueue q = new FrameQueue(port); |
q.sendRequest(frame); |
WriteIMUConfigurationResponseFrame r = (WriteIMUConfigurationResponseFrame) q.getResponseFor(frame, 5000); |
if (r == null) { |
System.err.println("ERROR. Timeout waiting for response."); |
} else if (!r.wasAccepted()) { |
System.err |
.println("ERROR. Parameter set not accepted. Check version against MK firmware EEPROM configuration version."); |
} else { |
System.out.println("Saved IMU configuration."); |
} |
q.kill(); |
} |
private static void writeConfiguration(String portIdentifier, String fileName) throws IOException { |
System.out.println("Writing IMU configuration from file: " + fileName); |
InputStream inputStream = new FileInputStream(fileName); |
WriteIMUConfigurationRequestFrame frame = parseXMLIMUConfiguration(inputStream); |
configure(portIdentifier, frame); |
} |
private static IMUConfiguration readConfiguration(String portIdentifier) throws IOException { |
MKConnection port = new RXTXSerialPort(); |
port.init(portIdentifier); |
FrameQueue q = new FrameQueue(port); |
IMUConfiguration cs = null; |
ReadIMUConfigurationRequestFrame frame = new ReadIMUConfigurationRequestFrame(); |
q.sendRequest(frame); |
ReadIMUConfigurationResponseFrame r = (ReadIMUConfigurationResponseFrame) q.getResponseFor(frame, 5000); |
if (r == null) { |
System.err.println("ERROR. Timeout waiting for response."); |
} else { |
int paramSetVersion = r.getConfigurationVersion(); |
int[] data = r.getData(); |
cs = IMUConfiguration.parseXMLIMUConfiguration(paramSetVersion); |
cs.setData(data); |
System.out.println(cs.toXML()); |
} |
q.kill(); |
return cs; |
} |
private static void readConfiguration(String portIdentifier, String fileName) throws IOException { |
IMUConfiguration cs = readConfiguration(portIdentifier); |
if (cs != null) { |
FileWriter fw = new FileWriter(fileName); |
fw.write(cs.toXML()); |
fw.close(); |
} |
} |
private static WriteIMUConfigurationRequestFrame parseXMLIMUConfiguration(InputStream input) throws IOException { |
DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance(); |
saxfac.setValidating(false); |
try { |
DocumentBuilder bldr = saxfac.newDocumentBuilder(); |
Document doc = bldr.parse(input); |
XPath xpath = XPathFactory.newInstance().newXPath(); |
String s_eepromVersion = xpath.evaluate( |
"/imuconfiguration/@eepromVersion", doc); |
String ss_length = xpath.evaluate("/imuconfiguration/@length", doc); |
int s_length = 0; |
try { |
s_length = Integer.parseInt(ss_length); |
} catch (NumberFormatException ex) { |
// ignore. |
} |
int eepromVersion = -1; |
try { |
eepromVersion = Integer.parseInt(s_eepromVersion); |
} catch (NumberFormatException ex) { |
System.err |
.println("The imuconfiguration element must have an 'eepromVersion' attribute with a numerical value (eg.<parameterset eepromVersion='74'>)"); |
System.exit(-1); |
} |
NodeList parameterNodes = (NodeList) xpath.evaluate( |
"/imuconfiguration/parameter", doc, XPathConstants.NODESET); |
int[] parameters = new int[parameterNodes.getLength()]; |
NodeList allChildNodes = (NodeList) xpath.evaluate("/imuconfiguration/*", doc, XPathConstants.NODESET); |
if (parameterNodes.getLength() != allChildNodes.getLength()) { |
System.err.println("There seems to be a child element of imuconfiguration whose name is not \"parameter\"."); |
// System.exit(-1); |
} |
if (s_length >=0 && s_length != parameterNodes.getLength()) { |
System.err.println("The number of parameters ("+parameterNodes.getLength()+") does not match the number in the length attribute of the imuconfiguration element ("+s_length+")."); |
// System.exit(-1); |
} |
for (int i = 0; i < parameterNodes.getLength(); i++) { |
Element e = (Element) parameterNodes.item(i); |
int value = 0; |
if (e.hasAttribute("value")) { |
String s_value = e.getAttribute("value"); |
value = Integer.parseInt(s_value); |
if (value < 0) |
try { |
value = Integer.parseInt(s_value); |
} catch (NumberFormatException ex) { |
throw new NumberFormatException( |
"Value is not a number and not a variable name."); |
} |
} else { |
NodeList bitNodes = (NodeList) xpath.evaluate("bit", e, |
XPathConstants.NODESET); |
for (int j = 0; j < 8; j++) { |
Element bitElement = (Element) bitNodes.item(j); |
if (bitElement != null) { |
String s_bitValue = bitElement |
.getAttribute("value"); |
if ("1".equals(s_bitValue)) |
value |= (1 << j); |
else if (!"0".equals(s_bitValue)) |
throw new NumberFormatException( |
"Bit value was not 0 or 1."); |
} |
} |
} |
parameters[i] = value; |
} |
input.close(); |
return new WriteIMUConfigurationRequestFrame(eepromVersion, parameters); |
} catch (ParserConfigurationException ex) { |
// Should never happen. |
throw new RuntimeException(ex); |
} catch (SAXException ex) { |
System.err.println(ex); |
System.err |
.println("There is something screwed with your XML document. It is not well-formed and won't parse."); |
throw new RuntimeException("Parse error."); |
} catch (XPathExpressionException ex) { |
// Should never happen. |
throw new RuntimeException(ex); |
} |
} |
static void help() { |
System.err.println("Usage: IMUConfigurator r [filename to write to]"); |
System.err.println("Usage: IMUConfigurator w [filename to read from]"); |
System.exit(-1); |
} |
public static void main(String[] args) throws IOException { |
if (!"r".equals(args[0]) && !"w".equals(args[0])) help(); |
if ("w".equals(args[0]) && (args.length!=2)) help(); |
if ("r".equals(args[0]) && (args.length!=2)) help(); |
String portIdentifier = null; |
if ("r".equals(args[0])) { |
readConfiguration(portIdentifier, args[1]); |
} else { |
writeConfiguration(portIdentifier, args[1]); |
} |
System.exit(0); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/main/ParameterSetConfigurator.java |
---|
0,0 → 1,260 |
package dongfang.mkt.main; |
import java.io.FileInputStream; |
import java.io.FileWriter; |
import java.io.IOException; |
import java.io.InputStream; |
import javax.xml.parsers.DocumentBuilder; |
import javax.xml.parsers.DocumentBuilderFactory; |
import javax.xml.parsers.ParserConfigurationException; |
import javax.xml.xpath.XPath; |
import javax.xml.xpath.XPathConstants; |
import javax.xml.xpath.XPathExpressionException; |
import javax.xml.xpath.XPathFactory; |
import org.w3c.dom.Document; |
import org.w3c.dom.Element; |
import org.w3c.dom.NodeList; |
import org.xml.sax.SAXException; |
import dongfang.mkt.comm.FrameQueue; |
import dongfang.mkt.comm.MKConnection; |
import dongfang.mkt.comm.serial.RXTXSerialPort; |
import dongfang.mkt.configuration.ParameterSet; |
import dongfang.mkt.frames.ReadParamSetRequestFrame; |
import dongfang.mkt.frames.ReadParamSetResponseFrame; |
import dongfang.mkt.frames.WriteParamSetRequestFrame; |
import dongfang.mkt.frames.WriteParamSetResponseFrame; |
public class ParameterSetConfigurator { |
private static void configure(String portIdentifier, WriteParamSetRequestFrame frame, |
int parameterSetNumber) throws IOException { |
MKConnection port = new RXTXSerialPort(); |
port.init(portIdentifier); |
FrameQueue q = new FrameQueue(port); |
frame.setConfigurationSetNumber(parameterSetNumber); |
q.sendRequest(frame); |
WriteParamSetResponseFrame r = (WriteParamSetResponseFrame) q.getResponseFor(frame, 5000); |
if (r == null) { |
System.err.println("ERROR. Timeout waiting for response."); |
} else if (!r.wasAccepted()) { |
System.err |
.println("ERROR. Parameter set not accepted. Check version against MK firmware EEPROM configuration version and checkparameter set number"); |
} else { |
System.out.println("Saved parameter set #" |
+ r.getParameterSetNumber() + "."); |
} |
q.kill(); |
} |
private static void writeConfiguration(String portIdentifier, String s_parameterSetNumber, |
String fileName) throws IOException { |
System.out.println("Writing parameter set #" + s_parameterSetNumber + " from file: " + fileName); |
int parameterSetNumber = Integer.parseInt(s_parameterSetNumber); |
InputStream inputStream = new FileInputStream(fileName); |
WriteParamSetRequestFrame frame = parseXMLParameterSet(inputStream); |
configure(portIdentifier, frame, parameterSetNumber); |
} |
private static ParameterSet readConfiguration(String portIdentifier, String s_parameterSetNumber) throws IOException { |
MKConnection port = new RXTXSerialPort(); |
port.init(portIdentifier); |
FrameQueue q = new FrameQueue(port); |
ParameterSet cs = null; |
int parameterSetNumber = Integer.parseInt(s_parameterSetNumber); |
ReadParamSetRequestFrame frame = new ReadParamSetRequestFrame(); |
frame.setConfigurationSetNumber(parameterSetNumber); |
q.sendRequest(frame); |
ReadParamSetResponseFrame r = (ReadParamSetResponseFrame) q.getResponseFor(frame, 5000); |
if (r == null) { |
System.err.println("ERROR. Timeout waiting for response."); |
} else { |
int paramSetVersion = r.getConfigurationVersion(); |
int[] data = r.getData(); |
cs = ParameterSet.parseXMLParameterSet(paramSetVersion); |
cs.setData(data); |
System.out.println(cs.toXML()); |
} |
q.kill(); |
return cs; |
} |
/* |
private static ConfigSet simpleReadConfiguration(int parameterSetNumber) |
throws IOException { |
MKCommPort port = new RXTXSerialPort(); |
port.init(null); |
FrameQueue q = new FrameQueue(port); |
ConfigSet cs = null; |
UniversalReadParamSetRequestFrame frame = new UniversalReadParamSetRequestFrame(); |
frame.setConfigurationSetNumber(parameterSetNumber); |
q.sendRequest(frame); |
UniversalReadParamSetResponseFrame r = (UniversalReadParamSetResponseFrame) q |
.getResponseFor(frame, 3000); |
if (r == null) { |
System.err.println("ERROR. Timeout waiting for response."); |
} else { |
int paramSetVersion = r.getConfigurationVersion(); |
int[] data = r.getData(); |
for (int i=0; i<data.length; i++) |
System.out.println(data[i]); |
} |
q.kill(); |
return cs; |
} |
*/ |
private static void readConfiguration(String portIdentifier, String s_parameterSetNumber, String fileName) throws IOException { |
ParameterSet cs = readConfiguration(portIdentifier, s_parameterSetNumber); |
if (cs != null) { |
FileWriter fw = new FileWriter(fileName); |
fw.write(cs.toXML()); |
fw.close(); |
} |
} |
private static int substituteVariables(String s_value) { |
int numberOfHighestVar = 255; |
int numberOfLowestVar = numberOfHighestVar - ParameterSet.NUMBER_OF_VARIABLES + 1; |
for (int i = 0; i < ParameterSet.NUMBER_OF_VARIABLES; i++) { |
String varName = "var" + i; |
if (varName.equals(s_value)) { |
System.out.println("Substing: " + s_value + "-->" + (numberOfLowestVar + i)); |
return numberOfLowestVar + i; |
} |
} |
return -1; |
} |
private static WriteParamSetRequestFrame parseXMLParameterSet( |
InputStream input) throws IOException { |
DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance(); |
saxfac.setValidating(false); |
try { |
DocumentBuilder bldr = saxfac.newDocumentBuilder(); |
Document doc = bldr.parse(input); |
XPath xpath = XPathFactory.newInstance().newXPath(); |
String s_eepromVersion = xpath.evaluate( |
"/parameterset/@eepromVersion", doc); |
String ss_length = xpath.evaluate("/parameterset/@length", doc); |
int s_length = 0; |
try { |
s_length = Integer.parseInt(ss_length); |
} catch (NumberFormatException ex) { |
// ignore. |
} |
int eepromVersion = -1; |
try { |
eepromVersion = Integer.parseInt(s_eepromVersion); |
} catch (NumberFormatException ex) { |
System.err |
.println("The parameterset element must have an 'eepromVersion' attribute with a numerical value (eg.<parameterset eepromVersion='74'>)"); |
System.exit(-1); |
} |
// if (s_length != null) |
// try { |
// length = Integer.parseInt(s_length); |
// } catch (NumberFormatException ex) { |
// System.err.println("The length attribute of the parameterset must have a numerical value"); |
// System.exit(-1); |
// } |
NodeList parameterNodes = (NodeList) xpath.evaluate( |
"/parameterset/parameter", doc, XPathConstants.NODESET); |
int[] parameters = new int[parameterNodes.getLength()]; |
NodeList allChildNodes = (NodeList) xpath.evaluate( |
"/parameterset/*", doc, XPathConstants.NODESET); |
if (parameterNodes.getLength() != allChildNodes.getLength()) { |
System.err.println("There seems to be a child element of parameterset whose name is not \"parameter\"."); |
// System.exit(-1); |
} |
if (s_length >=0 && s_length != parameterNodes.getLength()) { |
System.err.println("The number of parameters ("+parameterNodes.getLength()+") does not match the number in the length attribute of the parameterset element ("+s_length+")."); |
// System.exit(-1); |
} |
for (int i = 0; i < parameterNodes.getLength(); i++) { |
Element e = (Element) parameterNodes.item(i); |
int value = 0; |
if (e.hasAttribute("value")) { |
String s_value = e.getAttribute("value"); |
value = substituteVariables(s_value); |
if (value < 0) |
try { |
value = Integer.parseInt(s_value); |
} catch (NumberFormatException ex) { |
throw new NumberFormatException( |
"Value is not a number and not a variable name."); |
} |
} else { |
NodeList bitNodes = (NodeList) xpath.evaluate("bit", e, |
XPathConstants.NODESET); |
for (int j = 0; j < 8; j++) { |
Element bitElement = (Element) bitNodes.item(j); |
if (bitElement != null) { |
String s_bitValue = bitElement |
.getAttribute("value"); |
if ("1".equals(s_bitValue)) |
value |= (1 << j); |
else if (!"0".equals(s_bitValue)) |
throw new NumberFormatException( |
"Bit value was not 0 or 1."); |
} |
} |
} |
parameters[i] = value; |
} |
input.close(); |
return new WriteParamSetRequestFrame(eepromVersion, "01234567890ab".toCharArray(), parameters); |
} catch (ParserConfigurationException ex) { |
// Should never happen. |
throw new RuntimeException(ex); |
} catch (SAXException ex) { |
System.err.println(ex); |
System.err |
.println("There is something screwed with your XML document. It is not well-formed and won't parse."); |
throw new RuntimeException("Parse error."); |
} catch (XPathExpressionException ex) { |
// Should never happen. |
throw new RuntimeException(ex); |
} |
} |
static void help() { |
System.err |
.println("Usage: UniversalConfigurator r [parameter set number to read from] [filename to write to]"); |
System.err |
.println("Usage: UniversalConfigurator w [parameter set number to write to] [filename to read from]"); |
System.exit(-1); |
} |
public static void main(String[] args) throws IOException { |
if (!"r".equals(args[0]) && !"w".equals(args[0])) help(); |
if ("w".equals(args[0]) && (args.length!=3 && args.length!=4)) help(); |
if ("r".equals(args[0]) && (args.length!=3 && args.length!=4)) help(); |
String portIdentifier = null; |
if ("r".equals(args[0])) { |
readConfiguration(portIdentifier, args[1]); |
} else { |
writeConfiguration(portIdentifier, args[1], args[2]); |
} |
System.exit(0); |
} |
} |