/usr/lib/gpsman/realtime.tcl is in gpsman 6.4.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | #
# This file is part of:
#
# gpsman --- GPS Manager: a manager for GPS receiver data
#
# Copyright (c) 1998-2013 Miguel Filgueiras migfilg@t-online.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.
#
# File: realtime.tcl
# Last change: 6 October 2013
#
#### real time logging control
proc GPSRealTimeLogOnOff {} {
# start or stop the real time log
# change the button label accordingly
global TXT RealTimeLogOn WConf
if { $RealTimeLogOn } {
StopRealTimeLog
set txt $TXT(getlog)
} else {
if { ! [StartRealTimeLog 2] } { return }
set txt $TXT(stop)
}
foreach w $WConf(realtime) type $WConf(realtimetype) {
switch $type {
button {
$w configure -text $txt
}
menuentry {
[lindex $w 0] entryconfigure [lindex $w 1] -label $txt
}
}
}
return
}
proc StartRealTimeLog {interval} {
# start real time logging with given $interval in seconds
# assume it is currently off
# return 0 on failure
global GPSProtocol RealTimeLogIntv RealTimeLogOn RealTimeLogLast \
Travelling MESS MYGPS
set RealTimeLogIntv $interval
switch $GPSProtocol {
garmin - garmin_usb {
if { ! [GarminStartPVT] } { return 0 }
}
stext {
if { ! [StartSimpleText] } { return 0 }
}
simul {
SimulPVTOn
}
drivesim {
SimulDriveOn
}
nmea {
if { $MYGPS == "Lowrance" } {
NMEASetupWindow
} elseif { ! [GarminStartNMEA rec] } { return 0 }
}
lowrance {
NMEASetupWindow
}
default {
GMMessage $MESS(rltmnotsupp)
return 0
}
}
if { $Travelling } {
TravelRealTimeOn
}
set RealTimeLogLast 0
set RealTimeLogOn 1
return 1
}
proc StopRealTimeLog {} {
# stop real time logging
# assume it is currently on
global GPSProtocol RealTimeLogOn RealTimeLogAnim Travelling MYGPS
switch $GPSProtocol {
garmin - garmin_usb {
GarminStopPVT
}
lowrance -
nmea {
if { $MYGPS == "Lowrance" } {
NMEAOff
} else { GarminStopNMEA }
}
stext {
StopSimpleText
}
simul {
SimulPVTOff
}
drivesim {
SimulDriveOff
}
}
if { $RealTimeLogAnim } {
AnimStopRealTime
set RealTimeLogAnim 0
}
if { $Travelling } {
TravelRealTimeOff
}
set RealTimeLogOn 0
return
}
##### real time log window and hook to animation procs
proc UseRealTimeData {data} {
# use position, velocity and time data
# UTC time - as a list with y m d h mn s
# position - as a list with latd, longd (for datum WGS 84)
# pos fix - in {error, _, 2D, 3D, 2D-diff, 3D-diff, GPS, DGPS, Auto,
# simul}
# pos error - as a list with
# estimated position error EPE in metres
# estimated horizontal error EPH in metres
# estimated vertical error in metres
# altitude - signed number in metres
# velocity vector - as list with vlat vlong valt, m/s
# course over ground - degrees
# number of satellites in view
# HDOP - horizontal dilution of precision
# speed - km/h
# any value may be "_" or have a "_" to mean non-available data
global TXT DateFormat RealTimeLogIntv RealTimeLogLast RealTimeLogAnim \
PVTLast PVTState PVTElapsed PVTZero PVTPosns PVTSecs PVTInterval \
PVTDFile GPSProtocol MYGPS Travelling CMDLINE
set date [lindex $data 0]
if { $date == "_" } {
if { [string first "garmin" $GPSProtocol] == 0 || \
($MYGPS == "Garmin" && $GPSProtocol == "nmea") } {
Log "UPVTD> bad date: $date"
}
if { $Travelling } { TravelBadDate }
return
}
set date [eval LocalTimeAndUTC $date UTC]
set secs [eval DateToSecs $date]
set PVTInterval $RealTimeLogIntv
if { [llength $data] < 10 } { return }
foreach "x rpos fix err alt velv trk nsat hdop speed" $data { break }
if { $rpos == "_" || $secs-$RealTimeLogLast < $RealTimeLogIntv } {
return
}
set RealTimeLogLast $secs
foreach "epe eph epv" $err {}
foreach "velx vely velz" $velv {}
if { $RealTimeLogAnim } { AnimNextRealTime $rpos "WGS 84" $secs }
set posn [eval FormatLatLong $rpos DMS]
set flat [lindex $posn 2] ; set flong [lindex $posn 3]
if { $Travelling } {
TravelData [lrange $date 3 5] $posn $flat $flong $fix $alt \
$velx $vely $velz $trk $speed
}
if { $PVTState != "on" } { return }
# recording
if { ! [winfo exists .pvt] } { RealTimeLogWindow }
if { $PVTZero < 0 } { set PVTZero $secs }
set PVTElapsed " [FormatTime [expr $secs-$PVTZero]]"
lappend PVTSecs $secs
lappend PVTPosns $posn
set vals [list [format "%4d." [incr PVTLast]] \
[eval FormatDate $DateFormat $date] \
$flat $flong \
[RTimeFormat $alt %7.1f] \
$TXT(posfix$fix) \
[RTimeFormat $epe %5.1f] \
[RTimeFormat $eph %5.1f] \
[RTimeFormat $epv %5.1f] \
[RTimeFormat $velx %7.1f] \
[RTimeFormat $vely %7.1f] \
[RTimeFormat $velz %7.1f] \
[RTimeFormat $trk %3.1f]]
if { $PVTDFile != "" } { RTimeDumpLine $vals }
if { ! $CMDLINE } {
set fx .pvt.fri.frtbx ; set col 0
foreach b "n d lat long alt fix epe eph epv velx vely velz trk" \
v $vals {
if { [$fx.bx$b size] == 0 && $v == "" } {
CollapseColumn "$fx.tit$b $fx.bx$b" $col \
[lindex $TXT(PVTflds) $col] \
menubtentry .pvt.frs.frbt.show.m .pvt.frs.frbt.show
}
incr col
$fx.bx$b insert end $v ; $fx.bx$b see end
}
}
update
return
}
proc RealTimeLogWindow {} {
# create window for displaying real-time log
# columns with empty first values will be collapsed
global RealTimeLogIntv RealTimeLogAnim DATEWIDTH TXT MPOSX MPOSY COLOUR \
PVTLast PVTState PVTStateExt PVTElapsed PVTZero PVTPosns \
PVTSecs PVTInterval PVTDumping PVTDFile CMDLINE FixedFont
set PVTLast 0
set PVTElapsed "" ; set PVTZero -1
set PVTPosns "" ; set PVTSecs ""
if { $CMDLINE } { return }
set fx .pvt.fri.frtbx
set PVTInterval $RealTimeLogIntv
set PVTStateExt $TXT(animon)
set PVTDumping 0 ; set PVTDFile ""
trace variable PVTState w RTimeStateChange
trace variable PVTInterval w RTimeIntervalChange
GMToplevel .pvt realtimelog +[expr $MPOSX+10]+[expr $MPOSY+80] {} \
{WM_DELETE_WINDOW RTimeCancel} {}
label .pvt.tit -text $TXT(realtimelog)
frame .pvt.fri -relief flat -borderwidth 5 -bg $COLOUR(messbg)
# see above for initialization of $fx
frame $fx -relief flat -borderwidth 0
# see below for creation of $fb and $show
set fb .pvt.frs.frbt
set show $fb.show ; set mn $show.m
set col 0
foreach b "n d lat long alt fix epe eph epv velx vely velz trk" \
m "5 $DATEWIDTH 10 10 4 4 4 4 4 6 6 6 4" \
t $TXT(PVTflds) {
button $fx.tit$b -width $m -text $t -font $FixedFont \
-command [list CollapseColumn "$fx.tit$b $fx.bx$b" $col \
$t menubtentry $mn $show]
BalloonBindings $fx.tit$b hide
listbox $fx.bx$b -height 15 -width $m -relief flat \
-yscrollcommand "$fx.bscr set" \
-selectmode single -exportselection false
bind $fx.bx$b <Button-1> {
MultSelect [winfo parent %W] [%W nearest %y] \
"bxn bxd bxlat bxlong bxalt bxfix bxepe bxeph bxepv \
bxvelx bxvely bxvelz bxtrk"
}
bind $fx.bx$b <Double-1> {
set i [%W nearest %y] ; set n [%W get $i]
set ww [winfo toplevel %W]
MultSelect [winfo parent %W] $i \
"bxn bxd bxlat bxlong bxalt bxfix bxepe bxeph bxepv \
bxvelx bxvely bxvelz bxtrk"
if { $n != "" } {
MarkPoint PVT $ww $i
}
}
grid configure $fx.tit$b -column $col -row 0 -sticky news
grid configure $fx.bx$b -column $col -row 1 -sticky news
incr col
}
set boxes [list $fx.bxd $fx.bxn $fx.bxlat $fx.bxlong \
$fx.bxalt $fx.bxfix $fx.bxepe $fx.bxeph $fx.bxepv \
$fx.bxvelx $fx.bxvely $fx.bxvelz $fx.bxtrk]
scrollbar $fx.bscr -command [list ScrollMany $boxes]
Mscroll $boxes
grid configure $fx.bscr -column $col -row 1 -sticky news
frame .pvt.frs -relief flat -borderwidth 0
# $fb == .pvt.frs.frbt
frame $fb -relief flat -borderwidth 0
button $fb.rest -text $TXT(restart) \
-command "RTimeRestart ; $fb.rest configure -state normal"
button $fb.pause -text $TXT(pause) \
-command "RTimePause ; $fb.pause configure -state normal"
menubutton $show -text $TXT(show) -relief raised \
-direction below -menu $show.m -state disabled
menu $show.m -tearoff 0
set fb1 ${fb}1
frame $fb1 -relief flat -borderwidth 0
button $fb1.stan -text $TXT(animation) \
-command "set RealTimeLogAnim 1 ; \
$fb1.stan configure -state normal"
button $fb1.totr -text $TXT(mkTR) \
-command "RTimeToTR ; $fb1.totr configure -state normal"
set mn $fb1.save.m
menubutton $fb1.save -text $TXT(save) -relief raised \
-direction below -menu $mn
menu $mn -tearoff 0
$mn add command -label $TXT(exstglog) \
-command { SaveFile comp PVTData }
$mn add checkbutton -label $TXT(contnsly) -selectcolor $COLOUR(check) \
-variable PVTDumping -command RTimeDump
frame .pvt.frs.int -relief flat -borderwidth 0
set fs .pvt.frs.int
label $fs.sl -text $TXT(slow) -width 6
scale $fs.sp -orient horizontal -from 1 -to 101 -showvalue 1 \
-width 8 -length 150 -variable PVTInterval \
-label "$TXT(rtimelogintv) (s):"
label $fs.fst -text $TXT(fast) -width 6
grid configure $fs.fst -column 0 -row 0 -sticky news
grid configure $fs.sp -column 1 -row 0 -sticky news
grid configure $fs.sl -column 2 -row 0 -sticky news
frame .pvt.frs.st -relief flat -borderwidth 0
set ft .pvt.frs.st
label $ft.tit -text $TXT(state):
label $ft.st -width 10 -textvariable PVTStateExt
label $ft.tm -width 15 -textvariable PVTElapsed
button .pvt.cnc -text $TXT(cancel) -command RTimeCancel
pack $fb.rest $fb.pause $show -side top -pady 3 -fill x
pack $fb1.stan $fb1.totr $fb1.save -side top -pady 3 -fill x
pack $fx
pack $fs $ft $fb $fb1 -side left -padx 10
pack $ft.tit $ft.st $ft.tm -side left
pack .pvt.tit .pvt.fri .pvt.frs .pvt.cnc -side top -pady 5
return
}
proc RTimeFormat {f fmt} {
if { $f == "_" } { return "" }
return [format $fmt $f]
}
proc RTimeCancel {} {
global PVTState PVTDFile
set PVTState abort
if { $PVTDFile != "" } {
close $PVTDFile
}
trace vdelete PVTState w RTimeStateChange
trace vdelete PVTInterval w RTimeIntervalChange
destroy .pvt
return
}
proc RTimeToTR {} {
# make a TR from the PVT data
global PVTSecs PVTPosns
set fx .pvt.fri.frtbx
set tpfs "latd longd latDMS longDMS date secs alt"
set i 0 ; set tps ""
foreach p $PVTPosns s $PVTSecs {
if { "$p" != "" } {
lappend p [$fx.bxd get $i] $s [$fx.bxalt get $i]
lappend tps [FormData TP $tpfs $p]
}
incr i
}
if { "$tps" == "" } { bell ; return }
set opts "create revert cancel"
GMTrack -1 $opts [FormData TR "Datum TPoints" [list "WGS 84" $tps]]
return
}
proc RTimeRestart {} {
# continue after a pause or restart logging
# clear information in PVT window if restarting
global RealTimeLogLast PVTSecs PVTPosns PVTLast PVTState PVTElapsed PVTZero
if { "$PVTState" == "pause" } {
set PVTState on
} else {
set PVTSecs "" ; set PVTPosns ""
set RealTimeLogLast 0
set PVTLast 0 ; set PVTState on ; set PVTElapsed "" ; set PVTZero -1
set fx .pvt.fri.frtbx
foreach b "n d lat long alt fix epe eph epv velx vely velz trk" {
$fx.bx$b delete 0 end
}
}
return
}
proc RTimePause {} {
# pause or continue after a pause
global PVTState
if { "$PVTState" == "pause" } {
set PVTState on
} else { set PVTState pause }
return
}
proc RTimeStateChange {n no op} {
# called by trace when $PVTState has been changed
global PVTState PVTStateExt TXT
set PVTStateExt $TXT(anim$PVTState)
return
}
proc RTimeIntervalChange {n no op} {
# called by trace when $PVTInterval has been changed
# if there is an animation window for the log set Anim(speed,-1)
# that has a trace on it; otherwise set RealTimeLogIntv directly
global PVTInterval RealTimeLogIntv Anim
if { [winfo exists .anim-1] } {
after 0 "set Anim(speed,-1) [expr $PVTInterval-51]"
} else {
set RealTimeLogIntv $PVTInterval
}
return
}
proc RTimeDump {} {
# start/stop dumping continuously
global PVTDFile PVTDumping TXT
if { $PVTDFile == "" } {
if { [set PVTDFile [GMOpenFile $TXT(saveto) PVTData wapp]] == ".." } {
set PVTDumping 0 ; set PVTDFile ""
} else {
SavePVTData $PVTDFile
}
} else {
close $PVTDFile
set PVTDFile ""
}
return
}
proc RTimeDumpLine {vals} {
# dump PVT data (except line number) unless only one fix is to be
# got (in command-line mode) in which case set the appropriate
# global to the PVT data
global PVTDFile RealTimeGettingFix
if { $RealTimeGettingFix != 0 } {
if { $RealTimeGettingFix == 1 } { set RealTimeGettingFix $vals }
return
}
set sep ""
foreach v [lreplace $vals 0 0] {
puts -nonewline $PVTDFile "${sep}$v"
set sep "\t"
}
puts $PVTDFile ""
flush $PVTDFile
return
}
##### driving simulator
proc SimulDriveOn {} {
# simulate PVT by generating fake PVT data lists and calls to
# proc UseRealTimeData
# the data lists are computed from user actions in a driving window
global SimulDrive COLOUR TXT EPOSX EPOSY SPUNIT MESS
set w .simdrive
if { [winfo exists $w] } { Raise $w ; return }
set SimulDrive(data) ""
set SimulDrive(mess) ""
GMToplevel $w drivesim +$EPOSX+$EPOSY {} \
{WM_DELETE_WINDOW {GMMessage $MESS(chgrecprot)}} \
[list <Key-Up> {SimulDriveChange speed 5} \
<Key-Down> {SimulDriveChange speed -5} \
<Key-Left> {SimulDriveChange turn 1} \
<Key-Right> {SimulDriveChange turn -1} \
<Key-space> {SimulDriveChange turnval 0} \
<Leave> {SimulDriveControl 0} \
<Enter> "focus $w ; SimulDriveControl 1"]
frame $w.fr -borderwidth 2 -bg $COLOUR(messbg)
frame $w.fr.frsw
# steering wheel
set swwd 74 ; set swht 74
set cwl $w.fr.frsw.c_whl
canvas $cwl -width $swwd -height $swht -relief flat -bg $COLOUR(dialbg)
if { $swwd >= $swht } { set sl $swht } else { set sl $swwd }
set sl [expr int($sl*0.8)]
set x0 [expr ($swwd-$sl)/2] ; set xe [expr $x0+$sl]
set y0 [expr ($swht-$sl)/2] ; set ye [expr $y0+$sl]
$cwl create oval $x0 $y0 $xe $ye -fill $COLOUR(dialbg) -width 4 \
-outline green
set xm [expr $swwd/2] ; set sl [expr $sl*0.5]
set fx 2 ; set fy 2
set d [expr $sl/6] ; set d1 [expr $sl/10]
set gx 5 ; set gy 3
set d2 [expr $sl/4]
set ps [list [expr $xm-$sl+$fx] [expr $xm-$fy] \
[expr $xm-$sl+$d] [expr $xm-$d1] \
[expr $xm+$sl-$d] [expr $xm-$d1] \
[expr $xm+$sl-$fx] [expr $xm-$fy] \
[expr $xm+$sl-$gx] [expr $xm+$gy] \
[expr $xm+$d2] [expr $xm+$d1] \
[expr $xm+$d] [expr $xm+$d] [expr $xm-$d] [expr $xm+$d] \
[expr $xm-$d2] [expr $xm+$d1] \
[expr $xm-$sl+$gx] [expr $xm+$gy] \
[expr $xm-$sl+$fx] [expr $xm-$fy]]
eval $cwl create polygon $ps -fill green -tags wheel
set cs ""
foreach "x y" $ps {
lappend cs [expr $x-$xm] [expr $y-$xm]
}
set d 3 ; set m [expr $xm+$d] ; set n [expr $xm-$d]
$cwl create oval $n $n $m $m -fill black
set SimulDrive(wheel) [list $xm $xm wheel $cwl $cs]
# speed bar
scale $w.fr.frsw.speed -length $swht -from 500 -to 0 -showvalue 1 \
-width 20 -label $SPUNIT -variable SimulDrive(speed) \
-command SimulDriveSpeedChange
# help
BalloonButton $w.fr.frsw.bhlp rthlpdsim
# steering buttons
set i -1
foreach b "left straight right" op "turn turnval turn" v "1 0 -1" {
button $w.fr.frsw.b$b -text $TXT($b) -width 6 \
-command "$w.fr.frsw.b$b configure -state normal ; \
SimulDriveChange $op $v"
grid $w.fr.frsw.b$b -row 1 -column [incr i] -sticky ew
}
grid $w.fr.frsw.bhlp -column 0 -row 0 -sticky es
grid $cwl -column 1 -row 0
grid $w.fr.frsw.speed -column 2 -row 0 -sticky wns
# message
label $w.fr.mess -textvariable SimulDrive(mess) -width 15 -fg red
frame $w.fr.frbs
button $w.fr.frbs.start -text $TXT(startfrom) -command SimulDriveStart
grid $w.fr.frbs.start
foreach x "frsw mess" {
grid $w.fr.$x
}
grid $w.fr.frbs -pady 5
grid $w.fr
RaiseWindow $w
update idletasks
return
}
proc SimulDriveControl {flag} {
# pointer left from/returned to window
global SimulDrive TXT
if { $SimulDrive(data) != "" && ! $flag } {
set SimulDrive(mess) $TXT(outofctrl)
} else { set SimulDrive(mess) "" }
return
}
proc SimulDriveSpeedChange {val} {
# change in speed scale: start if needs be
global SimulDrive MESS
if { $SimulDrive(data) == "" } {
GMMessage $MESS(drvsimoff)
}
return
}
proc SimulDriveChange {what d} {
# $what in {speed, turn, turnval}
# $d is change in value unless $what==turnval in which case is new value
global SimulDrive MESS
if { $SimulDrive(data) == "" } {
GMMessage $MESS(drvsimoff)
} elseif { $what == "turnval" } {
set SimulDrive(turn) $d
TurnObject $d $SimulDrive(wheel)
} else {
incr SimulDrive($what) $d
if { $what == "turn" } {
if { $SimulDrive(turn) > 180 } {
set SimulDrive(turn) 180
} elseif { $SimulDrive(turn) < -180 } {
set SimulDrive(turn) -180
}
TurnObject $SimulDrive(turn) $SimulDrive(wheel)
}
}
return
}
proc SimulDriveStart {} {
# fix the initial point and start the simulation
global SimulDrive Number WPPosn WPDatum RealTimeLogOn MESS
if { $Number(WP) == 0 } {
GMMessage $MESS(needWP)
return
}
if { [set ix [ChooseItems WP]] == "" } { return }
set ix [lindex $ix 0]
set p $WPPosn($ix)
if { $WPDatum($ix) != "WGS 84" } {
set p [ToDatum [lindex $p 0] [lindex $p 1] \
$WPDatum($ix) "WGS 84"]
} else { set p [lrange $p 0 1] }
foreach x "trk turn speed" { set SimulDrive($x) 0 }
TurnObject 0 $SimulDrive(wheel)
set SimulDrive(secs) [clock seconds]
set date [clock format $SimulDrive(secs) -format "%Y %m %d %H %M %S"]
regsub -all { 0([0-9])} $date { \1} date
set SimulDrive(data) [list $date $p simul {_ _ _} _ {0 0 0} _ _ _ 0]
if { $RealTimeLogOn } { UseRealTimeData $SimulDrive(data) }
after 1000 SimulDrivePVT
return
}
proc SimulDrivePVT {} {
# generate a fake PVT data list and a call to proc UseRealTimeData
# the previous data list is changed in answer to the user actions
global SimulDrive RealTimeLogOn DSCALE
if { $SimulDrive(data) != "" } {
foreach "date pos fix errv alt velv" $SimulDrive(data) { break }
set s [clock seconds]
set dt [expr $s-$SimulDrive(secs)]
set SimulDrive(secs) $s
set date [clock format $s -format "%Y %m %d %H %M %S"]
regsub -all { 0([0-9])} $date { \1} date
if { $SimulDrive(speed) == 0 } {
# update time and velocity vector only
set SimulDrive(data) [lreplace $SimulDrive(data) 0 0 $date]
set SimulDrive(data) [lreplace $SimulDrive(data) 5 5 {0 0 0}]
} else {
foreach "lat long" $pos { break }
foreach "vx vy vz" $velv {}
set SimulDrive(trk) \
[expr round($SimulDrive(trk)-$SimulDrive(turn)/6.0)%360]
set a [expr $SimulDrive(trk)*0.01745329251994329576]
# m/s
set sp [expr $SimulDrive(speed)/$DSCALE/3.6]
set vx [expr $sp*sin($a)] ; set vy [expr $sp*cos($a)]
# plane sailing formulas
set dlat [expr $vy*$dt/111120.0]
set coslat [expr cos($lat*0.01745329251994329576)]
if { $coslat < 1e-15 } {
set dlong 0
} else { set dlong [expr $vx*$dt/111120.0/$coslat] }
set SimulDrive(data) [list $date \
[list [expr $lat+$dlat] [expr $long+$dlong]] simul $errv \
$alt [list $vx $vy $vz] $SimulDrive(trk) _ _ _]
}
if { $RealTimeLogOn } { UseRealTimeData $SimulDrive(data) }
after 1000 SimulDrivePVT
}
return
}
proc SimulDriveOff {} {
global SimulDrive
destroy .simdrive
set SimulDrive(data) ""
return
}
|