Main Page | Class List | Directories | File List | Class Members | File Members

ccu.c File Reference

CCU (communication with the CCD Control Unit). More...

#include "ccu.h"
#include "error.h"
#include <stdlib.h>
#include <stdio.h>
#include <gnome.h>
#include "semaphore.h"
#include "math.h"
#include "background.h"

Defines

#define WIDTH   0x0850
#define HEIGHT   0x800
#define BYTESPERPIX   2
#define BYTEORDER   ccu_channels;

Functions

void ccu_fail (char *str)
 extracts the error code from an endmessage received from the CCU.
int end_message_get_error_code (const char *endmsg)
 extracts the error code from an endmessage received from the CCU.
ccu_status_struct ccu_get_status ()
 returns the current status of the CCU.
void ccu_set_status_async (struct ccu_status_struct input)
 sets the status of the CCU (for internal use by ccu.c only).
void ccu_set_progress (char *msg, float f)
 sets the progress struct of ccu.c.
void ccu_set_status (struct ccu_status_struct input)
 sets the status of the CCU.
void ccu_set_com_problem (void)
 sets the CCUs communication problem flag.
void ccu_reset_com_problem (void)
 resets the CCUs communication problem flag.
int ccu_get_dummy_read ()
 retruns 1 if dummy read is running and 0 otherwise.
void ccu_reset_breakcondition ()
 resets the CCUs break condition flag.
void ccu_reset_warning ()
 resets the CCUs warning flag.
int ccu_get_xsize ()
 returns the x size of the image beeing acquired currently.
int ccu_get_ysize ()
 returns the y size of the image beeing acquired currently.
progress_struct ccu_get_progress ()
 returns the current progress of the CCU.
int ccu_get_available ()
 retruns the availabilty of the ccu.
int ccu_init (void)
 initializes ccu.c.
void ccu_done (void)
 closes ccu.c.
int ccu_load_sequence_context (void)
 loads the sequence list from the CCU.
int ccu_simulate_sequence_context (void)
 generates a simulated sequence list.
int ccu_load_version_number (void)
 loads the version number from the CCU.
int ccu_simulate_version_number (void)
 gernerates a simulated version number.
int ccu_load_and_check_sequence_context ()
 loads the sequence list from the CCU, and compares it with data store in the .SQ file.
int ccu_simulate_and_dont_check_sequence_context ()
 loads the sequence list from the CCU, and compares it with data store in the .SQ file.
int ccu_send_simple_command (char *command, char *description, int timeout)
 sends a command to the CCU and waits for the corresponding start message.
int ccu_send_ending_command (char *command, char *description, int timeout)
 sends a command to the CCU and waits for the corresponding start and end messages.
int ccu_wait_for_end_message (int timeout)
 waits for the CCU to send an end message.
int ccu_dummy_read ()
 starts a continues dummy read
int ccu_quit ()
 sends a quit signal to the CCU
int ccu_quit_msg ()
 sends a quit signal to the CCU
int ccu_clear_queue ()
 clears the queue CCU and empties the queue in ccu.c
int ccu_contact (void)
 contacts the CCU
int ccu_test_avail (void)
 tests whether the CCU is available and initalized it if possible.
int ccu_start_queue ()
 starts a queue in the ccu.
int ccu_shutter_open ()
 opens the shutter.
int ccu_shutter_close ()
 closes the shutter.
int ccu_single_dummy_read ()
 runs a single dummy read.
int ccu_zero_volt ()
 starts the zero volt sequence on the CCU.
int ccu_set_gain (int gain)
 sets the gain.
int ccu_set_capacity (int capacity)
 sets the capacity of the integration capacitor.
int ccu_readout (int sequence)
 starts a readout.
int ccu_readout_user (char *str)
 starts a readout, with a user defined readout command.
int ccu_reset_kerneldriver ()
 resets the kernel driver.
size_t ccu_read_usb (unsigned char *data)
 reads 512 bytesfrom the usb kerneldriver.
int ccu_parse_database ()
 loads and parses a database given in the .SQ file
char * ccu_function_origin_message (int funcorig)
 retruns a string corresponding to the given function origin code emitted by the CCU.
char * ccu_error_message (int error)
 retruns a string corresponding to the given error code emitted by the CCU.
