fix some bugs
This commit is contained in:
parent
40f70acd14
commit
2ca3dd97ff
|
@ -110,6 +110,7 @@ func (b *JBroker) Subscribe(name string) (ch chan CANDumpEntry, err error) {
|
||||||
b.logger.Info("new subscriber", "name", name)
|
b.logger.Info("new subscriber", "name", name)
|
||||||
ch = make(chan CANDumpEntry, b.bufsize)
|
ch = make(chan CANDumpEntry, b.bufsize)
|
||||||
|
|
||||||
|
b.subs[name] = ch
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ func (c *CanLoggerService) Status() {
|
||||||
|
|
||||||
|
|
||||||
func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l *slog.Logger) (err error) {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -186,6 +186,7 @@ func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l
|
||||||
case msg := <-rxCh:
|
case msg := <-rxCh:
|
||||||
|
|
||||||
enc.Encode(msg)
|
enc.Encode(msg)
|
||||||
|
|
||||||
case <-cCtx.Done():
|
case <-cCtx.Done():
|
||||||
f.Close()
|
f.Close()
|
||||||
return
|
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())
|
logger.Info("connected to local xbee", "addr", x.session.LocalAddr())
|
||||||
|
|
||||||
|
encode := json.NewEncoder(x.session)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-cCtx.Done():
|
case <-cCtx.Done():
|
||||||
|
@ -237,11 +239,7 @@ func (x *XBeeService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger *
|
||||||
return
|
return
|
||||||
case msg := <-rxCh:
|
case msg := <-rxCh:
|
||||||
logger.Info("got msg", "msg", msg)
|
logger.Info("got msg", "msg", msg)
|
||||||
buf := make([]byte, 0)
|
encode.Encode(msg)
|
||||||
|
|
||||||
// FIXME: implement serialzation over xbee.
|
|
||||||
|
|
||||||
_, err := x.session.Write(buf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("error writing to xbee", "err", err)
|
logger.Warn("error writing to xbee", "err", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ func (s *socketCANService) Start(cCtx *cli.Context, broker *gotelem.JBroker, log
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cde := gotelem.CANDumpEntry{
|
cde := gotelem.CANDumpEntry{
|
||||||
Timestamp: float64(time.Now().Unix()),
|
Timestamp: float64(time.Now().UnixNano()) / 1e9,
|
||||||
Id: uint64(msg.Id),
|
Id: uint64(msg.Id),
|
||||||
Data: p,
|
Data: p,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue