public Downloader(HexFile hf, DaemonConnection dc, byte receiveID, bool isBiosUpdate) { this.hf = hf; this.dc = dc; this.receiveID = receiveID; this.isBiosUpdate = isBiosUpdate; }
public bool doReset(DaemonConnection dc, byte receiver, byte sender, uint hwid) { bool success = false; if (HWID_INUSE) { byte[] data = new byte[8]; data[0] = (byte)(hwid&0xff); data[1] = (byte)((hwid>>8)&0xff); data[2] = (byte)((hwid>>16)&0xff); data[3] = (byte)((hwid>>24)&0xff); cp.setData(data); cp.setDataLength(4); } else { setReceiver(receiver); } dc.sendCanPacket(getResetPacket()); CanPacket getcp; running = true; dc.flushData(); for (int i = 0; i < 150; i++) { Thread.Sleep(50); if (dc.getData(out getcp)) { if (isBiosStart(getcp, receiver, hwid)) { success = true; break; } } if (!running) { break; } } if (!success) { Console.WriteLine("Timed out while waiting for node to reset"); } return success; }
public bool doReset(DaemonConnection dc, byte receiver, byte sender) { bool success = false; setReceiver(receiver); dc.sendCanPacket(getResetPacket()); CanPacket getcp; running = true; dc.flushData(); for (int i = 0; i < 150; i++) { Thread.Sleep(50); if (dc.getData(out getcp)) { if (isBiosStart(getcp, receiver)) { success = true; break; } } if (!running) { break; } } if (!success) { Console.WriteLine("Timed out while waiting for node to reset"); } return success; }
public bool doStart(DaemonConnection dc, byte receiver, byte sender) { bool success = true; setReceiver(receiver); dc.sendCanPacket(getStartPacket()); return success; }
public Downloader(HexFile hf, DaemonConnection dc, byte receiveID, bool isBiosUpdate, bool HWID_INUSE, uint hwid) { this.hf = hf; this.dc = dc; this.receiveID = receiveID; this.isBiosUpdate = isBiosUpdate; this.hwid = hwid; this.HWID_INUSE = HWID_INUSE; }
static bool sNodeid = false; //true when a nodeid has been parsed #endregion Fields #region Methods static void Main(string[] args) { bool error = false; if (args.Length < 4) { //if to few arguments then print info and quit printSyntax(); error = true; } if (!error) { //parse commandline arguments CommandLine=new Arguments(args); //check single arguments if (CommandLine["b"] == "true") { aBios = true; } if (CommandLine["r"] == "true") { aReset = true; } if (CommandLine["s"] == "true") { aStart = true; } if (CommandLine["t"] == "true") { aTerminal = true; } //check hexfile argument hexfile = CommandLine["f"]; if (hexfile != null) { sHexfile = true; } if (!aTerminal && !sHexfile && !aReset && !aStart) { if (DEBUG_LEVEL>0) { Console.WriteLine("When not in terminal mode a hexfile, a reset or a start parameter must be supplied, I quit"); } error = true; } //check nodeid argument string node = CommandLine["n"]; if (node != null) { if (!parseNodeId(node)) { error = true; } } if (!aTerminal && !sNodeid) { if (DEBUG_LEVEL>0) { Console.WriteLine("When not in terminal mode a nodeid must be supplied, I quit"); } error = true; } //check host and port arguments host = CommandLine["h"]; string sPort = CommandLine["p"]; if ((host == null) || (sPort.Length == 0)) { if (DEBUG_LEVEL>0) { printSyntax(); } error = true; } else { try { port = int.Parse(sPort); } catch { if (DEBUG_LEVEL>0) { Console.WriteLine("Was not able to parse port, I quit"); } error = true; } } } if (!error) { //commandline feedback output if (DEBUG_LEVEL>2) { Console.WriteLine("canDude settings:"); if (sNodeid) { Console.WriteLine("Nodeaddress: 0x" + String.Format("{0:x2}", nodeid)); } Console.WriteLine("Host: {0}:{1}", host, port); if (hexfile != null) { Console.WriteLine("Hexfile: {0}", hexfile); } Console.Write("Parameters: "); if (aBios) { Console.Write("Bios "); } if (aReset) { Console.Write("Reset "); } if (aStart) { Console.Write("Start "); } if (aTerminal) { Console.Write("Terminal"); } Console.WriteLine(""); } } if (!error) { //connect to candaemon dc = new DaemonConnection(); if (dc.init(host, port)) { if (DEBUG_LEVEL>1) { Console.WriteLine("Connected to candaemon"); } } else { if (DEBUG_LEVEL>0) { Console.WriteLine("Connection to candaemon could not be established, I quit"); } error = true; } } if (!error && aTerminal) { //terminal mode (==interactive mode) bool success = true; //load hexfile if one has been specified as commandline argument hf = new HexFile(); if (sHexfile && success) { if (hf.loadHex(hexfile)) { if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile loaded"); } } else { success = false; } } if (success) { if (DEBUG_LEVEL>1) { Console.WriteLine(""); printHelp(); //print available commands Console.WriteLine(""); } string instr; do { Console.Write("> "); //a command has been executed, print a new console char instr = Console.ReadLine(); //read std in } while (parseInput(instr)); //parse a line from std in //exit command } } if (!error && !aTerminal) { //not terminal mode bool success = true; if (sHexfile) { //load hexfile (a hexfile must be supplied as commandline argument) hf = new HexFile(); if (hf.loadHex(hexfile)) { if (DEBUG_LEVEL>1) { Console.WriteLine("Hexfile loaded"); } } else { success = false; if (DEBUG_LEVEL>0) { Console.WriteLine("Hexfile could not be loaded, I quit"); } } } //if a hexfile is loaded then start autodownloading sequence if (success) { bool autosuccess = true; CanNMT cpn = new CanNMT(); if (aReset) { //send a reset command (and wait for feedback) if (!cpn.doReset(dc, nodeid)) { if (DEBUG_LEVEL>0) { Console.WriteLine("Target node did not respond to reset, I quit"); } autosuccess = false; } } if (sHexfile && autosuccess) { //send application dl = new Downloader(hf, dc, nodeid, aBios); if (!dl.go()) { if (DEBUG_LEVEL>0) { Console.WriteLine("Error occured during download"); } autosuccess = false; } } if (autosuccess && aStart) { //start application cpn.doStart(dc, nodeid); } } } if (dc != null) { //stop tcp client thread dc.stop(); } }
public bool doStart(DaemonConnection dc, byte receiver, uint hwid) { return doStart(dc, receiver, 0, hwid); }
public bool doReset(DaemonConnection dc, byte receiver) { return doReset(dc, receiver, 0); }
public bool doStart(DaemonConnection dc, byte receiver, byte sender, uint hwid) { bool success = true; if (HWID_INUSE) { byte[] data = new byte[8]; data[0] = (byte)(hwid&0xff); data[1] = (byte)((hwid>>8)&0xff); data[2] = (byte)((hwid>>16)&0xff); data[3] = (byte)((hwid>>24)&0xff); cp.setData(data); cp.setDataLength(4); } setReceiver(receiver); dc.sendCanPacket(getStartPacket()); return success; }