Skip to content

Commit

Permalink
Prepare for compensation, fix velocity unit
Browse files Browse the repository at this point in the history
  • Loading branch information
bclswl0827 committed Sep 26, 2023
1 parent 7582838 commit 71cb9f3
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish release

on:
push:
tags:
branches:
- master

workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.1.5p
v2.1.6p
6 changes: 3 additions & 3 deletions app/station/geophone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "github.com/bclswl0827/observer/config"

func getGeophone(conf *config.Conf) Geophone {
return Geophone{
EHZ: conf.Geophone.EHZ,
EHE: conf.Geophone.EHE,
EHN: conf.Geophone.EHN,
EHZ: conf.Geophone.EHZ.Sensitivity,
EHE: conf.Geophone.EHE.Sensitivity,
EHN: conf.Geophone.EHN.Sensitivity,
}
}
26 changes: 19 additions & 7 deletions build/assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@
"longitude": 1.0,
"altitude": 0
},
"geophone_settings": {
"ehz": {
"sensitivity": 0.288,
"damping": 0.6,
"frequency": 4.5
},
"ehe": {
"sensitivity": 0.288,
"damping": 0.6,
"frequency": 4.5
},
"ehn": {
"sensitivity": 0.288,
"damping": 0.6,
"frequency": 4.5
}
},
"adc_settings": {
"resolution": 24,
"fullscale": 5.0
},
"serial_settings": {
"packet": 2,
"packet": 4,
"baud": 19200,
"device": "/dev/ttyUSB0"
},
"geophone_settings": {
"ehz": 0.288,
"ehe": 0.288,
"ehn": 0.288
"device": "/dev/ttyS4"
},
"ntpclient_settings": {
"host": "0.pool.ntp.org",
Expand Down
12 changes: 9 additions & 3 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ type adc struct {
Resolution int `json:"resolution"`
}

type channel struct {
Damping float64 `json:"damping"`
Frequency float64 `json:"frequency"`
Sensitivity float64 `json:"sensitivity"`
}

type geophone struct {
EHZ float64 `json:"ehz"`
EHE float64 `json:"ehe"`
EHN float64 `json:"ehn"`
EHZ channel `json:"ehz"`
EHE channel `json:"ehe"`
EHN channel `json:"ehn"`
}

type ntpclient struct {
Expand Down
4 changes: 2 additions & 2 deletions feature/geophone/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (g *Geophone) OnStop(options *feature.FeatureOptions, v ...any) {
logger.Print(MODULE, text.Concat(v...), color.FgBlue)
}

func (a *Geophone) OnReady(options *feature.FeatureOptions, v ...any) {
func (g *Geophone) OnReady(options *feature.FeatureOptions, v ...any) {
if options.Status.IsReady {
var (
packet = v[0].(Packet)
Expand All @@ -39,12 +39,12 @@ func (a *Geophone) OnReady(options *feature.FeatureOptions, v ...any) {
// Set packet timestamp
options.Status.System.Messages++
options.Status.Buffer.TS = currentTime.UnixMilli()
logger.Print(MODULE, "1 full packet received", color.FgGreen)
// 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)
}
} else {
logger.Print(MODULE, "waiting for time alignment", color.FgYellow)
Expand Down
11 changes: 10 additions & 1 deletion feature/geophone/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (

func (g *Geophone) Start(options *feature.FeatureOptions) {
var (
ehz = options.Config.Geophone.EHZ
ehe = options.Config.Geophone.EHE
ehn = options.Config.Geophone.EHN
device = options.Config.Serial.Device
baud = options.Config.Serial.Baud
packetLen = options.Config.Serial.Packet
Expand All @@ -24,12 +27,18 @@ func (g *Geophone) Start(options *feature.FeatureOptions) {
}
defer serial.Close(port)

var (
ehzFilter = g.getFilter(ehz.Sensitivity, ehz.Frequency, ehz.Damping)
eheFilter = g.getFilter(ehe.Sensitivity, ehe.Frequency, ehe.Damping)
ehnFilter = g.getFilter(ehn.Sensitivity, ehn.Frequency, ehn.Damping)
)

var packet Packet
g.OnStart(options, "service has started")

lastRead := time.Now().UTC()
for {
err := g.Read(port, &packet, packetLen)
err := g.Read(port, &packet, packetLen, ehzFilter, eheFilter, ehnFilter)
if err != nil {
serial.Close(port)
g.OnError(options, err)
Expand Down
25 changes: 25 additions & 0 deletions feature/geophone/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package geophone

func (g *Geophone) getFilter(sensitivity, frequency, damping float64) *Filter {
return nil
}

func (g *Geophone) Filter(xValues []int32, filter *Filter) []int32 {
x := make([]float64, len(xValues))
for i, v := range xValues {
x[i] = float64(v)
}

y := []float64{x[0], x[1]}
for i := 2; i < len(xValues); i++ {
yNext := filter.a1*y[i-1] + filter.a2*y[i-2] + filter.b0*x[i] + filter.b1*x[i-1] + filter.b2*x[i-2]
y = append(y, yNext)
}

yValues := make([]int32, len(y))
for i, v := range y {
yValues[i] = int32(v)
}

return yValues
}
14 changes: 5 additions & 9 deletions feature/geophone/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ import (
"bytes"
"encoding/binary"
"io"
"time"

"github.com/bclswl0827/observer/driver/serial"
)

func (g *Geophone) Read(port io.ReadWriteCloser, packet *Packet, packetLen int) error {
func (g *Geophone) Read(port io.ReadWriteCloser, packet *Packet, packetLen int, ehzFilter, eheFilter, ehnFilter *Filter) error {
// Filter frame header
_, err := serial.Filter(port, SYNC_WORD[:], 16)
_, err := serial.Filter(port, SYNC_WORD[:], 128)
if err != nil {
return err
}

// checksumLen * (uint8 + int32 * packetLen) + uint8
checksumLen := len(packet.Checksum)
packetSize := checksumLen*(1+4*packetLen) + 1

// Read data frame
buf := make([]byte, packetSize)
n, err := serial.Read(port, buf, 5*time.Second)
checksumLen := len(packet.Checksum)
buf := make([]byte, g.getSize(packetLen, checksumLen))
n, err := serial.Read(port, buf, TIMEOUT_THRESHOLD)
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions feature/geophone/size.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package geophone

func (g *Geophone) getSize(packetLen, checksumLen int) int {
// channelLen*packetLen*int32 + checksumLen + 1
return checksumLen*packetLen*4 + checksumLen + 1
}
15 changes: 15 additions & 0 deletions feature/geophone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const (
TIMEOUT_THRESHOLD time.Duration = 3 * time.Second
)

const (
// TARGET_DAMPING is the target damping ratio
TARGET_DAMPING float64 = 0.707
// TARGET_FREQUENCY is the target frequency
TARGET_FREQUENCY float64 = 0.1
)

var (
// RESET_WORD resets geophone ADC module
RESET_WORD = [...]byte{0x61}
Expand All @@ -28,3 +35,11 @@ type Packet struct {
EHN []int32 // North-South
Checksum [3]uint8
}

type Filter struct {
a1 float64
a2 float64
b0 float64
b1 float64
b2 float64
}
4 changes: 2 additions & 2 deletions frontend/dist/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "/static/css/main.6306a3a5.css",
"main.js": "/static/js/main.8eb19dec.js",
"main.js": "/static/js/main.373d84f0.js",
"static/css/10.525e2941.chunk.css": "/static/css/10.525e2941.chunk.css",
"static/js/10.acbbbcaf.chunk.js": "/static/js/10.acbbbcaf.chunk.js",
"static/js/311.a3ecb2f6.chunk.js": "/static/js/311.a3ecb2f6.chunk.js",
Expand Down Expand Up @@ -41,6 +41,6 @@
},
"entrypoints": [
"static/css/main.6306a3a5.css",
"static/js/main.8eb19dec.js"
"static/js/main.373d84f0.js"
]
}
6 changes: 3 additions & 3 deletions frontend/dist/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
"areas": {
"ehz": {
"label": "EHZ Channel Waveform Count",
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} cm/s\nIntensity: {{ intensity }}"
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} kine\nIntensity: {{ intensity }}"
},
"ehe": {
"label": "EHE Channel Waveform Count",
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} cm/s\nIntensity: {{ intensity }}"
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} kine\nIntensity: {{ intensity }}"
},
"ehn": {
"label": "EHN Channel Waveform Count",
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} cm/s\nIntensity: {{ intensity }}"
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} kine\nIntensity: {{ intensity }}"
}
},
"toasts": {
Expand Down
6 changes: 3 additions & 3 deletions frontend/dist/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
"areas": {
"ehz": {
"label": "EHZ 通道波形计数",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
},
"ehe": {
"label": "EHE 通道波形计数",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
},
"ehn": {
"label": "EHN 通道波形计数",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
}
},
"toasts": {
Expand Down
6 changes: 3 additions & 3 deletions frontend/dist/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
"areas": {
"ehz": {
"label": "EHZ 通道波形計數",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
},
"ehe": {
"label": "EHE 通道波形計數",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
},
"ehn": {
"label": "EHN 通道波形計數",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
}
},
"toasts": {
Expand Down
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"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><link rel="icon" href="/favicon.ico"/><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.8eb19dec.js"></script><link href="/static/css/main.6306a3a5.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><link rel="icon" href="/favicon.ico"/><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.373d84f0.js"></script><link href="/static/css/main.6306a3a5.css" rel="stylesheet"></head><body><div id="root"></div></body></html>

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/src/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REACT_APP_VERSION=v2.1.5p
REACT_APP_RELEASE=9365d454-20230924200350
REACT_APP_VERSION=v2.1.6p
REACT_APP_RELEASE=7582838d-20230926132235
6 changes: 3 additions & 3 deletions frontend/src/public/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
"areas": {
"ehz": {
"label": "EHZ Channel Waveform Count",
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} cm/s\nIntensity: {{ intensity }}"
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} kine\nIntensity: {{ intensity }}"
},
"ehe": {
"label": "EHE Channel Waveform Count",
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} cm/s\nIntensity: {{ intensity }}"
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} kine\nIntensity: {{ intensity }}"
},
"ehn": {
"label": "EHN Channel Waveform Count",
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} cm/s\nIntensity: {{ intensity }}"
"text": "PGA: {{ pga }} gal\nPGV: {{ pgv }} kine\nIntensity: {{ intensity }}"
}
},
"toasts": {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/public/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
"areas": {
"ehz": {
"label": "EHZ 通道波形计数",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
},
"ehe": {
"label": "EHE 通道波形计数",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
},
"ehn": {
"label": "EHN 通道波形计数",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
}
},
"toasts": {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/public/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
"areas": {
"ehz": {
"label": "EHZ 通道波形計數",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
},
"ehe": {
"label": "EHE 通道波形計數",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
},
"ehn": {
"label": "EHN 通道波形計數",
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} cm/s\n震度:{{ intensity }}"
"text": "PGA:{{ pga }} gal\nPGV:{{ pgv }} kine\n震度:{{ intensity }}"
}
},
"toasts": {
Expand Down

0 comments on commit 71cb9f3

Please sign in to comment.