Pleora Technologies Inc. eBUS SDK v6.2.8.5877 API



PvSampleTransmitterConfig.h
1 // *****************************************************************************
2 //
3 // Copyright (c) 2012, Pleora Technologies Inc., All rights reserved.
4 //
5 // *****************************************************************************
6 
7 #ifndef __PVSAMPLETRANSMITTERCONFIG_H__
8 #define __PVSAMPLETRANSMITTERCONFIG_H__
9 
10 #include <PvSampleUtils.h>
11 #include <PvSystem.h>
12 #include <PvNetworkAdapter.h>
13 #include <PvPixelType.h>
14 
15 #include <map>
16 
17 
18 #define DEFAULT_NUMBER_OF_BUFFERS ( 48 )
19 #define DEFAULT_SOURCE_ADDRESS ( "" )
20 #define DEFAULT_DESTINATION_ADDRESS ( "239.192.1.1" )
21 #define DEFAULT_DESTINATION_PORT ( 1042 )
22 #define DEFAULT_SOURCE_PORT ( 0 )
23 #define DEFAULT_BUFFER_COUNT ( 4 )
24 #define DEFAULT_PACKET_SIZE ( 1440 )
25 #define DEFAULT_FPS ( 30 )
26 #define DEFAULT_SILENT ( false )
27 
28 
29 #ifndef PV_GENERATING_DOXYGEN_DOC
30 
31 
32 // Application config
33 class PvSampleTransmitterConfig
34 {
35 public:
36 
37  PvSampleTransmitterConfig()
38  {
39  SetDefaults();
40  }
41 
42  ~PvSampleTransmitterConfig()
43  {
44  }
45 
46  const char *GetSourceAddress() const { return mSourceAddress.c_str(); }
47  uint16_t GetSourcePort() const { return mSourcePort; }
48  const char *GetDestinationAddress() const { return mDestinationAddress.c_str(); }
49  uint16_t GetDestinationPort() const { return mDestinationPort; }
50  float GetFPS() const { return mFPS; }
51  bool GetSilent() const { return mSilent; }
52  uint32_t GetPacketSize() const { return mPacketSize; }
53  uint32_t GetBufferCount() const { return mBufferCount; }
54 
55  virtual void ParseCommandLine( int aCount, const char **aArgs )
56  {
57  if ( ParseOptionFlag( aCount, aArgs, "--help" ) )
58  {
59  PrintHelp();
60  exit( 0 );
61  }
62 
63  ParseOption<float>( aCount, aArgs, "--fps", mFPS );
64  ParseOption<uint32_t>( aCount, aArgs, "--packetsize", mPacketSize );
65  ParseOption<string>( aCount, aArgs, "--destinationaddress", mDestinationAddress );
66  ParseOption<uint16_t>( aCount, aArgs, "--destinationport", mDestinationPort );
67  ParseOption<string>( aCount, aArgs, "--sourceaddress", mSourceAddress );
68  ParseOption<uint16_t>( aCount, aArgs, "--sourceport", mSourcePort );
69  ParseOption<uint32_t>( aCount, aArgs, "--buffercount", mBufferCount );
70  ParseOptionFlag( aCount, aArgs, "--silent", &mSilent );
71  if ( mDestinationPort == 0 )
72  {
73  cout << "Please enter a destination port." << endl;
74  cin >> mDestinationPort;
75  }
76  }
77 
78  virtual void PrintHelp()
79  {
80  cout << "Optional command line arguments:" << endl << endl;
81 
82  cout << "--help " << endl << "Print this help message." << endl << endl;
83 
84  cout << "--packetsize=<maximimum size of streaming packets>" << endl;
85  cout << "Default: 1440 For best results, set \"Jumbo Frames\" property on your NIC and increase this value accordingly." << endl << endl;
86 
87  cout << "--destinationaddress=<destination address in the form 123.456.789.101>" << endl;
88  cout << "Default: " << DEFAULT_DESTINATION_ADDRESS << endl << endl;
89 
90  cout << "--destinationport=<destination port>" << endl;
91  cout << "Default: " << DEFAULT_DESTINATION_PORT << endl << endl;
92 
93  cout << "--sourceaddress=<source address in the form 123.456.789.101>" << endl;
94  cout << "Default: first valid address encountered while enumerating interfaces" << endl << endl;
95 
96  cout << "--sourceport=<source port>" << endl;
97  cout << "Default: " << DEFAULT_SOURCE_PORT << " - a port is automatically assigned when the socket is opened" << endl << endl;
98 
99  cout << "--buffercount=<number of transmit buffers to use>" << endl;
100  cout << "Default: " << DEFAULT_BUFFER_COUNT << " - increase this number when sending smaller images at high frame rates." << endl << endl;
101 
102  cout << "--silent" << endl;
103  cout << "Don't wait for a key press." << endl;
104  cout << "By default, the system waits for a key press before it begins transmitting. " << endl << endl;
105 
106  cout << "--fps=<frame per second>" << endl;
107  cout << "Default: " << DEFAULT_FPS << endl << endl;
108 
109  }
110 
111 private:
112 
113  void SetDefaults()
114  {
115  // Only used to enumerate network interfaces, no need to call Find
116  PvSystem lSystem;
117 
118  // Find default source address
119  bool lFound = false;
120  for ( uint32_t i = 0; i < lSystem.GetInterfaceCount() && !lFound; i++ )
121  {
122  const PvNetworkAdapter *lNetworkAdapter = dynamic_cast<const PvNetworkAdapter *>( lSystem.GetInterface( i ) );
123  if ( lNetworkAdapter == NULL )
124  {
125  continue;
126  }
127 
128  uint32_t lIPCount = lNetworkAdapter->GetIPAddressCount();
129  for ( uint32_t j = 0; j < lIPCount; j++ )
130  {
131  PvString lIP = lNetworkAdapter->GetIPAddress( j );
132  if ( strcmp( "0.0.0.0", lIP.GetAscii() ) != 0 )
133  {
134  mSourceAddress = lIP.GetAscii();
135  lFound = true;
136  }
137  }
138  }
139  if ( !lFound )
140  {
141  cout << "No valid interfaces found." << endl;
142  exit( 1 );
143  }
144 
145  // Set static defaults
146  mDestinationAddress = DEFAULT_DESTINATION_ADDRESS;
147  mDestinationPort = DEFAULT_DESTINATION_PORT;
148  mSourcePort = DEFAULT_SOURCE_PORT;
149  mPacketSize = DEFAULT_PACKET_SIZE;
150  mBufferCount = DEFAULT_BUFFER_COUNT;
151  mFPS = DEFAULT_FPS;
152  mSilent = DEFAULT_SILENT;
153  }
154 
155  string mSourceAddress;
156  uint16_t mSourcePort;
157 
158  string mDestinationAddress;
159  uint16_t mDestinationPort;
160 
161  float mFPS;
162  bool mSilent;
163 
164  uint32_t mPacketSize;
165  uint32_t mBufferCount;
166 
167 };
168 
169 
170 #endif // PV_GENERATING_DOXYGEN_DOC
171 
172 #endif
PvSystem::GetInterfaceCount
uint32_t GetInterfaceCount() const
Get the number of interfaces detected on the system.
Definition: PvSystem.cpp:248
PvNetworkAdapter::GetIPAddress
PvString GetIPAddress(uint32_t aIndex) const
Returns the IP address of the network adapter.
Definition: PvNetworkAdapter.cpp:152
PvString
String class.
Definition: PvString.h:21
PvSystem::GetInterface
const PvInterface * GetInterface(uint32_t aIndex) const
Get a PvInterface.
Definition: PvSystem.cpp:264
PvSystem
Find interfaces (network adapters or USB host controllers) and devices reachable from this PC.
Definition: PvSystem.h:27
PvString::GetAscii
const char * GetAscii() const
Get the string in ASCII format.
Definition: PvString.cpp:322
PvNetworkAdapter
Represents one Ethernet network adapter on a system (the PC)
Definition: PvNetworkAdapter.h:36
PvNetworkAdapter::GetIPAddressCount
uint32_t GetIPAddressCount() const
Returns one of the IP addresses for the network adapter, index-based.
Definition: PvNetworkAdapter.cpp:135
PvPixelType.h

Copyright (c) 2002-2021 Pleora Technologies Inc.
www.pleora.com