Rev 427 | Rev 435 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 427 | Rev 434 | ||
---|---|---|---|
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 | } __attribute__((packed)) FTP_direntry_t; |
76 | } __attribute__((packed)) FTP_direntry_t; |
77 | 77 | ||
78 | FTP_direntry_t FTP_direntry; |
78 | FTP_direntry_t FTP_direntry; |
79 | 79 | ||
80 | char FTP_data[DATA_TRANSFER_SIZE+10]; // rx & tx buffer to avoid 2 buffers |
80 | char FTP_data[DATA_TRANSFER_SIZE+10]; // rx & tx buffer to avoid 2 buffers |
81 | 81 | ||
82 | u16 CompressBuffer(char *buf, u16 size, u16 offset) |
82 | u16 CompressBuffer(char *buf, u16 size, u16 offset) |
83 | { |
83 | { |
84 | #define KEYWORD_COUNT 27 |
84 | #define KEYWORD_COUNT 44 |
85 | 85 | ||
86 | // most used gpx tags can be compressed |
86 | // most used gpx tags can be compressed |
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 | "name>\0 \0", |
|
- | 115 | "FCFlags2>\0 \0", |
|
- | 116 | "MagnetField>\0 \0", |
|
- | 117 | "trkseg>\0 \0", |
|
- | 118 | "MotorCurrent>\0 \0", |
|
- | 119 | "AnalogInputs>\0 \0", |
|
- | 120 | "Servo>\0 \0", |
|
- | 121 | "BL_State>\0 \0", |
|
- | 122 | "BL_MaxPWM>\0 \0", |
|
- | 123 | "MikroKopter\0 \0", |
|
- | 124 | "metadata>\0 \0", |
|
- | 125 | "<WP>----,0,0,0<\0", |
|
- | 126 | "MagnetInclinati\0", |
|
- | 127 | "BL_Temperature<\0", |
|
- | 128 | "AvaiableMotorPo\0", |
|
- | 129 | "FC_I2C_ErrorCom\0", |
|
- | 130 | "FC_SPI_ErrorCom\0", |
|
114 | "TargetDistance>\0" }; |
131 | "TargetDistance>\0" }; |
- | 132 | ||
115 | u16 i, count = size; |
133 | u16 i, count = size; |
116 | char *s = NULL, *start = buf+offset; |
134 | char *s = NULL, *start = buf+offset; |
117 | 135 | ||
118 | for ( i = 0; i < KEYWORD_COUNT; i++) |
136 | for ( i = 0; i < KEYWORD_COUNT; i++) |
119 | { |
137 | { |
120 | s = strstr(start, keyword[i]); |
138 | s = strstr(start, keyword[i]); |
121 | if (s != NULL) |
139 | if (s != NULL) |
122 | { u8 keylen = strlen(keyword[i]); |
140 | { u8 keylen = strlen(keyword[i]); |
123 | *s= 27; |
141 | *s= 27; |
124 | *(s+1) = i+1; |
142 | *(s+1) = i+1; |
125 | count-= (keylen-2); |
143 | count-= (keylen-2); |
126 | memcpy(s+2, s+keylen, count - (s-buf)); |
144 | memcpy(s+2, s+keylen, count - (s-buf)); |
127 | i--; |
145 | i--; |
128 | } |
146 | } |
129 | } |
147 | } |
130 | 148 | ||
131 | return (count); |
149 | return (count); |
132 | } |
150 | } |
133 | // -------------------------------------------------------------------- |
151 | // -------------------------------------------------------------------- |
134 | void CheckFTPCommand(u8 FTP_command) |
152 | void CheckFTPCommand(u8 FTP_command) |
135 | { |
153 | { |
136 | static Find_t fe; |
154 | static Find_t fe; |
137 | static File_t *fp = NULL; |
155 | static File_t *fp = NULL; |
138 | static u8 blockindex, compressLevel = 0; |
156 | static u8 blockindex, compressLevel = 0; |
139 | 157 | ||
140 | u32 filesize; |
158 | u32 filesize; |
141 | 159 | ||
142 | switch (FTP_command) |
160 | switch (FTP_command) |
143 | { |
161 | { |
144 | case FTP_CMD_FINDFIRST: |
162 | case FTP_CMD_FINDFIRST: |
145 | FTP_direntry.Name[0] = 0; |
163 | FTP_direntry.Name[0] = 0; |
146 | // any file or directory except volume labels and hidden files |
164 | // any file or directory except volume labels and hidden files |
147 | if(findfirst_("*.*", (ATTR_ARCHIVE|ATTR_SUBDIRECTORY|ATTR_SYSTEM|ATTR_READONLY), &fe)) |
165 | if(findfirst_("*.*", (ATTR_ARCHIVE|ATTR_SUBDIRECTORY|ATTR_SYSTEM|ATTR_READONLY), &fe)) |
148 | { |
166 | { |
149 | memcpy(&FTP_direntry.Name, &fe.name, 13); |
167 | memcpy(&FTP_direntry.Name, &fe.name, 13); |
150 | FTP_direntry.Attribute = fe.fp.Attribute; |
168 | FTP_direntry.Attribute = fe.fp.Attribute; |
151 | FTP_direntry.Size = fe.fp.Size; |
169 | FTP_direntry.Size = fe.fp.Size; |
152 | } |
170 | } |
153 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry)); |
171 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry)); |
154 | break; |
172 | break; |
155 | 173 | ||
156 | case FTP_CMD_FINDNEXT: |
174 | case FTP_CMD_FINDNEXT: |
157 | FTP_direntry.Name[0] = 0; |
175 | FTP_direntry.Name[0] = 0; |
158 | if (findnext_(&fe)) |
176 | if (findnext_(&fe)) |
159 | { |
177 | { |
160 | memcpy(&FTP_direntry.Name, &fe.name, 13); |
178 | memcpy(&FTP_direntry.Name, &fe.name, 13); |
161 | FTP_direntry.Attribute = fe.fp.Attribute; |
179 | FTP_direntry.Attribute = fe.fp.Attribute; |
162 | FTP_direntry.Size = fe.fp.Size; |
180 | FTP_direntry.Size = fe.fp.Size; |
163 | } |
181 | } |
164 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry)); |
182 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry)); |
165 | break; |
183 | break; |
166 | 184 | ||
167 | case FTP_CMD_GET_CWD: // get current working directory |
185 | case FTP_CMD_GET_CWD: // get current working directory |
168 | { |
186 | { |
169 | char data_null = 0; |
187 | char data_null = 0; |
170 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, getcwd_(), strlen(getcwd_()), &data_null, 1 ); |
188 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, getcwd_(), strlen(getcwd_()), &data_null, 1 ); |
171 | } |
189 | } |
172 | break; |
190 | break; |
173 | 191 | ||
174 | case FTP_CMD_SET_CWD: // set current working directory |
192 | case FTP_CMD_SET_CWD: // set current working directory |
175 | { |
193 | { |
176 | u8 cmd_successful; |
194 | u8 cmd_successful; |
177 | cmd_successful = chdir_(FTP_data); |
195 | cmd_successful = chdir_(FTP_data); |
178 | 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); |
179 | } |
197 | } |
180 | break; |
198 | break; |
181 | 199 | ||
182 | case FTP_CMD_CDUP: // change dir up |
200 | case FTP_CMD_CDUP: // change dir up |
183 | { |
201 | { |
184 | u8 cmd_successful; |
202 | u8 cmd_successful; |
185 | cmd_successful = chdir_(".."); |
203 | cmd_successful = chdir_(".."); |
186 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
204 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
187 | } |
205 | } |
188 | break; |
206 | break; |
189 | 207 | ||
190 | case FTP_CMD_MKDIR: // create directory |
208 | case FTP_CMD_MKDIR: // create directory |
191 | { |
209 | { |
192 | u8 cmd_successful; |
210 | u8 cmd_successful; |
193 | cmd_successful = mkdir_(&FTP_data[0]); |
211 | cmd_successful = mkdir_(&FTP_data[0]); |
194 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
212 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
195 | } |
213 | } |
196 | break; |
214 | break; |
197 | 215 | ||
198 | case FTP_CMD_RMDIR: // delete directory |
216 | case FTP_CMD_RMDIR: // delete directory |
199 | { |
217 | { |
200 | u8 cmd_successful; |
218 | u8 cmd_successful; |
201 | cmd_successful = rmdir_(&FTP_data[0]); |
219 | cmd_successful = rmdir_(&FTP_data[0]); |
202 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
220 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
203 | } |
221 | } |
204 | break; |
222 | break; |
205 | 223 | ||
206 | case FTP_CMD_DELETE_FILE: // delete file |
224 | case FTP_CMD_DELETE_FILE: // delete file |
207 | { |
225 | { |
208 | u8 cmd_successful; |
226 | u8 cmd_successful; |
209 | cmd_successful = fdelete_(&FTP_data[0]); |
227 | cmd_successful = fdelete_(&FTP_data[0]); |
210 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
228 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1); |
211 | } |
229 | } |
212 | break; |
230 | break; |
213 | 231 | ||
214 | case FTP_CMD_OPEN_FILE: // open the file for reading |
232 | case FTP_CMD_OPEN_FILE: // open the file for reading |
215 | { |
233 | { |
216 | u8 filefound; |
234 | u8 filefound; |
217 | compressLevel = FTP_data[0]; |
235 | compressLevel = FTP_data[0]; |
218 | fp = fopen_(&FTP_data[1], 'r'); |
236 | fp = fopen_(&FTP_data[1], 'r'); |
219 | if (fp != NULL) |
237 | if (fp != NULL) |
220 | { |
238 | { |
221 | filefound = 1; |
239 | filefound = 1; |
222 | filesize = fp->Size; |
240 | filesize = fp->Size; |
223 | blockindex = 0; // reset index counter |
241 | blockindex = 0; // reset index counter |
224 | } |
242 | } |
225 | else filefound = 0; // this means, no valid file found for transfer |
243 | else filefound = 0; // this means, no valid file found for transfer |
226 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, &filefound, 1, &filesize, sizeof(filesize)); |
244 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, &filefound, 1, &filesize, sizeof(filesize)); |
227 | } |
245 | } |
228 | break; |
246 | break; |
229 | 247 | ||
230 | case FTP_CMD_GET_FILE_DATA: |
248 | case FTP_CMD_GET_FILE_DATA: |
231 | { |
249 | { |
232 | u16 size = DATA_TRANSFER_SIZE; |
250 | u16 size = DATA_TRANSFER_SIZE; |
233 | if (FTP_data[0] == blockindex + 1) // next block is requested |
251 | if (FTP_data[0] == blockindex + 1) // next block is requested |
234 | { |
252 | { |
235 | blockindex++; |
253 | blockindex++; |
236 | } |
254 | } |
237 | else |
255 | else |
238 | { |
256 | { |
239 | u32 filepos; |
257 | u32 filepos; |
240 | blockindex = FTP_data[0]; |
258 | blockindex = FTP_data[0]; |
241 | filepos = FTP_data[1]; |
259 | filepos = FTP_data[1]; |
242 | filepos |= ((u32)FTP_data[2] * 0x100); |
260 | filepos |= ((u32)FTP_data[2] * 0x100); |
243 | filepos |= ((u32) FTP_data[3] * 0x10000L); |
261 | filepos |= ((u32) FTP_data[3] * 0x10000L); |
244 | filepos |= ((u32) FTP_data[4] * 0x1000000L); |
262 | filepos |= ((u32) FTP_data[4] * 0x1000000L); |
245 | fseek_(fp, filepos, SEEK_SET); // set filepointer to beginning of requested block |
263 | fseek_(fp, filepos, SEEK_SET); // set filepointer to beginning of requested block |
246 | } |
264 | } |
247 | 265 | ||
248 | fread_(FTP_data, DATA_TRANSFER_SIZE, 1, fp); // read data block to buffer); |
266 | fread_(FTP_data, DATA_TRANSFER_SIZE, 1, fp); // read data block to buffer); |
249 | FTP_data[DATA_TRANSFER_SIZE] = 0; |
267 | FTP_data[DATA_TRANSFER_SIZE] = 0; |
250 | 268 | ||
251 | if (compressLevel) |
269 | if (compressLevel) |
252 | { |
270 | { |
253 | size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, 0); |
271 | size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, 0); |
254 | 272 | ||
255 | if (compressLevel > 1) |
273 | if (compressLevel > 1) |
256 | { |
274 | { |
257 | if (size < DATA_TRANSFER_SIZE - 50) |
275 | if (size < DATA_TRANSFER_SIZE - 50) |
258 | { |
276 | { |
259 | fread_(&FTP_data[size], DATA_TRANSFER_SIZE - size, 1, fp); // read data block to buffer); |
277 | fread_(&FTP_data[size], DATA_TRANSFER_SIZE - size, 1, fp); // read data block to buffer); |
260 | FTP_data[DATA_TRANSFER_SIZE] = 0; |
278 | FTP_data[DATA_TRANSFER_SIZE] = 0; |
261 | size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, size); |
279 | size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, size); |
262 | } |
280 | } |
263 | } |
281 | } |
264 | } |
282 | } |
265 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 4, &FTP_command, 1, &blockindex, 1, &size, 2, &FTP_data, size); |
283 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 4, &FTP_command, 1, &blockindex, 1, &size, 2, &FTP_data, size); |
266 | } |
284 | } |
267 | break; |
285 | break; |
268 | 286 | ||
269 | case FTP_CMD_CLOSE_FILE: |
287 | case FTP_CMD_CLOSE_FILE: |
270 | fclose_(fp); |
288 | fclose_(fp); |
271 | Debug("ftp: CloseFile"); |
289 | Debug("ftp: CloseFile"); |
272 | break; |
290 | break; |
273 | 291 | ||
274 | case FTP_CMD_CREATE_FILE: // open the file for writing |
292 | case FTP_CMD_CREATE_FILE: // open the file for writing |
275 | { |
293 | { |
276 | u16 size = DATA_TRANSFER_SIZE; |
294 | u16 size = DATA_TRANSFER_SIZE; |
277 | //compressLevel = FTP_data[0]; |
295 | //compressLevel = FTP_data[0]; |
278 | // FTP_data[1..4] contains filesize in bytes |
296 | // FTP_data[1..4] contains filesize in bytes |
279 | compressLevel = 0; // no compression for writing |
297 | compressLevel = 0; // no compression for writing |
280 | fp = fopen_(&FTP_data[5], 'w'); |
298 | fp = fopen_(&FTP_data[5], 'w'); |
281 | if (fp != NULL) |
299 | if (fp != NULL) |
282 | { |
300 | { |
283 | blockindex = 0; // reset index counter |
301 | blockindex = 0; // reset index counter |
284 | } |
302 | } |
285 | else size = 0; // this means, no valid file for transfer (maybe readonly) |
303 | else size = 0; // this means, no valid file for transfer (maybe readonly) |
286 | //if (size == 0) Debug("ftp: create ERR "); |
304 | //if (size == 0) Debug("ftp: create ERR "); |
287 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &size, 2); |
305 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &size, 2); |
288 | } |
306 | } |
289 | break; |
307 | break; |
290 | 308 | ||
291 | case FTP_CMD_SEND_FILE_DATA: |
309 | case FTP_CMD_SEND_FILE_DATA: |
292 | { |
310 | { |
293 | u16 size = (u8)FTP_data[2]; |
311 | u16 size = (u8)FTP_data[2]; |
294 | size *= 0x100; |
312 | size *= 0x100; |
295 | size += (u8) FTP_data[1]; |
313 | size += (u8) FTP_data[1]; |
296 | // if (FTP_data[0] == blockindex) // next block is requested |
314 | // if (FTP_data[0] == blockindex) // next block is requested |
297 | { |
315 | { |
298 | blockindex++; |
316 | blockindex++; |
299 | fwrite_(&FTP_data[3], size, 1, fp); // write data block to buffer); |
317 | fwrite_(&FTP_data[3], size, 1, fp); // write data block to buffer); |
300 | } |
318 | } |
301 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &blockindex, 1 ); |
319 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &blockindex, 1 ); |
302 | } |
320 | } |
303 | break; |
321 | break; |
304 | 322 | ||
305 | case FTP_CMD_NONE: |
323 | case FTP_CMD_NONE: |
306 | default: |
324 | default: |
307 | FTP_command = FTP_CMD_NONE; |
325 | FTP_command = FTP_CMD_NONE; |
308 | Debug("ftp: CMD None"); |
326 | Debug("ftp: CMD None"); |
309 | break; |
327 | break; |
310 | } |
328 | } |
311 | } |
329 | } |
312 | 330 | ||
313 | 331 | ||
314 | 332 |