Beispiel #1
0
        private static bool parseInput(string instr)
        {
            if (instr.Equals("load")) {
                Console.WriteLine("loading...");
                //string filepath = "/home/arune/eclipse/c/AVR-App/main.hex";
                string filepath = argHexfile;
                hf = new HexFile();
                if (hf.loadHex(filepath)) {
                    Console.WriteLine("done!");
                    Console.WriteLine("File "+filepath+" loaded.");
                    Console.WriteLine("Size: " + hf.getLength().ToString() + " bytes, end adress " + hf.getAddrUpper().ToString() + "(0x" + hf.getAddrUpper().ToString("X") + ").");
                }
                else Console.WriteLine("Error loading " + filepath + "!");

            }
            else if (instr.Equals("go")) {
                Console.WriteLine("Connecting..");
                sc = new SerialConnection();
                try {
                    sc.setConfiguration(argBaud, System.IO.Ports.Parity.None, argPort, System.IO.Ports.StopBits.One, 8, false);
                }
                catch (Exception e) { Console.WriteLine("Error: " + e.Message); return true; }
                if (!sc.open()) { Console.WriteLine("Error opening port."); return true; }
                dl = new Downloader(hf, sc, argReceiverID, false);
                if (!dl.go()) { Console.WriteLine("Error gooing..."); return true; }
                sc.close();
            }
            else if (instr.Equals("go bios")) {
                Console.WriteLine("Connecting..");
                sc = new SerialConnection();
                try {
                    sc.setConfiguration(argBaud, System.IO.Ports.Parity.None, argPort, System.IO.Ports.StopBits.One, 8, false);
                }
                catch (Exception e) { Console.WriteLine("Error: " + e.Message); return true; }
                if (!sc.open()) { Console.WriteLine("Error opening port."); return true; }
                dl = new Downloader(hf, sc, argReceiverID, true);
                if (!dl.go()) { Console.WriteLine("Error gooing..."); return true; }
                sc.close();
            }
            else if (instr.Equals("start")) {
                Console.WriteLine("Starting..");
                sc = new SerialConnection();
                try {
                    sc.setConfiguration(argBaud, System.IO.Ports.Parity.None, argPort, System.IO.Ports.StopBits.One, 8, false);
                }
                catch (Exception e) { Console.WriteLine("Error: " + e.Message); return true; }
                if (!sc.open()) { Console.WriteLine("Error opening port."); return true; }
                byte[] data = new byte[8];
                CanPacket cp = new CanPacket(CAN_NMT, CAN_NMT_START_APP, MY_ID, argReceiverID, 0, data);
                sc.writePacket(cp);
                sc.close();
            }
            else if (instr.Equals("reset")) {
                Console.WriteLine("Resetting..");
                sc = new SerialConnection();
                try {
                    sc.setConfiguration(argBaud, System.IO.Ports.Parity.None, argPort, System.IO.Ports.StopBits.One, 8, false);
                }
                catch (Exception e) { Console.WriteLine("Error: " + e.Message); return true; }
                if (!sc.open()) { Console.WriteLine("Error opening port."); return true; }

                byte[] data = new byte[8];
                CanPacket cp = new CanPacket(CAN_NMT, CAN_NMT_RESET, MY_ID, argReceiverID, 0, data);
                sc.writePacket(cp);
                sc.close();
            }
            else if (instr.Equals("abort")) {
                if (dl != null) dl.abort();
            }
            else if (instr.Equals("exit")) {
                return false;
            }
            else {
                Console.WriteLine("Unknown command.");
            }

            return true;
        }
Beispiel #2
0
        private void download(Downloader.downloadMode downloadmode)
        {
            if (dl != null) { log("Process in progress..."); return; }

            if (downloadmode == Downloader.downloadMode.PROGRAM)
            {
                loadFile(currentLoadedFile);

                if (hf == null) { log("No hexfile loaded."); return; }
            }

            if (currentTarget == null) { log("No target selected."); return; }

            sc = new SerialConnection();
            try
            {
                sc.setConfiguration((int)serialSettings["baud"], (System.IO.Ports.Parity)Enum.Parse(typeof(System.IO.Ports.Parity), serialSettings["parity"].ToString()), (string)serialSettings["port"], (System.IO.Ports.StopBits)Enum.Parse(typeof(System.IO.Ports.StopBits), serialSettings["stopbits"].ToString()), (int)serialSettings["databits"], false);
            }
            catch (Exception e) { log("Error setting serial connection settings: " + e.Message); setTrayIcon(TrayIcon.FAIL); return; }
            if (!sc.open()) { log("Error opening port."); setTrayIcon(TrayIcon.FAIL); return; }

            dl = new Downloader(hf, sc, myid, currentTarget.getTargetId(), downloadmode, tmp_new_id);
            if (!dl.go()) { log("Error downloading/ID change..."); setTrayIcon(TrayIcon.FAIL); return; }
            setTrayIcon(TrayIcon.DOWNLOADING);
            downloadTimeout.Stop();
            downloadTimeout.Start();
            downloadTimeout.Enabled = true;
            if (downloadmode == Downloader.downloadMode.PROGRAM)
            {
                log("Downloading...");
            }
            else if (downloadmode == Downloader.downloadMode.CHANGE_ID)
            {
                log("Changeing ID.");
            }
            dl.threadAbort += new EventHandler(dl_threadAbort);
        }