Example #1
0
#!/usr/bin/python

from zcm import ZCM, LogFile, LogEvent
import sys
sys.path.insert(0, '../build/types/')
from example_t import example_t

msg = example_t()
msg.timestamp = 10

event = LogEvent()
event.setEventnum  (0)
event.setTimestamp (1)
event.setChannel   ("test channel")
event.setData      (msg.encode())

log = LogFile('testlog.log', 'w')
log.writeEvent(event)
log.close()

log = LogFile('testlog.log', 'r')
evt = log.readNextEvent()
assert evt.getEventnum() == event.getEventnum(), "Event nums dont match"
assert evt.getTimestamp() == event.getTimestamp(), "Timestamps dont match"
assert evt.getChannel() == event.getChannel(), "Channels dont match"
assert evt.getData() == event.getData(), "Data doesn't match"

evt = log.readPrevEvent()
assert evt.getEventnum() == event.getEventnum(), "Event nums dont match"
assert evt.getTimestamp() == event.getTimestamp(), "Timestamps dont match"
assert evt.getChannel() == event.getChannel(), "Channels dont match"
Example #2
0
#!/usr/bin/python

from zcm import ZCM, LogFile, LogEvent
import sys, os
blddir= os.path.dirname(os.path.realpath(__file__)) + '/../build/'
sys.path.insert(0, blddir + "types/")
from example_t import example_t

msg = example_t()
msg.timestamp = 10

event = LogEvent()
event.setTimestamp (1)
event.setChannel   ("test channel")

log = LogFile('/tmp/testlog.log', 'w')
i = 0
while i < 100:
    msg.position[0] = i
    event.setData(msg.encode())
    log.writeEvent(event)
    i = i + 1
log.close()

from subprocess import call
cmd=["zcm-log-indexer", "-l/tmp/testlog.log", "-o/tmp/testlog.dbz",
      "-t" + blddir + "types/libexamplezcmtypes.so",
      "-p" + blddir + "cpp/libexample-indexer-plugin.so", "-r"]
call(cmd)
# To see the indexer command that runs here, uncomment the following two lines
print ' '.join(cmd)