mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
rename BLEData to BleUart
These actions all relate specifically to the nRF UART GATT service
This commit is contained in:
committed by
David Lechner
parent
802f2bc05d
commit
f3425e2f0f
@@ -2,7 +2,7 @@
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
|
||||
import { AsyncSaga } from '../../test';
|
||||
import { didFailToWrite } from '../actions/ble';
|
||||
import { didFailToWrite } from '../actions/ble-uart';
|
||||
import {
|
||||
BootloaderConnectionFailureReason,
|
||||
didError,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
|
||||
import { takeEvery } from 'redux-saga/effects';
|
||||
import { BLEDataActionType, BLEDataDidFailToWriteAction } from '../actions/ble';
|
||||
import { BleUartActionType, BleUartDidFailToWriteAction } from '../actions/ble-uart';
|
||||
import {
|
||||
BootloaderConnectionActionType,
|
||||
BootloaderConnectionDidErrorAction,
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
BootloaderConnectionFailureReason,
|
||||
} from '../actions/lwp3-bootloader';
|
||||
|
||||
function bleDataDidFailToWrite(action: BLEDataDidFailToWriteAction): void {
|
||||
function bleDataDidFailToWrite(action: BleUartDidFailToWriteAction): void {
|
||||
console.error(action.err);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ function bootloaderDidError(action: BootloaderConnectionDidErrorAction): void {
|
||||
}
|
||||
|
||||
export default function* (): Generator {
|
||||
yield takeEvery(BLEDataActionType.DidFailToWrite, bleDataDidFailToWrite);
|
||||
yield takeEvery(BleUartActionType.DidFailToWrite, bleDataDidFailToWrite);
|
||||
yield takeEvery(
|
||||
BootloaderConnectionActionType.DidFailToConnect,
|
||||
bootloaderDidFailToConnect,
|
||||
|
||||
+12
-12
@@ -4,7 +4,7 @@
|
||||
import { Ace } from 'ace-builds';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { AsyncSaga } from '../../test';
|
||||
import { BLEDataActionType, BLEDataWriteAction, didWrite } from '../actions/ble';
|
||||
import { BleUartActionType, BleUartWriteAction, didWrite } from '../actions/ble-uart';
|
||||
import {
|
||||
HubMessageActionType,
|
||||
HubRuntimeStatusMessageAction,
|
||||
@@ -42,23 +42,23 @@ describe('downloadAndRun', () => {
|
||||
|
||||
// first message is the length
|
||||
const writeAction = await saga.take();
|
||||
expect(writeAction.type).toBe(BLEDataActionType.Write);
|
||||
expect((writeAction as BLEDataWriteAction).value.length).toBe(4);
|
||||
saga.put(didWrite((writeAction as BLEDataWriteAction).id));
|
||||
expect(writeAction.type).toBe(BleUartActionType.Write);
|
||||
expect((writeAction as BleUartWriteAction).value.length).toBe(4);
|
||||
saga.put(didWrite((writeAction as BleUartWriteAction).id));
|
||||
saga.put(checksum(30));
|
||||
|
||||
// then the first chunk of 20 bytes
|
||||
const writeAction2 = await saga.take();
|
||||
expect(writeAction2.type).toBe(BLEDataActionType.Write);
|
||||
expect((writeAction2 as BLEDataWriteAction).value.length).toBe(20);
|
||||
saga.put(didWrite((writeAction2 as BLEDataWriteAction).id));
|
||||
expect(writeAction2.type).toBe(BleUartActionType.Write);
|
||||
expect((writeAction2 as BleUartWriteAction).value.length).toBe(20);
|
||||
saga.put(didWrite((writeAction2 as BleUartWriteAction).id));
|
||||
saga.put(checksum(0));
|
||||
|
||||
// then last chunk
|
||||
const writeAction3 = await saga.take();
|
||||
expect(writeAction3.type).toBe(BLEDataActionType.Write);
|
||||
expect((writeAction3 as BLEDataWriteAction).value.length).toBe(10);
|
||||
saga.put(didWrite((writeAction3 as BLEDataWriteAction).id));
|
||||
expect(writeAction3.type).toBe(BleUartActionType.Write);
|
||||
expect((writeAction3 as BleUartWriteAction).value.length).toBe(10);
|
||||
saga.put(didWrite((writeAction3 as BleUartWriteAction).id));
|
||||
saga.put(checksum(0));
|
||||
|
||||
// Then a status message saying that we are done
|
||||
@@ -80,7 +80,7 @@ test('repl', async () => {
|
||||
saga.put(repl());
|
||||
|
||||
const compileAction = await saga.take();
|
||||
expect(compileAction.type).toBe(BLEDataActionType.Write);
|
||||
expect(compileAction.type).toBe(BleUartActionType.Write);
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
@@ -91,7 +91,7 @@ test('stop', async () => {
|
||||
saga.put(stop());
|
||||
|
||||
const compileAction = await saga.take();
|
||||
expect(compileAction.type).toBe(BLEDataActionType.Write);
|
||||
expect(compileAction.type).toBe(BleUartActionType.Write);
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
+13
-13
@@ -15,12 +15,12 @@ import {
|
||||
} from 'redux-saga/effects';
|
||||
import { Action } from '../actions';
|
||||
import {
|
||||
BLEDataActionType,
|
||||
BLEDataDidFailToWriteAction,
|
||||
BLEDataDidWriteAction,
|
||||
BLEDataWriteAction,
|
||||
BleUartActionType,
|
||||
BleUartDidFailToWriteAction,
|
||||
BleUartDidWriteAction,
|
||||
BleUartWriteAction,
|
||||
write,
|
||||
} from '../actions/ble';
|
||||
} from '../actions/ble-uart';
|
||||
import {
|
||||
HubActionType,
|
||||
HubChecksumMessageAction,
|
||||
@@ -44,8 +44,8 @@ const downloadChunkSize = 100;
|
||||
|
||||
function waitForWrite(id: number): RaceEffect<TakeEffect> {
|
||||
return race([
|
||||
take((a: Action) => a.type === BLEDataActionType.DidWrite && a.id === id),
|
||||
take((a: Action) => a.type === BLEDataActionType.DidFailToWrite && a.id === id),
|
||||
take((a: Action) => a.type === BleUartActionType.DidWrite && a.id === id),
|
||||
take((a: Action) => a.type === BleUartActionType.DidFailToWrite && a.id === id),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ function* downloadAndRun(_action: HubDownloadAndRunAction): Generator {
|
||||
const sizeBuf = new Uint8Array(4);
|
||||
const sizeView = new DataView(sizeBuf.buffer);
|
||||
sizeView.setUint32(0, mpy.data.byteLength, true);
|
||||
const writeAction = (yield put(write(sizeBuf))) as BLEDataWriteAction;
|
||||
const writeAction = (yield put(write(sizeBuf))) as BleUartWriteAction;
|
||||
const [, didFailToWrite] = (yield waitForWrite(writeAction.id)) as [
|
||||
BLEDataDidWriteAction,
|
||||
BLEDataDidFailToWriteAction,
|
||||
BleUartDidWriteAction,
|
||||
BleUartDidFailToWriteAction,
|
||||
];
|
||||
|
||||
if (didFailToWrite) {
|
||||
@@ -112,10 +112,10 @@ function* downloadAndRun(_action: HubDownloadAndRunAction): Generator {
|
||||
for (let j = 0; j < chunk.length; j += 20) {
|
||||
const writeAction = (yield put(
|
||||
write(chunk.slice(j, j + 20)),
|
||||
)) as BLEDataWriteAction;
|
||||
)) as BleUartWriteAction;
|
||||
const [, didFailToWrite] = (yield waitForWrite(writeAction.id)) as [
|
||||
BLEDataDidWriteAction,
|
||||
BLEDataDidFailToWriteAction,
|
||||
BleUartDidWriteAction,
|
||||
BleUartDidFailToWriteAction,
|
||||
];
|
||||
|
||||
if (didFailToWrite) {
|
||||
|
||||
+25
-25
@@ -4,12 +4,12 @@
|
||||
import { AsyncSaga, delay } from '../../test';
|
||||
|
||||
import {
|
||||
BLEDataActionType,
|
||||
BLEDataWriteAction,
|
||||
BleUartActionType,
|
||||
BleUartWriteAction,
|
||||
didFailToWrite,
|
||||
didWrite,
|
||||
notify,
|
||||
} from '../actions/ble';
|
||||
} from '../actions/ble-uart';
|
||||
import {
|
||||
HubChecksumMessageAction,
|
||||
HubMessageActionType,
|
||||
@@ -351,8 +351,8 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
saga.put(receiveData('test1234'));
|
||||
|
||||
const action = await saga.take();
|
||||
expect(action.type).toBe(BLEDataActionType.Write);
|
||||
expect((action as BLEDataWriteAction).value).toEqual(expected);
|
||||
expect(action.type).toBe(BleUartActionType.Write);
|
||||
expect((action as BleUartWriteAction).value).toEqual(expected);
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
@@ -372,19 +372,19 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
expect(saga.numPending()).toBe(1);
|
||||
|
||||
const action = await saga.take();
|
||||
expect(action.type).toBe(BLEDataActionType.Write);
|
||||
expect((action as BLEDataWriteAction).value).toEqual(expected);
|
||||
expect(action.type).toBe(BleUartActionType.Write);
|
||||
expect((action as BleUartWriteAction).value).toEqual(expected);
|
||||
|
||||
// second message is queued until didWrite or didFailToWrite
|
||||
expect(saga.numPending()).toBe(0);
|
||||
|
||||
saga.put(didWrite((action as BLEDataWriteAction).id));
|
||||
saga.put(didWrite((action as BleUartWriteAction).id));
|
||||
|
||||
const action2 = await saga.take();
|
||||
expect(action2.type).toBe(BLEDataActionType.Write);
|
||||
expect((action2 as BLEDataWriteAction).value).toEqual(expected);
|
||||
expect(action2.type).toBe(BleUartActionType.Write);
|
||||
expect((action2 as BleUartWriteAction).value).toEqual(expected);
|
||||
|
||||
saga.put(didWrite((action2 as BLEDataWriteAction).id));
|
||||
saga.put(didWrite((action2 as BleUartWriteAction).id));
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
@@ -404,21 +404,21 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
expect(saga.numPending()).toBe(1);
|
||||
|
||||
const action = await saga.take();
|
||||
expect(action.type).toBe(BLEDataActionType.Write);
|
||||
expect((action as BLEDataWriteAction).value).toEqual(expected);
|
||||
expect(action.type).toBe(BleUartActionType.Write);
|
||||
expect((action as BleUartWriteAction).value).toEqual(expected);
|
||||
|
||||
// second message is queued until didWrite or didFailToWrite
|
||||
expect(saga.numPending()).toBe(0);
|
||||
|
||||
saga.put(
|
||||
didFailToWrite((action as BLEDataWriteAction).id, new Error('test error')),
|
||||
didFailToWrite((action as BleUartWriteAction).id, new Error('test error')),
|
||||
);
|
||||
|
||||
const action2 = await saga.take();
|
||||
expect(action2.type).toBe(BLEDataActionType.Write);
|
||||
expect((action2 as BLEDataWriteAction).value).toEqual(expected);
|
||||
expect(action2.type).toBe(BleUartActionType.Write);
|
||||
expect((action2 as BleUartWriteAction).value).toEqual(expected);
|
||||
|
||||
saga.put(didWrite((action2 as BLEDataWriteAction).id));
|
||||
saga.put(didWrite((action2 as BleUartWriteAction).id));
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
@@ -434,8 +434,8 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
saga.put(receiveData('test1234'));
|
||||
|
||||
const action = await saga.take();
|
||||
expect(action.type).toBe(BLEDataActionType.Write);
|
||||
expect((action as BLEDataWriteAction).value).toEqual(
|
||||
expect(action.type).toBe(BleUartActionType.Write);
|
||||
expect((action as BleUartWriteAction).value).toEqual(
|
||||
new Uint8Array([...expected, ...expected]),
|
||||
);
|
||||
|
||||
@@ -452,16 +452,16 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
saga.put(receiveData('012345678901234567890123456789'));
|
||||
|
||||
const action = await saga.take();
|
||||
expect(action.type).toBe(BLEDataActionType.Write);
|
||||
expect((action as BLEDataWriteAction).value.length).toEqual(20);
|
||||
expect(action.type).toBe(BleUartActionType.Write);
|
||||
expect((action as BleUartWriteAction).value.length).toEqual(20);
|
||||
|
||||
saga.put(didWrite((action as BLEDataWriteAction).id));
|
||||
saga.put(didWrite((action as BleUartWriteAction).id));
|
||||
|
||||
const action2 = await saga.take();
|
||||
expect(action2.type).toBe(BLEDataActionType.Write);
|
||||
expect((action2 as BLEDataWriteAction).value.length).toEqual(10);
|
||||
expect(action2.type).toBe(BleUartActionType.Write);
|
||||
expect((action2 as BleUartWriteAction).value.length).toEqual(10);
|
||||
|
||||
saga.put(didWrite((action2 as BLEDataWriteAction).id));
|
||||
saga.put(didWrite((action2 as BleUartWriteAction).id));
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
+10
-10
@@ -15,11 +15,11 @@ import {
|
||||
import PushStream from 'zen-push';
|
||||
import { Action } from '../actions';
|
||||
import {
|
||||
BLEDataActionType,
|
||||
BLEDataNotifyAction,
|
||||
BLEDataWriteAction,
|
||||
BleUartActionType,
|
||||
BleUartNotifyAction,
|
||||
BleUartWriteAction,
|
||||
write,
|
||||
} from '../actions/ble';
|
||||
} from '../actions/ble-uart';
|
||||
import { HubRuntimeStatusType, checksum, updateStatus } from '../actions/hub';
|
||||
import {
|
||||
TerminalActionType,
|
||||
@@ -55,7 +55,7 @@ function* handleMatch(
|
||||
return true;
|
||||
}
|
||||
|
||||
function* receiveUartData(action: BLEDataNotifyAction): Generator {
|
||||
function* receiveUartData(action: BleUartNotifyAction): Generator {
|
||||
const hubState = (yield select((s: RootState) => s.hub.runtime)) as HubRuntimeState;
|
||||
|
||||
if (hubState === HubRuntimeState.Loading && action.value.buffer.byteLength === 1) {
|
||||
@@ -119,17 +119,17 @@ function* receiveTerminalData(): Generator {
|
||||
for (let i = 0; i < data.length; i += 20) {
|
||||
const { id } = (yield put(
|
||||
write(data.slice(i, i + 20)),
|
||||
)) as BLEDataWriteAction;
|
||||
)) as BleUartWriteAction;
|
||||
|
||||
yield take(
|
||||
(a: Action) =>
|
||||
(a.type === BLEDataActionType.DidWrite ||
|
||||
a.type === BLEDataActionType.DidFailToWrite) &&
|
||||
(a.type === BleUartActionType.DidWrite ||
|
||||
a.type === BleUartActionType.DidFailToWrite) &&
|
||||
a.id === id,
|
||||
);
|
||||
|
||||
// wait for echo so tht we don't overrun the hub with messages
|
||||
yield race([take(BLEDataActionType.Notify), delay(100)]);
|
||||
yield race([take(BleUartActionType.Notify), delay(100)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ function sendTerminalData(action: TerminalDataReceiveDataAction): void {
|
||||
}
|
||||
|
||||
export default function* (): Generator {
|
||||
yield takeEvery(BLEDataActionType.Notify, receiveUartData);
|
||||
yield takeEvery(BleUartActionType.Notify, receiveUartData);
|
||||
yield fork(receiveTerminalData);
|
||||
yield takeEvery(TerminalActionType.SendData, sendTerminalData);
|
||||
yield put(setDataSource(terminalDataSource.observable));
|
||||
|
||||
Reference in New Issue
Block a user