Precompile port-filter regexp
This commit is contained in:
@@ -6,10 +6,15 @@
|
|||||||
|
|
||||||
package serial
|
package serial
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
import (
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
const devFolder = "/dev"
|
const devFolder = "/dev"
|
||||||
const regexFilter = "^(cu|tty)\\..*"
|
|
||||||
|
var osPortFiler = regexp.MustCompile("^(cu|tty)\\..*")
|
||||||
|
|
||||||
const ioctlTcgetattr = unix.TIOCGETA
|
const ioctlTcgetattr = unix.TIOCGETA
|
||||||
const ioctlTcsetattr = unix.TIOCSETA
|
const ioctlTcsetattr = unix.TIOCSETA
|
||||||
|
|||||||
@@ -6,10 +6,15 @@
|
|||||||
|
|
||||||
package serial
|
package serial
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
import (
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
const devFolder = "/dev"
|
const devFolder = "/dev"
|
||||||
const regexFilter = "^(cu|tty)\\..*"
|
|
||||||
|
var osPortFiler = regexp.MustCompile("^(cu|tty)\\..*")
|
||||||
|
|
||||||
// termios manipulation functions
|
// termios manipulation functions
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,15 @@
|
|||||||
|
|
||||||
package serial
|
package serial
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
import (
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
const devFolder = "/dev"
|
const devFolder = "/dev"
|
||||||
const regexFilter = "(ttyS|ttyHS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO|ttymxc)[0-9]{1,3}"
|
|
||||||
|
var osPortFilter = regexp.MustCompile("(ttyS|ttyHS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO|ttymxc)[0-9]{1,3}")
|
||||||
|
|
||||||
// termios manipulation functions
|
// termios manipulation functions
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,15 @@
|
|||||||
|
|
||||||
package serial
|
package serial
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
import (
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
const devFolder = "/dev"
|
const devFolder = "/dev"
|
||||||
const regexFilter = "^(cu|tty)\\..*"
|
|
||||||
|
var osPortFiler = regexp.MustCompile("^(cu|tty)\\..*")
|
||||||
|
|
||||||
// termios manipulation functions
|
// termios manipulation functions
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ package serial
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -298,10 +297,6 @@ func nativeGetPortsList() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ports := make([]string, 0, len(files))
|
ports := make([]string, 0, len(files))
|
||||||
regex, err := regexp.Compile(regexFilter)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
// Skip folders
|
// Skip folders
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
@@ -309,7 +304,7 @@ func nativeGetPortsList() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Keep only devices with the correct name
|
// Keep only devices with the correct name
|
||||||
if !regex.MatchString(f.Name()) {
|
if !osPortFilter.MatchString(f.Name()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user