08-21-2017, 04:43 +0200
AuthorPost
thommey  08-09-2010, 15:58   | [TCL] Hexdump Jabber
(Administrator)
Member since 03/2004
62 Posts
                                                                                                                              
01
02
03
04
05
06
07
08
09
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
proc Int2Hex {data} {
    if {![string is digit -strict $data]} {return -1}
    set str "0123456789abcdefghijklmnopqrstuvwxyz"; set text ""
    set i [expr {$data & 15}]; set r [expr {$data / 16}]
    set text [string index $str $i]
    while {$r>0} {
        set i [expr {$r & 15}]; set r [expr {$r / 16}]
        set text "[string index $str $i]$text"
    }
    return $text
}

proc conv {text} {
    foreach ch [split $text ""] {
        if {[scan $ch %c]<27} {
            set text [string map [list $ch [format %c [expr {[scan $ch %c]+64}]]] $text]
        }
    }
    return $text
}

proc puthex {data {saddr 0}} {
    set pos 0; set sw 0; set hex(0) ""; set hex(1) ""; set text(0) ""; set text(1) "";
    while {[string length $data]>0} {
        set spos [string range "0000[Int2Hex $pos]" end-3 end]
        if {$saddr!=0} {
            set stpos [string range "0000[Int2Hex [expr {$pos+$saddr}]]" end-3 end]
        } {set stpos ""}
        if {[string length $data]<8} {
            set text($sw) $data
            incr pos [string length $data]
            binary scan $data H* hex($sw)
            set data ""
        } {
            incr pos 8
            binary scan $data H16 hex($sw)
            set text($sw) [string range $data 0 7]
            set data [string range $data 8 end]
        }
        set sw [expr {$sw^1}]
        if {[string length $data]<8} {
            set text($sw) $data
            incr pos [string length $data]
            binary scan $data H* hex($sw)
            set data ""
        } {
            incr pos 8
            binary scan $data H16 hex($sw)
            set text($sw) [string range $data 0 7]
            set data [string range $data 8 end]
        }
        set sw [expr {$sw^1}]
        set txt(0) ""; foreach {ch0 ch1} [split $hex(0) ""] {append txt(0) "$ch0$ch1 "}; append txt(0) "                        "; set txt(0) [string range $txt(0) 0 22]
        set txt(1) ""; foreach {ch0 ch1} [split $hex(1) ""] {append txt(1) "$ch0$ch1 "}; append txt(1) "                        "; set txt(1) [string range $txt(1) 0 22]
        set text(0) [string range "[conv $text(0)]        " 0 7]
        set text(1) [string range "[conv $text(1)]        " 0 7]
        if {$stpos!=""} {
            putcmdlog "0x$stpos | 0x$spos | $txt(0) | $txt(1) | $text(0) | $text(1)"
        } {
            putcmdlog "0x$spos | $txt(0) | $txt(1) | $text(0) | $text(1)"
        }
        set hex(0) ""; set hex(1) ""; set text(0) ""; set text(1) "";
    }
}





puthex $message
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen