1 /**********************************************************************
2 The following UNLICENSE statement applies to this example.
4 This is free and unencumbered software released into the public domain.
6 Anyone is free to copy, modify, publish, use, compile, sell, or
7 distribute this software, either in source code form or as a compiled
8 binary, for any purpose, commercial or non-commercial, and by any
11 In jurisdictions that recognize copyright laws, the author or authors
12 of this software dedicate any and all copyright interest in the
13 software to the public domain. We make this dedication for the benefit
14 of the public at large and to the detriment of our heirs and
15 successors. We intend this dedication to be an overt act of
16 relinquishment in perpetuity of all present and future rights to this
17 software under copyright law.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 OTHER DEALINGS IN THE SOFTWARE.
27 For more information, please refer to <http://unlicense.org/>
28 *********************************************************************/
30 /*********************************************************************
31 For Further Information on KDIS:
32 http://p.sf.net/kdis/UserGuide
34 For a tutorial on sending the Entity State PDU see:
35 https://sourceforge.net/p/kdis/wiki/Sending_a_Entity_State_PDU_Tutorial/
37 This example shows the older method for sending a PDU, to see how the connection class can further help see the Environmental_Process_PDU example.
38 *********************************************************************/
41 #include "KDIS/PDU/Entity_Info_Interaction/Entity_State_PDU.h"
42 #include "KDIS/Network/Connection.h" // A cross platform connection class.
44 // Lets declare all namespaces to keep the code small.
47 using namespace DATA_TYPE
;
49 using namespace ENUMS
;
50 using namespace UTILS
;
51 using namespace NETWORK
;
57 // First create the PDU we are going to send, for this example I will use a
58 // Entity_State_PDU, When this PDU is sent most DIS applications should then show a new entity
59 EntityIdentifier
EntID( 1, 3001, 3 );
60 ForceID
EntForceID( Friendly
);
61 EntityType
EntType( 3, 1, 225, 3, 0, 1, 0 ); // A Civilian male
62 Vector
EntityLinearVelocity( 0, 0, 0 );
64 // Convert local coordinate systems to DIS
65 KFLOAT64 Lat
= 40.664, Lon
= -122.63, Alt
= 615; // West coast of USA
66 KFLOAT64 GeoX
= 0.0, GeoY
= 0.0, GeoZ
= 0.0;
67 KFLOAT64 Heading
= 0.0, Pitch
= 0.0, Roll
= 0.0;
68 KFLOAT64 Psi
= 0.0, Theta
= 0.0, Phi
= 0.0;
69 KDIS::UTILS::GeodeticToGeocentric( Lat
, Lon
, Alt
, GeoX
, GeoY
, GeoZ
, WGS_1984
);
70 KDIS::UTILS::HeadingPitchRollToEuler( DegToRad( Heading
), DegToRad( Pitch
), DegToRad( Roll
), DegToRad( Lat
), DegToRad( Lon
), Psi
, Theta
, Phi
);
72 WorldCoordinates
EntityLocation( GeoX
, GeoY
, GeoZ
);
73 EulerAngles
EntityOrientation( Psi
, Theta
, Phi
);
74 EntityAppearance EntEA
;
75 DeadReckoningParameter
DRP( Static
, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
76 EntityMarking
EntMarking( ASCII
, "KARL", 4 );
77 EntityCapabilities
EntEC( false, false, false, false );
80 Entity_State_PDU
Entity( EntID
, EntForceID
, EntType
, EntType
, EntityLinearVelocity
, EntityLocation
,
81 EntityOrientation
, EntEA
, DRP
, EntMarking
, EntEC
);
83 // Set the PDU Header values
84 Entity
.SetExerciseID( 1 );
86 // Set the time stamp to automatically calculate each time encode is called.
87 Entity
.SetTimeStamp( TimeStamp( RelativeTime
, 0, true ) );
89 // Note: This address will probably be different for your network.
90 Connection
myConnection( "192.168.0.255" );
92 // Encode the PDU contents into network data
94 Entity
.Encode( stream
);
98 // Send the data on the network.
99 myConnection
.Send( stream
.GetBufferPtr(), stream
.GetBufferSize() );
100 cout
<< "Sent the PDU" << endl
;
103 catch( exception
& e
)
105 cout
<< e
.what() << endl
;