Skip to content

Commit

Permalink
fix duplicate msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
beasteers committed Nov 18, 2024
1 parent 6bab2c6 commit 3a190a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ptgctl/tools/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def video(api, src=0, pos=0, width=0.3, shape=None, fps=15, speed=1, stepb
'''Send video (by default your webcam) to the API.'''
sid = CAM_POS_SIDS[pos]
sid = f'{prefix or ""}{sid}'
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:
Expand All @@ -46,7 +47,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
Expand Down
8 changes: 6 additions & 2 deletions ptgctl/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a190a0

Please sign in to comment.