Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. while ridx != widx:
  2. # note: it may be faster to copy a batch of messages from shared memory
  3. # instead of directly accessing individual messages and their fields.
  4. msg = msgbuf[ ridx ]
  5. # sanity-check that message id increments monotonically
  6. lastid = ( lastid + 1 ) & 0xffffffff
  7. assert msg.id == lastid
  8. # get 32-bit timestamp (in cycles) from message and unwrap it:
  9. timestamp_cycles += ( msg.timestamp - timestamp_cycles ) & 0xffffffff
  10. # convert to timestamp in seconds:
  11. timestamp = timestamp_cycles / 200e6
  12. position = msg.position
  13. force = msg.force
  14. # consume message and update read pointer
  15. del msg # direct access to message forbidden beyond this point
  16. ridx += 1
  17. if ridx == NUM_MSGS:
  18. ridx = 0
  19. shmem.ridx = ridx
  20. # update user interface
  21. print(f'\ridx=0x{ridx:04x} id=0x{lastid:08x} time={timestamp:08f} position={position:08d} force={force:08d}', end='', flush=True )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement