1 /*
2 
3     Implementation of special data used by Garmin products.
4 
5     Copyright (C) 2006 Olaf Klein, o.b.klein@gpsbabel.org
6 
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
20 
21  */
22 
23 #ifndef GARMIN_FS_H
24 #define GARMIN_FS_H
25 
26 #include <ctype.h>
27 #include "defs.h"
28 #include "jeeps/gps.h"
29 
30 /* this order is used by most devices */
31 /* typedef enum {
32 	garmin_display_symbol_and_name = 0,
33 	garmin_display_symbol_only = 1,
34 	garmin_display_symbol_and_description = 2
35 } garmin_display_t;
36 */
37 
38 /* macros */
39 
40 #define GMSD_FIND(a) (garmin_fs_t *) fs_chain_find((a)->fs, FS_GMSD)
41 #define GMSD_HAS(a) (gmsd && gmsd->flags.a)
42 
43 /* GMSD_GET(a,b): a = any gmsd field, b = default value */
44 #define GMSD_GET(a,b) ((gmsd) && (gmsd->flags.a)) ? (gmsd->a) : (b)
45 
46 /* GMSD_SET(a,b): a = numeric gmsd field, b = numeric source */
47 #define GMSD_SET(a,b) if (gmsd) {gmsd->a = (b); gmsd->flags.a = 1; }
48 
49 /* GMSD_UNSET(a): a = gmsd field */
50 #define GMSD_UNSET(a) if (gmsd) { gmsd->flags.a = 0; }
51 
52 /* GMSD_SETSTR(a,b): a = gmsd field, b = null terminated source */
53 #define GMSD_SETSTR(a,b) if (gmsd && (b) && (b)[0]) { gmsd->a = xstrdup((b)); gmsd->flags.a = 1; }
54 
55 /* GMSD_SETNSTR(a,b,c): a = gmsd field, b = source, c = sizeof(source) */
56 #define GMSD_SETNSTR(a,b,c) if (gmsd && (b) && (b)[0]) { gmsd->a = xstrndup((b),(c)); gmsd->flags.a = 1; }
57 
58 /* GMSD_GETNSTR(a,b,c): a = gmsd field, b = target, c = sizeof(target) */
59 #define GMSD_GETNSTR(a,b,c) if (gmsd && gmsd->flags.a) strncpy((b),gmsd->a,(c))
60 
61 typedef struct garmin_ilink_s {
62   int ref_count;
63   double lat, lon, alt;
64   struct garmin_ilink_s* next;
65 } garmin_ilink_t;
66 
67 typedef struct {
68   unsigned int icon:1;
69   unsigned int wpt_class:1;
70   unsigned int display:1;
71   unsigned int category:1;
72   unsigned int city:1;
73   unsigned int state:1;
74   unsigned int facility:1;
75   unsigned int cc:1;
76   unsigned int cross_road:1;
77   unsigned int addr:1;
78   unsigned int country:1;
79   unsigned int phone_nr:1;
80   unsigned int phone_nr2:1;
81   unsigned int fax_nr:1;
82   unsigned int postal_code:1;
83   unsigned int email:1;
84 #ifdef GMSD_EXPERIMENTAL
85   unsigned int subclass:1;
86 #endif
87 } garmin_fs_flags_t;
88 
89 typedef struct garmin_fs_s {
90   format_specific_data fs;
91   garmin_fs_flags_t flags;
92 
93   int protocol;		/* ... used by device (-1 is MapSource) */
94 
95   gbint32 icon;
96   int wpt_class;
97   gbint32 display;
98   gbint16 category;
99   char* city;			/* city name */
100   char* facility;			/* facility name */
101   char* state;			/* state */
102   char* cc;			/* country code */
103   char* cross_road;		/* Intersection road label */
104   char* addr;			/* address + number */
105   char* country;			/* country */
106   char* phone_nr;			/* phone number */
107   char* phone_nr2;		/* phone number (2) */
108   char* fax_nr;			/* fax number */
109   char* postal_code;		/* postal code */
110   char* email;			/* email address */
111   garmin_ilink_t* ilinks;
112 #ifdef GMSD_EXPERIMENTAL
113   char subclass[22];
114 #endif
115 } garmin_fs_t, *garmin_fs_p;
116 
117 garmin_fs_t* garmin_fs_alloc(const int protocol);
118 void garmin_fs_destroy(void* fs);
119 void garmin_fs_copy(garmin_fs_t** dest, garmin_fs_t* src);
120 void garmin_fs_convert(void* fs);
121 char* garmin_fs_xstrdup(const char* src, size_t size);
122 
123 /* for GPX */
124 void garmin_fs_xml_convert(const int base_tag, int tag, const char* cdatastr, waypoint* waypt);
125 void garmin_fs_xml_fprint(gbfile* ofd, const waypoint* waypt);
126 
127 /* common garmin_fs utilities */
128 
129 /* ..convert_category: returns 1=OK; 0=Unable to convert category */
130 unsigned char garmin_fs_convert_category(const char* category_name, gbuint16* category);
131 
132 /* ..merge_category: returns 1=OK; 0=Unable to convert category */
133 unsigned char garmin_fs_merge_category(const char* category_name, waypoint* waypt);
134 
135 #define GMSD_SECTION_CATEGORIES "Garmin Categories"
136 
137 void garmin_fs_garmin_after_read(const GPS_PWay way, waypoint* wpt, const int protoid);
138 void garmin_fs_garmin_before_write(const waypoint* wpt, GPS_PWay way, const int protoid);
139 
140 #endif
141