J2534_WIN: Support for changing Baudrate with IOCTL.

This commit is contained in:
Jessy Diamond Exum 2017-10-15 21:12:25 -07:00
parent ef65503fdf
commit 4d02257243
7 changed files with 100 additions and 1 deletions

View File

@ -123,6 +123,25 @@ namespace pandaJ2534DLLTest
UnloadJ2534Dll();
}
//Test that the BAUD rate of a CAN connection can be changed.
TEST_METHOD(J2534_CAN_SetBaud)
{
auto chanid = J2534_open_and_connect("", CAN, 0, 500000, LINE_INFO());
write_ioctl(chanid, LOOPBACK, TRUE, LINE_INFO()); // ENABLE J2534 ECHO/LOOPBACK
auto p = getPanda(250);
J2534_send_msg_checked(chanid, CAN, 0, 0, 0, 4 + 2, 0, "\x0\x0\x3\xAB""HI", LINE_INFO());
j2534_recv_loop(chanid, 0);
panda_recv_loop(p, 0);
write_ioctl(chanid, DATA_RATE, 250000, LINE_INFO());
auto j2534_msg_recv = j2534_recv_loop(chanid, 1);
check_J2534_can_msg(j2534_msg_recv[0], CAN, TX_MSG_TYPE, 0, 4 + 2, 0, "\x0\x0\x3\xAB""HI", LINE_INFO());
auto panda_msg_recv = panda_recv_loop(p, 1);
check_panda_can_msg(panda_msg_recv[0], 0, 0x3AB, FALSE, FALSE, "HI", LINE_INFO());
}
TEST_METHOD(J2534_CAN_11b_Tx)
{
auto chanid = J2534_open_and_connect("", CAN, 0, 500000, LINE_INFO());
@ -488,6 +507,26 @@ namespace pandaJ2534DLLTest
UnloadJ2534Dll();
}
//Test that the BAUD rate of a ISO15765 connection can be changed.
TEST_METHOD(J2534_ISO15765_SetBaud)
{
auto chanid = J2534_open_and_connect("", ISO15765, 0, 500000, LINE_INFO());
write_ioctl(chanid, LOOPBACK, TRUE, LINE_INFO()); // ENABLE J2534 ECHO/LOOPBACK
auto p = getPanda(250);
J2534_send_msg_checked(chanid, ISO15765, 0, 0, 0, 4 + 2, 0, "\x0\x0\x3\xAB""HI", LINE_INFO());
j2534_recv_loop(chanid, 0);
panda_recv_loop(p, 0);
write_ioctl(chanid, DATA_RATE, 250000, LINE_INFO());
auto j2534_msg_recv = j2534_recv_loop(chanid, 2);
check_J2534_can_msg(j2534_msg_recv[0], ISO15765, TX_INDICATION, 0, 4, 0, "\x0\x0\x3\xAB", LINE_INFO());
check_J2534_can_msg(j2534_msg_recv[1], ISO15765, TX_MSG_TYPE, 0, 4 + 2, 0, "\x0\x0\x3\xAB""HI", LINE_INFO());
auto panda_msg_recv = panda_recv_loop(p, 1);
check_panda_can_msg(panda_msg_recv[0], 0, 0x3AB, FALSE, FALSE, "\x2""HI", LINE_INFO());
}
///////////////////// Tests checking things don't send/receive /////////////////////
//Check tx PASSES and rx FAIL WITHOUT a filter. 29 bit. NO Filter. NoPadding. STD address. Single Frame.

View File

