Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions connections/serialbusconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
mDev_p->setConfigurationParameter(QCanBusDevice::UserKey, sbusconfig);

/* connect device */
if (!mDev_p->connectDevice()) {
disconnectDevice();
qDebug() << "can't connect device";
if (mDev_p && mDev_p->state() == QCanBusDevice::UnconnectedState) {
if (!mDev_p->connectDevice()) {
disconnectDevice();
qDebug() << "SerialBusConnection::piSetBusSettings - can't connect device";
}
}
}

Expand Down Expand Up @@ -201,11 +203,16 @@ void SerialBusConnection::framesReceived()
if(frame_p) {
frame_p->setPayload(recFrame.payload());
frame_p->setBus(0);
// All frames arriving via framesReceived() are genuinely received frames.
// Do not use QCanBusFrame::hasLocalEcho() to determine direction: some backends
// (e.g. PeakCAN/PCAN on certain platforms) report local echo unreliably,
// causing all received frames to appear as Tx.
frame_p->setReceived(true);

if (recFrame.frameType() == recFrame.ErrorFrame)
{
frame_p->setExtendedFrameFormat(recFrame.hasExtendedFrameFormat());
frame_p->setFrameId(recFrame.frameId() + 0x20000000ull);
frame_p->setReceived(true);
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions help/scriptingwindow.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ setup () - If you create a function named setup then it will be called as soon a

tick () - If you registered to receive a periodic tick within your setup function then the script interface will call this function for every tick. You can do whatever you need to periodically do here. But, you get only one tick handler so if you need multiple tick rates you'll have to create a fast tick here and dispatch from this function at different rates yourself.

gotCommFrame (bus, id, len, data) - A callback that will be called whenever a CAN frame comes in that you've registered for. You did register for frames in your setup function didn't you? Well, if you use one of the below callbacks you might not need this one.
gotCommFrame (bus, id, len, data) - A callback that will be called whenever a CAN frame comes in that you've registered for. You did register for frames in your setup function didn't you? Well, if you use one of the below callbacks you might not need this one. For backward compatibility, older scripts that still define gotCANFrame(bus, id, len, data) are also accepted.

gotISOTPMessage (bus, id, len, data) - If you are instead looking for ISO-TP messages (which could have been multiple CAN frames in length) then you can create this function and it will automatically be registered with the system. But, you still will need to set which ISO-TP message IDs you want to receive. That is covered later on.

Expand Down Expand Up @@ -130,4 +130,3 @@ A full example script
}
}


10 changes: 8 additions & 2 deletions scriptcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ void ScriptContainer::compileScript()

//Find out which callbacks the script has created.
setupFunction = scriptEngine->globalObject().property("setup");
canHelper->setRxCallback(scriptEngine->globalObject().property("gotCommFrame"));
QJSValue canRxCallback = scriptEngine->globalObject().property("gotCommFrame");
if (!canRxCallback.isCallable())
{
// Backward compatibility with older scripts.
canRxCallback = scriptEngine->globalObject().property("gotCANFrame");
if (canRxCallback.isCallable()) qDebug() << "Using legacy gotCANFrame callback";
}
canHelper->setRxCallback(canRxCallback);
isoHelper->setRxCallback(scriptEngine->globalObject().property("gotISOTPMessage"));
udsHelper->setRxCallback(scriptEngine->globalObject().property("gotUDSMessage"));

Expand Down Expand Up @@ -438,4 +445,3 @@ void UDSScriptHelper::newUDSMessage(UDS_MESSAGE msg)
args.append(dataBytes);
gotFrameFunction.call(args);
}