]> git.itanic.dy.fi Git - maemo-mapper/blobdiff - src/types.h
Added basic APRS support - Can be disabled by removing definition of INCLUDE_APRS
[maemo-mapper] / src / types.h
index 08fa06462636c9fb56e940722ccc2d836a4efac6..85bdb9b28517d10f50f6c51a0e2b2d51c9d47b19 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with Maemo Mapper.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  
+ * Parts of this code have been ported from Xastir by Rob Williams (10 Aug 2008):
+ * 
+ *  * XASTIR, Amateur Station Tracking and Information Reporting
+ * Copyright (C) 1999,2000  Frank Giannandrea
+ * Copyright (C) 2000-2007  The Xastir Group
+ * 
  */
 
 #ifndef MAEMO_MAPPER_TYPES_H
 #define MAEMO_MAPPER_TYPES_H
 
+
+#ifdef HAVE_CONFIG_H
+#    include "config.h"
+#endif
+
 #include <time.h>
 #include <gdbm.h>
 #include <gtk/gtk.h>
 #include "sqlite3.h"
 #endif
 
+// Latitude and longitude string formats.
+#define CONVERT_HP_NORMAL       0
+#define CONVERT_HP_NOSP         1
+#define CONVERT_LP_NORMAL       2
+#define CONVERT_LP_NOSP         3
+#define CONVERT_DEC_DEG         4
+#define CONVERT_UP_TRK          5
+#define CONVERT_DMS_NORMAL      6
+#define CONVERT_VHP_NOSP        7
+#define CONVERT_DMS_NORMAL_FORMATED      8
+#define CONVERT_HP_NORMAL_FORMATED       9
+#define CONVERT_DEC_DEG_N       10
+
+#define MAX_DEVICE_BUFFER       4096
+
 /** This enumerated type defines the possible connection states. */
 typedef enum
 {
@@ -224,6 +252,9 @@ typedef enum
     COLORABLE_ROUTE_WAY,
     COLORABLE_ROUTE_BREAK,
     COLORABLE_POI,
+#ifdef INCLUDE_APRS
+    COLORABLE_APRS_STATION,
+#endif // INCLUDE_APRS
     COLORABLE_ENUM_COUNT
 } Colorable;
 
@@ -238,9 +269,23 @@ typedef enum
     NSEW_DDPDDDDD,
     NSEW_DD_MMPMMM,
     NSEW_DD_MM_SSPS,
+    IARU_LOC,
+    UK_OSGB,
+    UK_NGR,
     DEG_FORMAT_ENUM_COUNT
 } DegFormat;
 
