stella.telescope
Class OpenPilarSocket

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by io.AbstractDriver
                  extended by stella.telescope.AbstractPilarDriver
                      extended by stella.telescope.OpenPilarSocket
All Implemented Interfaces:
Driver, Cloneable, EventListener, PilarDriver, TplListener, ParameterDepending, TelescopeDriver, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, Retrying

public class OpenPilarSocket
extends AbstractPilarDriver
implements TplListener, Retrying

Case implementation of the open TSI driver. Main difference to Pilar3Socket is the different error handling.


Nested Class Summary
private  class OpenPilarSocket.Monitor
          A class that takes a list of commands and checks incoming state changes if all of the monitored commands are completed/acknowledged.
static class OpenPilarSocket.PilarTest
          Test class.
private  class OpenPilarSocket.TplHandler
          A thread that permanently moitors the incoming stream for replies sent by the socket.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static long DEFACKNOWLEDGETIMEOUT
          Time out on acknowledge of command.
private static double DEFALTOFFHORIZONTAL
          The default offset on horizontal pointings.
private static double DEFAZOFFHORIZONTAL
          The default offset on horizontal pointings.
private static long DEFCLOSETIMEOUT
          Time out on listening-thread dead on close.
private static long DEFCOMPLETEDTIMEOUT
          Default time out on completing of a command.
private static long DEFCOVERTIMEOUT
          A general timeout for commands.
private static boolean DEFDEROTATOR
          Default no derotator present.
private static double DEFDEROTATORACCURACY
          The default offset setting accuracy.
private static int DEFDEROTATORAXIS
          Default derotator axis.
private static int DEFDEROTATORRETRY
          A retry maximum on derotator.
private static long DEFDEROTATORTIMEOUT
          A general timeout for commands.
private static double DEFFOCUSACCURACY
          The default focus setting accuracy.
private static int DEFFOCUSRETRY
          A retry maximum on focus.
private static long DEFFOCUSTIMEOUT
          A general timeout for commands.
private static int DEFINITPROBE
          A retry maximum on init.
private static int DEFINITRETRY
          A retry maximum on init.
private static long DEFINITTIMEOUT
          A general timeout for commands.
private static long DEFMOVEFAILTIME
          A general timeout for commands.
private static int DEFMOVERETRY
          A retry maximum on move.
private static long DEFMOVETIMEOUT
          A general timeout for commands.
private static int DEFPARKPROBE
          A retry maximum on park.
private static int DEFPARKRETRY
          A retry maximum on park.
private static long DEFPARKTIMEOUT
          A general timeout for commands.
private static long DEFQUERYSLEEP
          A general timeout for sleeps .
private static int DEFRESETRETRY
          A retry maximum on move.
private static long DEFRESETSLEEP
          A general timeout for resets .
private static double DEFSLOPPY
          The default sloppiness on horizontal pointings.
private static long DEFTCSTIMELAG
          During derotator offset measured to at least 6 seconds .
private static long DEFTIMEOUT
          Time out on simple command.
private static String DEFTPLASSWORD
          The default tpl password.
private static String DEFTPLHOST
          The default hostname the TPL server runs on.
private static String DEFTPLLOGIN
          The default tpl login name.
private static int DEFTPLPORT
          The default TPL server port.
private static int DEFTPLRETRIES
          The number of connection attempts until we give up.
private static long DEFTPLTIMEOUT
          The time-out between connection attempts.
private static boolean DEFUSEDEROTATOR
          Default we use the derotator, if present.
private  Map<String,Map<TsiError,Shelf<Date>>> errgroups
          The collection of errors on each group.
private  TplGet get
          TPL get instance.
private  BufferedReader in
          The input stream from the server as a buffered reader.
static String KEY_ACKNOWLEDGETIMEOUT
          Time out on acknowledge of command.
static String KEY_ALTOFFHORIZONTAL
          Some versions ignore the classic PM during horizontal move.
static String KEY_AUTHOK
          Points to the expected reply immediately after login.
static String KEY_AZOFFHORIZONTAL
          Some versions ignore the classic PM during horizontal move.
static String KEY_CLOSETIMEOUT
          Time out on listening-thread dead on close.
static String KEY_COMPLETEDTIMEOUT
          Time out on completing of a command.
static String KEY_COVERTIMEOUT
          A general timeout for commands.
static String KEY_DEROTATOR
          If true, the current port is equipped with a derotator.
static String KEY_DEROTATORACCURACY
          The maximum allowed deviation from the required derotator position.
static String KEY_DEROTATORAXIS
          The axis index with a derotator.
static String KEY_DEROTATORRETRY
          A retry maximum on derotator.
static String KEY_DEROTATORTIMEOUT
          A general timeout for commands.
static String KEY_FOCUSACCURACY
          The maximum allowed deviation from the required focus position.
static String KEY_FOCUSRETRY
          A retry maximum on focus.
static String KEY_FOCUSTIMEOUT
          A general timeout for commands.
static String KEY_INITPROBE
          A retry maximum on init.
static String KEY_INITRETRY
          A retry maximum on init.
static String KEY_INITTIMEOUT
          A general timeout for commands.
