In short: added the ability to detect when a device has disconnected. From this we have to achieve a way of: - reconnecting the device - re-subscribing to the fields it needs (it should already be subscribed since the ESDI didn't stop tho - but for the sake of it, or in case a device joins later) - start sending data to it (which should be automatic given how we are handling the devices)
57 lines
913 B
Go
57 lines
913 B
Go
package uidevice
|
|
|
|
import (
|
|
"esdi/peripheral"
|
|
"esdi/telemetry"
|
|
)
|
|
|
|
type UIDevice struct {
|
|
dataChan chan telemetry.TelemetryData
|
|
}
|
|
|
|
const NAME = "UIView"
|
|
|
|
func NewUIDevice() (peripheral.Peripheral, error) {
|
|
return &UIDevice{
|
|
dataChan: make(chan telemetry.TelemetryData, 1),
|
|
}, nil
|
|
}
|
|
|
|
func (uid *UIDevice) Close() error {
|
|
if uid.dataChan != nil {
|
|
close(uid.dataChan)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (uid *UIDevice) SendData(data *telemetry.TelemetryData) error {
|
|
if data == nil {
|
|
return peripheral.ErrInvalidData
|
|
}
|
|
|
|
select {
|
|
case uid.dataChan <- *data:
|
|
default:
|
|
// Drop frame if buffer is full
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (uid *UIDevice) Name() string {
|
|
return NAME
|
|
}
|
|
|
|
func (uid *UIDevice) DataChannel() <-chan telemetry.TelemetryData {
|
|
return uid.dataChan
|
|
}
|
|
|
|
func (uid *UIDevice) RequiredFields() []telemetry.FieldID {
|
|
return []telemetry.FieldID{
|
|
telemetry.Speed,
|
|
telemetry.Gear,
|
|
telemetry.RPM,
|
|
}
|
|
}
|