Code Monkey home page Code Monkey logo

Comments (6)

lanwin avatar lanwin commented on September 13, 2024

Thanks for reporting this! And thank you that you attached example data. That is a good start to find a better way.

The current solution is a pretty basic approach.

A far better approach would it be to fill the buffer and check if we found a valid packed until we found one or the buffer has reached its max size.

from esphome_samsung_ac.

Foxhill67 avatar Foxhill67 commented on September 13, 2024

Tried this in 'my' fork in the second part of void Samsung_AC::loop(), and it seems to work fine (declared bytes_ and size_ as uint16_t in samsung_ac.h):
last_transmission_ = now;
while (available())
{
uint8_t c;
read_byte(&c);
if (c == 0x32 && !receiving_) // start-byte found
{
receiving_ = true;
bytes_ = 0;
size_ = 0;
data_.clear();
}
if (receiving_)
{
data_.push_back(c);
bytes_++;
switch (bytes_)
{
case 1: // start byte found
break;
case 2: // first part of size found
{
size_ = c;
break;
}
case 3: // second part of size found
{
size_ = (int)size_ << 8 | c;
ESP_LOGV(TAG, "Message size in packet: %d", size_);
break;
}
default: // subsequent bytes
{
if (bytes_ >= (size_+2)) // end byte found
{
receiving_ = false;
process_message(data_, this);
}
break;
}
}
}
}

from esphome_samsung_ac.

lanwin avatar lanwin commented on September 13, 2024

The problem with that solution is that it only works for the NASA protocol. I will try to find a more general solution next week.

from esphome_samsung_ac.

lanwin avatar lanwin commented on September 13, 2024

I now have commited a solution to that. May you have a look?

from esphome_samsung_ac.

Foxhill67 avatar Foxhill67 commented on September 13, 2024

Hi, checked for NASA protocol on my SAMSUNG heatpump and all seems to work fine, data is read correctly. So regression test wise: looks good. However, I don't think that my current data stream includes the 0x34 end byte as part of the data, so we have no 100% proof that the original issue is definitively solved. And I do not know how to manipulate the data stream to create a test case. So what shall we do with this issue, close it for now?

from esphome_samsung_ac.

lanwin avatar lanwin commented on September 13, 2024

👍🏻

from esphome_samsung_ac.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.