char * ccu_status_message (int code)
 retruns a string corresponding to status code defined in ccu.h.
char * ccu_status_text (int code)
 retruns a string corresponding to status code defined in ccu.h.
void ccu_parse_endmessage (const char *endmsg)
 parses an endmessage and sets the status accordingly
void ccu_parse_message (const char *msg)
 parses a message and sets the status accordingly
void ccu_queue_push_item (char *input)
 queues a new command into the queue.
int ccu_queue_pop_item (char *dummy)
 pops a command from the queue.
int ccu_send_queue ()
 send a queue to the CCU.
int ccu_queue_file (char *filename)
 queues a list of commands read from a file.
int ccu_upload_database_file (char *filename)
 downloads a database into the CCU.
void ccu_start_database_dowload (char *str)
 starts a thread that will download the database into the CCU
void ccu_start_zero_volt ()
 starts a thread that will run the zero volt sequence in the CCU
void ccu_start_database_dowload_basename (char *str)
 starts a thread that will download the database into the CCU
void ccu_ser_in (const char *str)
 called whenever something is received from the CCU
void ccu_ser_out (const char *str)
 called whenever something is sent to the CCU
int ccu_send_command (char *cmd)
 sends a command to the CCD controller.
int ccu_send_byte (int byte)
 sends a single byte to the CCD controller.
int ccu_receive_command (char *cmd, int timeout)
 sends a single byte to the CCD controller.
int ccu_finish ()
 Destuctor.
void makestar (long x, long y, unsigned long f, int boxsize, double sigma, unsigned char *image)
 Writes a simulated star to the image buffer.
void makebias (unsigned long bias, unsigned long noise, unsigned char *image)
 Writes a simulated bias image to the image buffer.
void ccu_simulate_image ()
 Fills the image buffer with some pseudoastronimical data.

Variables

sem_t ccu_sem
sem_t ccu_queue_sem
serdev * ccu_device
FILE * ccu_usbdev_file = NULL
sem_t ccu_status_sem
ccu_status_struct ccu_status
volatile int ccu_expect_break = 0
char ccu_sequence_context [100][1000]
char ccu_sequence_context_full [100][1000]
char ui_ccu_sequence_context [100][1000]
ccu_database_struct ccu_database [100]
char ccu_dev [1000]
char ccu_usbdev [1000]
int ccu_stty_baud
char ccu_database_filename [1000]
char ccu_database_dir [1000]
char ccu_ctrldir [1000]
int ccu_channels
GList * ccu_queue_list = NULL
int ccu_simulation_mode = 0
unsigned char * ccu_simulated_image = NULL
unsigned long ccu_simulation_position
double ccu_shutter_offset
int command_block = 1


Detailed Description

CCU (communication with the CCD Control Unit).

Copyright (C) 2001-2003 Dirk Huenniger (dhun@astro.uni-bonn.de)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.


Function Documentation

int ccu_clear_queue  ) 
 

clears the queue CCU and empties the queue in ccu.c

Returns:
integer an error code
This function clears the queue CCU and empties the queue in ccu.c

int ccu_contact void   ) 
 

contacts the CCU

Returns:
integer an error code
This function contacts the CCU. It sends up to 30 quit signals until a proper reply is received.

void ccu_done void   ) 
 

closes ccu.c.

Returns:
void
This function closes ccu.c. It has to be called exatly one time. No function of ccu.c should be called after ccu_done has been called.

int ccu_dummy_read  ) 
 

starts a continues dummy read

Returns:
integer an error code
This function starts a continues dummy read. All charges on the chip are removed. Be carful, because it will take some time until the charge is actually removed from the chip. Use ccu_single_dummy read to make shure that the chip was cleased at least once.

char* ccu_error_message int  error  ) 
 

retruns a string corresponding to the given error code emitted by the CCU.

Parameters:
error the error code
Returns:
char* the error message string
This function retruns a string corresponding to the given error code emitted by the CCU.

void ccu_fail char *  str  ) 
 

extracts the error code from an endmessage received from the CCU.

Parameters:
endmsg the endmessage revceived from the CCU
Returns:
integer (0 means: no error)
This function extracts the error code from an endmessage received from the CCU.

int ccu_finish  ) 
 

Destuctor.

