MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / read_device

Function read_device

src/microham.c:737–881  ·  view source on GitHub ↗

This thread reads from the microHam device and puts data on the sockets it also issues periodic heartbeat messages it also reads the sockets if data is available

Source from the content-addressed store, hash-verified

735// it also reads the sockets if data is available
736//
737static void *read_device(void *p)
738{
739 unsigned char frame[4];
740 int framepos = 0;
741 unsigned char buf[2];
742 fd_set fds;
743 struct timeval tv;
744
745 // the bytes from the microHam decive come in "frames"
746 // a frame is a four-byte sequence. The first byte has the MSB unset,
747 // then come three bytes with the MSB set
748 // What comes here is an "infinite" loop. However this thread
749 // terminates if the device is closed.
750 for (;;)
751 {
752 int ret;
753 int maxdev;
754
755 //
756 // setting uh_is_initialized to zero in the main thread
757 // tells this one that it is all over now
758 //
759 if (!uh_is_initialized)
760 {
761 return NULL;
762 }
763
764
765#if defined(HAVE_SOCKETPAIR) && defined(HAVE_SELECT)
766
767 //
768 // This is the right place to ensure that a heartbeat is sent
769 // to the microham device regularly (15 sec delay is the maximum
770 // allowed, let us use 5 secs to be on the safe side).
771 //
772 if ((time(NULL) - lastbeat) > 5)
773 {
774 heartbeat();
775 }
776
777#endif
778
779 //
780 // Wait for something to arrive, either from the microham device
781 // or from the sockets used for I/O from hamlib.
782 // If nothing arrives within 100 msec, restart the "infinite loop".
783 //
784 FD_ZERO(&fds);
785 FD_SET(uh_device_fd, &fds);
786 FD_SET(uh_radio_pair[0], &fds);
787 FD_SET(uh_ptt_pair[0], &fds);
788 FD_SET(uh_wkey_pair[0], &fds);
789
790 // determine max of these fd's for use in select()
791 maxdev = uh_device_fd;
792
793 if (uh_radio_pair[0] > maxdev)
794 {

Callers

nothing calls this directly

Calls 4

heartbeatFunction · 0.85
parseFrameFunction · 0.85
writeRadioFunction · 0.85
writeWkeyFunction · 0.85

Tested by

no test coverage detected