Subversion Repositories HomeAutomation

Rev

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

Rev 456 Rev 458
Line 130... Line 130...
130
            }
130
            }
131
           
131
           
132
            if (success) {
132
            if (success) {
133
                if (DEBUG_LEVEL>0) {
133
                if (DEBUG_LEVEL>0) {
134
                    Console.WriteLine("");
134
                    Console.WriteLine("");
135
                    Console.WriteLine("canDude commands:");
135
                    printHelp();
136
                    //Console.WriteLine("reset - reset communication.");
-
 
137
                    Console.WriteLine("exit             - exit program");
-
 
138
                    Console.WriteLine("load [<hexfile>] - reload hexfile or load new hexfile");
-
 
139
                    Console.WriteLine("node <nodeid>    - specify id of target node, hex or decimal");
-
 
140
                    Console.WriteLine("reset            - reset node");
-
 
141
                    Console.WriteLine("start            - start application in node (no feedback yet)");
-
 
142
                    Console.WriteLine("go               - start download application to target");
-
 
143
                    Console.WriteLine("go bios          - start download bios to target, use with caution");
-
 
144
                    Console.WriteLine("");
136
                    Console.WriteLine("");
145
                    //Thread.Sleep(1000);
137
                    //Thread.Sleep(1000);
146
                }
138
                }
147
               
139
               
148
                string instr;
140
                string instr;
Line 205... Line 197...
205
                }
197
                }
206
               
198
               
207
            }
199
            }
208
        }
200
        }
209
    }
201
    }
-
 
202
   
-
 
203
    static private void printHelp() {
-
 
204
        Console.WriteLine("canDude commands:");
-
 
205
        //Console.WriteLine("reset - reset communication.");
-
 
206
        Console.WriteLine("load [<hexfile>] - reload hexfile or load new hexfile");
-
 
207
        Console.WriteLine("node <nodeid>    - specify id of target node, hex or decimal");
-
 
208
        Console.WriteLine("reset            - reset node");
-
 
209
        Console.WriteLine("start            - start application in node (no feedback yet)");
-
 
210
        Console.WriteLine("go               - start download application to target");
-
 
211
        Console.WriteLine("go bios          - start download bios to target, use with caution");
-
 
212
        Console.WriteLine("help             - prints this help");
-
 
213
        Console.WriteLine("exit or quit     - exit program");
-
 
214
    }  
210
   
215
   
211
    static private bool parseNodeId(string node) {
216
    static private bool parseNodeId(string node) {
212
        sNodeid = false;
217
        sNodeid = false;
213
        if (node.Length > 0) {
218
        if (node.Length > 0) {
214
            try {
219
            try {
Line 219... Line 224...
219
        if (node.Length > 2) {
224
        if (node.Length > 2) {
220
            if (node.Substring(0, 2).Equals("0x")) {
225
            if (node.Substring(0, 2).Equals("0x")) {
221
                if (node.Length == 3) {
226
                if (node.Length == 3) {
222
                    try {
227
                    try {
223
                        nodeid = byte.Parse(node.Substring(2, 1), System.Globalization.NumberStyles.HexNumber);
228
                        nodeid = byte.Parse(node.Substring(2, 1), System.Globalization.NumberStyles.HexNumber);
224
                        sNodeid = true;
229
                        sNodeid = true;
225
                    } catch {
230
                    } catch {
226
                        Console.WriteLine("nodeadress error!");
231
                        Console.WriteLine("nodeadress error!");
227
                        return false;
232
                        return false;
228
                    }
233
                    }
229
                } else if (node.Length == 4) {
234
                } else if (node.Length == 4) {
230
                    try {
235
                    try {
231
                        nodeid = byte.Parse(node.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
236
                        nodeid = byte.Parse(node.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
232
                        sNodeid = true;
237
                        sNodeid = true;
233
                    } catch {
238
                    } catch {
Line 235... Line 240...
235
                        return false;
240
                        return false;
236
                    }
241
                    }
237
                } else {
242
                } else {
238
                    Console.WriteLine("nodeadress error!");
243
                    Console.WriteLine("nodeadress error!");
239
                    return false;
244
                    return false;
240
                }
245
                }
241
            }
246
            }
242
        }
247
        }
243
       
248
       
244
        return true;
249
        return true;
245
    }
250
    }
246
   
251
   
247
    static private bool parseInput(string instr) {
252
    static private bool parseInput(string instr) {
Line 283... Line 288...
283
            CanNMT cpn = new CanNMT();
288
            CanNMT cpn = new CanNMT();
284
            if (!error && aReset) {
289
            if (!error && aReset) {
285
                //send a reset command (and wait for feedback)
290
                //send a reset command (and wait for feedback)
286
                if (!cpn.doReset(dc, nodeid)) {
291
                if (!cpn.doReset(dc, nodeid)) {
287
                    Console.WriteLine("Target node did not respond to reset");
292
                    Console.WriteLine("Target node did not respond to reset");
288
                    error = true;
293
                    error = true;
289
                }
294
                }
290
            }
295
            }
291
               
296
               
292
            if (!error) {
297
            if (!error) {
293
                //send application
298
                //send application
294
                dl = new Downloader(hf, dc, nodeid, dlBios);
299
                dl = new Downloader(hf, dc, nodeid, dlBios);
295
                if (!dl.go()) {
300
                if (!dl.go()) {
Line 301... Line 306...
301
            if (!error && aStart) {
306
            if (!error && aStart) {
302
                //start applikation
307
                //start applikation
303
                cpn.doStart(dc, nodeid);
308
                cpn.doStart(dc, nodeid);
304
            }
309
            }
305
           
310
           
306
        }
311
        }
307
        else if (instr.StartsWith("load")) {
312
        else if (instr.StartsWith("load")) {
308
            if (instr.Length > 5) {
313
            if (instr.Length > 5) {
309
                //second argument is a hexfile, this file should be loaded
314
                //second argument is a hexfile, this file should be loaded
310
                hexfile = instr.Substring(5);
315
                hexfile = instr.Substring(5);
311
                if (hf.loadHex(hexfile)) {
316
                if (hf.loadHex(hexfile)) {
Line 335... Line 340...
335
                string node = instr.Substring(5);
340
                string node = instr.Substring(5);
336
                parseNodeId(node);
341
                parseNodeId(node);
337
            }
342
            }
338
            Console.WriteLine("NodeId is 0x"+ String.Format("{0:x2}", nodeid));
343
            Console.WriteLine("NodeId is 0x"+ String.Format("{0:x2}", nodeid));
339
        }
344
        }
340
        else if (instr.Equals("exit")) {
345
        else if (instr.Equals("help")) {
-
 
346
            printHelp();
-
 
347
        }
-
 
348
        else if (instr.Equals("exit") || instr.Equals("quit")) {
341
            return false;
349
            return false;
342
        }
350
        }
343
        else {
351
        else {
344
            Console.WriteLine("Unknown command.");
352
            Console.WriteLine("Unknown command.");
345
        }
353
        }