Shop OBEX P1 Docs P2 Docs Learn Events
Buffer entries read back in reverse order — Parallax Forums

Buffer entries read back in reverse order

dbpagedbpage Posts: 217
edited 2020-11-25 17:43 in Propeller 1
I created a byte buffer to help me track down a communication issue. Unfortunately, I am having trouble with my buffer. The buffer records up to 1153 bytes. Why does RxView display bytes in reverse order?
Note: SDA is an address that is initialized by another method. Buffer1 is an offset of 20 longs from @SDA. RxView displays only the Rx buffer.
CON
  En = (Buffer1*4)+1280         ' bytes 1280-128+1=1153 bytes in Rx buffer 
  St = (Buffer1*4)+128          ' bytes 128 bytes in Tx buffer             
  
VAR
  long n
  
PUB RxStart 
  n  := En
  RxClear
  
PUB RxClear
  bytefill(SDA+(Buffer1*4),0,1280) ' Clear buffer (includes 128-byte Tx buffer)

PUB RxSave(c)
  if n =< St
    return
  byte[SDA][n--] := c
  if n < St
    n := En

PUB RxView | i
  i := n-1
  repeat 1153
    if i < St
      i := En
    if (byte[SDA][i] < 32) or (byte[SDA][i] > 127)
      StrUSB(Format.hexstr(byte[SDA][i--],2))
      CharUSB(" ")
    else
      CharUSB(byte[SDA][i--])

Comments

  • Nevermind. My mistake. I increased the Tx buffer to 1024 bytes without updating the buffer pointers. The Tx buffer bytes are stored at increasing memory addresses and the Rx buffer bytes are stored and read out in decreasing memory addresses. RxView is displaying a portion of the Tx buffer.

    Issue resolved.
Sign In or Register to comment.