Fix time formatting for "system clock" mode, fix a few small bugs

elsewhere, add ability to send/receive CAN-FD frames in GVRET.
This commit is contained in:
Collin Kidder
2022-05-05 20:04:44 -04:00
parent c4a9f99445
commit b37af8d948
5 changed files with 111 additions and 9 deletions
+1
View File
@@ -133,6 +133,7 @@ bool CANFrameModel::getInterpretMode()
void CANFrameModel::setTimeFormat(QString format)
{
Utility::timeFormat = format;
timeFormat = format;
beginResetModel(); //reset model to show new time format
endResetModel();
}
+4 -1
View File
@@ -339,7 +339,10 @@ void CANConnection::checkTargettedFrame(CANFrame &frame)
//qDebug() << "Got frame with ID " << frame.ID << " on bus " << frame.bus;
if (mBusData.count() == 0) return;
if (mBusData[frame.bus].mTargettedFrames.length() == 0) return;
int bus = frame.bus;
if (bus > (mBusData.length() - 1)) bus = mBusData.length() - 1;
if (mBusData[bus].mTargettedFrames.length() == 0) return;
foreach (const CANFltObserver filt, mBusData[frame.bus].mTargettedFrames)
{
//qDebug() << "Checking filter with id " << filt.id << " mask " << filt.mask;
+4 -4
View File
@@ -78,7 +78,6 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
//Need to make sure it tries to share the address in case there are
//multiple instances of SavvyCAN running.
rxBroadcastGVRET->bind(QHostAddress::AnyIPv4, 17222, QAbstractSocket::ShareAddress);
connect(rxBroadcastGVRET, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
//Doing the same for socketcand/kayak hosts:
@@ -415,8 +414,9 @@ void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QMode
int selIdx = current.row();
disconnect(connModel->getAtIdx(previous.row()), SIGNAL(debugOutput(QString)), 0, 0);
disconnect(this, SIGNAL(sendDebugData(QByteArray)), connModel->getAtIdx(previous.row()), SLOT(debugInput(QByteArray)));
disconnect(connModel->getAtIdx(previous.row()), SIGNAL(debugOutput(QString)), nullptr, nullptr);
disconnect(this, SIGNAL(sendDebugData(QByteArray)), nullptr, nullptr);
/* set parameters */
if (selIdx == -1) {
@@ -488,7 +488,7 @@ CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QS
connect(conn_p, SIGNAL(status(CANConStatus)),
this, SLOT(connectionStatus(CANConStatus)));
if (ui->ckEnableConsole->isChecked())
{
{
//set up the debug console to operate if we've selected it. Doing so here allows debugging right away during set up
connect(conn_p, SIGNAL(debugOutput(QString)), this, SLOT(getDebugText(QString)));
}
+99 -3
View File
@@ -584,10 +584,11 @@ void GVRetSerial::readSerialData()
{
c = data.at(i);
//qDebug() << c << " " << QString::number(c, 16) << " " << QString(c);
debugBuild = debugBuild % QString::number(c, 16) % " ";
debugBuild = debugBuild % QString::number(c, 16).rightJustified(2,'0') % " ";
procRXChar(c);
}
debugOutput(debugBuild);
//qDebug() << debugBuild;
}
//Debugging data sent from connection window. Inject it into Comm traffic.
@@ -640,7 +641,7 @@ void GVRetSerial::procRXChar(unsigned char c)
break;
case 9:
validationCounter = 10;
//qDebug() << "Got validated";
qDebug() << "Got validated";
rx_state = IDLE;
break;
case 12:
@@ -653,6 +654,15 @@ void GVRetSerial::procRXChar(unsigned char c)
qDebug() << "Got extended buses info reply";
rx_step = 0;
break;
case 20:
rx_state = BUILD_FD_FRAME;
rx_step = 0;
break;
case 22:
rx_state = GET_FD_SETTINGS;
rx_step = 0;
qDebug() << "Got FD settings reply";
break;
}
break;
case BUILD_CAN_FRAME:
@@ -702,6 +712,92 @@ void GVRetSerial::procRXChar(unsigned char c)
break;
default:
if (rx_step < buildData.length() + 9)
{
buildData[rx_step - 9] = c;
if (rx_step == buildData.length() + 8) //it's the last data byte so immediately process the frame
{
rx_state = IDLE;
rx_step = 0;
buildFrame.isReceived = true;
buildFrame.setPayload(buildData);
buildFrame.setFrameType(QCanBusFrame::FrameType::DataFrame);
if (!isCapSuspended())
{
/* get frame from queue */
CANFrame* frame_p = getQueue().get();
if(frame_p) {
//qDebug() << "GVRET got frame on bus " << frame_p->bus;
/* copy frame */
*frame_p = buildFrame;
checkTargettedFrame(buildFrame);
/* enqueue frame */
getQueue().queue();
}
else
qDebug() << "can't get a frame, ERROR";
//take the time the frame came in and try to resync the time base.
//if (continuousTimeSync) txTimestampBasis = QDateTime::currentMSecsSinceEpoch() - (buildFrame.timestamp / 1000);
}
}
}
else //should never get here! But, just in case, reset the comm
{
rx_state = IDLE;
rx_step = 0;
}
break;
}
rx_step++;
break;
case BUILD_FD_FRAME:
switch (rx_step)
{
case 0:
buildTimestamp = c;
break;
case 1:
buildTimestamp |= (uint)(c << 8);
break;
case 2:
buildTimestamp |= (uint)c << 16;
break;
case 3:
buildTimestamp |= (uint)c << 24;
buildTimestamp += timeBasis;
if (useSystemTime)
{
buildTimestamp = QDateTime::currentMSecsSinceEpoch() * 1000l;
}
buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, buildTimestamp));
break;
case 4:
buildId = c;
break;
case 5:
buildId |= c << 8;
break;
case 6:
buildId |= c << 16;
break;
case 7:
buildId |= c << 24;
if ((buildId & 1 << 31) == 1u << 31)
{
buildId &= 0x7FFFFFFF;
buildFrame.setExtendedFrameFormat(true);
}
else buildFrame.setExtendedFrameFormat(false);
buildFrame.setFrameId(buildId);
break;
case 8:
buildData.resize(c & 0x3F);
break;
case 9:
buildFrame.bus = c;
default:
if (rx_step < buildData.length() + 10)
{
buildData[rx_step - 9] = c;
}
@@ -719,7 +815,7 @@ void GVRetSerial::procRXChar(unsigned char c)
if(frame_p) {
//qDebug() << "GVRET got frame on bus " << frame_p->bus;
/* copy frame */
*frame_p = buildFrame;
*frame_p = buildFrame;
checkTargettedFrame(buildFrame);
/* enqueue frame */
getQueue().queue();
+3 -1
View File
@@ -32,7 +32,9 @@ enum STATE
GET_DEVICE_INFO,
SET_SINGLEWIRE_MODE,
GET_NUM_BUSES,
GET_EXT_BUSES
GET_EXT_BUSES,
BUILD_FD_FRAME,
GET_FD_SETTINGS
};
}