Skip to content

Commit

Permalink
Address Bryan PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
goetzrrGit committed Nov 19, 2024
1 parent 3ffde47 commit 684ea67
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/utilities/sequence-editor/from-seq-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,20 @@ export async function seqJsonToSequence(input: string | null): Promise<string> {
if (seqJson.immediate_commands) {
sequence.push(`\n`);
sequence.push(`@IMMEDIATE\n`);
for (const rtc of seqJson.immediate_commands) {
switch (rtc.type) {
for (const realTimeCommand of seqJson.immediate_commands) {
switch (realTimeCommand.type) {
case 'command': {
// FSW Commands
sequence.push(commandToString(rtc));
sequence.push(commandToString(realTimeCommand));
break;
}
case 'activate':
case 'load': {
sequence.push(loadOrActivateToString(rtc));
sequence.push(loadOrActivateToString(realTimeCommand));
break;
}
default: {
throw new Error(`Invalid immediate command type ${rtc.type}`);
throw new Error(`Invalid immediate command type ${realTimeCommand.type}`);
}
}
}
Expand Down Expand Up @@ -257,13 +257,23 @@ export async function seqJsonToSequence(input: string | null): Promise<string> {
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')) {
Expand All @@ -275,7 +285,7 @@ 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) : '';
Expand Down
17 changes: 15 additions & 2 deletions src/utilities/sequence-editor/to-seq-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ function parseActivateLoad(
const metadata = parseMetadata(stepNode, text);
const models = parseModel(stepNode, text);

if (stepNode.name === 'Activate') {
return {
args,
description,
engine,
epoch,
metadata,
models,
sequence,
...(!isRTC ? { time } : {}),
type: 'activate',
};
}
return {
args,
description,
Expand All @@ -199,8 +212,8 @@ function parseActivateLoad(
models,
sequence,
...(!isRTC ? { time } : {}),
type: stepNode.name === 'Load' ? 'load' : 'activate',
} as Activate | Load | ImmediateActivate | ImmediateLoad;
type: 'load',
};
}

function parseEngine(stepNode: SyntaxNode, text: string): number | undefined {
Expand Down

0 comments on commit 684ea67

Please sign in to comment.