help with pointers

Hello all.

i have been able to figure out how to capture incoming serial data and store it into an array for controlling functions. But I am now working with a radio module that recieves incoming data and stores it into a uint_8t.

from there in the basic sketch that the radio library came with it is printed in the serial terminal like this:
1
2
3
4
5
6
7
8
9
10
uint8_t buf[RF22_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if (rf22.waitAvailableTimeout(500))
    { 
      // Should be a message for us now   
      if (rf22.recv(buf, &len))
      {
        Serial.print("got reply: ");
        Serial.println((char*)buf);


I have read a lot of tutorials on pointers, and I am just having a very hard time grasping how to extract data out of one. I realize this is char and not integers.
The goal is to transmit five integers in a digital state of either 1 or 0, and then store them in the receiving side and control 5 outputs based on the status of those 5 bits. This is proving to be quite confusing for me though as I cannot seem to grasp how to control the pointer logic
I realize this is char and not integers.
You need to send/receive the data as bytes (chars) irrespective of what they actually are. The process is called serialisation.

The goal is to transmit five integers in a digital state of either 1 or 0, and then store them in the receiving side
Ok. So recv should get 5 integers back, i.e. 5*sizeof(int). You should expect that 5*sizeof(int) <= RF22_MAX_MESSAGE_LEN.

The data will be 5 integers, so we use a cast to override the language's type system as we know better.
 
int* data = (int*)buf;

Then you can index into it to get the 5 elements.
1
2
for (int i = 0; i < 5; ++i)
     std::cout << data[i] << std::endl;
Topic archived. No new replies allowed.