69 lines
1.8 KiB
C++
69 lines
1.8 KiB
C++
#include "CANSignal.h"
|
|
#include "defines.h"
|
|
|
|
|
|
CCANSignal::CCANSignal():
|
|
mRawValue(0),
|
|
mPhysicalValue(0.0)
|
|
{
|
|
mEncoding = CAN_SIGNAL_ENCODING_INVALID;
|
|
|
|
}
|
|
|
|
int CCANSignal::ComputeNewSignalValue(quint64 NewValue, quint16 MessageSize)
|
|
{
|
|
if(mEncoding == CAN_SIGNAL_ENCODING_INTEL)
|
|
{
|
|
//TODO: trouver un device qui crache du intel??
|
|
mRawValue = NewValue;
|
|
}
|
|
else if(mEncoding == CAN_SIGNAL_ENCODING_MOTOROLA)
|
|
{
|
|
//mRawValue = MotorolaValue;
|
|
mRawValue = NewValue;
|
|
int StartIndex = mStartBit - (mStartBit % 8) + 7 - (mStartBit % 8);
|
|
int shift = ((MessageSize * 8) - StartIndex -1);
|
|
mRawValue >>= shift;
|
|
quint64 mask = 1;
|
|
mask <<= mSignalSize;
|
|
mask -= 1;
|
|
mRawValue &= mask;
|
|
}
|
|
else
|
|
{
|
|
//TODO: À faire!!!
|
|
return RET_GENERAL_ERROR;
|
|
}
|
|
|
|
|
|
mPhysicalValue = ((signed) mRawValue * mValueFactor) + mValueOffset;
|
|
// mPhysicalValueUINT = ((quint64)((quint64) mRawValue * mValueFactor)) + (quint64)mValueOffset;
|
|
// mPhysicalValue = (qint64)((qint64) mRawValue * mValueFactor) + (qint64)mValueOffset;
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
CCANSignal& CCANSignal::operator=(const CCANSignal &source)
|
|
{
|
|
if(&source == this)
|
|
{
|
|
return *this;
|
|
}
|
|
qDebug("CANSignal Equal operator");
|
|
this->mSignalName = source.mSignalName;
|
|
this->mSignalComment = source.mSignalComment;
|
|
this->mEncoding = source.mEncoding;
|
|
this->mMultiplexing = source. mMultiplexing;
|
|
this->mStartBit = source. mStartBit;
|
|
this->mSignalSize = source. mSignalSize;
|
|
this->mValueType = source. mValueType;
|
|
this->mValueFactor = source.mValueFactor;
|
|
this->mValueOffset = source. mValueOffset;
|
|
this->mMinValue = source.mMinValue;
|
|
this->mMaxValue = source.mMaxValue;
|
|
this->mSignalUnit = source.mSignalUnit;
|
|
|
|
return *this;
|
|
}
|