Subversion Repositories NaviCtrl

Rev

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

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