Rev 1532 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1532 | Rev 1559 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | 29 | ||
30 | public class UniversalConfigurator { |
30 | public class UniversalConfigurator { |
31 | private static void configure(UniversalWriteParamSetRequestFrame frame, |
31 | private static void configure(UniversalWriteParamSetRequestFrame frame, |
32 | int parameterSetNumber) throws IOException { |
32 | int parameterSetNumber) throws IOException { |
33 | MKCommPort port = new RXTXSerialPort(); |
33 | MKCommPort port = new RXTXSerialPort(); |
34 | port.init("COM10"); |
34 | port.init(null); |
Line 35... | Line 35... | ||
35 | FrameQueue q = new FrameQueue(port); |
35 | FrameQueue q = new FrameQueue(port); |
Line 36... | Line 36... | ||
36 | 36 | ||
Line 59... | Line 59... | ||
59 | InputStream inputStream = new FileInputStream(fileName); |
59 | InputStream inputStream = new FileInputStream(fileName); |
60 | UniversalWriteParamSetRequestFrame frame = parseXMLParameterSet(inputStream); |
60 | UniversalWriteParamSetRequestFrame frame = parseXMLParameterSet(inputStream); |
61 | configure(frame, parameterSetNumber); |
61 | configure(frame, parameterSetNumber); |
62 | } |
62 | } |
Line -... | Line 63... | ||
- | 63 | ||
- | 64 | private static ConfigSet readConfiguration(int parameterSetNumber) throws IOException { |
|
- | 65 | MKCommPort port = new RXTXSerialPort(); |
|
- | 66 | port.init(null); |
|
- | 67 | FrameQueue q = new FrameQueue(port); |
|
- | 68 | ConfigSet cs = null; |
|
- | 69 | ||
- | 70 | UniversalReadParamSetRequestFrame frame = new UniversalReadParamSetRequestFrame(); |
|
- | 71 | frame.setConfigurationSetNumber(parameterSetNumber); |
|
- | 72 | q.sendRequest(frame); |
|
- | 73 | UniversalReadParamSetResponseFrame r = (UniversalReadParamSetResponseFrame) q.getResponseFor(frame, 3000); |
|
- | 74 | if (r == null) { |
|
- | 75 | System.err.println("ERROR. Timeout waiting for response."); |
|
- | 76 | } else { |
|
- | 77 | int paramSetVersion = r.getConfigurationVersion(); |
|
- | 78 | int[] data = r.getData(); |
|
- | 79 | cs = ConfigSet.parseXMLConfigSet(paramSetVersion); |
|
- | 80 | cs.setData(data); |
|
- | 81 | System.out.println(cs.toXML()); |
|
- | 82 | } |
|
- | 83 | q.kill(); |
|
- | 84 | return cs; |
|
- | 85 | } |
|
- | 86 | ||
63 | 87 | /* |
|
64 | private static ConfigSet readConfiguration(int parameterSetNumber) |
88 | private static ConfigSet simpleReadConfiguration(int parameterSetNumber) |
65 | throws IOException { |
89 | throws IOException { |
66 | MKCommPort port = new RXTXSerialPort(); |
90 | MKCommPort port = new RXTXSerialPort(); |
67 | port.init(null); |
91 | port.init(null); |
68 | FrameQueue q = new FrameQueue(port); |
92 | FrameQueue q = new FrameQueue(port); |
Line 76... | Line 100... | ||
76 | if (r == null) { |
100 | if (r == null) { |
77 | System.err.println("ERROR. Timeout waiting for response."); |
101 | System.err.println("ERROR. Timeout waiting for response."); |
78 | } else { |
102 | } else { |
79 | int paramSetVersion = r.getConfigurationVersion(); |
103 | int paramSetVersion = r.getConfigurationVersion(); |
80 | int[] data = r.getData(); |
104 | int[] data = r.getData(); |
81 | - | ||
82 | cs = ConfigSet.parseXMLConfigSet(paramSetVersion); |
105 | for (int i=0; i<data.length; i++) |
83 | cs.setData(data); |
- | |
84 | // System.out.println(cs.toXML()); |
106 | System.out.println(data[i]); |
85 | } |
107 | } |
86 | q.kill(); |
108 | q.kill(); |
87 | return cs; |
109 | return cs; |
88 | } |
110 | } |
- | 111 | */ |
|
Line 89... | Line 112... | ||
89 | 112 | ||
90 | private static void readConfiguration(String s_parameterSetNumber, |
113 | private static void readConfiguration(String s_parameterSetNumber, |
91 | String fileName) throws IOException { |
114 | String fileName) throws IOException { |
92 | int parameterSetNumber = Integer.parseInt(s_parameterSetNumber); |
115 | int parameterSetNumber = Integer.parseInt(s_parameterSetNumber); |
Line 208... | Line 231... | ||
208 | throw new RuntimeException(ex); |
231 | throw new RuntimeException(ex); |
209 | } |
232 | } |
210 | } |
233 | } |
Line 211... | Line 234... | ||
211 | 234 | ||
212 | public static void main(String[] args) throws IOException { |
235 | public static void main(String[] args) throws IOException { |
213 | if (args.length != 3 || (!"r".equals(args[0]) && !"w".equals(args[0]))) { |
236 | if (("w".equals(args[0]) && args.length != 3) || ("r".equals(args[0]) && args.length != 2)) { |
214 | System.err |
237 | System.err |
215 | .println("Usage: UniversalConfigurator r [parameter set number to read from] [filename to write to]"); |
238 | .println("Usage: UniversalConfigurator r [parameter set number to read from] [filename to write to]"); |
216 | System.err |
239 | System.err |
217 | .println("Usage: UniversalConfigurator w [parameter set number to write to] [filename to read from]"); |
240 | .println("Usage: UniversalConfigurator w [parameter set number to write to] [filename to read from]"); |
218 | System.exit(-1); |
241 | System.exit(-1); |
Line 219... | Line 242... | ||
219 | } |
242 | } |
220 | 243 | ||
221 | if ("r".equals(args[0])) { |
244 | if ("r".equals(args[0])) { |
222 | readConfiguration(args[1], args[2]); |
245 | readConfiguration(Integer.parseInt(args[1])); |
223 | } else { |
246 | } else { |
224 | writeConfiguration(args[1], args[2]); |
247 | writeConfiguration(args[1], args[2]); |
225 | } |
248 | } |