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';
17
17
import { SetControlCommand } from './scenario/SetControlCommand.js' ;
18
18
import { WaitSerialCommand } from './scenario/WaitSerialCommand.js' ;
19
19
import { uploadFirmware } from './uploadFirmware.js' ;
20
+ import { WriteSerialCommand } from './scenario/WriteSerialCommand.js' ;
20
21
21
22
const millis = 1_000_000 ;
22
23
@@ -143,6 +144,7 @@ async function main() {
143
144
'expect-pin' : new ExpectPinCommand ( ) ,
144
145
'set-control' : new SetControlCommand ( ) ,
145
146
'wait-serial' : new WaitSerialCommand ( expectEngine ) ,
147
+ 'write-serial' : new WriteSerialCommand ( ) ,
146
148
} ) ;
147
149
scenario . validate ( ) ;
148
150
}
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