Subversion Repositories HomeAutomation

Rev

Rev 466 | Rev 586 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 466 Rev 473
1
using System;
1
using System;
2
using System.Threading;
2
using System.Threading;
3
using System.Collections.Generic;
3
using System.Collections.Generic;
4
using System.Text;
4
using System.Text;
-
 
5
 
-
 
6
///TODO:
-
 
7
// argument -v # (debuglevel)
-
 
8
// argument till konstruktor på alla objekt: debuglevel
5
 
9
 
6
class Program {
10
class Program {
7
    const byte DEBUG_LEVEL = 3; //0, 1, 2, 3
11
    const byte DEBUG_LEVEL = 3; //0, 1, 2, 3
8
   
12
   
9
    //connects to candaemon on tcp to send and receive packets
13
    //connects to candaemon on tcp to send and receive packets
10
    static DaemonConnection dc;
14
    static DaemonConnection dc;
11
    //a commandline arguments parser
15
    //a commandline arguments parser
12
    static Arguments CommandLine;
16
    static Arguments CommandLine;
13
    //functions for downloading hex to target
17
    //functions for downloading hex to target
14
    static Downloader dl;
18
    static Downloader dl;
15
    //maintains a hexfile
19
    //maintains a hexfile
16
    private static HexFile hf;
20
    private static HexFile hf;
17
   
21
   
18
    static bool aBios=false;        //if commandline says it is a bios update
22
    static bool aBios=false;        //if commandline says it is a bios update
19
    static bool aReset=false;       //if commandline says a reset should be sent before downloading to target
23
    static bool aReset=false;       //if commandline says a reset should be sent before downloading to target
20
    static bool aStart=false;       //if commandline says a start should be sent after downloading to target
24
    static bool aStart=false;       //if commandline says a start should be sent after downloading to target
21
    static bool aTerminal=false;    //if commandline says we should start in interactive mode
25
    static bool aTerminal=false;    //if commandline says we should start in interactive mode
22
       
26
       
23
    static bool sNodeid=false;      //true when a nodeid has been parsed
27
    static bool sNodeid=false;      //true when a nodeid has been parsed
24
    static bool sHexfile=false;     //true when a hexfile has been specified
28
    static bool sHexfile=false;     //true when a hexfile has been specified
25
       
29
       
26
    static string hexfile=null;     //path to a hexfile
30
    static string hexfile=null;     //path to a hexfile
27
    static byte nodeid=0;           //id of current node
31
    static byte nodeid=0;           //id of current node
28
    static string host=null;        //address of candaemon-host
32
    static string host=null;        //address of candaemon-host
29
    static int port=1200;           //port of candaemon-host
33
    static int port=1200;           //port of candaemon-host
30
   
34
   
31
    static void Main(string[] args) {
35
    static void Main(string[] args) {
32
        bool error = false;
36
        bool error = false;
33
        if (args.Length < 4) {
37
        if (args.Length < 4) {
34
            //if to few arguments then print info and quit
38
            //if to few arguments then print info and quit
35
            printSyntax();
39
            printSyntax();
36
            error = true;
40
            error = true;
37
        }
41
        }
38
 
42
 
39
        if (!error) {
43
        if (!error) {
40
            //parse commandline arguments
44
            //parse commandline arguments
41
            CommandLine=new Arguments(args);
45
            CommandLine=new Arguments(args);
42
           
46
           
43
            //check single arguments
47
            //check single arguments
44
            if (CommandLine["b"] == "true") { aBios = true; }
48
            if (CommandLine["b"] == "true") { aBios = true; }
45
            if (CommandLine["r"] == "true") { aReset = true; }
49
            if (CommandLine["r"] == "true") { aReset = true; }
46
            if (CommandLine["s"] == "true") { aStart = true; }
50
            if (CommandLine["s"] == "true") { aStart = true; }
47
            if (CommandLine["t"] == "true") { aTerminal = true; }
51
            if (CommandLine["t"] == "true") { aTerminal = true; }
48
           
52
           
49
            //check hexfile argument
53
            //check hexfile argument
50
            hexfile = CommandLine["f"];
54
            hexfile = CommandLine["f"];
51
            if (hexfile != null) {
55
            if (hexfile != null) {
52
                sHexfile = true;
56
                sHexfile = true;
53
            }
57
            }
54
            if (!aTerminal && !sHexfile) {
58
            if (!aTerminal && !sHexfile && !aReset && !aStart) {
55
                if (DEBUG_LEVEL>0) { Console.WriteLine("When not in terminal mode a hexfile must be supplied, I quit"); }
59
                if (DEBUG_LEVEL>0) { Console.WriteLine("When not in terminal mode a hexfile, a reset or a start parameter must be supplied, I quit"); }
56
                error = true;
60
                error = true;
57
            }
61
            }
58
           
62
           
59
            //check nodeid argument
63
            //check nodeid argument
60
            string node = CommandLine["n"];
64
            string node = CommandLine["n"];
61
            if (node != null) {
65
            if (node != null) {
62
                if (!parseNodeId(node)) {
66
                if (!parseNodeId(node)) {
63
                    error = true;
67
                    error = true;
64
                }
68
                }
65
            }
69
            }
66
            if (!aTerminal && !sNodeid) {
70
            if (!aTerminal && !sNodeid) {
67
                if (DEBUG_LEVEL>0) { Console.WriteLine("When not in terminal mode a nodeid must be supplied, I quit"); }
71
                if (DEBUG_LEVEL>0) { Console.WriteLine("When not in terminal mode a nodeid must be supplied, I quit"); }
68
                error = true;
72
                error = true;
69
            }
73
            }
70
           
74
           
71
            //check host and port arguments
75
            //check host and port arguments
72
            host = CommandLine["h"];
76
            host = CommandLine["h"];
73
            string sPort = CommandLine["p"];
77
            string sPort = CommandLine["p"];
74
            if ((host == null) || (sPort.Length == 0)) {
78
            if ((host == null) || (sPort.Length == 0)) {
75
                if (DEBUG_LEVEL>0) { printSyntax(); }
79
                if (DEBUG_LEVEL>0) { printSyntax(); }
76
                error = true;
80
                error = true;
77
            } else {
81
            } else {
78
                try {
82
                try {
79
                    port = int.Parse(sPort);
83
                    port = int.Parse(sPort);
80
                } catch {
84
                } catch {
81
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Was not able to parse port, I quit"); }
85
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Was not able to parse port, I quit"); }
82
                    error = true;
86
                    error = true;
83
                }
87
                }
84
            }
88
            }
85
        }
89
        }
86
       
90
       
87
        if  (!error) {
91
        if  (!error) {
88
            //commandline feedback output
92
            //commandline feedback output
89
            if (DEBUG_LEVEL>2) {
93
            if (DEBUG_LEVEL>2) {
90
                Console.WriteLine("canDude settings:");
94
                Console.WriteLine("canDude settings:");
91
                if (sNodeid) { Console.WriteLine("Nodeaddress: 0x" + String.Format("{0:x2}", nodeid)); }
95
                if (sNodeid) { Console.WriteLine("Nodeaddress: 0x" + String.Format("{0:x2}", nodeid)); }
92
                Console.WriteLine("Host: {0}:{1}", host, port);
96
                Console.WriteLine("Host: {0}:{1}", host, port);
93
                if (hexfile != null) { Console.WriteLine("Hexfile: {0}", hexfile); }
97
                if (hexfile != null) { Console.WriteLine("Hexfile: {0}", hexfile); }
94
                Console.Write("Parameters: ");
98
                Console.Write("Parameters: ");
95
                if (aBios) { Console.Write("Bios "); }
99
                if (aBios) { Console.Write("Bios "); }
96
                if (aReset) { Console.Write("Reset "); }
100
                if (aReset) { Console.Write("Reset "); }
97
                if (aStart) { Console.Write("Start "); }
101
                if (aStart) { Console.Write("Start "); }
98
                if (aTerminal) { Console.Write("Terminal"); }
102
                if (aTerminal) { Console.Write("Terminal"); }
99
                Console.WriteLine("");
103
                Console.WriteLine("");
100
            }
104
            }
101
        }
105
        }
102
       
106
       
103
        if (!error) {
107
        if (!error) {
104
            //connect to candaemon
108
            //connect to candaemon
105
            dc = new DaemonConnection();
109
            dc = new DaemonConnection();
106
            if (dc.init(host, port)) {
110
            if (dc.init(host, port)) {
107
                if (DEBUG_LEVEL>1) { Console.WriteLine("Connected to candaemon"); }
111
                if (DEBUG_LEVEL>1) { Console.WriteLine("Connected to candaemon"); }
108
            } else {
112
            } else {
109
                if (DEBUG_LEVEL>0) { Console.WriteLine("Connection to candaemon could not be established, I quit"); }
113
                if (DEBUG_LEVEL>0) { Console.WriteLine("Connection to candaemon could not be established, I quit"); }
110
                error = true;
114
                error = true;
111
            }
115
            }
112
        }
116
        }
113
           
117
           
114
        if (!error && aTerminal) {
118
        if (!error && aTerminal) {
115
            //terminal mode (==interactive mode)
119
            //terminal mode (==interactive mode)
116
            bool success = true;
120
            bool success = true;
117
            //load hexfile if one has been specified as commandline argument
121
            //load hexfile if one has been specified as commandline argument
118
            hf = new HexFile();
122
            hf = new HexFile();
119
            if (sHexfile && success) {
123
            if (sHexfile && success) {
120
                if (hf.loadHex(hexfile)) {
124
                if (hf.loadHex(hexfile)) {
121
                    if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile loaded"); }
125
                    if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile loaded"); }
122
                } else { success = false; }
126
                } else { success = false; }
123
            }
127
            }
124
           
128
           
125
            if (success) {
129
            if (success) {
126
                if (DEBUG_LEVEL>1) {
130
                if (DEBUG_LEVEL>1) {
127
                    Console.WriteLine("");
131
                    Console.WriteLine("");
128
                    printHelp();        //print available commands
132
                    printHelp();        //print available commands
129
                    Console.WriteLine("");
133
                    Console.WriteLine("");
130
                }
134
                }
131
               
135
               
132
                string instr;
136
                string instr;
133
                do {
137
                do {
134
                    Console.Write("> ");            //a command has been executed, print a new console char
138
                    Console.Write("> ");            //a command has been executed, print a new console char
135
                    instr = Console.ReadLine();     //read std in
139
                    instr = Console.ReadLine();     //read std in
136
                } while (parseInput(instr));        //parse a line from std in
140
                } while (parseInput(instr));        //parse a line from std in
137
               
141
               
138
                //exit command
142
                //exit command
139
            }
143
            }
140
        }
144
        }
141
 
145
 
142
        if (!error && !aTerminal) {
146
        if (!error && !aTerminal) {
143
            //not terminal mode
147
            //not terminal mode
144
            bool success = true;
148
            bool success = true;
145
           
149
           
-
 
150
            if (sHexfile) {
146
            //load hexfile (a hexfile must be supplied as commandline argument)
151
                //load hexfile (a hexfile must be supplied as commandline argument)
147
            hf = new HexFile();
152
                hf = new HexFile();
148
            if (hf.loadHex(hexfile)) {
153
                if (hf.loadHex(hexfile)) {
149
                if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile loaded"); }
154
                    if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile loaded"); }
150
            } else {
155
                } else {
151
                success = false;
156
                    success = false;
152
                if (DEBUG_LEVEL>0) { Console.WriteLine("Hexfile could not be loaded, I quit"); }
157
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Hexfile could not be loaded, I quit"); }
-
 
158
                }
153
            }
159
            }
154
           
160
           
155
            //if a hexfile is loaded then start autodownloading sequence
161
            //if a hexfile is loaded then start autodownloading sequence
156
            if (success) {
162
            if (success) {
157
                bool autosuccess = true;
163
                bool autosuccess = true;
158
               
164
               
159
                CanNMT cpn = new CanNMT();
165
                CanNMT cpn = new CanNMT();
160
                if (aReset) {
166
                if (aReset) {
161
                    //send a reset command (and wait for feedback)
167
                    //send a reset command (and wait for feedback)
162
                    if (!cpn.doReset(dc, nodeid)) {
168
                    if (!cpn.doReset(dc, nodeid)) {
163
                        if (DEBUG_LEVEL>0) { Console.WriteLine("Target node did not respond to reset, I quit"); }
169
                        if (DEBUG_LEVEL>0) { Console.WriteLine("Target node did not respond to reset, I quit"); }
164
                        autosuccess = false;
170
                        autosuccess = false;
165
                    }
171
                    }
166
                }
172
                }
167
               
173
               
168
                if (autosuccess) {
174
                if (sHexfile && autosuccess) {
169
                    //send application
175
                    //send application
170
                    dl = new Downloader(hf, dc, nodeid, aBios);
176
                    dl = new Downloader(hf, dc, nodeid, aBios);
171
                    if (!dl.go()) {
177
                    if (!dl.go()) {
172
                        if (DEBUG_LEVEL>0) { Console.WriteLine("Error occured during download"); }
178
                        if (DEBUG_LEVEL>0) { Console.WriteLine("Error occured during download"); }
173
                        autosuccess = false;
179
                        autosuccess = false;
174
                    }
180
                    }
175
                }
181
                }
176
               
182
               
177
                if (autosuccess && aStart) {
183
                if (autosuccess && aStart) {
178
                    //start application
184
                    //start application
179
                    cpn.doStart(dc, nodeid);
185
                    cpn.doStart(dc, nodeid);
180
                }
186
                }
181
               
187
               
182
            }
188
            }
183
        }
189
        }
184
        if (dc != null) {
190
        if (dc != null) {
185
            //stop tcp client thread
191
            //stop tcp client thread
186
            dc.stop();
192
            dc.stop();
187
        }
193
        }
188
    }
194
    }
189
   
195
   
190
    static private void printSyntax() {
196
    static private void printSyntax() {
191
        Console.WriteLine("Syntax: program.exe [options] -h <host> -p <port>");
197
        Console.WriteLine("Syntax: program.exe [options] -h <host> -p <port>");
192
        Console.WriteLine("Host and port are host and port of canDaemon, most likely localhost and 1200.");
198
        Console.WriteLine("Host and port are host and port of canDaemon, most likely localhost and 1200.");
193
        Console.WriteLine("Options:");
199
        Console.WriteLine("Options:");
194
        Console.WriteLine("  -f <hexfile>   Specify a file to be loaded to target.");
200
        Console.WriteLine("  -f <hexfile>   Specify a file to be loaded to target.");
195
        Console.WriteLine("  -n <nodeid>    Id of target node, hex or decimal.");
201
        Console.WriteLine("  -n <nodeid>    Id of target node, hex or decimal.");
196
        Console.WriteLine("  -t             Enter terminal mode.");
202
        Console.WriteLine("  -t             Enter terminal mode.");
197
        Console.WriteLine("  -r             Reset node before loading target.");
203
        Console.WriteLine("  -r             Reset node before loading target.");
198
        Console.WriteLine("  -s             Start node after loading target.");
204
        Console.WriteLine("  -s             Start node after loading target.");
199
        Console.WriteLine("  -b             Program hex as bios, use with caution.");
205
        Console.WriteLine("  -b             Program hex as bios, use with caution.");
200
    }
206
    }
201
   
207
   
202
    static private void printHelp() {
208
    static private void printHelp() {
203
        Console.WriteLine("canDude commands:");
209
        Console.WriteLine("canDude commands:");
204
        Console.WriteLine("load [<hexfile>] - reload hexfile or load new hexfile");
210
        Console.WriteLine("load [<hexfile>] - reload hexfile or load new hexfile");
205
        Console.WriteLine("node <nodeid>    - specify id of target node, hex or decimal");
211
        Console.WriteLine("node <nodeid>    - specify id of target node, hex or decimal");
206
        Console.WriteLine("reset            - reset node");
212
        Console.WriteLine("reset            - reset node");
207
        Console.WriteLine("start            - start application in node (no feedback yet)");
213
        Console.WriteLine("start            - start application in node (no feedback yet)");
208
        Console.WriteLine("go               - start download application to target");
214
        Console.WriteLine("go               - start download application to target");
209
        Console.WriteLine("go bios          - start download bios to target, use with caution");
215
        Console.WriteLine("go bios          - start download bios to target, use with caution");
210
        Console.WriteLine("help             - prints this help");
216
        Console.WriteLine("help             - prints this help");
211
        Console.WriteLine("exit or quit     - exit program");
217
        Console.WriteLine("exit or quit     - exit program");
212
    }  
218
    }  
213
   
219
   
214
    static private bool parseNodeId(string node) {
220
    static private bool parseNodeId(string node) {
215
        // the goal here is to find a byte from 0-255 in a string, format in decimal (0-255) or in hex (0x0-0xff)
221
        // the goal here is to find a byte from 0-255 in a string, format in decimal (0-255) or in hex (0x0-0xff)
216
        // this is probably not done very neat
222
        // this is probably not done very neat
217
        sNodeid = false;
223
        sNodeid = false;
218
        if (node.Length > 0) {
224
        if (node.Length > 0) {
219
            try {
225
            try {
220
                nodeid = byte.Parse(node);
226
                nodeid = byte.Parse(node);
221
                sNodeid = true;
227
                sNodeid = true;
222
            } catch {}
228
            } catch {}
223
        }
229
        }
224
        if (node.Length > 2) {
230
        if (node.Length > 2) {
225
            if (node.Substring(0, 2).Equals("0x")) {
231
            if (node.Substring(0, 2).Equals("0x")) {
226
                if (node.Length == 3) {
232
                if (node.Length == 3) {
227
                    try {
233
                    try {
228
                        nodeid = byte.Parse(node.Substring(2, 1), System.Globalization.NumberStyles.HexNumber);
234
                        nodeid = byte.Parse(node.Substring(2, 1), System.Globalization.NumberStyles.HexNumber);
229
                        sNodeid = true;
235
                        sNodeid = true;
230
                    } catch {
236
                    } catch {
231
                        if (DEBUG_LEVEL>0) { Console.WriteLine("nodeadress parse error 1"); }
237
                        if (DEBUG_LEVEL>0) { Console.WriteLine("nodeadress parse error 1"); }
232
                        return false;
238
                        return false;
233
                    }
239
                    }
234
                } else if (node.Length == 4) {
240
                } else if (node.Length == 4) {
235
                    try {
241
                    try {
236
                        nodeid = byte.Parse(node.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
242
                        nodeid = byte.Parse(node.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
237
                        sNodeid = true;
243
                        sNodeid = true;
238
                    } catch {
244
                    } catch {
239
                        if (DEBUG_LEVEL>0) { Console.WriteLine("nodeadress parse error 2"); }
245
                        if (DEBUG_LEVEL>0) { Console.WriteLine("nodeadress parse error 2"); }
240
                        return false;
246
                        return false;
241
                    }
247
                    }
242
                } else {
248
                } else {
243
                    if (DEBUG_LEVEL>0) { Console.WriteLine("nodeadress parse error 3"); }
249
                    if (DEBUG_LEVEL>0) { Console.WriteLine("nodeadress parse error 3"); }
244
                    return false;
250
                    return false;
245
                }
251
                }
246
            }
252
            }
247
        }
253
        }
248
       
254
       
249
        return true;
255
        return true;
250
    }
256
    }
251
   
257
   
252
    static private bool parseInput(string instr) {
258
    static private bool parseInput(string instr) {
253
        //parse commands entered on std in
259
        //parse commands entered on std in
254
        if (instr.Equals("reset")) {        //reset command, send a reset to current node
260
        if (instr.Equals("reset")) {        //reset command, send a reset to current node
255
            if (sNodeid) {
261
            if (sNodeid) {
256
                dc.flushData();
262
                dc.flushData();
257
                CanNMT cpn = new CanNMT();
263
                CanNMT cpn = new CanNMT();
258
                cpn.doReset(dc, nodeid);
264
                cpn.doReset(dc, nodeid);
259
            } else {
265
            } else {
260
                if (DEBUG_LEVEL>0) { Console.WriteLine("No nodeid has been specified"); }
266
                if (DEBUG_LEVEL>0) { Console.WriteLine("No nodeid has been specified"); }
261
            }
267
            }
262
        }
268
        }
263
        else if (instr.Equals("start")) {   //start command, send a start to current node
269
        else if (instr.Equals("start")) {   //start command, send a start to current node
264
            if (sNodeid) {
270
            if (sNodeid) {
265
                CanNMT cpn = new CanNMT();
271
                CanNMT cpn = new CanNMT();
266
                cpn.doStart(dc, nodeid);
272
                cpn.doStart(dc, nodeid);
267
            } else {
273
            } else {
268
                if (DEBUG_LEVEL>0) { Console.WriteLine("No nodeid has been specified"); }
274
                if (DEBUG_LEVEL>0) { Console.WriteLine("No nodeid has been specified"); }
269
            }
275
            }
270
        }
276
        }
271
        else if (instr.StartsWith("go")) {  //downloading command
277
        else if (instr.StartsWith("go")) {  //downloading command
272
            bool dlBios = false;
278
            bool dlBios = false;
273
            bool error = true;
279
            bool error = true;
274
            if (instr.Equals("go bios")) {  //if bios should be downloaded
280
            if (instr.Equals("go bios")) {  //if bios should be downloaded
275
                dlBios = true;
281
                dlBios = true;
276
                error = false;
282
                error = false;
277
            } else if (instr.Equals("go")) {    //is an application should be downloaded
283
            } else if (instr.Equals("go")) {    //is an application should be downloaded
278
                error = false;
284
                error = false;
279
            }
285
            }
280
           
286
           
281
            if (!sNodeid) {
287
            if (!sNodeid) {
282
                if (DEBUG_LEVEL>0) { Console.WriteLine("No nodeid has been specified"); }
288
                if (DEBUG_LEVEL>0) { Console.WriteLine("No nodeid has been specified"); }
283
                error = true;
289
                error = true;
284
            }
290
            }
285
            if (!sHexfile) {
291
            if (!sHexfile) {
286
                if (DEBUG_LEVEL>0) { Console.WriteLine("No hexfile has been specified"); }
292
                if (DEBUG_LEVEL>0) { Console.WriteLine("No hexfile has been specified"); }
287
                error = true;
293
                error = true;
288
            }
294
            }
289
           
295
           
290
            CanNMT cpn = new CanNMT();
296
            CanNMT cpn = new CanNMT();
291
            if (!error && aReset) {             //commandline arguments specified that a reset should be done before download
297
            if (!error && aReset) {             //commandline arguments specified that a reset should be done before download
292
                //send a reset command (and wait for feedback)
298
                //send a reset command (and wait for feedback)
293
                if (!cpn.doReset(dc, nodeid)) {
299
                if (!cpn.doReset(dc, nodeid)) {
294
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Target node did not respond to reset"); }
300
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Target node did not respond to reset"); }
295
                    error = true;
301
                    error = true;
296
                }
302
                }
297
            }
303
            }
298
               
304
               
299
            if (!error) {
305
            if (!error) {
300
                //send application
306
                //send application
301
                dc.flushData();
307
                dc.flushData();
302
                dl = new Downloader(hf, dc, nodeid, dlBios);
308
                dl = new Downloader(hf, dc, nodeid, dlBios);
303
                if (!dl.go()) {
309
                if (!dl.go()) {
304
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Error occured during download"); }
310
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Error occured during download"); }
305
                    error = true;
311
                    error = true;
306
                }
312
                }
307
            }
313
            }
308
               
314
               
309
            if (!error && aStart) {             //commandline arguments specified that a start should be done after download
315
            if (!error && aStart) {             //commandline arguments specified that a start should be done after download
310
                //start applikation
316
                //start applikation
311
                cpn.doStart(dc, nodeid);
317
                cpn.doStart(dc, nodeid);
312
            }
318
            }
313
           
319
           
314
        }
320
        }
315
        else if (instr.StartsWith("load")) {    //load hexfile or reload current hexfile
321
        else if (instr.StartsWith("load")) {    //load hexfile or reload current hexfile
316
            if (instr.Length > 5) {
322
            if (instr.Length > 5) {
317
                //second argument is a hexfile, this file should be loaded
323
                //second argument is a hexfile, this file should be loaded
318
                hexfile = instr.Substring(5);
324
                hexfile = instr.Substring(5);
319
                if (hf.loadHex(hexfile)) {
325
                if (hf.loadHex(hexfile)) {
320
                    sHexfile = true;
326
                    sHexfile = true;
321
                    if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile loaded"); }
327
                    if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile loaded"); }
322
                } else {
328
                } else {
323
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Hexfile could not be loaded"); }
329
                    if (DEBUG_LEVEL>0) { Console.WriteLine("Hexfile could not be loaded"); }
324
                }
330
                }
325
            } else {
331
            } else {
326
                //reload current hexfile. if a hexfile already has been specified
332
                //reload current hexfile. if a hexfile already has been specified
327
                if (sHexfile) {
333
                if (sHexfile) {
328
                    if (hf.loadHex(hexfile)) {
334
                    if (hf.loadHex(hexfile)) {
329
                        if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile reloaded"); }
335
                        if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile reloaded"); }
330
                    } else {
336
                    } else {
331
                        if (DEBUG_LEVEL>0) { Console.WriteLine("Hexfile could not be reloaded"); }
337
                        if (DEBUG_LEVEL>0) { Console.WriteLine("Hexfile could not be reloaded"); }
332
                    }
338
                    }
333
                } else {
339
                } else {
334
                    if (DEBUG_LEVEL>0) { Console.WriteLine("No hexfile has been specified"); }
340
                    if (DEBUG_LEVEL>0) { Console.WriteLine("No hexfile has been specified"); }
335
                }
341
                }
336
               
342
               
337
            }
343
            }
338
        }
344
        }
339
        else if (instr.StartsWith("node")) {
345
        else if (instr.StartsWith("node")) {
340
            //change nodeid
346
            //change nodeid
341
            if (instr.Length > 5) {
347
            if (instr.Length > 5) {
342
                //second argument is nodeid
348
                //second argument is nodeid
343
                string node = instr.Substring(5);
349
                string node = instr.Substring(5);
344
                parseNodeId(node);
350
                parseNodeId(node);
345
            }
351
            }
346
            if (DEBUG_LEVEL>1) { Console.WriteLine("NodeId is 0x"+ String.Format("{0:x2}", nodeid)); }
352
            if (DEBUG_LEVEL>1) { Console.WriteLine("NodeId is 0x"+ String.Format("{0:x2}", nodeid)); }
347
        }
353
        }
348
        else if (instr.Equals("help")) {
354
        else if (instr.Equals("help")) {
349
            printHelp();
355
            printHelp();
350
        }
356
        }
351
        else if (instr.Equals("exit") || instr.Equals("quit") || instr.Equals("q")) {
357
        else if (instr.Equals("exit") || instr.Equals("quit") || instr.Equals("q")) {
352
            return false;
358
            return false;
353
        }
359
        }
354
        else {
360
        else {
355
            Console.WriteLine("Unknown command.");
361
            Console.WriteLine("Unknown command.");
356
        }
362
        }
357
       
363
       
358
        return true;
364
        return true;
359
    }
365
    }
360
   
366
   
361
}
367
}
362
 
368