5. Solaris SDK
The only purpose for the read (2) call is to read a GPS data packet that was previously requested with
an ioctl (2) or write (2) call. These packets contain position, velocity, GPS system status, and other
GPS information. One GPS packet is read for each read (2) call. The maximum GPS packet size is
defined by STFP_ MAX_ READ found in 'stfpio. h'. Refer to Chapter 1.
The packet data contains floating-point types as well as various integer types, but these elements
cannot be directly accessed when read into a char buffer because they are not properly aligned in
memory. To obtain access to the various types of GPS data elements, union structures are generally
used. For example, to extract a 4-byte float from the packet data, use the union shown below. Copy
four consecutive bytes of packet data into the fconv. uc[] array, starting with fconv. uc[0] (since Sun
workstations are big-endian machines,) then access the float data as fconv. f.
union {
float f;
u_ char uc[4];
} fconv;
Following a successful read(2) call, the read buffer will contain the packet length, ID, and data bytes
of the requested GPS data packet as described in the GPS documentation section of Chapter 1. Note
that a successful read(2) call will return the number of bytes read which will equal the packet length
plus 1 (one for the packet length byte itself.)
The write(2) call allows the user to send commands to the TFP. The TFP commands are used to set
the timing mode, time code format, and other TFP functions. Refer to Chapter 1 for TFP command
details. The write buffer must contain the TFP command ID and zero or more command data bytes.
As with GPS packets, command data consists of various data types that must be converted to a char
array for the write(2) call. The maximum number of bytes used for a command is defined by STFP_
MAX_ WRITE found in "stfpio. h". Most commands are implemented with ioctl(2) calls, which are
much simpler to use since they provide the conversion of data to an array of chars as required. Since
most TFP commands can be executed with ioctl(2) calls, the only really useful function for the
write(2) call is to execute the TFP commands that write data packets to the GPS receiver. In fact, the
write(2) call is the only way to send GPS data packets to the GPS receiver. When write(2) is used to
execute the Manually Request Packet from GPS Receiver command (command 0x32 described in
Chapter 1) and a response is expected (non-zero response packet ID), the write(2) call puts the call-
ing process to sleep until the response arrives. The driver will not call sleep() if the user has directed
the driver to send a signal on the occurrence of the INT_ PACKET (GPS packet available) interrupt.
The response packet can take 10's or 100's of milliseconds to arrive. The read(2) call can then be
used to read the response packet.
Ioctl Calls ioctl (fd, request[, arg])
- 200 -
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com