Subversion Repositories NaviCtrl

Rev

Rev 435 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 435 Rev 436
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
  #define KEYWORD_COUNT 46
-
 
83
 
82
  #define KEYWORD_COUNT 47
84
  // most used gpx tags can be compressed 
83
  // most used gpx tags can be compressed 
85
  const char keyword[KEYWORD_COUNT][16]=
84
  const char keyword[KEYWORD_COUNT][16]=
86
                                        {"Altimeter>\0    \0",
85
                                        {"Altimeter>\0    \0",
87
                                         "MotorCurrent>\0 \0",
86
                                         "MotorCurrent>\0 \0",
88
                                         "Current>\0      \0",
87
                                         "Current>\0      \0",
89
                                         "Variometer>\0   \0",
88
                                         "Variometer>\0   \0",
90
                                         "GroundSpeed>\0  \0",
89
                                         "GroundSpeed>\0  \0",
91
                                         "VerticalSpeed>\0\0",
90
                                         "VerticalSpeed>\0\0",
92
                                         "FlightTime>\0   \0",
91
                                         "FlightTime>\0   \0",
93
                                         "Voltage>\0      \0",
92
                                         "Voltage>\0      \0",
94
                                         "Capacity>\0     \0",
93
                                         "Capacity>\0     \0",
95
                                         "RCQuality>\0    \0",
94
                                         "RCQuality>\0    \0",
96
                                         "RCRSSI>\0       \0",
95
                                         "RCRSSI>\0       \0",
97
                                         "Compass>\0      \0",
96
                                         "Compass>\0      \0",
98
                                         "NickAngle>\0    \0",
97
                                         "NickAngle>\0    \0",
99
                                         "RollAngle>\0    \0",
98
                                         "RollAngle>\0    \0",
100
                                         "NCFlag>\0       \0",
99
                                         "NCFlag>\0       \0",
101
                                         "ErrorCode>\0    \0",
100
                                         "ErrorCode>\0    \0",
102
                                         "TargetBearing>\0\0",
101
                                         "TargetBearing>\0\0",
103
                                         "RCSticks>\0     \0",
102
                                         "RCSticks>\0     \0",
104
                                         "GPSSticks>\0    \0",
103
                                         "GPSSticks>\0    \0",
105
                                         "extensions>\0   \0",
104
                                         "extensions>\0   \0",
106
                                         "Course>\0       \0",
105
                                         "Course>\0       \0",
107
                                         "trkpt\0         \0",
106
                                         "trkpt\0         \0",
108
                                         "time>\0         \0",
107
                                         "time>\0         \0",
109
                                         "sat>\0          \0",
108
                                         "sat>\0          \0",
110
                                         "ele>\0          \0",
109
                                         "ele>\0          \0",
111
                                         " lat=\0         \0",
110
                                         " lat=\0         \0",
112
                                         " lon=\0         \0",
111
                                         " lon=\0         \0",
113
                                         "0,0,0,0\0       \0",
112
                                         "0,0,0,0\0       \0",
114
                                         "name>\0         \0",
113
                                         "name>\0         \0",
115
                                         "FCFlags2>\0     \0",
114
                                         "FCFlags2>\0     \0",
116
                                         "MagnetField>\0  \0",
115
                                         "MagnetField>\0  \0",
117
                                         "trkseg>\0       \0",
116
                                         "trkseg>\0       \0",
118
                                         "AnalogInputs>\0 \0",
117
                                         "AnalogInputs>\0 \0",
119
                                         "Servo>\0        \0",
118
                                         "Servo>\0        \0",
120
                                         "BL_State>\0     \0",
119
                                         "BL_State>\0     \0",
121
                                         "BL_MaxPWM>\0    \0",
120
                                         "BL_MaxPWM>\0    \0",
122
                                         "MikroKopter\0   \0",
121
                                         "MikroKopter\0   \0",
123
                                         "nter>000</\0    \0",
122
                                         "nter>000</\0    \0",
124
                                         "metadata>\0     \0",
123
                                         "metadata>\0     \0",
-
 
124
                                         "Speak>\0        \0",
125
                                         "<WP>----,0,0,0<\0",
125
                                         "<WP>----,0,0,0<\0",
126
                                         "MagnetInclinati\0",
126
                                         "MagnetInclinati\0",
127
                                         "BL_Temperature>\0",
127
                                         "BL_Temperature>\0",
128
                                         "AvaiableMotorPo\0",
128
                                         "AvaiableMotorPo\0",
129
                                         "FC_I2C_ErrorCou\0",    
129
                                         "FC_I2C_ErrorCou\0",    
130
                                         "FC_SPI_ErrorCou\0",
130
                                         "FC_SPI_ErrorCou\0",
131
                                         "TargetDistance>\0" };
131
                                         "TargetDistance>\0" };
