8/11
Check out BICEP pipeline from CVS
8/12
8/13
Looking into reduc_makecomap.m
Bicep gcp
Control Software Overview
Control Software Structure
8/14
bicep scheduling language
Bicep system Ethernet Protocol v0.34
PMAC
8/15
check out BICEP gcp from CVS:
bicepControl
genericcontrol.c
8/18
Archiver
Grabber
Logger
Navigator
Terminal
bicepMediator Control
Control thread
Scanner thread
GrabberControl
Signal Thread
Check out newest GCP code from CVS onto bicep0.caltech.edu:
8/19
bicepAntenna Control
AntennaMaster
AntennaControl
AntennaMonitor
AntennaDrive
AntennaRx
8/20
bicepGrabber Control
Master
Control
Scanner
FrameGrabber
Try to run gcp
8/21
genericcontrol.cc: Program::main()
8/22
Collected thoughts on how to integrate MCE
bicepMediator Control
8/25
bicepViewer
netobj: netobj.c, netobj.h
bicepViewer connecting to bicepControl
8/26
How bicepViewer parses a message:
8/27
How bicepControl command loop starts:
How bicepControl parses a message from bicepViewer:
8/28

8/11

Trying to get reduc_makecomap() run.

This finally worked:

>> mapopt.jacktype=2
>> % this just initializes mapopt.
>> reduc_makecomap({'B20070702_cmb16_2A_B_315'}, mapopt)

Now plot the output -> Done
I did this by copying then hacking Chris's function plot_coadd.m, calling it bicep_analysis/Matlab/plot_coadd2.m

Check out BICEP pipeline from CVS

cd ~/
cvs co -r bicep quad_analysis/Matlab
mv quad_analysis/bicep bicep_analysis

make soft links:

--- link to tod data files ---
cd bicep_analysis
ln -s /data/csheehy/bicep_products scratch
--- link to other data ---
ln -s /data/csheehy/bicep_aux_data aux_data

8/12

Today I worked on getting my web page set up. I am currently confused about where to publish:

Solution:

I talked to Leo, and had the permissions on my file system changed to chmod 755. I changed my publishing directory to ~/public_html, rather than ~/web/public_html/

Now the publish page is: http://find.uchicago.edu/~kstory

For information about emacs muse webpages, look at: Xin Shi's how to page

8/13

Change color on the website at ~/public_html/css/common.css

Looking into reduc_makecomap.m

Location: ~/bicep_analysis/Matlab/reduc_makecomap.m
input:
  - tags -> a cell element of the form {'tag'}. For example, a file called /scratch/B20070702_cmb16_2A_B_315_tod.mat has a tag={'B20070702_cmb16_2A_B_315'}. the \_tod is added automatically by the code.
  - mapops -> options on how to analyze the map. Options (fields) include:
    ~ type
    ~ filt
    ~ jacktype
    ~ coaddtype
    ~ weight
    ~ gs
    ~ exname
    ~ exmaptag
    ~ polpar
    ~ roundto
    ~ proj
    ~ beamcen
    ~ beamwid
    ~ abgain
    ~ diffpoint
    ~ usepsm
output:
  - a map called 'tag'_'mapops'.mat, stored in bicep_analysis/maps/
how to run:

cd ~/
matlab
>> cd bicep_analysis/
>> mapopt.jacktype=1  % merely for initialization of mapopt
>> reduc_makecomap({'B20070702_cmb16_2A_C_315'},mapopt)

mapopt =

          jactype: 1
             type: 'bicep'
             filt: 'p3'
         filttype: 'normal'
               gs: 0
         jacktype: 0
        coaddtype: 0
           weight: 2
          beamcen: 'ideal'
           polpar: 'ideal'
             proj: 'radec'
          roundto: 1
         deglitch: 'scancheck'
    hsvarfromreal: 0
           exname: ''
         exmaptag: 'B20070702_cmb16_2A_C_315_'
              usr: ''
           usepsm: 1


filename =

scratch/B20070702_cmb16_2A_C_315_tod

Elapsed time is 6.493054 seconds.
sumdiff_pairs...
filter_scans...with type normal
Warning: Divide by zero.
> In reduc_makecomap>accumulate at 574
  In reduc_makecomap at 251
Elapsed time is 27.349562 seconds.
accumulating no-split maps...
acsum
acsum
acdiff
acdiff
Elapsed time is 67.376875 seconds.
Warning: Divide by zero.
> In reduc_makecomap>make_map at 868
  In reduc_makecomap at 255
...
>>

The output from the above is:
~/bicep_analysis/maps/B20070702_cmb16_2A_C_315_filtp3_weight2_jack0.mat

I can make picutres with bicep_analysis/Matlab/plot_coadd2.m:

>> pwd
/home/kstory/bicep_analysis
>> plot_coadd2('B20070702_cmb16_2A_C_315_filtp3_weight2_jack0.mat')

reduc_makecomap:
  - set default values for mapopt fields if they weren't set by the user.
  - fetch map area/pixel size using get_map_defn
  - make arrays for each requested jackknife. This array is called ac{jacktype#}(index). Fields of ac are wsum, wz, wwv, w, wcz, wsz, scc, wss, wcs, wwccv, wwssv, wwcsv.
  - create [p, ind]=get_array_info(tags{1})
... finish later?

get_map_defn:

get_array_info(tag,beamcen,polpar,beamwid,diffpoint)
if input vars are not filled, set defaults
read fp parameters
make a channel_name field for fp
initialize 'ind' with make_ind(fp) -> generates lists of channels
create ideal chi reference theta
read in beam params: beamcen, polpar, beamwid, diffpoint
if beamcen='obs', read in fp.r and fp.theta
if polpar='obs', read in fp.epsilon, fp.chi, fp.chi_thetaref
if beamwid='obs' or 'fixed' read fp.fwhm
if diffpoint='obs', re-calculate r and theta from ~/bicep_analysis/aux_data/beams/beams_dp_moon.csv, find the difference between these and fp.r, fp.theta, and adjust fp.r by this amount. not sure what is going on here, what is being adjusted for, and why we don't just reset fp.r = r.
p=fp
returns [p,ind]

make_ind(fp)
Generate a convenient ind structure of index lists
ind.all=1:144 %all bolometers
initialize ind.alla and ind.allb. -> What are a and b for?
ind.n bool if p.type = 'L', 'D' 'T' or 'N'
ind.a bool if p.type = 'L' or 'D'
ind.l bool if p.type = 'L'
ind.t bool if p.type = 'T'
ind.l150 bool if p.type='L'&p.band=150
ind.l100, ind.l220 -> take a guess...
Channels listed as good if p.flag=0:
ind.ga, ind.gl, ind.gd, ind.gl150, ind.gl100
reduce to channel pairs by adjusting p.flag
flag rg channels "realy good", ind.rgl
initialize 'intersect' channels: example ind.la
get all index arrays into row vectors with f=fieldnames(ind)
initialize arr=getfield(ind,f{i}); ind=setfield(ind,f{i},rvec(arr));


Bicep gcp

The new plan is for me to become a Bicep gcp expert. The gcp is the software system that stands at the interface between the software and hardware. The person responsible for it is Eric Leitch.

Links (password protected):
Spud homepage: http://bmode.caltech.edu/~spuder/
Bicep homepage: http://bicep.caltech.edu/~bicep
control software (gcp): http://bicep.caltech.edu/~bicep/control_software/
analysis logbook: http://bicep.caltech.edu/~bicep/analysis_logbook_index.html

Control Software Overview

The GCP has 3 main parts:
1) bicepControl
2) bicepMediator
3) bicepAntennaControl

Other parts:
  - bicepGrabber: A process that controls the frame grabber via a PCI card

bicepControl:
top-level layer.
  - interpret schedules (a.k.a. telescope command files)
  - handle source ephemerides (locations of celestial bodies)
  - procession calculations
  - archive data to a disk
  - serve data to remote monitoring clients

bicepMediator:
middle layer between bicepControl and low-level data acquisition / telescope control software.
for BICEP this layer serves as a bi-directional pass-through betwen bicepControl and bicepAntennaControl. It also talks to the frame grabber controller.

Old Objective:
  - bring together data streams from diverse sources and collate them into a single data stream for bicepControl.
  - take in a single stream of commands from bicepControl and send out verious separate control commands.
This capability seems to no loger be necessary for BICEP

bicepAntennaControl:
main low-level control.
Communicates with:
  - PMAC PCI card 1-> drive system electronics
  - timecode reader PCI interface
  - receiver data acquisition via UDP socket connections 2
  - weather station data coming directly from the QUAD control system
  - tripper data from Simon Radford's tripper (attached to a windows machine via a SAMBA connection using smbget() system calls)
  - 1pps signal used to synchronize the computer/PMAC communications, delivered to the computer's parallel port.

bicepGrabber:
controls the frame grabber via a PCI card. It gets commands from the bicepMediator and sends images directly to the bicepControl via a separate socket connection.


