altos: Expose ao_gps_set_rate from u-blox driver
[fw/altos] / libaltos / libaltos.c
index 69a6735f50e72febc28db62726d9f80760d2a8f7..b7ec98fc58f5c17994c523955b4e20c6d680f23d 100644 (file)
@@ -53,6 +53,8 @@ altos_get_last_error(struct altos_error *error)
 
 #ifdef DARWIN
 
+#include <unistd.h>
+
 #undef USE_POLL
 
 /* Mac OS X don't have strndup even if _GNU_SOURCE is defined */
@@ -765,6 +767,7 @@ altos_bt_open(struct altos_bt_device *device)
                altos_set_last_posix_error();
                goto no_link;
        }
+       usleep(100 * 1000);
 
 #ifdef USE_POLL
        pipe(file->pipe);
@@ -814,7 +817,7 @@ get_string(io_object_t object, CFStringRef entry, char *result, int result_len)
                got_string = CFStringGetCString(entry_as_string,
                                                result, result_len,
                                                kCFStringEncodingASCII);
-    
+
                CFRelease(entry_as_string);
                if (got_string)
                        return 1;
@@ -827,7 +830,7 @@ get_number(io_object_t object, CFStringRef entry, int *result)
 {
        CFTypeRef entry_as_number;
        Boolean got_number;
-       
+
        entry_as_number = IORegistryEntrySearchCFProperty (object,
                                                           kIOServicePlane,
                                                           entry,
@@ -882,19 +885,10 @@ altos_list_next(struct altos_list *list, struct altos_device *device)
                object = IOIteratorNext(list->iterator);
                if (!object)
                        return 0;
-  
+
                if (!get_number (object, CFSTR(kUSBVendorID), &device->vendor) ||
                    !get_number (object, CFSTR(kUSBProductID), &device->product))
                        continue;
-               if (list->ftdi) {
-                       if (device->vendor != 0x0403)
-                               continue;
-               } else {
-                       if (device->vendor != 0xfffe)
-                               continue;
-                       if (device->product < 0x000a || 0x0013 < device->product)
-                               continue;
-               }
                if (get_string (object, CFSTR("IOCalloutDevice"), device->path, sizeof (device->path)) &&
                    get_string (object, CFSTR("USB Product Name"), device->name, sizeof (device->name)) &&
                    get_string (object, CFSTR("USB Serial Number"), serial_string, sizeof (serial_string))) {
@@ -993,6 +987,11 @@ log_message(char *fmt, ...)
        if (!log)
                log = fopen("\\temp\\altos.txt", "w");
        if (log) {
+               SYSTEMTIME time;
+               GetLocalTime(&time);
+               fprintf (log, "%4d-%02d-%02d %2d:%02d:%02d. ",
+                        time.wYear, time.wMonth, time.wDay,
+                        time.wHour, time.wMinute, time.wSecond);
                va_start(a, fmt);
                vfprintf(log, fmt, a);
                va_end(a);
@@ -1338,9 +1337,10 @@ altos_open(struct altos_device *device)
                file->handle = open_serial(full_name);
                if (file->handle != INVALID_HANDLE_VALUE)
                        break;
+               altos_set_last_windows_error();
                Sleep(100);
        }
-       
+
        if (file->handle == INVALID_HANDLE_VALUE) {
                free(file);
                return NULL;
@@ -1372,13 +1372,19 @@ altos_open(struct altos_device *device)
 PUBLIC void
 altos_close(struct altos_file *file)
 {
-       if (file->handle != INVALID_HANDLE_VALUE) {
-               CloseHandle(file->handle);
+       HANDLE  handle = file->handle;
+       if (handle != INVALID_HANDLE_VALUE) {
+               HANDLE  ov_read = file->ov_read.hEvent;
+               HANDLE  ov_write = file->ov_write.hEvent;
+               file->handle = INVALID_HANDLE_VALUE;
+               file->ov_read.hEvent = INVALID_HANDLE_VALUE;
+               file->ov_write.hEvent = INVALID_HANDLE_VALUE;
+               PurgeComm(handle, PURGE_RXABORT|PURGE_RXCLEAR|PURGE_TXABORT|PURGE_TXCLEAR);
+               Sleep(100);
+               CloseHandle(handle);
                file->handle = INVALID_HANDLE_VALUE;
-               SetEvent(file->ov_read.hEvent);
-               SetEvent(file->ov_write.hEvent);
-               CloseHandle(file->ov_read.hEvent);
-               CloseHandle(file->ov_write.hEvent);
+               CloseHandle(ov_read);
+               CloseHandle(ov_write);
        }
 }