Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/features/flows/nRF54L15_cloud/evaluate/EstablishConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,38 @@
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
*/

import React from 'react';
import React, { useEffect, useRef } from 'react';
import {
getPersistedNickname,
logger,
} from '@nordicsemiconductor/pc-nrfconnect-shared';

import qrImage from '../../../../../resources/cloud_qr.svg';
import { useAppDispatch } from '../../../../app/store';
import { useAppDispatch, useAppSelector } from '../../../../app/store';
import { Back } from '../../../../common/Back';
import Main from '../../../../common/Main';
import { Next } from '../../../../common/Next';
import { reset } from '../../../device/deviceLib';
import { getSelectedDeviceUnsafely } from '../../../device/deviceSlice';
import { nextSubStep } from './cloudEvaluateSlice';
import { setDeviceName } from './device';

export default () => {
export default ({ vComIndex }: { vComIndex: number }) => {
const dispatch = useAppDispatch();
const device = useAppSelector(getSelectedDeviceUnsafely);
const btName = useRef<string>();

useEffect(() => {
const persistedName = getPersistedNickname(device.serialNumber);
if (persistedName && btName.current !== persistedName) {
setDeviceName(device, vComIndex, persistedName)
.then(() => {
reset(device);
btName.current = persistedName;
})
.catch(logger.error);
}
}, [device, vComIndex]);

return (
<Main>
Expand Down
63 changes: 58 additions & 5 deletions src/features/flows/nRF54L15_cloud/evaluate/TestCrash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
*/

import React, { useEffect, useState } from 'react';
import { IssueBox, Spinner } from '@nordicsemiconductor/pc-nrfconnect-shared';
import {
IssueBox,
NoticeBox,
Spinner,
useStopwatch,
} from '@nordicsemiconductor/pc-nrfconnect-shared';
import describeError from '@nordicsemiconductor/pc-nrfconnect-shared/src/logging/describeError';

import { useAppDispatch, useAppSelector } from '../../../../app/store';
Expand All @@ -25,13 +30,28 @@ import {
import { fetchDeviceInfo } from './deviceInfoEffects';
import { reportEvaluateError } from './reportError';

const TIMEOUT_MS = 60000;

export default ({ vComIndex }: { vComIndex: number }) => {
const dispatch = useAppDispatch();
const deviceInfo = useAppSelector(getDeviceInfo);
const crashReportBaselineDate = useAppSelector(getCrashReportBaselineDate);
const crashReport = useAppSelector(getCrashReport);
const [error, setError] = useState<string>();

const { reset, pause, time } = useStopwatch({
autoStart: !crashReport,
Comment thread
formalmia marked this conversation as resolved.
resolution: TIMEOUT_MS,
});

const [takingTooLong, setTakingTooLong] = useState(false);

useEffect(() => {
if (time >= TIMEOUT_MS) {
setTakingTooLong(true);
}
}, [time]);

const serialNumber =
deviceInfo.status === 'success' ? deviceInfo.serialNumber : undefined;

Expand Down Expand Up @@ -59,7 +79,10 @@ export default ({ vComIndex }: { vComIndex: number }) => {
crashReportBaselineDate,
controller.signal,
)
.then(crash => dispatch(setCrashReport(crash)))
.then(crash => {
pause();
dispatch(setCrashReport(crash));
})
.catch(e => {
if ((e as Error).name === 'AbortError') {
return;
Expand All @@ -69,9 +92,20 @@ export default ({ vComIndex }: { vComIndex: number }) => {
});
}

return () => controller.abort();
return () => {
console.log('TestCrash: aborting fetch/poll for crash report');
Comment thread
kylebonnici marked this conversation as resolved.
controller.abort();
};
// Once the baseline is established the effect re-runs and starts polling for a new crash.
}, [dispatch, serialNumber, crashReport, error, crashReportBaselineDate]);
}, [
dispatch,
serialNumber,
crashReport,
error,
crashReportBaselineDate,
reset,
pause,
]);

const preparingBaseline =
deviceInfo.status === 'success' &&
Expand Down Expand Up @@ -136,6 +170,25 @@ export default ({ vComIndex }: { vComIndex: number }) => {
</div>
)}

{!crashReport && takingTooLong && (
<NoticeBox
mdiIcon="mdi-information-outline"
color="tw-text-primary"
title="This is taking longer than expected."
content={
<div className="tw-flex tw-flex-col tw-gap-1">
<span>
This is taking longer than expected...
<br />
Be sure to press <b>Button 1</b> and
reconnect to the mobile app.
Alternatively you can skip this step.
</span>
</div>
}
/>
)}

{deviceInfo.status === 'error' && (
<IssueBox
mdiIcon="mdi-lightbulb-alert-outline"
Expand Down Expand Up @@ -191,7 +244,7 @@ export default ({ vComIndex }: { vComIndex: number }) => {
</Main.Content>
<Main.Footer>
<Back onClick={() => dispatch(prevSubStep())} />
{(error || deviceInfo.status === 'error') && (
{(error || deviceInfo.status === 'error' || takingTooLong) && (
<Skip
label="Skip"
onClick={() => dispatch(nextSubStep())}
Expand Down
19 changes: 16 additions & 3 deletions src/features/flows/nRF54L15_cloud/evaluate/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ export const readDeviceInfo = (
});
});

export const setDeviceProjectKey = async (
const runShellCommand = async (
device: DeviceWithSerialnumber,
vComIndex: number,
projectKey: string,
command: string,
): Promise<void> => {
const path = device.serialPorts?.[vComIndex]?.comName;
if (!path) {
Expand All @@ -135,7 +135,7 @@ export const setDeviceProjectKey = async (

try {
await new Promise<string>((resolve, reject) => {
parser.enqueueRequest(`mflt set_project_key ${projectKey}`, {
parser.enqueueRequest(command, {
onSuccess: resolve,
onError: reject,
onTimeout: () => reject(new Error('timeout')),
Expand All @@ -146,3 +146,16 @@ export const setDeviceProjectKey = async (
serialPort.close();
}
};

export const setDeviceProjectKey = (
device: DeviceWithSerialnumber,
vComIndex: number,
projectKey: string,
): Promise<void> =>
runShellCommand(device, vComIndex, `mflt set_project_key ${projectKey}`);

export const setDeviceName = (
device: DeviceWithSerialnumber,
vComIndex: number,
name: string,
): Promise<void> => runShellCommand(device, vComIndex, `bt name "${name}"`);
2 changes: 1 addition & 1 deletion src/features/flows/nRF54L15_cloud/evaluate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default ({ vComIndex }: { vComIndex: number }) => {

switch (subStep) {
case CloudSubStep.ESTABLISH_CONNECTION:
return <EstablishConnection />;
return <EstablishConnection vComIndex={vComIndex} />;
case CloudSubStep.TRY_LBS:
return <TryLbs />;
case CloudSubStep.TEST_CRASH:
Expand Down