1 /*
2     Abstraction of underlying device types, serial or USB.  OS agnostic..
3 
4     Copyright (C) 2006 Robert Lipe, robertlipe@usa.net
5 
6     This program is free software{} you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation{} either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY{} without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program{} if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
19 
20  */
21 
22 #include "gps.h"
23 #include "gpsdevice.h"
24 #include "gpsserial.h"
25 
26 extern gps_device_ops gps_serial_ops;
27 extern gps_device_ops gps_usb_ops;
28 gps_device_ops* ops = NULL;
29 
GPS_Device_On(const char * port,gpsdevh ** fd)30 int32  GPS_Device_On(const char* port, gpsdevh** fd)
31 {
32   gps_is_usb = (0 == case_ignore_strncmp(port, "usb:", 4));
33 
34   if (gps_is_usb) {
35     ops = &gps_usb_ops;
36   } else {
37     ops = &gps_serial_ops;
38   }
39 
40   return (ops->Device_On)(port, fd);
41 }
42 
GPS_Device_Off(gpsdevh * fd)43 int32  GPS_Device_Off(gpsdevh* fd)
44 {
45   return (ops->Device_Off)(fd);
46 }
47 
GPS_Device_Wait(gpsdevh * fd)48 int32  GPS_Device_Wait(gpsdevh* fd)
49 {
50   return (ops->Device_Wait)(fd);
51 }
52 
GPS_Device_Chars_Ready(gpsdevh * fd)53 int32  GPS_Device_Chars_Ready(gpsdevh* fd)
54 {
55   return (ops->Device_Chars_Ready)(fd);
56 }
57 
GPS_Device_Flush(gpsdevh * fd)58 int32  GPS_Device_Flush(gpsdevh* fd)
59 {
60   return (ops->Device_Flush)(fd);
61 }
62 
GPS_Write_Packet(gpsdevh * fd,GPS_PPacket packet)63 int32  GPS_Write_Packet(gpsdevh* fd, GPS_PPacket packet)
64 {
65   return (ops->Write_Packet)(fd, packet);
66 }
67 
GPS_Packet_Read(gpsdevh * fd,GPS_PPacket * packet)68 int32 GPS_Packet_Read(gpsdevh* fd, GPS_PPacket* packet)
69 {
70   return (ops->Read_Packet)(fd, packet);
71 }
72 
GPS_Send_Ack(gpsdevh * fd,GPS_PPacket * tra,GPS_PPacket * rec)73 int32 GPS_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec)
74 {
75   return (ops->Send_Ack)(fd, tra, rec);
76 }
77 
GPS_Get_Ack(gpsdevh * fd,GPS_PPacket * tra,GPS_PPacket * rec)78 int32 GPS_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec)
79 {
80   return (ops->Get_Ack)(fd, tra, rec);
81 }
82 
GPS_Make_Packet(GPS_PPacket * packet,US type,UC * data,uint32 n)83 void GPS_Make_Packet(GPS_PPacket* packet, US type, UC* data, uint32 n)
84 {
85   (*packet)->type = type;
86   memcpy((*packet)->data, data, n);
87   (*packet)->n = n;
88 }
89