Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while ridx != widx:
- # note: it may be faster to copy a batch of messages from shared memory
- # instead of directly accessing individual messages and their fields.
- msg = msgbuf[ ridx ]
- # sanity-check that message id increments monotonically
- lastid = ( lastid + 1 ) & 0xffffffff
- assert msg.id == lastid
- # get 32-bit timestamp (in cycles) from message and unwrap it:
- timestamp_cycles += ( msg.timestamp - timestamp_cycles ) & 0xffffffff
- # convert to timestamp in seconds:
- timestamp = timestamp_cycles / 200e6
- position = msg.position
- force = msg.force
- # consume message and update read pointer
- del msg # direct access to message forbidden beyond this point
- ridx += 1
- if ridx == NUM_MSGS:
- ridx = 0
- shmem.ridx = ridx
- # update user interface
- 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