//------------------------------------------------------------------------------
static tOplkError eventCbPowerlink(tOplkApiEventType EventType_p,
                                   tOplkApiEventArg* pEventArg_p, void* pUserArg_p)
{
    tOplkError                      ret = kErrorOk;
    tOplkApiEventReceivedNonPlk*    pFrameInfo = &pEventArg_p->receivedEth;

    UNUSED_PARAMETER(pUserArg_p);

    switch (EventType_p)
    {
        case kOplkApiEventNmtStateChange:
            lcd_printNmtState(pEventArg_p->nmtStateChange.newNmtState);

            switch (pEventArg_p->nmtStateChange.newNmtState)
            {
                case kNmtGsOff:
                    // NMT state machine was shut down
                    ret = kErrorShutdown;

                    // NMT off state is reached
                    instance_l.fGsOff = TRUE;
                    break;

                case kNmtCsBasicEthernet:
                    // ARP demo: Send request to MN
                    arp_sendRequest((0xFFFFFF00 & IP_ADDR) | C_ADR_MN_DEF_NODE_ID);
                    break;

                default:
                    break;
            }
            break;

        case kOplkApiEventReceivedNonPlk:
            if (arp_processReceive(pFrameInfo->pFrame, pFrameInfo->frameSize) == 0)
                return kErrorOk;

            // If you get here, the received Ethernet frame is no ARP frame.
            // Here you can call other protocol stacks for processing.

            ret = kErrorOk; // Frame wasn't processed, so simply dump it.
            break;

        case kOplkApiEventDefaultGwChange:
            // ARP demo: Set default gateway and send request
            arp_setDefGateway(pEventArg_p->defaultGwChange.defaultGateway);

            arp_sendRequest(pEventArg_p->defaultGwChange.defaultGateway);
            break;

        default:
            break;
    }
    return ret;
}
//------------------------------------------------------------------------------
static tOplkError eventCbPowerlink(tOplkApiEventType EventType_p,
                                   tOplkApiEventArg* pEventArg_p, void* pUserArg_p)
{
    tOplkError ret = kErrorOk;

    UNUSED_PARAMETER(pUserArg_p);

    // Handle ARP demo:
    // - If a node is found (e.g. plug in a CN), then an ARP request is sent
    //   to this node. There is no timeout handling done.
    // - If an Ethernet frame is received, it is forwarded to process reply.
    //   The function prints the ARP reply information.
    if (EventType_p == kOplkApiEventNode)
    {
        tOplkApiEventNode* pNode = &pEventArg_p->nodeEvent;

        // Note: This is a demonstration to generate non-POWERLINK frames.
        if (pNode->nodeEvent == kNmtNodeEventFound)
        {
            arp_sendRequest((0xFFFFFF00 & IP_ADDR) | pNode->nodeId);
        }
    }
    else if (EventType_p == kOplkApiEventReceivedNonPlk)
    {
        tOplkApiEventReceivedNonPlk* pFrameInfo = &pEventArg_p->receivedEth;

        // Note: This is a demonstration how to forward Ethernet frames to upper
        //       layers. Instead you can insert an IP stack and forward the
        //       pFrameInfo content to it. Frames that are sent from the IP
        //       stack to lower layers must be forwarded with the function
        //       \ref oplk_sendEthFrame.

        // Forward received frame to ARP processing
        if (arp_processReceive(pFrameInfo->pFrame, pFrameInfo->frameSize) == 0)
            return kErrorOk;

        // If you get here, the received Ethernet frame is no ARP frame.
        // Here you can call other protocol stacks for processing.

        ret = kErrorOk; // Frame wasn't processed, so simply dump it.
    }
    else if (EventType_p == kOplkApiEventDefaultGwChange)
    {
        // ARP demo: Set default gateway and send request
        arp_setDefGateway(pEventArg_p->defaultGwChange.defaultGateway);

        arp_sendRequest(pEventArg_p->defaultGwChange.defaultGateway);
    }

    return ret;
}
Example #3
0
//------------------------------------------------------------------------------
static tOplkError eventCbPowerlink(tOplkApiEventType eventType_p,
                                   tOplkApiEventArg* pEventArg_p, void* pUserArg_p)
{
    tOplkError                      ret = kErrorOk;
    tOplkApiEventReceivedNonPlk*    pFrameInfo = &pEventArg_p->receivedEth;

    UNUSED_PARAMETER(pUserArg_p);

    switch (eventType_p)
    {
        case kOplkApiEventNmtStateChange:
            lcd_printNmtState(pEventArg_p->nmtStateChange.newNmtState);

            switch (pEventArg_p->nmtStateChange.newNmtState)
            {
                case kNmtGsOff:
                    // NMT state machine was shut down
                    ret = kErrorShutdown;

                    // NMT off state is reached
                    instance_l.fGsOff = TRUE;
                    break;

                case kNmtCsBasicEthernet:
                    // ARP demo: Send request to MN
                    arp_sendRequest((0xFFFFFF00 & IP_ADDR) | C_ADR_MN_DEF_NODE_ID);
                    break;

                case kNmtCsPreOperational2:
                     // automatic change to kEplNmtCsReadyToOperate can be
                     // prevented with:
                     // ret = kErrorReject;
                     // As soon as application is ready for OPERATIONAL state,
                     // execute the following function call:
                     // oplk_execNmtCommand(kNmtEventEnterReadyToOperate);
                     break;

                default:
                    break;
            }
            break;

        case kOplkApiEventReceivedNonPlk:
            if (arp_processReceive(pFrameInfo->pFrame, pFrameInfo->frameSize) == 0)
                return kErrorOk;

            // If you get here, the received Ethernet frame is no ARP frame.
            // Here you can call other protocol stacks for processing.

            ret = kErrorOk; // Frame wasn't processed, so simply dump it.
            break;

        case kOplkApiEventDefaultGwChange:
            // ARP demo: Set default gateway and send request
            arp_setDefGateway(pEventArg_p->defaultGwChange.defaultGateway);

            arp_sendRequest(pEventArg_p->defaultGwChange.defaultGateway);
            break;

        default:
            break;
    }
    return ret;
}