Rev 1688 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1688 | Rev 1689 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package dongfang.mkt.configuration; |
1 | package dongfang.mkt.configuration; |
Line 2... | Line -... | ||
2 | - | ||
3 | import java.io.File; |
2 | |
4 | import java.io.IOException; |
3 | import java.io.IOException; |
Line 5... | Line 4... | ||
5 | import java.io.InputStream; |
4 | import java.io.InputStream; |
6 | 5 | ||
Line 15... | Line 14... | ||
15 | import org.w3c.dom.Document; |
14 | import org.w3c.dom.Document; |
16 | import org.w3c.dom.Element; |
15 | import org.w3c.dom.Element; |
17 | import org.w3c.dom.NodeList; |
16 | import org.w3c.dom.NodeList; |
18 | import org.xml.sax.SAXException; |
17 | import org.xml.sax.SAXException; |
Line 19... | Line -... | ||
19 | - | ||
20 | import dongfang.mkt.frames.WriteParamSetRequestFrame; |
- | |
21 | 18 | ||
22 | public class MotorMixer { |
19 | public class MotorMixer { |
Line 23... | Line 20... | ||
23 | public static final int EEPROMVERSION = 11; |
20 | public static final int EEPROMVERSION = 1; |
24 | 21 | ||
25 | public static final int MAX_MOTORS = 12; |
22 | public static final int MAX_MOTORS = 12; |
26 | public static final int MIX_PITCH = 0; |
23 | public static final int MIX_PITCH = 0; |
27 | public static final int MIX_ROLL = 1; |
24 | public static final int MIX_ROLL = 1; |
28 | public static final int MIX_THROTTLE = 2; |
25 | public static final int MIX_THROTTLE = 2; |
29 | public static final int MIX_YAW = 3; |
- | |
30 | public static final int MIX_OPPOSITE_MOTOR = 4; |
- | |
31 | - | ||
32 | private int getByteCount() { |
- | |
Line 33... | Line 26... | ||
33 | return MAX_MOTORS * 4 + MAX_MOTORS; |
26 | public static final int MIX_YAW = 3; |
34 | } |
27 | public static final int MIX_OPPOSITE_MOTOR = 4; |
35 | 28 | ||
36 | void rowToXML(int[] row, StringBuilder out) { |
29 | void rowToXML(int[] row, StringBuilder out) { |
- | 30 | out.append("<motor throttlePart=\"" + row[MIX_THROTTLE] + "\" pitchPart=\"" + row[MIX_PITCH] + "\" rollPart=\"" + row[MIX_ROLL] + "\" yawPart=\"" + row[MIX_YAW] + "\" oppositeMotor=\"" + row[MIX_OPPOSITE_MOTOR] + "\" />"); |
|
- | 31 | } |
|
37 | out.append("<motor throttlePart=\"" + row[MIX_THROTTLE] + "\" pitchPart=\"" + row[MIX_PITCH] + "\" rollPart=\"" + row[MIX_ROLL] + "\" yawPart=\"" + row[MIX_YAW] + "\" oppositeMotor=\"" + row[MIX_OPPOSITE_MOTOR] + "\"/>"); |
32 | |
Line 38... | Line 33... | ||
38 | } |
33 | private String name; |
39 | 34 | ||
40 | private int[][] matrix = new int[MAX_MOTORS][]; |
35 | private int[][] matrix = new int[MAX_MOTORS][]; |
Line -... | Line 36... | ||
- | 36 | ||
- | 37 | public void setMatrix(int[][] matrix) { |
|
- | 38 | this.matrix = matrix; |
|
- | 39 | } |
|
- | 40 | ||
- | 41 | public String getName() { |
|
- | 42 | return name; |
|
- | 43 | } |
|
41 | 44 | ||
42 | public void setMatrix(int[][] matrix) { |
45 | public void setName(String name) { |
43 | this.matrix = matrix; |
46 | this.name = name; |
Line 44... | Line 47... | ||
44 | } |
47 | } |
45 | 48 | ||
46 | public int[][] toBinary() { |
49 | public int[][] toBinary() { |
47 | return matrix; |
50 | return matrix; |
48 | } |
51 | } |
49 | 52 | ||
50 | public String toXML() { |
53 | public String toXML() { |
51 | StringBuilder result = new StringBuilder(); |
54 | StringBuilder result = new StringBuilder(); |
52 | result.append("<motorMixer eepromVersion=\"" + EEPROMVERSION + "\" length=\"" + getByteCount() + "\">\n"); |
55 | result.append("<motorMixer eepromVersion=\"" + EEPROMVERSION + "\" name=\"" + name + "\">\n"); |
53 | for (int i = 0; i < MAX_MOTORS; i++) { |
56 | for (int i = 0; i < MAX_MOTORS; i++) { |
54 | int[] row = matrix[i]; |
57 | int[] row = matrix[i]; |
55 | result.append(" "); |
58 | result.append(" "); |
Line 56... | Line 59... | ||
56 | this.rowToXML(row, result); |
59 | this.rowToXML(row, result); |
57 | result.append("\n"); |
60 | result.append("\n"); |
58 | } |
61 | } |
59 | result.append("</motorMixer>\n"); |
62 | result.append("</motorMixer>\n"); |
60 | return result.toString(); |
63 | return result.toString(); |
61 | } |
64 | } |
Line 77... | Line 80... | ||
77 | System.err |
80 | System.err |
78 | .println("The motorMixer element must have an 'eepromVersion' attribute with a numerical value (eg.<motorMixer eepromVersion='1'>)"); |
81 | .println("The motorMixer element must have an 'eepromVersion' attribute with a numerical value (eg.<motorMixer eepromVersion='1'>)"); |
79 | System.exit(-1); |
82 | System.exit(-1); |
80 | } |
83 | } |
Line -... | Line 84... | ||
- | 84 | ||
- | 85 | this.name = xpath.evaluate("/motorMixer/@name", doc); |
|
81 | 86 | ||
82 | NodeList rowNodes = (NodeList) xpath.evaluate( |
87 | NodeList rowNodes = (NodeList) xpath.evaluate( |
Line 83... | Line 88... | ||
83 | "/motorMixer/motor", doc, XPathConstants.NODESET); |
88 | "/motorMixer/motor", doc, XPathConstants.NODESET); |
84 | 89 | ||
85 | for (int i = 0; i < rowNodes.getLength(); i++) { |
90 | for (int i = 0; i < rowNodes.getLength(); i++) { |
Line 86... | Line 91... | ||
86 | Element e = (Element) rowNodes.item(i); |
91 | Element e = (Element) rowNodes.item(i); |
87 | int[] row = new int[5]; |
92 | int[] row = new int[5]; |
Line 88... | Line 93... | ||
88 | 93 | ||
89 | String s_value = e.getAttribute("throttle"); |
94 | String s_value = e.getAttribute("throttlePart"); |
Line 90... | Line 95... | ||
90 | row[MIX_THROTTLE] = Integer.parseInt(s_value); |
95 | row[MIX_THROTTLE] = Integer.parseInt(s_value); |
91 | 96 | ||
Line 92... | Line 97... | ||
92 | s_value = e.getAttribute("pitch"); |
97 | s_value = e.getAttribute("pitchPart"); |
93 | row[MIX_PITCH] = Integer.parseInt(s_value); |
98 | row[MIX_PITCH] = Integer.parseInt(s_value); |
Line 94... | Line 99... | ||
94 | 99 | ||
95 | s_value = e.getAttribute("roll"); |
100 | s_value = e.getAttribute("rollPart"); |