Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to compare/process received data #31

Open
Siem-H opened this issue Feb 10, 2019 · 8 comments
Open

Unable to compare/process received data #31

Siem-H opened this issue Feb 10, 2019 · 8 comments

Comments

@Siem-H
Copy link

Siem-H commented Feb 10, 2019

I am trying to modify the RX_Demo to trigger a script based on the received data, but I am unable to compare the received data to anything.
I don't know how to compare the Rx_fifo buffer to a pre-set value.
I want to make a simple if comparison, e.g.

if (Rx_fifo == 0x06 0x02 0x01 0x01 0x01 0x01 0x01)

But that is clearly not the solution.
Can someone help me?

@SpaceTeddy
Copy link
Owner

Hi,
basically there are different ways to compare arrays.
you may try the function 'memcmp' function.

your compare array:
int trigger[] = {0x06, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01};

copmare with Rx_fifo:
int n=0;
n=memcmp ( trigger, Rx_fifo, sizeof(trigger) );

if the variable n is == 0, then the campare matches.

try it

@Siem-H
Copy link
Author

Siem-H commented Feb 11, 2019

It keeps not returning 0, even though it seems to match.
Does the ' | 0xF5 0xAB | ' behind the RX_FIFO matter? If it does, how do I add it to the trigger / exclude it from the compare?
I also tried comparing with std::search but that kept returning 0 even though it didn't match, I even tried to change the trigger to only contain the data (0x01, 0x01, 0x01, 0x01), but that didn't work either.

@SpaceTeddy
Copy link
Owner

SpaceTeddy commented Feb 12, 2019

yes, the last 2 bytes in the Rx_fifo are the RSSI and LQI value. These will change almost every time. Therefore you should only compare your real payload. But IMHO this is covered with sizeof(trigger). That means that only the count of bytes in trigger[] is compared.

please add your code here. thx

@Siem-H
Copy link
Author

Siem-H commented Feb 12, 2019

// Global variable
int trigger[] = {0x06, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01};

//...... (just stock stuff between these two)

    for (;;) {
            delay(1);                            //delay to reduce system load
            if (cc1100.packet_available())           //checks if a packed is available
            {
              cc1100.get_payload(Rx_fifo, pktlen, rx_addr, sender, rssi_dbm, lqi); //stores the payload data to Rx_fifo
              int n=0;
              printf("comparing ... \r\n\r\n");
              n=memcmp (trigger, Rx_fifo, sizeof(trigger));
              // n=std::search(Rx_fifo, Rx_fifo + sizeof(Rx_fifo), trigger, trigger + sizeof(trigger)) != (Rx_fifo + sizeof(Rx_fifo));
              // also tried this with int trigger[] = {0x01, 0x01, 0x01, 0x01};
              if (n == 0)
              {
                printf("YES \r\n\r\n");
              }else{
                printf("NO \r\n\r\n");
              }
            }
    }

@SpaceTeddy
Copy link
Owner

Which are your Sender & Receiver addresses?

@Siem-H
Copy link
Author

Siem-H commented Feb 12, 2019

Sender is 1, received is 2

@SpaceTeddy
Copy link
Owner

SpaceTeddy commented Feb 14, 2019

you can also do:

int compareArrays(int a[], int b[], int n)
{
  for (int i=0; i<n; ++i)
  {
      if (a[i] != b[i])
      {
          return -1;
          break;
      }
  }
  return 0;
}

@Siem-H
Copy link
Author

Siem-H commented Feb 15, 2019

What is 'n' in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants