Skip to content

Generalize the protocol handling of the ports in IDE #1334

Open
@kittaakos

Description

@kittaakos

Describe the request

Follow-up of #1332.

Originally posted here:

I don't understand why these two specific protocols are treated differently than any other arbitrary protocol. In this new era of pluggable discovery, where no assumptions or restrictions are placed on which communication channel might be used between the Arduino tooling and an Arduino board, it seems best for the Arduino IDE to generalize the handling of ports.

Describe the current behavior

IDE2 handles 'serial' and 'network' protocols but nothing else. Generalize the protocol handling of the ports.

Besides showing the protocol label somewhere on the UI, IDE should not treat 'serial' and 'network' port protocols differently than other protocols.

Arduino IDE version

d674ab9

Operating system

macOS

Operating system version

12.3.1

Additional context

To clean up in the code-base:

To single-source in the code-base:

  • export const compare = (left: AvailableBoard, right: AvailableBoard) => {
    if (left.port?.protocol === 'serial' && right.port?.protocol !== 'serial') {
    return -1;
    } else if (
    left.port?.protocol !== 'serial' &&
    right.port?.protocol === 'serial'
    ) {
    return 1;
    } else if (
    left.port?.protocol === 'network' &&
    right.port?.protocol !== 'network'
    ) {
    return -1;
    } else if (
    left.port?.protocol !== 'network' &&
    right.port?.protocol === 'network'
    ) {
    return 1;
    } else if (left.port?.protocol === right.port?.protocol) {
    // We show all ports, including those that have guessed
    // or unrecognized boards, so we must sort those too.
    if (left.state < right.state) {
    return -1;
    } else if (left.state > right.state) {
    return 1;
    }
    }
    return naturalCompare(left.port?.address!, right.port?.address!);
    };
  • // Available ports must be sorted in this order:
    // 1. Serial with recognized boards
    // 2. Serial with guessed boards
    // 3. Serial with incomplete boards
    // 4. Network with recognized boards
    // 5. Other protocols with recognized boards
    const ports = (await availablePorts).sort((left: Port, right: Port) => {
    if (left.protocol === 'serial' && right.protocol !== 'serial') {
    return -1;
    } else if (left.protocol !== 'serial' && right.protocol === 'serial') {
    return 1;
    } else if (left.protocol === 'network' && right.protocol !== 'network') {
    return -1;
    } else if (left.protocol !== 'network' && right.protocol === 'network') {
    return 1;
    } else if (left.protocol === right.protocol) {
    // We show ports, including those that have guessed
    // or unrecognized boards, so we must sort those too.
    const leftBoard = this.availableBoards.find(
    (board) => board.port === left
    );
    const rightBoard = this.availableBoards.find(
    (board) => board.port === right
    );
    if (leftBoard && !rightBoard) {
    return -1;
    } else if (!leftBoard && rightBoard) {
    return 1;
    } else if (leftBoard?.state! < rightBoard?.state!) {
    return -1;
    } else if (leftBoard?.state! > rightBoard?.state!) {
    return 1;
    }
    }
    return naturalCompare(left.address, right.address);

Issue checklist

  • I searched for previous requests in the issue tracker
  • I verified the feature was still missing when using the latest nightly build
  • My request contains all necessary details

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: enhancementProposed improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions