Storyboard IO with multiple data arguments

Questions and information about Crank Software's Storyboard Engine

Moderator: jamiev

Storyboard IO with multiple data arguments

Postby jason » Thu Mar 31, 2011 12:35 pm

If you want to send a Storyboard IO message to an external application with more than 1 argument you'll need to do this through Lua. The function you should look at is the gre.send_event_data(). Here is a simple example of a Lua function that is sending multiple arguments of different types in a single message to an external program .

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.
User avatar
jason
 
Posts: 148
Joined: Mon Nov 02, 2009 4:53 pm

Re: Storyboard IO with multiple data arguments

Postby Pascal » Wed May 02, 2012 9:23 am

Hello Jason,

I've tried to repeat the same process for my code:

Storyboard
Code: Select all
local format = "4u1 DataType 4u1 StartTimestamp 4u1 StopTimestamp 4u1 Count"
local trend_request_data = {}
      
trend_request_data["DataType"] = 4
trend_request_data["StartTimestamp"] = 0
trend_request_data["StopTimestamp"] = 10
trend_request_data["Count"] = 11
   
print("Sending a trend request for " .. trend_request_data["Count"] .. " points of type " .. trend_request_data["DataType"])
print(" [" .. trend_request_data["StartTimestamp"] .. ", " .. trend_request_data["StopTimestamp"] .. "]")
gre.send_event_data("GUI_GET_TREND_DATA", format, trend_request_data, "GUI_Out")


C++
Code: Select all
// GUI_GET_TREND_DATA
struct CS_GuiGetTrendData
{
    uint32_t/*uint8_t*/ DataType; // uint8_t was from a previous try, wthat didn't succeed
    uint32_t/*uint64_t*/ StartTimestamp;
    uint32_t/*uint64_t*/ StopTimestamp;
    uint32_t/*uint16_t*/ Count;
};

[...]

rc = gre_io_receive(m_ServerHandle, &pBuffer);
iDataSize = gre_io_unserialize(pBuffer, &pTarget, &pName, &pFormat, (void **)&pData);
printf("gre_io_receive: Received : %s, %s, %s\n", pName, pData, pFormat);

std::cout << "MessageQueue:CS_GUI_GET_TREND_DATA " <<
                    ((CS_GuiGetTrendData*)pBuffer)->DataType << ", " <<
                    ((CS_GuiGetTrendData*)pBuffer)->Count << " " <<
                    ((CS_GuiGetTrendData*)pBuffer)->StartTimestamp << " " <<
                    ((CS_GuiGetTrendData*)pBuffer)->StopTimestamp << " " <<
                    std::endl;
[...]


It actually doesn't work as well as it should... here is the output:
Storyboard
Sending a trend request for 11 points of type 4
[0, 10]

That's fine

C++
gre_io_receive: Received : GUI_GET_TREND_DATA, , 4u1 DataType 4u1 StartTimestamp 4u1 StopTimestamp 4u1 Count
MessageQueue:CS_GUI_GET_TREND_DATA 1310744, 0 51200 108

As you seem the first print shows empty pData, and the second print shows..well.. incorrect data.

Any idea on where I should look for a problem? (Storyboard or C++ side?)

Thanks,
Pascal
User avatar
Pascal
 
Posts: 5
Joined: Wed May 02, 2012 7:37 am

Re: Storyboard IO with multiple data arguments

Postby thomas » Wed May 02, 2012 9:44 am

Pascal,

I think that you are printing out the wrong values. You are printing out values from the raw buffer (pBuffer) rather than the values
from your own data structure (pData). If you change that then you should get better results.

Thomas
thomas
 
Posts: 91
Joined: Mon Nov 02, 2009 4:32 pm
Location: Ottawa

Re: Storyboard IO with multiple data arguments

Postby Pascal » Wed May 02, 2012 9:59 am

Hi Thomas,

Well, I thought this one would be a tougher one...
It works fine, thanks!

Pascal
Last edited by Pascal on Fri May 04, 2012 8:43 am, edited 1 time in total.
User avatar
Pascal
 
Posts: 5
Joined: Wed May 02, 2012 7:37 am

Re: Storyboard IO with multiple data arguments

Postby Pascal » Fri May 04, 2012 8:42 am

(There was an edit of the message you may have missed, let me put it here instead)

By the way, are they any limitations for the size or the format of the data sent with gre.send_event_data? (are 8u1 fine? is a "package " {1u1, 8u1, 8u1, 2u1} fine?)
User avatar
Pascal
 
Posts: 5
Joined: Wed May 02, 2012 7:37 am

Re: Storyboard IO with multiple data arguments

Postby jason » Sat May 05, 2012 11:13 am

As a number space we can't actually represent it's full range since we convert to either integers or doubles, but as a payload it should be fine.

However, your structure isn't aligned in this example. You'd want be like this "8u1, 8u1, 2u1, 2u1, 2u1, 1u1, 1u1" for proper alignment.
User avatar
jason
 
Posts: 148
Joined: Mon Nov 02, 2009 4:53 pm


Return to Storyboard Engine

Who is online

Users browsing this forum: No registered users and 1 guest