¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: How would you parse this data?


 

Hi Matt,

That looks like a classic candidate for a state machine.

I.e. rather that attempt to parse a complete message in one mouthful, implement a routine that eats numbers, delimited by white space or the lf/cr.

Lf/cr resets the state machine and spits out your interesting data, and for each "number" you maintain a couple of state variables (data chunk, sub element).

And Atoi won't work on negative numbers will it?

Sorry this is a bit brief/vague, but I hate typing on my phone :)
All the best,
Ol

--- In Crestron@..., "matt_rasmussen_2000" <mjrtoo@...> wrote:

Yeah, right, the string is not always the same, like I said, the attenuation value can be from 1 to 4 bytes long, for each channel. I was thinking of getting the LEN of the attenuation data, then MID the string based on that but seems more work than the removes anyway.

--- In Crestron@..., "jrw_96" <jrw_96@> wrote:

Use a buffer and collect everything in said buffer. Then just break it down as necessary. Only if the incoming strings are predictable and/or the end of the string is always &#92;x0d&#92;x0a...

If the above is true then this should be gravy for you. It's when you do NOT have set points (delimiter(s) and actual sub-headers differentiating the substring/channel info) [always seems to be my case with crc's and what not] that you have to wonder "is this really worth it" imo...

JRW

--- In Crestron@..., "matt_rasmussen_2000" <mjrtoo@> wrote:

Here's the string

0 0 0 0 1 0 0 0 0 0 0 0 -44 0 0 0 0 0 0 0 0 -27 0 0 0 0 0 0 0 1 -26 0 0 0 0 0 0 0 0&#92;x0d&#92;x0a

The first three 0's are status of the device itself, then the next group of 9 (not including spaces) are individual channel data. So channel 1 = 0 1 0 0 0 0 0 0 0
channel 2 = -44 0 0 0 0 0 0 0 0
channel 3 = -27 0 0 0 0 0 0 0 1
channel 4 = -26 0 0 0 0 0 0 0 0

the first set of chars before the first space can be 0...-100, all the other data is a single byte.

My method is using REMOVE statements like below
status1 = ATOI(REMOVE("&#92;x20", rx$);
status2 = ATOI(REMOVE("&#92;x20", rx$);
status3 = ATOI(REMOVE("&#92;x20", rx$);

Attenuation[1] = REMOVE("&#92;x20", rx$);
ch1Clip[1] = ATOI(REMOVE("&#92;x20", rx$);
etc.,

all the way through the string. Not sure if it's even worth going through breaking up the string into channel groups and working on it that way. What do you think, splitting hairs?

Join [email protected] to automatically receive all group messages.