1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

OP-21/Bootloader CLI- New version to be used with the new BL FW. Linux and MacOs Devs please test it, I'm having probs using serial port in unbuffered mode under Linux VM. I'm hoping its just a VM problem.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2212 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-12-10 19:16:09 +00:00 committed by zedamota
parent cc5a4c2bb9
commit eb01c55478
11 changed files with 584 additions and 317 deletions

View File

@ -15,39 +15,61 @@ int main(int argc, char *argv[])
port * info;
PortSettings settings;
settings.BaudRate=BAUD19200;
settings.BaudRate=BAUD57600;
settings.DataBits=DATA_8;
settings.FlowControl=FLOW_OFF;
settings.Parity=PAR_NONE;
settings.StopBits=STOP_2;
settings.Timeout_Millisec=500;
settings.StopBits=STOP_1;
settings.Timeout_Millisec=5000;
info=new port(settings,"COM2");
info=new port(settings,"COM3");
info->rxBuf = sspRxBuf;
info->rxBufSize = MAX_PACKET_DATA_LEN;
info->txBuf = sspTxBuf;
info->txBufSize = 255;
info->max_retry = 3;
info->timeoutLen = 100;
info->timeoutLen = 5000;
//qssp b(info);
qsspt bb(info);
uint8_t buf[1000];
QCoreApplication a(argc, argv);
QByteArray arr;
while(!bb.ssp_Synchronise())
{
qDebug()<<"trying sync";
}
bb.start();
qDebug()<<"sync complete";
buf[0]=0;
buf[1]=1;
buf[2]=2;
while(true)
{
if(bb.sendData(buf,63))
qDebug()<<"send OK";
// else
// qDebug()<<"send NOK";
// //bb.ssp_SendData(buf,63);
}
while(true)
{
if(bb.packets_Available()>0)
{
arr=bb.read_Packet();
qDebug()<<"receive="<<(int)arr[0]<<(int)arr[1]<<(int)arr[2];
}
// b.ssp_ReceiveProcess();
// b.ssp_SendProcess();
// if(b.isDataAvailable())
// {
// QByteArray bb=b.readData();
// qDebug()<<bb[0]<<bb[1]<<bb[2];
// }
bb.read_Packet(buf);
qDebug()<<"receive="<<(int)buf[0]<<(int)buf[1]<<(int)buf[2];
++buf[0];
++buf[1];
++buf[2];
//bb.ssp_SendData(buf,63);
bb.sendData(buf,63);
}
//bb.ssp_ReceiveProcess();
//bb.ssp_SendProcess();
}
return a.exec();
}

View File

@ -1,29 +1,38 @@
#include "port.h"
port::port(PortSettings settings,QString name)
#include "..\delay.h"
port::port(PortSettings settings,QString name):mstatus(port::closed)
{
timer.start();
sport = new QextSerialPort(name,settings, QextSerialPort::Polling);
sport->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
if(sport->open(QIODevice::ReadWrite|QIODevice::Unbuffered))
{
mstatus=port::open;
// sport->setDtr();
}
else
mstatus=port::error;
}
port::portstatus port::status()
{
return mstatus;
}
int16_t port::pfSerialRead(void)
{
char c[1];
if(sport->bytesAvailable()>0)
if(sport->bytesAvailable())
{
sport->read(c,1);
}
else return -1;
//qDebug()<<"read="<<c[0];
return c[0];
return (uint8_t)c[0];
}
void port::pfSerialWrite(uint8_t c)
{
char cc[1];
cc[0]=c;
while (sport->write(cc,1)==-1){};
sport->write(cc,1);
}
uint32_t port::pfGetTime(void)

View File

@ -9,7 +9,7 @@
class port
{
public:
enum portstatus{open,closed,error};
virtual int16_t pfSerialRead(void); // function to read a character from the serial input stream
virtual void pfSerialWrite( uint8_t ); // function to write a byte to be sent out the serial port
virtual uint32_t pfGetTime(void);
@ -38,7 +38,9 @@ public:
uint32_t TxError;
uint16_t flags;
port(PortSettings settings,QString name);
portstatus status();
private:
portstatus mstatus;
QTime timer;
QextSerialPort *sport;
};

View File

