Search in sources :

Example 1 with OrderRequest

use of com.example.commadapter.vehicle.telegrams.OrderRequest in project opentcs-integration-example by openTCS.

the class ControlPanel method updateLastOrder.

/**
 * Updates the list of last orders sent with the given one as last order.
 *
 * @param lastOrderSent The last order sent
 * @param connected The connection state to the vehicle with <code>true</code> indicates a
 * connection is established
 */
private void updateLastOrder(OrderRequest lastOrderSent, boolean connected) {
    SwingUtilities.invokeLater(() -> {
        if (lastOrderSent != null) {
            OrderRequest selectedTelegram = lastOrdersList.getSelectedValue();
            if (selectedTelegram == null) {
                selectedTelegram = lastOrderSent;
            }
            updateLastOrderTextFields(selectedTelegram);
            repeatLastOrderButton.setEnabled(connected);
            lastOrderListModel.add(0, lastOrderSent);
            lastOrdersList.setSelectedIndex(0);
            // Delete last element if our listmodel contains too many elements
            while (lastOrderListModel.getSize() > MAX_LAST_ORDERS) {
                lastOrderListModel.removeElement(lastOrderListModel.lastElement());
            }
        }
    });
}
Also used : OrderRequest(com.example.commadapter.vehicle.telegrams.OrderRequest)

Example 2 with OrderRequest

use of com.example.commadapter.vehicle.telegrams.OrderRequest in project opentcs-integration-example by openTCS.

the class ControlPanel method lastOrdersSentValueChanged.

// GEN-LAST:event_enableLoggingChkBoxActionPerformed
/**
 * Updates the panel containing informations about the last order sent with the selected order
 * from the list.
 *
 * @param evt The selection event for the order list
 */
private void lastOrdersSentValueChanged(javax.swing.event.ListSelectionEvent evt) {
    OrderRequest selectedTelegram = lastOrdersList.getSelectedValue();
    updateLastOrderTextFields(selectedTelegram);
}
Also used : OrderRequest(com.example.commadapter.vehicle.telegrams.OrderRequest)

Example 3 with OrderRequest

use of com.example.commadapter.vehicle.telegrams.OrderRequest in project opentcs-integration-example by openTCS.

the class OrderListCellRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (value instanceof OrderRequest) {
        OrderRequest request = (OrderRequest) value;
        JLabel label = (JLabel) component;
        StringBuilder sb = new StringBuilder();
        sb.append('#');
        sb.append(request.getOrderId());
        sb.append(": Dest.: ");
        sb.append(request.getDestinationId());
        sb.append(", Act.: ");
        sb.append(request.getDestinationAction());
        sb.append("...");
        label.setText(sb.toString());
    }
    return component;
}
Also used : OrderRequest(com.example.commadapter.vehicle.telegrams.OrderRequest) JLabel(javax.swing.JLabel) Component(java.awt.Component)

Example 4 with OrderRequest

use of com.example.commadapter.vehicle.telegrams.OrderRequest in project opentcs-integration-example by openTCS.

the class ExampleCommAdapter method sendCommand.

@Override
public synchronized void sendCommand(MovementCommand cmd) throws IllegalArgumentException {
    requireNonNull(cmd, "cmd");
    try {
        OrderRequest telegram = orderMapper.mapToOrder(cmd);
        orderIds.put(cmd, telegram.getOrderId());
        LOG.debug("{}: Enqueuing order request with: order id={}, dest. id={}, dest. action={}", getName(), telegram.getOrderId(), telegram.getDestinationId(), telegram.getDestinationAction());
        // Add the telegram to the queue. Telegram will be send later when its the first telegram in
        // the queue. This ensures that we always wait for a response until we send a new request.
        requestResponseMatcher.enqueueRequest(telegram);
    } catch (IllegalArgumentException exc) {
        LOG.error("{}: Failed to enqueue command {}", getName(), cmd, exc);
    }
}
Also used : OrderRequest(com.example.commadapter.vehicle.telegrams.OrderRequest)

Example 5 with OrderRequest

use of com.example.commadapter.vehicle.telegrams.OrderRequest 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)

Aggregations

OrderRequest (com.example.commadapter.vehicle.telegrams.OrderRequest)7 SendRequestCommand (com.example.commadapter.vehicle.exchange.commands.SendRequestCommand)1 Component (java.awt.Component)1 JLabel (javax.swing.JLabel)1 Point (org.opentcs.data.model.Point)1