1. PCI card means Peripheral Component Interconnect. The PCI is a bus that interfaces between hardware and software. In a typical PC, it connects the processor to things like the hard disc or sound cards.

Wikipedia: PCI wiki
PCI link.

2. UDP means User Datagram Protocol. This is a protocol for data transport, for example of an Ethernet LAN segment. It is implimented in the Dynamic C TCP/IP libraries over IP (Internet Protocol). UDP uses ports for application-to-application communication. The "UDP socket" represents the connection state on the local side. Sockets make use of port numbers, which allow several simultaneous connections to exist between the same two hosts.

Wikipedia: UDP wiki
UDP link. This contains UDP functions: control, status, I/O, open, close, read, porting from older code to UDP API starting with Dynamic C 7.05, data handlers, blocking programs, and example an example skeleton program for TCP/IP


Control Software Structure

Each software layer is a multi-threaded (posix) program:
  - master thread: start/stop/forward messages to other threads.
  - each thread has a message queue. Threads exchange information by pushing a message into another thread's queue (usually via the master thread).
  - Each thread's main() sits in a select() loop and responds when messages appear on its message queue.
  - Each thread is a single C++ object.
Communication between layers is bi-directional, with two separate socket connections between each layer and the one above/below.

bicepControl:
located in gcp/control. Generally in C, with some C++ thrown in for kicks.
  - start with gcp/control/code/unix/control_src/common
  - main thread in genericcontrol.c, which manages the following threads:
    ~ archiver (archiver.c) -> archives data to disk.
    ~ grabber (grabber.c) -> writing images from frame grabber to disk.
    ~ logger (logger.c) -> propagation of messages logged throughout the system.
    ~ navitagor (navigator.c) -> handles source ephemeris files and precession calculations from antenna control layer.
    ~ terminal (terminal.c) -> manages the pager.

8/14

bicepControl (cont):

bicepMediator: code at gcp/mediator/bicep
  - has a Master thread in Master.cc -> manages a collection of threads (threads_.push_back in the constructor)
  - control thread (Control.cc) -> handles control information from software layer above.
  - scanner thread (Scanner.cc) -> handles data from below
  - grabber thread (GrabberControl.cc) -> forwards commands to the frame grabber process.
  - signal thread (gcp/util/common/SignalTask.cc) -> handles timers and signals.

bicepAntennaControl: (gcp/antenna/control/bicep)
  - master thread (inconsistently in AntennaMaster.cc)
  - control thread (AntennaControl.cc)
  - scanner thread (AntennaMonitor.cc)
  - signal thread (gcp/util/common/SignalTask.cc)
  - drive control thread (AntennaDrive.cc)
  - receiver data/control thread (AntennaRx.cc)
    ~ This is a wrapper around the Tracker thread (Tracker.cc), which contains all logic and drive control.

bicepViewer: tcl/tk based interface program.

Running the Software:
1) define the environment variable GCP_DIR:

setenv GCP_DIR /home/bicep/gcp/control
(in tcsh)

2) on startup, the default source file is bicepControl.init in GCP_DIR/conf. To specify an alternate startup file, use the command

bicepControl startuupScript=aDifferentFile

3) All pieces operate by passively listening for connections from lower-level programs, and actively attempt to connect to higher-level programs.
  - ex: bicepcontrol -(pasv)-> bicepMediator -(pasv)-> bicepAntenna Control
  - bicepControl <-(actv)- bicepMediator <-(actv)- bicepAntennaControl

4) bicepAntennaControl must be run as root, because the thread prioritizing requires root priveleges. On bicep1/3, bicep can sudo these commands. On bicep2, you have to be root.

5) You can start this suite of programs with a script in gcp/misc/scripts/bicep/controlSystem:

controlSystem start bicepTest

- note, on bicep2 you need the root password to run this.
  - Ctrl-c will not always exit properly. Use bicep/misc/scripts/killAll:

killAll bicepMediator
or
controlSystem stop bicepTest

6) Once bicepControl is running, connect by starting the bicepViewer:

[in the menu]
File->Connect to the control program

bicep scheduling language

bicep scheduling language documentation

Bicep system Ethernet Protocol v0.34

Ethernet Protocol.pdf

In the data system, each box contains an Ethernet adapter, a Controller card, and data-taking cards. The Ethernet adapter has a unique IP address 192.168.1.x and port number 1500+x.

Commands consist of 24 ASCII characters:

struct {
    char length[2];
    char channel[2];
    char protocol;
    char command;
    char parameters[16];
    char cksum[2];
} command;

Bias card
The bias card only occupies one channel (the lower one). The channel number is hence necessary for the Bias and Housekeeping cards. Every command that is sent to a Bias card puts that card in DC mode, because the bias generator interrupts must be disabled before the card can receive further commands. The user is responsible for (manually) restoring the card to AC mode with an additional command. Because bias commands interrupt the signal generation process, they will only be sent by the controller when there is a change in bias settings.

Other cards
Each physical PC card has two channels. The channel number is not necessary for other cards. For these, set channel to "FF" to indicate that it is not used.

cksum
the ASCII HEX value of the number that, when added to the ASCII value of all other characters, will result in a mod 256 sum of 0. ??

parameters
sent as hexidecimal strings.

channel
in HEX with FF for global commands

length
always 22 (0x16) in this version. This is the length of the data characters only (excluding the two cksum chars).

Get Status command
Following the "Get Status" command, the bias generator will return the following in its six bytes of HEX science data:
  Byte 1=Frequency
  Byte 2=Multiplier
  Byte 3=H DAC Byte
  Byte 4=M DAC Byte
  Byte 5=L DAC Byte
  Byte 6=Mode("A" for AC, "D" for DC, "S" for Off)

Housekeeping commands
When sending 10-bit analog or 1-bit digital outputs, all 4 values must be sent each time.
Jumper settings on the Housekeeping board determine whether the DAC or TTL outputs are archives.

PMAC

Programmable Multi Axis Controller, made by Delta Tau.
BICEP PMAC reference page
The PMAC has 3 main components:
Turbo PMAC-PCI
11 connectors: J1-J8, J2 (CPU Board), JS1, JS2.
ACC-51P Interpolation Card
6 connectors: J1, J1A, J3-J6
ACC-8D Terminal Block Board
8 connectors: J1A-J4A, J5, J6, TB1

8/15

I have files!! Directory for new files:
~/gcp_bicep/

Email from John Kovac regarding gcp_bicep:

To checkout a copy of the current BICEP1 cvs archive:

   cvs -d bicep0.caltech.edu:/home/bicep0/cvsroot checkout -r working14Feb gcp

I believe that this reflects all the up-to-date code running on bicep1
(antenna computer) and bicep3 (control computer) at Pole...Steff, can you
confirm?

I just checked out a copy per the above into bicep0.caltech.edu:~john and
just typing "make" fails.  So I don't know what's required to compile
starting from a fresh copy.

check out BICEP gcp from CVS:

cvs -d bicep0.caltech.edu:/home/bicep0/cvsroot checkout -r working14Feb gcp

bicepControl

Location: ~/gcp_bicep/control/code/unix/control_src/common/genericcontrol.c

genericcontrol.h
struct ControlProg -> main struc defined here. Definition in genericcontrol.c, L409
functions:
CHAN_IO_FN(ControlProg *cp, ComHeader *head)
  - remove appropropriate aspect of channel when data arrives on readable channel, or writeable channel has room for more data.
SOCK_RCVD_FN(ControlProg *cp, SockChan *sock)
  - process message after msg has been read into sock->nrs.
SOCK_SENT_FN(ControlProg *cp, SockChan *sock)
  - called after msg in sock->nss has been successfully sent.
SOCK_COND_FN(ControlProg *cp, SockChan *sock, SockCond cond)
  - called if an I/O error occurs while reading or writing a socket, or if socket connection is lost.
cp_ThreadData(ControlProg *cp, CpThreadId id)
  - Look up the resource object of a given thread.
CP_NEW_FN(controlProg *cp, Pipe *pipe)
  - Allocate the resource object of a thread
CP_DEL_FN
CP_THREAD_FN_void *arg)
  - the thread start fn. The thread resource object is via 'arg'
CP_STOP_FN(ControlProg \*cp)
  - send shutdown message to thread using non-blocking I/O.

Data Types:
struct ControlProg {
  ArrayMap *arraymap; /*The register map of the SZA */
  PipeChan *pipe; /*The communications thread control pipe */
  CpThread thread[NTHREAD]; /*The client threads of the control program */
  RtController *rtc; /*The connection to the real-time controller */
  RtScanner *rts; /*The connection to the real-time scanner */
  RtOptCam *rto; /*The connection to the real-time optical camera task */
  MonitorServer *ms; /*The monitor-client server */
  ImMonitorServer *ims; /*The monitor-client image server */
  ControlServer *cs; /*The control-client server */
  ComList active_list; /*The list of channels to watch for I/O */
  fd_set read_fds; /*The set of readable file-descriptors to watch */
  fd_set send_fds; /*The set of writable file-descriptors to watch */
  int fd_set_size; /*The size of the read_fds and send_fds sets */
  CpWhatNext whatnext; /*The continuation status of the event loop*/
  gcp::util::AntNum defaultAntSet; // A set of antennas to be used as the default for command which take an optional antenna argument
}
struct SockChan {}
struct ComHeader{}
struct ComAspect{}

