URL
https://opencores.org/ocsvn/bw_tiff_compression/bw_tiff_compression/trunk
Subversion Repositories bw_tiff_compression
Compare Revisions
- This comparison shows the changes necessary to convert path
/bw_tiff_compression
- from Rev 15 to Rev 16
- ↔ Reverse comparison
Rev 15 → Rev 16
/trunk/client_application/src/Kernel/CDevice.cpp
0,0 → 1,120
/* |
* @file Device.cpp |
* @date May 14, 2012 |
* @author Aart Mulder |
*/ |
|
#include <QTime> |
|
#include "CDevice.h" |
|
/** @author Aart Mulder |
* @version 1 |
*/ |
|
/* {since=2011-12-09}*/ |
|
CDevice::CDevice(int nLoopTime, QString sName) : QThread(NULL), m_nLoopTime(nLoopTime), m_sName(sName) |
{ |
this->m_oDeviceState.SetDeviceState(DEVICE_STATE_WAIT_FOR_FIRST_START); |
|
this->start(); |
} |
|
CDevice::~CDevice() |
{ |
} |
|
void CDevice::Start() |
{ |
if(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_WAIT_FOR_FIRST_START) |
{ |
this->m_oDeviceState.SetDeviceState(DEVICE_STATE_RUN); |
} |
} |
|
void CDevice::Pause() |
{ |
if(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_RUN) |
{ |
this->m_oDeviceState.SetDeviceState(DEVICE_STATE_PAUSE); |
} |
} |
|
void CDevice::Resume() |
{ |
if(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_PAUSE) |
{ |
this->m_oDeviceState.SetDeviceState(DEVICE_STATE_RUN); |
} |
} |
|
void CDevice::Stop() |
{ |
this->m_oDeviceState.SetDeviceState(DEVICE_STATE_STOP); |
} |
|
int CDevice::GetLoopTime() |
{ |
return m_nLoopTime; |
} |
|
QString CDevice::GetName() |
{ |
return m_sName; |
} |
|
void CDevice::DelayMs(int delay) |
{ |
this->msleep(delay); |
} |
|
void CDevice::DeviceLoopWaitForStart() |
{ |
|
} |
|
/** |
* Needs local variable to store the last timestamp that the deviceloop has been executed. |
*/ |
void CDevice::run() |
{ |
QTime elapsedTimer; |
|
while(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_WAIT_FOR_FIRST_START) |
{ |
DeviceLoopWaitForStart(); |
this->msleep(this->m_nLoopTime); |
} |
|
this->BeforeDeviceLoop(); |
|
try |
{ |
while(this->m_oDeviceState.GetDeviceState() != DEVICE_STATE_STOP |
&& this->m_oDeviceState.GetDeviceState() != DEVICE_STATE_UNKNOWN) |
{ |
while(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_PAUSE) |
{ |
this->msleep(this->m_nLoopTime); |
} |
|
while(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_RUN) |
{ |
elapsedTimer.restart(); |
|
this->DeviceLoop(); |
|
int nSleep = (elapsedTimer.elapsed() < m_nLoopTime ? m_nLoopTime-elapsedTimer.elapsed() : 0); |
|
this->msleep(nSleep); |
} |
} |
} |
catch(...) |
{ |
//Handle ERROR |
} |
|
this->AfterDeviceLoop(); |
} |
trunk/client_application/src/Kernel/CDevice.cpp
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/Kernel/CDeviceState.cpp
===================================================================
--- trunk/client_application/src/Kernel/CDeviceState.cpp (nonexistent)
+++ trunk/client_application/src/Kernel/CDeviceState.cpp (revision 16)
@@ -0,0 +1,32 @@
+/*
+ * @file DeviceState.cpp
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#include "CDeviceState.h"
+
+CDeviceState::CDeviceState()
+{
+ this->m_eDeviceState = DEVICE_STATE_STOP;
+}
+
+CDeviceState::~CDeviceState()
+{
+}
+
+EDeviceState CDeviceState::GetDeviceState()
+{
+ EDeviceState eDeviceState;
+ this->m_oMutex.lock();
+ eDeviceState = this->m_eDeviceState;
+ this->m_oMutex.unlock();
+ return eDeviceState;
+}
+
+void CDeviceState::SetDeviceState(EDeviceState eDeviceState)
+{
+ this->m_oMutex.lock();
+ this->m_eDeviceState = eDeviceState;
+ this->m_oMutex.unlock();
+}
Index: trunk/client_application/src/Kernel/CSerialportDevice.cpp
===================================================================
--- trunk/client_application/src/Kernel/CSerialportDevice.cpp (nonexistent)
+++ trunk/client_application/src/Kernel/CSerialportDevice.cpp (revision 16)
@@ -0,0 +1,427 @@
+/*
+ * @file SerialportDevice.cpp
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#include
+#include
+#include
+#ifdef linux
+#include
+#include
+#include
+#include
+#include "CPathLib.h" //For serial port enumeration
+#else
+#include
+#include
+#endif
+
+#include
+#include
+#include
+
+#include "CSerialportDevice.h"
+#include "sysconf.h"
+
+ /** @author Aart Mulder
+ * @version 1
+ */
+
+#define RX_BUF_SIZE 5000
+
+CSerialportDevice::CSerialportDevice(int nLoopTime, QString sName) : CDevice(nLoopTime, sName)
+{
+#ifdef linux
+ fd1 = -1;
+#else
+ m_fpSerialPort = INVALID_HANDLE_VALUE;
+#endif
+
+ this->ResetRxCnt();
+}
+
+CSerialportDevice::~CSerialportDevice()
+{
+ this->Disconnect();
+}
+
+bool CSerialportDevice::Send(unsigned char cData)
+{
+ int wr;
+
+#ifdef SIM_SERIAL_LOOPBACK
+ REFER(wr);
+ OnDataReceived(cData);
+#else
+#ifdef linux
+ wr = write(fd1, &cData, 1);
+#else
+ WriteFile(m_fpSerialPort, &cData, 1, (DWORD*)&wr, 0);
+#endif
+ if(wr != 1)
+ {
+ return false;
+ }
+#endif
+ return true;
+}
+
+bool CSerialportDevice::Send(unsigned char *pData, unsigned int nSize)
+{
+ unsigned int wr;
+
+#ifdef SIM_SERIAL_LOOPBACK
+ REFER(wr);
+ for(unsigned int i = 0; i < nSize; i++)
+ {
+ OnDataReceived(pData[i]);
+ }
+#else
+#ifdef linux
+ wr = write(fd1, pData, nSize);
+#else
+ WriteFile(m_fpSerialPort, pData, nSize, (DWORD*)&wr, 0);
+#endif
+ if(wr != nSize)
+ {
+ return false;
+ }
+#endif
+
+ return true;
+}
+
+QList CSerialportDevice::GetPortNames()
+{
+ QList aPortNames;
+
+#ifdef linux
+ CPathLib::ReadDir("/dev", &aPortNames, "\\b(ttyS|ttyUSB|rfcomm|ttyACM)");
+ aPortNames = QStringList(aPortNames).replaceInStrings("tty", "/dev/tty");
+ aPortNames = QStringList(aPortNames).replaceInStrings("rfcomm", "/dev/rfcomm");
+#else
+ HKEY hKey;
+ long lResult;
+
+ if( (lResult = RegCreateKeyExA(
+ HKEY_LOCAL_MACHINE, //hKey
+ "HARDWARE\\DEVICEMAP\\SERIALCOMM",
+ 0, //Reserved
+ NULL, //lpClass
+ 0, //dwOptions
+ KEY_READ, //samDesired
+ NULL, //lpSecurityAttributes
+ &hKey, //phkResult
+ NULL)) == ERROR_SUCCESS) //lpdwDisposition
+ {
+ char rval[256];
+ DWORD rval_len = 256 ;
+
+ char rdata[256];
+ DWORD rdata_len = 256;
+
+ DWORD rtype = REG_SZ ;
+ int i = 0;
+
+ while( RegEnumValueA(hKey, i, rval, &rval_len, NULL, &rtype,
+ (unsigned char*)rdata, &rdata_len) != ERROR_NO_MORE_ITEMS)
+ {
+ qDebug() << rval << " : " << rdata;
+ aPortNames.append(QString(rdata));
+ i++;
+ rval_len=256;
+ rdata_len=256;
+ memset(rval, '\0', rval_len);
+ memset(rdata, '\0', rdata_len);
+ }
+ RegCloseKey (hKey);
+ }
+#endif
+
+ return aPortNames;
+}
+
+bool CSerialportDevice::Connect(char *sName)
+{
+ return Connect(sName, 9600);
+}
+
+bool CSerialportDevice::Connect(char *sName, quint32 nBaudrate)
+{
+#ifdef linux
+ QProcess oProcess;
+
+#if 0
+ if(QString(sName).contains("/dev/rfcomm0"))
+ {
+ oProcess.start("gksudo rfcomm release /dev/rfcomm0");
+ oProcess.waitForFinished(20000);
+ oProcess.start("gksudo rfcomm bind /dev/rfcomm0 00:07:80:4B:23:7A 1");
+ oProcess.waitForFinished(20000);
+ }
+#endif
+ fd1 = open(sName, O_RDWR | O_NOCTTY | O_NDELAY);
+
+ if (fd1 == -1 )
+ {
+ qDebug() << "Could not connect to " << sName << "\n";
+ return false;
+ }
+ else
+ {
+ fcntl(fd1, F_SETFL,0);
+ configure_port(nBaudrate);
+ qDebug() << "Successfully connected to " << sName << "\n";
+ return true;
+ }
+#else
+ DCB dcb;
+ BOOL fSuccess;
+ char aTmpCommPort[20];
+ HANDLE fpSerialPort = INVALID_HANDLE_VALUE;
+
+ strcpy(aTmpCommPort, "\\\\.\\");
+ strcat(aTmpCommPort, sName);
+ fpSerialPort = CreateFileA( aTmpCommPort,
+ GENERIC_READ | GENERIC_WRITE,
+ 0, // must be opened with exclusive-access
+ NULL, // default security attributes
+ OPEN_EXISTING, // must use OPEN_EXISTING
+ 0,//FILE_FLAG_NO_BUFFERING, // not overlapped I/O
+ NULL // hTemplate must be NULL for comm devices
+ );
+
+ if (fpSerialPort == INVALID_HANDLE_VALUE)
+ {
+ qDebug() << "Could not connect to " << sName << "\n";
+ // Handle the error.
+
+ return false;
+ }
+
+ qDebug() << "Successfully connected to " << sName << "\n";
+
+ /*
+ * Build on the current configuration, and skip setting the size
+ * of the input and output buffers with SetupComm.
+ */
+ dcb.DCBlength = sizeof(DCB);
+ fSuccess = GetCommState(fpSerialPort, &dcb);
+
+ if (!fSuccess)
+ {
+ // Handle the error.
+ return false;
+ }
+
+ switch(nBaudrate)
+ {
+ case 9600:
+ dcb.BaudRate = CBR_9600; // set the baud rate
+ break;
+ case 19200:
+ dcb.BaudRate = CBR_19200; // set the baud rate
+ break;
+ case 38400:
+ dcb.BaudRate = CBR_38400; // set the baud rate
+ break;
+ case 57600:
+ dcb.BaudRate = CBR_57600; // set the baud rate
+ break;
+ case 115200:
+ dcb.BaudRate = CBR_115200; // set the baud rate
+ break;
+#ifdef linux
+ case 230400:
+ dcb.BaudRate = CBR_230400; // set the baud rate
+ break;
+#endif
+ default:
+ dcb.BaudRate = CBR_9600; // set the baud rate
+ break;
+ }
+
+ dcb.ByteSize = 8; // data size, xmit, and rcv
+ dcb.Parity = ODDPARITY; // no parity bit
+ dcb.StopBits = ONESTOPBIT; // one stop bit
+
+ fSuccess = SetCommState(fpSerialPort, &dcb);
+
+ if (!fSuccess)
+ {
+ // Handle the error.
+ return false;
+ }
+
+ COMMTIMEOUTS CommTimeouts;
+ if(!GetCommTimeouts (fpSerialPort, &CommTimeouts))
+ {
+ // Handle the error.
+ return false;
+ }
+ // Change the COMMTIMEOUTS structure settings.
+ memset((void*)&CommTimeouts, 0, sizeof(CommTimeouts));
+ CommTimeouts.ReadIntervalTimeout = 5;
+ CommTimeouts.ReadTotalTimeoutMultiplier = 1;
+ CommTimeouts.ReadTotalTimeoutConstant = 5;
+ CommTimeouts.WriteTotalTimeoutMultiplier = 10;
+ CommTimeouts.WriteTotalTimeoutConstant = 10;
+
+ // Set the timeout parameters for all read and write operations
+ // on the port.
+ if (!SetCommTimeouts (fpSerialPort, &CommTimeouts))
+ {
+ // Could not set the timeout parameters.
+ return false;
+ }
+
+ m_fpSerialPort = fpSerialPort;
+#endif
+
+ return true;
+}
+
+bool CSerialportDevice::Disconnect()
+{
+#ifdef linux
+ ::close(fd1);
+ fd1 = -1;
+#else
+ CloseHandle(m_fpSerialPort);
+ m_fpSerialPort = INVALID_HANDLE_VALUE;
+#endif
+
+ return true;
+}
+
+void CSerialportDevice::BeforeDeviceLoop()
+{
+ quint8 aFlush[1000];
+
+ this->serialRead((char*)aFlush, 1000);
+
+ BeforeClientLoop();
+}
+
+void CSerialportDevice::DeviceLoop()
+{
+ quint8 rxBuf[RX_BUF_SIZE+1];
+ int nBytesReceived = 0;
+
+ while( (nBytesReceived = this->serialRead((char*)rxBuf, RX_BUF_SIZE+1)) > 0)
+ {
+ this->OnDataReceived(rxBuf, nBytesReceived);
+ }
+
+ ClientLoop();
+}
+
+void CSerialportDevice::AfterDeviceLoop()
+{
+ AfterClientLoop();
+
+ qDebug() << "@CSerialportDevice::AfterDeviceLoop()";
+}
+
+int CSerialportDevice::serialRead(char* aData, int nMaxSize)
+{
+#ifdef linux
+ int iIn = 0;
+#else
+ unsigned long iIn = 0;
+#endif
+
+#ifdef linux
+ if (fd1 < 1)
+ return -1;
+#else
+ if(m_fpSerialPort == INVALID_HANDLE_VALUE)
+ return -1;
+#endif
+
+
+#ifdef linux
+ iIn = read(fd1, aData, nMaxSize - 1);
+#else
+ ReadFile(m_fpSerialPort, aData, nMaxSize-1, &iIn, 0);
+#endif
+
+ if (iIn <= 0)
+ {
+ return 0; // assume that command generated no response
+ }
+ else if(iIn > 0)
+ {
+ aData[iIn < nMaxSize ? iIn : nMaxSize-1] = '\0';
+ this->m_nRxCnt += iIn;
+ }
+ return iIn;
+}
+
+#ifdef linux
+void CSerialportDevice::configure_port(quint32 nBaudrate) // configure the port
+{
+ struct termios port_settings; // structure to store the port settings in
+
+ switch(nBaudrate)
+ {
+ case 9600:
+ port_settings.c_cflag = B9600;
+ break;
+ case 19200:
+ port_settings.c_cflag = B19200;
+ break;
+ case 38400:
+ port_settings.c_cflag = B38400;
+ break;
+ case 57600:
+ port_settings.c_cflag = B57600;
+ break;
+ case 115200:
+ port_settings.c_cflag = B115200;
+ break;
+ case 230400:
+ port_settings.c_cflag = B230400;
+ break;
+ default:
+ port_settings.c_cflag = B9600;
+ break;
+ }
+// port_settings.c_cflag = B9600;
+ port_settings.c_cflag &= ~PARODD; // set no parity, stop bits, data bits
+ port_settings.c_cflag &= ~CSTOPB;
+ port_settings.c_cflag &= ~CSIZE;
+ port_settings.c_cflag |= CS8;
+
+ port_settings.c_lflag = 0;
+
+ port_settings.c_cc[VTIME] = 1;
+ port_settings.c_cc[VMIN] = 0;
+
+ port_settings.c_iflag = 0;
+ port_settings.c_oflag = 0;
+
+ tcsetattr(fd1, TCSANOW, &port_settings); // apply the settings to the port
+
+ tcflush(fd1, TCIOFLUSH);
+}
+#endif
+
+void CSerialportDevice::ResetRxCnt()
+{
+ this->m_nRxCnt = 0;
+}
+
+quint64 CSerialportDevice::GetRxCnt()
+{
+ return this->m_nRxCnt;
+}
+
+void CSerialportDevice::Flush()
+{
+#ifdef linux
+ tcflush(fd1, TCIOFLUSH);
+#endif
+}
trunk/client_application/src/Kernel/CSerialportDevice.cpp
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/Kernel/CDevice.h
===================================================================
--- trunk/client_application/src/Kernel/CDevice.h (nonexistent)
+++ trunk/client_application/src/Kernel/CDevice.h (revision 16)
@@ -0,0 +1,54 @@
+/*
+ * @file Device.h
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#ifndef CDevice_h
+#define CDevice_h
+
+#include
+#include
+
+#include "CDeviceState.h"
+
+ /** @author Aart Mulder
+ * @version 1
+ */
+class CDevice : public QThread {
+ /* {since=2011-12-09}*/
+
+ Q_OBJECT
+
+ public:
+ CDevice(int nLoopTime, QString sName);
+ virtual ~CDevice();
+ void Start();
+ void Pause();
+ void Resume();
+ void Stop();
+ int GetLoopTime();
+ QString GetName();
+
+ protected:
+ virtual void DeviceLoopWaitForStart();
+ virtual void BeforeDeviceLoop() = 0;
+ virtual void DeviceLoop() = 0;
+ virtual void AfterDeviceLoop() = 0;
+ void DelayMs(int delay);
+
+ private:
+ /**
+ * Needs local variable to store the last timestamp that the deviceloop has been executed.
+ */
+ void run();
+ /* {deprecated=false}*/
+
+ CDeviceState m_oDeviceState;
+
+ protected:
+ const QString m_sName;
+ const int m_nLoopTime;
+};
+
+#endif // CDevice_h
trunk/client_application/src/Kernel/CDevice.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/Kernel/CSerialport.cpp
===================================================================
--- trunk/client_application/src/Kernel/CSerialport.cpp (nonexistent)
+++ trunk/client_application/src/Kernel/CSerialport.cpp (revision 16)
@@ -0,0 +1,387 @@
+/*
+ * @file Serialport.cpp
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#include
+#include
+#include
+#include
+
+#include "CSerialport.h"
+
+#define NEW_FRAME_CHAR char('S')
+
+CSerialport::CSerialport() :
+ CSerialportDevice(10, "SerialportDevice")
+{
+ connect(this, SIGNAL(send(QByteArray)), this, SLOT(onSend(QByteArray)));
+ connect(this, SIGNAL(send(unsigned char)), this, SLOT(onSend(unsigned char)));
+
+ m_nBytesExpected = 0;
+ m_nBytesReceived = 0;
+
+ m_bTimeoutTimer = false;
+ m_nTimeoutTime = 10000;
+ m_sFilename = "";
+ m_sDir = "";
+ m_oRxQMutex.unlock();
+ m_aRxQForGUI.clear();
+
+ this->Start();
+}
+
+void CSerialport::BeforeClientLoop()
+{
+
+}
+
+void CSerialport::ClientLoop()
+{
+ if(m_bTimeoutTimer)
+ {
+ if(m_oRxTimeoutTimer.elapsed() >= m_nTimeoutTime)
+ {
+ /* Communication timeout occured */
+ if(this->m_oCommState == S_WaitForData)
+ {
+ handleStreamComplete("", m_sDir);
+ }
+
+ m_bTimeoutTimer = false;
+ }
+ }
+}
+
+void CSerialport::AfterClientLoop()
+{
+
+}
+
+void CSerialport::OnDataReceived(quint8 cData)
+{
+ handleRxByte(cData);
+}
+
+void CSerialport::OnDataReceived(quint8 *pData, int nSize)
+{
+ for(int i = 0; i < nSize; i++)
+ {
+ handleRxByte(pData[i]);
+ }
+}
+
+void CSerialport::Send(unsigned char cData)
+{
+ emit send(cData);
+}
+
+void CSerialport::Send(QByteArray aData)
+{
+ emit send(aData);
+}
+
+void CSerialport::onSend(unsigned char cData)
+{
+ CSerialportDevice::Send(cData);
+}
+
+void CSerialport::onSend(QByteArray aData)
+{
+ CSerialportDevice::Send((unsigned char*)aData.data(), (unsigned int)aData.size());
+}
+
+bool CSerialport::Connect(char *sName, quint32 nBaudrate)
+{
+ m_oCommState = S_StandBy;
+ m_bTimeoutTimer = false;
+
+ return CSerialportDevice::Connect(sName, nBaudrate);
+}
+
+bool CSerialport::Disconnect()
+{
+ m_oCommState = S_StandBy;
+ m_bTimeoutTimer = false;
+
+ return CSerialportDevice::Disconnect();
+}
+
+bool CSerialport::IsStateStandby()
+{
+ return (m_oCommState == S_StandBy ? true : false);
+}
+
+bool CSerialport::IsStateWaitForData()
+{
+ return (m_oCommState == S_WaitForData ? true : false);
+}
+
+int CSerialport::GetBytesExpected()
+{
+ return this->m_nBytesExpected;
+}
+
+/**
+ * @brief Reads the number of bytes received.
+ * @return int with the number of bytes received.
+ */
+int CSerialport::GetBytesReceived()
+{
+ return this->m_nBytesReceived;
+}
+
+/**
+ * @brief Writes the data that has been received since the last call
+ * of this function into the QByteArray where @e pRxData is pointing to.
+ * @param pRxData is the pointer to a QByteArray where the received data
+ * will be stored in.
+ */
+void CSerialport::GetNewBytes(QByteArray *pRxData)
+{
+ m_oRxQMutex.lock();
+ pRxData->reserve(m_aRxQForGUI.size());
+ while(!m_aRxQForGUI.empty())
+ {
+ pRxData->append(m_aRxQForGUI.dequeue());
+ }
+ m_oRxQMutex.unlock();
+}
+
+void CSerialport::CancelRequest()
+{
+ m_bTimeoutTimer = false;
+ m_oCommState = S_StandBy;
+
+ m_nBytesReceived = 0;
+ m_nBytesExpected = 0;
+
+ this->Flush();
+}
+
+void CSerialport::RequestNewFrame(QString sFilename, QString sDir)
+{
+ /* Request of a new frame is only allowed if no request is pending */
+ if(m_oCommState != S_StandBy)
+ {
+ return;
+ }
+
+ m_sFilename = sFilename;
+ if(sFilename.length() == 0)
+ {
+ m_sFilename = QString("image_") + QDateTime::currentDateTime().toString("yyyyMMdd_hh_mm_ss_zzz") + QString(".tif");
+ }
+
+ m_sDir = sDir;
+ if(sDir.length() == 0)
+ {
+ m_sDir = QDir::currentPath();
+ }
+
+ m_nBytesReceived = 0;
+ m_nBytesExpected = 0;
+
+ this->Flush();
+
+ m_oCommState = S_WaitForData;
+
+ m_oRxTimeoutTimer.restart();
+ m_bTimeoutTimer = true;
+
+ this->Send(NEW_FRAME_CHAR);
+}
+
+void CSerialport::handleRxByte(quint8 cData)
+{
+ m_oRxTimeoutTimer.restart();
+ m_bTimeoutTimer = true;
+
+ if(this->m_oCommState != S_WaitForData)
+ {
+ /*
+ * When no frame is requested: only display the received data
+ * to the user. No processing or storage in the Queue is done.
+ */
+ m_oRxQMutex.lock();
+ m_aRxQForGUI.append(cData);
+ m_oRxQMutex.unlock();
+
+ return;
+ }
+
+ switch(m_nBytesReceived)
+ {
+ case 0:
+ m_nBytesExpected = (quint32)cData;
+ m_aRxBuf.clear();
+ break;
+ case 1:
+ m_nBytesExpected = m_nBytesExpected + ((quint32)cData << 8) + 2;
+ m_aRxBuf.reserve(m_nBytesExpected);
+ break;
+ default:
+ /* Add all following bytes to the buffer */
+ m_aRxBuf.append(cData);
+ break;
+ }
+ m_oRxQMutex.lock();
+ m_aRxQForGUI.append(cData);
+ m_oRxQMutex.unlock();
+
+ m_nBytesReceived++;
+
+ if(m_nBytesReceived == m_nBytesExpected)
+ {
+ handleStreamComplete(m_sFilename, m_sDir);
+ }
+}
+
+void CSerialport::handleStreamComplete(QString sFilename, QString sDir)
+{
+ QImage *pImage;
+ QString sFilename2;
+ QFile file;
+ QDir oDir;
+
+ if(sFilename.length() == 0)
+ {
+ sFilename = QString("image_") + QDateTime::currentDateTime().toString("yyyyMMdd_hh_mm_ss_zzz") + QString(".tif");
+ }
+
+ if(sDir.length() == 0)
+ {
+ sDir = QDir::currentPath();
+ }
+
+ oDir.setCurrent(sDir);
+ sFilename2 = oDir.absoluteFilePath(sFilename);
+
+ file.setFileName(sFilename2);
+
+ /*
+ * Don't create the file if no data has been received
+ * and turn of the repeat function if enabled.
+ */
+ if(m_aRxBuf.size() < 1)
+ {
+ m_oCommState = S_StandBy;
+ m_bTimeoutTimer = false;
+
+ emit showErrorMessage("No data has been received.", true, false);
+
+ return;
+ }
+
+ if (!file.open(QIODevice::WriteOnly))
+ return;
+
+ if(m_aRxBuf.size() & 0x1)
+ m_aRxBuf.append('\0');
+
+ QDataStream dStream(&file);
+
+ m_nImageWidth = 752;
+ m_nImageHeight = 480;
+
+ /* Write tiff header */
+ dStream << (quint8)0x4D << (quint8)0x4D << (quint8)0x00 << (quint8)0x2A << (quint8)0x00 << (quint8)0x00;
+
+ /* Write header offset */
+ dStream << (quint8)(((m_aRxBuf.size() + 8) & 0xFF00) >> 8) << (quint8)(((m_aRxBuf.size() + 8) & 0x00FF) >> 0);
+
+ /* Write stream data */
+ dStream.writeRawData(m_aRxBuf.data(), m_aRxBuf.size());
+
+ /* Write number of directories */
+ dStream << (quint8)0x00 << (quint8)0x08;
+
+ /* Write image width */
+ //Byte 0 to 7
+ dStream << (quint8)0x01 << (quint8)0x00 << (quint8)0x00 << (quint8)0x03 << (quint8)0x00 << (quint8)0x00 << (quint8)0x00 << (quint8)0x01;
+ //Byte 8 to 9
+ dStream << (quint8)((m_nImageWidth & 0xFF00) >> 8) << (quint8)((m_nImageWidth & 0x00FF) >> 0);
+ //Byte 10 to 11
+ dStream << (quint8)0x00 << (quint8)0x00;
+
+ /* Write image height */
+ //Byte 0 to 7
+ dStream << (quint8)0x01 << (quint8)0x01 << (quint8)0x00 << (quint8)0x03 << (quint8)0x00 << (quint8)0x00 << (quint8)0x00 << (quint8)0x01;
+ //Byte 8 to 9
+ dStream << (quint8)((m_nImageHeight & 0xFF00) >> 8) << (quint8)((m_nImageHeight & 0x00FF) >> 0);
+ //Byte 10 to 11
+ dStream << (quint8)0x00 << (quint8)0x00;
+
+ /* Write bits per sample */
+ //Byte 0 to 5
+ dStream << (quint8)0x01 << (quint8)0x02 << (quint8)0x00 << (quint8)0x03 << (quint8)0x00 << (quint8)0x00;
+ //Byte 6 to 11
+ dStream << (quint8)0x00 << (quint8)0x01 << (quint8)0x00 << (quint8)0x01 << (quint8)0x00 << (quint8)0x00;
+
+ /* Write compression */
+ //Byte 0 to 5
+ dStream << (quint8)0x01 << (quint8)0x03 << (quint8)0x00 << (quint8)0x03 << (quint8)0x00 << (quint8)0x00;
+ //Byte 6 to 11
+ dStream << (quint8)0x00 << (quint8)0x01 << (quint8)0x00 << (quint8)0x04 << (quint8)0x00 << (quint8)0x00;
+
+ /* Write photometric interpretation */
+ //Byte 0 to 5
+ dStream << (quint8)0x01 << (quint8)0x06 << (quint8)0x00 << (quint8)0x03 << (quint8)0x00 << (quint8)0x00;
+ //Byte 6 to 11
+ dStream << (quint8)0x00 << (quint8)0x01 << (quint8)0x00 << (quint8)0x00 << (quint8)0x00 << (quint8)0x00;
+
+ /* Write strip offset */
+ //Byte 0 to 5
+ dStream << (quint8)0x01 << (quint8)0x11 << (quint8)0x00 << (quint8)0x03 << (quint8)0x00 << (quint8)0x00;
+ //Byte 6 to 11
+ dStream << (quint8)0x00 << (quint8)0x01 << (quint8)0x00 << (quint8)0x08 << (quint8)0x00 << (quint8)0x08;
+
+ /* Write rows per strip */
+ //Byte 0 to 5
+ dStream << (quint8)0x01 << (quint8)0x16 << (quint8)0x00 << (quint8)0x03 << (quint8)0x00 << (quint8)0x00;
+ //Byte 6 to 7
+ dStream << (quint8)0x00 << (quint8)0x01;
+ //Byte 8 to 9
+ dStream << (quint8)((m_nImageHeight & 0xFF00) >> 8) << (quint8)((m_nImageHeight & 0x00FF) >> 0);
+ //Byte 10 to 11
+ dStream << (quint8)0x00 << (quint8)0x00;
+
+ /* Write strip byte count */
+ //Byte 0 to 5
+ dStream << (quint8)0x01 << (quint8)0x17 << (quint8)0x00 << (quint8)0x03 << (quint8)0x00 << (quint8)0x00;
+ //Byte 6 to 7
+ dStream << (quint8)0x00 << (quint8)0x01;
+ //Byte 8 to 9
+ dStream << (quint8)((m_aRxBuf.size() & 0xFF00) >> 8) << (quint8)((m_aRxBuf.size() & 0x00FF) >> 0);
+ //Byte 10 to 11
+ dStream << (quint8)0x00 << (quint8)0x00;
+
+ /* Write EOB */
+ dStream << (quint8)0x00 << (quint8)0x00 << (quint8)0x00 << (quint8)0x00;
+
+ file.close();
+
+ qDebug() << " ";
+ qDebug() << "=========================================================";
+ qDebug() << "========== Start decoding of new frame ==================";
+ qDebug() << "=========================================================";
+ qDebug() << " ";
+
+ pImage = new QImage(sFilename2);
+ if(pImage->isNull())
+ {
+ m_oCommState = S_StandBy;
+ m_bTimeoutTimer = false;
+
+ emit showErrorMessage(QString("Failed to open the file: %1").arg(sFilename2), true, false);
+
+ return;
+ }
+ delete pImage;
+
+ emit frameCompleted(sFilename2);
+
+ m_oCommState = S_StandBy;
+ m_bTimeoutTimer = false;
+}
trunk/client_application/src/Kernel/CSerialport.cpp
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/Kernel/CDeviceState.h
===================================================================
--- trunk/client_application/src/Kernel/CDeviceState.h (nonexistent)
+++ trunk/client_application/src/Kernel/CDeviceState.h (revision 16)
@@ -0,0 +1,41 @@
+/*
+ * @file DeviceState.h
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#ifndef CDeviceState_h
+#define CDeviceState_h
+
+#include
+
+enum EDeviceState
+{
+ DEVICE_STATE_UNKNOWN,
+ DEVICE_STATE_WAIT_FOR_FIRST_START,
+ DEVICE_STATE_STOP,
+ DEVICE_STATE_RUN,
+ DEVICE_STATE_PAUSE,
+
+ NR_OF_DEVICE_STATES
+};
+
+
+class CDeviceState {
+
+ public:
+
+ CDeviceState();
+
+ virtual ~CDeviceState();
+
+ EDeviceState GetDeviceState();
+
+ void SetDeviceState(EDeviceState eDeviceState);
+
+ public:
+ EDeviceState m_eDeviceState;
+ QMutex m_oMutex;
+};
+
+#endif // CDeviceState_h
trunk/client_application/src/Kernel/CDeviceState.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/Kernel/CSerialport.h
===================================================================
--- trunk/client_application/src/Kernel/CSerialport.h (nonexistent)
+++ trunk/client_application/src/Kernel/CSerialport.h (revision 16)
@@ -0,0 +1,80 @@
+/*
+ * @file Serialport.h
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#ifndef CSERIALPORT_H
+#define CSERIALPORT_H
+
+/** @author Aart Mulder
+ * @version 1
+ */
+
+#include
+#include
+#include
+#include
+
+#include "CSerialportDevice.h"
+
+class CSerialport : public CSerialportDevice
+{
+ Q_OBJECT
+
+ enum E_CommState
+ {
+ S_Unknown,
+ S_StandBy,
+ S_WaitForData
+ };
+
+public:
+ CSerialport();
+ void Send(unsigned char cData);
+ void Send(QByteArray aData);
+ void RequestNewFrame(QString sFilename = "", QString sDir = "");
+ bool Connect(char *sName, quint32 nBaudrate);
+ bool Disconnect();
+ bool IsStateStandby();
+ bool IsStateWaitForData();
+ int GetBytesReceived();
+ int GetBytesExpected();
+ void GetNewBytes(QByteArray *pRxData);
+ void CancelRequest();
+
+protected:
+ void BeforeClientLoop();
+ void ClientLoop();
+ void AfterClientLoop();
+ void OnDataReceived(quint8 cData);
+ void OnDataReceived(quint8 *pData, int nSize);
+
+private:
+ unsigned int m_nBytesExpected, m_nBytesReceived, m_nImageWidth, m_nImageHeight;
+ QByteArray m_aRxBuf;
+ E_CommState m_oCommState;
+ bool m_bTimeoutTimer;
+ QTime m_oRxTimeoutTimer;
+ int m_nTimeoutTime;
+ QString m_sFilename;
+ QString m_sDir;
+ QQueue m_aRxQForGUI;
+ QMutex m_oRxQMutex;
+
+ void handleRxByte(quint8 cData);
+ void handleStreamComplete(QString sFilename = "", QString sDir = "");
+
+private slots:
+ void onSend(unsigned char cData);
+ void onSend(QByteArray aData);
+
+signals:
+ void send(unsigned char cData);
+ void send(QByteArray aData);
+ void showErrorMessage(QString sMessage, bool bEnableBtSingleShot, bool bCheckedBtRepeat);
+ void frameCompleted(QString sFilename);
+
+};
+
+#endif // CSERIALPORT_H
trunk/client_application/src/Kernel/CSerialport.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/Kernel/CSerialportDevice.h
===================================================================
--- trunk/client_application/src/Kernel/CSerialportDevice.h (nonexistent)
+++ trunk/client_application/src/Kernel/CSerialportDevice.h (revision 16)
@@ -0,0 +1,73 @@
+/*
+ * @file SerialportDevice.h
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#ifndef CSerialportDevice_h
+#define CSerialportDevice_h
+
+#include
+#include
+
+#ifndef linux
+#include
+#include
+#include
+#endif
+
+#include "CDevice.h"
+
+ /** @author Aart Mulder
+ * @version 1
+ */
+
+class CSerialportDevice : public CDevice {
+ /* {since=2011-12-09}*/
+ Q_OBJECT
+
+ public:
+ CSerialportDevice(int nLoopTime, QString sName);
+ virtual ~CSerialportDevice();
+ static QList GetPortNames();
+ bool Connect(char *sName);
+ bool Connect(char *sName, quint32 nBaudrate);
+ bool Disconnect();
+ void ResetRxCnt();
+ quint64 GetRxCnt();
+ void Flush();
+
+ protected:
+ void BeforeDeviceLoop();
+ void DeviceLoop();
+ void AfterDeviceLoop();
+ virtual void BeforeClientLoop() = 0;
+ virtual void ClientLoop() = 0;
+ virtual void AfterClientLoop() = 0;
+ virtual void OnDataReceived(quint8 cData) = 0;
+ virtual void OnDataReceived(quint8 *pData, int nSize) = 0;
+ bool Send(unsigned char cData);
+ bool Send(unsigned char *pData, unsigned int nSize);
+
+ quint64 m_nRxCnt;
+
+ private:
+ int serialRead(char* aData, int nMaxSize);
+#ifdef linux
+ void configure_port(quint32 nBaudrate);
+#endif
+
+#ifdef linux
+ int fd1;
+#else
+ HANDLE m_fpSerialPort;
+#endif
+
+ signals:
+ void DebugMessage(QString sMessage);
+
+ private slots:
+
+};
+
+#endif // CSerialportDevice_h
trunk/client_application/src/Kernel/CSerialportDevice.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/GUI/CCITT4Client.h
===================================================================
--- trunk/client_application/src/GUI/CCITT4Client.h (nonexistent)
+++ trunk/client_application/src/GUI/CCITT4Client.h (revision 16)
@@ -0,0 +1,68 @@
+/*
+ * @file CCITT4Client.h
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#ifndef CCITT4CLIENT_H
+#define CCITT4CLIENT_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "CSerialport.h"
+#include "PortSelectionDialog.h"
+
+namespace Ui {
+class CCCITT4Client;
+}
+
+class CCCITT4Client : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit CCCITT4Client(QWidget *parent = 0, QString sStoragePath = "");
+ ~CCCITT4Client();
+ void UpdateFileList();
+
+protected:
+ void showEvent (QShowEvent * event);
+
+private:
+ Ui::CCCITT4Client *ui;
+ CSerialport* m_pSerialport;
+ CPortSelectionDialog *m_pPortSelectionDialog;
+ int m_nCursorPos;
+ QTimer m_oScreenRefreshTimer;
+
+ QString byteToHexString(quint8 nValue);
+ void setVerticalSpitter(int nIndex, int nSizePercent);
+ void setHorizontalSpitter(int nIndex, int nSizePercent, int nSizePixels = 0);
+
+public slots:
+ void Show();
+
+private slots:
+ void OnBtConnectClicked();
+ void OnBtSingleShotClicked();
+ void OnBtRepeatClicked();
+ void OnBtPathClicked();
+ void keyPressEvent(QKeyEvent *event);
+ void keyReleaseEvent(QKeyEvent *event);
+ void OnFilesListItemClicked(QListWidgetItem* pItem);
+ void OnFilesListSelectionChanged();
+ void OnLineEditPathChanged(QString sPath);
+ void OnScreenRefreshTimer();
+ void OnShowErrorMessage(QString sMessage, bool bEnableBtSingleShot, bool bCheckedBtRepeat);
+ void OnFrameCompleted(QString sFilename);
+};
+
+#endif // CCITT4CLIENT_H
trunk/client_application/src/GUI/CCITT4Client.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/GUI/PortSelectionDialog.h
===================================================================
--- trunk/client_application/src/GUI/PortSelectionDialog.h (nonexistent)
+++ trunk/client_application/src/GUI/PortSelectionDialog.h (revision 16)
@@ -0,0 +1,31 @@
+/*
+ * @file PortSelectionDialog.h
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#ifndef PORTSELECTIONDIALOG_H
+#define PORTSELECTIONDIALOG_H
+
+#include
+
+namespace Ui {
+ class CPortSelectionDialog;
+}
+
+class CPortSelectionDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit CPortSelectionDialog(QWidget *parent = 0);
+ ~CPortSelectionDialog();
+ void UpdateList(QList sPortNames);
+ QString GetPortname();
+ quint32 GetBaudrate();
+
+private:
+ Ui::CPortSelectionDialog *ui;
+};
+
+#endif // PORTSELECTIONDIALOG_H
trunk/client_application/src/GUI/PortSelectionDialog.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/GUI/CMyGraphicsView.cpp
===================================================================
--- trunk/client_application/src/GUI/CMyGraphicsView.cpp (nonexistent)
+++ trunk/client_application/src/GUI/CMyGraphicsView.cpp (revision 16)
@@ -0,0 +1,167 @@
+/*
+ * Thanks to the autor of http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming
+ */
+
+//Our includes
+#include "CMyGraphicsView.h"
+#include "stddefs.h"
+
+//Qt includes
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/**
+* Sets up the subclassed QGraphicsView
+*/
+CMyGraphicsView::CMyGraphicsView(QWidget* parent) : QGraphicsView(parent) {
+
+ setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
+
+ //Set-up the scene
+ Scene = new QGraphicsScene(this);
+ QBrush oBrush;
+ oBrush.setColor(Qt::lightGray);
+ oBrush.setStyle(Qt::SolidPattern);
+ Scene->setBackgroundBrush(oBrush);
+ setScene(Scene);
+ setCursor(Qt::OpenHandCursor);
+// setBackgroundBrush();
+}
+
+/**
+ * Sets the current centerpoint. Also updates the scene's center point.
+ * Unlike centerOn, which has no way of getting the floating point center
+ * back, SetCenter() stores the center point. It also handles the special
+ * sidebar case. This function will claim the centerPoint to sceneRec ie.
+ * the centerPoint must be within the sceneRec.
+ */
+//Set the current centerpoint in the
+void CMyGraphicsView::SetCenter(const QPointF& centerPoint) {
+ //Get the rectangle of the visible area in scene coords
+ QRectF visibleArea = mapToScene(rect()).boundingRect();
+
+ //Get the scene area
+ QRectF sceneBounds = sceneRect();
+
+ double boundX = visibleArea.width() / 2.0;
+ double boundY = visibleArea.height() / 2.0;
+ double boundWidth = sceneBounds.width() - 2.0 * boundX;
+ double boundHeight = sceneBounds.height() - 2.0 * boundY;
+
+ //The max boundary that the centerPoint can be to
+ QRectF bounds(boundX, boundY, boundWidth, boundHeight);
+
+ if(bounds.contains(centerPoint)) {
+ //We are within the bounds
+ CurrentCenterPoint = centerPoint;
+ } else {
+ //We need to clamp or use the center of the screen
+ if(visibleArea.contains(sceneBounds)) {
+ //Use the center of scene ie. we can see the whole scene
+ CurrentCenterPoint = sceneBounds.center();
+ } else {
+
+ CurrentCenterPoint = centerPoint;
+
+ //We need to clamp the center. The centerPoint is too large
+ if(centerPoint.x() > bounds.x() + bounds.width()) {
+ CurrentCenterPoint.setX(bounds.x() + bounds.width());
+ } else if(centerPoint.x() < bounds.x()) {
+ CurrentCenterPoint.setX(bounds.x());
+ }
+
+ if(centerPoint.y() > bounds.y() + bounds.height()) {
+ CurrentCenterPoint.setY(bounds.y() + bounds.height());
+ } else if(centerPoint.y() < bounds.y()) {
+ CurrentCenterPoint.setY(bounds.y());
+ }
+
+ }
+ }
+
+ //Update the scrollbars
+ centerOn(CurrentCenterPoint);
+}
+
+/**
+ * Handles when the mouse button is pressed
+ */
+void CMyGraphicsView::mousePressEvent(QMouseEvent* event) {
+ //For panning the view
+ LastPanPoint = event->pos();
+ setCursor(Qt::ClosedHandCursor);
+}
+
+/**
+ * Handles when the mouse button is released
+ */
+void CMyGraphicsView::mouseReleaseEvent(QMouseEvent* event)
+{
+ REFER(event);
+ setCursor(Qt::OpenHandCursor);
+ LastPanPoint = QPoint();
+}
+
+/**
+*Handles the mouse move event
+*/
+void CMyGraphicsView::mouseMoveEvent(QMouseEvent* event) {
+ if(!LastPanPoint.isNull()) {
+ //Get how much we panned
+ QPointF delta = mapToScene(LastPanPoint) - mapToScene(event->pos());
+ LastPanPoint = event->pos();
+
+ //Update the center ie. do the pan
+ SetCenter(GetCenter() + delta);
+ }
+}
+
+/**
+ * Zoom the view in and out.
+ */
+void CMyGraphicsView::wheelEvent(QWheelEvent* event) {
+
+ //Get the position of the mouse before scaling, in scene coords
+ QPointF pointBeforeScale(mapToScene(event->pos()));
+
+ //Get the original screen centerpoint
+ QPointF screenCenter = GetCenter(); //CurrentCenterPoint; //(visRect.center());
+
+ //Scale the view ie. do the zoom
+ double scaleFactor = 1.15; //How fast we zoom
+ if(event->delta() > 0) {
+ //Zoom in
+ scale(scaleFactor, scaleFactor);
+ } else {
+ //Zooming out
+ scale(1.0 / scaleFactor, 1.0 / scaleFactor);
+ }
+
+ //Get the position after scaling, in scene coords
+ QPointF pointAfterScale(mapToScene(event->pos()));
+
+ //Get the offset of how the screen moved
+ QPointF offset = pointBeforeScale - pointAfterScale;
+
+ //Adjust to the new center for correct zooming
+ QPointF newCenter = screenCenter + offset;
+ SetCenter(newCenter);
+}
+
+/**
+ * Need to update the center so there is no jolt in the
+ * interaction after resizing the widget.
+ */
+void CMyGraphicsView::resizeEvent(QResizeEvent* event) {
+ //Get the rectangle of the visible area in scene coords
+ QRectF visibleArea = mapToScene(rect()).boundingRect();
+ SetCenter(visibleArea.center());
+
+ //Call the subclass resize so the scrollbars are updated correctly
+ QGraphicsView::resizeEvent(event);
+}
trunk/client_application/src/GUI/CMyGraphicsView.cpp
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/GUI/CCITT4Client.ui
===================================================================
--- trunk/client_application/src/GUI/CCITT4Client.ui (nonexistent)
+++ trunk/client_application/src/GUI/CCITT4Client.ui (revision 16)
@@ -0,0 +1,359 @@
+
+
+ CCCITT4Client
+
+
+
+ 0
+ 0
+ 764
+ 608
+
+
+
+
+ 200
+ 0
+
+
+
+ CCCITT4 Client
+
+
+
+ :/new/prefix1/logo_tiff_top_largest.png :/new/prefix1/logo_tiff_top_largest.png
+
+
+
+ -
+
+
+
+ 0
+
+ -
+
+
+ Qt::Horizontal
+
+
+ 6
+
+
+
+
+ 0
+
+ -
+
+
+ Qt::Vertical
+
+
+ 6
+
+
+
+
+ 0
+
+ -
+
+
+
+
+
+
+
+ 0
+
+ -
+
+
+
+ TlwgMono
+ 75
+ true
+
+
+
+ false
+
+
+ 20
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 0
+
+
+
+
+ 16777215
+ 16777215
+
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+
+ -
+
+
+ Qt::Vertical
+
+
+
+
+ 0
+
+ -
+
+
+
+ 0
+ 100
+
+
+
+
+ 16777215
+ 100
+
+
+
+ image: url(:/new/prefix1/logo_tiff_top_largest.png);
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 16777215
+ 30
+
+
+
+
+ 6
+
+
+ 0
+
+ -
+
+
+
+ 75
+ false
+ true
+
+
+
+ Storage folder
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+ 30
+ 16777215
+
+
+
+ ...
+
+
+
+
+
+
+ -
+
+
+
+ 16777215
+ 48
+
+
+
+
+ 6
+
+
+ 0
+
+ -
+
+
+
+ 48
+ 48
+
+
+
+ Connect
+
+
+
+
+
+
+ :/new/prefix1/Disconnect.png
+ :/new/prefix1/Connect2.png :/new/prefix1/Disconnect.png
+
+
+
+ 48
+ 48
+
+
+
+ true
+
+
+
+ -
+
+
+
+ 48
+ 48
+
+
+
+
+
+
+
+ :/new/prefix1/Basic 2/PlayPause.png :/new/prefix1/Basic 2/PlayPause.png
+
+
+
+ 40
+ 40
+
+
+
+
+ -
+
+
+
+ 0
+ 48
+
+
+
+
+ 48
+ 48
+
+
+
+
+
+
+
+ :/new/prefix1/Basic 2/Play.png
+ :/new/prefix1/Basic 2/Stop.png :/new/prefix1/Basic 2/Play.png
+
+
+
+ 40
+ 40
+
+
+
+ true
+
+
+ false
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ CMyGraphicsView
+ QGraphicsView
+ CMyGraphicsView.h
+
+
+
+
+
+
+
Index: trunk/client_application/src/GUI/PortSelectionDialog.ui
===================================================================
--- trunk/client_application/src/GUI/PortSelectionDialog.ui (nonexistent)
+++ trunk/client_application/src/GUI/PortSelectionDialog.ui (revision 16)
@@ -0,0 +1,110 @@
+
+
+ CPortSelectionDialog
+
+
+
+ 0
+ 0
+ 397
+ 39
+
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 0
+
+
+
+ Serialport selection
+
+
+
+ :/new/prefix1/logo_tiff_top_largest.png :/new/prefix1/logo_tiff_top_largest.png
+
+
+ true
+
+
+
+ 6
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+ 60
+ 16777215
+
+
+
+ Ok
+
+
+
+ -
+
+
+
+ 60
+ 16777215
+
+
+
+ Cancel
+
+
+
+
+
+
+
+
+
+
+ BtOk
+ clicked()
+ CPortSelectionDialog
+ accept()
+
+
+ 141
+ 19
+
+
+ 121
+ 19
+
+
+
+
+ BtCancel
+ clicked()
+ CPortSelectionDialog
+ reject()
+
+
+ 207
+ 19
+
+
+ 121
+ 19
+
+
+
+
+
Index: trunk/client_application/src/GUI/CCITT4Client.cpp
===================================================================
--- trunk/client_application/src/GUI/CCITT4Client.cpp (nonexistent)
+++ trunk/client_application/src/GUI/CCITT4Client.cpp (revision 16)
@@ -0,0 +1,523 @@
+/*
+ * @file CCITT4Client.cpp
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "CCITT4Client.h"
+#include "ui_CCITT4Client.h"
+#include "CPathLib.h"
+
+CCCITT4Client::CCCITT4Client(QWidget *parent, QString sStoragePath) :
+ QMainWindow(parent),
+ ui(new Ui::CCCITT4Client)
+{
+ QString sTmp = sStoragePath;
+
+ ui->setupUi(this);
+
+ m_nCursorPos = 0;
+
+ m_pSerialport = new CSerialport();
+ m_pPortSelectionDialog = new CPortSelectionDialog();
+
+ ui->BtSingleShot->setEnabled(false);
+ ui->BtRepeat->setEnabled(false);
+
+ if( (sStoragePath != "") && (QFile::exists(sStoragePath)) )
+ {
+ this->ui->lineEditPath->setText(sStoragePath);
+ }
+ else
+ {
+ this->ui->lineEditPath->setText(QDir::currentPath());
+ }
+
+ UpdateFileList();
+
+ m_oScreenRefreshTimer.start(100);
+
+ connect(ui->BtConnect, SIGNAL(clicked()), this, SLOT(OnBtConnectClicked()));
+ connect(ui->BtSingleShot, SIGNAL(clicked()), this, SLOT(OnBtSingleShotClicked()));
+ connect(ui->BtRepeat, SIGNAL(clicked()), this, SLOT(OnBtRepeatClicked()));
+ connect(ui->BtPath, SIGNAL(clicked()), this, SLOT(OnBtPathClicked()));
+ connect(ui->lineEditPath, SIGNAL(textChanged(QString)), this, SLOT(OnLineEditPathChanged(QString)));
+ connect(ui->listWidgetFiles, SIGNAL(itemSelectionChanged()), this, SLOT(OnFilesListSelectionChanged()));
+ connect(&m_oScreenRefreshTimer, SIGNAL(timeout()), this, SLOT(OnScreenRefreshTimer()));
+ connect(m_pSerialport, SIGNAL(showErrorMessage(QString, bool, bool)), this, SLOT(OnShowErrorMessage(QString, bool, bool)));
+ connect(m_pSerialport, SIGNAL(frameCompleted(QString)), this, SLOT(OnFrameCompleted(QString)));
+
+}
+
+CCCITT4Client::~CCCITT4Client()
+{
+ delete ui;
+}
+
+void CCCITT4Client::Show()
+{
+ QMainWindow::show();
+
+ this->setHorizontalSpitter(1, -1, 140);
+}
+
+void CCCITT4Client::showEvent(QShowEvent *event)
+{
+ this->setHorizontalSpitter(1, -1, 240);
+}
+
+void CCCITT4Client::OnBtConnectClicked()
+{
+ QString sPortname = "";
+ QList aPortNames;
+
+ if(m_pSerialport == NULL)
+ return;
+
+ if(ui->BtConnect->isChecked())
+ {
+ ui->BtConnect->setChecked(false);
+
+ /*
+ * Show the port selection dialog to the user if there is more than
+ * one port available. Show an error pop-up if no ports are available.
+ */
+ aPortNames = CSerialport::GetPortNames();
+ if(aPortNames.size() <= 0)
+ {
+ QMessageBox::critical(this, "Error",
+ "No serial ports available");
+ return;
+ }
+
+ m_pPortSelectionDialog->UpdateList(aPortNames);
+ if(m_pPortSelectionDialog->exec() == QDialog::Accepted)
+ {
+ sPortname = m_pPortSelectionDialog->GetPortname();
+ }
+ else
+ {
+ ui->BtConnect->setChecked(false);
+ return;
+ }
+
+#ifdef linux
+ if(m_pSerialport->Connect((char*)sPortname.toStdString().c_str(), m_pPortSelectionDialog->GetBaudrate()))
+#else
+ if(m_pSerialport->Connect((char*)sPortname.toStdString().c_str(), m_pPortSelectionDialog->GetBaudrate()))
+#endif
+ {
+ ui->BtSingleShot->setEnabled(true);
+ ui->BtRepeat->setEnabled(true);
+ ui->BtConnect->setChecked(true);
+ ui->BtRepeat->setChecked(false);
+ }
+ else
+ {
+ ui->BtConnect->setChecked(false);
+ QMessageBox::critical(this, "Error",
+ "Unable to connect to "+sPortname);
+ }
+ }
+ else
+ {
+ m_pSerialport->Disconnect();
+
+ ui->BtSingleShot->setEnabled(false);
+ ui->BtRepeat->setEnabled(false);
+ ui->BtRepeat->setChecked(false);
+ }
+}
+
+void CCCITT4Client::OnBtSingleShotClicked()
+{
+ this->ui->statusBar->clearMessage();
+ ui->textEditRxLog->insertPlainText("\n");
+ m_nCursorPos = 0;
+
+ ui->BtSingleShot->setEnabled(false);
+
+ m_pSerialport->RequestNewFrame(QString(""), ui->lineEditPath->text());
+}
+
+void CCCITT4Client::OnBtRepeatClicked()
+{
+ if(ui->BtRepeat->isChecked())
+ {
+ if(m_pSerialport->IsStateStandby())
+ {
+ ui->BtSingleShot->setEnabled(false);
+ OnBtSingleShotClicked();
+ }
+ else
+ {
+ ui->BtRepeat->setChecked(false);
+ }
+ }
+ else
+ {
+ ui->BtSingleShot->setEnabled(true);
+ }
+}
+
+void CCCITT4Client::OnBtPathClicked()
+{
+ QString sStorageDir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
+ ui->lineEditPath->text(),
+ QFileDialog::ShowDirsOnly
+ | QFileDialog::DontResolveSymlinks);
+ this->ui->lineEditPath->setText(sStorageDir);
+}
+
+void CCCITT4Client::OnLineEditPathChanged(QString sPath)
+{
+ sPath.clear(); //To surpress the unused warning when building
+
+ this->UpdateFileList();
+}
+
+void CCCITT4Client::OnFilesListItemClicked(QListWidgetItem *pItem)
+{
+ QImage *pImage;
+ QString sFilename;
+ QDir oDir;
+ QMessageBox msgBox;
+
+ oDir.setCurrent(ui->lineEditPath->text());
+
+ sFilename = oDir.absoluteFilePath(pItem->text());
+
+ this->ui->graphicsView->Scene->clear();
+
+ pImage = new QImage(sFilename);
+ if(pImage->isNull())
+ {
+ msgBox.setText(QString("Can't' open the file: %1").arg(sFilename));
+ msgBox.exec();
+
+ /* Update the file list because it seems to be corrupt */
+ UpdateFileList();
+
+ return;
+ }
+
+ this->ui->graphicsView->Scene->addItem(new QGraphicsPixmapItem(QPixmap::fromImage(*pImage)));
+ this->show();
+
+ /* Move the splitter to enhance the image viewer. */
+ setVerticalSpitter(0, 80);
+}
+
+void CCCITT4Client::OnFilesListSelectionChanged()
+{
+ QListWidgetItem *pListItem = ui->listWidgetFiles->currentItem();
+
+ OnFilesListItemClicked(pListItem);
+}
+
+void CCCITT4Client::UpdateFileList()
+{
+ QListWidgetItem *pListItem;
+ QDir *pDir;
+ QFileInfoList list;
+ int i, j;
+ bool bFileExists, bItemExists;
+
+ /* Disconnect the list event while changing the contents */
+ disconnect(ui->listWidgetFiles, SIGNAL(itemSelectionChanged()), this, SLOT(OnFilesListSelectionChanged()));
+
+ /* Obtain a list of all the tif files in the selected directory */
+ pDir = new QDir(ui->lineEditPath->text());
+ list = pDir->entryInfoList(QStringList("*.tif"), QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks, QDir::Time);
+
+ /* Remove list elements of which the corresponding file does not exist anymore */
+ for(i = 0; i < ui->listWidgetFiles->count(); i++)
+ {
+ pListItem = ui->listWidgetFiles->item(i);
+
+ /* Verify if the file exists */
+ bFileExists = false;
+ if(pListItem != NULL)
+ {
+ for(j = 0; (j < list.size()) && (bFileExists == false); j++)
+ {
+ if(list.at(j).fileName().compare(pListItem->text()) == 0)
+ {
+ bFileExists = true;
+ }
+ }
+ }
+
+ /* Delete the list element if the file doesn't exists */
+ if(bFileExists == false)
+ {
+ ui->listWidgetFiles->removeItemWidget(pListItem);
+ delete pListItem;
+ pListItem = NULL;
+ i = 0;
+ }
+ }
+
+ /* Iterate over all the files and add them to the list if they are not contained yet */
+ for(i = 0; i < list.size(); ++i)
+ {
+ bItemExists = false;
+ for(j = 0; j < ui->listWidgetFiles->count(); j++)
+ {
+ if(list.at(i).fileName().compare(ui->listWidgetFiles->item(j)->text()) == 0)
+ {
+ bItemExists = true;
+ }
+ }
+
+ if(bItemExists == false)
+ {
+ pListItem = new QListWidgetItem(QIcon(list.at(i).absoluteFilePath()), list.at(i).fileName());
+
+ ui->listWidgetFiles->addItem(pListItem);
+ }
+ }
+
+ /* Alternate the backgroundcolor of the list elements */
+ for(i = 0; i < ui->listWidgetFiles->count(); i++)
+ {
+ if(i & 0x1)
+ {
+ ui->listWidgetFiles->item(i)->setBackgroundColor(QColor::fromHsv(0,0,240));
+ }
+ else
+ {
+ ui->listWidgetFiles->item(i)->setBackgroundColor(QColor::fromHsv(0,0,255));
+ }
+ }
+
+ delete pDir;
+
+ /* reconnnect the list event */
+ connect(ui->listWidgetFiles, SIGNAL(itemSelectionChanged()), this, SLOT(OnFilesListSelectionChanged()));
+}
+
+void CCCITT4Client::setHorizontalSpitter(int nIndex, int nSizePercent, int nSizePixels)
+{
+ QList aSize;
+ int nSizeTotal, nSizeTotalOthers, i;
+
+ if(nSizePercent > 100)
+ return;
+
+ /* Obtain current sizes */
+ aSize = ui->splitter->sizes();
+
+ /* Verify that the splitter contains enough items */
+ if( (nIndex >= aSize.count()) || (nIndex < 0) )
+ return;
+
+ /* Calculate the total size */
+ nSizeTotal = this->ui->splitter->width()
+ - (this->ui->splitter->handleWidth() * (this->ui->splitter->count()-1))
+ - (this->ui->splitter->lineWidth() * (this->ui->splitter->count()-1) );
+
+ /* Set the size for the other items */
+ for(i = 0; i < aSize.count(); i++)
+ {
+ if(i != nIndex)
+ {
+ /* Special option: when nSizePercent < 0 then nSizePixels is used instead */
+ if(nSizePercent >= 0)
+ {
+ aSize[i] = ((nSizeTotal * ((100 - nSizePercent) / aSize.count()-1)) / 100);
+ }
+ else
+ {
+ aSize[i] = (nSizeTotal - nSizePixels) / (aSize.count()-1);
+ }
+ }
+ }
+
+ /* Calcualte ocupied size of the other items */
+ for(i = 0, nSizeTotalOthers = 0; i < aSize.count(); i++)
+ {
+ if(i != nIndex)
+ nSizeTotalOthers += aSize.at(i);
+ }
+
+ /* Calculate and set the size of the requested item */
+ aSize[nIndex] = nSizeTotal - nSizeTotalOthers;
+
+ this->ui->splitter->setSizes(aSize);
+}
+
+void CCCITT4Client::setVerticalSpitter(int nIndex, int nSizePercent)
+{
+ QList aSize;
+ int nSizeTotal, nSizeTotalOthers, i;
+
+ if( (nSizePercent < 0) || (nSizePercent > 100) )
+ return;
+
+ /* Obtain current sizes */
+ aSize = ui->splitterWidgetViewer->sizes();
+
+ /* Verify that the splitter contains 3 items(log, image and graph) */
+ if( (nIndex >= aSize.count()) || (nIndex < 0) )
+ return;
+
+ /* Calculate the total size */
+ nSizeTotal = this->ui->splitterWidgetViewer->height()
+ - (this->ui->splitterWidgetViewer->handleWidth() * (this->ui->splitterWidgetViewer->count()-1))
+ - (this->ui->splitterWidgetViewer->lineWidth() * (this->ui->splitterWidgetViewer->count()-1) );
+
+ /* Set the size for the other items */
+ for(i = 0; i < aSize.count(); i++)
+ {
+ if(i != nIndex)
+ aSize[i] = ((nSizeTotal * ((100 - nSizePercent) / aSize.count()-1)) / 100);
+ }
+
+ /* Calcualte ocupied size of the other items */
+ for(i = 0, nSizeTotalOthers = 0; i < aSize.count(); i++)
+ {
+ if(i != nIndex)
+ nSizeTotalOthers += aSize.at(i);
+ }
+
+ /* Calculate and set the size of the requested item */
+ aSize[nIndex] = nSizeTotal - nSizeTotalOthers;
+
+ this->ui->splitterWidgetViewer->setSizes(aSize);
+}
+
+void CCCITT4Client::keyPressEvent(QKeyEvent *event)
+{
+ if(event->key() == Qt::Key_Escape)
+ {
+
+ }
+}
+
+void CCCITT4Client::keyReleaseEvent(QKeyEvent *event)
+{
+ /*
+ * On the first escape event cancel any pending request.
+ * On the second escape event clear the log window.
+ */
+ if(event->key() == Qt::Key_Escape)
+ {
+ if(this->m_pSerialport->IsStateWaitForData() || ui->BtRepeat->isChecked())
+ {
+ this->m_pSerialport->CancelRequest();
+
+ ui->BtSingleShot->setEnabled(true);
+ ui->BtRepeat->setChecked(false);
+ }
+ else
+ {
+ this->ui->textEditRxLog->clear();
+ }
+ }
+}
+
+QString CCCITT4Client::byteToHexString(quint8 nValue)
+{
+ QString sResult;
+
+ sResult = QString("%1").arg((int)nValue, 2, 16, QChar('0'));
+
+ return sResult;
+}
+
+void CCCITT4Client::OnScreenRefreshTimer()
+{
+ QByteArray aRxData;
+ int i;
+ char cData;
+
+ aRxData.clear();
+ m_pSerialport->GetNewBytes(&aRxData);
+
+ for(i = 0; i < aRxData.size(); i++)
+ {
+ cData = aRxData.at(i);
+ /*
+ * Print the data on the receive log
+ */
+ if(m_nCursorPos == 8)
+ {
+ ui->textEditRxLog->insertPlainText("\t");
+ }
+ if(m_nCursorPos >= 16)
+ {
+ ui->textEditRxLog->insertPlainText("\n");
+ m_nCursorPos = 0;
+ }
+
+ ui->textEditRxLog->insertPlainText(byteToHexString(cData) + " ");
+
+ m_nCursorPos++;
+ }
+
+ this->ui->statusBar->showMessage(QString("Expected:%1, received:%2").arg(m_pSerialport->GetBytesExpected()).arg(m_pSerialport->GetBytesReceived()));
+}
+
+void CCCITT4Client::OnShowErrorMessage(QString sMessage, bool bEnableBtSingleShot, bool bCheckedBtRepeat)
+{
+ QMessageBox msgBox;
+
+ msgBox.setText(sMessage);
+ msgBox.exec();
+
+ ui->BtSingleShot->setEnabled(bEnableBtSingleShot);
+ ui->BtRepeat->setChecked(bCheckedBtRepeat);
+
+ /* Update the file list */
+ this->UpdateFileList();
+}
+
+void CCCITT4Client::OnFrameCompleted(QString sFilename)
+{
+ QImage *pImage;
+
+ /*
+ * Call this function to be sure that all the data is printed before
+ * starting a new request.
+ */
+ OnScreenRefreshTimer();
+
+ /* Update the file list */
+ this->UpdateFileList();
+
+ this->ui->graphicsView->Scene->clear();
+
+ pImage = new QImage(sFilename);
+ if(pImage->isNull())
+ {
+ return;
+ }
+
+ this->ui->graphicsView->Scene->addItem(new QGraphicsPixmapItem(QPixmap::fromImage(*pImage)));
+ this->show();
+
+ /* Move the splitter to enhance the image viewer. */
+ setVerticalSpitter(0, 80);
+
+ ui->BtSingleShot->setEnabled(true);
+
+ /* Request for a new frame if the repeat mode is active */
+ if(ui->BtRepeat->isChecked())
+ {
+ OnBtSingleShotClicked();
+ }
+}
trunk/client_application/src/GUI/CCITT4Client.cpp
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/GUI/CMyGraphicsView.h
===================================================================
--- trunk/client_application/src/GUI/CMyGraphicsView.h (nonexistent)
+++ trunk/client_application/src/GUI/CMyGraphicsView.h (revision 16)
@@ -0,0 +1,40 @@
+/*
+ * Thanks to the autor of http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming
+ */
+
+#ifndef CMyGraphicsView_H
+#define CMyGraphicsView_H
+
+#include
+#include
+#include
+
+class CMyGraphicsView : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ CMyGraphicsView(QWidget* parent = NULL);
+
+ QGraphicsScene* Scene;
+
+protected:
+ //Holds the current centerpoint for the view, used for panning and zooming
+ QPointF CurrentCenterPoint;
+
+ //From panning the view
+ QPoint LastPanPoint;
+
+ //Set the current centerpoint in the
+ void SetCenter(const QPointF& centerPoint);
+ QPointF GetCenter() { return CurrentCenterPoint; }
+
+ //Take over the interaction
+ virtual void mousePressEvent(QMouseEvent* event);
+ virtual void mouseReleaseEvent(QMouseEvent* event);
+ virtual void mouseMoveEvent(QMouseEvent* event);
+ virtual void wheelEvent(QWheelEvent* event);
+ virtual void resizeEvent(QResizeEvent* event);
+};
+
+#endif // CMyGraphicsView_H
trunk/client_application/src/GUI/CMyGraphicsView.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/GUI/PortSelectionDialog.cpp
===================================================================
--- trunk/client_application/src/GUI/PortSelectionDialog.cpp (nonexistent)
+++ trunk/client_application/src/GUI/PortSelectionDialog.cpp (revision 16)
@@ -0,0 +1,46 @@
+/*
+ * @file PortSelectionDialog.cpp
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#include "PortSelectionDialog.h"
+#include "ui_PortSelectionDialog.h"
+
+CPortSelectionDialog::CPortSelectionDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::CPortSelectionDialog)
+{
+ ui->setupUi(this);
+
+ ui->BaudrateComboBox->addItem("9600", QVariant(9600));
+ ui->BaudrateComboBox->addItem("19200", QVariant(19200));
+ ui->BaudrateComboBox->addItem("38400", QVariant(38400));
+ ui->BaudrateComboBox->addItem("57600", QVariant(57600));
+ ui->BaudrateComboBox->addItem("115200", QVariant(115200));
+ ui->BaudrateComboBox->addItem("230400", QVariant(230400));
+ ui->BaudrateComboBox->setCurrentIndex(0);
+}
+
+CPortSelectionDialog::~CPortSelectionDialog()
+{
+ delete ui;
+}
+
+void CPortSelectionDialog::UpdateList(QList sPortNames)
+{
+ ui->PortsComboBox->clear();
+ ui->PortsComboBox->addItems(QStringList(sPortNames));
+ if(ui->PortsComboBox->count() > 0)
+ ui->PortsComboBox->setCurrentIndex(0);
+}
+
+QString CPortSelectionDialog::GetPortname()
+{
+ return this->ui->PortsComboBox->currentText();
+}
+
+quint32 CPortSelectionDialog::GetBaudrate()
+{
+ return (quint32)ui->BaudrateComboBox->itemData(ui->BaudrateComboBox->currentIndex()).toInt();
+}
trunk/client_application/src/GUI/PortSelectionDialog.cpp
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/main.cpp
===================================================================
--- trunk/client_application/src/main.cpp (nonexistent)
+++ trunk/client_application/src/main.cpp (revision 16)
@@ -0,0 +1,33 @@
+/*
+ * @file main.cpp
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#if QT_MAJOR_VERSION == 4
+#include
+#else
+#include
+#endif
+
+#include "CCITT4Client.h"
+
+int main(int argc, char *argv[])
+{
+ CCCITT4Client *pApp;
+
+ QApplication a(argc, argv);
+
+ if(argc > 1)
+ {
+ pApp = new CCCITT4Client(NULL, QString(argv[1]));
+ }
+ else
+ {
+ pApp = new CCCITT4Client();
+ }
+
+ pApp->show();
+
+ return a.exec();
+}
trunk/client_application/src/main.cpp
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/client_application/src/Libs/CPathLib.cpp
===================================================================
--- trunk/client_application/src/Libs/CPathLib.cpp (nonexistent)
+++ trunk/client_application/src/Libs/CPathLib.cpp (revision 16)
@@ -0,0 +1,262 @@
+/*
+ * @file PathLib.cpp
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+/* System includes */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#ifdef linux
+#include
+#else
+//#include
+#include
+#include
+#include
+#endif
+
+#ifdef QT
+#include
+#include
+#include
+#endif
+
+/* Own includes */
+#include "CPathLib.h"
+#include "stddefs.h"
+
+CPathLib::CPathLib()
+{
+
+}
+
+char* CPathLib::CompletePath(char* pcPath)
+{
+ char aCurrentDir[FILENAME_MAX], *pResult;
+#ifdef linux
+ char szTmp[32];
+#endif
+ int bytes;
+
+ pResult = (char*)malloc(sizeof(char) * FILENAME_MAX);
+
+ if( (pcPath[0] == '.') && (pcPath[1] == '/') )
+ {
+#ifdef linux
+ sprintf(szTmp, "/proc/%d/exe", getpid());
+ aCurrentDir[0] = '\0';
+ bytes = MIN(readlink(szTmp, aCurrentDir, FILENAME_MAX), FILENAME_MAX - 1);
+ if(bytes >= 0)
+ aCurrentDir[bytes] = '\0';
+#else
+ bytes = GetModuleFileNameA(NULL, aCurrentDir, FILENAME_MAX);
+ if(bytes == 0)
+ return NULL;
+#endif
+
+ strcpy(pResult, aCurrentDir);
+ strcat(pResult, pcPath+1);
+ }
+ else
+ {
+ strcpy(pResult, pcPath);
+ }
+
+ return pResult;
+}
+
+std::string CPathLib::CompletePath(std::string sPath)
+{
+ char aCurrentDir[FILENAME_MAX];
+ std::string sResult;
+#ifdef linux
+ char szTmp[32];
+#endif
+ int bytes;
+
+ if( (sPath.at(0) == '.') && (sPath.at(1) == '/') )
+ {
+#ifdef linux
+ sprintf(szTmp, "/proc/%d/exe", getpid());
+ aCurrentDir[0] = '\0';
+ bytes = MIN(readlink(szTmp, aCurrentDir, FILENAME_MAX), FILENAME_MAX - 1);
+ if(bytes >= 0)
+ aCurrentDir[bytes] = '\0';
+#else
+ bytes = GetModuleFileNameA(NULL, aCurrentDir, FILENAME_MAX);
+ if(bytes == 0)
+ return sResult;
+#endif
+ sResult.assign(aCurrentDir);
+ sResult.append(sPath.substr(1, sPath.length()-1));
+ }
+ else
+ {
+ sResult = sPath;
+ }
+
+ return sResult;
+}
+
+#ifdef QT
+QString CPathLib::CompletePath(QString sPath)
+{
+ char aCurrentDir[FILENAME_MAX];
+ QString sResult;
+#ifdef linux
+ char szTmp[32];
+#endif
+ int bytes;
+
+ if( (sPath.at(0) == '.') && (sPath.at(1) == '/') )
+ {
+#ifdef linux
+ sprintf(szTmp, "/proc/%d/exe", getpid());
+ aCurrentDir[0] = '\0';
+ bytes = MIN(readlink(szTmp, aCurrentDir, FILENAME_MAX), FILENAME_MAX - 1);
+ if(bytes >= 0)
+ aCurrentDir[bytes] = '\0';
+#else
+ bytes = GetModuleFileNameA(NULL, aCurrentDir, FILENAME_MAX);
+ if(bytes == 0)
+ return sResult;
+#endif
+ sResult.fromAscii(aCurrentDir);
+ sResult.append(sPath.right(sPath.length()-1));
+ }
+ else
+ {
+ sResult = sPath;
+ }
+
+ return sResult;
+}
+#endif
+
+#ifdef QT
+void CPathLib::DeleteFiles(QList *pFiles, QList *pResults)
+#else
+void CPathLib::DeleteFiles(std::list *pFiles, std::list *pResults)
+#endif
+{
+#ifdef QT
+ QList::iterator itFiles;
+ QString sFilename;
+#else
+ std::list::iterator itFiles;
+ std::string sFilename;
+#endif
+
+ if(pFiles == NULL)
+ return;
+
+ if(pResults == NULL)
+ return;
+
+ pResults->clear();
+
+ for(itFiles = pFiles->begin(); itFiles != pFiles->end(); itFiles++)
+ {
+ sFilename = CompletePath(*itFiles);
+
+#ifdef QT
+ if(remove(sFilename.toStdString().c_str()) != 0)
+#else
+ if(remove(sFilename.c_str()) != 0)
+#endif
+ {
+ pResults->push_back(false);
+ }
+ else
+ {
+ pResults->push_back(true);
+ }
+ }
+}
+
+#ifdef QT
+QList CPathLib::ReadDir(QString sDir)
+{
+ QList aFiles;
+
+ ReadDir(sDir, &aFiles);
+
+ return aFiles;
+}
+#endif
+
+#ifdef QT
+bool CPathLib::ReadDir(QString sDir, QList *paFiles, QString sFilter)
+{
+ return ReadDir(sDir, paFiles, NULL, &sFilter);
+}
+#endif
+
+#ifdef QT
+bool CPathLib::ReadDir(QString sDir, QList *paFiles, QList *paFileSizes, QString *sFilter)
+{
+ QString filepath;
+ DIR *dp;
+ struct dirent *dirp;
+ struct stat filestat;
+
+ if(paFiles == NULL)
+ return false;
+
+ paFiles->clear();
+
+ if(paFileSizes != NULL)
+ paFileSizes->clear();
+
+ sDir = CPathLib::CompletePath(sDir);
+
+ dp = opendir(sDir.toStdString().c_str());
+ if(dp == NULL)
+ return false;
+
+ while( (dirp = readdir(dp)) )
+ {
+ filepath = sDir + QString("/") + QString("%1").arg(dirp->d_name);
+
+ if(stat(filepath.toStdString().c_str(), &filestat)) continue;
+ if( S_ISDIR(filestat.st_mode)) continue;
+
+ /*
+ * Do the filter operation.
+ */
+ if(sFilter != NULL)
+ {
+ if(sFilter->length() > 0)
+ {
+ QString sFileName(dirp->d_name);
+ QRegExp oRegExp(sFilter->toStdString().c_str());
+ if( oRegExp.indexIn(sFileName) == 0)
+ {
+ paFiles->push_back(QString(dirp->d_name));
+ }
+ }
+ else
+ {
+ paFiles->push_back(QString(dirp->d_name));
+ }
+ }
+ else
+ {
+ paFiles->push_back(QString(dirp->d_name));
+ }
+
+ if(paFileSizes != NULL)
+ paFileSizes->push_back(filestat.st_size);
+ }
+
+ return true;
+}
+#endif
Index: trunk/client_application/src/Libs/CPathLib.h
===================================================================
--- trunk/client_application/src/Libs/CPathLib.h (nonexistent)
+++ trunk/client_application/src/Libs/CPathLib.h (revision 16)
@@ -0,0 +1,47 @@
+/*
+ * @file PathLib.h
+ * @date May 14, 2012
+ * @author Aart Mulder
+ */
+
+#ifndef CPATHLIB_H
+#define CPATHLIB_H
+
+/* System includes */
+#ifdef QT
+#include
+#include
+#include
+#else
+#include
-
+#include
trunk/client_application/src/Libs/CPathLib.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property