132
 
132
 
133
u16 CompressBuffer(char *buf, u16 size, u16 offset)
133
u16 CompressBuffer(char *buf, u16 size, u16 offset)
134
{
134
{
135
 
135
 
136
  u16 i, count = size;
136
  u16 i, count = size;
137
  char *s = NULL, *start = buf+offset;
137
  char *s = NULL, *start = buf+offset;
138
 
138
 
139
   for ( i = 0; i < KEYWORD_COUNT; i++)
139
   for ( i = 0; i < KEYWORD_COUNT; i++)
140
   {
140
   {
141
                s = strstr(start, keyword[i]);
141
                s = strstr(start, keyword[i]);
142
                if (s != NULL)
142
                if (s != NULL)
143
                {       u8 keylen = strlen(keyword[i]);
143
                {       u8 keylen = strlen(keyword[i]);
144
                        *s= 27;  
144
                        *s= 27;  
145
                        *(s+1) = i+1;
145
                        *(s+1) = i+1;
146
                        count-= (keylen-2);
146
                        count-= (keylen-2);
147
                        memcpy(s+2, s+keylen, count - (s-buf));
147
                        memcpy(s+2, s+keylen, count - (s-buf));
148
                        i--;
148
                        i--;
149
                }
149
                }
150
        }
150
        }
151
   
151
   
152
   return (count);
152
   return (count);
153
}
153
}
154
// --------------------------------------------------------------------
154
// --------------------------------------------------------------------
155
void CheckFTPCommand(u8 FTP_command)
155
void CheckFTPCommand(u8 FTP_command)
156
{
156
{
157
        static Find_t fe;
157
        static Find_t fe;
158
        static File_t *fp = NULL;
158
        static File_t *fp = NULL;
159
        static u8 blockindex, compressLevel = 0;
159
        static u8 blockindex, compressLevel = 0;
160
 
160
 
161
        u32 filesize;
161
        u32 filesize;
162
 
162
 
163
        switch (FTP_command)
163
        switch (FTP_command)
164
        {
164
        {
165
                case FTP_CMD_FINDFIRST:
165
                case FTP_CMD_FINDFIRST:
166
                        FTP_direntry.Name[0] = 0;
166
                        FTP_direntry.Name[0] = 0;
167
                        // any file or directory except volume labels and hidden files 
167
                        // any file or directory except volume labels and hidden files 
168
                        if(findfirst_("*.*", (ATTR_ARCHIVE|ATTR_SUBDIRECTORY|ATTR_SYSTEM|ATTR_READONLY), &fe))
168
                        if(findfirst_("*.*", (ATTR_ARCHIVE|ATTR_SUBDIRECTORY|ATTR_SYSTEM|ATTR_READONLY), &fe))
169
                        {
169
                        {
170
                                memcpy(&FTP_direntry.Name, &fe.name, 13);      
170
                                memcpy(&FTP_direntry.Name, &fe.name, 13);      
171
                                FTP_direntry.Attribute = fe.fp.Attribute;
171
                                FTP_direntry.Attribute = fe.fp.Attribute;
172
                                FTP_direntry.Size = fe.fp.Size;
172
                                FTP_direntry.Size = fe.fp.Size;
173
                        }
173
                        }
174
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry));
174
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry));
175
                        break;
175
                        break;
176
       
176
       
177
                case FTP_CMD_FINDNEXT:
