Skip to content
Snippets Groups Projects
Commit 77764094 authored by Ramin Yaghoubzadeh Torky's avatar Ramin Yaghoubzadeh Torky
Browse files

Added ipaaca-ping and ipaaca-pong pair

Start ipaaca-pong on one system to listen for and reply to ping IUs.
ipaaca-ping on the other hand will send these pings and report round
trip times and estimated system clock difference.
parent 3322d3d3
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
import ipaaca
import time
class PingSender(object):
def __init__(self):
self.times = []
self.ob = ipaaca.OutputBuffer('IpaacaPing')
self.ob.register_handler(self.iu_event_handler)
def iu_event_handler(self, iu, event_type, local):
recv_t = time.time()
if event_type=='UPDATED':
print('OK')
send_t = float(iu.payload['sender_local_t'])
receiver_recv_t = float(iu.payload['receiver_local_t'])
round_trip_t = recv_t - send_t
locally_estimated_receiver_recv_t = (recv_t + send_t) / 2
estimated_clock_skew = receiver_recv_t - locally_estimated_receiver_recv_t
self.times.append(estimated_clock_skew)
average_clock_difference = sum(self.times) / len(self.times)
print('Received ping reply')
print(' round trip time [ms]: %0.3f'%(1000.0 * round_trip_t))
print(' estimated system clock difference [s]: %0.3f'%(average_clock_difference))
def send_ping(self):
t = time.time()
iu = ipaaca.IU('ipaacaPing')
iu.payload['sender_local_t'] = t
self.ob.add(iu)
ps = PingSender()
while True:
ps.send_ping()
time.sleep(1)
#!/usr/bin/env python
import ipaaca
import time
def iu_event_handler(iu, event_type, local):
if event_type=='ADDED':
iu.payload['receiver_local_t'] = time.time()
print('Sent IPAACA ping reply')
ib = ipaaca.InputBuffer('IpaacaPong', ['ipaacaPing'])
ib.register_handler(iu_event_handler)
while True:
time.sleep(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment