UserHooks

This subdirectory is defined by the userhooksdir keyword in the /etc/ccursim.conf file and contains source and libraries for the functions that can be called by the CAN I/O task for pre- and post- processing of the CAN Id messages.

The libraries must be created as Linux shared (.so libraries) and be placed in the lib subdirectory of this directory.

Preprocessing applies to input CAN messages and postprocessing to output messages. This gives the user the ability of altering raw messages before they are processed by SimWB on output and after the raw output message has been assembled and just before it is transmitted by the hardware.

In this case, the I/O hooks are configured by creating a file in the corresponding RTDB folder. The name of the file is specific to the type of CAN I/O board for which the user hooks code is to be defined.

where x is the board number - starting at 1 .

The format of the file is as follows:

canid=x,netnum=y,library=libname,setuproutine=setupname,inputroutine=inputname

canid=x,netnum=y,library=libname,setuproutine=setupname,outputroutine=outputname

Different processing routines can thus be defined for different CANID's or different channel numbers (netnum).

canid

the CAN id  to pass the specified routine. The routine is only called when the specified CAN is received or transmitted. Set this to -1 if you want to process all the CAN id on that channel (netnum).

netnum

The board network number (channel) on which to process the CAN id.

library

The name of the .so library where the routine is defined. By default , this file is in /usr/local/ccursim/UserHooks/lib/

setuproutine

The name of the routine that has to be called at initialization time for this CAN id. This is where you would performed initialization of your own code with the library. If this entry does not exist, a setup routine is not called.

onputroutine

The name of the routine to call to process an input CAN id messaged.

outputroutine

The name of the routine to call to process an output CAN id message.

The prototype for the 3 types of routine must be as follows:

int setup(
         int boardnum, /* The board number for which this is called. */
         int netnum,     /* The board net number */
         int netnum,     /* The board net number */
         int canid,        /*The cCAN id */
         int ioflags,
         RTDBItemPair *pointList, /* Definition of the RTDB items mapped to this CAN id*/
         int pointCount); /* Number of point in the list above */
 

int input(
         int boardnum, /* The board number for which this is called. */
         int netnum,     /* The board net number */
         int canid,        /*The cCAN id */
         unsigned char *buffer, /* Pointer to the data buffer as received by the hardware */
         int length);     /* The number of bytes in the buffer */
 

int output(
          int boardnum, /* The board number for which this is called. */
          int netnum,     /* The board net number */
          int canid,        /* The CAN id */
          unsigned char *buffer, /* Pointer to the data buffer that will be sent after this call returns */
          int length);     /* The number of bytes in the buffer */

Your user input and output routines could modify the data buffer to insert a calculated CRC byte or to check the CRC on reception, for instance.