Skip navigation.
Home
The QNX Community Portal

View topic - How to pass data from driver to Application??

How to pass data from driver to Application??

For discussion of realtime and/or embedded programming.

How to pass data from driver to Application??

Postby garyritu » Thu Jul 02, 2009 3:04 pm

Hi All,
I have an issue for devctl function. My client application needs the some data from a driver. So i started to do some R&d on it. I have implemented my own custom devctl function and replaced in the resource manager.

But i am unable to get correct values passed from driver to application. Please help me out to understand more on devctl functionality.

Please have a look on my driver code.

int
custom_devctl(resmgr_context_t *ctp, io_devctl_t *msg, RESMGR_OCB_T *ocb)
{
int nbytes=0, status=0;
typedef union devctl_msg
{
int tx; //Filled by client on send
int rx; //Filled by server on reply
char errorString[512];
} data_t;

union
{
data_t data;
int data32;
}*rx_data;

if ((status = iofunc_devctl_default(ctp, msg, ocb)) != _RESMGR_DEFAULT)
{
return(status);
}

/*
Note this assumes that you can fit the entire data portion of
the devctl into one message. */

rx_data = _DEVCTL_DATA(msg->i);

switch (msg->i.dcmd)
{
case DEVCTL_DSCGETERRORSTRING:

printf("\n DEVCTL_DSCGETERRORSTRING command came");
rx_data->data.rx = 10; // Testing data

strcpy(rx_data->data.errorString,"Some Error came");
nbytes = sizeof(rx_data->data.errorString);

// return data to the client
memset(&msg->o,0,sizeof(msg->o));
msg->o.nbytes = nbytes;

SETIOV (ctp -> iov, &msg -> o, sizeof (msg -> o) + nbytes);
return (_RESMGR_NPARTS (2));
break;

default:
printf ("command unknown \n" );

}
return( _RESMGR_PTR(ctp, &msg->o, sizeof(msg->o) + nbytes));

}


On application side, i am getting correct string under rx_data->data.errorString but rx_data->data.rx is coming as wrong value(15645345).
It would be better, if i get good link on devctl for passing data.
garyritu
Active Member
 
Posts: 58
Joined: Fri May 22, 2009 7:09 am

Postby Tim » Thu Jul 02, 2009 4:57 pm

Garyritu,

This union

typedef union devctl_msg
{
int tx; //Filled by client on send
int rx; //Filled by server on reply
char errorString[512];
} data_t;

means that you can either have

rx_data->data.rx = 10; // Testing data

OR

strcpy(rx_data->data.errorString,"Some Error came");

but not both. The strcpy is over writing the rx variable because there is only 512 bytes in the union, not 512 + 2 int's. You want a struct not a union.

Tim
Tim
Senior Member
 
Posts: 1388
Joined: Wed Mar 10, 2004 12:28 am

Postby mario » Thu Jul 02, 2009 6:55 pm

Or if applicable you can implement support for read() instead of using ioctl(). If read() is already used for other type of data, you could setup a different mount point, something like /dev/xxx_log or /dev/xxx/log.

I always favor that option because ioctl are hard to do from a shell ;-)
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 2 guests

cron