I have a stream of partially binary data, and I want to match when a certain bit is set in a byte in a certain position in the string.
This is an existing system in .NET using System.Text.RegularExpressions
which is configured with a number of patterns - when certain patterns are matched, the match triggers an action.
I'm interfacing to a device where one of the indicators is only available within a bitfield.
The only alternative I can see is to match a whole equivalence class of all the bytes which have that bit set.
This is a Mettler-Toledo scale interface.
The stream looks like this:
STX
SWA
SWB
SWC
WEIGHT (6 bytes ASCII)
TARE (6 bytes ASCII)
0x0D (CR)
(Optional checksum)
Where SWA
, SWB
, SWC
are status word bytes and I'm interested in bit 3 of SWB
.
They always set bit 5 to 1 in all these status words so that it is a space (0x20
) when no bits are set. So in practice with no other status bits coming through, SWB
alternates between (
(0x50
- 01010000
) and SPACE (0x20
- 00100000
) In actuality, the scale is also likely to send bits 0 and 4 in other states which I don't care about.
So I could match ..[\(all other equivalent characters]..{6}.{6}\r\0