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