mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 07:08:20 +00:00
fixed transmission issues
This commit is contained in:
parent
6ac80483f4
commit
cf2cf87a66
@ -21,8 +21,6 @@ template<typename... Ts> class CanbusSendAction : public Action<Ts...>, public P
|
|||||||
|
|
||||||
void set_can_id(uint32_t can_id) { this->can_id_ = can_id; }
|
void set_can_id(uint32_t can_id) { this->can_id_ = can_id; }
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(float, data)
|
|
||||||
|
|
||||||
void play(Ts... x) override {
|
void play(Ts... x) override {
|
||||||
if (this->static_) {
|
if (this->static_) {
|
||||||
this->parent_->send_data(this->can_id_, this->data_static_);
|
this->parent_->send_data(this->can_id_, this->data_static_);
|
||||||
@ -33,9 +31,7 @@ template<typename... Ts> class CanbusSendAction : public Action<Ts...>, public P
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Canbus *parent_;
|
|
||||||
uint32_t can_id_;
|
uint32_t can_id_;
|
||||||
|
|
||||||
bool static_{false};
|
bool static_{false};
|
||||||
std::function<std::vector<uint8_t>(Ts...)> data_func_{};
|
std::function<std::vector<uint8_t>(Ts...)> data_func_{};
|
||||||
std::vector<uint8_t> data_static_{};
|
std::vector<uint8_t> data_static_{};
|
||||||
|
@ -19,28 +19,28 @@ void Canbus::dump_config() { ESP_LOGCONFIG(TAG, "Canbus: sender_id=%d", this->se
|
|||||||
void Canbus::send_data(uint32_t can_id, const std::vector<uint8_t> data) {
|
void Canbus::send_data(uint32_t can_id, const std::vector<uint8_t> data) {
|
||||||
struct can_frame can_message;
|
struct can_frame can_message;
|
||||||
|
|
||||||
//uint8_t size = static_cast<uint8_t>(data.size());
|
uint8_t size = static_cast<uint8_t>(data.size());
|
||||||
//ESP_LOGD(TAG, "size=%d", size);
|
ESP_LOGD(TAG, "size=%d", size);
|
||||||
// if (size > CAN_MAX_DLC)
|
if (size > CAN_MAX_DLC)
|
||||||
// size = CAN_MAX_DLC;
|
size = CAN_MAX_DLC;
|
||||||
// can_message.can_dlc = size;
|
can_message.can_dlc = size;
|
||||||
// can_message.can_id = this->sender_id_;
|
|
||||||
|
|
||||||
// for (int i = 0; i < size; i++) {
|
|
||||||
// can_message.data[i] = data[i];
|
|
||||||
// ESP_LOGD(TAG, "data[%d] = %02x", i, can_message.data[i]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
can_message.can_id = this->sender_id_;
|
can_message.can_id = this->sender_id_;
|
||||||
can_message.can_dlc = 8;
|
|
||||||
can_message.data[0] = 0x00;
|
for (int i = 0; i < size; i++) {
|
||||||
can_message.data[1] = 0x01;
|
can_message.data[i] = data[i];
|
||||||
can_message.data[2] = 0x02;
|
ESP_LOGD(TAG, "data[%d] = %02x", i, can_message.data[i]);
|
||||||
can_message.data[3] = 0x03;
|
}
|
||||||
can_message.data[4] = 0x04;
|
|
||||||
can_message.data[5] = 0x05;
|
// can_message.can_id = this->sender_id_;
|
||||||
can_message.data[6] = 0x06;
|
// can_message.can_dlc = 8;
|
||||||
can_message.data[7] = 0x07;
|
// can_message.data[0] = 0x00;
|
||||||
|
// can_message.data[1] = 0x01;
|
||||||
|
// can_message.data[2] = 0x02;
|
||||||
|
// can_message.data[3] = 0x03;
|
||||||
|
// can_message.data[4] = 0x04;
|
||||||
|
// can_message.data[5] = 0x05;
|
||||||
|
// can_message.data[6] = 0x06;
|
||||||
|
// can_message.data[7] = 0x07;
|
||||||
//this->dump_frame_(&can_message);
|
//this->dump_frame_(&can_message);
|
||||||
|
|
||||||
this->send_message_(&can_message);
|
this->send_message_(&can_message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user