fixed bug in ulsch_scheduler
ue runs again on exmimo2 (but does not connect yet) added openair0_reconfig function in exmimo2 library added sensing thread for SPECTRA in lte-softmodem (protected by #ifdef SPECTRA) added Rohde and Schwarz client git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5780 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
#include <iostream>
|
||||
#include "TcpClient.h"
|
||||
|
||||
void printUsage()
|
||||
{
|
||||
cout<<"usage: EthernetRawCommand <server-ip> [scpi-command]"<<endl;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int errorCode = 0; //no error
|
||||
|
||||
bool useSingleCommand = false;
|
||||
string singleCommand = "";
|
||||
string hostname = "";
|
||||
int port = 5025;
|
||||
|
||||
string input = "";
|
||||
TcpClient client;
|
||||
|
||||
|
||||
switch( argc )
|
||||
{
|
||||
case 3:
|
||||
useSingleCommand = true;
|
||||
singleCommand = argv[2];
|
||||
case 2:
|
||||
hostname = argv[1];
|
||||
break;
|
||||
default:
|
||||
printUsage();
|
||||
return(-1);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
client.connectToServer( hostname, port );
|
||||
|
||||
bool terminate = false;
|
||||
|
||||
while( !terminate )
|
||||
{
|
||||
char buffer[1024];
|
||||
|
||||
if( useSingleCommand )
|
||||
{
|
||||
input = singleCommand; //send string
|
||||
}
|
||||
else
|
||||
{
|
||||
cin.getline( buffer, 1024 );
|
||||
input = buffer;
|
||||
|
||||
if( input == "end" )
|
||||
{
|
||||
terminate = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( !terminate)
|
||||
{
|
||||
client.transmit( input ); //send string
|
||||
|
||||
int qPos = input.find( "?", 0 );
|
||||
//receive string only when needed
|
||||
if( qPos > 0 )
|
||||
{
|
||||
string rcStr = "";
|
||||
client.receive( rcStr );
|
||||
cout << rcStr << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if( useSingleCommand )
|
||||
{
|
||||
terminate = true;
|
||||
}
|
||||
}
|
||||
|
||||
}catch( const string errorString )
|
||||
{
|
||||
cout<<errorString<<endl;
|
||||
}
|
||||
|
||||
client.disconnect( );
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
all:
|
||||
g++ TcpClient.cpp EthernetRawCommand.cpp -o EthernetRawCommand.out
|
||||
@@ -0,0 +1,146 @@
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "TcpClient.h"
|
||||
|
||||
|
||||
TcpClient::TcpClient()
|
||||
: currentHostName( "" )
|
||||
, currentPort( 0 )
|
||||
, currentSocketDescr( 0 )
|
||||
, serverAddress ( )
|
||||
, currentHostInfo( NULL )
|
||||
, clientIsConnected( false )
|
||||
, receiveBufferSize( 1024 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TcpClient::~TcpClient()
|
||||
{
|
||||
currentHostInfo = NULL;
|
||||
}
|
||||
|
||||
|
||||
void TcpClient::connectToServer( string &hostname, int port )
|
||||
{
|
||||
currentHostInfo = gethostbyname( hostname.c_str( ) );
|
||||
|
||||
if( currentHostInfo == NULL )
|
||||
{
|
||||
currentHostName = "";
|
||||
currentPort = 0;
|
||||
currentHostInfo = NULL;
|
||||
clientIsConnected = false;
|
||||
printf("error connecting host\n" );
|
||||
}
|
||||
|
||||
currentHostName = hostname;
|
||||
currentPort = port;
|
||||
|
||||
currentSocketDescr = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if( currentSocketDescr == 0 )
|
||||
{
|
||||
currentHostName = "";
|
||||
currentPort = 0;
|
||||
currentHostInfo = NULL;
|
||||
clientIsConnected = false;
|
||||
printf("can't create socket\n" );
|
||||
}
|
||||
|
||||
serverAddress.sin_family = currentHostInfo->h_addrtype;
|
||||
serverAddress.sin_port = htons( currentPort );
|
||||
|
||||
memcpy( (char *) &serverAddress.sin_addr.s_addr, currentHostInfo->h_addr_list[0], currentHostInfo->h_length );
|
||||
|
||||
if( connect( currentSocketDescr, ( struct sockaddr *) &serverAddress, sizeof( serverAddress ) ) < 0 )
|
||||
{
|
||||
throw string("can't connect server\n" );
|
||||
}
|
||||
|
||||
clientIsConnected = true;
|
||||
}
|
||||
|
||||
|
||||
void TcpClient::disconnect( )
|
||||
{
|
||||
if( clientIsConnected )
|
||||
{
|
||||
close( currentSocketDescr );
|
||||
}
|
||||
|
||||
currentSocketDescr = 0;
|
||||
currentHostName = "";
|
||||
currentPort = 0;
|
||||
currentHostInfo = NULL;
|
||||
clientIsConnected = false;
|
||||
}
|
||||
|
||||
|
||||
void TcpClient::transmit( string &txString )
|
||||
{
|
||||
if( !clientIsConnected )
|
||||
{
|
||||
throw string("connection must be established before any data can be sent\n");
|
||||
}
|
||||
|
||||
char * transmitBuffer = new char[txString.length() +1];
|
||||
|
||||
|
||||
memcpy( transmitBuffer, txString.c_str(), txString.length() );
|
||||
transmitBuffer[txString.length()] = '\n'; //newline is needed!
|
||||
|
||||
if( send( currentSocketDescr, transmitBuffer, txString.length() + 1, 0 ) < 0 )
|
||||
{
|
||||
throw string("can't transmit data\n");
|
||||
}
|
||||
|
||||
delete [] transmitBuffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TcpClient::receive( string &rxString )
|
||||
{
|
||||
if( !clientIsConnected )
|
||||
{
|
||||
throw string("connection must be established before any data can be received\n");
|
||||
}
|
||||
|
||||
char * receiveBuffer = new char[receiveBufferSize];
|
||||
|
||||
memset( receiveBuffer, 0, receiveBufferSize );
|
||||
|
||||
bool receiving = true;
|
||||
while( receiving )
|
||||
{
|
||||
int receivedByteCount = recv( currentSocketDescr, receiveBuffer, receiveBufferSize, 0 );
|
||||
if( receivedByteCount < 0 )
|
||||
{
|
||||
throw string("error while receiving data\n");
|
||||
}
|
||||
|
||||
rxString += string( receiveBuffer );
|
||||
|
||||
receiving = ( receivedByteCount == receiveBufferSize );
|
||||
}
|
||||
delete [] receiveBuffer;
|
||||
}
|
||||
|
||||
|
||||
string TcpClient::getCurrentHostName( ) const
|
||||
{
|
||||
return currentHostName;
|
||||
}
|
||||
|
||||
|
||||
int TcpClient::getCurrentPort( ) const
|
||||
{
|
||||
return currentPort;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <string>
|
||||
|
||||
//defines structs for socket handling
|
||||
#include <netinet/in.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct sockaddr_in SockAddrStruct;
|
||||
typedef struct hostent HostInfoStruct;
|
||||
|
||||
class TcpClient
|
||||
{
|
||||
public:
|
||||
TcpClient();
|
||||
~TcpClient();
|
||||
|
||||
void connectToServer( string &hostname, int port );
|
||||
void disconnect( );
|
||||
void transmit( string &txString );
|
||||
void receive( string &rxString );
|
||||
|
||||
string getCurrentHostName( ) const;
|
||||
int getCurrentPort( ) const;
|
||||
|
||||
private:
|
||||
string currentHostName;
|
||||
int currentPort;
|
||||
int currentSocketDescr;
|
||||
SockAddrStruct serverAddress;
|
||||
HostInfoStruct * currentHostInfo;
|
||||
bool clientIsConnected;
|
||||
|
||||
int receiveBufferSize;
|
||||
};
|
||||
Reference in New Issue
Block a user