@ -120,6 +120,12 @@ void qssp::ssp_Init(const PortConfig_t* const info)
thisport->rxSeqNo = 255;
thisport->txSeqNo = 255;
thisport->SendState = SSP_IDLE;
thisport->InputState =(ReceiveState)0;
thisport->DecodeState =(decodeState_)0;
thisport->TxError =0;
thisport->RxError =0;
thisport->txSeqNo =0;
thisport->rxSeqNo =0;
}
/*!
@ -149,6 +155,8 @@ int16_t qssp::ssp_SendProcess( )
value = SSP_TX_TIMEOUT;
CLEARBIT( thisport->flags, ACK_RECEIVED);
thisport->SendState = SSP_IDLE;
if (debug)
qDebug()<<"Send TimeOut!";
}
} else {
value = SSP_TX_WAITING;
@ -184,6 +192,7 @@ int16_t qssp::ssp_ReceiveProcess()
}
// keep going until either we received a full packet or there are no more bytes to process
} while (packet_status != SSP_RX_COMPLETE && b != -1);
return packet_status;
}
@ -297,9 +306,13 @@ int16_t qssp::ssp_SendData(const uint8_t *data, const uint16_t length )
sf_MakePacket( thisport->txBuf, data, length, thisport->txSeqNo );
sf_SendPacket( ); // punch out the packet to the serial port
sf_SetSendTimeout( ); // do the timeout values
if (debug)
qDebug()<<"Sent DATA PACKET:"<<thisport->txSeqNo;
} else {
// error we are already sending a packet. Need to wait for the current packet to be acked or timeout.
value = SSP_TX_BUSY;
if (debug)
qDebug()<<"Error sending TX was busy";
}
return value;
}
@ -434,6 +447,8 @@ void qssp::sf_SendAckPacket(uint8_t seqNumber)
// create the packet, note we pass AckSequenceNumber directly
sf_MakePacket( thisport->txBuf, NULL, 0, AckSeqNumber );
sf_SendPacket( );
if (debug)
qDebug()<<"Sent ACK PACKET:"<<seqNumber;
// we don't set the timeout for an ACK because we don't ACK our ACKs in this protocol
}
@ -520,6 +535,9 @@ uint16_t qssp::sf_CheckTimeout()
if( current_time > thisport->timeout ) {
retval = TRUE;
}
if(retval)
if (debug)
qDebug()<<"timeout"<<current_time<<thisport->timeout;
return retval;
}
@ -695,11 +713,15 @@ int16_t qssp::sf_ReceivePacket()
SETBIT( thisport->txSeqNo, ACK_BIT );
thisport->SendState = SSP_ACKED;
value = FALSE;
if (debug)
qDebug()<<"Received ACK:"<<(thisport->txSeqNo & 0x7F);
}
// else ignore the ACK packet
} else {
// Received a 'data' packet, figure out what type of packet we received...
if( thisport->rxBuf[SEQNUM] == 0 ) {
if (debug)
qDebug()<<"Received SYNC Request";
// Synchronize sequence number with host
#ifdef ACTIVE_SYNCH
thisport->sendSynch = TRUE;
@ -717,6 +739,8 @@ int16_t qssp::sf_ReceivePacket()
// Let the application do something with the data/packet.
// skip the first two bytes (length and seq. no.) in the buffer.
if (debug)
qDebug()<<"Received DATA PACKET seq="<<thisport->rxSeqNo<<"Data="<<(uint8_t)thisport->rxBuf[2]<<(uint8_t)thisport->rxBuf[3]<<(uint8_t)thisport->rxBuf[4];
pfCallBack( &(thisport->rxBuf[2]), thisport->rxBufLen);
// after we send the ACK, it is possible for the host to send a new packet.
@ -728,16 +752,30 @@ int16_t qssp::sf_ReceivePacket()
}
return value;
}
qssp::qssp(port * info)
qssp::qssp(port * info,bool debug):debug(debug)
{
thisport=info;
thisport->maxRetryCount = info->max_retry;
thisport->timeoutLen = info->timeoutLen;
thisport->txBufSize = info->txBufSize;
thisport->rxBufSize = info->rxBufSize;
thisport->txBuf = info->txBuf;
thisport->rxBuf = info->rxBuf;
thisport->retryCount = 0;
thisport->sendSynch = FALSE; //TRUE;
thisport->rxSeqNo = 255;
thisport->txSeqNo = 255;
thisport->SendState = SSP_IDLE;
thisport->InputState =(ReceiveState)0;
thisport->DecodeState =(decodeState_)0;
thisport->TxError =0;
thisport->RxError =0;
thisport->txSeqNo =0;
thisport->rxSeqNo =0;
}
void qssp::pfCallBack( uint8_t * buf, uint16_t size)
{
if (debug)
qDebug()<<"receive callback"<<buf[0]<<buf[1]<<buf[2]<<buf[3]<<buf[4];
}

View File

@ -79,6 +79,7 @@ private:
void sf_MakePacket( uint8_t *buf, const uint8_t * pdata, uint16_t length, uint8_t seqNo );
int16_t sf_ReceivePacket();
uint16_t ssp_SendDataBlock(uint8_t *data, uint16_t length );
bool debug;
public:
/** PUBLIC FUNCTIONS **/
virtual void pfCallBack( uint8_t *, uint16_t); // call back function that is called when a full packet has been received
@ -89,7 +90,7 @@ public:
void ssp_Init( const PortConfig_t* const info);
int16_t ssp_ReceiveByte( );
uint16_t ssp_Synchronise( );
qssp(port * info);
qssp(port * info,bool debug);
};
#endif // QSSP_H