177
                case FTP_CMD_FINDNEXT:
178
                        FTP_direntry.Name[0] = 0;
178
                        FTP_direntry.Name[0] = 0;
179
                        if (findnext_(&fe))
179
                        if (findnext_(&fe))
180
                        {
180
                        {
181
                                memcpy(&FTP_direntry.Name, &fe.name, 13);      
181
                                memcpy(&FTP_direntry.Name, &fe.name, 13);      
182
                                FTP_direntry.Attribute = fe.fp.Attribute;
182
                                FTP_direntry.Attribute = fe.fp.Attribute;
183
                                FTP_direntry.Size = fe.fp.Size;
183
                                FTP_direntry.Size = fe.fp.Size;
184
                        }
184
                        }
185
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry));
185
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &FTP_direntry, sizeof(FTP_direntry));
186
                        break;
186
                        break;
187
       
187
       
188
                case FTP_CMD_GET_CWD: // get current working directory
188
                case FTP_CMD_GET_CWD: // get current working directory
189
                        {
189
                        {
190
                        char data_null = 0;
190
                        char data_null = 0;
191
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, getcwd_(), strlen(getcwd_()), &data_null, 1 );
191
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, getcwd_(), strlen(getcwd_()), &data_null, 1 );
192
                        }
192
                        }
193
                        break;
193
                        break;
194
       
194
       
195
                case FTP_CMD_SET_CWD: // set current working directory
195
                case FTP_CMD_SET_CWD: // set current working directory
196
                        {
196
                        {
197
                        u8 cmd_successful;
197
                        u8 cmd_successful;
198
                        cmd_successful = chdir_(FTP_data);
198
                        cmd_successful = chdir_(FTP_data);
199
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
199
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
200
                        }
200
                        }
201
                        break;
201
                        break;
202
 
202
 
203
                case FTP_CMD_CDUP: // change dir up
203
                case FTP_CMD_CDUP: // change dir up
204
                        {
204
                        {
205
                        u8 cmd_successful;
205
                        u8 cmd_successful;
206
                        cmd_successful = chdir_("..");
206
                        cmd_successful = chdir_("..");
207
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
207
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
208
                        }
208
                        }
209
                        break;
209
                        break;
210
 
210
 
211
                case FTP_CMD_MKDIR:     // create directory 
211
                case FTP_CMD_MKDIR:     // create directory 
212
                        {
212
                        {
213
                        u8 cmd_successful;
213
                        u8 cmd_successful;
214
                    cmd_successful = mkdir_(&FTP_data[0]);
214
                    cmd_successful = mkdir_(&FTP_data[0]);
215
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
215
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
216
                        }
216
                        }
217
                        break;
217
                        break;
218
       
218
       
219
                case FTP_CMD_RMDIR:     // delete directory 
219
                case FTP_CMD_RMDIR:     // delete directory 
220
                        {
220
                        {
221
                        u8 cmd_successful;
221
                        u8 cmd_successful;
222
                    cmd_successful = rmdir_(&FTP_data[0]);
222
                    cmd_successful = rmdir_(&FTP_data[0]);
223
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
223
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
224
                        }
224
                        }
225
                        break;
225
                        break;
226
 
226
 
227
                case FTP_CMD_DELETE_FILE:       // delete file 
227
                case FTP_CMD_DELETE_FILE:       // delete file 
228
                        {
228
                        {
229
                        u8 cmd_successful;
229
                        u8 cmd_successful;
230
                cmd_successful = fdelete_(&FTP_data[0]);
230
                cmd_successful = fdelete_(&FTP_data[0]);
231
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
231
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &cmd_successful, 1);
232
                        }
232
                        }
233
                        break;
233
                        break;
234
 
234
 
235
                case FTP_CMD_OPEN_FILE: // open the file for reading
235
                case FTP_CMD_OPEN_FILE: // open the file for reading
