|
| 1 | +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 | + |
| 3 | +/* |
| 4 | + BasicUploader - basic uploader implementation |
| 5 | + Part of the Arduino project - http://www.arduino.cc/ |
| 6 | +
|
| 7 | + Copyright (c) 2012 |
| 8 | + Andrew Dalgleish |
| 9 | +
|
| 10 | + This program is free software; you can redistribute it and/or modify |
| 11 | + it under the terms of the GNU General Public License as published by |
| 12 | + the Free Software Foundation; either version 2 of the License, or |
| 13 | + (at your option) any later version. |
| 14 | +
|
| 15 | + This program is distributed in the hope that it will be useful, |
| 16 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + GNU General Public License for more details. |
| 19 | +
|
| 20 | + You should have received a copy of the GNU General Public License |
| 21 | + along with this program; if not, write to the Free Software Foundation, |
| 22 | + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | + |
| 24 | + $Id$ |
| 25 | +*/ |
| 26 | + |
| 27 | +package processing.app.debug; |
| 28 | + |
| 29 | +import processing.app.Base; |
| 30 | +import processing.app.Preferences; |
| 31 | +import processing.app.Serial; |
| 32 | +import processing.app.SerialException; |
| 33 | + |
| 34 | +import java.io.*; |
| 35 | +import java.util.*; |
| 36 | +import java.util.zip.*; |
| 37 | +import javax.swing.*; |
| 38 | +import gnu.io.*; |
| 39 | + |
| 40 | + |
| 41 | +public class BasicUploader extends Uploader { |
| 42 | + public BasicUploader() { |
| 43 | + } |
| 44 | + |
| 45 | + public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer) |
| 46 | + throws RunnerException, SerialException { |
| 47 | + this.verbose = verbose; |
| 48 | + |
| 49 | + |
| 50 | + // if no protocol is specified for this board, assume it lacks a |
| 51 | + // bootloader and upload using the selected programmer. |
| 52 | + Map<String, String> boardPreferences = Base.getBoardPreferences(); |
| 53 | + if (!usingProgrammer && boardPreferences.get("upload.protocol") != null) { |
| 54 | + // We should never get here - BasicUploader is only for using a programmer |
| 55 | + return false; |
| 56 | + } |
| 57 | + |
| 58 | + String programmer = Preferences.get("programmer"); |
| 59 | + Target target = Base.getTarget(); |
| 60 | + |
| 61 | + if (programmer.indexOf(":") != -1) { |
| 62 | + target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":"))); |
| 63 | + programmer = programmer.substring(programmer.indexOf(":") + 1); |
| 64 | + } |
| 65 | + Map<String, String> programmerPreferences = target.getProgrammers().get(programmer); |
| 66 | + |
| 67 | + String command = programmerPreferences.get("uploader.basic.command"); |
| 68 | + String parameters = programmerPreferences.get("uploader.basic.parameters"); |
| 69 | + |
| 70 | + List commandList = new ArrayList(); |
| 71 | + |
| 72 | + // Try our tools directories first, else assume the command includes the full path |
| 73 | + // |
| 74 | + if ((new File(Base.getHardwarePath() + "/tools/" + command)).exists()) { |
| 75 | + commandList.add(Base.getHardwarePath() + "/tools/" + command); |
| 76 | + } else if ((new File(Base.getHardwarePath() + "/tools/avr/bin/" + command)).exists()) { |
| 77 | + commandList.add(Base.getHardwarePath() + "/tools/avr/bin/" + command); |
| 78 | + } else { |
| 79 | + commandList.add(command); |
| 80 | + } |
| 81 | + |
| 82 | + // If we have any parameters, split them using the first character |
| 83 | + // This lets us define any character for the separator, but you always need at least one. |
| 84 | + // For example: |
| 85 | + // |param1 |
| 86 | + // /param1/param2 |
| 87 | + // |
| 88 | + if (parameters != null) { |
| 89 | + |
| 90 | + // Get the first character to use as a separator, and remove it |
| 91 | + // |
| 92 | + String separator = parameters.substring(0, 1); |
| 93 | + parameters = parameters.substring(1); |
| 94 | + |
| 95 | + // While we have another separator, split the first part off and remember the rest |
| 96 | + // |
| 97 | + while (parameters.indexOf(separator) != -1) { |
| 98 | + commandList.add(parameters.substring(0, parameters.indexOf(separator))); |
| 99 | + parameters = parameters.substring(parameters.indexOf(separator)+1); |
| 100 | + } |
| 101 | + |
| 102 | + // If we have any left, use it |
| 103 | + // |
| 104 | + if (parameters != null) { |
| 105 | + commandList.add(parameters); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + // Add our hex file as the last parameter |
| 110 | + commandList.add(buildPath + File.separator + className + ".hex"); |
| 111 | + |
| 112 | + return executeUploadCommand(commandList); |
| 113 | + } |
| 114 | + |
| 115 | + public boolean burnBootloader() throws RunnerException { |
| 116 | + // BasicUploader does not handle burning a bootloader |
| 117 | + return false; |
| 118 | + } |
| 119 | + |
| 120 | +} |
0 commit comments