Exemplo n.º 1
0
Msg const *MainState_idle(MainState *me, Msg *msg)
{
	switch (msg->evt)
	{
	case ENTRY_EVT:
		OscLog(INFO, "Enter idle mode.\n");
#ifndef HAS_CPLD
		/* Set onboard LED green */
		OscGpioSetTestLed( TRUE);       
		OscGpioSetTestLedColor(FALSE, TRUE); /* R, G*/ 
#endif /* !HAS_CPLD */
		return 0;
	case FRAMESEQ_EVT:
		/* Sleep here for a short while in order not to violate the vertical
		 * blank time of the camera sensor when triggering a new image
		 * right after receiving the old one. This can be removed if some
		 * heavy calculations are done here. */
		usleep(1000);
		return 0;
	case FRAMEPAR_EVT:		
		return 0;
	case CMD_GO_IDLE_EVT:
		data.comm.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case CMD_GO_ACQ_EVT:
		if(data.enTriggerMode == TRIG_MODE_INTERNAL)
		{
			STATE_TRAN(me, &me->internal);
		} else if(data.enTriggerMode == TRIG_MODE_EXTERNAL)
		{
			STATE_TRAN(me, &me->external);
		} else {
			OscLog(ERROR, "%d: Invalid trigger mode configured (%d)!\n",
			       __func__, data.enTriggerMode);
			data.comm.enReqState = REQ_STATE_NACK_PENDING;
			return 0;
		}
		data.comm.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case CMD_USE_INTERN_TRIGGER_EVT:
		/* Switch state to internal capturing mode.  */
		data.enTriggerMode = TRIG_MODE_INTERNAL;
		data.comm.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case CMD_USE_EXTERN_TRIGGER_EVT:
		/* Switch state to external capturing mode.  */
		data.enTriggerMode = TRIG_MODE_EXTERNAL;
		data.comm.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	}
	return msg;
}
Exemplo n.º 2
0
Msg const *MainState_CaptureColor(MainState *me, Msg *msg)
{
	struct APPLICATION_STATE *pState;
	bool bCaptureColor;
	
	switch (msg->evt)
	{
	case ENTRY_EVT:
		data.ipc.state.enAppMode = APP_CAPTURE_COLOR;
		data.pCurRawImg = data.u8FrameBuffers[0];
		return 0;
	case FRAMESEQ_EVT:
		/* Sleep here for a short while in order not to violate the vertical
		 * blank time of the camera sensor when triggering a new image
		 * right after receiving the old one. This can be removed if some
		 * heavy calculations are done here. */
		usleep(1000);
		return 0;
	case FRAMEPAR_EVT:
		/* Process the image. */
		ProcessFrame(data.pCurRawImg);
		
		/* Timestamp the capture of the image. */
		data.ipc.state.imageTimeStamp = OscSupCycGet();
		data.ipc.state.bNewImageReady = TRUE;
		return 0;
	case IPC_GET_APP_STATE_EVT:
		/* Fill in the response and schedule an acknowledge for the request. */
		pState = (struct APPLICATION_STATE*)data.ipc.req.pAddr;
		memcpy(pState, &data.ipc.state, sizeof(struct APPLICATION_STATE));
		
		data.ipc.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case IPC_GET_COLOR_IMG_EVT:
		/* Write out the image to the address space of the CGI. */
		memcpy(data.ipc.req.pAddr, data.u8ResultImage, sizeof(data.u8ResultImage));
		
		data.ipc.state.bNewImageReady = FALSE;
		
		/* Mark the request as executed, so it will be acknowledged later. */
		data.ipc.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case IPC_SET_CAPTURE_MODE_EVT:
		/* Read the option from the address space of the CGI. */
		bCaptureColor = *((bool*)data.ipc.req.pAddr);
		if (bCaptureColor == FALSE)
		{
			/* Need to capture raw images from now on, this is done in the captureRaw state.  */
			STATE_TRAN(me, &me->captureRaw);
		}
		data.ipc.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	}
	return msg;
}
Exemplo n.º 3
0
Msg const *MainState_top(MainState *me, Msg *msg)
{
	struct APPLICATION_STATE *pState;
	switch (msg->evt)
	{
	case START_EVT:
		/* initialize the whole stuff - is this the right place ? */
		STATE_START(me, &me->showgray);
		data.ipc.state.enAppMode = APP_CAPTURE_ON;
		data.pCurRawImg = data.u8FrameBuffers[0];
		data.nExposureTimeChanged = true;
		data.ipc.state.nExposureTime = 25;
		data.ipc.state.nStepCounter = 0;
		data.ipc.state.nThreshold = 30;
		return 0;
	case IPC_GET_APP_STATE_EVT:
		/* Fill in the response and schedule an acknowledge for the request. */
		pState = (struct APPLICATION_STATE*)data.ipc.req.pAddr;
		memcpy(pState, &data.ipc.state, sizeof(struct APPLICATION_STATE));

		data.ipc.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case FRAMESEQ_EVT:
		/* Timestamp the capture of the image. */
		data.ipc.state.imageTimeStamp = OscSupCycGet();
		data.ipc.state.bNewImageReady = TRUE;
		/* Sleep here for a short while in order not to violate the vertical
		 * blank time of the camera sensor when triggering a new image
		 * right after receiving the old one. This can be removed if some
		 * heavy calculations are done here. */
		usleep(4000);
		return 0;
	case FRAMEPAR_EVT:
	{
		/* we have a new image increase counter: here and only here! */
		data.ipc.state.nStepCounter++;
		/* debayer the image first -> to half size*/
		OscVisDebayerGreyscaleHalfSize( data.pCurRawImg, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT, ROW_BGBG, data.u8TempImage[GRAYSCALE]);
		/* Process the image. */
		/* the parameter is not really required */
		ProcessFrame(data.u8TempImage[GRAYSCALE]);

		return 0;
	}
	case IPC_SET_IMAGE_TYPE_EVT:
	{
		if(data.ipc.state.nImageType == GRAYSCALE) {
			STATE_TRAN(me, &me->showgray);
		}
		else if(data.ipc.state.nImageType == THRESHOLD) {
			STATE_TRAN(me, &me->showthresh);
		}
		else if(data.ipc.state.nImageType == EROSION) {
			STATE_TRAN(me, &me->showerosion);
		}
    else if(data.ipc.state.nImageType == DILATION) {
      STATE_TRAN(me, &me->showdilation);
    }
    else if(data.ipc.state.nImageType == LABELIMG) {
      STATE_TRAN(me, &me->showlabel);
    }
		else {
			data.ipc.enReqState = REQ_STATE_NACK_PENDING;
		}
		data.ipc.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	}
	case IPC_GET_NEW_IMG_EVT:
		/* If the IPC event is not handled in the actual substate, a negative acknowledge is returned by default. */
		data.ipc.enReqState = REQ_STATE_NACK_PENDING;
	return 0;
	}
	return msg;
}
Exemplo n.º 4
0
Msg const *MainState_capture(MainState *me, Msg *msg)
{
        OSC_ERR err;
	uint8 *pDummyImg = NULL;
	uint32 imgSize;

	switch (msg->evt)
	{
	case ENTRY_EVT:
		OscLog(INFO, "Enter generic capture mode.\n");
#ifndef HAS_CPLD
		/* Set onboard LED red */
		OscGpioSetTestLed( TRUE);       
		OscGpioSetTestLedColor(TRUE, FALSE); /* R, G*/ 
#endif /* !HAS_CPLD */

		OscLog(INFO, "Setup capture\n");
		err = OscCamSetupCapture( OSC_CAM_MULTI_BUFFER);
		if (err != SUCCESS)
		{
			OscLog(ERROR, "%s: Unable to setup initial capture (%d)!\n", __func__, err);
		}
		return 0;
	case FRAMESEQ_EVT:
		/* Fill out the feed header. */
		data.comm.feedHdr.seqNr++;
		/* We need the uptime in milliseconds. */
		data.comm.feedHdr.timeStamp = (uint32)(OscSupCycToMilliSecs(OscSupCycGet64()));
		
		data.comm.feedHdr.imgWidth = OSC_CAM_MAX_IMAGE_WIDTH;
		data.comm.feedHdr.imgHeight = OSC_CAM_MAX_IMAGE_HEIGHT;
#ifdef TARGET_TYPE_LEANXCAM
		data.comm.feedHdr.pixFmt = V4L2_PIX_FMT_GREY;
		imgSize = data.comm.feedHdr.imgWidth * data.comm.feedHdr.imgHeight * 1;
#endif /* TARGET_TYPE_LEANXCAM */
#ifdef TARGET_TYPE_INDXCAM
		data.comm.feedHdr.pixFmt = V4L2_PIX_FMT_SBGGR8;
		imgSize = data.comm.feedHdr.imgWidth * data.comm.feedHdr.imgHeight * 1;
#endif /* TARGET_TYPE_INDXCAM */
		/* Send the image to the host. */
	  	Comm_SendImage(&data.comm, 
			       data.pCurRawImg, 
			       imgSize,
			       &data.comm.feedHdr);
		return 0;
	case FRAMEPAR_EVT:	
		return 0;
	case CMD_GO_IDLE_EVT:
		/* Read picture until no more capture is active.Always use self-trigg*/
		err = SUCCESS;
		while(err != -ENO_CAPTURE_STARTED)
		{
			SelfTrigger();
			err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, &pDummyImg, 0, CAMERA_TIMEOUT);
			OscLog(DEBUG, "%s: Removed picture from queue! (%d)\n", __func__, err);
		} 
		STATE_TRAN(me, &me->idle);
		data.comm.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case CMD_GO_ACQ_EVT:
		data.comm.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case CMD_USE_INTERN_TRIGGER_EVT:
	case CMD_USE_EXTERN_TRIGGER_EVT:
		/* Not supported in acquisition mode. */
		data.comm.enReqState = REQ_STATE_NACK_PENDING;
		return 0;
	case EXIT_EVT:
		/* Read picture until no more capture is active. Always use self-trigg*/
		err = SUCCESS;
		while(err != -ENO_CAPTURE_STARTED)
		{
			SelfTrigger();
			err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, &pDummyImg, 0, CAMERA_TIMEOUT);
			OscLog(DEBUG, "%s: Removed picture from queue! (%d)\n", __func__, err);
		} 
		return 0;
	}
	return msg;
}
Exemplo n.º 5
0
Msg const *MainState_top(MainState *me, Msg *msg)
{
        struct APPLICATION_STATE *pState;
        switch (msg->evt) {
        case START_EVT:
                /* initialize the whole stuff - is this the right place ? */
                STATE_START(me, &me->showGray);
                data.ipc.state.enAppMode = APP_CAPTURE_ON;
                data.pCurRawImg = data.u8FrameBuffers[0];
                data.nExposureTimeChanged = true;
                data.nResetProcessing = false;
                data.AddBufSize = 0;
                data.ipc.state.nExposureTime = 25;
                data.ipc.state.nStepCounter = 0;
                data.ipc.state.nThreshold = 0;
                return 0;
        case IPC_GET_APP_STATE_EVT:
                /* Fill in the response and schedule an acknowledge for the request. */
                pState = (struct APPLICATION_STATE*)data.ipc.req.pAddr;
                memcpy(pState, &data.ipc.state, sizeof(struct APPLICATION_STATE));

                data.ipc.enReqState = REQ_STATE_ACK_PENDING;
                return 0;
        case FRAMESEQ_EVT:
                /* Timestamp the capture of the image. */
                data.ipc.state.imageTimeStamp = OscSupCycGet();
                data.ipc.state.bNewImageReady = TRUE;
                /* Sleep here for a short while in order not to violate the vertical
                 * blank time of the camera sensor when triggering a new image
                 * right after receiving the old one. This can be removed if some
                 * heavy calculations are done here. */
                //usleep(4000);
                return 0;
        case FRAMEPAR_EVT: {
                /* we have a new image increase counter: here and only here! */
                data.ipc.state.nStepCounter++;
                /* debayer the image first -> to half size*/
#if NUM_COLORS == 1
                OscVisDebayerGreyscaleHalfSize(data.pCurRawImg, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT, ROW_YUYV, data.u8TempImage[SENSORIMG]);
#else
                memcpy(data.u8TempImage[SENSORIMG], data.pCurRawImg, NUM_COLORS*OSC_CAM_MAX_IMAGE_HEIGHT*OSC_CAM_MAX_IMAGE_WIDTH);
#endif
                /* Process the image. */
                //set data buffer to zero before each step
                data.AddBufSize = 0;
                ProcessFrame();

                return 0;
        }
        case IPC_SET_IMAGE_TYPE_EVT: {
                if(data.ipc.state.nImageType == SENSORIMG) {
                        STATE_TRAN(me, &me->showGray);
                } else if(data.ipc.state.nImageType == THRESHOLD) {
                        STATE_TRAN(me, &me->showThreshold);
                } else if(data.ipc.state.nImageType == BACKGROUND) {
                        STATE_TRAN(me, &me->showBackground);
                } else {
                        data.ipc.enReqState = REQ_STATE_NACK_PENDING;
                }
                data.ipc.enReqState = REQ_STATE_ACK_PENDING;
                return 0;
        }
        case IPC_GET_NEW_IMG_EVT:
                /* If the IPC event is not handled in the actual substate, a negative acknowledge is returned by default. */
                data.ipc.enReqState = REQ_STATE_NACK_PENDING;
                return 0;
        }
        return msg;
}