Beispiel #1
0
//------------------------------------------------------------------------------
static BOOL getCnNmtRequest(tDllReqServiceId* pReqServiceId_p, UINT* pNodeId_p)
{
    tCircBufError   err;
    UINT            rxNodeId;
    size_t          size = sizeof(rxNodeId);

    // next queue will be MnGenReq queue
    instance_l.nextRequestQueue = 2;

    err = circbuf_readData(instance_l.pQueueCnRequestNmt, &rxNodeId, size, &size);

    switch (err)
    {
        case kCircBufOk:
            if (instance_l.aCnRequestCntNmt[rxNodeId-1] > 0)
            {
                *pNodeId_p = rxNodeId;
                *pReqServiceId_p = kDllReqServiceNmtRequest;
                // dllkcal_ackAsyncRequest() will decrement the request count!

                return TRUE;
            }
            // fall-trough

        case kCircBufNoReadableData:
        default:
            // an empty or faulty queue has no requests
            return FALSE;
    }
}
//------------------------------------------------------------------------------
static tOplkError getDataBlock(tDllCalQueueInstance pDllCalQueue_p,
                               BYTE* pData_p, UINT* pDataSize_p)
{
    tOplkError              ret = kErrorOk;
    tCircBufError           error;
    tDllCalCircBufInstance* pDllCalCircBufInstance =
                                            (tDllCalCircBufInstance*)pDllCalQueue_p;
    size_t                  actualDataSize;

    if (pDllCalCircBufInstance == NULL)
    {
        ret = kErrorInvalidInstanceParam;
        goto Exit;
    }

    error = circbuf_readData(pDllCalCircBufInstance->pCircBufInstance, pData_p,
                             (size_t)*pDataSize_p, &actualDataSize);
    if (error != kCircBufOk)
    {
        if (error == kCircBufNoReadableData)
        {
            ret = kErrorDllAsyncTxBufferEmpty;
        }
        else
        {
            ret = kErrorNoResource;
        }
        goto Exit;
    }

    *pDataSize_p = (UINT)actualDataSize;

Exit:
    return ret;
}
Beispiel #3
0
//------------------------------------------------------------------------------
static BOOL getMnStatusRequest(tDllReqServiceId* pReqServiceId_p, UINT* pNodeId_p)
{
    tCircBufError   err;
    UINT            rxNodeId;
    size_t          size = sizeof(rxNodeId);

    // next queue will be MnSyncReq queue
    instance_l.nextRequestQueue = 5;
    err = circbuf_readData(instance_l.pQueueStatusReq, &rxNodeId, size, &size);

    if (err == kCircBufOk)
    {   // queue is not empty
        *pNodeId_p = rxNodeId;
        *pReqServiceId_p = kDllReqServiceStatus;
        return TRUE;
    }
    return FALSE;
}
//------------------------------------------------------------------------------
static tOplkError getDataBlock(tDllCalQueueInstance pDllCalQueue_p,
                               UINT8* pData_p,
                               UINT* pDataSize_p)
{
    tOplkError              ret = kErrorOk;
    tCircBufError           error;
    tDllCalCircBufInstance* pDllCalCircBufInstance =
                                (tDllCalCircBufInstance*)pDllCalQueue_p;
    size_t                  actualDataSize;

    // Check parameter validity
    ASSERT(pData_p != NULL);
    ASSERT(pDataSize_p != NULL);

    if (pDllCalCircBufInstance == NULL)
    {
        ret = kErrorInvalidInstanceParam;
        goto Exit;
    }

    error = circbuf_readData(pDllCalCircBufInstance->pCircBufInstance,
                             (void*)pData_p,
                             (ULONG)*pDataSize_p,
                             &actualDataSize);
    if (error != kCircBufOk)
    {
        if (error == kCircBufNoReadableData)
            ret = kErrorDllAsyncTxBufferEmpty;
        else
            ret = kErrorNoResource;
        goto Exit;
    }

    *pDataSize_p = (UINT)actualDataSize;

Exit:
    return ret;
}
//------------------------------------------------------------------------------
tOplkError sdotestcom_cbEvent(tEvent* pOplkEvent_p)
{
    tOplkError               ret;
    tOplkError               Sequret;
    tSdoTestComCon*          pCmdCon;
    tPlkFrame*               pFrame;
    tCircBufError            Cbret;
    ULONG                    ulDataSize;
    size_t                   size_p;
    size_t                   FrameSize;

    ret         = kErrorOk;
    pFrame      = NULL;
    FrameSize   = C_DLL_MAX_ASYNC_MTU;
    size_p      = 0x00;
    ulDataSize  = 0x00;

    switch (pOplkEvent_p->eventType)
    {
        case kEventTypeSdoAsySend:

            // Check parameter
            if (sizeof(*pCmdCon) == pOplkEvent_p->eventArgSize)
            {
                pCmdCon = (tSdoTestComCon*)pOplkEvent_p->pEventArg;
            }
            else
            {
                ret = kErrorSdoComInvalidParam;
                goto Exit;
            }

            pFrame = (tPlkFrame*)OPLK_MALLOC(FrameSize);

            if (pFrame == NULL)
            {
                ret = kErrorNoResource;
                goto Exit;
            }

            // Send all frames in that are currently in the shared buffer
            do
            {
                OPLK_MEMSET(pFrame, 0, FrameSize);

                Cbret = circbuf_readData(pCmdCon->pCbBufInst,
                                         pFrame, size_p,
                                         &FrameSize);

                if ((kCircBufOk == Cbret) &&
                    (ulDataSize > PLK_FRAME_OFFSET_SDO_COMU))
                {
                    Sequret = sdoseq_sendData(pCmdCon->tSeqHdl,
                                              ulDataSize - PLK_FRAME_OFFSET_SDO_COMU,
                                              pFrame);

                    // Send all frames, but return error code if any frame fails
                    if (Sequret != kErrorOk)
                    {
                        ret = Sequret;
                    }
                }
            }
            while (Cbret == kCircBufOk);

            // kShbNoReadableData would be the only error free condition
            // for the preceding loop to end
            if (kCircBufNoReadableData != Cbret)
            {
                ret = kErrorInvalidOperation;
            }
            break;

        default:

            // Reject unknown events
            ret = kErrorInvalidOperation;
            break;
    }

Exit:
    if (pFrame != NULL)
    {
        OPLK_FREE(pFrame);
    }

    return ret;
}