Rev 349 |
Rev 368 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*#######################################################################################*/
/* !!! THIS IS NOT FREE SOFTWARE !!! */
/*#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Software Nutzungsbedingungen (english version: see below)
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
// + des Mitverschuldens offen.
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
// + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Software LICENSING TERMS
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
// + The Software may only be used with the Licensor's products.
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
// + agreement shall be the property of the Licensor.
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
// + features that can be used to identify the program may not be altered or defaced by the customer.
// + The customer shall be responsible for taking reasonable precautions
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
// + #### END OF LICENSING TERMS ####
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "91x_lib.h"
#include "config.h"
#include "main.h"
#include "fat16.h"
#include "ftphelper.h"
#include "mkprotocol.h"
#include "debug.h"
#include "uart1.h"
typedef struct
{
u8 Name
[13];
u8 Attribute
;
u32 Size
;
} __attribute__
((packed
)) FTP_direntry_t
;
FTP_direntry_t FTP_direntry
;
char FTP_data
[DATA_TRANSFER_SIZE
+1]; // rx & tx buffer to avoid 2 buffers
u16 CompressBuffer
(char *buf
, u16 size
, u16 offset
)
{
#define KEYWORD_COUNT 27
const char keyword
[KEYWORD_COUNT
][16]=
{"Altimeter>\0 \0",
"Current>\0 \0",
"Variometer>\0 \0",
"GroundSpeed>\0 \0",
"VerticalSpeed>\0\0",
"FlightTime>\0 \0",
"Voltage>\0 \0",
"Capacity>\0 \0",
"RCQuality>\0 \0",
"RCRSSI>\0 \0",
"Compass>\0 \0",
"NickAngle>\0 \0",
"RollAngle>\0 \0",
"NCFlag>\0 \0",
"ErrorCode>\0 \0",
"TargetBearing>\0\0",
"RCSticks>\0 \0",
"GPSSticks>\0 \0",
"extensions>\0 \0",
"Course>\0 \0",
"trkpt\0 \0",
"time>\0 \0",
"sat>\0 \0",
"ele>\0 \0",
" lat=\0 \0",
" lon=\0 \0",
"TargetDistance>\0" };
u16 i
, count
= size
;
char *s
= NULL
, *start
= buf
+offset
;
for ( i
= 0; i
< KEYWORD_COUNT
; i
++)
{
s
= strstr(start
, keyword
[i
]);
if (s
!= NULL
)
{ u8 keylen
= strlen(keyword
[i
]);
*s
= 27;
*(s
+1) = i
+1;
count
-= (keylen
-2);
memcpy(s
+2, s
+keylen
, count
- (s
-buf
));
i
--;
}
}
return (count
);
}
// --------------------------------------------------------------------
void CheckFTPCommand
(u8 FTP_command
)
{
static Find_t fe
;
static File_t
*fp
= NULL
;
static u8 blockindex
, compressLevel
= 0;
u32 filesize
;
switch (FTP_command
)
{
case FTP_CMD_FINDFIRST
:
FTP_direntry.
Name[0] = 0;
if (findfirst_
("*.*", 0x35, &fe
))
{
memcpy(&FTP_direntry.
Name, &fe.
name, 13);
FTP_direntry.
Attribute = fe.
fp.
Attribute;
FTP_direntry.
Size = fe.
fp.
Size;
// Debug(FTP_direntry.Name);
}
MKProtocol_CreateSerialFrame
(&UART1_tx_buffer
, 'F', NC_ADDRESS
, 2, &FTP_command
, 1, &FTP_direntry
, sizeof(FTP_direntry
));
break;
case FTP_CMD_FINDNEXT
:
FTP_direntry.
Name[0] = 0;
if (findnext_
(&fe
))
{
memcpy(&FTP_direntry.
Name, &fe.
name, 13);
FTP_direntry.
Attribute = fe.
fp.
Attribute;
FTP_direntry.
Size = fe.
fp.
Size;
// Debug(FTP_direntry.Name);
}
MKProtocol_CreateSerialFrame
(&UART1_tx_buffer
, 'F', NC_ADDRESS
, 2, &FTP_command
, 1, &FTP_direntry
, sizeof(FTP_direntry
));
break;
case FTP_CMD_GET_CWD
:
{
char data_null
= 0;
MKProtocol_CreateSerialFrame
(&UART1_tx_buffer
, 'F', NC_ADDRESS
, 3, &FTP_command
, 1, GetPath
(), strlen(GetPath
()), &data_null
, 1 );
}
break;
case FTP_CMD_SET_CWD
:
chdir_
(FTP_data
);
break;
case FTP_CMD_OPEN_FILE
:
{
u8 filefound
;
compressLevel
= FTP_data
[0];
fp
= fopen_
(&FTP_data
[1], 'r');
if (fp
!= NULL
)
{
filefound
= 1;
filesize
= fp
->Size
;
blockindex
= 0; // reset index counter
}
else filefound
= 0; // this means, no valid file found for transfer
MKProtocol_CreateSerialFrame
(&UART1_tx_buffer
, 'F', NC_ADDRESS
, 3, &FTP_command
, 1, &filefound
, 1, &filesize
, sizeof(filesize
));
}
break;
case FTP_CMD_GET_FILE_DATA
:
{
u16 size
= DATA_TRANSFER_SIZE
;
if (FTP_data
[0] == blockindex
+ 1) // next block is requested
{
blockindex
++;
}
else if (FTP_data
[0] == blockindex
) // repeat last block
{
fseek_
(fp
, SEEK_CUR
, -DATA_TRANSFER_SIZE
); // set filepointer to beginning of last block
}
else blockindex
= FTP_data
[0]+ 10; // ABORT transfer, blockindex now out of valid range
fread_
(FTP_data
, DATA_TRANSFER_SIZE
, 1, fp
); // read data block to buffer);
FTP_data
[DATA_TRANSFER_SIZE
] = 0;
if (compressLevel
)
{
size
= CompressBuffer
(FTP_data
, DATA_TRANSFER_SIZE
, 0);
if (compressLevel
> 1)
{
if (size
< DATA_TRANSFER_SIZE
- 50)
{
fread_
(&FTP_data
[size
], DATA_TRANSFER_SIZE
- size
, 1, fp
); // read data block to buffer);
FTP_data
[DATA_TRANSFER_SIZE
] = 0;
size
= CompressBuffer
(FTP_data
, DATA_TRANSFER_SIZE
, size
);
}
}
}
MKProtocol_CreateSerialFrame
(&UART1_tx_buffer
, 'F', NC_ADDRESS
, 4, &FTP_command
, 1, &blockindex
, 1, &size
, 2, &FTP_data
, size
);
}
break;
case FTP_CMD_CLOSE_FILE
:
fclose_
(fp
);
Debug
("ftp: CloseFile");
break;
case FTP_CMD_NONE
:
default:
FTP_command
= FTP_CMD_NONE
;
Debug
("ftp: CMD None");
break;
}
}