+typedef struct _CoordFormatSetup CoordFormatSetup;
+struct _CoordFormatSetup 
+{
+       gchar    *name;
+       gchar    *short_field_1;
+       gchar    *long_field_1;
+       gchar    *short_field_2;
+       gchar    *long_field_2;
+       gboolean field_2_in_use;
+} _CoordFormatSetup;
+
 typedef enum
 {
     SPEED_LOCATION_BOTTOM_LEFT,
@@ -457,4 +502,460 @@ struct _BrowseInfo {
     GtkWidget *txt;
 };
 
+
+#ifdef INCLUDE_APRS
+
+// --------------------------------------------------------------------------------------
+// Start of APRS Types - Code taken from Xastir code 25 March 2008 by Rob Williams
+// Modification made to fit in with Maemo mapper
+// --------------------------------------------------------------------------------------
+
+typedef struct _TWriteBuffer TWriteBuffer;
+struct _TWriteBuffer
+{
+    int    write_in_pos;                          /* current write buffer input pos          */
+    int    write_out_pos;                         /* current write buffer output pos         */
+    GMutex* write_lock;                      /* Lock for writing the port data          */
+    char   device_write_buffer[MAX_DEVICE_BUFFER];/* write buffer for this port              */
+    int    errors;
+};
+
+
+typedef enum
+{
+       TNC_CONNECTION_BT,
+       TNC_CONNECTION_FILE
+} TTncConnection;
+
+typedef enum
+{
+       APRS_PORT_INET,
+       APRS_PORT_TTY,
+       APRS_PORT_COUNT
+} TAprsPort;
+
+// We should probably be using APRS_DF in extract_bearing_NRQ()
+// and extract_omnidf() functions.  We aren't currently.
+/* Define APRS Types */
+enum APRS_Types {
+    APRS_NULL,
+    APRS_MSGCAP,
+    APRS_FIXED,
+    APRS_DOWN,      // Not used anymore
+    APRS_MOBILE,
+    APRS_DF,
+    APRS_OBJECT,
+    APRS_ITEM,
+    APRS_STATUS,
+    APRS_WX1,
+    APRS_WX2,
+    APRS_WX3,
+    APRS_WX4,
+    APRS_WX5,
+    APRS_WX6,
+    QM_WX,
+    PEET_COMPLETE,
+    RSWX200,
+    GPS_RMC,
+    GPS_GGA,
+    GPS_GLL,
+    STATION_CALL_DATA,
+    OTHER_DATA,
+    APRS_MICE,
+    APRS_GRID,
+    DALLAS_ONE_WIRE,
+    DAVISMETEO
+};
+
+
+/* Define Record Types */
+#define NORMAL_APRS     'N'
+#define MOBILE_APRS     'M'
+#define DF_APRS         'D'
+#define DOWN_APRS       'Q'
+#define NORMAL_GPS_RMC  'C'
+#define NORMAL_GPS_GGA  'A'
+#define NORMAL_GPS_GLL  'L'
+
+/* define RECORD ACTIVES */
+#define RECORD_ACTIVE    'A'
+#define RECORD_NOTACTIVE 'N'
+#define RECORD_CLOSED     'C'
+
+/* define data from info type */
+#define DATA_VIA_LOCAL 'L'
+#define DATA_VIA_TNC   'T'
+#define DATA_VIA_NET   'I'
+#define DATA_VIA_FILE  'F'
+
+
+/* define Heard info type */
+#define VIA_TNC         'Y'
+#define NOT_VIA_TNC     'N'
+
+/* define Message types */
+#define MESSAGE_MESSAGE  'M'
+#define MESSAGE_BULLETIN 'B'
+#define MESSAGE_NWS      'W'
+
+
+// trail flag definitions
+#define MAX_CALLSIGN 9
+#define MAX_TIME             20
+#define MAX_LONG             12
+#define MAX_LAT              11
+#define MAX_ALTITUDE         10         //-32808.4 to 300000.0? feet
+#define MAX_SPEED             9         /* ?? 3 in knots */
+#define MAX_COURSE            7         /* ?? */
+#define MAX_POWERGAIN         7
+#define MAX_STATION_TIME     10         /* 6+1 */
+#define MAX_SAT               4
+#define MAX_DISTANCE         10
+#define MAX_WXSTATION        50
+#define MAX_TEMP            100
+#define MAX_MULTIPOINTS 35
+
+#define MAX_DEVICE_BUFFER 4096
+
+/* define max size of info field */
+#define MAX_INFO_FIELD_SIZE 256
+
+// Number of times to send killed objects/items before ceasing to
+// transmit them.
+#define MAX_KILLED_OBJECT_RETRANSMIT 20
+
+// Check entire station list at this rate for objects/items that
+// might need to be transmitted via the decaying algorithm.  This is
+// the start rate, which gets doubled on each transmit.
+#define OBJECT_CHECK_RATE 20
+
+
+#define MAX_MESSAGE_LENGTH  100
+#define MAX_MESSAGE_ORDER    10
+
+
+#define CHECKMALLOC(m)  if (!m) { fprintf(stderr, "***** Malloc Failed *****\n"); exit(0); }
+
+
+#define STATION_REMOVE_CYCLE 300    /* check station remove in seconds (every 5 minutes) */
+#define MESSAGE_REMOVE_CYCLE 600    /* check message remove in seconds (every 10 minutes) */
+#define IN_VIEW_MIN         600l    /* margin for off-screen stations, with possible trails on screen, in minutes */
+#define TRAIL_POINT_MARGIN   30l    /* margin for off-screen trails points, for segment to be drawn, in minutes */
+#define TRAIL_MAX_SPEED      900    /* max. acceptible speed for drawing trails, in mph */
+#define MY_TRAIL_COLOR      0x16    /* trail color index reserved for my station */
+#define TRAIL_ECHO_TIME       30    /* check for delayed echos during last 30 minutes */
+/* MY_TRAIL_DIFF_COLOR changed to user configurable my_trail_diff_color  */
+
+
+typedef struct { 
+    int digis;
+    int wxs;
+    int other_mobiles;
+    int mobiles_in_motion;
+    int homes;
+    int total;
+} aloha_stats;
+
+
+// station flag definitions.  We have 16 bits available here as
+// "flag" in "DataRow" is defined as a short.
+//
+#define ST_OBJECT       0x01    // station is an object
+#define ST_ITEM         0x02    // station is an item
+#define ST_ACTIVE       0x04    // station is active (deleted objects are
+                                // inactive)
+#define ST_MOVING       0x08    // station is moving
+#define ST_DIRECT       0x10    // heard direct (not via digis)
+#define ST_VIATNC       0x20    // station heard via TNC
+#define ST_3RD_PT       0x40    // third party traffic (not used yet)
+#define ST_MSGCAP       0x80    // message capable (not used yet)
+#define ST_STATUS       0x100   // got real status message
+#define ST_INVIEW       0x200   // station is in current screen view
+#define ST_MYSTATION    0x400   // station is owned by my call-SSID
+#define ST_MYOBJITEM    0x800   // object/item owned by me
+
+
+#define TR_LOCAL        0x01    // heard direct (not via digis)
+#define TR_NEWTRK       0x02    // start new track
+
+
+enum AprsAreaObjectTypes {
+    AREA_OPEN_CIRCLE     = 0x0,
+    AREA_LINE_LEFT       = 0x1,
+    AREA_OPEN_ELLIPSE    = 0x2,
+    AREA_OPEN_TRIANGLE   = 0x3,
+    AREA_OPEN_BOX        = 0x4,
+    AREA_FILLED_CIRCLE   = 0x5,
+    AREA_LINE_RIGHT      = 0x6,
+    AREA_FILLED_ELLIPSE  = 0x7,
+    AREA_FILLED_TRIANGLE = 0x8,
+    AREA_FILLED_BOX      = 0x9,
+    AREA_MAX             = 0x9,
+    AREA_NONE            = 0xF
+};
+
+
+
+enum AprsAreaObjectColors {
+    AREA_BLACK_HI  = 0x0,
+    AREA_BLUE_HI   = 0x1,
+    AREA_GREEN_HI  = 0x2,
+    AREA_CYAN_HI   = 0x3,
+    AREA_RED_HI    = 0x4,
+    AREA_VIOLET_HI = 0x5,
+    AREA_YELLOW_HI = 0x6,
+    AREA_GRAY_HI   = 0x7,
+    AREA_BLACK_LO  = 0x8,
+    AREA_BLUE_LO   = 0x9,
+    AREA_GREEN_LO  = 0xA,
+    AREA_CYAN_LO   = 0xB,
+    AREA_RED_LO    = 0xC,
+    AREA_VIOLET_LO = 0xD,
+    AREA_YELLOW_LO = 0xE,
+    AREA_GRAY_LO   = 0xF
+};
+
+
+typedef struct {
+    unsigned type : 4;
+    unsigned color : 4;
+    unsigned sqrt_lat_off : 8;
+    unsigned sqrt_lon_off : 8;
+    unsigned corridor_width : 16;
+} AprsAreaObject;
+
+typedef struct {
+    char aprs_type;
+    char aprs_symbol;
+    char special_overlay;
+    AprsAreaObject area_object;
+} APRS_Symbol;
+
+// Struct for holding track data.  Keeps a dynamically allocated
+// doubly-linked list of track points.  The first record should have its
+// "prev" pointer set to NULL and the last record should have its "next"
+// pointer set to NULL.  If no track storage exists then the pointers to
+// these structs in the DataRow struct should be NULL.
+typedef struct _AprsTrackRow{
+    long    trail_long_pos;     // coordinate of trail point
+    long    trail_lat_pos;      // coordinate of trail point
+    time_t  sec;                // date/time of position
+    long    speed;              // in 0.1 km/h   undefined: -1
+    int     course;             // in degrees    undefined: -1
+    long    altitude;           // in 0.1 m      undefined: -99999
+    char    flag;               // several flags, see below
+    struct  _AprsTrackRow *prev;    // pointer to previous record in list
+    struct  _AprsTrackRow *next;    // pointer to next record in list
+} AprsTrackRow;
+
+
+
+// Struct for holding current weather data.
+// This struct is pointed to by the DataRow structure.
+// An empty string indicates undefined data.
+typedef struct {                //                      strlen
+    time_t  wx_sec_time;
+    int     wx_storm;           // Set to one if severe storm
+    char    wx_time[MAX_TIME];
+    char    wx_course[4];       // in °                     3
+    char    wx_speed[4];        // in mph                   3
+    time_t  wx_speed_sec_time;
+    char    wx_gust[4];         // in mph                   3
+    char    wx_hurricane_radius[4];  //nautical miles       3
+    char    wx_trop_storm_radius[4]; //nautical miles       3
+    char    wx_whole_gale_radius[4]; // nautical miles      3
+    char    wx_temp[5];         // in °F                    3
+    char    wx_rain[10];        // in hundredths inch/h     3
+    char    wx_rain_total[10];  // in hundredths inch
+    char    wx_snow[6];         // in inches/24h            3
+    char    wx_prec_24[10];     // in hundredths inch/day   3
+    char    wx_prec_00[10];     // in hundredths inch       3
+    char    wx_hum[5];          // in %                     3
+    char    wx_baro[10];        // in hPa                   6
+    char    wx_fuel_temp[5];    // in °F                    3
+    char    wx_fuel_moisture[5];// in %                     2
+    char    wx_type;
+    char    wx_station[MAX_WXSTATION];
+} AprsWeatherRow;
+
+
+// Struct for holding comment/status data.  Will keep a dynamically
+// allocated list of text.  Every different comment field will be
+// stored in a separate line.
+typedef struct _AprsCommentRow{
+    char   *text_ptr;           // Ptr to the comment text
+    time_t sec_heard;           // Latest timestamp for this comment/status
+    struct _AprsCommentRow *next;   // Ptr to next record or NULL
+} AprsCommentRow;
+
+
+
+
+// Struct for holding multipoint data.
+typedef struct _AprsMultipointRow{
+    long multipoints[MAX_MULTIPOINTS][2];
+} AprsMultipointRow;
+
+typedef struct _AprsDisplayData
+{
+    gchar *call_sign; // call sign or name index or object/item
+                                    // name
+    gdouble coord_lon;
+    gdouble coord_lat;
+
+    gchar   *coord_lat_lon;
+    gchar   *path;
+    
+    gchar   *comment;
+    gchar   *status;
+} AprsDisplayData;
+
+typedef struct _AprsDataRow {
+
+    struct _AprsDataRow *n_next;    // pointer to next element in name ordered list
+    struct _AprsDataRow *n_prev;    // pointer to previous element in name ordered
+                                // list
+    struct _AprsDataRow *t_newer;   // pointer to next element in time ordered
+                                // list (newer)
+    struct _AprsDataRow *t_older;   // pointer to previous element in time ordered
+                                // list (older)
+
+    
+    char call_sign[MAX_CALLSIGN+1]; // call sign or name index or object/item
+                                    // name
+    char *tactical_call_sign;   // Tactical callsign.  NULL if not assigned
+    APRS_Symbol aprs_symbol;
+    long coord_lon;             // Xastir coordinates 1/100 sec, 0 = 180°W
+    long coord_lat;             // Xastir coordinates 1/100 sec, 0 =  90°N
+
+    int  time_sn;               // serial number for making time index unique
+    time_t sec_heard;           // time last heard, used also for time index
+    time_t heard_via_tnc_last_time;
+    time_t direct_heard;        // KC2ELS - time last heard direct
+
+// Change into time_t structs?  It'd save us a bunch of space.
+    char packet_time[MAX_TIME];
+    char pos_time[MAX_TIME];
+
+    short flag;                 // several flags, see below
+    char pos_amb;               // Position ambiguity, 0 = none,
+                                // 1 = 0.1 minute...
+
+    unsigned int error_ellipse_radius; // Degrades precision for this
+                                // station, from 0 to 65535 cm or
+                                // 655.35 meters.  Assigned when we
+                                // decode each type of packet.
+                                // Default is 6.0 meters (600 cm)
+                                // unless we know the GPS position
+                                // is augmented, or is degraded by
+                                // less precision in the packet.
+
+    unsigned int lat_precision;        // In 100ths of a second latitude
+    unsigned int lon_precision;        // In 100ths of a second longitude
+
+    int trail_color;            // trail color (when assigned)
+    char record_type;
+    //char data_via;              // L local, T TNC, I internet, F file
+
+// Change to char's to save space?
+    int  heard_via_tnc_port;    // Current this will always be 0, but keep for future
+    TAprsPort  last_port_heard;       // Current this will always be 0, but keep for future
+    unsigned int  num_packets;
+    char *node_path_ptr;        // Pointer to path string
+    char altitude[MAX_ALTITUDE]; // in meters (feet gives better resolution ??)
+    char speed[MAX_SPEED+1];    // in knots (same as nautical miles/hour)
+    char course[MAX_COURSE+1];
+    char bearing[MAX_COURSE+1];
+    char NRQ[MAX_COURSE+1];
+    char power_gain[MAX_POWERGAIN+1];   // Holds the phgd values
+    char signal_gain[MAX_POWERGAIN+1];  // Holds the shgd values (for DF'ing)
+
+    AprsWeatherRow *weather_data;   // Pointer to weather data or NULL
+    AprsCommentRow *status_data;    // Ptr to status records or NULL
+    AprsCommentRow *comment_data;   // Ptr to comment records or NULL
+
+    // Below two pointers are NULL if only one position has been received
+    AprsTrackRow *oldest_trackpoint; // Pointer to oldest track point in
+                                 // doubly-linked list
+    AprsTrackRow *newest_trackpoint; // Pointer to newest track point in
+                                 // doubly-linked list
+
+    // When the station is an object, it can include coordinates
+    // of related points. Currently these are being used to draw
+    // outlines of NWS severe weather watches and warnings, and
+    // storm regions. The coordinates are stored here in Xastir
+    // coordinate form. Element [x][0] is the latitude, and 
+    // element [x][1] is the longitude.  --KG4NBB
+    //
+    // Is there anything preventing a multipoint string from being
+    // in other types of packets, in the comment field?  --WE7U
+    //
+    int num_multipoints;
+    char type;      // from '0' to '9'
+    char style;     // from 'a' to 'z'
+    AprsMultipointRow *multipoint_data;
+
+
+///////////////////////////////////////////////////////////////////////
+// Optional stuff for Objects/Items only (I think, needs to be
+// checked).  These could be moved into an ObjectRow structure, with
+// only a NULL pointer here if not an object/item.
+///////////////////////////////////////////////////////////////////////
+    char origin[MAX_CALLSIGN+1]; // call sign originating an object
+    short object_retransmit;     // Number of times to retransmit object.
+                                 // -1 = forever
+                                 // Used currently to stop sending killed
+                                 // objects.
+    time_t last_transmit_time;   // Time we last transmitted an object/item.
+                                 // Used to implement decaying transmit time
+                                 // algorithm
+    short transmit_time_increment; // Seconds to add to transmit next time
+                                   // around.  Used to implement decaying
+                                   // transmit time algorithm
+//    time_t last_modified_time;   // Seconds since the object/item
+                                 // was last modified.  We'll
+                                 // eventually use this for
+                                 // dead-reckoning.
+    char signpost[5+1];          // Holds signpost data
+    int  df_color;
+    char sats_visible[MAX_SAT];
+    char probability_min[10+1];  // Holds prob_min (miles)
+    char probability_max[10+1];  // Holds prob_max (miles)
+
+} AprsDataRow;
+
+typedef enum
+{
+    APRSPOI_SELECTED,
+    APRSPOI_CALLSIGN,
+//    APRSPOI_LAT,
+//    APRSPOI_LON,
+//    APRSPOI_LATLON,
+//    APRSPOI_BEARING,
+//    APRSPOI_DISTANCE,
+//    APRSPOI_PATH,
+//    APRSPOI_COMMENT,
+//    APRSPOI_STATUS,
+    APRSPOI_NUM_COLUMNS
+} APRSPOIList;
+
+
+
+typedef struct _AprsStationList{
+    struct  _AprsStationList *next;    // pointer to next record in list
+    AprsDataRow *station;
+} AprsStationList;
+
+
+
+
+// --------------------------------------------------------------------------------------
+// End of APRS Types - Code taken from Xastir code 25 March 2008 by Rob Williams M1BGT
+// Modification made to fit in with Maemo mapper
+// --------------------------------------------------------------------------------------
+#endif // INCLUDE_APRS
+
+
 #endif /* ifndef MAEMO_MAPPER_TYPES_H */