diff --git a/examples/src/OpenDis7Examples/PduSender.java b/examples/src/OpenDis7Examples/PduSender.java index ec4e975b2e08a2096d4b6e9621e1ed374713d6fa..271af1fecfeab2e90d6105e86dcb10eb53f46a99 100644 --- a/examples/src/OpenDis7Examples/PduSender.java +++ b/examples/src/OpenDis7Examples/PduSender.java @@ -1,458 +1,439 @@ -package OpenDis7Examples; - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis7.*; -import edu.nps.moves.dis7.enumerations.*; - -/** - * This is an example that sends many/most types of PDUs. Useful for testing standards - * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. - * Adapted from OpenDIS library example package edu.nps.moves.examples - * - * @author DMcG - * @version $Id:$ - */ -public class PduSender -{ - /** Default multicast group address we send on. */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** Default multicast port used, matches Wireshark DIS capture default */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public PduSender(int port, String multicast) { - try - { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) - { - System.out.println("Not a multicast address: " + multicast); - } - } - catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run() - { - System.out.println("DisExamplesOpenDis7.PduSender started..."); - try { - List<Pdu> generatedPdusList = new ArrayList<>(); - - // Loop through all the enumerated PDU types, create a PDU for each type, - // add that PDU to generatedPdusList, and send each one - for (DISPDUType pdu : DISPDUType.values()) - { -// System.out.println("PDU " + pdu.getValue() + " " + pdu.name() + " " + pdu.getDescription()); // diagnostic - - Pdu aPdu = null; // edu.​nps.​moves7.​dis.PDU superclass for all PDUs, in preparation for custom assignment - - try { - switch (pdu) // using enumeration values from edu.​nps.​moves.​dis7.​enumerations.​DISPDUType - { - case OTHER: // 0 - System.out.println ("DISPDUType." + pdu.name() + " not supported"); // TODO explain - break; - - case ENTITY_STATE: //1 - aPdu = new EntityStatePdu(); - EntityStatePdu espdu = (EntityStatePdu) aPdu; - EntityMarking entityMarking = new EntityMarking (); - entityMarking.setCharacters(Byte.valueOf("0")); // 11 characters max? - // TODO entityMarking.setCharactersString("PduSender"); // 11 characters max - - espdu.setMarking(entityMarking); - Vector3Double espduLocation = new Vector3Double(); - espduLocation.setX(1.0); - espduLocation.setY(2.0); - espduLocation.setZ(3.0); - espdu.setEntityLocation(espduLocation); - // it is important to identify questions as you think of them - // TODO how to set azimuth, i.e. course direction over ground? - break; - - case FIRE: // 2 - aPdu = new FirePdu(); - break; - - case DETONATION: // 3 - aPdu = new DetonationPdu(); - break; - - case COLLISION: // 4 - aPdu = new CollisionPdu(); - break; - - case SERVICE_REQUEST: // 5 - aPdu = new ServiceRequestPdu(); - break; - - case RESUPPLY_OFFER: // 6 - aPdu = new ResupplyOfferPdu(); - break; - - case RESUPPLY_RECEIVED: // 7 - aPdu = new ResupplyReceivedPdu(); - break; - - case RESUPPLY_CANCEL: //8 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); - // aPdu = new ResupplyCancelPdu(); // TODO exception - break; - - case REPAIR_COMPLETE: // 9 - aPdu = new RepairCompletePdu(); - break; - - case REPAIR_RESPONSE: // 10 - aPdu = new RepairResponsePdu(); - break; - - case CREATE_ENTITY: // 11 - aPdu = new CreateEntityPdu(); - break; - - case REMOVE_ENTITY: // 12 - aPdu = new RemoveEntityPdu(); - break; - - case START_RESUME: // 13 - aPdu = new StartResumePdu(); - break; - - case STOP_FREEZE: // 14 - aPdu = new StopFreezePdu(); - break; - - case ACKNOWLEDGE: // 15 - aPdu = new AcknowledgePdu(); - break; - - case ACTION_REQUEST: // 16 - aPdu = new ActionRequestPdu(); - break; - - case ACTION_RESPONSE: // 17 - aPdu = new ActionResponsePdu(); - break; - - case DATA_QUERY: // 18 - aPdu = new DataQueryPdu(); - break; - - case SET_DATA: // 19 - aPdu = new SetDataPdu(); - break; - - case DATA: // 20 - aPdu = new DataPdu(); - break; - - case EVENT_REPORT: // 21 - aPdu = new EventReportPdu(); - break; - - case ELECTROMAGNETIC_EMISSION: // 23 - aPdu = new ElectronicEmissionsPdu(); // TODO misnamed as ElectromagneticEmissionPdu - break; - - case DESIGNATOR: // 24 - aPdu = new DesignatorPdu(); - break; - - case TRANSMITTER: // 25 - aPdu = new TransmitterPdu(); - break; - - case SIGNAL: // 26 - aPdu = new SignalPdu(); - break; - - case RECEIVER: // 27 - aPdu = new ReceiverPdu(); - break; - - case IFF: // 28 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new IffPdu(); // TODO misnamed as IFFPdu(); - break; - - case UNDERWATER_ACOUSTIC: // 29 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new UnderwaterAcousticPdu(); - break; - - case SUPPLEMENTAL_EMISSION_ENTITY_STATE: // 30 - aPdu = new SeesPdu(); // TODO misnamed as SupplementalEmission/EntityStatePdu(); - break; - - case INTERCOM_SIGNAL: // 31 - aPdu = new IntercomSignalPdu(); - break; - - case INTERCOM_CONTROL: // 32 - aPdu = new IntercomControlPdu(); - break; - - case AGGREGATE_STATE: // 33 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new AggregateStatePdu(); - break; - - case ISGROUPOF: // 34 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new IsGroupOfPdu(); - break; - - case TRANSFER_OWNERSHIP: // 35 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new TransferOwnershipPdu(); - break; - - case ISPARTOF: // 36 - aPdu = new IsPartOfPdu(); - break; - - case MINEFIELD_STATE: // 37 - aPdu = new MinefieldStatePdu(); - break; - - case MINEFIELD_QUERY: // 38 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new MinefieldQueryPdu(); - break; - - case MINEFIELD_DATA: // 39 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new MinefieldDataPdu(); - break; - - case MINEFIELD_RESPONSE_NACK: // 40 - aPdu = new MinefieldResponseNackPdu(); // TODO misnamed as MinefieldResponseNACKPdu(); - break; - - case ENVIRONMENTAL_PROCESS: // 41 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new EnvironmentalProcessPdu(); - break; - - case GRIDDED_DATA: // 42 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new GriddedDataPdu(); - break; - - case POINT_OBJECT_STATE: // 43 - aPdu = new PointObjectStatePdu(); - break; - - case LINEAR_OBJECT_STATE: // 44 - aPdu = new LinearObjectStatePdu(); - break; - - case AREAL_OBJECT_STATE: // 45 - aPdu = new ArealObjectStatePdu(); - break; - - case TSPI: // 46 - System.out.println ("DISPDUType." + pdu.name() + " not supported"); - // aPdu = new TspiPdu(); // TODO misnamed as TSPIPdu(); also extends LiveEntityFamilyPdu but cannot be cast to class Pdu - break; - - case APPEARANCE: // 47 - System.out.println ("DISPDUType." + pdu.name() + " not supported"); - // aPdu = new AppearancePdu(); // TODO extends LiveEntityFamilyPdu but cannot be cast to class Pdu - break; - - case ARTICULATED_PARTS: // 48 - System.out.println ("DISPDUType." + pdu.name() + " not supported"); - // aPdu = new ArticulatedPartsPdu(); // TODO extends LiveEntityFamilyPdu but cannot be cast to class Pdu - break; - - case LE_FIRE: // 49 - System.out.println ("DISPDUType." + pdu.name() + " not supported"); - // aPdu = new LEFirePdu(); // TODO extends LiveEntityFamilyPdu but cannot be cast to class Pdu - break; - - case LE_DETONATION: // 50 - System.out.println ("DISPDUType." + pdu.name() + " not supported"); - // aPdu = new LEDetonationPdu(); // TODO extends LiveEntityFamilyPdu but cannot be cast to class Pdu - break; - - case CREATE_ENTITY_R: // 51 - aPdu = new CreateEntityReliablePdu(); // TODO misnamed as CreateEntityRPdu(); - break; - - case REMOVE_ENTITY_R: // 52 - aPdu = new RemoveEntityReliablePdu(); // TODO misnamed as RemoveEntityRPdu(); - break; - - case START_RESUME_R: // 53 - aPdu = new StartResumeReliablePdu(); // TODO misnamed as StartResumeRPdu(); - break; - - case STOP_FREEZE_R: // 54 - aPdu = new StopFreezeReliablePdu(); // TODO misnamed as StopFreezeRPdu(); - break; - - case ACKNOWLEDGE_R: // 55 - aPdu = new AcknowledgeReliablePdu(); // TODO misnamed as AcknowledgeRPdu(); - break; - - case ACTION_REQUEST_R: // 56 - aPdu = new ActionRequestReliablePdu(); // TODO misnamed as ActionRequestRPdu(); - break; - - case ACTION_RESPONSE_R: // 57 - aPdu = new ActionResponseReliablePdu(); // TODO misnamed as ActionResponseRPdu(); - break; - - case DATA_QUERY_R: // 58 - aPdu = new DataQueryReliablePdu(); // TODO misnamed as DataQueryRPdu(); - break; - - case SET_DATA_R: // 59 - aPdu = new SetDataReliablePdu(); // TODO misnamed as SetDataRPdu(); - break; - - case DATA_R: // 60 - aPdu = new DataReliablePdu(); // TODO misnamed as DataRPdu(); - break; - - case EVENT_REPORT_R: // 61 - aPdu = new EventReportReliablePdu(); // TODO misnamed as EventReportRPdu(); - break; - - case COMMENT_R: // 62 - aPdu = new CommentReliablePdu(); // TODO misnamed as CommentRPdu(); - break; - - case RECORD_R: // 63 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new RecordReliablePdu(); // TODO misnamed as RecordRPdu(); - break; - - case SET_RECORD_R: // 64 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new SetRecordReliablePdu(); // TODO misnamed as SetRecordRPdu(); - break; - - case RECORD_QUERY_R: // 65 - aPdu = new RecordQueryReliablePdu(); // TODO misnamed as RecordQueryRPdu(); - break; - - case COLLISION_ELASTIC: // 66 - aPdu = new CollisionElasticPdu(); - break; - - case ENTITY_STATE_UPDATE: // 67 - aPdu = new EntityStateUpdatePdu(); - break; - - case DIRECTED_ENERGY_FIRE: // 68 - aPdu = new DirectedEnergyFirePdu(); - break; - - case ENTITY_DAMAGE_STATUS: // 69 - aPdu = new EntityDamageStatusPdu(); - break; - - case INFORMATION_OPERATIONS_ACTION: // 70 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new InformationOperationsActionPdu(); - break; - - case INFORMATION_OPERATIONS_REPORT: // 71 - System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); -// aPdu = new InformationOperationsReportPdu(); - break; - - case ATTRIBUTE: // 72 - aPdu = new AttributePdu(); - break; - - // TODO unused?? - case COMMENT: - aPdu = new CommentPdu(); - CommentPdu newCommentPdu = (CommentPdu)aPdu; - VariableDatum newVariableDatum = new VariableDatum(); - // etc. see Garrett and Pete's code - break; - - default: - System.out.print("PDU " + pdu.getValue() + " " + pdu + " not supported, created or sent "); - - // code generation block for this class follow: - // System.out.println(" case " + pdu + ": // " + pdu.getValue()); - // System.out.println(" aPdu = new " + pdu.getDescription().replace(" ","").replace("-","").replace("/","") + - // "Pdu();"); - // System.out.println(" break;"); - // System.out.println(); - } - if (aPdu != null) - { - generatedPdusList.add(aPdu); - } - } - catch (Exception e) - { - System.out.print("Exception thrown for PDU " + pdu.getValue() + " " + pdu); - System.out.print(Arrays.toString(e.getStackTrace())); - // continue looping - } - } - System.out.println("Send the " + generatedPdusList.size() + " PDUs we created..."); - - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.joinGroup(localMulticastAddress); - - for (int idx = 0; idx < generatedPdusList.size(); idx++) - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - Pdu aPdu = generatedPdusList.get(idx); - aPdu.marshal(dos); - - buffer = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); - socket.send(packet); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()); - } - // write the PDUs out to an XML file. - //PduContainer container = new PduContainer(); - //container.setPdus(generatedPdus); - //container.marshallToXml("examplePdus.xml"); - } - catch (IOException e) - { - System.out.println(e); - } - } - - public static void main(String args[]) - { - if (args.length == 2) - { - PduSender sender = new PduSender(Integer.parseInt(args[0]), args[1]); - sender.run(); - } - else - { - System.out.println("Usage: PduSender <port> <multicast group>"); - System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); - PduSender sender = new PduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); - sender.run(); - } - } -} +package OpenDis7Examples; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. + * Adapted from OpenDIS library example package edu.nps.moves.examples + * + * @author DMcG + * @version $Id:$ + */ +public class PduSender +{ + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** Default multicast port used, matches Wireshark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + private int port; + InetAddress multicastAddress; + + public PduSender(int port, String multicast) { + try + { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run() + { + System.out.println("DisExamplesOpenDis7.PduSender started..."); + try { + List<Pdu> generatedPdusList = new ArrayList<>(); + + // Loop through all the enumerated PDU types, create a PDU for each type, + // add that PDU to generatedPdusList, and send each one + for (DISPDUType pdu : DISPDUType.values()) + { +// System.out.println("PDU " + pdu.getValue() + " " + pdu.name() + " " + pdu.getDescription()); // diagnostic + + Pdu aPdu = null; // edu.​nps.​moves7.​dis.PDU superclass for all PDUs, in preparation for custom assignment + + try { + switch (pdu) // using enumeration values from edu.​nps.​moves.​dis7.​enumerations.​DISPDUType + { + case OTHER: // 0 + System.out.println ("DISPDUType." + pdu.name() + " not supported"); // TODO explain + break; + + case ENTITY_STATE: //1 + aPdu = new EntityStatePdu(); + + EntityStatePdu espdu = (EntityStatePdu) aPdu; + EntityMarking entityMarking = new EntityMarking (); + entityMarking.setCharacters("PduSender".getBytes()); //entityMarking.setCharacters(Byte.valueOf("0")); // 11 characters max? + + espdu.setMarking(entityMarking); + Vector3Double espduLocation = new Vector3Double(); + espduLocation.setX(1.0); + espduLocation.setY(2.0); + espduLocation.setZ(3.0); + espdu.setEntityLocation(espduLocation); + // it is important to identify questions as you think of them + // TODO how to set azimuth, i.e. course direction over ground? + break; + + case FIRE: // 2 + aPdu = new FirePdu(); + break; + + case DETONATION: // 3 + aPdu = new DetonationPdu(); + break; + + case COLLISION: // 4 + aPdu = new CollisionPdu(); + break; + + case SERVICE_REQUEST: // 5 + aPdu = new ServiceRequestPdu(); + break; + + case RESUPPLY_OFFER: // 6 + aPdu = new ResupplyOfferPdu(); + break; + + case RESUPPLY_RECEIVED: // 7 + aPdu = new ResupplyReceivedPdu(); + break; + + case RESUPPLY_CANCEL: //8 + System.out.println ("DISPDUType." + pdu.name() + " not supported, throws exception"); + // aPdu = new ResupplyCancelPdu(); // TODO exception + break; + + case REPAIR_COMPLETE: // 9 + aPdu = new RepairCompletePdu(); + break; + + case REPAIR_RESPONSE: // 10 + aPdu = new RepairResponsePdu(); + break; + + case CREATE_ENTITY: // 11 + aPdu = new CreateEntityPdu(); + break; + + case REMOVE_ENTITY: // 12 + aPdu = new RemoveEntityPdu(); + break; + + case START_RESUME: // 13 + aPdu = new StartResumePdu(); + break; + + case STOP_FREEZE: // 14 + aPdu = new StopFreezePdu(); + break; + + case ACKNOWLEDGE: // 15 + aPdu = new AcknowledgePdu(); + break; + + case ACTION_REQUEST: // 16 + aPdu = new ActionRequestPdu(); + break; + + case ACTION_RESPONSE: // 17 + aPdu = new ActionResponsePdu(); + break; + + case DATA_QUERY: // 18 + aPdu = new DataQueryPdu(); + break; + + case SET_DATA: // 19 + aPdu = new SetDataPdu(); + break; + + case DATA: // 20 + aPdu = new DataPdu(); + break; + + case EVENT_REPORT: // 21 + aPdu = new EventReportPdu(); + break; + + case ELECTROMAGNETIC_EMISSION: // 23 + aPdu = new ElectromagneticEmissionPdu(); + break; + + case DESIGNATOR: // 24 + aPdu = new DesignatorPdu(); + break; + + case TRANSMITTER: // 25 + aPdu = new TransmitterPdu(); + break; + + case SIGNAL: // 26 + aPdu = new SignalPdu(); + break; + + case RECEIVER: // 27 + aPdu = new ReceiverPdu(); + break; + + case IFF: // 28 + aPdu = new IFFPdu(); + break; + + case UNDERWATER_ACOUSTIC: // 29 + aPdu = new UnderwaterAcousticPdu(); + break; + + case SUPPLEMENTAL_EMISSION_ENTITY_STATE: // 30 + aPdu = new SEESPdu(); + break; + + case INTERCOM_SIGNAL: // 31 + aPdu = new IntercomSignalPdu(); + break; + + case INTERCOM_CONTROL: // 32 + aPdu = new IntercomControlPdu(); + break; + + case AGGREGATE_STATE: // 33 + aPdu = new AggregateStatePdu(); + break; + + case ISGROUPOF: // 34 + aPdu = new IsGroupOfPdu(); + break; + + case TRANSFER_OWNERSHIP: // 35 + aPdu = new TransferOwnershipPdu(); + break; + + case ISPARTOF: // 36 + aPdu = new IsPartOfPdu(); + break; + + case MINEFIELD_STATE: // 37 + aPdu = new MinefieldStatePdu(); + break; + + case MINEFIELD_QUERY: // 38 + aPdu = new MinefieldQueryPdu(); + break; + + case MINEFIELD_DATA: // 39 + aPdu = new MinefieldDataPdu(); + break; + + case MINEFIELD_RESPONSE_NACK: // 40 + aPdu = new MinefieldResponseNACKPdu(); + break; + + case ENVIRONMENTAL_PROCESS: // 41 + aPdu = new EnvironmentalProcessPdu(); + break; + + case GRIDDED_DATA: // 42 + aPdu = new GriddedDataPdu(); + break; + + case POINT_OBJECT_STATE: // 43 + aPdu = new PointObjectStatePdu(); + break; + + case LINEAR_OBJECT_STATE: // 44 + aPdu = new LinearObjectStatePdu(); + break; + + case AREAL_OBJECT_STATE: // 45 + aPdu = new ArealObjectStatePdu(); + break; + + case TSPI: // 46 + aPdu = new TSPIPdu(); + break; + + case APPEARANCE: // 47 + aPdu = new AppearancePdu(); + break; + + case ARTICULATED_PARTS: // 48 + aPdu = new ArticulatedPartsPdu(); + break; + + case LE_FIRE: // 49 + aPdu = new LEFirePdu(); + break; + + case LE_DETONATION: // 50 + aPdu = new LEDetonationPdu(); + break; + + case CREATE_ENTITY_R: // 51 + aPdu = new CreateEntityReliablePdu(); + break; + + case REMOVE_ENTITY_R: // 52 + aPdu = new RemoveEntityReliablePdu(); + break; + + case START_RESUME_R: // 53 + aPdu = new StartResumeReliablePdu(); + break; + + case STOP_FREEZE_R: // 54 + aPdu = new StopFreezeReliablePdu(); + break; + + case ACKNOWLEDGE_R: // 55 + aPdu = new AcknowledgeReliablePdu(); + break; + + case ACTION_REQUEST_R: // 56 + aPdu = new ActionRequestReliablePdu(); + break; + + case ACTION_RESPONSE_R: // 57 + aPdu = new ActionResponseReliablePdu(); + break; + + case DATA_QUERY_R: // 58 + aPdu = new DataQueryReliablePdu(); + break; + + case SET_DATA_R: // 59 + aPdu = new SetDataReliablePdu(); + break; + + case DATA_R: // 60 + aPdu = new DataReliablePdu(); + break; + + case EVENT_REPORT_R: // 61 + aPdu = new EventReportReliablePdu(); + break; + + case COMMENT_R: // 62 + aPdu = new CommentReliablePdu(); + break; + + case RECORD_R: // 63 + aPdu = new RecordReliablePdu(); + break; + + case SET_RECORD_R: // 64 + aPdu = new SetRecordReliablePdu(); + break; + + case RECORD_QUERY_R: // 65 + aPdu = new RecordQueryReliablePdu(); + break; + + case COLLISION_ELASTIC: // 66 + aPdu = new CollisionElasticPdu(); + break; + + case ENTITY_STATE_UPDATE: // 67 + aPdu = new EntityStateUpdatePdu(); + break; + + case DIRECTED_ENERGY_FIRE: // 68 + aPdu = new DirectedEnergyFirePdu(); + break; + + case ENTITY_DAMAGE_STATUS: // 69 + aPdu = new EntityDamageStatusPdu(); + break; + + case INFORMATION_OPERATIONS_ACTION: // 70 + aPdu = new InformationOperationsActionPdu(); + break; + + case INFORMATION_OPERATIONS_REPORT: // 71 + aPdu = new InformationOperationsReportPdu(); + break; + + case ATTRIBUTE: // 72 + aPdu = new AttributePdu(); + break; + + case COMMENT: + aPdu = new CommentPdu(); + CommentPdu newCommentPdu = (CommentPdu)aPdu; + VariableDatum newVariableDatum = new VariableDatum(); + // etc. see Garrett and Pete's code + break; + + default: + System.out.print("PDU " + pdu.getValue() + " " + pdu + " not supported, created or sent "); + + // code generation block for this class follow: + // System.out.println(" case " + pdu + ": // " + pdu.getValue()); + // System.out.println(" aPdu = new " + pdu.getDescription().replace(" ","").replace("-","").replace("/","") + + // "Pdu();"); + // System.out.println(" break;"); + // System.out.println(); + } + if (aPdu != null) + { + generatedPdusList.add(aPdu); + } + } + catch (Exception e) + { + System.out.print("Exception thrown for PDU " + pdu.getValue() + " " + pdu); + System.out.print(Arrays.toString(e.getStackTrace())); + // continue looping + } + } + System.out.println("Send the " + generatedPdusList.size() + " PDUs we created..."); + + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdusList.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdusList.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + System.out.println("Sent PDU of type " + aPdu.getClass().getName()); + } + // write the PDUs out to an XML file. + //PduContainer container = new PduContainer(); + //container.setPdus(generatedPdus); + //container.marshallToXml("examplePdus.xml"); + } + catch (IOException e) + { + System.out.println(e); + } + } + + public static void main(String args[]) + { + if (args.length == 2) + { + PduSender sender = new PduSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } + else + { + System.out.println("Usage: PduSender <port> <multicast group>"); + System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + PduSender sender = new PduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(); + } + } +}