Commit c1e57800 authored by mfioren's avatar mfioren
Browse files

testDBESM file working

parent cfdcd821
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
           Recovery="false">

    <Autoload>
        <cdb:_ string="baci" />
        <cdb:e string="baci" />
    </Autoload>

    <LoggingConfig 
+1 −5
Original line number Diff line number Diff line
<?xml version='1.0' encoding='ISO-8859-1'?>

<SRTDBESM xmlns="urn:schemas-cosylab-com:SRT_DBESM:1.0" xmlns:baci="urn:schemas-cosylab-com:BACI:1.0" xmlns:cdb="urn:schemas-cosylab-com:CDB:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" DBESM_IPAddress="192.168.60.107" DBESM_Port="5002">
	<addr_1>15</addr_1>
	<addr_2>14</addr_2>
   <addr_3>13</addr_3>
	<addr_4>12</addr_4> 
<SRTDBESM xmlns="urn:schemas-cosylab-com:SRT_DBESM:1.0" xmlns:baci="urn:schemas-cosylab-com:BACI:1.0" xmlns:cdb="urn:schemas-cosylab-com:CDB:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" addr_1="15" addr_2="14" addr_3="13" addr_4="12" DBESM_IPAddress="192.168.60.107" DBESM_Port="5002" >
   	<regs_1 description="values of the 5 double port registers on board 1" />	
		<regs_2 description="values of the 5 double port registers on board 2" />
  		<regs_3 description="values of the 5 double port registers on board 3" />	
+4 −4
Original line number Diff line number Diff line
@@ -16,10 +16,6 @@
   <xs:complexContent>
    <xs:extension base="baci:CharacteristicComponent">
      <xs:sequence>
	    <xs:element name="addr_1" type="xs:short" />
	    <xs:element name="addr_2" type="xs:short" />
	    <xs:element name="addr_3" type="xs:short" />
	    <xs:element name="addr_4" type="xs:short" />
	    	 <xs:element name="regs_1" type="baci:ROuLongSeq" />
	   	 <xs:element name="regs_2" type="baci:ROuLongSeq" />
	   	 <xs:element name="regs_3" type="baci:ROuLongSeq" />
@@ -49,6 +45,10 @@
	   	 <xs:element name="temps_3" type="baci:ROdoubleSeq" />
	   	 <xs:element name="temps_4" type="baci:ROdoubleSeq" />
      </xs:sequence>
       <xs:element name="addr_1" type="xs:short" use="required"/>
	    <xs:element name="addr_2" type="xs:short" use="required"/>
	    <xs:element name="addr_3" type="xs:short" use="required"/>
	    <xs:element name="addr_4" type="xs:short" use="required"/>
      <xs:attribute name="DBESM_IPAddress" type="xs:string" use="required"/>
	  <xs:attribute name="DBESM_Port" type="xs:unsignedInt" use="required"/>
    </xs:extension>
+1 −0
Original line number Diff line number Diff line
"@(#) $Id$"
+140 −0
Original line number Diff line number Diff line
#ifndef COMMANDSOCKET_H_
#define COMMANDSOCKET_H_


#include <IRA>
#include <BackendsErrors.h>
#include <ComponentErrors.h>
#include "Configuration.h"
#include "DBESMprotocol.h"


/**
 * This class is inherited from the IRA::CSocket class. It takes charge of the management of the socket used to command the SRT ACU via the remote interface. 
  * if the remote side disconnects or a problem affects the comunication line, this class try to reconnect to the ACU until the communication is up again..
*/
class CCommandSocket: public IRA::CSocket
{
public:
	/**
	 * Constructor.
	*/
	CCommandSocket();
	/**
	 * Destructor
	*/
	virtual ~CCommandSocket();
	
	/**
     * This member function is used to enstablish and configure the communication channel to the ACU. 
	 * This must be the first call before using any other function of this class.
	 * @param config pointer to the component configuration data structure
	 * @param data pointer to the ACU data structure
	 * @throw ComponentErrors::SocketError
	 * 		  @arg \c IRALibraryResource>
	*/
	void init(CConfiguration *config) throw (ComponentErrors::SocketErrorExImpl);
	