236
                        {
236
                        {
237
                        u8 filefound;  
237
                        u8 filefound;  
238
                        compressLevel = FTP_data[0];
238
                        compressLevel = FTP_data[0];
239
                        fp = fopen_(&FTP_data[1], 'r');
239
                        fp = fopen_(&FTP_data[1], 'r');
240
                        if (fp != NULL)
240
                        if (fp != NULL)
241
                        {
241
                        {
242
                                filefound = 1;
242
                                filefound = 1;
243
                                filesize = fp->Size;
243
                                filesize = fp->Size;
244
                                blockindex = 0;                         // reset index counter
244
                                blockindex = 0;                         // reset index counter
245
                        }
245
                        }
246
                        else filefound = 0;                             // this means, no valid file found for transfer
246
                        else filefound = 0;                             // this means, no valid file found for transfer
247
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, &filefound, 1, &filesize, sizeof(filesize));
247
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, &filefound, 1, &filesize, sizeof(filesize));
248
                        }
248
                        }
249
                        break;
249
                        break;
250
 
250
 
251
                case FTP_CMD_GET_FILE_DATA:
251
                case FTP_CMD_GET_FILE_DATA:
252
                        {
252
                        {
253
                        u16 size = DATA_TRANSFER_SIZE;
253
                        u16 size = DATA_TRANSFER_SIZE;
254
                        if (FTP_data[0] == blockindex + 1)                                      // next block is requested
254
                        if (FTP_data[0] == blockindex + 1)                                      // next block is requested
255
                        {
255
                        {
256
                        blockindex++;                                  
256
                        blockindex++;                                  
257
                        }
257
                        }
258
                        else
258
                        else
259
                        {
259
                        {
260
                                u32 filepos;
260
                                u32 filepos;
261
                                blockindex = FTP_data[0];
261
                                blockindex = FTP_data[0];
262
                                filepos = FTP_data[1];
262
                                filepos = FTP_data[1];
263
                                filepos |= ((u32)FTP_data[2] * 0x100);
263
                                filepos |= ((u32)FTP_data[2] * 0x100);
264
                                filepos |= ((u32) FTP_data[3] * 0x10000L);
264
                                filepos |= ((u32) FTP_data[3] * 0x10000L);
265
                                filepos |= ((u32) FTP_data[4] * 0x1000000L);
265
                                filepos |= ((u32) FTP_data[4] * 0x1000000L);
266
                        fseek_(fp, filepos, SEEK_SET);  // set filepointer to beginning of requested block
266
                        fseek_(fp, filepos, SEEK_SET);  // set filepointer to beginning of requested block
267
                        }
267
                        }
268
               
268
               
269
                        fread_(FTP_data, DATA_TRANSFER_SIZE, 1, fp);                            // read data block to buffer);
269
                        fread_(FTP_data, DATA_TRANSFER_SIZE, 1, fp);                            // read data block to buffer);
270
                        FTP_data[DATA_TRANSFER_SIZE] = 0;              
270
                        FTP_data[DATA_TRANSFER_SIZE] = 0;              
271
           
271
           
272
                if (compressLevel)
272
                if (compressLevel)
273
                        {
273
                        {
274
                                size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, 0);
274
                                size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, 0);
275
                               
275
                               
276
                                if (compressLevel > 1)
276
                                if (compressLevel > 1)
277
                                {
277
                                {
278
                                        if (size < DATA_TRANSFER_SIZE - 50)
278
                                        if (size < DATA_TRANSFER_SIZE - 50)
279
                                        {              
279
                                        {              
280
                                                fread_(&FTP_data[size], DATA_TRANSFER_SIZE - size, 1, fp);                              // read data block to buffer);  
280
                                                fread_(&FTP_data[size], DATA_TRANSFER_SIZE - size, 1, fp);                              // read data block to buffer);  
281
                                                FTP_data[DATA_TRANSFER_SIZE] = 0;              
281
                                                FTP_data[DATA_TRANSFER_SIZE] = 0;              
282
                                                size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, size);
282
                                                size = CompressBuffer(FTP_data, DATA_TRANSFER_SIZE, size);
283
                                        }
283
                                        }
284
                                }
284
                                }
285
                        }  
285
                        }  
286
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 4, &FTP_command, 1, &blockindex, 1, &size, 2, &FTP_data, size);
286
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 4, &FTP_command, 1, &blockindex, 1, &size, 2, &FTP_data, size);
287
                        }
