Esempio n. 1
0
DWORD GpsIdPort::RxThread() {
    DWORD rc = 0;
    const int nh = 2;
    HANDLE handles[nh] = {0};
    handles[0] = _hLoc;
    handles[1] = _hState;

    GPS_POSITION loc = {0};
    GPSResetData(loc);

    GPS_DEVICE dev = {0};
    GPSResetData(dev);

    bool listen = true;
    while (listen && !StopEvt.tryWait(0)) {
        DWORD dw = ::WaitForMultipleObjects(nh, handles, FALSE, 100);
        switch (dw) {
            case WAIT_OBJECT_0:
                rc = GPSGetPosition(_hGPS, &loc, 10000, 0);
                if(ERROR_SUCCESS == rc) {
                    AddStatRx(1);
                    NMEAParser::ParseGPS_POSITION(GetPortIndex(), loc, GPS_INFO);
                }
                GPSResetData(loc);
                break;
            case WAIT_OBJECT_0 + 1:
                rc = GPSGetDeviceState(&dev);
                if(ERROR_SUCCESS == rc) {
                    AddStatRx(1);
                    StartupStore(_T("GPSID : DeviceState: %lX, ServiceState: %lX%s"), dev.dwDeviceState, dev.dwServiceState, NEWLINE);
                }
                GPSResetData(dev);
                break;
            case WAIT_FAILED:
                listen = false;
                rc = ::GetLastError();
                break;
            case WAIT_TIMEOUT:
                break;
        }
    }

    return rc;
}
Esempio n. 2
0
size_t SerialPort::Read(void *szString, size_t size) {
    if (hPort != INVALID_HANDLE_VALUE) {
        DWORD dwBytesTransferred = 0U;
        if (ReadFile(hPort, szString, size, &dwBytesTransferred, (OVERLAPPED *) NULL)) {
            AddStatRx(dwBytesTransferred);
            return dwBytesTransferred;
        }
    }
    return 0U;
}