#include "cameraconfig.h"
#include <mil.h>
#include "mil3dcam_sickrangere.h"
#include "sickcamera_rangere.h"
#include "sickframegrabber.h"
#if !USE_REAL_CAMERA
#else
#include "icon_auto_link.h"
#include "icon_api.h"
#include "ethernetcamera.h"
#include "framegrabber.h"
#include "dataformat.h"
using namespace std;
using namespace icon;
void ProcessCallback(IconBuffer *pBuffer, FrameGrabber* pFrameGrab, void* UserData)
{
FrameGrabberHookStruct* pFrameGrabHookStruct = (FrameGrabberHookStruct*) UserData;
MIL_ID MilRangerImage = MbufCreate2d(pFrameGrabHookStruct->MilSystem,
pBuffer->getWidth(),
pBuffer->getHeight(),
8 + M_UNSIGNED,
M_IMAGE + M_PROC,
M_HOST_ADDRESS + M_PITCH_BYTE,
pBuffer->getWidth(),
pBuffer->getWritePointer(0),
M_NULL);
(*(pFrameGrabHookStruct->HookHandlerPtr))(0, MilRangerImage, pFrameGrabHookStruct->UserDataPtr);
MbufFree(MilRangerImage);
}
MIL_INT StartGrab(FrameGrabber* pFrameGrab, RangerE* pCam, MIL_ID StartStageEvent )
{
MIL_INT Index = GetNewActiveIndex();
if(Index != -1)
{
MIL_INT Ret;
ActiveFrameGrabber[Index] = pFrameGrab;
Ret = pFrameGrab->startGrab();
if(Ret != FrameGrabber::E_ALL_OK)
return SICK_FRAME_GRABBER_NOT_OK;
Ret = pCam->start();
if(Ret != Camera::E_ALL_OK)
return SICK_CAMERA_NOT_OK;
if(StartStageEvent)
MthrControl(StartStageEvent, M_EVENT_SET, M_SIGNALED);
MosSleep(STAGE_STARTUP_DELAY_MS);
}
else
return SICK_CAMERA_NOT_OK;
return SICK_FRAME_GRABBER_OK;
}
MIL_INT StopGrab(FrameGrabber* pFrameGrab, RangerE* pCam)
{
MIL_INT Ret;
MIL_INT Ret2;
if(RemoveActiveFrameGrabber(pFrameGrab))
{
Ret = pFrameGrab->stopGrab();
if(Ret != FrameGrabber::E_ALL_OK)
return SICK_FRAME_GRABBER_NOT_OK;
int Status;
Ret2 = pCam->checkCamStatus(Status);
if(Ret2 != Camera::E_ALL_OK)
return SICK_CAMERA_NOT_OK;
if(Status != RangerE::Stopped)
{
Ret = pCam->stop();
if(Ret != Camera::E_ALL_OK)
return SICK_CAMERA_NOT_OK;
}
}
return SICK_FRAME_GRABBER_OK;
}
MIL_INT GetNewActiveIndex()
{
for(MIL_INT i = 0; i < MAX_FRAME_GRABBER; i++)
{
if(ActiveFrameGrabber[i] == NULL)
return i;
}
return -1;
}
bool IsActive(FrameGrabber* pFrameGrab)
{
for(MIL_INT i = 0; i < MAX_FRAME_GRABBER; i++)
{
if(ActiveFrameGrabber[i] == pFrameGrab)
return true;
}
return false;
}
bool RemoveActiveFrameGrabber(FrameGrabber* pFrameGrab)
{
for(MIL_INT i = 0; i < MAX_FRAME_GRABBER; i++)
{
if(ActiveFrameGrabber[i] == pFrameGrab)
{
ActiveFrameGrabber[i] = NULL;
return true;
}
}
return false;
}
#endif