Help with repeat loops and if else statements
Don M
Posts: 1,652
I am trying to parse some data from a dat data file. I have one method I wrote (included in the archive) that will parse the data using specific case statements. It is a long program and will only respond to specific addresses within the data. What I was trying to do was parse through the data without using specific addresses. I'm thinking this should be possible but am having trouble understanding the "quit" or "next" command trying to get out of a loop and back into the main repeat loop.
Anywhere you see the "quit" directive is where I want to go back to the Main repeat loop.
If you download the zipped file and run the other method it will print on PST the way I'm trying to get this piece of code to work. I've spent a great number of hours (days) trying to make my way through this...
Any help greatly appreciated.
Edit: Added this dat data section for viewing. It is included in zip file.
Anywhere you see the "quit" directive is where I want to go back to the Main repeat loop.
pub testing2 | chk, d, t, h i := 0 n := 0 chksum := 0 term.tx(13) ' Move down 1 line repeat i from 0 to 127 ' Main loop. Cycle through xxx words from dat section if (data[i] & $0F00) == $0100 ' Check for Command and Slave ACK if data[i] == $0100 ' Slave ACK found term.hex(data[i], 3) ' Print Slave ACK i++ ' Increment index if data[i] == $0000 ' Check for Master ACK term.tx(58) ' Master ACK found print colon term.hex(data[i], 3) ' Print Master ACK quit ' Need to quit to main repeat loop else ' If no Master ACK such as in Slave reset i-- ' Decrement index term.tx(13) ' Print carriage return quit ' Need to quit to main repeat loop term.hex(data[i], 3) ' Print Master command term.tx(32) ' Print space repeat ' Repeat to look for rest of Master command chksum += data[i] ' Add word to checksum i++ ' Increment index n++ ' Increment N counter if data[i] ==(chksum & $00FF) ' Check for Command checksum repeat n ' Print N times term.hex(data[i], 3) ' Print checksum term.tx(32) ' Print space term.tx(58) ' Print colon chksum := $0000 ' Clear checksum n := 0 ' Reset N counter quit ' Need to quit to main repeat loop else ' If checksum does not match data i-- ' Decrement index n := 0 ' Reset N counter if data[i] == $000 ' Check for Master ACK was printed so print term.tx(13) ' Master ACK was printed so print carriage return quit ' Need to quit to main repeat loop repeat ' Collecting additional data from Master chksum += data[i] ' Add word to checksum i++ ' Increment index n++ ' Increment N counter if (data[i] & $00FF) ==chksum ' Looking for checksum match chksum := $0000 ' Clear checksum i := i - n ' Preset index counter if data[i] == $0100 ' Look for Slave ACK term.hex(data[i], 3) ' Print data from Slave such as from Reader Just Reset term.tx(32) ' Print space quit ' Need to quit to main repeat loop repeat n + 1 ' Repeat printing of data N + 1 times term.hex(data[i], 3) ' Print Slave data term.tx(32) ' Print space i++ ' Increment index n := 0 ' Reset N counter quit ' Need to quit to main repeat loop
If you download the zipped file and run the other method it will print on PST the way I'm trying to get this piece of code to work. I've spent a great number of hours (days) trying to make my way through this...
Any help greatly appreciated.
Edit: Added this dat data section for viewing. It is included in zip file.
dat version byte "Parse_Playground5", 13, 0 data word $0110, $0010, $0100, $0108, $0008, $0100, $0130, $0030, $0100, $0112, $0012, $0000, $0100, $0000, $0133, $0033 word $0006, $0009, $010F, $0000, $0111, $0000, $0003, $0010, $0001, $0001, $0026, $0100, $010B, $000B, $000B, $010B word $0000, $0131, $0031, $0001, $0000, $0001, $0000, $0064, $0002, $0000, $00C8, $0000, $0000, $00FF, $0001, $0002 word $0005, $000A, $0014, $00FF, $0000, $0000, $0154, $0000, $0112, $0012, $0001, $0001, $0000, $0001, $0001, $0002 word $0030, $000D, $0143, $0000, $0109, $0009, $0003, $0000, $0001, $0005, $0002, $0000, $000F, $0001, $0002, $0005 word $0014, $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0136, $0000, $0137 word $0000, $0037, $004D, $0045, $0049, $0030, $0035, $0030, $0031, $0039, $0030, $0037, $0039, $0035, $0034, $0031 word $0037, $0056, $004E, $0032, $0037, $0030, $0030, $0020, $0055, $0053, $0020, $0020, $0020, $0012, $0020, $0112 word $0000, $0117, $0000, $0056, $0045, $0045, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030 word $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0030, $0031, $0032 word $00DA, $0100, $010A, $000A, $0000, $0000, $0015, $0018, $001F, $0000, $0000, $0000, $0000, $0000, $0000, $0000 word $0000, $0000, $0000, $0000, $0000, $0000, $014C, $0000, $0136, $0036, $0000, $0000, $0100, $0000, $0112, $0012 word $0009, $0055, $0053, $0041, $0045, $0045, $0031, $0030, $0030, $0030, $0033, $0037, $0039, $0030, $0036, $002E word $0045, $0070, $006F, $0072, $0074, $0020, $0045, $0064, $0067, $0065, $0020, $0020, $0030, $0030, $01B3, $0000 word $010C, $0000, $00FF, $0000, $00FF, $000A, $0100, $0134, $0000, $000F, $0000, $000F, $0052, $0100, $0111, $0001 word $0001, $0077, $0000, $0032, $00BC, $0100, $010B, $000B, $0100, $0133, $0033, $0100, $0114, $0001, $0015, $0100
Comments
On lines 77 and 81, I don't think you want to have quit since that will break out of the main loop (and go to the next statement, in this case an implied return from function).
On lines 95 and 101, I don't think you want to have quit on both. Every time through the loop (the plain "repeat" loop) one or the other of the if or else statements will be run. Putting quit in both means the loop only runs once.
That's correct. Each Master string with Slave response and Master ACK on their own line. If you try the other method in the zip archive called "testing" you will see the format of what I'm looking for on PST.
Tried taking out the quit statements on lines 77, 81 & 95 as you suggest here but still doesn't work....
Here's a screen shot of how it should look:
After making your suggested changes here is what I get:
Here's an example of how you can display a block of data by passing the address of the block and the number of entries in it.
This somewhat simple looking project has kicked my @@s. I have spent hours going through the loops by hand trying to understand how the data is handled through them and I just can't figure it out. It's confusing to me to understand how the quit (and next) work to exit the loops in an orderly fashion. I can get it to somewhat work but when I start to tweak it it falls apart.
I'm willing to pay someone to help me out with this at this point. Anyone interested?
Don
In other words the case statements would exit to your repeat loop without quit statements since each case is only executed if it is true.