send/recv structures

Can someone tell me what im doing wrong. I have an application that uses a packet header when sending messages. I’m looking at how the person is sending the message and i tried to make my own structure and send it with the header. Its not working, I get to the part on the receiver that checks the messages and the header seem right but the values i’m receiving are not what i expected. from their code we use function writeTo to send the message like this,

struct Sequencer : public TimerInfos {
writeTo('*', this, sizeof(TimerInfos), true);
}

and the writeTo function is,

bool writeTo(byte to, const void* data, byte len, bool multi) {
  radio.stopListening();
  targetAddress[0] = to;
  radio.openWritingPipe(targetAddress);
  bool success  = radio.write(data, len, multi) || multi;
  radio.startListening();
  return success;
}

Ignore the empty display function but this is the structure pointed to by cmd,

struct Command : public Hdr {
  byte text[32 - sizeof(Hdr)];
  Command(byte from) : Hdr('!', '?', from), text("") {}
  byte setData(byte target, const char* txt) {
    to = target;
    strcpy((char*)text, txt);
    return strlen(txt) + 1 + sizeof(Hdr);
  }
  void disp() {
    Hdr::disp();

  }
};

Now on the receiving end of this its start out reading the message like this,

if (radio.available(&pipe)) {
    byte len = radio.getDynamicPayloadSize();
    radio.read(incomingData, len);
    if (showMulticast || pipe == 1) {
      Command* pCmd = (Command*)incomingData;
       //Command2* pCmd2 = (Command2*)incomingData;
      switch (pCmd->type) {
        case 'T':
          if (pipe == 1 && pCmd->isTo(*personalAddress)) {
            seq.setFrom((TimerInfos*)pCmd); //right here its setting the structure data
            ((TimerInfos*)pCmd)->disp();
            seq.disp();
          } else {
            ((TimerInfos*)pCmd)->disp();
          }
          break;

I tried to replicate that and send my own structure without success, here how i send the message,

writeTo(‘Y’, &tNewTime, sizeof(tNewTime), false);

now here the message is received,

if (radio.available(&pipe)) {
    byte len = radio.getDynamicPayloadSize();
    radio.read(incomingData, len);
    if (showMulticast || pipe == 1) {
       Command2* pCmd2 = (Command2*)incomingData;
      switch (pCmd->type) {
        case 'T':
          if (pipe == 1 && pCmd->isTo(*personalAddress)) {
           tNewTime.setFrom((updateCommands*)pCmd2); //incoming structure

          } else {
            ((TimerInfos*)pCmd)->disp();
          }
          break;

i think this subtracts the header, this is the Command2 class i made pCmds2 an object of.

struct Command2 : public Hdr {
  byte text[32 - sizeof(updateCommands)];
  Command2(byte from) : Hdr('!', '?', from), text("") {}
  byte setData(byte target, const char* txt) {
    to = target;
    strcpy((char*)text, txt);
    return strlen(txt) + 1 + sizeof(updateCommands);
  }
  void disp() {
    Hdr::disp();
    if (!Hdr::compressed) {
      Serial.print(F("text "));
    }
    Serial.write('\'');
    Serial.print((char*)text);
    Serial.println(F("'"));
  }
};

What am i doing wrong. the code is a couple files, with lots of pointers hopefully someone can recognize the problem from what i posted. If not id am will to upload all the code.

Can someone tell me what im doing wrong. I have an application that uses a packet header when sending messages. I’m looking at how the person is sending the message and i tried to make my own structure and send it with the header. Its not working, I get to the part on the receiver that checks the messages and the header seem right but the values i’m receiving are not what i expected. from their code we use function writeTo to send the message like this,

struct Sequencer : public TimerInfos {
writeTo('*', this, sizeof(TimerInfos), true);
}

and the writeTo function is,

 bool writeTo(byte to, const void* data, byte len, bool multi) {
  radio.stopListening();
  targetAddress[0] = to;
  radio.openWritingPipe(targetAddress);
  bool success  = radio.write(data, len, multi) || multi;
  radio.startListening();
  return success;
}

Ignore the empty display function but this is the structure pointed to by cmd,

struct Command : public Hdr {
  byte text[32 - sizeof(Hdr)];
  Command(byte from) : Hdr('!', '?', from), text("") {}
  byte setData(byte target, const char* txt) {
    to = target;
    strcpy((char*)text, txt);
    return strlen(txt) + 1 + sizeof(Hdr);
  }
  void disp() {
    Hdr::disp();

  }
};

Now on the receiving end of this its start out reading the message like this,

if (radio.available(&pipe)) {
    byte len = radio.getDynamicPayloadSize();
    radio.read(incomingData, len);
    if (showMulticast || pipe == 1) {
      Command* pCmd = (Command*)incomingData;
       //Command2* pCmd2 = (Command2*)incomingData;
      switch (pCmd->type) {
        case 'T':
          if (pipe == 1 && pCmd->isTo(*personalAddress)) {
            seq.setFrom((TimerInfos*)pCmd); //right here its setting the structure data
            ((TimerInfos*)pCmd)->disp();
            seq.disp();
          } else {
            ((TimerInfos*)pCmd)->disp();
          }
          break;

I tried to replicate that and send my own structure without success, here how i send the message,

writeTo(‘Y’, &tNewTime, sizeof(tNewTime), false);

now here the message is received,

if (radio.available(&pipe)) {
    byte len = radio.getDynamicPayloadSize();
    radio.read(incomingData, len);
    if (showMulticast || pipe == 1) {
       Command2* pCmd2 = (Command2*)incomingData;
      switch (pCmd->type) {
        case 'T':
          if (pipe == 1 && pCmd->isTo(*personalAddress)) {
           tNewTime.setFrom((updateCommands*)pCmd2); //incoming structure

          } else {
            ((TimerInfos*)pCmd)->disp();
          }
          break;

i think this subtracts the header, this is the Command2 class i made pCmds2 an object of.

struct Command2 : public Hdr {
  byte text[32 - sizeof(updateCommands)];
  Command2(byte from) : Hdr('!', '?', from), text("") {}
  byte setData(byte target, const char* txt) {
    to = target;
    strcpy((char*)text, txt);
    return strlen(txt) + 1 + sizeof(updateCommands);
  }
  void disp() {
    Hdr::disp();
    if (!Hdr::compressed) {
      Serial.print(F("text "));
    }
    Serial.write('\'');
    Serial.print((char*)text);
    Serial.println(F("'"));
  }
};

What am i doing wrong. the code is a couple files, with lots of pointers hopefully someone can recognize the problem from what i posted. If not i am will to upload all the code.

there is a huge thread here here that i have been working with someone but they gave up.

Might be better if you just attach your .ino file (and any other source files) so that we can see all your code in context.

It is a bit hard to figure anything out with just snippets of code.

Also why don't you describe in essence and in dot point form the data you are trying to send.

E.G. Command name: string X characters long, integer: status code.......whatever is the case

You structs are some what confusing.

program is to operate some timers and setup communication. You will notice in packetDefinitions that the structure TimerInfos is sent on a timer to the receiver. that works fine. but i need a way to send data back to the timer to update some time variables in the structure. In his program he setup some sort of header he calls it Hdr. i “think” the data is attached to the header and sent to the receiver. when data comes in its compared to see if the header matches any commands. So far it works but i cannot figure out how to send something using Hdr like he does. i would like to create another small structure i can update from the master. I tried to create the structure in both programs and send it but i cant extract the data from it on the receiving side. if you read my posts in the link i listed you’ll see me asking the same question a hundred times over. it might help get an idea of what going on here if your as confused as i am.

TimerModule_1.ino (11.2 KB)

packetDefinitions.h (24 KB)

i want to send a structure to another node,

from sender node,
struct a {
int b;
int c;
a() : b(0),c(0){}
};
radio.write(a header,&a, sizeof(a));

on the receiver side,

if (radio.available(&pipe)) {
byte len = radio.getDynamicPayloadSize();
radio.read(incomingData, len);
if (header matches '*') {
update local structure "a" with new values
}

i duplicated an already existing structure and just renamed it and removed what i could and it works,. I’m too novice to understand all of these pointers yet. why cant i create a structre outside of hdr that works like this.

struct TimerInfos3 : public Hdr {
    aTimer Timers3[2];
    TimerInfos3 (byte from) : Hdr('Y', '*', from), Timers3{  aTimer(), aTimer() } {}
    void disp() {
      Hdr::disp();
    }
    bool copyFlags(byte timerNumber, byte flags) {
      byte previous = Timers3[timerNumber].status & tiSetable;
      flags &= tiSetable;
      if (previous != flags) {
        Timers3[timerNumber].status = flags | tiUpdated;
        return true;
      }
      return false;
    }
    bool setOnTime(byte timerNumber, uint16_t value) {
      Timers3[timerNumber].onTime = value;
    }
    bool setOffTime(byte timerNumber, uint16_t value) {
      Timers3[timerNumber].offTime = value;
    }
    bool setFrom(TimerInfos3* in) {
      bool changes = false;
      for (byte i = 0; i < sizeof(Timers3) / sizeof(Timers3[0]); i++) {
        changes |= copyFlags(i, in->Timers3[i].status);
        changes |= setOnTime(i, in->Timers3[i].onTime);
        changes |= setOffTime(i, in->Timers3[i].offTime);
      }
      return changes;
       
    }
    void process2(){
      if (millis() - sometime>= 3000){
         writeTo('*', this, sizeof(TimerInfos3), true);
         sometime= millis();
      }
        
    }
};

IDK where to start