Rev 396 | Rev 427 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 396 | Rev 397 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
42 | // + clearly linked as origin |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | 57 | ||
58 | #include <stdio.h> |
58 | #include <stdio.h> |
59 | #include <stdarg.h> |
59 | #include <stdarg.h> |
60 | #include <string.h> |
60 | #include <string.h> |
61 | #include "91x_lib.h" |
61 | #include "91x_lib.h" |
62 | #include "config.h" |
62 | #include "config.h" |
63 | #include "main.h" |
63 | #include "main.h" |
64 | #include "fat16.h" |
64 | #include "fat16.h" |
65 | #include "ftphelper.h" |
65 | #include "ftphelper.h" |
66 | #include "mkprotocol.h" |
66 | #include "mkprotocol.h" |
67 | #include "debug.h" |
67 | #include "debug.h" |
68 | #include "uart1.h" |
68 | #include "uart1.h" |
69 | 69 | ||
70 | 70 | ||
71 | typedef struct |
71 | typedef struct |
72 | { |
72 | { |
73 | u8 Name[13]; |
73 | u8 Name[13]; |
74 | u8 Attribute; |
74 | u8 Attribute; |
75 | u32 Size; |
75 | u32 Size; |
76 | 76 | ||
77 | } __attribute__((packed)) FTP_direntry_t; |
77 | } __attribute__((packed)) FTP_direntry_t; |
78 | 78 | ||
79 | FTP_direntry_t FTP_direntry; |
79 | FTP_direntry_t FTP_direntry; |
80 | 80 | ||
81 | char FTP_data[DATA_TRANSFER_SIZE+10]; // rx & tx buffer to avoid 2 buffers |
81 | char FTP_data[DATA_TRANSFER_SIZE+10]; // rx & tx buffer to avoid 2 buffers |
82 | 82 | ||
83 | u16 CompressBuffer(char *buf, u16 size, u16 offset) |
83 | u16 CompressBuffer(char *buf, u16 size, u16 offset) |
84 | { |
84 | { |
85 | #define KEYWORD_COUNT 27 |
85 | #define KEYWORD_COUNT 27 |
86 | 86 | ||
87 | const char keyword[KEYWORD_COUNT][16]= |
87 | const char keyword[KEYWORD_COUNT][16]= |
88 | {"Altimeter>\0 \0", |
88 | {"Altimeter>\0 \0", |
89 | "Current>\0 \0", |
89 | "Current>\0 \0", |
90 | "Variometer>\0 \0", |
90 | "Variometer>\0 \0", |
91 | "GroundSpeed>\0 \0", |
91 | "GroundSpeed>\0 \0", |
92 | "VerticalSpeed>\0\0", |
92 | "VerticalSpeed>\0\0", |
93 | "FlightTime>\0 \0", |
93 | "FlightTime>\0 \0", |
94 | "Voltage>\0 \0", |
94 | "Voltage>\0 \0", |
95 | "Capacity>\0 \0", |
95 | "Capacity>\0 \0", |
96 | "RCQuality>\0 \0", |
96 | "RCQuality>\0 \0", |
97 | "RCRSSI>\0 \0", |
97 | "RCRSSI>\0 \0", |
98 | "Compass>\0 \0", |
98 | "Compass>\0 \0", |
99 | "NickAngle>\0 \0", |
99 | "NickAngle>\0 \0", |
100 | "RollAngle>\0 \0", |
100 | "RollAngle>\0 \0", |
101 | "NCFlag>\0 \0", |
101 | "NCFlag>\0 \0", |
102 | "ErrorCode>\0 \0", |
102 | "ErrorCode>\0 \0", |
103 | "TargetBearing>\0\0", |
103 | "TargetBearing>\0\0", |
104 | "RCSticks>\0 \0", |
104 | "RCSticks>\0 \0", |
105 | "GPSSticks>\0 \0", |
105 | "GPSSticks>\0 \0", |
106 | "extensions>\0 \0", |
106 | "extensions>\0 \0", |
107 | "Course>\0 \0", |
107 | "Course>\0 \0", |
108 | "trkpt\0 \0", |
108 | "trkpt\0 \0", |
109 | "time>\0 \0", |
109 | "time>\0 \0", |
110 | "sat>\0 \0", |
110 | "sat>\0 \0", |
111 | "ele>\0 \0", |
111 | "ele>\0 \0", |
112 | " lat=\0 \0", |
112 | " lat=\0 \0", |
113 | " lon=\0 \0", |
113 | " lon=\0 \0", |
114 | "TargetDistance>\0" }; |
114 | "TargetDistance>\0" }; |
115 | u16 i, count = size; |
115 | u16 i, count = size; |
116 | char *s = NULL, *start = buf+offset; |
116 | char *s = NULL, *start = buf+offset; |
117 | 117 | ||
118 | for ( i = 0; i < KEYWORD_COUNT; i++) |
118 | for ( i = 0; i < KEYWORD_COUNT; i++) |
119 | { |
119 | { |
120 | s = strstr(start, keyword[i]); |
120 | s = strstr(start, keyword[i]); |
121 | if (s != NULL) |
121 | if (s != NULL) |
122 | { u8 keylen = strlen(keyword[i]); |
122 | { u8 keylen = strlen(keyword[i]); |
123 | *s= 27; |
123 | *s= 27; |
124 | *(s+1) = i+1; |
124 | *(s+1) = i+1; |
125 | count-= (keylen-2); |
125 | count-= (keylen-2); |
126 | memcpy(s+2, s+keylen, count - (s-buf)); |
126 | memcpy(s+2, s+keylen, count - (s-buf)); |
127 | i--; |
127 | i--; |
128 | } |
128 | } |
129 | } |
129 | } |
130 | 130 | ||
131 | return (count); |
131 | return (count); |
132 | } |
132 | } |
133 | // -------------------------------------------------------------------- |
133 | // -------------------------------------------------------------------- |
134 | void CheckFTPCommand(u8 FTP_command) |
134 | void CheckFTPCommand(u8 FTP_command) |
135 | { |
135 | { |
- | 136 | /* |
|
136 | static Find_t fe; |
137 | static Find_t fe; |
137 | static File_t *fp = NULL; |
138 | static File_t *fp = NULL; |
138 | static u8 blockindex, compressLevel = 0; |
139 | static u8 blockindex, compressLevel = 0; |
139 | 140 | |
|
140 | u32 filesize; |
141 | u32 filesize; |
141 | 142 | ||
142 | switch (FTP_command) |
143 | switch (FTP_command) |
143 | { |
144 | { |
144 | case FTP_CMD_FINDFIRST: |
145 | case FTP_CMD_FINDFIRST: |
145 | FTP_direntry.Name[0] = 0; |
146 | FTP_direntry.Name[0] = 0; |
146 | if (findfirst_("*.*", 0x35, &fe)) |
147 | if (findfirst_("*.*", 0x35, &fe)) |
147 | { |
148 | { |
148 | memcpy(&FTP_direntry.Name, &fe.name, 13); |
149 | memcpy(&FTP_direntry.Name, &fe.name, 13); |
149 | FTP_direntry.Attribute = fe.fp.Attribute; |
150 | FTP_direntry.Attribute = fe.fp.Attribute; |
150 | FTP_direntry.Size = fe.fp.Size; |
151 | FTP_direntry.Size = fe.fp.Size; |
151 | // Debug(FTP_direntry.Name); |
152 | // Debug(FTP_direntry.Name); |
152 | } |
153 | } |
153 | 154 | |
|
154 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry)); |
155 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry)); |
155 | break; |
156 | break; |
156 | 157 | |
|
157 | case FTP_CMD_FINDNEXT: |
158 | case FTP_CMD_FINDNEXT: |
158 | 159 | |
|
159 | FTP_direntry.Name[0] = 0; |
160 | FTP_direntry.Name[0] = 0; |
160 | 161 | ||
161 | if (findnext_(&fe)) |
162 | if (findnext_(&fe)) |
162 | { |
163 | { |
163 | memcpy(&FTP_direntry.Name, &fe.name, 13); |
164 | memcpy(&FTP_direntry.Name, &fe.name, 13); |
164 | FTP_direntry.Attribute = fe.fp.Attribute; |
165 | FTP_direntry.Attribute = fe.fp.Attribute; |
165 | FTP_direntry.Size = fe.fp.Size; |
166 | FTP_direntry.Size = fe.fp.Size; |
166 | // Debug(FTP_direntry.Name); |
167 | // Debug(FTP_direntry.Name); |
167 | } |
168 | } |
168 | 169 | |
|
169 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry)); |
170 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry)); |
170 | break; |
171 | break; |
171 | 172 | |
|
172 | case FTP_CMD_GET_CWD: |
173 | case FTP_CMD_GET_CWD: |
173 | { |
174 | { |
174 | char data_null = 0; |
175 | char data_null = 0; |
175 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, GetPath(), strlen(GetPath()), &data_null, 1 ); |
176 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, GetPath(), strlen(GetPath()), &data_null, 1 ); |
176 | } |
177 | } |
177 | 178 | |
|
178 | break; |
179 | break; |
179 | 180 | |
|
180 | case FTP_CMD_SET_CWD: |
181 | case FTP_CMD_SET_CWD: |
181 | { |
182 | { |
182 | u8 cmd_successful; |
183 | u8 cmd_successful; |
183 | 184 | ||
184 | cmd_successful = chdir_(FTP_data); |
185 | cmd_successful = chdir_(FTP_data); |
185 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
186 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
186 | } |
187 | } |
187 | break; |
188 | break; |
188 | 189 | |
|
189 | case FTP_CMD_DELETE_FILE: // delete file |
190 | case FTP_CMD_DELETE_FILE: // delete file |
190 | { |
191 | { |
191 | u8 cmd_successful = 1; |
192 | u8 cmd_successful = 1; |
192 | 193 | ||
193 | Debug(&FTP_data[0]); |
194 | Debug(&FTP_data[0]); |
194 | 195 | ||
195 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
196 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
196 | 197 | ||
197 | if (fdelete_(&FTP_data[0])) |
198 | if (fdelete_(&FTP_data[0])) |
198 | { |
199 | { |
199 | cmd_successful = 1; |
200 | cmd_successful = 1; |
200 | } |
201 | } |
201 | else cmd_successful = 0; |
202 | else cmd_successful = 0; |
202 | 203 | ||
203 | } |
204 | } |
204 | break; |
205 | break; |
205 | case FTP_CMD_OPEN_FILE: // open the file for reading |
206 | case FTP_CMD_OPEN_FILE: // open the file for reading |
206 | { |
207 | { |
207 | u8 filefound; |
208 | u8 filefound; |
208 | 209 | |
|
209 | compressLevel = FTP_data[0]; |
210 | compressLevel = FTP_data[0]; |
210 | fp = fopen_(&FTP_data[1], 'r'); |
211 | fp = fopen_(&FTP_data[1], 'r'); |
211 | if (fp != NULL) |
212 | if (fp != NULL) |
212 | { |
213 | { |
213 | filefound = 1; |
214 | filefound = 1; |
214 | filesize = fp->Size; |
215 | filesize = fp->Size; |
215 | blockindex = 0; // reset index counter |
216 | blockindex = 0; // reset index counter |
216 | } |
217 | } |
217 | else filefound = 0; // this means, no valid file found for transfer |
218 | else filefound = 0; // this means, no valid file found for transfer |
218 | 219 | ||
219 | 220 | ||
220 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, &filefound, 1, &filesize, sizeof(filesize)); |
221 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, &filefound, 1, &filesize, sizeof(filesize)); |
221 | } |
222 | } |
222 | break; |
223 | break; |
223 | 224 | |
|
224 | case FTP_CMD_GET_FILE_DATA: |
225 | case FTP_CMD_GET_FILE_DATA: |
225 | { |
226 | { |
226 | u16 size = DATA_TRANSFER_SIZE; |
227 | u16 size = DATA_TRANSFER_SIZE; |
227 | 228 | |
|
228 | if (FTP_data[0] == blockindex + 1) // next block is requested |
229 | if (FTP_data[0] == blockindex + 1) // next block is requested |
229 | { |
230 | { |
230 | blockindex++; |
231 | blockindex++; |
231 | } |
232 | } |
232 | else if (FTP_data[0] == blockindex) // repeat last block |
233 | else if (FTP_data[0] == blockindex) // repeat last block |
233 | { |
234 | { |
234 | fseek_(fp, SEEK_CUR, -DATA_TRANSFER_SIZE); // set filepointer to beginning of last block |
235 | fseek_(fp, SEEK_CUR, -DATA_TRANSFER_SIZE); // set filepointer to beginning of last block |
235 | } |
236 | } |
236 | else blockindex = FTP_data[0]+ 10; // ABORT transfer, blockindex now out of valid range |
237 | else blockindex = FTP_data[0]+ 10; // ABORT transfer, blockindex now out of valid range |
237 | 238 | |
|
238 | fread_(FTP_data, DATA_TRANSFER_SIZE, 1, fp); // read data block to buffer); |
239 | fread_(FTP_data, DATA_TRANSFER_SIZE, 1, fp); // read data block to buffer); |
239 | FTP_data[DATA_TRANSFER_SIZE] = 0; |
240 | FTP_data[DATA_TRANSFER_SIZE] = 0; |
240 | 241 | |
|
241 | if (compressLevel) |
242 | if (compressLevel) |
242 | { |
243 | { |
243 | size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, 0); |
244 | size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, 0); |
244 | 245 | |
|
245 | if (compressLevel > 1) |
246 | if (compressLevel > 1) |
246 | { |
247 | { |
247 | if (size < DATA_TRANSFER_SIZE - 50) |
248 | if (size < DATA_TRANSFER_SIZE - 50) |
248 | { |
249 | { |
249 | fread_(&FTP_data[size], DATA_TRANSFER_SIZE - size, 1, fp); // read data block to buffer); |
250 | fread_(&FTP_data[size], DATA_TRANSFER_SIZE - size, 1, fp); // read data block to buffer); |
250 | FTP_data[DATA_TRANSFER_SIZE] = 0; |
251 | FTP_data[DATA_TRANSFER_SIZE] = 0; |
251 | size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, size); |
252 | size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, size); |
252 | } |
253 | } |
253 | } |
254 | } |
254 | } |
255 | } |
255 | 256 | |
|
256 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 4, &FTP_command, 1, &blockindex, 1, &size, 2, &FTP_data, size); |
257 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 4, &FTP_command, 1, &blockindex, 1, &size, 2, &FTP_data, size); |
257 | } |
258 | } |
258 | break; |
259 | break; |
259 | 260 | ||
260 | case FTP_CMD_CLOSE_FILE: |
261 | case FTP_CMD_CLOSE_FILE: |
261 | fclose_(fp); |
262 | fclose_(fp); |
262 | Debug("ftp: CloseFile"); |
263 | Debug("ftp: CloseFile"); |
263 | 264 | ||
264 | break; |
265 | break; |
265 | 266 | ||
266 | case FTP_CMD_CREATE_FILE: // open the file for writing |
267 | case FTP_CMD_CREATE_FILE: // open the file for writing |
267 | { |
268 | { |
268 | u16 size = DATA_TRANSFER_SIZE; |
269 | u16 size = DATA_TRANSFER_SIZE; |
269 | 270 | |
|
270 | //compressLevel = FTP_data[0]; |
271 | //compressLevel = FTP_data[0]; |
271 | compressLevel = 0; // no compression for writing |
272 | compressLevel = 0; // no compression for writing |
272 | 273 | |
|
273 | 274 | ||
274 | fp = fopen_(&FTP_data[5], 'w'); |
275 | fp = fopen_(&FTP_data[5], 'w'); |
275 | if (fp != NULL) |
276 | if (fp != NULL) |
276 | { |
277 | { |
277 | blockindex = 0; // reset index counter |
278 | blockindex = 0; // reset index counter |
278 | } |
279 | } |
279 | else size = 0; // this means, no valid file for transfer (maybe readonly) |
280 | else size = 0; // this means, no valid file for transfer (maybe readonly) |
280 | 281 | ||
281 | if (size == 0) Debug("ftp: create ERR "); |
282 | if (size == 0) Debug("ftp: create ERR "); |
282 | 283 | ||
283 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &size, 2); |
284 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &size, 2); |
284 | } |
285 | } |
285 | break; |
286 | break; |
286 | 287 | ||
287 | case FTP_CMD_SEND_FILE_DATA: |
288 | case FTP_CMD_SEND_FILE_DATA: |
288 | { |
289 | { |
289 | u16 size = (u8)FTP_data[2]; |
290 | u16 size = (u8)FTP_data[2]; |
290 | size *= 0x100; |
291 | size *= 0x100; |
291 | size += (u8) FTP_data[1]; |
292 | size += (u8) FTP_data[1]; |
292 | 293 | ||
293 | 294 | ||
294 | if (FTP_data[0] == blockindex) // next block is requested |
295 | if (FTP_data[0] == blockindex) // next block is requested |
295 | { |
296 | { |
296 | blockindex++; |
297 | blockindex++; |
297 | fwrite_(&FTP_data[3], size, 1, fp); // write data block to buffer); |
298 | fwrite_(&FTP_data[3], size, 1, fp); // write data block to buffer); |
298 | } |
299 | } |
299 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &blockindex, 1 ); |
300 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &blockindex, 1 ); |
300 | } |
301 | } |
301 | break; |
302 | break; |
302 | 303 | ||
303 | case FTP_CMD_NONE: |
304 | case FTP_CMD_NONE: |
304 | default: |
305 | default: |
305 | FTP_command = FTP_CMD_NONE; |
306 | FTP_command = FTP_CMD_NONE; |
306 | Debug("ftp: CMD None"); |
307 | Debug("ftp: CMD None"); |
307 | break; |
308 | break; |
308 | } |
309 | } |
- | 310 | */ |
|
309 | } |
311 | } |
310 | 312 | ||
311 | 313 | ||
312 | 314 | ||
313 | 315 |