Ejemplo n.º 1
0
/**********************************************************************************************
    errorType STLServerCommandSetNoiseAmplitudeLUTValue::Read(const wxString &m_device)
;will have already read the Socket command type and the command id
A polymorphic Read()
We take a sock as a parameter even though this code has access to the sock
This is because it is called from a base class and some of the polymorphic
classes derived from the base will not have a sock. This overrides that Read(sock)
***********************************************************************************************/
errorType STLServerCommandSetNoiseAmplitudeLUTValueXXX::Read(wxSocketBase &sock)
{
errorType rv;
wxInt16 index;
wxInt16 value;

    sock.SetFlags(wxSOCKET_WAITALL);
	rv=ReadFixedFields(sock);		//reads qflag, at_tick
	if(rv)
		return rv;


//-----Read the index, a wxUint16 in this instance ----

    sock.Read(&index,sizeof(index));   //Read the index
    if(sock.Error())
        return(errFail);
	AppendToReadFromSocketString(index);
//-----Read the value

    sock.Read(&value,sizeof(value));   //Read the value
    if(sock.Error())
        return(errFail);
	AppendToReadFromSocketString(value);

	SetValue(value);
	SetIndex(index);

    SetReadFlag(true);
    return errNone;
}
Ejemplo n.º 2
0
/*************************************************************************
    errorType STLServerCommandSetAmplitudeSPL::Read(wxSocketBase s&ock)
will have already read the Socket command type and the command id
now need to read the command specific data from the client.
Should only be called from a GSISocket server or derived class

Note that the corresponding ::Write function will be waiting for a
ServerReturnRecord. This function does not return this record as it
doesn't know if the task was completed without error.
The calling code will need to perform the required hardware (or other) tasks
and return the ServerReturnRecord indicating status of the function

*************************************************************************/
errorType STLServerCommandSetAmplitudeSPLXXX::Read(wxSocketBase & sock)
{
//read amplitude
	wxInt16 amplitude;
errorType rv;

	rv=ReadFixedFields(GetSock());		//reads qflag, at_tick
	sock.Read(&amplitude,sizeof(amplitude));
	SetReadFlag(true);
	AppendToReadFromSocketString(amplitude);
    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
		SetLastError(sockErr.GetErrorType());
        return(sockErr.GetErrorType());
	}
	SetAmplitude(amplitude);
	FillGSIRecord();				//perform LUT conversion
    return errNone;
}
Ejemplo n.º 3
0
/**********************************************************************************************
    errorType STLServerCommandReset::Read(wxSocketBase sock)
;will have already read the Socket command type and the command id
A polymorphic Read()
We take a sock as a parameter even though this code has access to the sock
This is because it is called from a base class and some of the polymorphic
classes derived from the base will not have a sock. This overrides that Read(sock)
***********************************************************************************************/
errorType STLServerCommandResetXXX::Read(wxSocketBase &sock)
{
errorType rv;

    sock.SetFlags(wxSOCKET_WAITALL);
	rv=ReadFixedFields(sock);		//reads qflag, at_tick
	if(rv)
		return rv;

    FillGSIRecord();
    SetReadFlag(true);
    return errNone;
}
Ejemplo n.º 4
0
/*!
	errorType STLServerCommandAcquireXXX::Read()

will have already read the Socket command type and the command id
now need to read the command specific data from the client.
Should only be called from a GSISocket server or derived class

Note that the corresponding ::Write function will be waiting for a
ServerReturnRecord. This function does not return this record as it
doesn't know if the task was completed without error.
The calling code will need to perform the required hardware (or other) tasks
and return the ServerReturnRecord indicating status of the function


Reads
wxInt16 queuedFlag
wxUint16 atTick
wxInt16 channel
*************************************************************************/
errorType STLServerCommandAcquireXXX::Read(wxSocketBase &sock)
{
//read amplitude
wxUint16 numDataPoints;
errorType rv;

	rv=ReadFixedFields(GetSock());		//reads qflag, at_tick
	sock.Read(&numDataPoints,sizeof(numDataPoints));
	SetReadFlag(true);
	AppendToReadFromSocketString(numDataPoints);

    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
		SetLastError(sockErr.GetErrorType());
        return(sockErr.GetErrorType());
	}
	SetNumDataPoints(numDataPoints);
	FillGSIRecord();
	AppendText("Read STLCommandAcquireXXX from client\n");
    return errNone;
}
Ejemplo n.º 5
0
/**********************************************************************************************
    errorType STLServerCommandSetFrequency::Read(const wxString &m_device)
;will have already read the Socket command type and the command id
A polymorphic Read()
We take a sock as a parameter even though this code has access to the sock
This is because it is called from a base class and some of the polymorphic
classes derived from the base will not have a sock. This overrides that Read(sock)
***********************************************************************************************/
errorType STLServerCommandSetFrequencyXXX::Read(wxSocketBase &sock)
{
errorType rv;
wxUint16 f;

    sock.SetFlags(wxSOCKET_WAITALL);
	rv=ReadFixedFields(sock);		//reads qflag, at_tick
	if(rv)
		return rv;


//-----Read the data, a wxUint16 in this instance ----

    sock.Read(&f,sizeof(f));   //Read the str
    if(sock.Error())
        return(errFail);
	AppendToReadFromSocketString(f);
	SetFrequency(f);
	FillGSIRecord();

    SetReadFlag(true);
    return errNone;
}
Ejemplo n.º 6
0
/*!
	errorType STLServerCommandSetChannelXXX::Read()

will have already read the Socket command type and the command id
now need to read the command specific data from the client.
Should only be called from a GSISocket server or derived class

Note that the corresponding ::Write function will be waiting for a
ServerReturnRecord. This function does not return this record as it
doesn't know if the task was completed without error.
The calling code will need to perform the required hardware (or other) tasks
and return the ServerReturnRecord indicating status of the function


Reads
wxInt16 queuedFlag
wxUint16 atTick
wxInt16 channel
*************************************************************************/
errorType STLServerCommandSetChannelXXX::Read(wxSocketBase &sock)
{
//read amplitude
wxInt16 chan;
errorType rv;

	rv=ReadFixedFields(sock);		//reads qflag, at_tick

	sock.Read(&chan,sizeof(chan));
	SetReadFlag(true);
	AppendToReadFromSocketString(chan);
    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
		SetLastError(sockErr.GetErrorType());
        return(sockErr.GetErrorType());
	}
	SetChannel(chan);
	FillGSIRecord();
	wxString s;
	s.Printf("Read SetChannel (%i) from client\n",chan);
	AppendText(s);
    return errNone;
}
Ejemplo n.º 7
0
errorType STLServerCommandCloseDeviceXXX::Read(wxSocketBase &sock)
{
GSIDevHandle hDev;
errorType rv;

    sock.SetFlags(wxSOCKET_WAITALL);
	rv=ReadFixedFields(sock);		//reads qflag, at_tick
	if(rv)
		return rv;

//reading a string, so first read its length, followed by the buffer
//----read the data length in bytes-----------------       //socket server will understand this format
    GetSock().Read(&hDev,sizeof(hDev));
    if(GetSock().Error())
	    return(errFail);
	AppendToReadFromSocketString(hDev);
	SetDeviceHandle(hDev);
    SetReadFlag(true);
    return errNone;
}
Ejemplo n.º 8
0
errorType StartleServer::ProcessUser1Record(wxSocketBase &sock) //override this function only
{
errorType rv=errNone;
wxString s;
//StartleRecord stl;
wxInt16 recType;
wxInt16 queuedFlag;
wxUint16 atTick;

// Can't use ReadMsg as this is a wx extension
//have already read the GSISocketUser1 id, which is why we are here
//1)Command
//2)flag

    TextCtrl()->AppendText("\n\n--------- New startle record ----------\n");


    //sock.SetFlags(wxSOCKET_WAITALL);
/*--------------Read the STL Type field----------------*/
    sock.Read(&recType,sizeof (recType));
    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
        return(sockErr.GetErrorCode());
	}

	s.Printf("Type=%i\n",recType);
    TextCtrl()->AppendText(s);

