mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
OP-35 Cleanup of the uploader gadget, and removal of the ymodem library which is not used anymore.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2062 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
3e5797a8d2
commit
ae22e9103b
@ -10,7 +10,6 @@ SUBDIRS = \
|
||||
qextserialport \
|
||||
utils \
|
||||
glc_lib\
|
||||
qymodem \
|
||||
sdlgamepad \
|
||||
libqxt
|
||||
|
||||
|
@ -1,2 +0,0 @@
|
||||
LIBS += -l$$qtLibraryTarget(QYmodem)
|
||||
|
@ -1,5 +0,0 @@
|
||||
#
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS = src \
|
||||
|
@ -1,98 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file qymodem.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by J.D.Medhurst (a.k.a. Tixy)
|
||||
* @brief Implementation of base class for QymodemTx.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup ymodem_lib
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \section Credits
|
||||
* This implementation is based on J.D.Medhurst (a.k.a. Tixy) work from
|
||||
* <a href="http://yxit.co.uk">Tixy's source code</a>.
|
||||
*/
|
||||
|
||||
#include "qymodem.h"
|
||||
|
||||
quint16 QymodemBase::UpdateCRC16(quint16 crcIn, quint8 byte)
|
||||
{
|
||||
quint32 crc = crcIn;
|
||||
quint32 in = byte|0x100;
|
||||
do
|
||||
{
|
||||
crc <<= 1;
|
||||
in <<= 1;
|
||||
if(in&0x100)
|
||||
++crc;
|
||||
if(crc&0x10000)
|
||||
crc ^= 0x1021;
|
||||
}
|
||||
while(!(in&0x10000));
|
||||
return crc&0xffffu;
|
||||
}
|
||||
|
||||
|
||||
quint16 QymodemBase::CRC16(const quint8* data, size_t size)
|
||||
{
|
||||
quint32 crc = 0;
|
||||
const quint8* dataEnd = data+size;
|
||||
while(data<dataEnd)
|
||||
crc = UpdateCRC16(crc,*data++);
|
||||
crc = UpdateCRC16(crc,0);
|
||||
crc = UpdateCRC16(crc,0);
|
||||
return crc&0xffffu;
|
||||
}
|
||||
|
||||
|
||||
quint8 QymodemBase::Checksum(const quint8* data, size_t size)
|
||||
{
|
||||
int sum = 0;
|
||||
const quint8* dataEnd = data+size;
|
||||
while(data<dataEnd)
|
||||
sum += *data++;
|
||||
return sum&0xffu;
|
||||
}
|
||||
|
||||
|
||||
int QymodemBase::InChar(long timeout)
|
||||
{
|
||||
quint8 c;
|
||||
char cc;
|
||||
Port.setTimeout(timeout);
|
||||
int result =(int)Port.read(&cc,1);
|
||||
c=(quint8)cc;
|
||||
if(result==1)
|
||||
return c;
|
||||
if(result==0)
|
||||
return ErrorTimeout;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void QymodemBase::Cancel()
|
||||
{
|
||||
const quint8 CancelString[] = { CAN,CAN,CAN,CAN,CAN };
|
||||
Port.setTimeout(1000);
|
||||
Port.write((char*)CancelString,sizeof(CancelString));
|
||||
}
|
||||
|
@ -1,155 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file qymodem.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup ymodem_lib
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \section Credits
|
||||
* This implementation is based on J.D.Medhurst (a.k.a. Tixy) work from
|
||||
* <a href="http://yxit.co.uk">Tixy's source code</a>.
|
||||
*/
|
||||
|
||||
#ifndef YMODEM_H
|
||||
#define YMODEM_H
|
||||
#include <qextserialport/src/qextserialport.h>
|
||||
#include <QThread>
|
||||
|
||||
/**
|
||||
Base Class for QymodemTx.
|
||||
*/
|
||||
class QymodemBase: public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
/*!
|
||||
An error has ocorred.
|
||||
|
||||
\param errorString A string containing the error that has occurred.
|
||||
|
||||
\param errorNumber The error code.
|
||||
*/
|
||||
void Error(QString errorString,int errorNumber);
|
||||
/*!
|
||||
Information regarding a change of state in the transmission process.
|
||||
|
||||
\param infoString A string containing the information of the new state.
|
||||
|
||||
\param infoNumber The information number of the new state.
|
||||
*/
|
||||
void Information(QString infoString,int infoNumber);
|
||||
/*!
|
||||
Percentage of the file already sent.
|
||||
|
||||
\param percentSent The percentage of the file already sent.
|
||||
|
||||
*/
|
||||
void Percent(int percentSent);
|
||||
|
||||
protected:
|
||||
|
||||
inline QymodemBase(QextSerialPort& port)
|
||||
: Port(port)
|
||||
{}
|
||||
|
||||
/**
|
||||
Checksum a block of data.
|
||||
|
||||
@param data Start of data to checksum.
|
||||
@param size Size of data.
|
||||
|
||||
@return Sum of bytes in data, modulo 256.
|
||||
*/
|
||||
quint8 Checksum(const quint8* data, size_t size);
|
||||
|
||||
/**
|
||||
Calculate CRC for a block of data.
|
||||
|
||||
@param data Start of data to checksum.
|
||||
@param size Size of data.
|
||||
|
||||
@return CRC of data.
|
||||
*/
|
||||
quint16 CRC16(const quint8* data, size_t size);
|
||||
|
||||
/**
|
||||
Update CRC value by accumulating another byte of data.
|
||||
|
||||
@param crcIn Previous CRC value.
|
||||
@param byte A byte of data.
|
||||
|
||||
@return Updated CRC value.
|
||||
*/
|
||||
quint16 UpdateCRC16(quint16 crcIn, quint8 byte);
|
||||
|
||||
/**
|
||||
Receive a single character.
|
||||
If the timeout period is exceeded, ErrorTimeout is returned.
|
||||
|
||||
@param timeout Time in milliseconds to wait if no data available.
|
||||
|
||||
@return The character received, or a negative error value if failed.
|
||||
*/
|
||||
int InChar(long timeout);
|
||||
|
||||
/**
|
||||
Send CANcel sequence.
|
||||
*/
|
||||
void Cancel();
|
||||
|
||||
/**
|
||||
Enumeration of control characted used in communications protocol.
|
||||
*/
|
||||
enum ControlCharacters
|
||||
{
|
||||
SOH = 0x01,
|
||||
STX = 0x02,
|
||||
EOT = 0x04,
|
||||
ACK = 0x06,
|
||||
NAK = 0x15,
|
||||
CAN = 0x18
|
||||
};
|
||||
|
||||
/**
|
||||
Enumeration of possible error values.
|
||||
*/
|
||||
enum Error
|
||||
{
|
||||
ErrorTimeout = -200, /**< Timed out trying to communicate with other device */
|
||||
ErrorBlockRetriesExceded = -201 /**< A block could not be sent */
|
||||
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
The serial port to use for communications.
|
||||
*/
|
||||
|
||||
QextSerialPort& Port;
|
||||
};
|
||||
|
||||
|
||||
/** @} */ // End of group
|
||||
|
||||
#endif // YMODEM_H
|
@ -1,421 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file qymodem_tx.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by J.D.Medhurst (a.k.a. Tixy)
|
||||
* @brief Implementation of base class for QymodemSend.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup ymodem_lib
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \section Credits
|
||||
* This implementation is based on J.D.Medhurst (a.k.a. Tixy) work from
|
||||
* <a href="http://yxit.co.uk">Tixy's source code</a>.
|
||||
*/
|
||||
|
||||
#include "qymodem_tx.h"
|
||||
#include <string.h> // for memcpy and memset
|
||||
|
||||
|
||||
/**
|
||||
Minimum time in milli-seconds to wait for response from receiver.
|
||||
*/
|
||||
const unsigned SendTimeout = 11*1000;
|
||||
|
||||
|
||||
/**
|
||||
Process response from receiver.
|
||||
|
||||
@param c Value received from InChar.
|
||||
|
||||
@return One if received an ACKnowledge,
|
||||
zero if received a Negative AcKnowledge,
|
||||
or a negative error value.
|
||||
*/
|
||||
int QymodemTx::ProcessResponse(int c)
|
||||
{
|
||||
if(c<0)
|
||||
return c;
|
||||
if(c==CAN)
|
||||
{
|
||||
if(CancelCount++)
|
||||
return ErrorTranferTerminatedByReceiver;
|
||||
return 0;
|
||||
}
|
||||
CancelCount = 0;
|
||||
if(c==ACK)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Begin the Y-Modem transfer.
|
||||
|
||||
@param timeout Time in milliseconds to wait receiver to become ready.
|
||||
|
||||
@return Zero if transfer initialisation was successful, or an error code on failure.
|
||||
*/
|
||||
int QymodemTx::SendInitialise(unsigned timeout)
|
||||
{
|
||||
emit Information("Waiting for Receiver",QymodemTx::InfoSending);
|
||||
if(timeout<SendTimeout)
|
||||
timeout = SendTimeout;
|
||||
|
||||
while(InChar(-1)>=0) // flush input buffers
|
||||
{}
|
||||
|
||||
CancelCount = 0;
|
||||
|
||||
int c;
|
||||
for(;;)
|
||||
{
|
||||
const unsigned timeoutStep = 100;
|
||||
c = InChar(timeoutStep);
|
||||
if(c=='G')
|
||||
{
|
||||
SendCRC = true;
|
||||
WaitForBlockACK = false;
|
||||
break;
|
||||
}
|
||||
else if(c=='C')
|
||||
{
|
||||
SendCRC = true;
|
||||
WaitForBlockACK = true;
|
||||
break;
|
||||
}
|
||||
else if(c==NAK)
|
||||
{
|
||||
SendCRC = false;
|
||||
WaitForBlockACK = true;
|
||||
break;
|
||||
}
|
||||
if(c<0 && c!=ErrorTimeout)
|
||||
return c;
|
||||
if(timeout<timeoutStep)
|
||||
return ErrorTimeout;
|
||||
timeout -= timeoutStep;
|
||||
}
|
||||
|
||||
ModeChar = c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Send a single block of data.
|
||||
A zero sized block terminates the transfer.
|
||||
|
||||
@param data The data to transfer.
|
||||
@param size Size of data.
|
||||
|
||||
@return The number of transfered, or an error code on failure.
|
||||
The number of bytes may be less than \a size.
|
||||
|
||||
@pre SendInitialise() must have been successful.
|
||||
*/
|
||||
int QymodemTx::SendBlock(const quint8* data, size_t size)
|
||||
{
|
||||
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;
|
||||
|
||||
change_mode:
|
||||
|
||||
size_t blockSize = (Use1KBlocks && size>=1024) ? 1024 : 128;
|
||||
size_t dataSize = size<blockSize ? size : blockSize; // size of data to send in block
|
||||
|
||||
if(!dataSize)
|
||||
{
|
||||
// all bytes sent, so end transfer by sending a single EOT...
|
||||
block[0] = EOT;
|
||||
blockSize = 1;
|
||||
waitForBlockACK = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// make block header...
|
||||
block[0] = blockSize==1024 ? STX : SOH;
|
||||
block[1] = BlockNumber&0xffu;
|
||||
block[2] = (~BlockNumber)&0xffu;
|
||||
|
||||
// copy data for block (padding with EOF)...
|
||||
memcpy(block+3,data,dataSize);
|
||||
memset(block+3+dataSize,26,blockSize-dataSize);
|
||||
|
||||
// append checksum/crc...
|
||||
if(SendCRC)
|
||||
{
|
||||
quint16 crc = CRC16(block+3,blockSize);
|
||||
blockSize += 3;
|
||||
block[blockSize++] = (quint8)(crc>>8);
|
||||
block[blockSize++] = (quint8)crc;
|
||||
}
|
||||
else
|
||||
{
|
||||
quint8 sum = Checksum(block+3,blockSize);
|
||||
blockSize += 3;
|
||||
block[blockSize++] = sum;
|
||||
}
|
||||
}
|
||||
|
||||
do_retry:
|
||||
// count attenpts...
|
||||
if(!retryCount--)
|
||||
return ErrorBlockRetriesExceded;
|
||||
|
||||
quint8* out = block;
|
||||
size_t outSize = blockSize;
|
||||
for(;;)
|
||||
{
|
||||
// send some data...
|
||||
Port.setTimeout(1000);;
|
||||
int result = (int)Port.write((char*)out,outSize);
|
||||
if(result<0)
|
||||
return result; // return error
|
||||
if(result==0)
|
||||
return ErrorTimeout;
|
||||
|
||||
// adjust for data remaining...
|
||||
out += result;
|
||||
outSize -= result;
|
||||
|
||||
// end if done...
|
||||
if(!outSize)
|
||||
break;
|
||||
|
||||
// poll for signal from receiver...
|
||||
result = ProcessResponse(InChar(10));
|
||||
if(result==ErrorTimeout)
|
||||
continue; // nothing received
|
||||
if(result<0)
|
||||
return result; // return error
|
||||
if(!result)
|
||||
goto retry; // negative acknowledge received
|
||||
}
|
||||
|
||||
if(waitForBlockACK)
|
||||
{
|
||||
// wait for up to one second for block to be acknowledged...
|
||||
int c = InChar(1000);
|
||||
int result = ProcessResponse(c);
|
||||
if(result<0)
|
||||
return result; // return error
|
||||
if(!result)
|
||||
{
|
||||
// negagtive acknowledge received...
|
||||
if(c=='C' && !SendCRC)
|
||||
{
|
||||
// change to CRC mode if receiver sent 'C', and retry...
|
||||
SendCRC = true;
|
||||
goto change_mode;
|
||||
}
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// check for receiver sending a cancel byte...
|
||||
int result = ProcessResponse(InChar(0));
|
||||
if(result<0)
|
||||
{
|
||||
if(result!=ErrorTimeout)
|
||||
return result; // return error if it's not a timeout
|
||||
}
|
||||
else
|
||||
{
|
||||
// ignore other responses
|
||||
}
|
||||
}
|
||||
|
||||
// block transferred OK...
|
||||
++BlockNumber;
|
||||
return dataSize;
|
||||
|
||||
retry:
|
||||
while(InChar(500)>=0) // flush input buffers
|
||||
{}
|
||||
goto do_retry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Send data.
|
||||
A zero sized block terminates the transfer.
|
||||
|
||||
@param data The data to transfer.
|
||||
@param size Size of data.
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
|
||||
@pre SendInitialise() must have been successful.
|
||||
*/
|
||||
int QymodemTx::SendData(const quint8* data, size_t size)
|
||||
{
|
||||
do
|
||||
{
|
||||
int result = SendBlock(data, size);
|
||||
if(result<0)
|
||||
return result;
|
||||
data += result;
|
||||
size -= result;
|
||||
}
|
||||
while(size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Send an entire stread of data.
|
||||
|
||||
@param in The stream of data to send.
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
|
||||
@pre SendInitialise() must have been successful.
|
||||
*/
|
||||
int QymodemTx::SendAll(InStream& in)
|
||||
{
|
||||
BlockNumber = 1; // first block to send is number one
|
||||
size_t size;
|
||||
do
|
||||
{
|
||||
// get data from input stream...
|
||||
quint8 data[1024];
|
||||
int result = in.In(data,sizeof(data));
|
||||
emit Percent(in.percent);
|
||||
if(result<0)
|
||||
return ErrorInputStreamError;
|
||||
|
||||
// send data...
|
||||
|
||||
size = result;
|
||||
result = SendData(data,size);
|
||||
if(result<0)
|
||||
return result;
|
||||
}
|
||||
while(size); // end when no more data left
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Construct the data for the first block of a Y-Modem transfer.
|
||||
|
||||
@param[out] buffer The buffer to store the constructed block. Size must be >=128 bytes.
|
||||
@param fileName The name of the file being transferred.
|
||||
@param fileSize The size of the file being transferred.
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
*/
|
||||
int QymodemTx::MakeBlock0(quint8* buffer, const char* fileName, size_t fileSize)
|
||||
{
|
||||
// setup buffer for block 0...
|
||||
quint8* out = buffer;
|
||||
quint8* outEnd = buffer+128-1;
|
||||
memset(buffer,0,128);
|
||||
|
||||
// copy file name to block data...
|
||||
while(out<outEnd)
|
||||
{
|
||||
char c = *fileName++;
|
||||
if(c>='A' && c<='Z')
|
||||
c += 'a'-'A'; // convert name to lower-case
|
||||
else if(c=='\\')
|
||||
c = '/'; // convert back-slash to forward-slash
|
||||
*out++ = c;
|
||||
if(!c)
|
||||
break; // end of name
|
||||
}
|
||||
|
||||
// convert fileSize to a decimal number...
|
||||
char length[sizeof(size_t)*3+1]; // buffer big enough to hold length as decimal number
|
||||
char* lenEnd = length+sizeof(length);
|
||||
char* len = lenEnd;
|
||||
do
|
||||
{
|
||||
*--len = '0'+fileSize%10; // prepend digit to buffer
|
||||
fileSize /= 10;
|
||||
}
|
||||
while(fileSize); // end when all digits done
|
||||
|
||||
// append file length to block data...
|
||||
while(out<outEnd && len<lenEnd)
|
||||
*out++ = *len++;
|
||||
|
||||
// check that buffer was big enough...
|
||||
if(out>=outEnd)
|
||||
return ErrorFileNameTooLong;
|
||||
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
|
||||
QymodemTx::QymodemTx(QextSerialPort& port)
|
||||
: QymodemBase(port)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
int QymodemTx::SendY(const char* fileName, size_t size, InStream& in, unsigned timeout)
|
||||
{
|
||||
Use1KBlocks = true;
|
||||
quint8 buffer[128];
|
||||
int result = MakeBlock0(buffer,fileName,size);
|
||||
if(result<0)
|
||||
return result;
|
||||
|
||||
result = SendInitialise(timeout);
|
||||
if(result<0 && result!=ErrorBlockRetriesExceded)
|
||||
return result;
|
||||
emit Information("Sending "+QString(fileName),QymodemTx::InfoSending);
|
||||
BlockNumber = 0;
|
||||
result = SendBlock(buffer,sizeof(buffer));
|
||||
if(result<0)
|
||||
return result;
|
||||
|
||||
result = InChar(SendTimeout);
|
||||
if(result<0)
|
||||
return result;
|
||||
if(result!=ModeChar)
|
||||
return ErrorReceiverNotBehaving;
|
||||
|
||||
result = SendAll(in);
|
||||
if(result<0)
|
||||
return result;
|
||||
|
||||
result = InChar(SendTimeout);
|
||||
if(result<0)
|
||||
return result;
|
||||
if(result!=ModeChar)
|
||||
return ErrorReceiverNotBehaving;
|
||||
|
||||
memset(buffer,0,sizeof(buffer));
|
||||
BlockNumber = 0;
|
||||
result = SendBlock(buffer,sizeof(buffer));
|
||||
if(result<0)
|
||||
return result;
|
||||
emit Percent(100);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,129 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file qymodem_tx.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup ymodem_lib
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \section Credits
|
||||
* This implementation is based on J.D.Medhurst (a.k.a. Tixy) work from
|
||||
* <a href="http://yxit.co.uk">Tixy's source code</a>.
|
||||
*/
|
||||
|
||||
#ifndef YMODEM_TX_H
|
||||
#define YMODEM_TX_H
|
||||
#include "qymodem.h"
|
||||
|
||||
/**
|
||||
Base Class for QymodemSend.
|
||||
*/
|
||||
class QymodemTx : public QymodemBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Construct a Y-Modem object which will transmit data over the given port.
|
||||
|
||||
@param port The port.
|
||||
*/
|
||||
QymodemTx(QextSerialPort& port);
|
||||
|
||||
/**
|
||||
Abstract class representing a stream of data being read.
|
||||
*/
|
||||
|
||||
class InStream
|
||||
{
|
||||
public:
|
||||
int percent;
|
||||
/**
|
||||
Read data from the stream.
|
||||
|
||||
@param[out] data Pointer to buffer to hold data read from stream.
|
||||
@param size Maximum size of data to read.
|
||||
|
||||
@return Number of bytes successfully read, or a negative error value if failed.
|
||||
*/
|
||||
virtual int In(quint8* data, size_t size) =0;
|
||||
|
||||
/**
|
||||
Empty destructor to avoid compiler warnings.
|
||||
*/
|
||||
inline virtual ~InStream() {}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Send data using Y-Modem.
|
||||
|
||||
@param fileName The name of the file being transferred.
|
||||
@param size The size of the data being transferred.
|
||||
@param in The stream of data to send.
|
||||
@param timeout Time in milliseconds to wait receiver to become ready.
|
||||
|
||||
@return Zero if transfer was successful, or a negative error value if failed.
|
||||
*/
|
||||
int SendY(const char* fileName, size_t size, InStream& in, unsigned timeout);
|
||||
|
||||
/**
|
||||
Enumeration of possible error values.
|
||||
*/
|
||||
enum TxError
|
||||
{
|
||||
ErrorInputStreamError = -300, /**< Error with input stream */
|
||||
ErrorReceiverNotBehaving = -301, /**< Unexpected data received */
|
||||
ErrorTranferTerminatedByReceiver= -302, /**< Transfer was terminated by receiver */
|
||||
ErrorFileNameTooLong = -303, /**< File name was too long to be transmitted */
|
||||
ErrorFileNotFound = -303,/**< Error file not found */
|
||||
ErrorCoulNotOpenPort = -304,/**< Error Port could not be open */
|
||||
ErrorFileTransmissionInProgress = -305/**< Error, user tried to transmit a File while other File transmisssion is in progress */
|
||||
|
||||
};
|
||||
/**
|
||||
Enumeration of possible information values.
|
||||
*/
|
||||
enum Info
|
||||
{
|
||||
InfoSending = -100,/**< Info, the transmission started and the file is being sent*/
|
||||
InfoSent =-101,/**< Info, transmission finished,the file as been sent */
|
||||
InfoWaitingforReceiver =-102/**< Info, the transmission is waiting for the receiver to signal begin of transfer */
|
||||
};
|
||||
|
||||
private:
|
||||
int SendInitialise(unsigned timeout);
|
||||
int SendBlock(const quint8* data, size_t size);
|
||||
int SendData(const quint8* data, size_t size);
|
||||
int SendAll(InStream& in);
|
||||
int MakeBlock0(quint8* buffer, const char* fileName, size_t fileSize);
|
||||
int ProcessResponse(int c);
|
||||
private:
|
||||
size_t BlockNumber;
|
||||
bool SendCRC;
|
||||
bool WaitForBlockACK;
|
||||
bool Use1KBlocks;
|
||||
quint8 ModeChar;
|
||||
int CancelCount;
|
||||
};
|
||||
|
||||
|
||||
#endif // YMODEM_TX_H
|
@ -1,127 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file qymodemsend.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by J.D.Medhurst (a.k.a. Tixy)
|
||||
* @brief Implementation of Class for presenting a file as a input stream.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup ymodem_lib
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \section Credits
|
||||
* This implementation is based on J.D.Medhurst (a.k.a. Tixy) work from
|
||||
* <a href="http://yxit.co.uk">Tixy's source code</a>.
|
||||
*/
|
||||
|
||||
#include "qymodem_tx.h"
|
||||
|
||||
/**
|
||||
Class for presenting a file as a input stream.
|
||||
*/
|
||||
class QymodemFileStream : public QymodemTx::InStream
|
||||
{
|
||||
public :
|
||||
QymodemFileStream()
|
||||
: File(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Open the file stream.
|
||||
|
||||
@param filename The name of the file to Open.
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
|
||||
*/
|
||||
int Open(const char* fileName)
|
||||
{
|
||||
File = fopen(fileName,"rb");
|
||||
if(!File)
|
||||
return QymodemTx::ErrorInputStreamError;
|
||||
// find file size...
|
||||
if(fseek(File,0,SEEK_END))
|
||||
{
|
||||
fclose(File);
|
||||
return QymodemTx::ErrorInputStreamError;
|
||||
}
|
||||
TotalSize = ftell(File);
|
||||
if(fseek(File,0,SEEK_SET))
|
||||
{
|
||||
fclose(File);
|
||||
return QymodemTx::ErrorInputStreamError;
|
||||
}
|
||||
TransferredSize = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Close the stream.
|
||||
*/
|
||||
void Close()
|
||||
{
|
||||
if(File)
|
||||
{
|
||||
fclose(File);
|
||||
File = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Return the size of the file.
|
||||
|
||||
@return File size.
|
||||
*/
|
||||
inline size_t Size()
|
||||
{
|
||||
return TotalSize;
|
||||
}
|
||||
|
||||
/**
|
||||
Read data from the stream.
|
||||
|
||||
@param[out] data Pointer to buffer to hold data read from stream.
|
||||
@param size Maximum size of data to read.
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
*/
|
||||
int In(quint8* data, size_t size)
|
||||
{
|
||||
percent = TotalSize ? ((quint64)TransferredSize*(quint64)100)/(quint64)TotalSize : 0;
|
||||
fflush(stdout);
|
||||
size=fread(data,sizeof(quint8),size,File);
|
||||
if(size)
|
||||
{
|
||||
TransferredSize += size;
|
||||
return size;
|
||||
}
|
||||
if(TransferredSize!=TotalSize)
|
||||
return QymodemTx::ErrorInputStreamError;
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
FILE* File;
|
||||
size_t TotalSize;
|
||||
size_t TransferredSize;
|
||||
|
||||
};
|
@ -1,141 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file qymodemsend.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Implementation of Y-Modem File transmit protocol.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup ymodem_lib
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "qymodemsend.h"
|
||||
|
||||
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param port The port to use for File transmission.
|
||||
|
||||
|
||||
*/
|
||||
QymodemSend::QymodemSend(QextSerialPort& port)
|
||||
: QymodemTx(port)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Send the file.
|
||||
|
||||
*/
|
||||
void QymodemSend::Send()
|
||||
{
|
||||
|
||||
QymodemFileStream source;
|
||||
int error = source.Open(FileName);
|
||||
if(error)
|
||||
emit Error("Can't open file " + QString(FileName),error);
|
||||
|
||||
|
||||
unsigned Timeout=30000;
|
||||
error = SendY(FileName,source.Size(),source,Timeout);
|
||||
if(error)
|
||||
{
|
||||
emit Error("Error during file transfer, error "+QString::number(error),error);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
emit Information("Sent OK",QymodemSend::InfoSent);
|
||||
}
|
||||
source.Close();
|
||||
}
|
||||
/**
|
||||
Send file.
|
||||
|
||||
@param filename The name of the file to Send.
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
|
||||
*/
|
||||
int QymodemSend::SendFile(QString filename)
|
||||
{
|
||||
QFile file;
|
||||
if(!file.exists(filename))
|
||||
{
|
||||
emit Error("File not found",QymodemSend::ErrorFileNotFound);
|
||||
return QymodemSend::ErrorFileNotFound;
|
||||
}
|
||||
if(!Port.open(_DEVICE_SET_))
|
||||
{
|
||||
emit Error("Could not open port",QymodemSend::ErrorCoulNotOpenPort);
|
||||
return QymodemSend::ErrorCoulNotOpenPort;
|
||||
}
|
||||
QByteArray a=filename.toLocal8Bit();
|
||||
FileName=a.constData();
|
||||
Send();
|
||||
Port.close();
|
||||
return 0;
|
||||
|
||||
}
|
||||
/**
|
||||
Send file on a new Thread.
|
||||
|
||||
@param filename The name of the file to Send.
|
||||
|
||||
@return Zero if successful, or a negative error value if failed.
|
||||
|
||||
*/
|
||||
int QymodemSend::SendFileT(QString filename)
|
||||
{
|
||||
if(!isRunning())
|
||||
{
|
||||
FileNameT=filename;
|
||||
start();
|
||||
}
|
||||
else
|
||||
{
|
||||
return QymodemSend::ErrorFileTransmissionInProgress;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QymodemSend::run()
|
||||
{
|
||||
QFile file;
|
||||
if(!file.exists(FileNameT))
|
||||
{
|
||||
emit Error("File not found",QymodemSend::ErrorFileNotFound);
|
||||
return;
|
||||
}
|
||||
if(!Port.open(_DEVICE_SET_))
|
||||
{
|
||||
emit Error("Could not open port",QymodemSend::ErrorCoulNotOpenPort);
|
||||
return;
|
||||
}
|
||||
QByteArray a=FileNameT.toLocal8Bit();
|
||||
FileName=a.constData();
|
||||
Send();
|
||||
Port.close();
|
||||
return;
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file qymodemsend.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup ymodem_lib
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QYMODEMSEND_H
|
||||
#define QYMODEMSEND_H
|
||||
#include "qymodem_tx.h"
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include "qymodemfilestream.cpp"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#define _DEVICE_SET_ QIODevice::ReadWrite|QIODevice::Unbuffered
|
||||
#else
|
||||
#define _DEVICE_SET_ QIODevice::ReadWrite
|
||||
#endif
|
||||
|
||||
/**
|
||||
Class for sending a file via Y-Modem transmit protocol.
|
||||
*/
|
||||
class QymodemSend:public QymodemTx
|
||||
{
|
||||
|
||||
public:
|
||||
QymodemSend(QextSerialPort& port);
|
||||
int SendFile(QString filename);
|
||||
int SendFileT(QString filename);
|
||||
|
||||
private:
|
||||
void run();
|
||||
const char* FileName;
|
||||
void Send();
|
||||
QymodemFileStream InFile;
|
||||
QString FileNameT;
|
||||
|
||||
};
|
||||
#endif // QYmodemSend_H
|
@ -1,17 +0,0 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = QYmodem
|
||||
DEFINES += QYMODEM_LIBRARY
|
||||
include(../../../openpilotgcslibrary.pri)
|
||||
|
||||
# CONFIG += staticlib
|
||||
SOURCES += qymodem.cpp \
|
||||
qymodem_tx.cpp \
|
||||
qymodemfilestream.cpp \
|
||||
qymodemsend.cpp
|
||||
HEADERS += qymodem_tx.h \
|
||||
qymodem.h \
|
||||
qymodemsend.h
|
||||
LIBS += -l$$qtLibraryTarget(QExtSerialPort)
|
||||
|
||||
|
||||
win32:LIBS += -lsetupapi
|
@ -72,6 +72,8 @@ SUBDIRS += plugin_modelview
|
||||
#Uploader Gadget
|
||||
plugin_uploader.subdir = uploader
|
||||
plugin_uploader.depends = plugin_coreplugin
|
||||
plugin_modelview.depends = plugin_uavobjects
|
||||
plugin_modelview.depends = plugin_rawhid
|
||||
SUBDIRS += plugin_uploader
|
||||
|
||||
#Dial Gadget
|
||||
|
@ -31,6 +31,10 @@ deviceWidget::deviceWidget(QWidget *parent) :
|
||||
{
|
||||
myDevice = new Ui_deviceWidget();
|
||||
myDevice->setupUi(this);
|
||||
|
||||
connect(myDevice->verifyButton, SIGNAL(clicked()), this, SLOT(verifyFirmware()));
|
||||
connect(myDevice->retrieveButton, SIGNAL(clicked()), this, SLOT(downloadFirmware()));
|
||||
connect(myDevice->updateButton, SIGNAL(clicked()), this, SLOT(uploadFirmware()));
|
||||
}
|
||||
|
||||
void deviceWidget::setDeviceID(int devID){
|
||||
@ -48,15 +52,78 @@ void deviceWidget::setDfu(OP_DFU *dfu)
|
||||
void deviceWidget::populate()
|
||||
{
|
||||
int id = m_dfu->devices[deviceID].ID;
|
||||
myDevice->deviceID->setText(QString("ID: ") + QString::number(id));
|
||||
myDevice->deviceID->setText(QString("Device ID: ") + QString::number(id));
|
||||
bool r = m_dfu->devices[deviceID].Readable;
|
||||
bool w = m_dfu->devices[deviceID].Writable;
|
||||
myDevice->deviceACL->setText(r ? "R" : "-" + w ? "W" : "-");
|
||||
myDevice->deviceACL->setText(QString("Access: ") + QString(r ? "R" : "-") + QString(w ? "W" : "-"));
|
||||
myDevice->maxCodeSize->setText(QString("Max code size: ") +QString::number(m_dfu->devices[deviceID].SizeOfCode));
|
||||
myDevice->fwCRC->setText(QString("FW CRC: ") + QString::number(m_dfu->devices[deviceID].FW_CRC));
|
||||
|
||||
int size=((OP_DFU::device)m_dfu->devices[deviceID]).SizeOfDesc;
|
||||
m_dfu->enterDFU(deviceID);
|
||||
QString str = m_dfu->DownloadDescription(size);
|
||||
myDevice->description->setMaxLength(size);
|
||||
myDevice->description->setText(str.left(str.indexOf(QChar(255))));
|
||||
|
||||
myDevice->statusLabel->setText(QString("Ready..."));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Verifies the firmware CRC
|
||||
*/
|
||||
void deviceWidget::verifyFirmware()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Sends a firmware to the device
|
||||
*/
|
||||
void deviceWidget::uploadFirmware()
|
||||
{
|
||||
if (!m_dfu->devices[deviceID].Writable) {
|
||||
myDevice->statusLabel->setText(QString("Device not writable!"));
|
||||
return;
|
||||
}
|
||||
|
||||
bool verify = true;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
OP_DFU::Status retstatus=dfu.UploadFirmware(file.toAscii(),verify, device);
|
||||
if(retstatus!=OP_DFU::Last_operation_Success)
|
||||
{
|
||||
cout<<"Upload failed with code:"<<dfu.StatusToString(retstatus).toLatin1().data();
|
||||
return -1;
|
||||
}
|
||||
if(!description.isEmpty())
|
||||
{
|
||||
retstatus=dfu.UploadDescription(description);
|
||||
if(retstatus!=OP_DFU::Last_operation_Success)
|
||||
{
|
||||
cout<<"Upload failed with code:"<<dfu.StatusToString(retstatus).toLatin1().data();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
cout<<"Uploading Succeded!\n";
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieves the firmware from the device
|
||||
*/
|
||||
void deviceWidget::downloadFirmware()
|
||||
{
|
||||
if (!m_dfu->devices[deviceID].Readable) {
|
||||
myDevice->statusLabel->setText(QString("Device not readable!"));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
qint32 size=((OP_DFU::device)dfu.devices[device]).SizeOfCode;
|
||||
bool ret=dfu.SaveByteArrayToFile(file.toAscii(),dfu.StartDownload(size,OP_DFU::FW));
|
||||
return ret;
|
||||
*/
|
||||
}
|
||||
|
@ -49,6 +49,9 @@ private:
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void verifyFirmware();
|
||||
void uploadFirmware();
|
||||
void downloadFirmware();
|
||||
|
||||
};
|
||||
|
||||
|
@ -26,10 +26,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -40,28 +40,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="maxCodeSize">
|
||||
<property name="text">
|
||||
<string>MaxCodeSize</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="fwCRC">
|
||||
<property name="text">
|
||||
<string>fwCRC</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="BLVersion">
|
||||
<property name="text">
|
||||
<string>BootLoaderVersion</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="4">
|
||||
<item row="8" column="0" colspan="4">
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
@ -74,7 +60,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<item row="3" column="2" rowspan="2">
|
||||
<widget class="QGraphicsView" name="devicePicture">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
@ -84,27 +70,41 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<item row="5" column="2">
|
||||
<widget class="QPushButton" name="verifyButton">
|
||||
<property name="text">
|
||||
<string>Verify...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<item row="6" column="2">
|
||||
<widget class="QPushButton" name="updateButton">
|
||||
<property name="text">
|
||||
<string>Update...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<item row="7" column="2">
|
||||
<widget class="QPushButton" name="retrieveButton">
|
||||
<property name="text">
|
||||
<string>Retrieve...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="BLVersion">
|
||||
<property name="text">
|
||||
<string>BootLoaderVersion</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="fwCRC">
|
||||
<property name="text">
|
||||
<string>fwCRC</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -3,9 +3,7 @@ TARGET = Uploader
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/uavobjects/uavobjects.pri)
|
||||
include(../../libs/qextserialport/qextserialport.pri)
|
||||
include(../../plugins/rawhid/rawhid.pri)
|
||||
include(../../libs/qymodem/qymodem.pri)
|
||||
HEADERS += uploadergadget.h \
|
||||
uploadergadgetconfiguration.h \
|
||||
uploadergadgetfactory.h \
|
||||
|
@ -27,8 +27,6 @@
|
||||
#include "uploadergadget.h"
|
||||
#include "uploadergadgetwidget.h"
|
||||
#include "uploadergadgetconfiguration.h"
|
||||
#include <qextserialport/src/qextserialport.h>
|
||||
#include <qextserialport/src/qextserialenumerator.h>
|
||||
|
||||
UploaderGadget::UploaderGadget(QString classId, UploaderGadgetWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
@ -47,15 +45,5 @@ UploaderGadget::~UploaderGadget()
|
||||
void UploaderGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
UploaderGadgetConfiguration *m = qobject_cast< UploaderGadgetConfiguration*>(config);
|
||||
PortSettings portsettings;
|
||||
portsettings.BaudRate=m->Speed();
|
||||
portsettings.DataBits=m->DataBits();
|
||||
portsettings.FlowControl=m->Flow();
|
||||
portsettings.Parity=m->Parity();
|
||||
portsettings.StopBits=m->StopBits();
|
||||
portsettings.Timeout_Millisec=m->TimeOut();
|
||||
//Creates new serial port with the user configuration and passes it to the widget
|
||||
QextSerialPort *port=new QextSerialPort(m->Port(),portsettings,QextSerialPort::Polling);
|
||||
m_widget->setPort(port);
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,8 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
|
||||
*/
|
||||
void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
|
||||
{
|
||||
Q_UNUSED(callerObj);
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
UAVObject *fwIAP = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("FirmwareIAPObj")));
|
||||
@ -66,7 +68,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
|
||||
if (!success) {
|
||||
log(QString("Oops, failure step 1"));
|
||||
log("Reset did NOT happen");
|
||||
currentStep == IAP_STATE_READY;
|
||||
currentStep = IAP_STATE_READY;
|
||||
disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool)));
|
||||
break;
|
||||
}
|
||||
@ -80,7 +82,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
|
||||
if (!success) {
|
||||
log(QString("Oops, failure step 2"));
|
||||
log("Reset did NOT happen");
|
||||
currentStep == IAP_STATE_READY;
|
||||
currentStep = IAP_STATE_READY;
|
||||
disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool)));
|
||||
break;
|
||||
}
|
||||
@ -90,7 +92,8 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
|
||||
fwIAP->updated();
|
||||
log(QString("IAP Step 3"));
|
||||
break;
|
||||
case IAP_STEP_RESET: {
|
||||
case IAP_STEP_RESET:
|
||||
{
|
||||
currentStep = IAP_STATE_READY;
|
||||
if (success) {
|
||||
log("Oops, unexpected success step 3");
|
||||
@ -124,7 +127,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
|
||||
}
|
||||
m_config->boardStatus->setText("Bootloader");
|
||||
currentStep = IAP_STATE_BOOTLOADER;
|
||||
OP_DFU::Status ret=dfu.StatusRequest();
|
||||
//OP_DFU::Status ret=dfu.StatusRequest();
|
||||
dfu.findDevices();
|
||||
log(QString("Found ") + QString::number(dfu.numberOfDevices) + QString(" device(s)."));
|
||||
// Delete all previous tabs:
|
||||
@ -144,7 +147,12 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
|
||||
m_config->resetButton->setEnabled(false);
|
||||
m_config->bootButton->setEnabled(true);
|
||||
}
|
||||
break;
|
||||
case IAP_STATE_BOOTLOADER:
|
||||
// We should never end up here anyway.
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,49 +217,14 @@ void UploaderGadgetWidget::clearLog()
|
||||
//user pressed send, send file using a new thread with qymodem library
|
||||
void UploaderGadgetWidget::send()
|
||||
{
|
||||
Ymodem->SendFileT(openFileNameLE->text());
|
||||
|
||||
}
|
||||
//destructor !!?! do I need to delete something else?
|
||||
UploaderGadgetWidget::~UploaderGadgetWidget()
|
||||
{
|
||||
delete Port;
|
||||
delete Ymodem;
|
||||
}
|
||||
|
||||
//from load configuration, creates a new qymodemsend class with the the port
|
||||
/**
|
||||
Cteates a new qymodemsend class.
|
||||
|
||||
@param port The serial port to use.
|
||||
|
||||
|
||||
*/
|
||||
void UploaderGadgetWidget::setPort(QextSerialPort* port)
|
||||
{
|
||||
|
||||
Port=port;
|
||||
Ymodem=new QymodemSend(*Port);
|
||||
//only now can we connect this signals
|
||||
//signals errors
|
||||
connect(Ymodem,SIGNAL(Error(QString,int))
|
||||
,this,SLOT(error(QString,int)));
|
||||
//signals new information
|
||||
connect(Ymodem,SIGNAL(Information(QString,int)),
|
||||
this,SLOT(info(QString,int)));
|
||||
//signals new percentage value
|
||||
connect(Ymodem,SIGNAL(Percent(int)),
|
||||
this,SLOT(updatePercSlot(int)));
|
||||
}
|
||||
/**
|
||||
Updates progress bar value.
|
||||
|
||||
@param i New percentage value.
|
||||
|
||||
*/
|
||||
void UploaderGadgetWidget::updatePercSlot(int i)
|
||||
{
|
||||
progressBar->setValue(i);
|
||||
}
|
||||
/**
|
||||
|
||||
Opens an open file dialog.
|
||||
@ -280,11 +253,12 @@ Shows a message box with an error string.
|
||||
*/
|
||||
void UploaderGadgetWidget::error(QString errorString, int errorNumber)
|
||||
{
|
||||
Q_UNUSED(errorNumber);
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setText(errorString);
|
||||
msgBox.exec();
|
||||
status->setText(errorString);
|
||||
m_config->boardStatus->setText(errorString);
|
||||
}
|
||||
/**
|
||||
Shows a message box with an information string.
|
||||
@ -296,5 +270,6 @@ Shows a message box with an information string.
|
||||
*/
|
||||
void UploaderGadgetWidget::info(QString infoString, int infoNumber)
|
||||
{
|
||||
status->setText(infoString);
|
||||
Q_UNUSED(infoNumber);
|
||||
m_config->boardStatus->setText(infoString);
|
||||
}
|
||||
|
@ -39,16 +39,11 @@
|
||||
|
||||
#include "rawhid/rawhidplugin.h"
|
||||
#include <QtGui/QWidget>
|
||||
#include <qextserialport/src/qextserialport.h>
|
||||
#include <qymodem/src/qymodemsend.h>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QThread>
|
||||
#include <QProgressBar>
|
||||
#include <QStringList>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
//using namespace qmapcontrol;
|
||||
|
||||
|
||||
class UploaderGadgetWidget : public QWidget
|
||||
@ -60,8 +55,6 @@ public:
|
||||
~UploaderGadgetWidget();
|
||||
typedef enum { IAP_STATE_READY, IAP_STATE_STEP_1, IAP_STATE_STEP_2, IAP_STEP_RESET, IAP_STATE_BOOTLOADER} IAPStep;
|
||||
|
||||
void setPort(QextSerialPort* port);
|
||||
|
||||
|
||||
private:
|
||||
Ui_UploaderWidget *m_config;
|
||||
@ -71,18 +64,12 @@ private:
|
||||
void clearLog();
|
||||
|
||||
QLineEdit* openFileNameLE;
|
||||
QextSerialPort *Port;
|
||||
QLabel* status;
|
||||
QymodemSend * Ymodem;
|
||||
QProgressBar *progressBar;
|
||||
QTimer *timer;
|
||||
|
||||
private slots:
|
||||
void setOpenFileName();
|
||||
void send();
|
||||
void error(QString errorString,int errorNumber);
|
||||
void info(QString infoString,int infoNumber);
|
||||
void updatePercSlot(int);
|
||||
void goToBootloader(UAVObject* = NULL, bool = false);
|
||||
void systemReset();
|
||||
void systemBoot();
|
||||
|
Loading…
x
Reference in New Issue
Block a user