- Code: Select all
function greio_send(mapargs)
local format = "4u1 uint32 2s1 int16 1u1 uint8 1s1 int8 1s0 string"
local data = {}
data["uint32"] = 32
data["int16"] = -16
data["uint8"] = 8
data["int8"] = -8
data["string"] = "Crank Rules!"
gre.send_event_data("MyEvent", format, data, "/tmp/test")
end
The key to this working is that in the embedded C/C++ process they will need to create a structure that matches this format string in order to interpret the data. Like this
- Code: Select all
//"4u1 uint32 2s1 int16 1u1 uint8 1s1 int8 1s0 string"
struct data{
uint32_t uint32num;
int16_t int16num;
uint8_t uint8num;
int8_t int8num;
char str;
}data_t;
Now inside you code you receive this message as usual and use a pointer to this structure to interpret the data
- Code: Select all
struct data * my_data;
.
.
.
.
ret = gre_io_receive(recv_handle, &buffer);
if(ret < 0) {
printf("Problem receiving data on channel\n");
break;
}
rnbytes = gre_io_unserialize(buffer, &revent_target, &revent_name, &revent_format, (void **)&revent_data);
my_data = (struct data * )revent_data;
printf("uint32num = %d\n",my_data->uint32num);
printf("int16num = %d\n",my_data->int16num);
printf("uint8num = %d\n",my_data->uint8num);
printf("int8num = %d\n",my_data->int8num);
printf("str = %s\n",&my_data->str);
Also make sure to be aware of structure alignment when setting up you messages.
