Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Add season-23 debouncing #17

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cmd/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ package cmd
import (
"context"
"fmt"
"io"
"net"
"net/http"
"os"
"os/signal"
"strings"

"github.com/jakoblorz/autofone/constants"
"github.com/jakoblorz/autofone/packets/process"
"github.com/jakoblorz/autofone/packets/process/reader"
Expand All @@ -19,6 +12,12 @@ import (
"github.com/jakoblorz/autofone/pkg/streamdb"
"github.com/spf13/cobra"
"golang.org/x/net/websocket"
"io"
"net"
"net/http"
"os"
"os/signal"
"strings"
)

type snapshotWriter struct {
Expand Down Expand Up @@ -162,15 +161,16 @@ for the packet ids to select.
}()
go func() {
boltWriter := &writer.Bolt{
P: &stream,
Client: api,
DB: db,
P: &stream,
DB: db,
}
boltWriter.Motion = writer.NewMotionDebouncer(boltWriter, 0)
boltWriter.Lap = writer.NewPacketDebouncer(boltWriter, 0)
boltWriter.CarTelemetry = writer.NewPacketDebouncer(boltWriter, 0)
boltWriter.CarStatus = writer.NewPacketDebouncer(boltWriter, 0)
boltWriter.SessionHistory = writer.NewSessionHistoryDebouncer(boltWriter, 0)
boltWriter.TyreSets = writer.NewTyreSetsDebouncer(boltWriter, 0)
boltWriter.MotionEx = writer.NewMotionExDebouncer(boltWriter, 0)
defer boltWriter.Close()

for {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.16

require (
github.com/boltdb/bolt v1.3.1
github.com/boltdb/boltd v0.0.0-20150220181201-1f04e2021e45 // indirect
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf
github.com/jmoiron/sqlx v1.3.5
github.com/kr/text v0.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/boltdb/boltd v0.0.0-20150220181201-1f04e2021e45 h1:ep0QrTbZFgXa8e4lTAdd/NPY9ZiSP/ysDf26+UNPogo=
github.com/boltdb/boltd v0.0.0-20150220181201-1f04e2021e45/go.mod h1:512MO8jN3usqrPdyZ8YtG6vLsQ8wGV5W9cykDwCy1WI=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down
18 changes: 16 additions & 2 deletions packets/process/writer/bolt_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (
"github.com/boltdb/bolt"
"github.com/jakoblorz/autofone/constants"
"github.com/jakoblorz/autofone/packets/process"
"github.com/jakoblorz/autofone/pkg/privateapi"
"github.com/jakoblorz/autofone/pkg/streamdb"
"go.mongodb.org/mongo-driver/bson/primitive"
)

type Bolt struct {
*process.P
privateapi.Client

Motion *motionDebouncer
Lap *packetDebouncer
CarTelemetry *packetDebouncer
CarStatus *packetDebouncer
SessionHistory *sessionHistoryDebouncer
TyreSets *tyreSetsDebouncer
MotionEx *motionExDebouncer

DB streamdb.I
}
Expand All @@ -41,6 +41,12 @@ func (ch *Bolt) Close() error {
if ch.SessionHistory != nil {
ch.SessionHistory.Stop()
}
if ch.TyreSets != nil {
ch.TyreSets.Stop()
}
if ch.MotionEx != nil {
ch.MotionEx.timer.Stop()
}
return nil
}

Expand Down Expand Up @@ -82,5 +88,13 @@ func (ch *Bolt) Write(m *process.M) {
ch.SessionHistory.Write(m)
return
}
if ch.TyreSets != nil && m.Header.GetPacketID() == constants.PacketTyreSets {
ch.TyreSets.Write(m)
return
}
if ch.MotionEx != nil && m.Header.GetPacketID() == constants.PacketMotionEx {
ch.MotionEx.Write(m)
return
}
ch.write(m)
}
Loading