org.lsst.ccs.subsystems.fcs.drivers
Class CanOpenProxy

java.lang.Object
  extended by java.util.Observable
      extended by org.lsst.ccs.framework.Module
          extended by org.lsst.ccs.subsystems.fcs.drivers.CanOpenProxy
All Implemented Interfaces:
Serializable, Observer, org.lsst.ccs.framework.Configurable

public class CanOpenProxy
extends org.lsst.ccs.framework.Module

This Module starts a tcpip server, waits for the connection of a client whose name is the value of the field myClientName. This client is supposed to be a CanOpen C-wrapper. When the client starts it scans the can open network and send to the server some information on the can open nodes living on the network.

Author:
virieux
See Also:
Serialized Form

Nested Class Summary
 class CanOpenProxy.PDOStorage
          To store the values returned by the PDO.
 
Nested classes/interfaces inherited from class org.lsst.ccs.framework.Module
org.lsst.ccs.framework.Module.ValueUpdate
 
Nested classes/interfaces inherited from interface org.lsst.ccs.framework.Configurable
org.lsst.ccs.framework.Configurable.Environment
 
Field Summary
 PieceOfHardware[] hardwareList
           
 
Fields inherited from class org.lsst.ccs.framework.Module
environment, log, name, nObserverThreads, registry, tickMillis
 
Constructor Summary
CanOpenProxy()
           
 
Method Summary
 Object call(String clientName, String command)
          This methods send a command to the tcp client.
 boolean checkCanOpenNodeConfiguration(PieceOfHardware pieceOfHardware)
          When the hardware is booted and we have retrieve the information, we want to check for each piece of hardware that the node ID stored in the Configuration data base is the same than the node ID which is stored on the hardware with a switch : so we compare the serial number found on the can open bus for the piece of hardware node id with the serial number of the harwdare configuration.
 boolean checkCanOpenNodes()
           
 String configAsHeartbeatConsumer(int nodeID, int producerNodeID, int heartbeat_time)
          Configure a node as a hearbeat consumer.
 String configAsHeartbeatProducer(int nodeID, int heartbeat_time)
          Command to be used by the end users.
 String configAsHeartbeatProducer(String nodeID, String heartbeat_time)
          Configure a node as a hearbeat producer.
 int getBootedNodesNB()
           
 CanOpenNode getDetectedNodeForSerialNumber(String aSerialNB)
          This method returns the can open detected on the can open network for a piece of hardware identified by its serial number.
 int getExpectedNodesNB()
           
 long getHardwareBootTimeout()
           
 String getMyClientName()
           
 CanOpenProxy.PDOStorage getPdoStorage()
           
 int getPortNumber()
           
 void identifieHardware()
          Identification of the hardware : we want to retrieve the information stored in the hardware of the booted nodes and update the array of nodes with this information.
 String initializeHardware()
           
 void initModule()
           
 boolean isBooted(PieceOfHardware piece)
           
 boolean isBooted(String aNodeID)
           
 boolean isHardwareIdentified()
           
 boolean isHardwareInitialized()
           
 boolean isHardwareReady()
          This method returns true if : all the hardware items are booted and identified and the hardware have the node ID expected within the configuration and the hardware is initialized.
 boolean isNodeIdBootedAndOK(PieceOfHardware piece)
          Check if a piece of hardware is booted and if its can open node ID is correct.
 boolean isReady(String clientName)
           
 String listHardware()
           
 String listNodes()
          List the can open nodes which are in the nodes table.
 CanOpenProxy.PDOStorage readPDOs()
          This method sends a sync command to the can open stack and returns the reply.
 String readSDO(int nodeID, String index, String subindex)
          Command to be used by the end user at the console in engineering mode.
 String readSDO(String nodeID, String index, String subindex)
          Read a SDO with the given index and subindex RETURNS the value read in hexa (String) if no error occured or returns the error code if a error was detected.
 String sendCanOpen(String command)
          For engineering mode, this method can be used to send Can Open commands to the Wrapper.
 void setExpectedNodesNB(int nodeNB)
           
 void setHardwareBootTimeout(int hardwareBootTimeout)
           
 void setHardwareBootTimeout(long hardwareBootTimeout)
           
 void setMyClientName(String myClientName)
           
 void setPortNumber(int portNumber)
           
protected  void startTheadReader()
          Starts a thread which read on the tcp socket, waiting for messages coming from tcp proxy.
 void stop()
           
 void tick()
           
 String writeSDO(int nodeID, String index, String subindex, int size, int value)
          Command to be used by the end user at the console.
 String writeSDO(String nodeID, String index, String subindex, String size, String value)
          Write a SDO request and send it to the can open stack, then analyses the response or throws an exception if the request failed.
 
