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