7 static const char *
const TAG =
"canbus";
10 ESP_LOGCONFIG(TAG,
"Setting up Canbus...");
12 ESP_LOGE(TAG,
"setup error!");
19 ESP_LOGCONFIG(TAG,
"config extended id=0x%08" PRIx32, this->
can_id_);
21 ESP_LOGCONFIG(TAG,
"config standard id=0x%03" PRIx32, this->
can_id_);
25 void Canbus::send_data(uint32_t can_id,
bool use_extended_id,
bool remote_transmission_request,
26 const std::vector<uint8_t> &data) {
29 uint8_t size =
static_cast<uint8_t
>(data.size());
30 if (use_extended_id) {
31 ESP_LOGD(TAG,
"send extended id=0x%08" PRIx32
" rtr=%s size=%d", can_id, TRUEFALSE(remote_transmission_request),
34 ESP_LOGD(TAG,
"send standard id=0x%03" PRIx32
" rtr=%s size=%d", can_id, TRUEFALSE(remote_transmission_request),
37 if (size > CAN_MAX_DATA_LENGTH)
38 size = CAN_MAX_DATA_LENGTH;
40 can_message.
can_id = can_id;
44 for (
int i = 0; i < size; i++) {
45 can_message.data[i] = data[i];
46 ESP_LOGVV(TAG,
" data[%d]=%02x", i, can_message.data[i]);
54 ESP_LOGVV(TAG,
"add trigger for extended canid=0x%08" PRIx32, trigger->
can_id_);
56 ESP_LOGVV(TAG,
"add trigger for std canid=0x%03" PRIx32, trigger->
can_id_);
64 int message_counter = 0;
68 ESP_LOGD(TAG,
"received can message (#%d) extended can_id=0x%" PRIx32
" size=%d", message_counter,
71 ESP_LOGD(TAG,
"received can message (#%d) std can_id=0x%" PRIx32
" size=%d", message_counter, can_message.
can_id,
75 std::vector<uint8_t> data;
79 ESP_LOGV(TAG,
" can_message.data[%d]=%02x", i, can_message.data[i]);
80 data.push_back(can_message.data[i]);
85 if ((trigger->can_id_ == (can_message.
can_id & trigger->can_id_mask_)) &&
87 (!trigger->remote_transmission_request_.has_value() ||
void add_trigger(CanbusTrigger *trigger)
uint8_t can_data_length_code
bool remote_transmission_request
virtual Error read_message(struct CanFrame *frame)
virtual bool setup_internal()
virtual Error send_message(struct CanFrame *frame)
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
void send_data(uint32_t can_id, bool use_extended_id, bool remote_transmission_request, const std::vector< uint8_t > &data)
std::vector< CanbusTrigger * > triggers_
void dump_config() override