Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: kondrag_X1 en 14 Diciembre 2015, 10:36 am



Título: Ayuda para entender el código.
Publicado por: kondrag_X1 en 14 Diciembre 2015, 10:36 am
Hola estoy desarrollando una implementación de Modbus master basándome en el estándar de Freemodbus, el cual lo podeis descargar en el siguiente link -> http://www.freemodbus.org/index.php?idx=5

mi pregunta es que hay parte del código que no consigo entender.

me defino un tipo de función con typedef eMBErrorCode etc
Código
  1. /* ----------------------- Prototypes  0-------------------------------------*/
  2. typedef void    ( *pvMBFrameStart ) ( void );
  3.  
  4. typedef void    ( *pvMBFrameStop ) ( void );
  5.  
  6. typedef eMBErrorCode( *peMBFrameReceive ) ( UCHAR * pucRcvAddress,
  7.                                            UCHAR ** pucFrame,
  8.                                            USHORT * pusLength );
  9.  
  10. typedef eMBErrorCode( *peMBFrameSend ) ( UCHAR slaveAddress,
  11.                                         const UCHAR * pucFrame,
  12.                                         USHORT usLength );
  13.  
  14. typedef void( *pvMBFrameClose ) ( void );
  15.  


Luego desde la máquina de estados llamo a las funciones:

Código
  1. /* Functions pointer which are initialized in eMBInit( ). Depending on the
  2.  * mode (RTU or ASCII) the are set to the correct implementations.
  3.  */
  4. static peMBFrameSend peMBFrameSendCur;
  5. static pvMBFrameStart pvMBFrameStartCur;
  6. static pvMBFrameStop pvMBFrameStopCur;
  7. static peMBFrameReceive peMBFrameReceiveCur;
  8. static pvMBFrameClose pvMBFrameCloseCur;
  9.  
  10. eMBErrorCode
  11. eMBPoll( void ) {
  12.    static UCHAR   *ucMBFrame;
  13.    static UCHAR    ucRcvAddress;
  14.    static UCHAR    ucFunctionCode;
  15.    static USHORT   usLength;
  16.    static eMBException eException;
  17.  
  18.    int             i;
  19.    eMBErrorCode    eStatus = MB_ENOERR;
  20.    eMBEventType    eEvent;
  21.  
  22.    /* Check if the protocol stack is ready. */
  23.    if ( eMBState != STATE_ENABLED ) {
  24.        return MB_EILLSTATE;
  25.    }
  26.  
  27.    /* Check if there is a event available. If not return control to caller.
  28.      * Otherwise we will handle the event. */
  29.    if ( xMBPortEventGet( &eEvent ) == TRUE ) {
  30.        switch ( eEvent ) {
  31.            case EV_READY:
  32.                break;
  33.  
  34.            case EV_FRAME_RECEIVED:
  35.                eStatus = peMBFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
  36.                if ( eStatus == MB_ENOERR ) {
  37.                    /* Check if the frame is for us. If not ignore the frame. */
  38.                    if ( ( ucRcvAddress == ucMBAddress ) || ( ucRcvAddress == MB_ADDRESS_BROADCAST ) ) {
  39.                        ( void )xMBPortEventPost( EV_EXECUTE );
  40.                    }
  41.                }
  42.                break;
  43.  
  44.            case EV_EXECUTE:
  45.                ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
  46.                eException = MB_EX_ILLEGAL_FUNCTION;
  47.  
  48.  
  49.                for ( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ ) {
  50.                    /* No more function handlers registered. Abort. */
  51.                    if ( xFuncHandlers[i].ucFunctionCode == 0 ) {
  52.                        break;
  53.                    } else if ( xFuncHandlers[i].ucFunctionCode == ucFunctionCode ) {
  54.                        eException = xFuncHandlers[i].pxHandler( ucMBFrame, &usLength );
  55.                        break;
  56.                    }
  57.                }
  58.  
  59.                /* If the request was not sent to the broadcast address we
  60.                  * return a reply. */
  61.                if ( ucRcvAddress != MB_ADDRESS_BROADCAST ) {
  62.                    if ( eException != MB_EX_NONE ) {
  63.                        /* An exception occured. Build an error frame. */
  64.                        usLength = 0;
  65.                        ucMBFrame[usLength++] = ( UCHAR )( ucFunctionCode | MB_FUNC_ERROR );
  66.                        ucMBFrame[usLength++] = eException;
  67.                    }
  68.                    eStatus = peMBFrameSendCur( ucMBAddress, ucMBFrame, usLength );
  69.                }
  70.                break;
  71.  
  72.            case EV_FRAME_SENT:
  73.                break;
  74.        }
  75.    }
  76.    return MB_ENOERR;
  77. }
  78.  

el problema es que no encuentro la implementación de donde se trata la función peMBFrameSendCur. Alguien sabe como está estructurado el código?