File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import { ExpectPinCommand } from './scenario/ExpectPinCommand.js';
1717import { SetControlCommand } from './scenario/SetControlCommand.js' ;
1818import { WaitSerialCommand } from './scenario/WaitSerialCommand.js' ;
1919import { uploadFirmware } from './uploadFirmware.js' ;
20+ import { WriteSerialCommand } from './scenario/WriteSerialCommand.js' ;
2021
2122const millis = 1_000_000 ;
2223
@@ -143,6 +144,7 @@ async function main() {
143144 'expect-pin' : new ExpectPinCommand ( ) ,
144145 'set-control' : new SetControlCommand ( ) ,
145146 'wait-serial' : new WaitSerialCommand ( expectEngine ) ,
147+ 'write-serial' : new WriteSerialCommand ( ) ,
146148 } ) ;
147149 scenario . validate ( ) ;
148150 }
Original file line number Diff line number Diff line change 1+ import type { APIClient } from '../APIClient.js' ;
2+ import type { IScenarioCommand , TestScenario } from '../TestScenario.js' ;
3+
4+ const encoder = new TextEncoder ( ) ;
5+
6+ export class WriteSerialCommand implements IScenarioCommand {
7+ validate ( value : string | number [ ] ) {
8+ if ( value instanceof Array ) {
9+ if ( value . length === 0 ) {
10+ throw new Error ( `Array must contain at least one number` ) ;
11+ }
12+ if ( value . some ( ( v ) => typeof v !== 'number' ) ) {
13+ throw new Error ( `Array must contain only numbers` ) ;
14+ }
15+ return ;
16+ }
17+ if ( typeof value !== 'string' ) {
18+ throw new Error ( `Value must be a string or an array of numbers` ) ;
19+ }
20+ }
21+
22+ async run ( scenario : TestScenario , client : APIClient , text : string | number [ ] ) {
23+ const data = text instanceof Array ? new Uint8Array ( text ) : encoder . encode ( text ) ;
24+ await client . serialMonitorWrite ( data ) ;
25+ await scenario . resume ( ) ;
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments