Développement CAN Watchdog
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "CANMessage.h"
|
||||
#include "defines.h"
|
||||
#include <QtEndian>
|
||||
|
||||
CCANMessage::CCANMessage():
|
||||
mPendingData(false)
|
||||
@@ -97,6 +98,34 @@ int CCANMessage::UpdateValue(CCANMessage *NewDeviceMessage)
|
||||
|
||||
}
|
||||
|
||||
//This function should be used to set the raw data to send over CAN
|
||||
//It will do the byte swapping crap and fill the data array
|
||||
int CCANMessage::SetRawData(quint64 RawData, int Encoding)
|
||||
{
|
||||
if(Encoding != CCANSignal::CAN_SIGNAL_ENCODING_INTEL)
|
||||
{
|
||||
//MOTOROLA encoding not supported for now...
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
mCANRawDataIntel = qToLittleEndian(RawData);
|
||||
// mCANRawDataIntel = RawData;
|
||||
|
||||
|
||||
for(unsigned int i = 0; i < mCANMsgLength; i++)
|
||||
{
|
||||
unsigned char byte;
|
||||
byte = (unsigned char)((mCANRawDataIntel >> (i*8)) & 0xFF);
|
||||
mCANMsgData[i] = byte;
|
||||
}
|
||||
}
|
||||
|
||||
quint64 CCANMessage::GetRawData()
|
||||
{
|
||||
// return qFromBigEndian(mCANRawDataIntel);
|
||||
return mCANRawDataIntel;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CCANMessage &source)
|
||||
{
|
||||
out << source.mCANChannel
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
unsigned int mCANChannel;
|
||||
unsigned int mCANMsgType; // Type of the message, using the PCAN interface driver encoding defined in PCANbasic.h
|
||||
QByteArray mCANMsgData; // Raw data structure of the message, max size = 8 bytes
|
||||
quint64 mCANRawDataMotorola, mCANRawDataIntel;
|
||||
|
||||
bool mPendingData;
|
||||
|
||||
|
||||
@@ -40,6 +40,11 @@ public:
|
||||
int SetDataFromDriver(quint32 Channel,TPCANMsg CANMsg,TPCANTimestamp CANTimeStamp);
|
||||
int AddSignal(CCANSignal* NewSignal);
|
||||
int UpdateValue(CCANMessage* NewDeviceMessage);
|
||||
int SetRawData(quint64 RawData,int Encoding);
|
||||
quint64 GetRawData();
|
||||
|
||||
private:
|
||||
quint64 mCANRawDataMotorola, mCANRawDataIntel;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
#include "CANWatchdog.h"
|
||||
#include "GeneralMessagesLogDispatcher.h"
|
||||
#include <QDate>
|
||||
#include <QTime>
|
||||
#include <QFloat16>
|
||||
|
||||
CCANWatchdog::CCANWatchdog()
|
||||
{
|
||||
@@ -45,14 +48,49 @@ int CCANWatchdog::Init(CPCANInterface *CANDriverIF, TPCANHandle CANDeviceHandle,
|
||||
|
||||
void CCANWatchdog::WatchdogTimeoutTimerExpired()
|
||||
{
|
||||
char data = mWDTCANMsg.mCANMsgData[7];
|
||||
data ^= (char)0x01;
|
||||
mWDTCANMsg.mCANMsgData[7] = data;
|
||||
quint64 BigData = 0;
|
||||
|
||||
// int seconds = (QTime::currentTime().minute() * 60) + QTime::currentTime().second();
|
||||
// float Hours32bits = (float)((float)seconds / 3600);
|
||||
// Hours32bits += QTime::currentTime().hour();
|
||||
|
||||
// quint16 Hours = static_cast<quint16>(Hours32bits*1000);
|
||||
// quint16 buffer;
|
||||
// memcpy(&buffer,&Hours,2);
|
||||
// BigData |= buffer;
|
||||
// BigData <<= 16;
|
||||
// quint16 DaysSinceALongTimeAgo;
|
||||
// DaysSinceALongTimeAgo = -QDate::currentDate().daysTo(QDate(1899,12,30));
|
||||
// BigData |= DaysSinceALongTimeAgo;
|
||||
// BigData |= 0x100000000;
|
||||
|
||||
BigData = GetCANDateTimeBuffer();
|
||||
|
||||
mWDTCANMsg.SetRawData(BigData,CCANSignal::CAN_SIGNAL_ENCODING_INTEL);
|
||||
mCANDriverIF->SendCANMessage(mCANDeviceHandle,mWDTCANMsg);
|
||||
qDebug("Sending 0x%X to CAN",data);
|
||||
|
||||
// qDebug("Sending 0x%X to CAN",data);
|
||||
//QString LogMsg = QString("Écriture du watchdog. CAN ID %1 Payload: 0x%2 0x%3 0x%4 0x%5 0x%6 0x%7 0x%8 0x%9").arg(mWDTCANMsg.mCANMsgID,0,16).arg(mWDTCANMsg.mCANMsgData.at(7),0,16).arg(mWDTCANMsg.mCANMsgData.at(6),0,16).arg(mWDTCANMsg.mCANMsgData.at(5),0,16).arg(mWDTCANMsg.mCANMsgData.at(4),0,16).arg(mWDTCANMsg.mCANMsgData.at(3),0,16).arg(mWDTCANMsg.mCANMsgData.at(2),0,16).arg(mWDTCANMsg.mCANMsgData.at(1),0,16).arg(mWDTCANMsg.mCANMsgData[0],0,16);
|
||||
QString LogMsg = QString("Écriture du watchdog. CAN ID 0x%1").arg(mWDTCANMsg.mCANMsgID,0,16);
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(LogMsg,"CCANWatchdog",true,3);
|
||||
// QString LogMsg = QString("Écriture du watchdog. CAN ID 0x%1").arg(mWDTCANMsg.mCANMsgID,0,16);
|
||||
// CGeneralMessagesLogDispatcher::instance()->AddLogMessage(LogMsg,"CCANWatchdog",true,3);
|
||||
}
|
||||
|
||||
quint64 CCANWatchdog::GetCANDateTimeBuffer()
|
||||
{
|
||||
quint64 OutputBuffer = 0;
|
||||
|
||||
int seconds = (QTime::currentTime().minute() * 60) + QTime::currentTime().second();
|
||||
float Hours32bits = (float)((float)seconds / 3600);
|
||||
Hours32bits += QTime::currentTime().hour();
|
||||
quint16 Hours = static_cast<quint16>(Hours32bits*1000);
|
||||
OutputBuffer |= Hours;
|
||||
OutputBuffer <<= 16;
|
||||
|
||||
quint16 DaysSinceALongTimeAgo;
|
||||
DaysSinceALongTimeAgo = -QDate::currentDate().daysTo(QDate(1899,12,30));
|
||||
OutputBuffer |= DaysSinceALongTimeAgo;
|
||||
|
||||
return OutputBuffer;
|
||||
}
|
||||
|
||||
int CCANWatchdog::StartWDT()
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
#include <QTimer>
|
||||
#include "CANMessage.h"
|
||||
|
||||
|
||||
//This class is not a watchdog per say. It manages the update of the CAN register that is sent to the
|
||||
//Parker controller. This controller uses this update as a watchdog signal, but the register contains
|
||||
//some useful data for the Parker controller as well.
|
||||
|
||||
class CCANWatchdog: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -17,6 +22,7 @@ public:
|
||||
int StartWDT();
|
||||
int StopWDT();
|
||||
bool IsInitialized(){return mWDTInitialized;}
|
||||
quint64 GetCANDateTimeBuffer();
|
||||
|
||||
CPCANInterface *mCANDriverIF;
|
||||
unsigned int mWDTPeriod;
|
||||
|
||||
Reference in New Issue
Block a user