Logger

typedef struct{} LoggerMessage
typedef enum LoggerMessageType
  - enumerate logger message types.

functions:
CP_THREAD_FN, CP_NEW_FN, CP_DEL_FN, CP_STOP_FN
pack_logger_blah
  - set of functions to pack messages into a LoggerMessage
bool log_isValidDevice(Logger \*log, char \*device);
  - return true if named device is recognized
send_LoggerMessage
  - send LoggerMessage to the logger thread
log_thread_stream(\*cp, FILE \*stream)
  - redirects the specified stream of the calling thread to the input pipe of the logger thread.

Archiver

typedef struct Archiver Archiver
typedef enum ArchiveMessageType
typedef struct{} ArchiverMessage

functions:
CP_THREAD_FN, CP_NEW_FN, CP_DEL_FN, CP_STOP_FN
pack_archiver_blah
send_ArchiverMessage(*cp, Archiver message \*msg, long timeout)
arc_integrate_frame(*cp,*frame)

Scheduler

typedef struct Scheduler Scheduler
enum SchedulerMessageType{}
class SchCommand{}
  - Objects that are used to pass messages to the scheduler task.
  Fields: char string[], Pipe\*client, SchCommand
class SchClient{}
  Files: Pipe \*pipe, SchClient
class SchRtcNetMsg{}
  Fields: int id, gcp::util::NewRtcNetMsg msg, SchRtcNetMsg
class SchMarkDone{}
  Fields: unsigned seq, SchMarkDone
class SchGrabDone{}
  Field: unsigned seq, SchGrabDone
class SchSetregDone{}
  Fields: unsigned seq, SchSetregDone
class SchTvOffsetDone{}
  Fields: unsigned seq, SchTvOffsetDone
class SchFrameDone{}
  Fields: unsigned seq, SchFrameDone
class SchAutoDir{}
  Fields: unsigned seq, SchAutoDir
class SchAutoPoll{}
  Fields: unsigned seq, SchAutoPoll
class SchAutoState{}
  Fields: unsigned seq, SchAutoSate
class SchMessageBody{}
class SchedulerMessage{}

Functions:
Scheduler(*cp)
pack_scheduler_blah
send_SchedulerMessage(*cp, SchedulerMessage*msg, long timeout)
  - send message to scheduler thread

Navigator

typedef struct Navigator Navigator
typedef enum NavigatorMessageType
typedef struct NavSiteMsg
typedef struct NavigatorMessage

Functions:
cp_Navigator(*cp)
pack_navigator_blah
send_NavigatorMessage(*cp, NavigatorMessate*msg, long timeout)

Grabber

typedef struct Grabber Grabber
typedef enum GrabberMessageType
typedef struct GrabberMessage

Functions:
cp_Grabber(*cp)
pack_grabber_blah
send_GrabberMessage(*cp, GrabberMessage*msg, long timeout)
grabber_save_image(*cp,*image,long utc[], signed actual[], signed expected[])

Term

typedef struct Term Term
typedef enum TermMessageType
typedef enum PagerDev
typedef struct TermMessage

Functions:
pack_term_blah
send_TermMessage(*cp,TermMessage*msg, long timeout)

Other Functions

Data Types:
typedef struct CcPipeMsg

Functions:
cp_ArrayMap(*cp)
  - Get registered map of the control program.
cp_AntSet(ControlProg \*cp)
  - Provide access to the default antenna set
queue_cc_message(Pipe*client, CcPipeMsg*msg)
  - Send a text message to a control client
sendToCcClients(*cp,*pmsg)
queue_rtc_command(ControlProg \*cp, gcp::control::RtcNetCmd \*cmd, gcp::control::NetCmdId type)
  - Queue a network command object to be sent to the real-time controller.
cp_rtc_online(ControlProg \*cp)
  - Return true if real-time controller is currently connected.

Pack a control message:
cp_request_shutdown(*cp)
cp_request_restart(*cp)
cp_report_exit(*cp)
cp_initialized(*cp)
send_scheduler_rtcnetmsg(*cp, gcp::util::NewRtcNetMsg& netmsg)

processspecificMsg(...)
add_readable_channel(*cp,*head)
sendPeakOffsets(\*cp,ipeak,jpeak)
find_CpThread

genericcontrol.c

Data Types:
ComList
Rtcontroller
  - struct status
RtcPipeCmd
RtScanner
RtOptCam
MonitorClient, enum MonitorState
ImMonitorClient, ImMonitorState
MonitorServer
ImMonitorServer
ControlClient
ControlServer
CpThreadType
CpThread
CpWhatNext
ControlProg
ControlMessage, enum CpMessagetype

Functions:
ini_ComHeader -> initialize communications header, only called by thread constructors
set_channel_fds -> assign a given fd to a channel
new_SockChan, del_SockChan, open_socket_channel, close_socket_channel
add_readable_channel, rem_readable_channel
cp_add_read_fd, cp_rem_read_fd
add_writable_channel, rem_writable_channel
cp_add_send_fd, cp_rem_send_fd
PIPE_RCFC_FN, PIPE_SENT_FN, new_PipeChan, del_PipeChan
new_RtController, del_RtController, connect_controller
SOCK_RCVD_FN, SOCK_SENT_FN, SOCK_COND_FN
record_rtc_status, watch_rtc_readablility
PIPE_RCVD_FN
new_RtScanner, del_RtScanner, connect_scanner
new_RtOptCam, del_RtOptCam, connect_optcam
new_MonitorServer, del_MonitorServer, connect_monitor_client
new_ImMonitorServer, del_ImMonitorServer, connect_im_monitor_client
new_ControlServer, del_ControlServer, connect_control_client
add_scheduler_channel, rem_scheduler_channel, connect
add_navigator_channel, rem_navigator_channel
add_logger_channel, rem_logger_channel
send_ControlMessage
cp_add_read_fd, cp_rem_read_fd, cp_add_send_fd, cp_rem_send_fd
processGenericMsg

main:
initializations of cp, waserr, whatnext
while loop: (whatnext==CP_RESTART && !waserr)
  1) cp=new_ControlProg() -> allocate the resources of the control program and create its threads.
  2) waserr=cp_event_loop(cp) -> main event loop
  3) whatnext=cp->whatnext -> record contiuation status
  4) cp = del_ControlProg(cp) -> terminate other threads and reclaim resources.

cpEventLoop:
  - the set of readable (writable) files is kept in read_fds (send_fds)
  - If an active channel was found, remove it from the set of channels being watched and call its I/O method.
  - connect to various ports if requested:
    ~ control-server, monitor-server, image monitor-server, rt controller, rt scanner, rt optical camera

8/18

Archiver

Location: gcp_bicep/control/code/unix/control_src/common/archiver.c
in namespace gcp, control
Data Types:
class ArchiverWriter
typedef struct FrameBuffer{}
struct Archiver{}
Functions:
cp_Archiver, get_reg_info, arc_find_reg, arcFindActualReg
chdir_archiver, open_arcfile, flush_arcfile, close_arcfile
arc_send_ccmsg, send_ArchiverMessage, pack_archiver_[blah]
arc_frame_error, arc_save_intergration, arc_update_sampling
arc_add_client, arc_rem_client

Grabber

Location: gcp_bicep/control/code/unix/control_src/common/grabber.c
in namespace gcp, util
Data Types:
class Angle
typedef struct ImageBuffre{}
struct Grabber{} -> State of the grabber thread.
Functions:
setOpticalCameraFov, sendOpticalCameraFov
setOpticalCameraAspect, sendOpticalCameraAspect
setOpticalCameraXImDir, sendOpticalCameraXImDir
setOpticalCameraYImDir sendOpticalCameraYImDir
setDeckAngleRotationSense, sendDeckAngleRotationSense
setOpticalCameraCollimation, sendOpticalCameraCollimation
setImageSearchRegion

sendGrabberCombine, sendGrabberChannel, sendGrabberMessage
sendGrabberFlatfield, sendCurrentGrabberConfiguration
sendPeakOffsets
grabber_write_image, grabber_save_image
grabber_offset_info, grabber_peak_info

chdir_grabber, open_grabfile, close_grabfile
pack_grabber_[blah], flush_grabfile, flush_grabfile

Logger

Location: gcp_bicep/control/code/unix/control_src/common/logger.c
using namespace gcp::control
Data Types:
struct Logger{}
Functions:
open_logfile, close_logfile, chdir_logger, flush_logfile
log_date_message, log_add_client, log_rem_client, log_log_transaction
write_logclient, write_logfile, write_terminal
drain_log_pipe, dispatch_log_message
cp_Logger
LOG_DISPATCHER, LOG_HANDLER_FN

