]> git.itanic.dy.fi Git - maemo-mapper/blob - src/aprs.h
Added basic APRS support - Can be disabled by removing definition of INCLUDE_APRS
[maemo-mapper] / src / aprs.h
1 /*
2  * 
3  * This file is part of Maemo Mapper.
4  *
5  * Maemo Mapper is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Maemo Mapper is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Maemo Mapper.  If not, see <http://www.gnu.org/licenses/>.
17  * 
18  * 
19  * Parts of this code have been ported from Xastir by Rob Williams (10 Aug 2008):
20  * 
21  *  * XASTIR, Amateur Station Tracking and Information Reporting
22  * Copyright (C) 1999,2000  Frank Giannandrea
23  * Copyright (C) 2000-2007  The Xastir Group
24  * 
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #    include "config.h"
29 #endif
30
31 #ifdef INCLUDE_APRS
32
33 #ifndef MAEMO_MAPPER_APRS_H
34 #define MAEMO_MAPPER_APRS_H
35
36 #include "types.h"
37 #include <termios.h>
38
39 #define MAX_LINE_SIZE                   512
40 #define MAX_STATUS_LINES                20
41 #define MAX_COMMENT_LINES               20
42 #define EARTH_RADIUS_METERS     6378138.0
43 #define MAX_TACTICAL_CALL               20
44 #define TACTICAL_HASH_SIZE              1024
45
46
47 #define START_STR " }"
48 #define LBRACE '{'
49 #define RBRACE '}'
50
51
52
53 #define MAX_DEVICE_NAME 128
54 #define MAX_DEVICE_BUFFER_UNTIL_BINARY_SWITCH 700
55 #define MAX_DEVICE_HOSTNM 40
56 #define MAX_DEVICE_HOSTPW 40
57
58 // KISS Protocol Special Characters & Commands:
59 #define KISS_FEND           0xc0  // Frame End
60 #define KISS_FESC           0xdb  // Frame Escape
61 #define KISS_TFEND          0xdc  // Transposed Frame End
62 #define KISS_TFESC          0xdd  // Transposed Frame Escape
63 #define KISS_DATA           0x00
64 #define KISS_TXDELAY        0x01
65 #define KISS_PERSISTENCE    0x02
66 #define KISS_SLOTTIME       0x03
67 #define KISS_TXTAIL         0x04
68 #define KISS_FULLDUPLEX     0x05
69 #define KISS_SETHARDWARE    0x06
70 #define KISS_RETURN         0xff
71
72
73 enum Device_Types {
74     DEVICE_NONE,
75     DEVICE_SERIAL_TNC,
76     DEVICE_NET_STREAM,
77     DEVICE_AX25_TNC,
78     DEVICE_SERIAL_KISS_TNC,     // KISS TNC on serial port (not ax.25 kernel device)
79     DEVICE_SERIAL_MKISS_TNC     // Multi-port KISS TNC, like the Kantronics KAM
80 };
81
82 enum Device_Active {
83     DEVICE_NOT_IN_USE,
84     DEVICE_IN_USE
85 };
86
87 enum Device_Status {
88     DEVICE_DOWN,
89     DEVICE_UP,
90     DEVICE_ERROR
91 };
92
93
94
95
96 typedef struct {
97     int    device_type;                           /* device type                             */
98     int    active;                                /* channel in use                          */
99     int    status;                                /* current status (up or down)             */
100     char   device_name[MAX_DEVICE_NAME+1];        /* device name                             */
101     char   device_host_name[MAX_DEVICE_HOSTNM+1]; /* device host name for network            */
102     unsigned long int address;                    /* socket address for network              */
103     int    thread_status;                         /* thread status for connect thread        */
104     int    connect_status;                        /* connect status for connect thread       */
105     int    decode_errors;                         /* decode error count, used for data type  */
106     int    data_type;                             /* 0=normal 1=wx_binary                    */
107     int    socket_port;                           /* socket port# for network                */
108     char   device_host_pswd[MAX_DEVICE_HOSTPW+1]; /* host password                           */
109     int    channel;                               /* for serial and net ports                */
110     int    channel2;                              /* for AX25 ports                          */
111     char   ui_call[30];                           /* current call for this port              */
112     struct termios t,t_old;                       /* terminal struct for serial port         */
113     int    dtr;                                   /* dtr signal for HSP cable (status)       */
114     int    sp;                                    /* serial port speed                       */
115     int    style;                                 /* serial port style                       */
116     int    scan;                                  /* data read available                     */
117     int    errors;                                /* errors for this port                    */
118     int    reconnect;                             /* reconnect on net failure                */
119     int    reconnects;                            /* total number of reconnects by this port */
120     unsigned long   bytes_input;                  /* total bytes read by this port           */
121     unsigned long   bytes_output;                 /* total bytes written by this port        */
122     unsigned long   bytes_input_last;             /* total bytes read last check             */
123     unsigned long   bytes_output_last;            /* total bytes read last check             */
124     int    port_activity;                         /* 0 if no activity between checks         */
125     pthread_t read_thread;                        /* read thread                             */
126     int    read_in_pos;                           /* current read buffer input pos           */
127     int    read_out_pos;                          /* current read buffer output pos          */
128     char   device_read_buffer[MAX_DEVICE_BUFFER]; /* read buffer for this port               */
129     pthread_mutex_t read_lock;                       /* Lock for reading the port data          */
130     pthread_t write_thread;                       /* write thread                            */
131     int    write_in_pos;                          /* current write buffer input pos          */
132     int    write_out_pos;                         /* current write buffer output pos         */
133     pthread_mutex_t write_lock;                      /* Lock for writing the port data          */
134     char   device_write_buffer[MAX_DEVICE_BUFFER];/* write buffer for this port              */
135 } iface;
136
137 extern iface port_data;     // shared port data
138 extern TWriteBuffer _write_buffer[APRS_PORT_COUNT];
139
140 // Incoming data queue
141 typedef struct _incoming_data_record {
142     int length;   // Used for binary strings such as KISS
143     int port;
144     unsigned char data[MAX_LINE_SIZE];
145 } incoming_data_record;
146
147 gboolean aprs_server_connect(void); // Called from menu.c 
148 void aprs_server_disconnect(void);  // Called from menu.c
149
150 void aprs_init(void);                           // Called form main.c
151
152 void map_render_aprs();
153 double distance_from_my_station(char *call_sign, char *course_deg, gint course_len);
154
155 void pad_callsign(char *callsignout, char *callsignin);
156 gboolean aprs_send_beacon(TAprsPort port);
157 gboolean aprs_send_beacon_inet();
158 void update_aprs_inet_options(gboolean force);
159 void port_write_string(gchar *data, gint len, TAprsPort port);
160
161 extern AprsDataRow *station_shortcuts[16384];
162
163 #endif /* ifndef MAEMO_MAPPER_APRS_H */
164
165 #endif // INCLUDE_APRS