Returns:
error code
This function has to be called when you dont waht to use the ccd controller anymore. If just frees some memory.

char* ccu_function_origin_message int  funcorig  ) 
 

retruns a string corresponding to the given function origin code emitted by the CCU.

Parameters:
funcorig the function origin code
Returns:
char* the message string
This function retruns a string corresponding to the given function origin code emitted by the CCU.

int ccu_get_available  ) 
 

retruns the availabilty of the ccu.

Returns:
integer (1 if ccu is available, 0 otherwise)
This function returns 1 if ccu is available and 0 otherwise. The status code of the ccu is set to ccu_status_idle during the initilazation of ccu.c, when something is received from the ccu this status is changed to something different from ccu_status_idle.

int ccu_get_dummy_read  ) 
 

retruns 1 if dummy read is running and 0 otherwise.

Returns:
integer (1 if dummy read is running 0 otherwise) This function retruns 1 if dummy read is running and 0 otherwise.

struct progress_struct ccu_get_progress  ) 
 

returns the current progress of the CCU.

Returns:
progress_struct a struct describing the current progress of the CCU
This function returns a struct describing the current progress of the CCU.

struct ccu_status_struct ccu_get_status  ) 
 

returns the current status of the CCU.

Returns:
ccu_status_struct a struct describing the current status of the CCU
This function returns a struct describing the current status of the CCU.

int ccu_get_xsize  ) 
 

returns the x size of the image beeing acquired currently.

Returns:
integere the x size in pixels of the current image This function returns the x size of the image beeing acquired currently.

int ccu_get_ysize  ) 
 

returns the y size of the image beeing acquired currently.

Returns:
integer the y size in pixels of the current image This function returns the y size of the image beeing acquired currently.

int ccu_init void   ) 
 

initializes ccu.c.

Returns:
integer (0 on success, an errorcode described in error.h otherwise)
This function initializes ccu.c. It has to be called exatly one time. It has to called before any other function of ccu.c is called.

int ccu_load_and_check_sequence_context  ) 
 

loads the sequence list from the CCU, and compares it with data store in the .SQ file.

Returns:
integer an error code
This function loads the sequence list from the CCU, and compares it with data store in the .SQ file. Anappropriate error/sucess code is returned.

int ccu_load_sequence_context void   ) 
 

loads the sequence list from the CCU.

Returns:
integer an error code
This function loads the sequence list from the CCU. the sequencst list is loaded until it two subsequncet trys lead to an identical sequence list. If this condition cannot be fullfilled by the 4th try an error is returned.

int ccu_load_version_number void   ) 
 

loads the version number from the CCU.

Returns:
integer an error code
This function loads the version number from the CCU. The version number is loaded until it two subsequncet trys lead to an identical version number. If this condition cannot be fullfilled by the 4th try an error is returned.

int ccu_parse_database  ) 
 

loads and parses a database given in the .SQ file

Returns:
integer an error code
This function loads and parses a database given in the .SQ file. The results are stored in ccu_database.

void ccu_parse_endmessage const char *  endmsg  ) 
 

parses an endmessage and sets the status accordingly

Parameters:
endmsg the endmessage received form the CCU
Returns:
void
This function parses an endmessage received from the CCU and sets the ccu_status_struct accordingly.

void ccu_parse_message const char *  msg  ) 
 

parses a message and sets the status accordingly

Parameters:
msg the message received form the CCU
Returns:
void
This function parses a message received from the CCU and sets the ccu_status_struct accordingly.

int ccu_queue_file char *  filename  ) 
 

queues a list of commands read from a file.

Parameters:
filename the name of the file to be read
Returns:
integer error/success code
This function queues a list of commands read from a file. Later on the queue can be transferred to the ccu via ccu_send_queue and started using ccu_start_queue.

int ccu_queue_pop_item char *  dummy  ) 
 

pops a command from the queue.

Parameters:
dummy a pointer to the region in memory where the poped command shall be stored
Returns:
integer 0 on success, -1 on failure
This function pops a command from the queue.

void ccu_queue_push_item char *  input  ) 
 

queues a new command into the queue.

Parameters:
input the command to be queued
Returns:
void
This function queues a command into the queue. Later on the queue can be transferred to the ccu via ccu_send_queue and started using ccu_start_queue.

