Skip to content

Commit f3ea2c6

Browse files
committed
Add ability to set padding byte for isotp frames
"isotp.setPaddingByte(0x??);"
1 parent 466e0c0 commit f3ea2c6

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

bus_protocols/isotp_handler.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ISOTP_HANDLER::ISOTP_HANDLER()
1010
sendPartialMessages = false;
1111
lastSenderBus = 0;
1212
lastSenderID = 0;
13+
padByte = (char)0xAA;
1314

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

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

25+
void ISOTP_HANDLER::setPadByte(char newpad)
26+
{
27+
padByte = newpad;
28+
}
29+
2430
void ISOTP_HANDLER::setExtendedAddressing(bool mode)
2531
{
2632
useExtendedAddressing = mode;
@@ -67,7 +73,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QByteArray data)
6773

6874
if (data.length() < 8)
6975
{
70-
QByteArray bytes(8,0);
76+
QByteArray bytes(8, padByte);
7177
bytes.resize(8);
7278
bytes[0] = data.length();
7379
for (int i = 0; i < data.length(); i++) bytes[i + 1] = data[i];
@@ -76,7 +82,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QByteArray data)
7682
}
7783
else //need to send a multi-part ISO_TP message - Respects timing and frame number based flow control
7884
{
79-
QByteArray bytes(8, 0);
85+
QByteArray bytes(8, padByte);
8086
bytes[0] = 0x10 + (data.length() / 256);
8187
bytes[1] = data.length() & 0xFF;
8288
for (int i = 0; i < 6; i++) bytes[2 + i] = data[currByte++];
@@ -89,7 +95,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QByteArray data)
8995
frameTimer.start();
9096
while (currByte < data.length())
9197
{
92-
for (int b = 0; b < 8; b++) bytes[b] = 0x00;
98+
for (int b = 0; b < 8; b++) bytes[b] = padByte;
9399
bytes[0] = 0x20 + sequence; //Consecutive Frame starts from 0x20 + 1 (2: Frame type, 1: Sequence number)
94100
sequence = (sequence + 1) & 0xF;
95101
int bytesToGo = data.length() - currByte;

bus_protocols/isotp_handler.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ISOTP_HANDLER : public QObject
2626
void addFilter(int pBusId, uint32_t ID, uint32_t mask);
2727
void removeFilter(int pBusId, uint32_t ID, uint32_t mask);
2828
void clearAllFilters();
29+
void setPadByte(char newpad);
2930

3031
public slots:
3132
void updatedFrames(int);
@@ -50,6 +51,7 @@ public slots:
5051
QTimer frameTimer;
5152
uint32_t lastSenderID;
5253
uint32_t lastSenderBus;
54+
char padByte;
5355

5456
void processFrame(const CANFrame &frame);
5557
void checkNeedFlush(uint64_t ID);

scriptcontainer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ void ISOTPScriptHelper::sendISOTP(QJSValue bus, QJSValue id, QJSValue length, QJ
329329
handler->sendISOTPFrame(msg.bus, msg.frameId(), msg.payload());
330330
}
331331

332+
void ISOTPScriptHelper::setPaddingByte(QJSValue byt)
333+
{
334+
char newB = byt.toInt();
335+
handler->setPadByte(newB);
336+
}
337+
332338
void ISOTPScriptHelper::setRxCallback(QJSValue cb)
333339
{
334340
gotFrameFunction = cb;

scriptcontainer.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public slots:
4545
void clearFilters();
4646
void sendISOTP(QJSValue bus, QJSValue id, QJSValue length, QJSValue data);
4747
void setRxCallback(QJSValue cb);
48+
void setPaddingByte(QJSValue byt);
4849
private slots:
4950
void newISOMessage(ISOTP_MESSAGE msg);
5051
private:

0 commit comments

Comments
 (0)