	/**
	 * Called to close the socket and free everything.
	 */
	void cleanUp();
	
	
	/**
	 * Force the socket to connect to the ACU. If the operation fails an exception is thrown, if the operation could not succesfully complete immediately 
	 * the command line state is set to <i>ACU::ACU_CNTDING</i>. It must be called by an external watchdog in order to keep the connection enstablished.
	 * This is not synchronized because this method acts on the socket only by accessing the mutex for the <i>CCommonData</i> class as the background thread of this socket @sa <i>onconnect()</i> 
	 */
	void connectSocket() throw (ComponentErrors::SocketErrorExImpl);
	
		/**
	 * This function can be used to send a command to the ACU.
	 * In case of problems it changes the component status accordingly. 
	 * @param cmd command to be sent
	 * @param len lenght in bytes of the command
	 * @throw TimeoutExImpl if the operation timeout before completing. 
	 * @thorw SocketErrorExImpl if the connection fails before completing. In that case the status is set to <i>Antenna::ACU_NOTCNTD</i>
	 */
	void sendCommand(std::string cmd,std::string outBuff, int all=0) throw (ComponentErrors::TimeoutExImpl,ComponentErrors::SocketErrorExImpl);

		
protected:
	/**
	 * Automatically called by the framework as a result of a connection request. See super-class for more details.
	 * @param  ErrorCode connection operation result, zero means operation is succesful.
	*/
	void onConnect(int ErrorCode);
	

private:
	
	template <class X> class autoArray {
	public:
		autoArray(): m_message(NULL) {}
		~autoArray() { if (m_message!=NULL) delete [] m_message; }
		operator X *&() { return m_message; }
		operator const X *() const { return m_message; }
		X operator[](WORD pos) const { return m_message[pos]; }
		X& operator[](WORD pos) { return m_message[pos]; }
	private:
		X* m_message;
	};

	CConfiguration * m_pConfiguration;
	IRA::CSecureArea<CDBESMCommand> * m_pData;
	
	CDBESMCommand m_dbesm_command;

	bool m_bTimedout;
	
	/**
	 * This mutex is used to sync external calls to the public methods of the class. The requirements is that just one call at the time must be served if the methos requires to
	 * send a message to the ACU. the reason for that is that we need to wait to known the result of the previous command to the ACU that comes form the status socket.
	 */
	ACE_Recursive_Thread_Mutex m_syncMutex;
	
	
	/**
    * This member function is called to send a buffer to the ACU.
	 * @param Msg pointer to the byte buffer that contains the message for the ACU
	 * @param Len length of the buffer
	 * @param error It will contain the error description in case the operation fails.
	 * @return SUCCESS if the buffer was sent correctly, WOULDBLOCK if the send would block, FAIL in case of error, the parameter error is set accordingly.
	*/
	OperationResult sendBuffer(std::string Msg,CError& error);
	
	/**
	 * This methos will cycle to check is the ACU responded to the last command sent. There three possible scenarios:
	 * @arg the ACU responded and the operation was succesfull
	 * @arg the ACU did not responded yet (in that case a timeout policy is implemented)
	 * @arg the ACU responded but the operation was not completed correctly.
	 * @param commandTime marks the epoch the command message was sent to the ACU, used to apply the timeout mechanism.
	 * @throw AntennaErrors::NakExImpl if an error was repoerted by the ACU
	 * @throw TimeoutExImpl if the ACU does not report back the answer within the expected time
	 */
	void waitAck(const ACS::Time& commandTime) throw (BackendsErrors::NakExImpl,ComponentErrors::TimeoutExImpl);
		
  int CCommandSocket::receiveBuffer(std::string Msg,CError& error, int all=0);
	
	/**
	 * This function checks if the connection is ok. 
	 * @return true if the connection is ok, false is the connection is not available.
	 */
	bool checkConnection();
	
	/**
	 * This method check if the Antenna is busy with long jobs and could not accept new commands.
	 * @return true if the antenna is busy
	 */
	bool checkIsBusy();
	
	void createSocket() throw (ComponentErrors::SocketErrorExImpl);
	
};





#endif /*COMMANDSOCKET_H_*/
Loading