View File

@ -1,24 +1,50 @@
#include "qsspt.h"
qsspt::qsspt(port * info):qssp(info),endthread(false)
qsspt::qsspt(port * info,bool debug):qssp(info,debug),endthread(false),datapending(false),debug(debug)
{
this->start();
}
void qsspt::run()
{
while(!endthread)
{
this->ssp_ReceiveProcess();
this->ssp_SendProcess();
receivestatus=this->ssp_ReceiveProcess();
sendstatus=this->ssp_SendProcess();
sendbufmutex.lock();
if(datapending && receivestatus==SSP_TX_IDLE)
{
this->ssp_SendData(mbuf,msize);
datapending=false;
}
sendbufmutex.unlock();
if(sendstatus==SSP_TX_ACKED)
sendwait.wakeAll();
}
}
bool qsspt::sendData(uint8_t * buf,uint16_t size)
{
if(datapending)
return false;
sendbufmutex.lock();
datapending=true;
mbuf=buf;
msize=size;
sendbufmutex.unlock();
msendwait.lock();
sendwait.wait(&msendwait,100000);
msendwait.unlock();
return true;
}
void qsspt::pfCallBack( uint8_t * buf, uint16_t size)
{
//qDebug()<<"receive callback"<<buf[0]<<buf[1]<<buf[2]<<buf[3]<<buf[4]<<"array size="<<queue.count();
if (debug)
qDebug()<<"receive callback"<<buf[0]<<buf[1]<<buf[2]<<buf[3]<<buf[4]<<"array size="<<queue.count();
QByteArray array;
for(int x=0;x<size;x++)
{
array.append((char)buf[x]);
array.append(buf[x]);
}
mutex.lock();
queue.enqueue(array);
@ -29,12 +55,18 @@ int qsspt::packets_Available()
{
return queue.count();
}
QByteArray qsspt::read_Packet()
int qsspt::read_Packet(void * data)
{
mutex.lock();
QByteArray arr=queue.dequeue();
if(queue.size()==0)
{
mutex.unlock();
return arr;
return -1;
}
QByteArray arr=queue.dequeue();
memcpy(data,(uint8_t*)arr.data(),arr.length());
mutex.unlock();
return arr.length();
}
qsspt::~qsspt()
{

View File

@ -4,20 +4,30 @@
#include "qssp.h"
#include <QThread>
#include <QQueue>
class qsspt:private qssp, public QThread
#include <QWaitCondition>
class qsspt:public qssp, public QThread
{
public:
qsspt(port * info);
qsspt(port * info,bool debug);
void run();
int packets_Available();
QByteArray read_Packet();
int read_Packet(void *);
~qsspt();
bool sendData(uint8_t * buf,uint16_t size);
private:
virtual void pfCallBack( uint8_t *, uint16_t);
uint8_t * mbuf;
uint16_t msize;
QQueue<QByteArray> queue;
QMutex mutex;
QMutex sendbufmutex;
bool datapending;
bool endthread;
uint16_t sendstatus;
uint16_t receivestatus;
QWaitCondition sendwait;
QMutex msendwait;
bool debug;
};
#endif // QSSPT_H

View File

@ -8,15 +8,26 @@
int main(int argc, char *argv[])
{
///SSP/////////////////////////////////
/////////////////////////////////////////////
// OP_DFU dfu(false);
// dfu.test();
QCoreApplication a(argc, argv);
// argc=4;
// argv[1]="-ls";
// argv[2]="-t";
// argv[3]="COM3";
if(argc>1||!PRIVATE)
{
bool use_serial=false;
bool verify;
bool debug=false;
OP_DFU::Actions action;
QString file;
QString serialport;
QString description;
int device=-1;
QStringList args;
@ -44,6 +55,7 @@ int main(int argc, char *argv[])
cout<<"| -r : resets the device |\n";
cout<<"| -j : exits bootloader and jumps to user FW |\n";
cout<<"| -debug : prints debug information |\n";
cout<<"| -t <port> : uses serial port* |\n";
cout<<"| |\n";
cout<<"| examples: |\n";
cout<<"| |\n";
@ -52,6 +64,8 @@ int main(int argc, char *argv[])
cout<<"| |\n";
cout<<"| Perform a quick compare of FW in file with FW in device #1 |\n";
cout<<"| OPUploadTool -ch c:/OpenPilot2.bin -d 2 |\n";
cout<<"| |\n";
cout<<"| *requires valid user space firmwares already running |\n";
cout<<"|________________________________________________________________________|\n";
return 0;
@ -168,6 +182,14 @@ int main(int argc, char *argv[])
cout<<"wrong parameters";
return -1;
}
if(args.contains(USE_SERIAL))
{
if(args.indexOf(USE_SERIAL)+1<args.length())
{
serialport=(args[args.indexOf(USE_SERIAL)+1]);
use_serial=true;
}
}
if(debug)
{
qDebug()<<"Action="<<(int)action;
@ -175,10 +197,16 @@ int main(int argc, char *argv[])
qDebug()<<"Device="<<device;
qDebug()<<"Action="<<action;
qDebug()<<"Desctription"<<description;
qDebug()<<"Use Serial port"<<use_serial;
if(use_serial)
qDebug()<<"Port Name"<<serialport;
}
///////////////////////////////////ACTIONS START///////////////////////////////////////////////////
OP_DFU dfu(debug);
OP_DFU dfu(debug,use_serial,serialport);
if(!dfu.ready())
return -1;
dfu.AbortOperation();
if(!dfu.enterDFU(0))
{
@ -294,12 +322,12 @@ int main(int argc, char *argv[])
return 0;
}
OP_DFU dfu(true);
//dfu.findDevices();
dfu.enterDFU(1);
dfu.UploadFirmware("c:/ahrs.bin",true,1);
// dfu.UploadDescription("josemanuel");
// QString str=dfu.DownloadDescription(12);
// OP_DFU dfu(true);
// //dfu.findDevices();
// dfu.enterDFU(1);
// dfu.UploadFirmware("c:/ahrs.bin",true,1);
// // dfu.UploadDescription("josemanuel");
// // QString str=dfu.DownloadDescription(12);
// dfu.JumpToApp();
// qDebug()<<"Description="<<str;
return a.exec();

View File

@ -2,9 +2,49 @@
#include <cmath>
#include <qwaitcondition.h>
#include <QMutex>
#include <conio.h>
OP_DFU::OP_DFU(bool _debug): debug(_debug)
OP_DFU::OP_DFU(bool _debug,bool _use_serial,QString portname): debug(_debug),use_serial(_use_serial),mready(true)
{
if(use_serial)
{
cout<<"Connect hw now and press any key";
// getch();
// delay::msleep(2000);
PortSettings settings;
settings.BaudRate=BAUD57600;
settings.DataBits=DATA_8;
settings.FlowControl=FLOW_OFF;
settings.Parity=PAR_NONE;
settings.StopBits=STOP_1;
settings.Timeout_Millisec=1000;
info=new port(settings,portname);
info->rxBuf = sspRxBuf;
info->rxBufSize = MAX_PACKET_DATA_LEN;
info->txBuf = sspTxBuf;
info->txBufSize = MAX_PACKET_DATA_LEN;
info->max_retry = 10;
info->timeoutLen = 1000;
if(info->status()!=port::open)
{
cout<<"Could not open serial port\n";
mready=false;
return;
}
serialhandle=new qsspt(info,debug);
while(serialhandle->ssp_Synchronise()==false)
{
if (debug)
qDebug()<<"SYNC failed, resending";
}
qDebug()<<"SYNC Succeded";
serialhandle->start();
// serialhandle->start();
}
else
{
send_delay=10;
use_delay=true;
int numDevices=0;
@ -27,16 +67,17 @@ OP_DFU::OP_DFU(bool _debug): debug(_debug)
qDebug() << numDevices << " device(s) opened";
//sendReset();
}
}
void OP_DFU::sendReset(void)
{
char b[64]={0x02,0x24,0x3C,0x20,0x17,0x00,0x30,0x76,0x1F,0x40,0x62,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6C,0x40,0x2E,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
hidHandle.send(0,b,64,1000);
sendData(b,64);
delay::msleep(600);
char bb[64]={0x02,0x24,0x3C,0x20,0x17,0x00,0x30,0x76,0x1F,0x40,0xB9,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0xE8,0x30,0x00,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
hidHandle.send(0,bb,64,1000);
sendData(bb,64);
delay::msleep(600);
char bbb[64]={0x02,0x24,0x3C,0x20,0x17,0x00,0x30,0x76,0x1F,0x40,0x10,0x0D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF9,0x61,0x34,0x00,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
hidHandle.send(0,bbb,64,1000);
sendData(bbb,64);
}
bool OP_DFU::SaveByteArrayToFile(QString const & sfile, const QByteArray &array)
@ -68,7 +109,7 @@ bool OP_DFU::enterDFU(int const &devNumber)
buf[8] = 1;//DFU Data2
buf[9] = 1;//DFU Data3
int result = hidHandle.send(0,buf, BUF_LEN, 500);
int result = sendData(buf, BUF_LEN);
if(result<1)
return false;
if(debug)
@ -104,7 +145,8 @@ bool OP_DFU::StartUpload(qint32 const & numberOfBytes, TransferTypes const & typ
buf[11] = crc;
if(debug)
qDebug()<<"Number of packets:"<<numberOfPackets<<" Size of last packet:"<<lastPacketCount;
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
int result = sendData(buf, BUF_LEN);
delay::msleep(1000);
if(debug)
qDebug() << result << " bytes sent";
if(result>0)
@ -164,7 +206,7 @@ bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data)
// qDebug()<<" Data0="<<(int)data[0]<<" Data0="<<(int)data[1]<<" Data0="<<(int)data[2]<<" Data0="<<(int)data[3]<<" buf6="<<(int)buf[6]<<" buf7="<<(int)buf[7]<<" buf8="<<(int)buf[8]<<" buf9="<<(int)buf[9];
//delay::msleep(send_delay);
if(int ret=StatusRequest()!=OP_DFU::uploading) return false;
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
int result = sendData(buf, BUF_LEN);
// qDebug()<<"sent:"<<result;
if(result<1)
{
@ -229,8 +271,8 @@ void OP_DFU::test()
++buf[1];
++buf[2];
++buf[63];
hidHandle.send(0,buf,BUF_LEN,5000);
result = hidHandle.receive(0,buf,BUF_LEN,5000);
sendData(buf,BUF_LEN);
result = receiveData(buf,BUF_LEN);
qDebug()<<"Result="<<result;
qDebug()<<(int)buf[0]<<":"<<(int)buf[1]<<":"<<(int)buf[2]<<":"<<(int)buf[63];
@ -263,7 +305,7 @@ QByteArray OP_DFU::StartDownload(qint32 const & numberOfBytes, TransferTypes con
buf[8] = 1;//DFU Data2
buf[9] = 1;//DFU Data3
int result = hidHandle.send(0,buf, BUF_LEN, 500);
int result = sendData(buf, BUF_LEN);
if(debug)
qDebug() << "StartDownload:"<<numberOfPackets<<"packets"<<" Last Packet Size="<<lastPacketCount<<" "<<result << " bytes sent";
float percentage;
@ -277,7 +319,7 @@ QByteArray OP_DFU::StartDownload(qint32 const & numberOfBytes, TransferTypes con
// qDebug()<<"Status="<<StatusToString(StatusRequest());
result = hidHandle.receive(0,buf,BUF_LEN,5000);
result = receiveData(buf,BUF_LEN);
if(debug)
qDebug() << result << " bytes received"<<" Count="<<x<<"-"<<(int)buf[2]<<";"<<(int)buf[3]<<";"<<(int)buf[4]<<";"<<(int)buf[5]<<" Data="<<(int)buf[6]<<";"<<(int)buf[7]<<";"<<(int)buf[8]<<";"<<(int)buf[9];
int size;
@ -304,7 +346,7 @@ void OP_DFU::ResetDevice(void)
buf[7] = 0;
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 500);
int result = sendData(buf, BUF_LEN);
}
void OP_DFU::AbortOperation(void)
{
@ -319,7 +361,7 @@ void OP_DFU::AbortOperation(void)
buf[7] = 0;
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 500);
int result = sendData(buf, BUF_LEN);
}
void OP_DFU::JumpToApp()
{
@ -335,7 +377,7 @@ void OP_DFU::JumpToApp()
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 500);
int result = sendData(buf, BUF_LEN);
}
OP_DFU::Status OP_DFU::StatusRequest()
{
@ -351,10 +393,10 @@ OP_DFU::Status OP_DFU::StatusRequest()
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 10000);
int result = sendData(buf, BUF_LEN);
if(debug)
qDebug() << result << " bytes sent";
result = hidHandle.receive(0,buf,BUF_LEN,10000);
result = receiveData(buf,BUF_LEN);
if(debug)
qDebug() << result << " bytes received";
if(buf[1]==OP_DFU::Status_Rep)
@ -380,12 +422,12 @@ bool OP_DFU::findDevices()
buf[7] = 0;
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
int result = sendData(buf, BUF_LEN);
if(result<1)
{
return false;
}
result = hidHandle.receive(0,buf,BUF_LEN,5000);
result = receiveData(buf,BUF_LEN);
if(result<1)
{
return false;
@ -413,8 +455,8 @@ bool OP_DFU::findDevices()
buf[7] = 0;
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
result = hidHandle.receive(0,buf,BUF_LEN,5000);
int result = sendData(buf, BUF_LEN);
result = receiveData(buf,BUF_LEN);
devices[x].ID=buf[9];
devices[x].BL_Version=buf[7];
devices[x].SizeOfDesc=buf[8];
@ -466,7 +508,7 @@ bool OP_DFU::EndOperation()
buf[8] = 0;
buf[9] = 0;
int result = hidHandle.send(0,buf, BUF_LEN, 5000);
int result = sendData(buf, BUF_LEN);
// hidHandle.receive(0,buf,BUF_LEN,5000);
if(debug)
qDebug() << result << " bytes sent";
@ -736,3 +778,43 @@ quint32 OP_DFU::CRCFromQBArray(QByteArray array, quint32 Size)
}
return CRC32WideFast(0xFFFFFFFF,Size/4,(quint32*)t);
}
int OP_DFU::sendData(void * data,int size)
{
if(!use_serial)
{
return hidHandle.send(0,data, size, 5000);
}
else
{
if(serialhandle->sendData((uint8_t*)data+1,size-1))
{
if (debug)
qDebug()<<"packet sent"<<"data0"<<((uint8_t*)data+1)[0];
return size;
}
if(debug)
qDebug()<<"Serial send OVERRUN";
}
}
int OP_DFU::receiveData(void * data,int size)
{
if(!use_serial)
{
return hidHandle.receive(0,data, size, 10000);
}
else
{
int x;
QTime time;
time.start();
while(true)
{
if(x=serialhandle->read_Packet(data+1)!=-1||time.elapsed()>10000)
{
if(time.elapsed()>10000)
qDebug()<<"____timeout";
return x;
}
}
}
}

View File

@ -9,6 +9,11 @@
#include <QList>
#include <iostream>
#include "delay.h"
#include "../../../libs/qextserialport/src/qextserialport.h"
#include <QTime>
#include ".\SSP\qssp.h"
#include ".\SSP\port.h"
#include ".\SSP\qsspt.h"
using namespace std;
#define BUF_LEN 64
@ -25,6 +30,11 @@ using namespace std;
#define LISTDEVICES "-ls" //done
#define RESET "-r"
#define JUMP "-j"
#define USE_SERIAL "-t"
#define MAX_PACKET_DATA_LEN 255
#define MAX_PACKET_BUF_SIZE (1+1+MAX_PACKET_DATA_LEN+2)
class OP_DFU
{
@ -73,19 +83,19 @@ public:
enum Commands
{
Reserved,
Req_Capabilities,
Rep_Capabilities,
EnterDFU,
JumpFW,
Reset,
Abort_Operation,
Upload,
Op_END,
Download_Req,
Download,
Status_Request,
Status_Rep,
Reserved,//0
Req_Capabilities,//1
Rep_Capabilities,//2
EnterDFU,//3
JumpFW,//4
Reset,//5
Abort_Operation,//6
Upload,//7
Op_END,//8
Download_Req,//9
Download,//10
Status_Request,//11
Status_Rep,//12
};
struct device
@ -98,7 +108,6 @@ public:
bool Readable;
bool Writable;
};
void JumpToApp();
void ResetDevice(void);
bool enterDFU(int const &devNumber);
@ -114,7 +123,7 @@ public:
bool SaveByteArrayToFile(QString const & file,QByteArray const &array);
void CopyWords(char * source, char* destination, int count);
// QByteArray DownloadData(int devNumber,int numberOfPackets);
OP_DFU(bool debug);
OP_DFU(bool debug,bool use_serial,QString port);
void sendReset(void);
bool findDevices();
QList<device> devices;
@ -126,13 +135,22 @@ public:
void test();
int send_delay;
bool use_delay;
bool ready(){return mready;}
void AbortOperation(void);
private:
bool mready;
bool debug;
int RWFlags;
bool use_serial;
qsspt * serialhandle;
int sendData(void*,int);
int receiveData(void * data,int size);
pjrc_rawhid hidHandle;
int setStartBit(int command){return command|0x20;}
uint8_t sspTxBuf[MAX_PACKET_BUF_SIZE];
uint8_t sspRxBuf[MAX_PACKET_BUF_SIZE];
port * info;
};

View File

@ -7,7 +7,7 @@
QT += core
QT -= gui
DEFINES += QEXTSERIALPORT_LIBRARY
TARGET = OPUploadTool
CONFIG += console
CONFIG -= app_bundle
@ -16,14 +16,26 @@ TEMPLATE = app
DEFINES += RAWHID_LIBRARY
SOURCES += main.cpp \
op_dfu.cpp \
delay.cpp
delay.cpp \
./SSP/qssp.cpp \
./SSP/port.cpp \
./SSP/qsspt.cpp \
../../libs/qextserialport/src/qextserialport.cpp
HEADERS += ../../plugins/rawhid/pjrc_rawhid.h \
../../plugins/rawhid/rawhid_global.h \
op_dfu.h \
delay.h
delay.h \
../../libs/qextserialport/src/qextserialport.h \
../../libs/qextserialport/src/qextserialenumerator.h \
../../libs/qextserialport/src/qextserialport_global.h \
./SSP/qssp.h \
./SSP/port.h \
./SSP/common.h \
./SSP/qsspt.h
win32 {
SOURCES += ../../plugins/rawhid/pjrc_rawhid_win.cpp
LIBS += -lhid \
-lsetupapi
}
@ -51,3 +63,16 @@ linux-g++-64 {
SOURCES += ../../plugins/rawhid/pjrc_rawhid_unix.cpp
LIBS += -lusb
}
unix:SOURCES += ../../libs/qextserialport/src/posix_qextserialport.cpp
unix:!macx:SOURCES += ../../libs/qextserialport/src/qextserialenumerator_unix.cpp
macx {
SOURCES += ../../libs/qextserialport/src/qextserialenumerator_osx.cpp
LIBS += -framework IOKit -framework CoreFoundation
}
win32 {
SOURCES += ../../libs/qextserialport/src/win_qextserialport.cpp \
../../libs/qextserialport/src/qextserialenumerator_win.cpp
DEFINES += WINVER=0x0501 # needed for mingw to pull in appropriate dbt business...probably a better way to do this
LIBS += -lsetupapi
}