Subversion Repositories svn.mios

Rev

Rev 693 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 693 Rev 721
Line 29... Line 29...
29
import org.midibox.utils.Utils;
29
import org.midibox.utils.Utils;
30
30
31
public class HexFileUpload extends MIOSSysexSendReceive {
31
public class HexFileUpload extends MIOSSysexSendReceive {
32
32
33
    public final static Object FILE = new Object();
33
    public final static Object FILE = new Object();
34
-
 
35
    public final static Object BANKSTICK_NO = new Object();
-
 
36
34
37
    public final static Object UPLOAD_MODE = new Object();
35
    public final static Object UPLOAD_MODE = new Object();
38
36
39
    public final static Object WAIT_FOR_UPLOAD = new Object();
37
    public final static Object WAIT_FOR_UPLOAD = new Object();
40
38
Line 46... Line 44...
46
44
47
    public final static int DUMB_MODE = 1;
45
    public final static int DUMB_MODE = 1;
48
46
49
    private File file;
47
    private File file;
50
48
51
    private int bankstickNo;
49
    //private int bankstickNo;
52
50
53
    private int uploadMode;
51
    private int uploadMode;
54
52
55
    private boolean waitForUploadRequest;
53
    private boolean waitForUploadRequest;
56
54
Line 82... Line 80...
82
80
83
    private int nUploadCase;
81
    private int nUploadCase;
84
82
85
    public HexFileUpload(Receiver receiver) {
83
    public HexFileUpload(Receiver receiver) {
86
        super(receiver);
84
        super(receiver);
87
-
 
88
        this.bankstickNo = 0;
-
 
89
-
 
90
        this.deviceID = 0;
-
 
91
85
92
        this.waitForUploadRequest = false;
86
        this.waitForUploadRequest = false;
93
87
94
        this.uploadMode = 0;
88
        this.uploadMode = 0;
95
89
Line 115... Line 109...
115
        clearChanged();
109
        clearChanged();
116
    }
110
    }
117
111
118
    public void readHexFile() {
112
    public void readHexFile() {
119
        hexFile = new HexFile();
113
        hexFile = new HexFile();
120
        fileLastMIOS32_Mode = getMIOS32_Mode();
114
        fileLastMIOS32_Mode = isMIOS32Mode();
121
        if (!hexFile.read(file.getPath(), fileLastMIOS32_Mode)) {
115
        if (!hexFile.read(file.getPath(), fileLastMIOS32_Mode)) {
122
            // TODO
116
            // TODO
123
        }
117
        }
124
    }
118
    }
125
119
126
    public int getBankstickNo() {
-
 
127
        return bankstickNo;
-
 
128
    }
-
 
129
-
 
130
    public void setBankstickNo(int bankstickNo) {
-
 
131
        this.bankstickNo = bankstickNo;
-
 
132
-
 
133
        setChanged();
-
 
134
        notifyObservers(BANKSTICK_NO);
-
 
135
        clearChanged();
-
 
136
    }
-
 
137
120
138
    public int getDelayTime() {
121
    public int getDelayTime() {
139
        return delayTime;
122
        return delayTime;
140
    }
123
    }
141
124
Line 185... Line 168...
185
       
168
       
186
        synchronized (this) {
169
        synchronized (this) {
187
170
188
            addMessage("Starting upload of " + file.getName());
171
            addMessage("Starting upload of " + file.getName());
189
172
190
            if (fileLastMIOS32_Mode != getMIOS32_Mode()) {
173
            if (fileLastMIOS32_Mode != isMIOS32Mode()) {
191
                addMessage("MIOS version has been changed - reloading file");
174
                addMessage("MIOS version has been changed - reloading file");
192
                readHexFile();
175
                readHexFile();
193
            }
176
            }
194
177
195
            // TK: determine .hex file type, we have three cases:
178
            // TK: determine .hex file type, we have three cases:
Line 215... Line 198...
215
198
216
            expectUploadRequest = false;
199
            expectUploadRequest = false;
217
            expectDummyError = false;
200
            expectDummyError = false;
218
            boolean forceRebootReq = false;
201
            boolean forceRebootReq = false;
219
202
220
            if (!getMIOS32_Mode()) {
203
            if (!isMIOS32Mode()) {
221
                for (int i = 0; i < hexFile.getBlockCount(); ++i) {
204
                for (int i = 0; i < hexFile.getBlockCount(); ++i) {
222
                    Block block = hexFile.getBlock(i);
205
                    Block block = hexFile.getBlock(i);
223
                    long lAddressMapped = block.lAddressMapped;
206
                    long lAddressMapped = block.lAddressMapped;
224
                    if (lAddressMapped >= 0x0000 && lAddressMapped <= 0x2fff) {
207
                    if (lAddressMapped >= 0x0000 && lAddressMapped <= 0x2fff) {
225
                        nUploadCase = 1;
208
                        nUploadCase = 1;
Line 306... Line 289...
306
                    addMessage("Upload of " + (totalBlocks * 256)
289
                    addMessage("Upload of " + (totalBlocks * 256)
307
                            + " bytes completed after " + timeUpload + "s ("
290
                            + " bytes completed after " + timeUpload + "s ("
308
                            + transferRateKb + " kb/s)");
291
                            + transferRateKb + " kb/s)");
309
292
310
                    // reboot BSL in MIOS32 mode
293
                    // reboot BSL in MIOS32 mode
311
                    if (getMIOS32_Mode()) {
294
                    if (isMIOS32Mode()) {
312
                        forceReboot();
295
                        forceReboot();
313
                    } else {
296
                    } else {
314
                       
297
                       
315
                        setChanged();
298
                        setChanged();
316
                        notifyObservers(REBOOT);
299
                        notifyObservers(REBOOT);
Line 327... Line 310...
327
                byte[] axDumpData = Utils.convertTo7Bit(block.axData);
310
                byte[] axDumpData = Utils.convertTo7Bit(block.axData);
328
311
329
                long lAddressExtension = 0x00;
312
                long lAddressExtension = 0x00;
330
                byte[] axAddress;
313
                byte[] axAddress;
331
314
332
                if (!getMIOS32_Mode()) {
315
                if (!isMIOS32Mode()) {
333
                    // build address/len field of MIOS SysEx message
316
                    // build address/len field of MIOS SysEx message
334
317
335
                    if (lAddress >= HexFile.HEX_FILE_FLASH_ADDRESS_START
318
                    if (lAddress >= HexFile.HEX_FILE_FLASH_ADDRESS_START
336
                            && lAddress <= HexFile.HEX_FILE_FLASH_ADDRESS_END) {
319
                            && lAddress <= HexFile.HEX_FILE_FLASH_ADDRESS_END) {
337
                        lAddressExtension = (lAddress >> 15) & 0x07;
320
                        lAddressExtension = (lAddress >> 15) & 0x07;
Line 448... Line 431...
448
        }
431
        }
449
    }
432
    }
450
433
451
    public void createQuery() {
434
    public void createQuery() {
452
435
453
        if (!getMIOS32_Mode()) {
436
        if (!isMIOS32Mode()) {
454
            addMessage("Query is only supported for MIOS32");
437
            addMessage("Query is only supported for MIOS32");
455
            return;
438
            return;
456
        }
439
        }
457
440
458
        expectQueryReply = false;
441
        expectQueryReply = false;
Line 514... Line 497...
514
497
515
    public void forceReboot() {
498
    public void forceReboot() {
516
499
517
        byte[] forceRebootCode;
500
        byte[] forceRebootCode;
518
501
519
        if (getMIOS32_Mode()) {
502
        if (isMIOS32Mode()) {
520
            forceRebootCode = new byte[9];
503
            forceRebootCode = new byte[9];
521
            forceRebootCode[0] = (byte) 0xF0;
504
            forceRebootCode[0] = (byte) 0xF0;
522
            forceRebootCode[1] = (byte) 0x00;
505
            forceRebootCode[1] = (byte) 0x00;
523
            forceRebootCode[2] = (byte) 0x00;
506
            forceRebootCode[2] = (byte) 0x00;
524
            forceRebootCode[3] = (byte) 0x7E;
507
            forceRebootCode[3] = (byte) 0x7E;