コード例 #1
0
int GSkipBaseDevice::OSClearMeasurementPacketQueue()
{
    int nReturn = 0;

    if (LockDevice(1) && IsOKToUse())
    {
        nReturn = local_ClearPacketQueue(this, kMeasurementPipe);
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return nReturn;
}
コード例 #2
0
int GSkipBaseDevice::OSClearCmdRespPacketQueue()
{
    int nReturn = 0;

    if (LockDevice(1) && IsOKToUse())
    {
        nReturn = local_ClearPacketQueue(this, kCommandPipe);
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return nReturn;
}
コード例 #3
0
int GSkipBaseDevice::OSReadCmdRespPackets(void * pBuffer, int * pIONumPackets, int nBufferSizeInPackets)
{
    int nReturn = 0;

    if (LockDevice(1) && IsOKToUse())
    {
        nReturn = local_ReadPackets(this, pBuffer, pIONumPackets, nBufferSizeInPackets, kCommandPipe);
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return nReturn;
}
コード例 #4
0
int GSkipBaseDevice::OSCmdRespPacketsAvailable(void)
{
    int nReturn = 0;

    if (LockDevice(1) && IsOKToUse())
    {
        nReturn = local_PacketsAvailable(this, kCommandPipe);
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return nReturn;
}
コード例 #5
0
int GSkipBaseDevice::OSClose(void)
{
    if (LockDevice(1) && IsOKToUse())
    {
        TUSBBulkDevice usbDevice = static_cast<TUSBBulkDevice>(GetOSData());
        if ((usbDevice != NULL) && IsOpen())
            VST_CloseUSBPort((VST_USBBulkDevice *)usbDevice);
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return kResponse_OK;
}
コード例 #6
0
void GSkipBaseDevice::OSDestroy(void)
{
    if (LockDevice(1) && IsOKToUse())
    {
        TUSBBulkDevice usbDevice = static_cast<TUSBBulkDevice>(GetOSData());
        if (usbDevice != NULL)
        {
            VST_CloseUSBPort((VST_USBBulkDevice *)usbDevice);
            VST_ReleaseUSBBulkDevice((VST_USBBulkDevice *)usbDevice);
        }
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);
}
コード例 #7
0
int GSkipBaseDevice::OSMeasurementPacketsAvailable(unsigned char *pNumMeasurementsInLastPacket)
{
    int nReturn = 0;

    if (LockDevice(1) && IsOKToUse())
    {
        nReturn = local_PacketsAvailable(this, kMeasurementPipe);
        if (pNumMeasurementsInLastPacket != NULL)
            *pNumMeasurementsInLastPacket = local_NumLastMeasurements(this);
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return nReturn;
}
コード例 #8
0
int GSkipBaseDevice::OSClearIO(void)
{
    int nResult = kResponse_Error;

    if (LockDevice(1) && IsOKToUse())
    {
        nResult = OSClearMeasurementPacketQueue();
        if (nResult != kResponse_Error)
            nResult = GSkipBaseDevice::OSClearCmdRespPacketQueue();
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return nResult;
}
コード例 #9
0
int GSkipBaseDevice::OSOpen(GPortRef * /*pPortRef*/)
{
    int nResult = kResponse_Error;

    if (LockDevice(1) && IsOKToUse())
    {
        TUSBBulkDevice usbDevice = static_cast<TUSBBulkDevice>(GetOSData());

        // port may be NULL if initialization failed
        if (usbDevice == NULL)
            return kResponse_Error;

        int err = VST_OpenUSBPortForIO((VST_USBBulkDevice *)usbDevice);
        if (err == (int)kCFM_IOExclusiveAccess)
        {
            // If another app (including Classic) has the device we
            // can simply retry a few times.  The driver should be able to get a lock
            // on the device at some point.
            int nTry = 0;
            while ((err == (int)kCFM_IOExclusiveAccess) && (nTry < 4))
            {
                err = VST_OpenUSBPortForIO((VST_USBBulkDevice *)usbDevice);
                nTry++;
            }
        }

        if (err == 0)
            nResult = kResponse_OK;
        else
        {
            cppsstream ssErr;
            ssErr << "GUSBDirectTempDevice:OSOpen -- Error: " << err;
            GSTD_LOG(ssErr.str());
        }

        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return nResult;
}
コード例 #10
0
int GSkipBaseDevice::OSWriteCmdPackets(void * pBuffer, int nNumPackets)
{
    int nResult = kResponse_Error;
    UInt32 nIONumBytes = nNumPackets * sizeof(GSkipPacket);

    if (LockDevice(1) && IsOKToUse())
    {
        TUSBBulkDevice usbDevice = static_cast<TUSBBulkDevice>(GetOSData());
        if (usbDevice != NULL)
        {
            int err = VST_WriteBytes((VST_USBBulkDevice *)usbDevice, pBuffer, nIONumBytes);
            if (err == 0)
                nResult = kResponse_OK;
        }
        UnlockDevice();
    }
    else
        GSTD_ASSERT(0);

    return nResult;
}
コード例 #11
0
long GSkipDevice::SendInitCmdAndGetResponse(
	void *pParams,		//[in] ptr to cmd specific parameter block, may be NULL.
	long nParamBytes,	//[in] # of bytes in (*pParams).
	void *pRespBuf,		//[out] ptr to destination buffer, may be NULL.
	long *pnRespBytes,  //[in, out] size of of dest buffer on input, size of response on output, may be NULL if pRespBuf is NULL.
	long nTimeoutMs /* = 1000 */,//[in] # of milliseconds to wait before giving up.
	bool *pExitFlag /* = NULL */)//[in] ptr to flag that another thread can set to force early exit. 
						//		THIS FLAG MUST BE FALSE FOR THIS ROUTINE TO RUN.
						//		Ignore this if NULL.
{
	long nResult = kResponse_Error;
	unsigned char initStatus;
	long initStatusLength = sizeof(initStatus);

	if (LockDevice(1) && IsOKToUse())
	{
		nResult = kResponse_OK; 
		long maxNumRetries = (nTimeoutMs + SKIP_TIMEOUT_MS_CMD_ID_INIT_WITH_BUSY_STATUS - 1)/SKIP_TIMEOUT_MS_CMD_ID_INIT_WITH_BUSY_STATUS;
		if (maxNumRetries > 1)
			nTimeoutMs = SKIP_TIMEOUT_MS_CMD_ID_INIT_WITH_BUSY_STATUS;
		bool bSuccess = false;
		long numRetries;
		GSkipInitParams initParams;
		initParams.reportErrorWhilePoweringUpFlag = 1;
		if (pParams)
			GSTD_ASSERT(nParamBytes == sizeof(initParams));
		else
		{
			pParams = &initParams;
			nParamBytes = sizeof(initParams);
		}

		//Send multiple init commands until the timeout is reached because Skip may ignore commands sent before it is done
		//powering up.
		for (numRetries = 0; (numRetries < maxNumRetries) && (kResponse_OK == nResult) && (!bSuccess); numRetries++)
		{
			nResult = SendCmd(SKIP_CMD_ID_INIT,	pParams, nParamBytes);

			if (kResponse_OK == nResult)
			{
				unsigned int nTimeCmdSent = GUtils::OSGetTimeStamp();

				initStatusLength = sizeof(initStatus);
				initStatus = SKIP_STATUS_CMD_NOT_SUPPORTED;
				if (kResponse_OK == GetInitCmdResponse(&initStatus, &initStatusLength, nTimeoutMs, pExitFlag))
					bSuccess = true;
				else if ((sizeof(initStatus) == initStatusLength) && (SKIP_STATUS_ERROR_SLAVE_POWERUP_INIT == initStatus))
				{
					unsigned int nTimeNow = GUtils::OSGetTimeStamp();
					unsigned int nElapsedTimeMs = nTimeNow - nTimeCmdSent;
					if (nElapsedTimeMs < nTimeoutMs)
						GUtils::Sleep(nTimeoutMs - nElapsedTimeMs);
				}
			}
			else
				initStatusLength = 0;
		}

		if (!bSuccess)
			nResult = kResponse_Error;

		UnlockDevice();
	}
	else
		GSTD_ASSERT(0);	// Can't use this device -- some other thread has it open!

	if (pRespBuf && pnRespBytes)
	{
		if (((*pnRespBytes) >= initStatusLength) && (initStatusLength > 0))
		{
			(*pnRespBytes) = initStatusLength;
			memcpy(pRespBuf, &initStatus, initStatusLength);
		}
		else
			(*pnRespBytes) = 0;
	}

	return nResult;
}