has way too many things
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)
This commit is contained in:
@@ -108,6 +108,15 @@ func (wt *WalkieTalkie) sendPacket(cmd types.Command, data any) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// slog.Debug("# START ########################################################")
|
||||
// slog.Debug(fmt.Sprintf("StartMarker: %02x", constvar.StartOfText))
|
||||
// slog.Debug(fmt.Sprintf("CMD: %02x", cmd))
|
||||
// slog.Debug(fmt.Sprintf("Len: %d", len(payload)))
|
||||
// slog.Debug(fmt.Sprintf("Payload: %v", payload))
|
||||
// slog.Debug(fmt.Sprintf("CRC: %v", CRC8(payload)))
|
||||
// slog.Debug(fmt.Sprintf("EndMarker: %02x", constvar.EndOfText))
|
||||
// slog.Debug("-")
|
||||
|
||||
packet := CMDDataPacket{
|
||||
StartMarker: constvar.StartOfText,
|
||||
CMD: cmd,
|
||||
@@ -119,7 +128,9 @@ func (wt *WalkieTalkie) sendPacket(cmd types.Command, data any) error {
|
||||
|
||||
// Send the payload
|
||||
serializedPacket := packet.Serialize()
|
||||
// fmt.Fprintf(os.Stderr, "%+v", serializedPacket)
|
||||
|
||||
// slog.Debug("Serialized packet", "packet", packet)
|
||||
// slog.Debug("# END ##########################################################")
|
||||
|
||||
_, err = wt.Serial.Write(serializedPacket)
|
||||
if err != nil {
|
||||
@@ -176,21 +187,11 @@ func (wt *WalkieTalkie) readPacket(resp packets.Packet) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func (wt *WalkieTalkie) SendCommand(cmd types.Command, payload any,
|
||||
responseBody packets.Packet) error {
|
||||
// Prepare the header
|
||||
// header := header{
|
||||
// StartByte: constvar.StartOfText,
|
||||
// CMD: cmd,
|
||||
// EndByte: constvar.EndOfText,
|
||||
// }
|
||||
|
||||
// Send the header
|
||||
// err := wt.sendHeader(&header)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (wt *WalkieTalkie) SendCommand(
|
||||
cmd types.Command,
|
||||
payload any,
|
||||
responseBody packets.Packet,
|
||||
) error {
|
||||
// Send the body
|
||||
err := wt.sendPacket(cmd, payload)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,6 +19,7 @@ type Peripheral interface {
|
||||
Name() string
|
||||
SendData(*telemetry.TelemetryData) error
|
||||
RequiredFields() []telemetry.FieldID
|
||||
Close() error
|
||||
}
|
||||
|
||||
type PeripheralDeviceClerk struct {
|
||||
|
||||
Reference in New Issue
Block a user