#if STL_DEBUG_USING_XXX //xxx functions read their own fixed length data
queuedFlag;
atTick;
#else

/*----------Read the STL QUEUED/IMMEDIATE Flag field--------------------*/
    sock.Read(&queuedFlag,sizeof (queuedFlag));
    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
        return(sockErr.GetErrorCode());
	}

	s.Printf("flag=%i: ",queuedFlag);
    TextCtrl()->AppendText(s);

    if( (queuedFlag != STL_QUEUED) && (queuedFlag != STL_IMMEDIATE) )
    {
        TextCtrl()->AppendText("\n--- Flag error! ---\n");
        rv=errParameter;
    }
	else
	{
		if(queuedFlag==	STL_QUEUED)
			TextCtrl()->AppendText("Queued\n");
		else
			TextCtrl()->AppendText("Immediate\n");
	}
/*-----------------------------------------------------*/

/*--------------Read the atTick field----------------*/
    sock.Read(&atTick,sizeof(atTick));
    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
        return(sockErr.GetErrorCode());
	}

	s.Printf("at tick=%i \n",atTick);
    TextCtrl()->AppendText(s);
//----Read all fixed record elements---------------------------------------------

    TextCtrl()->AppendText("\n---------- Processing StartleRecord ----------\n");

    if(recType !=STL_COMMAND_OPEN_DEVICE && ! IsOpen())
    {
        //device isn't open and we are trying to send a command
        //return an error to the client
        //STLSocketReturnData sr(GSIClient(),(enum GSISocketReturnValue) GSINoNode);      //instantiate

        GSISocketReturnData sr(sock,GSISocketReturnData::GSI_NO_DEVICE);      //instantiate
        s.Printf("\n------------------- Failed: %s -----------------\n\n",sr.GetErrorString());
        TextCtrl()->AppendText(s);
        return errFail;
    }
