| |
Image you want to define a mapper for this protocol :
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| High | Low | List |A|B|C| Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
composed of two 4-bits integers, a byte with some well-known values,
three flags A,B and C, and some data stored on 13 bits.
You have to write the abstract specification for it :
mapper example = {
size = 4
field -high @ (0, 0.4) = {
type = integer
}
field -low @ (0.4, 0.4) = {
type = integer
}
field -list @ (1, 1) = {
type = list {
0 "one" "value one"
1 "two" "value two"
2 "three" "value three"
}
}
field -flags @ (2, 0.3) = {
type = flags {
0x04 "a" "A is off" "A is on"
0x02 "b" "B is off" "B is on"
0x01 "c" "C is off" "C is on"
}
}
field -data @ (0.19, 0.13) = {
type = integer
}
}
|
|
As you can see, the syntax is quite straight forward. The position (offset) and size
of a field is given with the number of bytes followed by the number of bits. You then
specify the type of the field, and that's all (a more detailled description of the
field is possible, but this example should be kept simple.
Refers to the documentation).
To use it, run the compiler which will generate a new Tcl command, then load it
in your Tcl interpreter (use the load command as the compiler generate
a .so module). The following session illustrate how it works :
% packet pkt 16
pkt
% dumpraw pkt
00000000 00 00 00 00|00 00 00 00|00 00 00 00|00 00 00 00 ................
% pkt newmapper example
example
% pkt example configure
-high 0 -low 0 -list one -flags {-a -b -c} -data 0
% pkt example configure -high 4 -low 0xA -data 12345
% dumpraw pkt
00000000 4A 00 10 39|00 00 00 00|00 00 00 00|00 00 00 00 J..9............
% pkt example configure
-high 4 -low 10 -list one -flags {-a -b -c} -data 4153
% pkt example configure -list two -flags +b
% dumpraw pkt
00000000 4A 01 50 39|00 00 00 00|00 00 00 00|00 00 00 00 J.P9............
% pkt example configure
-high 4 -low 10 -list two -flags {-a +b -c} -data 4153
% pkt example getverbose
-high 4 -low 10 -list {value two} -flags {{A is off} {B is on} {C is off}} -data 4153
%
|
|
This short example illustrates the main concepts of GASP. The first step
is to create a packet which is a physical area of memory as shown
with the dump command.
Then create a mapper to tell GASP how to code/encode the fields contained
in the physical memory. To see the value in human readable form (as opposed
to hex dump) use the configure command applied to the mapper. To modify
a(some) value(s) just put them after configure.
If the value doesn't fit in the space allocated for the field, the data is
truncated (as 12345=0x3039 whose highest bit is lost).
When refering to a list, you can use the abstract name to set the value ;
when refering to a flag, use +name to set it and -name to clear it.
| | |