static int
VMwareXineramaIsActive(ClientPtr client)
{
    xXineramaIsActiveReply	rep;
    ExtensionEntry *ext;
    ScrnInfoPtr pScrn;
    VMWAREPtr pVMWARE;

    REQUEST_SIZE_MATCH(xXineramaIsActiveReq);

    if (!(ext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) {
       return BadMatch;
    }
    pScrn = ext->extPrivate;
    pVMWARE = VMWAREPTR(pScrn);

    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;
    rep.state = pVMWARE->xinerama;
    if(client->swapped) {
	register int n;
	_swaps(&rep.sequenceNumber, n);
	_swapl(&rep.length, n);
	_swapl(&rep.state, n);
    }
    WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *) &rep);
    return client->noClientException;
}
static int
VMwareXineramaQueryScreens(ClientPtr client)
{
    xXineramaQueryScreensReply	rep;
    ExtensionEntry *ext;
    ScrnInfoPtr pScrn;
    VMWAREPtr pVMWARE;

    REQUEST_SIZE_MATCH(xXineramaQueryScreensReq);

    if (!(ext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) {
       return BadMatch;
    }
    pScrn = ext->extPrivate;
    pVMWARE = VMWAREPTR(pScrn);

    rep.type = X_Reply;
    rep.sequenceNumber = client->sequence;
    rep.number = pVMWARE->xinerama ? pVMWARE->xineramaNumOutputs : 0;
    rep.length = rep.number * sz_XineramaScreenInfo >> 2;
    if(client->swapped) {
       register int n;
       _swaps(&rep.sequenceNumber, n);
       _swapl(&rep.length, n);
       _swapl(&rep.number, n);
    }
    WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *)&rep);

    if(pVMWARE->xinerama) {
       xXineramaScreenInfo scratch;
       int i;

       for(i = 0; i < pVMWARE->xineramaNumOutputs; i++) {
	  scratch.x_org  = pVMWARE->xineramaState[i].x_org;
	  scratch.y_org  = pVMWARE->xineramaState[i].y_org;
	  scratch.width  = pVMWARE->xineramaState[i].width;
	  scratch.height = pVMWARE->xineramaState[i].height;
	  if(client->swapped) {
	     register int n;
	     _swaps(&scratch.x_org, n);
	     _swaps(&scratch.y_org, n);
	     _swaps(&scratch.width, n);
	     _swaps(&scratch.height, n);
	  }
	  WriteToClient(client, sz_XineramaScreenInfo, (char *)&scratch);
       }
    }

    return client->noClientException;
}
static int
VMwareXineramaGetScreenSize(ClientPtr client)
{
    REQUEST(xPanoramiXGetScreenSizeReq);
    WindowPtr				pWin;
    xPanoramiXGetScreenSizeReply	rep;
    register int			n;
    ExtensionEntry *ext;
    ScrnInfoPtr pScrn;
    VMWAREPtr pVMWARE;
    int rc;


    REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
    if (rc != Success)
	return rc;

    if (!(ext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) {
       return BadMatch;
    }
    pScrn = ext->extPrivate;
    pVMWARE = VMWAREPTR(pScrn);

    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;
    rep.width  = pVMWARE->xineramaState[stuff->screen].width;
    rep.height  = pVMWARE->xineramaState[stuff->screen].height;
    rep.window = stuff->window;
    rep.screen = stuff->screen;
    if(client->swapped) {
       _swaps(&rep.sequenceNumber, n);
       _swapl(&rep.length, n);
       _swapl(&rep.width, n);
       _swapl(&rep.height, n);
       _swapl(&rep.window, n);
       _swapl(&rep.screen, n);
    }
    WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *)&rep);
    return client->noClientException;
}
static int
VMwareXineramaQueryVersion(ClientPtr client)
{
    xPanoramiXQueryVersionReply	  rep;
    register int		  n;

    REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq);
    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;
    rep.majorVersion = 1;
    rep.minorVersion = 0;
    if(client->swapped) {
        _swaps(&rep.sequenceNumber, n);
        _swapl(&rep.length, n);
        _swaps(&rep.majorVersion, n);
        _swaps(&rep.minorVersion, n);
    }
    WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), (char *)&rep);
    return (client->noClientException);
}
// Private Methods 
void 
AP_GPS_MTK::_parse_gps(void)
{
	fix				= (_buffer.msg.fix_type == FIX_3D);
	latitude		= _swapl(&_buffer.msg.latitude)  * 10;
	longitude		= _swapl(&_buffer.msg.longitude) * 10;
	altitude		= _swapl(&_buffer.msg.altitude);
	ground_speed	= _swapl(&_buffer.msg.ground_speed);
	ground_course	= _swapl(&_buffer.msg.ground_course) / 10000;
	num_sats		= _buffer.msg.satellites;
			
	// XXX docs say this is UTC, but our clients expect msToW
	time			= _swapl(&_buffer.msg.utc_time);
	_setTime();
	valid_read = true;
	new_data = true;
}
Example #6
0
// Process bytes available from the stream
//
// The stream is assumed to contain only our custom message.  If it
// contains other messages, and those messages contain the preamble bytes,
// it is possible for this code to become de-synchronised.  Without
// buffering the entire message and re-processing it from the top,
// this is unavoidable.
//
// The lack of a standard header length field makes it impossible to skip
// unrecognised messages.
//
bool
AP_GPS_MTK::read(void)
{
    uint8_t	data;
    int		numc;
    bool	parsed = false;

    numc = _port->available();
    for (int i = 0; i < numc; i++) {	// Process bytes received

        // read the next byte
        data = _port->read();

restart:
        switch(_step) {

            // Message preamble, class, ID detection
            //
            // If we fail to match any of the expected bytes, we
            // reset the state machine and re-consider the failed
            // byte as the first byte of the preamble.  This
            // improves our chances of recovering from a mismatch
            // and makes it less likely that we will be fooled by
            // the preamble appearing as data in some other message.
            //
        case 0:
            if(PREAMBLE1 == data)
                _step++;
            break;
        case 1:
            if (PREAMBLE2 == data) {
                _step++;
                break;
            }
            _step = 0;
            goto restart;
        case 2:
            if (MESSAGE_CLASS == data) {
                _step++;
                _ck_b = _ck_a = data;					// reset the checksum accumulators
            } else {
                _step = 0;							// reset and wait for a message of the right class
                goto restart;
            }
            break;
        case 3:
            if (MESSAGE_ID == data) {
                _step++;
                _ck_b += (_ck_a += data);
                _payload_counter = 0;
            } else {
                _step = 0;
                goto restart;
            }
            break;

            // Receive message data
            //
        case 4:
            _buffer.bytes[_payload_counter++] = data;
            _ck_b += (_ck_a += data);
            if (_payload_counter == sizeof(_buffer))
                _step++;
            break;

            // Checksum and message processing
            //
        case 5:
            _step++;
            if (_ck_a != data) {
                _error("GPS_MTK: checksum error\n");
                _step = 0;
            }
            break;
        case 6:
            _step = 0;
            if (_ck_b != data) {
                _error("GPS_MTK: checksum error\n");
                break;
            }

            fix				= (_buffer.msg.fix_type == FIX_3D);
            latitude		= _swapl(&_buffer.msg.latitude)  * 10;
            longitude		= _swapl(&_buffer.msg.longitude) * 10;
            altitude		= _swapl(&_buffer.msg.altitude);
            ground_speed	= _swapl(&_buffer.msg.ground_speed);
            ground_course	= _swapl(&_buffer.msg.ground_course) / 10000;
            num_sats		= _buffer.msg.satellites;

            // time from gps is UTC, but convert here to msToD
            long time_utc	= _swapl(&_buffer.msg.utc_time);
            long temp = (time_utc/10000000);
            time_utc -= temp*10000000;
            time = temp * 3600000;
            temp = (time_utc/100000);
            time_utc -= temp*100000;
            time += temp * 60000 + time_utc;

            parsed = true;
        }
    }
    return parsed;
}