From 862151cea6fb794b03568da9af2738e0db3f0858 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Sun, 21 Feb 2016 14:02:57 -0600 Subject: [PATCH] regex updates and device fix --- main/sdr.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/main/sdr.go b/main/sdr.go index ec2c3ed4..998d85dc 100644 --- a/main/sdr.go +++ b/main/sdr.go @@ -34,13 +34,8 @@ type Device struct { hasID bool } -type UAT struct { - Device -} - -type ES struct { - Device -} +type UAT Device +type ES Device var UATDev *UAT var ESDev *ES @@ -316,31 +311,36 @@ func sdrKill() { } } -type rUAT regexp.Regexp +func reCompile(s string) *regexp.Regexp { + // Compile returns a nil pointer when there's an error + r, _ := regexp.Compile(s) + return r +} + +type regexUAT regexp.Regexp + +var rUAT = (*regexUAT)(reCompile("str?a?t?u?x:978")) func (r *rUAT) hasID(serial string) bool { if r == nil { return strings.HasPrefix(serial, "stratux:978") } - return r.MatchString(serial) + return (*regexp.Regexp)(r).MatchString(serial) } -type rES regexp.Regexp +type regexES regexp.Regexp + +var rES = (*regexUAT)(reCompile("str?a?t?u?x:1090")) func (r *rES) hasID(serial string) bool { if r == nil { return strings.HasPrefix(serial, "stratux:1090") } - return r.MatchString(serial) + return (*regexp.Regexp)(r).MatchString(serial) } // Watch for config/device changes. func sdrWatcher() { - // Compile returns a nil pointer when it fails and - // we do the nil check in the hasID method - rES, _ = regexp.Compile("str?a?t?u?x:1090") - rUAT, _ = regexp.Compile("str?a?t?u?x:978") - for { time.Sleep(1 * time.Second) if sdrShutdown {