@@ -7,7 +7,7 @@ J2534Connection::J2534Connection(
7
7
unsigned long ProtocolID,
8
8
unsigned long Flags,
9
9
unsigned long BaudRate
10
- ) : panda_dev(panda_dev), ProtocolID(ProtocolID), Flags(Flags), BaudRate(BaudRate), port(0 ) { }
10
+ ) : panda_dev(panda_dev), ProtocolID(ProtocolID), Flags(Flags), BaudRate(BaudRate), Parity( 0 ), port(0 ) { }
11
11
12
12
unsigned long J2534Connection::validateTxMsg (PASSTHRU_MSG* msg) {
13
13
if (msg->DataSize < this ->getMinMsgLen () || msg->DataSize > this ->getMaxMsgLen ())
@@ -60,7 +60,7 @@ long J2534Connection::PassThruReadMsgs(PASSTHRU_MSG *pMsg, unsigned long *pNumMs
60
60
61
61
long J2534Connection::PassThruWriteMsgs (PASSTHRU_MSG *pMsg, unsigned long *pNumMsgs, unsigned long Timeout) {
62
62
// There doesn't seem to be much reason to implement the timeout here.
63
- for (int msgnum = 0 ; msgnum < *pNumMsgs; msgnum++) {
63
+ for (unsigned int msgnum = 0 ; msgnum < *pNumMsgs; msgnum++) {
64
64
PASSTHRU_MSG* msg = &pMsg[msgnum];
65
65
if (msg->ProtocolID != this ->ProtocolID ) {
66
66
*pNumMsgs = msgnum;
@@ -87,7 +87,7 @@ long J2534Connection::PassThruStartPeriodicMsg(PASSTHRU_MSG *pMsg, unsigned long
87
87
if (pMsg->ProtocolID != this ->ProtocolID ) return ERR_MSG_PROTOCOL_ID;
88
88
if (TimeInterval < 5 || TimeInterval > 65535 ) return ERR_INVALID_TIME_INTERVAL;
89
89
90
- for (int i = 0 ; i < this ->periodicMessages .size (); i++) {
90
+ for (unsigned int i = 0 ; i < this ->periodicMessages .size (); i++) {
91
91
if (periodicMessages[i] != nullptr ) continue ;
92
92
93
93
*pMsgID = i;
@@ -114,11 +114,11 @@ long J2534Connection::PassThruStopPeriodicMsg(unsigned long MsgID) {
114
114
115
115
long J2534Connection::PassThruStartMsgFilter (unsigned long FilterType, PASSTHRU_MSG *pMaskMsg, PASSTHRU_MSG *pPatternMsg,
116
116
PASSTHRU_MSG *pFlowControlMsg, unsigned long *pFilterID) {
117
- for (int i = 0 ; i < this ->filters .size (); i++) {
117
+ for (unsigned int i = 0 ; i < this ->filters .size (); i++) {
118
118
if (filters[i] == nullptr ) {
119
119
try {
120
120
auto newfilter = std::make_shared<J2534MessageFilter>(this , FilterType, pMaskMsg, pPatternMsg, pFlowControlMsg);
121
- for (int check_idx = 0 ; check_idx < filters.size (); check_idx++) {
121
+ for (unsigned int check_idx = 0 ; check_idx < filters.size (); check_idx++) {
122
122
if (filters[check_idx] == nullptr ) continue ;
123
123
if (filters[check_idx] == newfilter) {
124
124
filters[i] = nullptr ;
@@ -147,28 +147,99 @@ long J2534Connection::PassThruIoctl(unsigned long IoctlID, void *pInput, void *p
147
147
return STATUS_NOERROR;
148
148
}
149
149
150
- long J2534Connection::init5b (SBYTE_ARRAY* pInput, SBYTE_ARRAY* pOutput) { return ERR_FAILED; }
151
- long J2534Connection::initFast (PASSTHRU_MSG* pInput, PASSTHRU_MSG* pOutput) { return ERR_FAILED; }
150
+ long J2534Connection::init5b (SBYTE_ARRAY* pInput, SBYTE_ARRAY* pOutput) {
151
+ if (pInput->NumOfBytes == 1 ) {
152
+ if (auto panda_ps = this ->panda_dev .lock ()) {
153
+ auto resp = panda_ps->kline_five_baud_init (pInput->BytePtr [0 ]);
154
+ if (resp.size () > 0 ) {
155
+ auto key_bytes = resp.c_str ();
156
+ if (pOutput->NumOfBytes >= 1 ) {
157
+ pOutput->BytePtr [0 ] = key_bytes[0 ];
158
+ }
159
+ if (pOutput->NumOfBytes >= 2 ) {
160
+ pOutput->BytePtr [1 ] = key_bytes[1 ];
161
+ }
162
+ return STATUS_NOERROR;
163
+ }
164
+ }
165
+ }
166
+
167
+ return ERR_FAILED;
168
+ }
169
+ long J2534Connection::initFast (PASSTHRU_MSG* pInput, PASSTHRU_MSG* pOutput) {
170
+ if (auto panda_ps = this ->panda_dev .lock ()) {
171
+ auto start_comm = std::string ((char *)pInput->Data , pInput->DataSize );
172
+ auto resp = panda_ps->kline_wakeup_start_comm (start_comm);
173
+ if (resp.size () > 0 ) {
174
+ pOutput->ProtocolID = pInput->ProtocolID ;
175
+ pOutput->RxStatus = 0 ;
176
+ pOutput->TxFlags = 0 ;
177
+ pOutput->Timestamp = pInput->Timestamp ;
178
+ pOutput->ExtraDataIndex = resp.size ();
179
+ memcpy (pOutput->Data , resp.c_str (), resp.size ());
180
+ pOutput->DataSize = resp.size ();
181
+ return STATUS_NOERROR;
182
+ }
183
+ }
184
+
185
+ return ERR_FAILED;
186
+ }
152
187
long J2534Connection::clearTXBuff () {
153
188
if (auto panda_ps = this ->panda_dev .lock ()) {
154
189
synchronized (staged_writes_lock) {
155
190
this ->txbuff = {};
156
- panda_ps->panda ->can_clear (panda::PANDA_CAN1_TX);
191
+ switch (this ->ProtocolID )
192
+ {
193
+ case CAN:
194
+ case CAN_PS:
195
+ case ISO15765:
196
+ case ISO15765_PS:
197
+ panda_ps->panda ->can_clear (panda::PANDA_CAN1_TX);
198
+ break ;
199
+ case ISO9141:
200
+ case ISO9141_PS:
201
+ case ISO14230:
202
+ case ISO14230_PS:
203
+ panda_ps->panda ->serial_clear (panda::SERIAL_LIN1);
204
+ panda_ps->panda ->serial_clear (panda::SERIAL_LIN2);
205
+ break ;
206
+ default :
207
+ break ;
208
+ }
157
209
}
210
+ return STATUS_NOERROR;
158
211
}
159
- return STATUS_NOERROR ;
212
+ return ERR_FAILED ;
160
213
}
161
214
long J2534Connection::clearRXBuff () {
162
215
if (auto panda_ps = this ->panda_dev .lock ()) {
163
216
synchronized (messageRxBuff_mutex) {
164
217
this ->messageRxBuff = {};
165
- panda_ps->panda ->can_clear (panda::PANDA_CAN_RX);
218
+ switch (this ->ProtocolID )
219
+ {
220
+ case CAN:
221
+ case CAN_PS:
222
+ case ISO15765:
223
+ case ISO15765_PS:
224
+ panda_ps->panda ->can_clear (panda::PANDA_CAN_RX);
225
+ break ;
226
+ case ISO9141:
227
+ case ISO9141_PS:
228
+ case ISO14230:
229
+ case ISO14230_PS:
230
+ panda_ps->panda ->serial_clear (panda::SERIAL_LIN1);
231
+ panda_ps->panda ->serial_clear (panda::SERIAL_LIN2);
232
+ break ;
233
+ default :
234
+ break ;
235
+ }
166
236
}
237
+ return STATUS_NOERROR;
167
238
}
168
- return STATUS_NOERROR ;
239
+ return ERR_FAILED ;
169
240
}
170
241
long J2534Connection::clearPeriodicMsgs () {
171
- for (int i = 0 ; i < this ->periodicMessages .size (); i++) {
242
+ for (unsigned int i = 0 ; i < this ->periodicMessages .size (); i++) {
172
243
if (periodicMessages[i] == nullptr ) continue ;
173
244
this ->periodicMessages [i]->cancel ();
174
245
this ->periodicMessages [i] = nullptr ;
@@ -185,6 +256,10 @@ void J2534Connection::setBaud(unsigned long baud) {
185
256
this ->BaudRate = baud;
186
257
}
187
258
259
+ void J2534Connection::setParity (unsigned long parity) {
260
+ this ->Parity = parity;
261
+ }
262
+
188
263
void J2534Connection::schedultMsgTx (std::shared_ptr<Action> msgout) {
189
264
if (auto panda_ps = this ->panda_dev .lock ()) {
190
265
synchronized (staged_writes_lock) {
@@ -226,6 +301,9 @@ void J2534Connection::processIOCTLSetConfig(unsigned long Parameter, unsigned lo
226
301
case LOOPBACK: // 0 (OFF), 1 (ON) [0]
227
302
this ->loopback = (Value != 0 );
228
303
break ;
304
+ case PARITY:
305
+ this ->setParity (Value);
306
+ break ;
229
307
case ISO15765_WFT_MAX:
230
308
break ;
231
309
case NODE_ADDRESS: // J1850PWM Related (Not supported by panda). HDS requires these to 'work'.
@@ -247,7 +325,6 @@ void J2534Connection::processIOCTLSetConfig(unsigned long Parameter, unsigned lo
247
325
case TIDLE:
248
326
case TINIL:
249
327
case TWUP:
250
- case PARITY:
251
328
case T1_MAX: // SCI related options. The panda does not appear to support this
252
329
case T2_MAX:
253
330
case T3_MAX:
@@ -259,9 +336,9 @@ void J2534Connection::processIOCTLSetConfig(unsigned long Parameter, unsigned lo
259
336
}
260
337
261
338
// reserved parameters usually mean special equiptment is required
262
- if (Parameter >= 0x20 ) {
263
- throw ERR_NOT_SUPPORTED;
264
- }
339
+ // if (Parameter >= 0x20) {
340
+ // throw ERR_NOT_SUPPORTED;
341
+ // }
265
342
}
266
343
267
344
unsigned long J2534Connection::processIOCTLGetConfig (unsigned long Parameter) {
0 commit comments