930 SG_LOG(SG_IO, SG_ALERT,
"This shouldn't happen, but the channel "
931 "is already in use, ignoring");
935 if (_federation.empty()) {
936 SG_LOG(SG_IO, SG_ALERT,
"No federation to join given to "
941 if (_federate.empty()) {
942 SG_LOG(SG_IO, SG_ALERT,
"No federate name given to the HLA module");
946 if (!SGPath(_objectModelConfig).exists()) {
947 SGPath path(
globals->get_fg_root());
949 path.append(_objectModelConfig);
951 _objectModelConfig = path.str();
953 SG_LOG(SG_IO, SG_ALERT,
"Federate object model configuration \""
954 << _objectModelConfig <<
"\" does not exist.");
961 readXML(_objectModelConfig, configReader);
962 }
catch (
const sg_throwable& e) {
963 SG_LOG(SG_IO, SG_ALERT,
"Could not open HLA configuration file: "
967 SG_LOG(SG_IO, SG_ALERT,
"Could not open HLA configuration file");
973 if (objectModel.empty()) {
974 SG_LOG(SG_IO, SG_ALERT,
"No federate object model given to "
978 if (!SGPath(objectModel).exists()) {
979 SGPath path(SGPath(_objectModelConfig).dir());
980 path.append(objectModel);
982 objectModel = path.str();
984 SG_LOG(SG_IO, SG_ALERT,
"Federate object model file \""
985 << objectModel <<
"\" does not exist.");
993 _hlaFederate->setVersion(simgear::HLAFederate::RTI13);
996 _hlaFederate->setVersion(simgear::HLAFederate::RTI1516);
999 _hlaFederate->setVersion(simgear::HLAFederate::RTI1516E);
1003 _hlaFederate->setFederationExecutionName(_federation);
1004 _hlaFederate->setFederationObjectModel(objectModel);
1005 _hlaFederate->setFederateType(_federate);
1008 XMLConfigReader::ObjectClassConfigList::const_iterator
i;
1012 if (
i->_type !=
"Multiplayer") {
1013 SG_LOG(SG_IO, SG_ALERT,
"Ignoring unknown object class type \"" <<
i->_type <<
"\"!");
1018 _hlaFederate->_multiplayerObjectClassNames.push_back(
i->_name);
1023 if (!_hlaFederate->init()) {
1024 SG_LOG(SG_IO, SG_ALERT,
"Could not init the hla/rti connect.");
1036 if (
i->_type !=
"Multiplayer")
1040 SGSharedPtr<MultiplayerObjectClass> objectClass;
1043 std::string aircraftClassName =
i->_name;
1045 if (!objectClass.valid()) {
1046 SG_LOG(SG_IO, SG_ALERT,
"Could not find " << aircraftClassName <<
" object class!");
1050 SGSharedPtr<MultiplayerObjectClass> mpClassCallback = objectClass;
1052 if (
i->_positionConfig._type ==
"cartesian") {
1053 SGSharedPtr<sg::HLACartesianLocationFactory> locationFactory;
1054 locationFactory =
new sg::HLACartesianLocationFactory;
1055 XMLConfigReader::DataElementList::const_iterator j;
1056 for (j =
i->_positionConfig._dataElementList.begin();
1057 j !=
i->_positionConfig._dataElementList.end(); ++j) {
1059 if (j->_type ==
"position-x")
1060 locationFactory->setPositionIndex(0, objectClass->getDataElementIndex(j->_name));
1061 else if (j->_type ==
"position-y")
1062 locationFactory->setPositionIndex(1, objectClass->getDataElementIndex(j->_name));
1063 else if (j->_type ==
"position-z")
1064 locationFactory->setPositionIndex(2, objectClass->getDataElementIndex(j->_name));
1066 else if (j->_type ==
"orientation-sin-angle-axis-x")
1067 locationFactory->setOrientationIndex(0, objectClass->getDataElementIndex(j->_name));
1068 else if (j->_type ==
"orientation-sin-angle-axis-y")
1069 locationFactory->setOrientationIndex(1, objectClass->getDataElementIndex(j->_name));
1070 else if (j->_type ==
"orientation-sin-angle-axis-z")
1071 locationFactory->setOrientationIndex(2, objectClass->getDataElementIndex(j->_name));
1073 else if (j->_type ==
"angular-velocity-x")
1074 locationFactory->setAngularVelocityIndex(0, objectClass->getDataElementIndex(j->_name));
1075 else if (j->_type ==
"angular-velocity-y")
1076 locationFactory->setAngularVelocityIndex(1, objectClass->getDataElementIndex(j->_name));
1077 else if (j->_type ==
"angular-velocity-z")
1078 locationFactory->setAngularVelocityIndex(2, objectClass->getDataElementIndex(j->_name));
1080 else if (j->_type ==
"linear-velocity-x")
1081 locationFactory->setLinearVelocityIndex(0, objectClass->getDataElementIndex(j->_name));
1082 else if (j->_type ==
"linear-velocity-y")
1083 locationFactory->setLinearVelocityIndex(1, objectClass->getDataElementIndex(j->_name));
1084 else if (j->_type ==
"linear-velocity-z")
1085 locationFactory->setLinearVelocityIndex(2, objectClass->getDataElementIndex(j->_name));
1088 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown position configuration type \""
1089 << j->_type <<
"\"for object class \"" << aircraftClassName <<
"\". Ignoring!");
1093 mpClassCallback->setLocationFactory(locationFactory.get());
1094 }
else if (
i->_positionConfig._type ==
"geodetic") {
1095 SGSharedPtr<sg::HLAGeodeticLocationFactory> locationFactory;
1096 locationFactory =
new sg::HLAGeodeticLocationFactory;
1098 XMLConfigReader::DataElementList::const_iterator j;
1099 for (j =
i->_positionConfig._dataElementList.begin();
1100 j !=
i->_positionConfig._dataElementList.end(); ++j) {
1102 if (j->_type ==
"latitude-deg")
1103 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::LatitudeDeg,
1104 objectClass->getDataElementIndex(j->_name));
1105 else if (j->_type ==
"latitude-rad")
1106 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::LatitudeRad,
1107 objectClass->getDataElementIndex(j->_name));
1108 else if (j->_type ==
"longitude-deg")
1109 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::LongitudeDeg,
1110 objectClass->getDataElementIndex(j->_name));
1111 else if (j->_type ==
"longitude-rad")
1112 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::LongitudeRad,
1113 objectClass->getDataElementIndex(j->_name));
1114 else if (j->_type ==
"elevation-m")
1115 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::ElevationM,
1116 objectClass->getDataElementIndex(j->_name));
1117 else if (j->_type ==
"elevation-m")
1118 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::ElevationFt,
1119 objectClass->getDataElementIndex(j->_name));
1120 else if (j->_type ==
"heading-deg")
1121 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::HeadingDeg,
1122 objectClass->getDataElementIndex(j->_name));
1123 else if (j->_type ==
"heading-rad")
1124 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::HeadingRad,
1125 objectClass->getDataElementIndex(j->_name));
1126 else if (j->_type ==
"pitch-deg")
1127 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::PitchDeg,
1128 objectClass->getDataElementIndex(j->_name));
1129 else if (j->_type ==
"pitch-rad")
1130 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::PitchRad,
1131 objectClass->getDataElementIndex(j->_name));
1132 else if (j->_type ==
"roll-deg")
1133 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::RollDeg,
1134 objectClass->getDataElementIndex(j->_name));
1135 else if (j->_type ==
"roll-rad")
1136 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::RollRad,
1137 objectClass->getDataElementIndex(j->_name));
1138 else if (j->_type ==
"ground-track-deg")
1139 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::GroundTrackDeg,
1140 objectClass->getDataElementIndex(j->_name));
1141 else if (j->_type ==
"ground-track-rad")
1142 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::GroundTrackRad,
1143 objectClass->getDataElementIndex(j->_name));
1144 else if (j->_type ==
"ground-speed-kt")
1145 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::GroundSpeedKnots,
1146 objectClass->getDataElementIndex(j->_name));
1147 else if (j->_type ==
"ground-speed-ft-per-sec")
1148 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::GroundSpeedFtPerSec,
1149 objectClass->getDataElementIndex(j->_name));
1150 else if (j->_type ==
"ground-speed-m-per-sec")
1151 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::GroundSpeedMPerSec,
1152 objectClass->getDataElementIndex(j->_name));
1153 else if (j->_type ==
"vertical-speed-ft-per-sec")
1154 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::VerticalSpeedFtPerSec,
1155 objectClass->getDataElementIndex(j->_name));
1156 else if (j->_type ==
"vertical-speed-ft-per-min")
1157 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::VerticalSpeedFtPerMin,
1158 objectClass->getDataElementIndex(j->_name));
1159 else if (j->_type ==
"vertical-speed-m-per-sec")
1160 locationFactory->setIndex(sg::HLAGeodeticLocationFactory::VerticalSpeedMPerSec,
1161 objectClass->getDataElementIndex(j->_name));
1163 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown position configuration type \""
1164 << j->_type <<
"\" for object class \"" << aircraftClassName <<
"\". Ignoring!");
1168 mpClassCallback->setLocationFactory(locationFactory.get());
1171 if (
i->_modelConfig._type ==
"native") {
1172 SGSharedPtr<AttributeModelFactory> attributeModelFactory;
1175 XMLConfigReader::DataElementList::const_iterator j;
1176 for (j =
i->_modelConfig._dataElementList.begin();
1177 j !=
i->_modelConfig._dataElementList.end(); ++j) {
1179 if (j->_type ==
"model-path")
1180 attributeModelFactory->setModelIndex(objectClass->getDataElementIndex(j->_name));
1183 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown model configuration type \""
1184 << j->_type <<
"\" for object class \"" << aircraftClassName <<
"\". Ignoring!");
1188 mpClassCallback->setModelFactory(attributeModelFactory.get());
1189 }
else if (
i->_modelConfig._type ==
"map") {
1191 SGSharedPtr<AttributeMapModelFactory> attributeModelFactory;
1194 XMLConfigReader::DataElementList::const_iterator j;
1195 for (j =
i->_modelConfig._dataElementList.begin();
1196 j !=
i->_modelConfig._dataElementList.end(); ++j) {
1198 if (j->_type ==
"external")
1199 attributeModelFactory->setModelIndex(objectClass->getDataElementIndex(j->_name));
1202 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown model configuration type \""
1203 << j->_type <<
"\" for object class \"" << aircraftClassName <<
"\". Ignoring!");
1207 std::list<std::pair<std::string, std::string> >::const_iterator k;
1208 for (k =
i->_modelConfig._modelMap.begin();
1209 k !=
i->_modelConfig._modelMap.end(); ++k) {
1211 if (k->second.empty())
1212 attributeModelFactory->setExternalDefault(k->first);
1214 attributeModelFactory->addExternalModelPathPair(k->first, k->second);
1217 mpClassCallback->setModelFactory(attributeModelFactory.get());
1220 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown model configuration type \""
1221 <<
i->_modelConfig._type <<
"\" for object class \"" << aircraftClassName <<
"\". Ignoring!");
1224 if (
i->_simTimeConfig._type ==
"attribute") {
1225 SGSharedPtr<AttributeSimTimeFactory> attributeSimTimeFactory;
1228 XMLConfigReader::DataElementList::const_iterator j;
1229 for (j =
i->_simTimeConfig._dataElementList.begin();
1230 j !=
i->_simTimeConfig._dataElementList.end(); ++j) {
1232 if (j->_type ==
"local-simtime")
1233 attributeSimTimeFactory->setSimTimeIndex(objectClass->getDataElementIndex(j->_name));
1235 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown simtime configuration type \""
1236 << j->_type <<
"\" for object class \"" << aircraftClassName <<
"\". Ignoring!");
1240 mpClassCallback->setSimTimeFactory(attributeSimTimeFactory.get());
1241 }
else if (
i->_simTimeConfig._type ==
"attribute-sec-msec") {
1242 SGSharedPtr<MSecAttributeSimTimeFactory> attributeSimTimeFactory;
1245 XMLConfigReader::DataElementList::const_iterator j;
1246 for (j =
i->_simTimeConfig._dataElementList.begin();
1247 j !=
i->_simTimeConfig._dataElementList.end(); ++j) {
1249 if (j->_type ==
"local-simtime-sec")
1250 attributeSimTimeFactory->setSecIndex(objectClass->getDataElementIndex(j->_name));
1251 else if (j->_type ==
"local-simtime-msec")
1252 attributeSimTimeFactory->setMSecIndex(objectClass->getDataElementIndex(j->_name));
1254 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown simtime configuration type \""
1255 << j->_type <<
"\" for object class \"" << aircraftClassName <<
"\". Ignoring!");
1259 mpClassCallback->setSimTimeFactory(attributeSimTimeFactory.get());
1261 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown simtime configuration type \""
1262 <<
i->_simTimeConfig._type <<
"\" for object class \"" << aircraftClassName <<
"\". Ignoring!");
1265 if (!
i->_mpPropertiesConfig._name.empty()) {
1266 mpClassCallback->setMPPropertiesIndex(objectClass->getDataElementIndex(
i->_mpPropertiesConfig._name));
1270 XMLConfigReader::DataElementList::const_iterator j;
1271 for (j =
i->_dataElementList.begin();
1272 j !=
i->_dataElementList.end(); ++j) {
1274 if (j->_type ==
"property") {
1275 if (!j->_inProperty.empty())
1276 mpClassCallback->setInputProperty(objectClass->getDataElementIndex(j->_name), j->_inProperty);
1277 if (!j->_outProperty.empty())
1278 mpClassCallback->setOutputProperty(objectClass->getDataElementIndex(j->_name), j->_outProperty);
1280 SG_LOG(SG_IO, SG_ALERT,
"HLA: Unknown dataElement configuration type \""
1281 << j->_type <<
"\" for object class \"" << aircraftClassName <<
"\". Ignoring!");