ahbuartplugin.h
133 lines
| 4.3 KiB
| text/x-c
|
CLexer
/ ahbuartplugin / ahbuartplugin.h
r0 | /*------------------------------------------------------------------------------ | |||
Jeandet Alexis
|
r4 | -- This file is a part of the SocExplorer Software | ||
r0 | -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS | |||
-- | ||||
-- 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 | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@lpp.polytechnique.fr | ||||
----------------------------------------------------------------------------*/ | ||||
#ifndef AHBUARTPLUGIN_H | ||||
#define AHBUARTPLUGIN_H | ||||
#include <QMenuBar> | ||||
#include <QMenu> | ||||
#include <QAction> | ||||
#include <QLayout> | ||||
#include <QMutex> | ||||
#include <QProgressDialog> | ||||
#include <QStringListModel> | ||||
#include <QTime> | ||||
#include <socexplorerplugin.h> | ||||
#include "ahbuartpluginui.h" | ||||
#ifdef WinRs232 | ||||
#include "librs232/RS232.h" | ||||
#else | ||||
#include <RS232.h> | ||||
#undef debug | ||||
#endif | ||||
#define APPENDTOLOG(message) this->UI->appendToLogFile(QTime::currentTime().toString() +":" + QString::number(QTime::currentTime().msec()) + ": " + message) | ||||
#define APENDTABLETOLOG(table,size,Qstr,message) \ | ||||
Qstr.clear();\ | ||||
Qstr+=message;\ | ||||
for(int __i__tbllog__=0;(unsigned int)__i__tbllog__<size;__i__tbllog__++)\ | ||||
{\ | ||||
if(__i__tbllog__%16==0) Qstr += "\n"; \ | ||||
Qstr += "0x" + QString::number((int)(0xff & table[__i__tbllog__]),16) +"\t";\ | ||||
}\ | ||||
APPENDTOLOG(Qstr); | ||||
#define SAFEWRITE(data,count,timer,timeout,error) \ | ||||
while(1)\ | ||||
{\ | ||||
unsigned int __writen__=0; \ | ||||
(timer).restart(); \ | ||||
while(__writen__!=(count)) \ | ||||
{\ | ||||
__writen__ += rs232write(this->port,((data)+__writen__),((count)-__writen__)); \ | ||||
if((timer).elapsed()>(timeout)) \ | ||||
{\ | ||||
APPENDTOLOG(QString("Timeout error while writing"));\ | ||||
this->port = (rs232port_t)NULL; \ | ||||
this->Connected = false; \ | ||||
emit this->activateSig(false); \ | ||||
error; \ | ||||
} \ | ||||
} \ | ||||
break;\ | ||||
} | ||||
#define SAFEREAD(data,count,timer,timeout,error) \ | ||||
unsigned int __read__=0; \ | ||||
(timer).restart(); \ | ||||
while(__read__ != (count)) \ | ||||
{ \ | ||||
__read__+=rs232read(this->port,((data)+__read__),((count)-__read__)); \ | ||||
if((timer).elapsed()>(timeout)) \ | ||||
{ \ | ||||
APPENDTOLOG(QString("Timeout error while reading"));\ | ||||
this->Connected = false; \ | ||||
emit this->activateSig(false); \ | ||||
this->portMutex->unlock(); \ | ||||
error; \ | ||||
} \ | ||||
} \ | ||||
class ahbuartplugin : public socexplorerplugin | ||||
{ | ||||
Q_OBJECT | ||||
public: | ||||
ahbuartplugin(QWidget *parent = 0); | ||||
~ahbuartplugin(); | ||||
int registermenu(QMainWindow *menuHolder); | ||||
int VID(){return driver_VID;} | ||||
int PID(){return driver_PID;} | ||||
public slots: | ||||
void togglePort(QString PortName,int baudrate); | ||||
unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0); | ||||
unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0); | ||||
void closeMe(); | ||||
void close(); | ||||
bool open(QString PortName,int baudrate); | ||||
void updatePortList(); | ||||
QVariantList ReadBytes(unsigned int address,unsigned int count); | ||||
void WriteBytes(unsigned int address,QList<QVariant> dataList); | ||||
signals: | ||||
void setProgressValue(int progress); | ||||
private: | ||||
bool scanDone; | ||||
QProgressDialog* progress; | ||||
QLayout * mainLayout; | ||||
ahbUartPluginUI* UI; | ||||
QMutex* portMutex; | ||||
rs232port_t port; | ||||
QCompleter *portListcompleter; | ||||
QStringListModel *portListcompleterModel; | ||||
void connectPort(QString PortName,int baudrate); | ||||
bool checkConnection(); | ||||
}; | ||||
#endif // AHBUARTPLUGIN_H | ||||