Ejemplo n.º 1
0
extern "C" BOOL	ReadByteEx (BYTE *data, int timeout, BOOL warn)
{
	if(data == NULL)
		return FALSE;
	if (ParPort == -1)
	{
		DWORD BytesReceived = 0;
		FT_SetTimeouts(ftHandleA,timeout*1000,0);
		ftStatus = FT_Read(ftHandleA,RxBuffer,1,&BytesReceived);
		if (ftStatus == FT_OK)
		{
			if (BytesReceived == 1)
			{
				// FT_Read OK
				*data = RxBuffer[0];
				return TRUE;
			}
			else
			{
				// FT_Read Timeout
				if (warn)
					MessageBox(topHWnd, "USB Error: Read Timeout", "ReadByteEx", MB_OK | MB_ICONERROR);
				return FALSE;
			}
		}
		else
		{
			// FT_Read Failed
			if (warn)
				MessageBox(topHWnd, "USB Error: Read Failed", "ReadByteEx", MB_OK | MB_ICONERROR);
			return FALSE;
		}
	}
	else
	{
		BYTE a, b;
		time_t starttime = time(NULL);
		shadow |= 0x20;
		pwControl(shadow);	// set port to input mode
		b = prStatus();		// wait for ACK
		while (!((b ^ c) & 0x20))
		{
			b = prStatus();
			if (time(NULL) > starttime + (time_t)timeout)
			{
				if (warn)
					MessageBox(topHWnd, "Timeout on data transfer!", "ReadByte", MB_OK | MB_ICONERROR);
				return FALSE;
			}
		}
		c = b;
		a = prData();		// read data
		shadow ^= 0x02;
		pwControl(shadow);	// signal byte received
		*data = a;
		return TRUE;
	}
}
// -----------------------------------------------------------------------------
// CPIMAgnToDoAdapter::ReadIntFieldsL
// (other items were commented in a header)
// -----------------------------------------------------------------------------
//
void CPIMAgnToDoAdapter::ReadIntFieldsL(MPIMItemData& aData, CCalEntry& aEntry)
{
    JELOG2(EPim);
    // Convert synchornization field to PIM API. The default value is private
    // and unrecognized priority values are mapped also to private due to
    // security reasons
    TPIMToDoClassValue value = EPIMToDoClassPrivate;
    const CCalEntry::TReplicationStatus status = aEntry.ReplicationStatusL();
    if (status == CCalEntry::EOpen)
    {
        // Open is mapped as public synhronization
        value = EPIMToDoClassPublic;
    }
    else if (status == CCalEntry::ERestricted)
    {
        // Open is mapped as user confidential synhronization
        value = EPIMToDoClassConfidential;
    }
    // Note that boolean and integer fields must be identified in the constructor
    TPIMFieldData classData(EPIMToDoClass, EPIMFieldInt, KPIMAttrNone, value);
    aData.AddValueL(classData);

    // Default value is zero acording to vCalendar specification. PIM API default
    // priority is medium which indicates normal native priority
    // See common/pimtodo.h for platform-specific native priorities.
    TUint nativePriority = aEntry.PriorityL();
    TPIMToDoPriority priority = EPIMToDoPriorityMedium;
    if (nativePriority == EPIMToDoNativePriorityHigh)
    {
        // Native priority value High is mapped to value 1
        priority = EPIMToDoPriorityHigh;
    }
    else if (nativePriority == EPIMToDoNativePriorityLow)
    {
        // Native priority value Low is mapped to value 7
        priority = EPIMToDoPriorityLow;
    }
    // Note that boolean and integer fields must be identified in the constructor
    TPIMFieldData
    prData(EPIMToDoPriority, EPIMFieldInt, KPIMAttrNone, priority);
    aData.AddValueL(prData);
}