287
                        }
288
                        break;
288
                        break;
289
 
289
 
290
                case FTP_CMD_CLOSE_FILE:
290
                case FTP_CMD_CLOSE_FILE:
291
                        fclose_(fp);
291
                        fclose_(fp);
292
                        Debug("ftp: CloseFile");               
292
                        Debug("ftp: CloseFile");               
293
                        break;
293
                        break;
294
 
294
 
295
                case FTP_CMD_CREATE_FILE:       // open the file for writing
295
                case FTP_CMD_CREATE_FILE:       // open the file for writing
296
                        {
296
                        {
297
                        u16 size = DATA_TRANSFER_SIZE;
297
                        u16 size = DATA_TRANSFER_SIZE;
298
                        //compressLevel = FTP_data[0];
298
                        //compressLevel = FTP_data[0];
299
                        // FTP_data[1..4] contains filesize in bytes
299
                        // FTP_data[1..4] contains filesize in bytes
300
                        compressLevel = 0;                      // no compression for writing
300
                        compressLevel = 0;                      // no compression for writing
301
                        fp = fopen_(&FTP_data[5], 'w');
301
                        fp = fopen_(&FTP_data[5], 'w');
302
                        if (fp != NULL)
302
                        if (fp != NULL)
303
                        {
303
                        {
304
                                blockindex = 0;                                                                 // reset index counter
304
                                blockindex = 0;                                                                 // reset index counter
305
                        }
305
                        }
306
                        else size = 0;                                                                          // this means, no valid file for transfer (maybe readonly)
306
                        else size = 0;                                                                          // this means, no valid file for transfer (maybe readonly)
307
                        //if (size == 0) Debug("ftp: create ERR ");
307
                        //if (size == 0) Debug("ftp: create ERR ");
308
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &size, 2);
308
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &size, 2);
309
                        }
309
                        }
310
                        break;
310
                        break;
311
 
311
 
312
                case FTP_CMD_SEND_FILE_DATA:
312
                case FTP_CMD_SEND_FILE_DATA:
313
                        {
313
                        {
314
                        u16 size = (u8)FTP_data[2];
314
                        u16 size = (u8)FTP_data[2];
315
                        size *= 0x100;
315
                        size *= 0x100;
316
                        size += (u8) FTP_data[1];
316
                        size += (u8) FTP_data[1];
317
                        //      if (FTP_data[0] == blockindex)                                          // next block is requested
317
                        //      if (FTP_data[0] == blockindex)                                          // next block is requested
318
                        {
318
                        {
319
                                blockindex++;                                  
319
                                blockindex++;                                  
320
                        fwrite_(&FTP_data[3], size, 1, fp);                             // write data block to buffer);
320
                        fwrite_(&FTP_data[3], size, 1, fp);                             // write data block to buffer);
321
                        }      
321
                        }      
322
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &blockindex, 1 );
322
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &FTP_command, 1, &blockindex, 1 );
323
                        }
323
                        }
324
                        break;
324
                        break;
325
 
325
 
326
                case FTP_CMD_NONE:
326
                case FTP_CMD_NONE:
327
                default:
327
                default:
328
                        FTP_command = FTP_CMD_NONE;
328
                        FTP_command = FTP_CMD_NONE;
329
                        Debug("ftp: CMD None");
329
                        Debug("ftp: CMD None");
330
                        break;
330
                        break;
331
 
331
 
332
                case FTP_CMD_GET_KEYWORDS:
332
                case FTP_CMD_GET_KEYWORDS:
333
                        {
333
                        {
334
                        u8 count = KEYWORD_COUNT;
334
                        u8 count = KEYWORD_COUNT;
335
 
335
 
336
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, &count, 1, keyword, sizeof(keyword) );
336
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 3, &FTP_command, 1, &count, 1, keyword, sizeof(keyword) );
337
                        }
337
                        }
338
                        break;
338
                        break;
339
 
339
 
340
 
340
 
341
        }
341
        }
342
}
342
}
343
 
343
 
344
 
344
 
345
 
345