Program overview:
The p12mprogram consists of 1 main
programs with 3 cooperating threads:
- p12mMain.c : main program.
- p12mXfThr.c: thread that controls the 12meter (via
ethernet). Does ra,dec -> az,el once a second.
Xf=transformation
- p12mLogThr.c: does logging of stat info once a second..to
disc and broadcast packets.
- p12mIoThr.c: handles i/o between external user and
p12mProg. Passes requests on to p12mXfThr
p12mMain.c: main program
p12Main program flow is:
- process user options
- initialization:
- data structs: location, precession,nutation structs,
utcToUt1,
- get lock file to make sure just 1 copy of p12mProg
- connect to p12m telescope controller via ethernet
- initialize the aoQueues used for thread communication,
and io buffer free list
- Start threads:
- start p12mXfThr.c: thread that controls the 12meter,
does 1 sec ra,dec -> az el
- start p12mLogThr.c : logging thread. writes status
info to disk and network once a sec.. also error
messages
- start p12mIoThr.c: thread to handle external user
requests, and then pass the requests to p12mXfThr
- currently there can be a maximum of 5 io threads
active at one time.
- Enter main loop:
- wait (with timeout) for external user connect request:
- If signal present, goto cleanup ,exit
- the signal handler catches: SIGHUP,SIGINT,SIGTERM
- If connect request, start p12mIoThr for this
request. log in active ioThr table
- If timeout (no connect request) check if any
ioThreads have exited.. if so, do resource cleanup.
- cleanup:
- free up resources, clear lock file, exit.
A number of routines common to the other
threads are located in p12mProg.c
- sleepSecs: wait routine
- msgThrToThr, putNodeQ, getNodeQ: thread to thread
communication
- For interthread communication aoQueues are used.
- p12mXfThr and p12mLogThr both have input queues based
on aoQueues.
- the queue is a linked list of nodes with a semaphore
protecting access.
- timeDifSec: compute time differences between 2 times
- dbgOut: output debugging info
- messageLxxxx : send warning, error messages from threads
to syslog
Miscellaneous details:
- Linux time (secs from 1970) is used to track many times.
- This get around the wrapping at midnite or years.
- The program was originally written to use the 12meter
track array option..
- you send time stamped az,el positions ahead of time to
the controller.
- It uses the previous and next points to compute a
velocity. This caused large accelerations, de
accelerations at the end of a cross strip (more
info).
- The IoThr occasionally wants status info that is stored in
the xfThr status blocks during the 1 sec tick processing (to
send back to the requester).
- Rather than go through the cmdQueue for request, reply..
ioThr can access info in the XfThr struct in a read only
mode:
- pxfI->tickI.secMidBusy is a
sentinel
- It is set to minus the current time when
xfThr starts to modify it's status block,
- It is set to plus the current time xfThr is done
- IoThr checks this flag. If negative, it will wait a few
millisecs and try again. This repeats till it gets the
data or times out.