static String KEY_MOVEFAILTIME
          Even during track=1 retries, we are not allowed to pass this time.
static String KEY_MOVERETRY
          A retry maximum on move.
static String KEY_MOVETIMEOUT
          A general timeout for commands.
static String KEY_PARKPROBE
          A retry maximum on park.
static String KEY_PARKRETRY
          A retry maximum on park.
static String KEY_PARKTIMEOUT
          A general timeout for commands.
static String KEY_PREWAITMOVE
          This key adds an additional time-out between track=1 and move listen.
static String KEY_QUERYSLEEP
          A sleep time between variable queries.
static String KEY_RESETRETRY
          A retry maximum on park.
static String KEY_RESETSLEEP
          A sleep time between reset tries .
static String KEY_SLOPPY
          If > 0 , the alt/az position is not needed to accurately.
static String KEY_TCSTIMELAG
          This time-lag was first discovered during derotator offset.
static String KEY_TIMEOUT
          A general timeout for commands.
static String KEY_TPLHOST
          The host the TPL servers runs on.
static String KEY_TPLLOGIN
          The user name how the client identifies itself at the server.
static String KEY_TPLPASSWORD
          The password for identification.
static String KEY_TPLPORT
          The port the TPL servers listens to.
static String KEY_TPLRETRIES
          The number of connection attempts until we give up.
static String KEY_TPLTIMEOUT
          The time-out between connection attempts.
static String KEY_USEDEROTATOR
          If true and above true, we steer the derotator on move, if present.
private  Date lastcleanse
          Last date of a cleansing event.
private  Thread listen
          The thread watching the input line for incoming replies.
private  Collection<OpenPilarSocket.Monitor> monitors
          The collection of monitors.
private  BufferedWriter out
          The output stream to the server as a buffered writer.
private  Map<Integer,TplCommand> sending
          All active commands, those sending and those not processd.
private  TplSet set
          TPL set instance.
private  double sumaltoff
          For relative offsets, this double holds the currently applied h-off.
private  double sumazoff
          For relative offsets, this double holds the currently applied az-off.
private  Socket tpl
          The socket connection to the server.
 
Fields inherited from class stella.telescope.AbstractPilarDriver
DEFDRIVERNAME, KEY_AVERAGEPRESS, KEY_AVERAGETEMP, KEY_COMMANDID, KEY_PRESSURE, KEY_TEMPERATURE
 
Fields inherited from class io.AbstractDriver
KEY_DRIVERNAME
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
OpenPilarSocket(Map<String,String> prop)
          Constructs a new pilar3 driver.
 
Method Summary
private  boolean afterDisconnect()
          This method is called after a disconnect has been commenced or if the initial open fails.
private  boolean applyOffset(double dazenc, double dz)
          Applies an encoder difference in azimuth and zenith distance to the current azimuth and height.
private  boolean checkForFatalErrors(Collection<Map<TsiError,Shelf<Date>>> errs, Date cleared)
          We go through a list of errors and see if a fatal condition occured from the last error-clearing time provided.
private  boolean checkForTrivialErrors(Collection<Map<TsiError,Shelf<Date>>> errs, Date cleared)
          We go through a collection of all errors and check, if all of them are ignorable, INFOs or have a reset lag of zero.
 boolean close()
          Closes the connection by sending disconnect.
 boolean commenceAbort()
          Aborts all telescope operation.
 boolean commenceAbsoluteOffset(double azoff, double altoff)
          Applies an AZ-ALT offset to the current telescope position.
 boolean commenceAbsoluteOffset(double azoff, double altoff, double h)
          Applies an AZ-ALT offset to the current telescope position.
 boolean commenceClear()
          Try to clear the telescope errors.
 boolean commenceDerotator(double position)
          Sets the absolut position of the telescope derotator and disables tracking adjustment.
 boolean commenceDerotatorOffset(double position)
          Sets the offset of the telescope derotator and prepares the telescope for derotator tracking adjustment.
 boolean commenceFocus(double position)
          Sets the absolut position of the telescope primary focus (in mm).
 boolean commenceFocusOffset(double dpos)
          Sets the offset position of the telescope primary focus (in mm).
 boolean commenceGuiding(boolean start)
          Starts/stops telescope tracking and waits until pilar acknowledges the new state.
 boolean commenceInit()
          Initializes the telescope.
 boolean commenceMove(double radeg, double dedeg)
          Moves the telescope into a new RA-DE position.
 boolean commenceMove(double radeg, double dedeg, double off, boolean fol)
          Moves the telescope into a new RA-DE position.
 boolean commenceMove(double radeg, double dedeg, double off, boolean follow, boolean use)
          Moves the telescope into a new RA-DE position.
 boolean commenceMoveAzAlt(double azdeg, double altdeg)
          Moves the telescope into a new AZ-ALT position and stops tracking.
 boolean commencePark()
          Brings the telescope into its park position.
 boolean commenceRelativeOffset(double azoff, double altoff)
          Adds an AZ-ALT offset to the current telescope position.
 boolean commenceRelativeOffset(double azoff, double altoff, double h)
          Adds an AZ-ALT offset to the current telescope position.
 boolean commenceSetCovers(boolean close)
          Sets the position of the mirror covers.
