elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Ayuda para entender el código.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda para entender el código.  (Leído 1,580 veces)
kondrag_X1

Desconectado Desconectado

Mensajes: 157


Ver Perfil
Ayuda para entender el código.
« 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?


« Última modificación: 14 Diciembre 2015, 10:58 am por kondrag_X1 » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[AYUDA] Necesito entender el código - C++
Programación C/C++
Alape04 1 1,505 Último mensaje 21 Octubre 2016, 05:27 am
por palacio29
Ayuda a entender este código
Programación C/C++
Bastiannjs 1 2,062 Último mensaje 7 Septiembre 2017, 20:11 pm
por ivancea96
Ayudemne solo a entender un código por favor
Programación C/C++
piyor6 4 1,971 Último mensaje 5 Junio 2018, 17:19 pm
por DarK_FirefoX
Linea de código dificil de entender
Programación C/C++
Skali 9 2,962 Último mensaje 4 Julio 2018, 14:30 pm
por srWhiteSkull
Problemas para entender un codigo
Programación C/C++
DanteS00 0 1,287 Último mensaje 9 Julio 2018, 22:41 pm
por DanteS00
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines