Subversion Repositories Projects

Rev

Rev 1570 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1570 Rev 1573
Line 19... Line 19...
19
import org.xml.sax.SAXException;
19
import org.xml.sax.SAXException;
Line 20... Line 20...
20
 
20
 
21
import dongfang.mkt.comm.FrameQueue;
21
import dongfang.mkt.comm.FrameQueue;
22
import dongfang.mkt.comm.MKConnection;
22
import dongfang.mkt.comm.MKConnection;
23
import dongfang.mkt.comm.serial.RXTXSerialPort;
-
 
24
import dongfang.mkt.comm.tcp.MKTCPConnection;
23
import dongfang.mkt.comm.serial.RXTXSerialPort;
25
import dongfang.mkt.configuration.ConfigSet;
24
import dongfang.mkt.configuration.ConfigSet;
26
import dongfang.mkt.frames.UniversalReadParamSetRequestFrame;
25
import dongfang.mkt.frames.UniversalReadParamSetRequestFrame;
27
import dongfang.mkt.frames.UniversalReadParamSetResponseFrame;
26
import dongfang.mkt.frames.UniversalReadParamSetResponseFrame;
28
import dongfang.mkt.frames.UniversalWriteParamSetRequestFrame;
27
import dongfang.mkt.frames.UniversalWriteParamSetRequestFrame;
Line 36... Line 35...
36
                FrameQueue q = new FrameQueue(port);
35
                FrameQueue q = new FrameQueue(port);
Line 37... Line 36...
37
 
36
 
Line 38... Line 37...
38
                frame.setConfigurationSetNumber(parameterSetNumber);
37
                frame.setConfigurationSetNumber(parameterSetNumber);
39
 
38
 
40
                q.sendRequest(frame);
-
 
41
                UniversalWriteParamSetResponseFrame r = (UniversalWriteParamSetResponseFrame) q
39
                q.sendRequest(frame);
42
                                .getResponseFor(frame, 5000);
40
                UniversalWriteParamSetResponseFrame r = (UniversalWriteParamSetResponseFrame) q.getResponseFor(frame, 5000);
43
                if (r == null) {
41
                if (r == null) {
44
                        System.err.println("ERROR. Timeout waiting for response.");
42
                        System.err.println("ERROR. Timeout waiting for response.");
45
                } else if (!r.wasAccepted()) {
43
                } else if (!r.wasAccepted()) {
Line 60... Line 58...
60
                InputStream inputStream = new FileInputStream(fileName);
58
                InputStream inputStream = new FileInputStream(fileName);
61
                UniversalWriteParamSetRequestFrame frame = parseXMLParameterSet(inputStream);
59
                UniversalWriteParamSetRequestFrame frame = parseXMLParameterSet(inputStream);
62
                configure(portIdentifier, frame, parameterSetNumber);
60
                configure(portIdentifier, frame, parameterSetNumber);
63
        }
61
        }
Line 64... Line 62...
64
 
62
 
65
        private static ConfigSet readConfiguration(String portIdentifier, int parameterSetNumber) throws IOException {
63
        private static ConfigSet readConfiguration(String portIdentifier, String s_parameterSetNumber) throws IOException {
66
                MKConnection port =  new RXTXSerialPort();
64
                MKConnection port =  new RXTXSerialPort();
67
                port.init(portIdentifier);
65
                port.init(portIdentifier);
68
                FrameQueue q = new FrameQueue(port);
66
                FrameQueue q = new FrameQueue(port);
-
 
67
                ConfigSet cs = null;
Line 69... Line 68...
69
                ConfigSet cs = null;
68
                int parameterSetNumber = Integer.parseInt(s_parameterSetNumber);
70
 
69
 
71
                UniversalReadParamSetRequestFrame frame = new UniversalReadParamSetRequestFrame();
70
                UniversalReadParamSetRequestFrame frame = new UniversalReadParamSetRequestFrame();
72
                frame.setConfigurationSetNumber(parameterSetNumber);
71
                frame.setConfigurationSetNumber(parameterSetNumber);
Line 110... Line 109...
110
                return cs;
109
                return cs;
111
        }
110
        }