int ccu_quit  ) 
 

sends a quit signal to the CCU

Returns:
integer an error code
This function sends a quit signal to the CCU. Any operastion on the CCU is stopped.

int ccu_quit_msg  ) 
 

sends a quit signal to the CCU

Returns:
integer an error code
This function sends a quit signal to the CCU. Any operastion on the CCU is stopped.

size_t ccu_read_usb unsigned char *  data  ) 
 

reads 512 bytesfrom the usb kerneldriver.

Parameters:
data a pointer to 512 byte of memory to store the data
Returns:
size_t 1 if 512 byte have been read, 0 otherwise
This function reads up 512 byte from the usb kerneldriver. It retruns 1 if a 512 byte block has been read, and 0 otherwise.

int ccu_readout int  sequence  ) 
 

starts a readout.

Parameters:
sequence the number of the sequence to be used for the readout
Returns:
integer an error code
This function starts a readout with a sequence given by the parameter.

int ccu_readout_user char *  str  ) 
 

starts a readout, with a user defined readout command.

Parameters:
str the user defined readout command
Returns:
integer an error code
This function starts a readout with a readout command given by the parameter.

int ccu_receive_command char *  cmd,
int  timeout
 

sends a single byte to the CCD controller.

Parameters:
byte to be send
Returns:
error code
This function sends a single byte to the CCD controller.

void ccu_reset_breakcondition  ) 
 

resets the CCUs break condition flag.

Returns:
void This function resets the CCUs break condition flag.

void ccu_reset_com_problem void   ) 
 

resets the CCUs communication problem flag.

Returns:
void This function resets the CCUs communication problem flag.

int ccu_reset_kerneldriver  ) 
 

resets the kernel driver.

Returns:
integer an error code
The deltails of this routine are still subject of ongoing research. Open for writing removes all usb request block from the queue in the usb kernel subsystem and resets the cypress chip totally. For reasons not fully understood jet it is necessary to reset the kernel driver twice before it can finally be opened for reading.

void ccu_reset_warning  ) 
 

resets the CCUs warning flag.

Returns:
void This function resets the CCUs warning flag.

int ccu_send_byte int  byte  ) 
 

sends a single byte to the CCD controller.

Parameters:
byte to be send
Returns:
error code
This function sends a single byte to the CCD controller.

int ccu_send_command char *  cmd  ) 
 

sends a command to the CCD controller.

Parameters:
cmd command to be send
Returns:
error code
This function sends a command to the CCD controller. The commands H 10, H 11 and H 12 are blocked.

int ccu_send_ending_command char *  command,
char *  description,
int  timeout
 

sends a command to the CCU and waits for the corresponding start and end messages.

Parameters:
command the command string to be send to CCU
description a string to be read by a human, describing the command.
timeout timeout in seconds
Returns:
integer an error code
This function sends a command to the CCU and waits for the corresponding start and end messages. If something goes wrong the command is retryed up to three times. An appropriate error/success code is returned.

int ccu_send_queue  ) 
 

send a queue to the CCU.

Returns:
integer error/success code
This function sends the queue to the CCU.

int ccu_send_simple_command char *  command,
char *  description,
int  timeout
 

sends a command to the CCU and waits for the corresponding start message.

Parameters:
command the command string to be send to CCU
description a string to be read by a human, describing the command.
timeout timeout in seconds
Returns:
integer an error code
This function sends a command to the CCU and waits for the corresponding start message. An appropriate error/success code is returned.

void ccu_ser_in const char *  str  ) 
 

called whenever something is received from the CCU

Parameters:
str the string received from the CCU
Returns:
void
This function is called whenever something is received from the CCU.

void ccu_ser_out const char *  str  ) 
 

called whenever something is sent to the CCU

Parameters:
str the string sent to the CCU
Returns:
void
This function is called whenever something is sent to the CCU.

int ccu_set_capacity int  capacity  ) 
 

sets the capacity of the integration capacitor.

Parameters:
capacity the capacity to be set
Returns:
integer an error code
This function sets the capacity of the integration capacitor. The charge collected on the CCD is converted into a voltage which is integrated using an operational amplifier and a capacitor. The slope of this intgration can be set by changing its capacity.

void ccu_set_com_problem void   ) 
 

