2009-05-24 09:54:11 -05:00
|
|
|
#include <qendian.h>
|
|
|
|
#include <QHostAddress>
|
|
|
|
|
|
|
|
#include "sample.h"
|
|
|
|
|
2009-11-03 08:02:09 -06:00
|
|
|
/*! \todo (MED) Complete the "sample" protocol and make it compilable so that
|
|
|
|
it can be used as an example for new protocols
|
|
|
|
*/
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
SampleConfigForm::SampleConfigForm(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
SampleProtocol::SampleProtocol(StreamBase *stream, AbstractProtocol *parent);
|
|
|
|
: AbstractProtocol(stream, parent)
|
2009-05-24 09:54:11 -05:00
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
configForm = NULL;
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SampleProtocol::~SampleProtocol()
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
delete configForm;
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
AbstractProtocol* SampleProtocol::createInstance(StreamBase *stream,
|
|
|
|
AbstractProtocol *parent)
|
2009-05-24 09:54:11 -05:00
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
return new SampleProtocol(stream, parent);
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
quint32 SampleProtocol::protocolNumber() const
|
2009-05-24 09:54:11 -05:00
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
return OstProto::Protocol::kSampleFieldNumber;
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
void SampleProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
2009-05-24 09:54:11 -05:00
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
protocol.MutableExtension(OstProto::sample)->CopyFrom(data);
|
|
|
|
protocol.mutable_protocol_id()->set_id(protocolNumber())
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
|
|
|
{
|
|
|
|
if (protocol.protocol_id()->id() == protocolNumber() &&
|
|
|
|
protocol.HasExtension(OstProto::sample))
|
|
|
|
data.MergeFrom(protocol.GetExtension(OstProto::sample));
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SampleProtocol::name() const
|
|
|
|
{
|
|
|
|
return QString("Sample");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SampleProtocol::shortName() const
|
|
|
|
{
|
|
|
|
return QString("Sample");
|
|
|
|
}
|
|
|
|
|
|
|
|
int SampleProtocol::fieldCount() const
|
|
|
|
{
|
|
|
|
return sample_fieldCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProtocol::FieldFlags SampleProtocol::fieldFlags(int index) const
|
|
|
|
{
|
|
|
|
AbstractProtocol::FieldFlags flags;
|
|
|
|
|
|
|
|
flags = AbstractProtocol::fieldFlags(index);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case sample_normal:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sample_cksum:
|
|
|
|
flags |= FieldIsCksum;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sample_meta:
|
|
|
|
flags |= FieldIsMeta;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SampleProtocol::fieldData(int index, FieldAttrib attrib,
|
|
|
|
int streamIndex) const
|
|
|
|
{
|
|
|
|
switch (index)
|
|
|
|
{
|
2009-11-03 08:02:09 -06:00
|
|
|
case sample_one:
|
2009-05-24 09:54:11 -05:00
|
|
|
{
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
2009-11-03 08:02:09 -06:00
|
|
|
return QString("ONE");
|
2009-05-24 09:54:11 -05:00
|
|
|
case FieldValue:
|
2009-11-03 08:02:09 -06:00
|
|
|
return data.one();
|
2009-05-24 09:54:11 -05:00
|
|
|
case FieldTextValue:
|
2009-11-03 08:02:09 -06:00
|
|
|
return QString("%1").arg(data.one());
|
2009-05-24 09:54:11 -05:00
|
|
|
case FieldFrameValue:
|
2009-11-03 08:02:09 -06:00
|
|
|
return QByteArray(1, (char)(data.one() & 0xF0));
|
2009-05-24 09:54:11 -05:00
|
|
|
case FieldBitSize:
|
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2009-11-03 08:02:09 -06:00
|
|
|
case sample_two:
|
2009-05-24 09:54:11 -05:00
|
|
|
{
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
2009-11-03 08:02:09 -06:00
|
|
|
return QString("TWO");
|
2009-05-24 09:54:11 -05:00
|
|
|
case FieldValue:
|
2009-11-03 08:02:09 -06:00
|
|
|
return data.two();
|
2009-05-24 09:54:11 -05:00
|
|
|
case FieldTextValue:
|
2009-11-03 08:02:09 -06:00
|
|
|
return QString("%1").arg(data.two());
|
2009-05-24 09:54:11 -05:00
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
fv.resize(0);
|
|
|
|
qToBigEndian(FIXME, (uchar*) fv.data());
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
return QByteArray(1, (char)(FIXME() & 0xF0));
|
|
|
|
case FieldBitSize:
|
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Meta fields
|
|
|
|
|
|
|
|
case sample_FIXME:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AbstractProtocol::fieldData(index, attrib, streamIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleProtocol::setFieldData(int index, const QVariant &value,
|
|
|
|
FieldAttrib attrib)
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* SampleProtocol::configWidget()
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
if (configForm == NULL)
|
2009-09-23 09:53:26 -05:00
|
|
|
{
|
|
|
|
configForm = new SampleConfigForm;
|
|
|
|
loadConfigWidget();
|
|
|
|
}
|
2009-08-02 09:52:34 -05:00
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
return configForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleProtocol::loadConfigWidget()
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
configWidget();
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SampleProtocol::storeConfigWidget()
|
|
|
|
{
|
|
|
|
bool isOk;
|
2009-08-02 09:52:34 -05:00
|
|
|
|
|
|
|
configWidget();
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|