private  TplAbort commenceTplAbort(boolean killit, int what)
          Sends a new TPL abort command with the default command completition timeout.
private  TplAbort commenceTplAbort(boolean killit, int what, long timeout)
          Sends a new TPL abort command.
private  TplGet commenceTplGet(String request)
          Sends a new get command with the default command completition timeout.
private  TplGet commenceTplGet(String request, long timeout)
          Sends a new get command.
private  TplSet commenceTplSet(String request)
          Sends a new set command with the default command completition timeout.
private  TplSet commenceTplSet(String request, long timeout)
          Sends a new set command.
 boolean commenceTracking(boolean start)
          Starts/stops telescope tracking.
 boolean commenceUsePort(int portnum)
          Optical port, specifies used derotator and filter and will also rotate M3 (if supported by the telescope hardware).
private  int countErrors(Collection<Map<TsiError,Shelf<Date>>> errs, Date cleared)
          We count the number of errors in all component groups.
private  Set<TsiError> errList(Date cleared)
          Returns the list of errors, ordered by severity, then component and name.
 void exit()
          Always closes the connection on exit.
 Collection<TsiError> getErrors()
          Updates the error list the error list.
private  double getHorizontalHeight()
          Returns the current height as returned by the telescope or throws an error.
 int getMaximumRetries()
          The maximum of retries feasible for this component.
 Object getValue(String name)
          Returns the value of a TSI variable as a java Object.
 void init()
          Initializes the driver by instantiating monitor tables.
 boolean isOpen()
          Returns true if the connection is open.
 boolean open()
          Opens a new connection to the TSI server (Pilar3).
 void processData(TplEvent reply)
          Processes a TplEvent.
 void rebuild()
          A way to rebuild the error base.
 long retryAfter(int attempt)
          The time-out between individual retries.
private  boolean send(TplCommand command)
          Sends the specified command to the server socket and puts the command to the sending lookup table.
 boolean setValue(String name, String to)
          Sets the value of a TSI varibale.
private  void stateChanged(TplCommand changed)
          An event signaled that the state on a command has changed.
private  int updatedErrorList()
          We retrieve the list of errors on the telescope and updated our internal error map with new errors encountered.
 boolean updateEnvironment()
          Writes the actual ambient temperature and pressure to Pilar3 to make use it in the refraction correction.
private  boolean waitCommandCompleted(TplCommand command, long timeout)
          Waits for a given TPL command gets completed.
 boolean waitForValue(String variable, String value, String notvalue, long timeout)
          Waits until (monitors) a TSI variable gets a specified value.
 
Methods inherited from class stella.telescope.AbstractPilarDriver
getNextId, getPressure, getTemperature, registerParameter
 
Methods inherited from class io.AbstractDriver
createDriver, equals, getDriverName, hashCode
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface io.Driver
getDriverName
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

KEY_TPLHOST

public static final String KEY_TPLHOST
The host the TPL servers runs on.

See Also:
Constant Field Values

KEY_TPLPORT

public static final String KEY_TPLPORT
The port the TPL servers listens to.

See Also:
Constant Field Values

KEY_TPLLOGIN

public static final String KEY_TPLLOGIN
The user name how the client identifies itself at the server.

See Also:
Constant Field Values

KEY_TPLPASSWORD

public static final String KEY_TPLPASSWORD
The password for identification.

See Also:
Constant Field Values

KEY_AUTHOK

public static final String KEY_AUTHOK
Points to the expected reply immediately after login. Can be null.

See Also:
Constant Field Values

KEY_TPLRETRIES

public static final String KEY_TPLRETRIES
The number of connection attempts until we give up.

See Also:
Constant Field Values

KEY_TPLTIMEOUT

public static final String KEY_TPLTIMEOUT
The time-out between connection attempts.

See Also:
Constant Field Values

KEY_TIMEOUT

public static final String KEY_TIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

KEY_ACKNOWLEDGETIMEOUT

public static final String KEY_ACKNOWLEDGETIMEOUT
Time out on acknowledge of command.

See Also:
Constant Field Values

KEY_COMPLETEDTIMEOUT

public static final String KEY_COMPLETEDTIMEOUT
Time out on completing of a command.

See Also:
Constant Field Values

KEY_CLOSETIMEOUT

public static final String KEY_CLOSETIMEOUT
Time out on listening-thread dead on close.

See Also:
Constant Field Values

KEY_FOCUSACCURACY

public static final String KEY_FOCUSACCURACY
The maximum allowed deviation from the required focus position.

See Also:
Constant Field Values

KEY_INITTIMEOUT

public static final String KEY_INITTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

KEY_PARKTIMEOUT

public static final String KEY_PARKTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

KEY_FOCUSTIMEOUT

public static final String KEY_FOCUSTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

KEY_PREWAITMOVE

public static final String KEY_PREWAITMOVE
This key adds an additional time-out between track=1 and move listen.

See Also:
Constant Field Values

KEY_MOVETIMEOUT

public static final String KEY_MOVETIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

KEY_MOVEFAILTIME

