Skip to content

Commit

Permalink
Re-support for the SeedLink protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
bclswl0827 committed Aug 25, 2024
1 parent 01429d8 commit 46d00b1
Show file tree
Hide file tree
Showing 31 changed files with 624 additions and 81 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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

## v3.1.0

### New Features

- Added support for forwarding raw messages via TCP.
- Re-support for the SeedLink protocol.
- Updated Go version to v1.23.0.
- Updated Gin version to v1.10.0.

## v3.0.5

### New Features
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.0.5
v3.1.0
2 changes: 1 addition & 1 deletion api/v1/socket/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *Socket) Register(rg *gin.RouterGroup, resolver *v1.Resolver) error {
logger.GetLogger(s.GetApiName()).Errorln(err)
return
}
defer s.Unsubscribe(clienrId)
defer s.unsubscribe(clienrId)

// Listen for incoming messages
for {
Expand Down
2 changes: 1 addition & 1 deletion api/v1/socket/unsubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
)

func (s *Socket) Unsubscribe(clientId string) error {
func (s *Socket) unsubscribe(clientId string) error {
fn, ok := s.subscribers.Get(clientId)
if !ok {
return errors.New("this client has not subscribed")
Expand Down
28 changes: 14 additions & 14 deletions api/v2/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/v2/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
scalar Int64

type Query {
test: Boolean
ping: String
}
8 changes: 4 additions & 4 deletions api/v2/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion build/assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"explorer_settings": {
"dsn": "transport:///dev/ttyUSB0?baudrate=115200",
"engine": "serial",
"legacy": true
"legacy": false
},
"sensor_settings": {
"frequency": 4.5,
Expand Down Expand Up @@ -62,6 +62,16 @@
"archiver": {
"enable": true,
"lifecycle": 10
},
"forwarder": {
"enable": true,
"host": "0.0.0.0",
"port": 30000
},
"seedlink": {
"enable": true,
"host": "0.0.0.0",
"port": 18000
}
}
}
4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"github.com/anyshake/observer/services"
service_archiver "github.com/anyshake/observer/services/archiver"

service_forwarder "github.com/anyshake/observer/services/forwarder"
service_miniseed "github.com/anyshake/observer/services/miniseed"
service_seedlink "github.com/anyshake/observer/services/seedlink"
service_timesync "github.com/anyshake/observer/services/timesync"
service_watchdog "github.com/anyshake/observer/services/watchdog"
"github.com/anyshake/observer/startups"
Expand Down Expand Up @@ -177,6 +179,8 @@ func main() {
&service_archiver.ArchiverService{},
&service_miniseed.MiniSeedService{},
&service_timesync.TimeSyncService{},
&service_seedlink.SeedLinkService{},
&service_forwarder.ForwarderService{},
}
serviceOptions := &services.Options{
Config: &conf,
Expand Down
36 changes: 17 additions & 19 deletions drivers/explorer/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,22 @@ func (g *legacyPacket) decode(data []byte) error {

// Using XOR algorithm
calc_checksum := [3]uint8{0, 0, 0}
z_axis_offset := 0
e_axis_offset := int(unsafe.Sizeof(int32(0)) * legacy_packet_channel_size)
n_axis_offset := int(unsafe.Sizeof(int32(0)) * legacy_packet_channel_size * 2)
for i := z_axis_offset; i < e_axis_offset; i++ {
z_axis_offset := int(unsafe.Sizeof(g.Z_Axis))
for i := 0; i < z_axis_offset; i++ {
calc_checksum[0] ^= data[i]
}
for i := e_axis_offset; i < n_axis_offset; i++ {
e_axis_offset := z_axis_offset + int(unsafe.Sizeof(g.E_Axis))
for i := z_axis_offset; i < e_axis_offset; i++ {
calc_checksum[1] ^= data[i]
}
for i := e_axis_offset; i < len(data)-int(unsafe.Sizeof([3]uint8{})); i++ {
n_axis_offset := e_axis_offset + int(unsafe.Sizeof(g.N_Axis))
for i := e_axis_offset; i < n_axis_offset; i++ {
calc_checksum[2] ^= data[i]
}
if bytes.Equal(g.Checksum[:], calc_checksum[:]) {
return fmt.Errorf("checksum mismatch, expected %v, got %v", g.Checksum, calc_checksum)
for i := 0; i < len(calc_checksum); i++ {
if calc_checksum[i] != g.Checksum[i] {
return fmt.Errorf("checksum mismatch, expected %v, got %v", g.Checksum, calc_checksum)
}
}

return nil
Expand Down Expand Up @@ -123,7 +125,7 @@ type mainlinePacketChannel struct {

func (g *mainlinePacketChannel) length(sampleRate int) int {
return 3*sampleRate*int(unsafe.Sizeof(int32(0))) + // Z, E, N axis data
int(unsafe.Sizeof(uint32(0))) // Checksum of Z, E, N axis
int(unsafe.Sizeof(g.checksum)) // Checksum of Z, E, N axis
}

func (g *mainlinePacketChannel) decode(data []byte, sampleRate int) error {
Expand Down Expand Up @@ -198,11 +200,11 @@ type ExplorerDriverImpl struct {
}

func (e *ExplorerDriverImpl) handleReadLegacyPacket(deps *ExplorerDependency) {
fifoBuffer := fifo.New(16384)
fifoBuffer := fifo.New(e.legacyPacket.length() * 512)

// Read data from the transport continuously
go func() {
buf := make([]byte, 1024)
buf := make([]byte, e.legacyPacket.length())
for {
select {
case <-deps.CancelToken.Done():
Expand All @@ -218,7 +220,7 @@ func (e *ExplorerDriverImpl) handleReadLegacyPacket(deps *ExplorerDependency) {
}
}()

// reference: https://stackoverflow.com/a/51424566
// Reference: https://stackoverflow.com/a/51424566
// Calculate the duration to the next whole second to allivate the drift
calcDuration := func(currentTime time.Time, duration time.Duration) time.Duration {
return currentTime.Round(duration).Add(duration).Sub(currentTime)
Expand Down Expand Up @@ -268,13 +270,9 @@ func (e *ExplorerDriverImpl) handleReadLegacyPacket(deps *ExplorerDependency) {

ticker.Reset(calcDuration(currentTick, time.Second))
}
case <-time.After(2 * time.Millisecond):
for {
dat, err := fifoBuffer.Read(legacy_packet_frame_header, len(legacy_packet_frame_header)+e.legacyPacket.length())
if err != nil {
break
}

case <-time.After(500 * time.Microsecond):
dat, err := fifoBuffer.Read(legacy_packet_frame_header, len(legacy_packet_frame_header)+e.legacyPacket.length())
if err == nil {
// Read the packet data
err = e.legacyPacket.decode(dat[len(legacy_packet_frame_header):])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion drivers/explorer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
messagebus "github.com/vardius/message-bus"
)

const EXPLORER_ALLOWED_JITTER_MS = 2
const EXPLORER_ALLOWED_JITTER_MS = 5

const (
EXPLORER_CHANNEL_CODE_Z = "Z"
Expand Down
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=v3.0.5
REACT_APP_RELEASE=0e50a2dc-20240822174555
REACT_APP_VERSION=v3.1.0
REACT_APP_RELEASE=01429d85-20240825141612
22 changes: 13 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/anyshake/observer

go 1.21.5
go 1.23.0

require (
github.com/99designs/gqlgen v0.17.49
Expand All @@ -9,11 +9,12 @@ require (
github.com/bclswl0827/go-serial v0.0.1
github.com/bclswl0827/mseedio v1.0.9
github.com/bclswl0827/sacio v1.0.6
github.com/bclswl0827/slgo v0.0.3
github.com/bclswl0827/sqlite v1.11.1-0.20240613172512-9e6ac9861470
github.com/beevik/ntp v1.4.3
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be
github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.9.0
github.com/gin-gonic/gin v1.10.0
github.com/gorilla/websocket v1.5.0
github.com/juju/ratelimit v1.0.2
github.com/mackerelio/go-osstat v0.2.5
Expand Down Expand Up @@ -69,6 +70,10 @@ require (
require (
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/clbanning/anyxml v1.2.2 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -80,26 +85,25 @@ require (
)

require (
github.com/bytedance/sonic v1.8.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/creack/goselect v0.1.3-0.20221130125424-8eac7f782437 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0
github.com/goccy/go-json v0.10.0 // indirect
github.com/go-playground/validator/v10 v10.20.0
github.com/goccy/go-json v0.10.2 // indirect
github.com/json-iterator/go v1.1.12
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
Expand Down
Loading

0 comments on commit 46d00b1

Please sign in to comment.