Skip to content

Commit

Permalink
Add ability to set padding byte for isotp frames
Browse files Browse the repository at this point in the history
"isotp.setPaddingByte(0x??);"
  • Loading branch information
collin80 committed Dec 12, 2023
1 parent 466e0c0 commit f3ea2c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bus_protocols/isotp_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ISOTP_HANDLER::ISOTP_HANDLER()
sendPartialMessages = false;
lastSenderBus = 0;
lastSenderID = 0;
padByte = (char)0xAA;

modelFrames = MainWindow::getReference()->getCANFrameModel()->getListReference();

Expand All @@ -21,6 +22,11 @@ ISOTP_HANDLER::~ISOTP_HANDLER()
disconnect(&frameTimer, SIGNAL(timeout()), this, SLOT(frameTimerTick()));
}

void ISOTP_HANDLER::setPadByte(char newpad)
{
padByte = newpad;
}

void ISOTP_HANDLER::setExtendedAddressing(bool mode)
{
useExtendedAddressing = mode;
Expand Down Expand Up @@ -67,7 +73,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QByteArray data)

if (data.length() < 8)
{
QByteArray bytes(8,0);
QByteArray bytes(8, padByte);
bytes.resize(8);
bytes[0] = data.length();
for (int i = 0; i < data.length(); i++) bytes[i + 1] = data[i];
Expand All @@ -76,7 +82,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QByteArray data)
}
else //need to send a multi-part ISO_TP message - Respects timing and frame number based flow control
{
QByteArray bytes(8, 0);
QByteArray bytes(8, padByte);
bytes[0] = 0x10 + (data.length() / 256);
bytes[1] = data.length() & 0xFF;
for (int i = 0; i < 6; i++) bytes[2 + i] = data[currByte++];
Expand All @@ -89,7 +95,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QByteArray data)
frameTimer.start();
while (currByte < data.length())
{
for (int b = 0; b < 8; b++) bytes[b] = 0x00;
for (int b = 0; b < 8; b++) bytes[b] = padByte;
bytes[0] = 0x20 + sequence; //Consecutive Frame starts from 0x20 + 1 (2: Frame type, 1: Sequence number)
sequence = (sequence + 1) & 0xF;
int bytesToGo = data.length() - currByte;
Expand Down
2 changes: 2 additions & 0 deletions bus_protocols/isotp_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ISOTP_HANDLER : public QObject
void addFilter(int pBusId, uint32_t ID, uint32_t mask);
void removeFilter(int pBusId, uint32_t ID, uint32_t mask);
void clearAllFilters();
void setPadByte(char newpad);

public slots:
void updatedFrames(int);
Expand All @@ -50,6 +51,7 @@ public slots:
QTimer frameTimer;
uint32_t lastSenderID;
uint32_t lastSenderBus;
char padByte;

void processFrame(const CANFrame &frame);
void checkNeedFlush(uint64_t ID);
Expand Down
6 changes: 6 additions & 0 deletions scriptcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ void ISOTPScriptHelper::sendISOTP(QJSValue bus, QJSValue id, QJSValue length, QJ
handler->sendISOTPFrame(msg.bus, msg.frameId(), msg.payload());
}

void ISOTPScriptHelper::setPaddingByte(QJSValue byt)
{
char newB = byt.toInt();
handler->setPadByte(newB);
}

void ISOTPScriptHelper::setRxCallback(QJSValue cb)
{
gotFrameFunction = cb;
Expand Down
1 change: 1 addition & 0 deletions scriptcontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public slots:
void clearFilters();
void sendISOTP(QJSValue bus, QJSValue id, QJSValue length, QJSValue data);
void setRxCallback(QJSValue cb);
void setPaddingByte(QJSValue byt);
private slots:
void newISOMessage(ISOTP_MESSAGE msg);
private:
Expand Down

0 comments on commit f3ea2c6

Please sign in to comment.