1#
2# This file is part of:
3#
4#  gpsman --- GPS Manager: a manager for GPS receiver data
5#
6# Copyright (c) 1998-2013 Miguel Filgueiras migfilg@t-online.de
7#
8#    This program is free software; you can redistribute it and/or modify
9#      it under the terms of the GNU General Public License as published by
10#      the Free Software Foundation; either version 3 of the License, or
11#      (at your option) any later version.
12#
13#      This program is distributed in the hope that it will be useful,
14#      but WITHOUT ANY WARRANTY; without even the implied warranty of
15#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16#      GNU General Public License for more details.
17#
18#      You should have received a copy of the GNU General Public License
19#      along with this program.
20#
21#  File: gpsinfo.tcl
22#  Last change:  6 October 2013
23#
24# Includes contributions by Brian Baulch (baulchb_AT_onthenet.com.au)
25#  marked "BSB contribution"
26
27
28proc DisableGPS {} {
29    # change interface appearance when detecting that the receiver went offline
30    global RcW RcMenu GPSState GPSLabel COLOUR TXT SYMBOLIMAGE WConf
31
32    # state
33    set GPSState offline ; set GPSLabel $TXT(offline)
34    $RcW.frgps.bs.state configure -fg $COLOUR(offline)
35    $RcMenu entryconfigure 5 -image $SYMBOLIMAGE(diamond_red)
36    # device name can be changed
37    $RcMenu.dev entryconfigure 0 -state normal
38    $RcW.frgps.dev.dev configure -state normal
39    # baud rate cannot be changed
40    if { [winfo exists $RcW.frgps.dev.baud] } {
41	$RcMenu.dev entryconfigure 1 -state disabled
42	$RcW.frgps.dev.baud configure -state disabled
43    }
44    # cannot turn off or get/put items
45    foreach ix "6 7 8" {
46	$RcMenu entryconfigure $ix -state disabled
47    }
48    $RcW.frgps.bs.off configure -state disabled
49    foreach m "getbs putbs" {
50	foreach b $WConf(rec,$m) { $b configure -state disabled	}
51    }
52    return
53}
54
55proc EnableGPS {} {
56    # change interface appearance when detecting that the receiver went on-line
57    global RcW RcMenu GPSState GPSLabel COLOUR ListInds TXT RECTYPES RECINFO \
58	MYGPS SYMBOLIMAGE WConf RecCanChgBaud
59
60    # state
61    set GPSState online ; set GPSLabel $TXT(online)
62    $RcW.frgps.bs.state configure -fg $COLOUR(online)
63    $RcMenu entryconfigure 5 -image $SYMBOLIMAGE(diamond_green)
64    # cannot change device name when in use
65    $RcMenu.dev entryconfigure 0 -state disabled
66    $RcW.frgps.dev.dev configure -state disabled
67    # baud rate can be changed if receiver supports that
68    if { [winfo exists $RcW.frgps.dev.baud] && $RecCanChgBaud } {
69	$RcMenu.dev entryconfigure 1 -state normal
70	$RcW.frgps.dev.baud configure -state normal
71    }
72    # can turn off and see get/put submenus
73    foreach ix "6 7 8" {
74	$RcMenu entryconfigure $ix -state normal
75    }
76    # disable all get/put buttons and submenu entries, then enable valid ones
77    foreach m "$RcMenu.gm $RcMenu.ptm" {
78	set l [$m index last]
79	for { set i 0 } { $i <= $l } { incr i } {
80	    $m entryconfigure $i -state disabled
81	}
82    }
83    $RcW.frgps.bs.off configure -state normal
84    foreach m "getbs putbs" {
85	foreach b $WConf(rec,$m) { $b configure -state disabled }
86    }
87    # enable valid entries in those menus and the corresponding buttons
88    foreach i $RECTYPES {
89	if { $i != "GR" || $ListInds(GR) != "" } {
90	    $RcW.frget.frget2.get$i configure -state normal
91	    $RcMenu.gm entryconfigure $WConf(rec,getmn,$i) -state normal
92	}
93	# based on BSB contribution: no IC put button
94	if { $i != "IC" && $i != "LAP" && $ListInds($i) != "" } {
95	    $RcW.frput.put$i configure -state normal
96	    $RcMenu.ptm entryconfigure $WConf(rec,putmn,$i) -state normal
97	}
98    }
99    foreach i $RECINFO {
100	$RcW.frget.frget2.get$i configure -state normal
101	$RcMenu.gm entryconfigure $WConf(rec,getmn,$i) -state normal
102    }
103    InitGPS
104    return
105}
106
107proc CheckGPS {} {
108    # check connectivity to receiver
109    global GPSState GPSLabel COLOUR MESS TXT
110
111    SetCursor . watch
112    if { $GPSState == "offline" } {
113	GPSConnection EnableGPS
114    } else {
115	GPSConnection [list GMMessage $MESS(GPSok)] DisableGPS
116    }
117    set GPSLabel $TXT($GPSState)
118    ResetCursor .
119    return
120}
121
122proc TurnOff {} {
123    global GPSState COLOUR
124
125    GPSOff
126    DisableGPS
127    return
128}
129
130proc PutOnGPS {how wh} {
131    # put data into receiver
132    #  $how in {all, select}, $wh in $RECTYPES
133    global ListInds RECTYPES MESS TXT
134
135    if { $wh == "LAP" } { return }
136    switch $how {
137	all {
138	    set ixs $ListInds($wh)
139	}
140	select {
141	    if { [set ixs [ChooseItems $wh]] == "" } {
142		return
143	    }
144	}
145    }
146    switch $wh {
147	GR {
148	    set gtypes [Delete $RECTYPES LAP]
149	    set ts ""
150	    foreach k $gtypes { lappend ts $TXT(name$k) }
151	    while 1 {
152		set whs [GMChooseFrom many $MESS(putwhat) 6 $ts $gtypes]
153		if { [set i [lsearch -exact $whs GR]] != -1 } {
154		    set whs [lreplace $whs $i $i]
155		    set r 1
156		} else { set r 0 }
157		if { [llength $whs] > 1 } {
158		    GMMessage $MESS(exportonly1)
159		} else { break }
160	    }
161	    # this only works for a single type
162	    if { [set l [GRsElements $ixs $r $whs]] != "" } {
163		PutItemsOnGPS $whs $l
164	    }
165	}
166	default {
167	    PutItemsOnGPS $wh $ixs
168	}
169    }
170    return
171}
172
173proc PutItemsOnGPS {wh ixs} {
174    # put items of kind $wh (in $RECTYPES except GR and LAP) on receiver
175    #  $ixs is list of indices
176    global MAX MESS TXT
177
178    if { [llength $ixs] > $MAX($wh) } {
179	GMMessage [format $MESS(toomany) $TXT(name$wh) $MAX($wh)]
180	return
181    }
182    PutGPS $wh $ixs
183    return
184}
185
186proc GetFromGPS {wh} {
187    # get data from receiver
188    #  $wh in $RECTYPES
189    # if $wh==GR, select a single item type (in $RECTYPES except TR) to get
190    global RECTYPES
191    # BSB contribution
192    global MYGPS
193
194    if { $wh == "GR" } {
195	# based on BSB contribution: do not get ICs
196	if { $MYGPS != "Lowrance" } {
197	    set not "TR"
198	} else { set not "IC TR" }
199	InputToGR $RECTYPES $not Ignore GetGPSIn Ignore receiver
200    } else {
201	GetGPS $wh
202    }
203    return
204}
205
206proc GPSChangeDevice {} {
207    # get device name from user and set global SERIALPORT
208    global SERIALPORT TXT
209
210    set old $SERIALPORT
211    if { [GMChooseParams $TXT(chgdev) SERIALPORT [list =$TXT(optDEFSPORT)]] \
212	     == 0 } {
213	set SERIALPORT $old
214    }
215    return
216}
217
218
219
220