public static final String KEY_MOVEFAILTIME
Even during track=1 retries, we are not allowed to pass this time.

See Also:
Constant Field Values

KEY_COVERTIMEOUT

public static final String KEY_COVERTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

KEY_QUERYSLEEP

public static final String KEY_QUERYSLEEP
A sleep time between variable queries.

See Also:
Constant Field Values

KEY_TCSTIMELAG

public static final String KEY_TCSTIMELAG
This time-lag was first discovered during derotator offset.

See Also:
Constant Field Values

KEY_RESETSLEEP

public static final String KEY_RESETSLEEP
A sleep time between reset tries .

See Also:
Constant Field Values

KEY_FOCUSRETRY

public static final String KEY_FOCUSRETRY
A retry maximum on focus.

See Also:
Constant Field Values

KEY_MOVERETRY

public static final String KEY_MOVERETRY
A retry maximum on move.

See Also:
Constant Field Values

KEY_INITPROBE

public static final String KEY_INITPROBE
A retry maximum on init.

See Also:
Constant Field Values

KEY_PARKPROBE

public static final String KEY_PARKPROBE
A retry maximum on park.

See Also:
Constant Field Values

KEY_INITRETRY

public static final String KEY_INITRETRY
A retry maximum on init.

See Also:
Constant Field Values

KEY_PARKRETRY

public static final String KEY_PARKRETRY
A retry maximum on park.

See Also:
Constant Field Values

KEY_RESETRETRY

public static final String KEY_RESETRETRY
A retry maximum on park.

See Also:
Constant Field Values

KEY_SLOPPY

public static final String KEY_SLOPPY
If > 0 , the alt/az position is not needed to accurately.

See Also:
Constant Field Values

KEY_DEROTATOR

public static final String KEY_DEROTATOR
If true, the current port is equipped with a derotator.

See Also:
Constant Field Values

KEY_USEDEROTATOR

public static final String KEY_USEDEROTATOR
If true and above true, we steer the derotator on move, if present.

See Also:
Constant Field Values

KEY_DEROTATORACCURACY

public static final String KEY_DEROTATORACCURACY
The maximum allowed deviation from the required derotator position.

See Also:
Constant Field Values

KEY_DEROTATORAXIS

public static final String KEY_DEROTATORAXIS
The axis index with a derotator.

See Also:
Constant Field Values

KEY_DEROTATORTIMEOUT

public static final String KEY_DEROTATORTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

KEY_DEROTATORRETRY

public static final String KEY_DEROTATORRETRY
A retry maximum on derotator.

See Also:
Constant Field Values

KEY_AZOFFHORIZONTAL

public static final String KEY_AZOFFHORIZONTAL
Some versions ignore the classic PM during horizontal move.

See Also:
Constant Field Values

KEY_ALTOFFHORIZONTAL

public static final String KEY_ALTOFFHORIZONTAL
Some versions ignore the classic PM during horizontal move.

See Also:
Constant Field Values

DEFTPLHOST

private static final String DEFTPLHOST
The default hostname the TPL server runs on.

See Also:
Constant Field Values

DEFTPLPORT

private static final int DEFTPLPORT
The default TPL server port.

See Also:
Constant Field Values

DEFTPLLOGIN

private static final String DEFTPLLOGIN
The default tpl login name.

See Also:
Constant Field Values

DEFTPLASSWORD

private static final String DEFTPLASSWORD
The default tpl password.

See Also:
Constant Field Values

DEFTPLRETRIES

private static final int DEFTPLRETRIES
The number of connection attempts until we give up.

See Also:
Constant Field Values

DEFTPLTIMEOUT

private static final long DEFTPLTIMEOUT
The time-out between connection attempts.

See Also:
Constant Field Values

DEFTIMEOUT

private static final long DEFTIMEOUT
Time out on simple command.

See Also:
Constant Field Values

DEFACKNOWLEDGETIMEOUT

private static final long DEFACKNOWLEDGETIMEOUT
Time out on acknowledge of command.

See Also:
Constant Field Values

DEFCOMPLETEDTIMEOUT

private static final long DEFCOMPLETEDTIMEOUT
Default time out on completing of a command.

See Also:
Constant Field Values

DEFCLOSETIMEOUT

private static final long DEFCLOSETIMEOUT
Time out on listening-thread dead on close.

See Also:
Constant Field Values

DEFFOCUSACCURACY

private static final double DEFFOCUSACCURACY
The default focus setting accuracy.

See Also:
Constant Field Values

DEFINITTIMEOUT

private static final long DEFINITTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

DEFPARKTIMEOUT

private static final long DEFPARKTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

DEFFOCUSTIMEOUT

private static final long DEFFOCUSTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

DEFMOVETIMEOUT

private static final long DEFMOVETIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

DEFMOVEFAILTIME

private static final long DEFMOVEFAILTIME
A general timeout for commands.

See Also:
Constant Field Values

DEFCOVERTIMEOUT

private static final long DEFCOVERTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

DEFQUERYSLEEP

private static final long DEFQUERYSLEEP
A general timeout for sleeps .

See Also:
Constant Field Values

DEFTCSTIMELAG

