示例#1
0
 /**
  * issues a command with a location target to the selected entities
  *
  * @param command
  * @param location
  */
 private void doCommand(int command, Vector3f location) {
   for (Iterator<Spatial> it = selectedEntities.iterator(); it.hasNext(); ) {
     Spatial spatial1 = it.next();
     CommandControl commandControl = spatial1.getControl(CommandControl.class);
     if (commandControl == null) {
       return;
     }
     try {
       Command commandInst = commands.get(command).newInstance();
       commandInst.setPriority(10);
       commandControl.clearCommands();
       commandControl.initializeCommand(commandInst);
       Command.TargetResult info = commandInst.setTargetLocation(location);
       if (info == Command.TargetResult.Accept
           || info == Command.TargetResult.AcceptEnemy
           || info == Command.TargetResult.AcceptFriendly) {
         commandControl.addCommand(commandInst);
       }
     } catch (InstantiationException ex) {
       Logger.getLogger(UserCommandControl.class.getName()).log(Level.SEVERE, null, ex);
     } catch (IllegalAccessException ex) {
       Logger.getLogger(UserCommandControl.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
 }
示例#2
0
  private void handlePacket(DatagramPacket receivedDatagram) throws IOException {
    byte[] received = receivedDatagram.getData();

    if (received[2] == 2) {
      System.out.println(" Discovery packet received ");
      this.remoteAddress = receivedDatagram.getAddress();
      this.remotePort = receivedDatagram.getPort();
      System.out.println(
          " Discovery Remote Address " + this.remoteAddress + " Remote Port " + this.remotePort);
      byte[] response = getDiscoveryReplyMessage();
      DatagramPacket datagram =
          new DatagramPacket(response, response.length, this.remoteAddress, this.remotePort);
      socket.send(datagram);
      System.out.println(" Discovery reply packet sent ");

      return;

    } else if (received[2] == 4) {
      if (received[3] == 1 || received[3] == 3) {
        running = true;
        this.remotePort = receivedDatagram.getPort();
        System.out.println(
            " Data Remote Address " + this.remoteAddress + " Remote Port " + this.remotePort);
        System.out.println(" SDR Program sends Start command ");
        return;
      } else {
        last_sequence_number = 0;
        running = false;
        System.out.println("  SDR Program sends Stop command ");
        return;
      }
    }

    if (isValidFrame(received)) {
      // packet contains 2 hpsdr frames; so 2 c&c's
      byte[] cc = new byte[5];
      System.arraycopy(received, 11, cc, 0, 5); // index 11 .... 15
      ccontrol.CommandAndControl(cc);
      System.arraycopy(received, 523, cc, 0, 5); // index 523 .... 531 (8
      // + 512 + 3 sync)
      ccontrol.CommandAndControl(cc);

      nrx = ccontrol.getNrOfReceivers();

      if (ccontrol.isControlDataChanged()) {
        rxHandler.setRXFrequency(ccontrol.getRXFrequency());
        System.out.println("Number of receivers " + nrx);
      }

      // lees data en vul buffers
      for (int frame = 0; frame < 2; frame++) {
        int coarse_pointer = frame * 512 + 8;

        for (int j = 8; j < 512; j += 8) {
          int k = coarse_pointer + j;

          // M
          // No codec.. skip
          // TX IQ
          // No tx yet

        }
      }
    } else {
      System.out.println(" Invalid frame ");
    }
  }