Bit fields from content in hexadecimal notation.

Jun 12, 2012 at 8:39 PM

Hi all,

is there a way to define bit fields e.g. if a byte content is written as two hexadecimal digits? Something like this:

AsciiString(2) ByteValue
{
    UINT8 b0:1 = ....;
    UINT8 b1:1 = ....;
    ....
}

 I tried to define Local.Byte and use typecast, i.e.

[Local.Byte = StringToNumber("0x"+ByteValue)]
AsciiString(2) ByteValue
{
    UINT8(Local.Byte) b0:1 = .....;
    ....
}

but compiler does not accept such syntax.

My current ugly implementation looks like this:

Struct SomeStruct = Local.Result
{
    _struct
    {
	[Local.Result = ""]
	[Local.Separator = ""]
	[Local.Byte = StringToNumber("0x"+ByteValue)]
	[Local.Result = Local.Result + Local.Separator + (Local.Byte & 0x04)!=0 ? ....]
	[Local.Separator = " | "]
	[Local.Result = Local.Result + Local.Separator + (Local.Byte & 0x08)!=0 ? ....]
	[Local.Result = Local.Result + Local.Separator + (Local.Byte & 0x10)!=0 ? ....]
        ....
        AsciiString(2) ByteValue;
    }
}

Please, could somebody help me with such bit fields definition?

Thanks for any help, pf

 

Jun 13, 2012 at 6:16 AM
Edited Jun 13, 2012 at 6:17 AM
pf1957 wrote:

My current ugly implementation looks like this:

Struct SomeStruct = Local.Result
{
   ...
}

 

While debugging, I found that this does not work at all, here is the new iplementation, which works, but is still ugly:

Struct SomeStruct = Local.Result
{
	_struct
	{
		[Local.Byte = StringToNumber("0x"+ByteValue)]
		AsciiString(2) ByteValue;
		[Local.Result 
			= FormatString("0x%s = ",ByteValue)
			+ ((Local.Byte & 4)!=0 ? "b2:..." : "b2:...")
			+ " | "
			+ ((Local.Byte & 8)!=0 ? "b3:..." : "b3:...")
		]
		_struct {}
	}
}

 

Jun 13, 2012 at 4:43 PM

I'm not aware of any easier way to do this.  Currently we only support using raw values from the frame as input into the parsing.

Paul

Jun 13, 2012 at 6:13 PM

Never mind,

thanks for your time, pf