Esempio n. 1
0
void CNetworkMgmt::vReinitAdresClaimProc(DWORD dwClient)
{
    CNodeConManager* pNodConMgr = pouGetConMagrObj(dwClient);

    if (pNodConMgr != NULL)
    {
        BYTE byPreferedAdres = byGetUnclaimedAddress();
        pNodConMgr->StartAdresClaimProc(byPreferedAdres);
    }
}
Esempio n. 2
0
HRESULT CNetworkMgmt::StartAdresClaimProc(void)
{
    //Give a random delay to start
    HRESULT hResult = S_OK;
    UINT unRandomWait = rand() % sg_unTO_RESPONSE;
    Sleep(unRandomWait);
    static BYTE byPreferedAdres = 0;
    for (int i = 0; i < m_nConMgrCnt; i++)
    {
        CNodeConManager* pNodConMgr = m_ConMgrArr[i];

        if (pNodConMgr != NULL)
        {
            byPreferedAdres = pNodConMgr->m_byPrefAddress;
            if (bIsAddressClaimed(byPreferedAdres) == TRUE)
            {
                byPreferedAdres = byGetUnclaimedAddress(i);
            }
            hResult |= pNodConMgr->StartAdresClaimProc(byPreferedAdres);
        }
    }
    return hResult;
}
Esempio n. 3
0
LONG CNetworkMgmt::lCreateNodeConManager(char* pacNodeName,
        UINT64 un64ECUName,
        BYTE   byPrefAdres,
        DWORD& dwClientId)
{
    VALIDATE_POINTER_RETURN_VAL(m_pIDIL_CAN, S_FALSE);
    LONG lResult = S_OK;
    CNodeConManager* pNodeConMgr = NULL;
    //Search the array if node is already present
    pNodeConMgr = pouGetConMagrObj(pacNodeName);
    if (pNodeConMgr != NULL)
    {
        lResult = ERR_CLIENT_EXISTS;
        dwClientId = pNodeConMgr->m_dwClientID;
    }
    //If no. of node reached limit
    else if(m_nConMgrCnt == DEF_MAX_SIMULATED_NODE)
    {
        lResult = ALLOWED_NOMORE;
    }
    //Create new node
    if (lResult == S_OK)
    {
        //Find the first available position in the Array. There will
        //be empty places in beween due to deletion
        int nEmptyPos = 0;
        for (int i = 0; i < DEF_MAX_SIMULATED_NODE; i++)
        {
            if (m_ConMgrArr[i] == NULL)
            {
                nEmptyPos = i;
                break;
            }
        }
        if ( _tcscmp(pacNodeName, J1939_MONITOR_NODE) == 0 )
        {
            pNodeConMgr = new CMonitorNode(nEmptyPos, pacNodeName, un64ECUName, byPrefAdres);
        }
        else
        {
            //Provide its position in array and its PGN
            pNodeConMgr = new CNodeConManager(nEmptyPos, pacNodeName, un64ECUName, byPrefAdres);
        }
        if (pNodeConMgr != NULL)
        {
            m_ConMgrArr[nEmptyPos] = pNodeConMgr;
            m_nConMgrCnt++;
            HRESULT hResult = S_FALSE;
            // Connection manager is created. Proceed with rest of the procedures
            if ( _tcscmp(pacNodeName, J1939_MONITOR_NODE) == 0 )
            {
                hResult = m_pIDIL_CAN->DILC_RegisterClient(TRUE, dwClientId,
                          CAN_MONITOR_NODE);
                m_dwCANMonitorNodeClientId = dwClientId;
                if (hResult == ERR_CLIENT_EXISTS)
                {
                    hResult = S_OK;
                }
            }
            else
            {
                hResult = m_pIDIL_CAN->DILC_RegisterClient(TRUE, dwClientId,
                          pacNodeName);
            }
            //ASSERT(hResult == S_OK);
            if ((hResult == S_OK) || (hResult == ERR_CLIENT_EXISTS))
            {
                CBaseCANBufFSE* pouBuffer = pNodeConMgr->pouGetBuf();
                hResult = m_pIDIL_CAN->DILC_ManageMsgBuf(MSGBUF_ADD, dwClientId, pouBuffer);
                ASSERT(hResult == S_OK);
                if (hResult == S_OK)
                {
                    pNodeConMgr->m_dwClientID = dwClientId;
                    m_ouReadCANMsg.AddEventHandle(pouBuffer->hGetNotifyingEvent(), (BYTE)nEmptyPos);
                }
                //Join this node to network if started.
                if (m_bOnline == TRUE)
                {
                    pNodeConMgr->vActivate();
                    BYTE byPrefAddress = pNodeConMgr->m_byPrefAddress;

                    if ((byPrefAddress >= ADDRESS_NULL) || (bIsAddressClaimed(byPrefAddress) == TRUE))
                    {
                        byPrefAddress = byGetUnclaimedAddress();
                    }
                    pNodeConMgr->StartAdresClaimProc(byPrefAddress);
                }
            }
        }
        else
        {
            ASSERT(FALSE);
        }
    }
    return lResult;
}