proc getOneLine {} { global convertBuffer global convertLine if {[string length $convertLine] > 0} { set a $convertLine set convertLine "" return $a } set i [string first "\n" $convertBuffer] set o [string length $convertBuffer] if {$o < 1} { return "" } set o [expr $o + 32] if {$i < 0} { set i $o } set a [string range $convertBuffer 0 [expr $i - 1]] set convertBuffer [string range $convertBuffer [expr $i + 1] $o] return $a } proc putBackLine {a} { global convertLine set convertLine $a } proc getNextLine {} { global convertBuffer for {set a ""} {[string length $a] < 1} {} { if {[string length $convertBuffer] < 1} { return "" } set a [getOneLine] } return $a } proc testHeadingLine {a} { set b [string range $a 2 2] if {[string compare $b ":"] != 0} { return 0 } set b [string range $a 5 5] if {[string compare $b ":"] != 0} { return 0 } set b [string range $a 8 8] if {[string compare $b "."] != 0} { return 0 } return 1 } proc testDataLine {a} { set b [string range $a 8 8] if {[string compare $b ":"] != 0} { return 0 } return 1 } proc readUpOnePacket {} { for {set a ""} {[testHeadingLine $a] != 1} {} { set a [getNextLine] if {[string length $a] < 1} { return "" } } set a [string range $a 0 7] set ret "+---------+---------------+----------+\n$a,000,000 ETHER\n|0 |" for {} {1==1} {} { set a [getNextLine] if {[string length $a] < 1} { break } if {[testDataLine $a] != 1} { putBackLine $a break } set a [string range $a 9 45] regsub -all " " $a "" b set b [string tolower $b] for {} {[string length $b] > 1} {} { set a [string range $b 0 1] set b [string range $b 2 99] set ret "$ret$a|" } } return "$ret\n" } proc doConvertBuffer {dataIn} { global convertBuffer global convertLine set convertBuffer $dataIn set convertLine "" set dataOut "" for {} {1==1} {} { set a [readUpOnePacket] if {[string length $a] < 1} { break } set dataOut "$dataOut$a\n" puts -nonewline stdout "." flush stdout } return $dataOut } proc doConvertFile {ni no} { puts "reading file $ni..." set f [open "$ni" "r"] set di [read $f] close $f puts -nonewline "converting data..." set do [doConvertBuffer $di] puts "" puts "writing file $no..." set f [open "$no" "w+"] puts $f $do close $f } proc doConvertShow {bi no} { puts "reading buffer $bi..." set di [exec show monitor capture buffer $bi dump] puts -nonewline "converting data..." set do [doConvertBuffer $di] puts "" puts "writing file $no..." set f [open "$no" "w+"] puts $f $do close $f } # doConvertShow b1 flash:cap.eth doConvertFile cap.in cap.out