Skip to content

Commit

Permalink
Use time.Ticker to collect geophone counts by second
Browse files Browse the repository at this point in the history
  • Loading branch information
bclswl0827 committed May 4, 2024
1 parent a124a14 commit 1fe3bd6
Show file tree
Hide file tree
Showing 110 changed files with 4,557 additions and 4,389 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Starting from v2.2.5, all notable changes to this project will be documented in this file.

## v2.12.3

- Format frontend code using ESLint and Prettier
- Use `time.Ticker` to collect geophone counts by second

## v2.12.2

- Always use fallback locale if the preferred locale is not available
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.12.2
v2.12.3
2 changes: 1 addition & 1 deletion feature/archiver/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (a *Archiver) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou
os.Exit(1)
}
options.Database = pdb
defer dao.Close(pdb)

// Start cleanup routine if life cycle bigger than 0
lifeCycle := options.Config.MiniSEED.LifeCycle
Expand Down Expand Up @@ -75,5 +76,4 @@ func (a *Archiver) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou
// Wait for interrupt signals
<-sigCh
logger.Print(MODULE, "closing database connection", color.FgBlue, true)
dao.Close(pdb)
}
27 changes: 5 additions & 22 deletions feature/geophone/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package geophone

import (
"github.com/anyshake/observer/feature"
"github.com/anyshake/observer/utils/duration"
"github.com/anyshake/observer/utils/logger"
"github.com/anyshake/observer/utils/text"
"github.com/fatih/color"
Expand All @@ -17,34 +16,18 @@ func (g *Geophone) OnStop(options *feature.FeatureOptions, v ...any) {
}

func (g *Geophone) OnReady(options *feature.FeatureOptions, v ...any) {
if len(v) == 0 {
logger.Print(MODULE, "1 full packet received", color.FgGreen, false)
return
}
if !options.Status.ReadyTime.IsZero() {
var (
packet = v[0].(Packet)
currentTime, _ = duration.Timestamp(options.Status.System.Offset)
)

// Appending packet data to buffer
packet := v[0].(Packet)
for i := 0; i < options.Config.Serial.Packet; i++ {
options.Status.Buffer.EHZ = append(options.Status.Buffer.EHZ, packet.EHZ[i])
options.Status.Buffer.EHE = append(options.Status.Buffer.EHE, packet.EHE[i])
options.Status.Buffer.EHN = append(options.Status.Buffer.EHN, packet.EHN[i])
}

// Archive approximately 1 second has passed
timeDiff := duration.Difference(currentTime, options.Status.LastRecvTime)
if timeDiff >= READY_THRESHOLD {
// Set packet timestamp, note that the timestamp in buffer is the start of the packet
options.Status.Buffer.TS = currentTime.UnixMilli() - timeDiff.Milliseconds()
// Set last received time is the current timestamp
options.Status.LastRecvTime = currentTime
options.Status.System.Messages++
// Copy buffer and reset
options.Status.Geophone = *options.Status.Buffer
options.Status.Buffer.EHZ = []int32{}
options.Status.Buffer.EHE = []int32{}
options.Status.Buffer.EHN = []int32{}
logger.Print(MODULE, "1 full packet received", color.FgGreen, false)
}
} else {
logger.Print(MODULE, "waiting for time alignment", color.FgYellow, false)
}
Expand Down
22 changes: 21 additions & 1 deletion feature/geophone/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func (g *Geophone) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou
}
defer serial.Close(port)

g.Ticker = time.NewTicker(READY_THRESHOLD)
defer g.Ticker.Stop()

go func() {
// Initialize geophone packet
var packet Packet
Expand Down Expand Up @@ -80,12 +83,29 @@ func (g *Geophone) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou
}
}()

go func() {
for {
<-g.Ticker.C
currentTime, _ := duration.Timestamp(options.Status.System.Offset)
// Set packet timestamp, note that the timestamp in buffer is the start of the packet
options.Status.Buffer.TS = currentTime.UnixMilli() - time.Second.Milliseconds()
// Set last received time is the current timestamp
options.Status.LastRecvTime = currentTime
options.Status.System.Messages++
// Copy and reset buffer
options.Status.Geophone = *options.Status.Buffer
options.Status.Buffer.EHZ = []int32{}
options.Status.Buffer.EHE = []int32{}
options.Status.Buffer.EHN = []int32{}
g.OnReady(options)
}
}()

// Receive interrupt signals
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)

// Wait for interrupt signals
<-sigCh
g.OnStop(options, "closing serial connection")
serial.Close(port)
}
4 changes: 3 additions & 1 deletion feature/geophone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ var (
ACK_WORD = [...]byte{0xFC, 0x2B}
)