#endif

#warning ("Need to test sending commands with no Device Opened")
	try
	{

	/*------------perform any Type specific transforms, or operations ------*/
		switch (recType)
		{
//STL_COMMAND_RESET and STL_COMMAND_SET_AMPLITUDE use the current
//method of communication. Work is done by StartleFrame::xxx functions
		case STL_COMMAND_RESET:
			{
				STLServerCommandResetXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
		case STL_COMMAND_SET_AMPLITUDE_SPL:        //requires 1023=0, 0=1023.
			{
				STLServerCommandSetAmplitudeSPLXXX Cmd(sock,GetAmplitudeLUT());
				Cmd.SetStatusText(TextCtrl());

				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
//New commands tested through the socket up to here
		case STL_COMMAND_SET_FREQUENCY:
			{
				STLServerCommandSetFrequencyXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

			//rv=GetStartleFrame()->SetFrequency(sock,queuedFlag,atTick); //Hz is coming through the socket
			break;
		case STL_COMMAND_ACQUIRE:
			{
				STLServerCommandAcquireXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

		case STL_COMMAND_WAIT_FOR_COMPLETION:
			{
				STLServerCommandWaitForCompletionXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
		case STL_COMMAND_SET_CHANNEL:
			{
				STLServerCommandSetChannelXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());

				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

//New commands implemented up to here
		case STL_COMMAND_SET_NOISE_AMPLITUDE_SPL:
			{
				STLServerCommandSetNoiseAmplitudeSPLXXX Cmd(sock,GetNoiseAmplitudeLUT());
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
		case STL_COMMAND_EXECUTE:
			{
				STLServerCommandExecuteXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

		case STL_COMMAND_OPEN_DEVICE:  //param0=comport number 1-6
			{
				STLServerCommandOpenDeviceXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				//rv=GetGSIFrame().ProcessServerCommand(Cmd);
#warning ("Need to update state of GSIFrame/StartleFrame with device information")

#if STL_DEBUG_USING_XXX
				//will stop ProcessServerCommandRead()
				//from reading fixed length records
				//so must add them here. Though not reqd for Open()
#endif
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
			//rv=GetStartleFrame()->OpenDevice(sock); //inherited from GSIFrame
			break;
		case STL_COMMAND_CLOSE_DEVICE:  //param0=comport number 1-6
			{
				STLServerCommandCloseDeviceXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

			//rv=GetStartleFrame()->CloseDevice(sock);	//inherited from GSIFrame
			break;
		case STL_COMMAND_SET_AMPLITUDE_LUT_VALUE:           //set an element of the LUT p0=index, p1=value
			//rv=GetStartleFrame()->SetAmplitudeLUTValue(sock);
			break;
		case STL_COMMAND_SET_NOISE_AMPLITUDE_LUT_VALUE:           //set an element of the LUT p0=index, p1=value
			//rv=GetStartleFrame()->SetNoiseAmplitudeLUTValue(sock);
			break;
		default:
			//only instantiate the STLSocketReturnData here as it will write the code in it's dtor
			//STLSocketReturnData sr(*sock,GSISocketReturnData:: GSI_PARAM_ERROR,false);      //instantiate
			GSISocketReturnData sr(sock,GSISocketReturnData:: GSI_PARAM_ERROR,false);      //instantiate
			TextCtrl()->AppendText("\n-------- Bad Command ---------\n");
			rv=errParameter;        //this needs to return a SocketReturn
			break;
		}
	/*---------------------------------------------------------*/
		//TextCtrl()->AppendText(s);
		TextCtrl()->AppendText("\n--------Finished processing record---------\n");
		TextCtrl()->AppendText("\n-------------------------------------------\n");
	}
	catch(gsException &exc)
	{
        wxString s;
        s.Printf("Exception: %s. \nError code=%i %s",exc.GetUserString(),exc.GetErrorCode(),exc.GetString());
        TextCtrl()->AppendText(s);
		return exc.GetErrorCode();
	}
    return rv;
}
Ejemplo n.º 9
0
 static void ReadSocket(wxSocketBase& socket)
 {
     char ch;
     while ( socket.Read(&ch, 1).LastCount() == 1 )
         ;
 }
Ejemplo n.º 10
0
 // socket thread functions
 static void WriteSocket(wxSocketBase& socket)
 {
     socket.Write("hello, world!", 13);
 }