Rev 1688 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1688 | Rev 1689 | ||
---|---|---|---|
Line 51... | Line 51... | ||
51 | 51 | ||
52 | private static void writeConfiguration(String portIdentifier, String fileName) throws IOException { |
52 | private static void writeConfiguration(String portIdentifier, String fileName) throws IOException { |
53 | System.out.println("Writing motor mixer from file: " + fileName); |
53 | System.out.println("Writing motor mixer from file: " + fileName); |
54 | InputStream inputStream = new FileInputStream(fileName); |
54 | InputStream inputStream = new FileInputStream(fileName); |
55 | MotorMixer mm = new MotorMixer(); |
55 | MotorMixer mm = new MotorMixer(); |
- | 56 | mm.parseXML(inputStream); |
|
- | 57 | char[] name = new char[12]; |
|
56 | mm.parseXMLMotorMixer(inputStream); |
58 | mm.getName().getChars(0, mm.getName().length(), name, 0); |
- | 59 | WriteMotorMixerRequestFrame frame = new WriteMotorMixerRequestFrame(1, name, mm.toBinary()); |
|
57 | WriteMotorMixerRequestFrame frame = new WriteMotorMixerRequestFrame(1, mm.toBinary()); |
60 | |
58 | configure(portIdentifier, frame); |
61 | configure(portIdentifier, frame); |
Line 59... | Line 62... | ||
59 | } |
62 | } |
60 | 63 | ||
Line 68... | Line 71... | ||
68 | q.sendRequest(frame); |
71 | q.sendRequest(frame); |
69 | ReadMotorMixerResponseFrame r = (ReadMotorMixerResponseFrame) q.getResponseFor(frame, 5000); |
72 | ReadMotorMixerResponseFrame r = (ReadMotorMixerResponseFrame) q.getResponseFor(frame, 5000); |
70 | if (r == null) { |
73 | if (r == null) { |
71 | System.err.println("ERROR. Timeout waiting for response."); |
74 | System.err.println("ERROR. Timeout waiting for response."); |
72 | } else { |
75 | } else { |
73 | int[][] matrix = r.getMatrix(); |
76 | mm.setMatrix(r.getMatrix()); |
74 | mm.setMatrix(matrix); |
77 | char[] name = r.getName(); |
75 | System.out.println(mm.toXML()); |
78 | int firstNulPos = name.length; |
- | 79 | for (int i=0; i<name.length; i++) { |
|
- | 80 | if (name[i] == 0) { |
|
- | 81 | firstNulPos = i; |
|
- | 82 | break; |
|
- | 83 | } |
|
- | 84 | } |
|
- | 85 | String s_name = new String(name, 0, firstNulPos); |
|
- | 86 | mm.setName(s_name); |
|
76 | } |
87 | } |
77 | q.kill(); |
88 | q.kill(); |
78 | return mm; |
89 | return mm; |
79 | } |
90 | } |
Line 80... | Line 91... | ||
80 | 91 | ||
81 | private static void readMotorMixer(String portIdentifier, String fileName) throws IOException { |
92 | private static void readMotorMixer(String portIdentifier, String fileName) throws IOException { |
82 | MotorMixer mm = readMotorMixer(portIdentifier); |
93 | MotorMixer mm = readMotorMixer(portIdentifier); |
- | 94 | if (mm != null) { |
|
83 | if (mm != null) { |
95 | if (fileName != null) { |
84 | FileWriter fw = new FileWriter(fileName); |
96 | FileWriter fw = new FileWriter(fileName); |
85 | fw.write(mm.toXML()); |
97 | fw.write(mm.toXML()); |
- | 98 | fw.close(); |
|
- | 99 | } |
|
86 | fw.close(); |
100 | System.out.println(mm.toXML()); |
87 | } |
101 | } |
Line 88... | Line 102... | ||
88 | } |
102 | } |
89 | 103 | ||
90 | static void help() { |
104 | static void help() { |
91 | System.err.println("Usage: MotorMixerConfigurator r [filename to write to]"); |
105 | System.err.println("Usage: MotorMixerConfigurator r <filename to write to>"); |
92 | System.err.println("Usage: MotorMixerConfigurator w [filename to read from]"); |
106 | System.err.println("Usage: MotorMixerConfigurator w [filename to read from]"); |
Line 93... | Line 107... | ||
93 | System.exit(-1); |
107 | System.exit(-1); |
- | 108 | } |
|
94 | } |
109 | |
95 | 110 | public static void main(String[] args) throws IOException { |
|
96 | public static void main(String[] args) throws IOException { |
- | |
Line 97... | Line 111... | ||
97 | if (!"r".equals(args[0]) && !"w".equals(args[0])) help(); |
111 | if (args.length < 1) help(); |
Line 98... | Line 112... | ||
98 | if ("w".equals(args[0]) && (args.length!=2)) help(); |
112 | if (!"r".equals(args[0]) && !"w".equals(args[0])) help(); |
99 | if ("r".equals(args[0]) && (args.length!=2)) help(); |
113 | if ("w".equals(args[0]) && args.length < 2) help(); |
100 | 114 | ||
101 | String portIdentifier = null; |
115 | String portIdentifier = null; |
102 | 116 | ||
103 | if ("r".equals(args[0])) { |
117 | if ("r".equals(args[0])) { |
104 | readMotorMixer(portIdentifier, args[1]); |
118 | readMotorMixer(portIdentifier, args.length < 2 ? null : args[1]); |