diff --git a/ptgctl/tools/mock.py b/ptgctl/tools/mock.py index 6d7cf7c..3b7d45f 100644 --- a/ptgctl/tools/mock.py +++ b/ptgctl/tools/mock.py @@ -38,6 +38,7 @@ async def video(api, src=0, pos=0, width=0.3, shape=None, fps=15, speed=1, stepb sid = f'{prefix or ""}{sid}' if skill: api.session.start_recipe(skill) + tlast = 0 async with api.data_push_connect(sid, batch=True) as ws: async for im in _video_feed(src, fps, shape, speed=speed): if pos: @@ -48,7 +49,9 @@ async def video(api, src=0, pos=0, width=0.3, shape=None, fps=15, speed=1, stepb # print(load(dump_v3(im))) if stepbystep: input() - await ws.send_data([dump_v3(im)], [sid], [util.format_epoch_time(time.time())]) + t=time.time() + await ws.send_data([dump_v3(im)], [sid], [util.format_epoch_time(t, tlast)]) + tlast = t def _img_dump(im, format='jpeg'): from PIL import Image diff --git a/ptgctl/util/__init__.py b/ptgctl/util/__init__.py index 191ffbf..cb0e1ce 100644 --- a/ptgctl/util/__init__.py +++ b/ptgctl/util/__init__.py @@ -51,8 +51,12 @@ def parse_epoch_time(tid: str): def format_time(dt: datetime.datetime): return format_epoch_time(dt.timestamp()) -def format_epoch_time(tid: float): - return f'{int(tid * 1000)}-0' +def format_epoch_time(tid: float, tlast=None): + tms = int(tid * 1000) + i = 0 + if tlast and tms == int(tlast * 1000): + i = int((tid*1000 - tms)*100) + return f'{tms}-{i}' # misc