Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues for the use of NSI devices, including #1072 issue #1137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/BUSMASTER/Application/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13512,6 +13512,10 @@ INT CMainFrame::nGetControllerID(std::string strDriverName)
{
nDriverID = DRIVER_CAN_PEAK_USB;
}
else if (strDriverName == "NSI CAN-API")
{
nDriverID = DRIVER_CAN_NSI;
}
else
{
nDriverID = DRIVER_CAN_STUB;
Expand Down
26 changes: 17 additions & 9 deletions Sources/BUSMASTER/CAN_NSI/CAN_NSI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ static int nSetFilter(UINT unDrvChannel, BOOL /*bWrite*/)
}
else
{
cr = Ic_SetRxMask(NSI_hCanal[sg_aodChannels[unDrvChannel].m_nChannel], dwCode, dwMask, _CAN_EXT);
cr = Ic_SetRxMask(NSI_hCanal[sg_aodChannels[unDrvChannel].m_nChannel], dwCode, dwMask, _CAN_ALL); // to accept both Standard and Extended
}
if(cr != _OK)
{
Expand Down Expand Up @@ -1644,9 +1644,11 @@ static int nConnect(BOOL bConnect, BYTE /*hClient*/)
int nReturn = S_OK;
unsigned int i;

if(bConnect)
if (!flagConnect && bConnect)
{
InitializeCriticalSection(&sg_CritSectForAckBuf);
bLoadDataFromContr(sg_ControllerDetails);
nSetApplyConfiguration();
InitializeCriticalSection(&sg_CritSectForAckBuf);
for(i=0; i<sg_nNoOfChannels; i++)
{
/* Start CAN controler. Receptions are starting now. The controler is seting the acknowledge bit
Expand All @@ -1663,7 +1665,7 @@ static int nConnect(BOOL bConnect, BYTE /*hClient*/)
sg_byCurrState[i] = CREATE_MAP_TIMESTAMP;
}
}
else
else if (flagConnect && !bConnect)
{
DeleteCriticalSection(&sg_CritSectForAckBuf);
for(i=0; i<sg_nNoOfChannels; i++)
Expand Down Expand Up @@ -2068,7 +2070,15 @@ HRESULT CDIL_CAN_NSI::CAN_PerformClosureOperations(void)
{
HRESULT hResult = S_OK;

hResult = CAN_StopHardware();
if (flagConnect)
{
hResult = CAN_StopHardware();
}
else
{
hResult = S_FALSE;
}

// Remove all the existing clients
UINT ClientIndex = 0;
while (sg_unClientCnt > 0)
Expand Down Expand Up @@ -2243,8 +2253,6 @@ HRESULT CDIL_CAN_NSI::CAN_StartHardware(void)
USES_CONVERSION;
HRESULT hResult = S_OK;

flagConnect = TRUE;

//Connect to the channels
hResult = nConnect(TRUE, 0);
if (hResult == S_OK)
Expand All @@ -2253,6 +2261,7 @@ HRESULT CDIL_CAN_NSI::CAN_StartHardware(void)
sg_bCurrState = STATE_CONNECTED;
SetEvent(NSI_hEvent[0]);
vCreateTimeModeMapping(NSI_hEvent[0]);
flagConnect = TRUE;
}
else
{
Expand Down Expand Up @@ -2292,13 +2301,12 @@ HRESULT CDIL_CAN_NSI::CAN_StopHardware(void)
//Terminate the read thread
sg_sParmRThread.bTerminateThread();

flagConnect = FALSE;

hResult = nConnect(FALSE, 0);
if (hResult == S_OK)
{
hResult = S_OK;
sg_bCurrState = STATE_HW_INTERFACE_SELECTED;
flagConnect = FALSE;
}
else
{
Expand Down