Ajout interface ISpindel
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
#include "Ispindel.h"
|
||||
#include <QDataStream>
|
||||
#include "IspindelInterface.h"
|
||||
|
||||
CIspindel::CIspindel(CIspindelGUI *IspindelGui)
|
||||
{
|
||||
mIspindelGui = IspindelGui;
|
||||
IspindelGui->mProgramHandle = this;
|
||||
mNetworkInterface = new CIspindelInterface(this);
|
||||
|
||||
}
|
||||
|
||||
CIspindel::~CIspindel()
|
||||
{
|
||||
delete mNetworkInterface;
|
||||
}
|
||||
|
||||
void CIspindel::Start()
|
||||
{
|
||||
mNetworkInterface->ConnectToMasterCtrl();
|
||||
}
|
||||
|
||||
void CIspindel::IspindelFullBufferReceived(QByteArray *Data)
|
||||
{
|
||||
int NbItems;
|
||||
QDataStream Strm(Data,QIODevice::ReadOnly | QIODevice::Unbuffered);
|
||||
|
||||
Strm >> NbItems;
|
||||
|
||||
if(NbItems == 0)
|
||||
{
|
||||
qDebug("Received empty Ispindel buffer...");
|
||||
return;
|
||||
}
|
||||
|
||||
ClearIspindleDataList();
|
||||
|
||||
for(int i = 0; i < NbItems; i++)
|
||||
{
|
||||
CIspindelData *NewFrame = new CIspindelData;
|
||||
Strm >> *NewFrame;
|
||||
|
||||
mIspindelDataList.append(NewFrame);
|
||||
}
|
||||
|
||||
SetLasFrameTextInGUI(*mIspindelDataList.last());
|
||||
mIspindelGui->UpdateIspindelPlot(&mIspindelDataList);
|
||||
|
||||
}
|
||||
|
||||
void CIspindel::IspindelLastFrameReceived(QByteArray Data)
|
||||
{
|
||||
int DataSize;
|
||||
QDataStream Strm(&Data,QIODevice::ReadOnly | QIODevice::Unbuffered);
|
||||
|
||||
if(Data.size() == 0)
|
||||
return;
|
||||
|
||||
CIspindelData *NewData = new CIspindelData();
|
||||
Strm >> *NewData;
|
||||
|
||||
mIspindelDataList.append(NewData);
|
||||
SetLasFrameTextInGUI(*NewData);
|
||||
mIspindelGui->NewIspindelFrameReceived(NewData);
|
||||
|
||||
// qDebug("Latest Ispindel data received");
|
||||
|
||||
}
|
||||
|
||||
void CIspindel::ClearIspindleDataList()
|
||||
{
|
||||
for(int i = 0; i < mIspindelDataList.size(); i++)
|
||||
{
|
||||
delete mIspindelDataList[i];
|
||||
}
|
||||
|
||||
mIspindelDataList.clear();
|
||||
}
|
||||
|
||||
void CIspindel::ConnectedToMaster(bool connected)
|
||||
{
|
||||
if(connected)
|
||||
{
|
||||
mNetworkInterface->SendMasterCtrlCommand(ISPINDEL_GET_FULL_DATA_BUFFER_REQUEST,QByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
void CIspindel::SetLasFrameTextInGUI(CIspindelData Frame)
|
||||
{
|
||||
QString FrameText;
|
||||
|
||||
FrameText = QString("\nLast Frame:\n------------------------------\nAngle: %1\nBattery Voltage: %2\nGravity: %3\nSample Interval: %4\nIspindel ID: %5\nIspindel Name: %6\nRSSI: %7\nTemperature: %8%9\nSample date time: %10\n------------------------------")\
|
||||
.arg(Frame.mAngle)\
|
||||
.arg(Frame.mBattery)\
|
||||
.arg(Frame.mGravity)\
|
||||
.arg(Frame.mInterval)\
|
||||
.arg(Frame.mIspindelID)\
|
||||
.arg(Frame.mIspindelName)\
|
||||
.arg(Frame.mRSSI)\
|
||||
.arg(Frame.mTemperature).arg(Frame.mTemperatureUnits)\
|
||||
.arg(Frame.mSampleDateTime.toString("yyyy-MM-dd - hh:mm:ss"));
|
||||
// FrameText = QString("\nLast Frame\n\
|
||||
// Angle: %1\n\
|
||||
// Battery Voltage: %2\n\
|
||||
// Gravity: %3\n\
|
||||
// Sample Interval: %4\n\
|
||||
// Ispindel ID: %5\n\
|
||||
// Ispindel Name: %6\n\
|
||||
// RSSI: %7\n\
|
||||
// Temperature: %8%9\n\
|
||||
// Sample date time: %10")\
|
||||
// .arg(Frame.mAngle)\
|
||||
// .arg(Frame.mBattery)\
|
||||
// .arg(Frame.mGravity)\
|
||||
// .arg(Frame.mInterval)\
|
||||
// .arg(Frame.mIspindelID)\
|
||||
// .arg(Frame.mIspindelName)\
|
||||
// .arg(Frame.mRSSI)\
|
||||
// .arg(Frame.mTemperature).arg(Frame.mTemperatureUnits)\
|
||||
// .arg(Frame.mSampleDateTime.toString("yyyy-MM-dd - hh:mm:ss"));
|
||||
|
||||
mIspindelGui->SetLastIspindelFrameData(FrameText);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef ISPINDEL_H
|
||||
#define ISPINDEL_H
|
||||
|
||||
#include <QObject>
|
||||
#include "IspindelGUI.h"
|
||||
#include "IspindelData.h"
|
||||
#include <QList>
|
||||
#include "QCustomPlot/qcustomplot.h"
|
||||
|
||||
class CIspindelInterface;
|
||||
|
||||
class CIspindel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CIspindel(CIspindelGUI *IspindelGui);
|
||||
~CIspindel();
|
||||
|
||||
CIspindelGUI *mIspindelGui;
|
||||
|
||||
|
||||
void Start();
|
||||
void IspindelFullBufferReceived(QByteArray *Data);
|
||||
void IspindelLastFrameReceived(QByteArray Data);
|
||||
void ClearIspindleDataList();
|
||||
void ConnectedToMaster(bool connected);
|
||||
void SetLasFrameTextInGUI(CIspindelData Frame);
|
||||
|
||||
QList<CIspindelData*> mIspindelDataList;
|
||||
CIspindelInterface *mNetworkInterface;
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // ISPINDEL_H
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "IspindelData.h"
|
||||
|
||||
|
||||
CIspindelData::CIspindelData()
|
||||
{
|
||||
mIspindelID = mRSSI = mInterval = 0;
|
||||
mIspindelName = mTemperatureUnits = "";
|
||||
mAngle = mBattery = mGravity = mTemperature = 0.0;
|
||||
mSampleDateTime = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CIspindelData &source)
|
||||
{
|
||||
out << source.mAngle
|
||||
<< source.mBattery
|
||||
<< source.mGravity
|
||||
<< source.mInterval
|
||||
<< source.mIspindelID
|
||||
<< source.mIspindelName
|
||||
<< source.mRSSI
|
||||
<< source.mTemperature
|
||||
<< source.mTemperatureUnits
|
||||
<< source.mSampleDateTime;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, CIspindelData &dest)
|
||||
{
|
||||
in >> dest.mAngle
|
||||
>> dest.mBattery
|
||||
>> dest.mGravity
|
||||
>> dest.mInterval
|
||||
>> dest.mIspindelID
|
||||
>> dest.mIspindelName
|
||||
>> dest.mRSSI
|
||||
>> dest.mTemperature
|
||||
>> dest.mTemperatureUnits
|
||||
>> dest.mSampleDateTime;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
QByteArray CIspindelData::ToByteArray()
|
||||
{
|
||||
QByteArray Array;
|
||||
QDataStream Strm(&Array,QIODevice::WriteOnly | QIODevice::Unbuffered);
|
||||
|
||||
Strm << *this;
|
||||
|
||||
return Array;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CISPINDELDATA_H
|
||||
#define CISPINDELDATA_H
|
||||
|
||||
#include <QString>
|
||||
#include <QDataStream>
|
||||
#include <QDateTime>
|
||||
|
||||
class CIspindelData
|
||||
{
|
||||
public:
|
||||
CIspindelData();
|
||||
|
||||
int mIspindelID, mRSSI, mInterval;
|
||||
QString mIspindelName, mTemperatureUnits;
|
||||
double mAngle, mBattery, mGravity, mTemperature;
|
||||
QDateTime mSampleDateTime;
|
||||
|
||||
QByteArray ToByteArray();
|
||||
|
||||
};
|
||||
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CIspindelData &source);
|
||||
QDataStream &operator>>(QDataStream &in, CIspindelData &dest);
|
||||
#endif // CISPINDELDATA_H
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "IspindelGUI.h"
|
||||
#include "ui_IspindelGUI.h"
|
||||
#include "Ispindel.h"
|
||||
#include "IspindelData.h"
|
||||
#include "GlobalDefine.h"
|
||||
|
||||
CIspindelGUI::CIspindelGUI(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::CIspindelGUI)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
mIspindelPlot = new QCustomPlot(ui->mIspindelPlot);
|
||||
mIspindelPlot->resize(ui->mIspindelPlot->size());
|
||||
|
||||
// create graph and assign data to it:
|
||||
mIspindelPlot->addGraph();
|
||||
mIspindelPlot->addGraph(mIspindelPlot->xAxis,mIspindelPlot->yAxis2);
|
||||
|
||||
|
||||
// give the axes some labels:
|
||||
mIspindelPlot->xAxis->setLabel("Time");
|
||||
mIspindelPlot->yAxis->setLabel("Gravity");
|
||||
mIspindelPlot->yAxis2->setLabel("Temprature (C)");
|
||||
mIspindelPlot->yAxis2->setVisible(true);
|
||||
|
||||
double now = QDateTime::currentDateTime().toSecsSinceEpoch();
|
||||
QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
|
||||
dateTicker->setDateTimeFormat("hh:mm:ss\ndd MMM");
|
||||
mIspindelPlot->xAxis->setTicker(dateTicker);
|
||||
mIspindelPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
|
||||
QList<QCPAxis*> xAxis, yAxis;
|
||||
xAxis.append(mIspindelPlot->xAxis);
|
||||
yAxis.append(mIspindelPlot->yAxis);
|
||||
yAxis.append(mIspindelPlot->yAxis2);
|
||||
mIspindelPlot->axisRect()->setRangeDragAxes(xAxis,yAxis);
|
||||
mIspindelPlot->axisRect()->setRangeZoomAxes(xAxis,yAxis);
|
||||
// mIspindelPlot->yAxis2->axisRect()->setRangeZoomAxes(0,mIspindelPlot->yAxis2);
|
||||
|
||||
|
||||
QDateTime Now = QDateTime::currentDateTime().toLocalTime();
|
||||
|
||||
QDateTime midnight = Now;
|
||||
midnight.setTime(QTime(0,0,0));
|
||||
QDateTime eod = Now;
|
||||
eod.setTime(QTime(23,59,0));
|
||||
|
||||
//mIspindelPlot->xAxis->setRange(0/*QCPAxisTickerDateTime::dateTimeToKey(midnight)*/,QCPAxisTickerDateTime::dateTimeToKey(eod));
|
||||
// mIspindelPlot->xAxis->setRange(now, now+(2*3600));
|
||||
mIspindelPlot->xAxis->setRange(midnight.toSecsSinceEpoch(), eod.toSecsSinceEpoch());
|
||||
|
||||
mIspindelPlot->yAxis->setRange(1.000,1.01);
|
||||
mIspindelPlot->yAxis2->setRange(15,25);
|
||||
|
||||
// mIspindelPlot->graph(0)->addData(now,1.005);
|
||||
// mIspindelPlot->graph(1)->addData(now,20);
|
||||
|
||||
mIspindelPlot->replot();
|
||||
}
|
||||
|
||||
CIspindelGUI::~CIspindelGUI()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CIspindelGUI::SetLastIspindelFrameData(QString Data)
|
||||
{
|
||||
ui->mLastFrameDataLbl->setText(Data);
|
||||
}
|
||||
|
||||
int CIspindelGUI::UpdateIspindelPlot(QList<CIspindelData *> *Data)
|
||||
{
|
||||
if(Data->size() == 0)
|
||||
return RET_ERROR;
|
||||
|
||||
QVector<double> x,y,ty;
|
||||
for(int i = 0; i < Data->size(); i++)
|
||||
{
|
||||
x.append(Data->at(i)->mSampleDateTime.toSecsSinceEpoch());
|
||||
y.append(Data->at(i)->mGravity);
|
||||
ty.append(Data->at(i)->mTemperature);
|
||||
}
|
||||
|
||||
if(x.size() == 0 || y.size() == 0)
|
||||
return RET_ERROR;
|
||||
|
||||
mIspindelPlot->graph(0)->data().clear();
|
||||
mIspindelPlot->graph(0)->setData(x,y);
|
||||
mIspindelPlot->xAxis->setRange(x.first(),x.last());
|
||||
mIspindelPlot->yAxis->setRange(y.first(),y.last());
|
||||
|
||||
|
||||
mIspindelPlot->graph(1)->setPen(QColor(Qt::red));
|
||||
mIspindelPlot->graph(1)->setName("Température");
|
||||
mIspindelPlot->graph(1)->setData(x,ty);
|
||||
mIspindelPlot->yAxis2->setRange(10,30);
|
||||
|
||||
mIspindelPlot->replot();
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CIspindelGUI::NewIspindelFrameReceived(CIspindelData *Data)
|
||||
{
|
||||
mIspindelPlot->graph(0)->addData(Data->mSampleDateTime.toSecsSinceEpoch(),Data->mGravity);
|
||||
mIspindelPlot->graph(1)->addData(Data->mSampleDateTime.toSecsSinceEpoch(),Data->mTemperature);
|
||||
|
||||
mIspindelPlot->replot();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef ISPINDELGUI_H
|
||||
#define ISPINDELGUI_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "QCustomPlot/qcustomplot.h"
|
||||
#include <QList>
|
||||
|
||||
namespace Ui {
|
||||
class CIspindelGUI;
|
||||
}
|
||||
|
||||
class CIspindel;
|
||||
class CIspindelData;
|
||||
|
||||
class CIspindelGUI : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CIspindelGUI(QWidget *parent = 0);
|
||||
~CIspindelGUI();
|
||||
CIspindel *mProgramHandle;
|
||||
|
||||
void SetLastIspindelFrameData(QString Data);
|
||||
int UpdateIspindelPlot(QList<CIspindelData*> *Data);
|
||||
int NewIspindelFrameReceived(CIspindelData *Data);
|
||||
|
||||
QCustomPlot *mIspindelPlot;
|
||||
|
||||
private:
|
||||
Ui::CIspindelGUI *ui;
|
||||
};
|
||||
|
||||
#endif // ISPINDELGUI_H
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CIspindelGUI</class>
|
||||
<widget class="QDialog" name="CIspindelGUI">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1123</width>
|
||||
<height>629</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>510</x>
|
||||
<y>20</y>
|
||||
<width>91</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>ISpindel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="mIspindelPlot" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>520</x>
|
||||
<y>100</y>
|
||||
<width>661</width>
|
||||
<height>461</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="mLastFrameDataLbl">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>50</y>
|
||||
<width>381</width>
|
||||
<height>211</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>11</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>No data...</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>290</y>
|
||||
<width>461</width>
|
||||
<height>331</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "IspindelInterface.h"
|
||||
#include "IspindelData.h"
|
||||
#include "Ispindel.h"
|
||||
#include "ProtocolDefs.h"
|
||||
|
||||
CIspindelInterface::CIspindelInterface(CIspindel *ProgramHandle)
|
||||
{
|
||||
mMyDeviceID = ID_ISPINDEL_INTERFACE;
|
||||
mNetworkPort = 2182;
|
||||
mMasterCtrlIPAddress = "127.0.0.1";
|
||||
mNetworkCommSocket = 0;
|
||||
mDeviceAddress = 1;
|
||||
|
||||
mProgramHandle = ProgramHandle;
|
||||
}
|
||||
|
||||
int CIspindelInterface::DeviceConnectedToMaster(bool Connected)
|
||||
{
|
||||
if(Connected)
|
||||
{
|
||||
qDebug("Ispindel Interface connected to Master.");
|
||||
mProgramHandle->ConnectedToMaster(Connected);
|
||||
|
||||
}
|
||||
else
|
||||
return RET_ERROR;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CIspindelInterface::DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data)
|
||||
{
|
||||
Q_UNUSED(DataSize)
|
||||
Q_UNUSED(SenderID)
|
||||
Q_UNUSED(SenderAddress)
|
||||
|
||||
if(TargetDeviceID == mMyDeviceID && (TargetDeviceAddress == BROADCAST_VALUE || TargetDeviceAddress == mDeviceAddress))
|
||||
{
|
||||
switch(MessageID)
|
||||
{
|
||||
case ISPINDEL_GET_FULL_DATA_BUFFER_RESPONSE:
|
||||
{
|
||||
mProgramHandle->IspindelFullBufferReceived(&Data);
|
||||
break;
|
||||
}
|
||||
case ISPINDLE_LATEST_DATA_RESPONSE:
|
||||
{
|
||||
mProgramHandle->IspindelLastFrameReceived(Data);
|
||||
break;
|
||||
}
|
||||
case ISPINDEL_GET_FULL_DATA_BUFFER_REQUEST:
|
||||
case ISPINDLE_LATEST_DATA_REQUEST:
|
||||
default:
|
||||
{
|
||||
qDebug("Ispindel: Invalid Ethernet Msg received from MasterCtrl: %d",MessageID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef ISPINDELINTERFACE_H
|
||||
#define ISPINDELINTERFACE_H
|
||||
|
||||
#include "MasterCtrlInterface.h"
|
||||
|
||||
class CIspindel;
|
||||
|
||||
class CIspindelInterface : public CMasterCtrlInterface
|
||||
{
|
||||
public:
|
||||
CIspindelInterface(CIspindel *ProgramHandle);
|
||||
|
||||
int DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data);
|
||||
int DeviceConnectedToMaster(bool Connected);
|
||||
|
||||
private:
|
||||
CIspindel *mProgramHandle;
|
||||
};
|
||||
|
||||
#endif // ISPINDELINTERFACE_H
|
||||
Reference in New Issue
Block a user