112
        */
111
        */
Line 113... Line 112...
113
 
112
 
114
        private static void readConfiguration(String portIdentifier, String s_parameterSetNumber, String fileName) throws IOException {
-
 
115
                int parameterSetNumber = Integer.parseInt(s_parameterSetNumber);
113
        private static void readConfiguration(String portIdentifier, String s_parameterSetNumber, String fileName) throws IOException {
116
                ConfigSet cs = readConfiguration(portIdentifier, parameterSetNumber);
114
                ConfigSet cs = readConfiguration(portIdentifier, s_parameterSetNumber);
117
                if (cs != null) {
115
                if (cs != null) {
118
                        FileWriter fw = new FileWriter(fileName);
116
                        FileWriter fw = new FileWriter(fileName);
119
                        fw.write(cs.toXML());
117
                        fw.write(cs.toXML());
120
                        fw.close();
118
                        fw.close();
Line 177... Line 175...
177
 
175
 
178
                        NodeList parameterNodes = (NodeList) xpath.evaluate(
176
                        NodeList parameterNodes = (NodeList) xpath.evaluate(
179
                                        "/parameterset/parameter", doc, XPathConstants.NODESET);
177
                                        "/parameterset/parameter", doc, XPathConstants.NODESET);
Line -... Line 178...
-
 
178
                        int[] parameters = new int[parameterNodes.getLength()];
-
 
179
 
-
 
180
                        NodeList allChildNodes = (NodeList) xpath.evaluate(
-
 
181
                                        "/parameterset/*", doc, XPathConstants.NODESET);
-
 
182
 
-
 
183
                        if (parameterNodes.getLength() != allChildNodes.getLength()) {
-
 
184
                                System.err.println("There seems to be a child element of parameterset whose name is not \"parameter\".");
-
 
185
                        // System.exit(-1);
180
                        int[] parameters = new int[parameterNodes.getLength()];
186
                        }
181
 
187
 
182
                        if (s_length >=0 && s_length != parameterNodes.getLength()) {
188
                        if (s_length >=0 && s_length != parameterNodes.getLength()) {
183
                        System.err.println("The number of parameters ("+parameterNodes.getLength()+") does not match the number in the length attribute of the parameterset element ("+s_length+").");
189
                        System.err.println("The number of parameters ("+parameterNodes.getLength()+") does not match the number in the length attribute of the parameterset element ("+s_length+").");
Line 214... Line 220...
214
                                        }
220
                                        }
215
                                }
221
                                }
216
                                parameters[i] = value;
222
                                parameters[i] = value;
217
                        }
223
                        }
218
                        input.close();
224
                        input.close();
219
                        return new UniversalWriteParamSetRequestFrame(eepromVersion,
225
                        return new UniversalWriteParamSetRequestFrame(eepromVersion, "01234567890ab".toCharArray(), parameters);
220
                                        parameters);
-
 
221
                } catch (ParserConfigurationException ex) {
226
                } catch (ParserConfigurationException ex) {
222
                        // Should never happen.
227
                        // Should never happen.
223
                        throw new RuntimeException(ex);
228
                        throw new RuntimeException(ex);
224
                } catch (SAXException ex) {
229
                } catch (SAXException ex) {
225
                        System.err.println(ex);
230
                        System.err.println(ex);
Line 246... Line 251...
246
                if ("r".equals(args[0]) && (args.length!=3 && args.length!=4)) help();
251
                if ("r".equals(args[0]) && (args.length!=3 && args.length!=4)) help();
Line 247... Line 252...
247
 
252
 
Line 248... Line 253...
248
                String portIdentifier = null;
253
                String portIdentifier = null;
249
               
254
               
250
                if ("r".equals(args[0])) {
255
                if ("r".equals(args[0])) {
251
                        readConfiguration(portIdentifier, Integer.parseInt(args[1]));
256
                        readConfiguration(portIdentifier, args[1]);
252
                } else {
257
                } else {
253
                        writeConfiguration(portIdentifier, args[1], args[2]);
258
                        writeConfiguration(portIdentifier, args[1], args[2]);
254
                }
259
                }