Rev 466 | Rev 586 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 466 | Rev 473 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 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 |
| Line 37... | Line 41... | ||
| 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; } |
| Line 49... | Line 53... | ||
| 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 |
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"]; |
| Line 111... | Line 115... | ||
| 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"); } |
| Line 141... | Line 145... | ||
| 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; |
| Line 163... | Line 169... | ||
| 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; |