Provided with the skeleton system is the outline of a module. This basically consists of an endless loop which receives command messages and processes them with a case statement. This example provides a single command which takes the data in the message, (
on mp->inpdata[]) and puts the result in an array in the shared memory (adp->adata[]). Results are sent back with the SndReplyMsg(). Note the error return of the integer 501 with the success value 0.
/* MO_CALLMOD
* Sample command. Receives a list of numbers in the data
* part of the message. Takes these numbers, multiplies them
* by 2 and stuffs the results in the shared memory segment.
* Returns an error on nsamples <= 0.
*/
case MO_CALLMOD:
if(mp->nsamples <= 0) {
printf("Bad Nsamples %d\n", mp->nsamples);
SndReplyMsg(mrfd, (void *)-501, 0, rtype);
break;
}
for(i=0; i<mp->nsamples; i++) {
printf("Value %d\n", mp->inpdata[i]);
adp->adata[i] = mp->inpdata[i] * 2;
}
adp->nsamples = mp->nsamples;
rval = 0;
SndReplyMsg(mrfd, (void *)rval, 0, rtype);
break;
Normally a module such as this would control some hardware via a device driver.