@ -113,6 +113,37 @@ namespace pandaTestNative
}
}
TEST_METHOD(Panda_CAN_ChangeBaud)
{
auto p0 = getPanda(250);
auto p1 = getPanda(500);
p0->can_send(0xAA, FALSE, (const uint8_t*)"\x1\x2\x3\x4\x5\x6\x7\x8", 8, panda::PANDA_CAN1);
panda_recv_loop(p0, 0);
panda_recv_loop(p1, 0);
p0->set_can_speed_kbps(panda::PANDA_CAN1, 500);
auto panda_msg_recv = panda_recv_loop(p0, 1);
check_panda_can_msg(panda_msg_recv[0], 0, 0xAA, FALSE, TRUE, "\x1\x2\x3\x4\x5\x6\x7\x8", LINE_INFO());
panda_msg_recv = panda_recv_loop(p1, 1);
check_panda_can_msg(panda_msg_recv[0], 0, 0xAA, FALSE, FALSE, "\x1\x2\x3\x4\x5\x6\x7\x8", LINE_INFO());
//////////////////
p0->set_can_speed_kbps(panda::PANDA_CAN1, 250);
p0->can_send(0xC4, FALSE, (const uint8_t*)"\xA\B\xC\xD\xE\xF\x10\x11", 8, panda::PANDA_CAN1);
panda_recv_loop(p0, 0);
panda_recv_loop(p1, 0);
p1->set_can_speed_kbps(panda::PANDA_CAN1, 250);
panda_msg_recv = panda_recv_loop(p0, 1);
check_panda_can_msg(panda_msg_recv[0], 0, 0xC4, FALSE, TRUE, "\xA\B\xC\xD\xE\xF\x10\x11", LINE_INFO());
panda_msg_recv = panda_recv_loop(p1, 1);
check_panda_can_msg(panda_msg_recv[0], 0, 0xC4, FALSE, FALSE, "\xA\B\xC\xD\xE\xF\x10\x11", LINE_INFO());
}
TEST_METHOD(Panda_CAN_ClearClears)
{
auto p0 = getPanda(500, TRUE);

View File

@ -47,7 +47,8 @@ public:
long clearPeriodicMsgs();
long clearMsgFilters();
long setBaud(unsigned long baud);
virtual long setBaud(unsigned long baud);
unsigned long getBaud() {
return this->BaudRate;
}

View File

@ -27,3 +27,15 @@ unsigned long J2534Connection_CAN::validateTxMsg(PASSTHRU_MSG* msg) {
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));
}
long J2534Connection_CAN::setBaud(unsigned long BaudRate) {
if (auto panda_dev = this->getPandaDev()) {
if (BaudRate % 100 || BaudRate < 10000 || BaudRate > 5000000)
return ERR_NOT_SUPPORTED;
panda_dev->panda->set_can_speed_cbps(panda::PANDA_CAN1, (uint16_t)(BaudRate / 100));
return J2534Connection::setBaud(BaudRate);
} else {
return ERR_DEVICE_NOT_CONNECTED;
}
}

View File

@ -18,6 +18,8 @@ public:
virtual std::shared_ptr<MessageTx> parseMessageTx(PASSTHRU_MSG& pMsg);
virtual long setBaud(unsigned long baud);
virtual unsigned long getMinMsgLen() {
return 4;
}

View File

@ -170,6 +170,18 @@ void J2534Connection_ISO15765::processMessage(const J2534Frame& msg) {
}
}
long J2534Connection_ISO15765::setBaud(unsigned long BaudRate) {
if (auto panda_dev = this->getPandaDev()) {
if (BaudRate % 100 || BaudRate < 10000 || BaudRate > 5000000)
return ERR_NOT_SUPPORTED;
panda_dev->panda->set_can_speed_cbps(panda::PANDA_CAN1, (uint16_t)(BaudRate / 100));
return J2534Connection::setBaud(BaudRate);
} else {
return ERR_DEVICE_NOT_CONNECTED;
}
}
long J2534Connection_ISO15765::PassThruStartMsgFilter(unsigned long FilterType, PASSTHRU_MSG *pMaskMsg, PASSTHRU_MSG *pPatternMsg,
PASSTHRU_MSG *pFlowControlMsg, unsigned long *pFilterID) {

View File

@ -33,6 +33,8 @@ public:
virtual void processMessage(const J2534Frame& msg);
virtual long setBaud(unsigned long baud);
virtual unsigned long getMinMsgLen() {
return 4;
}