fix some bugs

This commit is contained in:
saji 2023-05-26 17:22:44 -05:00
parent 40f70acd14
commit 2ca3dd97ff
3 changed files with 6 additions and 7 deletions

View file

@ -110,6 +110,7 @@ func (b *JBroker) Subscribe(name string) (ch chan CANDumpEntry, err error) {
b.logger.Info("new subscriber", "name", name)
ch = make(chan CANDumpEntry, b.bufsize)
b.subs[name] = ch
return
}

View file

@ -164,7 +164,7 @@ func (c *CanLoggerService) Status() {
func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l *slog.Logger) (err error) {
rxCh, err := broker.Subscribe("candump")
rxCh, err := broker.Subscribe("canDump")
if err != nil {
return err
}
@ -186,6 +186,7 @@ func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l
case msg := <-rxCh:
enc.Encode(msg)
case <-cCtx.Done():
f.Close()
return
@ -230,6 +231,7 @@ func (x *XBeeService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger *
}
logger.Info("connected to local xbee", "addr", x.session.LocalAddr())
encode := json.NewEncoder(x.session)
for {
select {
case <-cCtx.Done():
@ -237,11 +239,7 @@ func (x *XBeeService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger *
return
case msg := <-rxCh:
logger.Info("got msg", "msg", msg)
buf := make([]byte, 0)
// FIXME: implement serialzation over xbee.
_, err := x.session.Write(buf)
encode.Encode(msg)
if err != nil {
logger.Warn("error writing to xbee", "err", err)
}

View file

@ -114,7 +114,7 @@ func (s *socketCANService) Start(cCtx *cli.Context, broker *gotelem.JBroker, log
continue
}
cde := gotelem.CANDumpEntry{
Timestamp: float64(time.Now().Unix()),
Timestamp: float64(time.Now().UnixNano()) / 1e9,
Id: uint64(msg.Id),
Data: p,
}