CC1101 icon indicating copy to clipboard operation
CC1101 copied to clipboard

Unable to compare/process received data

Open Siem-H opened this issue 6 years ago • 9 comments
trafficstars

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?

Siem-H avatar Feb 10 '19 18:02 Siem-H

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

SpaceTeddy avatar Feb 11 '19 12:02 SpaceTeddy

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.

Siem-H avatar Feb 11 '19 16:02 Siem-H

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

SpaceTeddy avatar Feb 12 '19 08:02 SpaceTeddy

// 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");
              }
            }
    }

Siem-H avatar Feb 12 '19 16:02 Siem-H

Which are your Sender & Receiver addresses?

SpaceTeddy avatar Feb 12 '19 17:02 SpaceTeddy

Sender is 1, received is 2

Siem-H avatar Feb 12 '19 17:02 Siem-H

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;
}

SpaceTeddy avatar Feb 14 '19 06:02 SpaceTeddy

What is 'n' in this case?

Siem-H avatar Feb 15 '19 15:02 Siem-H