diff --git a/src/utilities/sequence-editor/from-seq-json.test.ts b/src/utilities/sequence-editor/from-seq-json.test.ts index 68736f4fb8..7f070554cd 100644 --- a/src/utilities/sequence-editor/from-seq-json.test.ts +++ b/src/utilities/sequence-editor/from-seq-json.test.ts @@ -461,19 +461,19 @@ C FSW_CMD_2 10 "ENUM" # fsw cmd 2 description description: 'immediate command', metadata: {}, stem: 'IC', - type: 'command', + type: 'immediate_command', }, { args: [], stem: 'IC2', - type: 'command', + type: 'immediate_command', }, { args: [], description: 'noop command, no arguments', metadata: { processor: 'VC1A' }, stem: 'NOOP', - type: 'command', + type: 'immediate_command', }, { args: [ @@ -487,12 +487,12 @@ C FSW_CMD_2 10 "ENUM" # fsw cmd 2 description Key: 'Value', }, sequence: 'seqA', - type: 'load', + type: 'immediate_load', }, { description: 'description', sequence: 'seqB', - type: 'activate', + type: 'immediate_activate', }, ], metadata: {}, diff --git a/src/utilities/sequence-editor/from-seq-json.ts b/src/utilities/sequence-editor/from-seq-json.ts index 160764e128..aa0540cff8 100644 --- a/src/utilities/sequence-editor/from-seq-json.ts +++ b/src/utilities/sequence-editor/from-seq-json.ts @@ -208,20 +208,20 @@ export async function seqJsonToSequence(input: string | null): Promise { if (seqJson.immediate_commands) { sequence.push(`\n`); sequence.push(`@IMMEDIATE\n`); - for (const rtc of seqJson.immediate_commands) { - switch (rtc.type) { - case 'command': { + for (const realTimeCommand of seqJson.immediate_commands) { + switch (realTimeCommand.type) { + case 'immediate_command': { // FSW Commands - sequence.push(commandToString(rtc)); + sequence.push(commandToString(realTimeCommand)); break; } - case 'activate': - case 'load': { - sequence.push(loadOrActivateToString(rtc)); + case 'immediate_activate': + case 'immediate_load': { + sequence.push(loadOrActivateToString(realTimeCommand)); break; } default: { - throw new Error(`Invalid immediate command type ${rtc.type}`); + throw new Error(`Invalid immediate command type ${realTimeCommand.type}`); } } } @@ -257,13 +257,23 @@ export async function seqJsonToSequence(input: string | null): Promise { return sequence.join(''); } +function isCommand(step: Command | ImmediateFswCommand): step is Command { + return (step as Command).time !== undefined; +} + function commandToString(step: Command | ImmediateFswCommand): string { - const time = 'time' in step ? `${seqJsonTimeToSequence(step.time)} ` : ''; const args = seqJsonArgsToSequence(step.args); const metadata = step.metadata ? seqJsonMetadataToSequence(step.metadata) : ''; - const models = 'models' in step ? (step.models ? seqJsonModelsToSequence(step.models) : '') : ''; const description = step.description ? seqJsonDescriptionToSequence(step.description) : ''; + // used for commands, ImmediateFswCommand doesn't support 'time' and 'models' + let time = ''; + let models = ''; + if (isCommand(step)) { + time = step.time ? `${seqJsonTimeToSequence(step.time)} ` : ''; + models = step.models ? (step.models ? seqJsonModelsToSequence(step.models) : '') : ''; + } + let commandString = `${time}${step.stem}${args}${description}`; // add a new line if on doesn't exit at the end of the commandString if (!commandString.endsWith('\n')) { @@ -275,14 +285,25 @@ function commandToString(step: Command | ImmediateFswCommand): string { } function loadOrActivateToString(step: Activate | Load | ImmediateActivate | ImmediateLoad) { - const time = 'time' in step ? `${seqJsonTimeToSequence(step.time)} ` : ''; + const time = (step as Activate | Load).time ? `${seqJsonTimeToSequence((step as Activate | Load).time)} ` : ''; const args = step.args ? seqJsonArgsToSequence(step.args) : ''; const metadata = step.metadata ? seqJsonMetadataToSequence(step.metadata) : ''; const models = step.models ? seqJsonModelsToSequence(step.models) : ''; const engine = step.engine !== undefined ? `@ENGINE ${step.engine.toString(10)}\n` : ''; const epoch = step.epoch !== undefined ? `@EPOCH ${quoteEscape(step.epoch)}\n` : ''; const description = step.description ? seqJsonDescriptionToSequence(step.description) : ''; - const stepType = `@${step.type === 'activate' ? 'ACTIVATE' : 'LOAD'}(${quoteEscape(step.sequence)})`; + let stepType = ''; + switch (step.type) { + case 'activate': + case 'immediate_activate': + stepType = '@ACTIVATE'; + break; + case 'load': + case 'immediate_load': + stepType = '@LOAD'; + break; + } + stepType += `(${quoteEscape(step.sequence)})`; let stepString = `${time}${stepType}${args}${description}`; if (!stepString.endsWith('\n')) { stepString += '\n';