send_loggerMessage -> send a message to a logger thread
pack_logger_[blah]
log_thread_stream, log_isValidDevice
log_isValidSerialNumber, log_isvalidLocation

Navigator

Location: gcp_bicep/control/code/unix/control_src/common/navigator.c
Data Types:
TimeWindows{} -> send updates of various emphemerides to the RTC.
LastCache{} -> values of ephemerides that were last sent to the RTC.
struct Navitagor{}
    Most of the time this thread is idle waiting for input from its input pipe.
    At such times the following guard mutex is released to enable other threads
    to access the data that this thread manages. All public accessor functions
    must acquire this mutex before accessing the source catalog and release
    it when done.

Functions:
nav_print_scan_info, nav_lookup_source
navLookupSourceExtended, nav_source_info, nav_lookup_scan
nav_pamc_done,


source handling
nav_handle_message, nav_check_caches
nav_update_utlutc, nav_upate_eqneqx, nav_update_source, nav_update_scan, nav_update_ephem_source, nav_update_J2000_source
nav_track_fixed_source, nav_track_center_source, nav_track_J2000_source, nav_track_ephem_source

Scan functions
nav_track_source, nav_start_scan
nav_slew_telescope, nav_halt_telescope, navIsCurrent
nav_start_normal_scan, nav_start_continuous_scan
nav_update_normal_scan, nav_update_continuous_scan
nav_current_scan, nav_set_site, nav_adopt_rtc_state, nav_dispatch_site_to_rtc

cp_Navigator
send_NavigatorMessage
pack_navigator_[blah]
nav_error_while_locked

Terminal

Location: gcp_bicep/control/code/unix/control_src/common/terminal.c
Data Type:
struct Term{
    struct mapo_redlight{}
    struct dome_pager{}
    struct eldorm_pager{}
}

Functions:
paper_port, active_pager, pager_chip, pagerAddEmailAddress
cp_Term
send_TermMessage
pack_term_[blah]


bicepMediator Control

in namespacd gcp, mediator
Classes:
  - Master -> main controlling thread. The master has 3 sub-threads:
  - Control -> Control.h, Control.cc
  - Scanner -> Scanner.h, Scanner.cc
  - Grabber -> GrabberControl.h, GrabberControl.cc
  - Signal -> /gcp_bicep/util/common/SignalTask.cc
Methods initialize threads, send and receive messages, ping threads, talk to the weather station, etc.

Control thread

location: gcp_bicep_mediator/bicep/Control.cc
Class declaration:
  - sub-thread startup functions
  - sub-thread clean up functions
  - sub-thread ping functions
sub-threads:
AntennaControl* antennaControl_;
DcControl* dcControl_;
DelayControl* delayControl_;
GrabberControl* grabberControl_;
StripControl* stripControl_;
WxControl* wxControl_;

Functions:
CONTROL_TASK_FWD_FN, LOG_HANDLER_FN
NET_READ_HANDLER, NET_SEND_HANDLER, NET_ERROR_HANDLER
THREAD_START, THREAD_CLEAN, THREAD_PING
forwardMasterMsg, forwardNetCmd
forwardControlMsg, forwardMasterMsg, forwardGrabberControlMsg, forwardStripControlMsg, forwardWxControlMsg
disconnect, connectControl, disconnectcontrol
sendHeartBeat, respondtoHeartBeat
serviceMsgQ, processMsg, packNetMsg
sendcontrolConnectedMsg, sendAntennaInitMsg

Scanner thread

location: gcp_bicep/mediator/bicep/Scanner.cc
Class Scanner

Functions:
THREAD_START, THREAD_CLEAN
NET_READ_HANDLER, NET_SEND_HANDLER, NET_ERROR_HANDLER
disconnect, connectScanner, disconnectScanner
setAntReceived, antennasChangeState, respondToHeartBeat
checkDataFrames, packFrames, packAntennaFrame, initAntennaResources, dispatchNextFrame, startNewFrame, checkDataFrames
sendDispatchDataFrameMsg, sendFlagAntennaMst, sendScannerconnectedMsg, sendControlConnectedMsg
parsGreeting, processMsg, serviceMsgQ
changeFeatures. reportStateChange

GrabberControl

location: gcp_bicep/mediator/bicep/GrabberControl.cc
in namespace GrabberControl
Class GrabberControl

Functions:
THREAD_START, THREAD_CLEAN
NET_READ_HANDLER, NET_SEND_HANDLER, NET_ERROR_HANDLER
processMsg, processNetMsg, forwardNetMsg, serviceMsgQ
connectGrabber, disconnectGrabber
setRctNetCmd, sendRctNetCmd, readNetMsg, forwardNetMsg
listen

Signal Thread

location: gcp/util/common/SignalTask.cc
in namespace gcp, util
Class:
Thread -> a generic base-class task for handling timers & signals.
SignalTask ->
  Classes:
  TimerInfo
    reArm
  SignalHandler
    struct HandlerPair
    reArm
    addHandler
    removeHandler
  Functions:
  sendAddHandlerMsg, addHandler, removeHandler, getHandler
  sendInstallSignalMsg, installSignal
  run, getIoSig
  THREAD_START, SIGNALTASK_HANDLER_FN
  sendInstallTimerMsg, sendEnableTimerMsg, installTimer, enableTimer, startTimer, stopTimer, getTimer
  processTaskMsg, fwdTaskMsg, serviceMsgQ



Check out newest GCP code from CVS onto bicep0.caltech.edu:

bicep0 bicep0/kstory> cvs -d bicep0.caltech.edu:/home/bicep0/cvsroot checkout -r working14Feb gcp
bicep0 bicep0/kstory> ls
bin  Documents  gcp  public_html

Link to compling errors for the bicep gcp

Email Steff and ask what I should do about it.

Steff's response:

Hi All,
Kyle Story was trying to get gcp to compile on bicep0. Looks like the
TCL/TK installation was a bit dodgy and the the pgplot installation
never finished to compile the pgplottk library.
I fixed both of the above problems and GCP now compiles.

Cheers,
Steff

The gcp now compiles!

For tomorrow:
Look through bicepAntennaControl.

8/19

Fix command prompt on bicep0. Useful Bash command prompt link.
Re-looking over bicepControl code in the most recent bicep0 version that I checked out yesterday. -> Done
Re-looking over bicepMediator code. -> Done

bicepAntenna Control

Location: gcp/antenna/control/bicep/
Contains files for talking to each piece of hardware:
examples: CameraBoard, DataBase, GpsBoard, UmacControl, Pmac
Classes:
class AntennaMaster -> encapsulates the entire Antenna control.
class AntennaControl
class AntennaMonitor
class AntennaDrive
class AntennaRx
class AntennaData
class UmacControl

AntennaMaster

DataTypes:
class AntennaMaster
  subthreads
    AntennaControl
    AntennaMonitor
    AntennaDrive
    AntennaRx
    AntennaSignal
Functions:
SIGNALTASK_HANDLER_FN
ANTENNAMASTER_TASK_FWD_FN
THREAD_START, THREAD_CLEAN, THREAD_PING
sendPackDataFrameMsg, sendDataStrobeMsg, sendStrobePmacMsg, sendAdoptBoardMsg
host, dataPort, cmdPort
processMsg, sendHeartBeat, restartServices
installTimers, installSignals, getShare, getAnt

AntennaControl

Location: gcp/antenna/control/bicep/AntennaControl.cc
in namespace gcp, antenna, control
class AntennaControl

Functions:
connect, disconnect, connectControl, disconnectControl, isconnected, sendcontrolConnectedMsg
serviceMsgQ ,getSender, processMsg, packNetMsg, sendAntennaIdMsg
sendGreeting, parseGreetingMsg
LOG_HANDLER_FN
NET_READ_HANDLER, NET_SEND_HANDLER, NET_ERROR_HANDLER

AntennaMonitor

Location: gcp/antenna/control/bicep/AntennaMonitor.cc
in gcp, antenna, control
class AntennaMonitor

Functions:
sendDispatchDataFrameMsg, sendScannerConnectedMsg, sendAntennaIdMsg
processMsg, serviceMsgQ
connect, disconnect, connectScanner, disconnectScanner
packNextFrame, dispatchNextFrame, packFrame
parseGreetingMsg
NET_READ_HANDLER, NET_SEND_HANDLER, NET_ERROR_HANDLER

AntennaDrive

Location: gcp/antenna/control/bicep/AntennaDrive.cc
in gcp, antenna, control
class AntennaDrive

Functions:
sendPmacConnectedMsg, sendPmacDoneMsg, sendScanDoneMsg, sendSourceSetMsg
processMsg, respondToHeartBeat, tipperHost
THREAD_START, THREAD_CLEAN, THREAD_PING
ANTENNADRIVE_TASK_FWD_FN

AntennaRx

