AGX Dynamics  2.37.2.0
CoSimulationServer.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
20 #include <agx/agx_vector_types.h>
21 
22 #include <agx/Thread.h>
23 
24 namespace agxSDK
25 {
26  class Simulation;
27 }
28 
29 namespace agxNet
30 {
31 
34  {
35  public:
36 
37  void run();
38 
40  void shutdown();
41 
42 
44  {
45  NO_SCRIPT=0,
46  PYTHON_SCRIPT=1,
47  };
48 
49  void setScriptMode(ScriptMode);
50  ScriptMode getScriptMode() const;
51 
56  CoSimulationServer( uint16_t port );
57 
62  void setEnableCompression( bool flag ) { m_useCompression = flag; }
63 
67  bool getEnableCompression( ) const { return m_useCompression; }
68 
69  const agx::String& getFilename();
70 
71  Header::Mode receiveInstructions( agxSDK::Simulation *simulation );
72  void setInstructionStatus( Header::Mode mode, const agx::String& message );
73 
74  bool applyInitInputs(agxSDK::Simulation *simulation );
75  bool obtainInitOutputs(agxSDK::Simulation* simulation );
76 
77  bool isShutdown();
78 
79  protected:
80 
81  virtual void waitForDataAndTransfer();
82  virtual bool waitForConnection();
83  void dropConnection(bool shouldShutdown) override;
84 
85  virtual ~CoSimulationServer();
86 
87  private:
88  void handlePreloadScript();
89  void handleSetTimeStep();
90  void handleStepInput();
91  void handleInitInput();
92  void handleNop();
93 
94  void sendReplyPacket();
95 
96  TCPServerSocketRef m_serverSocket;
97  uint16_t m_port;
98  bool m_useCompression;
99 
100  agx::Block m_hasInstructions;
101 
102  Header::Mode m_currentInstruction;
103  Header::Mode m_replyInstruction;
104  agx::String m_replyMessage;
105  agx::String m_filename;
106  double m_timeStep;
107 
108  agx::RealVector m_inputs;
109  agx::RealVector m_outputs;
110 
111  agx::RealVector m_initInputs;
112  agx::RealVector m_initOutputs;
113  agx::Timer stepTimer;
114  ScriptMode m_scriptMode;
115 
116  };
117 
118 }
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition: MacUtil.h:22
Basic wrapper class aroud std::thread.
Definition: Thread.h:82
void AGXPHYSICS_EXPORT shutdown()
Shutdown of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...
bool AGXPHYSICS_EXPORT isShutdown()
#define AGXPHYSICS_EXPORT
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:74
Base class for multi threaded transferring simulation between a server and a client using sockets...
Block synchronization primitive.
Base class providing referencing counted objects.
Definition: Referenced.h:119
Class for sending serialized agxSDK::Simulation over to a client.
void setEnableCompression(bool flag)
Enable/disable compression of transmitted data.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30