1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-13 22:28:14 +00:00

fixed transmission issues

This commit is contained in:
mvturnho 2019-08-01 06:59:23 +02:00
parent 6ac80483f4
commit cf2cf87a66
2 changed files with 21 additions and 25 deletions

View File

@ -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; }
TEMPLATABLE_VALUE(float, data)
void play(Ts... x) override {
if (this->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:
Canbus *parent_;
uint32_t can_id_;
bool static_{false};
std::function<std::vector<uint8_t>(Ts...)> data_func_{};
std::vector<uint8_t> data_static_{};

View File

@ -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) {
struct can_frame can_message;
//uint8_t size = static_cast<uint8_t>(data.size());
//ESP_LOGD(TAG, "size=%d", size);
// if (size > CAN_MAX_DLC)
// size = CAN_MAX_DLC;
// 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]);
// }
uint8_t size = static_cast<uint8_t>(data.size());
ESP_LOGD(TAG, "size=%d", size);
if (size > CAN_MAX_DLC)
size = CAN_MAX_DLC;
can_message.can_dlc = size;
can_message.can_id = this->sender_id_;
can_message.can_dlc = 8;
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;
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_dlc = 8;
// 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->send_message_(&can_message);