Location: gcp/antenna/control/bicep/AntennaRx.cc
in gcp, antenna, control
class AntennaRx

Functions:
registerDone, processMsg
sendTrackerRxMsg, sendPackDataFrameMsg
simData, simPmac, simGps
ANTENNARX_TAXK_FWD_FN
THREAD_START, THREAD_CLEAN, THREAD_PING

For Tomorrow: Look at the "how to run" directions in Erik's short description.

8/20

bicepGrabber Control

Classes:
Master -> a class for reading frames from the frame grabber, and sending them to the outside world.
Control -> a class to encapsulate the control connection between the AC and the ACC
Scanner
FrameGrabber -> deal with visual output and user interface
GrabberNetCmdForwarder

Master

Location: gcp/grabber/common/Master.cc
in namespace gcp, grabber
Class Master
sub-threads:
  ~ Control
  ~ Scanner
  ~ Signal

Functions:
processMsg,
sendcontrolConnectedMsg, sendScannerConnectedMsg
installSignals, installTimers
SIGNALTASK_HANDLER_FN
MASTER_TASK_FWD_FN
THREAD_START, THREAD_CLEAN

Control

Location: gcp/grabber/comon/Control.cc
in namespace gcp, grabber
Class Control

Functions:
connect, disconnect, connectControl, disconnectControl, isConnected
sendControlConnectedMsg
serviceMsgQ, processMsg, packNetMsg
NET_READ_HANDLER, NET_SEND_HANDLER, NET_ERROR_HANDLER
CONTROL_TASK_FN
LOG_HANDLER_FN

Scanner

Location: gcp/grabber/comon/Scanner.cc
in namespace gcp, grabber
Class Scanner

Function:
parseGreeting
connect, disconnect, connectScanner, disconnectScanner
processMsg, serviceMsgQ
sendScannerconnectedMsg
addFakeImage, addFakeImageSingleStar, addRampImage, addGrabberImage
finalizeImage, flatfieldImage, packImage, sendImage
rowFlatfield, imageFlatfield, storeCurrentImageAsFlatfield
getHotPixels, getMaskedMean, getMaskedSigma
outlierReject
NET_READ_HANDLER, NET_SEND_HANDLER, NET_ERROR_HANDLER

FrameGrabber

Location: gcp/grabber/comon/FrameGrabber.cc
in namespace gcp, grabber
Class FrameGrabber

Functions:
setDeviceFileName
initialize
setImageSize, getImage
queryProperties, printProperties
queryCapabilities, printCapabilities
queryWindow, printWindow, setWindow
queryChannel, printChannel, setChannel
queryImageBuffer, printImageBuffer
queryPicture, printPicture
setDepth, setBrightness, setContrast
createCaptureBuffer
openFrameGrabber


Try to run gcp

I'm supposed to have a startup script in $GCP_DIR/conf/bicepControl.init. This file does not exist. ??

Look for startup script in:
    gcp/misc/scripts/bicep/controlSystem
run by typing:

controlSystem |start(d)|restart(d)

    commands:
controlSystem start(d)|stop|restart(d) command
Try the following:
kstory@bicep0:bicep$ pwd
/home/bicep0/kstory/gcp/misc/scripts/bicep
kstory@bicep0:bicep$ ./controlSystem start bicepTest
Starting bicepControl test version
Starting bicepMediator test version
Starting bicepAntennaControl test version

Then 3 windows pop up:
Control -> Closed immediately.
Mediator -> 'Can't execvp /home/bicep/gcp/bin/bicepMediator: No such file or directory'. This is true, however there is a file in /home/bicep0/kstory/gcp/bin/bicepMediator
AntennaControl-> I do not have the correct permissions to access this.

Edit controlSystem to change where program looks for bicepMediator to /home/bicep0/kstory/gcp/bin/bicepMediator. Now:
Control -> Closes immediately
Mediator -> Closes immedaitely
Antennacontrol -> need root password.

Looking at the script file 'controlSystem'

controlSystem

bash script.
args: status|start(d)|restart(d)|stop
Functions:
startAll: args all|bicep|bicepTest
    start control, mediator, antenna
stopAll: all|bicep|bicepTest
status:
    print status of the control system processf
start: control|testControl|mediator|testMediator|antenna|gestAntenna
stop: grabber|control|testControl|mediator|testMediator|antenna|testAntenna
printUsage:
    print general usage info message

Calls:
        testControl)
            echo "Starting bicepControl test version"
            case $2 in
                fg)
                    \xterm +vb -geometry 70x30+900+0    -bg DarkOliveGreen \
     -T "bicepControl" -e /home/bicep0/kstory/gcp/bin/bicepControl logd=/ho\
me/bicep/runlogs logf=bicepTestControl &
                    ;;
                bg)
                    ssh localhost '/home/bicep0/kstory/gcp/bin/bicepControl\
 logd=/home/bicep/runlogs logf=bicepTestControl < /dev/null >& /dev/null &'
                    ;;
            esac
            ;;

Enter manually in to command line:

kstory@bicep0:~/gcp/$ \xterm +vb -geometry 70x30+900+0 -bg DarkOliveGreen -T "bicepControl"
Now in new xterm, enter:
kstory@bicep0:~/gcp/$  /home/bicep0/kstory/gcp/bin/bicepControl logd=/home/bicep/runlogs logf=bicepTestControl &
[1] 10977
kstory@bicep0:~/gcp/$ 20-AUG-2008 18:45:32.092: In int gcp::program::Program::run(int, char**): Caught an exception:
In void gcp::util::LogFile::open(): Unable to open file.In void gcp::util::LogFile::open(): In fopen(): No such file or directory.

[1]    Exit 255                      /home/bicep0/kstory/gcp/bin/bicepControl logd=/home/bicep/runlogs  ...
kstory@bicep0:~/gcp/$

I have the file
    gcp/util/common/LogFile.h
which declares a function open() -> this is just the function that is failing, because the desired file does not exist.
The file I think they want to source is
    /home/bicep/gcp/control/conf/bicep/control.init
The code that is actually running is at:
    /gcp/program/common/Program.cc

By editing Program.cc, I can get a debug message, "Kyle debug 1" to show up in the xterm!
The read file is failing in the main loop.


Meet with Clem
Next project: write code to allow the bicepControl to take in data from the MCE.
MCE is a control software and hardware system that is analogous to the bicepAntennaControl in the gcp hierarchy. It is being worked on by Walt Ogborne.

For example code, look at spt code on spt.uchicago.edu. Talk to Ken here at Chicago.


Debugging fopen problem:
Problem is in Program::run(){ returnValue = this->main(); }
Where the comments for main say:
/**.......................................................................
  * main() is defined here, application programmers will need to define
  * Program::main() as well as a set of (actually optional) keywords,
  * usage, version, description that the "keys" program parses into C++
  * code to be linked in during program compilation*/

8/21

Trying to get control to run:
I am trying to run from the script:
    ~/gcp/misc/scripts/bicep/controlSystem
I still do not have an init file in the correct location. Try sourcing another one at:
    ~/gcp/control/conf/bicep/control.init

kstory@bicep0:bicep/$ pwd
/export/home/bicep0/kstory/gcp/misc/scripts/bicep
kstory@bicep0:bicep/$ ./controlSystem start bicepTest startupScript=~/gcp/control/conf/bicep/control.init
  ...
  Nothing happens.

questions:
  1) Where is the init script called from?
  2) how do I run the init script?

In ./controlSystem, the command start bicepTest does the following:
    ./controlSystem start bicepTest
    calls startAll bicepTest fg
    calls start testControl fg, start testMediator, testAntennaControl
    calls \xterm +vb -geometry 70x30+900+0 -bg DarkOliveGreen -T "bicepControl" -e /home/bicep0/kstory/gcp/bin/bicepControl logd=/home/bicep/runlogs logf=bicepTestControl & ;;

So it looks like the real call is to /home/bicep0/kstory/gcp/bin/bicepControl.
Try to run this directly:

kstory@bicep0:bin/$ pwd
/export/home/bicep0/kstory/gcp/bin
kstory@bicep0:bin/$ ./bicepControl

in main
entering run loop:

in run
in try{}, next initialize

in initialize
in try{to open logfile}
mytmp=1
return 0 from initialize

returnValue = 0
in run() try{this->main()}
Kyle anything
program->run has operated, retval = 0
program deleted

Look at /bin/bicepControl -> Problem: this is a binary executable file. I need to find the source code.

Try th efollowing:

kstory@bicep0:common/$ pwd
/export/home/bicep0/kstory/gcp/program/common
kstory@bicep0:common/$ /home/bicep0/kstory/gcp/bin/bicepControl logf=bicepTestControl

in main
entering run loop:

in run
in try{}, next initialize

in initialize
in try{to open logfile}
mytmp=1
return 0 from initialize

