boolean PlainProtocol::available()
{
    if (receiveFrame()) {
        receivedContentLenthIndex=0;
        return true;
    }
    else{
        return false;
    }
    
}
Example #2
0
Ctrl::Ctrl() {
	gui = new Gui(this);

	gui->setCamDevList(cGrabber::enumDevices());

	processingThread = new ProcThread();

	cv::FileStorage calibrationSettings;

	if(!calibrationSettings.open("mystereocalib_0.17.yml", cv::FileStorage::READ)){
		printf("Can't open camera calibration");
		return;
	}

	cv::Mat CM1;
	cv::Mat T;
	calibrationSettings["CM1"] >> CM1;
	calibrationSettings["T"] >> T;

	std::cout << CM1 << std::endl;
	std::cout << CM1.at<double>(0, 0) << " " << CM1.at<double>(1, 1) << " "
			<< CM1.at<double>(0, 2) << " " << CM1.at<double>(1, 2) << " "
			<< std::endl;
	std::cout << "b:" << cv::norm(T) << std::endl;

	gui->setCameraData(CM1.at<double>(0, 0), CM1.at<double>(1, 1),
			CM1.at<double>(0, 2), CM1.at<double>(1, 2), cv::norm(T));

	connect(processingThread,
			SIGNAL(finishedFrame(QImage , QImage, QImage , QImage , QImage )),
			this,
			SLOT(receiveFrame(QImage , QImage, QImage , QImage , QImage )),
			Qt::QueuedConnection);

//	QImage l, r;
//	l.load("tsukubaleft.jpg");
//	r.load("tsukubaright.jpg");
//
//	if (l.format() == QImage::Format_RGB888) {
//		QImage lG(l.width(), l.height(), QImage::Format_Grayscale8);
//		QImage rG(l.width(), l.height(), QImage::Format_Grayscale8);
//		cudaRGBToGray(l.bits(), lG.bits(), l.width() * l.height());
//		cudaRGBToGray(r.bits(), rG.bits(), r.width() * r.height());
//	} else if (l.format() == QImage::Format_Grayscale8) {
//		QImage ldisp(l.width(), l.height(), QImage::Format_Grayscale8);
//		QImage rdisp(l.width(), l.height(), QImage::Format_Grayscale8);
//		gui->displayRGB(l, r);
//		cudaStereoMatch(l.bits(), r.bits(), ldisp.bits(), rdisp.bits(),
//				l.width(), l.height(), 7, 30, 5);
//		gui->displayDisp(ldisp, rdisp);
//	}
}
/*!
 * \fn UvAbstractFrameProcessor::UvAbstractFrameProcessor(UvAbstractFrameTransceiver *transceiver)
 * \brief Construct a frame processor.
 */