type Geophone struct{}
type Geophone struct {
Ticker *time.Ticker
}

type Packet struct {
EHZ []int32 // Vertical
Expand Down
2 changes: 1 addition & 1 deletion feature/seedlink/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *SeedLink) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou
s.OnError(options, err)
return
}
defer slGlobal.SeedLinkBuffer.Database.Close()

// Accept incoming connections
s.OnStart(options, "service has started")
Expand Down Expand Up @@ -79,5 +80,4 @@ func (s *SeedLink) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou
// Wait for interrupt signals
<-sigCh
logger.Print(MODULE, "closing buffer area", color.FgBlue, true)
slGlobal.SeedLinkBuffer.Database.Close()
}
14 changes: 7 additions & 7 deletions frontend/dist/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"files": {
"main.css": "./static/css/main.7a040865.css",
"main.js": "./static/js/main.c4da8e75.js",
"main.js": "./static/js/main.b9d5c092.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",
"static/js/154.cebd5677.chunk.js": "./static/js/154.cebd5677.chunk.js",
"static/js/600.23a606ea.chunk.js": "./static/js/600.23a606ea.chunk.js",
"static/js/708.22872728.chunk.js": "./static/js/708.22872728.chunk.js",
"static/js/594.ccfa0385.chunk.js": "./static/js/594.ccfa0385.chunk.js",
"static/js/846.45094087.chunk.js": "./static/js/846.45094087.chunk.js",
"static/js/154.13af8e6a.chunk.js": "./static/js/154.13af8e6a.chunk.js",
"static/js/600.140630e8.chunk.js": "./static/js/600.140630e8.chunk.js",
"static/js/708.26ef62d2.chunk.js": "./static/js/708.26ef62d2.chunk.js",
"static/js/699.e75d4402.chunk.js": "./static/js/699.e75d4402.chunk.js",
"static/js/303.28dd2180.chunk.js": "./static/js/303.28dd2180.chunk.js",
"static/js/548.b98bfbf6.chunk.js": "./static/js/548.b98bfbf6.chunk.js",
Expand Down Expand Up @@ -49,6 +49,6 @@
},
"entrypoints": [
"static/css/main.7a040865.css",
"static/js/main.c4da8e75.js"
"static/js/main.b9d5c092.js"
]
}
2 changes: 1 addition & 1 deletion frontend/dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><style>.public-loading{width:100%;height:100%;display:flex;position:fixed;align-items:center;flex-direction:column;justify-content:center}.public-loading span{color:#1f2937;margin-top:20px;font-weight:600;font-size:1.25rem}.public-loading svg{animation:rotate 1s linear infinite}@keyframes rotate{100%{transform:rotate(360deg)}}</style><script defer="defer" src="./static/js/main.c4da8e75.js"></script><link href="./static/css/main.7a040865.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div class="public-loading"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="#6b21a8" width="70px"><path d="M304 48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zm0 416a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM48 304a48 48 0 1 0 0-96 48 48 0 1 0 0 96zm464-48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM142.9 437A48 48 0 1 0 75 369.1 48 48 0 1 0 142.9 437zm0-294.2A48 48 0 1 0 75 75a48 48 0 1 0 67.9 67.9zM369.1 437A48 48 0 1 0 437 369.1 48 48 0 1 0 369.1 437z"/></svg> <span>Loading...</span></div><div id="root"></div></body></html>
<!doctype html><html><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><style>.public-loading{width:100%;height:100%;display:flex;position:fixed;align-items:center;flex-direction:column;justify-content:center}.public-loading span{color:#1f2937;margin-top:20px;font-weight:600;font-size:1.25rem}.public-loading svg{animation:rotate 1s linear infinite}@keyframes rotate{100%{transform:rotate(360deg)}}</style><script defer="defer" src="./static/js/main.b9d5c092.js"></script><link href="./static/css/main.7a040865.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div class="public-loading"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="#6b21a8" width="70px"><path d="M304 48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zm0 416a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM48 304a48 48 0 1 0 0-96 48 48 0 1 0 0 96zm464-48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM142.9 437A48 48 0 1 0 75 369.1 48 48 0 1 0 142.9 437zm0-294.2A48 48 0 1 0 75 75a48 48 0 1 0 67.9 67.9zM369.1 437A48 48 0 1 0 437 369.1 48 48 0 1 0 369.1 437z"/></svg> <span>Loading...</span></div><div id="root"></div></body></html>
1 change: 1 addition & 0 deletions frontend/dist/static/js/154.13af8e6a.chunk.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion frontend/dist/static/js/154.cebd5677.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion frontend/dist/static/js/594.7755917b.chunk.js

This file was deleted.

Loading

0 comments on commit 1fe3bd6

Please sign in to comment.