returnValue = 0
in run() try{this->main()}
21-AUG-2008 16:45:48.028: In void gcp::util::LogFile::open(): Opened logfile: ./bicepTestControl0 on Thu Aug 21 09:45:48 2008
Unable to bind TCP/IP socket to port 5460.
Address already in use
Inside del_ControlProg
Cancled threads: 0
Cancled threads2
Deleted thread resources
program->run has operated, retval = 1
program deleted
kstory@bicep0:common/$

Thus this runs fine, but is unable to bind TCP/IP socket.

Thus the error was coming from the command:

 logd=/home/bicep/runlogs

Ignore that for now, and focus on "Unable to bind TCP/IP" error first.

Question: where is the function this->main() defined?
The output
    Inside del_ControlProg
comes from
    /home/bicep0/kstory/gcp/control/code/unix/control_src/common/genericcontrol.c, L737
Thus somehow genericcontrol is getting called. But from where?

Inside new_ControlProg,
    add_readable_channel(cp, &cp->pipe->head)
is failing.
Looking inside add_readable_channel. Look at cp_add_send_fd.
Inside this, look at FD_SET: Where is this defined??
The Error message
    "Unable to bind TCP/IP socket to port 5460."
comes from
    ~/gcp/control/code/unix/libunix_src/common/tcpip.c, L119
inside of declaration of
    static int server_socket()
The public interface to this method is:
    tcp_server_sock
The method inside server_socket that failed to return this message was:
    bind(sock, (struct sockaddr \*)&address, sizeof(address))
which must be defined elsewhere.
Look for tcp_server_sock:

genericcontrol.cc: Program::main()

Finall, this is where the main control program is run from.
In the command
    /home/bicep0/kstory/gcp/bin/bicepControl logd=/home/bicep/runlogs logf=bicepTestControl &
logf is the LogFile Prefix for the output log.
logd is the LogFile Directory for the output log.
Thus this works:

kstory@bicep0:~/gcp/$ /home/bicep0/kstory/gcp/bin/bicepControl logd=/home/bicep0/kstory/gcp/runlogs logf=bicepTestControl &
[1] 15091
kstory@bicep0:~/gcp/$ 21-AUG-2008 20:57:48.106: In void gcp::util::LogFile::open(): Opened logfile: /home/bicep0/kstory/gcp/runlogs/bicepTestControl0 on Thu Aug 21 13:57:48 2008
Unable to bind TCP/IP socket to port 5460.
Address already in use
Inside del_ControlProg
Cancled threads: 0
Cancled threads2
Deleted thread resources

[1]    Exit 1                        /home/bicep0/kstory/gcp/bin/bicepControl logd=/home/bicep0/kstory/gcp/runlogs  ...
kstory@bicep0:~/gcp/$ ls runlogs/
bicepTestControl0

Still looking for exactly where the TCP/IP socket fails.
It occurs at:
    cp->rtc = new_RtController(cp);
which calls
    tcp_server_sock(CP_RTC_PORT, 1)

Conclusion for today:
I now know that programs are run from a function called Program::main() that resides in the particular location of the thing you are running. I can't connect to the specific requested socet connection, which is probably because my software is (hopefully) not hooked up to any hardware. But now I have a basis to start asking quesitons to Walt about this stuff.

For Tomorrow:
  - Email Walt Ogborne again
  - Look at spt code
  - try to talk to Ken.


Questions:
  1. Where is source code that runs /bin/bicepControl?
  2. What is the deal with the user-defined Program::main()?
  3. How is FD_SET defined?
  4. Better ways to search for functions and variables?

8/22

For Today:
  1. Look in to bicepMediator
  2. Figure out how the control program eats data from the AntennaControl.

Collected thoughts on how to integrate MCE

- We will need a MceControl subthread in the bicepMediator. This probably means three new files in gcp/mediator/bicep/: MceControl.h, MceControl.cc, MceControl.o
  - MasterMsg.h
    ~ include "gcp/mediator/bicep/MceControl.h"
    ~ new MsgType MCE_CONNECTED, MCE_MSG
    ~ add struct { bool connected } mceConnected;
    ~ packMceControlConnectMsg(...){}

  - Master.cc
    ~ include MceControl.h
    Functions:
    ~ Master::processMsg -> add case MasterMsg::MCE_CONNECTED
    ~ SIGNALTASK_HANDLER_FN(Master::sendMceConnectMsg)

  - MceControl.h
    ~ will be in namespace gcp, mediator
    ~ forward declaration of Control class
    ~ declare class MceControl:
      public:
        -constructor, destructor
      private:
        -friend class Control
        -Control*parent_
        -static MceControl*control_
        -gcp::util::TcpListner*listener_ -> the server socket on which to listen for connection requests from the MCE
        -gcp::util::NetCommHandler temporaryHandler_ -> network buffer associated with a mce whose connection we have accepted, but for which a greeting-response cycle is not yet complete.
        -std::vector connectedHandlers_ -> (maybe) a vector of network buffers associated with established antenna connections.
        -std::list initScript_ -> a list of initialization commands
        -std::list::iterator
        -bool recordingInitScript_ -> (maybe) True when we are recording an initialization script.
        -bool initInProgress_ -> True when an initialization is in process.
        -enum InitState -> a type for specifying the initialization state of the mce.
        -std::vector mceInitState_ -> a vector of initialization flags for the mce.
        -std::vector mcsConnectState_ -> a vector of connected flags for the mce.
        -std::vector sendPending_ -> a vector of pending flags for the mce.
        -gcp::util::TimeVal startTime_ -> Time structs we will use for handling timeouts in select
        -gcp::util::TimeVal timer_
        -struct timeval*timeOut_
        -unsigned int pending_ -> A count of pending network commands to the mce.
        -
        Functions:
        -void setPending() -> de/increment the count of commands pending to the mce
        -bool have ControlConnection() -> Attempt to get a control connection to the mce.
        -void connectTcpIp() -> Set up for TCP/IP communications.
        -void processMsg() -> Process a message received on our message queue
        -sendRtcNetCmd() -> Respond to a message to send a network command to the antenna control socket.
        -decrementPending() -> Decrement the count of commands pending to the mce.
        -static NET_SEND_HANDLER(netMsgSentHandler) -> A handler to be called when a message is sent to the mce.
        -static NET_SEND_HANDLER(netCmdSentHandler) -> A handler to be called when a command is sent to the mce.
        -static NET_ERROR_HANDLER(netErrorHandler) -> A handler to be called when an error occurs sending a command to the mce.
        initialization methods
        -void setInitState()
        -void recordInitMsg()
        -void beginInitScript()
        -void sendNextInitMst()
        -endInitScript()
        -setNavUpdateMsg() -> Send a request for an update of ephemeris data from the AAC
        -bool haveMceReady() -> (maybe) Return true if the mce is ready to be initialized.
        -void flagMce() -> Respond to a message that the mce changed state.
        -bool listening() -> Returns true if we are currently listening for connection requests.
        -void serviceMsgQ()
        -void initializationConnection() -> Initialize a connection to the mce.
        -finalizeConnection()
        -terminateConnection() -> Terminate a socket connection.
        -terminateConnection() -> Terminate a connection to the mce.
        -forwardNetMsg() -> Forward a net message to the control task.
        -sendGreetingMsg() -> Send a greeting message to the mce.
        -static NET_READ_HANDLER(processTemporaryNetMsg)
        -static NET_READ_HANDLER(processNetMsg)
        -void listen() -> Start listening for connections from the mce.
        -bool timedOut() -> Return true if we timed out waiting for a response from the mce.
        -void startRecordingInitScript() -> Mark subsequent commands as belonging to the initialization script.
        -stopRecordingInitScript() -> Finish recording initializaiton commands.

  - MceControl.cc
    ~ class MceControl

  - MceControlMsg.h
    like AntennaControlMsg.h

  - MceNetCmdForwarder.h
    like AntennaNetCmdForwarderNormal.h

  - control/code/unix/libunix_src/common/control.c
    probably nothing.
  - control/code/unix/libunix_src/common/control.h
    probably nothing.

  - mediator/Control.cc
    L19: #include "gcp/mediator/specific/MceControl.h"
    L78: threads_.push_back(new Thread(&startMceControl, ...)
    L297: case ControlMsg::MCE_CONTROL_MSG:
    L4xx: THREAD_START(Control::startMceControl)
    L5xx: THREAD_CLEAN(Control::cleanMceControl)
    L749: void Control::forwardMceControlMsg(ControlMsg* msg){}

  - mediator/ControlMsg.h
    L48: MCE_CONTROL_MSG,
    L86: MceControlMsg mceControlMsg;
    L131: inline MceControlMsg* getMceControlMsg()

  - mediator/Scanner.h
    L36: class MceDataFrameManager;
    L38: #if DIR_HAVE_MAS
          namespace receiver{ class MceConsumer }
          
    L47: class MceConsumer
    L73: void packMceFrame(gcp::util::MceDataFrameManager* mceFrame);
    L7x: void sendPackedMceDataFrameMsg();
    L8x: friend Consumer classes?
    L109: void initAntennaResources();
    L115: static THREAD_START(startMceConsumer);
    L121: static THREAD_CLEAN(cleanMceConsumer);
    L132: MceConsumer* mceConsumer_; //object to capture data from mce
    L155: static const unsigned int NUM_BUFFER_FRAMES ?
    ...

  - mediator/Scanner.cc
    ...

  - util/specific/MceNetCmdForwarder.h

  Other Data Types:
  ~ class MceControlMsg
  ~ CcMceMsg -> in control.h
  ~ class MceConsumer -> from mediator/Scanner.h
  ~ class MceDataFrameManager -> from mediator/Scanner.h
  ~ class MceDataFrame -> from mediator/Scanner.h
  Other Functions:
  ~ startMce
  ~ cleanMce
  ~ pingMce

bicepMediator Control

Try to run:
Looking at misc/scripts/bicep/controlSystem: start testMediator
The relevant commands are:

\xterm +vb -geometry 70x30+450+0  -bg goldenrod -fg black -T "bicepMediator" -e
    /home/bicep0/kstory/gcp/bin/bicepMediator host=localhost logd=/home/bicep0/kstory/gcp/runlogs logf=bicepTestMediator &

In a bicep0 terminal, type:

\xterm +vb -geometry 70x30+450+0  -bg goldenrod -fg black -T "bicepMediator" &

In the xterm, type:

kstory@bicep0:bicep/$ /home/bicep0/kstory/gcp/bin/bicepMediator host=localhost logd=/home/bicep0/kstory/gcp/runlogs logf=bicepTestMediator &
[1] 26161
kstory@bicep0:bicep/$ 22-AUG-2008 15:15:46.443: In void gcp::util::LogFile::open(): Opened logfile: /home/bicep0/kstory/gcp/runlogs/bicepTestMediator0 on Fri Aug 22 08:15:46 2008

kstory@bicep0:bicep/$
kstory@bicep0:bicep/$ ps
  PID TTY          TIME CMD
26127 pts/4    00:00:00 tcsh
26161 pts/4    00:00:00 bicepMediator
26178 pts/4    00:00:00 ps

Thus the Mediator appears to be running!

Write a new control system script called mycontrolSystem -> Done
Try to run it:

kstory@bicep0:bicep/$ ./mycontrolSystem start testViewer
Starting bicepViewer test
-> xterm opens, then window closes.

The commands that are being called are:

\xterm +vb -geometry 70x30+900+0    -bg gold1 -T "bicepViewer"
/home/bicep0/kstory/gcp/bin/bicepViewer logd=/home/bicep0/kstory/gcp/runlogs logf=bicepViewer &

Try opening a terminal separately and running explicitly:
Prints out the following help message:

kstory@bicep0:bicep/$ /home/bicep0/kstory/gcp/bin/bicepViewer logd=/home/bicep0/kstory/gcp/runlogs logf=bicepViewer &
[1] 30630
kstory@bicep0:bicep/$ /home/bicep0/kstory/gcp/bin/bicepViewer: Unrecognized first argument.

Usage:

 /home/bicep0/kstory/gcp/bin/bicepViewer [options] configure <configuration_file]>

  or

 /home/bicep0/kstory/gcp/bin/bicepViewer [options] monitor <hostname> [configuration_file]

  or

 /home/bicep0/kstory/gcp/bin/bicepViewer [options] read <start_time>V <end_time> <configuration_file>

