From a124a14b8d3013422ebf36f7e8f4ec550cfcd992 Mon Sep 17 00:00:00 2001 From: Chengxun Lee <24319042+bclswl0827@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:17:54 +0800 Subject: [PATCH] Optimize the serial port reading process --- CHANGELOG.md | 5 +++++ VERSION | 2 +- driver/serial/filter.go | 15 +++++++++++---- driver/serial/open.go | 6 +++--- feature/geophone/read.go | 2 +- feature/geophone/reset.go | 2 +- frontend/dist/asset-manifest.json | 4 ++-- frontend/dist/index.html | 2 +- frontend/dist/static/js/main.9e9bedf8.js | 2 -- frontend/dist/static/js/main.c4da8e75.js | 2 ++ ...s.LICENSE.txt => main.c4da8e75.js.LICENSE.txt} | 0 frontend/src/.env | 4 ++-- frontend/src/src/helpers/app/getRelease.tsx | 2 +- frontend/src/src/helpers/app/getVersion.tsx | 2 +- .../src/src/helpers/i18n/getCurrentLocale.tsx | 12 ++++++------ frontend/src/src/helpers/i18n/setUserLocale.tsx | 9 +++++++-- 16 files changed, 44 insertions(+), 27 deletions(-) delete mode 100644 frontend/dist/static/js/main.9e9bedf8.js create mode 100644 frontend/dist/static/js/main.c4da8e75.js rename frontend/dist/static/js/{main.9e9bedf8.js.LICENSE.txt => main.c4da8e75.js.LICENSE.txt} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac9a007a..2813d393 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Starting from v2.2.5, all notable changes to this project will be documented in this file. +## v2.12.2 + +- Always use fallback locale if the preferred locale is not available +- Optimize the serial port reading process + ## v2.12.1 - Sort earthquake event source API by name in frontend diff --git a/VERSION b/VERSION index ba6ff6bf..6f9cc441 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.12.1 +v2.12.2 diff --git a/driver/serial/filter.go b/driver/serial/filter.go index c04d1782..7dc473b7 100644 --- a/driver/serial/filter.go +++ b/driver/serial/filter.go @@ -4,16 +4,23 @@ import ( "bytes" "fmt" "io" + "math" + "time" ) -func Filter(port io.ReadWriteCloser, signature []byte, retry int) ([]byte, error) { +func Filter(port io.ReadWriteCloser, signature []byte) ([]byte, error) { header := make([]byte, len(signature)) - for i := 0; i < retry; i++ { - port.Read(header) + for i := 0; i < math.MaxUint8; i++ { + _, err := port.Read(header) + if err != nil { + return nil, err + } if bytes.Equal(header, signature) { - return nil, nil + return header, nil + } else { + time.Sleep(time.Millisecond) } } diff --git a/driver/serial/open.go b/driver/serial/open.go index 2b561b39..87319f25 100644 --- a/driver/serial/open.go +++ b/driver/serial/open.go @@ -8,11 +8,11 @@ import ( func Open(device string, baud int) (io.ReadWriteCloser, error) { port, err := serial.Open(device, - serial.WithHUPCL(false), + serial.WithHUPCL(true), serial.WithDataBits(8), serial.WithBaudrate(baud), - serial.WithReadTimeout(500), - serial.WithWriteTimeout(500), + serial.WithReadTimeout(5), + serial.WithWriteTimeout(5), serial.WithParity(serial.NoParity), serial.WithStopBits(serial.OneStopBit), ) diff --git a/feature/geophone/read.go b/feature/geophone/read.go index 98e00d17..3f74181f 100644 --- a/feature/geophone/read.go +++ b/feature/geophone/read.go @@ -11,7 +11,7 @@ import ( func (g *Geophone) Read(port io.ReadWriteCloser, conf *config.Conf, packet *Packet, packetLen int) error { // Filter frame header - _, err := serial.Filter(port, SYNC_WORD[:], 128) + _, err := serial.Filter(port, SYNC_WORD[:]) if err != nil { return err } diff --git a/feature/geophone/reset.go b/feature/geophone/reset.go index 11643458..d4fcd1ea 100644 --- a/feature/geophone/reset.go +++ b/feature/geophone/reset.go @@ -12,6 +12,6 @@ func (g *Geophone) Reset(port io.ReadWriteCloser) error { return err } - serial.Filter(port, ACK_WORD[:], 128) + serial.Filter(port, ACK_WORD[:]) return nil } diff --git a/frontend/dist/asset-manifest.json b/frontend/dist/asset-manifest.json index 983bdc69..298e4500 100644 --- a/frontend/dist/asset-manifest.json +++ b/frontend/dist/asset-manifest.json @@ -1,7 +1,7 @@ { "files": { "main.css": "./static/css/main.7a040865.css", - "main.js": "./static/js/main.9e9bedf8.js", + "main.js": "./static/js/main.c4da8e75.js", "static/css/594.d6bfd15f.chunk.css": "./static/css/594.d6bfd15f.chunk.css", "static/js/594.7755917b.chunk.js": "./static/js/594.7755917b.chunk.js", "static/js/846.88ce4ddb.chunk.js": "./static/js/846.88ce4ddb.chunk.js", @@ -49,6 +49,6 @@ }, "entrypoints": [ "static/css/main.7a040865.css", - "static/js/main.9e9bedf8.js" + "static/js/main.c4da8e75.js" ] } \ No newline at end of file diff --git a/frontend/dist/index.html b/frontend/dist/index.html index 5df88805..f3348aa2 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -1 +1 @@ -