2017-09-09 03:25:36 -07:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "J2534Connection_CAN.h"
|
2017-10-10 02:27:37 -07:00
|
|
|
#include "MessageTx_CAN.h"
|
2017-09-09 03:25:36 -07:00
|
|
|
#include "Timer.h"
|
|
|
|
|
|
|
|
|
|
J2534Connection_CAN::J2534Connection_CAN(
|
2017-09-25 23:08:14 -07:00
|
|
|
std::shared_ptr<PandaJ2534Device> panda_dev,
|
2017-09-09 03:25:36 -07:00
|
|
|
unsigned long ProtocolID,
|
|
|
|
|
unsigned long Flags,
|
|
|
|
|
unsigned long BaudRate
|
|
|
|
|
) : J2534Connection(panda_dev, ProtocolID, Flags, BaudRate) {
|
|
|
|
|
this->port = 0;
|
2017-09-15 00:45:35 -07:00
|
|
|
|
|
|
|
|
if (BaudRate % 100 || BaudRate < 10000 || BaudRate > 5000000)
|
|
|
|
|
throw ERR_INVALID_BAUDRATE;
|
|
|
|
|
|
2017-09-25 23:08:14 -07:00
|
|
|
panda_dev->panda->set_can_speed_cbps(panda::PANDA_CAN1, BaudRate/100);
|
2017-09-09 03:25:36 -07:00
|
|
|
};
|
|
|
|
|
|
2017-10-15 17:35:33 -07:00
|
|
|
unsigned long J2534Connection_CAN::validateTxMsg(PASSTHRU_MSG* msg) {
|
|
|
|
|
if ((msg->DataSize < this->getMinMsgLen() || msg->DataSize > this->getMaxMsgLen() ||
|
|
|
|
|
(val_is_29bit(msg->TxFlags) != this->_is_29bit() && !check_bmask(this->Flags, CAN_ID_BOTH))))
|
|
|
|
|
return ERR_INVALID_MSG;
|
2017-09-09 03:25:36 -07:00
|
|
|
return STATUS_NOERROR;
|
|
|
|
|
}
|
2017-10-15 17:35:33 -07:00
|
|
|
|
|
|
|
|
std::shared_ptr<MessageTx> J2534Connection_CAN::parseMessageTx(PASSTHRU_MSG& msg) {
|
|
|
|
|
return std::dynamic_pointer_cast<MessageTx>(std::make_shared<MessageTx_CAN>(shared_from_this(), msg));
|
|
|
|
|
}
|
2017-10-15 21:12:25 -07:00
|
|
|
|
2017-10-16 02:59:26 -07:00
|
|
|
void J2534Connection_CAN::setBaud(unsigned long BaudRate) {
|
2017-10-15 21:12:25 -07:00
|
|
|
if (auto panda_dev = this->getPandaDev()) {
|
|
|
|
|
if (BaudRate % 100 || BaudRate < 10000 || BaudRate > 5000000)
|
2017-10-16 02:59:26 -07:00
|
|
|
throw ERR_NOT_SUPPORTED;
|
2017-10-15 21:12:25 -07:00
|
|
|
|
|
|
|
|
panda_dev->panda->set_can_speed_cbps(panda::PANDA_CAN1, (uint16_t)(BaudRate / 100));
|
|
|
|
|
return J2534Connection::setBaud(BaudRate);
|
|
|
|
|
} else {
|
2017-10-16 02:59:26 -07:00
|
|
|
throw ERR_DEVICE_NOT_CONNECTED;
|
2017-10-15 21:12:25 -07:00
|
|
|
}
|
|
|
|
|
}
|