Skip to content

Commit 813f766

Browse files
committed
Add service and characteristic UUID fields to SidecarTransport; implement CentralBroadcast method for sending data to discovered peers.
1 parent eea4faa commit 813f766

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

internal/ble/transport_sidecar_windows.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ type SidecarTransport struct {
3030

3131
// fallback scanner for discovery
3232
scanner core.BLETransport
33+
34+
// service/characteristic identifiers for central operations
35+
serviceUUID string
36+
charUUID string
3337
}
3438

3539
type sidecarRequest struct {
@@ -62,7 +66,9 @@ func tryNewSidecarTransport(cfg *core.NetworkConfig, logger *logging.Logger) (co
6266
if err != nil {
6367
fallback = newSim(cfg, logger)
6468
}
65-
st := &SidecarTransport{logger: logger, addr: addr, scanner: fallback}
69+
svc := cfg.ServiceUUID
70+
chr := cfg.CharacteristicUUID
71+
st := &SidecarTransport{logger: logger, addr: addr, scanner: fallback, serviceUUID: svc, charUUID: chr}
6672
return st, true, nil
6773
}
6874

@@ -267,3 +273,23 @@ func (t *SidecarTransport) SendNotification(ctx context.Context, data []byte) er
267273
// EffectiveMTU returns the effective ATT_MTU for notifications.
268274
// Windows GATT typically negotiates ~185; we use a conservative default.
269275
func (t *SidecarTransport) EffectiveMTU() int { return 185 }
276+
277+
// CentralBroadcast writes the given payload to all discovered peers advertising
278+
// the configured service UUID by connecting as a central and performing a characteristic write.
279+
// This provides a simple one-hop broadcast suitable for command delivery.
280+
func (t *SidecarTransport) CentralBroadcast(ctx context.Context, data []byte) error {
281+
if t.serviceUUID == "" || t.charUUID == "" {
282+
return errors.New("missing service/characteristic UUID for central broadcast")
283+
}
284+
p := map[string]interface{}{
285+
"service_uuid": t.serviceUUID,
286+
"characteristic_uuid": t.charUUID,
287+
"value_b64": base64.StdEncoding.EncodeToString(data),
288+
"scan_ms": 800,
289+
}
290+
// Best-effort: make a short-lived request; sidecar performs scan/connect/write internally
291+
if _, err := t.do("central_broadcast", p); err != nil {
292+
return err
293+
}
294+
return nil
295+
}

0 commit comments

Comments
 (0)