UvAbstractFrameProcessor::UvAbstractFrameProcessor(UvAbstractFrameTransceiver *transceiver)
{
    d = new UvAbstractFrameProcessorPrivate;
    UV_CHK_PTR(d);

    d->transceiver = transceiver;
    UV_CHK_PTR(d->transceiver);
    connect(d->transceiver, SIGNAL(frameReady()), this, SLOT(receiveFrame()));

    //create and start frame parsing and sending thread
    d->parsingThread = new UvFrameParsingThread(this);
    UV_CHK_PTR(d->parsingThread);
    d->parsingThread->start();
    d->sendingThread = new UvFrameSendingThread(this);
    UV_CHK_PTR(d->sendingThread);
    d->sendingThread->start();

    d->sendingDelayTime = 0;
}
Example #4
0
MB_ErrorTypeDef MB_poll()
{
static uint8_t destAddr;
static uint8_t *pPdu;
static uint16_t pduSize;
static uint8_t functionCode;
static MB_ExceptionTypeDef excep;

  if (mbState != MB_STATE_ENABLED)
    return MB_ERROR_ILLSTATE;

  if (mbEvent != MB_EVENT_NONE)
  {
    switch (mbEvent) {
      case MB_EVENT_READY :                                                   //t35 pause after Start passed
        mbEvent = MB_EVENT_NONE;
        break;
      case MB_EVENT_ERROR :                                                   //Error occurred
        mbEvent = MB_EVENT_NONE;
        break;
      case MB_EVENT_FRAME_RECEIVED :                                          //Frame received
        if (receiveFrame(&destAddr, &pPdu, &pduSize) == MB_ERROR_OK) {        //CRC and length correct
          if ((destAddr == mbDevAddr) || (destAddr == MB_ADDR_BROADCAST)) {   //Destination address is own
            mbEvent = MB_EVENT_EXECUTE;
          }
          else {                                                              //Destination address is wrong
            mbEvent = MB_EVENT_NONE;
          }
        }
        else {                                                                //Frame CRC or length failed
          mbEvent = MB_EVENT_ERROR;
        }
        break;
      case MB_EVENT_EXECUTE :                                                 //Valid frame with own address received
        functionCode = *(pPdu + PDU_FUNC_OFFSET);
        if (functionCode == MB_FUNC_WRITE_REGISTER) {                         //Function #06
          excep = APP_WriteHoldingRegister(pPdu, &pduSize);
        }
        else if (functionCode == MB_FUNC_READ_REGISTERS) {                    //Function #03
          excep = APP_ReadHoldingRegisters(pPdu, &pduSize);
        }
        else {                                                                //Unsupported function
          excep = MB_EXCEP_ILLFUNCTION;
        }

        mbEvent = MB_EVENT_NONE;
        if (destAddr != MB_ADDR_BROADCAST) {                                  //Destination address is not broadcast
          if (excep != MB_EXCEP_NONE) {                                       //Build exception response
            pduSize = 0;
            *(pPdu + pduSize++) = functionCode | MB_FUNC_ERROR;
            *(pPdu + pduSize++) = excep;
          }
          if(sendFrame(pduSize) != MB_ERROR_OK) {                             //Send normal or exception response
            mbEvent = MB_EVENT_ERROR;                                         //UART transmitter error
          }
        }
        break;
      case MB_EVENT_SENT :                                                    //All frame sent
        mbEvent = MB_EVENT_NONE;
        break;
      case MB_EVENT_NONE :
        break;
    }
  }
  return MB_ERROR_OK;
}
respData_t *receiveChainedFrame(struct file *filp,short rPcb, short rLen) 
{
	respData_t *data_rec=NULL;
	respData_t *header=NULL ;
	respData_t *respData=NULL;
	respData_t *apdbuff=NULL;
	NFC_DBG_MSG(KERN_ALERT "receiveChainedFrame -Enter\n");
	// receive a chained frame as long as chaining is indicated in the PCB
	do
	{
		// receive the DATA field of the current frame
		NFC_DBG_MSG(KERN_ALERT "p61_dev_read - test4 count [0x%x] \n",rLen);
		data_rec = receiveFrame(filp,rPcb, rLen);
		// write it into an apduBuffer memory
		memcpy((apduBuffer+apduBufferidx),data_rec->data,data_rec->len);

		//update the index to next free slot
		apduBufferidx += data_rec->len;

		// send the acknowledge for the current frame
		udelay(1000);
		sendAcknowledge(filp);
		udelay(1000);
		// receive the header of the next frame
		header = receiveHeader(filp);

		rPcb = header->data[0];
		rLen = (header->data[1] & 0xFF);


	}while ((rPcb & PH_SCAL_T1_CHAINING) == PH_SCAL_T1_CHAINING);


	// receive the DATA field of the last frame

	respData = receiveFrame(filp,rPcb, rLen);
	memcpy(apduBuffer+apduBufferidx,respData->data,respData->len);
	//update the index to next free slot
	apduBufferidx += respData->len;


	// return the entire received apdu
	apdbuff=(respData_t *)kmalloc(sizeof(respData_t),GFP_KERNEL);
	if(apdbuff == NULL)
	{
		NFC_ERR_MSG(KERN_ALERT "receiveChainedFrame 2-KMALLOC FAILED!!!\n");
		return NULL;
	}

	apdbuff->data= (unsigned char*)kmalloc(apduBufferidx,GFP_KERNEL);
	if(apdbuff->data == NULL)
	{
		NFC_ERR_MSG(KERN_ALERT "receiveChainedFrame 3-KMALLOC FAILED!!!\n");
		return NULL;
	}
	memcpy(apdbuff->data,apduBuffer,apduBufferidx);
	apdbuff->len=apduBufferidx;

	NFC_DBG_MSG(KERN_ALERT "receiveChainedFrame -Exit\n");
	return apdbuff;
}
static respData_t* p61_dev_receiveData_internal(struct file *filp)
{
	short rPcb = 0;
	short rLen = 0;
	respData_t *header=NULL;
	respData_t *respData=NULL;
	unsigned char *wtx=NULL;
	unsigned char *data=NULL;
	//unsigned char *data1=NULL;
	int len=0;
	int len1=0;
	int stat_timer;
Start:
	NFC_DBG_MSG(KERN_INFO  "receiveData -Enter\n");

	// receive the T=1 header
	header = (respData_t*)receiveHeader(filp);
	if(header == NULL)
	{
		NFC_ERR_MSG(KERN_ALERT "ERROR:Failed to receive header data\n");
		return NULL;
	}
	rPcb = header->data[0];
	rLen = (short) (header->data[1] & 0xFF);
	NFC_DBG_MSG(KERN_ALERT "receive header data rPcb = 0x%x , rLen = %d\n", rPcb, rLen);

#if 1

	//check the header if wtx is requested
	if ((rPcb & PH_SCAL_T1_S_BLOCK) == PH_SCAL_T1_S_BLOCK)
	{
		NFC_DBG_MSG(KERN_ALERT "receiveDatav - WTX requested\n");
		data = gRecvBuff;
		len = 1;
		NFC_DBG_MSG(KERN_ALERT "receiveDatav - WTX1 requested\n");
		receive(filp,&data,len, C_TRANSMIT_NO_STOP_CONDITION | C_TRANSMIT_NO_START_CONDITION);
		NFC_DBG_MSG(KERN_ALERT "receiveDatav - WTX2 requested\n");
		receiveAndCheckChecksum(filp,rPcb, rLen, data,len);
		NFC_DBG_MSG(KERN_ALERT "receiveDatav - WTX3 requested\n");
		NFC_DBG_MSG(KERN_ALERT "value is %x %x",data[0],data[1]);
                memset(gRecvBuff,0,300);
		wtx = gRecvBuff;
		wtx[0] = 0x00; wtx[1] = 0xE3; wtx[2] = 0x01; wtx[3] = 0x01; wtx[4] = 0xE3;
		len1 = 5;
		udelay(1000);
		send(filp,&wtx, C_TRANSMIT_NORMAL_SPI_OPERATION,len1);
		udelay(1000);

                //gStRecvData->len = 5;
                //memcpy(gStRecvData->data, wtx, 5);;
#ifdef TIMER_ENABLE
                stat_timer = start_timer();
#endif
                //return gStRecvData;
		goto Start;
	}

	//check the header if retransmit is requested
	if ((rPcb & PH_SCAL_T1_R_BLOCK) == PH_SCAL_T1_R_BLOCK)
	{
		memset(data1,0,1);
		len1=1;
		receiveAndCheckChecksum(filp,rPcb, rLen, data1,len1);
		udelay(1000);
		send(filp,&lastFrame, C_TRANSMIT_NORMAL_SPI_OPERATION,lastFrameLen);
		udelay(1000);
		goto Start;
//		return (ssize_t)p61_dev_receiveData_internal(filp);
	}

	//check the PCB byte and receive the rest of the frame
	if ((rPcb & PH_SCAL_T1_CHAINING) == PH_SCAL_T1_CHAINING)
	{
		NFC_DBG_MSG(KERN_ALERT "Chained Frame Requested\n");

		return receiveChainedFrame(filp,rPcb, rLen);

	}
	else
	{
		NFC_DBG_MSG(KERN_ALERT "receiveFrame Requested\n");
		respData = receiveFrame(filp,rPcb, rLen);
		NFC_DBG_MSG(KERN_ALERT "***************** 0x%x \n",respData->data[0]);
		return respData;
	}
#endif
	return NULL;
}