Ejemplo n.º 1
0
/**
* \brief         Processing of the received packets from bus
* \param[in]     XLevent& xlEvent message polled from the bus in XLevent format
* \param[in]     unClientIndex is the client index
* \return        void
* \authors       Arunkumar Karri
* \date          07.10.2011 Created
*/
void CDIL_LIN_VectorXL::ProcessLINMsg(XLevent& xlEvent)
{
    if ( S_OK == bClassifyMsgType(xlEvent, sg_asLINMsg) )
    {
        vWriteIntoClientsBuffer(sg_asLINMsg);
    }
}
Ejemplo n.º 2
0
// RxD Event-Funktion
static void CALLBACK_TYPE CanRxEvent(uint32_t index, struct TCanMsg* msg, int32_t count)
{
    (void)index;
    static STCANDATA can_data;
    can_data.m_uDataInfo.m_sCANMsg.m_bCANFD = false;

    for (; count; count--)
    {
        EnterCriticalSection(&sg_DIL_CriticalSection);

        can_data.m_uDataInfo.m_sCANMsg.m_ucChannel = 1;
        can_data.m_uDataInfo.m_sCANMsg.m_unMsgID = msg->Id;
        can_data.m_uDataInfo.m_sCANMsg.m_ucDataLen = msg->MsgLen;
        can_data.m_uDataInfo.m_sCANMsg.m_ucEXTENDED = msg->MsgEFF;
        can_data.m_uDataInfo.m_sCANMsg.m_ucRTR = msg->MsgRTR;
        if (msg->MsgTxD)
        {
            can_data.m_ucDataType = TX_FLAG;
        }
        else
        {
            can_data.m_ucDataType = RX_FLAG;
        }
        //can_data.m_lTickCount.QuadPart = (LONGLONG)(msg->TimeStamp);
        memcpy(can_data.m_uDataInfo.m_sCANMsg.m_ucData, msg->MsgData, 8);

        //Write the msg into registered client's buffer
        vWriteIntoClientsBuffer(can_data);
        LeaveCriticalSection(&sg_DIL_CriticalSection);
        msg++;
    }
}
Ejemplo n.º 3
0
/**
* \brief         Processing of the received packets from bus
* \param[in]     LinMessageInfo msgInf message polled from the bus in LinMessageInfo format
* \param[in]     unClientIndex is the client index
* \return        void
* \authors       [email protected]
* \date          05.29.2015 Created
*/
void CDIL_LIN_Kvaser::ProcessLINMsg(LinMessageInfo msgInf,unsigned char* msg,unsigned int flags,unsigned int len,unsigned int id,int chnindex)
{
    if ( S_OK == bClassifyMsgType(&msgInf, sg_asLINMsg,msg,flags,len,id, chnindex) )
    {
        vWriteIntoClientsBuffer(sg_asLINMsg);
    }
}
Ejemplo n.º 4
0
/**
* @brief         Sends STCAN_MSG structure from the client dwClientID.
* @param[in]     dwClientID is the client ID
* @param[in]     sMessage is the application specific CAN message structure
* @return        S_OK for success, S_FALSE for failure
*/
HRESULT CDIL_CAN_VSCOM::sendMessage(DWORD dwClientID, const STCAN_MSG& sMessage)
{
    VSCAN_MSG msg;
    DWORD dwTemp;
    static SACK_MAP sAckMap;
    HRESULT hResult;

    VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_CONNECTED, ERR_IMPROPER_STATE);

    hResult = S_FALSE;
    if (bClientIdExist(dwClientID))
    {
        if (sMessage.m_ucChannel <= sg_nNoOfChannels)
        {
            memset(&msg, 0, sizeof(msg));

            if (sMessage.m_ucEXTENDED == 1)
            {
                msg.Flags |= VSCAN_FLAGS_EXTENDED;
            }
            if (sMessage.m_ucRTR == 1)
            {
                msg.Flags |= VSCAN_FLAGS_REMOTE;
            }
            msg.Id = sMessage.m_unMsgID;
            msg.Size = sMessage.m_ucDataLen;
            memcpy(msg.Data, &sMessage.m_ucData, msg.Size);
            sAckMap.m_ClientID = dwClientID;
            sAckMap.m_Channel  = sMessage.m_ucChannel;
            sAckMap.m_MsgID    = msg.Id;
            vMarkEntryIntoMap(sAckMap);
            if (VSCAN_Write(sg_VSCanCfg.hCan, &msg, 1, &dwTemp) == VSCAN_ERR_OK && dwTemp == 1)
            {
                static STCANDATA can_data;
                CopyMsg2CanData(&can_data, &msg, TX_FLAG);
                EnterCriticalSection(&sg_DIL_CriticalSection);
                //Write the msg into registered client's buffer
                vWriteIntoClientsBuffer(can_data);
                LeaveCriticalSection(&sg_DIL_CriticalSection);
                hResult = S_OK;
            }
            else
            {
                hResult = S_FALSE;
                sg_pIlog->logMessage(A2T(__FILE__), __LINE__, _("could not write can data into bus"));
            }
        }
        else
        {
            hResult = ERR_INVALID_CHANNEL;
        }
    }
    else
    {
        hResult = ERR_NO_CLIENT_EXIST;
    }
    return(hResult);
}
Ejemplo n.º 5
0
// RxD Event-Funktion
static DWORD WINAPI CanRxEvent(LPVOID /*lpParam*/)
{
    static STCANDATA can_data;
    can_data.m_uDataInfo.m_sCANMsg.m_bCANFD = false;
    DWORD dwTemp;
    VSCAN_MSG msg;

    for (;;)
    {
        if (WaitForSingleObject(sg_hEventRecv, INFINITE) == WAIT_OBJECT_0)
        {
            for (;;)
            {
                if (VSCAN_Read(sg_VSCanCfg.hCan, &msg, 1, &dwTemp) != VSCAN_ERR_OK)
                {
                    sg_pIlog->logMessage(A2T(__FILE__), __LINE__, _("VSCAN_Read failed"));
                    Sleep(100);
                    continue;
                }

                if (dwTemp == 1)
                {
                    CopyMsg2CanData(&can_data, &msg, RX_FLAG);
                    //Write the msg into registered client's buffer
                    EnterCriticalSection(&sg_DIL_CriticalSection);
                    vWriteIntoClientsBuffer(can_data);
                    LeaveCriticalSection(&sg_DIL_CriticalSection);
                }
                else
                {
                    break;
                }
            }
        }
        else
        {
            sg_pIlog->logMessage(A2T(__FILE__), __LINE__, _("WaitForSingleObject failed"));
            Sleep(100);
        }

    }
}
Ejemplo n.º 6
0
/**
* \brief         Read thread procedure
* \param[in]     pVoid contains the CPARAM_THREADPROC class object
* \return        void
* \authors       Prince Varghese
* \date          09.04.2013 Created
*/
DWORD WINAPI CanMsgReadThreadProc_CAN_ISolar_Eve(LPVOID pVoid)
{
    USES_CONVERSION;

    CPARAM_THREADPROC* pThreadParam = (CPARAM_THREADPROC*) pVoid;

    /* Assign thread action to CREATE_TIME_MAP */
    pThreadParam->m_unActionCode = CREATE_TIME_MAP;

    bool bLoopON = true;

    while (bLoopON)
    {
        Sleep (10); // To avoid continuous loop as there is no event mechanism
        switch (pThreadParam->m_unActionCode)
        {
            case INVOKE_FUNCTION:
            {

                int functionType = 0;
                unsigned int dataSize = 0;

                if (ReceiveCommandFromClient(&functionType, &dataSize) >= 0)
                {
                    switch (functionType)
                    {
                        case SEND_MESSAGE:
                        {
                            STCAN_MSG RxMsg;
                            int receiveResult = ReceiveCANMessageFromClient(&RxMsg);
                            if (receiveResult > 0)
                            {
                                sg_EVE_CANMsg.m_uDataInfo.m_sCANMsg.m_bCANFD = false;
                                sg_EVE_CANMsg.m_ucDataType = receiveResult;
                                sg_EVE_CANMsg.m_uDataInfo.m_sCANMsg = RxMsg;

                                RxMsg.m_ucChannel = 1;
                                vWriteIntoClientsBuffer(sg_EVE_CANMsg);
                            }
                        }
                        break;

                        default:
                            break;
                    }
                }
            }
            break;
            case EXIT_THREAD:
            {
                bLoopON = false;
            }
            break;
            case CREATE_TIME_MAP:
            {
                SetEvent(pThreadParam->m_hActionEvent);
                pThreadParam->m_unActionCode = INVOKE_FUNCTION;
            }
            break;
            default:
            case INACTION:
            {
                // nothing right at this moment
            }
            break;
        }

    }
    SetEvent(pThreadParam->hGetExitNotifyEvent());
    pThreadParam->m_hActionEvent = nullptr;

    return 0;
}
Ejemplo n.º 7
0
/**
* \brief         Read thread procedure
* \param[in]     pVoid contains the CPARAM_THREADPROC class object
* \return        void
* \authors       Prince Varghese
* \date          09.04.2013 Created
*/
DWORD WINAPI LinMsgReadThreadProc_LIN_ISolar_Eve(LPVOID pVoid)
{
    USES_CONVERSION;

    CPARAM_THREADPROC* pThreadParam = (CPARAM_THREADPROC*) pVoid;

    /* Assign thread action to CREATE_TIME_MAP */
    pThreadParam->m_unActionCode = CREATE_TIME_MAP;

    /* Dummy action event */
    pThreadParam->m_hActionEvent = CreateEvent(nullptr, false, false, nullptr);

    bool bLoopON = true;

    while (bLoopON)
    {
        Sleep (10);
        switch (pThreadParam->m_unActionCode)
        {
            case INVOKE_FUNCTION:
            {
                static STLIN_FRAME RxFrame;
                static STLIN_MSG RxMsg;
                static int iRxLength;
                int iChecksum = 0;
                RxMsg.m_ucDataLen = 0;
                unsigned int uiDataType = ReceiveLINMessageFromClient(&RxFrame, &iRxLength);


                if (iRxLength == LIN_PID_LENGTH)
                {
                    RxMsg.m_ucMsgID   =  RxFrame.m_ucMsgID;
                    RxMsg.m_ucChksum  = 0;

                    vValidateReceivedLinPID(RxMsg);

                    /*sg_EVE_LINMsg.m_ucDataType = TX_FLAG;*/
                    sg_EVE_LINMsg.m_uDataInfo.m_sLINMsg = RxMsg;
                    RxMsg.m_ucChannel = LIN_CHANNEL_1;
                    //vWriteIntoClientsBuffer(sg_EVE_LINMsg);
                }
                else if (iRxLength > LIN_PID_LENGTH)
                {
                    RxMsg.m_ucMsgID   =  RxFrame.m_ucMsgID;
                    RxMsg.m_ucChksum  =  RxFrame.m_ucChksum;
                    RxMsg.m_ucDataLen =  iRxLength - (LIN_PID_LENGTH + LIN_CHECKSUM_LENGTH); // 2 (1 byte checksum and 1byte pid)

                    for(int i=0; i<8; i++)
                    {
                        RxMsg.m_ucData[i] = RxFrame.m_ucData[i];
                        iChecksum = iChecksum + RxFrame.m_ucData[i];
                        if (iChecksum > 255)
                        {
                            iChecksum = iChecksum - 255;
                        }
                    }
                    RxMsg.m_ucChksum = 255 - iChecksum;

                    if((RxMsg.m_ucChksum != RxFrame.m_ucChksum))
                    {
                        RxMsg.m_ucMsgTyp = LIN_CHECKSUM_ERROR;
                        RxMsg.m_ucChksum = RxFrame.m_ucChksum;
                    }
                    else
                    {
                        vValidateReceivedLinMsg(RxMsg);
                    }

                    if(uiDataType == TX_LOOPBACK_UDP_DATA)
                    {
                        sg_EVE_LINMsg.m_ucDataType = TX_FLAG;
                    }
                    else if((uiDataType == RX_UDP_PID)||(uiDataType == RX_UDP_DATA))
                    {
                        sg_EVE_LINMsg.m_ucDataType = RX_FLAG;
                    }

                    RxMsg.m_ucChannel = LIN_CHANNEL_1;

                    sg_EVE_LINMsg.m_uDataInfo.m_sLINMsg = RxMsg;
                    RxMsg.m_ucChannel = 1;
                    vWriteIntoClientsBuffer(sg_EVE_LINMsg);
                }
            }
            break;
            case EXIT_THREAD:
            {
                bLoopON = false;
            }
            break;
            case CREATE_TIME_MAP:
            {
                SetEvent(pThreadParam->m_hActionEvent);
                pThreadParam->m_unActionCode = INVOKE_FUNCTION;
            }
            break;
            default:
            case INACTION:
            {
                // nothing right at this moment
            }
            break;
        }

    }
    SetEvent(pThreadParam->hGetExitNotifyEvent());
    pThreadParam->m_hActionEvent = nullptr;

    return 0;
}