Post by Tasp on Jan 11, 2021 9:30:41 GMT -5
I'm having difficulty parsing information I'm receiving, been working on this for quite some time but I cannot successfully parse consistently. Mainly because the dataset isn't always the same format.
There are some consistent portions which I've tried to factor in. But I'm getting blinded and decided to ask for help.
Some of the info is easy to parse because the identifiers are /ti /ri /pi, But there is a 2 letter code which doesn't have anything preceding it to identify it. That 2 letter code normally falls within 3 specific places, there are 305 different pairs, I have code that coverts those 2 letter codes into English readable elements elsewhere and working.
The data is sent a block at a time, which I've mimicked by reading a file (attached) a line at a time. The structure is always, account, data, description. It's the data mainly that I'm having difficulty parsing for the various components.
My original thought was that the first 2 chars in the string represented the data type or identifier and for 97% this is the case however there is that 3% anomaly.
This is what I have nailed it down to so far. It seems super clunky and I'm sure there's a simpler way to achieve this.
Any thoughts gratefully recieved.
There are some consistent portions which I've tried to factor in. But I'm getting blinded and decided to ask for help.
Some of the info is easy to parse because the identifiers are /ti /ri /pi, But there is a 2 letter code which doesn't have anything preceding it to identify it. That 2 letter code normally falls within 3 specific places, there are 305 different pairs, I have code that coverts those 2 letter codes into English readable elements elsewhere and working.
The data is sent a block at a time, which I've mimicked by reading a file (attached) a line at a time. The structure is always, account, data, description. It's the data mainly that I'm having difficulty parsing for the various components.
My original thought was that the first 2 chars in the string represented the data type or identifier and for 97% this is the case however there is that 3% anomaly.
This is what I have nailed it down to so far. It seems super clunky and I'm sure there's a simpler way to achieve this.
Any thoughts gratefully recieved.
'CRC code courtesy Chris Inverson / Rod
'For testing we are grabbing the info from a file, IRL this will come from IP, while the chance of RXing different signals at the
'same time is low, each block's IP address will be checked and the block discarded if it doesn't match the previously recieved block.
GLOBAL RXDATAlen
OPEN "RXDATA.txt" FOR INPUT AS #file
WHILE NOT(EOF(#file))
block = block + 1
LINE INPUT #file, RXDATA$
GOSUB [Parser]
WEND
SUB CRC RXDATA$
RXDATAlen = LEN(RXDATA$)
crcdata$ = RXDATA$
crc = 255
FOR x = 1 TO (RXDATAlen - 1)
crc = crc XOR ASC(MID$(crcdata$, x, 1))
NEXT x
IF RIGHT$(RXDATA$, 1) = CHR$(crc) THEN
crc = 1
PRINT "CRC OK!"
ELSE
PRINT "***CRC FAILED!***"
END IF
END SUB