clean up dead code

This commit is contained in:
saji 2024-02-28 14:01:44 -06:00
parent c95593bb86
commit 9a98117384
3 changed files with 1 additions and 113 deletions

View file

@ -15,8 +15,6 @@ var subCmds = []*cli.Command{
xbeeCmd, xbeeCmd,
} }
var f os.File
func Execute() { func Execute() {
app := &cli.App{ app := &cli.App{
Name: "gotelem", Name: "gotelem",

View file

@ -4,11 +4,9 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"net"
"net/http" "net/http"
"os" "os"
"sync" "sync"
"time"
"log/slog" "log/slog"
@ -134,108 +132,6 @@ func serve(cCtx *cli.Context) error {
return nil return nil
} }
type rpcService struct {
}
func (r *rpcService) Status() {
}
func (r *rpcService) String() string {
return "rpcService"
}
func (r *rpcService) Start(ctx *cli.Context, deps svcDeps) error {
logger := deps.Logger
broker := deps.Broker
// TODO: extract port/ip from cli context.
ln, err := net.Listen("tcp", "0.0.0.0:8082")
if err != nil {
logger.Warn("error listening", "err", err)
return err
}
for {
conn, err := ln.Accept()
if err != nil {
logger.Warn("error accepting connection", "err", err)
}
go handleCon(conn, broker, logger.With("addr", conn.RemoteAddr()), ctx.Done())
}
}
func handleCon(conn net.Conn, broker *gotelem.Broker, l *slog.Logger, done <-chan struct{}) {
subname := fmt.Sprint("tcp", conn.RemoteAddr().String())
l.Info("started handling", "name", subname)
defer conn.Close()
rxCh, err := broker.Subscribe(subname)
if err != nil {
l.Error("error subscribing to connection", "err", err)
return
}
defer broker.Unsubscribe(subname)
jEncode := json.NewEncoder(conn)
for {
select {
case msg := <-rxCh:
l.Info("got packet")
// FIXME: poorly optimized
err := jEncode.Encode(msg)
if err != nil {
l.Warn("error encoding json", "err", err)
}
case <-done:
return
}
}
}
// this spins up a new can socket on vcan0 and broadcasts a packet every second. for testing.
type canLoggerService struct {
}
func (c *canLoggerService) String() string {
return "CanLoggerService"
}
func (c *canLoggerService) Status() {
}
func (c *canLoggerService) Start(cCtx *cli.Context, deps svcDeps) (err error) {
broker := deps.Broker
l := deps.Logger
rxCh, err := broker.Subscribe("canDump")
if err != nil {
return err
}
t := time.Now()
fname := fmt.Sprintf("candump_%d-%02d-%02dT%02d.%02d.%02d.txt",
t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
l.Info("logging to file", "filename", fname)
f, err := os.Create(fname)
if err != nil {
l.Error("error opening file", "filename", fname, "err", err)
return
}
enc := json.NewEncoder(f)
for {
select {
case msg := <-rxCh:
enc.Encode(msg)
case <-cCtx.Done():
f.Close()
return
}
}
}
// xBeeService provides data over an Xbee device, either by serial or TCP // xBeeService provides data over an Xbee device, either by serial or TCP
// based on the url provided in the xbee flag. see the description for details. // based on the url provided in the xbee flag. see the description for details.

View file

@ -4,7 +4,6 @@ package db
import ( import (
"context" "context"
"database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "strings"
@ -12,14 +11,9 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/kschamplin/gotelem/skylab" "github.com/kschamplin/gotelem/skylab"
sqlite3 "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )
func init() {
sql.Register("custom_sqlite3", &sqlite3.SQLiteDriver{
// TODO: add helper that convert between unix milliseconds and sqlite times?
})
}
type TelemDb struct { type TelemDb struct {
db *sqlx.DB db *sqlx.DB