Remove old changelog
[KDIS.git] / examples / pdu / environmental_process_pdu / src / main.cpp
bloba2f757640fe2aedbd2d72cc1102e261d403f3395
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
9 means.
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 This example shows how to correctly use the Environmental_Process_PDU to create
35 a point feature in our simulation which will represent a cloud.
36 *********************************************************************/
38 #include <iostream>
40 #include "KDIS/Network/Connection.hpp"
41 #include "KDIS/PDU/Synthetic_Environment/Environmental_Process_PDU.hpp"
43 using namespace std;
44 using namespace KDIS;
45 using namespace DATA_TYPE;
46 using namespace PDU;
47 using namespace ENUMS;
48 using namespace UTILS;
49 using namespace NETWORK;
51 int main() {
52 try {
53 // First lets create the PDU object.
54 Environmental_Process_PDU ourEnvProcPDU;
56 ourEnvProcPDU.SetEnvironmentalProcessID(EntityIdentifier(
57 1, 123, 1)); // The ID of our application (SiteID, AppID, ObjectID)
58 ourEnvProcPDU.SetEnvironmentType(
59 EnvironmentType(Air, 0, 3, SmallSize, 0,
60 0)); // This value is taken from section 4 of the
61 // SISO-REF-010-2006. It represents a small cloud.
63 // Convert local coordinate systems to DIS
64 // 51.5° N 3.2° W. Cardiff, Wales.
65 // A cloud over Wales, what a surprise!
66 // Convert Degrees, Minutes, Seconds to decimal and then convert to
67 // geocentric.
68 KFLOAT64 Lat = KDIS::UTILS::DMSToDecimal(51.0, 5.0, 0.0);
69 KFLOAT64 Lon = KDIS::UTILS::DMSToDecimal(3.0, 2.0, 0.0);
70 KFLOAT64 Alt = KDIS::UTILS::FeetToMeters(3000.0);
71 KFLOAT64 GeoX = 0.0, GeoY = 0.0, GeoZ = 0.0;
72 KDIS::UTILS::GeodeticToGeocentric(Lat, Lon, Alt, GeoX, GeoY, GeoZ,
73 WGS_1984);
74 WorldCoordinates loc(GeoX, GeoY, GeoZ);
75 ourEnvProcPDU.SetEnvironmentStatusOn(true);
76 ourEnvProcPDU.SetSequenceNumber(EP_NO_SEQUENCE);
77 ourEnvProcPDU.AddEnvironmentRecord(
78 EnvironmentRecordPtr(new PointRecord1(0, loc)));
80 // Set the PDU Header values
81 ourEnvProcPDU.SetExerciseID(1);
83 // Set the time stamp to automatically calculate.
84 ourEnvProcPDU.SetTimeStamp(TimeStamp(RelativeTime, 0, true));
86 // Note this multi cast address will probably be different for your network.
87 Connection conn("192.168.3.255");
89 KOCTET cBuffer[MAX_PDU_SIZE]; // Somewhere to store the data we send.
91 while (true) {
92 // Keep sending the pdu.
93 conn.SendPDU((Header*)&ourEnvProcPDU);
95 } catch (exception& e) {
96 cout << e.what() << endl;
99 return 0;