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
|
#! @TCL_WISH@
#
# $Id$
#
package require Itcl
namespace import itcl::*
proc locateInDirs {name dirs} {
foreach dir ${dirs} {
set toTest ${dir}/${name}
if { [file exists ${toTest}] } {
return ${toTest}
}
}
error "unable to locate ${name}"
}
class Kbd {
protected {
variable parent
variable win
variable objname
}
public {
constructor { _parent _objname _win } {
set parent $_parent
set win $_win
set objname $_objname
if { ! [info exists GuiDir] } { set GuiDir "" }
set prefix "@prefix@"
set kbdImage [locateInDirs kbd.xbm \
[list ${GuiDir} . .. examples \
../@srcdir@ @srcdir@ \
@datadir@ /usr/share]]
image create bitmap kbd -file ${kbdImage}
button $win.b -image kbd
pack $win.b
bind $win.b <Enter> "focus $win.b"
bind $win.b <KeyPress> "$this SendMakeKey %k"
bind $win.b <KeyRelease> "$this SendBrakeKey %k"
}
method SendMakeKey { key } {
puts "$parent SendToSimulator $objname M$key"
$parent SendToSimulator $objname M$key
}
method SendBrakeKey { key } {
puts "$parent SendToSimulator $objname B$key"
$parent SendToSimulator $objname B$key
}
}
}
class Scope {
protected {
variable parent
variable win
variable objname
variable noOfChannels
variable value
variable xvalue
variable actIdx
variable sizex
variable sizey
#for all channels
variable minx
variable maxx
#for each channel a seperate val
variable miny
variable maxy
}
public {
constructor { _parent _objname _win _noOfChannels} {
set parent $_parent
set win $_win
set objname $_objname
set noOfChannels $_noOfChannels
set minx 0
set maxx 0
set sizex 100
set sizey 100
for { set cnt 0 } { $cnt < $_noOfChannels} { incr cnt } {
set actIdx($cnt) 0
set miny($cnt) 0
set maxy($cnt) 0
}
canvas $win.c
pack $win.c
}
method DrawChannel { channel } {
set anzValues [expr $actIdx($channel) -1]
if {$anzValues > 2} {
set xrange [expr $maxx - $minx]
set yrange($channel) [expr $maxy($channel) - $miny($channel) ]
puts "Versuche Kanal $channel mit yrange $yrange($channel) max: $maxy($channel) min: $miny($channel)"
for { set cnt 0 } { $cnt < $anzValues } { incr cnt } {
set a [expr ( $value($channel,$cnt) - $miny($channel)) ]
set b [ expr $a * (20 * ($channel+1) ) ]
set c [ expr $b / $yrange($channel) ]
puts "Ber: $a $b $c miny $miny($channel)"
set val [expr ( $value($channel,$cnt) - $miny($channel) ) * (20 * ($channel+1)) / $yrange($channel) ]
set aa [expr ( $xvalue($channel,$cnt) - $minx) ]
set bb [expr $aa * $sizex ]
set cc [expr $bb / $xrange ]
puts "Berx: $aa $bb $cc minx: $minx range: $xrange"
set xval [expr ( $xvalue($channel,$cnt) - $minx) * $sizex / $xrange]
lappend coords $xval $val
#puts "Channel $channel cnt: $cnt val: $val"
#update
} ; #for
puts $coords
$win.c create line $coords
}
}
method Redraw { } {
puts "##################### Redraw ###################################"
#now draw the channels
for { set cnt 0 } { $cnt < $noOfChannels} { incr cnt } {
DrawChannel $cnt
}
#set l [array names value]
#puts "l: $l"
#set len [llength $l]
#for { set ii 0 } { $ii < $len } { incr ii } {
# puts "[lindex $l $ii]"
# set tmp $value([lindex $l $ii])
# puts "[lindex $l $ii] value: $tmp"
#}
}
method PrintOut { zeit } {
puts -nonewline "$zeit ,"
for { set cnt 0 } { $cnt < $noOfChannels} { incr cnt } {
set idx [expr $actIdx($cnt) -1]
if {$idx > 1} {
puts -nonewline "$value($cnt,$idx) ,"
} else {
puts -nonewline "0 ,"
}
}
puts ";"
}
method ChangeValue { time channel val } {
#puts "Scope Change Value aufgerufen mit $time $channel $val"
set idx $actIdx($channel)
#puts "Idx fuer Kanal $channel ist $idx"
set value($channel,$idx) $val
set xvalue($channel,$idx) $time
incr actIdx($channel)
if { $time > $maxx} { set maxx $time }
if { $time < $minx} { set minx $time }
if { $val > $maxy($channel) } { set maxy($channel) $val }
if { $val < $miny($channel) } { set miny($channel) $val }
#Redraw
PrintOut $time
}
}
}
class TraceControl {
protected {
variable parent
variable win
variable objname
variable traceOn
}
public {
constructor { _parent _objname _win } {
set parent $_parent
set objname $_objname
set win $_win
set traceOn 0
puts "Trace Control"
puts "parent $parent"
puts "objname $objname"
puts "win $win"
button $win.$objname -text "Trace: $objname" -command "$this ToggleControl" -background red
pack $win.$objname
}
method ToggleControl { } {
if { $traceOn == 0 } {
set traceOn 1
$win.$objname configure -background red
} else {
set traceOn 0
$win.$objname configure -background green
}
$parent SendToSimulator $objname $traceOn
}
}
}
class UpdateControl {
protected {
variable parent
variable win
variable objname
variable updateOn
}
public {
constructor { _parent _objname _win } {
set parent $_parent
set objname $_objname
set win $_win
set updateOn 1
button .updateControl -text "Update Control" -command "$this ToggleControl" -background green
pack .updateControl
}
method ToggleControl { } {
if { $updateOn == 1 } {
set updateOn 0
.updateControl configure -background red
} else {
set updateOn 1
.updateControl configure -background green
}
$parent SendToSimulator UpdateControl $updateOn
}
}
}
class SerialTx {
protected {
variable parent
variable win
variable objname
}
public {
constructor { _parent _objname _win} {
set parent $_parent
set win $_win
set objname $_objname
frame $win.$objname
frame $win.$objname.tx
label $win.$objname.tx.name -text $objname
text $win.$objname.tx.text -width 40 -height 6
label $win.$objname.tx.status -text "Serial transmitter of PC"
label $win.$objname.tx.pin -text "-----------"
bind $win.$objname.tx.text <KeyPress> "$this NewCharEntered %A"
bind $win.$objname.tx.text <Button-2> "$this GetStringFromSelection "
frame $win.$objname.config
label $win.$objname.config.baudrate -text "-----------"
pack $win.$objname.tx $win.$objname.tx.name $win.$objname.tx.text $win.$objname.tx.status $win.$objname.tx.pin
pack $win.$objname.config $win.$objname.config.baudrate
pack $win.$objname
}
method GetStringFromSelection {} {
NewStringEntered [selection get]
}
method NewStringEntered { str } {
foreach buchstabe [split $str {} ] { NewCharEntered $buchstabe }
}
method NewCharEntered { c } {
set trans ""
if { $c == "space" || $c == " " } {
set trans __SPACE__
} else {
if { $c != "" } { set trans $c }
}
if { $trans != "" } { $parent SendToSimulator $objname $trans }
}
}
}
class SerialRx {
protected {
variable parent
variable win
variable objname
}
public {
constructor { _parent _objname _win} {
set parent $_parent
set win $_win
set objname $_objname
frame $win.$objname
frame $win.$objname.rx
label $win.$objname.rx.name -text $objname
text $win.$objname.rx.text -width 40 -height 6
label $win.$objname.rx.status -text "Serial receiver of PC"
label $win.$objname.rx.pin -text "-----------"
frame $win.$objname.config
label $win.$objname.config.baudrate -text "-----------"
pack $win.$objname.rx $win.$objname.rx.name $win.$objname.rx.text $win.$objname.rx.status $win.$objname.rx.pin
pack $win.$objname.config $win.$objname.config.baudrate
pack $win.$objname
}
method ChangeValue { c } {
switch $c {
__SPACE__ { $win.$objname.rx.text insert end " " }
__SEMICOLON__ { $win.$objname.rx.text insert end ";" }
__CR__ { }
__LF__ { $win.$objname.rx.text insert end "\n" }
__DOUBLE_QUOTE__ { $win.$objname.rx.text insert end "\"" }
__SINGLE_QUOTE__ { $win.$objname.rx.text insert end "\'" }
__DOLLAR__ { $win.$objname.rx.text insert end "\'" }
__COMMA__ { $win.$objname.rx.text insert end ";" }
__MINUS__ { $win.$objname.rx.text insert end "-" }
default { $win.$objname.rx.text insert end $c }
}
}
}
}
class Lcd {
protected {
variable xsize
variable ysize
variable parent
variable win
variable objname
}
public {
constructor { _parent _objname _win _xs _ys } {
set xsize $_xs
set ysize $_ys
set parent $_parent
set win $_win
set objname $_objname
#label $win.t -width $xsize -height $ysize
#pack $win.t
frame $win.$objname -borderwidth 2 -relief solid
pack $win.$objname
for { set y 0 } { $y < $ysize } { incr y } {
frame $win.$objname.y$y
pack $win.$objname.y$y -side top
for { set x 1 } { $x <= $xsize } { incr x } {
#label $win.f.y$y.$x -textvariable $objname$y$x -width 3
label $win.$objname.y$y.x$x -text "-" -width 1
pack $win.$objname.y$y.x$x -side left
}
}
}
method WriteChar { x y ch } {
set tmp [binary format c $ch]
#global $objname$y$x
#set $objname$y$x $tmp
if { $x <= $xsize } {
if { $y < $ysize } {
$win.$objname.y$y.x$x configure -text $tmp
}
}
}
method MoveCursor { x y } {
set cursor_x $x
incr cursor_x
set cursor_y $y
for { set y 0 } { $y < $ysize } { incr y } {
for { set x 1 } { $x <= $xsize } { incr x } {
$win.$objname.y$y.x$x configure -background gray
}
}
if {$cursor_x < $xsize} {
if { $cursor_y < $ysize} {
$win.$objname.y$cursor_y.x$cursor_x configure -background blue
}
}
}
}
}
class Net {
protected {
variable outState
variable inState
variable objname
variable win
variable parent
}
public {
constructor { _parent _objname _win } {
set parent $_parent
set win $_win
set objname $_objname
frame $win.$objname -borderwidth 2 -relief solid
pack $win.$objname -side left
label $win.$objname.l -text $objname
pack $win.$objname.l
set outState t ; #tritstate
set inState u ; #unknown
menubutton $win.$objname.mb -menu $win.$objname.mb.m -text $outState -relief raised
menu $win.$objname.mb.m
$win.$objname.mb.m add radiobutton -label H -value H -variable $objname.var -command "$this ValueChangedFromGui H"
$win.$objname.mb.m add radiobutton -label h -value h -variable $objname.var -command "$this ValueChangedFromGui h"
$win.$objname.mb.m add radiobutton -label t -value t -variable $objname.var -command "$this ValueChangedFromGui t"
$win.$objname.mb.m add radiobutton -label l -value l -variable $objname.var -command "$this ValueChangedFromGui l"
$win.$objname.mb.m add radiobutton -label L -value L -variable $objname.var -command "$this ValueChangedFromGui L"
pack $win.$objname.mb
global $objname.var
set $objname.var $outState
label $win.$objname.lin -text $inState
pack $win.$objname.lin
}
method ValueChangedFromGui { newValue } {
set outState $newValue
$win.$objname.mb configure -text $outState
#puts "Value from menu $this has changed"
#puts "$outState"
$parent SendToSimulator $objname $newValue
}
method ChangeValue { newValue } {
set inState $newValue
$win.$objname.lin configure -text $inState
}
}
}
class AnalogNet {
protected {
variable outValue
variable inValue
variable objname
variable win
variable parent
}
public {
constructor { _parent _objname _win } {
set parent $_parent
set win $_win
set objname $_objname
#puts "Ich bin this: $this extern objname : $objname"
frame $win.$objname -borderwidth 2 -relief solid
pack $win.$objname -side left
label $win.$objname.l -text $objname
pack $win.$objname.l
set outState 0 ; #tritstate
set inState 0 ; #unknown
entry $win.$objname.e -width 4
pack $win.$objname.e
button $win.$objname.b -text "Update" -command "$this ValueChangedFromGui"
pack $win.$objname.b
}
method ValueChangedFromGui { } {
set newValue [$win.$objname.e get]
#puts "Neuer Wert: $newValue fuer $objname"
$parent SendToSimulator $objname $newValue
}
method ChangeValue { newValue } {
#set inState $newValue
#$win.$objname.lin configure -text $inState
}
}
}
class Master {
protected {
variable sock
}
public {
constructor { _sock } {
#puts "Constructor from Master called!"
set sock $_sock
#set sock [socket localhost $socketNo]
fileevent $sock readable "$this ReadFromSimulavr"
fconfigure $sock -blocking 0
}
method ReadFromSimulavr { } {
if { ![eof $sock] } {
gets $sock x
#puts "---> $x <---"
set readList [ split $x]
set offset [string first " " $x ]
set sub [ string range $x $offset end ]
#puts "offset: $offset rest: $sub"
# create class objName parent win objName
set front [lrange $x 1 2]
set back [lrange $x 3 end]
set objName [lindex $x 2]
switch [lindex $readList 0] {
create {
#puts "$front $this $objName $back"
eval "$front $this $objName $back"
puts -nonewline $sock "__ack X "
}
set {
if { [lindex $readList 2] == "__semicolon__" } {
eval "[lindex $readList 1] ChangeValue \";\""
} else {
eval "[lindex $readList 1] ChangeValue [lindex $readList 2]"
}
puts -nonewline $sock "__ack X "
}
default {
#puts ">$x<"
eval $x
puts -nonewline $sock "__ack X "
}
}
#puts -nonewline $sock "__ack X "
flush $sock
} else {
puts "Error condition in io input handler"
exit
}
}
method SendToSimulator { id val } {
#puts "Update the var $id to $val"
puts -nonewline $sock "$id $val "
flush $sock
update
}
}
}
# create a server socket
socket -server NewConnection 7777
proc NewConnection { _sock _address _port } {
puts "New Connection on GUI Server established!"
puts "Socket: $_sock from Address $_address and port $_port"
Master guiMaster_$_sock $_sock
}
frame .x
pack .x
#class NEwObjectName (parameters for constructor: baseWindow and NameOfNet)
#Net netz1 guiMaster .x netz1
#Net netz2 guiMaster .x netz2
#Lcd lcd1 guiMaster .x lcd1 20 4
|