Compare commits

...

3 commits

Author SHA1 Message Date
saji cf112ef561 fix socketcan bugs 2024-03-07 15:06:16 -06:00
saji 641c35afbd add more logging to BusEvent Broker 2024-03-07 15:05:51 -06:00
saji 4a292aa009 change default database path to gotelem.db 2024-03-07 15:05:31 -06:00
4 changed files with 7 additions and 4 deletions

View file

@ -37,7 +37,7 @@ func (b *Broker) Subscribe(name string) (ch chan skylab.BusEvent, err error) {
if ok {
return nil, errors.New("name already in use")
}
b.logger.Info("new subscriber", "name", name)
b.logger.Info("subscribe", "name", name)
ch = make(chan skylab.BusEvent, b.bufsize)
b.subs[name] = ch
@ -51,6 +51,7 @@ func (b *Broker) Unsubscribe(name string) {
// remove the channel from the map. We don't need to close it.
b.lock.Lock()
defer b.lock.Unlock()
b.logger.Debug("unsubscribe", "name", name)
delete(b.subs, name)
}
@ -59,6 +60,7 @@ func (b *Broker) Unsubscribe(name string) {
func (b *Broker) Publish(sender string, message skylab.BusEvent) {
b.lock.RLock()
defer b.lock.RUnlock()
b.logger.Debug("publish", "sender", sender, "message", message)
for name, ch := range b.subs {
if name == sender {
continue
@ -66,7 +68,6 @@ func (b *Broker) Publish(sender string, message skylab.BusEvent) {
// non blocking send.
select {
case ch <- message:
b.logger.Debug("sent message", "dest", name, "src", sender)
default:
b.logger.Warn("recipient buffer full", "dest", name)
}

View file

@ -92,7 +92,7 @@ func serve(cCtx *cli.Context) error {
broker := gotelem.NewBroker(20, logger.WithGroup("broker"))
// open database
dbPath := "file::memory:?cache=shared"
dbPath := "gotelem.db"
if cCtx.IsSet("db") {
dbPath = cCtx.Path("db")
}

View file

@ -144,6 +144,8 @@ func (sck *CanSocket) Send(msg *can.Frame) error {
idToWrite |= unix.CAN_RTR_FLAG
case can.CanErrFrame:
return errors.New("you can't send error frames")
case can.CanDataFrame:
default:
return errors.New("unknown frame type")
}

View file

@ -51,7 +51,7 @@ func TestCanSocket(t *testing.T) {
err := sock.Send(testFrame)
if err != nil {
t.Error(err)
t.Fatal(err)
}
})