select on udp recvfrom doesn't work ???

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Wed Aug 11 17:14:57 UTC 2010


On Wed, Aug 11, 2010 at 12:29:14PM -0400, Lennart Sorensen wrote:
> On Wed, Aug 11, 2010 at 12:23:40PM -0400, Lennart Sorensen wrote:
> > On Wed, Aug 11, 2010 at 12:14:55PM -0400, Lennart Sorensen wrote:
> > > > So this was a bust. The rtc on this board a ts7260 cannot generate interrupts :(
> > > > 
> > > > The chip itself has an rtc and some internal timers that could
> > > > generate interrupts.
> > > > 
> > > > The question still remains how to get them synchronized to the same
> > > > place in time. Using a udp message which would arrive roughly at the
> > > > same time to all devices still seems plausible ?
> > > 
> > > How about this little example.  It waits for a UDP message (anything at
> > > all) on port 5000, and when that happens it starts to print a message
> > > every 10 ticks, with a tick rate of 10ms, (so 10 times per second it
> > > does the print).
> > > 
> > > I start it by doing:
> > > 
> > > echo "Foo" | nc -u ipaddress 5000 -q 1
> > > 
> > > nc is netcat.  Any other udp capable network connection should work too.
> > 
> > By the way you can do a broadcast using something like:
> > 
> > echo "Foo" | nc -b -u broadcastaddress 5000 -q 0
> > 
> > So if your network is 192.168.1.0/24 then do:
> > 
> > echo "Foo" | nc -b -u 192.168.1.255s 5000 -q 0
> 
> Oops.  Typo.
> 
> echo "Foo" | nc -b -u 192.168.1.255 5000 -q 0

It might also be possible to get even more accurate sync by having the
main call recvfrom in blocking mode, and start the timer when it receives
the start message, rather than starting a completely non synced timer
loop that just starts counting ticks whenit receives the start message.

Here is a version that does that, plus a bit more cleanup.

-- 
Len Sorensen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timer.c
Type: text/x-csrc
Size: 2321 bytes
Desc: not available
URL: <http://gtalug.org/pipermail/legacy/attachments/20100811/b968759e/attachment.c>
-------------- next part --------------
ALL = timer
CFLAGS = -Wall
LDFLAGS = -lrt

all: $(ALL)


More information about the Legacy mailing list