private static final long DEFTCSTIMELAG
During derotator offset measured to at least 6 seconds .

See Also:
Constant Field Values

DEFRESETSLEEP

private static final long DEFRESETSLEEP
A general timeout for resets .

See Also:
Constant Field Values

DEFFOCUSRETRY

private static final int DEFFOCUSRETRY
A retry maximum on focus.

See Also:
Constant Field Values

DEFMOVERETRY

private static final int DEFMOVERETRY
A retry maximum on move.

See Also:
Constant Field Values

DEFINITPROBE

private static final int DEFINITPROBE
A retry maximum on init.

See Also:
Constant Field Values

DEFPARKPROBE

private static final int DEFPARKPROBE
A retry maximum on park.

See Also:
Constant Field Values

DEFINITRETRY

private static final int DEFINITRETRY
A retry maximum on init.

See Also:
Constant Field Values

DEFPARKRETRY

private static final int DEFPARKRETRY
A retry maximum on park.

See Also:
Constant Field Values

DEFRESETRETRY

private static final int DEFRESETRETRY
A retry maximum on move.

See Also:
Constant Field Values

DEFDEROTATOR

private static final boolean DEFDEROTATOR
Default no derotator present.

See Also:
Constant Field Values

DEFUSEDEROTATOR

private static final boolean DEFUSEDEROTATOR
Default we use the derotator, if present.

See Also:
Constant Field Values

DEFDEROTATORACCURACY

private static final double DEFDEROTATORACCURACY
The default offset setting accuracy.

See Also:
Constant Field Values

DEFDEROTATORTIMEOUT

private static final long DEFDEROTATORTIMEOUT
A general timeout for commands.

See Also:
Constant Field Values

DEFDEROTATORRETRY

private static final int DEFDEROTATORRETRY
A retry maximum on derotator.

See Also:
Constant Field Values

DEFDEROTATORAXIS

private static final int DEFDEROTATORAXIS
Default derotator axis.

See Also:
Constant Field Values

DEFAZOFFHORIZONTAL

private static final double DEFAZOFFHORIZONTAL
The default offset on horizontal pointings.

See Also:
Constant Field Values

DEFALTOFFHORIZONTAL

private static final double DEFALTOFFHORIZONTAL
The default offset on horizontal pointings.

See Also:
Constant Field Values

DEFSLOPPY

private static final double DEFSLOPPY
The default sloppiness on horizontal pointings.

See Also:
Constant Field Values

sumazoff

private double sumazoff
For relative offsets, this double holds the currently applied az-off.


sumaltoff

private double sumaltoff
For relative offsets, this double holds the currently applied h-off.


set

private TplSet set
TPL set instance.


get

private TplGet get
TPL get instance.


tpl

private Socket tpl
The socket connection to the server.


in

private BufferedReader in
The input stream from the server as a buffered reader.


out

private BufferedWriter out
The output stream to the server as a buffered writer.


monitors

private Collection<OpenPilarSocket.Monitor> monitors
The collection of monitors.


sending

private Map<Integer,TplCommand> sending
All active commands, those sending and those not processd.


lastcleanse

private Date lastcleanse
Last date of a cleansing event.


errgroups

private Map<String,Map<TsiError,Shelf<Date>>> errgroups
The collection of errors on each group.


listen

private Thread listen
The thread watching the input line for incoming replies.

Constructor Detail

OpenPilarSocket

public OpenPilarSocket(Map<String,String> prop)
Constructs a new pilar3 driver.

Method Detail

init

public void init()
Initializes the driver by instantiating monitor tables.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyResources

rebuild

public void rebuild()
             throws IOException,
                    TsiTimeoutException
A way to rebuild the error base.

Specified by:
rebuild in interface PilarDriver
Throws:
IOException
TsiTimeoutException

exit

public void exit()
Always closes the connection on exit.


open

public boolean open()
             throws IOException
Opens a new connection to the TSI server (Pilar3).

Specified by:
open in interface Driver
Parameters:
host - IP address of the TSI server.
port - communication port of the TSI server.
Returns:
if successfull.
Throws:
IOException

isOpen

public boolean isOpen()
Returns true if the connection is open.

Specified by:
isOpen in interface Driver
Returns:
True, if a previous initialization was successful

close

public boolean close()
              throws IOException
Closes the connection by sending disconnect.

Specified by:
close in interface Driver
Returns:
True if clean-up was successful.
Throws:
IOException

getMaximumRetries

public int getMaximumRetries()
Description copied from interface: Retrying
The maximum of retries feasible for this component.

Specified by:
getMaximumRetries in interface Retrying

retryAfter

public long retryAfter(int attempt)
Description copied from interface: Retrying
The time-out between individual retries.

Specified by:
retryAfter in interface Retrying
Parameters:
attempt - The number of failures still possible number.

commenceAbort

public boolean commenceAbort()
                      throws IOException,
                             TsiTimeoutException
Aborts all telescope operation. All running commands are stopped. Guiding and tracking is deactivated. NOT going to the park position.

Specified by:
commenceAbort in interface TelescopeDriver
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceClear

public boolean commenceClear()
                      throws IOException,
                             TsiTimeoutException
