Wireshark-dev: Re: [Wireshark-dev] Small (but annoying) display issue
From: "ronnie sahlberg" <ronniesahlberg@xxxxxxxxx>
Date: Tue, 24 Oct 2006 14:54:59 +1000
You must append to the actual item itself and not the expansion:
it=proto_tree_add_item(led_tree, hf_led_timing_3, tvb, offset,   2, FALSE);
switch( time_slot3 ) {
    case INDEX_0:
     break;
    case INDEX_1:
       proto_tree_add_text(it, tvb, offset, 2, "Fully ON for one second");
        break;
     case INDEX_2:
        proto_tree_add_text(it, tvb, offset, 2,"ON for .5 s and OFF for .5 s");
        break;
}




Much better however would be to do it using a proper proto_tree_add_item() and a value_string instead of the proto_tree_add_text() (we dont like proto_tree_add_text)

Something like
... value_string blink_vals[] = {
   {INDEX_1, "fully on for one second"},
   ...
   {0, NULL}
};

{ &hf_led_timing_3,
      { "LED Timing slot 3",
        "vppn.led.timing3",
        FT_UINT16, BASE_DEC, VALS(blink_vals), SLOT_3,
        "3rd second", HFILL }},



and a proto_tree_add_item(... hf_led_timing_3, ...);



On 10/24/06, Bill Fassler <bill.fassler@xxxxxxxxx> wrote:
You haven't heard from me for a while because with everyones help I progressed from complete novice all the way up to amateur, but try as I might I can't seem to get this silly display output to do as I wish.
 
Here's the scoop: I have 4 nibbles of individual data in 2 bytes.  I couldn't find a convenient way to parse nibbles, so I display the 2 bytes in 4 bit boolean fields. I can't seem to use the value strings to interpret the value because it isn't a bit and it isn't a byte.  It is a nibble or a guint4 (and there isn't such an animal).  Anyway, I interpret the value in my code and try to append or add the text but it always comes out in a separate line.  Here is what is now being displayed:
 
    LED Blinking schedule: 0x2222
        .... .... .... 0010 = LED Timing slot 3: Blink at:
        ON for .5 second and OFF for .5 second
        .... .... 0010 .... = LED Timing slot 4: Blink at:
        ON for .5 second and OFF for .5 second
        .... 0010 .... .... = LED Timing slot 5: Blink at:
        ON for .5 second and OFF for .5 second
        0010 .... .... .... = LED Timing slot 6: Blink at:
        ON for .5 second and OFF for .5 second
and I was shooting for:
 
    LED Blinking schedule: 0x2222
        .... .... .... 0010 = LED Timing slot 3: Blink at:  ON for .5s and OFF for .5s 
        .... .... 0010 .... = LED Timing slot 4: Blink at:  ON for .5s and OFF for .5s
        .... 0010 .... .... = LED Timing slot 5: Blink at:  ON for .5s and OFF for .5s 
        0010 .... .... .... = LED Timing slot 6: Blink at:  ON for .5s and OFF for .5s
 
Here is (hopefully) enough of my code to give you an idea of what my problem is:

 
led_item = proto_tree_add_item(vppn_tree, hf_led_timing, tvb, offset, 2, FALSE);
led_tree = proto_item_add_subtree(led_item, ett_led);
cmdcode = tvb_get_guint8(tvb, offset);
time_slot3 = lo_nibble(cmdcode);
time_slot4 = hi_nibble(cmdcode);
proto_tree_add_item(led_tree, hf_led_timing_3, tvb, offset,   2, FALSE);
switch( time_slot3 ) {
    case INDEX_0:
     break;
    case INDEX_1:
       proto_tree_add_text(led_item, tvb, offset, 2, "Fully ON for one second");
        break;
     case INDEX_2:
        proto_tree_add_text(led_item, tvb, offset, 2,"ON for .5 s and OFF for .5 s");
        break;
}
 
#define SLOT_3                   0x000F
#define SLOT_4                   0x00F0
#define SLOT_5                   0x0F00
#define SLOT_6                   0xF000
 
 { &hf_led_timing_3,
      { "LED Timing slot 3",
        "vppn.led.timing3",
        FT_BOOLEAN, 16, TFS (&blink_sched_tfs), SLOT_3,
        "3rd second", HFILL }},
Anyway, when I tried the append_text routine I got the text appended to the tree and not the item as so:
 
proto_item_append_text(led_item, "On for .5 and OFF for .5s");
 
gives me this:
 
    LED Blinking schedule: 0x2222 ON for .5s and OFF for .5s  ON for .5s and OFF for .5s  ON for .5s and OFF for .5s  ON for .5s and OFF for .5s 
        .... .... .... 0010 = LED Timing slot 3: Blink at: 
        .... .... 0010 .... = LED Timing slot 4: Blink at: 
        .... 0010 .... .... = LED Timing slot 5: Blink at:  
        0010 .... .... .... = LED Timing slot 6: Blink at:  
I apologize for such a petty question, but its drivin' me nuts.  I've tried every permutaion I can think of.
 
Bill Fassler
Vocal Tech


Stay in the know. Pulse on the new Yahoo.com. Check it out.


_______________________________________________
Wireshark-dev mailing list
Wireshark-dev@xxxxxxxxxxxxx
http://www.wireshark.org/mailman/listinfo/wireshark-dev