-
Notifications
You must be signed in to change notification settings - Fork 169
Add serial port discovery #1498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
0782756
Add libserialport to make/Cmake
MCUdude b744b19
Initial support for serial port discovery using libserialport
MCUdude 4107aa3
Use compile time constants to set string lengths
MCUdude 6e390d0
Remove comparisons that allways returns true
MCUdude 6976e75
Apply @stefanrueger's patch
MCUdude 37d896f
Remove unnecessary branch
MCUdude 385f210
Remove exits
MCUdude d9912f1
Reduce error messages to warnings
MCUdude 5aea6bd
Only deploy the serial port discovery when pgm->conntype == CONNTYPE_…
MCUdude ca245da
Make sure serialport is unique
MCUdude 9e65675
Use dynamic memory allocation for sernum and port
MCUdude 8258e08
Support partial serial numbers
MCUdude efce224
Rename serialadapter functions
MCUdude 5be3edb
Add support for "usb" suffix when specifying USB VID and PID
MCUdude af6fc08
Add print_available_serialports function
MCUdude d519286
Add missing usb prefix
MCUdude 58b4826
Search for matching serial adapter vid/pid in avrdude.conf
MCUdude e46a00a
Formatting
MCUdude f40366c
Require "usb:" prefix
MCUdude e0abcaf
Allocate space for tokens dynamically
MCUdude 1389463
Add support for trailing serial number matching using ...[end_of_sn]
MCUdude e1fb8c3
Fix token memory allocation issue
MCUdude d234bd1
Utilize usbsn if specified in avrduderc
MCUdude 6576825
Do not print all available serial ports unless ...
MCUdude 53a6775
Make it possible to override serial numbers specified in avrduderc
MCUdude c51ec19
Harden port printing logic
MCUdude 2268d8e
Fix another port print bug
MCUdude 970953d
Only suggest -P usb:[vid]:[pid](:[sn]) if the serial adapter is unique
MCUdude bd1b86f
Allow serial adapters to override the default baudrate
MCUdude c6e832a
Fix segfault
MCUdude 6e3722b
Add more serial adapters
MCUdude f06f18e
Add @stefanrueger's 0001-Fix-sublte-parsing-problems patch
MCUdude 23fad1a
Apply @stefanrueger's 0001-Draft-auxiliary-port-discovery-functions p…
MCUdude 2baf87d
Print serial numbers when two or more serial adapters has the same VI…
MCUdude af3d4e5
Remove unused functions and improve serial number matching
MCUdude d2cacf0
Only suggest serial adapters provided in avrduderc if...
MCUdude d89cf73
Print all serial adapter alternatives if specified serial adapter
MCUdude 88bbea8
Fix issue where serial adapters with non-matching serial number were …
MCUdude 0eb91e4
Add get_libserialport_data function
MCUdude 3df2b19
Add missing rv
MCUdude 77cbffc
Finally fix libserialport autoconf/make build issues
MCUdude 602b575
Replace the last few remaining tabs with spaces
MCUdude 862cc57
Mention serial port discovery in the docs
MCUdude e553c29
Apply @stefanrueger's parsing improvement patch
MCUdude c251450
Improve serial number matching logic
MCUdude d0f63ee
Add sa_num_matches_by_sea function
MCUdude 2d28a7b
Divide more functionality into functions
MCUdude 42c0655
Simplify/optimize setport_from_serialadapter() and setport_from_vid_p…
MCUdude 471e66f
move sa_flag_unique() inside get_libserialport_data()
MCUdude efd1716
Rename for loop counter variables
MCUdude d7dc844
Formatting
MCUdude 98f0640
Improve print_available_serialports() function
MCUdude 7511a5d
Apply @stenfanruegers 0001-Refactor-serialadapter patch
MCUdude 8730fc1
Apply @stefanrueger's 0001-Sort-list-of-plugged-in-SERPORTs-according…
MCUdude 6694e98
Don't suggest usb:vid:pid for serial ports where vid is zero
MCUdude ba72908
Move str_endnumber() to strutil.c
MCUdude 28e6187
Implement and document -P ?s and -P ?sa
stefanrueger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| /* | ||
| * AVRDUDE - A Downloader/Uploader for AVR device programmers | ||
| * Copyright (C) 2023 Stefan Rueger <[email protected]> | ||
| * Copyright (C) 2023 Hans Eirik Bull | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
|
|
@@ -24,6 +25,137 @@ | |
| #include "avrdude.h" | ||
| #include "libavrdude.h" | ||
|
|
||
| #ifdef HAVE_LIBSERIALPORT | ||
|
|
||
| #include <libserialport.h> | ||
|
|
||
| int find_serialport_adapter(const SERIALADAPTER *ser, char *serport, char *sernum) { | ||
| int rv = -1; | ||
| /* A pointer to a null-terminated array of pointers to | ||
| * struct sp_port, which will contain the ports found */ | ||
| struct sp_port **port_list; | ||
|
|
||
| /* Call sp_list_ports() to get the ports. The port_list | ||
| * pointer will be updated to refer to the array created */ | ||
| enum sp_return result = sp_list_ports(&port_list); | ||
|
|
||
| if (result != SP_OK) { | ||
| pmsg_error("sp_list_ports() failed!\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| for (int i = 0; port_list[i]; i++) { | ||
| struct sp_port *prt = port_list[i]; | ||
| int usb_vid, usb_pid; | ||
| sp_get_port_usb_vid_pid(prt, &usb_vid, &usb_pid); | ||
|
|
||
| // USB VID match | ||
| if(usb_vid == ser->usbvid) { | ||
| for (LNODEID usbpid = lfirst(ser->usbpid); usbpid; usbpid = lnext(usbpid)) { | ||
| // USB PID match | ||
| if (usb_pid == *(int *)(ldata(usbpid))) { | ||
| // SN present | ||
| if (sernum && sernum[0]) { | ||
| // SN matches | ||
| char *s = sp_get_port_usb_serial(prt); | ||
| if(s) { | ||
| if (str_eq(sernum, s)) { | ||
| strcpy(serport, sp_get_port_name(prt)); | ||
| rv = 0; | ||
| } | ||
| } | ||
| // SN does not match | ||
| else { | ||
| continue; | ||
| } | ||
| } | ||
| // SN not present | ||
| else { | ||
| char *p = sp_get_port_name(prt); | ||
| if(p) { | ||
| strcpy(serport, p); | ||
| rv = 0; | ||
| } | ||
| else | ||
| rv = -1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| sp_free_port_list(port_list); // Free the array created by sp_list_ports() | ||
| return rv; | ||
| } | ||
|
|
||
| int find_serialport_vid_pid(char *serport, int vid, int pid, char *sernum) { | ||
| int rv = -1; | ||
| /* A pointer to a null-terminated array of pointers to | ||
| * struct sp_port, which will contain the ports found */ | ||
| struct sp_port **port_list; | ||
|
|
||
| /* Call sp_list_ports() to get the ports. The port_list | ||
| * pointer will be updated to refer to the array created */ | ||
| enum sp_return result = sp_list_ports(&port_list); | ||
|
|
||
| if (result != SP_OK) { | ||
| pmsg_error("sp_list_ports() failed!\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| for (int i = 0; port_list[i]; i++) { | ||
| struct sp_port *prt = port_list[i]; | ||
| int usb_vid, usb_pid; | ||
| sp_get_port_usb_vid_pid(prt, &usb_vid, &usb_pid); | ||
|
|
||
| // USB VID and PIDmatch | ||
| if(usb_vid == vid && usb_pid == pid) { | ||
| // SN present | ||
| if (sernum && sernum[0]) { | ||
| // SN matches | ||
| char *s = sp_get_port_usb_serial(prt); | ||
| if(s) { | ||
| if (str_eq(sernum, s)) { | ||
| strcpy(serport, sp_get_port_name(prt)); | ||
| rv = 0; | ||
| } | ||
| } | ||
| // SN does not match | ||
| else { | ||
| continue; | ||
| } | ||
| } | ||
| // SN not present | ||
| else { | ||
| char *p = sp_get_port_name(prt); | ||
| if(p) { | ||
| strcpy(serport, p); | ||
| rv = 0; | ||
| } | ||
| else | ||
| rv = -1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| sp_free_port_list(port_list); // Free the array created by sp_list_ports() | ||
| return rv; | ||
| } | ||
|
|
||
| #else | ||
|
|
||
| int find_serialport_adapter(const SERIALADAPTER *ser, char *port, char *sernum) { | ||
| pmsg_error("Avrdude built without libserialport support; please compile again with libserialport installed\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| int find_serialport_vid_pid(char *port, int vid, int pid, char *sernum) { | ||
| pmsg_error("Avrdude built without libserialport support; please compile again with libserialport installed\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| void list_serialadapters(FILE *fp, const char *prefix, LISTID programmers) { | ||
| LNODEID ln1, ln2, ln3; | ||
| SERIALADAPTER *sea; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we exit here? Say, there is a serialadapter
ch340inavrdude.conf.-P ch340checks if there is a serial adapterch340connected and does not find one. OK, rather then exiting, it could still allow the open() routine to open the filech340; after all it could be a symbolic link to an existing port for all we know