sets the CCUs communication problem flag.

Returns:
void This function sets the CCUs communication problem flag.

int ccu_set_gain int  gain  ) 
 

sets the gain.

Parameters:
gain the gain to be set
Returns:
integer an error code
This function sets the gain to the value given by the parameter.

void ccu_set_progress char *  msg,
float  f
 

sets the progress struct of ccu.c.

Parameters:
msg a progress message.
f a number between 0 and 1 descibing how much progress has allready been made
Returns:
void This function sets the progress struct of the CCU. The abstract function ui_ccu_progress_changed is called in order to inform the ui about this change.

void ccu_set_status struct ccu_status_struct  input  ) 
 

sets the status of the CCU.

Parameters:
input a ccu_status_struct representing the status to be set.
Returns:
void This function sets the status of the CCU.

void ccu_set_status_async struct ccu_status_struct  input  ) 
 

sets the status of the CCU (for internal use by ccu.c only).

Parameters:
input a ccu_status_struct representing the status to be set.
Returns:
void This function sets the status of the ccu without repecting ccu_status_sem. This function for internal use by ccu.c only. To set the ccu status use ccu_set_status.

int ccu_shutter_close  ) 
 

closes the shutter.

Returns:
integer an error code
This function closes the shutter.

int ccu_shutter_open  ) 
 

opens the shutter.

Returns:
integer an error code
This function opens the shutter.

int ccu_simulate_and_dont_check_sequence_context  ) 
 

loads the sequence list from the CCU, and compares it with data store in the .SQ file.

Returns:
integer an error code
This function loads the sequence list from the CCU, and compares it with data store in the .SQ file. Anappropriate error/sucess code is returned.

void ccu_simulate_image  ) 
 

Fills the image buffer with some pseudoastronimical data.

Parameters:
bias the bias value (the mean value of the image).
the maximum value of the noise.
image the image buffer, must be 16bit*xsize*ysize
Returns:
void This function fills the image buffer with some pseudoastronimical data.

int ccu_simulate_sequence_context void   ) 
 

generates a simulated sequence list.

Returns:
integer an error code
This function generates a simulated sequence list.

int ccu_simulate_version_number void   ) 
 

gernerates a simulated version number.

Returns:
integer an error code
This function gernerates a simulated version number.

int ccu_single_dummy_read  ) 
 

runs a single dummy read.

Returns:
integer an error code
This function runs a single dummy read. All charge is removed from the chip.

void ccu_start_database_dowload char *  str  ) 
 

starts a thread that will download the database into the CCU

Parameters:
str the filename of the database to be downloaded without ".DB"
Returns:
void
This function starts a thread that will download the database into the CCU. For example if you would like to donwload "/user/classic.DB" you have to pass the string "/user/classic"

void ccu_start_database_dowload_basename char *  str  ) 
 

starts a thread that will download the database into the CCU

Parameters:
str the basename of the database to be downloaded.
Returns:
void
This function starts a thread that will download the database into the CCU. For example if you would like to donwload "/user/classic.DB" you have to pass the string "classic". Note that the database must be in the directory given by ccu_database_dir

int ccu_start_queue  ) 
 

starts a queue in the ccu.

Returns:
integer an error code
This function starts a queue in the ccu. You have to do queue your command with ccu_queue_push_item. Than you can send them with ccu_send_queue. And finally you can start it using this function.

void ccu_start_zero_volt  ) 
 

starts a thread that will run the zero volt sequence in the CCU

Returns:
void
This function starts a thread that will run the zero volt sequence in the CCU.

char* ccu_status_message int  code  ) 
 

retruns a string corresponding to status code defined in ccu.h.

Parameters:
code the status code
Returns:
char* the message string (pango markup)
This function retruns a string corresponding to status code defined in ccu.h.

char* ccu_status_text int  code  ) 
 

retruns a string corresponding to status code defined in ccu.h.

Parameters:
code the status code
Returns:
char* the message string (lain text)
This function retruns a string corresponding to status code defined in ccu.h.

int ccu_test_avail void   ) 
 

tests whether the CCU is available and initalized it if possible.

Returns:
integer an error code
This function tests whether the CCU is available. If so it reads the sequence context stored in the CCU and compares it with the data stored in the current .SQ file. The bits break waraning comproblem are reset. An error/success code is returned.

int ccu_upload_database_file char *  filename  ) 
 

downloads a database into the CCU.

Parameters:
filename the name of the file containing the database
Returns:
integer error/success code
This function downloads a database into the CCU.

int ccu_wait_for_end_message int  timeout  ) 
 

waits for the CCU to send an end message.

Parameters:
timeout timeout in seconds
Returns:
integer an error code
This function waits until an endmessage has been received from the CCU or the timeout condition has been reached.

int ccu_zero_volt  ) 
 

starts the zero volt sequence on the CCU.

Returns:
integer an error code
This function runs the zero volt sequnce. It is needed during the chip removal/installation procedure.

int end_message_get_error_code const char *  endmsg  ) 
 

extracts the error code from an endmessage received from the CCU.

Parameters:
endmsg the endmessage revceived from the CCU
Returns:
integer (0 means: no error)
This function extracts the error code from an endmessage received from the CCU.

void makebias unsigned long  bias,
unsigned long  noise,
unsigned char *  image
 

Writes a simulated bias image to the image buffer.

Parameters:
bias the bias value (the mean value of the image).
the maximum value of the noise.
image the image buffer, must be 16bit*xsize*ysize
Returns:
void This function writes a simulated bias image to the image buffer. Some simple noise algerythm, NO GAUSIAN noise!

void makestar long  x,
long  y,
unsigned long  f,
int  boxsize,
double  sigma,
unsigned char *  image
 

Writes a simulated star to the image buffer.

Parameters:
x the x position
y the y position
f the value at the center of the peak
boxsize the size of a box. The gausian is only evaluated inside the box and assumed to be 0 outside
sigma the standard deviation of the gausian
image the image buffer, must be 16bit*xsize*ysize
Returns:
void This function writes a simulated star to the image buffer. A simple gausian peak.


Variable Documentation

int ccu_channels
 

the number of channels to be read out simutaneously

char ccu_ctrldir[1000]
 

the name of the directory for ccu control files received via network

struct ccu_database_struct ccu_database[100]
 

the CCU Database as read form the ".SQ" file

char ccu_database_dir[1000]
 

the name of the directory containing the .DB and .SQ files to be selected

char ccu_database_filename[1000]
 

the name of the ".DB" file containing the sequences

char ccu_dev[1000]
 

the name of the file representing the serial port the CCU is connected to

serdev* ccu_device
 

serial device

volatile int ccu_expect_break = 0
 

1 if the next "break condition" message from the ccu shall be ignored 0 otherwise

GList* ccu_queue_list = NULL
 

a list to store a ccu queue (for later transmission and execution)

sem_t ccu_queue_sem
 

a semaphore protecting ccu_queue_list

sem_t ccu_sem
 

a semaphore protecting any operation on the CCU

char ccu_sequence_context[100][1000]
 

the names of the sequences as read from the CCU

char ccu_sequence_context_full[100][1000]
 

the full description of the sequences as read from the CCU, via H 13

double ccu_shutter_offset
 

Correction for incorrect shutter open time exposuretime_send_to_controlller=exposuretime_set_by_user-ccu_shutter_offset

unsigned char* ccu_simulated_image = NULL
 

a buffer used to hold a simulated image if simulation mode is on

int ccu_simulation_mode = 0
 

if set to one the communication with the ccu's serial port will performed everyting will be simulated instead also the kernel driver will no be accessed some random data will be generated instead

unsigned long ccu_simulation_position
 

the position inside the simulated image

struct ccu_status_struct ccu_status
 

a struct representing the current status of the CCU

sem_t ccu_status_sem
 

a semaphore procteting ccu_status

int ccu_stty_baud
 

the baud rate of the serial (ttyS) port used by the CCU

char ccu_usbdev[1000]
 

the name of the file representing the usb device for fast data transfer form the CCU into the computer

FILE* ccu_usbdev_file = NULL
 

a file pointer for data acquistion via usb

int command_block = 1
 

if this is not 0, any command to be sent to the ccu will be blocked

char ui_ccu_sequence_context[100][1000]
 

the names of the sequences for display in a user interface


Generated on Fri Dec 16 22:23:36 2005 for gboccia by  doxygen 1.4.2