How to return multiple pieces of data from an RPC.call/RPC.bind

Hello everyone, I am wondering how to return multiple pieces of data from the mbed os built in RPC.bind/RPC.call functions. I have already tried to use structs but keep getting " 'const struct FOO' has no member named 'msgpack_object' ". I also dont have access to the msgpack header files or functions. Any ideas of how to return the struct? or is there something I need to add to the struct so the compiler/mbedos know what to do? Thanks! :slight_smile:

After ripping mbed code apart here is how you do it:

for an example sending a struct called "FOO":

#include "Arduino.h"
#include "RPC.h"

struct FOO{
  int i;
  int j;
  MSGPACK_DEFINE_ARRAY(i, j)
};

void setup() { 
  RPC.begin(); //Boots the M4 core
  Serial.begin(9600);
  while(!Serial){};
  if (currentCPU() == "M4") {
    startM4();
  }

  if (currentCPU() == "M7") {
    startM7();
  }
}

void loop() {

}

String currentCPU() {
  if (HAL_GetCurrentCPUID() == CM7_CPUID) {
    return "M7";
  } else {
    return "M4";
  }
}
#include "Arduino.h"
#include "RPC.h"

int i = 0;

void startM4(){
  setupM4();
  loopM4();
}

void setupM4(){
  RPC.bind("getI", getI);
}

void loopM4(){
  for(;;){
    i++;
    delay(1000);
  }
}

FOO getI(){
  FOO data;
  data.i = i;
  data.j = i+15;
  return data;
}

#include "Arduino.h"
#include "RPC.h"

void startM7() {
  setupM7();
  loopM7();
}

void setupM7() {
  
}

void loopM7() {
  for (;;) {
    delay(1000);
    long time = micros();
    auto result = RPC.call("getI").as<FOO>();
    long time2 = micros();
    Serial.println(time2 - time);
    Serial.println(result.i);
    Serial.println(result.j);
    Serial.println("");
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.