Files
lunchpick/lib/domain/entities/share_device.dart
JiWoong Sul c608b6c7df feat(bluetooth): 실제 BLE 기반 맛집 리스트 공유 구현
- ble_peripheral 패키지 추가 (Peripheral/GATT Server 역할)
- flutter_blue_plus 패키지 활용 (Central/스캔/연결 역할)

변경 사항:
- BleConstants: BLE UUID 및 설정 상수 정의
- BluetoothService: Mock에서 실제 BLE 통신으로 전면 재작성
  - Receiver: GATT Server로 광고, Write callback으로 데이터 수신
  - Sender: 서비스 UUID로 스캔, 연결 후 Characteristic에 데이터 전송
  - 청크 기반 대용량 데이터 전송 프로토콜 구현
- ShareDevice: BLE 디바이스 정보 필드 추가 (remoteId, rssi, bleDevice)
- Android/iOS: BLE 권한 및 기능 선언 추가

데이터 전송 프로토콜:
- 'CHUNK:index:total:data' 형식으로 500바이트 단위 분할 전송
- 수신 측에서 청크 조립 후 JSON 파싱
2026-01-30 00:09:13 +09:00

69 lines
1.6 KiB
Dart

import 'package:flutter_blue_plus/flutter_blue_plus.dart';
/// BLE 공유를 위한 디바이스 정보
class ShareDevice {
/// 공유 코드 (6자리 숫자)
final String code;
/// 디바이스 고유 ID
final String deviceId;
/// BLE Remote ID (MAC 주소 또는 UUID)
final String? remoteId;
/// 신호 강도 (RSSI)
final int? rssi;
/// 발견 시각
final DateTime discoveredAt;
/// flutter_blue_plus BluetoothDevice 참조
/// 실제 BLE 연결 시 사용
final BluetoothDevice? bleDevice;
ShareDevice({
required this.code,
required this.deviceId,
this.remoteId,
this.rssi,
required this.discoveredAt,
this.bleDevice,
});
/// 신호 강도 레벨 (0-4)
/// RSSI 값을 기반으로 계산
int get signalLevel {
if (rssi == null) return 0;
if (rssi! >= -50) return 4; // 매우 강함
if (rssi! >= -60) return 3; // 강함
if (rssi! >= -70) return 2; // 보통
if (rssi! >= -80) return 1; // 약함
return 0; // 매우 약함
}
/// 디버그용 문자열
@override
String toString() {
return 'ShareDevice(code: $code, deviceId: $deviceId, rssi: $rssi)';
}
/// 복사본 생성
ShareDevice copyWith({
String? code,
String? deviceId,
String? remoteId,
int? rssi,
DateTime? discoveredAt,
BluetoothDevice? bleDevice,
}) {
return ShareDevice(
code: code ?? this.code,
deviceId: deviceId ?? this.deviceId,
remoteId: remoteId ?? this.remoteId,
rssi: rssi ?? this.rssi,
discoveredAt: discoveredAt ?? this.discoveredAt,
bleDevice: bleDevice ?? this.bleDevice,
);
}
}