/*devctl command*/ typedef enum { CMD_READ = __DIOTF(_DCMD_MISC, 1, Data_st), /*selection of read*/ }DevCtlCmd_et; /*different channels*/ typedef enum { CH_SELCTION_00, /*channel 1*/ CH_SELCTION_01, /*channel 2*/ }ChSelection_et; /*structure containing data and chanel information*/ typedef struct{ int iData; ChSelection_et etChSelectionInfo; }Data_st; /*##### CLIENT APPLICATION PROCESS #####*/ int ReadCh01Data(Data_st * pstData) { int iRet; int iFileDes; iFileDes = 0; pstData->iData = 0; pstData->etChSelectionInfo = CH_SELCTION_01; iFileDes = open("", (O_CREAT), (S_IRUSR | S_IRGRP | S_IROTH)); if(iFileDes > 0) { iRet = devctl(iFileDes, CMD_READ, (void *)pstData, (size_t)sizeof(*pstData ), NULL); if(iRet == 0) { printf("\nData Read : %xn", pstData->iData); /*## NO DATA IS RECEIVED FROM THE CLIENT APPLICATION, 0x0 IS PRINTED INSTEAD OF 0x89abcdef ##*/ } } return (iRet); } /*##### SERVER APPLICATION PROCESS #####*/ static sint Custom_Devctl (resmgr_context_t *ctp, io_devctl_t *msg, RESMGR_OCB_T *ocb) { /*return value*/ int etRetValue; /*local variables to store Devctl command type*/ DevCtlCmd_et etDevctlCmmdType; /*local data*/ static Data_st stData; etRetValue = 0; etDevctlCmmdType = CMD_MAX; /*initialize the local data with 0 using memset*/ (void)memset((void *)&stData, 0, (size_t)sizeof(stData)); /*invoke iofunc_devctl_default to set all the attributes as default*/ etRetValue = iofunc_devctl_default(ctp, msg, ocb); /*check if return value of iofunc_devctl_default is _RESMGR_DEFAULT or not*/ if (etRetValue == _RESMGR_DEFAULT) { /*Store the Devctl command type into the local variables*/ etDevctlCmmdType = msg->i.dcmd; /*check the type of command being sent using devctl()*/ switch(etDevctlCmmdType) { /*if the command is CMD_READ*/ case CMD_READ: { /*get the data being sent using devctl into local instance using memcpy*/ (void)memcpy((void *)&stData, _DEVCTL_DATA (msg->i), (size_t) sizeof(stData)); /*check the type of data requested*/ switch(stData.etChSelectionInfo) { /*if the data requested from channel CH_SELCTION_00*/ case CH_SELCTION_00: { etRetValue = -1; /*break statement*/ break; } /*if the data requested from channel CH_SELCTION_01*/ case CH_SELCTION_01: { /*set the data as 0x89abcdef*/ stData.iData = 0x89abcdef; break; } /*else the default case*/ default: { etRetValue = -2; break; } } /*set the return value for devctl*/ msg->o.ret_val = etRetValue; /*check if return value indicates success or not*/ if(etRetValue == 0) { /*set the size of data for the reply structure of for devctl*/ msg->o.nbytes= sizeof(stData); /*get the data being sent using devctl into local instance using memcpy*/ (void)memcpy((void *)_DEVCTL_DATA (msg->o), (void *) &stData, (size_t)msg->o.nbytes); /*## DATA IS FILLED IN THE MEMORY LOCATION AFTER THE UNION OF TYPE "io_devctl_t" ##*/ } /*if return value indicates failure*/ else { /*do nothing*/ } /*fill the I/O vector of resmgr_context_t with the data to be returned to the client*/ return(_RESMGR_PTR(ctp, _DEVCTL_DATA(msg->o), sizeof(stData))); /*## DATA IS FILLED IN THE IO VECTOR AND RETURNED TO THE CLIENT ##*/ break; } /*else the default case*/ default: { etRetValue = -3; break; } } } /*if return value of iofunc_devctl_default is not _RESMGR_DEFAULT*/ else { etRetValue = -4; } /*return value*/ return (etRetValue); }