diff --git a/cmd/gotelem/cli/server.go b/cmd/gotelem/cli/server.go index 061f201..713e3f2 100644 --- a/cmd/gotelem/cli/server.go +++ b/cmd/gotelem/cli/server.go @@ -274,16 +274,21 @@ func (x *xBeeService) Start(cCtx *cli.Context, deps svcDeps) (err error) { } logger.Info("connected to local xbee", "addr", x.session.LocalAddr()) - writeJSON := json.NewEncoder(x.session) - xbeePackets := make(chan skylab.BusEvent) - go func(){ - decoder := json.NewDecoder(x.session) + // these are the ways we send/recieve data. we could swap for binary format + // TODO: buffering and/or binary encoding instead of json which is horribly ineffective. + xbeeTxer := json.NewEncoder(x.session) + xbeeRxer := json.NewDecoder(x.session) + + // xbeePackets := make(chan skylab.BusEvent) + // background task to read json packets off of the xbee and send them to the + go func() { for { var p skylab.BusEvent - err := decoder.Decode(&p) + err := xbeeRxer.Decode(&p) if err != nil { logger.Error("failed to decode xbee packet") } + broker.Publish("xbee", p) } }() for { @@ -293,7 +298,7 @@ func (x *xBeeService) Start(cCtx *cli.Context, deps svcDeps) (err error) { return case msg := <-rxCh: logger.Info("got msg", "msg", msg) - writeJSON.Encode(msg) + xbeeTxer.Encode(msg) if err != nil { logger.Warn("error writing to xbee", "err", err) } @@ -321,6 +326,7 @@ func (h *httpService) Start(cCtx *cli.Context, deps svcDeps) (err error) { r := gotelem.TelemRouter(logger, broker, db) + /// TODO: use custom port if specified http.ListenAndServe(":8080", r) return } diff --git a/frame.go b/frame.go index 10b9f2d..1b68071 100644 --- a/frame.go +++ b/frame.go @@ -35,6 +35,7 @@ const ( // CanFilter is a basic filter for masking out data. It has an Inverted flag // which indicates opposite behavior (reject all packets that match Id and Mask). // The filter matches when (packet.Id & filter.Mask) == filter.Id +// TODO: is this needed anymore since we are using firmware based version instead? type CanFilter struct { Id uint32 Mask uint32 diff --git a/http.go b/http.go index 55e036f..12704f6 100644 --- a/http.go +++ b/http.go @@ -101,7 +101,9 @@ func apiV1(broker *Broker, db *db.TelemDb) chi.Router { }) - r.Get("/stats", func(w http.ResponseWriter, r *http.Request) {}) // v1 api stats (calls, clients, xbee connected, meta health ok) + r.Get("/stats", func(w http.ResponseWriter, r *http.Request) { + + }) // v1 api stats (calls, clients, xbee connected, meta health ok) return r } diff --git a/internal/middleware/slogger.go b/internal/middleware/slogger.go index fa25340..730a7c1 100644 --- a/internal/middleware/slogger.go +++ b/internal/middleware/slogger.go @@ -40,7 +40,10 @@ func Slogger(sl *slog.Logger) func(next http.Handler) http.Handler { }() // embed the logger and the attrs for later items in the chain. - r = r.WithContext(context.WithValue(r.Context(), SloggerAttrsKey, attrs)) + ctx := context.WithValue(r.Context(), SloggerAttrsKey, attrs) + ctx = context.WithValue(ctx, SloggerLogKey, logger) + // push it to the request and serve the next handler + r = r.WithContext(ctx) next.ServeHTTP(ww, r) } @@ -64,3 +67,5 @@ func AddSlogAttr(r *http.Request, attr slog.Attr) { attrs = append(attrs, attr) } + +// TODO: write rest of functions diff --git a/py/.idea/jupyter-settings.xml b/py/.idea/jupyter-settings.xml index dcb4e0c..6f83a48 100644 --- a/py/.idea/jupyter-settings.xml +++ b/py/.idea/jupyter-settings.xml @@ -1,20 +1,6 @@ -