Methods inherited from class org.lsst.ccs.framework.Module
change, checkHardware, dropConfigurationContext, getCheckedValueFromConfiguration, getChildren, getContext, getModule, getName, getNObserverThreads, getObservables, getSubsystem, getTickMillis, init, listens, newConfigurationContext, notifyChange, notifyChangeWithoutPreliminaryChecks, processUpdate, publishData, publishData, publishData, publishData, register, register, sendToReply, sendToStatus, setBeanName, setContext, setEnvironment, setName, setNObserverThreads, setObservables, setStateModularSubsystem, setStateModularSubsystem, setTickMillis, shutdownCommand, shutdownNow, start, startTicking, update
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hardwareList

public PieceOfHardware[] hardwareList
Constructor Detail

CanOpenProxy

public CanOpenProxy()
Method Detail

getExpectedNodesNB

public int getExpectedNodesNB()
Returns:
the expectedNodesNB

setExpectedNodesNB

public void setExpectedNodesNB(int nodeNB)
Parameters:
expectedNodesNB - the expectedNodesNB to set

getHardwareBootTimeout

public long getHardwareBootTimeout()

setHardwareBootTimeout

public void setHardwareBootTimeout(long hardwareBootTimeout)

setHardwareBootTimeout

public void setHardwareBootTimeout(int hardwareBootTimeout)

getBootedNodesNB

public int getBootedNodesNB()
Returns:
the bootedNodesNB

getMyClientName

public String getMyClientName()
Returns:
the myClientName

setMyClientName

public void setMyClientName(String myClientName)
Parameters:
myClientName - the myClientName to set

getPdoStorage

public CanOpenProxy.PDOStorage getPdoStorage()

isHardwareIdentified

public boolean isHardwareIdentified()

isHardwareInitialized

public boolean isHardwareInitialized()

initModule

public void initModule()

tick

public void tick()
Overrides:
tick in class org.lsst.ccs.framework.Module

isBooted

public boolean isBooted(String aNodeID)

isBooted

public boolean isBooted(PieceOfHardware piece)

isNodeIdBootedAndOK

public boolean isNodeIdBootedAndOK(PieceOfHardware piece)
Check if a piece of hardware is booted and if its can open node ID is correct.


listNodes

public String listNodes()
List the can open nodes which are in the nodes table.

Returns:
the list of can open nodes and the information stored in this.nodes.

sendCanOpen

public String sendCanOpen(String command)
                   throws TimeoutException,
                          org.lsst.ccs.bus.BadCommandException
For engineering mode, this method can be used to send Can Open commands to the Wrapper. Test if the command is valid before sending it to the can open stack.

Parameters:
command - A Can Open command that the Wrapper should understand.
Returns:
the response from the Wrapper
Throws:
TimeoutException
org.lsst.ccs.bus.BadCommandException

writeSDO

public String writeSDO(String nodeID,
                       String index,
                       String subindex,
                       String size,
                       String value)
                throws SDORequestError
Write a SDO request and send it to the can open stack, then analyses the response or throws an exception if the request failed. The parameters are given in HEXA.

Parameters:
nodeID - FORMAT=HEXA
index - FORMAT=HEXA
subindex - FORMAT=HEXA
size - FORMAT=HEXA
value - FORMAT=HEXA
Returns:
"OK" if OK
Throws:
SDORequestError

writeSDO

public String writeSDO(int nodeID,
                       String index,
                       String subindex,
                       int size,
                       int value)
                throws SDORequestError,
                       org.lsst.ccs.bus.BadCommandException
Command to be used by the end user at the console. Write a SDO message and send it to the can open stack. The parameters are given in the following format:

Parameters:
nodeID - FORMAT=decimal
index - FORMAT=HEXA
subindex - FORMAT=HEXA
size - FORMAT=decimal
value - FORMAT=decimal
Returns:
Throws:
SDORequestError
org.lsst.ccs.bus.BadCommandException

readSDO

public String readSDO(String nodeID,
                      String index,
                      String subindex)
               throws SDORequestError
Read a SDO with the given index and subindex RETURNS the value read in hexa (String) if no error occured or returns the error code if a error was detected.

Throws:
SDORequestError

readSDO

public String readSDO(int nodeID,
                      String index,
                      String subindex)
               throws SDORequestError,
                      org.lsst.ccs.bus.BadCommandException
Command to be used by the end user at the console in engineering mode.

Parameters:
nodeID - FORMAT=decimal
index - FORMAT=hexa
subindex - FORMAT=hexa
Returns:
the value sent by the can open stack if the read SDO request succeded.
Throws:
SDORequestError
org.lsst.ccs.bus.BadCommandException

readPDOs

public CanOpenProxy.PDOStorage readPDOs()
                                 throws HardwareError,
                                        org.lsst.ccs.bus.BadCommandException
This method sends a sync command to the can open stack and returns the reply. example of sync reply we can receive : sync,23_1=25a7,23_2=113,23_3=10,23_4=109,23_5=108,23_6=104,23_7=101,23_8=112

Returns:
Throws:
HardwareError
org.lsst.ccs.bus.BadCommandException

identifieHardware