Try to clear the telescope errors. If the errors reported by the underlying softand/or hardware are not resolved, this will not be able to clear the errors. Only resolved errors will be removed from the error list.

Specified by:
commenceClear in interface PilarDriver
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceFocus

public boolean commenceFocus(double position)
                      throws IOException,
                             TsiTimeoutException
Sets the absolut position of the telescope primary focus (in mm). Method returns after new focus position has reached. TODO: check if this works. TG: Method has to be redone, this might work, but not a clear implementation

Specified by:
commenceFocus in interface TelescopeDriver
Parameters:
position - the new focusposition in mm.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceFocusOffset

public boolean commenceFocusOffset(double dpos)
                            throws IOException,
                                   TsiTimeoutException
Sets the offset position of the telescope primary focus (in mm). Method returns immediately. Offset are not cummulative. TG: Method has to be redone, this might work, but not a clear implementation from the Pilar side.

Specified by:
commenceFocusOffset in interface TelescopeDriver
Parameters:
dpos - The focus offset that should be applyied.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceDerotator

public boolean commenceDerotator(double position)
                          throws IOException,
                                 TsiTimeoutException
Sets the absolut position of the telescope derotator and disables tracking adjustment. This method should be mainly used on a non-tracking mode, e.g. if taking sky flats tracking should be stopped. The axis where the derotator is located is set in KEY_DEROTATORAXIS. This method sets the absolute position of the derotator as the syncmode 1 plus offset, compare commenceDerotatorOffset(double).

Specified by:
commenceDerotator in interface TelescopeDriver
Parameters:
position - the new derotator position in degrees.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceDerotatorOffset

public boolean commenceDerotatorOffset(double position)
                                throws IOException,
                                       TsiTimeoutException
Sets the offset of the telescope derotator and prepares the telescope for derotator tracking adjustment. This method should be mainly used on science observations. The method only prepares the offset, it does not wait for the offset position to be reached. The axis where the derotator is located is set in KEY_DEROTATORAXIS. This method sets the offset position of the derotator as the syncmode 3 plus offset, compare commenceDerotator(double).

Specified by:
commenceDerotatorOffset in interface TelescopeDriver
Parameters:
position - the new derotator position in degrees.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceInit

public boolean commenceInit()
                     throws IOException,
                            TsiTimeoutException
Initializes the telescope.

Specified by:
commenceInit in interface TelescopeDriver
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceMove

public boolean commenceMove(double radeg,
                            double dedeg)
                     throws IOException,
                            TsiTimeoutException
Moves the telescope into a new RA-DE position.

Specified by:
commenceMove in interface TelescopeDriver
Parameters:
ra - new right ascension to move in degree.
de - new declination to move in degree.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceMove

public boolean commenceMove(double radeg,
                            double dedeg,
                            double off,
                            boolean fol)
                     throws IOException,
                            TsiTimeoutException
Moves the telescope into a new RA-DE position.

Specified by:
commenceMove in interface TelescopeDriver
Parameters:
radeg - new right ascension to move in degree.
dedeg - new declination to move in degree.
off - The derotator offset in degress
fol - If true, the derotator follows the tracking.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceMove

public boolean commenceMove(double radeg,
                            double dedeg,
                            double off,
                            boolean follow,
                            boolean use)
                     throws IOException,
                            TsiTimeoutException
Moves the telescope into a new RA-DE position.

Parameters:
ra - new right ascension to move in degree.
de - new declination to move in degree.
off - The derotator offset in degress
follow - If true, the derotator follows the tracking.
use - If true, the derotator is used if present.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceMoveAzAlt

public boolean commenceMoveAzAlt(double azdeg,
                                 double altdeg)
                          throws IOException,
                                 TsiTimeoutException
Moves the telescope into a new AZ-ALT position and stops tracking.

Specified by:
commenceMoveAzAlt in interface TelescopeDriver
Parameters:
azdeg - Astronomical azimuth of desired telescope position.
altdeg - Height of target of desired telescope position
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

getHorizontalHeight

private double getHorizontalHeight()
                            throws IOException,
                                   TsiTimeoutException
Returns the current height as returned by the telescope or throws an error. Used for correcting offsets if the height is not provided.

Throws:
IOException
TsiTimeoutException

applyOffset

private boolean applyOffset(double dazenc,
                            double dz)
                     throws IOException,
                            TsiTimeoutException
Applies an encoder difference in azimuth and zenith distance to the current azimuth and height. The offset sums are not altered.

Throws:
IOException
TsiTimeoutException

commenceAbsoluteOffset

public boolean commenceAbsoluteOffset(double azoff,
                                      double altoff)
                               throws IOException,
                                      TsiTimeoutException
Applies an AZ-ALT offset to the current telescope position. Azimuthal component will be corrected with the actual telescope altitude (ie. az_corrected = azoff * cos (alt_current)). The offset sums are reset to the new values.

Specified by:
commenceAbsoluteOffset in interface TelescopeDriver
Parameters:
azoff - AZ offset in degrees (will be corrected with the actual telescope altitude).
altoff - ALT offset in degrees.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceAbsoluteOffset

