mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-10-01 03:53:41 +08:00
dbe4641e04
* squash all PR commits for easy rebase * merged all panda rx can into one message * fix buffers in can_send * more cleanup and minor fixes * fix even more stuff * fix non-allocated send buffer * make connecting more robust * fix bus offset * fix controls_mismatch? * simplify mismatch check * C++ style struct * fix connect loop * update ref Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 585c16cd2aba6e2504c2427aaf1855b97035eb41
26 lines
883 B
C++
26 lines
883 B
C++
#include "cereal/messaging/messaging.h"
|
|
#include "panda.h"
|
|
|
|
extern "C" {
|
|
|
|
void can_list_to_can_capnp_cpp(const std::vector<can_frame> &can_list, std::string &out, bool sendCan, bool valid) {
|
|
MessageBuilder msg;
|
|
auto event = msg.initEvent(valid);
|
|
|
|
auto canData = sendCan ? event.initSendcan(can_list.size()) : event.initCan(can_list.size());
|
|
int j = 0;
|
|
for (auto it = can_list.begin(); it != can_list.end(); it++, j++) {
|
|
auto c = canData[j];
|
|
c.setAddress(it->address);
|
|
c.setBusTime(it->busTime);
|
|
c.setDat(kj::arrayPtr((uint8_t*)it->dat.data(), it->dat.size()));
|
|
c.setSrc(it->src);
|
|
}
|
|
const uint64_t msg_size = capnp::computeSerializedSizeInWords(msg) * sizeof(capnp::word);
|
|
out.resize(msg_size);
|
|
kj::ArrayOutputStream output_stream(kj::ArrayPtr<capnp::byte>((unsigned char *)out.data(), msg_size));
|
|
capnp::writeMessage(output_stream, msg);
|
|
}
|
|
|
|
}
|