public void identifieHardware()
                       throws TimeoutException
Identification of the hardware : we want to retrieve the information stored in the hardware of the booted nodes and update the array of nodes with this information. The Can Open node ID is a main information to retrieve.

Throws:
TimeoutException

isHardwareReady

public boolean isHardwareReady()
This method returns true if : all the hardware items are booted and identified and the hardware have the node ID expected within the configuration and the hardware is initialized.


getDetectedNodeForSerialNumber

public CanOpenNode getDetectedNodeForSerialNumber(String aSerialNB)
This method returns the can open detected on the can open network for a piece of hardware identified by its serial number. It can return NULL if the Serial Number is not on the can open network.

Parameters:
serialNB -
Returns:

checkCanOpenNodes

public boolean checkCanOpenNodes()
                          throws org.lsst.ccs.bus.BadCommandException,
                                 ErrorInBootingHardwareProcess,
                                 HardwareConfigurationError,
                                 HardwareNotDetectedException
Throws:
org.lsst.ccs.bus.BadCommandException
ErrorInBootingHardwareProcess
HardwareConfigurationError
HardwareNotDetectedException

checkCanOpenNodeConfiguration

public boolean checkCanOpenNodeConfiguration(PieceOfHardware pieceOfHardware)
                                      throws org.lsst.ccs.bus.BadCommandException,
                                             HardwareConfigurationError,
                                             HardwareNotDetectedException
When the hardware is booted and we have retrieve the information, we want to check for each piece of hardware that the node ID stored in the Configuration data base is the same than the node ID which is stored on the hardware with a switch : so we compare the serial number found on the can open bus for the piece of hardware node id with the serial number of the harwdare configuration.

Returns:
Throws:
org.lsst.ccs.bus.BadCommandException
HardwareConfigurationError
HardwareNotDetectedException

listHardware

public String listHardware()

initializeHardware

public String initializeHardware()
                          throws org.lsst.ccs.bus.BadCommandException,
                                 Exception
Throws:
org.lsst.ccs.bus.BadCommandException
Exception

configAsHeartbeatProducer

public String configAsHeartbeatProducer(String nodeID,
                                        String heartbeat_time)
                                 throws SDORequestError,
                                        TimeoutException,
                                        org.lsst.ccs.bus.BadCommandException
Configure a node as a hearbeat producer. Every heartbeat_time milliseconds this node will produce a message like: 0x700+nodeID: 05 - 1340268404.980000

Parameters:
nodeID - node ID in hexa
heartbeat_time - FORMAT=hexa UNIT=milliseconds
Throws:
SDORequestError
TimeoutException
org.lsst.ccs.bus.BadCommandException

configAsHeartbeatProducer

public String configAsHeartbeatProducer(int nodeID,
                                        int heartbeat_time)
                                 throws SDORequestError,
                                        TimeoutException,
                                        org.lsst.ccs.bus.BadCommandException
Command to be used by the end users. Configure a node as a heartbeat producer. Parameters given in decimal format.

Parameters:
nodeID - FORMAT=decimal
heartbeat_time - FORMAT=decimal UNIT=milliseconds
Throws:
SDORequestError
TimeoutException
org.lsst.ccs.bus.BadCommandException

configAsHeartbeatConsumer

public String configAsHeartbeatConsumer(int nodeID,
                                        int producerNodeID,
                                        int heartbeat_time)
                                 throws SDORequestError,
                                        TimeoutException,
                                        org.lsst.ccs.bus.BadCommandException
Configure a node as a hearbeat consumer. Every heartbeat_time milliseconds this node will produce a message like: 0x700+nodeID: 05 - 1340268404.980000

Parameters:
nodeID - node ID in decimal
heartbeat_time - FORMAT=decimal UNIT=milliseconds
Throws:
SDORequestError
TimeoutException
org.lsst.ccs.bus.BadCommandException

getPortNumber

public int getPortNumber()

setPortNumber

public void setPortNumber(int portNumber)

startTheadReader

protected void startTheadReader()
Starts a thread which read on the tcp socket, waiting for messages coming from tcp proxy. If the message has a known token (already registred in commandDispenser) it is a response to a can open command that we had sent to the proxy. If the token of the message is null, that means that is's an unsynchronous message coming from the can open stack and transmitted directly from the tcp proxy. That can be : - a boot message : "boot,nodeID" - an emergency message : "emcy,80+NodeID"


stop

public void stop()

isReady

public boolean isReady(String clientName)

call

public Object call(String clientName,
                   String command)
            throws TimeoutException
This methods send a command to the tcp client. The command is a String and can be understood by the client. Example for a Can Open command : rsdo,1,1018,0 The command is stored in the command dispenser with a token and command corelation. When the response comes back from the proxy we can retrieve it from the dispenser with the call token.

Parameters:
clientName -
command -
Returns:
result of the call or null if the call failed
Throws:
TimeoutException


Copyright © 2013 LSST. All Rights Reserved.