public boolean commenceAbsoluteOffset(double azoff,
                                      double altoff,
                                      double h)
                               throws IOException,
                                      TsiTimeoutException
Applies an AZ-ALT offset to the current telescope position. Azimuthal component will be corrected with the actual telescope altitude (ie. az_corrected = azoff * cos (alt_current)). The offset sums are reset to the new values.

Specified by:
commenceAbsoluteOffset in interface TelescopeDriver
Parameters:
azoff - AZ offset in degrees (will be corrected with the actual telescope altitude).
altoff - ALT offset in degrees.
h - Height of telescope in degrees.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceRelativeOffset

public boolean commenceRelativeOffset(double azoff,
                                      double altoff)
                               throws IOException,
                                      TsiTimeoutException
Adds an AZ-ALT offset to the current telescope position. Azimuthal component will be corrected with the actual telescope altitude (ie. az_corrected = azoff * cos (alt_current)). The offset sums reflect the new total offsets.

Specified by:
commenceRelativeOffset in interface TelescopeDriver
Parameters:
azoff - AZ offset in degrees (will be corrected with the actual telescope altitude).
altoff - ALT offset in degrees.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceRelativeOffset

public boolean commenceRelativeOffset(double azoff,
                                      double altoff,
                                      double h)
                               throws IOException,
                                      TsiTimeoutException
Adds an AZ-ALT offset to the current telescope position. Azimuthal component will be corrected with the actual telescope altitude (ie. az_corrected = azoff * cos (alt_current)). The offset sums reflect the new total offsets.

Specified by:
commenceRelativeOffset in interface TelescopeDriver
Parameters:
azoff - AZ offset in degrees (will be corrected with the actual telescope altitude).
altoff - ALT offset in degrees.
h - Height of telescope.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commencePark

public boolean commencePark()
                     throws IOException,
                            TsiTimeoutException
Brings the telescope into its park position. Closes the mirror covers. Powers-down the telescope.

Specified by:
commencePark in interface TelescopeDriver
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceSetCovers

public boolean commenceSetCovers(boolean close)
                          throws IOException,
                                 TsiTimeoutException
Sets the position of the mirror covers.

Specified by:
commenceSetCovers in interface PilarDriver
Parameters:
close - true for closing, false for opening.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceTracking

public boolean commenceTracking(boolean start)
                         throws IOException,
                                TsiTimeoutException
Starts/stops telescope tracking.

Specified by:
commenceTracking in interface TelescopeDriver
Parameters:
start - boolean to start or stop telescope tracking.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceGuiding

public boolean commenceGuiding(boolean start)
                        throws IOException,
                               TsiTimeoutException
Starts/stops telescope tracking and waits until pilar acknowledges the new state.

Specified by:
commenceGuiding in interface TelescopeDriver
Parameters:
start - boolean to start or stop telescope tracking.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

commenceUsePort

public boolean commenceUsePort(int portnum)
                        throws IOException,
                               TsiTimeoutException
Optical port, specifies used derotator and filter and will also rotate M3 (if supported by the telescope hardware).

Specified by:
commenceUsePort in interface PilarDriver
Parameters:
portnumber - id of the optical port.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

getValue

public Object getValue(String name)
                throws IOException,
                       TsiTimeoutException
Returns the value of a TSI variable as a java Object.

Specified by:
getValue in interface PilarDriver
Parameters:
name - TSI variable to query.
Returns:
if successfull.
Throws:
IOException
TsiTimeoutException

setValue

public boolean setValue(String name,
                        String to)
                 throws IOException,
                        TsiTimeoutException
Sets the value of a TSI varibale. If strings are set, they must include the quotes!

Specified by:
setValue in interface PilarDriver
Parameters:
name - The TSI variable to set
to - The value the variable should be set to.
Throws:
IOException
TsiTimeoutException

waitForValue

public boolean waitForValue(String variable,
                            String value,
                            String notvalue,
                            long timeout)
                     throws TsiTimeoutException,
                            IOException
Waits until (monitors) a TSI variable gets a specified value. Maximum timeout must also be given.

Specified by:
waitForValue in interface PilarDriver
Parameters:
variable - TSI variable to be monitored.
value - the TSI variable must get.
notvalue - If the TSI variable get this value, return with false
timeout - maximum time (ms) until the variable must get the given value.
Returns:
true if the operation was successful.
Throws:
TsiTimeoutException - ;
IOException

updateEnvironment

public boolean updateEnvironment()
                          throws IOException,
                                 TsiTimeoutException
Writes the actual ambient temperature and pressure to Pilar3 to make use it in the refraction correction.

Returns:
true if successfull.
Throws:
IOException
TsiTimeoutException

getErrors

public Collection<TsiError> getErrors()
                               throws IOException,
                                      TsiTimeoutException
Updates the error list the error list.

Specified by:
getErrors in interface PilarDriver
Throws:
IOException
TsiTimeoutException

updatedErrorList

private int updatedErrorList()
                      throws TsiTimeoutException,
                             IOException
We retrieve the list of errors on the telescope and updated our internal error map with new errors encountered. The old format is like
 ERR_oil_Level_low [I] (CABINET),ERR_Focus_Referenze [W] (FOCUS)
 
