mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
Fixes Problem under Linux, teste ok under Ubuntu
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@474 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
eb6961c173
commit
8ba2b0f4bc
@ -39,10 +39,10 @@ quint16 QymodemBase::UpdateCRC16(quint16 crcIn, quint8 byte)
|
||||
}
|
||||
|
||||
|
||||
quint16 QymodemBase::CRC16(const char* data, size_t size)
|
||||
quint16 QymodemBase::CRC16(const quint8* data, size_t size)
|
||||
{
|
||||
quint32 crc = 0;
|
||||
const char* dataEnd = data+size;
|
||||
const quint8* dataEnd = data+size;
|
||||
while(data<dataEnd)
|
||||
crc = UpdateCRC16(crc,*data++);
|
||||
crc = UpdateCRC16(crc,0);
|
||||
@ -51,10 +51,10 @@ quint16 QymodemBase::CRC16(const char* data, size_t size)
|
||||
}
|
||||
|
||||
|
||||
quint8 QymodemBase::Checksum(const char* data, size_t size)
|
||||
quint8 QymodemBase::Checksum(const quint8* data, size_t size)
|
||||
{
|
||||
int sum = 0;
|
||||
const char* dataEnd = data+size;
|
||||
const quint8* dataEnd = data+size;
|
||||
while(data<dataEnd)
|
||||
sum += *data++;
|
||||
return sum&0xffu;
|
||||
@ -63,9 +63,11 @@ quint8 QymodemBase::Checksum(const char* data, size_t size)
|
||||
|
||||
int QymodemBase::InChar(long timeout)
|
||||
{
|
||||
char c;
|
||||
quint8 c;
|
||||
char cc;
|
||||
Port.setTimeout(timeout);
|
||||
int result =(int)Port.read(&c,1);
|
||||
int result =(int)Port.read(&cc,1);
|
||||
c=(quint8)cc;
|
||||
if(result==1)
|
||||
return c;
|
||||
if(result==0)
|
||||
@ -76,8 +78,8 @@ int QymodemBase::InChar(long timeout)
|
||||
|
||||
void QymodemBase::Cancel()
|
||||
{
|
||||
const char CancelString[] = { CAN,CAN,CAN,CAN,CAN };
|
||||
const quint8 CancelString[] = { CAN,CAN,CAN,CAN,CAN };
|
||||
Port.setTimeout(1000);
|
||||
Port.write(CancelString,sizeof(CancelString));
|
||||
Port.write((char*)CancelString,sizeof(CancelString));
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@ class QymodemBase: public QThread
|
||||
signals:
|
||||
void Error(QString,int);
|
||||
void Information(QString,int);
|
||||
///
|
||||
void Percent(int);
|
||||
|
||||
protected:
|
||||
|
||||
@ -41,7 +43,7 @@ protected:
|
||||
|
||||
@return Sum of bytes in data, modulo 256.
|
||||
*/
|
||||
quint8 Checksum(const char* data, size_t size);
|
||||
quint8 Checksum(const quint8* data, size_t size);
|
||||
|
||||
/**
|
||||
Calculate CRC for a block of data.
|
||||
@ -51,7 +53,7 @@ protected:
|
||||
|
||||
@return CRC of data.
|
||||
*/
|
||||
quint16 CRC16(const char* data, size_t size);
|
||||
quint16 CRC16(const quint8* data, size_t size);
|
||||
|
||||
/**
|
||||
Update CRC value by accumulating another byte of data.
|
||||
@ -107,7 +109,6 @@ protected:
|
||||
*/
|
||||
|
||||
QextSerialPort& Port;
|
||||
int percent;
|
||||
};
|
||||
|
||||
|
||||
|
@ -79,7 +79,7 @@ int QymodemTx::SendInitialise(unsigned timeout)
|
||||
int c;
|
||||
for(;;)
|
||||
{
|
||||
const unsigned timeoutStep = 10;
|
||||
const unsigned timeoutStep = 1000;
|
||||
c = InChar(timeoutStep);
|
||||
if(c=='G')
|
||||
{
|
||||
@ -123,9 +123,9 @@ A zero sized block terminates the transfer.
|
||||
|
||||
@pre SendInitialise() must have been successful.
|
||||
*/
|
||||
int QymodemTx::SendBlock(const char* data, size_t size)
|
||||
int QymodemTx::SendBlock(const quint8* data, size_t size)
|
||||
{
|
||||
char block[1+2+1024+2]; // buffer to hold data in the block
|
||||
quint8 block[1+2+1024+2]; // buffer to hold data in the block
|
||||
int retryCount = 10; // number of attempts to send the block
|
||||
bool waitForBlockACK = WaitForBlockACK;
|
||||
|
||||
@ -173,13 +173,13 @@ do_retry:
|
||||
if(!retryCount--)
|
||||
return ErrorBlockRetriesExceded;
|
||||
|
||||
char* out = block;
|
||||
quint8* out = block;
|
||||
size_t outSize = blockSize;
|
||||
for(;;)
|
||||
{
|
||||
// send some data...
|
||||
Port.setTimeout(1000);;
|
||||
int result = (int)Port.write(out,outSize);
|
||||
int result = (int)Port.write((char*)out,outSize);
|
||||
if(result<0)
|
||||
return result; // return error
|
||||
if(result==0)
|
||||
@ -259,7 +259,7 @@ A zero sized block terminates the transfer.
|
||||
|
||||
@pre SendInitialise() must have been successful.
|
||||
*/
|
||||
int QymodemTx::SendData(const char* data, size_t size)
|
||||
int QymodemTx::SendData(const quint8* data, size_t size)
|
||||
{
|
||||
do
|
||||
{
|
||||
@ -290,8 +290,9 @@ int QymodemTx::SendAll(InStream& in)
|
||||
do
|
||||
{
|
||||
// get data from input stream...
|
||||
char data[1024];
|
||||
int result = in.In(data,sizeof(data),&percent);
|
||||
quint8 data[1024];
|
||||
int result = in.In(data,sizeof(data));
|
||||
emit Percent(in.percent);
|
||||
if(result<0)
|
||||
return ErrorInputStreamError;
|
||||
|
||||
@ -316,11 +317,11 @@ Construct the data for the first block of a Y-Modem transfer.
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
*/
|
||||
int QymodemTx::MakeBlock0(char* buffer, const char* fileName, size_t fileSize)
|
||||
int QymodemTx::MakeBlock0(quint8* buffer, const char* fileName, size_t fileSize)
|
||||
{
|
||||
// setup buffer for block 0...
|
||||
char* out = buffer;
|
||||
char* outEnd = buffer+128-1;
|
||||
quint8* out = buffer;
|
||||
quint8* outEnd = buffer+128-1;
|
||||
memset(buffer,0,128);
|
||||
|
||||
// copy file name to block data...
|
||||
@ -378,7 +379,7 @@ int QymodemTx::SendX(InStream& in, unsigned timeout, bool kMode)
|
||||
int QymodemTx::SendY(const char* fileName, size_t size, InStream& in, unsigned timeout)
|
||||
{
|
||||
Use1KBlocks = true;
|
||||
char buffer[128];
|
||||
quint8 buffer[128];
|
||||
int result = MakeBlock0(buffer,fileName,size);
|
||||
if(result<0)
|
||||
return result;
|
||||
@ -413,7 +414,7 @@ int QymodemTx::SendY(const char* fileName, size_t size, InStream& in, unsigned t
|
||||
result = SendBlock(buffer,sizeof(buffer));
|
||||
if(result<0)
|
||||
return result;
|
||||
|
||||
emit Percent(100);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
class InStream
|
||||
{
|
||||
public:
|
||||
int percent;
|
||||
/**
|
||||
Read data from the stream.
|
||||
|
||||
@ -52,7 +53,7 @@ public:
|
||||
|
||||
@return Number of bytes successfully read, or a negative error value if failed.
|
||||
*/
|
||||
virtual int In(char* data, size_t size, int * percent) =0;
|
||||
virtual int In(quint8* data, size_t size) =0;
|
||||
|
||||
/**
|
||||
Empty destructor to avoid compiler warnings.
|
||||
@ -105,10 +106,10 @@ public:
|
||||
|
||||
private:
|
||||
int SendInitialise(unsigned timeout);
|
||||
int SendBlock(const char* data, size_t size);
|
||||
int SendData(const char* data, size_t size);
|
||||
int SendBlock(const quint8* data, size_t size);
|
||||
int SendData(const quint8* data, size_t size);
|
||||
int SendAll(InStream& in);
|
||||
int MakeBlock0(char* buffer, const char* fileName, size_t fileSize);
|
||||
int MakeBlock0(quint8* buffer, const char* fileName, size_t fileSize);
|
||||
int ProcessResponse(int c);
|
||||
private:
|
||||
size_t BlockNumber;
|
||||
|
@ -20,12 +20,8 @@
|
||||
QymodemSend::QymodemSend(QextSerialPort& port)
|
||||
: QymodemTx(port)
|
||||
{
|
||||
percent=0;
|
||||
|
||||
}
|
||||
int QymodemSend::PercentSend()
|
||||
{
|
||||
return percent;
|
||||
}
|
||||
|
||||
/**
|
||||
Class for presenting a file as a input stream.
|
||||
@ -44,6 +40,8 @@ public:
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
*/
|
||||
|
||||
|
||||
int Open(const char* fileName)
|
||||
{
|
||||
File = fopen(fileName,"rb");
|
||||
@ -95,9 +93,11 @@ public:
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
*/
|
||||
int In(char* data, size_t size, int * percent)
|
||||
int In(quint8* data, size_t size)
|
||||
{
|
||||
*percent = TotalSize ? ((quint64)TransferredSize*(quint64)100)/(quint64)TotalSize : 0;
|
||||
// mutex.lock();
|
||||
percent = TotalSize ? ((quint64)TransferredSize*(quint64)100)/(quint64)TotalSize : 0;
|
||||
//mutex.unlock();
|
||||
fflush(stdout);
|
||||
size=fread(data,sizeof(quint8),size,File);
|
||||
if(size)
|
||||
@ -110,9 +110,11 @@ public:
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
// QMutex mutex;
|
||||
FILE* File;
|
||||
size_t TotalSize;
|
||||
size_t TransferredSize;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -140,10 +142,11 @@ void QymodemSend::Send()
|
||||
error = SendY(FileName,source.Size(),source,Timeout);
|
||||
if(error)
|
||||
{
|
||||
emit Error("Error during file transfer, error "+QString(error),error);
|
||||
emit Error("Error during file transfer, error "+QString::number(error),error);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
emit Information("Sent OK",QymodemSend::InfoSent);
|
||||
}
|
||||
source.Close();
|
||||
@ -157,7 +160,7 @@ int QymodemSend::SendFile(QString filename)
|
||||
emit Error("File not found",QymodemSend::ErrorFileNotFound);
|
||||
return QymodemSend::ErrorFileNotFound;
|
||||
}
|
||||
if(!Port.open(QIODevice::ReadWrite| QIODevice::Unbuffered))
|
||||
if(!Port.open(QIODevice::ReadWrite))
|
||||
{
|
||||
emit Error("Could not open port",QymodemSend::ErrorCoulNotOpenPort);
|
||||
return QymodemSend::ErrorCoulNotOpenPort;
|
||||
@ -191,7 +194,7 @@ void QymodemSend::run()
|
||||
emit Error("File not found",QymodemSend::ErrorFileNotFound);
|
||||
return;
|
||||
}
|
||||
if(!Port.open(QIODevice::ReadWrite| QIODevice::Unbuffered))
|
||||
if(!Port.open(QIODevice::ReadWrite))
|
||||
{
|
||||
emit Error("Could not open port",QymodemSend::ErrorCoulNotOpenPort);
|
||||
return;
|
||||
|
@ -28,7 +28,6 @@ public:
|
||||
QymodemSend(QextSerialPort& port);
|
||||
int SendFile(QString filename);
|
||||
int SendFileT(QString filename);
|
||||
int PercentSend();
|
||||
|
||||
private:
|
||||
void run();
|
||||
|
Loading…
Reference in New Issue
Block a user