Add jump from READ_STATE_BREAK to READ_STATE_SID.

This commit is contained in:
Your Name 2024-03-10 15:34:45 +01:00
parent f03d722407
commit adc86f7488

View File

@ -164,6 +164,7 @@ void LinBusListener::onReceive_() {
void LinBusListener::read_lin_frame_() { void LinBusListener::read_lin_frame_() {
u_int8_t buf; u_int8_t buf;
QUEUE_LOG_MSG log_msg = QUEUE_LOG_MSG(); QUEUE_LOG_MSG log_msg = QUEUE_LOG_MSG();
switch (this->current_state_) { switch (this->current_state_) {
case READ_STATE_BREAK: case READ_STATE_BREAK:
// Check if there was an unanswered message before break. // Check if there was an unanswered message before break.
@ -187,14 +188,19 @@ void LinBusListener::read_lin_frame_() {
// Reset current state // Reset current state
this->current_state_reset_(); this->current_state_reset_();
// First is Break expected // First is Break expected. Arduino platform does not relay BREAK if send as special.
if (!this->read_byte(&buf) || buf != LIN_BREAK) { if (!this->read_byte(&buf) || (buf != LIN_BREAK && buf != LIN_SYNC)) {
log_msg.type = QUEUE_LOG_MSG_TYPE::VV_READ_LIN_FRAME_BREAK_EXPECTED; log_msg.type = QUEUE_LOG_MSG_TYPE::VV_READ_LIN_FRAME_BREAK_EXPECTED;
log_msg.current_PID = buf; log_msg.current_PID = buf;
TRUMA_LOGVV_ISR(log_msg); TRUMA_LOGVV_ISR(log_msg);
} else { } else {
if (buf == LIN_BREAK) {
// ESP_LOGVV(TAG, "%02X BREAK received.", buf); // ESP_LOGVV(TAG, "%02X BREAK received.", buf);
this->current_state_ = READ_STATE_SYNC; this->current_state_ = READ_STATE_SYNC;
} else if (buf == LIN_SYNC) {
// ESP_LOGVV(TAG, "%02X SYNC found.", buf);
this->current_state_ = READ_STATE_SID;
}
} }
break; break;
case READ_STATE_SYNC: case READ_STATE_SYNC:
@ -232,14 +238,13 @@ void LinBusListener::read_lin_frame_() {
// Even on error read data. // Even on error read data.
this->current_state_ = READ_STATE_DATA; this->current_state_ = READ_STATE_DATA;
break; break;
case READ_STATE_DATA: { case READ_STATE_DATA:
auto current = micros(); auto current = micros();
if (current > (this->last_data_recieved_ + this->time_per_first_byte_)) { if (current > (this->last_data_recieved_ + this->time_per_first_byte_)) {
// timeout occured. // timeout occured.
this->current_state_ = READ_STATE_BREAK; this->current_state_ = READ_STATE_BREAK;
return; return;
} }
}
this->read_byte(&buf); this->read_byte(&buf);
this->current_data_[this->current_data_count_] = buf; this->current_data_[this->current_data_count_] = buf;
this->current_data_count_++; this->current_data_count_++;