J2534_WIN: Improved panda API. Added can listener to playground.
parent
0c9604e462
commit
098b703420
|
@ -264,22 +264,17 @@ bool Panda::can_send_many(const std::vector<PANDA_CAN_MSG>& can_msgs) {
|
|||
if (formatted_msgs.size() == 0) return FALSE;
|
||||
|
||||
unsigned int retcount;
|
||||
//uint8_t buff[0x10];
|
||||
|
||||
//std::string dat("\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf", 0x10);
|
||||
//bool res = this->bulk_transfer(2, dat.c_str(), 0x10, (PULONG)&retcount, 0);
|
||||
//bool res2 = this->bulk_transfer(1, dat.c_str(), 0x10, (PULONG)&retcount, 0);
|
||||
|
||||
return this->bulk_write(3, formatted_msgs.data(),
|
||||
sizeof(PANDA_CAN_MSG_INTERNAL)*formatted_msgs.size(), (PULONG)&retcount, 0);
|
||||
}
|
||||
|
||||
bool Panda::can_send(uint32_t addr, bool addr_29b, const uint8_t dat[8], uint8_t len, PANDA_CAN_PORT bus) {
|
||||
bool Panda::can_send(uint32_t addr, bool addr_29b, const uint8_t *dat, uint8_t len, PANDA_CAN_PORT bus) {
|
||||
if (bus == PANDA_CAN_UNK) return FALSE;
|
||||
if (len > 8) return FALSE;
|
||||
PANDA_CAN_MSG msg;
|
||||
msg.addr_29b = addr_29b;
|
||||
msg.addr = addr;
|
||||
msg.len = min(len, 8);
|
||||
msg.len = len;
|
||||
memcpy(msg.dat, dat, msg.len);
|
||||
msg.bus = bus;
|
||||
return this->can_send_many(std::vector<PANDA_CAN_MSG>{msg});
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace panda {
|
|||
bool set_uart_parity(PANDA_SERIAL_PORT uart, PANDA_SERIAL_PORT_PARITY parity);
|
||||
|
||||
bool can_send_many(const std::vector<PANDA_CAN_MSG>& can_msgs);
|
||||
bool can_send(uint32_t addr, bool addr_29b, const uint8_t dat[8], uint8_t len, PANDA_CAN_PORT bus);
|
||||
bool can_send(uint32_t addr, bool addr_29b, const uint8_t *dat, uint8_t len, PANDA_CAN_PORT bus);
|
||||
std::vector<PANDA_CAN_MSG> can_recv();
|
||||
bool can_clear(PANDA_CAN_PORT_CLEAR bus);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ int _tmain(int Argc, _TCHAR *Argv) {
|
|||
_tprintf(_T("Panda '%s'\n"), sn.c_str());
|
||||
}*/
|
||||
|
||||
auto p0 = Panda::openPanda("02000c000f51363038363036");//"0e800a000f51363038363036");
|
||||
auto p0 = Panda::openPanda("");// "02000c000f51363038363036");//"0e800a000f51363038363036");
|
||||
if (p0) {
|
||||
PANDA_HEALTH health = p0->get_health();
|
||||
_tprintf(_T(" Current: %u; Voltage: %u\n"), health.current, health.voltage);
|
||||
|
@ -43,7 +43,7 @@ int _tmain(int Argc, _TCHAR *Argv) {
|
|||
|
||||
p0->set_safety_mode(SAFETY_ALLOUTPUT);
|
||||
|
||||
for (auto lin_port : { SERIAL_LIN1, SERIAL_LIN2 }) {
|
||||
/*for (auto lin_port : { SERIAL_LIN1, SERIAL_LIN2 }) {
|
||||
printf("Doing a new LIN port\n");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
p0->serial_clear(lin_port);
|
||||
|
@ -68,24 +68,28 @@ int _tmain(int Argc, _TCHAR *Argv) {
|
|||
}
|
||||
|
||||
printf("\n\nSERIAL READ:\n");
|
||||
printf("%s\n\n", p0->serial_read(SERIAL_DEBUG).c_str());
|
||||
printf("%s\n\n", p0->serial_read(SERIAL_DEBUG).c_str());*/
|
||||
|
||||
/*p0->set_safety_mode(SAFETY_ALLOUTPUT);
|
||||
p0->set_can_loopback(TRUE);
|
||||
p0->can_clear(PANDA_CAN_RX);
|
||||
p0->set_can_speed_kbps(panda::PANDA_CAN1, 500);
|
||||
p0->set_safety_mode(SAFETY_ALLOUTPUT);
|
||||
p0->set_can_loopback(FALSE);
|
||||
//p0->can_clear(PANDA_CAN_RX);
|
||||
const uint8_t candata[8] = { 'H', 'E', 'L', 'L', 'O', '1', '2', '3' };
|
||||
p0->can_send(0xAA, FALSE, candata, 7, PANDA_CAN1);
|
||||
Sleep(500);
|
||||
auto can_msgs = p0->can_recv();
|
||||
printf("Got %d can message\n", can_msgs.size());
|
||||
for (auto msg : can_msgs) {
|
||||
printf(" Bus: %d%s; Addr: 0x%X (%s); Len: %d;",
|
||||
msg.bus, msg.is_receipt ? "r" : "", msg.addr, msg.addr_29b ? "29b" : "11b", msg.len);
|
||||
for (int i = 0; i < 8; i++) //msg.len; i++)
|
||||
printf("%02X ", msg.dat[i]);
|
||||
//Sleep(500);
|
||||
while (TRUE) {
|
||||
//p0->can_send(0x7E8, FALSE, candata, 7, PANDA_CAN1);
|
||||
auto can_msgs = p0->can_recv();
|
||||
if(can_msgs.size()) printf("Got %d can message\n", can_msgs.size());
|
||||
for (auto msg : can_msgs) {
|
||||
printf(" Bus: %d%s; Addr: 0x%X (%s); Len: %d;",
|
||||
msg.bus, msg.is_receipt ? "r" : "", msg.addr, msg.addr_29b ? "29b" : "11b", msg.len);
|
||||
for (int i = 0; i < 8; i++) //msg.len; i++)
|
||||
printf("%02X ", msg.dat[i]);
|
||||
//printf("%c", msg.dat[i]);
|
||||
printf("\n");
|
||||
}*/
|
||||
printf("\n");
|
||||
}
|
||||
Sleep(1000);
|
||||
}
|
||||
|
||||
/*p0->set_uart_baud(SERIAL_LIN1, 10400);
|
||||
p0->serial_write(SERIAL_LIN1, "DERP", 4);
|
||||
|
|
Loading…
Reference in New Issue