Search in sources :

Example 1 with SendRequestCommand

use of com.example.commadapter.vehicle.exchange.commands.SendRequestCommand in project opentcs-integration-example by openTCS.

the class ControlPanel method sendOrderButtonActionPerformed.

// GEN-LAST:event_repeatLastOrderButtonActionPerformed
private void sendOrderButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_sendOrderButtonActionPerformed
    // Parse and check destination
    Object selectedItem = destinationComboBox.getSelectedItem();
    String destinationIdString = selectedItem instanceof Point ? ((Point) selectedItem).getName() : selectedItem.toString();
    int destinationId = 0;
    try {
        destinationId = Integer.parseInt(destinationIdString);
        if (destinationId < 0 || destinationId > 65535) {
            throw new NumberFormatException("destinationId out of bounds");
        }
    } catch (NumberFormatException e) {
        JOptionPane.showMessageDialog(this, "Destination ID must be in [0..65535].");
        return;
    }
    // Parse and check action
    OrderRequest.OrderAction action = (OrderRequest.OrderAction) actionComboBox.getSelectedItem();
    // Parse and check order ID.
    int orderId;
    try {
        orderId = Integer.parseUnsignedInt(orderIdTextField.getText());
        if (orderId < 0 || orderId > 65535) {
            throw new NumberFormatException("orderId out of bounds");
        }
    } catch (NumberFormatException exc) {
        JOptionPane.showMessageDialog(this, "Order ID must be in [0..65535].");
        return;
    }
    OrderRequest telegram = new OrderRequest(0, orderId, destinationId, action);
    // Send this telegram to vehicle.
    sendAdapterCommand(new SendRequestCommand(telegram));
    // Increment the order ID in case the user wants to send another one.
    orderId = (orderId + 1) % 65535;
    if (orderId == 0) {
        orderId = 1;
    }
    orderIdTextField.setText(Integer.toString(orderId));
}
Also used : OrderRequest(com.example.commadapter.vehicle.telegrams.OrderRequest) SendRequestCommand(com.example.commadapter.vehicle.exchange.commands.SendRequestCommand) Point(org.opentcs.data.model.Point) Point(org.opentcs.data.model.Point)

Example 2 with SendRequestCommand

use of com.example.commadapter.vehicle.exchange.commands.SendRequestCommand in project opentcs-integration-example by openTCS.

the class StatusPanel method buttonGetStateActionPerformed.

// GEN-LAST:event_chkBoxEnablePeriodicGetStateActionPerformed
private void buttonGetStateActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_buttonGetStateActionPerformed
    SendRequestCommand command = new SendRequestCommand(new StateRequest(0));
    sendAdapterCommand(command);
}
Also used : StateRequest(com.example.commadapter.vehicle.telegrams.StateRequest) SendRequestCommand(com.example.commadapter.vehicle.exchange.commands.SendRequestCommand)

Aggregations

SendRequestCommand (com.example.commadapter.vehicle.exchange.commands.SendRequestCommand)2 OrderRequest (com.example.commadapter.vehicle.telegrams.OrderRequest)1 StateRequest (com.example.commadapter.vehicle.telegrams.StateRequest)1 Point (org.opentcs.data.model.Point)1