Rev 255 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
255 | ligi | 1 | /************************************** |
2 | * |
||
3 | * WatchDog for MK-Connection |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * |
||
7 | * see README for further Infos |
||
8 | * |
||
9 | * |
||
10 | |||
11 | **************************************/ |
||
12 | |||
382 | ligi | 13 | import java.util.Vector; |
14 | import java.io.*; |
||
255 | ligi | 15 | |
16 | public class FirmwareLoader |
||
382 | ligi | 17 | implements Runnable // for http download task |
18 | ,org.ligi.ufo.DUBwiseLangDefs |
||
19 | , DUBwiseUIDefinitions |
||
255 | ligi | 20 | { |
21 | |||
22 | public final static String base_url= "http://mikrocontroller.cco-ev.de/mikrosvn/Projects/DUBwise/trunk/misc/firmwares/"; |
||
23 | boolean got_list=false; |
||
24 | String list_str=""; |
||
25 | |||
26 | String[] names; |
||
27 | String[] filenames; |
||
28 | |||
382 | ligi | 29 | DUBwiseCanvas canvas; |
30 | |||
31 | |||
32 | int selected=0; |
||
33 | public void menu_fire(byte pos) |
||
255 | ligi | 34 | { |
382 | ligi | 35 | |
36 | if ( pos<(names.length-1)) |
||
37 | { |
||
38 | selected=pos; |
||
39 | canvas.chg_state(STATEID_FLASHING); |
||
40 | } |
||
41 | else |
||
42 | canvas.chg_state(STATEID_MAINMENU); |
||
43 | |||
255 | ligi | 44 | } |
45 | |||
382 | ligi | 46 | |
47 | public InputStream get_input_str() |
||
48 | { |
||
49 | if ( selected<fws_in_jar) |
||
50 | return this.getClass().getResourceAsStream("/fw_"+avrsig+"_"+selected+".bin"); |
||
51 | |||
52 | return null; |
||
53 | } |
||
54 | |||
55 | |||
56 | int fws_in_jar=0; |
||
57 | int avrsig; |
||
58 | |||
59 | public FirmwareLoader(int _avrsig,DUBwiseCanvas _canvas) |
||
60 | { |
||
61 | avrsig=_avrsig; |
||
62 | canvas=_canvas; |
||
63 | |||
64 | // firmware files in jar |
||
65 | Vector jar_names_vector = new Vector(); |
||
66 | |||
67 | String tmp_str=""; |
||
68 | try { |
||
69 | InputStream in=this.getClass().getResourceAsStream("/fw_"+avrsig+".lst"); |
||
70 | char ch=0; |
||
71 | while (in.available()>0) |
||
72 | { |
||
73 | if ( (ch=(char)in.read())!='\n') |
||
74 | tmp_str+=ch; |
||
75 | else |
||
76 | { |
||
77 | jar_names_vector.addElement( tmp_str ); |
||
78 | tmp_str=""; |
||
79 | } |
||
80 | |||
81 | } |
||
82 | } |
||
83 | catch (Exception e) {} |
||
84 | |||
85 | fws_in_jar= jar_names_vector.size(); |
||
86 | |||
87 | names=new String[ fws_in_jar+2]; |
||
88 | |||
89 | if ( jar_names_vector.size()>0) |
||
90 | for(int loop=0; loop<fws_in_jar; loop++) |
||
91 | names[loop] = (String)jar_names_vector.elementAt(loop); |
||
92 | |||
93 | names[jar_names_vector.size()]="Download"; |
||
94 | names[jar_names_vector.size()+1]=canvas.l(STRINGID_BACK); |
||
95 | |||
96 | // new Thread( this ).start(); // fire up main Thread |
||
97 | } |
||
98 | |||
255 | ligi | 99 | public void run() |
100 | { |
||
101 | if (!got_list) |
||
102 | { |
||
103 | list_str=DUBwiseHelper.get_http_string(base_url+"list"); |
||
104 | |||
105 | |||
106 | String[] split=DUBwiseHelper.split_str(list_str,"\n"); |
||
107 | names=new String[ split.length]; |
||
108 | filenames=new String[ split.length]; |
||
109 | |||
110 | |||
111 | for ( int i=0;i<split.length;i++) |
||
112 | { |
||
113 | String[] sp2=DUBwiseHelper.split_str(split[i],":"); |
||
114 | if (sp2.length==2) |
||
115 | { |
||
116 | names[i]=sp2[0]; |
||
117 | filenames[i]=sp2[1]; |
||
118 | } |
||
119 | else |
||
120 | names[i]="fail"; |
||
121 | |||
122 | |||
123 | } |
||
124 | |||
125 | System.out.println(list_str); |
||
126 | |||
127 | got_list=true; |
||
128 | } |
||
129 | else |
||
130 | { |
||
131 | |||
132 | } |
||
133 | } |
||
134 | |||
135 | |||
136 | } |