[Note that empty start_time and end_time arguments specify the
 corresponding time extremes of the archive. To have live monitoring
 start after reaching the end of the archive, specify the control
 program host name in the end_time field, instead of a time].

Options:
           -help     Print this help information.
           -arcdir   The directory that contains archive files.
           -bufsize  The size of the plot buffer (registers).
           -calfile  The name of the calibration file.
           -confdir  The directory that contains configuration files.
           -conffile The name of the default configuration file.

Environment variables:
     GCP_DIR        The root of the CBI directory tree.
     GCP_ARC_DIR    The main archive directory.

[1]    Exit 1                        /home/bicep0/kstory/gcp/bin/bicepViewer logd=/home/bicep0/kstory/gcp/runlogs  ...

From the terminal, just type:

/home/bicep0/kstory/gcp/bin/bicepViewer

and the bicepViewer gui pops up! Excellent...
Re-write a simple startup script called /misc/scripts/bicep/mysimpleStartup. This starts 3 things:
  - an xterm with bicepControl
  - an xterm with bicepMediator
  - bicepViewer in its own gui.
bicepMediator is complaining because it can't connect to bicepAntenna. That is good, because bicepAntenna is not running.

Try following the RTC Tour on the Bicep gcp page.
Connect the bicepViewer to my bicepControl, which is running at bicep0.caltech.edu:

File -> Connect to the Control Program
Control Computer = bicep0.caltech.edu (!! not blah.southpole.blah !!)
Error reading configuration file: /home/bicep0/kstory/gcp/control/conf/gcp//stat.page
couldn't read file "/home/bicep0/kstory/gcp/control/conf/gcp//stat.page": no such file or directory

This is ok; I gather that the stat.page is something I can write and personalize when I want to.
I can open everything and enter commands, but not much happens because I am not hooked up to anything.

Next, look at how bicepControl and bicepMediator talk to bicepAntenna.

For Monday:
  - Look at control code to see how commands there are packaged, then passed through the mediator to the antenna.
  - Look at spt code.
  - Talk to Ken about spt code and the fmux
  - Email Walt again.

8/25

bicepViewer

Location of source code: /gcp/control/code/unix/viewer_src/
Files: axes, color_tab.h, monitor_viewer, netscape_remote, panel, tclmonitor, tkviewer.

monitor_viewer
class MonitorViewer: The top-level object of the viewer hierarchy. Records the contents and state of the viewer.
struct MonitorPlot: The viewer can contain many plots, each of which is rendered on a separate pgplot output device.
    enum MpScrollMode
struct MonitorGraph: Each plot can contain many graphs, with all graphs sharing the same x_axis.
struct MonitorPage: The viewer can contain multiple pages, consisting of a collection of textual fields.
struct MonitorField: Each field on a page shows the instantaneous value of one register, textually formatted in one of a variety of ways.
    enum MonitorFormat
struct MonitorImage:
struct MonitorRegStatus
    enum MonitorRegState
struct MonitorPage:
struct MonitorTrace: A trace designates teh set of lines on a graph that display the values of one or more elements of a singe register, from a single register specification.
struct MpScroll: Provide a container for collecting scroll information.
struct MpPlotStats: Plot X-axis statistics
struct MonitorBuffReg: Each register that has been selected for monitoring is associated with an element of this type.
struct MonitorBuffMap: Encapsulate buffered monitor data.
struct MontiorBuff:
struct MpPointBuff: Encapsulate the X and Y axis arrays that are used to buffer up multpile points to be drawn by a single call to pgpt().
struct MpFormatBuf: Contains an output stream used to format textual values of output fields, and the string that it writes.

