Skip to content

Commit 14e9645

Browse files
committed
fixing for phone
1 parent 6595033 commit 14e9645

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

examples/dashboard/src/ConnManager.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { RaftConnector, RaftEventFn, RaftLog, RaftSystemUtils, RaftSysTypeManager } from "../../../src/main";
22
import SettingsManager from "./SettingsManager";
3+
import SystemTypeCog from "./SystemTypeCog/SystemTypeCog";
4+
import SystemTypeGeneric from "./SystemTypeGeneric/SystemTypeGeneric";
5+
import SystemTypeMarty from "./SystemTypeMarty/SystemTypeMarty";
36

47
const sysTypeManager = RaftSysTypeManager.getInstance();
58
const settingsManager = SettingsManager.getInstance();
69

10+
sysTypeManager.addSystemType('Cog', () => new SystemTypeCog());
11+
sysTypeManager.addSystemType('Marty', () => new SystemTypeMarty());
12+
sysTypeManager.addDefaultSystemType(() => new SystemTypeGeneric());
13+
714
export default class ConnManager {
815

916
// Singleton

examples/dashboard/src/Main.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ import StatusPanel from './StatusPanel';
1212
import DevicesPanel from './DevicesPanel';
1313
import CommandPanel from './CommandPanel';
1414
import LatencyTestPanel from './LatencyTestPanel';
15-
import SystemTypeCog from './SystemTypeCog/SystemTypeCog';
16-
import SystemTypeMarty from './SystemTypeMarty/SystemTypeMarty';
17-
import SystemTypeGeneric from './SystemTypeGeneric/SystemTypeGeneric';
1815
import SettingsManager from './SettingsManager';
1916

2017
const sysTypeManager = RaftSysTypeManager.getInstance();
2118
const connManager = ConnManager.getInstance();
22-
sysTypeManager.addSystemType('Cog', () => new SystemTypeCog());
23-
sysTypeManager.addSystemType('Marty', () => new SystemTypeMarty());
24-
sysTypeManager.addDefaultSystemType(() => new SystemTypeGeneric());
2519

2620
export default function Main() {
2721
const [connectionStatus, setConnectionStatus] = useState<RaftConnEvent>(

examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class SystemTypeMarty implements RaftSystemType {
2424

2525
// Latest data from servos, IMU, etc
2626
private _ricStateInfo: RICStateInfo = new RICStateInfo();
27-
getRICStateInfo(): RICStateInfo {
27+
getStateInfo(): RICStateInfo {
2828
return this._ricStateInfo;
2929
}
3030

src/RaftChannelBLE.native.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export default class RaftChannelPhoneBLE implements RaftChannel {
6161
private _requestedBatchAckSize = 10;
6262
private _requestedFileBlockSize = 500;
6363

64+
// Connected device UUID
65+
private _connectedDeviceServiceUUID?: string;
66+
6467
constructor() {
6568
RaftLog.debug('BLEChannel constructor');
6669

@@ -79,6 +82,10 @@ export default class RaftChannelPhoneBLE implements RaftChannel {
7982
}, true);
8083
}
8184

85+
setConnectedDeviceUUID(serviceUUID: string) {
86+
this._connectedDeviceServiceUUID = serviceUUID;
87+
}
88+
8289
getBleManager(): BleManager {
8390
return _bleManager;
8491
}
@@ -204,7 +211,9 @@ export default class RaftChannelPhoneBLE implements RaftChannel {
204211
*
205212
*/
206213
async connect(discoveredDevice: DiscoveredDevice): Promise<boolean> {
207-
RaftLog.debug('BLEChannel requested connection');
214+
RaftLog.debug('BLEChannel requested connection ' + JSON.stringify(discoveredDevice));
215+
this._connectedDeviceServiceUUID = discoveredDevice.serviceUUIDs ? discoveredDevice.serviceUUIDs[0] : undefined;
216+
208217
this._retryConnectionIfLost = false;
209218
this._bleScanner.scanningStop();
210219

@@ -352,9 +361,13 @@ export default class RaftChannelPhoneBLE implements RaftChannel {
352361
}
353362
// Monitor the inbound characteristic
354363
try {
355-
if (this._bleDevice && this._bleDevice.serviceUUIDs) {
364+
if (this._bleDevice) {
365+
if (!this._connectedDeviceServiceUUID) {
366+
RaftLog.error('BLEChannel _configDeviceConnection - no connected device service UUID');
367+
return false;
368+
}
356369
this._bleSubscrOnRx = this._bleDevice.monitorCharacteristicForService(
357-
this._bleDevice.serviceUUIDs[0],
370+
this._connectedDeviceServiceUUID,
358371
this._respUUID,
359372
(error: BleError | null, characteristic: Characteristic | null) => {
360373
this._onMsgRx(error, characteristic);
@@ -520,8 +533,12 @@ export default class RaftChannelPhoneBLE implements RaftChannel {
520533
const msgFrameBase64 = RaftUtils.btoa(msg);
521534

522535
try {
523-
await this._bleDevice.writeCharacteristicWithoutResponseForService(
524-
this._bleDevice.serviceUUIDs ? this._bleDevice.serviceUUIDs[0] : this._serviceUUIDs[0],
536+
if (!this._connectedDeviceServiceUUID) {
537+
RaftLog.error('BLEChannel sendTxMsg - no connected device service UUID');
538+
return false;
539+
}
540+
await this._bleDevice!.writeCharacteristicWithoutResponseForService(
541+
this._connectedDeviceServiceUUID,
525542
this._cmdUUID,
526543
msgFrameBase64!,
527544
);
@@ -559,8 +576,12 @@ export default class RaftChannelPhoneBLE implements RaftChannel {
559576
const msgFrameBase64 = RaftUtils.btoa(msg);
560577

561578
try {
579+
if (!this._connectedDeviceServiceUUID) {
580+
RaftLog.error('BLEChannel sendTxMsgNoAwait - no connected device service UUID');
581+
return false;
582+
}
562583
this._bleDevice!.writeCharacteristicWithoutResponseForService(
563-
this._bleDevice.serviceUUIDs ? this._bleDevice.serviceUUIDs[0] : this._serviceUUIDs[0],
584+
this._connectedDeviceServiceUUID,
564585
this._cmdUUID,
565586
msgFrameBase64!,
566587
);

0 commit comments

Comments
 (0)