which means the errors are simple co-aggulated into a coma-separated string. The new format, however, reads like:
 DRIVES|4:AZ|4:ERR_Brake_ClosedFromOther|azimut|4|AZ,SYSTEM|4:CABINET|4:ERR_USV_BatteryAlarm|USV\\| Alarm|4|CABINET
 
where errors are grouped together in DRIVES, SYSTEM, AUXILIARY, and UNKNOWN at the time of writing, but other groups may arise. directly following the group-ID is a pipe, with the ored level of all errors at the given group, see TsiError. After the first colon is a list of components that report error in the form AZ|4;FOKUS|8, i.e. a semi-colon separated list. This list is terminated with an other column, which is then followed by a semi-colon separated list of individual errors. On parsing, we split into different groups and ignore the component listing.

Returns:
Number of errors encountered.
Throws:
TsiTimeoutException
IOException

countErrors

private int countErrors(Collection<Map<TsiError,Shelf<Date>>> errs,
                        Date cleared)
We count the number of errors in all component groups.


checkForFatalErrors

private boolean checkForFatalErrors(Collection<Map<TsiError,Shelf<Date>>> errs,
                                    Date cleared)
We go through a list of errors and see if a fatal condition occured from the last error-clearing time provided. This is done in a multi-step approach along this line: If any of these conditions is met for any of the errors encountered, we raise a fatal condition flag.


checkForTrivialErrors

private boolean checkForTrivialErrors(Collection<Map<TsiError,Shelf<Date>>> errs,
                                      Date cleared)
We go through a collection of all errors and check, if all of them are ignorable, INFOs or have a reset lag of zero.


errList

private Set<TsiError> errList(Date cleared)
Returns the list of errors, ordered by severity, then component and name. Only currently active errors are returned


commenceTplGet

private TplGet commenceTplGet(String request,
                              long timeout)
                       throws TsiTimeoutException,
                              IOException
Sends a new get command. The command is provided with a new command id and put into the sending lookup table. For locking access, the command actually sent is returned.

Parameters:
request - TSI command string.
timeout - time out for the command completition.
Returns:
the original TPL command if command is completed or null.
Throws:
TsiTimeoutException
IOException

commenceTplGet

private TplGet commenceTplGet(String request)
                       throws TsiTimeoutException,
                              IOException
Sends a new get command with the default command completition timeout.

Parameters:
request - TSI command string.
Returns:
the original TPL command if command is completed or null.
Throws:
TsiTimeoutException
IOException

commenceTplSet

private TplSet commenceTplSet(String request,
                              long timeout)
                       throws TsiTimeoutException,
                              IOException
Sends a new set command. The command is provided with a new command id and put into the sending lookup table. For locking access, the command actually sent is returned.

Parameters:
request - TSI command string.
timeout - time out for the command completition.
Returns:
the original TPL command if command is completed or null.
Throws:
TsiTimeoutException
IOException

commenceTplSet

private TplSet commenceTplSet(String request)
                       throws TsiTimeoutException,
                              IOException
Sends a new set command with the default command completition timeout.

Parameters:
request - TSI command string.
Returns:
the original TPL command if command is completed or null.
Throws:
TsiTimeoutException
IOException

commenceTplAbort

private TplAbort commenceTplAbort(boolean killit,
                                  int what,
                                  long timeout)
                           throws TsiTimeoutException,
                                  IOException
Sends a new TPL abort command. The command is provided with a new command id and put into the sending lookup table. For locking access, the command actually sent is returned.

Parameters:
killit - if running command is to be killed (or aborted)
what - command ID of the command to be killed/aborted. If it is set to 0, then all the running commands are going to be killed/aborted.
Throws:
TsiTimeoutException
IOException

commenceTplAbort

private TplAbort commenceTplAbort(boolean killit,
                                  int what)
                           throws TsiTimeoutException,
                                  IOException
Sends a new TPL abort command with the default command completition timeout.

Throws:
TsiTimeoutException
IOException

waitCommandCompleted

private boolean waitCommandCompleted(TplCommand command,
                                     long timeout)
                              throws TsiTimeoutException
Waits for a given TPL command gets completed.

Parameters:
command - the TPL command to be waited.
timeout - timeout for the command complete.
Throws:
TsiTimeoutException

afterDisconnect

private boolean afterDisconnect()
                         throws IOException
This method is called after a disconnect has been commenced or if the initial open fails.

Throws:
IOException

send

private boolean send(TplCommand command)
              throws IOException
Sends the specified command to the server socket and puts the command to the sending lookup table.

Returns:
True if sending was successful.
Throws:
IOException

processData

public void processData(TplEvent reply)
Processes a TplEvent. If we have a command listening for the incoming event, we interpret it using the TplCommand.parseTplEvent(stella.net.tpl.TplEvent). If the acknowledge/complete state of the command changed, we also test if someone is waiting for notification.

Specified by:
processData in interface TplListener

stateChanged

private void stateChanged(TplCommand changed)
An event signaled that the state on a command has changed. We go through the list of all monitors and check the new state.