Functions:
  MonitorViewer
    (.c) flag_MonitorViewer, clr_Monitorviewer_regs, new_MonitorBuffMap, fill_MonitorBuffMap, del_MonitorBuffMap, new_MonitorBuff, del_MonitorBuff, config_MonitorBuff, refine_MonitorPlot_oldest, remap_MonitorBuff, cmp_MonitorBuffReg, page_preview_pending, shrink_Monitorbuff, expand_Monitorbuff, vet_axis_limits, init_MonitorImage
    (.h) new_MonitorViewer, del_MonitorViewer, rem_MonitorViewer_pages, rem_MonitorViewer_plots, change_MonitorStream, change_ImMonitorStream, clr_MonitorBuvv, Monitorviewer_ArrayMap, MonitorViewer_fd, MonitorViewer_im_fd, update_MonitorViewer, read_MonitorViewer_frame, read_MonitorViewer_image, send_MonitorViewer_msg, send_MonitorViewer_im_msg, set_Monitorviewer_interval, queue_MonitorViewer_rewind, can_MonitorViewer_rewind, is_MonitorViewer_archivedOnly
  MonitorPlot
    (.c) new_MonitorPlot, del_MonitorPlot, scroll_MonitorPlot, flag_MonitorPlot, get_MonitorPlot_stats, draw_MonitorPlot_title, add_MonitorPlot_regs, clr_MonitorPlot_regs
    (.h)tag_of_MonitorPlot, add_MonitorPlot, config_MonitorPlot, rem_MonitorPlot, rem_MonitorPlot_graphs, limit_MonitorPlot, find_MonitorPlot, full_MonitorPlot_xrange, update_MonitorPlot, resize_MonitorPlot
  MonitorGraph
    (.cc) new_MonitorGraph, del_MonitorGraph, draw_MonitorGraph_axes, draw_MonitorGraph_data, drawMonitorGraphData, checkYAxis, drawNext, drawPoint, drawNormalLine, drawPhaseLine, getStat, draw_value_points, drawValueSa, drawValueMaSe, drawValueMaMe, getStatsSa, getStatsMaSe, getStatsMaMe, findClosestPointSa, findClosestPointMaSe, findClosestPointMaMe, checkPoint, draw_logic_points, drawLogicSa, drawLogicMaSe, drawLogicMaMe, draw_value_lines, draw_logic_lines, draw_phase_lines, find_normal_point, find_logic_point, flag_MonitorGraph, x_ndc_to_graph, y_ndc_to_graph, x_graph_to_ndc, y_graph_to_ndc, checkXaxisValidity, mpTraceRegStats, findTrace
    (.h) tag_of_MonitorGraph, add_MonitorGraph, config_MonitorGraph, rem_MonitorGraph, clr_MonitorGraph_regs, find_MonitorGraph, update_MonitorGraph, int_MonitorGraph, auto_MonitorGraph_yrange
  MonitorPage
    (.c) rem_MonitorPage_fields, rem_MonitorViewer_pages, clr_MonitorPage_regs, draw_MonitorPage, add_MonitorPage_regs
    (.h) tag_ofMonitorPage, add_MonitorPage, find_MonitorPage, rem_MonitorPage, freeze_MonitorPage, unfreeze_MonitorPage
  MonitorField
    (.c) new_MonitorField, del_MonitorField
    (.h) add_MonitorField, tag_of_MonitorField, config_MonitorField, rem_MonitorField, find_MonitorField, rem_MonitorPage_fields, open_MonitorImage, draw_MonitorImage_data, set_MonitorImage_centroid, find_MonitorImage_centroid, fid_MonitorImage_contrast, set_MonitorImage_range, install_MonitorImage_colormap, reset_MonitorImage_colormap, reset_MonitorImage_contrast, get_MonitorImage_greyscale, get_MonitorImage_status, set_MonitorImage_step, set_MonitorImage_fov, set_MonitorImage_aspect, toggle_MonitorImage_grid, toggle_MonitorImage_bullseye, toggle_MonitorImage_compass, toggle_MonitorImage_crosshair, set_MonitorImage_compass
  MonitorRegStats
    mp_global_RegStats, mpRegStats, mp_hardcopy, mp_resize_buffer, mp_xaxis_limits, mp_set_calfile, reset_MonitorField_counters, outputRegName,
  MonitorPage
    new_MonitorPage, del_MonitorPage, add_MonitorPage_regs, draw_MonitorPage, ctr_MonitorPage_regs
  MonitorTrace
    new_MonitorTrace, del_MonitorTrace

  Other Functions:
    MP_DEL_FN
    MP_FIELD_FN
    MP_SCROLL_FN
    mf_callback_fn
    mp_scroo_callback
    mp_cursor_to_graph
    mp_graph_to_cursor
    find_Monitor_point
    findMonitorPoint

netobj: netobj.c, netobj.h

Location: /gcp/control/code/unix/libunix_src/common/netobj.c(h)
Description: This file describes network-transparent objects and the funcitons that manipulate them.
Data Types:
enum NetDataType: enumerates the basic database types
struct NetObjEnumTable: symbol table for enumeration members
struct NetObjMember: a type used to describe one member of an object
struct NetObjInfo: Declare an object description type
struct NetObjTable: A container of this type should be used to describe each of the network objects that are to be supported.
Functions:
obj_to_net: Pack a network object into a network buffer for transmission.
net_to_obj: Unpack a network object form a network buffer.
net_max_obj_size: Return the amount of buffer space needed to pack the largest of the objects from the given table of object definitions.
net_native_size: return the native size of a given network object on the local architecture
net_obj_info: look up the definition of a given network object type


Look at how a command gets passed from bicepViewer to bicepCommand to bicepMediator to bicepAntennaControl:
The main entry point is bicepViewer. The viewer then controls the following: MonitorTrace, MonitorGraph, MonitorPlot, MonitorPage, MonitorField.
Q: Where do commands that are typed into the bicepViewer go?
Launch Viewer, and do NOT connect to Control. Try typing a command:

bicepViewer> lockin ac, device=bolo
send: Not connected to the control program.

Search for the phrase "Not connected to the control program."
Found in control/code/unix/libtclcontrol_src/tclcontrol.c: Tcl_AppendResult()
Go look at that function.

tclcontrol
Location: gcp/control/code/unix/libtclcontrol_src/tclcontrol.c
Data Types:
  TcCommandType
  TcEventLoop
  TcControl: Record the resources of each package instance.
Functions:
  new_TclControl, del_TclControl, delete_TclControl, service_TclControl, tc_host, tc_send, tc_event_loop, tc_log_array, tc_reply_array, tc_sched_var, tc_archiver_var, tc_expname_var, tc_viewername_var, tc_pater_var, tc_ant_var, tc_grabber_var, tc_host_callback, is_empty_string, tc_connect, tc_disconnect, tc_check_connection, tc_server_event, tc_read_stdin, tc_prep_stdin, updateGrabberTclVariables

service_TclControl -> This function is called whenever the Tcl command registered by ControlInit() is invoked.
tc_server_event -> This function is called by the Tcl event dispatcher whenever the control-program connection becomes readable.

----
The bicepViewer opens up a Tclcontrol with the function new_TclControl(). This is then responsible for sending and receiving messages, with the funciton service_Tclcontrol(). Any message then is sent or received via the tc_server_event() function.
A message is sent with the obj_to_net() function. A message is received with the net_to_obj() function.

bicepViewer connecting to bicepControl

For example, this is how the bicepViewer connectes to the bicepControl:
BVw > means bicepViewer
BCtrl > means bicepControl

BVw > tc: in tc_connect
BVw > tc: in service_TclControl
BCtrl > 080825 19:53:00 Accepted control-client connection from 131.215.123.123.
BCtrl > no: in obj_to_net, id=grabber
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=grabber
BCtrl > no: in obj_to_net, id=arc
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=arc
BCtrl > no: in obj_to_net, id=arc
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=arc
BCtrl > no: in obj_to_net, id=arc
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=arc
BCtrl > no: in obj_to_net, id=arc
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=arc
BCtrl > no: in obj_to_net, id=log
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=log
BCtrl > no: in obj_to_net, id=page
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=page
BCtrl > no: in obj_to_net, id=ant
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=ant
BCtrl > no: in obj_to_net, id=sched
BVw > tc: inside tc_server_event
BVw > no: -- in net_to_obj, id=sched

For Tomorrow:
  - figure out where the message gets parsed on the control side.
    This should involve looking for functions that involve tcl in the bicepControl main software.
  - figure out how a command from the Viewer gets packaged to be sent to bicepControl and the mediator.
  - Try writing a new output port in bicepMediator called "MCE" which actually just prints things out to the command line, rather than doing anything.
  - Talk to Ken.
  - Email Walt.

8/26

Goal for today:
Be able to write down explicitly how a message is propagated from the bicepViewer to the bicepAntenna. i.e.

Type command into bicepViewer.
  Packaged by (function) in (struct:field)
  Sent to Control by (function)
bicepControl
  Receive package by (function)
  Parsed by (function)
  Read into (struct:field)
  Packaged by (function) in (struct:field)
  Sent to Mediator by (function)
bicepMediator
  Received package by (function)
  Parsed by (function)
  Read into (struct:field)
  Packaged by (function) in (struct: field)
bicepAntennaControl
  can't do much here without root priveleges.

How bicepViewer parses a message:

User types a command into bicepViewer
  1. Tcl reads it as type "command"
  2. service_TclControl() takes in command and calls tc_send()
  3. tc_send() -> argv[0] = actual str of user command
    - pack message with obj_to_net() function
      ~ this uses the net_put_*() function to write to the buffer
    - send message to controler via nss_send_msg()
      ~ uses write() function to write message to network buffer

For Tomorrow:
Continue down the chain; look into how controler receives the message.

8/27

How bicepControl command loop starts:

The bicepControl is started in the genericcontrol.c::Program::main() method.
  1. Program::main() enter while(whatnext==CP_RESTART && !waserr)
  - startup script
  - call cp_event_loop()
    + while(!waserr && cp->whatnext==CP_CONTINUE)

How bicepControl parses a message from bicepViewer:

+ while(!waserr && cp->whatnext==CP_CONTINUE)
      - chan = active channel at the head of the active list
      - chan->io_fn which is CHAN_IO_FN(sock_read_fn)
        + switch(nrs_read_msg(sock->nrs))
          - case NET_READ_DATA: add_readable_channel()
          - while(length of message)
            + nread = read()

For tomorrow:
  - Figure out exactly how the bicepControl reads in from the bicepViewer, i.e. understand my printout statements.
  - Look into how the bicepControl talks to the Mediator.
  - email Walt
  - Look for Ken.
  - Look at spt code.

8/28

Worked all day on understanding exactly how bicepControl talks to bicepViewer and bicepMediator. I made a lot of progress. Check my paper notebook for notes.

For tomorrow:
  - finish writing out how a message is propigated, with bV and bM. Type it up here.
  - look at spt code.