Ticket #332: windows_vehicle.patch

File windows_vehicle.patch, 8.3 KB (added by richt, 10 years ago)
  • Makefile.am

     
    11include $(top_srcdir)/Makefile.inc
    22AM_CPPFLAGS = @NAVIT_CFLAGS@ -I$(top_srcdir)/navit
    3 modulevehicle_LTLIBRARIES = libvehicle_file.la libvehicle_pipe.la libvehicle_socket.la
     3modulevehicle_LTLIBRARIES = libvehicle_file.la libvehicle_pipe.la libvehicle_socket.la libvehicle_serial.la
    44libvehicle_file_la_CFLAGS=-DMODULE=vehicle_file
    55libvehicle_file_la_SOURCES = vehicle_file.c
    66libvehicle_file_la_LDFLAGS = -module -avoid-version @NAVIT_MODULE_LDFLAGS@
     
    1010libvehicle_socket_la_CFLAGS=-DMODULE=vehicle_socket
    1111libvehicle_socket_la_SOURCES = vehicle_socket.c
    1212libvehicle_socket_la_LDFLAGS = -module -avoid-version @NAVIT_MODULE_LDFLAGS@
     13libvehicle_serial_la_CFLAGS=-DMODULE=vehicle_serial
     14libvehicle_serial_la_SOURCES = vehicle_serial.c
     15libvehicle_serial_la_LDFLAGS = -module -avoid-version @NAVIT_MODULE_LDFLAGS@
  • vehicle_file.c

     
    4444#include <netinet/in.h>
    4545#include <arpa/inet.h>
    4646#endif
     47#ifdef HAVE_WINSOCK
     48#include <winsock.h>
     49#endif
    4750
    4851static void vehicle_file_disable_watch(struct vehicle_priv *priv);
    4952static void vehicle_file_enable_watch(struct vehicle_priv *priv);
     
    5356
    5457
    5558enum file_type {
    56         file_type_pipe = 1, file_type_device, file_type_file, file_type_socket
     59        file_type_pipe = 1, file_type_device, file_type_file, file_type_socket, file_type_serial
    5760};
    5861
    5962static int buffer_size = 1024;
     
    9699        int no_data_count;
    97100        struct event_timeout * timeout;
    98101        struct callback *timeout_callback;
    99 #else
     102#endif
    100103        enum file_type file_type;
    101104        FILE *file;
    102105        struct event_watch *watch;
    103 #endif
    104106        speed_t baudrate;
    105107        struct attr ** attrs;
    106108        char fixiso8601[128];
     
    205207static int
    206208vehicle_file_open(struct vehicle_priv *priv)
    207209{
    208 #ifdef _WIN32
    209     dbg(1, "enter, priv->source='%s'\n", priv->source);
    210 
    211     if ( priv->source )
    212     {
    213         char* raw_setting_str = g_strdup( priv->source );
    214 
    215         char* strport = strchr(raw_setting_str, ':' );
    216         char* strsettings = strchr(raw_setting_str, ' ' );
    217 
    218         if ( strport && strsettings )
    219         {
    220             strport++;
    221             *strsettings = '\0';
    222             strsettings++;
    223 
    224             priv->fd=serial_io_init( strport, strsettings );
    225         }
    226         g_free( raw_setting_str );
    227 
    228         // Add the callback
    229         dbg(2, "Add the callback ...\n", priv->source);
    230                 priv->timeout_callback=callback_new_1(callback_cast(vehicle_win32_serial_track), priv);
    231     }
    232 #else
    233210        char *name;
    234211        struct stat st;
     212#ifndef _WIN32
    235213        struct termios tio;
     214#else
     215        #define O_NDELAY 0
     216#endif
    236217
    237218        name = priv->source + 5;
    238219        if (!strncmp(priv->source, "file:", 5)) {
     
    242223                stat(name, &st);
    243224                if (S_ISREG(st.st_mode)) {
    244225                        priv->file_type = file_type_file;
    245                 } else {
     226                }
     227#ifndef _WIN32
     228                else {
    246229                        tcgetattr(priv->fd, &tio);
    247230                        cfmakeraw(&tio);
    248231                        cfsetispeed(&tio, priv->baudrate);
     
    258241                        return 0;
    259242                priv->fd = fileno(priv->file);
    260243                priv->file_type = file_type_pipe;
    261 #ifdef HAVE_SOCKET
     244#endif //!_WIN32
     245#if defined(HAVE_SOCKET) || defined(HAVE_WINSOCK)
    262246        } else if (!strncmp(priv->source,"socket:", 7)) {
     247                #ifdef _WIN32
     248                WSADATA wsi;
     249                WSAStartup(0x00020002,&wsi);
     250                #endif
    263251                char *p,*s=g_strdup(priv->source+7);
    264252                struct sockaddr_in sin;
    265253                p=strchr(s,':');
     
    285273                        }
    286274                }
    287275                priv->file_type = file_type_socket;
    288 #endif
    289         }
    290 #endif
     276#endif //HAVE_SOCKET
     277        } else if (!strncmp(priv->source,"serial:",7)) {
     278#ifdef _WIN32
     279                char* raw_setting_str = g_strdup( priv->source );
     280
     281                char* strport = strchr(raw_setting_str, ':' );
     282                char* strsettings = strchr(raw_setting_str, ' ' );
     283
     284                if ( strport && strsettings )
     285                {
     286                    strport++;
     287                    *strsettings = '\0';
     288                    strsettings++;
     289
     290                    priv->fd=serial_io_init( strport, strsettings );
     291                }
     292                g_free( raw_setting_str );
     293                priv->file_type = file_type_serial;
     294                // Add the callback
     295                dbg(2, "Add the callback ...\n", priv->source);
     296                        priv->timeout_callback=callback_new_1(callback_cast(vehicle_win32_serial_track), priv);
     297#else
     298                //TODO - add linux serial
     299#endif //!_WIN32
     300    }
    291301    return(priv->fd != -1);
    292302}
    293303
     
    310320                priv->timeout_callback=NULL;    // dangling pointer! prevent double freeing.
    311321    }
    312322        serial_io_shutdown( priv->fd );
    313 #else
     323#else //!_WIN32
    314324        if (priv->file)
    315325                pclose(priv->file);
    316326        else if (priv->fd >= 0)
    317327                close(priv->fd);
    318328        priv->file = NULL;
    319 #endif
     329#endif //!_WIN32
    320330        priv->fd = -1;
    321331}
    322332
     
    457467                g_free(priv->nmea_data);
    458468                priv->nmea_data=priv->nmea_data_buf;
    459469                priv->nmea_data_buf=NULL;
    460 #ifndef _WIN32
    461470                if (priv->file_type == file_type_file) {
    462471                        if (priv->watch) {
    463472                                vehicle_file_disable_watch(priv);
    464473                                event_add_timeout(priv->time, 0, priv->cbt);
    465474                        }
    466475                }
    467 #endif
    468476        }
    469477        if (!strncmp(buffer, "$GPVTG", 6)) {
    470478                /* 0      1      2 34 5    6 7   8
     
    583591*****************************************************************************
    584592* @param      priv : pointer on the private data of the plugin
    585593*****************************************************************************
    586 * @remarks Not used on WIN32 operating system
     594* @remarks
    587595*****************************************************************************
    588596**/
    589597static void
    590598vehicle_file_io(struct vehicle_priv *priv)
    591599{
    592600        dbg(1, "vehicle_file_io : enter\n");
    593 #ifndef _WIN32
    594601        int size, rc = 0;
    595602        char *str, *tok;
    596603
     
    635642        }
    636643        if (rc)
    637644                callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
    638 #endif
    639645}
    640646
    641647//***************************************************************************
     
    652658        dbg(1, "enter\n");
    653659#ifdef _WIN32
    654660        // add an event : don't use glib timers and g_timeout_add
     661    if (priv->file_type == file_type_serial)
     662    {
    655663        if (priv->timeout_callback != NULL)
    656         priv->timeout = event_add_timeout(500, 1, priv->timeout_callback);
     664            priv->timeout = event_add_timeout(500, 1, priv->timeout_callback);
     665        else
     666            dbg(1, "error : watch not enabled : priv->timeout_callback is null\n"); }
    657667    else
    658         dbg(1, "error : watch not enabled : priv->timeout_callback is null\n");
    659 #else
     668#endif
     669    {
    660670        if (! priv->watch)
    661671                priv->watch = event_add_watch((void *)priv->fd, event_watch_cond_read, priv->cb);
    662 #endif
     672    }
    663673}
    664674
    665675//***************************************************************************
     
    675685{
    676686        dbg(1, "vehicle_file_disable_watch : enter\n");
    677687#ifdef _WIN32
     688    if(priv->file_type == file_type_serial)
     689    {
    678690    if (priv->timeout) {
    679691                event_remove_timeout(priv->timeout);
    680692                priv->timeout=NULL;             // dangling pointer! prevent double freeing.
     693        }
    681694    }
    682 #else
     695    else
     696#endif //!_WIN32
     697    {
    683698        if (priv->watch)
    684699                event_remove_watch(priv->watch);
    685700        priv->watch = NULL;
    686 #endif
     701    }
    687702}
    688703
    689704//***************************************************************************
     
    969984        plugin_register_vehicle_type("file", vehicle_file_new_file);
    970985        plugin_register_vehicle_type("pipe", vehicle_file_new_file);
    971986        plugin_register_vehicle_type("socket", vehicle_file_new_file);
     987        plugin_register_vehicle_type("serial", vehicle_file_new_file);
    972988}
  • vehicle_serial.c

     
     1/**
     2 * Navit, a modular navigation system.
     3 * Copyright (C) 2005-2010 Navit Team
     4 *
     5 * This program is free software; you can redistribute it and/or
     6 * modify it under the terms of the GNU General Public License
     7 * version 2 as published by the Free Software Foundation.
     8 *
     9 * This program is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with this program; if not, write to the
     16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17 * Boston, MA  02110-1301, USA.
     18 */
     19
     20#include "config.h"
     21#include "plugin.h"
     22
     23void
     24plugin_init(void)
     25{
     26        plugin_get_vehicle_type("file");
     27}